Use Resource layer for compute AZ and Aggregates
Change-Id: I72a02ade12667a797643998f1ee9d07a6889f369
This commit is contained in:
parent
38847204f9
commit
de03f4f53a
|
@ -138,19 +138,17 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
||||||
list could not be fetched.
|
list could not be fetched.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
data = proxy._json_response(
|
zones = self.compute.availability_zones()
|
||||||
self.compute.get('/os-availability-zone'))
|
ret = []
|
||||||
except exc.OpenStackCloudHTTPError:
|
for zone in zones:
|
||||||
|
if zone.state['available'] or unavailable:
|
||||||
|
ret.append(zone.name)
|
||||||
|
return ret
|
||||||
|
except exceptions.SDKException:
|
||||||
self.log.debug(
|
self.log.debug(
|
||||||
"Availability zone list could not be fetched",
|
"Availability zone list could not be fetched",
|
||||||
exc_info=True)
|
exc_info=True)
|
||||||
return []
|
return []
|
||||||
zones = self._get_and_munchify('availabilityZoneInfo', data)
|
|
||||||
ret = []
|
|
||||||
for zone in zones:
|
|
||||||
if zone['zoneState']['available'] or unavailable:
|
|
||||||
ret.append(zone['zoneName'])
|
|
||||||
return ret
|
|
||||||
|
|
||||||
@_utils.cache_on_arguments()
|
@_utils.cache_on_arguments()
|
||||||
def list_flavors(self, get_extra=False):
|
def list_flavors(self, get_extra=False):
|
||||||
|
@ -1619,16 +1617,13 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
||||||
aggregates = self.list_aggregates()
|
aggregates = self.list_aggregates()
|
||||||
return _utils._filter_list(aggregates, name_or_id, filters)
|
return _utils._filter_list(aggregates, name_or_id, filters)
|
||||||
|
|
||||||
def list_aggregates(self):
|
def list_aggregates(self, filters={}):
|
||||||
"""List all available host aggregates.
|
"""List all available host aggregates.
|
||||||
|
|
||||||
:returns: A list of aggregate dicts.
|
:returns: A list of aggregate dicts.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
data = proxy._json_response(
|
return self.compute.aggregates(allow_unknown_params=True, **filters)
|
||||||
self.compute.get('/os-aggregates'),
|
|
||||||
error_message="Error fetching aggregate list")
|
|
||||||
return self._get_and_munchify('aggregates', data)
|
|
||||||
|
|
||||||
def get_aggregate(self, name_or_id, filters=None):
|
def get_aggregate(self, name_or_id, filters=None):
|
||||||
"""Get an aggregate by name or ID.
|
"""Get an aggregate by name or ID.
|
||||||
|
@ -1661,16 +1656,10 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
||||||
|
|
||||||
:raises: OpenStackCloudException on operation error.
|
:raises: OpenStackCloudException on operation error.
|
||||||
"""
|
"""
|
||||||
data = proxy._json_response(
|
return self.compute.create_aggregate(
|
||||||
self.compute.post(
|
name=name,
|
||||||
'/os-aggregates',
|
availability_zone=availability_zone
|
||||||
json={'aggregate': {
|
)
|
||||||
'name': name,
|
|
||||||
'availability_zone': availability_zone
|
|
||||||
}}),
|
|
||||||
error_message="Unable to create host aggregate {name}".format(
|
|
||||||
name=name))
|
|
||||||
return self._get_and_munchify('aggregate', data)
|
|
||||||
|
|
||||||
@_utils.valid_kwargs('name', 'availability_zone')
|
@_utils.valid_kwargs('name', 'availability_zone')
|
||||||
def update_aggregate(self, name_or_id, **kwargs):
|
def update_aggregate(self, name_or_id, **kwargs):
|
||||||
|
@ -1685,17 +1674,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
||||||
:raises: OpenStackCloudException on operation error.
|
:raises: OpenStackCloudException on operation error.
|
||||||
"""
|
"""
|
||||||
aggregate = self.get_aggregate(name_or_id)
|
aggregate = self.get_aggregate(name_or_id)
|
||||||
if not aggregate:
|
return self.compute.update_aggregate(aggregate, **kwargs)
|
||||||
raise exc.OpenStackCloudException(
|
|
||||||
"Host aggregate %s not found." % name_or_id)
|
|
||||||
|
|
||||||
data = proxy._json_response(
|
|
||||||
self.compute.put(
|
|
||||||
'/os-aggregates/{id}'.format(id=aggregate['id']),
|
|
||||||
json={'aggregate': kwargs}),
|
|
||||||
error_message="Error updating aggregate {name}".format(
|
|
||||||
name=name_or_id))
|
|
||||||
return self._get_and_munchify('aggregate', data)
|
|
||||||
|
|
||||||
def delete_aggregate(self, name_or_id):
|
def delete_aggregate(self, name_or_id):
|
||||||
"""Delete a host aggregate.
|
"""Delete a host aggregate.
|
||||||
|
@ -1706,19 +1685,13 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
||||||
|
|
||||||
:raises: OpenStackCloudException on operation error.
|
:raises: OpenStackCloudException on operation error.
|
||||||
"""
|
"""
|
||||||
aggregate = self.get_aggregate(name_or_id)
|
try:
|
||||||
if not aggregate:
|
self.compute.delete_aggregate(name_or_id, ignore_missing=False)
|
||||||
|
return True
|
||||||
|
except exceptions.ResourceNotFound:
|
||||||
self.log.debug("Aggregate %s not found for deleting", name_or_id)
|
self.log.debug("Aggregate %s not found for deleting", name_or_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return proxy._json_response(
|
|
||||||
self.compute.delete(
|
|
||||||
'/os-aggregates/{id}'.format(id=aggregate['id'])),
|
|
||||||
error_message="Error deleting aggregate {name}".format(
|
|
||||||
name=name_or_id))
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def set_aggregate_metadata(self, name_or_id, metadata):
|
def set_aggregate_metadata(self, name_or_id, metadata):
|
||||||
"""Set aggregate metadata, replacing the existing metadata.
|
"""Set aggregate metadata, replacing the existing metadata.
|
||||||
|
|
||||||
|
@ -1735,15 +1708,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
||||||
raise exc.OpenStackCloudException(
|
raise exc.OpenStackCloudException(
|
||||||
"Host aggregate %s not found." % name_or_id)
|
"Host aggregate %s not found." % name_or_id)
|
||||||
|
|
||||||
err_msg = "Unable to set metadata for host aggregate {name}".format(
|
return self.compute.set_aggregate_metadata(aggregate, metadata)
|
||||||
name=name_or_id)
|
|
||||||
|
|
||||||
data = proxy._json_response(
|
|
||||||
self.compute.post(
|
|
||||||
'/os-aggregates/{id}/action'.format(id=aggregate['id']),
|
|
||||||
json={'set_metadata': {'metadata': metadata}}),
|
|
||||||
error_message=err_msg)
|
|
||||||
return self._get_and_munchify('aggregate', data)
|
|
||||||
|
|
||||||
def add_host_to_aggregate(self, name_or_id, host_name):
|
def add_host_to_aggregate(self, name_or_id, host_name):
|
||||||
"""Add a host to an aggregate.
|
"""Add a host to an aggregate.
|
||||||
|
@ -1758,14 +1723,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
||||||
raise exc.OpenStackCloudException(
|
raise exc.OpenStackCloudException(
|
||||||
"Host aggregate %s not found." % name_or_id)
|
"Host aggregate %s not found." % name_or_id)
|
||||||
|
|
||||||
err_msg = "Unable to add host {host} to aggregate {name}".format(
|
return self.compute.add_host_to_aggregate(aggregate, host_name)
|
||||||
host=host_name, name=name_or_id)
|
|
||||||
|
|
||||||
return proxy._json_response(
|
|
||||||
self.compute.post(
|
|
||||||
'/os-aggregates/{id}/action'.format(id=aggregate['id']),
|
|
||||||
json={'add_host': {'host': host_name}}),
|
|
||||||
error_message=err_msg)
|
|
||||||
|
|
||||||
def remove_host_from_aggregate(self, name_or_id, host_name):
|
def remove_host_from_aggregate(self, name_or_id, host_name):
|
||||||
"""Remove a host from an aggregate.
|
"""Remove a host from an aggregate.
|
||||||
|
@ -1780,14 +1738,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
||||||
raise exc.OpenStackCloudException(
|
raise exc.OpenStackCloudException(
|
||||||
"Host aggregate %s not found." % name_or_id)
|
"Host aggregate %s not found." % name_or_id)
|
||||||
|
|
||||||
err_msg = "Unable to remove host {host} to aggregate {name}".format(
|
return self.compute.remove_host_from_aggregate(aggregate, host_name)
|
||||||
host=host_name, name=name_or_id)
|
|
||||||
|
|
||||||
return proxy._json_response(
|
|
||||||
self.compute.post(
|
|
||||||
'/os-aggregates/{id}/action'.format(id=aggregate['id']),
|
|
||||||
json={'remove_host': {'host': host_name}}),
|
|
||||||
error_message=err_msg)
|
|
||||||
|
|
||||||
def set_compute_quotas(self, name_or_id, **kwargs):
|
def set_compute_quotas(self, name_or_id, **kwargs):
|
||||||
""" Set a quota in a project
|
""" Set a quota in a project
|
||||||
|
|
|
@ -122,15 +122,16 @@ class Proxy(proxy.Proxy):
|
||||||
flv = _flavor.FlavorDetail if details else _flavor.Flavor
|
flv = _flavor.FlavorDetail if details else _flavor.Flavor
|
||||||
return self._list(flv, **query)
|
return self._list(flv, **query)
|
||||||
|
|
||||||
def aggregates(self):
|
def aggregates(self, **query):
|
||||||
"""Return a generator of aggregate
|
"""Return a generator of aggregate
|
||||||
|
|
||||||
|
:param kwargs query: Optional query parameters to be sent to limit
|
||||||
|
the aggregates being returned.
|
||||||
|
|
||||||
:returns: A generator of aggregate
|
:returns: A generator of aggregate
|
||||||
:rtype: class: `~openstack.compute.v2.aggregate.Aggregate`
|
:rtype: class: `~openstack.compute.v2.aggregate.Aggregate`
|
||||||
"""
|
"""
|
||||||
aggregate = _aggregate.Aggregate
|
return self._list(_aggregate.Aggregate, **query)
|
||||||
|
|
||||||
return self._list(aggregate)
|
|
||||||
|
|
||||||
def get_aggregate(self, aggregate):
|
def get_aggregate(self, aggregate):
|
||||||
"""Get a single host aggregate
|
"""Get a single host aggregate
|
||||||
|
@ -1040,12 +1041,11 @@ class Proxy(proxy.Proxy):
|
||||||
:rtype: :class:`~openstack.compute.v2.availability_zone.\
|
:rtype: :class:`~openstack.compute.v2.availability_zone.\
|
||||||
AvailabilityZone`
|
AvailabilityZone`
|
||||||
"""
|
"""
|
||||||
if details:
|
base_path = '/os-availability-zone/detail' if details else None
|
||||||
az = availability_zone.AvailabilityZoneDetail
|
|
||||||
else:
|
|
||||||
az = availability_zone.AvailabilityZone
|
|
||||||
|
|
||||||
return self._list(az)
|
return self._list(
|
||||||
|
availability_zone.AvailabilityZone,
|
||||||
|
base_path=base_path)
|
||||||
|
|
||||||
def get_server_metadata(self, server):
|
def get_server_metadata(self, server):
|
||||||
"""Return a dictionary of metadata for a server
|
"""Return a dictionary of metadata for a server
|
||||||
|
|
|
@ -25,6 +25,7 @@ class Aggregate(resource.Resource):
|
||||||
allow_fetch = True
|
allow_fetch = True
|
||||||
allow_delete = True
|
allow_delete = True
|
||||||
allow_list = True
|
allow_list = True
|
||||||
|
allow_commit = True
|
||||||
|
|
||||||
# Properties
|
# Properties
|
||||||
#: Availability zone of aggregate
|
#: Availability zone of aggregate
|
||||||
|
|
|
@ -29,5 +29,4 @@ class AvailabilityZone(resource.Resource):
|
||||||
hosts = resource.Body('hosts')
|
hosts = resource.Body('hosts')
|
||||||
|
|
||||||
|
|
||||||
class AvailabilityZoneDetail(AvailabilityZone):
|
AvailabilityZoneDetail = AvailabilityZone
|
||||||
base_path = '/os-availability-zone/detail'
|
|
||||||
|
|
|
@ -69,10 +69,6 @@ class TestAggregate(base.TestCase):
|
||||||
|
|
||||||
def test_delete_aggregate(self):
|
def test_delete_aggregate(self):
|
||||||
self.register_uris([
|
self.register_uris([
|
||||||
dict(method='GET',
|
|
||||||
uri=self.get_mock_url(
|
|
||||||
'compute', 'public', append=['os-aggregates']),
|
|
||||||
json={'aggregates': [self.fake_aggregate]}),
|
|
||||||
dict(method='DELETE',
|
dict(method='DELETE',
|
||||||
uri=self.get_mock_url(
|
uri=self.get_mock_url(
|
||||||
'compute', 'public', append=['os-aggregates', '1'])),
|
'compute', 'public', append=['os-aggregates', '1'])),
|
||||||
|
|
|
@ -47,7 +47,7 @@ class TestAggregate(base.TestCase):
|
||||||
self.assertEqual('/os-aggregates', sot.base_path)
|
self.assertEqual('/os-aggregates', sot.base_path)
|
||||||
self.assertTrue(sot.allow_create)
|
self.assertTrue(sot.allow_create)
|
||||||
self.assertTrue(sot.allow_fetch)
|
self.assertTrue(sot.allow_fetch)
|
||||||
self.assertFalse(sot.allow_commit)
|
self.assertTrue(sot.allow_commit)
|
||||||
self.assertTrue(sot.allow_delete)
|
self.assertTrue(sot.allow_delete)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
|
|
||||||
|
|
|
@ -31,12 +31,6 @@ class TestAvailabilityZone(base.TestCase):
|
||||||
self.assertEqual('/os-availability-zone', sot.base_path)
|
self.assertEqual('/os-availability-zone', sot.base_path)
|
||||||
self.assertTrue(sot.allow_list)
|
self.assertTrue(sot.allow_list)
|
||||||
|
|
||||||
def test_basic_detail(self):
|
|
||||||
sot = az.AvailabilityZoneDetail()
|
|
||||||
self.assertEqual('availabilityZoneInfo', sot.resources_key)
|
|
||||||
self.assertEqual('/os-availability-zone/detail', sot.base_path)
|
|
||||||
self.assertTrue(sot.allow_list)
|
|
||||||
|
|
||||||
def test_make_basic(self):
|
def test_make_basic(self):
|
||||||
sot = az.AvailabilityZone(**BASIC_EXAMPLE)
|
sot = az.AvailabilityZone(**BASIC_EXAMPLE)
|
||||||
self.assertEqual(BASIC_EXAMPLE['id'], sot.id)
|
self.assertEqual(BASIC_EXAMPLE['id'], sot.id)
|
||||||
|
|
Loading…
Reference in New Issue