diff --git a/src/vmm_mad/remotes/ec2/ec2_driver.rb b/src/vmm_mad/remotes/ec2/ec2_driver.rb index e45c36625b..59d0d98113 100755 --- a/src/vmm_mad/remotes/ec2/ec2_driver.rb +++ b/src/vmm_mad/remotes/ec2/ec2_driver.rb @@ -198,7 +198,8 @@ class EC2Driver :ip_address, :subnet_id, :security_groups, - :instance_type + :instance_type, + :image_id ] # EC2 constructor, loads credentials and endpoint @@ -419,7 +420,7 @@ private ec2 end - # Retrive the vm information from the EC2 instance + # Retrieve the vm information from the EC2 instance def parse_poll(instance) begin info = "#{POLL_ATTRIBUTE[:usedmemory]}=0 " \ @@ -457,6 +458,10 @@ private end } + vm_template_to_one = vm_to_one(instance) + vm_template_to_one = Base64.encode64(vm_template_to_one).gsub("\n","") + info << "IMPORT_TEMPLATE=#{vm_template_to_one}" + info rescue # Unkown state if exception occurs retrieving information from @@ -566,5 +571,25 @@ private exit(-1) end end + + # Build template for importation + def vm_to_one(instance) + cpu, mem = instance_type_capacity(instance.instance_type) + + str = "NAME = \"Instance from #{instance.image_id}\"\n"\ + "CPU = \"#{cpu}\"\n"\ + "vCPU = \"#{cpu}\"\n"\ + "MEMORY = \"#{mem}\"\n"\ + "HYPERVISOR = \"ec2\"\n"\ + "PUBLIC_CLOUD = [\n"\ + " TYPE =\"ec2\",\n"\ + " AMI =\"#{instance.image_id}\"\n"\ + "]\n"\ + "IMPORT_VM_ID = \"#{instance.image_id}\"\n"\ + "SCHED_REQUIREMENTS=\"NAME=\\\"#{@host}\\\"\"\n"\ + "DESCRIPTION = \"Instance imported from EC2\"\n" + + str + end end