Class: CopyMsWindowsAmi::TargetVolumeCreatedState

Inherits:
CopyMsWindowsAmiState show all
Defined in:
lib/scripts/ec2/copy_mswindows_ami.rb

Overview

Snapshot Operation done. Now this snapshot must be registered as AMI Steps:

- launch same AMI as the one we want to copy and stop it (after it has boot up): use helper_ami_id
- detach the volume of this instance and attach the new volume
- start the instance to see if everything is good, then stop it
- create an AMI from this instance

Instance Attribute Summary

Attributes inherited from ScriptExecutionState

#context, #logger

Instance Method Summary collapse

Methods inherited from CopyMsWindowsAmiState

load_state, #local_region, #remote_region

Methods inherited from ScriptExecutionState

#done?, #end_state, #failed?, #initialize, #register_state_change_listener, #start_state_machine, #to_s

Methods included from StateTransitionHelper

#attach_volume, #connect, #copy_distribution, #create_fs, #create_labeled_fs, #create_snapshot, #create_volume, #create_volume_from_snapshot, #delete_snapshot, #delete_volume, #detach_volume, #determine_file, #disable_ssh_tty, #disconnect, #ec2_handler, #ec2_handler=, #enable_ssh_tty, #get_aws_kernel_image_aki, #get_aws_region_from_endpoint, #get_partition_fs_type, #get_partition_fs_type_and_label, #get_partition_label, #get_root_device_name, #get_root_partition_fs_type, #get_root_partition_fs_type_and_label, #get_root_partition_label, #get_root_volume_id, #launch_instance, #local_decompress_and_dump_file_to_device, #local_dump_and_compress_device_to_file, #mount_fs, #mount_fs_old, #register_snapshot, #remote_copy, #remote_copy_old, #remote_handler, #remote_handler=, #retrieve_instances, #retrieve_security_groups, #shut_down_instance, #snapshot_accessible, #start_instance, #stop_instance, #unmount_fs, #upload_file, #zip_volume

Methods included from VCloudTransitionHelper

#retrieve_ip_services

Constructor Details

This class inherits a constructor from ScriptExecutionState

Instance Method Details

#enterObject



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'lib/scripts/ec2/copy_mswindows_ami.rb', line 422

def enter()
  post_message("Launching Helper AMI '#{@context[:helper_ami_id]}' for attaching migrated volume...")
  remote_region()
  #XXX: launch instance in the right AZ
  result = launch_instance(@context[:helper_ami_id], @context[:target_key_name], @context[:target_security_groups], 
                           nil, nil, @context[:target_availability_zone])
  @context[:helper_instance_id] = result.first
  @context[:helper_dns_name] = result[1]
  @context[:helper_availability_zone] = result[2]
  @context[:helper_root_device_name] = result[6]

  #XXX:
  #  - wait for it to be running, and then stop it
  #  - wait for it to be stopped, and then start it with the new volume
  stop_instance(@context[:helper_instance_id])
  root_volume_id = get_root_volume_id(@context[:helper_instance_id])
  detach_volume(root_volume_id, @context[:helper_instance_id])
  attach_volume(@context[:target_volume_id], @context[:helper_instance_id], @context[:helper_root_device_name])
  start_instance(@context[:helper_instance_id])

  #XXX: return running instance for now
  @context[:result][:instance_id] = result.first

  #XXX: stop this instance
  stop_instance(@context[:helper_instance_id])

  #XXX: register as AMI
  new_ami_id = create_image(:instance_id => @context[:helper_instance_id], 
    :name => @context[:name], :description => @context[:description])
  @context[:result][:image_id] = new_ami_id

  AmiRegisteredState.new(@context)
end