1
# Copyright 2012 OpenStack LLC.
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
8
# http://www.apache.org/licenses/LICENSE-2.0
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
16
"""Aggregate interface."""
18
from novaclient import base
21
class Aggregate(base.Resource):
22
"""An aggregates is a collection of compute hosts."""
25
return "<Aggregate: %s>" % self.id
27
def update(self, values):
28
"""Update the name and/or availability zone."""
29
return self.manager.update(self, values)
31
def add_host(self, host):
32
return self.manager.add_host(self, host)
34
def remove_host(self, host):
35
return self.manager.remove_host(self, host)
37
def set_metadata(self, metadata):
38
return self.manager.set_metadata(self, metadata)
41
self.manager.delete(self)
44
class AggregateManager(base.ManagerWithFind):
45
resource_class = Aggregate
48
"""Get a list of os-aggregates."""
49
return self._list('/os-aggregates', 'aggregates')
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')
57
def get_details(self, aggregate):
58
"""Get details of the specified aggregate."""
59
return self._get('/os-aggregates/%s' % (base.getid(aggregate)),
62
def update(self, aggregate, values):
63
"""Update the name and/or availablity zone."""
64
body = {'aggregate': values}
65
result = self._update("/os-aggregates/%s" % base.getid(aggregate),
67
return self.resource_class(self, result["aggregate"])
69
def add_host(self, aggregate, host):
70
"""Add a host into the Host Aggregate."""
71
body = {'add_host': {'host': host}}
72
return self._create("/os-aggregates/%s/action" % base.getid(aggregate),
75
def remove_host(self, aggregate, host):
76
"""Remove a host from the Host Aggregate."""
77
body = {'remove_host': {'host': host}}
78
return self._create("/os-aggregates/%s/action" % base.getid(aggregate),
81
def set_metadata(self, aggregate, metadata):
82
"""Set a aggregate metadata, replacing the existing metadata."""
83
body = {'set_metadata': {'metadata': metadata}}
84
return self._create("/os-aggregates/%s/action" % base.getid(aggregate),
87
def delete(self, aggregate):
88
"""Delete the specified aggregates."""
89
self._delete('/os-aggregates/%s' % (base.getid(aggregate)))