def cloudlet_create_overlay_finish(self, context, instance, overlay_name, extra_properties=None): project_id, user_id = quotas_obj.ids_from_instance(context, instance) original_task_state = instance.task_state quotas = self._create_reservations(context,instance, original_task_state,project_id, user_id) overlay_meta_properties = { CloudletAPI.PROPERTY_KEY_CLOUDLET: True, CloudletAPI.PROPERTY_KEY_CLOUDLET_TYPE: CloudletAPI.IMAGE_TYPE_OVERLAY, } overlay_meta_properties.update(extra_properties or {}) recv_overlay_meta = self._cloudlet_create_image( context, instance, overlay_name, 'snapshot', extra_properties=overlay_meta_properties) instance.task_state = task_states.IMAGE_SNAPSHOT instance.save(expected_task_state=[None]) # api request version = self.client.target.version cctxt = self.client.prepare( server=nova_rpc._compute_host(None, instance), version=version ) cctxt.cast(context, 'cloudlet_overlay_finish', instance=instance,reservations=quotas.reservations, overlay_name=overlay_name, overlay_id=recv_overlay_meta['id']) return recv_overlay_meta
def cloudlet_handoff(self, context, instance, handoff_url, dest_token=None, dest_vmname=None, extra_properties=None): project_id, user_id = quotas_obj.ids_from_instance(context, instance) original_task_state = instance.task_state quotas = self._create_reservations(context, instance, original_task_state, project_id, user_id) recv_residue_meta = None parsed_handoff_url = urlsplit(handoff_url) residue_glance_id = None if parsed_handoff_url.scheme == "file": # save the VM residue to glance file dest_vm_name = parsed_handoff_url.netloc residue_meta_properties = { CloudletAPI.PROPERTY_KEY_CLOUDLET: True, CloudletAPI.PROPERTY_KEY_CLOUDLET_TYPE: CloudletAPI.IMAGE_TYPE_OVERLAY, } residue_meta_properties.update(extra_properties or {}) recv_residue_meta = self._cloudlet_create_image( context, instance, dest_vm_name, 'snapshot', extra_properties=residue_meta_properties) instance.task_state = task_states.IMAGE_SNAPSHOT instance.save(expected_task_state=[None]) residue_glance_id = recv_residue_meta['id'] elif parsed_handoff_url.scheme == "http": # handoff to other OpenStack # Send message to the destination ret_value = self._prepare_handoff_dest(urlparse(handoff_url), dest_token, instance, dest_vmname) # parse handoff URL from the return handoff_dest_addr = ret_value.get("handoff", None) if handoff_dest_addr is None: msg = "Cannot get handoff URL from the destination message" raise HandoffError(msg) handoff_url = "tcp://%s:%s" % (handoff_dest_addr['server_ip'], handoff_dest_addr['server_port']) # api request version = self.client.target.version cctxt = self.client.prepare(server=nova_rpc._compute_host( None, instance), version=version) cctxt.cast(context, 'cloudlet_handoff', instance=instance, reservations=quotas.reservations, handoff_url=handoff_url, residue_glance_id=residue_glance_id) return residue_glance_id
def cloudlet_handoff(self, context, instance, handoff_url, dest_token=None, dest_vmname=None, extra_properties=None): project_id, user_id = quotas_obj.ids_from_instance(context, instance) original_task_state = instance.task_state quotas = self._create_reservations(context,instance, original_task_state,project_id, user_id) recv_residue_meta = None parsed_handoff_url = urlsplit(handoff_url) residue_glance_id = None if parsed_handoff_url.scheme == "file": # save the VM residue to glance file dest_vm_name = parsed_handoff_url.netloc residue_meta_properties = { CloudletAPI.PROPERTY_KEY_CLOUDLET: True, CloudletAPI.PROPERTY_KEY_CLOUDLET_TYPE: CloudletAPI.IMAGE_TYPE_OVERLAY, } residue_meta_properties.update(extra_properties or {}) recv_residue_meta = self._cloudlet_create_image( context, instance, dest_vm_name, 'snapshot', extra_properties=residue_meta_properties ) instance.task_state = task_states.IMAGE_SNAPSHOT instance.save(expected_task_state=[None]) residue_glance_id = recv_residue_meta['id'] elif parsed_handoff_url.scheme == "http": # handoff to other OpenStack # Send message to the destination ret_value = self._prepare_handoff_dest(urlparse(handoff_url), dest_token, instance, dest_vmname) # parse handoff URL from the return handoff_dest_addr = ret_value.get("handoff", None) if handoff_dest_addr is None: msg = "Cannot get handoff URL from the destination message" raise HandoffError(msg) handoff_url = "tcp://%s:%s" % (handoff_dest_addr['server_ip'], handoff_dest_addr['server_port']) # api request version = self.client.target.version cctxt = self.client.prepare( server=nova_rpc._compute_host(None, instance), version=version ) cctxt.cast(context, 'cloudlet_handoff', instance=instance,reservations=quotas.reservations, handoff_url=handoff_url, residue_glance_id=residue_glance_id) return residue_glance_id
def test_ids_from_instance_admin(self): project_id, user_id = quotas_obj.ids_from_instance( self.context.elevated(), self.instance) self.assertEqual('fake_user2', user_id) self.assertEqual('fake_proj2', project_id)