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:
John Barker 2017-12-07 16:27:06 +00:00 committed by John R Barker
commit c57a7f05e1
314 changed files with 3462 additions and 3383 deletions

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)