Ejemplo n.º 1
0
    def __init__(self, request, *args, **kwargs):
        super(SecurityConfigAction, self).__init__(request, *args, **kwargs)

        self.fields["security_autogroup"] = forms.BooleanField(
            label=_("Auto Security Group"),
            widget=forms.CheckboxInput(),
            help_text=_("Create security group for this Node Group."),
            required=False,
            initial=True,
        )

        try:
            groups = network.security_group_list(request)
        except Exception:
            exceptions.handle(request, _("Unable to get security group list."))
            raise

        security_group_list = [(sg.id, sg.name) for sg in groups]
        self.fields["security_groups"] = forms.MultipleChoiceField(
            label=_("Security Groups"),
            widget=forms.CheckboxSelectMultiple(),
            help_text=_("Launch instances in these security groups."),
            choices=security_group_list,
            required=False,
        )
Ejemplo n.º 2
0
def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
    floating_ips = []
    try:
        if network.floating_ip_supported(request):
            floating_ips = network.tenant_floating_ip_list(request)
    except Exception:
        pass
    usages.tally('floating_ips', len(floating_ips))

    if 'security_group' not in disabled_quotas:
        security_groups = []
        security_groups = network.security_group_list(request)
        usages.tally('security_groups', len(security_groups))

    if 'network' not in disabled_quotas:
        networks = []
        networks = neutron.network_list(request, shared=False)
        if tenant_id:
            networks = filter(lambda net: net.tenant_id == tenant_id, networks)
        usages.tally('networks', len(networks))

    if 'subnet' not in disabled_quotas:
        subnets = []
        subnets = neutron.subnet_list(request)
        usages.tally('subnets', len(subnets))

    if 'router' not in disabled_quotas:
        routers = []
        routers = neutron.router_list(request)
        if tenant_id:
            routers = filter(lambda rou: rou.tenant_id == tenant_id, routers)
        usages.tally('routers', len(routers))
Ejemplo n.º 3
0
def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
    enabled_quotas = ((NOVA_NETWORK_QUOTA_FIELDS | NEUTRON_QUOTA_FIELDS) -
                      disabled_quotas)
    if not enabled_quotas:
        return

    # NOTE(amotoki): floatingip is Neutron quota and floating_ips is
    # Nova quota. We need to check both.
    if {'floatingip', 'floating_ips'} & enabled_quotas:
        floating_ips = []
        try:
            if network.floating_ip_supported(request):
                floating_ips = network.tenant_floating_ip_list(request)
        except Exception:
            pass
        usages.tally('floating_ips', len(floating_ips))

    if 'security_group' not in disabled_quotas:
        security_groups = []
        security_groups = network.security_group_list(request)
        usages.tally('security_groups', len(security_groups))

    if 'network' not in disabled_quotas:
        networks = neutron.network_list(request, tenant_id=tenant_id)
        usages.tally('networks', len(networks))

    if 'subnet' not in disabled_quotas:
        subnets = neutron.subnet_list(request, tenant_id=tenant_id)
        usages.tally('subnets', len(subnets))

    if 'router' not in disabled_quotas:
        routers = neutron.router_list(request, tenant_id=tenant_id)
        usages.tally('routers', len(routers))
Ejemplo n.º 4
0
    def __init__(self, request, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, *args, **kwargs)

        hlps = helpers.Helpers(request)

        plugin, hadoop_version = (
            workflow_helpers.get_plugin_and_hadoop_version(request))
        process_choices = []
        try:
            version_details = saharaclient.plugin_get_version_details(
                request, plugin, hadoop_version)
            for service, processes in version_details.node_processes.items():
                for process in processes:
                    process_choices.append(
                        (str(service) + ":" + str(process), process))
        except Exception:
            exceptions.handle(request,
                              _("Unable to generate process choices."))

        if not saharaclient.SAHARA_AUTO_IP_ALLOCATION_ENABLED:
            pools = network.floating_ip_pools_list(request)
            pool_choices = [(pool.id, pool.name) for pool in pools]
            pool_choices.insert(0, (None, "Do not assign floating IPs"))

            self.fields['floating_ip_pool'] = forms.ChoiceField(
                label=_("Floating IP Pool"),
                choices=pool_choices,
                required=False)

        self.fields["autogroup"] = forms.BooleanField(
            label=_("Auto Security Group"),
            widget=forms.CheckboxInput(),
            help_text=_("Create security group for this Node Group."),
            required=False)

        groups = network.security_group_list(request)
        security_group_list = [(sg.id, sg.name) for sg in groups]
        self.fields["groups"] = forms.MultipleChoiceField(
            label=_("Security Groups"),
            widget=forms.CheckboxSelectMultiple(),
            help_text=_("Launch instances in these security groups."),
            choices=security_group_list,
            required=False)

        self.fields["processes"] = forms.MultipleChoiceField(
            label=_("Processes"),
            widget=forms.CheckboxSelectMultiple(),
            help_text=_("Processes to be launched in node group"),
            choices=process_choices)

        self.fields["plugin_name"] = forms.CharField(
            widget=forms.HiddenInput(), initial=plugin)
        self.fields["hadoop_version"] = forms.CharField(
            widget=forms.HiddenInput(), initial=hadoop_version)

        node_parameters = hlps.get_general_node_group_configs(
            plugin, hadoop_version)
        for param in node_parameters:
            self.fields[param.name] = workflow_helpers.build_control(param)
Ejemplo n.º 5
0
 def get_security_groups_data(self):
     try:
         security_groups = network.security_group_list(self.request)
     except:
         security_groups = []
         exceptions.handle(self.request,
                           _('Unable to retrieve security groups.'))
     return security_groups
Ejemplo n.º 6
0
 def get_security_groups_data(self):
     try:
         security_groups = network.security_group_list(self.request)
     except Exception:
         security_groups = []
         exceptions.handle(self.request,
                           _('Unable to retrieve security groups.'))
     return security_groups
Ejemplo n.º 7
0
 def get_security_groups_data(self):
     try:
         security_groups = network.security_group_list(self.request)
     except neutron_exc.ConnectionFailed:
         security_groups = []
         exceptions.handle(self.request)
     except Exception:
         security_groups = []
         exceptions.handle(self.request,
                           _('Unable to retrieve security groups.'))
     return security_groups
Ejemplo n.º 8
0
 def get_security_groups_data(self):
     try:
         security_groups = network.security_group_list(self.request)
     except neutron_exc.ConnectionFailed:
         security_groups = []
         exceptions.handle(self.request)
     except Exception:
         security_groups = []
         exceptions.handle(self.request,
                           _('Unable to retrieve security groups.'))
     return sorted(security_groups, key=lambda group: group.name)
Ejemplo n.º 9
0
 def __init__(self, request, *args, **kwargs):
     super(ImportGroup, self).__init__(request, *args, **kwargs)
     err_msg = _('Unable to retrieve security group list. '
                 'Please try again later.')
     # Get list of available security groups
     all_groups = []
     try:
         all_groups = network.security_group_list(request)
     except Exception:
         exceptions.handle(request, err_msg)
     groups_list = [(group.id, group.name) for group in all_groups]
     self.fields['security_group'].choices = groups_list
Ejemplo n.º 10
0
def _get_tenant_network_usages(request,
                               usages,
                               disabled_quotas,
                               tenant_id,
                               region=None):
    floating_ips = []
    try:
        if network.floating_ip_supported(request):
            floating_ips = network.floating_ip_list(request,
                                                    region=region,
                                                    tenant_id=tenant_id)
            if tenant_id:
                floating_ips = filter(lambda fip: fip.tenant_id == tenant_id,
                                      floating_ips)
    except Exception:
        raise
        pass
    usages.tally('floating_ips', len(floating_ips))

    if 'security_group' not in disabled_quotas:
        security_groups = []
        security_groups = network.security_group_list(request)
        usages.tally('security_groups', len(security_groups))

    if 'network' not in disabled_quotas:
        networks = []
        networks = neutron.network_list(request, shared=False, region=region)
        if tenant_id:
            networks = filter(lambda net: net.tenant_id == tenant_id, networks)
        usages.tally('networks', len(networks))

    if 'subnet' not in disabled_quotas:
        subnets = []
        subnets = neutron.subnet_list(request, region=region)
        if tenant_id:
            subnets = filter(lambda subnet: subnet.tenant_id == tenant_id,
                             subnets)
        usages.tally('subnets', len(subnets))

    if 'router' not in disabled_quotas:
        routers = []
        routers = neutron.router_list(request, region=region)
        if tenant_id:
            routers = filter(lambda rou: rou.tenant_id == tenant_id, routers)
        usages.tally('routers', len(routers))
    if 'pool' not in disabled_quotas:
        pools = []
        pools = lbaas.pool_list(request)
        if tenant_id:
            pools = filter(lambda p: p.tenant_id == tenant_id, pools)
        usages.tally('pool', len(pools))
Ejemplo n.º 11
0
    def get_sg_id(self):
        sg_id = None
        try:
            security_groups = network.security_group_list(self.request)
        except Exception:
            security_groups = []
            exceptions.handle(self.request,
                              _('Unable to retrieve security groups.'))

        for security_group in security_groups:
            if security_group['name'] == 'default':
                sg_id = security_group['id']
                break

        return sg_id
Ejemplo n.º 12
0
    def get_sg_id(self):
        sg_id = None
        try:
            security_groups = network.security_group_list(self.request)
        except Exception:
            security_groups = []
            exceptions.handle(self.request,
                              _('Unable to retrieve security groups.'))

        for security_group in security_groups:
            if security_group['name'] == 'default':
                sg_id = security_group['id']
                break

        return sg_id
Ejemplo n.º 13
0
def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
    floating_ips = []
    try:
        if network.floating_ip_supported(request):
            floating_ips = network.tenant_floating_ip_list(request)
    except Exception:
        pass
    usages.tally('floating_ips', len(floating_ips))

    if 'security_group' not in disabled_quotas:
        security_groups = []
        security_groups = network.security_group_list(request)
        usages.tally('security_groups', len(security_groups))

    if 'network' not in disabled_quotas:
        networks = []
        networks = neutron.network_list(request, shared=False)
        if tenant_id:
            networks = [net for net in networks if net.tenant_id == tenant_id]
        usages.tally('networks', len(networks))
        # get shared networks
        shared_networks = neutron.network_list(request, shared=True)
        if tenant_id:
            shared_networks = [
                net for net in shared_networks if net.tenant_id == tenant_id
            ]
        usages.tally('networks', len(shared_networks))

    if 'subnet' not in disabled_quotas:
        subnets = neutron.subnet_list(request, shared=False)
        if tenant_id:
            subnets = [sub for sub in subnets if sub.tenant_id == tenant_id]
        # get shared subnets
        shared_subnets = neutron.subnet_list(request, shared=True)
        if tenant_id:
            shared_subnets = [
                subnet for subnet in shared_subnets
                if subnet.tenant_id == tenant_id
            ]
        usages.tally('subnets', len(subnets) + len(shared_subnets))

    if 'router' not in disabled_quotas:
        routers = []
        routers = neutron.router_list(request)
        if tenant_id:
            routers = [rou for rou in routers if rou.tenant_id == tenant_id]
        usages.tally('routers', len(routers))
Ejemplo n.º 14
0
def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id):
    floating_ips = []
    try:
        if network.floating_ip_supported(request):
            floating_ips = network.tenant_floating_ip_list(request)
    except Exception:
        pass
    usages.tally('floating_ips', len(floating_ips))

    if 'security_group' not in disabled_quotas:
        security_groups = []
        security_groups = network.security_group_list(request)
        usages.tally('security_groups', len(security_groups))

    if 'network' not in disabled_quotas:
        networks = []
        networks = neutron.network_list(request, shared=False)
        if tenant_id:
            networks = [net for net in networks if net.tenant_id == tenant_id]
        usages.tally('networks', len(networks))
        # get shared networks
        shared_networks = neutron.network_list(request, shared=True)
        if tenant_id:
            shared_networks = [net for net in shared_networks
                               if net.tenant_id == tenant_id]
        usages.tally('networks', len(shared_networks))

    if 'subnet' not in disabled_quotas:
        subnets = neutron.subnet_list(request, shared=False)
        if tenant_id:
            subnets = [sub for sub in subnets if sub.tenant_id == tenant_id]
        # get shared subnets
        shared_subnets = neutron.subnet_list(request, shared=True)
        if tenant_id:
            shared_subnets = [subnet for subnet in shared_subnets
                              if subnet.tenant_id == tenant_id]
        usages.tally('subnets', len(subnets) + len(shared_subnets))

    if 'router' not in disabled_quotas:
        routers = []
        routers = neutron.router_list(request)
        if tenant_id:
            routers = [rou for rou in routers if rou.tenant_id == tenant_id]
        usages.tally('routers', len(routers))
Ejemplo n.º 15
0
def _get_tenant_network_usages(request, usages, disabled_quotas, tenant_id, region=None):
    floating_ips = []
    try:
        if network.floating_ip_supported(request):
            floating_ips = network.floating_ip_list(request, region=region, tenant_id=tenant_id)
            if tenant_id:
                floating_ips = filter(lambda fip: fip.tenant_id == tenant_id, floating_ips)
    except Exception:
        raise
        pass
    usages.tally('floating_ips', len(floating_ips))

    if 'security_group' not in disabled_quotas:
        security_groups = []
        security_groups = network.security_group_list(request)
        usages.tally('security_groups', len(security_groups))

    if 'network' not in disabled_quotas:
        networks = []
        networks = neutron.network_list(request, shared=False, region=region)
        if tenant_id:
            networks = filter(lambda net: net.tenant_id == tenant_id, networks)
        usages.tally('networks', len(networks))

    if 'subnet' not in disabled_quotas:
        subnets = []
        subnets = neutron.subnet_list(request, region=region)
        if tenant_id:
            subnets = filter(lambda subnet: subnet.tenant_id == tenant_id, subnets)
        usages.tally('subnets', len(subnets))

    if 'router' not in disabled_quotas:
        routers = []
        routers = neutron.router_list(request, region=region)
        if tenant_id:
            routers = filter(lambda rou: rou.tenant_id == tenant_id, routers)
        usages.tally('routers', len(routers))
    if 'pool' not in disabled_quotas:
        pools = []
        pools = lbaas.pool_list(request)
        if tenant_id:
            pools = filter(lambda p: p.tenant_id == tenant_id, pools)
        usages.tally('pool', len(pools))
Ejemplo n.º 16
0
    def __init__(self, request, *args, **kwargs):
        super(SecurityConfigAction, self).__init__(request, *args, **kwargs)

        self.fields["security_autogroup"] = forms.BooleanField(
            label=_("Auto Security Group"),
            widget=forms.CheckboxInput(),
            help_text=_("Create security group for this Node Group."),
            required=False,
            initial=True)

        try:
            groups = network.security_group_list(request)
        except Exception:
            exceptions.handle(request, _("Unable to get security group list."))
            raise

        security_group_list = [(sg.id, sg.name) for sg in groups]
        self.fields["security_groups"] = forms.MultipleChoiceField(
            label=_("Security Groups"),
            widget=forms.CheckboxSelectMultiple(),
            help_text=_("Launch instances in these security groups."),
            choices=security_group_list,
            required=False)
Ejemplo n.º 17
0
    def _get_data(self):
        sg_id = None
        try:
            security_groups = network.security_group_list(self.request)
        except Exception:
            security_groups = []
            exceptions.handle(self.request,
                              _('Unable to retrieve security groups.'))

        for security_group in security_groups:
            if security_group['name'] == 'default':
                sg_id = security_group['id']
                break

        if sg_id == None:
            return None
        # sg_id = filters.get_int_or_uuid(self.kwargs['security_group_id'])
        try:
            return api.network.security_group_get(self.request, sg_id)
        except Exception:
            redirect = reverse('horizon:project:access_and_security:index')
            exceptions.handle(self.request,
                              _('Unable to retrieve security group.'),
                              redirect=redirect)
Ejemplo n.º 18
0
    def _get_data(self):
        sg_id = None
        try:
            security_groups = network.security_group_list(self.request)
        except Exception:
            security_groups = []
            exceptions.handle(self.request,
                              _('Unable to retrieve security groups.'))

        for security_group in security_groups:
            if security_group['name'] == 'default':
                sg_id = security_group['id']
                break

        if sg_id == None:
            return None
        # sg_id = filters.get_int_or_uuid(self.kwargs['security_group_id'])
        try:
            return api.network.security_group_get(self.request, sg_id)
        except Exception:
            redirect = reverse('horizon:project:access_and_security:index')
            exceptions.handle(self.request,
                              _('Unable to retrieve security group.'),
                              redirect=redirect)
Ejemplo n.º 19
0
    def __init__(self, request, *args, **kwargs):
        super(GeneralConfigAction, self).__init__(request, *args, **kwargs)

        hlps = helpers.Helpers(request)

        plugin, hadoop_version = (
            workflow_helpers.get_plugin_and_hadoop_version(request))
        process_choices = []
        try:
            version_details = saharaclient.plugin_get_version_details(
                request, plugin, hadoop_version)
            for service, processes in version_details.node_processes.items():
                for process in processes:
                    process_choices.append(
                        (str(service) + ":" + str(process), process))
        except Exception:
            exceptions.handle(request,
                              _("Unable to generate process choices."))

        if not saharaclient.SAHARA_AUTO_IP_ALLOCATION_ENABLED:
            pools = network.floating_ip_pools_list(request)
            pool_choices = [(pool.id, pool.name) for pool in pools]
            pool_choices.insert(0, (None, "Do not assign floating IPs"))

            self.fields['floating_ip_pool'] = forms.ChoiceField(
                label=_("Floating IP Pool"),
                choices=pool_choices,
                required=False)

        self.fields["autogroup"] = forms.BooleanField(
            label=_("Auto Security Group"),
            widget=forms.CheckboxInput(),
            help_text=_("Create security group for this Node Group."),
            required=False,
            initial=True)

        groups = network.security_group_list(request)
        security_group_list = [(sg.id, sg.name) for sg in groups]
        self.fields["groups"] = forms.MultipleChoiceField(
            label=_("Security Groups"),
            widget=forms.CheckboxSelectMultiple(),
            help_text=_("Launch instances in these security groups."),
            choices=security_group_list,
            required=False)

        self.fields["processes"] = forms.MultipleChoiceField(
            label=_("Processes"),
            widget=forms.CheckboxSelectMultiple(),
            help_text=_("Processes to be launched in node group"),
            choices=process_choices)

        self.fields["plugin_name"] = forms.CharField(
            widget=forms.HiddenInput(),
            initial=plugin
        )
        self.fields["hadoop_version"] = forms.CharField(
            widget=forms.HiddenInput(),
            initial=hadoop_version
        )

        node_parameters = hlps.get_general_node_group_configs(plugin,
                                                              hadoop_version)
        for param in node_parameters:
            self.fields[param.name] = workflow_helpers.build_control(param)
Ejemplo n.º 20
0
def tenant_quota_usages(request):
    # Get our quotas and construct our usage object.
    disabled_quotas = get_disabled_quotas(request)

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

    # Get our usages.
    floating_ips = []
    try:
        if network.floating_ip_supported(request):
            floating_ips = network.tenant_floating_ip_list(request)
    except Exception:
        pass
    flavors = dict([(f.id, f) for f in nova.flavor_list(request)])
    instances, has_more = nova.server_list(request)
    # 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 Exception:
                flavors[missing] = {}
                exceptions.handle(request, ignore=True)

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

    if 'security_group' not in disabled_quotas:
        security_groups = []
        security_groups = network.security_group_list(request)
        usages.tally('security_groups', len(security_groups))

    if 'network' not in disabled_quotas:
        networks = []
        networks = neutron.network_list(request, shared=False)
        usages.tally('networks', len(networks))

    if 'router' not in disabled_quotas:
        routers = []
        routers = neutron.router_list(request)
        usages.tally('routers', len(routers))

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

    # 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
Ejemplo n.º 21
0
def tenant_quota_usages(request, tenant_id=None):
    """Get our quotas and construct our usage object.
    If no tenant_id is provided, a the request.user.project_id
    is assumed to be used
    """
    if not tenant_id:
        tenant_id = request.user.project_id

    disabled_quotas = get_disabled_quotas(request)

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

    # Get our usages.
    floating_ips = []
    try:
        if network.floating_ip_supported(request):
            floating_ips = network.tenant_floating_ip_list(request)
    except Exception:
        pass
    flavors = dict([(f.id, f) for f in nova.flavor_list(request)])

    if tenant_id:
        instances, has_more = nova.server_list(
            request, search_opts={'tenant_id': tenant_id}, all_tenants=True)
    else:
        instances, has_more = nova.server_list(request)

    # 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 Exception:
                flavors[missing] = {}
                exceptions.handle(request, ignore=True)

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

    if 'security_group' not in disabled_quotas:
        security_groups = []
        security_groups = network.security_group_list(request)
        usages.tally('security_groups', len(security_groups))

    if 'network' not in disabled_quotas:
        networks = []
        networks = neutron.network_list(request, shared=False)
        if tenant_id:
            networks = filter(lambda net: net.tenant_id == tenant_id, networks)
        usages.tally('networks', len(networks))

    if 'subnet' not in disabled_quotas:
        subnets = []
        subnets = neutron.subnet_list(request)
        usages.tally('subnets', len(subnets))

    if 'router' not in disabled_quotas:
        routers = []
        routers = neutron.router_list(request)
        if tenant_id:
            routers = filter(lambda rou: rou.tenant_id == tenant_id, routers)
        usages.tally('routers', len(routers))

    if 'volumes' not in disabled_quotas:
        if tenant_id:
            opts = {'alltenants': 1, 'tenant_id': tenant_id}
            volumes = cinder.volume_list(request, opts)
            snapshots = cinder.volume_snapshot_list(request, opts)
        else:
            volumes = cinder.volume_list(request)
            snapshots = cinder.volume_snapshot_list(request)
        usages.tally('gigabytes', sum([int(v.size) for v in volumes]))
        usages.tally('volumes', len(volumes))
        usages.tally('snapshots', len(snapshots))

    # 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
Ejemplo n.º 22
0
def tenant_quota_usages(request, tenant_id=None):
    """Get our quotas and construct our usage object."""

    disabled_quotas = get_disabled_quotas(request)

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

    # Get our usages.
    floating_ips = []
    try:
        if network.floating_ip_supported(request):
            floating_ips = network.tenant_floating_ip_list(request)
    except Exception:
        pass
    flavors = dict([(f.id, f) for f in nova.flavor_list(request)])

    if tenant_id:
        instances, has_more = nova.server_list(
            request, search_opts={'tenant_id': tenant_id}, all_tenants=True)
    else:
        instances, has_more = nova.server_list(request)

    # 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 Exception:
                flavors[missing] = {}
                exceptions.handle(request, ignore=True)

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

    if 'security_group' not in disabled_quotas:
        security_groups = []
        security_groups = network.security_group_list(request)
        usages.tally('security_groups', len(security_groups))

    if 'network' not in disabled_quotas:
        networks = []
        networks = neutron.network_list(request, shared=False)
        if tenant_id:
            networks = filter(lambda net: net.tenant_id == tenant_id, networks)
        usages.tally('networks', len(networks))

    if 'router' not in disabled_quotas:
        routers = []
        routers = neutron.router_list(request)
        if tenant_id:
            routers = filter(lambda rou: rou.tenant_id == tenant_id, routers)
        usages.tally('routers', len(routers))

    if 'volumes' not in disabled_quotas:
        if tenant_id:
            opts = {'alltenants': 1, 'tenant_id': tenant_id}
            volumes = cinder.volume_list(request, opts)
            snapshots = cinder.volume_snapshot_list(request, opts)
        else:
            volumes = cinder.volume_list(request)
            snapshots = cinder.volume_snapshot_list(request)
        usages.tally('gigabytes', sum([int(v.size) for v in volumes]))
        usages.tally('volumes', len(volumes))
        usages.tally('snapshots', len(snapshots))

    # 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