Merge "Add role_net_map to expand roles output"
This commit is contained in:
commit
88c515cfad
@ -170,8 +170,10 @@ def expand(roles, stack_name, expand_provisioned=True, default_image=None,
|
|||||||
instances = []
|
instances = []
|
||||||
hostname_map = {}
|
hostname_map = {}
|
||||||
parameter_defaults = {'HostnameMap': hostname_map}
|
parameter_defaults = {'HostnameMap': hostname_map}
|
||||||
|
role_net_map = {}
|
||||||
for role in roles:
|
for role in roles:
|
||||||
name = role['name']
|
name = role['name']
|
||||||
|
role_net_map.setdefault(name, set())
|
||||||
hostname_format = build_hostname_format(
|
hostname_format = build_hostname_format(
|
||||||
role.get('hostname_format'), name)
|
role.get('hostname_format'), name)
|
||||||
count = role.get('count', 1)
|
count = role.get('count', 1)
|
||||||
@ -260,6 +262,9 @@ def expand(roles, stack_name, expand_provisioned=True, default_image=None,
|
|||||||
if provisioned == expand_provisioned:
|
if provisioned == expand_provisioned:
|
||||||
instances.append(inst)
|
instances.append(inst)
|
||||||
|
|
||||||
|
role_net_map[name].update(
|
||||||
|
[x['network'] for x in inst.get('networks', [])])
|
||||||
|
|
||||||
parameter_defaults['%sCount' % name] = (
|
parameter_defaults['%sCount' % name] = (
|
||||||
provisioned_count)
|
provisioned_count)
|
||||||
|
|
||||||
@ -268,7 +273,7 @@ def expand(roles, stack_name, expand_provisioned=True, default_image=None,
|
|||||||
env = {'parameter_defaults': parameter_defaults}
|
env = {'parameter_defaults': parameter_defaults}
|
||||||
else:
|
else:
|
||||||
env = {}
|
env = {}
|
||||||
return instances, env
|
return instances, env, role_net_map
|
||||||
|
|
||||||
|
|
||||||
def merge_networks_defaults(defaults, instance):
|
def merge_networks_defaults(defaults, instance):
|
||||||
|
@ -216,7 +216,7 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if state in ('present', 'all'):
|
if state in ('present', 'all'):
|
||||||
present, env = bd.expand(
|
present, env, role_net_map = bd.expand(
|
||||||
roles=module.params['baremetal_deployment'],
|
roles=module.params['baremetal_deployment'],
|
||||||
stack_name=module.params['stack_name'],
|
stack_name=module.params['stack_name'],
|
||||||
expand_provisioned=True,
|
expand_provisioned=True,
|
||||||
@ -226,13 +226,14 @@ def main():
|
|||||||
ssh_public_keys=module.params['ssh_public_keys'],
|
ssh_public_keys=module.params['ssh_public_keys'],
|
||||||
)
|
)
|
||||||
if state in ('absent', 'all'):
|
if state in ('absent', 'all'):
|
||||||
absent, _ = bd.expand(
|
absent, _, _ = bd.expand(
|
||||||
roles=module.params['baremetal_deployment'],
|
roles=module.params['baremetal_deployment'],
|
||||||
stack_name=module.params['stack_name'],
|
stack_name=module.params['stack_name'],
|
||||||
expand_provisioned=False,
|
expand_provisioned=False,
|
||||||
default_image=module.params['default_image'],
|
default_image=module.params['default_image'],
|
||||||
)
|
)
|
||||||
env = {}
|
env = {}
|
||||||
|
role_net_map = {}
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
instances = present
|
instances = present
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
@ -244,7 +245,8 @@ def main():
|
|||||||
changed=True,
|
changed=True,
|
||||||
msg='Expanded to %d instances' % len(instances),
|
msg='Expanded to %d instances' % len(instances),
|
||||||
instances=instances,
|
instances=instances,
|
||||||
environment=env
|
environment=env,
|
||||||
|
role_net_map=role_net_map
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg=str(e))
|
module.fail_json(msg=str(e))
|
||||||
|
@ -102,7 +102,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
{'name': 'Compute'},
|
{'name': 'Compute'},
|
||||||
{'name': 'Controller'},
|
{'name': 'Controller'},
|
||||||
]
|
]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image
|
roles, 'overcloud', True, self.default_image
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
{'name': 'Compute'},
|
{'name': 'Compute'},
|
||||||
{'name': 'Controller'},
|
{'name': 'Controller'},
|
||||||
]
|
]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image, self.default_network
|
roles, 'overcloud', True, self.default_image, self.default_network
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -165,7 +165,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
]}
|
]}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image, None
|
roles, 'overcloud', True, self.default_image, None
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -196,7 +196,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
]}
|
]}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image, self.default_network
|
roles, 'overcloud', True, self.default_image, self.default_network
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -229,7 +229,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
]}
|
]}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image, self.default_network
|
roles, 'overcloud', True, self.default_image, self.default_network
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -289,7 +289,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
'hostname': 'overcloud-controller-1',
|
'hostname': 'overcloud-controller-1',
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image
|
roles, 'overcloud', True, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -321,7 +321,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
},
|
},
|
||||||
'hostname_format': 'controller-%index%.example.com'
|
'hostname_format': 'controller-%index%.example.com'
|
||||||
}]
|
}]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image,
|
roles, 'overcloud', True, self.default_image,
|
||||||
user_name='heat-admin', ssh_public_keys='aaaa'
|
user_name='heat-admin', ssh_public_keys='aaaa'
|
||||||
)
|
)
|
||||||
@ -397,7 +397,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
'vif': True}]},
|
'vif': True}]},
|
||||||
]},
|
]},
|
||||||
]
|
]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image
|
roles, 'overcloud', True, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@ -464,7 +464,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
'nics': [{'subnet': 'leaf-2'}]},
|
'nics': [{'subnet': 'leaf-2'}]},
|
||||||
]},
|
]},
|
||||||
]
|
]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image
|
roles, 'overcloud', True, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual([
|
self.assertEqual([
|
||||||
@ -524,7 +524,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
'provisioned': False
|
'provisioned': False
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image
|
roles, 'overcloud', True, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual([
|
self.assertEqual([
|
||||||
@ -553,7 +553,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
},
|
},
|
||||||
environment['parameter_defaults'])
|
environment['parameter_defaults'])
|
||||||
|
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', False, self.default_image
|
roles, 'overcloud', False, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual([
|
self.assertEqual([
|
||||||
@ -584,7 +584,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
'provisioned': False
|
'provisioned': False
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image
|
roles, 'overcloud', True, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual([
|
self.assertEqual([
|
||||||
@ -623,7 +623,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
},
|
},
|
||||||
environment['parameter_defaults'])
|
environment['parameter_defaults'])
|
||||||
|
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', False, self.default_image
|
roles, 'overcloud', False, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual([
|
self.assertEqual([
|
||||||
@ -663,7 +663,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
'provisioned': True
|
'provisioned': True
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image
|
roles, 'overcloud', True, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual([
|
self.assertEqual([
|
||||||
@ -694,7 +694,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
},
|
},
|
||||||
environment['parameter_defaults'])
|
environment['parameter_defaults'])
|
||||||
|
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', False, self.default_image
|
roles, 'overcloud', False, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual([
|
self.assertEqual([
|
||||||
@ -732,7 +732,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
'provisioned': True
|
'provisioned': True
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image
|
roles, 'overcloud', True, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual([
|
self.assertEqual([
|
||||||
@ -763,7 +763,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
},
|
},
|
||||||
environment['parameter_defaults'])
|
environment['parameter_defaults'])
|
||||||
|
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', False, self.default_image
|
roles, 'overcloud', False, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual([
|
self.assertEqual([
|
||||||
@ -836,7 +836,7 @@ class TestExpandRoles(base.TestCase):
|
|||||||
'nics': [{'subnet': 'leaf-2'}]},
|
'nics': [{'subnet': 'leaf-2'}]},
|
||||||
]},
|
]},
|
||||||
]
|
]
|
||||||
instances, environment = bd.expand(
|
instances, environment, role_net_map = bd.expand(
|
||||||
roles, 'overcloud', True, self.default_image
|
roles, 'overcloud', True, self.default_image
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
Loading…
Reference in New Issue
Block a user