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, instance_id): """Creates a set of users""" LOG.info(_("Creating users for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("body : '%s'\n\n") % body) context = req.environ[wsgi.CONTEXT_KEY] self.validate(body) users = body['users'] model_users = populate_users(users) models.User.create(context, instance_id, model_users) return wsgi.Result(None, 202)
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, instance_id): """Creates a set of users""" LOG.info(_("Creating users for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("body : '%s'\n\n") % body) context = req.environ[wsgi.CONTEXT_KEY] self.validate(body) users = body['users'] try: model_users = populate_users(users) models.User.create(context, instance_id, model_users) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) return wsgi.Result(None, 202)
def create(self, req, body, tenant_id, instance_id): """Creates a set of users""" LOG.info(_("Creating users for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("body : '%s'\n\n") % body) context = req.environ[wsgi.CONTEXT_KEY] self.validate(body) users = body['users'] try: model_users = populate_users(users) models.User.create(context, instance_id, model_users) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=e) return wsgi.Result(None, 202)
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)