Exemple #1
0
    def discovery(self, req, version):
        """Returns appropriate json by its version."""

        key = version
        if key in self._files:
            return self._files[key]

        session = clients.admin_session()
        keystone = clients.keystone(None, session=session)
        if not keystone.has_service_catalog():
            keystone.authenticate(token=session.get_token())
        catalog = keystone.service_catalog.get_data()
        public_url = clients.get_url_from_catalog(catalog, "gceapi")
        if not public_url:
            public_url = req.host_url
        public_url = public_url.rstrip("/")

        self._lock.acquire()
        try:
            if key in self._files:
                return self._files[key]

            jfile = self._load_file(version)
            jfile = jfile.replace("{HOST_URL}", public_url)
            self._files[key] = jfile
            return jfile
        finally:
            self._lock.release()
Exemple #2
0
    def get_item(self, context, name, scope=None):
        session = clients.admin_session()
        keystone = clients.keystone(context, session=session)
        project = keystone.projects.get(context.project_id)
        result = utils.to_dict(project)
        result["keypair"] = self._get_gce_keypair(context)
        project_id = project.id

        nova = clients.nova(context, session=session)
        nova_limits = nova.limits.get(tenant_id=project_id)
        result["nova_limits"] = dict(
            (l.name, l.value) for l in nova_limits.absolute)

        cinder_client = clients.cinder(context, session=session)
        try:
            result["cinder_quotas"] = utils.to_dict(
                cinder_client.quotas.get(project_id, usage=True))
        except TypeError:
            # NOTE(apavlov): cinderclient of version 1.0.6 and below
            # has no usage parameter
            result["cinder_quotas"] = dict([
                ("limit", x)
                for x in utils.to_dict(cinder_client.quotas.get(project_id))
            ])

        net_api = CONF.get("network_api")
        if net_api is None or ("quantum" in net_api or "neutron" in net_api):
            neutron_client = clients.neutron(context, session=session)
            result["neutron_quota"] = (
                neutron_client.show_quota(project_id)["quota"])
            result["neutron_quota"]["network_used"] = len(
                neutron_client.list_networks(tenant_id=project_id)["networks"])
            result["neutron_quota"]["floatingip_used"] = len(
                neutron_client.list_floatingips(
                    tenant_id=project_id)["floatingips"])
            result["neutron_quota"]["security_group_used"] = len(
                neutron_client.list_security_groups(
                    tenant_id=project_id)["security_groups"])
        else:
            result["neutron_quota"] = {}

        return result
Exemple #3
0
    def get_item(self, context, name, scope=None):
        project_name = context.project_name

        keystone = clients.keystone(context)
        project = [t for t in keystone.tenants.list()
                if t.name == project_name][0]

        result = utils.to_dict(project)
        result["keypair"] = self._get_gce_keypair(context)
        project_id = project.id

        nova_limits = clients.nova(context).limits.get(tenant_id=project_id)
        result["nova_limits"] = dict((l.name, l.value)
                                     for l in nova_limits.absolute)

        cinder_client = clients.cinder(context)
        try:
            result["cinder_quotas"] = utils.to_dict(
                cinder_client.quotas.get(project_id, usage=True))
        except TypeError:
            # NOTE(apavlov): cinderclient of version 1.0.6 and below
            # has no usage parameter
            result["cinder_quotas"] = dict([("limit", x)
                for x in utils.to_dict(cinder_client.quotas.get(project_id))])

        net_api = CONF.get("network_api")
        if net_api is None or ("quantum" in net_api
                               or "neutron" in net_api):
            neutron_client = clients.neutron(context)
            result["neutron_quota"] = (
                neutron_client.show_quota(project_id)["quota"])
            result["neutron_quota"]["network_used"] = len(neutron_client
                .list_networks(tenant_id=project_id)["networks"])
            result["neutron_quota"]["floatingip_used"] = len(neutron_client
                .list_floatingips(tenant_id=project_id)["floatingips"])
            result["neutron_quota"]["security_group_used"] = len(neutron_client
                .list_security_groups(tenant_id=project_id)["security_groups"])
        else:
            result["neutron_quota"] = {}

        return result