Пример #1
0
    def create(self, req, body, tenant_id):
        # TODO(hub-cap): turn this into middleware
        LOG.info(_("Creating a database instance for tenant '%s'") % tenant_id)
        LOG.info(_("req : '%s'\n\n") % req)
        LOG.info(_("body : '%s'\n\n") % body)
        context = req.environ[wsgi.CONTEXT_KEY]
        # Set the service type to mysql if its not in the request
        service_type = (body['instance'].get('service_type') or
                        CONF.service_type)
        service = models.ServiceImage.find_by(service_name=service_type)
        image_id = service['image_id']
        name = body['instance']['name']
        flavor_ref = body['instance']['flavorRef']
        flavor_id = utils.get_id_from_href(flavor_ref)
        databases = populate_databases(body['instance'].get('databases', []))
        users = populate_users(body['instance'].get('users', []))
        if body['instance'].get('volume', None) is not None:
            try:
                volume_size = int(body['instance']['volume']['size'])
            except ValueError as e:
                raise exception.BadValue(msg=e)
        else:
            volume_size = None

        instance = models.Instance.create(context, name, flavor_id,
                                          image_id, databases, users,
                                          service_type, volume_size)

        view = views.InstanceDetailView(instance, req=req)
        return wsgi.Result(view.data(), 200)
Пример #2
0
    def show(self, req, tenant_id, id):
        """Return a single instance."""
        LOG.info(_("req : '%s'\n\n") % req)
        LOG.info(_("Showing a database instance for tenant '%s'") % tenant_id)
        LOG.info(_("id : '%s'\n\n") % id)

        context = req.environ[wsgi.CONTEXT_KEY]
        server = models.load_instance_with_guest(models.DetailInstance,
                                                 context, id)
        return wsgi.Result(
            views.InstanceDetailView(server, req=req).data(), 200)
Пример #3
0
    def create(self, req, body, tenant_id):
        # find the service id (cant be done yet at startup due to
        # inconsistencies w/ the load app paste
        # TODO(hub-cap): figure out how to get this to work in __init__ time
        # TODO(hub-cap): The problem with this in __init__ is that the paste
        #   config is generated w/ the same config file as the db flags that
        #   are needed for init. These need to be split so the db can be init'd
        #   w/o the paste stuff. Since the paste stuff inits the
        #   database.service module, it is a chicken before the egg problem.
        #   Simple refactor will fix it and we can move this into the __init__
        #   code. Or maybe we shouldnt due to the nature of changing images.
        #   This needs discussion.
        # TODO(hub-cap): turn this into middleware
        LOG.info(_("Creating a database instance for tenant '%s'") % tenant_id)
        LOG.info(_("req : '%s'\n\n") % req)
        LOG.info(_("body : '%s'\n\n") % body)
        context = req.environ[wsgi.CONTEXT_KEY]
        service_type = body['instance'].get('service_type')
        if service_type is None:
            service_type = 'mysql'
        service = models.ServiceImage.find_by(service_name=service_type)
        image_id = service['image_id']
        name = body['instance']['name']
        flavor_ref = body['instance']['flavorRef']
        flavor_id = utils.get_id_from_href(flavor_ref)
        databases = populate_databases(body['instance'].get('databases', []))
        users = populate_users(body['instance'].get('users', []))
        if body['instance'].get('volume', None) is not None:
            try:
                volume_size = int(body['instance']['volume']['size'])
            except ValueError as e:
                raise exception.BadValue(msg=e)
        else:
            volume_size = None

        instance_max = int(config.Config.get('max_instances_per_user', 5))
        number_instances = models.DBInstance.find_all(tenant_id=tenant_id,
                                                      deleted=False).count()

        if number_instances >= instance_max:
            # That's too many, pal. Got to cut you off.
            LOG.error(_("New instance would exceed user instance quota."))
            msg = "User instance quota of %d would be exceeded."
            raise exception.QuotaExceeded(msg % instance_max)

        instance = models.Instance.create(context, name, flavor_id, image_id,
                                          databases, users, service_type,
                                          volume_size)

        view = views.InstanceDetailView(instance,
                                        req=req,
                                        add_volumes=self.add_volumes)
        return wsgi.Result(view.data(), 200)