OpenStack Compute (Nova) Client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

metadata_extensions.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright 2013 Rackspace Hosting
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. from novaclient.i18n import _
  16. from novaclient.openstack.common import cliutils
  17. from novaclient.v1_1 import shell
  18. @cliutils.arg(
  19. 'host',
  20. metavar='<host>',
  21. help=_('Name of host.'))
  22. @cliutils.arg(
  23. 'action',
  24. metavar='<action>',
  25. choices=['set', 'delete'],
  26. help=_("Actions: 'set' or 'delete'"))
  27. @cliutils.arg(
  28. 'metadata',
  29. metavar='<key=value>',
  30. nargs='+',
  31. action='append',
  32. default=[],
  33. help=_('Metadata to set or delete (only key is necessary on delete)'))
  34. def do_host_meta(cs, args):
  35. """Set or Delete metadata on all instances of a host."""
  36. hypervisors = cs.hypervisors.search(args.host, servers=True)
  37. for hyper in hypervisors:
  38. metadata = shell._extract_metadata(args)
  39. if hasattr(hyper, 'servers'):
  40. for server in hyper.servers:
  41. if args.action == 'set':
  42. cs.servers.set_meta(server['uuid'], metadata)
  43. elif args.action == 'delete':
  44. cs.servers.delete_meta(server['uuid'], metadata.keys())