1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
# 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 exceptions
from openstack import resource
from openstack import utils
class ResourceProvider(resource.Resource):
resource_key = None
resources_key = 'resource_providers'
base_path = '/resource_providers'
# Capabilities
allow_create = True
allow_fetch = True
allow_commit = True
allow_delete = True
allow_list = True
# Filters
_query_mapping = resource.QueryParameters(
'name',
'member_of',
'resources',
'in_tree',
'required',
id='uuid',
)
# The parent_provider_uuid and root_provider_uuid fields were introduced in
# 1.14
# The required query parameter was added in 1.18
# The create operation started returning a body in 1.20
_max_microversion = '1.20'
# Properties
#: Aggregates
aggregates = resource.Body('aggregates', type=list, list_type=str)
#: The UUID of a resource provider.
id = resource.Body('uuid', alternate_id=True)
#: A consistent view marker that assists with the management of concurrent
#: resource provider updates.
generation = resource.Body('generation')
#: Links pertaining to this flavor. This is a list of dictionaries,
#: each including keys ``href`` and ``rel``.
links = resource.Body('links')
#: The name of this resource provider.
name = resource.Body('name')
#: The UUID of the immediate parent of the resource provider.
parent_provider_id = resource.Body('parent_provider_uuid')
#: Read-only UUID of the top-most provider in this provider tree.
root_provider_id = resource.Body('root_provider_uuid')
def fetch_aggregates(self, session):
"""List aggregates set on the resource provider
:param session: The session to use for making this request
:return: The resource provider with aggregates populated
"""
url = utils.urljoin(self.base_path, self.id, 'aggregates')
microversion = self._get_microversion(session, action='fetch')
response = session.get(url, microversion=microversion)
exceptions.raise_from_response(response)
data = response.json()
updates = {'aggregates': data['aggregates']}
if utils.supports_microversion(session, '1.19'):
updates['generation'] = data['resource_provider_generation']
self._body.attributes.update(updates)
return self
def set_aggregates(self, session, aggregates=None):
"""Replaces aggregates on the resource provider
:param session: The session to use for making this request
:param list aggregates: List of aggregates
:return: The resource provider with updated aggregates populated
"""
url = utils.urljoin(self.base_path, self.id, 'aggregates')
microversion = self._get_microversion(session, action='commit')
body = {
'aggregates': aggregates or [],
}
if utils.supports_microversion(session, '1.19'):
body['resource_provider_generation'] = self.generation
response = session.put(url, json=body, microversion=microversion)
exceptions.raise_from_response(response)
data = response.json()
updates = {'aggregates': data['aggregates']}
if 'resource_provider_generation' in data:
updates['resource_provider_generation'] = data[
'resource_provider_generation'
]
self._body.attributes.update(updates)
return self
|