Merge "Created a package for API controllers V1."

This commit is contained in:
Jenkins 2013-07-03 10:24:42 +00:00 committed by Gerrit Code Review
commit 1a1e300998
4 changed files with 91 additions and 30 deletions

View File

@ -0,0 +1,35 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Version 1 of the Ironic API
NOTE: IN PROGRESS AND NOT FULLY IMPLEMENTED.
Should maintain feature parity with Nova Baremetal Extension.
Specification can be found at ironic/doc/api/v1.rst
"""
from ironic.api.controllers.v1 import controller
from ironic.api.controllers.v1 import node
Controller = controller.Controller
NodesController = node.NodesController
__all__ = (Controller,
NodesController,)

View File

@ -0,0 +1,27 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import wsme
from wsme import types as wtypes
class APIBase(wtypes.Base):
def as_dict(self):
return dict((k, getattr(self, k))
for k in self.fields
if hasattr(self, k) and
getattr(self, k) != wsme.Unset)

View File

@ -0,0 +1,23 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from ironic.api.controllers.v1 import node
class Controller(object):
"""Version 1 API controller root."""
nodes = node.NodesController()

View File

@ -15,16 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.
"""
Version 1 of the Ironic API
NOTE: IN PROGRESS AND NOT FULLY IMPLEMENTED.
Should maintain feature parity with Nova Baremetal Extension.
Specification can be found at ironic/doc/api/v1.rst
"""
import pecan
from pecan import rest
@ -32,22 +22,14 @@ import wsme
from wsme import types as wtypes
import wsmeext.pecan as wsme_pecan
from ironic.objects import node as node_obj
from ironic.api.controllers.v1 import base
from ironic import objects
from ironic.openstack.common import log
LOG = log.getLogger(__name__)
class APIBase(wtypes.Base):
def as_dict(self):
return dict((k, getattr(self, k))
for k in self.fields
if hasattr(self, k) and
getattr(self, k) != wsme.Unset)
class Node(APIBase):
class Node(base.APIBase):
"""API representation of a bare metal node.
This class enforces type checking and value constraints, and converts
@ -82,7 +64,7 @@ class Node(APIBase):
# NOTE: also list / link to ports associated with this node
def __init__(self, **kwargs):
self.fields = node_obj.Node.fields.keys()
self.fields = objects.Node.fields.keys()
for k in self.fields:
setattr(self, k, kwargs.get(k))
@ -98,7 +80,7 @@ class NodesController(rest.RestController):
@wsme_pecan.wsexpose(Node, unicode)
def get_one(self, uuid):
"""Retrieve information about the given node."""
node = node_obj.Node.get_by_uuid(pecan.request.context, uuid)
node = objects.Node.get_by_uuid(pecan.request.context, uuid)
return node
@wsme.validate(Node)
@ -116,7 +98,7 @@ class NodesController(rest.RestController):
@wsme_pecan.wsexpose(Node, unicode, body=Node)
def put(self, uuid, delta_node):
"""Update an existing node."""
node = node_obj.Node.get_by_uuid(pecan.request.context, uuid)
node = objects.Node.get_by_uuid(pecan.request.context, uuid)
# NOTE: delta_node will be a full API Node instance, but only user-
# supplied fields will be set, so we extract those by converting
# the object to a dict, then scanning for non-None values, and
@ -134,9 +116,3 @@ class NodesController(rest.RestController):
def delete(self, node_id):
"""Delete a node."""
pecan.request.dbapi.destroy_node(node_id)
class Controller(object):
"""Version 1 API controller root."""
nodes = NodesController()