Merge "Add support for node list command"

This commit is contained in:
Jenkins 2017-08-15 07:31:10 +00:00 committed by Gerrit Code Review
commit bab9a4fc01
6 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,35 @@
# Copyright 2017 Huawei, Inc. 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.
#
"""Mogan v1 Baremetal node implementations"""
import logging
from osc_lib.command import command
LOG = logging.getLogger(__name__)
class ListNode(command.Lister):
"""List all baremetal nodes names"""
def take_action(self, parsed_args):
bc_client = self.app.client_manager.baremetal_compute
data = bc_client.node.list()
return (('Node',),
tuple((d,) for d in data))

View File

@ -23,6 +23,7 @@ from requests import Response
from moganclient.common import base from moganclient.common import base
from moganclient.v1 import availability_zone from moganclient.v1 import availability_zone
from moganclient.v1 import flavor from moganclient.v1 import flavor
from moganclient.v1 import node
from moganclient.v1 import server from moganclient.v1 import server
@ -65,6 +66,7 @@ class FakeBaremetalComputeV1Client(object):
self.server = server.ServerManager(self.fake_http_client) self.server = server.ServerManager(self.fake_http_client)
self.availability_zone = availability_zone.AvailabilityZoneManager( self.availability_zone = availability_zone.AvailabilityZoneManager(
self.fake_http_client) self.fake_http_client)
self.node = node.NodeManager(self.fake_http_client)
class FakeHTTPClient(object): class FakeHTTPClient(object):

View File

@ -0,0 +1,38 @@
# Copyright 2017 Huawei, Inc. 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 mock
from moganclient.osc.v1 import node
from moganclient.tests.unit import base as test_base
from moganclient.v1 import node as node_mgr
@mock.patch.object(node_mgr.NodeManager, '_list')
class TestNodeList(test_base.TestBaremetalComputeV1):
def setUp(self):
super(TestNodeList, self).setUp()
self.cmd = node.ListNode(self.app, None)
self.fake_node = ("node-1", "node-2", "node-3")
def test_list_node(self, mock_list):
arglist = []
verifylist = []
mock_list.return_value = [self.fake_node]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
mock_list.assert_called_once_with('/nodes', response_key='nodes')
self.assertEqual(('Node',), columns)
self.assertEqual(((("node-1", "node-2", "node-3"),),), data)

View File

@ -17,6 +17,7 @@ from moganclient.common import http
from moganclient.v1 import availability_zone from moganclient.v1 import availability_zone
from moganclient.v1 import flavor from moganclient.v1 import flavor
from moganclient.v1 import keypair from moganclient.v1 import keypair
from moganclient.v1 import node
from moganclient.v1 import server from moganclient.v1 import server
@ -33,3 +34,4 @@ class Client(object):
self.availability_zone = availability_zone.AvailabilityZoneManager( self.availability_zone = availability_zone.AvailabilityZoneManager(
self.http_client) self.http_client)
self.keypair = keypair.KeyPairManager(self.http_client) self.keypair = keypair.KeyPairManager(self.http_client)
self.node = node.NodeManager(self.http_client)

28
moganclient/v1/node.py Normal file
View File

@ -0,0 +1,28 @@
# Copyright 2017 Huawei, Inc. 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 moganclient.common import base
class Node(base.Resource):
pass
class NodeManager(base.ManagerWithFind):
resource_class = Node
def list(self):
url = '/nodes'
return self._list(url, response_key='nodes')

View File

@ -56,6 +56,9 @@ openstack.baremetal_compute.v1 =
baremetal_keypair_show = moganclient.osc.v1.keypair:ShowKeyPair baremetal_keypair_show = moganclient.osc.v1.keypair:ShowKeyPair
baremetal_keypair_list = moganclient.osc.v1.keypair:ListKeyPair baremetal_keypair_list = moganclient.osc.v1.keypair:ListKeyPair
baremetal_keypair_delete = moganclient.osc.v1.keypair:DeleteKeyPair baremetal_keypair_delete = moganclient.osc.v1.keypair:DeleteKeyPair
# TODO(liusheng): may change the "baremetal" to another word to avoid
# conflict with Ironic
baremetal_compute_node_list = moganclient.osc.v1.node:ListNode
[build_sphinx] [build_sphinx]