def rebuild_instance( self, ctxt, instance, new_pass, injected_files, image_ref, orig_image_ref, orig_sys_metadata, bdms, recreate=False, on_shared_storage=False, host=None, ): instance_p = jsonutils.to_primitive(instance) bdms_p = jsonutils.to_primitive(bdms) self.cast( ctxt, self.make_msg( "rebuild_instance", instance=instance_p, new_pass=new_pass, injected_files=injected_files, image_ref=image_ref, orig_image_ref=orig_image_ref, orig_sys_metadata=orig_sys_metadata, bdms=bdms_p, recreate=recreate, on_shared_storage=on_shared_storage, ), topic=_compute_topic(self.topic, ctxt, host, instance), version="2.22", )
def prep_resize( self, ctxt, image, instance, instance_type, host, reservations=None, request_spec=None, filter_properties=None, node=None, ): instance_p = jsonutils.to_primitive(instance) instance_type_p = jsonutils.to_primitive(instance_type) self.cast( ctxt, self.make_msg( "prep_resize", instance=instance_p, instance_type=instance_type_p, image=image, reservations=reservations, request_spec=request_spec, filter_properties=filter_properties, node=node, ), _compute_topic(self.topic, ctxt, host, None), version="2.20", )
def rebuild_instance(self, ctxt, instance, new_pass, injected_files, image_ref, orig_image_ref, orig_sys_metadata, bdms, recreate=False, on_shared_storage=False, host=None, preserve_ephemeral=False, kwargs=None): # NOTE(danms): kwargs is only here for cells compatibility, don't # actually send it to compute extra = {'preserve_ephemeral': preserve_ephemeral} if self.client.can_send_version('3.21'): version = '3.21' else: bdms = block_device.legacy_mapping(bdms) bdms = jsonutils.to_primitive(objects_base.obj_to_primitive(bdms)) if self.client.can_send_version('3.5'): version = '3.5' elif self.client.can_send_version('3.4'): version = '3.4' extra = {} else: # NOTE(russellb) Havana compat version = self._get_compat_version('3.0', '2.22') instance = jsonutils.to_primitive(instance) extra = {} cctxt = self.client.prepare(server=_compute_host(host, instance), version=version) cctxt.cast(ctxt, 'rebuild_instance', instance=instance, new_pass=new_pass, injected_files=injected_files, image_ref=image_ref, orig_image_ref=orig_image_ref, orig_sys_metadata=orig_sys_metadata, bdms=bdms, recreate=recreate, on_shared_storage=on_shared_storage, **extra)
def prep_resize( self, ctxt, image, instance, instance_type, host, reservations=None, request_spec=None, filter_properties=None, node=None, ): # NOTE(russellb) Havana compat version = self._get_compat_version("3.0", "2.43") instance_type_p = jsonutils.to_primitive(instance_type) image_p = jsonutils.to_primitive(image) cctxt = self.client.prepare(server=host, version=version) cctxt.cast( ctxt, "prep_resize", instance=instance, instance_type=instance_type_p, image=image_p, reservations=reservations, request_spec=request_spec, filter_properties=filter_properties, node=node, )
def test_shelved_poll_timedout(self): active_instance = jsonutils.to_primitive(self._create_fake_instance()) self.compute.run_instance(self.context, active_instance, {}, {}, [], None, None, True, None, False) instance = jsonutils.to_primitive(self._create_fake_instance()) self.compute.run_instance(self.context, instance, {}, {}, [], None, None, True, None, False) sys_meta = utils.metadata_to_dict(instance['system_metadata']) shelved_time = timeutils.utcnow() timeutils.set_time_override(shelved_time) timeutils.advance_time_seconds(CONF.shelved_offload_time + 1) sys_meta['shelved_at'] = timeutils.strtime(at=shelved_time) (old, instance) = db.instance_update_and_get_original(self.context, instance['uuid'], {'vm_state': vm_states.SHELVED, 'system_metadata': sys_meta}) def fake_destroy(inst, nw_info, bdm): # NOTE(alaski) There are too many differences between an instance # as returned by instance_update_and_get_original and # instance_get_all_by_filters so just compare the uuid. self.assertEqual(instance['uuid'], inst['uuid']) self.stubs.Set(self.compute.driver, 'destroy', fake_destroy) self.compute._poll_shelved_instances(self.context)
def terminate_instance(self, ctxt, instance, bdms): instance_p = jsonutils.to_primitive(instance) bdms_p = jsonutils.to_primitive(bdms) self.cast(ctxt, self.make_msg('terminate_instance', instance=instance_p, bdms=bdms_p), topic=_compute_topic(self.topic, ctxt, None, instance), version='2.4')
def migrate_server( self, context, instance, scheduler_hint, live, rebuild, flavor, block_migration, disk_over_commit, reservations=None, ): if self.client.can_send_version("1.6"): version = "1.6" else: instance = jsonutils.to_primitive(objects_base.obj_to_primitive(instance)) version = "1.4" flavor_p = jsonutils.to_primitive(flavor) cctxt = self.client.prepare(version=version) return cctxt.call( context, "migrate_server", instance=instance, scheduler_hint=scheduler_hint, live=live, rebuild=rebuild, flavor=flavor_p, block_migration=block_migration, disk_over_commit=disk_over_commit, reservations=reservations, )
def prep_resize(self, ctxt, image, instance, instance_type, host): instance_p = jsonutils.to_primitive(instance) instance_type_p = jsonutils.to_primitive(instance_type) self.cast(ctxt, self.make_msg('prep_resize', instance=instance_p, instance_type=instance_type_p, image=image), _compute_topic(self.topic, ctxt, host, None), version='1.38')
def prep_resize(self, ctxt, instance, instance_type, image, request_spec, filter_properties): instance_p = jsonutils.to_primitive(instance) instance_type_p = jsonutils.to_primitive(instance_type) self.cast(ctxt, self.make_msg('prep_resize', instance=instance_p, instance_type=instance_type_p, image=image, request_spec=request_spec, filter_properties=filter_properties), version='1.4')
def build_instances(self, ctxt, **kwargs): """Build instances.""" build_inst_kwargs = kwargs instances = build_inst_kwargs["instances"] instances_p = [jsonutils.to_primitive(inst) for inst in instances] build_inst_kwargs["instances"] = instances_p build_inst_kwargs["image"] = jsonutils.to_primitive(build_inst_kwargs["image"]) self.cast(ctxt, self.make_msg("build_instances", build_inst_kwargs=build_inst_kwargs), version="1.8")
def prep_resize(self, ctxt, image, instance, instance_type, host, reservations=None): instance_p = jsonutils.to_primitive(instance) instance_type_p = jsonutils.to_primitive(instance_type) self.cast(ctxt, self.make_msg('prep_resize', instance=instance_p, instance_type=instance_type_p, image=image, reservations=reservations), _compute_topic(self.topic, ctxt, host, None))
def generate_data(): def _generate_stats(id_num): stats = {} i = 0 while i < CONF.num_stat: key = 'key%d' % i stats[key] = id_num + i i = i + 1 return stats print "Starting prepare data in DB" ctx = context.get_admin_context() for i in range(CONF.num_comp): if i *100.0 % CONF.num_comp == 0: sys.stdout.write("prepared %d%% data\r" % (i * 100.0 / CONF.num_comp)) sys.stdout.flush() svc_values = { 'host': 'host-%d' % i, 'binary': 'novadbtest', 'topic': 'novadbtest', 'report_count': 0, } #created service record service_ref = jsonutils.to_primitive( db.service_get_by_host_and_topic(ctx, svc_values['host'], svc_values['topic'])) if not service_ref: service_ref = jsonutils.to_primitive( db.service_create(ctx, svc_values)) LOG.info('Service record created for id %d', service_ref['id']) #create/update compute node record comp_values = { 'service_id': service_ref['id'], 'vcpus': i, 'memory_mb': i, 'local_gb': i, 'vcpus_used': i, 'memory_mb_used': i, 'local_gb_used': i, 'hypervisor_type': 'qemu', 'hypervisor_version': 1, 'hypervisor_hostname': 'test', 'free_ram_mb': i, 'free_disk_gb': i, 'current_workload': i, 'running_vms': i, 'disk_available_least': i, } comp_values['cpu_info'] = jsonutils.dumps(_generate_stats(i)) if hasattr(ComputeNode, 'metrics'): comp_values['metrics'] = jsonutils.dumps(_generate_stats(i)) if CONF.join_stats: comp_values['stats'] = _generate_stats(i) compute_ref = jsonutils.to_primitive( db.compute_node_create(ctx, comp_values)) LOG.info('Compute node record created for id %d', compute_ref['id']) print "Finish preparing data in DB"
def get_host(self, ctxt, instance, instance_type, image, request_spec, filter_properties, reservations): instance_p = jsonutils.to_primitive(instance) instance_type_p = jsonutils.to_primitive(instance_type) return self.call(ctxt, self.make_msg('get_host', instance=instance_p, instance_type=instance_type_p, image=image, request_spec=request_spec, filter_properties=filter_properties, reservations=reservations))
def block_device_mapping_destroy(self, context, bdms=None, instance=None, volume_id=None, device_name=None): bdms_p = jsonutils.to_primitive(bdms) instance_p = jsonutils.to_primitive(instance) cctxt = self.client.prepare(version='1.14') return cctxt.call(context, 'block_device_mapping_destroy', bdms=bdms_p, instance=instance_p, volume_id=volume_id, device_name=device_name)
def resize_instance(self, ctxt, instance, migration, image, reservations=None): topic = _compute_topic(self.topic, ctxt, None, instance) instance_p = jsonutils.to_primitive(instance) migration_p = jsonutils.to_primitive(migration) self.cast(ctxt, self.make_msg('resize_instance', instance=instance_p, migration=migration_p, image=image, reservations=reservations), topic, version='2.6')
def build_instances(self, ctxt, **kwargs): """Build instances.""" build_inst_kwargs = kwargs instances = build_inst_kwargs["instances"] instances_p = [jsonutils.to_primitive(inst) for inst in instances] build_inst_kwargs["instances"] = instances_p build_inst_kwargs["image"] = jsonutils.to_primitive(build_inst_kwargs["image"]) cctxt = self.client.prepare(version="1.8") cctxt.cast(ctxt, "build_instances", build_inst_kwargs=build_inst_kwargs)
def terminate_instance(self, ctxt, instance, bdms, reservations=None): instance_p = jsonutils.to_primitive(instance) bdms_p = jsonutils.to_primitive(bdms) self.cast( ctxt, self.make_msg("terminate_instance", instance=instance_p, bdms=bdms_p, reservations=reservations), topic=_compute_topic(self.topic, ctxt, None, instance), version="2.27", )
def revert_resize(self, ctxt, instance, migration, host, reservations=None): instance_p = jsonutils.to_primitive(instance) migration_p = jsonutils.to_primitive(migration) self.cast(ctxt, self.make_msg('revert_resize', instance=instance_p, migration=migration_p, reservations=reservations), topic=_compute_topic(self.topic, ctxt, host, instance), version='2.12')
def finish_resize(self, ctxt, instance, migration, image, disk_info, host, reservations=None): instance_p = jsonutils.to_primitive(instance) migration_p = jsonutils.to_primitive(migration) self.cast(ctxt, self.make_msg('finish_resize', instance=instance_p, migration=migration_p, image=image, disk_info=disk_info, reservations=reservations), topic=_compute_topic(self.topic, ctxt, host, None), version='2.8')
def migrate_server(self, context, instance, scheduler_hint, live, rebuild, flavor, block_migration, disk_over_commit): instance_p = jsonutils.to_primitive(instance) flavor_p = jsonutils.to_primitive(flavor) msg = self.make_msg('migrate_server', instance=instance_p, scheduler_hint=scheduler_hint, live=live, rebuild=rebuild, flavor=flavor_p, block_migration=block_migration, disk_over_commit=disk_over_commit) return self.call(context, msg, version='1.1')
def prep_resize(self, ctxt, instance, instance_type, image, request_spec, filter_properties, reservations, keep_ephemeral=True): instance_p = jsonutils.to_primitive(instance) instance_type_p = jsonutils.to_primitive(instance_type) self.cast(ctxt, self.make_msg('prep_resize', instance=instance_p, instance_type=instance_type_p, image=image, request_spec=request_spec, filter_properties=filter_properties, reservations=reservations, keep_ephemeral=keep_ephemeral))
def block_device_mapping_destroy(self, context, bdms=None, instance=None, volume_id=None, device_name=None): bdms_p = jsonutils.to_primitive(bdms) instance_p = jsonutils.to_primitive(instance) msg = self.make_msg('block_device_mapping_destroy', bdms=bdms_p, instance=instance_p, volume_id=volume_id, device_name=device_name) return self.call(context, msg, version='1.14')
def confirm_resize(self, ctxt, instance, migration, host, reservations=None, cast=True): rpc_method = self.cast if cast else self.call instance_p = jsonutils.to_primitive(instance) migration_p = jsonutils.to_primitive(migration) return rpc_method(ctxt, self.make_msg('confirm_resize', instance=instance_p, migration=migration_p, reservations=reservations), topic=_compute_topic(self.topic, ctxt, host, instance), version='2.7')
def prep_resize(self, ctxt, instance, instance_type, image, request_spec, filter_properties, reservations): instance_p = jsonutils.to_primitive(instance) instance_type_p = jsonutils.to_primitive(instance_type) reservations_p = jsonutils.to_primitive(reservations) image_p = jsonutils.to_primitive(image) self.cast(ctxt, self.make_msg('prep_resize', instance=instance_p, instance_type=instance_type_p, image=image_p, request_spec=request_spec, filter_properties=filter_properties, reservations=reservations_p))
def build_instances(self, ctxt, **kwargs): """Build instances.""" build_inst_kwargs = kwargs instances = build_inst_kwargs['instances'] instances_p = [jsonutils.to_primitive(inst) for inst in instances] build_inst_kwargs['instances'] = instances_p build_inst_kwargs['image'] = jsonutils.to_primitive( build_inst_kwargs['image']) cctxt = self.client.prepare(version='1.8') cctxt.cast(ctxt, 'build_instances', build_inst_kwargs=build_inst_kwargs)
def setUp(self): super(ComputeRpcAPITestCase, self).setUp() self.context = context.get_admin_context() inst = db.instance_create(self.context, {'host': 'fake_host', 'instance_type_id': 1}) self.fake_instance = jsonutils.to_primitive(inst) self.fake_volume_bdm = jsonutils.to_primitive( fake_block_device.FakeDbBlockDeviceDict( {'source_type': 'volume', 'destination_type': 'volume', 'instance_uuid': self.fake_instance['uuid'], 'volume_id': 'fake-volume-id'}))
def rebuild_instance(self, ctxt, instance, new_pass, injected_files, image_ref, orig_image_ref, orig_sys_metadata, bdms): instance_p = jsonutils.to_primitive(instance) bdms_p = jsonutils.to_primitive(bdms) self.cast(ctxt, self.make_msg('rebuild_instance', instance=instance_p, new_pass=new_pass, injected_files=injected_files, image_ref=image_ref, orig_image_ref=orig_image_ref, orig_sys_metadata=orig_sys_metadata, bdms=bdms_p), topic=_compute_topic(self.topic, ctxt, None, instance), version='2.18')
def compute_confirm_resize(self, context, instance, migration_ref): migration_p = jsonutils.to_primitive(migration_ref) if not self.can_send_version('1.52'): instance = jsonutils.to_primitive( objects_base.obj_to_primitive(instance)) version = '1.46' else: version = '1.52' msg = self.make_msg('compute_confirm_resize', instance=instance, migration_ref=migration_p) return self.call(context, msg, version=version)
def build_instances(self, ctxt, **kwargs): """Build instances.""" build_inst_kwargs = kwargs instances = build_inst_kwargs['instances'] instances_p = [jsonutils.to_primitive(inst) for inst in instances] build_inst_kwargs['instances'] = instances_p build_inst_kwargs['image'] = jsonutils.to_primitive( build_inst_kwargs['image']) self.cast(ctxt, self.make_msg('build_instances', build_inst_kwargs=build_inst_kwargs), version='1.8')
def terminate_instance(self, ctxt, instance, bdms, reservations=None): if self.client.can_send_version('2.35'): version = '2.35' else: version = '2.27' instance = jsonutils.to_primitive(instance) bdms_p = jsonutils.to_primitive(bdms) cctxt = self.client.prepare(server=_compute_host(None, instance), version=_get_version(version)) cctxt.cast(ctxt, 'terminate_instance', instance=instance, bdms=bdms_p, reservations=reservations)
def change_instance_metadata(self, ctxt, instance, diff): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('change_instance_metadata', instance=instance_p, diff=diff), topic=_compute_topic(self.topic, ctxt, None, instance))
def detach_volume(self, ctxt, instance, volume_id): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('detach_volume', instance=instance_p, volume_id=volume_id), topic=_compute_topic(self.topic, ctxt, None, instance))
def check_can_live_migrate_source(self, ctxt, instance, dest_check_data): instance_p = jsonutils.to_primitive(instance) self.call(ctxt, self.make_msg('check_can_live_migrate_source', instance=instance_p, dest_check_data=dest_check_data), topic=_compute_topic(self.topic, ctxt, None, instance))
def rescue_instance(self, ctxt, instance, rescue_password): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('rescue_instance', instance=instance_p, rescue_password=rescue_password), topic=_compute_topic(self.topic, ctxt, None, instance))
def rollback_live_migration_at_destination(self, ctxt, instance, host): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('rollback_live_migration_at_destination', instance=instance_p), topic=_compute_topic(self.topic, ctxt, host, None))
def _shelve_instance(self, shelved_offload_time, clean_shutdown=True): CONF.set_override('shelved_offload_time', shelved_offload_time) db_instance = jsonutils.to_primitive(self._create_fake_instance()) instance = objects.Instance.get_by_uuid( self.context, db_instance['uuid'], expected_attrs=['metadata', 'system_metadata']) image_id = 'fake_image_id' host = 'fake-mini' cur_time = timeutils.utcnow() timeutils.set_time_override(cur_time) instance.task_state = task_states.SHELVING instance.save() sys_meta = dict(instance.system_metadata) sys_meta['shelved_at'] = timeutils.strtime(at=cur_time) sys_meta['shelved_image_id'] = image_id sys_meta['shelved_host'] = host db_instance['system_metadata'] = utils.dict_to_metadata(sys_meta) self.mox.StubOutWithMock(self.compute, '_notify_about_instance_usage') self.mox.StubOutWithMock(self.compute.driver, 'snapshot') self.mox.StubOutWithMock(self.compute.driver, 'power_off') self.mox.StubOutWithMock(self.compute, '_get_power_state') self.mox.StubOutWithMock(db, 'instance_update_and_get_original') self.compute._notify_about_instance_usage(self.context, instance, 'shelve.start') if clean_shutdown: self.compute.driver.power_off(instance, CONF.shutdown_timeout, self.compute.SHUTDOWN_RETRY_INTERVAL) else: self.compute.driver.power_off(instance, 0, 0) self.compute._get_power_state(self.context, instance).AndReturn(123) self.compute.driver.snapshot(self.context, instance, 'fake_image_id', mox.IgnoreArg()) update_values = { 'power_state': 123, 'vm_state': vm_states.SHELVED, 'task_state': None, 'expected_task_state': [task_states.SHELVING, task_states.SHELVING_IMAGE_UPLOADING], 'system_metadata': sys_meta } if CONF.shelved_offload_time == 0: update_values['task_state'] = task_states.SHELVING_OFFLOADING db.instance_update_and_get_original( self.context, instance['uuid'], update_values, update_cells=False, columns_to_join=['metadata', 'system_metadata'], ).AndReturn((db_instance, db_instance)) self.compute._notify_about_instance_usage(self.context, instance, 'shelve.end') if CONF.shelved_offload_time == 0: self.compute._notify_about_instance_usage(self.context, instance, 'shelve_offload.start') self.compute.driver.power_off(instance) self.compute._get_power_state(self.context, instance).AndReturn(123) db.instance_update_and_get_original( self.context, instance['uuid'], { 'power_state': 123, 'host': None, 'node': None, 'vm_state': vm_states.SHELVED_OFFLOADED, 'task_state': None, 'expected_task_state': [task_states.SHELVING, task_states.SHELVING_OFFLOADING] }, update_cells=False, columns_to_join=['metadata', 'system_metadata'], ).AndReturn((db_instance, db_instance)) self.compute._notify_about_instance_usage(self.context, instance, 'shelve_offload.end') self.mox.ReplayAll() self.compute.shelve_instance(self.context, instance, image_id=image_id, clean_shutdown=clean_shutdown)
def test_unshelve(self): db_instance = jsonutils.to_primitive(self._create_fake_instance()) instance = objects.Instance.get_by_uuid( self.context, db_instance['uuid'], expected_attrs=['metadata', 'system_metadata']) instance.task_state = task_states.UNSHELVING instance.save() image = {'id': 'fake_id'} host = 'fake-mini' node = test_compute.NODENAME limits = {} filter_properties = {'limits': limits} cur_time = timeutils.utcnow() cur_time_tz = cur_time.replace(tzinfo=iso8601.iso8601.Utc()) timeutils.set_time_override(cur_time) sys_meta = dict(instance.system_metadata) sys_meta['shelved_at'] = timeutils.strtime(at=cur_time) sys_meta['shelved_image_id'] = image['id'] sys_meta['shelved_host'] = host self.mox.StubOutWithMock(self.compute, '_notify_about_instance_usage') self.mox.StubOutWithMock(self.compute, '_prep_block_device') self.mox.StubOutWithMock(self.compute.driver, 'spawn') self.mox.StubOutWithMock(self.compute, '_get_power_state') self.mox.StubOutWithMock(self.rt, 'instance_claim') self.mox.StubOutWithMock(db, 'instance_update_and_get_original') self.mox.StubOutWithMock(self.compute.network_api, 'migrate_instance_finish') self.deleted_image_id = None def fake_delete(self2, ctxt, image_id): self.deleted_image_id = image_id def fake_claim(context, instance, limits): instance.host = self.compute.host return claims.Claim(context, db_instance, self.rt, _fake_resources()) fake_image.stub_out_image_service(self.stubs) self.stubs.Set(fake_image._FakeImageService, 'delete', fake_delete) self.compute._notify_about_instance_usage(self.context, instance, 'unshelve.start') db.instance_update_and_get_original( self.context, instance['uuid'], { 'task_state': task_states.SPAWNING }, update_cells=False, columns_to_join=['metadata', 'system_metadata'], ).AndReturn((db_instance, db_instance)) self.compute._prep_block_device( self.context, instance, mox.IgnoreArg(), do_check_attach=False).AndReturn('fake_bdm') db_instance['key_data'] = None db_instance['auto_disk_config'] = None self.compute.network_api.migrate_instance_finish( self.context, instance, { 'source_compute': '', 'dest_compute': self.compute.host }) self.compute.driver.spawn(self.context, instance, image, injected_files=[], admin_password=None, network_info=[], block_device_info='fake_bdm') self.compute._get_power_state(self.context, instance).AndReturn(123) db.instance_update_and_get_original( self.context, instance['uuid'], { 'power_state': 123, 'vm_state': vm_states.ACTIVE, 'task_state': None, 'image_ref': instance['image_ref'], 'key_data': None, 'host': self.compute.host, # rt.instance_claim set this 'auto_disk_config': False, 'expected_task_state': task_states.SPAWNING, 'launched_at': cur_time_tz }, update_cells=False, columns_to_join=['metadata', 'system_metadata']).AndReturn( (db_instance, dict(db_instance, host=self.compute.host))) self.compute._notify_about_instance_usage(self.context, instance, 'unshelve.end') self.mox.ReplayAll() with mock.patch.object(self.rt, 'instance_claim', side_effect=fake_claim): self.compute.unshelve_instance(self.context, instance, image=image, filter_properties=filter_properties, node=node) self.assertEqual(image['id'], self.deleted_image_id) self.assertEqual(instance.host, self.compute.host)
def inject_network_info(self, ctxt, instance): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('inject_network_info', instance=instance_p), topic=_compute_topic(self.topic, ctxt, None, instance))
def inject_file(self, ctxt, instance, path, file_contents): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('inject_file', instance=instance_p, path=path, file_contents=file_contents), topic=_compute_topic(self.topic, ctxt, None, instance))
def pre_live_migration(self, ctxt, instance, block_migration, disk, host): instance_p = jsonutils.to_primitive(instance) return self.call(ctxt, self.make_msg('pre_live_migration', instance=instance_p, block_migration=block_migration, disk=disk), _compute_topic(self.topic, ctxt, host, None))
def unpause_instance(self, ctxt, instance): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('unpause_instance', instance=instance_p), topic=_compute_topic(self.topic, ctxt, None, instance))
def reboot_instance(self, ctxt, instance, reboot_type): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('reboot_instance', instance=instance_p, reboot_type=reboot_type), topic=_compute_topic(self.topic, ctxt, None, instance))
def remove_fixed_ip_from_instance(self, ctxt, instance, address): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('remove_fixed_ip_from_instance', instance=instance_p, address=address), topic=_compute_topic(self.topic, ctxt, None, instance))
def remove_volume_connection(self, ctxt, instance, volume_id, host): instance_p = jsonutils.to_primitive(instance) return self.call(ctxt, self.make_msg('remove_volume_connection', instance=instance_p, volume_id=volume_id), topic=_compute_topic(self.topic, ctxt, host, None))
def add_fixed_ip_to_instance(self, ctxt, instance, network_id): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('add_fixed_ip_to_instance', instance=instance_p, network_id=network_id), topic=_compute_topic(self.topic, ctxt, None, instance))
def ping(self, context, arg, timeout=None): arg_p = jsonutils.to_primitive(arg) msg = self.make_msg('ping', arg=arg_p) return self.call(context, msg, version='1.22', timeout=timeout)
def stop_instance(self, ctxt, instance, cast=True): rpc_method = self.cast if cast else self.call instance_p = jsonutils.to_primitive(instance) return rpc_method(ctxt, self.make_msg('stop_instance', instance=instance_p), topic=_compute_topic(self.topic, ctxt, None, instance))
def get_ec2_ids(self, context, instance): instance_p = jsonutils.to_primitive(instance) msg = self.make_msg('get_ec2_ids', instance=instance_p) return self.call(context, msg, version='1.42')
def test_unshelve_volume_backed(self): db_instance = jsonutils.to_primitive(self._create_fake_instance()) node = test_compute.NODENAME limits = {} filter_properties = {'limits': limits} cur_time = timeutils.utcnow() cur_time_tz = cur_time.replace(tzinfo=iso8601.iso8601.Utc()) timeutils.set_time_override(cur_time) instance = objects.Instance.get_by_uuid( self.context, db_instance['uuid'], expected_attrs=['metadata', 'system_metadata']) instance.task_state = task_states.UNSHELVING instance.save() self.mox.StubOutWithMock(self.compute, '_notify_about_instance_usage') self.mox.StubOutWithMock(self.compute, '_prep_block_device') self.mox.StubOutWithMock(self.compute.driver, 'spawn') self.mox.StubOutWithMock(self.compute, '_get_power_state') self.mox.StubOutWithMock(self.rt, 'instance_claim') self.mox.StubOutWithMock(db, 'instance_update_and_get_original') self.mox.StubOutWithMock(self.compute.network_api, 'migrate_instance_finish') self.compute._notify_about_instance_usage(self.context, instance, 'unshelve.start') db.instance_update_and_get_original( self.context, instance['uuid'], { 'task_state': task_states.SPAWNING }, update_cells=False, columns_to_join=['metadata', 'system_metadata']).AndReturn( (db_instance, db_instance)) self.compute._prep_block_device( self.context, instance, mox.IgnoreArg(), do_check_attach=False).AndReturn('fake_bdm') db_instance['key_data'] = None db_instance['auto_disk_config'] = None self.compute.network_api.migrate_instance_finish( self.context, instance, { 'source_compute': '', 'dest_compute': self.compute.host }) self.rt.instance_claim(self.context, instance, limits).AndReturn( claims.Claim(self.context, db_instance, self.rt, _fake_resources())) self.compute.driver.spawn(self.context, instance, None, injected_files=[], admin_password=None, network_info=[], block_device_info='fake_bdm') self.compute._get_power_state(self.context, instance).AndReturn(123) db.instance_update_and_get_original( self.context, instance['uuid'], { 'power_state': 123, 'vm_state': vm_states.ACTIVE, 'task_state': None, 'key_data': None, 'auto_disk_config': False, 'expected_task_state': task_states.SPAWNING, 'launched_at': cur_time_tz }, update_cells=False, columns_to_join=['metadata', 'system_metadata']).AndReturn( (db_instance, db_instance)) self.compute._notify_about_instance_usage(self.context, instance, 'unshelve.end') self.mox.ReplayAll() self.compute.unshelve_instance(self.context, instance, image=None, filter_properties=filter_properties, node=node)
def reserve_block_device_name(self, ctxt, instance, device): instance_p = jsonutils.to_primitive(instance) return self.call(ctxt, self.make_msg('reserve_block_device_name', instance=instance_p, device=device), topic=_compute_topic(self.topic, ctxt, None, instance))
def instance_destroy_at_top(self, ctxt, instance): """Destroy instance at API level.""" if not CONF.cells.enable: return instance_p = jsonutils.to_primitive(instance) self.client.cast(ctxt, 'instance_destroy_at_top', instance=instance_p)
def security_groups_trigger_handler(self, context, event, args): args_p = jsonutils.to_primitive(args) msg = self.make_msg('security_groups_trigger_handler', event=event, args=args_p) return self.call(context, msg, version='1.40')
def compute_stop(self, context, instance, do_cast=True): instance_p = jsonutils.to_primitive(instance) msg = self.make_msg('compute_stop', instance=instance_p, do_cast=do_cast) return self.call(context, msg, version='1.43')
def quota_rollback(self, context, reservations): reservations_p = jsonutils.to_primitive(reservations) msg = self.make_msg('quota_rollback', reservations=reservations_p) return self.call(context, msg, version='1.41')
def get_vnc_console(self, ctxt, instance, console_type): instance_p = jsonutils.to_primitive(instance) return self.call(ctxt, self.make_msg('get_vnc_console', instance=instance_p, console_type=console_type), topic=_compute_topic(self.topic, ctxt, None, instance))
def set_admin_password(self, ctxt, instance, new_pass): instance_p = jsonutils.to_primitive(instance) return self.call(ctxt, self.make_msg('set_admin_password', instance=instance_p, new_pass=new_pass), topic=_compute_topic(self.topic, ctxt, None, instance))
def get_diagnostics(self, ctxt, instance): instance_p = jsonutils.to_primitive(instance) return self.call(ctxt, self.make_msg('get_diagnostics', instance=instance_p), topic=_compute_topic(self.topic, ctxt, None, instance))
def get_console_output(self, ctxt, instance, tail_length): instance_p = jsonutils.to_primitive(instance) return self.call(ctxt, self.make_msg('get_console_output', instance=instance_p, tail_length=tail_length), topic=_compute_topic(self.topic, ctxt, None, instance))
def service_update(self, context, service, values): service_p = jsonutils.to_primitive(service) msg = self.make_msg('service_update', service=service_p, values=values) return self.call(context, msg, version='1.34')
def reset_network(self, ctxt, instance): instance_p = jsonutils.to_primitive(instance) self.cast(ctxt, self.make_msg('reset_network', instance=instance_p), topic=_compute_topic(self.topic, ctxt, None, instance))