added ability to modify nova flavor metadata in os_nova_flavor module (#20091)

* added ability to modify nova flavor metadata

* documentation for os_nova_flavor module fixed
pull/21839/head
kuboj 8 years ago committed by Ricardo Carrillo Cruz
parent f7e426e636
commit 551a765ea5

@ -86,6 +86,12 @@ options:
description:
- Ignored. Present for backwards compatability
required: false
extra_specs:
description:
- Metadata dictionary
required: false
default: None
version_added: "2.3"
requirements: ["shade"]
'''
@ -105,6 +111,18 @@ EXAMPLES = '''
cloud: mycloud
state: absent
name: tiny
- name: Create flavor with metadata
os_nova_flavor:
cloud: mycloud
state: present
name: tiny
ram: 1024
vcpus: 1
disk: 10
extra_specs:
"quota:disk_read_iops_sec": 5000
"aggregate_instance_extra_specs:pinned": false
'''
RETURN = '''
@ -153,6 +171,13 @@ flavor:
returned: success
type: bool
sample: true
extra_specs:
description: Flavor metadata
returned: success
type: dict
sample:
"quota:disk_read_iops_sec": 5000
"aggregate_instance_extra_specs:pinned": false
'''
try:
@ -187,6 +212,7 @@ def main():
rxtx_factor = dict(required=False, default=1.0, type='float'),
is_public = dict(required=False, default=True, type='bool'),
flavorid = dict(required=False, default="auto"),
extra_specs = dict(required=False, default=None, type='dict'),
)
module_kwargs = openstack_module_kwargs()
@ -203,6 +229,7 @@ def main():
state = module.params['state']
name = module.params['name']
extra_specs = module.params['extra_specs'] or {}
try:
cloud = shade.operator_cloud(**module.params)
@ -228,6 +255,18 @@ def main():
else:
changed=False
old_extra_specs = flavor['extra_specs']
new_extra_specs = dict([(k, str(v)) for k, v in extra_specs.items()])
unset_keys = set(flavor['extra_specs'].keys()) - set(extra_specs.keys())
if unset_keys:
cloud.unset_flavor_specs(flavor['id'], unset_keys)
if old_extra_specs != new_extra_specs:
cloud.set_flavor_specs(flavor['id'], extra_specs)
changed = (changed or old_extra_specs != new_extra_specs)
module.exit_json(changed=changed,
flavor=flavor,
id=flavor['id'])

Loading…
Cancel
Save