def _validate_can_perform_action(self, tenant_id, instance_id, is_cluster, operation): if is_cluster: raise exception.ClusterOperationNotSupported(operation=operation) is_slave = self._is_slave(tenant_id, instance_id) if is_slave: raise exception.SlaveOperationNotSupported(operation=operation)
def root_index(self, req, tenant_id, instance_id, is_cluster): """Returns True if root is enabled; False otherwise.""" if is_cluster: raise exception.ClusterOperationNotSupported(operation='show_root') LOG.info(_LI("Getting root enabled for instance '%s'.") % instance_id) LOG.info(_LI("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 root_create(self, req, body, tenant_id, instance_id, is_cluster): if is_cluster: raise exception.ClusterOperationNotSupported( operation='enable_root') LOG.info("Enabling root for instance '%s'.", instance_id) LOG.info("req : '%s'\n\n", req) context = req.environ[wsgi.CONTEXT_KEY] password = DefaultRootController._get_password_from_body(body) root = models.Root.create(context, instance_id, password) return wsgi.Result(views.RootCreatedView(root).data(), 200)
def root_delete(self, req, tenant_id, instance_id, is_cluster): if is_cluster: raise exception.ClusterOperationNotSupported( operation='disable_root') LOG.info("Disabling root 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) if not is_root_enabled: raise exception.RootHistoryNotFound() models.Root.delete(context, instance_id) return wsgi.Result(None, 204)
def root_create(self, req, body, tenant_id, instance_id, is_cluster): if is_cluster: raise exception.ClusterOperationNotSupported( operation='enable_root') 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.Root.create(context, instance_id, user_name, password) return wsgi.Result(views.RootCreatedView(root).data(), 200)
def root_delete(self, req, tenant_id, instance_id, is_cluster): if is_cluster: raise exception.ClusterOperationNotSupported( operation='disable_root') LOG.info(_LI("Disabling root for instance '%s'.") % instance_id) LOG.info(_LI("req : '%s'\n\n") % req) context = req.environ[wsgi.CONTEXT_KEY] try: found_user = self._find_root_user(context, instance_id) except (ValueError, AttributeError) as e: raise exception.BadRequest(msg=str(e)) if not found_user: raise exception.UserNotFound(uuid="root") models.Root.delete(context, instance_id) return wsgi.Result(None, 200)