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 = None try: users = populate_users(body['instance'].get('users', [])) except ValueError as ve: raise exception.BadRequest(msg=ve) 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)
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)
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)
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 if body['instance'].get('restorePoint', None) is not None: backup_id = body['instance']['restorePoint']['backupId'] backup_info = backup_model.get_by_id(backup_id) if not backup_info.state == BackupState.COMPLETED: raise exception.BackupNotCompleteError(backup_id=backup_id) # verify backup file exist in swift location = backup_info.location if not InstanceController._check_object_exist(context, location): raise exception.BackupFileNotFound(location=location) else: backup_id = None instance = models.Instance.create(context, name, flavor_id, image_id, databases, users, service_type, volume_size, backup_id) view = views.InstanceDetailView(instance, req=req) return wsgi.Result(view.data(), 200)
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 "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 = CONF.max_instances_per_user 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) return wsgi.Result(view.data(), 200)
def _create_resources(): # parse the ID from the Ref instance_id = utils.get_id_from_href(instance) # verify that the instance exist and can perform actions from reddwarf.instance.models import Instance instance_model = Instance.load(context, instance_id) instance_model.validate_can_perform_action() cls.verify_swift_auth_token(context) try: db_info = DBBackup.create(name=name, description=description, tenant_id=context.tenant, state=BackupState.NEW, instance_id=instance_id, deleted=False) except exception.InvalidModelError as ex: LOG.exception("Unable to create Backup record:") raise exception.BackupCreationError(str(ex)) api.API(context).create_backup(db_info.id, instance_id) return db_info
def _action_resize_flavor(self, instance, flavorRef): new_flavor_id = utils.get_id_from_href(flavorRef) instance.resize_flavor(new_flavor_id) return wsgi.Result(None, 202)
def _action_resize_flavor(self, instance, flavorRef): new_flavor_id = utils.get_id_from_href(flavorRef) instance.resize_flavor(new_flavor_id) return webob.exc.HTTPAccepted()
# Extract flavor info from the request try: flavor_ref = body['instance']['flavorRef'] except KeyError, e: LOG.info("The body does not contain an [instance][flavorRef] key - using default flavor of medium") try: flavor_model = models.ServiceFlavor.find_by(service_name="database", flavor_name='large', deleted=False) except: LOG.exception("The ServiceFlavor table doesn't contain a default flavor named 'medium'!") return wsgi.Result(errors.wrap(errors.Instance.FLAVOR_NOT_FOUND_CREATE), 404) flavor_ref = flavor_utils.build_flavor_href(req, tenant_id, flavor_model['flavor_id']) # Validate the request try: flavor_id = utils.get_id_from_href(flavor_ref) #if not Sanitizer.whitelist_uuid(flavor_id): #TODO: (joshdorothy) we need to implement some sort of href sanitizer if we're # going to be accepting them in a request body LOG.debug("retrieved flavor id %s from flavor ref %s" % (flavor_id, flavor_ref)) except: LOG.exception("Could not parse %s" % flavor_ref) return wsgi.Result(errors.wrap(errors.Instance.MALFORMED_BODY), 500) # Fetch all boot parameters from Database try: image_id, flavor, keypair_name, region_az, credential = self._load_boot_params(tenant_id, flavor_id) except exception.ModelNotFoundError: return wsgi.Result(errors.wrap(errors.Instance.FLAVOR_NOT_FOUND_CREATE), 404)