def get_context_data(self, request): cluster_id = self.tab_group.kwargs['cluster_id'] try: sahara = saharaclient.client(request) cluster = sahara.clusters.get(cluster_id) for ng in cluster.node_groups: if ng["flavor_id"]: ng["flavor_name"] = ( nova.flavor_get(request, ng["flavor_id"]).name) if ng["floating_ip_pool"]: ng["floating_ip_pool_name"] = ( self._get_floating_ip_pool_name( request, ng["floating_ip_pool"])) if ng.get("node_group_template_id", None): ng["node_group_template"] = saharaclient.safe_call( sahara.node_group_templates.get, ng["node_group_template_id"]) ng["security_groups_full"] = helpers.get_security_groups( request, ng["security_groups"]) except Exception: cluster = {} exceptions.handle(request, _("Unable to get node group details.")) return {"cluster": cluster}
def tenant_quota_usages(request): # Get our quotas and construct our usage object. usages = QuotaUsage() for quota in get_tenant_quota_data(request): 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)]) volumes = cinder.volume_list(request) instances = 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: flavors[missing] = {} exceptions.handle(request, ignore=True) usages.tally('instances', len(instances)) usages.tally('floating_ips', len(floating_ips)) usages.tally('volumes', len(volumes)) usages.tally('gigabytes', sum([int(v.size) for v in 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)) return usages
def get_context_data(self, request): template_id = self.tab_group.kwargs['template_id'] try: template = saharaclient.nodegroup_template_get( request, template_id) except Exception as e: template = {} LOG.error( "Unable to fetch node group template details: %s" % str(e)) return {"template": template} try: flavor = nova.flavor_get(request, template.flavor_id) except Exception: flavor = {} exceptions.handle(request, _("Unable to fetch flavor for template.")) floating_ip_pool_name = None if template.floating_ip_pool: try: floating_ip_pool_name = self._get_floating_ip_pool_name( request, template.floating_ip_pool) except Exception: exceptions.handle(request, _("Unable to fetch floating ip pools.")) security_groups = helpers.get_security_groups( request, template.security_groups) return {"template": template, "flavor": flavor, "floating_ip_pool_name": floating_ip_pool_name, "security_groups": security_groups}
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id): 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. flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) 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)) # 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)
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
def get(self, request, project_id, all_tenants): """Get instance list with current telemetry data Example GET: http://localhost/api/ceilometer/instancemonitor """ search_opts = {} try: if int(all_tenants): search_opts['all_tenants'] = True except: search_opts['all_tenants'] = False if project_id != '-1': search_opts['project_id'] = project_id servers = nova.server_list(request, search_opts=search_opts)[0] items = [] for s in servers: server = s.to_dict() server['color'] = intToRGB(hashCode(server['id'])) server['host'] = server['OS-EXT-SRV-ATTR:host'] server['zone'] = server['OS-EXT-AZ:availability_zone'] server['full_flavor'] = nova.flavor_get( request, server['flavor']['id']).to_dict() items.append(server) return {'items': items}
def get_context_data(self, request): cluster_id = self.tab_group.kwargs['cluster_id'] try: sahara = saharaclient.client(request) cluster = sahara.clusters.get(cluster_id) for ng in cluster.node_groups: if ng["flavor_id"]: ng["flavor_name"] = (nova.flavor_get( request, ng["flavor_id"]).name) if ng["floating_ip_pool"]: ng["floating_ip_pool_name"] = ( self._get_floating_ip_pool_name( request, ng["floating_ip_pool"])) if ng.get("node_group_template_id", None): ng["node_group_template"] = saharaclient.safe_call( sahara.node_group_templates.get, ng["node_group_template_id"]) ng["security_groups_full"] = helpers.get_security_groups( request, ng["security_groups"]) except Exception: cluster = {} exceptions.handle(request, _("Unable to get node group details.")) return {"cluster": cluster}
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id, region=None): if tenant_id: instances, has_more = nova.server_list( request, search_opts={'tenant_id': tenant_id}, all_tenants=True, region=region) else: instances, has_more = nova.server_list(request, region=region) # Fetch deleted flavors if necessary. flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) 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)) # Sum our usage based on the flavors of the instances. # change by zhihao.ding 2015/7/17 for kill_flavor start #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)) for instance in instances: usages.tally('cores', instance.vcpus) usages.tally('ram', instance.memory_mb) # change by zhihao.ding 2015/7/17 for kill_flavor end # Initialise the tally if no instances have been launched yet if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0)
def get_context_data(self, request): template_id = self.tab_group.kwargs['template_id'] try: template = saharaclient.nodegroup_template_get( request, template_id) except Exception: template = {} exceptions.handle(request, _("Unable to fetch node group template.")) try: flavor = nova.flavor_get(request, template.flavor_id) except Exception: flavor = {} exceptions.handle(request, _("Unable to fetch flavor for template.")) floating_ip_pool_name = None if template.floating_ip_pool: try: floating_ip_pool_name = self._get_floating_ip_pool_name( request, template.floating_ip_pool) except Exception: exceptions.handle(request, _("Unable to fetch floating ip pools.")) security_groups = helpers.get_security_groups( request, template.security_groups) return {"template": template, "flavor": flavor, "floating_ip_pool_name": floating_ip_pool_name, "security_groups": security_groups}
def _estimate_instance(self): params = self.request.REQUEST flavor = nova.flavor_get(self.request, params['flavor']) return self.estimator.estimate_instance( flavor_name=flavor.name, image_id=(params['image_id'] if params.get('source_type', '').endswith('image_id') else None), count=params['count'], )
def save_flavors_info(request, flavors_ids, path): path = u.join_path(path, "flavors.json") flavors = [] for f_id in flavors_ids: flavor_info = nova.flavor_get(request, f_id).to_dict() flavors.append(flavor_info) flavors_info = {"flavors": flavors} u.save_to_json(path, flavors_info)
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
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id): enabled_compute_quotas = NOVA_COMPUTE_QUOTA_FIELDS - disabled_quotas if not enabled_compute_quotas: return # Unlike the other services it can be the case that nova is enabled but # doesn't support quotas, in which case we still want to get usage info, # so don't rely on '"instances" in disabled_quotas' as elsewhere if not base.is_service_enabled(request, 'compute'): return if tenant_id and tenant_id != request.user.project_id: # all_tenants is required when querying about any project the user is # not currently scoped to instances, has_more = nova.server_list(request, search_opts={ 'tenant_id': tenant_id, 'all_tenants': True }) else: instances, has_more = nova.server_list(request) _add_usage_if_quota_enabled(usages, 'instances', len(instances), disabled_quotas) if {'cores', 'ram'} - disabled_quotas: # Fetch deleted flavors if necessary. flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) 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) # Sum our usage based on the flavors of the instances. for flavor in [ flavors[instance.flavor['id']] for instance in instances ]: _add_usage_if_quota_enabled(usages, 'cores', getattr(flavor, 'vcpus', None), disabled_quotas) _add_usage_if_quota_enabled(usages, 'ram', getattr(flavor, 'ram', None), disabled_quotas) # Initialize the tally if no instances have been launched yet if len(instances) == 0: _add_usage_if_quota_enabled(usages, 'cores', 0, disabled_quotas) _add_usage_if_quota_enabled(usages, 'ram', 0, disabled_quotas)
def get_context_data(self, request): template_id = self.tab_group.kwargs['template_id'] try: template = saharaclient.nodegroup_template_get( request, template_id) except Exception as e: template = {} LOG.error("Unable to fetch node group template details: %s" % str(e)) return {"template": template} try: flavor = nova.flavor_get(request, template.flavor_id) except Exception: flavor = {} exceptions.handle(request, _("Unable to fetch flavor for template.")) floating_ip_pool_name = None if template.floating_ip_pool: try: floating_ip_pool_name = self._get_floating_ip_pool_name( request, template.floating_ip_pool) except Exception: exceptions.handle(request, _("Unable to fetch floating ip pools.")) base_image_name = None if template.image_id: try: base_image_name = saharaclient.image_get( request, template.image_id).name except Exception: exceptions.handle( request, _("Unable to fetch Base Image with id: %s.") % template.image_id) security_groups = helpers.get_security_groups(request, template.security_groups) if getattr(template, 'boot_from_volume', None) is None: show_bfv = False else: show_bfv = True return { "template": template, "flavor": flavor, "floating_ip_pool_name": floating_ip_pool_name, "base_image_name": base_image_name, "security_groups": security_groups, "show_bfv": show_bfv }
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 '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
def recovery_flavor(request, flavor): new_flavor = nova.flavor_create( request, name=flavor['name'] + uuidutils.generate_uuid()[0:7], memory=flavor['ram'], vcpu=flavor['vcpus'], disk=flavor['disk'], ephemeral=flavor['OS-FLV-EXT-DATA:ephemeral'], swap=get_flavor_swap(flavor['swap']), rxtx_factor=flavor['rxtx_factor']).to_dict() new_flavor = nova.flavor_get(request, new_flavor['id']).to_dict() new_flavor['old_id'] = flavor['id'] return new_flavor
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. try: floating_ips = network.tenant_floating_ip_list(request) except neutronclient.NeutronClientException: floating_ips = [] 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 '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
def get_context_data(self, request): template_id = self.tab_group.kwargs['template_id'] try: template = saharaclient.nodegroup_template_get( request, template_id) except Exception as e: template = {} LOG.error( "Unable to fetch node group template details: %s" % str(e)) return {"template": template} try: flavor = nova.flavor_get(request, template.flavor_id) except Exception: flavor = {} exceptions.handle(request, _("Unable to fetch flavor for template.")) floating_ip_pool_name = None if template.floating_ip_pool: try: floating_ip_pool_name = self._get_floating_ip_pool_name( request, template.floating_ip_pool) except Exception: exceptions.handle(request, _("Unable to fetch floating ip pools.")) base_image_name = None if template.image_id: try: base_image_name = saharaclient.image_get( request, template.image_id).name except Exception: exceptions.handle(request, _("Unable to fetch Base Image with id: %s.") % template.image_id) security_groups = helpers.get_security_groups( request, template.security_groups) if getattr(template, 'boot_from_volume', None) is None: show_bfv = False else: show_bfv = True return {"template": template, "flavor": flavor, "floating_ip_pool_name": floating_ip_pool_name, "base_image_name": base_image_name, "security_groups": security_groups, "show_bfv": show_bfv}
def get_context_data(self, request): template_id = self.tab_group.kwargs['template_id'] try: template = saharaclient.nodegroup_template_get(request, template_id) except Exception: template = {} exceptions.handle(request, _("Unable to fetch node group template.")) try: flavor = nova.flavor_get(request, template.flavor_id) except Exception: flavor = {} exceptions.handle(request, _("Unable to fetch flavor for template.")) return {"template": template, "flavor": flavor}
def get_context_data(self, request): template_id = self.tab_group.kwargs['template_id'] try: template = saharaclient.nodegroup_template_get( request, template_id) except Exception: template = {} exceptions.handle(request, _("Unable to fetch node group template.")) try: flavor = nova.flavor_get(request, template.flavor_id) except Exception: flavor = {} exceptions.handle(request, _("Unable to fetch flavor for template.")) return {"template": template, "flavor": flavor}
def get_context_data(self, request): template_id = self.tab_group.kwargs["template_id"] try: template = saharaclient.cluster_template_get(request, template_id) for ng in template.node_groups: if not ng["flavor_id"]: continue ng["flavor_name"] = nova.flavor_get(request, ng["flavor_id"]).name ng["node_group_template"] = saharaclient.safe_call( saharaclient.nodegroup_template_get, request, ng.get("node_group_template_id", None) ) ng["security_groups_full"] = helpers.get_security_groups(request, ng.get("security_groups")) except Exception: template = {} exceptions.handle(request, _("Unable to fetch node group details.")) return {"template": template}
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id): enabled_compute_quotas = NOVA_COMPUTE_QUOTA_FIELDS - disabled_quotas if not enabled_compute_quotas: return # Unlike the other services it can be the case that nova is enabled but # doesn't support quotas, in which case we still want to get usage info, # so don't rely on '"instances" in disabled_quotas' as elsewhere if not base.is_service_enabled(request, 'compute'): return if tenant_id: instances, has_more = nova.server_list( request, search_opts={'tenant_id': tenant_id}) else: instances, has_more = nova.server_list(request) _add_usage_if_quota_enabled(usages, 'instances', len(instances), disabled_quotas) if {'cores', 'ram'} - disabled_quotas: # Fetch deleted flavors if necessary. flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) 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) # Sum our usage based on the flavors of the instances. for flavor in [flavors[instance.flavor['id']] for instance in instances]: _add_usage_if_quota_enabled( usages, 'cores', getattr(flavor, 'vcpus', None), disabled_quotas) _add_usage_if_quota_enabled( usages, 'ram', getattr(flavor, 'ram', None), disabled_quotas) # Initialize the tally if no instances have been launched yet if len(instances) == 0: _add_usage_if_quota_enabled(usages, 'cores', 0, disabled_quotas) _add_usage_if_quota_enabled(usages, 'ram', 0, disabled_quotas)
def get_context_data(self, request): template_id = self.tab_group.kwargs['template_id'] try: template = saharaclient.cluster_template_get(request, template_id) for ng in template.node_groups: if not ng["flavor_id"]: continue ng["flavor_name"] = (nova.flavor_get(request, ng["flavor_id"]).name) ng["node_group_template"] = helpers.safe_call( saharaclient.nodegroup_template_get, request, ng.get("node_group_template_id", None)) except Exception: template = {} exceptions.handle(request, _("Unable to fetch node group details.")) return {"template": template}
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id): # Unlike the other services it can be the case that nova is enabled but # doesn't support quotas, in which case we still want to get usage info, # so don't rely on '"instances" in disabled_quotas' as elsewhere if not base.is_service_enabled(request, 'compute'): return if tenant_id: # determine if the user has permission to view across projects # there are cases where an administrator wants to check the quotas # on a project they are not scoped to all_tenants = policy.check((("compute", "compute:get_all_tenants"), ), request) instances, has_more = nova.server_list( request, search_opts={'tenant_id': tenant_id}, all_tenants=all_tenants) else: instances, has_more = nova.server_list(request) # Fetch deleted flavors if necessary. flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) 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)) # 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)) # Initialize the tally if no instances have been launched yet if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0)
def get_context_data(self, request): cluster_id = self.tab_group.kwargs['cluster_id'] try: sahara = saharaclient.client(request) cluster = sahara.clusters.get(cluster_id) for ng in cluster.node_groups: if not ng["flavor_id"]: continue ng["flavor_name"] = (nova.flavor_get(request, ng["flavor_id"]).name) ng["node_group_template"] = helpers.safe_call( sahara.node_group_templates.get, ng.get("node_group_template_id", None)) except Exception: cluster = {} exceptions.handle(request, _("Unable to get node group details.")) return {"cluster": cluster}
def tenant_quota_usages(request): # 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 = network.tenant_floating_ip_list(request) flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) instances = 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: 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
def get_context_data(self, request): cluster_id = self.tab_group.kwargs['cluster_id'] try: sahara = saharaclient.client(request) cluster = sahara.clusters.get(cluster_id) for ng in cluster.node_groups: if not ng["flavor_id"]: continue ng["flavor_name"] = ( nova.flavor_get(request, ng["flavor_id"]).name) ng["node_group_template"] = helpers.safe_call( sahara.node_group_templates.get, ng.get("node_group_template_id", None)) except Exception: cluster = {} exceptions.handle(request, _("Unable to get node group details.")) return {"cluster": cluster}
def get_context_data(self, **kwargs): context = super(OvercloudRoleView, self).get_context_data(**kwargs) overcloud = self.get_overcloud() redirect = reverse(DETAIL_URL, args=(overcloud.id,)) role = self.get_role(redirect) context['role'] = role context['image_name'] = role.image_name context['nodes'] = self._get_nodes(overcloud, role) try: context['flavor'] = nova.flavor_get(self.request, role.flavor_id) except novaclient.exceptions.NotFound: context['flavor'] = None except Exception: msg = _('Unable to retrieve flavor.') horizon.exceptions.handle(self.request, msg) return context
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id): # Unlike the other services it can be the case that nova is enabled but # doesn't support quotas, in which case we still want to get usage info, # so don't rely on '"instances" in disabled_quotas' as elsewhere if not base.is_service_enabled(request, 'compute'): return if tenant_id: # determine if the user has permission to view across projects # there are cases where an administrator wants to check the quotas # on a project they are not scoped to all_tenants = policy.check((("compute", "compute:get_all_tenants"),), request) instances, has_more = nova.server_list( request, search_opts={'tenant_id': tenant_id}, all_tenants=all_tenants) else: instances, has_more = nova.server_list(request) # Fetch deleted flavors if necessary. flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) 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)) # 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)) # Initialize the tally if no instances have been launched yet if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0)
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id): enabled_compute_quotas = NOVA_COMPUTE_QUOTA_FIELDS - disabled_quotas if not enabled_compute_quotas: return # Unlike the other services it can be the case that nova is enabled but # doesn't support quotas, in which case we still want to get usage info, # so don't rely on '"instances" in disabled_quotas' as elsewhere if not base.is_service_enabled(request, 'compute'): return if tenant_id: instances, has_more = nova.server_list( request, search_opts={'tenant_id': tenant_id}) else: instances, has_more = nova.server_list(request) # Fetch deleted flavors if necessary. flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) 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)) # 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)) # Initialize the tally if no instances have been launched yet if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0)
def tenant_quota_usages(request): # 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)]) instances = 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: 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)) return usages
def get_context_data(self, request): template_id = self.tab_group.kwargs["template_id"] try: template = saharaclient.nodegroup_template_get(request, template_id) except Exception: template = {} exceptions.handle(request, _("Unable to fetch node group template.")) try: flavor = nova.flavor_get(request, template.flavor_id) except Exception: flavor = {} exceptions.handle(request, _("Unable to fetch flavor for template.")) floating_ip_pool_name = None if template.floating_ip_pool: try: floating_ip_pool_name = self._get_floating_ip_pool_name(request, template.floating_ip_pool) except Exception: exceptions.handle(request, _("Unable to fetch floating ip pools.")) return {"template": template, "flavor": flavor, "floating_ip_pool_name": floating_ip_pool_name}
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
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 = network.tenant_floating_ip_list(request) flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) instances = 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: flavors[missing] = {} exceptions.handle(request, ignore=True) # jt project_id = request.user.tenant_id resources = api.jt.get_used_resources(project_id) floating_ips = resources.get('floating_ips', 0) instances = resources.get('instances', 0) cores = resources.get('cores', 0) ram = resources.get('ram', 0) gigabytes = resources.get('gigabytes', 0) volumes = resources.get('volumes', 0) # jt #usages.tally('instances', len(instances)) #usages.tally('floating_ips', len(floating_ips)) usages.tally('instances', instances) usages.tally('floating_ips', floating_ips) usages.tally('cores', cores) usages.tally('ram', ram) if 'volumes' not in disabled_quotas: # jt #volumes = cinder.volume_list(request) #usages.tally('gigabytes', sum([int(v.size) for v in volumes])) #usages.tally('volumes', len(volumes)) usages.tally('gigabytes', gigabytes) usages.tally('volumes', volumes) # jt # 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)) # jt # Initialise the tally if no instances have been launched yet if instances == 0: #if len(instances) == 0: usages.tally('cores', 0) usages.tally('ram', 0) # Images owned_image_count = api.jt.get_image_count(project_id, request) image_limit = api.jt.get_image_quota(project_id) usages['images']['quota'] = image_limit usages['images']['used'] = owned_image_count usages['images']['available'] = image_limit - owned_image_count # Expiration expiration_date = api.jt.get_expiration_date(project_id) usages['expiration']['quota'] = -1 usages['expiration']['used'] = 0 usages['expiration']['available'] = 0 usages['expiration']['expiration_date'] = expiration_date # Start Date start_date = api.jt.get_start_date(project_id) usages['start']['quota'] = -1 usages['start']['used'] = 0 usages['start']['available'] = 0 usages['start']['start_date'] = start_date # DAIR Notice dair_notice = api.jt.get_dair_notice(project_id) usages['dair_notice']['quota'] = -1 usages['dair_notice']['used'] = 0 usages['dair_notice']['available'] = 0 usages['dair_notice']['dair_notice'] = dair_notice # Object Storage object_mb_usage = api.jt.get_object_mb_usage(project_id) object_mb_limit = api.jt.get_object_mb_quota(project_id) usages['object_mb']['quota'] = object_mb_limit usages['object_mb']['used'] = object_mb_usage usages['object_mb']['available'] = object_mb_limit - object_mb_usage return usages
def _get_tenant_compute_usages(request, usages, disabled_quotas, tenant_id): if tenant_id: # determine if the user has permission to view across projects # there are cases where an administrator wants to check the quotas # on a project they are not scoped to all_tenants = policy.check((("compute", "compute:get_all_tenants"), ), request) ''' instances, has_more = nova.server_list( request, search_opts={'tenant_id': tenant_id}, all_tenants=all_tenants) ''' if is_m1_user_admin(request): instances, has_more = server_list_nova( request, search_opts={'tenant_id': tenant_id}, all_tenants=all_tenants) else: instances, has_more = nova.server_list( request, search_opts={'tenant_id': tenant_id}, all_tenants=all_tenants) else: #instances, has_more = nova.server_list(request) if is_m1_user_admin(request): instances, has_more = server_list_nova(request) else: instances, has_more = nova.server_list(request) # Fetch deleted flavors if necessary. #flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) if is_m1_user_admin(request): flavors = dict([(f.id, f) for f in flavor_list_nova(request)]) else: flavors = dict([(f.id, f) for f in nova.flavor_list(request)]) 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) if is_m1_user_admin(request): flavors[missing] = flavor_get_nova(request, missing) else: flavors[missing] = nova.flavor_get(request, missing) except Exception: flavors[missing] = {} exceptions.handle(request, ignore=True) usages.tally('instances', len(instances)) # 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)
def get(cls, request, flavor_id): return cls(nova.flavor_get(request, flavor_id))
def get_internalinstances_data(self): request = self.tab_group.request instances = [] marker = self.request.GET.get( project_tables.InstancesTable._meta.pagination_param, None) # # Gather our instances try: instances, self._more = nova.server_list( self.request, search_opts={'marker': marker, 'paginate': True}) except Exception: self._more = False instances = [] exceptions.handle(self.request, _('Unable to retrieve instances.')) # Gather our flavors and images and correlate our instances to them if instances: try: flavors = nova.flavor_list(self.request) except Exception: flavors = [] exceptions.handle(self.request, ignore=True) try: # TODO(gabriel): Handle pagination. images, more = glance.image_list_detailed(self.request) except Exception: images = [] exceptions.handle(self.request, ignore=True) full_flavors = SortedDict([(str(flavor.id), flavor) for flavor in flavors]) image_map = SortedDict([(str(image.id), image) for image in images]) # Loop through instances to get flavor info. for instance in instances: if hasattr(instance, 'image'): # Instance from image returns dict if isinstance(instance.image, dict): if instance.image.get('id') in image_map: instance.image = image_map[instance.image['id']] else: # Instance from volume returns a string instance.image = {'name': instance.image if instance.image else _("-")} try: flavor_id = instance.flavor["id"] if flavor_id in full_flavors: instance.full_flavor = full_flavors[flavor_id] else: # If the flavor_id is not in full_flavors list, # get it via nova api. instance.full_flavor = nova.flavor_get( self.request, flavor_id) except Exception: msg = _('Unable to retrieve instance size information.') exceptions.handle(self.request, msg) return instances
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