示例#1
0
class CobaltPolicyController(wsgi.Controller):
    def __init__(self):
        super(CobaltPolicyController, self).__init__()
        self.gridcentric_api = API()

    @convert_exception
    def create(self, req, body):
        context = req.environ["nova.context"]
        self.gridcentric_api.install_policy(context,
            body.get('policy_ini_string'), body.get('wait'))
示例#2
0
class CobaltPolicyController(wsgi.Controller):
    def __init__(self):
        super(CobaltPolicyController, self).__init__()
        self.gridcentric_api = API()

    @convert_exception
    def create(self, req, body):
        context = req.environ["nova.context"]
        self.gridcentric_api.install_policy(context,
            body.get('policy_ini_string'), body.get('wait'))
示例#3
0
class CobaltInfoController(object):

    def __init__(self):
        self.cobalt_api = API()

    @convert_exception
    @authorize
    def index(self, req):
        context = req.environ['nova.context']
        return webob.Response(status_int=200,
            body=json.dumps(self.cobalt_api.get_info()))
示例#4
0
class CobaltInfoController(object):

    def __init__(self):
        self.cobalt_api = API()

    @convert_exception
    @authorize
    def index(self, req):
        context = req.environ['nova.context']
        return webob.Response(status_int=200,
            body=json.dumps(self.cobalt_api.get_info()))
示例#5
0
class CobaltImportController(wsgi.Controller):

    _view_builder_class = views_servers.ViewBuilder

    def __init__(self):
        super(CobaltImportController, self).__init__()
        self.cobalt_api = API()

    @convert_exception
    @authorize
    def create(self, req, body):
        context = req.environ["nova.context"]

        data = body.get('data')

        instance = self.cobalt_api.import_blessed_instance(context, data)
        view = self._view_builder.create(req, instance)
        return wsgi.ResponseObject(view)
示例#6
0
class CobaltImportController(wsgi.Controller):

    _view_builder_class = views_servers.ViewBuilder

    def __init__(self):
        super(CobaltImportController, self).__init__()
        self.cobalt_api = API()

    @convert_exception
    @authorize
    def create(self, req, body):
        context = req.environ["nova.context"]

        data = body.get('data')

        instance = self.cobalt_api.import_blessed_instance(context, data)
        view = self._view_builder.create(req, instance)
        return wsgi.ResponseObject(view)
示例#7
0
 def __init__(self):
     self.cobalt_api = API()
示例#8
0
 def __init__(self):
     super(CobaltImportController, self).__init__()
     self.cobalt_api = API()
示例#9
0
 def __init__(self):
     super(CobaltPolicyController, self).__init__()
     self.gridcentric_api = API()
示例#10
0
 def __init__(self):
     super(CobaltPolicyController, self).__init__()
     self.gridcentric_api = API()
示例#11
0
 def __init__(self):
     super(CobaltServerControllerExtension, self).__init__()
     self.cobalt_api = API()
     # Add the gridcentric-specific states to the state map
     common._STATE_MAP['blessed'] = {'default': 'BLESSED'}
示例#12
0
class CobaltServerControllerExtension(wsgi.Controller):
    """
    The OpenStack Extension definition for Cobalt 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(CobaltServerControllerExtension, self).__init__()
        self.cobalt_api = API()
        # Add the gridcentric-specific states to the state map
        common._STATE_MAP['blessed'] = {'default': 'BLESSED'}

    @wsgi.action('co_bless')
    @convert_exception
    @authorize
    def _bless_instance(self, req, id, body):
        context = req.environ["nova.context"]
        params = body.get('co_bless', body.get('gc_bless', {}))
        result = self.cobalt_api.bless_instance(context, id, params=params)
        return self._build_instance_list(req, [result])

    @wsgi.action('gc_bless')
    def _dep_bless_instance(self, req, id, body):
        return self._bless_instance(req=req, id=id, body=body)

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

    @wsgi.action('gc_discard')
    def _dep_discard_instance(self, req, id, body):
        return self._discard_instance(req=req, id=id, body=body)

    @wsgi.action('co_launch')
    @convert_exception
    @authorize
    def _launch_instance(self, req, id, body):
        context = req.environ["nova.context"]
        try:
            params = body.get('co_launch', body.get('gc_launch', {}))
            result = self.cobalt_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_launch')
    def _dep_launch_instance(self, req, id, body):
        return self._launch_instance(req=req, id=id, body=body)

    @wsgi.action('co_migrate')
    @convert_exception
    @authorize
    def _migrate_instance(self, req, id, body):
        context = req.environ["nova.context"]
        try:
            migrate_data = body.get('co_migrate', body.get('gc_migrate', {}))
            dest = migrate_data.get('dest', None)
            self.cobalt_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_migrate')
    def _dep_migrate_instance(self, req, id, body):
        return self._migrate_instance(req=req, id=id, body=body)

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

    @wsgi.action('gc_list_launched')
    def _dep_list_launched_instances(self, req, id, body):
        return self._list_launched_instances(req=req, id=id, body=body)

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

    @wsgi.action('gc_list_blessed')
    def _dep_list_blessed_instances(self, req, id, body):
        return self._list_blessed_instances(req=req, id=id, body=body)

    @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.cobalt_api.check_delete(context, instance_uuid)

    @wsgi.action('co_export')
    @convert_exception
    @authorize
    def _export_blessed_instance(self, req, id, body):
        context = req.environ["nova.context"]
        return self.cobalt_api.export_blessed_instance(context, id)

    @wsgi.action('gc_export')
    def _dep_export_blessed_instance(self, req, id, body):
        return self._export_blessed_instance(req=req, id=id, body=body)

    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})
示例#13
0
 def __init__(self):
     self.cobalt_api = API()
示例#14
0
 def __init__(self):
     super(CobaltImportController, self).__init__()
     self.cobalt_api = API()
示例#15
0
class CobaltServerControllerExtension(wsgi.Controller):
    """
    The OpenStack Extension definition for Cobalt 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(CobaltServerControllerExtension, self).__init__()
        self.cobalt_api = API()
        # Add the gridcentric-specific states to the state map
        common._STATE_MAP['blessed'] = {'default': 'BLESSED'}

    @wsgi.action('co_bless')
    @convert_exception
    @authorize
    def _bless_instance(self, req, id, body):
        context = req.environ["nova.context"]
        params = body.get('co_bless', body.get('gc_bless', {}))
        result = self.cobalt_api.bless_instance(context, id, params=params)
        return self._build_instance_list(req, [result])

    @wsgi.action('gc_bless')
    def _dep_bless_instance(self, req, id, body):
        return self._bless_instance(req=req, id=id, body=body)

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

    @wsgi.action('gc_discard')
    def _dep_discard_instance(self, req, id, body):
        return self._discard_instance(req=req, id=id, body=body)

    @wsgi.action('co_launch')
    @convert_exception
    @authorize
    def _launch_instance(self, req, id, body):
        context = req.environ["nova.context"]
        try:
            params = body.get('co_launch', body.get('gc_launch', {}))
            result = self.cobalt_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_launch')
    def _dep_launch_instance(self, req, id, body):
        return self._launch_instance(req=req, id=id, body=body)

    @wsgi.action('co_migrate')
    @convert_exception
    @authorize
    def _migrate_instance(self, req, id, body):
        context = req.environ["nova.context"]
        try:
            migrate_data = body.get('co_migrate', body.get('gc_migrate', {}))
            dest = migrate_data.get('dest', None)
            self.cobalt_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_migrate')
    def _dep_migrate_instance(self, req, id, body):
        return self._migrate_instance(req=req, id=id, body=body)

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

    @wsgi.action('gc_list_launched')
    def _dep_list_launched_instances(self, req, id, body):
        return self._list_launched_instances(req=req, id=id, body=body)

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

    @wsgi.action('gc_list_blessed')
    def _dep_list_blessed_instances(self, req, id, body):
        return self._list_blessed_instances(req=req, id=id, body=body)

    @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.cobalt_api.check_delete(context, instance_uuid)

    @wsgi.action('co_export')
    @convert_exception
    @authorize
    def _export_blessed_instance(self, req, id, body):
        context = req.environ["nova.context"]
        return self.cobalt_api.export_blessed_instance(context, id)

    @wsgi.action('gc_export')
    def _dep_export_blessed_instance(self, req, id, body):
        return self._export_blessed_instance(req=req, id=id, body=body)

    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})
示例#16
0
 def __init__(self):
     super(CobaltServerControllerExtension, self).__init__()
     self.cobalt_api = API()
     # Add the gridcentric-specific states to the state map
     common._STATE_MAP['blessed'] = {'default': 'BLESSED'}
示例#17
0
 def __init__(self):
     self.nova_servers = servers.Controller()
     self.nova_servers.compute_api = API()