def kill(self): """Destroy the service object in the datastore.""" self.stop() try: db.service_destroy(context.get_admin_context(), self.service_id) except exception.NotFound: logging.warn(_('Service killed that has no database entry'))
def upgrade(migrate_engine): meta.bind = migrate_engine instances = Table('instances', meta, autoload=True, autoload_with=migrate_engine) types = {} for instance in migrate_engine.execute(instances.select()): if instance.instance_type_id is None: types[instance.id] = None continue try: types[instance.id] = int(instance.instance_type_id) except ValueError: logging.warn("Instance %s did not have instance_type_id " "converted to an integer because its value is %s" % (instance.id, instance.instance_type_id)) types[instance.id] = None integer_column = Column('instance_type_id_int', Integer(), nullable=True) string_column = instances.c.instance_type_id integer_column.create(instances) for instance_id, instance_type_id in types.iteritems(): update = instances.update().\ where(instances.c.id == instance_id).\ values(instance_type_id_int=instance_type_id) migrate_engine.execute(update) string_column.alter(name='instance_type_id_str') integer_column.alter(name='instance_type_id') string_column.drop()
def test_verify_index(self): req = webob.Request.blank( '/v2/123/os-simple-tenant-usage?start=%s&end=%s' % (START.isoformat(), STOP.isoformat())) req.method = "GET" req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app( fake_auth_context=self.admin_context)) self.assertEqual(res.status_int, 200) res_dict = json.loads(res.body) usages = res_dict['tenant_usages'] from engine import log as logging logging.warn(usages) for i in xrange(TENANTS): self.assertEqual(int(usages[i]['total_hours']), SERVERS * HOURS) self.assertEqual(int(usages[i]['total_local_gb_usage']), SERVERS * LOCAL_GB * HOURS) self.assertEqual(int(usages[i]['total_memory_mb_usage']), SERVERS * MEMORY_MB * HOURS) self.assertEqual(int(usages[i]['total_vcpus_usage']), SERVERS * VCPUS * HOURS) self.assertFalse(usages[i].get('server_usages'))
def get_all_host_data(self, context): """Returns a dict of all the hosts the ZoneManager knows about. Also, each of the consumable resources in HostInfo are pre-populated and adjusted based on data in the db. For example: {'192.168.1.100': HostInfo(), ...} Note: this can be very slow with a lot of instances. InstanceType table isn't required since a copy is stored with the instance (in case the InstanceType changed since the instance was created).""" # Make a compute node dict with the bare essential metrics. compute_nodes = self._compute_node_get_all(context) host_info_map = {} for compute in compute_nodes: all_disk = compute['local_gb'] all_ram = compute['memory_mb'] service = compute['service'] if not service: logging.warn(_("No service for compute ID %s") % compute['id']) continue host = service['host'] caps = self.service_states.get(host, None) host_info = HostInfo(host, caps=caps, free_disk_gb=all_disk, free_ram_mb=all_ram) # Reserve resources for host/dom0 host_info.consume_resources(FLAGS.reserved_host_disk_mb * 1024, FLAGS.reserved_host_memory_mb) host_info_map[host] = host_info # "Consume" resources from the host the instance resides on. instances = self._instance_get_all(context) for instance in instances: host = instance['host'] if not host: continue host_info = host_info_map.get(host, None) if not host_info: continue disk = instance['local_gb'] ram = instance['memory_mb'] host_info.consume_resources(disk, ram) return host_info_map
def test_verify_index(self): req = webob.Request.blank( '/v2/123/os-simple-tenant-usage?start=%s&end=%s' % (START.isoformat(), STOP.isoformat())) req.method = "GET" req.headers["content-type"] = "application/json" res = req.get_response( fakes.wsgi_app(fake_auth_context=self.admin_context)) self.assertEqual(res.status_int, 200) res_dict = json.loads(res.body) usages = res_dict['tenant_usages'] from engine import log as logging logging.warn(usages) for i in xrange(TENANTS): self.assertEqual(int(usages[i]['total_hours']), SERVERS * HOURS) self.assertEqual(int(usages[i]['total_local_gb_usage']), SERVERS * LOCAL_GB * HOURS) self.assertEqual(int(usages[i]['total_memory_mb_usage']), SERVERS * MEMORY_MB * HOURS) self.assertEqual(int(usages[i]['total_vcpus_usage']), SERVERS * VCPUS * HOURS) self.assertFalse(usages[i].get('server_usages'))