Beispiel #1
0
    def instances(self, req, tenant_id, id):
        LOG.info("Getting instances for module %s.", id)

        context = req.environ[wsgi.CONTEXT_KEY]

        module = models.Module.load(context, id)
        self.authorize_module_action(context, 'instances', module)

        count_only = req.GET.get('count_only', '').lower() == 'true'
        include_clustered = (req.GET.get('include_clustered',
                                         '').lower() == 'true')
        if count_only:
            instance_count = instance_models.module_instance_count(
                context, id, include_clustered=include_clustered)
            result_list = {
                'instances':
                instance_views.convert_instance_count_to_list(instance_count)
            }
        else:
            instance_modules, marker = models.InstanceModules.load(
                context, module_id=id)
            if instance_modules:
                instance_ids = [
                    inst_mod.instance_id for inst_mod in instance_modules
                ]
                instances, marker = instance_models.Instances.load(
                    context, include_clustered, instance_ids=instance_ids)
            else:
                instances = []
                marker = None
            view = instance_views.InstancesView(instances, req=req)
            result_list = pagination.SimplePaginatedDataView(
                req.url, 'instances', view, marker).data()
        return wsgi.Result(result_list, 200)
Beispiel #2
0
    def instances(self, req, tenant_id, id):
        LOG.info(_("Getting instances for module %s") % id)

        context = req.environ[wsgi.CONTEXT_KEY]

        module = models.Module.load(context, id)
        self.authorize_module_action(context, 'update', module)

        instance_modules, marker = models.InstanceModules.load(context,
                                                               module_id=id)
        if instance_modules:
            instance_ids = [
                inst_mod.instance_id for inst_mod in instance_modules
            ]
            include_clustered = (req.GET.get('include_clustered',
                                             '').lower() == 'true')
            instances, marker = instance_models.Instances.load(
                context, include_clustered, instance_ids=instance_ids)
        else:
            instances = []
            marker = None
        view = instance_views.InstancesView(instances, req=req)
        paged = pagination.SimplePaginatedDataView(req.url, 'instances', view,
                                                   marker)
        return wsgi.Result(paged.data(), 200)
Beispiel #3
0
    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]

        # This theoretically allows the Admin tenant list clusters for
        # only one particular tenant as opposed to listing all clusters for
        # for all tenants.
        # * As far as I can tell this is the only call which actually uses the
        #   passed-in 'tenant_id' for anything.
        if not context.is_admin and context.tenant != tenant_id:
            raise exception.TroveOperationAuthError(tenant_id=context.tenant)

        # The rule checks that the currently authenticated tenant can perform
        # the 'cluster-list' action.
        policy.authorize_on_tenant(context, 'cluster:index')

        # 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)
Beispiel #4
0
    def index(self, req, tenant_id):
        """
        Return all backups information for a tenant ID.
        """
        LOG.debug("Listing backups for tenant %s", tenant_id)
        datastore = req.GET.get('datastore')
        instance_id = req.GET.get('instance_id')
        project_id = req.GET.get('project_id')
        all_projects = strutils.bool_from_string(req.GET.get('all_projects'))
        context = req.environ[wsgi.CONTEXT_KEY]

        if project_id or all_projects:
            policy.authorize_on_tenant(context, 'backup:index:all_projects')
        else:
            policy.authorize_on_tenant(context, 'backup:index')

        backups, marker = Backup.list(context,
                                      datastore=datastore,
                                      instance_id=instance_id,
                                      project_id=project_id,
                                      all_projects=all_projects)
        view = views.BackupViews(backups)
        paged = pagination.SimplePaginatedDataView(req.url, 'backups', view,
                                                   marker)
        return wsgi.Result(paged.data(), 200)
Beispiel #5
0
 def index(self, req, tenant_id):
     context = req.environ[wsgi.CONTEXT_KEY]
     configs, marker = models.Configurations.load(context)
     view = views.ConfigurationsView(configs)
     paged = pagination.SimplePaginatedDataView(req.url, 'configurations',
                                                view, marker)
     return wsgi.Result(paged.data(), 200)
Beispiel #6
0
 def _get_instances(self, req, instance_view):
     context = req.environ[wsgi.CONTEXT_KEY]
     clustered_q = req.GET.get('include_clustered', '').lower()
     include_clustered = clustered_q == 'true'
     instances, marker = models.Instances.load(context, include_clustered)
     view = views.InstancesView(instances, item_view=instance_view, req=req)
     paged = pagination.SimplePaginatedDataView(req.url, 'instances', view,
                                                marker)
     return paged.data()
Beispiel #7
0
 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)
Beispiel #8
0
 def backups(self, req, tenant_id, id):
     """Return all backups for the specified instance."""
     LOG.info(_LI("Listing backups for instance '%s'"), id)
     LOG.debug("req : '%s'\n\n", req)
     context = req.environ[wsgi.CONTEXT_KEY]
     backups, marker = backup_model.list_for_instance(context, id)
     view = backup_views.BackupViews(backups)
     paged = pagination.SimplePaginatedDataView(req.url, 'backups', view,
                                                marker)
     return wsgi.Result(paged.data(), 200)
Beispiel #9
0
 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)
Beispiel #10
0
 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, marker = Backup.list(context)
     view = views.BackupViews(backups)
     paged = pagination.SimplePaginatedDataView(req.url, 'backups', view,
                                                marker)
     return wsgi.Result(paged.data(), 200)
Beispiel #11
0
 def index(self, req, tenant_id):
     """Return all instances."""
     LOG.info(_LI("Listing database instances for tenant '%s'"), tenant_id)
     LOG.debug("req : '%s'\n\n", req)
     context = req.environ[wsgi.CONTEXT_KEY]
     clustered_q = req.GET.get('include_clustered', '').lower()
     include_clustered = clustered_q == 'true'
     servers, marker = models.Instances.load(context, include_clustered)
     view = views.InstancesView(servers, req=req)
     paged = pagination.SimplePaginatedDataView(req.url, 'instances', view,
                                                marker)
     return wsgi.Result(paged.data(), 200)
Beispiel #12
0
 def index(self, req, tenant_id, instance_id):
     """Return all users."""
     LOG.info("Listing users 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, 'user:index', instance_id)
     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)
Beispiel #13
0
 def index(self, req, tenant_id):
     """
     Return all backups information for a tenant ID.
     """
     LOG.debug("Listing backups for tenant %s", tenant_id)
     datastore = req.GET.get('datastore')
     context = req.environ[wsgi.CONTEXT_KEY]
     policy.authorize_on_tenant(context, 'backup:index')
     backups, marker = Backup.list(context, datastore)
     view = views.BackupViews(backups)
     paged = pagination.SimplePaginatedDataView(req.url, 'backups', view,
                                                marker)
     return wsgi.Result(paged.data(), 200)
Beispiel #14
0
    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]
        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)
Beispiel #15
0
    def index(self, req, tenant_id):
        """Return a list of clusters."""
        LOG.debug("Showing a list of clusters for Tenant '%s'" % tenant_id)
        LOG.info(_("req : '%s'\n\n") % req)

        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)
Beispiel #16
0
 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)
Beispiel #17
0
    def instances(self, req, tenant_id, id):
        context = req.environ[wsgi.CONTEXT_KEY]
        configuration = models.Configuration.load(context, id)
        self.authorize_config_action(context, 'instances', configuration)

        kwargs = {
            'configuration_id': configuration.id,
            'deleted': False
        }
        if not context.is_admin:
            kwargs['tenant_id'] = context.tenant
        instances = instances_models.DBInstance.find_all(**kwargs)

        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)