summaryrefslogtreecommitdiff
path: root/novaclient/v2/contrib/metadata_extensions.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/contrib/metadata_extensions.py')
-rw-r--r--novaclient/v2/contrib/metadata_extensions.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/novaclient/v2/contrib/metadata_extensions.py b/novaclient/v2/contrib/metadata_extensions.py
new file mode 100644
index 0000000..ad843b7
--- /dev/null
+++ b/novaclient/v2/contrib/metadata_extensions.py
@@ -0,0 +1,47 @@
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
16from novaclient.i18n import _
17from novaclient.openstack.common import cliutils
18from novaclient.v2 import shell
19
20
21@cliutils.arg(
22 'host',
23 metavar='<host>',
24 help=_('Name of host.'))
25@cliutils.arg(
26 'action',
27 metavar='<action>',
28 choices=['set', 'delete'],
29 help=_("Actions: 'set' or 'delete'"))
30@cliutils.arg(
31 'metadata',
32 metavar='<key=value>',
33 nargs='+',
34 action='append',
35 default=[],
36 help=_('Metadata to set or delete (only key is necessary on delete)'))
37def do_host_meta(cs, args):
38 """Set or Delete metadata on all instances of a host."""
39 hypervisors = cs.hypervisors.search(args.host, servers=True)
40 for hyper in hypervisors:
41 metadata = shell._extract_metadata(args)
42 if hasattr(hyper, 'servers'):
43 for server in hyper.servers:
44 if args.action == 'set':
45 cs.servers.set_meta(server['uuid'], metadata)
46 elif args.action == 'delete':
47 cs.servers.delete_meta(server['uuid'], metadata.keys())