def main(): argument_spec = aci_argument_spec() argument_spec.update( mcp=dict(type='str', aliases=['mcp_interface', 'name']), # Not required for querying all objects description=dict(type='str', aliases=['descr']), admin_state=dict(type='bool'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['mcp']], ['state', 'present', ['mcp']], ], ) aci = ACIModule(module) mcp = module.params.get('mcp') description = module.params.get('description') admin_state = aci.boolean(module.params.get('admin_state'), 'enabled', 'disabled') state = module.params.get('state') name_alias = module.params.get('name_alias') aci.construct_url(root_class=dict( aci_class='mcpIfPol', aci_rn='infra/mcpIfP-{0}'.format(mcp), module_object=mcp, target_filter={'name': mcp}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='mcpIfPol', class_config=dict( name=mcp, descr=description, adminSt=admin_state, nameAlias=name_alias, ), ) aci.get_diff(aci_class='mcpIfPol') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( lldp_policy=dict(type='str', aliases=['name']), # Not required for querying all objects description=dict(type='str', aliases=['descr']), receive_state=dict(type='bool'), transmit_state=dict(type='bool'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['lldp_policy']], ['state', 'present', ['lldp_policy']], ], ) aci = ACIModule(module) lldp_policy = module.params.get('lldp_policy') description = module.params.get('description') receive_state = aci.boolean(module.params.get('receive_state'), 'enabled', 'disabled') transmit_state = aci.boolean(module.params.get('transmit_state'), 'enabled', 'disabled') state = module.params.get('state') name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='lldpIfPol', aci_rn='infra/lldpIfP-{0}'.format(lldp_policy), module_object=lldp_policy, target_filter={'name': lldp_policy}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='lldpIfPol', class_config=dict( name=lldp_policy, descr=description, adminRxSt=receive_state, adminTxSt=transmit_state, nameAlias=name_alias, ), ) aci.get_diff(aci_class='lldpIfPol') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( fc_policy=dict(type='str', aliases=['name' ]), # Not required for querying all objects description=dict(type='str', aliases=['descr']), port_mode=dict(type='str', choices=['f', 'np']), # No default provided on purpose state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['fc_policy']], ['state', 'present', ['fc_policy']], ], ) fc_policy = module.params.get('fc_policy') port_mode = module.params.get('port_mode') description = module.params.get('description') state = module.params.get('state') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url(root_class=dict( aci_class='fcIfPol', aci_rn='infra/fcIfPol-{0}'.format(fc_policy), module_object=fc_policy, target_filter={'name': fc_policy}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='fcIfPol', class_config=dict( name=fc_policy, descr=description, portMode=port_mode, nameAlias=name_alias, ), ) aci.get_diff(aci_class='fcIfPol') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( group=dict(type='str'), # Not required for querying all objects policy=dict(type='str'), # Not required for querying all objects state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['group']], ['state', 'present', ['group']], ], ) state = module.params.get('state') group = module.params.get('group') policy = module.params.get('policy') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='maintMaintGrp', aci_rn='fabric/maintgrp-{0}'.format(group), target_filter={'name': group}, module_object=group, ), child_classes=['maintRsMgrpp'], ) aci.get_existing() if state == 'present': aci.payload( aci_class='maintMaintGrp', class_config=dict( name=group, nameAlias=name_alias, ), child_configs=[ dict(maintRsMgrpp=dict(attributes=dict( tnMaintMaintPName=policy, ), ), ), ], ) aci.get_diff(aci_class='maintMaintGrp') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( leaf_profile=dict(type='str', aliases=['name', 'leaf_profile_name' ]), # Not required for querying all objects description=dict(type='str', aliases=['descr']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['leaf_profile']], ['state', 'present', ['leaf_profile']], ], ) leaf_profile = module.params.get('leaf_profile') description = module.params.get('description') state = module.params.get('state') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url(root_class=dict( aci_class='infraNodeP', aci_rn='infra/nprof-{0}'.format(leaf_profile), module_object=leaf_profile, target_filter={'name': leaf_profile}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='infraNodeP', class_config=dict( name=leaf_profile, descr=description, nameAlias=name_alias, ), ) aci.get_diff(aci_class='infraNodeP') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( contract=dict(type='str', aliases=['contract_name', 'name' ]), # Not required for querying all objects tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects description=dict(type='str', aliases=['descr']), scope=dict( type='str', choices=['application-profile', 'context', 'global', 'tenant']), priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified' ]), # No default provided on purpose dscp=dict(type='str', choices=[ 'AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42', 'AF43', 'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified' ], aliases=['target']), # No default provided on purpose state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['contract', 'tenant']], ['state', 'present', ['contract', 'tenant']], ], ) contract = module.params.get('contract') description = module.params.get('description') scope = module.params.get('scope') priority = module.params.get('priority') dscp = module.params.get('dscp') state = module.params.get('state') tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='vzBrCP', aci_rn='brc-{0}'.format(contract), module_object=contract, target_filter={'name': contract}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='vzBrCP', class_config=dict( name=contract, descr=description, scope=scope, prio=priority, targetDscp=dscp, nameAlias=name_alias, ), ) aci.get_diff(aci_class='vzBrCP') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects dst_group=dict(type='str'), # Not required for querying all objects src_group=dict(type='str'), # Not required for querying all objects description=dict(type='str', aliases=['descr']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['dst_group', 'src_group', 'tenant']], ['state', 'present', ['dst_group', 'src_group', 'tenant']], ], ) description = module.params.get('description') dst_group = module.params.get('dst_group') src_group = module.params.get('src_group') state = module.params.get('state') tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='spanSrcGrp', aci_rn='srcgrp-{0}'.format(src_group), module_object=src_group, target_filter={'name': src_group}, ), subclass_2=dict( aci_class='spanSpanLbl', aci_rn='spanlbl-{0}'.format(dst_group), module_object=dst_group, target_filter={'name': dst_group}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='spanSpanLbl', class_config=dict( descr=description, name=dst_group, nameAlias=name_alias, ), ) aci.get_diff(aci_class='spanSpanLbl') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( allow_useg=dict(type='str', choices=['encap', 'useg']), ap=dict(type='str', aliases=['app_profile', 'app_profile_name' ]), # Not required for querying all objects deploy_immediacy=dict(type='str', choices=['immediate', 'lazy']), domain=dict(type='str', aliases=['domain_name', 'domain_profile' ]), # Not required for querying all objects domain_type=dict(type='str', choices=['l2dom', 'phys', 'vmm'], aliases=['type' ]), # Not required for querying all objects encap=dict(type='int'), encap_mode=dict(type='str', choices=['auto', 'vlan', 'vxlan']), switching_mode=dict(type='str', default='native', choices=['AVE', 'native']), epg=dict(type='str', aliases=['name', 'epg_name' ]), # Not required for querying all objects netflow=dict(type='bool'), primary_encap=dict(type='int'), resolution_immediacy=dict( type='str', choices=['immediate', 'lazy', 'pre-provision']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects vm_provider=dict(type='str', choices=[ 'cloudfoundry', 'kubernetes', 'microsoft', 'openshift', 'openstack', 'redhat', 'vmware' ]), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['domain_type', 'vmm', ['vm_provider']], [ 'state', 'absent', ['ap', 'domain', 'domain_type', 'epg', 'tenant'] ], [ 'state', 'present', ['ap', 'domain', 'domain_type', 'epg', 'tenant'] ], ], ) aci = ACIModule(module) allow_useg = module.params.get('allow_useg') ap = module.params.get('ap') deploy_immediacy = module.params.get('deploy_immediacy') domain = module.params.get('domain') domain_type = module.params.get('domain_type') vm_provider = module.params.get('vm_provider') encap = module.params.get('encap') if encap is not None: if encap in range(1, 4097): encap = 'vlan-{0}'.format(encap) else: module.fail_json(msg='Valid VLAN assignments are from 1 to 4096') encap_mode = module.params.get('encap_mode') switching_mode = module.params.get('switching_mode') epg = module.params.get('epg') netflow = aci.boolean(module.params.get('netflow'), 'enabled', 'disabled') primary_encap = module.params.get('primary_encap') if primary_encap is not None: if primary_encap in range(1, 4097): primary_encap = 'vlan-{0}'.format(primary_encap) else: module.fail_json(msg='Valid VLAN assignments are from 1 to 4096') resolution_immediacy = module.params.get('resolution_immediacy') state = module.params.get('state') tenant = module.params.get('tenant') if domain_type in ['l2dom', 'phys'] and vm_provider is not None: module.fail_json(msg="Domain type '%s' cannot have a 'vm_provider'" % domain_type) # Compile the full domain for URL building if domain_type == 'vmm': epg_domain = 'uni/vmmp-{0}/dom-{1}'.format( VM_PROVIDER_MAPPING[vm_provider], domain) elif domain_type == 'l2dom': epg_domain = 'uni/l2dom-{0}'.format(domain) elif domain_type == 'phys': epg_domain = 'uni/phys-{0}'.format(domain) else: epg_domain = None aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvAp', aci_rn='ap-{0}'.format(ap), module_object=ap, target_filter={'name': ap}, ), subclass_2=dict( aci_class='fvAEPg', aci_rn='epg-{0}'.format(epg), module_object=epg, target_filter={'name': epg}, ), subclass_3=dict( aci_class='fvRsDomAtt', aci_rn='rsdomAtt-[{0}]'.format(epg_domain), module_object=epg_domain, target_filter={'tDn': epg_domain}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='fvRsDomAtt', class_config=dict( classPref=allow_useg, encap=encap, encapMode=encap_mode, switchingMode=switching_mode, instrImedcy=deploy_immediacy, netflowPref=netflow, primaryEncap=primary_encap, resImedcy=resolution_immediacy, ), ) aci.get_diff(aci_class='fvRsDomAtt') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( group=dict(type='str', aliases=['group']), # Not required for querying all objects node=dict(type='str', aliases=['node']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['node', 'group']], ['state', 'present', ['node', 'group']], ], ) state = module.params.get('state') group = module.params.get('group') node = module.params.get('node') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='firmwareFwGrp', aci_rn='fabric/fwgrp-{0}'.format(group), target_filter={'name': group}, module_object=group, ), subclass_1=dict( aci_class='fabricNodeBlk', aci_rn='nodeblk-blk{0}-{0}'.format(node), target_filter={'name': node}, module_object=node, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='fabricNodeBlk', class_config=dict( from_=node, to_=node, nameAlias=name_alias, ), ) aci.get_diff(aci_class='fabricNodeBlk') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( l2_policy=dict(type='str', aliases=['name']), # Not required for querying all policies description=dict(type='str', aliases=['descr']), vlan_scope=dict(type='str', choices=['global', 'portlocal']), # No default provided on purpose qinq=dict(type='str', choices=['core', 'disabled', 'edge']), vepa=dict(type='bool'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['l2_policy']], ['state', 'present', ['l2_policy']], ], ) aci = ACIModule(module) l2_policy = module.params.get('l2_policy') vlan_scope = module.params.get('vlan_scope') qinq = module.params.get('qinq') if qinq is not None: qinq = QINQ_MAPPING.get(qinq) vepa = aci.boolean(module.params.get('vepa'), 'enabled', 'disabled') description = module.params.get('description') state = module.params.get('state') name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='l2IfPol', aci_rn='infra/l2IfP-{0}'.format(l2_policy), module_object=l2_policy, target_filter={'name': l2_policy}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='l2IfPol', class_config=dict( name=l2_policy, descr=description, vlanScope=vlan_scope, qinq=qinq, vepa=vepa, nameAlias=name_alias, ), ) aci.get_diff(aci_class='l2IfPol') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( contract=dict(type='str', aliases=['contract_name' ]), # Not required for querying all objects filter=dict(type='str', aliases=['filter_name' ]), # Not required for querying all objects subject=dict(type='str', aliases=['contract_subject', 'subject_name' ]), # Not required for querying all objects tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects log=dict(type='str', choices=['log', 'none'], aliases=['directive']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['contract', 'filter', 'subject', 'tenant']], ['state', 'present', ['contract', 'filter', 'subject', 'tenant']], ], ) contract = module.params.get('contract') filter_name = module.params.get('filter') log = module.params.get('log') subject = module.params.get('subject') tenant = module.params.get('tenant') state = module.params.get('state') # Add subject_filter key to modul.params for building the URL module.params['subject_filter'] = filter_name # Convert log to empty string if none, as that is what API expects. An empty string is not a good option to present the user. if log == 'none': log = '' aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='vzBrCP', aci_rn='brc-{0}'.format(contract), module_object=contract, target_filter={'name': contract}, ), subclass_2=dict( aci_class='vzSubj', aci_rn='subj-{0}'.format(subject), module_object=subject, target_filter={'name': subject}, ), subclass_3=dict( aci_class='vzRsSubjFiltAtt', aci_rn='rssubjFiltAtt-{0}'.format(filter_name), module_object=filter_name, target_filter={'tnVzFilterName': filter_name}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='vzRsSubjFiltAtt', class_config=dict( tnVzFilterName=filter_name, directives=log, ), ) aci.get_diff(aci_class='vzRsSubjFiltAtt') aci.post_config() elif state == 'absent': aci.delete_config() # Remove subject_filter used to build URL from module.params module.params.pop('subject_filter') aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( name=dict(type='str', aliases=['maintenance_policy' ]), # Not required for querying all objects runmode=dict(type='str', default='pauseOnlyOnFailures', choices=['pauseOnlyOnFailures', 'pauseNever']), graceful=dict(type='bool'), scheduler=dict(type='str'), ignoreCompat=dict(type='bool'), adminst=dict(type='str', default='untriggered', choices=['triggered', 'untriggered']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['name']], ['state', 'present', ['name', 'scheduler']], ], ) aci = ACIModule(module) state = module.params.get('state') name = module.params.get('name') runmode = module.params.get('runmode') scheduler = module.params.get('scheduler') adminst = module.params.get('adminst') graceful = aci.boolean(module.params.get('graceful')) ignoreCompat = aci.boolean(module.params.get('ignoreCompat')) name_alias = module.params.get('name_alias') aci.construct_url(root_class=dict( aci_class='maintMaintP', aci_rn='fabric/maintpol-{0}'.format(name), target_filter={'name': name}, module_object=name, ), child_classes=['maintRsPolScheduler']) aci.get_existing() if state == 'present': aci.payload( aci_class='maintMaintP', class_config=dict( name=name, runMode=runmode, graceful=graceful, adminSt=adminst, ignoreCompat=ignoreCompat, nameAlias=name_alias, ), child_configs=[ dict(maintRsPolScheduler=dict(attributes=dict( tnTrigSchedPName=scheduler, ), ), ), ], ) aci.get_diff(aci_class='maintMaintP') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( contract=dict(type='str', aliases=['contract_name' ]), # Not required for querying all objects subject=dict(type='str', aliases=['contract_subject', 'name', 'subject_name' ]), # Not required for querying all objects tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects priority=dict(type='str', choices=['unspecified', 'level1', 'level2', 'level3']), reverse_filter=dict(type='bool'), dscp=dict(type='str', aliases=['target'], choices=[ 'AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42', 'AF43', 'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified' ]), description=dict(type='str', aliases=['descr']), consumer_match=dict( type='str', choices=['all', 'at_least_one', 'at_most_one', 'none']), provider_match=dict( type='str', choices=['all', 'at_least_one', 'at_most_one', 'none']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['contract', 'subject', 'tenant']], ['state', 'present', ['contract', 'subject', 'tenant']], ], ) aci = ACIModule(module) subject = module.params.get('subject') priority = module.params.get('priority') reverse_filter = aci.boolean(module.params.get('reverse_filter')) contract = module.params.get('contract') dscp = module.params.get('dscp') description = module.params.get('description') consumer_match = module.params.get('consumer_match') if consumer_match is not None: consumer_match = MATCH_MAPPING.get(consumer_match) provider_match = module.params.get('provider_match') if provider_match is not None: provider_match = MATCH_MAPPING.get(provider_match) state = module.params.get('state') tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='vzBrCP', aci_rn='brc-{0}'.format(contract), module_object=contract, target_filter={'name': contract}, ), subclass_2=dict( aci_class='vzSubj', aci_rn='subj-{0}'.format(subject), module_object=subject, target_filter={'name': subject}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='vzSubj', class_config=dict( name=subject, prio=priority, revFltPorts=reverse_filter, targetDscp=dscp, consMatchT=consumer_match, provMatchT=provider_match, descr=description, nameAlias=name_alias, ), ) aci.get_diff(aci_class='vzSubj') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( arp_flooding=dict(type='bool'), bd=dict(type='str', aliases=['bd_name', 'name']), # Not required for querying all objects bd_type=dict(type='str', choices=['ethernet', 'fc']), description=dict(type='str'), enable_multicast=dict(type='bool'), enable_routing=dict(type='bool'), endpoint_clear=dict(type='bool'), endpoint_move_detect=dict(type='str', choices=['default', 'garp']), endpoint_retention_action=dict(type='str', choices=['inherit', 'resolve']), endpoint_retention_policy=dict(type='str'), igmp_snoop_policy=dict(type='str'), ip_learning=dict(type='bool'), ipv6_nd_policy=dict(type='str'), l2_unknown_unicast=dict(type='str', choices=['proxy', 'flood']), l3_unknown_multicast=dict(type='str', choices=['flood', 'opt-flood']), limit_ip_learn=dict(type='bool'), mac_address=dict(type='str', aliases=['mac']), multi_dest=dict(type='str', choices=['bd-flood', 'drop', 'encap-flood']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects vrf=dict(type='str', aliases=['vrf_name']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['bd', 'tenant']], ['state', 'present', ['bd', 'tenant']], ], ) aci = ACIModule(module) arp_flooding = aci.boolean(module.params.get('arp_flooding')) bd = module.params.get('bd') bd_type = module.params.get('bd_type') if bd_type == 'ethernet': # ethernet type is represented as regular, but that is not clear to the users bd_type = 'regular' description = module.params.get('description') enable_multicast = aci.boolean(module.params.get('enable_multicast')) enable_routing = aci.boolean(module.params.get('enable_routing')) endpoint_clear = aci.boolean(module.params.get('endpoint_clear')) endpoint_move_detect = module.params.get('endpoint_move_detect') if endpoint_move_detect == 'default': # the ACI default setting is an empty string, but that is not a good input value endpoint_move_detect = '' endpoint_retention_action = module.params.get('endpoint_retention_action') endpoint_retention_policy = module.params.get('endpoint_retention_policy') igmp_snoop_policy = module.params.get('igmp_snoop_policy') ip_learning = aci.boolean(module.params.get('ip_learning')) ipv6_nd_policy = module.params.get('ipv6_nd_policy') l2_unknown_unicast = module.params.get('l2_unknown_unicast') l3_unknown_multicast = module.params.get('l3_unknown_multicast') limit_ip_learn = aci.boolean(module.params.get('limit_ip_learn')) mac_address = module.params.get('mac_address') multi_dest = module.params.get('multi_dest') state = module.params.get('state') tenant = module.params.get('tenant') vrf = module.params.get('vrf') name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvBD', aci_rn='BD-{0}'.format(bd), module_object=bd, target_filter={'name': bd}, ), child_classes=[ 'fvRsCtx', 'fvRsIgmpsn', 'fvRsBDToNdP', 'fvRsBdToEpRet' ], ) aci.get_existing() if state == 'present': aci.payload( aci_class='fvBD', class_config=dict( arpFlood=arp_flooding, descr=description, epClear=endpoint_clear, epMoveDetectMode=endpoint_move_detect, ipLearning=ip_learning, limitIpLearnToSubnets=limit_ip_learn, mac=mac_address, mcastAllow=enable_multicast, multiDstPktAct=multi_dest, name=bd, type=bd_type, unicastRoute=enable_routing, unkMacUcastAct=l2_unknown_unicast, unkMcastAct=l3_unknown_multicast, nameAlias=name_alias, ), child_configs=[ { 'fvRsCtx': { 'attributes': { 'tnFvCtxName': vrf } } }, { 'fvRsIgmpsn': { 'attributes': { 'tnIgmpSnoopPolName': igmp_snoop_policy } } }, { 'fvRsBDToNdP': { 'attributes': { 'tnNdIfPolName': ipv6_nd_policy } } }, { 'fvRsBdToEpRet': { 'attributes': { 'resolveAct': endpoint_retention_action, 'tnFvEpRetPolName': endpoint_retention_policy } } }, ], ) aci.get_diff(aci_class='fvBD') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( pool_type=dict(type='str', required=True, aliases=['type'], choices=['vlan', 'vsan', 'vxlan']), description=dict(type='str', aliases=['descr']), pool=dict(type='str', aliases=['name', 'pool_name' ]), # Not required for querying all objects pool_allocation_mode=dict(type='str', aliases=['allocation_mode', 'mode'], choices=['dynamic', 'static']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['pool']], ['state', 'present', ['pool']], ], ) description = module.params.get('description') pool = module.params.get('pool') pool_type = module.params.get('pool_type') pool_allocation_mode = module.params.get('pool_allocation_mode') state = module.params.get('state') name_alias = module.params.get('name_alias') aci_class = ACI_POOL_MAPPING[pool_type]['aci_class'] aci_mo = ACI_POOL_MAPPING[pool_type]['aci_mo'] pool_name = pool # ACI Pool URL requires the pool_allocation mode for vlan and vsan pools (ex: uni/infra/vlanns-[poolname]-static) if pool_type != 'vxlan' and pool is not None: if pool_allocation_mode is not None: pool_name = '[{0}]-{1}'.format(pool, pool_allocation_mode) else: module.fail_json( msg= "ACI requires parameter 'pool_allocation_mode' for 'pool_type' of 'vlan' and 'vsan' when parameter 'pool' is provided" ) # Vxlan pools do not support pool allocation modes if pool_type == 'vxlan' and pool_allocation_mode is not None: module.fail_json( msg= "vxlan pools do not support setting the 'pool_allocation_mode'; please remove this parameter from the task" ) aci = ACIModule(module) aci.construct_url(root_class=dict( aci_class=aci_class, aci_rn='{0}{1}'.format(aci_mo, pool_name), module_object=pool, target_filter={'name': pool}, ), ) aci.get_existing() if state == 'present': # Filter out module parameters with null values aci.payload(aci_class=aci_class, class_config=dict( allocMode=pool_allocation_mode, descr=description, name=pool, nameAlias=name_alias, )) # Generate config diff which will be used as POST request body aci.get_diff(aci_class=aci_class) # Submit changes if module not in check_mode and the proposed is different than existing aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( aaa_user=dict(type='str', required=True), aaa_user_type=dict(type='str', default='user', choices=['appuser', 'user']), certificate=dict(type='str', aliases=['cert_data', 'certificate_data']), certificate_name=dict( type='str', aliases=['cert_name']), # Not required for querying all objects state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['aaa_user', 'certificate_name']], [ 'state', 'present', ['aaa_user', 'certificate', 'certificate_name'] ], ], ) aaa_user = module.params.get('aaa_user') aaa_user_type = module.params.get('aaa_user_type') certificate = module.params.get('certificate') certificate_name = module.params.get('certificate_name') state = module.params.get('state') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class=ACI_MAPPING.get(aaa_user_type).get('aci_class'), aci_rn=ACI_MAPPING.get(aaa_user_type).get('aci_mo') + aaa_user, module_object=aaa_user, target_filter={'name': aaa_user}, ), subclass_1=dict( aci_class='aaaUserCert', aci_rn='usercert-{0}'.format(certificate_name), module_object=certificate_name, target_filter={'name': certificate_name}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='aaaUserCert', class_config=dict( data=certificate, name=certificate_name, nameAlias=name_alias, ), ) aci.get_diff(aci_class='aaaUserCert') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( leaf_profile=dict(type='str', aliases=['leaf_profile_name' ]), # Not required for querying all objects interface_selector=dict(type='str', aliases=[ 'interface_profile_name', 'interface_selector_name', 'name' ]), # Not required for querying all objects state=dict(type='str', default='present', choices=['absent', 'present', 'query'])) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[[ 'state', 'absent', ['leaf_profile', 'interface_selector'] ], ['state', 'present', ['leaf_profile', 'interface_selector']]], ) leaf_profile = module.params.get('leaf_profile') # WARNING: interface_selector accepts non existing interface_profile names and they appear on APIC gui with a state of "missing-target" interface_selector = module.params.get('interface_selector') state = module.params.get('state') # Defining the interface profile tDn for clarity interface_selector_tDn = 'uni/infra/accportprof-{0}'.format( interface_selector) aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='infraNodeP', aci_rn='infra/nprof-{0}'.format(leaf_profile), module_object=leaf_profile, target_filter={'name': leaf_profile}, ), subclass_1=dict( aci_class='infraRsAccPortP', aci_rn='rsaccPortP-[{0}]'.format(interface_selector_tDn), module_object=interface_selector, target_filter={'name': interface_selector}, )) aci.get_existing() if state == 'present': aci.payload( aci_class='infraRsAccPortP', class_config=dict(tDn=interface_selector_tDn), ) aci.get_diff(aci_class='infraRsAccPortP') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( epg=dict(type='str', aliases=['epg_name', 'name']), # Not required for querying all objects bd=dict(type='str', aliases=['bd_name', 'bridge_domain']), ap=dict(type='str', aliases=['app_profile', 'app_profile_name' ]), # Not required for querying all objects tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects description=dict(type='str', aliases=['descr']), priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']), intra_epg_isolation=dict(choices=['enforced', 'unenforced']), fwd_control=dict(type='str', choices=['none', 'proxy-arp']), preferred_group=dict(type='bool'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['ap', 'epg', 'tenant']], ['state', 'present', ['ap', 'epg', 'tenant']], ], ) aci = ACIModule(module) epg = module.params.get('epg') bd = module.params.get('bd') description = module.params.get('description') priority = module.params.get('priority') intra_epg_isolation = module.params.get('intra_epg_isolation') fwd_control = module.params.get('fwd_control') preferred_group = aci.boolean(module.params.get('preferred_group'), 'include', 'exclude') state = module.params.get('state') tenant = module.params.get('tenant') ap = module.params.get('ap') name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvAp', aci_rn='ap-{0}'.format(ap), module_object=ap, target_filter={'name': ap}, ), subclass_2=dict( aci_class='fvAEPg', aci_rn='epg-{0}'.format(epg), module_object=epg, target_filter={'name': epg}, ), child_classes=['fvRsBd'], ) aci.get_existing() if state == 'present': aci.payload( aci_class='fvAEPg', class_config=dict( name=epg, descr=description, prio=priority, pcEnfPref=intra_epg_isolation, fwdCtrl=fwd_control, prefGrMemb=preferred_group, nameAlias=name_alias, ), child_configs=[ dict(fvRsBd=dict(attributes=dict(tnFvBDName=bd, ), ), ) ], ) aci.get_diff(aci_class='fvAEPg') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( aaa_password=dict(type='str', no_log=True), aaa_password_lifetime=dict(type='int'), aaa_password_update_required=dict(type='bool'), aaa_user=dict(type='str', aliases=['name' ]), # Not required for querying all objects clear_password_history=dict(type='bool'), description=dict(type='str', aliases=['descr']), email=dict(type='str'), enabled=dict(type='bool'), expiration=dict(type='str'), expires=dict(type='bool'), first_name=dict(type='str'), last_name=dict(type='str'), phone=dict(type='str'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['aaa_user']], ['state', 'present', ['aaa_user']], ['expires', True, ['expiration']], ], ) aci = ACIModule(module) if not HAS_DATEUTIL: module.fail_json(msg='dateutil required for this module') aaa_password = module.params.get('aaa_password') aaa_password_lifetime = module.params.get('aaa_password_lifetime') aaa_password_update_required = aci.boolean( module.params.get('aaa_password_update_required')) aaa_user = module.params.get('aaa_user') clear_password_history = aci.boolean( module.params.get('clear_password_history'), 'yes', 'no') description = module.params.get('description') email = module.params.get('email') enabled = aci.boolean(module.params.get('enabled'), 'active', 'inactive') expires = aci.boolean(module.params.get('expires')) first_name = module.params.get('first_name') last_name = module.params.get('last_name') phone = module.params.get('phone') state = module.params.get('state') name_alias = module.params.get('name_alias') expiration = module.params.get('expiration') if expiration is not None and expiration != 'never': try: expiration = aci.iso8601_format( dateutil.parser.parse(expiration).replace(tzinfo=tzutc())) except Exception as e: module.fail_json(msg="Failed to parse date format '%s', %s" % (module.params.get('expiration'), e)) aci.construct_url(root_class=dict( aci_class='aaaUser', aci_rn='userext/user-{0}'.format(aaa_user), module_object=aaa_user, target_filter={'name': aaa_user}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='aaaUser', class_config=dict( accountStatus=enabled, clearPwdHistory=clear_password_history, descr=description, email=email, expiration=expiration, expires=expires, firstName=first_name, lastName=last_name, name=aaa_user, phone=phone, pwd=aaa_password, pwdLifeTime=aaa_password_lifetime, pwdUpdateRequired=aaa_password_update_required, nameAlias=name_alias, ), ) aci.get_diff(aci_class='aaaUser') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects epr_policy=dict(type='str', aliases=['epr_name', 'name' ]), # Not required for querying all objects bounce_age=dict(type='int'), bounce_trigger=dict(type='str', choices=['coop', 'flood']), hold_interval=dict(type='int'), local_ep_interval=dict(type='int'), remote_ep_interval=dict(type='int'), description=dict(type='str', aliases=['descr']), move_frequency=dict(type='int'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['epr_policy', 'tenant']], ['state', 'present', ['epr_policy', 'tenant']], ], ) epr_policy = module.params.get('epr_policy') bounce_age = module.params.get('bounce_age') if bounce_age is not None and bounce_age != 0 and bounce_age not in range( 150, 65536): module.fail_json( msg="The bounce_age must be a value of 0 or between 150 and 65535") if bounce_age == 0: bounce_age = 'infinite' bounce_trigger = module.params.get('bounce_trigger') if bounce_trigger is not None: bounce_trigger = BOUNCE_TRIG_MAPPING[bounce_trigger] description = module.params.get('description') hold_interval = module.params.get('hold_interval') if hold_interval is not None and hold_interval not in range(5, 65536): module.fail_json( msg="The hold_interval must be a value between 5 and 65535") local_ep_interval = module.params.get('local_ep_interval') if local_ep_interval is not None and local_ep_interval != 0 and local_ep_interval not in range( 120, 65536): module.fail_json( msg= "The local_ep_interval must be a value of 0 or between 120 and 65535" ) if local_ep_interval == 0: local_ep_interval = "infinite" move_frequency = module.params.get('move_frequency') if move_frequency is not None and move_frequency not in range(65536): module.fail_json( msg="The move_frequency must be a value between 0 and 65535") if move_frequency == 0: move_frequency = "none" remote_ep_interval = module.params.get('remote_ep_interval') if remote_ep_interval is not None and remote_ep_interval not in range( 120, 65536): module.fail_json( msg= "The remote_ep_interval must be a value of 0 or between 120 and 65535" ) if remote_ep_interval == 0: remote_ep_interval = "infinite" state = module.params.get('state') tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvEpRetPol', aci_rn='epRPol-{0}'.format(epr_policy), module_object=epr_policy, target_filter={'name': epr_policy}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='fvEpRetPol', class_config=dict( name=epr_policy, descr=description, bounceAgeIntvl=bounce_age, bounceTrig=bounce_trigger, holdIntvl=hold_interval, localEpAgeIntvl=local_ep_interval, remoteEpAgeIntvl=remote_ep_interval, moveFreq=move_frequency, nameAlias=name_alias, ), ) aci.get_diff(aci_class='fvEpRetPol') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( contract_type=dict(type='str', required=True, choices=['consumer', 'provider']), ap=dict(type='str', aliases=['app_profile', 'app_profile_name']), # Not required for querying all objects epg=dict(type='str', aliases=['epg_name']), # Not required for querying all objects contract=dict(type='str', aliases=['contract_name']), # Not required for querying all objects priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']), provider_match=dict(type='str', choices=['all', 'at_least_one', 'at_most_one', 'none']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['ap', 'contract', 'epg', 'tenant']], ['state', 'present', ['ap', 'contract', 'epg', 'tenant']], ], ) ap = module.params.get('ap') contract = module.params.get('contract') contract_type = module.params.get('contract_type') epg = module.params.get('epg') priority = module.params.get('priority') provider_match = module.params.get('provider_match') if provider_match is not None: provider_match = PROVIDER_MATCH_MAPPING[provider_match] state = module.params.get('state') tenant = module.params.get('tenant') aci_class = ACI_CLASS_MAPPING[contract_type]["class"] aci_rn = ACI_CLASS_MAPPING[contract_type]["rn"] if contract_type == "consumer" and provider_match is not None: module.fail_json(msg="the 'provider_match' is only configurable for Provided Contracts") aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvAp', aci_rn='ap-{0}'.format(ap), module_object=ap, target_filter={'name': ap}, ), subclass_2=dict( aci_class='fvAEPg', aci_rn='epg-{0}'.format(epg), module_object=epg, target_filter={'name': epg}, ), subclass_3=dict( aci_class=aci_class, aci_rn='{0}{1}'.format(aci_rn, contract), module_object=contract, target_filter={'tnVzBrCPName': contract}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class=aci_class, class_config=dict( matchT=provider_match, prio=priority, tnVzBrCPName=contract, ), ) aci.get_diff(aci_class=aci_class) aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( bd=dict(type='str', aliases=['bd_name']), # Not required for querying all objects description=dict(type='str', aliases=['descr']), enable_vip=dict(type='bool'), gateway=dict(type='str', aliases=['gateway_ip' ]), # Not required for querying all objects mask=dict(type='int', aliases=['subnet_mask' ]), # Not required for querying all objects subnet_name=dict(type='str', aliases=['name']), nd_prefix_policy=dict(type='str'), preferred=dict(type='bool'), route_profile=dict(type='str'), route_profile_l3_out=dict(type='str'), scope=dict(type='list', choices=['private', 'public', 'shared']), subnet_control=dict( type='str', choices=['nd_ra', 'no_gw', 'querier_ip', 'unspecified']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_together=[['gateway', 'mask']], required_if=[ ['state', 'present', ['bd', 'gateway', 'mask', 'tenant']], ['state', 'absent', ['bd', 'gateway', 'mask', 'tenant']], ], ) aci = ACIModule(module) description = module.params.get('description') enable_vip = aci.boolean(module.params.get('enable_vip')) tenant = module.params.get('tenant') bd = module.params.get('bd') gateway = module.params.get('gateway') mask = module.params.get('mask') if mask is not None and mask not in range(0, 129): # TODO: split checks between IPv4 and IPv6 Addresses module.fail_json( msg= 'Valid Subnet Masks are 0 to 32 for IPv4 Addresses and 0 to 128 for IPv6 addresses' ) if gateway is not None: gateway = '{0}/{1}'.format(gateway, str(mask)) subnet_name = module.params.get('subnet_name') nd_prefix_policy = module.params.get('nd_prefix_policy') preferred = aci.boolean(module.params.get('preferred')) route_profile = module.params.get('route_profile') route_profile_l3_out = module.params.get('route_profile_l3_out') scope = module.params.get('scope') if scope is not None: if 'private' in scope and 'public' in scope: module.fail_json( msg= "Parameter 'scope' cannot be both 'private' and 'public', got: %s" % scope) else: scope = ','.join(sorted(scope)) state = module.params.get('state') subnet_control = module.params.get('subnet_control') if subnet_control: subnet_control = SUBNET_CONTROL_MAPPING[subnet_control] name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='fvBD', aci_rn='BD-{0}'.format(bd), module_object=bd, target_filter={'name': bd}, ), subclass_2=dict( aci_class='fvSubnet', aci_rn='subnet-[{0}]'.format(gateway), module_object=gateway, target_filter={'ip': gateway}, ), child_classes=['fvRsBDSubnetToProfile', 'fvRsNdPfxPol'], ) aci.get_existing() if state == 'present': aci.payload( aci_class='fvSubnet', class_config=dict( ctrl=subnet_control, descr=description, ip=gateway, name=subnet_name, preferred=preferred, scope=scope, virtual=enable_vip, nameAlias=name_alias, ), child_configs=[ { 'fvRsBDSubnetToProfile': { 'attributes': { 'tnL3extOutName': route_profile_l3_out, 'tnRtctrlProfileName': route_profile } } }, { 'fvRsNdPfxPol': { 'attributes': { 'tnNdPfxPolName': nd_prefix_policy } } }, ], ) aci.get_diff(aci_class='fvSubnet') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( taboo_contract=dict( type='str', aliases=['name']), # Not required for querying all contracts tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all contracts scope=dict( type='str', choices=['application-profile', 'context', 'global', 'tenant']), description=dict(type='str', aliases=['descr']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['tenant', 'taboo_contract']], ['state', 'present', ['tenant', 'taboo_contract']], ], ) taboo_contract = module.params.get('taboo_contract') description = module.params.get('description') scope = module.params.get('scope') state = module.params.get('state') tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='vzTaboo', aci_rn='taboo-{0}'.format(taboo_contract), module_object=taboo_contract, target_filter={'name': taboo_contract}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='vzTaboo', class_config=dict( name=taboo_contract, descr=description, scope=scope, nameAlias=name_alias, ), ) aci.get_diff(aci_class='vzTaboo') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( pool_type=dict(type='str', required=True, aliases=['type'], choices=['vlan', 'vxlan', 'vsan']), allocation_mode=dict(type='str', aliases=['mode'], choices=['dynamic', 'inherit', 'static']), description=dict(type='str', aliases=['descr']), pool=dict(type='str', aliases=['pool_name' ]), # Not required for querying all objects pool_allocation_mode=dict(type='str', aliases=['pool_mode'], choices=['dynamic', 'static']), range_end=dict(type='int', aliases=['end' ]), # Not required for querying all objects range_name=dict(type='str', aliases=["name", "range" ]), # Not required for querying all objects range_start=dict(type='int', aliases=["start" ]), # Not required for querying all objects state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ [ 'state', 'absent', ['pool', 'range_end', 'range_name', 'range_start'] ], [ 'state', 'present', ['pool', 'range_end', 'range_name', 'range_start'] ], ], ) allocation_mode = module.params.get('allocation_mode') description = module.params.get('description') pool = module.params.get('pool') pool_allocation_mode = module.params.get('pool_allocation_mode') pool_type = module.params.get('pool_type') range_end = module.params.get('range_end') range_name = module.params.get('range_name') range_start = module.params.get('range_start') state = module.params.get('state') name_alias = module.params.get('name_alias') if range_end is not None: encap_end = '{0}-{1}'.format(pool_type, range_end) else: encap_end = None if range_start is not None: encap_start = '{0}-{1}'.format(pool_type, range_start) else: encap_start = None ACI_RANGE_MAPPING = dict( vlan=dict( aci_class='fvnsEncapBlk', aci_mo='from-[{0}]-to-[{1}]'.format(encap_start, encap_end), ), vxlan=dict( aci_class='fvnsEncapBlk', aci_mo='from-[{0}]-to-[{1}]'.format(encap_start, encap_end), ), vsan=dict( aci_class='fvnsVsanEncapBlk', aci_mo='vsanfrom-[{0}]-to-[{1}]'.format(encap_start, encap_end), ), ) # Collect proper class and mo information based on pool_type aci_range_class = ACI_RANGE_MAPPING[pool_type]["aci_class"] aci_range_mo = ACI_RANGE_MAPPING[pool_type]["aci_mo"] aci_pool_class = ACI_POOL_MAPPING[pool_type]["aci_class"] aci_pool_mo = ACI_POOL_MAPPING[pool_type]["aci_mo"] pool_name = pool # Validate range_end and range_start are valid for its respective encap type for encap_id in range_end, range_start: if encap_id is not None: if pool_type == 'vlan': if not 1 <= encap_id <= 4094: module.fail_json( msg= 'vlan pools must have "range_start" and "range_end" values between 1 and 4094' ) elif pool_type == 'vxlan': if not 5000 <= encap_id <= 16777215: module.fail_json( msg= 'vxlan pools must have "range_start" and "range_end" values between 5000 and 16777215' ) elif pool_type == 'vsan': if not 1 <= encap_id <= 4093: module.fail_json( msg= 'vsan pools must have "range_start" and "range_end" values between 1 and 4093' ) if range_end is not None and range_start is not None: # Validate range_start is less than range_end if range_start > range_end: module.fail_json( msg= 'The "range_start" must be less than or equal to the "range_end"' ) elif range_end is None and range_start is None: if range_name is None: # Reset range managed object to None for aci util to properly handle query aci_range_mo = None # Vxlan does not support setting the allocation mode if pool_type == 'vxlan' and allocation_mode is not None: module.fail_json( msg= 'vxlan pools do not support setting the "allocation_mode"; please omit this parameter for vxlan pools' ) # ACI Pool URL requires the allocation mode for vlan and vsan pools (ex: uni/infra/vlanns-[poolname]-static) if pool_type != 'vxlan' and pool is not None: if pool_allocation_mode is not None: pool_name = '[{0}]-{1}'.format(pool, pool_allocation_mode) else: module.fail_json( msg= 'ACI requires the "pool_allocation_mode" for "pool_type" of "vlan" and "vsan" when the "pool" is provided' ) aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class=aci_pool_class, aci_rn='{0}{1}'.format(aci_pool_mo, pool_name), module_object=pool, target_filter={'name': pool}, ), subclass_1=dict( aci_class=aci_range_class, aci_rn='{0}'.format(aci_range_mo), module_object=aci_range_mo, target_filter={ 'from': encap_start, 'to': encap_end, 'name': range_name }, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class=aci_range_class, class_config={ "allocMode": allocation_mode, "descr": description, "from": encap_start, "name": range_name, "to": encap_end, "nameAlias": name_alias, }, ) aci.get_diff(aci_class=aci_range_class) aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( leaf_interface_profile=dict(type='str', aliases=['leaf_interface_profile_name']), # Not required for querying all objects access_port_selector=dict(type='str', aliases=['name', 'access_port_selector_name']), # Not required for querying all objects description=dict(type='str'), leaf_port_blk=dict(type='str', aliases=['leaf_port_blk_name']), leaf_port_blk_description=dict(type='str'), from_port=dict(type='str', aliases=['from', 'fromPort', 'from_port_range']), to_port=dict(type='str', aliases=['to', 'toPort', 'to_port_range']), from_card=dict(type='str', aliases=['from_card_range']), to_card=dict(type='str', aliases=['to_card_range']), policy_group=dict(type='str', aliases=['policy_group_name']), interface_type=dict(type='str', default='switch_port', choices=['breakout', 'fex', 'port_channel', 'switch_port', 'vpc']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['leaf_interface_profile', 'access_port_selector']], ['state', 'present', ['leaf_interface_profile', 'access_port_selector']], ], ) leaf_interface_profile = module.params.get('leaf_interface_profile') access_port_selector = module.params.get('access_port_selector') description = module.params.get('description') leaf_port_blk = module.params.get('leaf_port_blk') leaf_port_blk_description = module.params.get('leaf_port_blk_description') from_port = module.params.get('from_port') to_port = module.params.get('to_port') from_card = module.params.get('from_card') to_card = module.params.get('to_card') policy_group = module.params.get('policy_group') interface_type = module.params.get('interface_type') state = module.params.get('state') # Build child_configs dynamically child_configs = [dict( infraPortBlk=dict( attributes=dict( descr=leaf_port_blk_description, name=leaf_port_blk, fromPort=from_port, toPort=to_port, fromCard=from_card, toCard=to_card, ), ), )] # Add infraRsAccBaseGrp only when policy_group was defined if policy_group is not None: child_configs.append(dict( infraRsAccBaseGrp=dict( attributes=dict( tDn=INTERFACE_TYPE_MAPPING[interface_type].format(policy_group), ), ), )) aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='infraAccPortP', aci_rn='infra/accportprof-{0}'.format(leaf_interface_profile), module_object=leaf_interface_profile, target_filter={'name': leaf_interface_profile}, ), subclass_1=dict( aci_class='infraHPortS', # NOTE: normal rn: hports-{name}-typ-{type}, hence here hardcoded to range for purposes of module aci_rn='hports-{0}-typ-range'.format(access_port_selector), module_object=access_port_selector, target_filter={'name': access_port_selector}, ), child_classes=['infraPortBlk', 'infraRsAccBaseGrp'], ) aci.get_existing() if state == 'present': aci.payload( aci_class='infraHPortS', class_config=dict( descr=description, name=access_port_selector, # type='range', ), child_configs=child_configs, ) aci.get_diff(aci_class='infraHPortS') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( name=dict(type='str', aliases=['name', 'scheduler_name' ]), # Not required for querying all objects description=dict(type='str', aliases=['descr']), windowname=dict(type='str', aliases=['windowname']), recurring=dict(type='bool'), concurCap=dict( type='int'), # Number of devices it will run against concurrently maxTime=dict( type='str' ), # The amount of minutes a process will be able to run (unlimited or dd:hh:mm:ss) date=dict(type='str', aliases=[ 'date' ]), # The date the process will run YYYY-MM-DDTHH:MM:SS state=dict(type='str', default='present', choices=['absent', 'present', 'query']), hour=dict(type='int'), minute=dict(type='int'), day=dict(type='str', default='every-day', choices=[ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday', 'every-day', 'even-day', 'odd-day' ]), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['name']], ['state', 'present', ['name']], ], ) state = module.params.get('state') name = module.params.get('name') windowname = module.params.get('windowname') recurring = module.params.get('recurring') date = module.params.get('date') hour = module.params.get('hour') minute = module.params.get('minute') maxTime = module.params.get('maxTime') concurCap = module.params.get('concurCap') day = module.params.get('day') description = module.params.get('description') name_alias = module.params.get('name_alias') if recurring: child_configs = [ dict(trigRecurrWindowP=dict(attributes=dict( name=windowname, hour=hour, minute=minute, procCa=maxTime, concurCap=concurCap, day=day, ))) ] elif recurring is False: child_configs = [ dict(trigAbsWindowP=dict(attributes=dict( name=windowname, procCap=maxTime, concurCap=concurCap, date=date, ))) ] else: child_configs = [] aci = ACIModule(module) aci.construct_url(root_class=dict( aci_class='trigSchedP', aci_rn='fabric/schedp-{0}'.format(name), target_filter={'name': name}, module_object=name, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='trigSchedP', class_config=dict( name=name, descr=description, nameAlias=name_alias, ), child_configs=child_configs, ) aci.get_diff(aci_class='trigSchedP') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects l3out=dict(type='str', aliases=['l3out_name' ]), # Not required for querying all objects extepg=dict(type='str', aliases=['extepg_name', 'name']), # Not required for querying all objects description=dict(type='str', aliases=['descr']), preferred_group=dict(type='bool'), dscp=dict(type='str', choices=[ 'AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42', 'AF43', 'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified' ], aliases=['target']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'present', ['extepg', 'l3out', 'tenant']], ['state', 'absent', ['extepg', 'l3out', 'tenant']], ], ) aci = ACIModule(module) tenant = module.params.get('tenant') l3out = module.params.get('l3out') extepg = module.params.get('extepg') description = module.params.get('description') preferred_group = aci.boolean(module.params.get('preferred_group'), 'include', 'exclude') dscp = module.params.get('dscp') state = module.params.get('state') name_alias = module.params.get('name_alias') aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='l3extOut', aci_rn='out-{0}'.format(l3out), module_object=l3out, target_filter={'name': l3out}, ), subclass_2=dict( aci_class='l3extInstP', aci_rn='instP-{0}'.format(extepg), module_object=extepg, target_filter={'name': extepg}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='l3extInstP', class_config=dict( name=extepg, descr=description, prefGrMemb=preferred_group, targetDscp=dscp, nameAlias=name_alias, ), ) aci.get_diff(aci_class='l3extInstP') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( arp_flag=dict(type='str', choices=VALID_ARP_FLAGS), description=dict(type='str', aliases=['descr']), dst_port=dict(type='str'), dst_port_end=dict(type='str'), dst_port_start=dict(type='str'), entry=dict(type='str', aliases=['entry_name', 'filter_entry', 'name']), # Not required for querying all objects ether_type=dict(choices=VALID_ETHER_TYPES, type='str'), filter=dict(type='str', aliases=['filter_name' ]), # Not required for querying all objects icmp_msg_type=dict(type='str', choices=VALID_ICMP_TYPES), icmp6_msg_type=dict(type='str', choices=VALID_ICMP6_TYPES), ip_protocol=dict(choices=VALID_IP_PROTOCOLS, type='str'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), stateful=dict(type='bool'), tenant=dict(type='str', aliases=['tenant_name' ]), # Not required for querying all objects name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['entry', 'filter', 'tenant']], ['state', 'present', ['entry', 'filter', 'tenant']], ], ) aci = ACIModule(module) arp_flag = module.params.get('arp_flag') if arp_flag is not None: arp_flag = ARP_FLAG_MAPPING.get(arp_flag) description = module.params.get('description') dst_port = module.params.get('dst_port') if FILTER_PORT_MAPPING.get(dst_port) is not None: dst_port = FILTER_PORT_MAPPING.get(dst_port) dst_end = module.params.get('dst_port_end') if FILTER_PORT_MAPPING.get(dst_end) is not None: dst_end = FILTER_PORT_MAPPING.get(dst_end) dst_start = module.params.get('dst_port_start') if FILTER_PORT_MAPPING.get(dst_start) is not None: dst_start = FILTER_PORT_MAPPING.get(dst_start) entry = module.params.get('entry') ether_type = module.params.get('ether_type') filter_name = module.params.get('filter') icmp_msg_type = module.params.get('icmp_msg_type') if icmp_msg_type is not None: icmp_msg_type = ICMP_MAPPING.get(icmp_msg_type) icmp6_msg_type = module.params.get('icmp6_msg_type') if icmp6_msg_type is not None: icmp6_msg_type = ICMP6_MAPPING.get(icmp6_msg_type) ip_protocol = module.params.get('ip_protocol') state = module.params.get('state') stateful = aci.boolean(module.params.get('stateful')) tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') # validate that dst_port is not passed with dst_start or dst_end if dst_port is not None and (dst_end is not None or dst_start is not None): module.fail_json( msg= "Parameter 'dst_port' cannot be used with 'dst_end' and 'dst_start'" ) elif dst_port is not None: dst_end = dst_port dst_start = dst_port aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='vzFilter', aci_rn='flt-{0}'.format(filter_name), module_object=filter_name, target_filter={'name': filter_name}, ), subclass_2=dict( aci_class='vzEntry', aci_rn='e-{0}'.format(entry), module_object=entry, target_filter={'name': entry}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='vzEntry', class_config=dict( arpOpc=arp_flag, descr=description, dFromPort=dst_start, dToPort=dst_end, etherT=ether_type, icmpv4T=icmp_msg_type, icmpv6T=icmp6_msg_type, name=entry, prot=ip_protocol, stateful=stateful, nameAlias=name_alias, ), ) aci.get_diff(aci_class='vzEntry') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects rtp=dict(type='str', aliases=['name', 'rtp_name']), # Not required for querying all objects description=dict(type='str', aliases=['descr']), tag=dict(type='int'), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['rtp', 'tenant']], ['state', 'present', ['rtp', 'tenant']], ], ) rtp = module.params.get('rtp') description = module.params.get('description') tag = module.params.get('tag') state = module.params.get('state') tenant = module.params.get('tenant') name_alias = module.params.get('name_alias') aci = ACIModule(module) aci.construct_url( root_class=dict( aci_class='fvTenant', aci_rn='tn-{0}'.format(tenant), module_object=tenant, target_filter={'name': tenant}, ), subclass_1=dict( aci_class='l3extRouteTagPol', aci_rn='rttag-{0}'.format(rtp), module_object=rtp, target_filter={'name': rtp}, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class='l3extRouteTagPol', class_config=dict( name=rtp, descr=description, tag=tag, nameAlias=name_alias, ), ) aci.get_diff(aci_class='l3extRouteTagPol') aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()
def main(): argument_spec = aci_argument_spec() argument_spec.update( name=dict(type='str', aliases=['credential_name', 'credential_profile']), credential_password=dict(type='str', no_log=True), credential_username=dict(type='str'), description=dict(type='str', aliases=['descr']), domain=dict(type='str', aliases=['domain_name', 'domain_profile']), state=dict(type='str', default='present', choices=['absent', 'present', 'query']), vm_provider=dict(type='str', choices=VM_PROVIDER_MAPPING.keys()), name_alias=dict(type='str'), ) module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=[ ['state', 'absent', ['domain']], ['state', 'present', ['domain']], ], ) name = module.params.get('name') credential_password = module.params.get('credential_password') credential_username = module.params.get('credential_username') description = module.params.get('description') domain = module.params.get('domain') state = module.params.get('state') vm_provider = module.params.get('vm_provider') name_alias = module.params.get('name_alias') credential_class = 'vmmUsrAccP' usracc_mo = 'uni/vmmp-{0}/dom-{1}/usracc-{2}'.format( VM_PROVIDER_MAPPING.get(vm_provider), domain, name) usracc_rn = 'vmmp-{0}/dom-{1}/usracc-{2}'.format( VM_PROVIDER_MAPPING.get(vm_provider), domain, name) # Ensure that querying all objects works when only domain is provided if name is None: usracc_mo = None aci = ACIModule(module) aci.construct_url(root_class=dict( aci_class=credential_class, aci_rn=usracc_rn, module_object=usracc_mo, target_filter={ 'name': domain, 'usracc': name }, ), ) aci.get_existing() if state == 'present': aci.payload( aci_class=credential_class, class_config=dict( descr=description, name=name, pwd=credential_password, usr=credential_username, nameAlias=name_alias, ), ) aci.get_diff(aci_class=credential_class) aci.post_config() elif state == 'absent': aci.delete_config() aci.exit_json()