~awstools-dev/ubuntu/lucid/ec2-ami-tools/lucid

« back to all changes in this revision

Viewing changes to lib/ec2/amitools/migratebundleparameters.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-01-13 11:46:59 UTC
  • Revision ID: james.westby@ubuntu.com-20090113114659-d2g70wekc6b0dz3x
Tags: 1.3-31057-0ubuntu1
* New upstream version. (LP: #310547)
* debian/patches/exclude-udev-rules.patch: Exclude the copying of 
  /etc/udev/rules.d/70-persistent-net.rules and
  /etc/udev/rules.d/z25_persistent-net.rules when rebundling an image. 
  (LP: #308548)
* debian/patches/point-to-right-place: Updated patch to take in account
  ec2-migrate-manifest and ec2-migrate-bundle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
10
 
 
11
require 'ec2/amitools/parameters_base'
 
12
require 'ec2/platform/current'
 
13
 
 
14
#------------------------------------------------------------------------------#
 
15
 
 
16
class MigrateBundleParameters < ParametersBase
 
17
  include EC2::Platform::Current::Constants
 
18
 
 
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."
 
41
 
 
42
  attr_accessor :user_pk_path,
 
43
                :user_cert_path,
 
44
                :ec2_cert_path,
 
45
                :user,
 
46
                :pass,
 
47
                :kernel_id,
 
48
                :ramdisk_id,
 
49
                :s3_url,
 
50
                :bucket,
 
51
                :dest_bucket,
 
52
                :manifest_name,
 
53
                :location,
 
54
                :acl,
 
55
                :retry,
 
56
                :mapping_file,
 
57
                :mapping_url,
 
58
                :use_mapping,
 
59
                :region
 
60
  
 
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
 
65
    end
 
66
    
 
67
    on('-k', '--privatekey PATH', String, USER_PK_PATH_DESCRIPTION) do |path|
 
68
      assert_file_exists(path, '--privatekey')
 
69
      @user_pk_path = path
 
70
    end
 
71
    
 
72
    on('-m', '--manifest NAME', String, MANIFEST_DESCRIPTION) do |manifest|
 
73
      raise InvalidValue.new("--manifest", manifest) unless manifest =~ /\.manifest\.xml$/
 
74
      @manifest_name = manifest
 
75
    end
 
76
    
 
77
    on('-b', '--bucket BUCKET', String, BUCKET_DESCRIPTION) do |bucket|
 
78
      assert_good_bucket(bucket, '--bucket')
 
79
      @bucket = bucket
 
80
    end
 
81
    
 
82
    on('-d', '--destination-bucket BUCKET', String, DEST_BUCKET_DESCRIPTION) do |bucket|
 
83
      assert_good_bucket(bucket, '--destination-bucket')
 
84
      @dest_bucket = bucket
 
85
    end
 
86
    
 
87
    on('-a', '--access-key USER', String, USER_DESCRIPTION) do |user|
 
88
      @user = user
 
89
    end
 
90
    
 
91
    on('-s', '--secret-key PASSWORD', String, PASS_DESCRIPTION) do |pass|
 
92
      @pass = pass
 
93
    end
 
94
  end
 
95
  
 
96
  def optional_params()
 
97
    on('--ec2cert PATH', String, *EC2_CERT_PATH_DESCRIPTION) do |path|
 
98
      assert_file_exists(path, '--ec2cert')
 
99
      @ec2_cert_path = path
 
100
    end
 
101
    
 
102
    on('--acl ACL', String, *ACL_DESCRIPTION) do |acl|
 
103
      raise InvalidValue.new('--acl', acl) unless ['public-read', 'aws-exec-read'].include?(acl)
 
104
      @acl = acl
 
105
    end
 
106
 
 
107
    on('--url URL', String, URL_DESCRIPTION) do |url|
 
108
      @s3_url = url
 
109
    end
 
110
    
 
111
    on('--retry', RETRY_DESCRIPTION) do
 
112
      @retry = true
 
113
    end
 
114
    
 
115
    on('--location LOCATION', LOCATION_DESCRIPTION) do |location|
 
116
      @location = location
 
117
      @location = :unconstrained if @location == "US"
 
118
    end
 
119
    
 
120
    on('--kernel KERNEL_ID', String, KERNEL_DESCRIPTION) do |kernel_id|
 
121
      @kernel_id = kernel_id
 
122
    end
 
123
    
 
124
    on('--ramdisk RAMDISK_ID', String, RAMDISK_DESCRIPTION) do |ramdisk_id|
 
125
      @ramdisk_id = ramdisk_id
 
126
    end
 
127
    
 
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
 
131
    end
 
132
 
 
133
    on('--mapping-url URL', String, MAPPING_URL_DESCRIPTION) do |mapping_url|
 
134
      @mapping_url = mapping_url
 
135
    end
 
136
 
 
137
    on('--no-mapping', String, NO_MAPPING_DESCRIPTION) do
 
138
      @use_mapping = false
 
139
    end
 
140
 
 
141
    on('--region REGION', String, REGION_DESCRIPTION) do |region|
 
142
      @region = region
 
143
    end
 
144
  end
 
145
 
 
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
 
154
  end
 
155
 
 
156
  def set_defaults()
 
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.
 
161
  end
 
162
end