From e560a50250daefc6ecd7e95fb6bb6a7f61d471c0 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Thu, 3 Oct 2013 09:45:29 -0400 Subject: [PATCH] Add python bindings for Nodes Change-Id: I09118980b1aae247ffcf4678001c48cad3cadc9f Implements: blueprint add-node-support --- tuskarclient/tests/v1/test_client.py | 4 ++++ tuskarclient/tests/v1/test_nodes.py | 35 ++++++++++++++++++++++++++++ tuskarclient/v1/client.py | 2 ++ tuskarclient/v1/nodes.py | 34 +++++++++++++++++++++++++++ tuskarclient/v1/nodes_shell.py | 11 +++++++++ tuskarclient/v1/shell.py | 2 ++ 6 files changed, 88 insertions(+) create mode 100644 tuskarclient/tests/v1/test_nodes.py create mode 100644 tuskarclient/v1/nodes.py create mode 100644 tuskarclient/v1/nodes_shell.py diff --git a/tuskarclient/tests/v1/test_client.py b/tuskarclient/tests/v1/test_client.py index 4575f99..4019c3f 100644 --- a/tuskarclient/tests/v1/test_client.py +++ b/tuskarclient/tests/v1/test_client.py @@ -30,6 +30,10 @@ class ClientTest(tutils.TestCase): self.client.resource_classes.__class__.__name__) self.assertEqual(self.client, self.client.resource_classes.api) + self.assertEqual("NodeManager", + self.client.nodes.__class__.__name__) + self.assertEqual(self.client, self.client.nodes.api) + self.assertEqual("FlavorManager", self.client.flavors.__class__.__name__) self.assertEqual(self.client, self.client.flavors.api) diff --git a/tuskarclient/tests/v1/test_nodes.py b/tuskarclient/tests/v1/test_nodes.py new file mode 100644 index 0000000..b9a29d3 --- /dev/null +++ b/tuskarclient/tests/v1/test_nodes.py @@ -0,0 +1,35 @@ +# 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 mock + +import tuskarclient.tests.utils as tutils +from tuskarclient.v1 import nodes + + +class NodeManagerTest(tutils.TestCase): + def setUp(self): + super(NodeManagerTest, self).setUp() + self.api = mock.Mock() + self.nm = nodes.NodeManager(self.api) + + def test_get(self): + self.nm._get = mock.Mock(return_value='fake_node') + + self.assertEqual(self.nm.get(42), 'fake_node') + self.nm._get.assert_called_with('/v1/nodes/42') + + def test_list(self): + self.nm._list = mock.Mock(return_value=['fake_node']) + + self.assertEqual(self.nm.list(), ['fake_node']) + self.nm._list.assert_called_with('/v1/nodes') diff --git a/tuskarclient/v1/client.py b/tuskarclient/v1/client.py index 6da7c86..cc3ccdc 100644 --- a/tuskarclient/v1/client.py +++ b/tuskarclient/v1/client.py @@ -13,6 +13,7 @@ from tuskarclient.common import http from tuskarclient.v1 import data_centers from tuskarclient.v1 import flavors +from tuskarclient.v1 import nodes from tuskarclient.v1 import racks from tuskarclient.v1 import resource_classes @@ -30,4 +31,5 @@ class Client(http.HTTPClient): self.racks = racks.RackManager(self) self.resource_classes = resource_classes.ResourceClassManager(self) self.flavors = flavors.FlavorManager(self) + self.nodes = nodes.NodeManager(self) self.data_centers = data_centers.DataCenterManager(self) diff --git a/tuskarclient/v1/nodes.py b/tuskarclient/v1/nodes.py new file mode 100644 index 0000000..428372a --- /dev/null +++ b/tuskarclient/v1/nodes.py @@ -0,0 +1,34 @@ +# 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 tuskarclient.common import base + + +class Node(base.Resource): + + def __repr__(self): + return "".format(self._info) + + +class NodeManager(base.Manager): + + resource_class = Node + + @staticmethod + def _path(id=None): + return '/v1/nodes/%s' % id if id else '/v1/nodes' + + def list(self): + return self._list(self._path()) + + def get(self, id): + return self._get(self._single_path(id)) diff --git a/tuskarclient/v1/nodes_shell.py b/tuskarclient/v1/nodes_shell.py new file mode 100644 index 0000000..94e731d --- /dev/null +++ b/tuskarclient/v1/nodes_shell.py @@ -0,0 +1,11 @@ +# 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. diff --git a/tuskarclient/v1/shell.py b/tuskarclient/v1/shell.py index 45106b8..f546e9c 100644 --- a/tuskarclient/v1/shell.py +++ b/tuskarclient/v1/shell.py @@ -13,12 +13,14 @@ from tuskarclient.common import utils from tuskarclient.v1 import data_centers_shell from tuskarclient.v1 import flavors_shell +from tuskarclient.v1 import nodes_shell from tuskarclient.v1 import racks_shell from tuskarclient.v1 import resource_classes_shell COMMAND_MODULES = [ data_centers_shell, flavors_shell, + nodes_shell, racks_shell, resource_classes_shell, ]