mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
MSO: Clean up internal references (#53242)
During the development of the new site modules the use of references is more common and this urged making the mechanism more simple overall.
This commit is contained in:
parent
e4093fbad4
commit
85eb8c30a6
3 changed files with 34 additions and 19 deletions
|
@ -97,7 +97,7 @@ def mso_reference_spec():
|
||||||
|
|
||||||
def mso_subnet_spec():
|
def mso_subnet_spec():
|
||||||
return dict(
|
return dict(
|
||||||
ip=dict(type='str', required=True),
|
subnet=dict(type='str', required=True, aliases=['ip']),
|
||||||
description=dict(type='str'),
|
description=dict(type='str'),
|
||||||
scope=dict(type='str', choices=['private', 'public']),
|
scope=dict(type='str', choices=['private', 'public']),
|
||||||
shared=dict(type='bool'),
|
shared=dict(type='bool'),
|
||||||
|
@ -393,19 +393,33 @@ class MSOModule(object):
|
||||||
ids.append(l['id'])
|
ids.append(l['id'])
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
def contract_ref(self, contract):
|
def anp_ref(self, **data):
|
||||||
''' Create contractRef string '''
|
''' Create anpRef string '''
|
||||||
return '/schemas/{schema_id}/templates/{template}/contracts/{name}'.format(**contract)
|
return '/schemas/{schema_id}/templates/{template}/anps/{anp}'.format(**data)
|
||||||
|
|
||||||
def filter_ref(self, schema_id, template, filter_name):
|
def epg_ref(self, **data):
|
||||||
|
''' Create epgRef string '''
|
||||||
|
return '/schemas/{schema_id}/templates/{template}/anps/{anp}/epgs/{epg}'.format(**data)
|
||||||
|
|
||||||
|
def bd_ref(self, **data):
|
||||||
|
''' Create bdRef string '''
|
||||||
|
return '/schemas/{schema_id}/templates/{template}/bds/{bd}'.format(**data)
|
||||||
|
|
||||||
|
def contract_ref(self, **data):
|
||||||
|
''' Create contractRef string '''
|
||||||
|
# Support the contract argspec
|
||||||
|
if 'name' in data:
|
||||||
|
data['contract'] = data['name']
|
||||||
|
return '/schemas/{schema_id}/templates/{template}/contracts/{contract}'.format(**data)
|
||||||
|
|
||||||
|
def filter_ref(self, **data):
|
||||||
''' Create a filterRef string '''
|
''' Create a filterRef string '''
|
||||||
data = dict(
|
|
||||||
schema_id=schema_id,
|
|
||||||
template=template,
|
|
||||||
filter=filter_name,
|
|
||||||
)
|
|
||||||
return '/schemas/{schema_id}/templates/{template}/filters/{filter}'.format(**data)
|
return '/schemas/{schema_id}/templates/{template}/filters/{filter}'.format(**data)
|
||||||
|
|
||||||
|
def vrf_ref(self, **data):
|
||||||
|
''' Create vrfRef string '''
|
||||||
|
return '/schemas/{schema_id}/templates/{template}/vrfs/{vrf}'.format(**data)
|
||||||
|
|
||||||
def make_reference(self, data, reftype, schema_id, template):
|
def make_reference(self, data, reftype, schema_id, template):
|
||||||
''' Create a reference from a dictionary '''
|
''' Create a reference from a dictionary '''
|
||||||
# Removes entry from payload
|
# Removes entry from payload
|
||||||
|
|
|
@ -211,7 +211,7 @@ def main():
|
||||||
if contract:
|
if contract:
|
||||||
contracts = [(c['contractRef'],
|
contracts = [(c['contractRef'],
|
||||||
c['relationshipType']) for c in schema_obj['templates'][template_idx]['anps'][anp_idx]['epgs'][epg_idx]['contractRelationships']]
|
c['relationshipType']) for c in schema_obj['templates'][template_idx]['anps'][anp_idx]['epgs'][epg_idx]['contractRelationships']]
|
||||||
contract_ref = mso.contract_ref(contract)
|
contract_ref = mso.contract_ref(**contract)
|
||||||
if (contract_ref, contract['type']) in contracts:
|
if (contract_ref, contract['type']) in contracts:
|
||||||
contract_idx = contracts.index((contract_ref, contract['type']))
|
contract_idx = contracts.index((contract_ref, contract['type']))
|
||||||
# FIXME: Changes based on index are DANGEROUS
|
# FIXME: Changes based on index are DANGEROUS
|
||||||
|
|
|
@ -234,7 +234,7 @@ def main():
|
||||||
contract_idx = contracts.index(contract)
|
contract_idx = contracts.index(contract)
|
||||||
|
|
||||||
filters = [f['filterRef'] for f in schema_obj['templates'][template_idx]['contracts'][contract_idx][filter_key]]
|
filters = [f['filterRef'] for f in schema_obj['templates'][template_idx]['contracts'][contract_idx][filter_key]]
|
||||||
filter_ref = mso.filter_ref(filter_schema_id, filter_template, filter_name)
|
filter_ref = mso.filter_ref(schema_id=filter_schema_id, template=filter_template, filter=filter_name)
|
||||||
if filter_ref in filters:
|
if filter_ref in filters:
|
||||||
filter_idx = filters.index(filter_ref)
|
filter_idx = filters.index(filter_ref)
|
||||||
# FIXME: Changes based on index are DANGEROUS
|
# FIXME: Changes based on index are DANGEROUS
|
||||||
|
@ -289,7 +289,8 @@ def main():
|
||||||
mso.existing = mso.sent
|
mso.existing = mso.sent
|
||||||
|
|
||||||
if contract_idx is None:
|
if contract_idx is None:
|
||||||
# COntract does not exist, so we have to create it
|
if not mso.existing:
|
||||||
|
# Contract does not exist, so we have to create it
|
||||||
if contract_display_name is None:
|
if contract_display_name is None:
|
||||||
contract_display_name = contract
|
contract_display_name = contract
|
||||||
if contract_filter_type is None:
|
if contract_filter_type is None:
|
||||||
|
|
Loading…
Reference in a new issue