~ubuntu-branches/ubuntu/vivid/ironic/vivid-updates

« back to all changes in this revision

Viewing changes to ironic/api/controllers/v1/chassis.py

  • Committer: Package Import Robot
  • Author(s): Adam Gandelman, Adam Gandelman, James Page
  • Date: 2014-04-04 11:54:02 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20140404115402-wz51btzqxomdizv0
Tags: 2014.1~rc1-0ubuntu1
[ Adam Gandelman ]
* debian/ironic-common.postinst: Fix syntax preventing postinst
  from running.
* debian/ironic-api.install: Create missing .install, install
  ironic-api to /usr/bin/ironic-api.
* debian/patches/set_logdir.patch: Set log_dir to /var/log/ironic/ in
  sample config, causing both daemons to log to respective files there.
* debian/{rules, ironic-common.install}: Install ironic.conf.sample
  as /etc/ironic/ironic.conf.
* Fail build if test suite fails, limit testing concurrency to 1.
* debian/control: Add missing alembic, python-lockfile dependencies.

[ James Page ]
* d/control: Add Vcs-* fields for ubuntu-server-dev branches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#    License for the specific language governing permissions and limitations
14
14
#    under the License.
15
15
 
 
16
import datetime
16
17
import jsonpatch
17
18
import six
18
19
 
23
24
from wsme import types as wtypes
24
25
import wsmeext.pecan as wsme_pecan
25
26
 
26
 
from ironic.api.controllers.v1 import base
 
27
from ironic.api.controllers import base
 
28
from ironic.api.controllers import link
27
29
from ironic.api.controllers.v1 import collection
28
 
from ironic.api.controllers.v1 import link
29
30
from ironic.api.controllers.v1 import node
30
31
from ironic.api.controllers.v1 import types
31
32
from ironic.api.controllers.v1 import utils as api_utils
32
33
from ironic.common import exception
33
34
from ironic import objects
34
 
from ironic.openstack.common import excutils
35
 
from ironic.openstack.common import log
36
 
 
37
 
LOG = log.getLogger(__name__)
38
35
 
39
36
 
40
37
class ChassisPatchType(types.JsonPatchType):
70
67
            setattr(self, k, kwargs.get(k))
71
68
 
72
69
    @classmethod
73
 
    def convert_with_links(cls, rpc_chassis, expand=True):
74
 
        chassis = Chassis(**rpc_chassis.as_dict())
 
70
    def _convert_with_links(cls, chassis, url, expand=True):
75
71
        if not expand:
76
72
            chassis.unset_fields_except(['uuid', 'description'])
77
73
        else:
78
74
            chassis.nodes = [link.Link.make_link('self',
79
 
                                                 pecan.request.host_url,
 
75
                                                 url,
80
76
                                                 'chassis',
81
77
                                                 chassis.uuid + "/nodes"),
82
78
                             link.Link.make_link('bookmark',
83
 
                                                 pecan.request.host_url,
 
79
                                                 url,
84
80
                                                 'chassis',
85
81
                                                 chassis.uuid + "/nodes",
86
82
                                                 bookmark=True)
87
83
                            ]
88
84
        chassis.links = [link.Link.make_link('self',
89
 
                                             pecan.request.host_url,
 
85
                                             url,
90
86
                                             'chassis', chassis.uuid),
91
87
                         link.Link.make_link('bookmark',
92
 
                                             pecan.request.host_url,
 
88
                                             url,
93
89
                                             'chassis', chassis.uuid)
94
90
                        ]
95
91
        return chassis
96
92
 
 
93
    @classmethod
 
94
    def convert_with_links(cls, rpc_chassis, expand=True):
 
95
        chassis = Chassis(**rpc_chassis.as_dict())
 
96
        return cls._convert_with_links(chassis, pecan.request.host_url,
 
97
                                       expand)
 
98
 
 
99
    @classmethod
 
100
    def sample(cls, expand=True):
 
101
        time = datetime.datetime(2000, 1, 1, 12, 0, 0)
 
102
        sample = cls(uuid='eaaca217-e7d8-47b4-bb41-3f99f20eed89', extra={},
 
103
                     description='Sample chassis', created_at=time)
 
104
        return cls._convert_with_links(sample, 'http://localhost:6385',
 
105
                                       expand)
 
106
 
97
107
 
98
108
class ChassisCollection(collection.Collection):
99
109
    """API representation of a collection of chassis."""
114
124
        collection.next = collection.get_next(limit, url=url, **kwargs)
115
125
        return collection
116
126
 
 
127
    @classmethod
 
128
    def sample(cls, expand=True):
 
129
        sample = cls()
 
130
        sample.chassis = [Chassis.sample(expand=False)]
 
131
        return sample
 
132
 
117
133
 
118
134
class ChassisController(rest.RestController):
119
135
    """REST controller for Chassis."""
190
206
 
191
207
        :param chassis: a chassis within the request body.
192
208
        """
193
 
        try:
194
 
            new_chassis = pecan.request.dbapi.create_chassis(chassis.as_dict())
195
 
        except Exception as e:
196
 
            with excutils.save_and_reraise_exception():
197
 
                LOG.exception(e)
 
209
        new_chassis = pecan.request.dbapi.create_chassis(chassis.as_dict())
 
210
 
198
211
        return Chassis.convert_with_links(new_chassis)
199
212
 
200
213
    @wsme.validate(types.uuid, [ChassisPatchType])