Class: Ami2EbsConversion

Inherits:
Ec2Script show all
Defined in:
lib/scripts/ec2/ami2_ebs_conversion.rb

Overview

Creates a bootable EBS storage from an existing AMI.

Defined Under Namespace

Classes: Ami2EbsConversionState, AmiStarted, CopyDone, Done, FileSystemCreated, FileSystemMounted, InitialState, SnapshotCreated, SnapshotRegistered, StorageAttached, StorageCreated, VolumeDeleted, VolumeDetached, VolumeUnmounted

Constant Summary

Constants inherited from Ec2Script

Ec2Script::CS_AWS_TIMEOUT, Ec2Script::CS_SEC_GRP_DESC, Ec2Script::CS_SEC_GRP_NAME

Instance Method Summary collapse

Methods inherited from Ec2Script

#get_execution_result, #post_message, #register_progress_message_listener, #register_state_change_listener, #start_script

Constructor Details

#initialize(input_params) ⇒ Ami2EbsConversion

Input parameters

  • aws_access_key => the Amazon AWS Access Key (see Your Account -> Security Credentials)

  • aws_secret_key => the Amazon AWS Secret Key

  • ami_id => the ID of the AMI to be converted

  • security_group_name => name of the security group to start

  • ssh_username => name of the ssh-user (default = root)

  • ssh_key_data => Key information for the security group that starts the AMI [if not set, use ssh_key_files]

  • ssh_key_files => Key information for the security group that starts the AMI

  • remote_command_handler => object that allows to connect via ssh and execute commands (optional)

  • ec2_api_handler => object that allows to access the EC2 API (optional)

  • ec2_api_server => server to connect to (option, default is us-east-1.ec2.amazonaws.com)

  • name => the name of the AMI to be created

  • description => description on AMI to be created (optional)

  • temp_device_name => [default /dev/sdj] device name used to attach the temporary storage; change this only if there’s already a volume attacged as /dev/sdj (optional, default is /dev/sdj)

  • root_device_name“=> [default /dev/sda1] device name used for the root device (optional)

  • connect_trials => number of trials during ssh connect to machine

  • connect_interval => seconds between two ssh connect trials



30
31
32
# File 'lib/scripts/ec2/ami2_ebs_conversion.rb', line 30

def initialize(input_params)
  super(input_params)
end

Instance Method Details

#check_input_parametersObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/scripts/ec2/ami2_ebs_conversion.rb', line 34

def check_input_parameters()
  if @input_params[:ami_id] == nil && !(@input_params[:ami_id] =~ /^ami-.*$/)
    raise Exception.new("Invalid AMI ID specified: #{@input_params[:ami_id]}")
  end
  ec2_helper = Ec2Helper.new(@input_params[:ec2_api_handler])
  # AWS Security Group
  if @input_params[:security_group_name] == nil
    @input_params[:security_group_name] = "default"
  end
  if !ec2_helper.check_open_port(@input_params[:security_group_name], 22)
    post_message("'#{@input_params[:security_group_name]}' Security Group not opened port 22 for connect via SSH in source region")
    @input_params[:security_group_name] = nil
  end
  # AWS KeyPair
  if @input_params[:key_name] == nil || @input_params[:key_name].empty?()
    raise Exception.new("No KeyPair name specified")
  else
   ec2_helper.check_keypair(@input_params[:key_name])
  end
  if @input_params[:name] == nil
    @input_params[:name] = "Boot EBS (for AMI #{@input_params[:ami_id]}) at #{Time.now.strftime('%d/%m/%Y %H.%M.%S')}"
  end
  if @input_params[:description] == nil
    @input_params[:description] = @input_params[:name]
  end
  if @input_params[:temp_device_name] == nil
    @input_params[:temp_device_name] = "/dev/sdj"
  end
  if @input_params[:root_device_name] == nil
    @input_params[:root_device_name] = "/dev/sda1"
  end
  # SSH Parameters
  if @input_params[:ssh_username] == nil
    @input_params[:ssh_username] = "root"
  end
  if @input_params[:ssh_keydata] == nil
    raise Exception.new("No Private Key for source region")
  else
    post_message("Checking SSH key for source region...")
    check_ssh_key(@input_params[:ssh_keydata])
  end
  if @input_params[:connect_trials] == nil
    @input_params[:connect_trials] = 6
  end
  if @input_params[:connect_interval] == nil
    @input_params[:connect_interval] = 20
  end
end

#load_initial_stateObject



83
84
85
# File 'lib/scripts/ec2/ami2_ebs_conversion.rb', line 83

def load_initial_state()
  Ami2EbsConversionState.load_state(@input_params)
end