Merge "Add support for availability zone request"
This commit is contained in:
commit
004bad9f1f
|
@ -10,6 +10,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstack.compute.v2 import availability_zone
|
||||
from openstack.compute.v2 import extension
|
||||
from openstack.compute.v2 import flavor as _flavor
|
||||
from openstack.compute.v2 import image as _image
|
||||
|
@ -569,3 +570,16 @@ class Proxy(proxy.BaseProxy):
|
|||
server = _server.Server.from_id(server)
|
||||
return server.rebuild(self.session, name, image_ref, admin_password,
|
||||
**attrs)
|
||||
|
||||
def availability_zones(self, **query):
|
||||
"""Return a generator of availability zones
|
||||
|
||||
:param kwargs \*\*query: Optional query parameters to be sent
|
||||
to limit the resources being returned.
|
||||
|
||||
:returns: A generator of availability zone
|
||||
:rtype: :class:`~openstack.compute.v2.availability_zone.
|
||||
AvailabilityZone`
|
||||
"""
|
||||
return self._list(availability_zone.AvailabilityZone,
|
||||
paginated=False, **query)
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
# 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 openstack.compute import compute_service
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class AvailabilityZone(resource.Resource):
|
||||
|
||||
resource_key = 'availability_zone'
|
||||
resources_key = 'availabilityZoneInfo'
|
||||
base_path = '/os-availability-zone'
|
||||
|
||||
service = compute_service.ComputeService()
|
||||
|
||||
# capabilities
|
||||
allow_list = True
|
||||
|
||||
# Properties
|
||||
#: name of availability zone
|
||||
name = resource.prop('zoneName')
|
||||
|
||||
#: state of availability zone
|
||||
state = resource.prop('zoneState')
|
||||
|
||||
#: hosts of availability zone
|
||||
hosts = resource.prop('hosts')
|
|
@ -0,0 +1,41 @@
|
|||
# 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 testtools
|
||||
|
||||
from openstack.compute.v2 import availability_zone as az
|
||||
|
||||
IDENTIFIER = 'IDENTIFIER'
|
||||
BASIC_EXAMPLE = {
|
||||
'id': IDENTIFIER,
|
||||
'zoneState': 'available',
|
||||
'hosts': 'host1',
|
||||
'zoneName': 'zone1'
|
||||
}
|
||||
|
||||
|
||||
class TestAvailabilityZone(testtools.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
sot = az.AvailabilityZone()
|
||||
self.assertEqual('availability_zone', sot.resource_key)
|
||||
self.assertEqual('availabilityZoneInfo', sot.resources_key)
|
||||
self.assertEqual('/os-availability-zone', sot.base_path)
|
||||
self.assertTrue(sot.allow_list)
|
||||
self.assertEqual('compute', sot.service.service_type)
|
||||
|
||||
def test_make_basic(self):
|
||||
sot = az.AvailabilityZone(BASIC_EXAMPLE)
|
||||
self.assertEqual(BASIC_EXAMPLE['id'], sot.id)
|
||||
self.assertEqual(BASIC_EXAMPLE['zoneState'], sot.state)
|
||||
self.assertEqual(BASIC_EXAMPLE['hosts'], sot.hosts)
|
||||
self.assertEqual(BASIC_EXAMPLE['zoneName'], sot.name)
|
|
@ -13,6 +13,7 @@
|
|||
import mock
|
||||
|
||||
from openstack.compute.v2 import _proxy
|
||||
from openstack.compute.v2 import availability_zone as az
|
||||
from openstack.compute.v2 import extension
|
||||
from openstack.compute.v2 import flavor
|
||||
from openstack.compute.v2 import image
|
||||
|
@ -272,3 +273,7 @@ class TestComputeProxy(test_proxy_base.TestProxyBase):
|
|||
expected_args=["test_server", "test_image_url",
|
||||
"test_pass"],
|
||||
expected_kwargs={"metadata": {"k1": "v1"}})
|
||||
|
||||
def test_availability_zones(self):
|
||||
self.verify_list(self.proxy.availability_zones, az.AvailabilityZone,
|
||||
paginated=False)
|
||||
|
|
Loading…
Reference in New Issue