Added basic CRUD functionality around Host Aggregates

"Actions" on Host Aggregates not implemented.

Change-Id: I0f0de45989956c85659d53c585c4e3f33d42cd86
This commit is contained in:
Daniel Speichert 2018-10-10 10:08:26 -04:00
parent ec90fb6402
commit 5225369c5d
4 changed files with 160 additions and 0 deletions

View File

@ -10,6 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from openstack.compute.v2 import aggregate as _aggregate
from openstack.compute.v2 import availability_zone
from openstack.compute.v2 import extension
from openstack.compute.v2 import flavor as _flavor
@ -120,6 +121,72 @@ class Proxy(proxy.Proxy):
flv = _flavor.FlavorDetail if details else _flavor.Flavor
return self._list(flv, paginated=True, **query)
def aggregates(self):
"""Return a generator of aggregate
:returns: A generator of aggregate
:rtype: class: `~openstack.compute.v2.aggregate.Aggregate`
"""
aggregate = _aggregate.Aggregate
return self._list(aggregate, paginated=False)
def get_aggregate(self, aggregate):
"""Get a single host aggregate
:param image: The value can be the ID of an aggregate or a
:class:`~openstack.compute.v2.aggregate.Aggregate`
instance.
:returns: One :class:`~openstack.compute.v2.aggregate.Aggregate`
:raises: :class:`~openstack.exceptions.ResourceNotFound`
when no resource can be found.
"""
return self._get(_aggregate.Aggregate, aggregate)
def create_aggregate(self, **attrs):
"""Create a new host aggregate from attributes
:param dict attrs: Keyword arguments which will be used to create a
:class:`~openstack.compute.v2.aggregate.Aggregate`,
comprised of the properties on the Aggregate class.
:returns: The results of aggregate creation
:rtype: :class:`~openstack.compute.v2.aggregate.Aggregate`
"""
return self._create(_aggregate.Aggregate, **attrs)
def update_aggregate(self, aggregate, **attrs):
"""Update a host aggregate
:param server: Either the ID of a host aggregate or a
:class:`~openstack.compute.v2.aggregate.Aggregate`
instance.
:attrs kwargs: The attributes to update on the aggregate represented
by ``aggregate``.
:returns: The updated aggregate
:rtype: :class:`~openstack.compute.v2.aggregate.Aggregate`
"""
return self._update(_aggregate.Aggregate, aggregate, **attrs)
def delete_aggregate(self, aggregate, ignore_missing=True):
"""Delete a host aggregate
:param keypair: The value can be either the ID of an aggregate or a
:class:`~openstack.compute.v2.aggregate.Aggregate`
instance.
:param bool ignore_missing: When set to ``False``
:class:`~openstack.exceptions.ResourceNotFound` will be
raised when the aggregate does not exist.
When set to ``True``, no exception will be set when
attempting to delete a nonexistent aggregate.
:returns: ``None``
"""
self._delete(_aggregate.Aggregate, aggregate,
ignore_missing=ignore_missing)
def delete_image(self, image, ignore_missing=True):
"""Delete an image

View File

@ -0,0 +1,38 @@
# 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 import resource
class Aggregate(resource.Resource):
resource_key = 'aggregate'
resources_key = 'aggregates'
base_path = '/os-aggregates'
# capabilities
allow_create = True
allow_fetch = True
allow_delete = True
allow_list = True
# Properties
#: Availability zone of aggregate
availability_zone = resource.Body('availability_zone')
#: Deleted?
deleted = resource.Body('deleted')
#: Name of aggregate
name = resource.Body('name')
#: Hosts
hosts = resource.Body('hosts')
#: Metadata
metadata = resource.Body('metadata')

View File

@ -0,0 +1,50 @@
# 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.tests.unit import base
from openstack.compute.v2 import aggregate
EXAMPLE = {
"name": "m-family",
"availability_zone": None,
"deleted": False,
"created_at": "2018-07-06T14:58:16.000000",
"updated_at": None,
"hosts": ["oscomp-m001", "oscomp-m002", "oscomp-m003"],
"deleted_at": None,
"id": 4,
"metadata": {"type": "public", "family": "m-family"}
}
class TestAggregate(base.TestCase):
def test_basic(self):
sot = aggregate.Aggregate()
self.assertEqual('aggregate', sot.resource_key)
self.assertEqual('aggregates', sot.resources_key)
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_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = aggregate.Aggregate(**EXAMPLE)
self.assertEqual(EXAMPLE['name'], sot.name)
self.assertEqual(EXAMPLE['availability_zone'], sot.availability_zone)
self.assertEqual(EXAMPLE['deleted'], sot.deleted)
self.assertEqual(EXAMPLE['hosts'], sot.hosts)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertDictEqual(EXAMPLE['metadata'], sot.metadata)

View File

@ -0,0 +1,5 @@
---
features:
- |
Basic CRUD functionality was added on Host Aggregates. Actions are not
implemented yet (adding/removing hosts from Host Aggregates).