Exemplo n.º 1
0
    def test_update_project_tenant_update_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # get/init
        api.tenant_get(IsA(http.HttpRequest), self.tenant.id, admin=True) \
            .AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        workflow_data = {}
        for user in users:
            api.roles_for_user(IsA(http.HttpRequest),
                               user.id,
                               self.tenant.id).AndReturn(roles)
            role_ids = [role.id for role in roles]
            if role_ids:
                workflow_data.setdefault("role_" + role_ids[0], []) \
                             .append(user.id)

        # update some fields
        project._info["name"] = "updated name"
        project._info["description"] = "updated description"
        quota.metadata_items = 444
        quota.volumes = 444

        updated_project = {"tenant_name": project._info["name"],
                           "tenant_id": project.id,
                           "description": project._info["description"],
                           "enabled": project.enabled}
        updated_quota = self._get_quota_info(quota)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        # handle
        api.tenant_update(IsA(http.HttpRequest), **updated_project) \
            .AndRaise(self.exceptions.keystone)

        self.mox.ReplayAll()

        # submit form data
        project_data = {"name": project._info["name"],
                         "id": project.id,
                         "description": project._info["description"],
                         "enabled": project.enabled}
        workflow_data.update(project_data)
        workflow_data.update(updated_quota)
        url = reverse('horizon:admin:projects:update',
                      args=[self.tenant.id])
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 2
0
    def test_update_project_when_default_role_does_not_exist(self):
        project = self.tenants.first()
        quota = self.quotas.first()

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .AndReturn(None)  # Default role doesn't exist
        api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
                                admin=True) \
            .AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest),
                                     tenant_id=self.tenant.id) \
            .AndReturn(quota)
        self.mox.ReplayAll()

        url = reverse('horizon:admin:projects:update',
                      args=[self.tenant.id])

        try:
            # Avoid the log message in the test output when the workflow's
            # step action cannot be instantiated
            logging.disable(logging.ERROR)
            with self.assertRaises(exceptions.NotFound):
                res = self.client.get(url)
        finally:
            logging.disable(logging.NOTSET)
Exemplo n.º 3
0
    def test_get_quota_data_cinder_exception(self):
        self._mock_service_enabled(compute_enabled=False)
        self.mock_tenant_quota_get.side_effect = \
            cinder.cinder_exception.ClientException('test')

        quotas.get_tenant_quota_data(self.request)

        self._check_service_enabled({'compute': 1, 'network': 1, 'volume': 1})
        self.mock_tenant_quota_get.assert_called_once_with(
            test.IsHttpRequest(), '1')
        self.mock_handle.assert_called_once_with(
            test.IsHttpRequest(),
            _("Unable to retrieve volume limit information."))
Exemplo n.º 4
0
    def test_update_project_get(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        domain_id = self._get_domain_id()
        users = self._get_all_users(domain_id)
        roles = self.roles.list()

        api.keystone.tenant_get(IsA(http.HttpRequest),
                                self.tenant.id, admin=True) \
            .AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest),
                                     tenant_id=self.tenant.id) \
            .AndReturn(quota)

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
            .AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)) \
            .MultipleTimes().AndReturn(roles)

        for user in users:
            api.keystone.roles_for_user(IsA(http.HttpRequest),
                                        user.id,
                                        self.tenant.id).AndReturn(roles)

        self.mox.ReplayAll()

        url = reverse('horizon:admin:projects:update',
                      args=[self.tenant.id])
        res = self.client.get(url)

        self.assertTemplateUsed(res, WorkflowView.template_name)

        workflow = res.context['workflow']
        self.assertEqual(res.context['workflow'].name, UpdateProject.name)

        step = workflow.get_step("update_info")
        self.assertEqual(step.action.initial['ram'], quota.get('ram').limit)
        self.assertEqual(step.action.initial['injected_files'],
                         quota.get('injected_files').limit)
        self.assertEqual(step.action.initial['name'], project.name)
        self.assertEqual(step.action.initial['description'],
                         project.description)
        self.assertQuerysetEqual(workflow.steps,
                            ['<UpdateProjectInfo: update_info>',
                             '<UpdateProjectMembers: update_members>',
                             '<UpdateProjectQuota: update_quotas>'])
Exemplo n.º 5
0
    def get_initial(self):
        initial = super(UpdateQuotaView, self).get_initial()
        user = self.get_object()

        # try:
        #     user_account = billing.RequestClient(self.request).get_account(project_id=user.project_id)
        # except Exception:
        #     redirect = reverse("horizon:identity:account:index")
        #     exceptions.handle(self.request,
        #                       _('Unable to retrieve user account details.'),
        #                       redirect=redirect)
        initial['user_id'] = user.id
        initial['region_id'] = self.request.user.services_region
        initial['project_id'] = user.default_project_id
        # initial['user_type'] = user_account['type']
        # initial['credit_line'] = user_account['credit_line']
        try:
            # get initial project quota
            quota_data = quotas.get_tenant_quota_data(self.request,
                                                      tenant_id=user.default_project_id,
                                                      region=self.request.user.services_region)
            if api.base.is_service_enabled(self.request, 'network') and \
                    api.neutron.is_quotas_extension_supported(self.request):
                quota_data += api.neutron.tenant_quota_get(
                    self.request, tenant_id=user.default_project_id, region=self.request.user.services_region)
            for field in quotas.QUOTA_FIELDS:
                initial[field] = quota_data.get(field).limit
        except Exception:
            redirect = reverse("horizon:identity:account:index")
            exceptions.handle(self.request,
                              _('Unable to retrieve project details.'),
                              redirect=redirect)
        return initial
Exemplo n.º 6
0
    def get_initial(self):
        initial = super(UpdateProjectView, self).get_initial()

        project_id = self.kwargs['tenant_id']
        initial['project_id'] = project_id

        try:
            # get initial project info
            project_info = api.keystone.tenant_get(self.request, project_id,
                                                   admin=True)
            for field in PROJECT_INFO_FIELDS:
                initial[field] = getattr(project_info, field, None)

            # get initial project quota
            quota_data = quotas.get_tenant_quota_data(self.request,
                                                      tenant_id=project_id)
            if api.base.is_service_enabled(self.request, 'network') and \
                    api.neutron.is_quotas_extension_supported(self.request):
                quota_data += api.neutron.tenant_quota_get(self.request,
                                                          tenant_id=project_id)
            for field in quotas.QUOTA_FIELDS:
                initial[field] = quota_data.get(field).limit
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve project details.'),
                              redirect=reverse(INDEX_URL))
        return initial
Exemplo n.º 7
0
    def test_update_project_get(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        api.keystone.tenant_get(IsA(http.HttpRequest),
                                self.tenant.id, admin=True) \
            .AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest),
                                     tenant_id=self.tenant.id) \
            .AndReturn(quota)

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        for user in users:
            api.keystone.roles_for_user(IsA(http.HttpRequest),
                                        user.id,
                                        self.tenant.id).AndReturn(roles)

        self.mox.ReplayAll()

        url = reverse('horizon:admin:projects:update',
                      args=[self.tenant.id])
        res = self.client.get(url)

        self.assertTemplateUsed(res, WorkflowView.template_name)

        workflow = res.context['workflow']
        self.assertEqual(res.context['workflow'].name, UpdateProject.name)

        step = workflow.get_step("update_info")
        self.assertEqual(step.action.initial['ram'], quota.get('ram').limit)
        self.assertEqual(step.action.initial['injected_files'],
                         quota.get('injected_files').limit)
        self.assertEqual(step.action.initial['name'], project.name)
        self.assertEqual(step.action.initial['description'],
                         project.description)
        self.assertQuerysetEqual(workflow.steps,
                            ['<UpdateProjectInfo: update_info>',
                             '<UpdateProjectMembers: update_members>',
                             '<UpdateProjectQuota: update_quotas>'])
Exemplo n.º 8
0
    def get_initial(self):

        if (api.keystone.is_multi_domain_enabled()
                and not api.keystone.is_cloud_admin(self.request)):
            self.workflow_class = project_workflows.UpdateProjectNoQuota

        initial = super(UpdateProjectView, self).get_initial()

        project_id = self.kwargs['tenant_id']
        initial['project_id'] = project_id

        try:
            # get initial project info
            project_info = api.keystone.tenant_get(self.request,
                                                   project_id,
                                                   admin=True)
            for field in PROJECT_INFO_FIELDS:
                initial[field] = getattr(project_info, field, None)

            if keystone.VERSIONS.active >= 3:
                # get extra columns info
                ex_info = getattr(settings, 'PROJECT_TABLE_EXTRA_INFO', {})
                for ex_field in ex_info:
                    initial[ex_field] = getattr(project_info, ex_field, None)

                # Retrieve the domain name where the project belong
                try:
                    if policy.check((("identity", "identity:get_domain"), ),
                                    self.request):
                        domain = api.keystone.domain_get(
                            self.request, initial["domain_id"])
                        initial["domain_name"] = domain.name

                    else:
                        domain = api.keystone.get_default_domain(self.request)
                        initial["domain_name"] = domain.name

                except Exception:
                    exceptions.handle(self.request,
                                      _('Unable to retrieve project domain.'),
                                      redirect=reverse(INDEX_URL))

            # get initial project quota
            if keystone.is_cloud_admin(self.request):
                quota_data = quotas.get_tenant_quota_data(self.request,
                                                          tenant_id=project_id)
                if api.base.is_service_enabled(self.request, 'network') and \
                        api.neutron.is_quotas_extension_supported(
                            self.request):
                    quota_data += api.neutron.tenant_quota_get(
                        self.request, tenant_id=project_id)
                for field in quotas.QUOTA_FIELDS:
                    initial[field] = quota_data.get(field).limit
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve project details.'),
                              redirect=reverse(INDEX_URL))
        return initial
Exemplo n.º 9
0
def tenant_quota_usages(request):

    cloud = None
    if 'cloud' in request.GET:
        cloud = request.GET['cloud']
    elif 'cloud' in request.POST:
        cloud = request.POST['cloud']

    # Get our quotas and construct our usage object.
    disabled_quotas = []
    if not is_service_enabled(request, 'volume'):
        disabled_quotas.extend(['volumes', 'gigabytes'])

    usages = QuotaUsage()
    for quota in get_tenant_quota_data(request, disabled_quotas):
        usages.add_quota(quota)

    # Get our usages.
    floating_ips = nova.tenant_floating_ip_list(request)
    #flavors = dict([(f.id, f) for f in nova.flavor_list(request) if limit_by_cloud(f) ])
    flavors = dict([(f.id, f) for f in nova.flavor_list(request) ])

    instances = nova.server_list(request)
    if cloud is not None:
        instances = [instance for instance in instances 
            if get_cloud(instance) == cloud]

    # Fetch deleted flavors if necessary.
    missing_flavors = [instance.flavor['id'] for instance in instances
                       if instance.flavor['id'] not in flavors]
    for missing in missing_flavors:
        if missing not in flavors:
            try:
                flavors[missing] = nova.flavor_get(request, missing)
            except:
                flavors[missing] = {}
                exceptions.handle(request, ignore=True)

    usages.tally('instances', len(instances))
    usages.tally('floating_ips', len(floating_ips))

    if 'volumes' not in disabled_quotas:
        volumes = cinder.volume_list(request)
        usages.tally('gigabytes', sum([int(v.size) for v in volumes]))
        usages.tally('volumes', len(volumes))

    # Sum our usage based on the flavors of the instances.
    for flavor in [flavors[instance.flavor['id']] for instance in instances]:
        usages.tally('cores', getattr(flavor, 'vcpus', None))
        usages.tally('ram', getattr(flavor, 'ram', None))

    # Initialise the tally if no instances have been launched yet
    if len(instances) == 0:
        usages.tally('cores', 0)
        usages.tally('ram', 0)

    return usages
Exemplo n.º 10
0
    def get_initial(self):

        if (api.keystone.is_multi_domain_enabled() and
                not api.keystone.is_cloud_admin(self.request)):
            self.workflow_class = project_workflows.UpdateProjectNoQuota

        initial = super(UpdateProjectView, self).get_initial()

        project_id = self.kwargs['tenant_id']
        initial['project_id'] = project_id

        try:
            # get initial project info
            project_info = api.keystone.tenant_get(self.request, project_id,
                                                   admin=True)
            for field in PROJECT_INFO_FIELDS:
                initial[field] = getattr(project_info, field, None)

            if keystone.VERSIONS.active >= 3:
                # get extra columns info
                ex_info = getattr(settings, 'PROJECT_TABLE_EXTRA_INFO', {})
                for ex_field in ex_info:
                    initial[ex_field] = getattr(project_info, ex_field, None)

                # Retrieve the domain name where the project belong
                try:
                    if policy.check((("identity", "identity:get_domain"),),
                                    self.request):
                        domain = api.keystone.domain_get(self.request,
                                                         initial["domain_id"])
                        initial["domain_name"] = domain.name

                    else:
                        domain = api.keystone.get_default_domain(self.request)
                        initial["domain_name"] = domain.name

                except Exception:
                    exceptions.handle(self.request,
                                      _('Unable to retrieve project domain.'),
                                      redirect=reverse(INDEX_URL))

            # get initial project quota
            if keystone.is_cloud_admin(self.request):
                quota_data = quotas.get_tenant_quota_data(self.request,
                                                          tenant_id=project_id)
                if api.base.is_service_enabled(self.request, 'network') and \
                        api.neutron.is_quotas_extension_supported(
                            self.request):
                    quota_data += api.neutron.tenant_quota_get(
                        self.request, tenant_id=project_id)
                for field in quotas.QUOTA_FIELDS:
                    initial[field] = quota_data.get(field).limit
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve project details.'),
                              redirect=reverse(INDEX_URL))
        return initial
Exemplo n.º 11
0
    def test_update_project_get(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        api.tenant_get(IsA(http.HttpRequest), self.tenant.id, admin=True).AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        for user in users:
            api.roles_for_user(IsA(http.HttpRequest), user.id, self.tenant.id).AndReturn(roles)

        self.mox.ReplayAll()

        url = reverse("horizon:admin:projects:update", args=[self.tenant.id])
        res = self.client.get(url)

        self.assertTemplateUsed(res, "admin/projects/update.html")

        workflow = res.context["workflow"]
        self.assertEqual(res.context["workflow"].name, UpdateProject.name)

        step = workflow.get_step("update_info")
        self.assertEqual(step.action.initial["ram"], quota.get("ram").limit)
        self.assertEqual(step.action.initial["injected_files"], quota.get("injected_files").limit)
        self.assertEqual(step.action.initial["name"], project.name)
        self.assertEqual(step.action.initial["description"], project.description)
        self.assertQuerysetEqual(
            workflow.steps,
            [
                "<UpdateProjectInfo: update_info>",
                "<UpdateProjectMembers: update_members>",
                "<UpdateProjectQuota: update_quotas>",
            ],
        )
Exemplo n.º 12
0
    def test_update_project_when_default_role_does_not_exist(self):
        project = self.tenants.first()
        quota = self.quotas.first()

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .AndReturn(None)  # Default role doesn't exist
        api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
                                admin=True) \
            .AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest)).AndReturn(quota)
        self.mox.ReplayAll()

        url = reverse('horizon:admin:projects:update', args=[self.tenant.id])

        try:
            # Avoid the log message in the test output when the workflow's
            # step action cannot be instantiated
            logging.disable(logging.ERROR)
            with self.assertRaises(exceptions.NotFound):
                res = self.client.get(url)
        finally:
            logging.disable(logging.NOTSET)
Exemplo n.º 13
0
    def get_initial(self):
        initial = super(UpdateProjectView, self).get_initial()

        project_id = self.kwargs['tenant_id']
        initial['project_id'] = project_id

        try:
            # get initial project info
            if is_m1_user_admin(self.request):
                project_info = get_project(self.request, project_id)
            else:
                project_info = api.keystone.tenant_get(self.request,
                                                       project_id,
                                                       admin=True)
            for field in PROJECT_INFO_FIELDS:
                initial[field] = getattr(project_info, field, None)

            # Retrieve the domain name where the project belong
            if keystone.VERSIONS.active >= 3:
                try:
                    if is_m1_user_admin(self.request):
                        domain = get_domain(self.request, initial["domain_id"])
                    else:
                        domain = api.keystone.domain_get(
                            self.request, initial["domain_id"])
                    initial["domain_name"] = domain.name
                except Exception:
                    exceptions.handle(self.request,
                                      _('Unable to retrieve project domain.'),
                                      redirect=reverse(INDEX_URL))

            # get initial project quota
            quota_data = quotas.get_tenant_quota_data(self.request,
                                                      tenant_id=project_id)
            if api.base.is_service_enabled(self.request, 'network') and \
                    api.neutron.is_quotas_extension_supported(self.request):

                if is_m1_user_admin(self.request):
                    quota_data += get_tenant_quota_neutron(
                        self.request, tenant_id=project_id)
                else:
                    quota_data += api.neutron.tenant_quota_get(
                        self.request, tenant_id=project_id)

            for field in quotas.QUOTA_FIELDS:
                initial[field] = quota_data.get(field).limit
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve project details.'),
                              redirect=reverse(INDEX_URL))
        return initial
Exemplo n.º 14
0
 def get_initial(self):
     initial = super().get_initial()
     project_id = self.kwargs['tenant_id']
     initial['project_id'] = project_id
     try:
         # get initial project quota
         if keystone.is_cloud_admin(self.request):
             quota_data = quotas.get_tenant_quota_data(self.request,
                                                       tenant_id=project_id)
             for field in quotas.QUOTA_FIELDS:
                 initial[field] = quota_data.get(field).limit
     except Exception:
         exceptions.handle(self.request,
                           _('Unable to retrieve project quotas.'),
                           redirect=reverse(INDEX_URL))
     initial['disabled_quotas'] = quotas.get_disabled_quotas(self.request)
     return initial
Exemplo n.º 15
0
 def get_initial(self):
     initial = super(UpdateQuotasView, self).get_initial()
     project_id = self.kwargs['tenant_id']
     initial['project_id'] = project_id
     try:
         # get initial project quota
         if keystone.is_cloud_admin(self.request):
             quota_data = quotas.get_tenant_quota_data(self.request,
                                                       tenant_id=project_id)
             for field in quotas.QUOTA_FIELDS:
                 initial[field] = quota_data.get(field).limit
     except Exception:
         exceptions.handle(self.request,
                           _('Unable to retrieve project quotas.'),
                           redirect=reverse(INDEX_URL))
     initial['disabled_quotas'] = quotas.get_disabled_quotas(self.request)
     return initial
Exemplo n.º 16
0
    def get_initial(self):
        initial = super(UpdateProjectView, self).get_initial()

        project_id = self.kwargs["tenant_id"]
        initial["project_id"] = project_id

        try:
            # get initial project info
            project_info = api.keystone.tenant_get(self.request, project_id, admin=True)
            for field in PROJECT_INFO_FIELDS:
                initial[field] = getattr(project_info, field, None)

            # get initial project quota
            quota_data = quotas.get_tenant_quota_data(self.request)
            for field in QUOTA_FIELDS:
                initial[field] = quota_data.get(field).limit
        except:
            exceptions.handle(self.request, _("Unable to retrieve project details."), redirect=reverse(INDEX_URL))
        return initial
Exemplo n.º 17
0
    def get_initial(self):
        initial = super(UpdateProjectView, self).get_initial()

        project_id = self.kwargs['tenant_id']
        initial['project_id'] = project_id

        try:
            # get initial project info
            project_info = api.tenant_get(self.request, project_id, admin=True)
            for field in PROJECT_INFO_FIELDS:
                initial[field] = getattr(project_info, field, None)

            # get initial project quota
            quota_data = quotas.get_tenant_quota_data(self.request)
            for field in QUOTA_FIELDS:
                initial[field] = quota_data.get(field).limit
        except:
            exceptions.handle(self.request,
                              _('Unable to retrieve project details.'),
                              redirect=reverse(INDEX_URL))
        return initial
Exemplo n.º 18
0
    def get_initial(self):
        initial = super(UpdateProjectView, self).get_initial()

        project_id = self.kwargs['tenant_id']
        initial['project_id'] = project_id

        try:
            # get initial project info
            project_info = api.keystone.tenant_get(self.request, project_id,
                                                   admin=True)
            for field in PROJECT_INFO_FIELDS:
                initial[field] = getattr(project_info, field, None)

            # Retrieve the domain name where the project belong
            if keystone.VERSIONS.active >= 3:
                try:
                    domain = api.keystone.domain_get(self.request,
                                                     initial["domain_id"])
                    initial["domain_name"] = domain.name
                except Exception:
                    exceptions.handle(self.request,
                                      _('Unable to retrieve project domain.'),
                                      redirect=reverse(INDEX_URL))

            # get initial project quota
            quota_data = quotas.get_tenant_quota_data(self.request,
                                                      tenant_id=project_id,
                                                      region=self.request.user.services_region)
            if api.base.is_service_enabled(self.request, 'network') and \
                    api.neutron.is_quotas_extension_supported(self.request):
                quota_data += api.neutron.tenant_quota_get(
                    self.request, tenant_id=project_id, region=self.request.user.services_region)
            for field in quotas.QUOTA_FIELDS:
                initial[field] = quota_data.get(field).limit
            initial['region_id'] = self.request.user.services_region
        except Exception:
            exceptions.handle(self.request,
                              _('Unable to retrieve project details.'),
                              redirect=reverse(INDEX_URL))
        return initial
Exemplo n.º 19
0
    def get_initial(self):
        initial = super(UpdateQuotaView, self).get_initial()
        user = self.get_object()

        # try:
        #     user_account = billing.RequestClient(self.request).get_account(project_id=user.project_id)
        # except Exception:
        #     redirect = reverse("horizon:identity:account:index")
        #     exceptions.handle(self.request,
        #                       _('Unable to retrieve user account details.'),
        #                       redirect=redirect)
        initial['user_id'] = user.id
        initial['region_id'] = self.request.user.services_region
        initial['project_id'] = user.default_project_id
        # initial['user_type'] = user_account['type']
        # initial['credit_line'] = user_account['credit_line']
        try:
            # get initial project quota
            quota_data = quotas.get_tenant_quota_data(
                self.request,
                tenant_id=user.default_project_id,
                region=self.request.user.services_region)
            if api.base.is_service_enabled(self.request, 'network') and \
                    api.neutron.is_quotas_extension_supported(self.request):
                quota_data += api.neutron.tenant_quota_get(
                    self.request,
                    tenant_id=user.default_project_id,
                    region=self.request.user.services_region)
            for field in quotas.QUOTA_FIELDS:
                initial[field] = quota_data.get(field).limit
        except Exception:
            redirect = reverse("horizon:identity:account:index")
            exceptions.handle(self.request,
                              _('Unable to retrieve project details.'),
                              redirect=redirect)
        return initial
Exemplo n.º 20
0
    def test_update_project_member_update_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # get/init
        api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
                                admin=True) \
            .AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest),
                                     tenant_id=self.tenant.id) \
            .AndReturn(quota)

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        workflow_data = {}
        for user in users:
            api.keystone.roles_for_user(IsA(http.HttpRequest),
                                        user.id,
                                        self.tenant.id).AndReturn(roles)
        workflow_data["role_1"] = ['1', '3']  # admin role
        workflow_data["role_2"] = ['1', '2', '3']  # member role

        # update some fields
        project._info["name"] = "updated name"
        project._info["description"] = "updated description"
        quota.metadata_items = 444
        quota.volumes = 444

        updated_project = {"tenant_name": project._info["name"],
                           "tenant_id": project.id,
                           "description": project._info["description"],
                           "enabled": project.enabled}
        updated_quota = self._get_quota_info(quota)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        # handle
        api.keystone.tenant_update(IsA(http.HttpRequest), **updated_project) \
            .AndReturn(project)

        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)
        api.keystone.user_list(IsA(http.HttpRequest),
                               tenant_id=self.tenant.id).AndReturn(users)

        # admin user - try to remove all roles on current project, warning
        api.keystone.roles_for_user(IsA(http.HttpRequest), '1',
                                    self.tenant.id) \
                           .AndReturn(roles)

        # member user 1 - has role 1, will remove it
        api.keystone.roles_for_user(IsA(http.HttpRequest), '2',
                                    self.tenant.id) \
                           .AndReturn((roles[1],))

        # member user 3 - has role 2
        api.keystone.roles_for_user(IsA(http.HttpRequest), '3',
                                    self.tenant.id) \
                           .AndReturn((roles[0],))
        # add role 2
        api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
                                          tenant_id=self.tenant.id,
                                          user_id='3',
                                          role_id='2')\
                                 .AndRaise(self.exceptions.nova)

        self.mox.ReplayAll()

        # submit form data
        project_data = {"name": project._info["name"],
                         "id": project.id,
                         "description": project._info["description"],
                         "enabled": project.enabled}
        workflow_data.update(project_data)
        workflow_data.update(updated_quota)
        url = reverse('horizon:admin:projects:update',
                      args=[self.tenant.id])
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertMessageCount(error=1, warning=0)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 21
0
    def test_update_project_tenant_update_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # get/init
        api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
                                admin=True) \
            .AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest),
                                     tenant_id=self.tenant.id) \
            .AndReturn(quota)

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        workflow_data = {}
        for user in users:
            api.keystone.roles_for_user(IsA(http.HttpRequest),
                                        user.id,
                                        self.tenant.id).AndReturn(roles)
            role_ids = [role.id for role in roles]
            if role_ids:
                workflow_data.setdefault("role_" + role_ids[0], []) \
                             .append(user.id)

        # update some fields
        project._info["name"] = "updated name"
        project._info["description"] = "updated description"
        quota.metadata_items = 444
        quota.volumes = 444

        updated_project = {"tenant_name": project._info["name"],
                           "tenant_id": project.id,
                           "description": project._info["description"],
                           "enabled": project.enabled}
        updated_quota = self._get_quota_info(quota)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        # handle
        api.keystone.tenant_update(IsA(http.HttpRequest), **updated_project) \
            .AndRaise(self.exceptions.keystone)

        self.mox.ReplayAll()

        # submit form data
        project_data = {"name": project._info["name"],
                         "id": project.id,
                         "description": project._info["description"],
                         "enabled": project.enabled}
        workflow_data.update(project_data)
        workflow_data.update(updated_quota)
        url = reverse('horizon:admin:projects:update',
                      args=[self.tenant.id])
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 22
0
    def get_data(self):
            instances, has_more0 = api.nova.server_list(self.request,all_tenants=True)
            ceiloclient = cc(self.request)
            hypervisor_list = api.nova.hypervisor_list(self.request)
            flavors = api.nova.flavor_list(self.request)
            full_flavors = SortedDict([(f.id, f) for f in flavors])

            cpu_util_avg_tmp = {}
            mem_util_avg_tmp = {}
            cpu_util_avg_tmp['cpu_util'] = []
            mem_util_avg_tmp['memory_util'] = []

            totals = { "local_gb":0, "memory_mb":0, "vcpus":0, "vcpus_flavored":0, "vcpu_util":0.0000000001, "memory_util":0.0000000001, }
            qs = { "cores":0, "ram":0, "gigabytes":0 }

            hvs_load_avg_list = []

            for hv in hypervisor_list:
               uptime = api.nova.hypervisor_uptime(self.request, hv)._info
               m = re.match("(.+)\sup\s+(.+),\s+(.+)\susers,\s+load average:\s(.+)", uptime['uptime'])
               if m:
                  (min1,min5,min15) = m.group(4).split(',')
                  hvs_load_avg_list.append([{"hv_hostname":hv.hypervisor_hostname, "min1":min1, "min5":min5, "min15":min15 }])
               for key, value in hv.to_dict().iteritems():
                   if key in ("local_gb","memory_mb","vcpus"):
                      totals[str(key)] = value

            hvs_load_avg_tmp = {}
            hvs_load_avg_tmp['date'] = time.time()
            for item in hvs_load_avg_list:
                it = dict(item[0])
                hv_hostname = ""
                for key,value in sorted(it.iteritems()):
                    if key == 'hv_hostname':
                       hv_hostname = value
                       hvs_load_avg_tmp[hv_hostname] = 0
                    if key == 'min15':
                       hvs_load_avg_tmp[hv_hostname] = value

            self.hvs_load_avg.append([hvs_load_avg_tmp])

            self.ten_list = []

            domain_context = self.request.session.get('domain_context', None)

            tenant_list, has_more1  = api.keystone.tenant_list(self.request, domain=domain_context)

            if tenant_list:

               for tenant in tenant_list:

                   quota_data = quotas.get_tenant_quota_data(self.request, tenant_id=tenant.id)
                   project = { "cpu_util": 0.0, "cpu_flavored": 0, "memory_util": 0, "memory_flavored": 0, "disk_util": 0, "disk_flavored": 0 }

                   for field in ("cores","ram","gigabytes"):
                       qs[str(field)] = quota_data.get(field).limit

                   for instance in instances:
                       if instance and instance.tenant_id == tenant.id:
                          query = [dict(field='resource_id', op='eq', value = instance.id)]
                          cpu = ceiloclient.samples.list(meter_name='cpu_util', limit=1, q=query)
                          mem = ceiloclient.samples.list(meter_name='memory.resident', limit=1, q=query)
                          disk = ceiloclient.samples.list(meter_name='disk.allocation', limit=1, q=query)

                          flavor_id = instance.flavor["id"]
                          if flavor_id in full_flavors:
                             instance.full_flavor = full_flavors[flavor_id]
                          else:
                             instance.full_flavor = api.nova.flavor_get(self.request, flavor_id)

                          try:
                             project['cpu_flavored'] += instance.full_flavor.vcpus
                             totals['vcpus_flavored'] += instance.full_flavor.vcpus
                             project['memory_flavored'] += instance.full_flavor.ram
                             project['disk_flavored'] += instance.full_flavor.disk
                          except:
                             LOG.error("Error flavor for instance: %s" % instance.id)

                          try:
                             project['cpu_util'] += cpu[0].counter_volume * instance.full_flavor.vcpus
                             totals['vcpu_util'] += project['cpu_util']
                             project['memory_util'] += mem[0].counter_volume
                             totals['memory_util'] += project['memory_util']
                             project['disk_util'] += disk[0].counter_volume*0.000000001024
                          except:
                             LOG.error("Error ceilometer for instance: %s" % instance.id)


                   cpu_util_avg_tmp['cpu_util'].append(project['cpu_util'])
                   mem_util_avg_tmp['memory_util'].append(project['memory_util'])

                   tenant.cpu_util = lambda:'-'
                   setattr(tenant,"cpu_util", round(project['cpu_util'],3))
                   tenant.memory_util = lambda:'-'
                   setattr(tenant,"memory_util", round(project['memory_util'],3))
                   tenant.disk_util = lambda:'-'
                   setattr(tenant,"disk_util", round(project['disk_util'],3))

                   tenant.cpu_flavored = lambda:'-'
                   setattr(tenant,"cpu_flavored",project['cpu_flavored'])
                   tenant.memory_flavored = lambda:'-'
                   setattr(tenant,"memory_flavored",project['memory_flavored'])
                   tenant.disk_flavored = lambda:'-'
                   setattr(tenant,"disk_flavored",project['disk_flavored'])

                   tenant.cpu_quota = lambda:'-'
                   setattr(tenant,"cpu_quota",qs['cores'])
                   tenant.memory_quota = lambda:'-'
                   setattr(tenant,"memory_quota",qs['ram'])
                   tenant.disk_quota = lambda:'-'
                   setattr(tenant,"disk_quota",qs['gigabytes'])

                   tenant.cpu_total = lambda:'-'
                   setattr(tenant,"cpu_total",totals['vcpus'])
                   tenant.memory_total = lambda:'-'
                   setattr(tenant,"memory_total",totals['memory_mb'])
                   tenant.disk_total = lambda:'-'
                   setattr(tenant,"disk_total",totals['local_gb'])

            self.ten_list = tenant_list
            #self.ten_list += tenant_list

            cpu_util_avg_tmp['date'] = int(time.time())
            mem_util_avg_tmp['date'] = int(time.time())
            try:
               cpu_util_avg_tmp['cpu_util_avg'] = 100 / ((totals['vcpus_flavored'] * 100) / totals['vcpu_util'])
               mem_util_avg_tmp['memory_util_avg'] = 100 / (totals['memory_mb'] / totals['memory_util'])
            except:
               pass

            LOG.info(totals)
            LOG.info(cpu_util_avg_tmp)
            LOG.info(mem_util_avg_tmp)

            try:
                self.cpu_util_avg.append([{"date":cpu_util_avg_tmp['date'],"cpu":cpu_util_avg_tmp['cpu_util_avg']}])
                self.mem_util_avg.append([{"date":mem_util_avg_tmp['date'],"memory":mem_util_avg_tmp['memory_util_avg']}])
            except:
                pass

            return self.ten_list
Exemplo n.º 23
0
    def test_update_project_quota_update_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        domain_id = self._get_domain_id()
        users = self._get_all_users(domain_id)
        proj_users = self._get_proj_users(project.id)
        roles = self.roles.list()

        # get/init
        api.keystone.tenant_get(IsA(http.HttpRequest), self.tenant.id,
                                admin=True) \
            .AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest),
                                     tenant_id=self.tenant.id) \
            .AndReturn(quota)

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
            .AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)) \
            .MultipleTimes().AndReturn(roles)

        workflow_data = {}

        for user in users:
            api.keystone.roles_for_user(IsA(http.HttpRequest),
                                        user.id,
                                        self.tenant.id).AndReturn(roles)

        workflow_data[USER_ROLE_PREFIX + "1"] = ['1', '3']  # admin role
        workflow_data[USER_ROLE_PREFIX + "2"] = ['1', '2', '3']  # member role

        # update some fields
        project._info["name"] = "updated name"
        project._info["description"] = "updated description"
        quota[0].limit = 444
        quota[1].limit = -1

        updated_project = {"name": project._info["name"],
                           "description": project._info["description"],
                           "enabled": project.enabled}
        updated_quota = self._get_quota_info(quota)

        # handle
        api.keystone.tenant_update(IsA(http.HttpRequest),
                                   project.id,
                                   **updated_project) \
            .AndReturn(project)

        api.keystone.user_list(IsA(http.HttpRequest),
                               project=self.tenant.id).AndReturn(proj_users)

        # admin user - try to remove all roles on current project, warning
        api.keystone.roles_for_user(IsA(http.HttpRequest), '1',
                                    self.tenant.id) \
                           .AndReturn(roles)

        # member user 1 - has role 1, will remove it
        api.keystone.roles_for_user(IsA(http.HttpRequest), '2',
                                    self.tenant.id) \
                           .AndReturn((roles[1],))

        # member user 3 - has role 2
        api.keystone.roles_for_user(IsA(http.HttpRequest), '3',
                                    self.tenant.id) \
                           .AndReturn((roles[0],))
        # add role 2
        api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
                                          project=self.tenant.id,
                                          user='******',
                                          role='2')

        nova_updated_quota = dict([(key, updated_quota[key]) for key in
                                   quotas.NOVA_QUOTA_FIELDS])
        api.nova.tenant_quota_update(IsA(http.HttpRequest),
                                     project.id,
                                     **nova_updated_quota) \
                            .AndRaise(self.exceptions.nova)

        self.mox.ReplayAll()

        # submit form data
        project_data = {"name": project._info["name"],
                         "id": project.id,
                         "description": project._info["description"],
                         "enabled": project.enabled}
        workflow_data.update(project_data)
        workflow_data.update(updated_quota)
        url = reverse('horizon:admin:projects:update',
                      args=[self.tenant.id])
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertMessageCount(error=1, warning=0)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 24
0
    def _test_update_quotas_save(self, with_neutron=False):
        project = self.tenants.first()
        quota = self.quotas.first()
        quota_usages = self.quota_usages.first()

        # get/init
        quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
            .AndReturn(set())
        quotas.get_tenant_quota_data(IsA(http.HttpRequest),
                                     tenant_id=self.tenant.id) \
            .AndReturn(quota)

        quota.metadata_items = 444
        quota.volumes = 444

        updated_quota = self._get_quota_info(quota)

        # handle
        quotas.tenant_quota_usages(IsA(http.HttpRequest),
                                   tenant_id=project.id,
                                   targets=tuple(quotas.NOVA_QUOTA_FIELDS)) \
            .AndReturn(quota_usages)
        nova_updated_quota = {
            key: updated_quota[key]
            for key in quotas.NOVA_QUOTA_FIELDS
        }
        api.nova.tenant_quota_update(IsA(http.HttpRequest), project.id,
                                     **nova_updated_quota)

        quotas.tenant_quota_usages(IsA(http.HttpRequest),
                                   tenant_id=project.id,
                                   targets=tuple(quotas.CINDER_QUOTA_FIELDS)) \
            .AndReturn(quota_usages)
        cinder_updated_quota = {
            key: updated_quota[key]
            for key in quotas.CINDER_QUOTA_FIELDS
        }
        api.cinder.tenant_quota_update(IsA(http.HttpRequest), project.id,
                                       **cinder_updated_quota)
        if with_neutron:
            api.neutron.is_quotas_extension_supported(IsA(http.HttpRequest)) \
                .AndReturn(with_neutron)
            quotas.tenant_quota_usages(
                IsA(http.HttpRequest), tenant_id=project.id,
                targets=tuple(quotas.NEUTRON_QUOTA_FIELDS)) \
                .AndReturn(quota_usages)
            neutron_updated_quota = {
                key: updated_quota[key]
                for key in quotas.NEUTRON_QUOTA_FIELDS
            }
            api.neutron.tenant_quota_update(IsA(http.HttpRequest),
                                            self.tenant.id,
                                            **neutron_updated_quota)
        self.mox.ReplayAll()

        # submit form data
        workflow_data = {}
        workflow_data.update(updated_quota)
        url = reverse('horizon:identity:projects:update_quotas',
                      args=[self.tenant.id])
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertMessageCount(error=0, warning=0)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 25
0
    def test_update_project_member_update_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # get/init
        api.tenant_get(IsA(http.HttpRequest), self.tenant.id, admin=True) \
            .AndReturn(project)
        quotas.get_tenant_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        workflow_data = {}
        for user in users:
            api.roles_for_user(IsA(http.HttpRequest),
                               user.id,
                               self.tenant.id).AndReturn(roles)
        workflow_data["role_1"] = ['1', '3']  # admin role
        workflow_data["role_2"] = ['1', '2', '3']  # member role

        # update some fields
        project._info["name"] = "updated name"
        project._info["description"] = "updated description"
        quota.metadata_items = 444
        quota.volumes = 444

        updated_project = {"tenant_name": project._info["name"],
                           "tenant_id": project.id,
                           "description": project._info["description"],
                           "enabled": project.enabled}
        updated_quota = self._get_quota_info(quota)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        # handle
        api.tenant_update(IsA(http.HttpRequest), **updated_project) \
            .AndReturn(project)

        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)
        api.keystone.user_list(IsA(http.HttpRequest),
                               tenant_id=self.tenant.id).AndReturn(users)

        # admin user - try to remove all roles on current project, warning
        api.roles_for_user(IsA(http.HttpRequest), '1', self.tenant.id) \
                           .AndReturn(roles)

        # member user 1 - has role 1, will remove it
        api.roles_for_user(IsA(http.HttpRequest), '2', self.tenant.id) \
                           .AndReturn((roles[1],))

        # member user 3 - has role 2
        api.roles_for_user(IsA(http.HttpRequest), '3', self.tenant.id) \
                           .AndReturn((roles[0],))
        # add role 2
        api.add_tenant_user_role(IsA(http.HttpRequest),
                                     tenant_id=self.tenant.id,
                                     user_id='3',
                                     role_id='2')\
                                 .AndRaise(self.exceptions.nova)

        self.mox.ReplayAll()

        # submit form data
        project_data = {"name": project._info["name"],
                         "id": project.id,
                         "description": project._info["description"],
                         "enabled": project.enabled}
        workflow_data.update(project_data)
        workflow_data.update(updated_quota)
        url = reverse('horizon:admin:projects:update',
                      args=[self.tenant.id])
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertMessageCount(error=1, warning=0)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Exemplo n.º 26
0
    def get_data(self):
        instances, has_more0 = api.nova.server_list(self.request,
                                                    all_tenants=True)
        ceiloclient = cc(self.request)
        hypervisor_list = api.nova.hypervisor_list(self.request)
        flavors = api.nova.flavor_list(self.request)
        full_flavors = SortedDict([(f.id, f) for f in flavors])

        cpu_util_avg_tmp = {}
        mem_util_avg_tmp = {}
        cpu_util_avg_tmp['cpu_util'] = []
        mem_util_avg_tmp['memory_util'] = []

        totals = {
            "local_gb": 0,
            "memory_mb": 0,
            "vcpus": 0,
            "vcpus_flavored": 0,
            "vcpu_util": 0.0000000001,
            "memory_util": 0.0000000001,
        }
        qs = {"cores": 0, "ram": 0, "gigabytes": 0}

        hvs_load_avg_list = []

        for hv in hypervisor_list:
            uptime = api.nova.hypervisor_uptime(self.request, hv)._info
            m = re.match(
                "(.+)\sup\s+(.+),\s+(.+)\susers,\s+load average:\s(.+)",
                uptime['uptime'])
            if m:
                (min1, min5, min15) = m.group(4).split(',')
                hvs_load_avg_list.append([{
                    "hv_hostname": hv.hypervisor_hostname,
                    "min1": min1,
                    "min5": min5,
                    "min15": min15
                }])
            for key, value in hv.to_dict().iteritems():
                if key in ("local_gb", "memory_mb", "vcpus"):
                    totals[str(key)] = value

        hvs_load_avg_tmp = {}
        hvs_load_avg_tmp['date'] = time.time()
        for item in hvs_load_avg_list:
            it = dict(item[0])
            hv_hostname = ""
            for key, value in sorted(it.iteritems()):
                if key == 'hv_hostname':
                    hv_hostname = value
                    hvs_load_avg_tmp[hv_hostname] = 0
                if key == 'min15':
                    hvs_load_avg_tmp[hv_hostname] = value

        self.hvs_load_avg.append([hvs_load_avg_tmp])

        self.ten_list = []

        domain_context = self.request.session.get('domain_context', None)

        tenant_list, has_more1 = api.keystone.tenant_list(
            self.request, domain=domain_context)

        if tenant_list:

            for tenant in tenant_list:

                quota_data = quotas.get_tenant_quota_data(self.request,
                                                          tenant_id=tenant.id)
                project = {
                    "cpu_util": 0.0,
                    "cpu_flavored": 0,
                    "memory_util": 0,
                    "memory_flavored": 0,
                    "disk_util": 0,
                    "disk_flavored": 0
                }

                for field in ("cores", "ram", "gigabytes"):
                    qs[str(field)] = quota_data.get(field).limit

                for instance in instances:
                    if instance and instance.tenant_id == tenant.id:
                        query = [
                            dict(field='resource_id',
                                 op='eq',
                                 value=instance.id)
                        ]
                        cpu = ceiloclient.samples.list(meter_name='cpu_util',
                                                       limit=1,
                                                       q=query)
                        mem = ceiloclient.samples.list(
                            meter_name='memory.resident', limit=1, q=query)
                        disk = ceiloclient.samples.list(
                            meter_name='disk.allocation', limit=1, q=query)

                        flavor_id = instance.flavor["id"]
                        if flavor_id in full_flavors:
                            instance.full_flavor = full_flavors[flavor_id]
                        else:
                            instance.full_flavor = api.nova.flavor_get(
                                self.request, flavor_id)

                        try:
                            project[
                                'cpu_flavored'] += instance.full_flavor.vcpus
                            totals[
                                'vcpus_flavored'] += instance.full_flavor.vcpus
                            project[
                                'memory_flavored'] += instance.full_flavor.ram
                            project[
                                'disk_flavored'] += instance.full_flavor.disk
                        except:
                            LOG.error("Error flavor for instance: %s" %
                                      instance.id)

                        try:
                            project['cpu_util'] += cpu[
                                0].counter_volume * instance.full_flavor.vcpus
                            totals['vcpu_util'] += project['cpu_util']
                            project['memory_util'] += mem[0].counter_volume
                            totals['memory_util'] += project['memory_util']
                            project['disk_util'] += disk[
                                0].counter_volume * 0.000000001024
                        except:
                            LOG.error("Error ceilometer for instance: %s" %
                                      instance.id)

                cpu_util_avg_tmp['cpu_util'].append(project['cpu_util'])
                mem_util_avg_tmp['memory_util'].append(project['memory_util'])

                tenant.cpu_util = lambda: '-'
                setattr(tenant, "cpu_util", round(project['cpu_util'], 3))
                tenant.memory_util = lambda: '-'
                setattr(tenant, "memory_util", round(project['memory_util'],
                                                     3))
                tenant.disk_util = lambda: '-'
                setattr(tenant, "disk_util", round(project['disk_util'], 3))

                tenant.cpu_flavored = lambda: '-'
                setattr(tenant, "cpu_flavored", project['cpu_flavored'])
                tenant.memory_flavored = lambda: '-'
                setattr(tenant, "memory_flavored", project['memory_flavored'])
                tenant.disk_flavored = lambda: '-'
                setattr(tenant, "disk_flavored", project['disk_flavored'])

                tenant.cpu_quota = lambda: '-'
                setattr(tenant, "cpu_quota", qs['cores'])
                tenant.memory_quota = lambda: '-'
                setattr(tenant, "memory_quota", qs['ram'])
                tenant.disk_quota = lambda: '-'
                setattr(tenant, "disk_quota", qs['gigabytes'])

                tenant.cpu_total = lambda: '-'
                setattr(tenant, "cpu_total", totals['vcpus'])
                tenant.memory_total = lambda: '-'
                setattr(tenant, "memory_total", totals['memory_mb'])
                tenant.disk_total = lambda: '-'
                setattr(tenant, "disk_total", totals['local_gb'])

        self.ten_list = tenant_list
        #self.ten_list += tenant_list

        cpu_util_avg_tmp['date'] = int(time.time())
        mem_util_avg_tmp['date'] = int(time.time())
        try:
            cpu_util_avg_tmp['cpu_util_avg'] = 100 / (
                (totals['vcpus_flavored'] * 100) / totals['vcpu_util'])
            mem_util_avg_tmp['memory_util_avg'] = 100 / (totals['memory_mb'] /
                                                         totals['memory_util'])
        except:
            pass

        LOG.info(totals)
        LOG.info(cpu_util_avg_tmp)
        LOG.info(mem_util_avg_tmp)

        try:
            self.cpu_util_avg.append([{
                "date": cpu_util_avg_tmp['date'],
                "cpu": cpu_util_avg_tmp['cpu_util_avg']
            }])
            self.mem_util_avg.append([{
                "date":
                mem_util_avg_tmp['date'],
                "memory":
                mem_util_avg_tmp['memory_util_avg']
            }])
        except:
            pass

        return self.ten_list