1
# Copyright 2008 Amazon.com, Inc. or its affiliates. All Rights
2
# Reserved. Licensed under the Amazon Software License (the
3
# "License"). You may not use this file except in compliance with the
4
# License. A copy of the License is located at
5
# http://aws.amazon.com/asl or in the "license" file accompanying this
6
# file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
# the License for the specific language governing permissions and
9
# limitations under the License.
11
require 'ec2/amitools/parameters_base'
12
require 'ec2/platform/current'
14
#------------------------------------------------------------------------------#
16
class MigrateBundleParameters < ParametersBase
17
include EC2::Platform::Current::Constants
19
MANIFEST_DESCRIPTION = "The name the manifest file."
20
DIRECTORY_DESCRIPTION = ["The directory containing the bundled AMI parts to upload.",
21
"Defaults to the directory containing the manifest."]
22
USER_CERT_PATH_DESCRIPTION = "The path to the user's PEM encoded RSA public key certificate file."
23
USER_PK_PATH_DESCRIPTION = "The path to the user's PEM encoded RSA private key file."
24
EC2_CERT_PATH_DESCRIPTION = ['The path to the EC2 X509 public key certificate bundled into the AMI.',
25
"Defaults to '#{Bundling::EC2_X509_CERT}'."]
26
KERNEL_DESCRIPTION = "Kernel id to bundle into the AMI."
27
RAMDISK_DESCRIPTION = "Ramdisk id to bundle into the AMI."
28
DEST_BUCKET_DESCRIPTION = "The bucket to copy bundle to. Created if nonexistent."
29
BUCKET_DESCRIPTION = "The bucket containing the AMI to be migrated."
30
USER_DESCRIPTION = "The user's AWS access key ID."
31
PASS_DESCRIPTION = "The user's AWS secret access key."
32
ACL_DESCRIPTION = ["The access control list policy [\"public-read\" | \"aws-exec-read\"].",
33
"Defaults to \"aws-exec-read\"."]
34
URL_DESCRIPTION = "The S3 service URL. Defaults to https://s3.amazonaws.com."
35
RETRY_DESCRIPTION = "Automatically retry failed uploads. Use with caution."
36
LOCATION_DESCRIPTION = "The location of the bucket to upload to [EU,US]."
37
MAPPING_FILE_DESCRIPTION = "File containing kernel/ramdisk region mappings."
38
MAPPING_URL_DESCRIPTION = "URL of file containing kernel/ramdisk region mappings."
39
NO_MAPPING_DESCRIPTION = "Do not perform automatic mappings."
40
REGION_DESCRIPTION = "Region to look up in the mapping file."
42
attr_accessor :user_pk_path,
61
def mandatory_params()
62
on('-c', '--cert PATH', String, USER_CERT_PATH_DESCRIPTION) do |path|
63
assert_file_exists(path, '--cert')
64
@user_cert_path = path
67
on('-k', '--privatekey PATH', String, USER_PK_PATH_DESCRIPTION) do |path|
68
assert_file_exists(path, '--privatekey')
72
on('-m', '--manifest NAME', String, MANIFEST_DESCRIPTION) do |manifest|
73
raise InvalidValue.new("--manifest", manifest) unless manifest =~ /\.manifest\.xml$/
74
@manifest_name = manifest
77
on('-b', '--bucket BUCKET', String, BUCKET_DESCRIPTION) do |bucket|
78
assert_good_bucket(bucket, '--bucket')
82
on('-d', '--destination-bucket BUCKET', String, DEST_BUCKET_DESCRIPTION) do |bucket|
83
assert_good_bucket(bucket, '--destination-bucket')
87
on('-a', '--access-key USER', String, USER_DESCRIPTION) do |user|
91
on('-s', '--secret-key PASSWORD', String, PASS_DESCRIPTION) do |pass|
97
on('--ec2cert PATH', String, *EC2_CERT_PATH_DESCRIPTION) do |path|
98
assert_file_exists(path, '--ec2cert')
102
on('--acl ACL', String, *ACL_DESCRIPTION) do |acl|
103
raise InvalidValue.new('--acl', acl) unless ['public-read', 'aws-exec-read'].include?(acl)
107
on('--url URL', String, URL_DESCRIPTION) do |url|
111
on('--retry', RETRY_DESCRIPTION) do
115
on('--location LOCATION', LOCATION_DESCRIPTION) do |location|
117
@location = :unconstrained if @location == "US"
120
on('--kernel KERNEL_ID', String, KERNEL_DESCRIPTION) do |kernel_id|
121
@kernel_id = kernel_id
124
on('--ramdisk RAMDISK_ID', String, RAMDISK_DESCRIPTION) do |ramdisk_id|
125
@ramdisk_id = ramdisk_id
128
on('--mapping-file FILE', String, MAPPING_FILE_DESCRIPTION) do |mapping_file|
129
assert_file_exists(mapping_file, '--mapping-file')
130
@mapping_file = mapping_file
133
on('--mapping-url URL', String, MAPPING_URL_DESCRIPTION) do |mapping_url|
134
@mapping_url = mapping_url
137
on('--no-mapping', String, NO_MAPPING_DESCRIPTION) do
141
on('--region REGION', String, REGION_DESCRIPTION) do |region|
146
def validate_params()
147
raise MissingMandatory.new('--manifest') unless @manifest_name
148
raise MissingMandatory.new('--cert') unless @user_cert_path
149
raise MissingMandatory.new('--privatekey') unless @user_pk_path
150
raise MissingMandatory.new('--bucket') unless @bucket
151
raise MissingMandatory.new('--destination-bucket') unless @dest_bucket
152
raise MissingMandatory.new('--access-key') unless @user
153
raise MissingMandatory.new('--secret-key') unless @pass
157
@acl ||= 'aws-exec-read'
158
@s3_url ||= 'https://s3.amazonaws.com'
159
@ec2_cert_path ||= Bundling::EC2_X509_CERT
160
@use_mapping = true if @use_mapping.nil? # False is different.