Support availability zone in nimbleclient

Change-Id: Ic209e1fc9a8a72e484a66b4ae06bed28d180327e
This commit is contained in:
liusheng
2016-12-16 16:09:52 +08:00
parent 42f5680dba
commit 9592ad7cb6
7 changed files with 108 additions and 1 deletions

View File

@@ -73,7 +73,10 @@ class Manager(object):
data = body[response_key]
else:
data = body
items = [obj_class(self, res, loaded=True) for res in data if res]
if all([isinstance(res, six.string_types) for res in data]):
items = data
else:
items = [obj_class(self, res, loaded=True) for res in data if res]
return ListWithMeta(items, resp)

View File

@@ -0,0 +1,34 @@
# Copyright 2016 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.
#
"""Nimble v1 availability zone action implementations"""
import logging
from osc_lib.command import command
LOG = logging.getLogger(__name__)
class ListAvailabilityZone(command.Lister):
"""List all available zones"""
def take_action(self, parsed_args):
bc_client = self.app.client_manager.baremetal_compute
data = bc_client.availability_zone.list()
return (('availability_zone',),
tuple((d,) for d in data))

View File

@@ -21,6 +21,7 @@ from oslo_serialization import jsonutils
from requests import Response
from nimbleclient.common import base
from nimbleclient.v1 import availability_zone
from nimbleclient.v1 import instance
from nimbleclient.v1 import instance_type
@@ -62,6 +63,8 @@ class FakeBaremetalComputeV1Client(object):
self.instance_type = instance_type.InstanceTypeManager(
self.fake_http_client)
self.instance = instance.InstanceManager(self.fake_http_client)
self.availability_zone = availability_zone.AvailabilityZoneManager(
self.fake_http_client)
class FakeHTTPClient(object):

View File

@@ -0,0 +1,39 @@
# Copyright 2016 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 nimbleclient.osc.v1 import availability_zone
from nimbleclient.tests.unit import base as test_base
from nimbleclient.v1 import availability_zone as az_mgr
@mock.patch.object(az_mgr.AvailabilityZoneManager, '_list')
class TestAvailabilityZoneList(test_base.TestBaremetalComputeV1):
def setUp(self):
super(TestAvailabilityZoneList, self).setUp()
self.cmd = availability_zone.ListAvailabilityZone(self.app, None)
self.fake_az = ("az1", "az2", "az3")
def test_list_az(self, mock_list):
arglist = []
verifylist = []
mock_list.return_value = [self.fake_az]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
mock_list.assert_called_once_with('/availability_zones',
response_key='availability_zones')
self.assertEqual(('availability_zone',), columns)
self.assertEqual(((('az1', 'az2', 'az3'),),), data)

View File

@@ -0,0 +1,24 @@
# Copyright 2016 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 nimbleclient.common import base
class AvailabilityZoneManager(base.ManagerWithFind):
resource_class = None
def list(self):
url = '/availability_zones'
return self._list(url, response_key='availability_zones')

View File

@@ -14,6 +14,7 @@
#
from nimbleclient.common import http
from nimbleclient.v1 import availability_zone
from nimbleclient.v1 import instance
from nimbleclient.v1 import instance_type
@@ -28,3 +29,5 @@ class Client(object):
self.instance_type = instance_type.InstanceTypeManager(
self.http_client)
self.instance = instance.InstanceManager(self.http_client)
self.availability_zone = availability_zone.AvailabilityZoneManager(
self.http_client)

View File

@@ -42,6 +42,7 @@ openstack.baremetal_compute.v1 =
baremetal_compute_instance_list = nimbleclient.osc.v1.instance:ListInstance
baremetal_compute_instance_show = nimbleclient.osc.v1.instance:ShowInstance
baremetal_compute_instance_update = nimbleclient.osc.v1.instance:UpdateInstance
baremetal_compute_az_list = nimbleclient.osc.v1.availability_zone:ListAvailabilityZone
[build_sphinx]