本文整理汇总了Python中ansible.module_utils.aci.ACIModule.construct_url方法的典型用法代码示例。如果您正苦于以下问题:Python ACIModule.construct_url方法的具体用法?Python ACIModule.construct_url怎么用?Python ACIModule.construct_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ansible.module_utils.aci.ACIModule
的用法示例。
在下文中一共展示了ACIModule.construct_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
lldp_policy=dict(type='str', require=False, aliases=['name']),
description=dict(type='str', aliases=['descr']),
receive_state=dict(type='str', choices=['disabled', 'enabled']),
transmit_state=dict(type='str', choices=['disabled', 'enabled']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['lldp_policy']],
['state', 'present', ['lldp_policy']],
],
)
lldp_policy = module.params['lldp_policy']
description = module.params['description']
receive_state = module.params['receive_state']
transmit_state = module.params['transmit_state']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='lldpIfPol',
aci_rn='infra/lldpIfP-{}'.format(lldp_policy),
filter_target='eq(lldpIfPol.name, "{}")'.format(lldp_policy),
module_object=lldp_policy,
),
)
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='lldpIfPol',
class_config=dict(
name=lldp_policy,
descr=description,
adminRxSt=receive_state,
adminTxSt=transmit_state,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='lldpIfPol')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例2: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
port_security=dict(type='str', required=False, aliases=['name']), # Not required for querying all objects
description=dict(type='str', aliases=['descr']),
max_end_points=dict(type='int'),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['port_security']],
['state', 'present', ['port_security']],
],
)
port_security = module.params['port_security']
description = module.params['description']
max_end_points = module.params['max_end_points']
if max_end_points is not None and max_end_points not in range(12001):
module.fail_json(msg='The "max_end_points" must be between 0 and 12000')
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='l2PortSecurityPol',
aci_rn='infra/portsecurityP-{}'.format(port_security),
filter_target='eq(l2PortSecurityPol.name, "{}")'.format(port_security),
module_object=port_security,
),
)
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='l2PortSecurityPol',
class_config=dict(
name=port_security,
descr=description,
maximum=max_end_points,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='l2PortSecurityPol')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例3: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
fc_policy=dict(type='str', required=False, 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']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['fc_policy']],
['state', 'present', ['fc_policy']],
],
)
fc_policy = module.params['fc_policy']
port_mode = module.params['port_mode']
description = module.params['description']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(
root_class=dict(
aci_class='fcIfPol',
aci_rn='infra/fcIfPol-{}'.format(fc_policy),
filter_target='eq(fcIfPol.name, "{}")'.format(fc_policy),
module_object=fc_policy,
),
)
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='fcIfPol',
class_config=dict(
name=fc_policy,
descr=description,
portMode=port_mode,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='fcIfPol')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例4: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
description=dict(type='str', aliases=['descr']),
dst_group=dict(type='str'),
src_group=dict(type='str'),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
tenant=dict(type='str', aliases=['tenant_name']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
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['description']
dst_group = module.params['dst_group']
src_group = module.params['src_group']
state = module.params['state']
# Add tenant_span_src_grp and tenant_span_src_grp_dst_grp to module.params for URL building
module.params['tenant_span_src_grp'] = src_group
module.params['tenant_span_src_grp_dst_grp'] = dst_group
aci = ACIModule(module)
aci.construct_url(root_class='tenant', subclass_1='tenant_span_src_grp', subclass_2='tenant_span_src_grp_dst_grp')
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='spanSpanLbl',
class_config=dict(
descr=description,
name=dst_group,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='spanSpanLbl')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
# Remove tenant_span_src_grp and tenant_span_src_grp_dst_grp that was used to build URL from module.params
module.params.pop('tenant_span_src_grp')
module.params.pop('tenant_span_src_grp_dst_grp')
module.exit_json(**aci.result)
示例5: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
ap=dict(type='str', aliases=['app_profile', 'app_profile_name']),
epg=dict(type='str', aliases=['epg_name']),
contract=dict(type='str', aliases=['contract_name']),
contract_type=dict(type='str', required=True, choices=['consumer', 'provider']),
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']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[['state', 'absent', ['ap', 'contract', 'epg', 'tenant']],
['state', 'present', ['ap', 'contract', 'epg', 'tenant']]]
)
contract = module.params['contract']
contract_type = module.params['contract_type']
aci_class = ACI_CLASS_MAPPING[contract_type]
priority = module.params['priority']
provider_match = module.params['provider_match']
state = module.params['state']
if contract_type == "consumer" and provider_match is not None:
module.fail_json(msg="the 'provider_match' is only configurable for Provided Contracts")
# Construct contract_class key and add to module.params for building URL
contract_class = 'epg_' + contract_type
module.params[contract_class] = contract
aci = ACIModule(module)
aci.construct_url(root_class='tenant', subclass_1='ap', subclass_2='epg', subclass_3=contract_class)
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(aci_class=aci_class, class_config=dict(matchT=provider_match, prio=priority, tnVzBrCPName=contract))
# 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()
# Remove contract_class that is used to build URL from module.params
module.params.pop(contract_class)
module.exit_json(**aci.result)
示例6: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
l2_policy=dict(type='str', required=False, 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='str', choices=['disabled', 'enabled']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['l2_policy']],
['state', 'present', ['l2_policy']],
],
)
l2_policy = module.params['l2_policy']
vlan_scope = module.params['vlan_scope']
qinq = module.params['qinq']
if qinq is not None:
qinq = QINQ_MAPPING[qinq]
vepa = module.params['vepa']
description = module.params['description']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(root_class='l2_policy')
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='l2IfPol',
class_config=dict(
name=l2_policy,
descr=description,
vlanScope=vlan_scope,
qinq=qinq, vepa=vepa,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='l2IfPol')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例7: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
contract=dict(type='str', aliases=['contract_name']),
filter=dict(type='str', aliases=['filter_name']),
log=dict(tyep='str', choices=['log', 'none'], aliases=['directive']),
subject=dict(type='str', aliases=['contract_subject', 'subject_name']),
tenant=dict(type='str', aliases=['tenant_name']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
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['contract']
filter_name = module.params['filter']
log = module.params['log']
# subject = module.params['subject']
# tenant = module.params['tenant']
state = module.params['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='tenant', subclass_1='contract', subclass_2='subject', subclass_3='subject_filter')
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(aci_class='vzRsSubjFiltAtt', class_config=dict(tnVzFilterName=filter_name, directives=log))
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='vzRsSubjFiltAtt')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
# Remove subject_filter used to build URL from module.params
module.params.pop('subject_filter')
module.exit_json(**aci.result)
示例8: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
description=dict(type='str', aliases=['descr']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
policy_control_direction=dict(choices=['ingress', 'egress'], type='str'),
policy_control_preference=dict(choices=['enforced', 'unenforced'], type='str'),
state=dict(choices=['absent', 'present', 'query'], type='str', default='present'),
tenant=dict(type='str', required=False, aliases=['tenant_name']), # Not required for querying all objects
vrf=dict(type='str', required=False, aliases=['context', 'name', 'vrf_name']), # Not required for querying all objects
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['tenant', 'vrf']],
['state', 'present', ['tenant', 'vrf']],
],
)
description = module.params['description']
policy_control_direction = module.params['policy_control_direction']
policy_control_preference = module.params['policy_control_preference']
state = module.params['state']
vrf = module.params['vrf']
aci = ACIModule(module)
aci.construct_url(root_class="tenant", subclass_1="vrf")
aci.get_existing()
if state == 'present':
# Filter out module params with null values
aci.payload(
aci_class='fvCtx',
class_config=dict(
descr=description,
pcEnfDir=policy_control_direction,
pcEnfPref=policy_control_preference,
name=vrf,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='fvCtx')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例9: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
epg=dict(type='str', aliases=['name', 'epg_name']),
bd=dict(type='str', aliases=['bd_name', 'bridge_domain']),
ap=dict(type='str', aliases=['app_profile', 'app_profile_name']),
tenant=dict(type='str', aliases=['tenant_name']),
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']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[['state', 'absent', ['ap', 'epg', 'tenant']],
['state', 'present', ['ap', 'epg', 'tenant']]]
)
epg = module.params['epg']
bd = module.params['bd']
description = module.params['description']
priority = module.params['priority']
intra_epg_isolation = module.params['intra_epg_isolation']
fwd_control = module.params['fwd_control']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(root_class="tenant", subclass_1="ap", subclass_2="epg", child_classes=['fvRsBd'])
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='fvAEPg',
class_config=dict(name=epg, descr=description, prio=priority, pcEnfPref=intra_epg_isolation, fwdCtrl=fwd_control),
child_configs=[dict(fvRsBd=dict(attributes=dict(tnFvBDName=bd)))]
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='fvAEPg')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例10: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
contract=dict(type='str', required=False, aliases=['contract_name', 'name']), # Not required for querying all objects
tenant=dict(type='str', required=False, 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']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[['state', 'absent', ['tenant', 'contract']],
['state', 'present', ['tenant', 'contract']]]
)
contract = module.params['contract']
description = module.params['description']
scope = module.params['scope']
priority = module.params['priority']
dscp = module.params['dscp']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(root_class='tenant', subclass_1='contract')
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='vzBrCP',
class_config=dict(name=contract, descr=description, scope=scope, prio=priority, targetDscp=dscp)
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='vzBrCP')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例11: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
bd=dict(type='str', aliases=['bd_name', 'bridge_domain']),
l3out=dict(type='str'),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
tenant=dict(type='str', aliases=['tenant_name']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6') # Deprecated starting from v2.6
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_together=[['gateway', 'mask']],
required_if=[
['state', 'present', ['bd', 'l3out', 'tenant']],
['state', 'absent', ['bd', 'l3out', 'tenant']],
],
)
l3out = module.params['l3out']
state = module.params['state']
# Add bd_l3out key to module.params for building the URL
module.params['bd_l3out'] = l3out
aci = ACIModule(module)
aci.construct_url(root_class='tenant', subclass_1='bd', subclass_2='bd_l3out')
aci.get_existing()
if state == 'present':
# Filter out module params with null values
aci.payload(
aci_class='fvRsBDToOut',
class_config=dict(tnL3extOutName=l3out),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='fvRsBDToOut')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
# Remove bd_l3out key used for URL building from module.params
module.params.pop('bd_l3out')
module.exit_json(**aci.result)
示例12: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
mcp=dict(type='str', required=False, aliases=['mcp_interface', 'name']), # Not required for querying all objects
description=dict(type='str', aliases=['descr']),
admin_state=dict(type='str', choices=['disabled', 'enabled']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['mcp']],
['state', 'present', ['mcp']],
],
)
mcp = module.params['mcp']
description = module.params['description']
admin_state = module.params['admin_state']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(root_class='mcp')
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='mcpIfPol',
class_config=dict(
name=mcp,
descr=description,
adminSt=admin_state,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='mcpIfPol')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例13: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
taboo_contract=dict(type='str', required=False, aliases=['name']), # Not required for querying all contracts
tenant=dict(type='str', required=False, 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']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
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['taboo_contract']
description = module.params['description']
scope = module.params['scope']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(root_class='tenant', subclass_1='taboo_contract')
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(
aci_class='vzTaboo',
class_config=dict(
name=taboo_contract,
descr=description, scope=scope,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='vzTaboo')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例14: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
aep=dict(type='str', aliases=['name', 'aep_name']), # not required for querying all AEPs
description=dict(type='str', aliases=['descr']),
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
)
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[['state', 'absent', ['aep']],
['state', 'present', ['aep']]]
)
aep = module.params['aep']
description = module.params['description']
state = module.params['state']
aci = ACIModule(module)
aci.construct_url(root_class="aep")
aci.get_existing()
if state == 'present':
# Filter out module parameters with null values
aci.payload(aci_class='infraAttEntityP', class_config=dict(name=aep, descr=description))
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='infraAttEntityP')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)
示例15: main
# 需要导入模块: from ansible.module_utils.aci import ACIModule [as 别名]
# 或者: from ansible.module_utils.aci.ACIModule import construct_url [as 别名]
def main():
argument_spec = aci_argument_spec
argument_spec.update(
tenant=dict(type='str', aliases=['tenant_name']), # not required for querying all EPRs
epr_policy=dict(type='str', aliases=['epr_name', 'name']),
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']),
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
)
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['epr_policy']
bounce_age = module.params['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['bounce_trigger']
if bounce_trigger is not None:
bounce_trigger = BOUNCE_TRIG_MAPPING[bounce_trigger]
description = module.params['description']
hold_interval = module.params['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['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['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['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['state']
aci = ACIModule(module)
aci.construct_url(root_class='tenant', subclass_1='epr_policy')
aci.get_existing()
if state == 'present':
# filter out module parameters with null values
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,
),
)
# Generate config diff which will be used as POST request body
aci.get_diff(aci_class='fvEpRetPol')
# Submit changes if module not in check_mode and the proposed is different than existing
aci.post_config()
elif state == 'absent':
aci.delete_config()
module.exit_json(**aci.result)