def asn_pool(module): margs = module.params try: aos = get_aos_session(module, margs['session']) except: module.fail_json(msg="Unable to login to the AOS server") item_name = False item_id = False # Check ID / Name and Content if margs['content'] is not None: content = content_to_dict(module, margs['content']) if 'display_name' in content.keys(): item_name = content['display_name'] else: module.fail_json( msg="Unable to extract 'display_name' from 'content'") elif margs['name'] is not None: item_name = margs['name'] elif margs['id'] is not None: item_id = margs['id'] # If ranges are provided, check if they are valid if 'ranges' in margs.keys(): check_ranges_are_valid(module, margs['ranges']) # ---------------------------------------------------- # Find Object if available based on ID or Name # ---------------------------------------------------- try: my_pool = find_collection_item(aos.AsnPools, 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" ) # ---------------------------------------------------- # Proceed based on State value # ---------------------------------------------------- if margs['state'] == 'absent': asn_pool_absent(module, aos, my_pool) elif margs['state'] == 'present': asn_pool_present(module, aos, my_pool)
def asn_pool(module): margs = module.params try: aos = get_aos_session(module, margs['session']) except: module.fail_json(msg="Unable to login to the AOS server") item_name = False item_id = False # Check ID / Name and Content if margs['content'] is not None: content = content_to_dict(module, margs['content']) if 'display_name' in content.keys(): item_name = content['display_name'] else: module.fail_json(msg="Unable to extract 'display_name' from 'content'") elif margs['name'] is not None: item_name = margs['name'] elif margs['id'] is not None: item_id = margs['id'] # If ranges are provided, check if they are valid if 'ranges' in margs.keys(): check_ranges_are_valid(module, margs['ranges']) # ---------------------------------------------------- # Find Object if available based on ID or Name # ---------------------------------------------------- try: my_pool = find_collection_item(aos.AsnPools, 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") # ---------------------------------------------------- # Proceed based on State value # ---------------------------------------------------- if margs['state'] == 'absent': asn_pool_absent(module, aos, my_pool) elif margs['state'] == 'present': asn_pool_present(module, aos, my_pool)
def aos_template(module): margs = module.params try: aos = get_aos_session(module, margs['session']) except: module.fail_json(msg="Unable to login to the AOS server") item_name = False item_id = False if margs['content'] is not None: content = content_to_dict(module, margs['content']) if 'display_name' in content.keys(): item_name = content['display_name'] else: module.fail_json( msg="Unable to extract 'display_name' from 'content'") elif margs['name'] is not None: item_name = margs['name'] elif margs['id'] is not None: item_id = margs['id'] #---------------------------------------------------- # Find Object if available based on ID or Name #---------------------------------------------------- try: my_template = find_collection_item(aos.DesignTemplates, 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" ) #---------------------------------------------------- # Proceed based on State value #---------------------------------------------------- if margs['state'] == 'absent': template_absent(module, aos, my_template) elif margs['state'] == 'present': template_present(module, aos, my_template)
def ip_pool(module): margs = module.params try: aos = get_aos_session(module, margs['session']) except: module.fail_json(msg="Unable to login to the AOS server") item_name = False item_id = False if margs['content'] is not None: content = content_to_dict(module, margs['content']) if 'display_name' in content.keys(): item_name = content['display_name'] else: module.fail_json(msg="Unable to extract 'display_name' from 'content'") elif margs['name'] is not None: item_name = margs['name'] elif margs['id'] is not None: item_id = margs['id'] # ---------------------------------------------------- # Find Object if available based on ID or Name # ---------------------------------------------------- try: my_pool = find_collection_item(aos.IpPools, 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") # ---------------------------------------------------- # Proceed based on State value # ---------------------------------------------------- if margs['state'] == 'absent': ip_pool_absent(module, aos, my_pool) elif margs['state'] == 'present': ip_pool_present(module, aos, my_pool)
def logical_device(module): margs = module.params try: aos = get_aos_session(module, margs['session']) except: module.fail_json(msg="Unable to login to the AOS server") item_name = False item_id = False if margs['content'] is not None: content = content_to_dict(module, margs['content']) if 'display_name' in content.keys(): item_name = content['display_name'] else: module.fail_json( msg="Unable to extract 'display_name' from 'content'") elif margs['name'] is not None: item_name = margs['name'] elif margs['id'] is not None: item_id = margs['id'] #---------------------------------------------------- # Find Object if available based on ID or Name #---------------------------------------------------- my_logical_dev = find_collection_item(aos.LogicalDevices, item_name=item_name, item_id=item_id) #---------------------------------------------------- # Proceed based on State value #---------------------------------------------------- if margs['state'] == 'absent': logical_device_absent(module, aos, my_logical_dev) elif margs['state'] == 'present': logical_device_present(module, aos, my_logical_dev)
def logical_device(module): margs = module.params try: aos = get_aos_session(module, margs['session']) except: module.fail_json(msg="Unable to login to the AOS server") item_name = False item_id = False if margs['content'] is not None: content = content_to_dict(module, margs['content']) if 'display_name' in content.keys(): item_name = content['display_name'] else: module.fail_json(msg="Unable to extract 'display_name' from 'content'") elif margs['name'] is not None: item_name = margs['name'] elif margs['id'] is not None: item_id = margs['id'] # ---------------------------------------------------- # Find Object if available based on ID or Name # ---------------------------------------------------- my_logical_dev = find_collection_item(aos.LogicalDevices, item_name=item_name, item_id=item_id) # ---------------------------------------------------- # Proceed based on State value # ---------------------------------------------------- if margs['state'] == 'absent': logical_device_absent(module, aos, my_logical_dev) elif margs['state'] == 'present': logical_device_present(module, aos, my_logical_dev)
def blueprint_virtnet(module): margs = module.params # -------------------------------------------------------------------- # Get AOS session object based on Session Info # -------------------------------------------------------------------- try: aos = get_aos_session(module, margs['session']) except: module.fail_json(msg="Unable to login to the AOS server") # -------------------------------------------------------------------- # Get the blueprint Object based on either name or ID # -------------------------------------------------------------------- try: blueprint = find_collection_item(aos.Blueprints, 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))) # -------------------------------------------------------------------- # Convert "content" to dict and extract name # -------------------------------------------------------------------- if margs['content'] is not None: content = content_to_dict(module, margs['content']) if 'display_name' in content.keys(): item_name = content['display_name'] else: module.fail_json( msg="Unable to extract 'display_name' from 'content'") elif margs['name'] is not None: item_name = margs['name'] # -------------------------------------------------------------------- # Try to find VirtualNetwork object # -------------------------------------------------------------------- try: 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)) # -------------------------------------------------------------------- # Proceed based on State value # -------------------------------------------------------------------- if margs['state'] == 'absent': ensure_absent(module, aos, blueprint, virtnet) elif margs['state'] == 'present': ensure_present(module, aos, blueprint, virtnet)
def blueprint_virtnet(module): margs = module.params # -------------------------------------------------------------------- # Get AOS session object based on Session Info # -------------------------------------------------------------------- try: aos = get_aos_session(module, margs['session']) except: module.fail_json(msg="Unable to login to the AOS server") # -------------------------------------------------------------------- # Get the blueprint Object based on either name or ID # -------------------------------------------------------------------- try: blueprint = find_collection_item(aos.Blueprints, 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))) # -------------------------------------------------------------------- # Convert "content" to dict and extract name # -------------------------------------------------------------------- if margs['content'] is not None: content = content_to_dict(module, margs['content']) if 'display_name' in content.keys(): item_name = content['display_name'] else: module.fail_json(msg="Unable to extract 'display_name' from 'content'") elif margs['name'] is not None: item_name = margs['name'] # -------------------------------------------------------------------- # Try to find VirtualNetwork object # -------------------------------------------------------------------- try: 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)) # -------------------------------------------------------------------- # Proceed based on State value # -------------------------------------------------------------------- if margs['state'] == 'absent': ensure_absent(module, aos, blueprint, virtnet) elif margs['state'] == 'present': ensure_present(module, aos, blueprint, virtnet)