Merge "Use Resource layer for compute AZ and Aggregates"
This commit is contained in:
commit
790fc14099
|
@ -143,19 +143,17 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
|||
list could not be fetched.
|
||||
"""
|
||||
try:
|
||||
data = proxy._json_response(
|
||||
self.compute.get('/os-availability-zone'))
|
||||
except exc.OpenStackCloudHTTPError:
|
||||
zones = self.compute.availability_zones()
|
||||
ret = []
|
||||
for zone in zones:
|
||||
if zone.state['available'] or unavailable:
|
||||
ret.append(zone.name)
|
||||
return ret
|
||||
except exceptions.SDKException:
|
||||
self.log.debug(
|
||||
"Availability zone list could not be fetched",
|
||||
exc_info=True)
|
||||
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()
|
||||
def list_flavors(self, get_extra=False):
|
||||
|
@ -1624,16 +1622,13 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
|||
aggregates = self.list_aggregates()
|
||||
return _utils._filter_list(aggregates, name_or_id, filters)
|
||||
|
||||
def list_aggregates(self):
|
||||
def list_aggregates(self, filters={}):
|
||||
"""List all available host aggregates.
|
||||
|
||||
:returns: A list of aggregate dicts.
|
||||
|
||||
"""
|
||||
data = proxy._json_response(
|
||||
self.compute.get('/os-aggregates'),
|
||||
error_message="Error fetching aggregate list")
|
||||
return self._get_and_munchify('aggregates', data)
|
||||
return self.compute.aggregates(allow_unknown_params=True, **filters)
|
||||
|
||||
def get_aggregate(self, name_or_id, filters=None):
|
||||
"""Get an aggregate by name or ID.
|
||||
|
@ -1666,16 +1661,10 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
|||
|
||||
:raises: OpenStackCloudException on operation error.
|
||||
"""
|
||||
data = proxy._json_response(
|
||||
self.compute.post(
|
||||
'/os-aggregates',
|
||||
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)
|
||||
return self.compute.create_aggregate(
|
||||
name=name,
|
||||
availability_zone=availability_zone
|
||||
)
|
||||
|
||||
@_utils.valid_kwargs('name', 'availability_zone')
|
||||
def update_aggregate(self, name_or_id, **kwargs):
|
||||
|
@ -1690,17 +1679,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
|||
:raises: OpenStackCloudException on operation error.
|
||||
"""
|
||||
aggregate = self.get_aggregate(name_or_id)
|
||||
if not aggregate:
|
||||
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)
|
||||
return self.compute.update_aggregate(aggregate, **kwargs)
|
||||
|
||||
def delete_aggregate(self, name_or_id):
|
||||
"""Delete a host aggregate.
|
||||
|
@ -1711,19 +1690,13 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
|||
|
||||
:raises: OpenStackCloudException on operation error.
|
||||
"""
|
||||
aggregate = self.get_aggregate(name_or_id)
|
||||
if not aggregate:
|
||||
try:
|
||||
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)
|
||||
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):
|
||||
"""Set aggregate metadata, replacing the existing metadata.
|
||||
|
||||
|
@ -1740,15 +1713,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
|||
raise exc.OpenStackCloudException(
|
||||
"Host aggregate %s not found." % name_or_id)
|
||||
|
||||
err_msg = "Unable to set metadata for host aggregate {name}".format(
|
||||
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)
|
||||
return self.compute.set_aggregate_metadata(aggregate, metadata)
|
||||
|
||||
def add_host_to_aggregate(self, name_or_id, host_name):
|
||||
"""Add a host to an aggregate.
|
||||
|
@ -1763,14 +1728,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
|||
raise exc.OpenStackCloudException(
|
||||
"Host aggregate %s not found." % name_or_id)
|
||||
|
||||
err_msg = "Unable to add host {host} to aggregate {name}".format(
|
||||
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)
|
||||
return self.compute.add_host_to_aggregate(aggregate, host_name)
|
||||
|
||||
def remove_host_from_aggregate(self, name_or_id, host_name):
|
||||
"""Remove a host from an aggregate.
|
||||
|
@ -1785,14 +1743,7 @@ class ComputeCloudMixin(_normalize.Normalizer):
|
|||
raise exc.OpenStackCloudException(
|
||||
"Host aggregate %s not found." % name_or_id)
|
||||
|
||||
err_msg = "Unable to remove host {host} to aggregate {name}".format(
|
||||
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)
|
||||
return self.compute.remove_host_from_aggregate(aggregate, host_name)
|
||||
|
||||
def set_compute_quotas(self, name_or_id, **kwargs):
|
||||
""" Set a quota in a project
|
||||
|
|
|
@ -122,15 +122,16 @@ class Proxy(proxy.Proxy):
|
|||
flv = _flavor.FlavorDetail if details else _flavor.Flavor
|
||||
return self._list(flv, **query)
|
||||
|
||||
def aggregates(self):
|
||||
def aggregates(self, **query):
|
||||
"""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
|
||||
:rtype: class: `~openstack.compute.v2.aggregate.Aggregate`
|
||||
"""
|
||||
aggregate = _aggregate.Aggregate
|
||||
|
||||
return self._list(aggregate)
|
||||
return self._list(_aggregate.Aggregate, **query)
|
||||
|
||||
def get_aggregate(self, aggregate):
|
||||
"""Get a single host aggregate
|
||||
|
@ -1040,12 +1041,11 @@ class Proxy(proxy.Proxy):
|
|||
:rtype: :class:`~openstack.compute.v2.availability_zone.\
|
||||
AvailabilityZone`
|
||||
"""
|
||||
if details:
|
||||
az = availability_zone.AvailabilityZoneDetail
|
||||
else:
|
||||
az = availability_zone.AvailabilityZone
|
||||
base_path = '/os-availability-zone/detail' if details else None
|
||||
|
||||
return self._list(az)
|
||||
return self._list(
|
||||
availability_zone.AvailabilityZone,
|
||||
base_path=base_path)
|
||||
|
||||
def get_server_metadata(self, server):
|
||||
"""Return a dictionary of metadata for a server
|
||||
|
|
|
@ -25,6 +25,7 @@ class Aggregate(resource.Resource):
|
|||
allow_fetch = True
|
||||
allow_delete = True
|
||||
allow_list = True
|
||||
allow_commit = True
|
||||
|
||||
# Properties
|
||||
#: Availability zone of aggregate
|
||||
|
|
|
@ -29,5 +29,4 @@ class AvailabilityZone(resource.Resource):
|
|||
hosts = resource.Body('hosts')
|
||||
|
||||
|
||||
class AvailabilityZoneDetail(AvailabilityZone):
|
||||
base_path = '/os-availability-zone/detail'
|
||||
AvailabilityZoneDetail = AvailabilityZone
|
||||
|
|
|
@ -69,10 +69,6 @@ class TestAggregate(base.TestCase):
|
|||
|
||||
def test_delete_aggregate(self):
|
||||
self.register_uris([
|
||||
dict(method='GET',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public', append=['os-aggregates']),
|
||||
json={'aggregates': [self.fake_aggregate]}),
|
||||
dict(method='DELETE',
|
||||
uri=self.get_mock_url(
|
||||
'compute', 'public', append=['os-aggregates', '1'])),
|
||||
|
|
|
@ -47,7 +47,7 @@ class TestAggregate(base.TestCase):
|
|||
self.assertEqual('/os-aggregates', sot.base_path)
|
||||
self.assertTrue(sot.allow_create)
|
||||
self.assertTrue(sot.allow_fetch)
|
||||
self.assertFalse(sot.allow_commit)
|
||||
self.assertTrue(sot.allow_commit)
|
||||
self.assertTrue(sot.allow_delete)
|
||||
self.assertTrue(sot.allow_list)
|
||||
|
||||
|
|
|
@ -31,12 +31,6 @@ class TestAvailabilityZone(base.TestCase):
|
|||
self.assertEqual('/os-availability-zone', sot.base_path)
|
||||
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):
|
||||
sot = az.AvailabilityZone(**BASIC_EXAMPLE)
|
||||
self.assertEqual(BASIC_EXAMPLE['id'], sot.id)
|
||||
|
|
Loading…
Reference in New Issue