def update(self, req, body, tenant_id, id): LOG.info("req : '%s'\n\n" % req) LOG.info("Updating quota limits for tenant '%s'" % id) if not body: raise exception.BadRequest(_("Invalid request body.")) quotas = {} quota = None registered_resources = quota_engine.resources for resource, limit in body['quotas'].items(): if limit is None: continue if resource == "xmlns": continue if resource not in registered_resources: raise exception.QuotaResourceUnknown(unknown=resource) try: quota = Quota.find_by(tenant_id=id, resource=resource) quota.hard_limit = limit quota.save() except exception.ModelNotFoundError: quota = Quota.create(tenant_id=id, resource=resource, hard_limit=limit) quotas[resource] = quota return wsgi.Result(views.QuotaView(quotas).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 index(self, req, tenant_id, detailed=False): """Return all hosts.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Indexing a host for tenant '%s'") % tenant_id) context = req.environ[wsgi.CONTEXT_KEY] hosts = models.SimpleHost.load_all(context) return wsgi.Result(views.HostsView(hosts).data(), 200)
def update(self, req, body, tenant_id, instance_id): """Change the password of one or more users.""" LOG.info(_("Updating user passwords for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] self.validate(body) users = body['users'] model_users = [] for user in users: try: mu = guest_models.MySQLUser() mu.name = user['name'] mu.host = user.get('host') mu.password = user['password'] found_user = models.User.load(context, instance_id, mu.name, mu.host) if not found_user: user_and_host = mu.name if mu.host: user_and_host += '@' + mu.host raise exception.UserNotFound(uuid=user_and_host) model_users.append(mu) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) models.User.change_password(context, instance_id, model_users) return wsgi.Result(None, 202)
def show(self, req, tenant_id, id): """Return a single flavor.""" context = req.environ[wsgi.CONTEXT_KEY] self._validate_flavor_id(id) flavor = models.Flavor(context=context, flavor_id=int(id)) # Pass in the request to build accurate links. return wsgi.Result(views.FlavorView(flavor, req).data(), 200)
def index(self, req, tenant_id): """Return all storage devices.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Indexing storage info for tenant '%s'") % tenant_id) context = req.environ[wsgi.CONTEXT_KEY] storages = models.StorageDevices.load(context) return wsgi.Result(views.StoragesView(storages).data(), 200)
def backups(self, req, tenant_id, id): """Return all backups for the specified instance.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Indexing backups for instance '%s'") % id) backups = backup_model.list_for_instance(id) return wsgi.Result(backup_views.BackupViews(backups).data(), 200)
class MgmtInstanceController(InstanceController): """Controller for instance functionality""" @admin_context def index(self, req, tenant_id, detailed=False): """Return all instances.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Indexing a database instance for tenant '%s'") % tenant_id) context = req.environ[wsgi.CONTEXT_KEY] deleted = None deleted_q = req.GET.get('deleted', '').lower() if deleted_q in ['true']: deleted = True elif deleted_q in ['false']: deleted = False try: instances = models.load_mgmt_instances(context, deleted=deleted) except nova_exceptions.ClientException, e: LOG.error(e) return wsgi.Result(str(e), 403) view_cls = views.MgmtInstancesView return wsgi.Result( view_cls(instances, req=req, add_addresses=self.add_addresses, add_volumes=self.add_volumes).data(), 200)
def index(self, req, tenant_id): """ Return all backups information for a tenant ID. """ LOG.debug("Listing Backups for tenant '%s'" % tenant_id) context = req.environ[wsgi.CONTEXT_KEY] backups = Backup.list(context) return wsgi.Result(views.BackupViews(backups).data(), 200)
def show(self, req, tenant_id, id): """Return a single host.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Showing a host for tenant '%s'") % tenant_id) LOG.info(_("id : '%s'\n\n") % id) context = req.environ[wsgi.CONTEXT_KEY] host = models.DetailedHost.load(context, id) return wsgi.Result(views.HostDetailedView(host).data(), 200)
def index(self, req, tenant_id, instance_id): """ Returns True if root is enabled for the given instance; False otherwise. """ LOG.info(_("Getting root enabled for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] is_root_enabled = models.Root.load(context, instance_id) return wsgi.Result(views.RootEnabledView(is_root_enabled).data(), 200)
def create(self, req, tenant_id, instance_id): """ Enable the root user for the db instance """ LOG.info(_("Enabling root for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] user_name = context.user root = models.Root.create(context, instance_id, user_name) return wsgi.Result(views.RootCreatedView(root).data(), 200)
def index(self, request): """Respond to a request for API versions.""" versions = [] for key, data in VERSIONS.items(): v = BaseVersion(data["id"], data["status"], request.application_url, data["updated"]) versions.append(v) return wsgi.Result(VersionsDataView(versions))
def show(self, req, tenant_id, id): """Return a account and instances associated with a single account.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Showing account information for '%s' to '%s'") % (id, tenant_id)) context = req.environ[wsgi.CONTEXT_KEY] account = models.Account.load(context, id) return wsgi.Result(views.AccountView(account).data(), 200)
def update(self, req, body, tenant_id, instance_id, user_id): """Grant access for a user to one or more databases.""" context = req.environ[wsgi.CONTEXT_KEY] self.validate(body) user = self._get_user(context, instance_id, user_id) username, hostname = unquote_user_host(user_id) databases = [db['name'] for db in body['databases']] models.User.grant(context, instance_id, username, hostname, databases) return wsgi.Result(None, 202)
def index(self, req, tenant_id): """ Return all absolute and rate limit information. """ quotas = QUOTAS.get_all_quotas_by_tenant(tenant_id) abs_limits = dict((k, v['hard_limit']) for k, v in quotas.items()) rate_limits = req.environ.get("reddwarf.limits", []) return wsgi.Result(views.LimitViews(abs_limits, rate_limits).data(), 200)
def hwinfo(self, req, tenant_id, id): """Return a single instance hardware info.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Showing hardware info for instance '%s'") % 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 create(self, req, body, tenant_id): LOG.debug("Creating a Backup for tenant '%s'" % tenant_id) self._validate_create_body(body) context = req.environ[wsgi.CONTEXT_KEY] data = body['backup'] instance = data['instance'] name = data['name'] desc = data.get('description') backup = Backup.create(context, instance, name, desc) return wsgi.Result(views.BackupView(backup).data(), 202)
def index(self, req, tenant_id): """Return all instances.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Indexing a database instance for tenant '%s'") % tenant_id) context = req.environ[wsgi.CONTEXT_KEY] servers, marker = models.Instances.load(context) view = views.InstancesView(servers, req=req) paged = pagination.SimplePaginatedDataView(req.url, 'instances', view, marker) return wsgi.Result(paged.data(), 200)
def index(self, req, tenant_id, instance_id): """Return all users.""" LOG.info(_("Listing users for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] users, next_marker = models.Users.load(context, instance_id) view = views.UsersView(users) paged = pagination.SimplePaginatedDataView(req.url, 'users', view, next_marker) return wsgi.Result(paged.data(), 200)
def diagnostics(self, req, tenant_id, id): """Return a single instance diagnostics.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Showing a instance diagnostics for instance '%s'") % id) LOG.info(_("id : '%s'\n\n") % 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 delete(self, req, tenant_id, id): """Delete a single instance.""" LOG.info(_("req : '%s'\n\n") % req) LOG.info(_("Deleting a database instance for tenant '%s'") % tenant_id) LOG.info(_("id : '%s'\n\n") % id) # TODO(hub-cap): turn this into middleware context = req.environ[wsgi.CONTEXT_KEY] instance = models.load_any_instance(context, id) instance.delete() # TODO(cp16net): need to set the return code correctly return wsgi.Result(None, 202)
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)
def delete(self, req, tenant_id, instance_id, user_id, id): """Revoke access for a user.""" context = req.environ[wsgi.CONTEXT_KEY] user = self._get_user(context, instance_id, user_id) 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 not id in databases: raise exception.DatabaseNotFound(uuid=id) models.User.revoke(context, instance_id, username, hostname, id) 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'] model_users = populate_users(users) models.User.create(context, instance_id, model_users) return wsgi.Result(None, 202)
def delete(self, req, tenant_id, instance_id, id): LOG.info(_("Deleting user for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] try: user = guest_models.MySQLUser() user.name = id models.User.delete(context, instance_id, user.serialize()) except ValueError as ve: raise exception.BadRequest(ve.message) return wsgi.Result(None, 202)
def delete(self, req, tenant_id, instance_id, id): LOG.info(_("Deleting schema for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] try: schema = guest_models.ValidatedMySQLDatabase() schema.name = id models.Schema.delete(context, instance_id, schema.serialize()) 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 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] self.validate(body) schemas = body['databases'] model_schemas = populate_validated_databases(schemas) models.Schema.create(context, instance_id, model_schemas) return wsgi.Result(None, 202)
def index(self, req, tenant_id, instance_id, user_id): """Show permissions for the given user.""" LOG.info(_("Showing user access for instance '%s'") % instance_id) LOG.info(_("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] # Make sure this user exists. user = self._get_user(context, instance_id, user_id) username, hostname = unquote_user_host(user_id) access = models.User.access(context, instance_id, username, hostname) view = views.UserAccessView(access.databases) return wsgi.Result(view.data(), 200)
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] username, host = unquote_user_host(id) user = models.User.load(context, instance_id, username, host) if not user: raise exception.UserNotFound(uuid=id) view = views.UserView(user) return wsgi.Result(view.data(), 200)