Class: MigrateManifestParameters

Inherits:
ParametersBase show all
Defined in:
lib/ec2/amitools/migratemanifestparameters.rb

Overview

——————————————————————————#

Constant Summary collapse

MANIFEST_DESCRIPTION =
"The path to the manifest file."
DIRECTORY_DESCRIPTION =
["The directory containing the bundled AMI parts to upload.",
"Defaults to the directory containing the manifest."]
EC2_CERT_PATH_DESCRIPTION =
['The path to the EC2 X509 public key certificate bundled into the AMI.',
"Defaults to the certificate of the region (usually '#{Bundling::EC2_X509_CERT}')."]
KERNEL_DESCRIPTION =
"Kernel id to bundle into the AMI."
RAMDISK_DESCRIPTION =
"Ramdisk id to bundle into the AMI."
USER_DESCRIPTION =
"The user's AWS access key ID."
PASS_DESCRIPTION =
"The user's AWS secret access key."
NO_MAPPING_DESCRIPTION =
"Do not perform automatic mappings."
REGION_DESCRIPTION =
"Region to look up in the mapping file."

Constants inherited from ParametersBase

ParametersBase::BATCH_DESCRIPTION, ParametersBase::DEBUG_DESCRIPTION, ParametersBase::HELP_DESCRIPTION, ParametersBase::MANUAL_DESCRIPTION, ParametersBase::USER_ACCOUNT_DESCRIPTION, ParametersBase::USER_CERT_PATH_DESCRIPTION, ParametersBase::USER_PK_PATH_DESCRIPTION, ParametersBase::VERSION_DESCRIPTION

Instance Attribute Summary collapse

Attributes inherited from ParametersBase

#batch_mode, #debug, #manual, #show_help, #version

Instance Method Summary collapse

Methods inherited from ParametersBase

#assert_directory_exists, #assert_exists, #assert_file_executable, #assert_file_exists, #assert_glob_expands, #assert_good_key, #assert_option_in, #common_params, #early_exit?, #initialize, #interactive?, #version_copyright_string

Constructor Details

This class inherits a constructor from ParametersBase

Instance Attribute Details

#ec2_cert_pathObject

Returns the value of attribute ec2_cert_path.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def ec2_cert_path
  @ec2_cert_path
end

#kernel_idObject

Returns the value of attribute kernel_id.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def kernel_id
  @kernel_id
end

#manifest_pathObject

Returns the value of attribute manifest_path.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def manifest_path
  @manifest_path
end

#passObject

Returns the value of attribute pass.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def pass
  @pass
end

#ramdisk_idObject

Returns the value of attribute ramdisk_id.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def ramdisk_id
  @ramdisk_id
end

#regionObject

Returns the value of attribute region.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def region
  @region
end

#use_mappingObject

Returns the value of attribute use_mapping.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def use_mapping
  @use_mapping
end

#userObject

Returns the value of attribute user.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def user
  @user
end

#user_cert_pathObject

Returns the value of attribute user_cert_path.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def user_cert_path
  @user_cert_path
end

#user_pk_pathObject

Returns the value of attribute user_pk_path.



32
33
34
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 32

def user_pk_path
  @user_pk_path
end

Instance Method Details

#mandatory_paramsObject

—————————————————————————-#



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 45

def mandatory_params()
  on('-c', '--cert PATH', String, USER_CERT_PATH_DESCRIPTION) do |path|
    assert_file_exists(path, '--cert')
    @user_cert_path = path
  end
  
  on('-k', '--privatekey PATH', String, USER_PK_PATH_DESCRIPTION) do |path|
    assert_file_exists(path, '--privatekey')
    @user_pk_path = path
  end

  on('-m', '--manifest PATH', String, MANIFEST_DESCRIPTION) do |manifest|
    assert_file_exists(manifest, '--manifest')
    @manifest_path = manifest
  end
end

#optional_paramsObject

—————————————————————————-#



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 64

def optional_params()
  on('-a', '--access-key USER', String, USER_DESCRIPTION) do |user|
    @user = user
  end
  
  on('-s', '--secret-key PASSWORD', String, PASS_DESCRIPTION) do |pass|
    @pass = pass
  end
  
  on('--ec2cert PATH', String, *EC2_CERT_PATH_DESCRIPTION) do |path|
    assert_file_exists(path, '--ec2cert')
    @ec2_cert_path = path
  end
  
  on('--kernel KERNEL_ID', String, KERNEL_DESCRIPTION) do |kernel_id|
    @kernel_id = kernel_id
  end
  
  on('--ramdisk RAMDISK_ID', String, RAMDISK_DESCRIPTION) do |ramdisk_id|
    @ramdisk_id = ramdisk_id
  end
  
  on('--no-mapping', String, NO_MAPPING_DESCRIPTION) do
    @use_mapping = false
  end

  on('--region REGION', String, REGION_DESCRIPTION) do |region|
    @region = region
  end
end

#set_defaultsObject

—————————————————————————-#



111
112
113
114
115
116
117
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 111

def set_defaults()
  @ec2_cert_path ||= case
    when (@region=="us-gov-west-1") then Bundling::EC2_X509_GOV_CERT
    when (@region=="cn-north-1") then Bundling::EC2_X509_CN_NORTH_1_CERT
    else Bundling::EC2_X509_CERT
  end
end

#validate_paramsObject

—————————————————————————-#

Raises:



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ec2/amitools/migratemanifestparameters.rb', line 97

def validate_params()
  raise MissingMandatory.new('--manifest') unless @manifest_path
  raise MissingMandatory.new('--cert') unless @user_cert_path
  raise MissingMandatory.new('--privatekey') unless @user_pk_path
  @use_mapping = true if @use_mapping.nil? # False is different.
  if @use_mapping
    raise ParameterExceptions::Error.new('If using automatic mapping, --region must be provided.') unless @region
    raise ParameterExceptions::Error.new('If using automatic mapping, --access-key must be provided.') unless @user
    raise ParameterExceptions::Error.new('If using automatic mapping, --secret-key must be provided.') unless @pass
  end
end