How to use the nova.api.openstack.extensions function in nova

To help you get started, we’ve selected a few nova examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / nova / nova / api / openstack / compute / legacy_v2 / contrib / agents.py View on Github external
try:
            agent_obj = objects.Agent(context=context)
            agent_obj.hypervisor = hypervisor
            agent_obj.os = os
            agent_obj.architecture = architecture
            agent_obj.version = version
            agent_obj.url = url
            agent_obj.md5hash = md5hash
            agent_obj.create()
            agent['agent_id'] = agent_obj.id
        except exception.AgentBuildExists as ex:
            raise webob.exc.HTTPConflict(explanation=ex.format_message())
        return {'agent': agent}


class Agents(extensions.ExtensionDescriptor):
    """Agents support."""

    name = "Agents"
    alias = "os-agents"
    namespace = "http://docs.openstack.org/compute/ext/agents/api/v2"
    updated = "2012-10-28T00:00:00Z"

    def get_resources(self):
        resources = []
        resource = extensions.ResourceExtension('os-agents',
                                                AgentController())
        resources.append(resource)
        return resources
github openstack / nova / nova / api / openstack / compute / legacy_v2 / contrib / cloudpipe.py View on Github external
from webob import exc

from nova.api.openstack import extensions
from nova.cloudpipe import pipelib
from nova import compute
from nova.compute import utils as compute_utils
from nova.compute import vm_states
from nova import exception
from nova.i18n import _
from nova import network
from nova import utils

CONF = cfg.CONF
CONF.import_opt('keys_path', 'nova.crypto')

authorize = extensions.extension_authorizer('compute', 'cloudpipe')


class CloudpipeController(object):
    """Handle creating and listing cloudpipe instances."""

    def __init__(self):
        self.compute_api = compute.API()
        self.network_api = network.API()
        self.cloudpipe = pipelib.CloudPipe()
        self.setup()

    def setup(self):
        """Ensure the keychains and folders exist."""
        # NOTE(vish): One of the drawbacks of doing this in the api is
        #             the keys will only be on the api node that launched
        #             the cloudpipe.
github openstack / nova / nova / api / openstack / compute / legacy_v2 / extensions.py View on Github external
#    under the License.

from oslo_log import log as logging

from nova.api.openstack import extensions as base_extensions
import nova.conf
from nova.i18n import _LW

STANDARD_EXTENSIONS = ('nova.api.openstack.compute.legacy_v2.contrib.' +
                       'standard_extensions')

CONF = nova.conf.CONF
LOG = logging.getLogger(__name__)


class ExtensionManager(base_extensions.ExtensionManager):
    def __init__(self):
        self.cls_list = CONF.osapi_compute_extension
        if (len(self.cls_list) > 0 and
                self.cls_list[0] != STANDARD_EXTENSIONS):
            LOG.warning(_LW('The extension configure options are deprecated. '
                            'In the near future you must run all of the API.'))
        self.extensions = {}
        self.sorted_ext_list = []
        self._load_extensions()
github openstack / nova / nova / api / openstack / compute / contrib / volumetypes.py View on Github external
#    License for the specific language governing permissions and limitations
#    under the License.

""" The volume type & volume types extra specs extension"""

from webob import exc

from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import db
from nova import exception
from nova.volume import volume_types


authorize = extensions.extension_authorizer('compute', 'volumetypes')


def make_voltype(elem):
    elem.set('id')
    elem.set('name')
    extra_specs = xmlutil.make_flat_dict('extra_specs', selector='extra_specs')
    elem.append(extra_specs)


class VolumeTypeTemplate(xmlutil.TemplateBuilder):
    def construct(self):
        root = xmlutil.TemplateElement('volume_type', selector='volume_type')
        make_voltype(root)
        return xmlutil.MasterTemplate(root, 1)
github openstack / nova / nova / api / openstack / volume / contrib / types_manage.py View on Github external
#    License for the specific language governing permissions and limitations
#    under the License.

"""The volume types manage extension."""

import webob

from nova.api.openstack import extensions
from nova.api.openstack.volume import types
from nova.api.openstack.volume.views import types as views_types
from nova.api.openstack import wsgi
from nova import exception
from nova.volume import volume_types


authorize = extensions.extension_authorizer('volume', 'types_manage')


class VolumeTypesManageController(wsgi.Controller):
    """ The volume types API controller for the OpenStack API """

    _view_builder_class = views_types.ViewBuilder

    @wsgi.action("create")
    @wsgi.serializers(xml=types.VolumeTypeTemplate)
    def _create(self, req, body):
        """Creates a new volume type."""
        context = req.environ['nova.context']
        authorize(context)

        if not self.is_valid_body(body, 'volume_type'):
            raise webob.exc.HTTPUnprocessableEntity()
github openstack / nova / nova / api / openstack / compute / contrib / evacuate.py View on Github external
raise exc.HTTPBadRequest(explanation=msg)
            self.compute_api.evacuate(context, instance, host,
                                      on_shared_storage, password)
        except exception.InstanceInvalidState as state_error:
            common.raise_http_conflict_for_instance_invalid_state(state_error,
                    'evacuate')
        except exception.InstanceNotFound as e:
            raise exc.HTTPNotFound(explanation=e.format_message())
        except exception.ComputeServiceInUse as e:
            raise exc.HTTPBadRequest(explanation=e.format_message())

        if password:
            return {'adminPass': password}


class Evacuate(extensions.ExtensionDescriptor):
    """Enables server evacuation."""

    name = "Evacuate"
    alias = "os-evacuate"
    namespace = "http://docs.openstack.org/compute/ext/evacuate/api/v2"
    updated = "2013-01-06T00:00:00Z"

    def get_controller_extensions(self):
        controller = Controller(self.ext_mgr)
        extension = extensions.ControllerExtension(self, 'servers', controller)
        return [extension]
github openstack / nova / nova / api / openstack / compute / legacy_v2 / contrib / instance_usage_audit_log.py View on Github external
import datetime

from oslo_config import cfg
import webob.exc

from nova.api.openstack import extensions
from nova import compute
from nova import context as nova_context
from nova.i18n import _
from nova import utils

CONF = cfg.CONF
CONF.import_opt('compute_topic', 'nova.compute.rpcapi')


authorize = extensions.extension_authorizer('compute',
                           'instance_usage_audit_log')


class InstanceUsageAuditLogController(object):
    def __init__(self):
        self.host_api = compute.HostAPI()

    def index(self, req):
        context = req.environ['nova.context']
        authorize(context)
        task_log = self._get_audit_task_logs(context)
        return {'instance_usage_audit_logs': task_log}

    def show(self, req, id):
        context = req.environ['nova.context']
        authorize(context)
github openstack / nova / nova / api / openstack / compute / plugins / v3 / images.py View on Github external
    @extensions.expected_errors((403, 404))
    @wsgi.response(204)
    def delete(self, req, id):
        """Delete an image, if allowed.

        :param req: `wsgi.Request` object
        :param id: Image identifier (integer)
        """
        context = req.environ['nova.context']
        try:
            self._image_api.delete(context, id)
        except exception.ImageNotFound:
            explanation = _("Image not found.")
            raise webob.exc.HTTPNotFound(explanation=explanation)
        except exception.ImageNotAuthorized:
            # The image service raises this exception on delete if glanceclient
            # raises HTTPForbidden.
github openstack / nova / nova / api / openstack / contrib / diskconfig.py View on Github external
def _image_extension_controller(self):
        resources = []
        metadata = {
            "attributes": {
                'managed_disk': ["image_id", "enabled"]}}

        body_serializers = {
            'application/xml': wsgi.XMLDictSerializer(metadata=metadata,
                                                      xmlns=wsgi.XMLNS_V11)}
        serializer = wsgi.ResponseSerializer(body_serializers, None)
        res = extensions.ResourceExtension(
            'os-disk-config',
            controller=ImageDiskConfigController(),
            collection_actions={'update': 'PUT'},
            parent=dict(member_name='image', collection_name='images'),
            serializer=serializer)
        return res