~ubuntu-branches/ubuntu/saucy/python-novaclient/saucy

« back to all changes in this revision

Viewing changes to novaclient/v1_1/aggregates.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-02-03 10:46:49 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20120203104649-3604yixrglbsoi0g
Tags: 2012.1~e4~20120203.484-0ubuntu1
New upstream release. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 OpenStack LLC.
 
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
 
 
18
from novaclient import base
 
19
 
 
20
 
 
21
class 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
 
 
44
class 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_details(self, aggregate):
 
58
        """Get details of the specified aggregate."""
 
59
        return self._get('/os-aggregates/%s' % (base.getid(aggregate)),
 
60
                         "aggregate")
 
61
 
 
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),
 
66
                              body)
 
67
        return self.resource_class(self, result["aggregate"])
 
68
 
 
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),
 
73
                            body, "aggregate")
 
74
 
 
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),
 
79
                            body, "aggregate")
 
80
 
 
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),
 
85
                            body, "aggregate")
 
86
 
 
87
    def delete(self, aggregate):
 
88
        """Delete the specified aggregates."""
 
89
        self._delete('/os-aggregates/%s' % (base.getid(aggregate)))