summaryrefslogtreecommitdiff
path: root/ironic/api/controllers/v1/node.py
diff options
context:
space:
mode:
authorLucas Alvares Gomes <lucasagomes@gmail.com>2013-07-31 12:27:21 +0100
committerDevananda van der Veen <devananda.vdv@gmail.com>2013-08-06 15:39:58 -0700
commitf15510bae38c345143a677af72c300f9c54cd7dc (patch)
treed5ed3b3ad02faf30f4bc48c6b66723496f8d4522 /ironic/api/controllers/v1/node.py
parentf06a40d319844d9fe162d7a6843ee956f784a3c7 (diff)
downloadironic-f15510bae38c345143a677af72c300f9c54cd7dc.tar.gz
Expose subresources for Chassis and Node
This patch will expose the "nodes" subresource of Chassis and the "ports" subresource of Nodes. Linking and pagination is also available for those, as well as in any other collection in the API. Change-Id: Icf805b0c47cdcb0521b66b85b0ffd8dd41414fe9
Diffstat (limited to 'ironic/api/controllers/v1/node.py')
-rw-r--r--ironic/api/controllers/v1/node.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/ironic/api/controllers/v1/node.py b/ironic/api/controllers/v1/node.py
index 01feb4cc2..d6a0006b2 100644
--- a/ironic/api/controllers/v1/node.py
+++ b/ironic/api/controllers/v1/node.py
@@ -27,6 +27,7 @@ from ironic import objects
from ironic.api.controllers.v1 import base
from ironic.api.controllers.v1 import collection
from ironic.api.controllers.v1 import link
+from ironic.api.controllers.v1 import port
from ironic.api.controllers.v1 import utils
from ironic.common import exception
from ironic.openstack.common import log
@@ -73,6 +74,9 @@ class Node(base.APIBase):
links = [link.Link]
"A list containing a self link and associated node links"
+ ports = [link.Link]
+ "Links to the collection of ports on this node"
+
def __init__(self, **kwargs):
self.fields = objects.Node.fields.keys()
for k in self.fields:
@@ -88,6 +92,13 @@ class Node(base.APIBase):
'nodes', node.uuid,
bookmark=True)
]
+ node.ports = [link.Link.make_link('self', pecan.request.host_url,
+ 'nodes', node.uuid + "/ports"),
+ link.Link.make_link('bookmark',
+ pecan.request.host_url,
+ 'nodes', node.uuid + "/ports",
+ bookmark=True)
+ ]
return node
@@ -109,6 +120,10 @@ class NodeCollection(collection.Collection):
class NodesController(rest.RestController):
"""REST controller for Nodes."""
+ _custom_actions = {
+ 'ports': ['GET'],
+ }
+
@wsme_pecan.wsexpose(NodeCollection, int, unicode, unicode, unicode)
def get_all(self, limit=None, marker=None, sort_key='id', sort_dir='asc'):
"""Retrieve a list of nodes."""
@@ -195,3 +210,29 @@ class NodesController(rest.RestController):
TODO(deva): don't allow deletion of an associated node.
"""
pecan.request.dbapi.destroy_node(node_id)
+
+ @wsme_pecan.wsexpose(port.PortCollection, unicode, int, unicode,
+ unicode, unicode)
+ def ports(self, node_uuid, limit=None, marker=None,
+ sort_key='id', sort_dir='asc'):
+ """Retrieve a list of ports on this node."""
+ limit = utils.validate_limit(limit)
+ sort_dir = utils.validate_sort_dir(sort_dir)
+
+ marker_obj = None
+ if marker:
+ marker_obj = objects.Port.get_by_uuid(pecan.request.context,
+ marker)
+
+ ports = pecan.request.dbapi.get_ports_by_node(node_uuid, limit,
+ marker_obj,
+ sort_key=sort_key,
+ sort_dir=sort_dir)
+ collection = port.PortCollection()
+ collection.type = 'port'
+ collection.items = [port.Port.convert_with_links(n) for n in ports]
+ resource_url = '/'.join(['nodes', node_uuid, 'ports'])
+ collection.links = collection.make_links(limit, resource_url,
+ sort_key=sort_key,
+ sort_dir=sort_dir)
+ return collection