summaryrefslogtreecommitdiff
path: root/novaclient/v2/aggregates.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/aggregates.py')
-rw-r--r--novaclient/v2/aggregates.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/novaclient/v2/aggregates.py b/novaclient/v2/aggregates.py
new file mode 100644
index 0000000..c2df315
--- /dev/null
+++ b/novaclient/v2/aggregates.py
@@ -0,0 +1,95 @@
1# Copyright 2012 OpenStack Foundation
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
16"""Aggregate interface."""
17
18from novaclient import base
19
20
21class Aggregate(base.Resource):
22 """An aggregates is a collection of compute hosts."""
23
24 def __repr__(self):
25 return "<Aggregate: %s>" % self.id
26
27 def update(self, values):
28 """Update the name and/or availability zone."""
29 return self.manager.update(self, values)
30
31 def add_host(self, host):
32 return self.manager.add_host(self, host)
33
34 def remove_host(self, host):
35 return self.manager.remove_host(self, host)
36
37 def set_metadata(self, metadata):
38 return self.manager.set_metadata(self, metadata)
39
40 def delete(self):
41 self.manager.delete(self)
42
43
44class AggregateManager(base.ManagerWithFind):
45 resource_class = Aggregate
46
47 def list(self):
48 """Get a list of os-aggregates."""
49 return self._list('/os-aggregates', 'aggregates')
50
51 def create(self, name, availability_zone):
52 """Create a new aggregate."""
53 body = {'aggregate': {'name': name,
54 'availability_zone': availability_zone}}
55 return self._create('/os-aggregates', body, 'aggregate')
56
57 def get(self, aggregate):
58 """Get details of the specified aggregate."""
59 return self._get('/os-aggregates/%s' % (base.getid(aggregate)),
60 "aggregate")
61
62 # NOTE:(dtroyer): utils.find_resource() uses manager.get() but we need to
63 # keep the API backward compatible
64 def get_details(self, aggregate):
65 """Get details of the specified aggregate."""
66 return self.get(aggregate)
67
68 def update(self, aggregate, values):
69 """Update the name and/or availability zone."""
70 body = {'aggregate': values}
71 return self._update("/os-aggregates/%s" % base.getid(aggregate),
72 body,
73 "aggregate")
74
75 def add_host(self, aggregate, host):
76 """Add a host into the Host Aggregate."""
77 body = {'add_host': {'host': host}}
78 return self._create("/os-aggregates/%s/action" % base.getid(aggregate),
79 body, "aggregate")
80
81 def remove_host(self, aggregate, host):
82 """Remove a host from the Host Aggregate."""
83 body = {'remove_host': {'host': host}}
84 return self._create("/os-aggregates/%s/action" % base.getid(aggregate),
85 body, "aggregate")
86
87 def set_metadata(self, aggregate, metadata):
88 """Set a aggregate metadata, replacing the existing metadata."""
89 body = {'set_metadata': {'metadata': metadata}}
90 return self._create("/os-aggregates/%s/action" % base.getid(aggregate),
91 body, "aggregate")
92
93 def delete(self, aggregate):
94 """Delete the specified aggregates."""
95 self._delete('/os-aggregates/%s' % (base.getid(aggregate)))