def instance_root_create(self, req, body, instance_id, cluster_instances=None): LOG.info(_LI("Enabling root for instance '%s'.") % instance_id) LOG.info(_LI("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] user_name = context.user if body: password = body['password'] if 'password' in body else None else: password = None root = models.VerticaRoot.create(context, instance_id, user_name, password, cluster_instances) return wsgi.Result(views.RootCreatedView(root).data(), 200)
def create(self, req, body, tenant_id): LOG.info(_("Creating a backup for tenant %s"), tenant_id) context = req.environ[wsgi.CONTEXT_KEY] data = body['backup'] instance = data['instance'] name = data['name'] desc = data.get('description') parent = data.get('parent_id') incremental = data.get('incremental') context.notification = notification.DBaaSBackupCreate(context, request=req) with StartNotification(context, name=name, instance_id=instance, description=desc, parent_id=parent): backup = Backup.create(context, instance, name, desc, parent_id=parent, incremental=incremental) return wsgi.Result(views.BackupView(backup).data(), 202)
def edit(self, req, id, body, tenant_id): """ Updates the instance to set or unset one or more attributes. """ LOG.info(_("Editing instance for tenant id %s.") % tenant_id) LOG.debug(logging.mask_password("req: %s"), req) LOG.debug(logging.mask_password("body: %s"), body) context = req.environ[wsgi.CONTEXT_KEY] instance = models.Instance.load(context, id) if 'slave_of' in body['instance']: LOG.debug("Detaching replica from source.") instance.detach_replica() return wsgi.Result(None, 202)
def delete(self, req, tenant_id, instance_id, user_id, id): """Revoke access for a user.""" LOG.info(_("Revoking user access for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] user = self._get_user(context, instance_id, user_id) if not user: LOG.error(_("No such user: %(user)s " % {'user': user})) raise exception.UserNotFound(uuid=user) username, hostname = unquote_user_host(user_id) access = models.User.access(context, instance_id, username, hostname) databases = [db.name for db in access.databases] if id not in databases: raise exception.DatabaseNotFound(uuid=id) models.User.revoke(context, instance_id, username, hostname, id) return wsgi.Result(None, 202)
def rpc_ping(self, req, tenant_id, id): """Checks if instance is reachable via rpc.""" LOG.info( "Sending RPC PING for a database " "instance %(id)s for tenant '%(tenant_id)s'\n" "req : '%(req)s'\n\n", { "tenant_id": tenant_id, "req": req, "id": id }) context = req.environ[wsgi.CONTEXT_KEY] instance = models.MgmtInstance.load(context=context, id=id) instance.rpc_ping() return wsgi.Result(None, 204)
def update(self, req, id, body, tenant_id): """Updates the instance to attach/detach configuration.""" LOG.info(_LI("Updating database instance '%(instance_id)s' for tenant " "'%(tenant_id)s'"), {'instance_id': id, 'tenant_id': tenant_id}) LOG.debug("req: %s", req) LOG.debug("body: %s", body) context = req.environ[wsgi.CONTEXT_KEY] instance = models.Instance.load(context, id) # Make sure args contains a 'configuration_id' argument, args = {} args['configuration_id'] = self._configuration_parse(context, body) self._modify_instance(context, req, instance, **args) return wsgi.Result(None, 202)
def delete(self, req, tenant_id, id): """Delete a cluster.""" LOG.debug(("Deleting a Cluster for Tenant '%(tenant_id)s'\n" "req : '%(req)s'\n\nid : '%(id)s'\n\n") % { "req": req, "id": id, "tenant_id": tenant_id }) context = req.environ[wsgi.CONTEXT_KEY] cluster = models.Cluster.load(context, id) context.notification = notification.DBaaSClusterDelete(context, request=req) with StartNotification(context, cluster_id=id): cluster.delete() return wsgi.Result(None, 202)
def index(self, req, tenant_id, instance_id): """Return all schemas.""" LOG.info( _("Listing schemas for instance '%(id)s'\n" "req : '%(req)s'\n\n") % { "id": instance_id, "req": req }) context = req.environ[wsgi.CONTEXT_KEY] self.authorize_target_action(context, 'database:index', instance_id) schemas, next_marker = models.Schemas.load(context, instance_id) view = views.SchemasView(schemas) paged = pagination.SimplePaginatedDataView(req.url, 'databases', view, next_marker) return wsgi.Result(paged.data(), 200)
def create(self, req, body, tenant_id, instance_id): """Creates a set of schemas.""" LOG.info(_("Creating schema 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] schemas = body['databases'] context.notification = notification.DBaaSDatabaseCreate(context, request=req) with StartNotification(context, instance_id=instance_id, dbname=".".join([db['name'] for db in schemas])): model_schemas = populate_validated_databases(schemas) models.Schema.create(context, instance_id, model_schemas) return wsgi.Result(None, 202)
def delete(self, req, tenant_id, id): LOG.info( 'Deleting backup for tenant %(tenant_id)s ' 'ID: %(backup_id)s', { 'tenant_id': tenant_id, 'backup_id': id }) context = req.environ[wsgi.CONTEXT_KEY] backup = Backup.get_by_id(context, id) policy.authorize_on_target(context, 'backup:delete', {'tenant': backup.tenant_id}) context.notification = notification.DBaaSBackupDelete(context, request=req) with StartNotification(context, backup_id=id): Backup.delete(context, id) return wsgi.Result(None, 202)
def show(self, req, tenant_id, instance_id, id): """Return a single user.""" LOG.info(_("Showing a user for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] id = correct_id_with_req(id, req) username, host = unquote_user_host(id) user = None try: user = models.User.load(context, instance_id, username, host) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) if not user: raise exception.UserNotFound(uuid=id) view = views.UserView(user) return wsgi.Result(view.data(), 200)
def create(self, req, body, tenant_id, instance_id): """Creates a set of schemas.""" LOG.info( _("Creating schema for instance '%(id)s'\n" "req : '%(req)s'\n\n" "body: '%(body)s'\n'n") % { "id": instance_id, "req": req, "body": body }) context = req.environ[wsgi.CONTEXT_KEY] schemas = body['databases'] model_schemas = populate_validated_databases(schemas) models.Schema.create(context, instance_id, model_schemas) return wsgi.Result(None, 202)
def hwinfo(self, req, tenant_id, id): """Return a single instance hardware info.""" LOG.info( "Showing hardware info for a database " "instance %(id)s for tenant '%(tenant_id)s'\n" "req : '%(req)s'\n\n", { "tenant_id": tenant_id, "req": req, "id": id }) context = req.environ[wsgi.CONTEXT_KEY] instance = models.MgmtInstance.load(context=context, id=id) hwinfo = instance.get_hwinfo() return wsgi.Result(HwInfoView(id, hwinfo).data(), 200)
def module_apply(self, req, body, tenant_id, id): """Apply modules to an instance.""" context = req.environ[wsgi.CONTEXT_KEY] instance = models.Instance.load(context, id) if not instance: raise exception.NotFound(uuid=id) self.authorize_instance_action(context, 'module_apply', instance) module_ids = [mod['id'] for mod in body.get('modules', [])] modules = module_models.Modules.load_by_ids(context, module_ids) module_models.Modules.validate( modules, instance.datastore.id, instance.datastore_version.id) module_list = module_views.convert_modules_to_list(modules) client = create_guest_client(context, id) result_list = client.module_apply(module_list) models.Instance.add_instance_modules(context, id, modules) return wsgi.Result({'modules': result_list}, 200)
def instances(self, req, tenant_id, id): context = req.environ[wsgi.CONTEXT_KEY] configuration = models.Configuration.load(context, id) instances = instances_models.DBInstance.find_all( tenant_id=context.tenant, configuration_id=configuration.id, deleted=False) limit = int(context.limit or CONF.instances_page_size) if limit > CONF.instances_page_size: limit = CONF.instances_page_size data_view = instances_models.DBInstance.find_by_pagination( 'instances', instances, "foo", limit=limit, marker=context.marker) view = views.DetailedConfigurationInstancesView(data_view.collection) paged = pagination.SimplePaginatedDataView(req.url, 'instances', view, data_view.next_page_marker) return wsgi.Result(paged.data(), 200)
def diagnostics(self, req, tenant_id, id): """Return instance diagnostics for a single instance.""" LOG.info( "Showing diagnostic info for a database " "instance %(id)s for tenant '%(tenant_id)s'\n" "req : '%(req)s'\n\n", { "tenant_id": tenant_id, "req": req, "id": id }) context = req.environ[wsgi.CONTEXT_KEY] instance = models.MgmtInstance.load(context=context, id=id) diagnostics = instance.get_diagnostics() return wsgi.Result(DiagnosticsView(id, diagnostics).data(), 200)
def module_remove(self, req, tenant_id, id, module_id): """Remove module from an instance.""" context = req.environ[wsgi.CONTEXT_KEY] instance = models.Instance.load(context, id) if not instance: raise exception.NotFound(uuid=id) self.authorize_instance_action(context, 'module_remove', instance) module = module_models.Module.load(context, module_id) module_info = module_views.DetailedModuleView(module).data() client = create_guest_client(context, id) client.module_remove(module_info) instance_module = module_models.InstanceModule.load( context, instance_id=id, module_id=module_id) if instance_module: module_models.InstanceModule.delete(context, instance_module) return wsgi.Result(None, 200)
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] deleted_q = req.GET.get('deleted', '').lower() include_deleted = deleted_q == 'true' server = models.DetailedMgmtInstance.load(context, id, include_deleted) root_history = mysql_models.RootHistory.load(context=context, instance_id=id) return wsgi.Result( views.MgmtInstanceDetailView(server, req=req, root_history=root_history).data(), 200)
def index(self, req, tenant_id): context = req.environ[wsgi.CONTEXT_KEY] instance_id = req.GET.get('instance_id') tenant_id = req.GET.get('project_id', context.project_id) LOG.info("Listing backup strateies for tenant %s", tenant_id) if tenant_id != context.project_id and not context.is_admin: raise exception.TroveOperationAuthError( tenant_id=context.project_id) policy.authorize_on_tenant(context, 'backup_strategy:index') result = BackupStrategy.list(context, tenant_id, instance_id=instance_id) view = views.BackupStrategiesView(result) return wsgi.Result(view.data(), 200)
def show(self, req, tenant_id, id): """Return a single instance.""" LOG.info( "Showing database instance '%(instance_id)s' for tenant " "'%(tenant_id)s'", { 'instance_id': id, 'tenant_id': tenant_id }) LOG.debug("req : '%s'\n\n", req) context = req.environ[wsgi.CONTEXT_KEY] server = models.load_instance_with_info(models.DetailInstance, context, id) self.authorize_instance_action(context, 'show', server) return wsgi.Result( views.InstanceDetailView(server, req=req).data(), 200)
def index(self, req, tenant_id): """Return a list of clusters.""" LOG.debug(("Showing a list of clusters for Tenant '%(tenant_id)s'\n" "req : '%(req)s'\n\n") % {"req": req, "tenant_id": tenant_id}) context = req.environ[wsgi.CONTEXT_KEY] if not context.is_admin and context.tenant != tenant_id: raise exception.TroveOperationAuthError(tenant_id=context.tenant) # load all clusters and instances for the tenant clusters, marker = models.Cluster.load_all(context, tenant_id) view = views.ClustersView(clusters, req=req) paged = pagination.SimplePaginatedDataView(req.url, 'clusters', view, marker) return wsgi.Result(paged.data(), 200)
def show(self, req, tenant_id, id): LOG.debug("Showing configuration group %(id)s on tenant %(tenant)s" % {"tenant": tenant_id, "id": id}) context = req.environ[wsgi.CONTEXT_KEY] configuration = models.Configuration.load(context, id) self.authorize_config_action(context, 'show', configuration) configuration_items = models.Configuration.load_items(context, id) configuration.instance_count = instances_models.DBInstance.find_all( tenant_id=context.tenant, configuration_id=configuration.id, deleted=False).count() return wsgi.Result(views.DetailedConfigurationView( configuration, configuration_items).data(), 200)
def delete(self, req, tenant_id, id): LOG.debug("Delete Security Group Rule called %s, %s" % (tenant_id, id)) context = req.environ[wsgi.CONTEXT_KEY] sec_group_rule = models.SecurityGroupRule.find_by(id=id, deleted=False) sec_group = sec_group_rule.get_security_group(tenant_id) if sec_group is None: LOG.error( _("Attempting to delete Group Rule that does not " "exist or does not belong to tenant %s") % tenant_id) raise exception.Forbidden("Unauthorized") sec_group_rule.delete(context, CONF.os_region_name) sec_group.save() return wsgi.Result(None, 204)
def create(self, req, body, tenant_id): LOG.debug("req : '%s'\n\n" % req) LOG.debug("body : '%s'\n\n" % req) context = req.environ[wsgi.CONTEXT_KEY] policy.authorize_on_tenant(context, 'configuration:create') context.notification = notification.DBaaSConfigurationCreate( context, request=req) name = body['configuration']['name'] description = body['configuration'].get('description') values = body['configuration']['values'] msg = _("Creating configuration group on tenant " "%(tenant_id)s with name: %(cfg_name)s") LOG.info(msg % {"tenant_id": tenant_id, "cfg_name": name}) datastore_args = body['configuration'].get('datastore', {}) datastore, datastore_version = ( ds_models.get_datastore_version(**datastore_args)) with StartNotification(context, name=name, datastore=datastore.name, datastore_version=datastore_version.name): configItems = [] if values: # validate that the values passed in are permitted by the # operator. ConfigurationsController._validate_configuration( body['configuration']['values'], datastore_version, models.DatastoreConfigurationParameters.load_parameters( datastore_version.id)) for k, v in values.items(): configItems.append(DBConfigurationParameter( configuration_key=k, configuration_value=v)) cfg_group = models.Configuration.create(name, description, tenant_id, datastore.id, datastore_version.id) with EndNotification(context, configuration_id=cfg_group.id): cfg_group_items = models.Configuration.create_items( cfg_group.id, values) view_data = views.DetailedConfigurationView(cfg_group, cfg_group_items) return wsgi.Result(view_data.data(), 200)
def create(self, req, body, tenant_id): LOG.debug("Creating a Cluster 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] name = body['cluster']['name'] datastore_args = body['cluster'].get('datastore', {}) datastore, datastore_version = ( datastore_models.get_datastore_version(**datastore_args)) # TODO(saurabhs): add extended_properties to apischema extended_properties = body['cluster'].get('extended_properties', {}) try: clusters_enabled = (CONF.get(datastore_version.manager) .get('cluster_support')) except NoSuchOptError: clusters_enabled = False if not clusters_enabled: raise exception.ClusterDatastoreNotSupported( datastore=datastore.name, datastore_version=datastore_version.name) nodes = body['cluster']['instances'] instances = [] for node in nodes: flavor_id = utils.get_id_from_href(node['flavorRef']) volume_size = nics = availability_zone = None if 'volume' in node: volume_size = int(node['volume']['size']) if 'nics' in node: nics = node['nics'] if 'availability_zone' in node: availability_zone = node['availability_zone'] instances.append({"flavor_id": flavor_id, "volume_size": volume_size, "nics": nics, "availability_zone": availability_zone}) cluster = models.Cluster.create(context, name, datastore, datastore_version, instances, extended_properties) view = views.load_view(cluster, req=req, load_servers=False) return wsgi.Result(view.data(), 200)
def update(self, req, id, body, tenant_id): """Updates the instance. - attach/detach configuration. - detach from primary. - access information. """ LOG.info( "Updating database instance '%(instance_id)s' for tenant " "'%(tenant_id)s'", { 'instance_id': id, 'tenant_id': tenant_id }) LOG.debug("req: %s", req) LOG.debug("body: %s", body) context = req.environ[wsgi.CONTEXT_KEY] name = body['instance'].get('name') if ((name and len(body['instance'].keys()) > 2) or (not name and len(body['instance'].keys()) >= 2)): raise exception.BadRequest("Only one attribute (except 'name') is " "allowed to update.") instance = models.Instance.load(context, id) self.authorize_instance_action(context, 'update', instance) args = {} if name: instance.update_db(name=name) detach_replica = ('replica_of' in body['instance'] or 'slave_of' in body['instance']) if detach_replica: args['detach_replica'] = detach_replica configuration_id = self._configuration_parse(context, body) if configuration_id is not None: args['configuration_id'] = configuration_id if 'access' in body['instance']: args['access'] = body['instance']['access'] if 'datastore_version' in body['instance']: args['datastore_version'] = body['instance']['datastore_version'] self._modify_instance(context, req, instance, **args) return wsgi.Result(None, 202)
def configuration(self, req, tenant_id, id): """ Returns the default configuration template applied to the instance. """ LOG.info("Getting default configuration for instance %s", id) context = req.environ[wsgi.CONTEXT_KEY] instance = models.Instance.load(context, id) self.authorize_instance_action(context, 'configuration', instance) LOG.debug("Server: %s", instance) config = instance.get_default_configuration_template() LOG.debug("Default config for instance %(instance_id)s is %(config)s", { 'instance_id': id, 'config': config }) return wsgi.Result(views.DefaultConfigurationView(config).data(), 200)
def guest_log_list(self, req, tenant_id, id): """Return all information about all logs for an instance.""" LOG.debug("Listing logs for tenant %s", tenant_id) context = req.environ[wsgi.CONTEXT_KEY] try: backup_model.verify_swift_auth_token(context) except exception.SwiftNotFound: raise exception.LogsNotAvailable() instance = models.Instance.load(context, id) if not instance: raise exception.NotFound(uuid=id) self.authorize_instance_action(context, 'guest_log_list', instance) client = create_guest_client(context, id) guest_log_list = client.guest_log_list() return wsgi.Result({'logs': guest_log_list}, 200)
def update(self, req, body, tenant_id, instance_id, id): """Change attributes for one user.""" LOG.info(_("Updating user attributes for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] username, hostname = unquote_user_host(id) user = None user_attrs = body['user'] try: user = models.User.load(context, instance_id, username, hostname) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) if not user: raise exception.UserNotFound(uuid=id) models.User.update_attributes(context, instance_id, username, hostname, user_attrs) return wsgi.Result(None, 202)
def create(self, req, body, tenant_id): """Adds a new datastore version.""" context = req.environ[wsgi.CONTEXT_KEY] datastore_name = body['version']['datastore_name'] version_name = body['version']['name'] manager = body['version']['datastore_manager'] image_id = body['version']['image'] packages = body['version']['packages'] if type(packages) is list: packages = ','.join(packages) active = body['version']['active'] default = body['version']['default'] LOG.info("Tenant: '%(tenant)s' is adding the datastore " "version: '%(version)s' to datastore: '%(datastore)s'", {'tenant': tenant_id, 'version': version_name, 'datastore': datastore_name}) client = clients.create_glance_client(context) try: client.images.get(image_id) except glance_exceptions.HTTPNotFound: raise exception.ImageNotFound(uuid=image_id) try: datastore = models.Datastore.load(datastore_name) except exception.DatastoreNotFound: # Create the datastore if datastore_name does not exists. LOG.info("Creating datastore %s", datastore_name) datastore = models.DBDatastore() datastore.id = utils.generate_uuid() datastore.name = datastore_name datastore.save() try: models.DatastoreVersion.load(datastore, version_name) raise exception.DatastoreVersionAlreadyExists(name=version_name) except exception.DatastoreVersionNotFound: models.update_datastore_version(datastore.name, version_name, manager, image_id, packages, active) if default: models.update_datastore(datastore.name, version_name) return wsgi.Result(None, 202)