def get_all_types(inactive=0): """Get all non-deleted instance_types. Pass true as argument if you want deleted instance types returned also. """ return db.instance_type_get_all(context.get_admin_context(), inactive)
def describe_instance_types(self, context, **_kwargs): """Returns all active instance types data (vcpus, memory, etc.)""" return { 'instanceTypeSet': [ instance_dict(v) for v in db.instance_type_get_all(context).values() ] }
def setUp(self): super(DisabledFlavorsWithRealDBTest, self).setUp() self.controller = flavors.FlavorsController() # Add a new disabled type to the list of flavors self.req = fakes.HTTPRequestV3.blank('/flavors') self.context = self.req.environ['nova.context'] self.admin_context = context.get_admin_context() self.disabled_type = self._create_disabled_instance_type() self.inst_types = db.instance_type_get_all(self.admin_context)
def get_all_types(inactive=0, filters=None): """Get all non-deleted instance_types. Pass true as argument if you want deleted instance types returned also. """ ctxt = context.get_admin_context() inst_types = db.instance_type_get_all(ctxt, inactive, filters) inst_type_dict = {} for inst_type in inst_types: inst_type_dict[inst_type['name']] = inst_type return inst_type_dict
def index(self, req): ''' return all quotas usage in platform. ''' context = req.environ['nova.context'] authorize(context) hosts = db.compute_node_get_all(context) memory_mb_capacity = 0 local_gb_capacity = 0 ecu_capacity = 0 private_network_qos_capacity = 0 public_network_qos_capacity = 0 for host in hosts: memory_mb_capacity += host.memory_mb local_gb_capacity += host.local_gb ecu_capacity += self._get_host_ecu(req, host).get('capacity') or 0 total_private_network_mbps = host.\ get('total_private_network_mbps') if total_private_network_mbps is not None: private_network_qos_capacity += total_private_network_mbps total_public_network_mbps = host.\ get('total_public_network_mbps') if total_private_network_mbps is not None: public_network_qos_capacity += total_public_network_mbps filters = {"deleted": False} instances = db.instance_get_all_by_filters(context, filters, "created_at", "desc") self.flavors = db.instance_type_get_all(context) usages = dict( ecus={"capacity": ecu_capacity, "ecus": []}, servers={"servers": []}, vcpus={"vcpus": []}, local_gb={"capacity": local_gb_capacity, "local_gb": []}, memory_mb={"capacity": memory_mb_capacity, "memory_mb": []}, network_qos={ "network_qos": [], "private_capacity": private_network_qos_capacity, "public_capacity": public_network_qos_capacity } ) for instance in instances: for key in usages: # Note(hzzhoushaoyu) key in usages should be the same as # list key in each item. 'key' in second parameter is not the # same hierarchy as 'key' in first parameter in usage. self._make_items(req, usages[key], key, instance) # update floating IPs usages.update(floating_ips=self._get_floating_ips(context)) return usages
def get_all_flavors(ctxt=None, inactive=False, filters=None): """Get all non-deleted flavors. Pass true as argument if you want deleted flavors returned also. """ if ctxt is None: ctxt = context.get_admin_context() inst_types = db.instance_type_get_all(ctxt, inactive=inactive, filters=filters) inst_type_dict = {} for inst_type in inst_types: inst_type_dict[inst_type["name"]] = inst_type return inst_type_dict
def _create_disabled_instance_type(self): inst_types = db.instance_type_get_all(self.admin_context) inst_type = inst_types[0] del inst_type['id'] inst_type['name'] += '.disabled' inst_type['flavorid'] = unicode( max([int(flavor['flavorid']) for flavor in inst_types]) + 1) inst_type['disabled'] = True disabled_type = db.instance_type_create(self.admin_context, inst_type) return disabled_type
def _create_disabled_instance_type(self): inst_types = db.instance_type_get_all(self.admin_context) inst_type = inst_types[0] del inst_type['id'] inst_type['name'] += '.disabled' inst_type['flavorid'] = unicode(max( [int(flavor['flavorid']) for flavor in inst_types]) + 1) inst_type['disabled'] = True disabled_type = db.instance_type_create( self.admin_context, inst_type) return disabled_type
def test_instance_type_get_all(self): specs = dict(cpu_arch="x86_64", cpu_model="Nehalem", xpu_arch="fermi", xpus='2', xpu_model="Tesla 2050") types = db.instance_type_get_all(self.context) name2specs = {} for instance_type in types: name = instance_type['name'] name2specs[name] = instance_type['extra_specs'] self.assertEquals(name2specs['cg1.4xlarge'], specs) self.assertEquals(name2specs['m1.small'], {})
def get_all_flavors(ctxt=None, inactive=False, filters=None): """Get all non-deleted flavors. Pass true as argument if you want deleted flavors returned also. """ if ctxt is None: ctxt = context.get_admin_context() inst_types = db.instance_type_get_all(ctxt, inactive=inactive, filters=filters) inst_type_dict = {} for inst_type in inst_types: inst_type_dict[inst_type['name']] = inst_type return inst_type_dict
def assertFilterResults(self, filters, expected): inst_types = db.instance_type_get_all( self.context, filters=filters) inst_names = [i['name'] for i in inst_types] self.assertEqual(inst_names, expected)
def describe_instance_types(self, context, **_kwargs): """Returns all active instance types data (vcpus, memory, etc.)""" return {'instanceTypeSet': [instance_dict(v) for v in db.instance_type_get_all(context).values()]}
def describe_instance_types(self, context, **_kwargs): """Returns all active instance types data (vcpus, memory, etc.)""" inst_types = db.instance_type_get_all(context) inst_type_dicts = [instance_dict(i) for i in inst_types] return {'instanceTypeSet': inst_type_dicts}
def _all_ids(self, req): """Return the list of all flavorids.""" ctxt = req.environ['nova.context'] inst_types = db.instance_type_get_all(ctxt) flavor_ids = [inst_types[i]['flavorid'] for i in inst_types.keys()] return sorted(flavor_ids)