示例#1
0
    def __init__(self, *args, **kwargs):
        self.vms_conn = kwargs.pop('vmsconn', None)

        self._init_vms()
        self.network_api = network.API()
        self.gridcentric_api = API()
        self.compute_manager = compute_manager.ComputeManager()

        # Use an eventlet green thread condition lock instead of the regular threading module. This
        # is required for eventlet threads because they essentially run on a single system thread.
        # All of the green threads will share the same base lock, defeating the point of using the
        # it. Since the main threading module is not monkey patched we cannot use it directly.
        self.cond = gthreading.Condition()
        self.locked_instances = {}
        super(GridCentricManager, self).__init__(service_name="gridcentric",
                                                 *args,
                                                 **kwargs)
示例#2
0
 def __init__(self):
     super(GridcentricServerControllerExtension, self).__init__()
     self.gridcentric_api = API()
     # Add the gridcentric-specific states to the state map
     common._STATE_MAP['blessed'] = {'default': 'BLESSED'}
示例#3
0
class GridcentricServerControllerExtension(wsgi.Controller):
    """
    The OpenStack Extension definition for the Gridcentric capabilities. Currently this includes:

        * Bless an existing virtual machine (creates a new server snapshot
          of the virtual machine and enables the user to launch new copies
          nearly instantaneously).

        * Launch new virtual machines from a blessed copy above.

        * Discard blessed VMs.
    """

    _view_builder_class = views_servers.ViewBuilder

    def __init__(self):
        super(GridcentricServerControllerExtension, self).__init__()
        self.gridcentric_api = API()
        # Add the gridcentric-specific states to the state map
        common._STATE_MAP['blessed'] = {'default': 'BLESSED'}

    @wsgi.action('gc_bless')
    @convert_exception
    def _bless_instance(self, req, id, body):
        context = req.environ["nova.context"]
        result = self.gridcentric_api.bless_instance(context, id)
        return self._build_instance_list(req, [result])

    @wsgi.action('gc_discard')
    @convert_exception
    def _discard_instance(self, req, id, body):
        context = req.environ["nova.context"]
        result = self.gridcentric_api.discard_instance(context, id)
        return webob.Response(status_int=200, body=json.dumps(result))

    @wsgi.action('gc_launch')
    @convert_exception
    def _launch_instance(self, req, id, body):
        context = req.environ["nova.context"]
        try:
            params = body.get('gc_launch', {})
            result = self.gridcentric_api.launch_instance(context,
                                                          id,
                                                          params=params)
            return self._build_instance_list(req, [result])
        except novaexc.QuotaError as error:
            self._handle_quota_error(error)

    @wsgi.action('gc_migrate')
    @convert_exception
    def _migrate_instance(self, req, id, body):
        context = req.environ["nova.context"]
        try:
            dest = body['gc_migrate'].get('dest', None)
            self.gridcentric_api.migrate_instance(context, id, dest)
            return webob.Response(status_int=200)
        except novaexc.QuotaError as error:
            self._handle_quota_error(error)

    @wsgi.action('gc_list_launched')
    @convert_exception
    def _list_launched_instances(self, req, id, body):
        context = req.environ["nova.context"]
        return self._build_instance_list(
            req, self.gridcentric_api.list_launched_instances(context, id))

    @wsgi.action('gc_list_blessed')
    @convert_exception
    def _list_blessed_instances(self, req, id, body):
        context = req.environ["nova.context"]
        return self._build_instance_list(
            req, self.gridcentric_api.list_blessed_instances(context, id))

    @wsgi.extends
    @convert_exception
    def delete(self, req, resp_obj, **kwargs):
        """ We want to raise an error to the user if they attempt to delete a blessed instance. """
        context = req.environ["nova.context"]
        instance_uuid = kwargs.get("id", None)
        if instance_uuid != None:
            self.gridcentric_api.check_delete(context, instance_uuid)

    def _build_instance_list(self, req, instances):
        def _build_view(req, instance, is_detail=True):
            project_id = getattr(req.environ['nova.context'], 'project_id', '')
            base_url = req.application_url
            flavor_builder = nova.api.openstack.views.flavors.ViewBuilderV11(
                base_url, project_id)
            image_builder = nova.api.openstack.views.images.ViewBuilderV11(
                base_url, project_id)
            addresses_builder = nova.api.openstack.views.addresses.ViewBuilderV11(
            )
            builder = nova.api.openstack.views.servers.ViewBuilderV11(
                addresses_builder, flavor_builder, image_builder, base_url,
                project_id)
            return builder.build(instance, is_detail=is_detail)

        instances = self._view_builder.detail(req, instances)['servers']
        return webob.Response(status_int=200, body=json.dumps(instances))

    ## Utility methods taken from nova core ##
    def _handle_quota_error(self, error):
        """
        Reraise quota errors as api-specific http exceptions
        """

        code_mappings = {
            "OnsetFileLimitExceeded": _("Personality file limit exceeded"),
            "OnsetFilePathLimitExceeded": _("Personality file path too long"),
            "OnsetFileContentLimitExceeded":
            _("Personality file content too long"),

            # NOTE(bcwaldon): expose the message generated below in order
            # to better explain how the quota was exceeded
            "InstanceLimitExceeded": error.message,
        }

        code = error.kwargs['code']
        expl = code_mappings.get(code, error.message) % error.kwargs
        raise webob.exc.HTTPRequestEntityTooLarge(explanation=expl,
                                                  headers={'Retry-After': 0})
示例#4
0
 def __init__(self):
     self.nova_servers = servers.Controller()
     self.nova_servers.compute_api = API()
 def __init__(self):
     super(GridcentricServerControllerExtension, self).__init__()
     self.gridcentric_api = API()
     # Add the gridcentric-specific states to the state map
     common._STATE_MAP['blessed'] = {'default': 'BLESSED'}
class GridcentricServerControllerExtension(wsgi.Controller):
    """
    The OpenStack Extension definition for the Gridcentric capabilities. Currently this includes:

        * Bless an existing virtual machine (creates a new server snapshot
          of the virtual machine and enables the user to launch new copies
          nearly instantaneously).

        * Launch new virtual machines from a blessed copy above.

        * Discard blessed VMs.
    """

    _view_builder_class = views_servers.ViewBuilder

    def __init__(self):
        super(GridcentricServerControllerExtension, self).__init__()
        self.gridcentric_api = API()
        # Add the gridcentric-specific states to the state map
        common._STATE_MAP['blessed'] = {'default': 'BLESSED'}

    @wsgi.action('gc_bless')
    @convert_exception
    def _bless_instance(self, req, id, body):
        context = req.environ["nova.context"]
        result = self.gridcentric_api.bless_instance(context, id)
        return self._build_instance_list(req, [result])

    @wsgi.action('gc_discard')
    @convert_exception
    def _discard_instance(self, req, id, body):
        context = req.environ["nova.context"]
        result = self.gridcentric_api.discard_instance(context, id)
        return webob.Response(status_int=200, body=json.dumps(result))

    @wsgi.action('gc_launch')
    @convert_exception
    def _launch_instance(self, req, id, body):
        context = req.environ["nova.context"]
        try:
            params = body.get('gc_launch', {})
            result = self.gridcentric_api.launch_instance(context, id,
                                                          params=params)
            return self._build_instance_list(req, [result])
        except novaexc.QuotaError as error:
            self._handle_quota_error(error)

    @wsgi.action('gc_migrate')
    @convert_exception
    def _migrate_instance(self, req, id, body):
        context = req.environ["nova.context"]
        try:
            dest = body['gc_migrate']['dest']
        except:
            return webob.Response(status_int=401, body='Invalid destination')
        try:
            self.gridcentric_api.migrate_instance(context, id, dest)
            return webob.Response(status_int=200)
        except novaexc.QuotaError as error:
            self._handle_quota_error(error)

    @wsgi.action('gc_list_launched')
    @convert_exception
    def _list_launched_instances(self, req, id, body):
        context = req.environ["nova.context"]
        return self._build_instance_list(req, self.gridcentric_api.list_launched_instances(context, id))

    @wsgi.action('gc_list_blessed')
    @convert_exception
    def _list_blessed_instances(self, req, id, body):
        context = req.environ["nova.context"]
        return self._build_instance_list(req, self.gridcentric_api.list_blessed_instances(context, id))

    def _build_instance_list(self, req, instances):
        def _build_view(req, instance, is_detail=True):
            project_id = getattr(req.environ['nova.context'], 'project_id', '')
            base_url = req.application_url
            flavor_builder = nova.api.openstack.views.flavors.ViewBuilderV11(
                base_url, project_id)
            image_builder = nova.api.openstack.views.images.ViewBuilderV11(
                base_url, project_id)
            addresses_builder = nova.api.openstack.views.addresses.ViewBuilderV11()
            builder = nova.api.openstack.views.servers.ViewBuilderV11(
                addresses_builder, flavor_builder, image_builder,
                base_url, project_id)
            return builder.build(instance, is_detail=is_detail)
        instances = self._view_builder.detail(req, instances)['servers']
        return webob.Response(status_int=200, body=json.dumps(instances))

    ## Utility methods taken from nova core ##
    def _handle_quota_error(self, error):
        """
        Reraise quota errors as api-specific http exceptions
        """

        code_mappings = {
            "OnsetFileLimitExceeded":
                    _("Personality file limit exceeded"),
            "OnsetFilePathLimitExceeded":
                    _("Personality file path too long"),
            "OnsetFileContentLimitExceeded":
                    _("Personality file content too long"),

            # NOTE(bcwaldon): expose the message generated below in order
            # to better explain how the quota was exceeded
            "InstanceLimitExceeded": error.message,
        }

        code = error.kwargs['code']
        expl = code_mappings.get(code, error.message) % error.kwargs
        raise webob.exc.HTTPRequestEntityTooLarge(explanation=expl,
                                            headers={'Retry-After': 0})