Merge "os_nova_host_aggregate: Add support for not 'purging' missing hosts"
This commit is contained in:
commit
8e64c96e48
@ -31,6 +31,10 @@ options:
|
|||||||
description: List of hosts to set for an aggregate.
|
description: List of hosts to set for an aggregate.
|
||||||
type: list
|
type: list
|
||||||
elements: str
|
elements: str
|
||||||
|
purge_hosts:
|
||||||
|
description: Whether hosts not in I(hosts) should be removed from the aggregate
|
||||||
|
type: bool
|
||||||
|
default: true
|
||||||
state:
|
state:
|
||||||
description: Should the resource be present or absent.
|
description: Should the resource be present or absent.
|
||||||
choices: [present, absent]
|
choices: [present, absent]
|
||||||
@ -55,6 +59,18 @@ EXAMPLES = '''
|
|||||||
- host2
|
- host2
|
||||||
metadata:
|
metadata:
|
||||||
type: dbcluster
|
type: dbcluster
|
||||||
|
|
||||||
|
# Add an additional host to the aggregate
|
||||||
|
- os_nova_host_aggregate:
|
||||||
|
cloud: mycloud
|
||||||
|
state: present
|
||||||
|
name: db_aggregate
|
||||||
|
hosts:
|
||||||
|
- host3
|
||||||
|
purge_hosts: false
|
||||||
|
metadata:
|
||||||
|
type: dbcluster
|
||||||
|
|
||||||
# Delete an aggregate
|
# Delete an aggregate
|
||||||
- os_nova_host_aggregate:
|
- os_nova_host_aggregate:
|
||||||
cloud: mycloud
|
cloud: mycloud
|
||||||
@ -78,12 +94,21 @@ def _needs_update(module, aggregate):
|
|||||||
if module.params['availability_zone'] is not None:
|
if module.params['availability_zone'] is not None:
|
||||||
new_metadata['availability_zone'] = module.params['availability_zone']
|
new_metadata['availability_zone'] = module.params['availability_zone']
|
||||||
|
|
||||||
if (
|
if module.params['name'] != aggregate.name:
|
||||||
(module.params['name'] != aggregate.name)
|
return True
|
||||||
or (module.params['hosts'] is not None and set(module.params['hosts']) != set(aggregate.hosts))
|
if module.params['hosts'] is not None:
|
||||||
or (module.params['availability_zone'] is not None and module.params['availability_zone'] != aggregate.availability_zone)
|
if module.params['purge_hosts']:
|
||||||
or (module.params['metadata'] is not None and new_metadata != aggregate.metadata)
|
if set(module.params['hosts']) != set(aggregate.hosts):
|
||||||
):
|
return True
|
||||||
|
else:
|
||||||
|
intersection = set(module.params['hosts']).intersection(set(aggregate.hosts))
|
||||||
|
if set(module.params['hosts']) != intersection:
|
||||||
|
return True
|
||||||
|
if module.params['availability_zone'] is not None:
|
||||||
|
if module.params['availability_zone'] != aggregate.availability_zone:
|
||||||
|
return True
|
||||||
|
if module.params['metadata'] is not None:
|
||||||
|
if new_metadata != aggregate.metadata:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
@ -102,12 +127,29 @@ def _system_state_change(module, aggregate):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _update_hosts(cloud, aggregate, hosts, purge_hosts):
|
||||||
|
if hosts is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
hosts_to_add = set(hosts) - set(aggregate.hosts)
|
||||||
|
for i in hosts_to_add:
|
||||||
|
cloud.add_host_to_aggregate(aggregate.id, i)
|
||||||
|
|
||||||
|
if not purge_hosts:
|
||||||
|
return
|
||||||
|
|
||||||
|
hosts_to_remove = set(aggregate.hosts) - set(hosts)
|
||||||
|
for i in hosts_to_remove:
|
||||||
|
cloud.remove_host_from_aggregate(aggregate.id, i)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argument_spec = openstack_full_argument_spec(
|
argument_spec = openstack_full_argument_spec(
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
metadata=dict(required=False, default=None, type='dict'),
|
metadata=dict(required=False, default=None, type='dict'),
|
||||||
availability_zone=dict(required=False, default=None),
|
availability_zone=dict(required=False, default=None),
|
||||||
hosts=dict(required=False, default=None, type='list', elements='str'),
|
hosts=dict(required=False, default=None, type='list', elements='str'),
|
||||||
|
purge_hosts=dict(default=True, type='bool'),
|
||||||
state=dict(default='present', choices=['absent', 'present']),
|
state=dict(default='present', choices=['absent', 'present']),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -120,6 +162,7 @@ def main():
|
|||||||
metadata = module.params['metadata']
|
metadata = module.params['metadata']
|
||||||
availability_zone = module.params['availability_zone']
|
availability_zone = module.params['availability_zone']
|
||||||
hosts = module.params['hosts']
|
hosts = module.params['hosts']
|
||||||
|
purge_hosts = module.params['purge_hosts']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
|
||||||
if metadata is not None:
|
if metadata is not None:
|
||||||
@ -143,9 +186,7 @@ def main():
|
|||||||
if aggregate is None:
|
if aggregate is None:
|
||||||
aggregate = cloud.create_aggregate(name=name,
|
aggregate = cloud.create_aggregate(name=name,
|
||||||
availability_zone=availability_zone)
|
availability_zone=availability_zone)
|
||||||
if hosts:
|
_update_hosts(cloud, aggregate, hosts, False)
|
||||||
for h in hosts:
|
|
||||||
cloud.add_host_to_aggregate(aggregate.id, h)
|
|
||||||
if metadata:
|
if metadata:
|
||||||
cloud.set_aggregate_metadata(aggregate.id, metadata)
|
cloud.set_aggregate_metadata(aggregate.id, metadata)
|
||||||
changed = True
|
changed = True
|
||||||
@ -160,11 +201,7 @@ def main():
|
|||||||
if i != 'availability_zone':
|
if i != 'availability_zone':
|
||||||
metas[i] = None
|
metas[i] = None
|
||||||
cloud.set_aggregate_metadata(aggregate.id, metas)
|
cloud.set_aggregate_metadata(aggregate.id, metas)
|
||||||
if hosts is not None:
|
_update_hosts(cloud, aggregate, hosts, purge_hosts)
|
||||||
for i in (set(aggregate.hosts) - set(hosts)):
|
|
||||||
cloud.remove_host_from_aggregate(aggregate.id, i)
|
|
||||||
for i in (set(hosts) - set(aggregate.hosts)):
|
|
||||||
cloud.add_host_to_aggregate(aggregate.id, i)
|
|
||||||
changed = True
|
changed = True
|
||||||
else:
|
else:
|
||||||
changed = False
|
changed = False
|
||||||
@ -174,9 +211,7 @@ def main():
|
|||||||
if aggregate is None:
|
if aggregate is None:
|
||||||
changed = False
|
changed = False
|
||||||
else:
|
else:
|
||||||
if hosts:
|
_update_hosts(cloud, aggregate, [], True)
|
||||||
for h in hosts:
|
|
||||||
cloud.remove_host_from_aggregate(aggregate.id, h)
|
|
||||||
cloud.delete_aggregate(aggregate.id)
|
cloud.delete_aggregate(aggregate.id)
|
||||||
changed = True
|
changed = True
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user