This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change splits api.py into multiple files for easier readability and modification. Much of the Overcloud-equivalent code in tuskar.py will later be refactored into heat.py once the api is updated to differentiate between a plan and a stack. Change-Id: Ie61a86125cf4dc8c8022f95e91fe0faccbf0af56
- Loading branch information
Showing
32 changed files
with
2,133 additions
and
1,882 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 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 tuskar_ui.api import flavor | ||
from tuskar_ui.api import heat | ||
from tuskar_ui.api import node | ||
from tuskar_ui.api import tuskar | ||
|
||
|
||
__all__ = [ | ||
"flavor", | ||
"heat", | ||
"node", | ||
"tuskar", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# 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 logging | ||
|
||
from django.utils.translation import ugettext_lazy as _ | ||
from horizon.utils import memoized | ||
from openstack_dashboard.api import nova | ||
|
||
from tuskar_ui.api import tuskar | ||
from tuskar_ui.cached_property import cached_property # noqa | ||
from tuskar_ui.handle_errors import handle_errors # noqa | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class Flavor(object): | ||
|
||
def __init__(self, flavor): | ||
"""Construct by wrapping Nova flavor | ||
:param flavor: Nova flavor | ||
:type flavor: novaclient.v1_1.flavors.Flavor | ||
""" | ||
self._flavor = flavor | ||
|
||
def __getattr__(self, name): | ||
return getattr(self._flavor, name) | ||
|
||
@property | ||
def ram_bytes(self): | ||
"""Get RAM size in bytes | ||
Default RAM size is in MB. | ||
""" | ||
return self.ram * 1024 * 1024 | ||
|
||
@property | ||
def disk_bytes(self): | ||
"""Get disk size in bytes | ||
Default disk size is in GB. | ||
""" | ||
return self.disk * 1024 * 1024 * 1024 | ||
|
||
@cached_property | ||
def extras_dict(self): | ||
"""Return extra flavor parameters | ||
:return: Nova flavor keys | ||
:rtype: dict | ||
""" | ||
return self._flavor.get_keys() | ||
|
||
@property | ||
def cpu_arch(self): | ||
return self.extras_dict.get('cpu_arch', '') | ||
|
||
@property | ||
def kernel_image_id(self): | ||
return self.extras_dict.get('baremetal:deploy_kernel_id', '') | ||
|
||
@property | ||
def ramdisk_image_id(self): | ||
return self.extras_dict.get('baremetal:deploy_ramdisk_id', '') | ||
|
||
@classmethod | ||
def create(cls, request, name, memory, vcpus, disk, cpu_arch, | ||
kernel_image_id, ramdisk_image_id): | ||
extras_dict = {'cpu_arch': cpu_arch, | ||
'baremetal:deploy_kernel_id': kernel_image_id, | ||
'baremetal:deploy_ramdisk_id': ramdisk_image_id} | ||
return cls(nova.flavor_create(request, name, memory, vcpus, disk, | ||
metadata=extras_dict)) | ||
|
||
@classmethod | ||
@handle_errors(_("Unable to load flavor.")) | ||
def get(cls, request, flavor_id): | ||
return cls(nova.flavor_get(request, flavor_id)) | ||
|
||
@classmethod | ||
@handle_errors(_("Unable to retrieve flavor list."), []) | ||
def list(cls, request): | ||
return [cls(item) for item in nova.flavor_list(request)] | ||
|
||
@classmethod | ||
@memoized.memoized | ||
@handle_errors(_("Unable to retrieve existing servers list."), []) | ||
def list_deployed_ids(cls, request): | ||
"""Get and memoize ID's of deployed flavors.""" | ||
servers = nova.server_list(request)[0] | ||
deployed_ids = set(server.flavor['id'] for server in servers) | ||
roles = tuskar.OvercloudRole.list(request) | ||
deployed_ids |= set(role.flavor_id for role in roles) | ||
return deployed_ids |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# 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 logging | ||
|
||
from openstack_dashboard.api import base | ||
from openstack_dashboard.api import heat | ||
|
||
from tuskar_ui.api import node | ||
from tuskar_ui.cached_property import cached_property # noqa | ||
from tuskar_ui.handle_errors import handle_errors # noqa | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class Resource(base.APIResourceWrapper): | ||
_attrs = ('resource_name', 'resource_type', 'resource_status', | ||
'physical_resource_id') | ||
|
||
def __init__(self, apiresource, request=None, **kwargs): | ||
"""Initialize a resource | ||
:param apiresource: apiresource we want to wrap | ||
:type apiresource: heatclient.v1.resources.Resource | ||
:param request: request | ||
:type request: django.core.handlers.wsgi.WSGIRequest | ||
:param node: node relation we want to cache | ||
:type node: tuskar_ui.api.Node | ||
:return: Resource object | ||
:rtype: Resource | ||
""" | ||
super(Resource, self).__init__(apiresource) | ||
self._request = request | ||
if 'node' in kwargs: | ||
self._node = kwargs['node'] | ||
|
||
@classmethod | ||
def get(cls, request, overcloud, resource_name): | ||
"""Return the specified Heat Resource within an Overcloud | ||
:param request: request object | ||
:type request: django.http.HttpRequest | ||
:param overcloud: the Overcloud from which to retrieve the resource | ||
:type overcloud: tuskar_ui.api.Overcloud | ||
:param resource_name: name of the Resource to retrieve | ||
:type resource_name: str | ||
:return: matching Resource, or None if no Resource in the Overcloud | ||
stack matches the resource name | ||
:rtype: tuskar_ui.api.Resource | ||
""" | ||
resource = heat.resource_get(overcloud.stack.id, | ||
resource_name) | ||
return cls(resource, request=request) | ||
|
||
@cached_property | ||
def node(self): | ||
"""Return the Ironic Node associated with this Resource | ||
:return: Ironic Node associated with this Resource, or None if no | ||
Node is associated | ||
:rtype: tuskar_ui.api.Node | ||
:raises: ironicclient.exc.HTTPNotFound if there is no Node with the | ||
matching instance UUID | ||
""" | ||
if hasattr(self, '_node'): | ||
return self._node | ||
if self.physical_resource_id: | ||
return node.Node.get_by_instance_uuid(self._request, | ||
self.physical_resource_id) | ||
return None |
Oops, something went wrong.