mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 14:41:23 -07:00
Bulk autopep8 (modules)
As agreed in 2017-12-07 Core meeting bulk fix pep8 issues Generated using: autopep8 1.3.3 (pycodestyle: 2.3.1) autopep8 -r --max-line-length 160 --in-place --ignore E305,E402,E722,E741 lib/ansible/modules Manually fix issues that autopep8 has introduced
This commit is contained in:
parent
d13d7e9404
commit
c57a7f05e1
314 changed files with 3462 additions and 3383 deletions
|
@ -171,7 +171,6 @@ def main():
|
|||
# validate the ports data structure
|
||||
validate_ports(module, slb_server_ports)
|
||||
|
||||
|
||||
json_post = {
|
||||
"server-list": [
|
||||
{
|
||||
|
@ -188,7 +187,7 @@ def main():
|
|||
if slb_server_status:
|
||||
json_post['server-list'][0]['action'] = slb_server_status
|
||||
|
||||
slb_server_data = axapi_call_v3(module, axapi_base_url+'slb/server/', method='GET', body='', signature=signature)
|
||||
slb_server_data = axapi_call_v3(module, axapi_base_url + 'slb/server/', method='GET', body='', signature=signature)
|
||||
|
||||
# for empty slb server list
|
||||
if axapi_failure(slb_server_data):
|
||||
|
@ -203,7 +202,7 @@ def main():
|
|||
changed = False
|
||||
if operation == 'create':
|
||||
if slb_server_exists is False:
|
||||
result = axapi_call_v3(module, axapi_base_url+'slb/server/', method='POST', body=json.dumps(json_post), signature=signature)
|
||||
result = axapi_call_v3(module, axapi_base_url + 'slb/server/', method='POST', body=json.dumps(json_post), signature=signature)
|
||||
if axapi_failure(result):
|
||||
module.fail_json(msg="failed to create the server: %s" % result['response']['err']['msg'])
|
||||
changed = True
|
||||
|
@ -234,7 +233,7 @@ def main():
|
|||
|
||||
# if the config has changed, save the config unless otherwise requested
|
||||
if changed and write_config:
|
||||
write_result = axapi_call_v3(module, axapi_base_url+'write/memory/', method='POST', body='', signature=signature)
|
||||
write_result = axapi_call_v3(module, axapi_base_url + 'write/memory/', method='POST', body='', signature=signature)
|
||||
if axapi_failure(write_result):
|
||||
module.fail_json(msg="failed to save the configuration: %s" % write_result['response']['err']['msg'])
|
||||
|
||||
|
|
|
@ -102,7 +102,7 @@ content:
|
|||
import json
|
||||
|
||||
from ansible.module_utils.network.a10.a10 import (axapi_call, a10_argument_spec, axapi_authenticate, axapi_failure,
|
||||
axapi_enabled_disabled, axapi_get_vport_protocol, AXAPI_VPORT_PROTOCOLS)
|
||||
axapi_enabled_disabled, axapi_get_vport_protocol, AXAPI_VPORT_PROTOCOLS)
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.urls import url_argument_spec
|
||||
|
||||
|
@ -146,6 +146,7 @@ def validate_ports(module, ports):
|
|||
if 'service_group' not in item:
|
||||
item['service_group'] = ''
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = a10_argument_spec()
|
||||
argument_spec.update(url_argument_spec())
|
||||
|
|
|
@ -142,18 +142,19 @@ import json
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.aos.aos import get_aos_session, find_collection_item, do_load_resource, check_aos_version, content_to_dict
|
||||
|
||||
|
||||
def check_ranges_are_valid(module, ranges):
|
||||
|
||||
i = 1
|
||||
for range in ranges:
|
||||
if not isinstance(range, list) :
|
||||
if not isinstance(range, list):
|
||||
module.fail_json(msg="Range (%i) must be a list not %s" % (i, type(range)))
|
||||
elif len(range) != 2:
|
||||
module.fail_json(msg="Range (%i) must be a list of 2 members, not %i" % (i, len(range)))
|
||||
elif not isinstance( range[0], int ):
|
||||
module.fail_json(msg="1st element of range (%i) must be integer instead of %s " % (i,type(range[0])))
|
||||
elif not isinstance( range[1], int ):
|
||||
module.fail_json(msg="2nd element of range (%i) must be integer instead of %s " % (i,type(range[1])))
|
||||
elif not isinstance(range[0], int):
|
||||
module.fail_json(msg="1st element of range (%i) must be integer instead of %s " % (i, type(range[0])))
|
||||
elif not isinstance(range[1], int):
|
||||
module.fail_json(msg="2nd element of range (%i) must be integer instead of %s " % (i, type(range[1])))
|
||||
elif range[1] <= range[0]:
|
||||
module.fail_json(msg="2nd element of range (%i) must be bigger than 1st " % (i))
|
||||
|
||||
|
@ -161,24 +162,26 @@ def check_ranges_are_valid(module, ranges):
|
|||
|
||||
return True
|
||||
|
||||
|
||||
def get_list_of_range(asn_pool):
|
||||
ranges = []
|
||||
|
||||
for range in asn_pool.value['ranges']:
|
||||
ranges.append([ range['first'], range['last']])
|
||||
ranges.append([range['first'], range['last']])
|
||||
|
||||
return ranges
|
||||
|
||||
|
||||
def create_new_asn_pool(asn_pool, name, ranges):
|
||||
|
||||
# Create value
|
||||
datum = dict(display_name=name, ranges=[])
|
||||
for range in ranges:
|
||||
datum['ranges'].append(dict(first=range[0],last=range[1]))
|
||||
datum['ranges'].append(dict(first=range[0], last=range[1]))
|
||||
|
||||
asn_pool.datum = datum
|
||||
|
||||
## Write to AOS
|
||||
# Write to AOS
|
||||
return asn_pool.write()
|
||||
|
||||
|
||||
|
@ -190,7 +193,7 @@ def asn_pool_absent(module, aos, my_pool):
|
|||
if my_pool.exists is False:
|
||||
module.exit_json(changed=False, name=margs['name'], id='', value={})
|
||||
|
||||
## Check if object is currently in Use or Not
|
||||
# Check if object is currently in Use or Not
|
||||
# If in Use, return an error
|
||||
if my_pool.value:
|
||||
if my_pool.value['status'] != 'not_in_use':
|
||||
|
@ -205,10 +208,10 @@ def asn_pool_absent(module, aos, my_pool):
|
|||
except:
|
||||
module.fail_json(msg="An error occurred, while trying to delete the ASN Pool")
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value={} )
|
||||
module.exit_json(changed=True,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value={})
|
||||
|
||||
|
||||
def asn_pool_present(module, aos, my_pool):
|
||||
|
@ -236,10 +239,10 @@ def asn_pool_present(module, aos, my_pool):
|
|||
except:
|
||||
module.fail_json(msg="An error occurred while trying to create a new ASN Pool ")
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value=my_pool.value )
|
||||
module.exit_json(changed=True,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value=my_pool.value)
|
||||
|
||||
# Currently only check if the pool exist or not
|
||||
# if exist return change false
|
||||
|
@ -248,14 +251,16 @@ def asn_pool_present(module, aos, my_pool):
|
|||
# if pool already exist, check if list of ASN is the same
|
||||
# if same just return the object and report change false
|
||||
# if set(get_list_of_range(my_pool)) == set(margs['ranges']):
|
||||
module.exit_json( changed=False,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value=my_pool.value )
|
||||
module.exit_json(changed=False,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value=my_pool.value)
|
||||
|
||||
# ########################################################
|
||||
# Main Function
|
||||
# ########################################################
|
||||
|
||||
|
||||
def asn_pool(module):
|
||||
|
||||
margs = module.params
|
||||
|
@ -271,7 +276,7 @@ def asn_pool(module):
|
|||
# Check ID / Name and Content
|
||||
if margs['content'] is not None:
|
||||
|
||||
content = content_to_dict(module, margs['content'] )
|
||||
content = content_to_dict(module, margs['content'])
|
||||
|
||||
if 'display_name' in content.keys():
|
||||
item_name = content['display_name']
|
||||
|
@ -293,8 +298,8 @@ def asn_pool(module):
|
|||
# ----------------------------------------------------
|
||||
try:
|
||||
my_pool = find_collection_item(aos.AsnPools,
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
except:
|
||||
module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")
|
||||
|
||||
|
@ -309,19 +314,20 @@ def asn_pool(module):
|
|||
|
||||
asn_pool_present(module, aos, my_pool)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
session=dict(required=True, type="dict"),
|
||||
name=dict(required=False ),
|
||||
id=dict(required=False ),
|
||||
name=dict(required=False),
|
||||
id=dict(required=False),
|
||||
content=dict(required=False, type="json"),
|
||||
state=dict( required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present"),
|
||||
state=dict(required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present"),
|
||||
ranges=dict(required=False, type="list", default=[])
|
||||
),
|
||||
mutually_exclusive = [('name', 'id', 'content')],
|
||||
mutually_exclusive=[('name', 'id', 'content')],
|
||||
required_one_of=[('name', 'id', 'content')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -136,6 +136,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
from ansible.module_utils.network.aos.aos import get_aos_session, check_aos_version, find_collection_item
|
||||
from ansible.module_utils.pycompat24 import get_exception
|
||||
|
||||
|
||||
def create_blueprint(module, aos, name):
|
||||
|
||||
margs = module.params
|
||||
|
@ -152,7 +153,7 @@ def create_blueprint(module, aos, name):
|
|||
exc = get_exception()
|
||||
msg = "Unable to create blueprint: %s" % exc.message
|
||||
if 'UNPROCESSABLE ENTITY' in exc.message:
|
||||
msg+= ' (likely missing dependencies)'
|
||||
msg += ' (likely missing dependencies)'
|
||||
|
||||
module.fail_json(msg=msg)
|
||||
|
||||
|
@ -177,6 +178,7 @@ def ensure_absent(module, aos, blueprint):
|
|||
id=blueprint.id,
|
||||
name=blueprint.name)
|
||||
|
||||
|
||||
def ensure_present(module, aos, blueprint):
|
||||
margs = module.params
|
||||
|
||||
|
@ -211,13 +213,14 @@ def ensure_present(module, aos, blueprint):
|
|||
module.exit_json(changed=True,
|
||||
name=margs['name'])
|
||||
|
||||
|
||||
def ensure_build_ready(module, aos, blueprint):
|
||||
margs = module.params
|
||||
|
||||
if not blueprint.exists:
|
||||
module.fail_json(msg='blueprint %s does not exist' % blueprint.name)
|
||||
|
||||
if blueprint.await_build_ready(timeout=margs['timeout']*1000):
|
||||
if blueprint.await_build_ready(timeout=margs['timeout'] * 1000):
|
||||
module.exit_json(contents=blueprint.contents)
|
||||
else:
|
||||
module.fail_json(msg='blueprint %s has build errors',
|
||||
|
@ -247,8 +250,8 @@ def aos_blueprint(module):
|
|||
#----------------------------------------------------
|
||||
try:
|
||||
my_blueprint = find_collection_item(aos.Blueprints,
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
except:
|
||||
module.fail_json(msg="Unable to find the Blueprint based on name or ID, something went wrong")
|
||||
|
||||
|
@ -273,7 +276,7 @@ def main():
|
|||
argument_spec=dict(
|
||||
session=dict(required=True, type="dict"),
|
||||
name=dict(required=False),
|
||||
id=dict(required=False ),
|
||||
id=dict(required=False),
|
||||
state=dict(choices=[
|
||||
'present', 'absent', 'build-ready'],
|
||||
default='present'),
|
||||
|
@ -281,7 +284,7 @@ def main():
|
|||
template=dict(required=False),
|
||||
reference_arch=dict(required=False)
|
||||
),
|
||||
mutually_exclusive = [('name', 'id')],
|
||||
mutually_exclusive=[('name', 'id')],
|
||||
required_one_of=[('name', 'id')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -189,6 +189,7 @@ param_map_list = dict(
|
|||
)
|
||||
)
|
||||
|
||||
|
||||
def get_collection_from_param_map(module, aos):
|
||||
|
||||
param_map = None
|
||||
|
@ -220,6 +221,7 @@ def get_collection_from_param_map(module, aos):
|
|||
|
||||
return None
|
||||
|
||||
|
||||
def blueprint_param_present(module, aos, blueprint, param, param_value):
|
||||
|
||||
margs = module.params
|
||||
|
@ -278,6 +280,7 @@ def blueprint_param_absent(module, aos, blueprint, param, param_value):
|
|||
name=param.name,
|
||||
value=param.value)
|
||||
|
||||
|
||||
def blueprint_param(module):
|
||||
|
||||
margs = module.params
|
||||
|
@ -295,15 +298,15 @@ def blueprint_param(module):
|
|||
# --------------------------------------------------------------------
|
||||
try:
|
||||
blueprint = find_collection_item(aos.Blueprints,
|
||||
item_name=margs['blueprint'],
|
||||
item_id=margs['blueprint'])
|
||||
item_name=margs['blueprint'],
|
||||
item_id=margs['blueprint'])
|
||||
except:
|
||||
module.fail_json(msg="Unable to find the Blueprint based on name or ID, something went wrong")
|
||||
|
||||
if blueprint.exists is False:
|
||||
module.fail_json(msg='Blueprint %s does not exist.\n'
|
||||
'known blueprints are [%s]'%
|
||||
(margs['blueprint'],','.join(aos.Blueprints.names)))
|
||||
'known blueprints are [%s]' %
|
||||
(margs['blueprint'], ','.join(aos.Blueprints.names)))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# If get_param_list is defined, build the list of supported parameters
|
||||
|
@ -316,8 +319,8 @@ def blueprint_param(module):
|
|||
params_list[param] = blueprint.params[param].info
|
||||
|
||||
module.exit_json(changed=False,
|
||||
blueprint= blueprint.name,
|
||||
params_list=params_list )
|
||||
blueprint=blueprint.name,
|
||||
params_list=params_list)
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Check Param name, return an error if not supported by this blueprint
|
||||
|
@ -325,7 +328,7 @@ def blueprint_param(module):
|
|||
if margs['name'] in blueprint.params.names:
|
||||
param = blueprint.params[margs['name']]
|
||||
else:
|
||||
module.fail_json(msg='unable to access param %s' % margs['name'] )
|
||||
module.fail_json(msg='unable to access param %s' % margs['name'])
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Check if param_value needs to be converted to an object
|
||||
|
@ -350,6 +353,7 @@ def blueprint_param(module):
|
|||
|
||||
blueprint_param_present(module, aos, blueprint, param, param_value)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
|
@ -359,7 +363,7 @@ def main():
|
|||
name=dict(required=False),
|
||||
value=dict(required=False, type="dict"),
|
||||
param_map=dict(required=False),
|
||||
state=dict( choices=['present', 'absent'], default='present')
|
||||
state=dict(choices=['present', 'absent'], default='present')
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -88,6 +88,7 @@ from ansible.module_utils.pycompat24 import get_exception
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.aos.aos import get_aos_session, find_collection_item, do_load_resource, check_aos_version, content_to_dict
|
||||
|
||||
|
||||
def ensure_present(module, aos, blueprint, virtnet):
|
||||
|
||||
# if exist already return tru
|
||||
|
@ -104,7 +105,7 @@ def ensure_present(module, aos, blueprint, virtnet):
|
|||
virtnet.create(module.params['content'])
|
||||
except:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to create virtual-network : %r" % e )
|
||||
module.fail_json(msg="unable to create virtual-network : %r" % e)
|
||||
|
||||
module.exit_json(changed=True,
|
||||
blueprint=blueprint.name,
|
||||
|
@ -121,7 +122,7 @@ def ensure_absent(module, aos, blueprint, virtnet):
|
|||
virtnet.delete()
|
||||
except:
|
||||
e = get_exception()
|
||||
module.fail_json(msg="unable to delete virtual-network %s : %r" % (virtnet.name, e) )
|
||||
module.fail_json(msg="unable to delete virtual-network %s : %r" % (virtnet.name, e))
|
||||
|
||||
module.exit_json(changed=True,
|
||||
blueprint=blueprint.name)
|
||||
|
@ -130,6 +131,7 @@ def ensure_absent(module, aos, blueprint, virtnet):
|
|||
module.exit_json(changed=False,
|
||||
blueprint=blueprint.name)
|
||||
|
||||
|
||||
def blueprint_virtnet(module):
|
||||
|
||||
margs = module.params
|
||||
|
@ -147,22 +149,22 @@ def blueprint_virtnet(module):
|
|||
# --------------------------------------------------------------------
|
||||
try:
|
||||
blueprint = find_collection_item(aos.Blueprints,
|
||||
item_name=margs['blueprint'],
|
||||
item_id=margs['blueprint'])
|
||||
item_name=margs['blueprint'],
|
||||
item_id=margs['blueprint'])
|
||||
except:
|
||||
module.fail_json(msg="Unable to find the Blueprint based on name or ID, something went wrong")
|
||||
|
||||
if blueprint.exists is False:
|
||||
module.fail_json(msg='Blueprint %s does not exist.\n'
|
||||
'known blueprints are [%s]'%
|
||||
(margs['blueprint'],','.join(aos.Blueprints.names)))
|
||||
'known blueprints are [%s]' %
|
||||
(margs['blueprint'], ','.join(aos.Blueprints.names)))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Convert "content" to dict and extract name
|
||||
# --------------------------------------------------------------------
|
||||
if margs['content'] is not None:
|
||||
|
||||
content = content_to_dict(module, margs['content'] )
|
||||
content = content_to_dict(module, margs['content'])
|
||||
|
||||
if 'display_name' in content.keys():
|
||||
item_name = content['display_name']
|
||||
|
@ -179,7 +181,7 @@ def blueprint_virtnet(module):
|
|||
virtnet = blueprint.VirtualNetworks[item_name]
|
||||
except:
|
||||
module.fail_json(msg="Something went wrong while trying to find Virtual Network %s in blueprint %s"
|
||||
% ( item_name, blueprint.name ))
|
||||
% (item_name, blueprint.name))
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Proceed based on State value
|
||||
|
@ -198,11 +200,11 @@ def main():
|
|||
argument_spec=dict(
|
||||
session=dict(required=True, type="dict"),
|
||||
blueprint=dict(required=True),
|
||||
name=dict(required=False ),
|
||||
name=dict(required=False),
|
||||
content=dict(required=False, type="json"),
|
||||
state=dict(choices=['present', 'absent'], default='present')
|
||||
),
|
||||
mutually_exclusive = [('name', 'content')],
|
||||
mutually_exclusive=[('name', 'content')],
|
||||
required_one_of=[('name', 'content')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -132,7 +132,7 @@ def aos_device_normal(module, aos, dev):
|
|||
value=dev.value)
|
||||
else:
|
||||
# Check if the device is online
|
||||
if dev.state in ('OOS-READY','IS-READY'):
|
||||
if dev.state in ('OOS-READY', 'IS-READY'):
|
||||
module.exit_json(changed=False,
|
||||
name=dev.name,
|
||||
id=dev.id,
|
||||
|
@ -140,6 +140,7 @@ def aos_device_normal(module, aos, dev):
|
|||
else:
|
||||
module.fail_json(msg="Device is in '%s' state" % dev.state)
|
||||
|
||||
|
||||
def aos_device(module):
|
||||
margs = module.params
|
||||
|
||||
|
@ -161,8 +162,8 @@ def aos_device(module):
|
|||
# Find Object if available based on ID or Name
|
||||
#----------------------------------------------------
|
||||
dev = find_collection_item(aos.Devices,
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
|
||||
if dev.exists is False:
|
||||
module.fail_json(msg="unknown device '%s'" % margs['name'])
|
||||
|
@ -189,6 +190,7 @@ def aos_device(module):
|
|||
if margs['state'] == 'normal':
|
||||
aos_device_normal(module, aos, dev)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
|
@ -196,12 +198,12 @@ def main():
|
|||
session=dict(required=True, type="dict"),
|
||||
name=dict(required=False),
|
||||
id=dict(required=False),
|
||||
state=dict( choices=['normal'],
|
||||
default='normal'),
|
||||
approve=dict( required=False, type='bool' ),
|
||||
location=dict( required=False, default='')
|
||||
state=dict(choices=['normal'],
|
||||
default='normal'),
|
||||
approve=dict(required=False, type='bool'),
|
||||
location=dict(required=False, default='')
|
||||
),
|
||||
mutually_exclusive = [('name', 'id')],
|
||||
mutually_exclusive=[('name', 'id')],
|
||||
required_one_of=[('name', 'id')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -155,16 +155,18 @@ from ansible.module_utils.network.aos.aos import get_aos_session, find_collectio
|
|||
def create_new_ext_router(module, my_ext_router, name, loopback, asn):
|
||||
|
||||
# Create value
|
||||
datum = dict(display_name=name, address=loopback, asn=asn )
|
||||
datum = dict(display_name=name, address=loopback, asn=asn)
|
||||
|
||||
my_ext_router.datum = datum
|
||||
|
||||
## Write to AOS
|
||||
# Write to AOS
|
||||
return my_ext_router.write()
|
||||
|
||||
#########################################################
|
||||
# State Processing
|
||||
#########################################################
|
||||
|
||||
|
||||
def ext_router_absent(module, aos, my_ext_router):
|
||||
|
||||
margs = module.params
|
||||
|
@ -174,7 +176,7 @@ def ext_router_absent(module, aos, my_ext_router):
|
|||
module.exit_json(changed=False,
|
||||
name=margs['name'],
|
||||
id=margs['id'],
|
||||
value={} )
|
||||
value={})
|
||||
|
||||
# If not in check mode, delete External Router
|
||||
if not module.check_mode:
|
||||
|
@ -185,10 +187,11 @@ def ext_router_absent(module, aos, my_ext_router):
|
|||
except:
|
||||
module.fail_json(msg="An error occurred, while trying to delete the External Router")
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_ext_router.name,
|
||||
id=my_ext_router.id,
|
||||
value={} )
|
||||
module.exit_json(changed=True,
|
||||
name=my_ext_router.name,
|
||||
id=my_ext_router.id,
|
||||
value={})
|
||||
|
||||
|
||||
def ext_router_present(module, aos, my_ext_router):
|
||||
|
||||
|
@ -210,16 +213,15 @@ def ext_router_present(module, aos, my_ext_router):
|
|||
my_ext_router,
|
||||
margs['name'],
|
||||
margs['loopback'],
|
||||
margs['asn'] )
|
||||
margs['asn'])
|
||||
my_ext_router = my_new_ext_router
|
||||
except:
|
||||
module.fail_json(msg="An error occurred while trying to create a new External Router")
|
||||
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_ext_router.name,
|
||||
id=my_ext_router.id,
|
||||
value=my_ext_router.value )
|
||||
module.exit_json(changed=True,
|
||||
name=my_ext_router.name,
|
||||
id=my_ext_router.id,
|
||||
value=my_ext_router.value)
|
||||
|
||||
# if external Router already exist, check if loopback and ASN are the same
|
||||
# if same just return the object and report change false
|
||||
|
@ -249,14 +251,16 @@ def ext_router_present(module, aos, my_ext_router):
|
|||
if int(asn) != int(my_ext_router.value['asn']):
|
||||
module.fail_json(msg="my_ext_router already exist but ASN is different, currently not supported to update a module")
|
||||
|
||||
module.exit_json( changed=False,
|
||||
name=my_ext_router.name,
|
||||
id=my_ext_router.id,
|
||||
value=my_ext_router.value )
|
||||
module.exit_json(changed=False,
|
||||
name=my_ext_router.name,
|
||||
id=my_ext_router.id,
|
||||
value=my_ext_router.value)
|
||||
|
||||
#########################################################
|
||||
# Main Function
|
||||
#########################################################
|
||||
|
||||
|
||||
def ext_router(module):
|
||||
|
||||
margs = module.params
|
||||
|
@ -271,7 +275,7 @@ def ext_router(module):
|
|||
|
||||
if margs['content'] is not None:
|
||||
|
||||
content = content_to_dict(module, margs['content'] )
|
||||
content = content_to_dict(module, margs['content'])
|
||||
|
||||
if 'display_name' in content.keys():
|
||||
item_name = content['display_name']
|
||||
|
@ -289,8 +293,8 @@ def ext_router(module):
|
|||
#----------------------------------------------------
|
||||
try:
|
||||
my_ext_router = find_collection_item(aos.ExternalRouters,
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
except:
|
||||
module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")
|
||||
|
||||
|
@ -305,20 +309,21 @@ def ext_router(module):
|
|||
|
||||
ext_router_present(module, aos, my_ext_router)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
session=dict(required=True, type="dict"),
|
||||
name=dict(required=False ),
|
||||
id=dict(required=False ),
|
||||
name=dict(required=False),
|
||||
id=dict(required=False),
|
||||
content=dict(required=False, type="json"),
|
||||
state=dict( required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present"),
|
||||
state=dict(required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present"),
|
||||
loopback=dict(required=False),
|
||||
asn=dict(required=False)
|
||||
),
|
||||
mutually_exclusive = [('name', 'id', 'content')],
|
||||
mutually_exclusive=[('name', 'id', 'content')],
|
||||
required_one_of=[('name', 'id', 'content')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -167,6 +167,7 @@ import json
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.network.aos.aos import get_aos_session, find_collection_item, do_load_resource, check_aos_version, content_to_dict
|
||||
|
||||
|
||||
def get_list_of_subnets(ip_pool):
|
||||
subnets = []
|
||||
|
||||
|
@ -175,6 +176,7 @@ def get_list_of_subnets(ip_pool):
|
|||
|
||||
return subnets
|
||||
|
||||
|
||||
def create_new_ip_pool(ip_pool, name, subnets):
|
||||
|
||||
# Create value
|
||||
|
@ -184,12 +186,14 @@ def create_new_ip_pool(ip_pool, name, subnets):
|
|||
|
||||
ip_pool.datum = datum
|
||||
|
||||
## Write to AOS
|
||||
# Write to AOS
|
||||
return ip_pool.write()
|
||||
|
||||
#########################################################
|
||||
# State Processing
|
||||
#########################################################
|
||||
|
||||
|
||||
def ip_pool_absent(module, aos, my_pool):
|
||||
|
||||
margs = module.params
|
||||
|
@ -198,7 +202,7 @@ def ip_pool_absent(module, aos, my_pool):
|
|||
if my_pool.exists is False:
|
||||
module.exit_json(changed=False, name=margs['name'], id='', value={})
|
||||
|
||||
## Check if object is currently in Use or Not
|
||||
# Check if object is currently in Use or Not
|
||||
# If in Use, return an error
|
||||
if my_pool.value:
|
||||
if my_pool.value['status'] != 'not_in_use':
|
||||
|
@ -213,10 +217,11 @@ def ip_pool_absent(module, aos, my_pool):
|
|||
except:
|
||||
module.fail_json(msg="An error occurred, while trying to delete the IP Pool")
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value={} )
|
||||
module.exit_json(changed=True,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value={})
|
||||
|
||||
|
||||
def ip_pool_present(module, aos, my_pool):
|
||||
|
||||
|
@ -248,24 +253,26 @@ def ip_pool_present(module, aos, my_pool):
|
|||
except:
|
||||
module.fail_json(msg="An error occurred while trying to create a new IP Pool ")
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value=my_pool.value )
|
||||
module.exit_json(changed=True,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value=my_pool.value)
|
||||
|
||||
# if pool already exist, check if list of network is the same
|
||||
# if same just return the object and report change false
|
||||
if set(get_list_of_subnets(my_pool)) == set(margs['subnets']):
|
||||
module.exit_json( changed=False,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value=my_pool.value )
|
||||
module.exit_json(changed=False,
|
||||
name=my_pool.name,
|
||||
id=my_pool.id,
|
||||
value=my_pool.value)
|
||||
else:
|
||||
module.fail_json(msg="ip_pool already exist but value is different, currently not supported to update a module")
|
||||
|
||||
#########################################################
|
||||
# Main Function
|
||||
#########################################################
|
||||
|
||||
|
||||
def ip_pool(module):
|
||||
|
||||
margs = module.params
|
||||
|
@ -280,7 +287,7 @@ def ip_pool(module):
|
|||
|
||||
if margs['content'] is not None:
|
||||
|
||||
content = content_to_dict(module, margs['content'] )
|
||||
content = content_to_dict(module, margs['content'])
|
||||
|
||||
if 'display_name' in content.keys():
|
||||
item_name = content['display_name']
|
||||
|
@ -298,8 +305,8 @@ def ip_pool(module):
|
|||
#----------------------------------------------------
|
||||
try:
|
||||
my_pool = find_collection_item(aos.IpPools,
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
except:
|
||||
module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")
|
||||
|
||||
|
@ -314,19 +321,20 @@ def ip_pool(module):
|
|||
|
||||
ip_pool_present(module, aos, my_pool)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
session=dict(required=True, type="dict"),
|
||||
name=dict(required=False ),
|
||||
id=dict(required=False ),
|
||||
name=dict(required=False),
|
||||
id=dict(required=False),
|
||||
content=dict(required=False, type="json"),
|
||||
state=dict( required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present"),
|
||||
state=dict(required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present"),
|
||||
subnets=dict(required=False, type="list")
|
||||
),
|
||||
mutually_exclusive = [('name', 'id', 'content')],
|
||||
mutually_exclusive=[('name', 'id', 'content')],
|
||||
required_one_of=[('name', 'id', 'content')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -134,6 +134,8 @@ from ansible.module_utils.network.aos.aos import get_aos_session, find_collectio
|
|||
#########################################################
|
||||
# State Processing
|
||||
#########################################################
|
||||
|
||||
|
||||
def logical_device_absent(module, aos, my_logical_dev):
|
||||
|
||||
margs = module.params
|
||||
|
@ -154,10 +156,11 @@ def logical_device_absent(module, aos, my_logical_dev):
|
|||
except:
|
||||
module.fail_json(msg="An error occurred, while trying to delete the Logical Device")
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_logical_dev.name,
|
||||
id=my_logical_dev.id,
|
||||
value={} )
|
||||
module.exit_json(changed=True,
|
||||
name=my_logical_dev.name,
|
||||
id=my_logical_dev.id,
|
||||
value={})
|
||||
|
||||
|
||||
def logical_device_present(module, aos, my_logical_dev):
|
||||
|
||||
|
@ -174,14 +177,16 @@ def logical_device_present(module, aos, my_logical_dev):
|
|||
if my_logical_dev.exists is False and 'content' not in margs.keys():
|
||||
module.fail_json(msg="'content' is mandatory for module that don't exist currently")
|
||||
|
||||
module.exit_json( changed=False,
|
||||
name=my_logical_dev.name,
|
||||
id=my_logical_dev.id,
|
||||
value=my_logical_dev.value )
|
||||
module.exit_json(changed=False,
|
||||
name=my_logical_dev.name,
|
||||
id=my_logical_dev.id,
|
||||
value=my_logical_dev.value)
|
||||
|
||||
#########################################################
|
||||
# Main Function
|
||||
#########################################################
|
||||
|
||||
|
||||
def logical_device(module):
|
||||
|
||||
margs = module.params
|
||||
|
@ -196,7 +201,7 @@ def logical_device(module):
|
|||
|
||||
if margs['content'] is not None:
|
||||
|
||||
content = content_to_dict(module, margs['content'] )
|
||||
content = content_to_dict(module, margs['content'])
|
||||
|
||||
if 'display_name' in content.keys():
|
||||
item_name = content['display_name']
|
||||
|
@ -227,18 +232,19 @@ def logical_device(module):
|
|||
|
||||
logical_device_present(module, aos, my_logical_dev)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
session=dict(required=True, type="dict"),
|
||||
name=dict(required=False ),
|
||||
id=dict(required=False ),
|
||||
name=dict(required=False),
|
||||
id=dict(required=False),
|
||||
content=dict(required=False, type="json"),
|
||||
state=dict( required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present")
|
||||
state=dict(required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present")
|
||||
),
|
||||
mutually_exclusive = [('name', 'id', 'content')],
|
||||
mutually_exclusive=[('name', 'id', 'content')],
|
||||
required_one_of=[('name', 'id', 'content')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -154,6 +154,8 @@ from ansible.module_utils.network.aos.aos import get_aos_session, find_collectio
|
|||
#########################################################
|
||||
# State Processing
|
||||
#########################################################
|
||||
|
||||
|
||||
def logical_device_map_absent(module, aos, my_log_dev_map):
|
||||
|
||||
margs = module.params
|
||||
|
@ -172,10 +174,11 @@ def logical_device_map_absent(module, aos, my_log_dev_map):
|
|||
except:
|
||||
module.fail_json(msg="An error occurred, while trying to delete the Logical Device Map")
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_log_dev_map.name,
|
||||
id=my_log_dev_map.id,
|
||||
value={} )
|
||||
module.exit_json(changed=True,
|
||||
name=my_log_dev_map.name,
|
||||
id=my_log_dev_map.id,
|
||||
value={})
|
||||
|
||||
|
||||
def logical_device_map_present(module, aos, my_log_dev_map):
|
||||
|
||||
|
@ -194,14 +197,16 @@ def logical_device_map_present(module, aos, my_log_dev_map):
|
|||
if my_log_dev_map.exists is False and 'content' not in margs.keys():
|
||||
module.fail_json(msg="'Content' is mandatory for module that don't exist currently")
|
||||
|
||||
module.exit_json( changed=False,
|
||||
name=my_log_dev_map.name,
|
||||
id=my_log_dev_map.id,
|
||||
value=my_log_dev_map.value )
|
||||
module.exit_json(changed=False,
|
||||
name=my_log_dev_map.name,
|
||||
id=my_log_dev_map.id,
|
||||
value=my_log_dev_map.value)
|
||||
|
||||
#########################################################
|
||||
# Main Function
|
||||
#########################################################
|
||||
|
||||
|
||||
def logical_device_map(module):
|
||||
|
||||
margs = module.params
|
||||
|
@ -216,7 +221,7 @@ def logical_device_map(module):
|
|||
|
||||
if margs['content'] is not None:
|
||||
|
||||
content = content_to_dict(module, margs['content'] )
|
||||
content = content_to_dict(module, margs['content'])
|
||||
|
||||
if 'display_name' in content.keys():
|
||||
item_name = content['display_name']
|
||||
|
@ -234,8 +239,8 @@ def logical_device_map(module):
|
|||
#----------------------------------------------------
|
||||
try:
|
||||
my_log_dev_map = find_collection_item(aos.LogicalDeviceMaps,
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
except:
|
||||
module.fail_json(msg="Unable to find the Logical Device Map based on name or ID, something went wrong")
|
||||
|
||||
|
@ -250,18 +255,19 @@ def logical_device_map(module):
|
|||
|
||||
logical_device_map_present(module, aos, my_log_dev_map)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
session=dict(required=True, type="dict"),
|
||||
name=dict(required=False ),
|
||||
id=dict(required=False ),
|
||||
name=dict(required=False),
|
||||
id=dict(required=False),
|
||||
content=dict(required=False, type="json"),
|
||||
state=dict( required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present")
|
||||
state=dict(required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present")
|
||||
),
|
||||
mutually_exclusive = [('name', 'id', 'content')],
|
||||
mutually_exclusive=[('name', 'id', 'content')],
|
||||
required_one_of=[('name', 'id', 'content')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -133,6 +133,8 @@ from ansible.module_utils.network.aos.aos import get_aos_session, find_collectio
|
|||
#########################################################
|
||||
# State Processing
|
||||
#########################################################
|
||||
|
||||
|
||||
def rack_type_absent(module, aos, my_rack_type):
|
||||
|
||||
margs = module.params
|
||||
|
@ -151,10 +153,11 @@ def rack_type_absent(module, aos, my_rack_type):
|
|||
except:
|
||||
module.fail_json(msg="An error occurred, while trying to delete the Rack Type")
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_rack_type.name,
|
||||
id=my_rack_type.id,
|
||||
value={} )
|
||||
module.exit_json(changed=True,
|
||||
name=my_rack_type.name,
|
||||
id=my_rack_type.id,
|
||||
value={})
|
||||
|
||||
|
||||
def rack_type_present(module, aos, my_rack_type):
|
||||
|
||||
|
@ -171,14 +174,16 @@ def rack_type_present(module, aos, my_rack_type):
|
|||
if my_rack_type.exists is False and 'content' not in margs.keys():
|
||||
module.fail_json(msg="'content' is mandatory for module that don't exist currently")
|
||||
|
||||
module.exit_json( changed=False,
|
||||
name=my_rack_type.name,
|
||||
id=my_rack_type.id,
|
||||
value=my_rack_type.value )
|
||||
module.exit_json(changed=False,
|
||||
name=my_rack_type.name,
|
||||
id=my_rack_type.id,
|
||||
value=my_rack_type.value)
|
||||
|
||||
#########################################################
|
||||
# Main Function
|
||||
#########################################################
|
||||
|
||||
|
||||
def rack_type(module):
|
||||
|
||||
margs = module.params
|
||||
|
@ -193,7 +198,7 @@ def rack_type(module):
|
|||
|
||||
if margs['content'] is not None:
|
||||
|
||||
content = content_to_dict(module, margs['content'] )
|
||||
content = content_to_dict(module, margs['content'])
|
||||
|
||||
if 'display_name' in content.keys():
|
||||
item_name = content['display_name']
|
||||
|
@ -210,8 +215,8 @@ def rack_type(module):
|
|||
# Find Object if available based on ID or Name
|
||||
#----------------------------------------------------
|
||||
my_rack_type = find_collection_item(aos.RackTypes,
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
|
||||
#----------------------------------------------------
|
||||
# Proceed based on State value
|
||||
|
@ -224,18 +229,19 @@ def rack_type(module):
|
|||
|
||||
rack_type_present(module, aos, my_rack_type)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
session=dict(required=True, type="dict"),
|
||||
name=dict(required=False ),
|
||||
id=dict(required=False ),
|
||||
name=dict(required=False),
|
||||
id=dict(required=False),
|
||||
content=dict(required=False, type="json"),
|
||||
state=dict( required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present")
|
||||
state=dict(required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present")
|
||||
),
|
||||
mutually_exclusive = [('name', 'id', 'content')],
|
||||
mutually_exclusive=[('name', 'id', 'content')],
|
||||
required_one_of=[('name', 'id', 'content')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -143,6 +143,8 @@ from ansible.module_utils.network.aos.aos import get_aos_session, find_collectio
|
|||
#########################################################
|
||||
# State Processing
|
||||
#########################################################
|
||||
|
||||
|
||||
def template_absent(module, aos, my_template):
|
||||
|
||||
margs = module.params
|
||||
|
@ -163,10 +165,11 @@ def template_absent(module, aos, my_template):
|
|||
except:
|
||||
module.fail_json(msg="An error occurred, while trying to delete the Template")
|
||||
|
||||
module.exit_json( changed=True,
|
||||
name=my_template.name,
|
||||
id=my_template.id,
|
||||
value={} )
|
||||
module.exit_json(changed=True,
|
||||
name=my_template.name,
|
||||
id=my_template.id,
|
||||
value={})
|
||||
|
||||
|
||||
def template_present(module, aos, my_template):
|
||||
|
||||
|
@ -186,10 +189,10 @@ def template_present(module, aos, my_template):
|
|||
module.fail_json(msg="'content' is mandatory for module that don't exist currently")
|
||||
|
||||
# if module already exist, just return it
|
||||
module.exit_json( changed=False,
|
||||
name=my_template.name,
|
||||
id=my_template.id,
|
||||
value=my_template.value )
|
||||
module.exit_json(changed=False,
|
||||
name=my_template.name,
|
||||
id=my_template.id,
|
||||
value=my_template.value)
|
||||
|
||||
|
||||
#########################################################
|
||||
|
@ -209,7 +212,7 @@ def aos_template(module):
|
|||
|
||||
if margs['content'] is not None:
|
||||
|
||||
content = content_to_dict(module, margs['content'] )
|
||||
content = content_to_dict(module, margs['content'])
|
||||
|
||||
if 'display_name' in content.keys():
|
||||
item_name = content['display_name']
|
||||
|
@ -227,8 +230,8 @@ def aos_template(module):
|
|||
#----------------------------------------------------
|
||||
try:
|
||||
my_template = find_collection_item(aos.DesignTemplates,
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
item_name=item_name,
|
||||
item_id=item_id)
|
||||
except:
|
||||
module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")
|
||||
|
||||
|
@ -243,18 +246,19 @@ def aos_template(module):
|
|||
|
||||
template_present(module, aos, my_template)
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
session=dict(required=True, type="dict"),
|
||||
name=dict(required=False ),
|
||||
id=dict(required=False ),
|
||||
name=dict(required=False),
|
||||
id=dict(required=False),
|
||||
content=dict(required=False, type="json"),
|
||||
state=dict( required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present")
|
||||
state=dict(required=False,
|
||||
choices=['present', 'absent'],
|
||||
default="present")
|
||||
),
|
||||
mutually_exclusive = [('name', 'id', 'content')],
|
||||
mutually_exclusive=[('name', 'id', 'content')],
|
||||
required_one_of=[('name', 'id', 'content')],
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
|
|
@ -151,6 +151,7 @@ def get_acl_config(module, acl_name):
|
|||
|
||||
return NetworkConfig(indent=1, contents='\n'.join(filtered_config))
|
||||
|
||||
|
||||
def parse_acl_name(module):
|
||||
first_line = True
|
||||
for line in module.params['lines']:
|
||||
|
@ -168,6 +169,7 @@ def parse_acl_name(module):
|
|||
|
||||
return acl_name
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
argument_spec = dict(
|
||||
|
|
|
@ -187,7 +187,6 @@ def main():
|
|||
msg = 'One or more conditional statements have not be satisfied'
|
||||
module.fail_json(msg=msg, failed_conditions=failed_conditions)
|
||||
|
||||
|
||||
result.update({
|
||||
'changed': False,
|
||||
'stdout': responses,
|
||||
|
|
|
@ -201,7 +201,6 @@ from ansible.module_utils.network.common.config import NetworkConfig, dumps
|
|||
from ansible.module_utils._text import to_native
|
||||
|
||||
|
||||
|
||||
def get_candidate(module):
|
||||
candidate = NetworkConfig(indent=1)
|
||||
if module.params['src']:
|
||||
|
@ -211,6 +210,7 @@ def get_candidate(module):
|
|||
candidate.add(module.params['lines'], parents=parents)
|
||||
return candidate
|
||||
|
||||
|
||||
def run(module, result):
|
||||
match = module.params['match']
|
||||
replace = module.params['replace']
|
||||
|
@ -251,6 +251,7 @@ def run(module, result):
|
|||
run_commands(module, 'write mem')
|
||||
result['changed'] = True
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
@ -293,7 +294,6 @@ def main():
|
|||
|
||||
config = None
|
||||
|
||||
|
||||
if module.params['backup']:
|
||||
result['__backup__'] = get_config(module)
|
||||
|
||||
|
|
|
@ -80,8 +80,8 @@ def chain(module):
|
|||
controller = module.params['controller']
|
||||
|
||||
rest = Rest(module,
|
||||
{'content-type': 'application/json', 'Cookie': 'session_cookie='+access_token},
|
||||
'https://'+controller+':8443/api/v1/data/controller/applications/bigchain')
|
||||
{'content-type': 'application/json', 'Cookie': 'session_cookie=' + access_token},
|
||||
'https://' + controller + ':8443/api/v1/data/controller/applications/bigchain')
|
||||
|
||||
if None in (name, state, controller):
|
||||
module.fail_json(msg='parameter `name` is missing')
|
||||
|
@ -115,6 +115,7 @@ def chain(module):
|
|||
else:
|
||||
module.fail_json(msg="error deleting chain '{}': {}".format(name, response.json['description']))
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
|
|
|
@ -113,8 +113,8 @@ def policy(module):
|
|||
controller = module.params['controller']
|
||||
|
||||
rest = Rest(module,
|
||||
{'content-type': 'application/json', 'Cookie': 'session_cookie='+access_token},
|
||||
'https://'+controller+':8443/api/v1/data/controller/applications/bigtap')
|
||||
{'content-type': 'application/json', 'Cookie': 'session_cookie=' + access_token},
|
||||
'https://' + controller + ':8443/api/v1/data/controller/applications/bigtap')
|
||||
|
||||
if name is None:
|
||||
module.fail_json(msg='parameter `name` is missing')
|
||||
|
@ -127,11 +127,11 @@ def policy(module):
|
|||
|
||||
matching = [policy for policy in response.json
|
||||
if policy['name'] == name and
|
||||
policy['duration'] == duration and
|
||||
policy['delivery-packet-count'] == delivery_packet_count and
|
||||
policy['policy-description'] == policy_description and
|
||||
policy['action'] == action and
|
||||
policy['priority'] == priority]
|
||||
policy['duration'] == duration and
|
||||
policy['delivery-packet-count'] == delivery_packet_count and
|
||||
policy['policy-description'] == policy_description and
|
||||
policy['action'] == action and
|
||||
policy['priority'] == priority]
|
||||
|
||||
if matching:
|
||||
config_present = True
|
||||
|
@ -143,9 +143,9 @@ def policy(module):
|
|||
module.exit_json(changed=False)
|
||||
|
||||
if state in ('present'):
|
||||
data={'name': name, 'action': action, 'policy-description': policy_description,
|
||||
'priority': priority, 'duration': duration, 'start-time': start_time,
|
||||
'delivery-packet-count': delivery_packet_count }
|
||||
data = {'name': name, 'action': action, 'policy-description': policy_description,
|
||||
'priority': priority, 'duration': duration, 'start-time': start_time,
|
||||
'delivery-packet-count': delivery_packet_count}
|
||||
|
||||
response = rest.put('policy[name="%s"]' % name, data=data)
|
||||
if response.status_code == 204:
|
||||
|
@ -160,6 +160,7 @@ def policy(module):
|
|||
else:
|
||||
module.fail_json(msg="error deleting policy '{}': {}".format(name, response.json['description']))
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
|
@ -168,7 +169,7 @@ def main():
|
|||
action=dict(choices=['forward', 'drop', 'capture', 'flow-gen'], default='forward'),
|
||||
priority=dict(type='int', default=100),
|
||||
duration=dict(type='int', default=0),
|
||||
start_time=dict(type='str', default=datetime.datetime.now().isoformat()+'+00:00'),
|
||||
start_time=dict(type='str', default=datetime.datetime.now().isoformat() + '+00:00'),
|
||||
delivery_packet_count=dict(type='int', default=0),
|
||||
controller=dict(type='str', required=True),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
|
|
|
@ -469,4 +469,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -163,4 +163,4 @@ def main():
|
|||
module.fail_json(msg=errorMsg)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -190,4 +190,4 @@ def main():
|
|||
module.fail_json(msg=errorMsg)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -228,4 +228,4 @@ def main():
|
|||
module.fail_json(msg=errorMsg)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -585,4 +585,4 @@ def main():
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -521,4 +521,4 @@ def main():
|
|||
module.fail_json(msg=errorMsg)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -273,4 +273,4 @@ def main():
|
|||
module.fail_json(msg=errorMsg)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -296,4 +296,4 @@ def main():
|
|||
module.fail_json(msg=errorMsg)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -288,6 +288,7 @@ def conv_array_to_str(_value):
|
|||
return ' '.join(_value)
|
||||
return _value
|
||||
|
||||
|
||||
def build_generic_attr(module, _attr):
|
||||
_value = module.params.get(_attr)
|
||||
_value = conv_bool_to_str(_value)
|
||||
|
|
|
@ -187,7 +187,6 @@ def check_fw_print_env(module, slot_num):
|
|||
return m0.group(1)
|
||||
|
||||
|
||||
|
||||
def get_primary_slot_num(module):
|
||||
cmd = None
|
||||
if platform.machine() == 'ppc':
|
||||
|
@ -264,7 +263,7 @@ def check_sw_version(module):
|
|||
if 'active' in slot:
|
||||
_msg = "Version %s is installed in the active slot" \
|
||||
% (_version)
|
||||
module.exit_json(changed=False, msg=_msg)
|
||||
module.exit_json(changed=False, msg=_msg)
|
||||
else:
|
||||
_msg = "Version " + _version + \
|
||||
" is installed in the alternate slot. "
|
||||
|
|
|
@ -103,7 +103,7 @@ msg:
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
CL_LICENSE_PATH='/usr/cumulus/bin/cl-license'
|
||||
CL_LICENSE_PATH = '/usr/cumulus/bin/cl-license'
|
||||
|
||||
|
||||
def install_license(module):
|
||||
|
|
|
@ -99,7 +99,7 @@ def hash_existing_ports_conf(module):
|
|||
except IOError as e:
|
||||
_msg = "Failed to open %s: %s" % (PORTS_CONF, to_native(e))
|
||||
module.fail_json(msg=_msg)
|
||||
return # for testing only should return on module.fail_json
|
||||
return # for testing only should return on module.fail_json
|
||||
|
||||
for _line in existing_ports_conf:
|
||||
_m0 = re.match(r'^(\d+)=(\w+)', _line)
|
||||
|
@ -129,7 +129,7 @@ def generate_new_ports_conf_hash(module):
|
|||
port_setting
|
||||
else:
|
||||
int_range = map(int, port_range_str)
|
||||
portnum_range = range(int_range[0], int_range[1]+1)
|
||||
portnum_range = range(int_range[0], int_range[1] + 1)
|
||||
for i in portnum_range:
|
||||
new_ports_conf_hash[i] = port_setting
|
||||
module.new_ports_hash = new_ports_conf_hash
|
||||
|
@ -160,6 +160,7 @@ def make_copy_of_orig_ports_conf(module):
|
|||
module.fail_json(msg=_msg)
|
||||
return # for testing only
|
||||
|
||||
|
||||
def write_to_ports_conf(module):
|
||||
"""
|
||||
use tempfile to first write out config in temp file
|
||||
|
|
|
@ -99,7 +99,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
|
||||
def command_helper(module, command, errmsg=None):
|
||||
"""Run a command, catch any nclu errors"""
|
||||
(_rc, output, _err) = module.run_command("/usr/bin/net %s"%command)
|
||||
(_rc, output, _err) = module.run_command("/usr/bin/net %s" % command)
|
||||
if _rc or 'ERROR' in output or 'ERROR' in _err:
|
||||
module.fail_json(msg=errmsg or output)
|
||||
return str(output)
|
||||
|
@ -141,7 +141,7 @@ def run_nclu(module, command_list, command_string, commit, atomic, abort, descri
|
|||
# Run all of the net commands
|
||||
output_lines = []
|
||||
for line in commands:
|
||||
output_lines += [command_helper(module, line.strip(), "Failed on line %s"%line)]
|
||||
output_lines += [command_helper(module, line.strip(), "Failed on line %s" % line)]
|
||||
output = "\n".join(output_lines)
|
||||
|
||||
# If pending changes changed, report a change.
|
||||
|
@ -153,7 +153,7 @@ def run_nclu(module, command_list, command_string, commit, atomic, abort, descri
|
|||
|
||||
# Do the commit.
|
||||
if do_commit:
|
||||
result = command_helper(module, "commit description '%s'"%description)
|
||||
result = command_helper(module, "commit description '%s'" % description)
|
||||
if "commit ignored" in result:
|
||||
_changed = False
|
||||
command_helper(module, "abort")
|
||||
|
@ -165,12 +165,12 @@ def run_nclu(module, command_list, command_string, commit, atomic, abort, descri
|
|||
|
||||
def main(testing=False):
|
||||
module = AnsibleModule(argument_spec=dict(
|
||||
commands = dict(required=False, type='list'),
|
||||
template = dict(required=False, type='str'),
|
||||
description = dict(required=False, type='str', default="Ansible-originated commit"),
|
||||
abort = dict(required=False, type='bool', default=False),
|
||||
commit = dict(required=False, type='bool', default=False),
|
||||
atomic = dict(required=False, type='bool', default=False)),
|
||||
commands=dict(required=False, type='list'),
|
||||
template=dict(required=False, type='str'),
|
||||
description=dict(required=False, type='str', default="Ansible-originated commit"),
|
||||
abort=dict(required=False, type='bool', default=False),
|
||||
commit=dict(required=False, type='bool', default=False),
|
||||
atomic=dict(required=False, type='bool', default=False)),
|
||||
mutually_exclusive=[('commands', 'template'),
|
||||
('commit', 'atomic'),
|
||||
('abort', 'atomic')]
|
||||
|
|
|
@ -126,6 +126,7 @@ def map_obj_to_commands(updates, module):
|
|||
|
||||
return commands
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
output = run_commands(module, ['show banner %s' % module.params['banner']])
|
||||
obj = {'banner': module.params['banner'], 'state': 'absent'}
|
||||
|
@ -144,6 +145,7 @@ def map_config_to_obj(module):
|
|||
obj['state'] = 'present'
|
||||
return obj
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
text = module.params['text']
|
||||
if text:
|
||||
|
@ -155,6 +157,7 @@ def map_params_to_obj(module):
|
|||
'state': module.params['state']
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
|
|
@ -146,6 +146,7 @@ from ansible.module_utils.network.eos.eos import eos_argument_spec, check_args
|
|||
|
||||
VALID_KEYS = ['command', 'output', 'prompt', 'response']
|
||||
|
||||
|
||||
def to_lines(stdout):
|
||||
lines = list()
|
||||
for item in stdout:
|
||||
|
@ -154,6 +155,7 @@ def to_lines(stdout):
|
|||
lines.append(item)
|
||||
return lines
|
||||
|
||||
|
||||
def parse_commands(module, warnings):
|
||||
spec = dict(
|
||||
command=dict(key=True),
|
||||
|
@ -176,12 +178,14 @@ def parse_commands(module, warnings):
|
|||
|
||||
return commands
|
||||
|
||||
|
||||
def to_cli(obj):
|
||||
cmd = obj['command']
|
||||
if obj.get('output') == 'json':
|
||||
cmd += ' | json'
|
||||
return cmd
|
||||
|
||||
|
||||
def main():
|
||||
"""entry point for module execution
|
||||
"""
|
||||
|
|
|
@ -403,7 +403,6 @@ def main():
|
|||
|
||||
result['changed'] = True
|
||||
|
||||
|
||||
running_config = None
|
||||
startup_config = None
|
||||
|
||||
|
|
|
@ -187,6 +187,7 @@ from ansible.module_utils.network.eos.eos import run_commands, load_config
|
|||
from ansible.module_utils.six import iteritems
|
||||
from ansible.module_utils.network.eos.eos import eos_argument_spec, check_args
|
||||
|
||||
|
||||
def check_transport(module):
|
||||
transport = module.params['transport']
|
||||
provider_transport = (module.params['provider'] or {}).get('transport')
|
||||
|
@ -194,18 +195,22 @@ def check_transport(module):
|
|||
if 'eapi' in (transport, provider_transport):
|
||||
module.fail_json(msg='eos_eapi module is only supported over cli transport')
|
||||
|
||||
|
||||
def validate_http_port(value, module):
|
||||
if not 1 <= value <= 65535:
|
||||
module.fail_json(msg='http_port must be between 1 and 65535')
|
||||
|
||||
|
||||
def validate_https_port(value, module):
|
||||
if not 1 <= value <= 65535:
|
||||
module.fail_json(msg='http_port must be between 1 and 65535')
|
||||
|
||||
|
||||
def validate_local_http_port(value, module):
|
||||
if not 1 <= value <= 65535:
|
||||
module.fail_json(msg='http_port must be between 1 and 65535')
|
||||
|
||||
|
||||
def validate_vrf(value, module):
|
||||
out = run_commands(module, ['show vrf'])
|
||||
configured_vrfs = re.findall(r'^\s+(\w+)(?=\s)', out[0], re.M)
|
||||
|
@ -213,11 +218,12 @@ def validate_vrf(value, module):
|
|||
if value not in configured_vrfs:
|
||||
module.fail_json(msg='vrf `%s` is not configured on the system' % value)
|
||||
|
||||
|
||||
def map_obj_to_commands(updates, module, warnings):
|
||||
commands = list()
|
||||
want, have = updates
|
||||
|
||||
needs_update = lambda x: want.get(x) is not None and (want.get(x) != have.get(x))
|
||||
def needs_update(x): return want.get(x) is not None and (want.get(x) != have.get(x))
|
||||
|
||||
def add(cmd):
|
||||
if 'management api http-commands' not in commands:
|
||||
|
@ -266,7 +272,6 @@ def map_obj_to_commands(updates, module, warnings):
|
|||
elif want['state'] == 'started':
|
||||
add('no shutdown')
|
||||
|
||||
|
||||
if needs_update('vrf'):
|
||||
add('vrf %s' % want['vrf'])
|
||||
# switching operational vrfs here
|
||||
|
@ -278,6 +283,7 @@ def map_obj_to_commands(updates, module, warnings):
|
|||
|
||||
return commands
|
||||
|
||||
|
||||
def parse_state(data):
|
||||
if data[0]['enabled']:
|
||||
return 'started'
|
||||
|
@ -299,6 +305,7 @@ def map_config_to_obj(module):
|
|||
'state': parse_state(out)
|
||||
}
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
obj = {
|
||||
'http': module.params['http'],
|
||||
|
@ -320,6 +327,7 @@ def map_params_to_obj(module):
|
|||
|
||||
return obj
|
||||
|
||||
|
||||
def verify_state(updates, module):
|
||||
want, have = updates
|
||||
|
||||
|
@ -348,6 +356,7 @@ def verify_state(updates, module):
|
|||
if timeout == 0:
|
||||
module.fail_json(msg='timeout expired before eapi running state changed')
|
||||
|
||||
|
||||
def collect_facts(module, result):
|
||||
out = run_commands(module, ['show management api http-commands | json'])
|
||||
facts = dict(eos_eapi_urls=dict())
|
||||
|
@ -359,6 +368,7 @@ def collect_facts(module, result):
|
|||
facts['eos_eapi_urls'][key].append(str(url).strip())
|
||||
result['ansible_facts'] = facts
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
|
|
@ -142,6 +142,7 @@ from ansible.module_utils.six import iteritems
|
|||
from ansible.module_utils.network.eos.eos import run_commands
|
||||
from ansible.module_utils.network.eos.eos import eos_argument_spec, check_args
|
||||
|
||||
|
||||
class FactsBase(object):
|
||||
|
||||
COMMANDS = frozenset()
|
||||
|
@ -190,6 +191,7 @@ class Default(FactsBase):
|
|||
value = None
|
||||
return dict(image=value)
|
||||
|
||||
|
||||
class Hardware(FactsBase):
|
||||
|
||||
COMMANDS = [
|
||||
|
@ -218,6 +220,7 @@ class Hardware(FactsBase):
|
|||
memtotal_mb=int(values['memTotal']) / 1024
|
||||
)
|
||||
|
||||
|
||||
class Config(FactsBase):
|
||||
|
||||
COMMANDS = ['show running-config']
|
||||
|
@ -312,6 +315,7 @@ FACT_SUBSETS = dict(
|
|||
|
||||
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
|
||||
|
||||
|
||||
def main():
|
||||
"""main entry point for module execution
|
||||
"""
|
||||
|
|
|
@ -135,6 +135,7 @@ from ansible.module_utils.network.eos.eos import eos_argument_spec
|
|||
|
||||
_CONFIGURED_VRFS = None
|
||||
|
||||
|
||||
def has_vrf(module, vrf):
|
||||
global _CONFIGURED_VRFS
|
||||
if _CONFIGURED_VRFS is not None:
|
||||
|
@ -144,11 +145,12 @@ def has_vrf(module, vrf):
|
|||
_CONFIGURED_VRFS.append('default')
|
||||
return vrf in _CONFIGURED_VRFS
|
||||
|
||||
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
state = module.params['state']
|
||||
|
||||
needs_update = lambda x: want.get(x) and (want.get(x) != have.get(x))
|
||||
def needs_update(x): return want.get(x) and (want.get(x) != have.get(x))
|
||||
|
||||
if state == 'absent':
|
||||
if have['domain_name']:
|
||||
|
@ -205,9 +207,9 @@ def map_obj_to_commands(want, have, module):
|
|||
module.fail_json(msg='vrf %s is not configured' % item['vrf'])
|
||||
if item['vrf'] not in ('default', None):
|
||||
values = (item['vrf'], item['server'])
|
||||
commands.append('no ip name-server vrf %s %s' % values)
|
||||
commands.append('no ip name-server vrf %s %s' % values)
|
||||
else:
|
||||
commands.append('no ip name-server %s' % item['server'])
|
||||
commands.append('no ip name-server %s' % item['server'])
|
||||
|
||||
# handle name_servers items to be added
|
||||
for item in want['name_servers']:
|
||||
|
@ -222,31 +224,36 @@ def map_obj_to_commands(want, have, module):
|
|||
|
||||
return commands
|
||||
|
||||
|
||||
def parse_hostname(config):
|
||||
match = re.search(r'^hostname (\S+)', config, re.M)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def parse_domain_name(config):
|
||||
match = re.search(r'^ip domain-name (\S+)', config, re.M)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def parse_lookup_source(config):
|
||||
objects = list()
|
||||
regex = r'ip domain lookup (?:vrf (\S+) )*source-interface (\S+)'
|
||||
for vrf, intf in re.findall(regex, config, re.M):
|
||||
if len(vrf) == 0:
|
||||
vrf= None
|
||||
vrf = None
|
||||
objects.append({'interface': intf, 'vrf': vrf})
|
||||
return objects
|
||||
|
||||
|
||||
def parse_name_servers(config):
|
||||
objects = list()
|
||||
for vrf, addr in re.findall(r'ip name-server vrf (\S+) (\S+)', config, re.M):
|
||||
objects.append({'server': addr, 'vrf': vrf})
|
||||
return objects
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
config = get_config(module)
|
||||
return {
|
||||
|
@ -257,6 +264,7 @@ def map_config_to_obj(module):
|
|||
'name_servers': parse_name_servers(config)
|
||||
}
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
obj = {
|
||||
'hostname': module.params['hostname'],
|
||||
|
@ -282,6 +290,7 @@ def map_params_to_obj(module):
|
|||
|
||||
return obj
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
|
|
@ -174,8 +174,9 @@ def map_obj_to_commands(updates, module):
|
|||
for update in updates:
|
||||
want, have = update
|
||||
|
||||
needs_update = lambda x: want.get(x) and (want.get(x) != have.get(x))
|
||||
add = lambda x: commands.append('username %s %s' % (want['name'], x))
|
||||
def needs_update(x): return want.get(x) and (want.get(x) != have.get(x))
|
||||
|
||||
def add(x): return commands.append('username %s %s' % (want['name'], x))
|
||||
|
||||
if want['state'] == 'absent':
|
||||
commands.append('no username %s' % want['name'])
|
||||
|
|
|
@ -548,9 +548,9 @@ class Difference(object):
|
|||
)
|
||||
elif self.want.timeout is not None:
|
||||
if self.have.interval >= self.want.timeout:
|
||||
raise F5ModuleError(
|
||||
"Parameter 'interval' must be less than 'timeout'."
|
||||
)
|
||||
raise F5ModuleError(
|
||||
"Parameter 'interval' must be less than 'timeout'."
|
||||
)
|
||||
elif self.want.interval is not None:
|
||||
if self.want.interval >= self.have.timeout:
|
||||
raise F5ModuleError(
|
||||
|
|
|
@ -466,6 +466,7 @@ class V1Manager(BaseManager):
|
|||
* No API to upload UCS files
|
||||
|
||||
"""
|
||||
|
||||
def create_on_device(self):
|
||||
remote_path = "/var/local/ucs"
|
||||
tpath_name = '/var/config/rest/downloads'
|
||||
|
|
|
@ -121,6 +121,7 @@ class AnsibleF5ClientStub(AnsibleF5Client):
|
|||
the result will replace this work here.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, argument_spec=None, supports_check_mode=False,
|
||||
mutually_exclusive=None, required_together=None,
|
||||
required_if=None, required_one_of=None, add_file_common_args=False,
|
||||
|
|
|
@ -76,26 +76,26 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
from ansible.module_utils.network.fortios.fortios import fortios_argument_spec, fortios_required_if
|
||||
from ansible.module_utils.network.fortios.fortios import backup
|
||||
|
||||
#check for pyFG lib
|
||||
# check for pyFG lib
|
||||
try:
|
||||
from pyFG import FortiOS, FortiConfig
|
||||
from pyFG.fortios import logger
|
||||
from pyFG.exceptions import CommandExecutionException, FailedCommit, ForcedCommit
|
||||
HAS_PYFG=True
|
||||
HAS_PYFG = True
|
||||
except:
|
||||
HAS_PYFG=False
|
||||
HAS_PYFG = False
|
||||
|
||||
|
||||
# some blocks don't support update, so remove them
|
||||
NOT_UPDATABLE_CONFIG_OBJECTS=[
|
||||
NOT_UPDATABLE_CONFIG_OBJECTS = [
|
||||
"vpn certificate local",
|
||||
]
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = dict(
|
||||
src = dict(type='str', default=None),
|
||||
filter = dict(type='str', default=""),
|
||||
src=dict(type='str', default=None),
|
||||
filter=dict(type='str', default=""),
|
||||
)
|
||||
|
||||
argument_spec.update(fortios_argument_spec)
|
||||
|
@ -114,20 +114,20 @@ def main():
|
|||
if not HAS_PYFG:
|
||||
module.fail_json(msg='Could not import the python library pyFG required by this module')
|
||||
|
||||
#define device
|
||||
f = FortiOS( module.params['host'],
|
||||
username=module.params['username'],
|
||||
password=module.params['password'],
|
||||
timeout=module.params['timeout'],
|
||||
vdom=module.params['vdom'])
|
||||
# define device
|
||||
f = FortiOS(module.params['host'],
|
||||
username=module.params['username'],
|
||||
password=module.params['password'],
|
||||
timeout=module.params['timeout'],
|
||||
vdom=module.params['vdom'])
|
||||
|
||||
#connect
|
||||
# connect
|
||||
try:
|
||||
f.open()
|
||||
except:
|
||||
module.fail_json(msg='Error connecting device')
|
||||
|
||||
#get config
|
||||
# get config
|
||||
try:
|
||||
f.load_config(path=module.params['filter'])
|
||||
result['running_config'] = f.running_config.to_text()
|
||||
|
@ -135,24 +135,23 @@ def main():
|
|||
except:
|
||||
module.fail_json(msg='Error reading running config')
|
||||
|
||||
#backup config
|
||||
# backup config
|
||||
if module.params['backup']:
|
||||
backup(module, f.running_config.to_text())
|
||||
|
||||
|
||||
#update config
|
||||
# update config
|
||||
if module.params['src'] is not None:
|
||||
#store config in str
|
||||
# store config in str
|
||||
try:
|
||||
conf_str = module.params['src']
|
||||
f.load_config(in_candidate=True, config_text=conf_str)
|
||||
except:
|
||||
module.fail_json(msg="Can't open configuration file, or configuration invalid")
|
||||
|
||||
#get updates lines
|
||||
# get updates lines
|
||||
change_string = f.compare_config()
|
||||
|
||||
#remove not updatable parts
|
||||
# remove not updatable parts
|
||||
c = FortiConfig()
|
||||
c.parse_config_output(change_string)
|
||||
|
||||
|
@ -165,7 +164,7 @@ def main():
|
|||
result['change_string'] = change_string
|
||||
result['changed'] = True
|
||||
|
||||
#Commit if not check mode
|
||||
# Commit if not check mode
|
||||
if module.check_mode is False and change_string != "":
|
||||
try:
|
||||
f.commit(change_string)
|
||||
|
|
|
@ -202,28 +202,28 @@ from ansible.module_utils.network.fortios.fortios import backup, AnsibleFortios
|
|||
|
||||
def main():
|
||||
argument_spec = dict(
|
||||
comment = dict(type='str'),
|
||||
id = dict(type='int', required=True),
|
||||
src_intf = dict(type='list', default='any'),
|
||||
dst_intf = dict(type='list', default='any'),
|
||||
state = dict(choices=['present', 'absent'], default='present'),
|
||||
src_addr = dict(type='list'),
|
||||
dst_addr = dict(type='list'),
|
||||
src_addr_negate = dict(type='bool', default=False),
|
||||
dst_addr_negate = dict(type='bool', default=False),
|
||||
policy_action = dict(choices=['accept','deny'], aliases=['action']),
|
||||
service = dict(aliases=['services'], type='list'),
|
||||
service_negate = dict(type='bool', default=False),
|
||||
schedule = dict(type='str', default='always'),
|
||||
nat = dict(type='bool', default=False),
|
||||
fixedport = dict(type='bool', default=False),
|
||||
poolname = dict(type='str'),
|
||||
av_profile = dict(type='str'),
|
||||
webfilter_profile = dict(type='str'),
|
||||
ips_sensor = dict(type='str'),
|
||||
application_list = dict(type='str'),
|
||||
logtraffic = dict(choices=['disable','all','utm'], default='utm'),
|
||||
logtraffic_start = dict(type='bool', default=False),
|
||||
comment=dict(type='str'),
|
||||
id=dict(type='int', required=True),
|
||||
src_intf=dict(type='list', default='any'),
|
||||
dst_intf=dict(type='list', default='any'),
|
||||
state=dict(choices=['present', 'absent'], default='present'),
|
||||
src_addr=dict(type='list'),
|
||||
dst_addr=dict(type='list'),
|
||||
src_addr_negate=dict(type='bool', default=False),
|
||||
dst_addr_negate=dict(type='bool', default=False),
|
||||
policy_action=dict(choices=['accept', 'deny'], aliases=['action']),
|
||||
service=dict(aliases=['services'], type='list'),
|
||||
service_negate=dict(type='bool', default=False),
|
||||
schedule=dict(type='str', default='always'),
|
||||
nat=dict(type='bool', default=False),
|
||||
fixedport=dict(type='bool', default=False),
|
||||
poolname=dict(type='str'),
|
||||
av_profile=dict(type='str'),
|
||||
webfilter_profile=dict(type='str'),
|
||||
ips_sensor=dict(type='str'),
|
||||
application_list=dict(type='str'),
|
||||
logtraffic=dict(choices=['disable', 'all', 'utm'], default='utm'),
|
||||
logtraffic_start=dict(type='bool', default=False),
|
||||
)
|
||||
|
||||
# merge global required_if & argument_spec from module_utils/fortios.py
|
||||
|
@ -236,7 +236,7 @@ def main():
|
|||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
required_if=fortios_required_if + ipv4_policy_required_if ,
|
||||
required_if=fortios_required_if + ipv4_policy_required_if,
|
||||
)
|
||||
|
||||
# init forti object
|
||||
|
|
|
@ -206,7 +206,6 @@ class IPTun(object):
|
|||
rc=rc)
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(
|
||||
argument_spec=dict(
|
||||
|
|
|
@ -231,7 +231,6 @@ def main():
|
|||
supports_check_mode=True
|
||||
)
|
||||
|
||||
|
||||
linkprop = LinkProp(module)
|
||||
|
||||
rc = None
|
||||
|
|
|
@ -96,6 +96,7 @@ from ansible.module_utils.network.ios.ios import load_config, run_commands
|
|||
from ansible.module_utils.network.ios.ios import ios_argument_spec, check_args
|
||||
import re
|
||||
|
||||
|
||||
def map_obj_to_commands(updates, module):
|
||||
commands = list()
|
||||
want, have = updates
|
||||
|
@ -114,6 +115,7 @@ def map_obj_to_commands(updates, module):
|
|||
|
||||
return commands
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
rc, out, err = exec_command(module, 'show banner %s' % module.params['banner'])
|
||||
if rc == 0:
|
||||
|
@ -132,6 +134,7 @@ def map_config_to_obj(module):
|
|||
obj['state'] = 'present'
|
||||
return obj
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
text = module.params['text']
|
||||
if text:
|
||||
|
@ -143,6 +146,7 @@ def map_params_to_obj(module):
|
|||
'state': module.params['state']
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
|
|
@ -140,12 +140,14 @@ from ansible.module_utils.network.common.utils import ComplexList
|
|||
from ansible.module_utils.network.common.parsing import Conditional
|
||||
from ansible.module_utils.six import string_types
|
||||
|
||||
|
||||
def to_lines(stdout):
|
||||
for item in stdout:
|
||||
if isinstance(item, string_types):
|
||||
item = str(item).split('\n')
|
||||
yield item
|
||||
|
||||
|
||||
def parse_commands(module, warnings):
|
||||
command = ComplexList(dict(
|
||||
command=dict(key=True),
|
||||
|
@ -167,6 +169,7 @@ def parse_commands(module, warnings):
|
|||
)
|
||||
return commands
|
||||
|
||||
|
||||
def main():
|
||||
"""main entry point for module execution
|
||||
"""
|
||||
|
@ -220,7 +223,6 @@ def main():
|
|||
msg = 'One or more conditional statements have not be satisfied'
|
||||
module.fail_json(msg=msg, failed_conditions=failed_conditions)
|
||||
|
||||
|
||||
result.update({
|
||||
'changed': False,
|
||||
'stdout': responses,
|
||||
|
|
|
@ -162,13 +162,13 @@ class FactsBase(object):
|
|||
self.facts = dict()
|
||||
self.responses = None
|
||||
|
||||
|
||||
def populate(self):
|
||||
self.responses = run_commands(self.module, self.COMMANDS, check_rc=False)
|
||||
|
||||
def run(self, cmd):
|
||||
return run_commands(self.module, cmd, check_rc=False)
|
||||
|
||||
|
||||
class Default(FactsBase):
|
||||
|
||||
COMMANDS = ['show version']
|
||||
|
@ -440,6 +440,7 @@ FACT_SUBSETS = dict(
|
|||
|
||||
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
|
||||
|
||||
|
||||
def main():
|
||||
"""main entry point for module execution
|
||||
"""
|
||||
|
|
|
@ -125,6 +125,7 @@ from ansible.module_utils.network.common.utils import ComplexList
|
|||
|
||||
_CONFIGURED_VRFS = None
|
||||
|
||||
|
||||
def has_vrf(module, vrf):
|
||||
global _CONFIGURED_VRFS
|
||||
if _CONFIGURED_VRFS is not None:
|
||||
|
@ -133,20 +134,23 @@ def has_vrf(module, vrf):
|
|||
_CONFIGURED_VRFS = re.findall(r'vrf definition (\S+)', config)
|
||||
return vrf in _CONFIGURED_VRFS
|
||||
|
||||
|
||||
def requires_vrf(module, vrf):
|
||||
if not has_vrf(module, vrf):
|
||||
module.fail_json(msg='vrf %s is not configured' % vrf)
|
||||
|
||||
|
||||
def diff_list(want, have):
|
||||
adds = [w for w in want if w not in have]
|
||||
removes = [h for h in have if h not in want]
|
||||
return (adds, removes)
|
||||
|
||||
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
state = module.params['state']
|
||||
|
||||
needs_update = lambda x: want.get(x) is not None and (want.get(x) != have.get(x))
|
||||
def needs_update(x): return want.get(x) is not None and (want.get(x) != have.get(x))
|
||||
|
||||
if state == 'absent':
|
||||
if have['hostname'] != 'Router':
|
||||
|
@ -226,7 +230,6 @@ def map_obj_to_commands(want, have, module):
|
|||
else:
|
||||
commands.append('ip domain list %s' % item['name'])
|
||||
|
||||
|
||||
if want['name_servers']:
|
||||
adds, removes = diff_list(want['name_servers'], have['name_servers'])
|
||||
for item in removes:
|
||||
|
@ -243,10 +246,12 @@ def map_obj_to_commands(want, have, module):
|
|||
|
||||
return commands
|
||||
|
||||
|
||||
def parse_hostname(config):
|
||||
match = re.search(r'^hostname (\S+)', config, re.M)
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def parse_domain_name(config):
|
||||
match = re.findall(r'^ip domain name (?:vrf (\S+) )*(\S+)', config, re.M)
|
||||
matches = list()
|
||||
|
@ -256,6 +261,7 @@ def parse_domain_name(config):
|
|||
matches.append({'name': name, 'vrf': vrf})
|
||||
return matches
|
||||
|
||||
|
||||
def parse_domain_search(config):
|
||||
match = re.findall(r'^ip domain list (?:vrf (\S+) )*(\S+)', config, re.M)
|
||||
matches = list()
|
||||
|
@ -265,6 +271,7 @@ def parse_domain_search(config):
|
|||
matches.append({'name': name, 'vrf': vrf})
|
||||
return matches
|
||||
|
||||
|
||||
def parse_name_servers(config):
|
||||
match = re.findall(r'^ip name-server (?:vrf (\S+) )*(.*)', config, re.M)
|
||||
matches = list()
|
||||
|
@ -275,11 +282,13 @@ def parse_name_servers(config):
|
|||
matches.append({'server': server, 'vrf': vrf})
|
||||
return matches
|
||||
|
||||
|
||||
def parse_lookup_source(config):
|
||||
match = re.search(r'ip domain lookup source-interface (\S+)', config, re.M)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
config = get_config(module)
|
||||
return {
|
||||
|
@ -291,6 +300,7 @@ def map_config_to_obj(module):
|
|||
'name_servers': parse_name_servers(config)
|
||||
}
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
obj = {
|
||||
'hostname': module.params['hostname'],
|
||||
|
@ -324,6 +334,7 @@ def map_params_to_obj(module):
|
|||
|
||||
return obj
|
||||
|
||||
|
||||
def main():
|
||||
""" Main entry point for Ansible module execution
|
||||
"""
|
||||
|
|
|
@ -175,9 +175,10 @@ def add_command_to_vrf(name, cmd, commands):
|
|||
])
|
||||
commands.append(cmd)
|
||||
|
||||
|
||||
def map_obj_to_commands(updates, module):
|
||||
commands = list()
|
||||
state = module.params['state'] # FIXME NOT USED
|
||||
state = module.params['state'] # FIXME NOT USED
|
||||
|
||||
for update in updates:
|
||||
want, have = update
|
||||
|
@ -226,6 +227,7 @@ def map_obj_to_commands(updates, module):
|
|||
|
||||
return commands
|
||||
|
||||
|
||||
def parse_description(configobj, name):
|
||||
cfg = configobj['vrf definition %s' % name]
|
||||
cfg = '\n'.join(cfg.children)
|
||||
|
@ -233,6 +235,7 @@ def parse_description(configobj, name):
|
|||
if match:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def parse_rd(configobj, name):
|
||||
cfg = configobj['vrf definition %s' % name]
|
||||
cfg = '\n'.join(cfg.children)
|
||||
|
@ -240,6 +243,7 @@ def parse_rd(configobj, name):
|
|||
if match:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def parse_interfaces(configobj, name):
|
||||
vrf_cfg = 'vrf forwarding %s' % name
|
||||
interfaces = list()
|
||||
|
@ -249,6 +253,7 @@ def parse_interfaces(configobj, name):
|
|||
interfaces.append(intf.split(' ')[1])
|
||||
return interfaces
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
config = get_config(module)
|
||||
configobj = NetworkConfig(indent=1, contents=config)
|
||||
|
@ -290,6 +295,7 @@ def get_param_value(key, item, module):
|
|||
|
||||
return value
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
vrfs = module.params.get('vrfs')
|
||||
if not vrfs:
|
||||
|
@ -320,6 +326,7 @@ def map_params_to_obj(module):
|
|||
|
||||
return objects
|
||||
|
||||
|
||||
def update_objects(want, have):
|
||||
updates = list()
|
||||
for entry in want:
|
||||
|
|
|
@ -1900,10 +1900,10 @@ def main():
|
|||
module.fail_json(msg=msg, diff=lb_vserver_diff(client, module, lbvserver_proxy), **module_result)
|
||||
|
||||
if not service_bindings_identical(client, module):
|
||||
module.fail_json(msg='service bindings are not identical', **module_result)
|
||||
module.fail_json(msg='service bindings are not identical', **module_result)
|
||||
|
||||
if not servicegroup_bindings_identical(client, module):
|
||||
module.fail_json(msg='servicegroup bindings are not identical', **module_result)
|
||||
module.fail_json(msg='servicegroup bindings are not identical', **module_result)
|
||||
|
||||
if module.params['servicetype'] == 'SSL':
|
||||
if not ssl_certkey_bindings_identical(client, module):
|
||||
|
|
|
@ -243,8 +243,8 @@ def main():
|
|||
pn_cliusername=dict(required=False, type='str'),
|
||||
pn_clipassword=dict(required=False, type='str', no_log=True),
|
||||
pn_cliswitch=dict(required=False, type='str', default='local'),
|
||||
state =dict(required=True, type='str',
|
||||
choices=['present', 'absent']),
|
||||
state=dict(required=True, type='str',
|
||||
choices=['present', 'absent']),
|
||||
pn_name=dict(required=True, type='str'),
|
||||
pn_cluster_node1=dict(type='str'),
|
||||
pn_cluster_node2=dict(type='str'),
|
||||
|
|
|
@ -140,8 +140,8 @@ def main():
|
|||
pn_cliusername=dict(required=True, type='str'),
|
||||
pn_clipassword=dict(required=True, type='str', no_log=True),
|
||||
pn_cliswitch=dict(required=False, type='str'),
|
||||
state =dict(required=True, type='str',
|
||||
choices=['present', 'absent', 'update']),
|
||||
state=dict(required=True, type='str',
|
||||
choices=['present', 'absent', 'update']),
|
||||
pn_vrouter_name=dict(required=True, type='str'),
|
||||
pn_ospf_area=dict(required=True, type='str'),
|
||||
pn_stub_type=dict(type='str', choices=['none', 'stub', 'nssa',
|
||||
|
|
|
@ -251,8 +251,8 @@ def main():
|
|||
pn_cliusername=dict(required=False, type='str'),
|
||||
pn_clipassword=dict(required=False, type='str', no_log=True),
|
||||
pn_cliswitch=dict(required=False, type='str', default='local'),
|
||||
state =dict(required=True, type='str',
|
||||
choices=['present', 'absent', 'update']),
|
||||
state=dict(required=True, type='str',
|
||||
choices=['present', 'absent', 'update']),
|
||||
pn_name=dict(required=True, type='str'),
|
||||
pn_port=dict(type='str'),
|
||||
pn_peer_port=dict(type='str'),
|
||||
|
@ -269,7 +269,7 @@ def main():
|
|||
),
|
||||
required_if=(
|
||||
["state", "present", ["pn_name", "pn_port", "pn_peer_port",
|
||||
"pn_peer_switch"]],
|
||||
"pn_peer_switch"]],
|
||||
["state", "absent", ["pn_name"]],
|
||||
["state", "update", ["pn_name"]]
|
||||
)
|
||||
|
|
|
@ -175,7 +175,7 @@ def run_cli(module, cli):
|
|||
:param module: The Ansible module to fetch command
|
||||
"""
|
||||
cliswitch = module.params['pn_cliswitch']
|
||||
state= module.params['state']
|
||||
state = module.params['state']
|
||||
command = get_command_from_state(state)
|
||||
|
||||
cmd = shlex.split(cli)
|
||||
|
@ -232,8 +232,8 @@ def main():
|
|||
pn_cliusername=dict(required=False, type='str'),
|
||||
pn_clipassword=dict(required=False, type='str', no_log=True),
|
||||
pn_cliswitch=dict(required=False, type='str', default='local'),
|
||||
state =dict(required=True, type='str',
|
||||
choices=['present', 'absent']),
|
||||
state=dict(required=True, type='str',
|
||||
choices=['present', 'absent']),
|
||||
pn_vlanid=dict(required=True, type='int'),
|
||||
pn_scope=dict(type='str', choices=['fabric', 'local']),
|
||||
pn_description=dict(type='str'),
|
||||
|
|
|
@ -289,8 +289,8 @@ def main():
|
|||
pn_cliusername=dict(required=False, type='str'),
|
||||
pn_clipassword=dict(required=False, type='str', no_log=True),
|
||||
pn_cliswitch=dict(required=False, type='str', default='local'),
|
||||
state =dict(required=True, type='str',
|
||||
choices=['present', 'absent', 'update']),
|
||||
state=dict(required=True, type='str',
|
||||
choices=['present', 'absent', 'update']),
|
||||
pn_name=dict(required=True, type='str'),
|
||||
pn_vnet=dict(type='str'),
|
||||
pn_service_type=dict(type='str', choices=['dedicated', 'shared']),
|
||||
|
|
|
@ -333,7 +333,7 @@ def main():
|
|||
)
|
||||
|
||||
# Accessing the arguments
|
||||
state= module.params['state']
|
||||
state = module.params['state']
|
||||
vrouter_name = module.params['pn_vrouter_name']
|
||||
neighbor = module.params['pn_neighbor']
|
||||
remote_as = module.params['pn_remote_as']
|
||||
|
|
|
@ -347,8 +347,8 @@ def main():
|
|||
pn_cliusername=dict(required=False, type='str'),
|
||||
pn_clipassword=dict(required=False, type='str', no_log=True),
|
||||
pn_cliswitch=dict(required=False, type='str', default='local'),
|
||||
state =dict(required=True, type='str',
|
||||
choices=['present', 'absent']),
|
||||
state=dict(required=True, type='str',
|
||||
choices=['present', 'absent']),
|
||||
pn_vrouter_name=dict(required=True, type='str'),
|
||||
pn_vlan=dict(type='int'),
|
||||
pn_interface_ip=dict(required=True, type='str'),
|
||||
|
|
|
@ -240,8 +240,8 @@ def main():
|
|||
pn_cliusername=dict(required=False, type='str'),
|
||||
pn_clipassword=dict(required=False, type='str', no_log=True),
|
||||
pn_cliswitch=dict(required=False, type='str', default='local'),
|
||||
state =dict(required=True, type='str',
|
||||
choices=['present', 'absent']),
|
||||
state=dict(required=True, type='str',
|
||||
choices=['present', 'absent']),
|
||||
pn_vrouter_name=dict(required=True, type='str'),
|
||||
pn_interface_ip=dict(type='str'),
|
||||
pn_index=dict(type='int')
|
||||
|
|
|
@ -125,6 +125,7 @@ from ansible.module_utils.network.nxos.nxos import load_config, run_commands
|
|||
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def execute_show_command(command, module):
|
||||
if 'show run' not in command:
|
||||
output = 'json'
|
||||
|
|
|
@ -276,12 +276,11 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
|
||||
server_type = module.params['server_type']
|
||||
address = module.params['address']
|
||||
key = module.params['key']
|
||||
|
@ -311,7 +310,6 @@ def main():
|
|||
module.fail_json(msg='auth_port and acct_port can only be used'
|
||||
'when server_type=radius')
|
||||
|
||||
|
||||
existing = get_aaa_host_info(module, server_type, address)
|
||||
end_state = existing
|
||||
|
||||
|
|
|
@ -300,9 +300,9 @@ def get_candidate(module):
|
|||
def execute_show_commands(module, commands, output='text'):
|
||||
cmds = []
|
||||
for command in to_list(commands):
|
||||
cmd = { 'command': command,
|
||||
'output': output,
|
||||
}
|
||||
cmd = {'command': command,
|
||||
'output': output,
|
||||
}
|
||||
cmds.append(cmd)
|
||||
body = run_commands(module, cmds)
|
||||
return body
|
||||
|
@ -460,7 +460,6 @@ def main():
|
|||
'diff': {'before': str(base_config), 'after': str(running_config)}
|
||||
})
|
||||
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
|
|
|
@ -168,6 +168,7 @@ from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_
|
|||
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def execute_show_command(command, module, command_type='cli_show_ascii'):
|
||||
cmds = [command]
|
||||
provider = module.params['provider']
|
||||
|
@ -260,40 +261,39 @@ def main():
|
|||
argument_spec = dict(
|
||||
system_mode_maintenance=dict(required=False, type='bool'),
|
||||
system_mode_maintenance_dont_generate_profile=dict(required=False,
|
||||
type='bool'),
|
||||
type='bool'),
|
||||
system_mode_maintenance_timeout=dict(required=False, type='str'),
|
||||
system_mode_maintenance_shutdown=dict(required=False, type='bool'),
|
||||
system_mode_maintenance_on_reload_reset_reason=dict(required=False,
|
||||
choices=['hw_error','svc_failure','kern_failure',
|
||||
'wdog_timeout','fatal_error','lc_failure',
|
||||
'match_any','manual_reload']),
|
||||
choices=['hw_error', 'svc_failure', 'kern_failure',
|
||||
'wdog_timeout', 'fatal_error', 'lc_failure',
|
||||
'match_any', 'manual_reload']),
|
||||
state=dict(choices=['absent', 'present', 'default'],
|
||||
default='present', required=False)
|
||||
default='present', required=False)
|
||||
)
|
||||
|
||||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
mutually_exclusive=[[
|
||||
'system_mode_maintenance',
|
||||
'system_mode_maintenance_dont_generate_profile',
|
||||
'system_mode_maintenance_timeout',
|
||||
'system_mode_maintenance_shutdown',
|
||||
'system_mode_maintenance_on_reload_reset_reason'
|
||||
]],
|
||||
required_one_of=[[
|
||||
'system_mode_maintenance',
|
||||
'system_mode_maintenance_dont_generate_profile',
|
||||
'system_mode_maintenance_timeout',
|
||||
'system_mode_maintenance_shutdown',
|
||||
'system_mode_maintenance_on_reload_reset_reason'
|
||||
]],
|
||||
supports_check_mode=True)
|
||||
mutually_exclusive=[[
|
||||
'system_mode_maintenance',
|
||||
'system_mode_maintenance_dont_generate_profile',
|
||||
'system_mode_maintenance_timeout',
|
||||
'system_mode_maintenance_shutdown',
|
||||
'system_mode_maintenance_on_reload_reset_reason'
|
||||
]],
|
||||
required_one_of=[[
|
||||
'system_mode_maintenance',
|
||||
'system_mode_maintenance_dont_generate_profile',
|
||||
'system_mode_maintenance_timeout',
|
||||
'system_mode_maintenance_shutdown',
|
||||
'system_mode_maintenance_on_reload_reset_reason'
|
||||
]],
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
|
||||
state = module.params['state']
|
||||
mode = get_system_mode(module)
|
||||
commands = get_commands(module, state, mode)
|
||||
|
|
|
@ -176,7 +176,7 @@ def main():
|
|||
commands=dict(required=False, type='list'),
|
||||
mode=dict(required=True, choices=['maintenance', 'normal']),
|
||||
state=dict(choices=['absent', 'present'],
|
||||
default='present'),
|
||||
default='present'),
|
||||
include_defaults=dict(default=False),
|
||||
config=dict()
|
||||
)
|
||||
|
@ -184,12 +184,11 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
|
||||
state = module.params['state']
|
||||
commands = module.params['commands'] or []
|
||||
|
||||
|
|
|
@ -95,6 +95,7 @@ from ansible.module_utils.network.nxos.nxos import load_config, run_commands
|
|||
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def get_current(module):
|
||||
output = run_commands(module, {'command': 'show running-config', 'output': 'text'})
|
||||
return {
|
||||
|
@ -126,12 +127,11 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
|
||||
current = get_current(module)
|
||||
desired = get_desired(module)
|
||||
|
||||
|
|
|
@ -242,6 +242,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
|
||||
import re
|
||||
|
||||
|
||||
def execute_show_command(command, module, command_type='cli_show'):
|
||||
if command_type == 'cli_show_ascii':
|
||||
cmds = [{
|
||||
|
@ -501,11 +502,11 @@ def config_remove_oif(existing, existing_oif_prefix_source):
|
|||
if each.get('prefix') and each.get('source'):
|
||||
command = 'no ip igmp static-oif {0} source {1} '.format(
|
||||
each.get('prefix'), each.get('source')
|
||||
)
|
||||
)
|
||||
elif each.get('prefix'):
|
||||
command = 'no ip igmp static-oif {0}'.format(
|
||||
each.get('prefix')
|
||||
)
|
||||
)
|
||||
if command:
|
||||
commands.append(command)
|
||||
command = None
|
||||
|
@ -533,7 +534,7 @@ def main():
|
|||
oif_source=dict(required=False, type='str'),
|
||||
restart=dict(type='bool', default=False),
|
||||
state=dict(choices=['present', 'absent', 'default'],
|
||||
default='present'),
|
||||
default='present'),
|
||||
include_defaults=dict(default=True),
|
||||
config=dict(),
|
||||
save=dict(type='bool', default=False)
|
||||
|
@ -542,12 +543,11 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
|
||||
state = module.params['state']
|
||||
interface = module.params['interface']
|
||||
oif_prefix = module.params['oif_prefix']
|
||||
|
@ -607,7 +607,7 @@ def main():
|
|||
changed = False
|
||||
commands = []
|
||||
proposed = dict((k, v) for k, v in module.params.items()
|
||||
if v is not None and k in args)
|
||||
if v is not None and k in args)
|
||||
|
||||
CANNOT_ABSENT = ['version', 'startup_query_interval',
|
||||
'startup_query_count', 'robustness', 'querier_timeout',
|
||||
|
|
|
@ -274,7 +274,7 @@ def main():
|
|||
if state == 'present':
|
||||
delta = dict(
|
||||
set(proposed.items()).difference(existing.items())
|
||||
)
|
||||
)
|
||||
if delta:
|
||||
command = config_igmp_snooping(delta, existing)
|
||||
if command:
|
||||
|
@ -283,7 +283,7 @@ def main():
|
|||
proposed = get_igmp_snooping_defaults()
|
||||
delta = dict(
|
||||
set(proposed.items()).difference(existing.items())
|
||||
)
|
||||
)
|
||||
if delta:
|
||||
command = config_igmp_snooping(delta, existing, default=True)
|
||||
if command:
|
||||
|
|
|
@ -343,13 +343,13 @@ def parse_interface_data(body):
|
|||
splitted_body = body.split('\n')
|
||||
|
||||
for index in range(0, len(splitted_body) - 1):
|
||||
if "Encapsulation 802.1Q" in splitted_body[index]:
|
||||
regex = r'(.+?ID\s(?P<dot1q>\d+).*)?'
|
||||
match = re.match(regex, splitted_body[index])
|
||||
if match:
|
||||
match_dict = match.groupdict()
|
||||
if match_dict['dot1q'] is not None:
|
||||
return int(match_dict['dot1q'])
|
||||
if "Encapsulation 802.1Q" in splitted_body[index]:
|
||||
regex = r'(.+?ID\s(?P<dot1q>\d+).*)?'
|
||||
match = re.match(regex, splitted_body[index])
|
||||
if match:
|
||||
match_dict = match.groupdict()
|
||||
if match_dict['dot1q'] is not None:
|
||||
return int(match_dict['dot1q'])
|
||||
return 0
|
||||
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ def map_obj_to_commands(updates, module):
|
|||
pass
|
||||
|
||||
if w['facility'] is not None:
|
||||
commands.append('logging level {} {}'.format(w['facility'], w['facility_level']))
|
||||
commands.append('logging level {} {}'.format(w['facility'], w['facility_level']))
|
||||
|
||||
return commands
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ def get_ntp_auth_info(key_id, module):
|
|||
|
||||
|
||||
def auth_type_to_num(auth_type):
|
||||
if auth_type == 'encrypt' :
|
||||
if auth_type == 'encrypt':
|
||||
return '7'
|
||||
else:
|
||||
return '0'
|
||||
|
@ -258,12 +258,11 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
|
||||
key_id = module.params['key_id']
|
||||
md5string = module.params['md5string']
|
||||
auth_type = module.params['auth_type']
|
||||
|
|
|
@ -95,7 +95,7 @@ def get_current(module):
|
|||
cmd = ('show running-config', 'show ntp logging')
|
||||
|
||||
output = run_commands(module, ({'command': cmd[0], 'output': 'text'},
|
||||
{'command': cmd[1], 'output': 'text'}))
|
||||
{'command': cmd[1], 'output': 'text'}))
|
||||
|
||||
match = re.search(r"^ntp master(?: (\d+))", output[0], re.M)
|
||||
if match:
|
||||
|
@ -167,7 +167,6 @@ def main():
|
|||
else:
|
||||
commands.append('no ntp logging')
|
||||
|
||||
|
||||
result['commands'] = commands
|
||||
result['updates'] = commands
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ from ansible.module_utils.network.nxos.nxos import check_args as nxos_check_args
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.six import iteritems
|
||||
|
||||
|
||||
def check_args(module, warnings):
|
||||
provider = module.params['provider']
|
||||
if provider['transport'] == 'nxapi':
|
||||
|
@ -159,10 +160,11 @@ def check_args(module, warnings):
|
|||
|
||||
return warnings
|
||||
|
||||
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
|
||||
needs_update = lambda x: want.get(x) is not None and (want.get(x) != have.get(x))
|
||||
def needs_update(x): return want.get(x) is not None and (want.get(x) != have.get(x))
|
||||
|
||||
if needs_update('state'):
|
||||
if want['state'] == 'absent':
|
||||
|
@ -191,6 +193,7 @@ def map_obj_to_commands(want, have, module):
|
|||
|
||||
return commands
|
||||
|
||||
|
||||
def parse_http(data):
|
||||
http_res = [r'nxapi http port (\d+)']
|
||||
http_port = None
|
||||
|
@ -203,6 +206,7 @@ def parse_http(data):
|
|||
|
||||
return {'http': http_port is not None, 'http_port': http_port}
|
||||
|
||||
|
||||
def parse_https(data):
|
||||
https_res = [r'nxapi https port (\d+)']
|
||||
https_port = None
|
||||
|
@ -215,6 +219,7 @@ def parse_https(data):
|
|||
|
||||
return {'https': https_port is not None, 'https_port': https_port}
|
||||
|
||||
|
||||
def parse_sandbox(data):
|
||||
sandbox = [item for item in data.split('\n') if re.search(r'.*sandbox.*', item)]
|
||||
value = False
|
||||
|
@ -222,6 +227,7 @@ def parse_sandbox(data):
|
|||
value = True
|
||||
return {'sandbox': value}
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
out = run_commands(module, ['show run all | inc nxapi'], check_rc=False)[0]
|
||||
match = re.search(r'no feature nxapi', out, re.M)
|
||||
|
@ -240,6 +246,7 @@ def map_config_to_obj(module):
|
|||
|
||||
return obj
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
obj = {
|
||||
'http': module.params['http'],
|
||||
|
@ -252,6 +259,7 @@ def map_params_to_obj(module):
|
|||
|
||||
return obj
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
@ -275,8 +283,6 @@ def main():
|
|||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
|
||||
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ def normalize_mac(proposed_mac, module):
|
|||
else:
|
||||
octect_len = len(octect)
|
||||
padding = 4 - octect_len
|
||||
splitted_mac.append(octect.zfill(padding+1))
|
||||
splitted_mac.append(octect.zfill(padding + 1))
|
||||
|
||||
elif ':' in proposed_mac:
|
||||
splitted_mac = proposed_mac.split(':')
|
||||
|
@ -150,7 +150,7 @@ def normalize_mac(proposed_mac, module):
|
|||
module.fail_json(msg='Invalid MAC address format', proposed_mac=proposed_mac)
|
||||
|
||||
joined_mac = ''.join(splitted_mac)
|
||||
mac = [joined_mac[i:i+4] for i in range(0, len(joined_mac), 4)]
|
||||
mac = [joined_mac[i:i + 4] for i in range(0, len(joined_mac), 4)]
|
||||
return '.'.join(mac).upper()
|
||||
|
||||
|
||||
|
@ -172,7 +172,7 @@ def main():
|
|||
|
||||
existing = get_existing(module, args)
|
||||
proposed = dict((k, v) for k, v in module.params.items()
|
||||
if v is not None and k in args)
|
||||
if v is not None and k in args)
|
||||
|
||||
candidate = CustomNetworkConfig(indent=3)
|
||||
get_commands(module, existing, proposed, candidate)
|
||||
|
|
|
@ -110,7 +110,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
|
||||
|
||||
def get_summary(results_list, reference_point):
|
||||
summary_string = results_list[reference_point+1]
|
||||
summary_string = results_list[reference_point + 1]
|
||||
summary_list = summary_string.split(',')
|
||||
|
||||
summary = dict(
|
||||
|
@ -119,7 +119,7 @@ def get_summary(results_list, reference_point):
|
|||
packet_loss=summary_list[2].split('packet')[0].strip(),
|
||||
)
|
||||
|
||||
if 'bytes from' not in results_list[reference_point-2]:
|
||||
if 'bytes from' not in results_list[reference_point - 2]:
|
||||
ping_pass = False
|
||||
else:
|
||||
ping_pass = True
|
||||
|
@ -168,7 +168,7 @@ def get_ping_results(command, module):
|
|||
splitted_ping = ping.split('\n')
|
||||
reference_point = get_statistics_summary_line(splitted_ping)
|
||||
summary, ping_pass = get_summary(splitted_ping, reference_point)
|
||||
rtt = get_rtt(splitted_ping, summary['packet_loss'], reference_point+2)
|
||||
rtt = get_rtt(splitted_ping, summary['packet_loss'], reference_point + 2)
|
||||
|
||||
return (summary, rtt, ping_pass)
|
||||
|
||||
|
|
|
@ -131,13 +131,12 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
results = {'changed': False, 'commands': [], 'warnings': warnings}
|
||||
|
||||
|
||||
pkg = module.params['pkg']
|
||||
file_system = module.params['file_system']
|
||||
remote_exists = remote_file_exists(module, pkg, file_system=file_system)
|
||||
|
|
|
@ -333,6 +333,7 @@ def write_on_file(content, filename, module):
|
|||
|
||||
return filepath
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = dict(
|
||||
action=dict(required=True, choices=['create', 'add', 'compare', 'delete', 'delete_all']),
|
||||
|
@ -421,4 +422,4 @@ def main():
|
|||
module.exit_json(**result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -182,7 +182,7 @@ def set_route_command(module, prefix):
|
|||
|
||||
def get_dotted_mask(mask):
|
||||
bits = 0
|
||||
for i in range(32-mask, 32):
|
||||
for i in range(32 - mask, 32):
|
||||
bits |= (1 << i)
|
||||
mask = ("%d.%d.%d.%d" % ((bits & 0xff000000) >> 24, (bits & 0xff0000) >> 16, (bits & 0xff00) >> 8, (bits & 0xff)))
|
||||
return mask
|
||||
|
|
|
@ -120,6 +120,7 @@ from ansible.module_utils.network.common.utils import ComplexList
|
|||
|
||||
_CONFIGURED_VRFS = None
|
||||
|
||||
|
||||
def has_vrf(module, vrf):
|
||||
global _CONFIGURED_VRFS
|
||||
if _CONFIGURED_VRFS is not None:
|
||||
|
@ -128,12 +129,14 @@ def has_vrf(module, vrf):
|
|||
_CONFIGURED_VRFS = re.findall(r'vrf context (\S+)', config)
|
||||
return vrf in _CONFIGURED_VRFS
|
||||
|
||||
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
state = module.params['state']
|
||||
|
||||
needs_update = lambda x: want.get(x) and (want.get(x) != have.get(x))
|
||||
difference = lambda x,y,z: [item for item in x[z] if item not in y[z]]
|
||||
def needs_update(x): return want.get(x) and (want.get(x) != have.get(x))
|
||||
|
||||
def difference(x, y, z): return [item for item in x[z] if item not in y[z]]
|
||||
|
||||
def remove(cmd, commands, vrf=None):
|
||||
if vrf:
|
||||
|
@ -195,7 +198,7 @@ def map_obj_to_commands(want, have, module):
|
|||
|
||||
if want['name_servers']:
|
||||
for item in difference(have, want, 'name_servers'):
|
||||
cmd = 'no ip name-server %s' % item['server']
|
||||
cmd = 'no ip name-server %s' % item['server']
|
||||
remove(cmd, commands, item['vrf'])
|
||||
for item in difference(want, have, 'name_servers'):
|
||||
cmd = 'ip name-server %s' % item['server']
|
||||
|
@ -206,11 +209,13 @@ def map_obj_to_commands(want, have, module):
|
|||
|
||||
return commands
|
||||
|
||||
|
||||
def parse_hostname(config):
|
||||
match = re.search(r'^hostname (\S+)', config, re.M)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
|
||||
def parse_domain_name(config, vrf_config):
|
||||
objects = list()
|
||||
regex = re.compile(r'ip domain-name (\S+)')
|
||||
|
@ -226,6 +231,7 @@ def parse_domain_name(config, vrf_config):
|
|||
|
||||
return objects
|
||||
|
||||
|
||||
def parse_domain_search(config, vrf_config):
|
||||
objects = list()
|
||||
|
||||
|
@ -238,6 +244,7 @@ def parse_domain_search(config, vrf_config):
|
|||
|
||||
return objects
|
||||
|
||||
|
||||
def parse_name_servers(config, vrf_config, vrfs):
|
||||
objects = list()
|
||||
|
||||
|
@ -256,11 +263,13 @@ def parse_name_servers(config, vrf_config, vrfs):
|
|||
|
||||
return objects
|
||||
|
||||
|
||||
def parse_system_mtu(config):
|
||||
match = re.search(r'^system jumbomtu (\d+)', config, re.M)
|
||||
if match:
|
||||
return int(match.group(1))
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
config = get_config(module)
|
||||
configobj = NetworkConfig(indent=2, contents=config)
|
||||
|
@ -281,10 +290,12 @@ def map_config_to_obj(module):
|
|||
'system_mtu': parse_system_mtu(config)
|
||||
}
|
||||
|
||||
|
||||
def validate_system_mtu(value, module):
|
||||
if not 1500 <= value <= 9216:
|
||||
module.fail_json(msg='system_mtu must be between 1500 and 9216')
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
obj = {
|
||||
'hostname': module.params['hostname'],
|
||||
|
@ -316,6 +327,7 @@ def map_params_to_obj(module):
|
|||
|
||||
return obj
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
|
|
@ -157,7 +157,6 @@ def apply_key_map(key_map, table):
|
|||
return new_dict
|
||||
|
||||
|
||||
|
||||
def get_commands_config_udld_global(delta, reset):
|
||||
config_args = {
|
||||
'enabled': 'udld aggressive',
|
||||
|
@ -224,13 +223,12 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
required_one_of=[['aggressive', 'msg_time', 'reset']],
|
||||
supports_check_mode=True)
|
||||
required_one_of=[['aggressive', 'msg_time', 'reset']],
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
|
||||
aggressive = module.params['aggressive']
|
||||
msg_time = module.params['msg_time']
|
||||
reset = module.params['reset']
|
||||
|
|
|
@ -171,7 +171,7 @@ def get_commands_config_udld_interface1(delta, interface, module, existing):
|
|||
if mode == 'aggressive':
|
||||
command = 'udld aggressive'
|
||||
if mode == 'enabled':
|
||||
command = 'no udld aggressive ; udld enable'
|
||||
command = 'no udld aggressive ; udld enable'
|
||||
elif mode == 'disabled':
|
||||
command = 'no udld aggressive ; no udld enable'
|
||||
if command:
|
||||
|
@ -188,7 +188,7 @@ def get_commands_config_udld_interface2(delta, interface, module, existing):
|
|||
if mode == 'aggressive':
|
||||
command = 'udld aggressive'
|
||||
if mode == 'enabled':
|
||||
command = 'no udld aggressive ; no udld disable'
|
||||
command = 'no udld aggressive ; no udld disable'
|
||||
elif mode == 'disabled':
|
||||
command = 'no udld aggressive ; udld disable'
|
||||
if command:
|
||||
|
@ -237,7 +237,7 @@ def get_commands_remove_udld_interface2(delta, interface, module, existing):
|
|||
def main():
|
||||
argument_spec = dict(
|
||||
mode=dict(choices=['enabled', 'disabled', 'aggressive'],
|
||||
required=True),
|
||||
required=True),
|
||||
interface=dict(type='str', required=True),
|
||||
state=dict(choices=['absent', 'present'], default='present'),
|
||||
)
|
||||
|
@ -245,7 +245,7 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
@ -265,14 +265,14 @@ def main():
|
|||
if state == 'present':
|
||||
if delta:
|
||||
command = get_commands_config_udld_interface1(delta, interface,
|
||||
module, existing)
|
||||
module, existing)
|
||||
commands.append(command)
|
||||
elif state == 'absent':
|
||||
common = set(proposed.items()).intersection(existing.items())
|
||||
if common:
|
||||
command = get_commands_remove_udld_interface1(
|
||||
dict(common), interface, module, existing
|
||||
)
|
||||
)
|
||||
commands.append(command)
|
||||
|
||||
cmds = flatten_list(commands)
|
||||
|
@ -297,11 +297,11 @@ def main():
|
|||
commands = []
|
||||
if state == 'present':
|
||||
command = get_commands_config_udld_interface2(delta, interface,
|
||||
module, existing)
|
||||
module, existing)
|
||||
elif state == 'absent':
|
||||
command = get_commands_remove_udld_interface2(
|
||||
dict(common), interface, module, existing
|
||||
)
|
||||
)
|
||||
commands.append(command)
|
||||
|
||||
cmds = flatten_list(commands)
|
||||
|
|
|
@ -166,6 +166,7 @@ def validate_roles(value, module):
|
|||
if item not in VALID_ROLES:
|
||||
module.fail_json(msg='invalid role specified')
|
||||
|
||||
|
||||
def map_obj_to_commands(updates, module):
|
||||
commands = list()
|
||||
state = module.params['state']
|
||||
|
@ -174,9 +175,11 @@ def map_obj_to_commands(updates, module):
|
|||
for update in updates:
|
||||
want, have = update
|
||||
|
||||
needs_update = lambda x: want.get(x) and (want.get(x) != have.get(x))
|
||||
add = lambda x: commands.append('username %s %s' % (want['name'], x))
|
||||
remove = lambda x: commands.append('no username %s %s' % (want['name'], x))
|
||||
def needs_update(x): return want.get(x) and (want.get(x) != have.get(x))
|
||||
|
||||
def add(x): return commands.append('username %s %s' % (want['name'], x))
|
||||
|
||||
def remove(x): return commands.append('no username %s %s' % (want['name'], x))
|
||||
|
||||
if want['state'] == 'absent':
|
||||
commands.append('no username %s' % want['name'])
|
||||
|
@ -192,7 +195,6 @@ def map_obj_to_commands(updates, module):
|
|||
if needs_update('sshkey'):
|
||||
add('sshkey %s' % want['sshkey'])
|
||||
|
||||
|
||||
if want['roles']:
|
||||
if have:
|
||||
for item in set(have['roles']).difference(want['roles']):
|
||||
|
@ -204,13 +206,14 @@ def map_obj_to_commands(updates, module):
|
|||
for item in want['roles']:
|
||||
add('role %s' % item)
|
||||
|
||||
|
||||
return commands
|
||||
|
||||
|
||||
def parse_password(data):
|
||||
if not data.get('remote_login'):
|
||||
return '<PASSWORD>'
|
||||
|
||||
|
||||
def parse_roles(data):
|
||||
configured_roles = data.get('TABLE_role')['ROW_role']
|
||||
roles = list()
|
||||
|
@ -219,6 +222,7 @@ def parse_roles(data):
|
|||
roles.append(item['role'])
|
||||
return roles
|
||||
|
||||
|
||||
def map_config_to_obj(module):
|
||||
out = run_commands(module, ['show user-account | json'])
|
||||
data = out[0]
|
||||
|
@ -235,6 +239,7 @@ def map_config_to_obj(module):
|
|||
})
|
||||
return objects
|
||||
|
||||
|
||||
def get_param_value(key, item, module):
|
||||
# if key doesn't exist in the item, get it from module.params
|
||||
if not item.get(key):
|
||||
|
@ -249,6 +254,7 @@ def get_param_value(key, item, module):
|
|||
|
||||
return value
|
||||
|
||||
|
||||
def map_params_to_obj(module):
|
||||
aggregate = module.params['aggregate']
|
||||
if not aggregate:
|
||||
|
@ -290,6 +296,7 @@ def map_params_to_obj(module):
|
|||
|
||||
return objects
|
||||
|
||||
|
||||
def update_objects(want, have):
|
||||
updates = list()
|
||||
for entry in want:
|
||||
|
@ -302,6 +309,7 @@ def update_objects(want, have):
|
|||
updates.append((entry, item))
|
||||
return updates
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
@ -328,7 +336,6 @@ def main():
|
|||
mutually_exclusive=mutually_exclusive,
|
||||
supports_check_mode=True)
|
||||
|
||||
|
||||
result = {'changed': False}
|
||||
|
||||
warnings = list()
|
||||
|
|
|
@ -162,7 +162,7 @@ def get_vrf_description(vrf, module):
|
|||
for element in splitted_body:
|
||||
if 'description' in element:
|
||||
match_description = re.match(descr_regex, element,
|
||||
re.DOTALL)
|
||||
re.DOTALL)
|
||||
group_description = match_description.groupdict()
|
||||
description = group_description["descr"]
|
||||
|
||||
|
@ -182,7 +182,7 @@ def get_vrf(vrf, module):
|
|||
vrf_key = {
|
||||
'vrf_name': 'vrf',
|
||||
'vrf_state': 'admin_state'
|
||||
}
|
||||
}
|
||||
|
||||
try:
|
||||
body = execute_show_command(command, module)[0]
|
||||
|
|
|
@ -167,7 +167,7 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
|
|
@ -194,13 +194,13 @@ def main():
|
|||
argument_spec = dict(
|
||||
vtp_password=dict(type='str', no_log=True),
|
||||
state=dict(choices=['absent', 'present'],
|
||||
default='present'),
|
||||
default='present'),
|
||||
)
|
||||
|
||||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
|
|
@ -165,7 +165,7 @@ def main():
|
|||
argument_spec.update(nxos_argument_spec)
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
supports_check_mode=True)
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
|
|
@ -206,6 +206,7 @@ def check_args(module, warnings):
|
|||
'match=none instead. This argument will be '
|
||||
'removed in the future')
|
||||
|
||||
|
||||
def extract_banners(config):
|
||||
banners = {}
|
||||
banner_cmds = re.findall(r'^banner (\w+)', config, re.M)
|
||||
|
@ -225,6 +226,7 @@ def extract_banners(config):
|
|||
config = re.sub(r'banner \w+ \^C\^C', '!! banner removed', config)
|
||||
return (config, banners)
|
||||
|
||||
|
||||
def diff_banners(want, have):
|
||||
candidate = {}
|
||||
for key, value in iteritems(want):
|
||||
|
@ -232,6 +234,7 @@ def diff_banners(want, have):
|
|||
candidate[key] = value
|
||||
return candidate
|
||||
|
||||
|
||||
def load_banners(module, banners):
|
||||
delimiter = module.params['multiline_delimiter']
|
||||
for key, value in iteritems(banners):
|
||||
|
@ -242,6 +245,7 @@ def load_banners(module, banners):
|
|||
time.sleep(1)
|
||||
module.connection.shell.receive()
|
||||
|
||||
|
||||
def get_config(module, result):
|
||||
contents = module.params['config']
|
||||
if not contents:
|
||||
|
@ -251,6 +255,7 @@ def get_config(module, result):
|
|||
contents, banners = extract_banners(contents)
|
||||
return NetworkConfig(indent=1, contents=contents), banners
|
||||
|
||||
|
||||
def get_candidate(module):
|
||||
candidate = NetworkConfig(indent=1)
|
||||
banners = {}
|
||||
|
@ -265,6 +270,7 @@ def get_candidate(module):
|
|||
|
||||
return candidate, banners
|
||||
|
||||
|
||||
def run(module, result):
|
||||
match = module.params['match']
|
||||
replace = module.params['replace']
|
||||
|
@ -275,7 +281,7 @@ def run(module, result):
|
|||
if match != 'none':
|
||||
config, have_banners = get_config(module, result)
|
||||
path = module.params['parents']
|
||||
configobjs = candidate.difference(config, path=path,match=match,
|
||||
configobjs = candidate.difference(config, path=path, match=match,
|
||||
replace=replace)
|
||||
else:
|
||||
configobjs = candidate.items
|
||||
|
@ -311,6 +317,7 @@ def run(module, result):
|
|||
module.config.save_config()
|
||||
result['changed'] = True
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
|
|
|
@ -223,6 +223,7 @@ FACT_SUBSETS = dict(
|
|||
|
||||
VALID_SUBSETS = frozenset(FACT_SUBSETS.keys())
|
||||
|
||||
|
||||
def main():
|
||||
spec = dict(
|
||||
gather_subset=dict(default=['!config'], type='list')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
#coding: utf-8 -*-
|
||||
# coding: utf-8 -*-
|
||||
|
||||
# (c) 2013, David Stygstra <david.stygstra@gmail.com>
|
||||
# Portions copyright @ 2015 VMware, Inc.
|
||||
|
@ -109,6 +109,7 @@ def _fail_mode_to_str(text):
|
|||
else:
|
||||
return text.strip()
|
||||
|
||||
|
||||
def _external_ids_to_dict(text):
|
||||
if not text:
|
||||
return None
|
||||
|
@ -122,6 +123,7 @@ def _external_ids_to_dict(text):
|
|||
|
||||
return d
|
||||
|
||||
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
|
||||
|
@ -156,7 +158,7 @@ def map_obj_to_commands(want, have, module):
|
|||
command = templatized_command % module.params
|
||||
|
||||
if want['parent']:
|
||||
templatized_command = "%(parent)s %(vlan)s"
|
||||
templatized_command = "%(parent)s %(vlan)s"
|
||||
command += " " + templatized_command % module.params
|
||||
|
||||
if want['set']:
|
||||
|
@ -175,7 +177,7 @@ def map_obj_to_commands(want, have, module):
|
|||
if want['external_ids']:
|
||||
for k, v in iteritems(want['external_ids']):
|
||||
templatized_command = ("%(ovs-vsctl)s -t %(timeout)s"
|
||||
" br-set-external-id %(bridge)s")
|
||||
" br-set-external-id %(bridge)s")
|
||||
command = templatized_command % module.params
|
||||
command += " " + k + " " + v
|
||||
commands.append(command)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
#coding: utf-8 -*-
|
||||
# coding: utf-8 -*-
|
||||
|
||||
# (c) 2013, David Stygstra <david.stygstra@gmail.com>
|
||||
# Portions copyright @ 2015 VMware, Inc.
|
||||
|
@ -118,6 +118,7 @@ def _external_ids_to_dict(text):
|
|||
|
||||
return d
|
||||
|
||||
|
||||
def _tag_to_str(text):
|
||||
text = text.strip()
|
||||
|
||||
|
@ -126,6 +127,7 @@ def _tag_to_str(text):
|
|||
else:
|
||||
return text
|
||||
|
||||
|
||||
def map_obj_to_commands(want, have, module):
|
||||
commands = list()
|
||||
|
||||
|
@ -167,7 +169,7 @@ def map_obj_to_commands(want, have, module):
|
|||
command = templatized_command % module.params
|
||||
|
||||
if want['tag']:
|
||||
templatized_command = " tag=%(tag)s"
|
||||
templatized_command = " tag=%(tag)s"
|
||||
command += templatized_command % module.params
|
||||
|
||||
if want['set']:
|
||||
|
@ -181,7 +183,7 @@ def map_obj_to_commands(want, have, module):
|
|||
templatized_command = ("%(ovs-vsctl)s -t %(timeout)s"
|
||||
" set port %(port)s external_ids:")
|
||||
command = templatized_command % module.params
|
||||
command += k + "=" + v
|
||||
command += k + "=" + v
|
||||
commands.append(command)
|
||||
|
||||
return commands
|
||||
|
@ -226,9 +228,10 @@ def map_params_to_obj(module):
|
|||
|
||||
return obj
|
||||
|
||||
|
||||
def main():
|
||||
""" Entry point. """
|
||||
argument_spec={
|
||||
argument_spec = {
|
||||
'bridge': {'required': True},
|
||||
'port': {'required': True},
|
||||
'state': {'default': 'present', 'choices': ['present', 'absent']},
|
||||
|
|
|
@ -137,7 +137,7 @@ def admin_set(xapi, module, admin_username, admin_password, role):
|
|||
element='<%s>%s</%s>' % (role, rbval, role))
|
||||
|
||||
if admin_password is not None:
|
||||
xapi.edit(xpath=_ADMIN_XPATH % admin_username+'/phash',
|
||||
xapi.edit(xpath=_ADMIN_XPATH % admin_username + '/phash',
|
||||
element='<phash>%s</phash>' % phash)
|
||||
changed = True
|
||||
|
||||
|
|
|
@ -84,9 +84,9 @@ import sys
|
|||
|
||||
try:
|
||||
import paramiko
|
||||
HAS_LIB=True
|
||||
HAS_LIB = True
|
||||
except ImportError:
|
||||
HAS_LIB=False
|
||||
HAS_LIB = False
|
||||
|
||||
_PROMPTBUFF = 4096
|
||||
|
||||
|
@ -101,7 +101,7 @@ def wait_with_timeout(module, shell, prompt, timeout=60):
|
|||
if len(endresult) != 0 and endresult[-1] == prompt:
|
||||
break
|
||||
|
||||
if time.time()-now > timeout:
|
||||
if time.time() - now > timeout:
|
||||
module.fail_json(msg="Timeout waiting for prompt")
|
||||
|
||||
return result
|
||||
|
@ -143,14 +143,14 @@ def set_panwfw_password(module, ip_address, key_filename, newpassword, username)
|
|||
stdout += buff
|
||||
|
||||
# enter password for the first time
|
||||
shell.send(newpassword+'\n')
|
||||
shell.send(newpassword + '\n')
|
||||
|
||||
# wait for the password prompt
|
||||
buff = wait_with_timeout(module, shell, ":")
|
||||
stdout += buff
|
||||
|
||||
# enter password for the second time
|
||||
shell.send(newpassword+'\n')
|
||||
shell.send(newpassword + '\n')
|
||||
|
||||
# wait for the config mode prompt
|
||||
buff = wait_with_timeout(module, shell, "#")
|
||||
|
|
|
@ -81,7 +81,7 @@ EXAMPLES = '''
|
|||
signed_by: "root-ca"
|
||||
'''
|
||||
|
||||
RETURN='''
|
||||
RETURN = '''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
@ -96,9 +96,9 @@ import time
|
|||
|
||||
try:
|
||||
import paramiko
|
||||
HAS_LIB=True
|
||||
HAS_LIB = True
|
||||
except ImportError:
|
||||
HAS_LIB=False
|
||||
HAS_LIB = False
|
||||
|
||||
_PROMPTBUFF = 4096
|
||||
|
||||
|
@ -113,14 +113,14 @@ def wait_with_timeout(module, shell, prompt, timeout=60):
|
|||
if len(endresult) != 0 and endresult[-1] == prompt:
|
||||
break
|
||||
|
||||
if time.time()-now > timeout:
|
||||
if time.time() - now > timeout:
|
||||
module.fail_json(msg="Timeout waiting for prompt")
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def generate_cert(module, ip_address, key_filename, password,
|
||||
cert_cn, cert_friendly_name, signed_by, rsa_nbits ):
|
||||
cert_cn, cert_friendly_name, signed_by, rsa_nbits):
|
||||
stdout = ""
|
||||
|
||||
client = paramiko.SSHClient()
|
||||
|
@ -154,7 +154,7 @@ def generate_cert(module, ip_address, key_filename, password,
|
|||
shell.send('exit\n')
|
||||
|
||||
if 'Success' not in buff:
|
||||
module.fail_json(msg="Error generating self signed certificate: "+stdout)
|
||||
module.fail_json(msg="Error generating self signed certificate: " + stdout)
|
||||
|
||||
client.close()
|
||||
return stdout
|
||||
|
|
|
@ -75,7 +75,7 @@ EXAMPLES = '''
|
|||
delay: 30
|
||||
'''
|
||||
|
||||
RETURN='''
|
||||
RETURN = '''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
@ -131,7 +131,7 @@ def main():
|
|||
timeout=60
|
||||
)
|
||||
|
||||
checkpnt = time.time()+timeout
|
||||
checkpnt = time.time() + timeout
|
||||
while True:
|
||||
try:
|
||||
xapi.op(cmd="show jobs all", cmd_xml=True)
|
||||
|
|
|
@ -71,7 +71,7 @@ EXAMPLES = '''
|
|||
dag_filter: "'aws-tag.aws:cloudformation:logical-id.ServerInstance' and 'instanceState.running'"
|
||||
'''
|
||||
|
||||
RETURN='''
|
||||
RETURN = '''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ EXAMPLES = '''
|
|||
category: software
|
||||
'''
|
||||
|
||||
RETURN='''
|
||||
RETURN = '''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
@ -118,7 +118,7 @@ def import_file(xapi, module, ip_address, file_, category):
|
|||
)
|
||||
|
||||
r = requests.post(
|
||||
'https://'+ip_address+'/api/',
|
||||
'https://' + ip_address + '/api/',
|
||||
verify=False,
|
||||
params=params,
|
||||
headers={'Content-Type': mef.content_type},
|
||||
|
|
|
@ -78,7 +78,7 @@ EXAMPLES = '''
|
|||
create_default_route: "yes"
|
||||
'''
|
||||
|
||||
RETURN='''
|
||||
RETURN = '''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
@ -98,8 +98,8 @@ _IF_XPATH = "/config/devices/entry[@name='localhost.localdomain']" +\
|
|||
|
||||
_ZONE_XPATH = "/config/devices/entry[@name='localhost.localdomain']" +\
|
||||
"/vsys/entry/zone/entry"
|
||||
_ZONE_XPATH_QUERY = _ZONE_XPATH+"[network/layer3/member/text()='%s']"
|
||||
_ZONE_XPATH_IF = _ZONE_XPATH+"[@name='%s']/network/layer3/member[text()='%s']"
|
||||
_ZONE_XPATH_QUERY = _ZONE_XPATH + "[network/layer3/member/text()='%s']"
|
||||
_ZONE_XPATH_IF = _ZONE_XPATH + "[@name='%s']/network/layer3/member[text()='%s']"
|
||||
_VR_XPATH = "/config/devices/entry[@name='localhost.localdomain']" +\
|
||||
"/network/virtual-router/entry"
|
||||
|
||||
|
@ -120,9 +120,9 @@ def add_dhcp_if(xapi, if_name, zone_name, create_default_route):
|
|||
if_xml = (''.join(if_xml)) % (if_name, cdr)
|
||||
xapi.edit(xpath=_IF_XPATH % if_name, element=if_xml)
|
||||
|
||||
xapi.set(xpath=_ZONE_XPATH+"[@name='%s']/network/layer3" % zone_name,
|
||||
xapi.set(xpath=_ZONE_XPATH + "[@name='%s']/network/layer3" % zone_name,
|
||||
element='<member>%s</member>' % if_name)
|
||||
xapi.set(xpath=_VR_XPATH+"[@name='default']/interface",
|
||||
xapi.set(xpath=_VR_XPATH + "[@name='default']/interface",
|
||||
element='<member>%s</member>' % if_name)
|
||||
|
||||
return True
|
||||
|
|
|
@ -71,7 +71,7 @@ EXAMPLES = '''
|
|||
file: "{{result.filename}}"
|
||||
'''
|
||||
|
||||
RETURN='''
|
||||
RETURN = '''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ EXAMPLES = '''
|
|||
panorama_secondary: "1.1.1.4"
|
||||
'''
|
||||
|
||||
RETURN='''
|
||||
RETURN = '''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
@ -112,11 +112,11 @@ def set_dns_server(xapi, new_dns_server, primary=True):
|
|||
tag = "primary"
|
||||
else:
|
||||
tag = "secondary"
|
||||
xpath = _XPATH_DNS_SERVERS+"/"+tag
|
||||
xpath = _XPATH_DNS_SERVERS + "/" + tag
|
||||
|
||||
# check the current element value
|
||||
xapi.get(xpath)
|
||||
val = xapi.element_root.find(".//"+tag)
|
||||
val = xapi.element_root.find(".//" + tag)
|
||||
if val is not None:
|
||||
# element exists
|
||||
val = val.text
|
||||
|
@ -135,11 +135,11 @@ def set_panorama_server(xapi, new_panorama_server, primary=True):
|
|||
tag = "panorama-server"
|
||||
else:
|
||||
tag = "panorama-server-2"
|
||||
xpath = _XPATH_PANORAMA_SERVERS+"/"+tag
|
||||
xpath = _XPATH_PANORAMA_SERVERS + "/" + tag
|
||||
|
||||
# check the current element value
|
||||
xapi.get(xpath)
|
||||
val = xapi.element_root.find(".//"+tag)
|
||||
val = xapi.element_root.find(".//" + tag)
|
||||
if val is not None:
|
||||
# element exists
|
||||
val = val.text
|
||||
|
|
|
@ -101,7 +101,7 @@ EXAMPLES = '''
|
|||
vulnerability: "default"
|
||||
'''
|
||||
|
||||
RETURN='''
|
||||
RETURN = '''
|
||||
# Default return values
|
||||
'''
|
||||
|
||||
|
|
|
@ -148,6 +148,7 @@ def to_lines(stdout):
|
|||
item = str(item).split('\n')
|
||||
yield item
|
||||
|
||||
|
||||
def parse_commands(module, warnings):
|
||||
command = ComplexList(dict(
|
||||
command=dict(key=True),
|
||||
|
@ -168,6 +169,7 @@ def parse_commands(module, warnings):
|
|||
)
|
||||
return commands
|
||||
|
||||
|
||||
def main():
|
||||
"""main entry point for module execution
|
||||
"""
|
||||
|
@ -221,7 +223,6 @@ def main():
|
|||
msg = 'One or more conditional statements have not be satisfied'
|
||||
module.fail_json(msg=msg, failed_conditions=failed_conditions)
|
||||
|
||||
|
||||
result = {
|
||||
'changed': False,
|
||||
'stdout': responses,
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue