Add python bindings for Nodes

Change-Id: I09118980b1aae247ffcf4678001c48cad3cadc9f
Implements: blueprint add-node-support
This commit is contained in:
Tzu-Mainn Chen
2013-10-03 09:45:29 -04:00
parent ebb41da6f6
commit e560a50250
6 changed files with 88 additions and 0 deletions

View File

@@ -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)

View File

@@ -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')

View File

@@ -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)

34
tuskarclient/v1/nodes.py Normal file
View File

@@ -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 "<Node {0}>".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))

View File

@@ -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.

View File

@@ -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,
]