ec2_amitools 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +54 -0
- data/bin/console +14 -0
- data/bin/ec2-ami-tools-version +6 -0
- data/bin/ec2-bundle-image +6 -0
- data/bin/ec2-bundle-vol +6 -0
- data/bin/ec2-delete-bundle +6 -0
- data/bin/ec2-download-bundle +6 -0
- data/bin/ec2-migrate-bundle +6 -0
- data/bin/ec2-migrate-manifest +6 -0
- data/bin/ec2-unbundle +6 -0
- data/bin/ec2-upload-bundle +6 -0
- data/bin/setup +8 -0
- data/etc/ec2/amitools/cert-ec2-cn-north-1.pem +28 -0
- data/etc/ec2/amitools/cert-ec2-gov.pem +17 -0
- data/etc/ec2/amitools/cert-ec2.pem +23 -0
- data/etc/ec2/amitools/mappings.csv +9 -0
- data/lib/ec2/amitools/bundle.rb +251 -0
- data/lib/ec2/amitools/bundle_base.rb +58 -0
- data/lib/ec2/amitools/bundleimage.rb +94 -0
- data/lib/ec2/amitools/bundleimageparameters.rb +42 -0
- data/lib/ec2/amitools/bundlemachineparameters.rb +60 -0
- data/lib/ec2/amitools/bundleparameters.rb +120 -0
- data/lib/ec2/amitools/bundlevol.rb +240 -0
- data/lib/ec2/amitools/bundlevolparameters.rb +164 -0
- data/lib/ec2/amitools/crypto.rb +379 -0
- data/lib/ec2/amitools/decryptmanifest.rb +20 -0
- data/lib/ec2/amitools/defaults.rb +12 -0
- data/lib/ec2/amitools/deletebundle.rb +212 -0
- data/lib/ec2/amitools/deletebundleparameters.rb +78 -0
- data/lib/ec2/amitools/downloadbundle.rb +161 -0
- data/lib/ec2/amitools/downloadbundleparameters.rb +84 -0
- data/lib/ec2/amitools/exception.rb +86 -0
- data/lib/ec2/amitools/fileutil.rb +219 -0
- data/lib/ec2/amitools/format.rb +127 -0
- data/lib/ec2/amitools/instance-data.rb +97 -0
- data/lib/ec2/amitools/manifest_wrapper.rb +132 -0
- data/lib/ec2/amitools/manifestv20070829.rb +361 -0
- data/lib/ec2/amitools/manifestv20071010.rb +403 -0
- data/lib/ec2/amitools/manifestv3.rb +331 -0
- data/lib/ec2/amitools/mapids.rb +148 -0
- data/lib/ec2/amitools/migratebundle.rb +222 -0
- data/lib/ec2/amitools/migratebundleparameters.rb +173 -0
- data/lib/ec2/amitools/migratemanifest.rb +225 -0
- data/lib/ec2/amitools/migratemanifestparameters.rb +118 -0
- data/lib/ec2/amitools/minimalec2.rb +116 -0
- data/lib/ec2/amitools/parameter_exceptions.rb +34 -0
- data/lib/ec2/amitools/parameters_base.rb +168 -0
- data/lib/ec2/amitools/region.rb +93 -0
- data/lib/ec2/amitools/s3toolparameters.rb +183 -0
- data/lib/ec2/amitools/showversion.rb +12 -0
- data/lib/ec2/amitools/syschecks.rb +27 -0
- data/lib/ec2/amitools/tool_base.rb +224 -0
- data/lib/ec2/amitools/unbundle.rb +107 -0
- data/lib/ec2/amitools/unbundleparameters.rb +65 -0
- data/lib/ec2/amitools/uploadbundle.rb +361 -0
- data/lib/ec2/amitools/uploadbundleparameters.rb +108 -0
- data/lib/ec2/amitools/util.rb +532 -0
- data/lib/ec2/amitools/version.rb +33 -0
- data/lib/ec2/amitools/xmlbuilder.rb +237 -0
- data/lib/ec2/amitools/xmlutil.rb +55 -0
- data/lib/ec2/common/constants.rb +16 -0
- data/lib/ec2/common/curl.rb +110 -0
- data/lib/ec2/common/headers.rb +95 -0
- data/lib/ec2/common/headersv4.rb +173 -0
- data/lib/ec2/common/http.rb +333 -0
- data/lib/ec2/common/s3support.rb +231 -0
- data/lib/ec2/common/signature.rb +68 -0
- data/lib/ec2/oem/LICENSE.txt +58 -0
- data/lib/ec2/oem/open4.rb +399 -0
- data/lib/ec2/platform/base/architecture.rb +26 -0
- data/lib/ec2/platform/base/constants.rb +54 -0
- data/lib/ec2/platform/base/pipeline.rb +181 -0
- data/lib/ec2/platform/base.rb +57 -0
- data/lib/ec2/platform/current.rb +55 -0
- data/lib/ec2/platform/linux/architecture.rb +35 -0
- data/lib/ec2/platform/linux/constants.rb +23 -0
- data/lib/ec2/platform/linux/fstab.rb +99 -0
- data/lib/ec2/platform/linux/identity.rb +16 -0
- data/lib/ec2/platform/linux/image.rb +811 -0
- data/lib/ec2/platform/linux/mtab.rb +74 -0
- data/lib/ec2/platform/linux/pipeline.rb +40 -0
- data/lib/ec2/platform/linux/rsync.rb +114 -0
- data/lib/ec2/platform/linux/tar.rb +124 -0
- data/lib/ec2/platform/linux/uname.rb +50 -0
- data/lib/ec2/platform/linux.rb +83 -0
- data/lib/ec2/platform/solaris/architecture.rb +28 -0
- data/lib/ec2/platform/solaris/constants.rb +30 -0
- data/lib/ec2/platform/solaris/fstab.rb +43 -0
- data/lib/ec2/platform/solaris/identity.rb +16 -0
- data/lib/ec2/platform/solaris/image.rb +327 -0
- data/lib/ec2/platform/solaris/mtab.rb +29 -0
- data/lib/ec2/platform/solaris/pipeline.rb +40 -0
- data/lib/ec2/platform/solaris/rsync.rb +24 -0
- data/lib/ec2/platform/solaris/tar.rb +36 -0
- data/lib/ec2/platform/solaris/uname.rb +21 -0
- data/lib/ec2/platform/solaris.rb +38 -0
- data/lib/ec2/platform.rb +69 -0
- data/lib/ec2/version.rb +8 -0
- data/lib/ec2_amitools +1 -0
- data/lib/ec2_amitools.rb +7 -0
- metadata +184 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright 2008-2014 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/tool_base'
|
12
|
+
require 'ec2/amitools/bundleparameters'
|
13
|
+
|
14
|
+
class BundleTool < AMITool
|
15
|
+
|
16
|
+
def user_override(name, value)
|
17
|
+
if interactive?
|
18
|
+
instr = interactive_prompt("Please specify a value for #{name} [#{value}]: ", name)
|
19
|
+
return instr.strip unless instr.nil? or instr.strip.empty?
|
20
|
+
end
|
21
|
+
value
|
22
|
+
end
|
23
|
+
|
24
|
+
def notify(msg)
|
25
|
+
$stdout.puts msg
|
26
|
+
if interactive?
|
27
|
+
print "Hit enter to continue anyway or Control-C to quit."
|
28
|
+
gets
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_parameters(params_class)
|
33
|
+
params = super(params_class)
|
34
|
+
|
35
|
+
if params.arch.nil?
|
36
|
+
params.arch = SysChecks::get_system_arch()
|
37
|
+
raise "missing or bad uname" if params.arch.nil?
|
38
|
+
params.arch = user_override("arch", params.arch)
|
39
|
+
end
|
40
|
+
|
41
|
+
unless BundleParameters::SUPPORTED_ARCHITECTURES.include?(params.arch)
|
42
|
+
unless warn_confirm("Unsupported architecture [#{params.arch}].")
|
43
|
+
raise EC2StopExecution.new()
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
tarcheck = SysChecks::good_tar_version?
|
48
|
+
raise "missing or bad tar" if tarcheck.nil?
|
49
|
+
unless tarcheck
|
50
|
+
unless warn_confirm("Possibly broken tar version found. Please use tar version 1.15 or later.")
|
51
|
+
raise EC2StopExecution.new()
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
params
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# Copyright 2008-2014 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/bundle'
|
12
|
+
require 'ec2/amitools/bundleimageparameters'
|
13
|
+
require 'ec2/amitools/bundle_base'
|
14
|
+
|
15
|
+
MAX_SIZE = 10 * 1024 * 1024 * 1024 # 10 GB in bytes.
|
16
|
+
BUNDLE_IMAGE_NAME = 'ec2-bundle-image'
|
17
|
+
|
18
|
+
# The manual.
|
19
|
+
BUNDLE_IMAGE_MANUAL=<<TEXT
|
20
|
+
#{BUNDLE_IMAGE_NAME} is a command line tool that creates a bundled Amazon Machine \
|
21
|
+
Image (AMI) from a specified loopback filesystem image.
|
22
|
+
|
23
|
+
#{BUNDLE_IMAGE_NAME} will:
|
24
|
+
- tar -S the AMI to preserve sparseness of the image file
|
25
|
+
- gzip the result
|
26
|
+
- encrypt it
|
27
|
+
- split it into parts
|
28
|
+
- generate a manifest file describing the bundled AMI
|
29
|
+
|
30
|
+
#{BUNDLE_IMAGE_NAME} will bundle AMIs of up to 10GB.
|
31
|
+
TEXT
|
32
|
+
|
33
|
+
class ImageBundler < BundleTool
|
34
|
+
|
35
|
+
def bundle_image(p)
|
36
|
+
if p.size_checks
|
37
|
+
file_size = File.size(p.image_path)
|
38
|
+
if file_size <= 0
|
39
|
+
raise "the specified image #{p.image_path} is zero sized"
|
40
|
+
elsif file_size > MAX_SIZE
|
41
|
+
raise "the specified image #{p.image_path} is too large"
|
42
|
+
end
|
43
|
+
else
|
44
|
+
$stderr.puts 'Warning: disabling size-checks can result in unbootable image'
|
45
|
+
end
|
46
|
+
|
47
|
+
optional_args = {
|
48
|
+
:kernel_id => p.kernel_id,
|
49
|
+
:ramdisk_id => p.ramdisk_id,
|
50
|
+
:product_codes => p.product_codes,
|
51
|
+
:ancestor_ami_ids => p.ancestor_ami_ids,
|
52
|
+
:block_device_mapping => p.block_device_mapping,
|
53
|
+
}
|
54
|
+
$stdout.puts 'Bundling image file...'
|
55
|
+
|
56
|
+
Bundle.bundle_image(File::expand_path(p.image_path),
|
57
|
+
p.user,
|
58
|
+
p.arch,
|
59
|
+
Bundle::ImageType::MACHINE,
|
60
|
+
p.destination,
|
61
|
+
p.user_pk_path,
|
62
|
+
p.user_cert_path,
|
63
|
+
p.ec2_cert_path,
|
64
|
+
p.prefix,
|
65
|
+
optional_args,
|
66
|
+
@debug,
|
67
|
+
false)
|
68
|
+
|
69
|
+
$stdout.puts( "#{BUNDLE_IMAGE_NAME} complete." )
|
70
|
+
end
|
71
|
+
|
72
|
+
#------------------------------------------------------------------------------#
|
73
|
+
# Overrides
|
74
|
+
#------------------------------------------------------------------------------#
|
75
|
+
|
76
|
+
def get_manual()
|
77
|
+
BUNDLE_IMAGE_MANUAL
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_name()
|
81
|
+
BUNDLE_IMAGE_NAME
|
82
|
+
end
|
83
|
+
|
84
|
+
def main(p)
|
85
|
+
bundle_image(p)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
#------------------------------------------------------------------------------#
|
91
|
+
# Script entry point. Execute only if this file is being executed.
|
92
|
+
if __FILE__ == $0 || $0.match(/bin\/ec2-bundle-image/)
|
93
|
+
ImageBundler.new().run(BundleImageParameters)
|
94
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright 2008-2014 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/bundlemachineparameters'
|
12
|
+
|
13
|
+
# The Bundle Image command line parameters.
|
14
|
+
class BundleImageParameters < BundleMachineParameters
|
15
|
+
|
16
|
+
IMAGE_PATH_DESCRIPTION = "The path to the file system image to bundle."
|
17
|
+
PREFIX_DESCRIPTION = "The filename prefix for bundled AMI files. Defaults to image name."
|
18
|
+
|
19
|
+
attr_reader :image_path,
|
20
|
+
:prefix
|
21
|
+
|
22
|
+
def mandatory_params()
|
23
|
+
super()
|
24
|
+
on('-i', '--image PATH', String, IMAGE_PATH_DESCRIPTION) do |path|
|
25
|
+
assert_file_exists(path, '--image')
|
26
|
+
@image_path = path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def optional_params()
|
31
|
+
super()
|
32
|
+
on('-p', '--prefix PREFIX', String, PREFIX_DESCRIPTION) do |prefix|
|
33
|
+
assert_good_key(prefix, '--prefix')
|
34
|
+
@prefix = prefix
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_params()
|
39
|
+
raise MissingMandatory.new('--image') unless @image_path
|
40
|
+
super()
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Copyright 2008-2014 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/bundleparameters'
|
12
|
+
|
13
|
+
# The Bundle command line parameters.
|
14
|
+
class BundleMachineParameters < BundleParameters
|
15
|
+
|
16
|
+
KERNEL_DESCRIPTION = "Id of the default kernel to launch the AMI with."
|
17
|
+
RAMDISK_DESCRIPTION = "Id of the default ramdisk to launch the AMI with."
|
18
|
+
ANCESTOR_AMI_IDS_DESCRIPTION = "Lineage of this image. Comma separated list of AMI ids."
|
19
|
+
BDM_DESCRIPTION = ['Default block-device-mapping scheme to launch the AMI with. This scheme',
|
20
|
+
'defines how block devices may be exposed to an EC2 instance of this AMI',
|
21
|
+
'if the instance-type of the instance is entitled to the specified device.',
|
22
|
+
'The scheme is a comma-separated list of key=value pairs, where each key',
|
23
|
+
'is a "virtual-name" and each value, the corresponding native device name',
|
24
|
+
'desired. Possible virtual-names are:',
|
25
|
+
' - "ami": denotes the root file system device, as seen by the instance.',
|
26
|
+
' - "root": denotes the root file system device, as seen by the kernel.',
|
27
|
+
' - "swap": denotes the swap device, if present.',
|
28
|
+
' - "ephemeralN": denotes Nth ephemeral store; N is a non-negative integer.',
|
29
|
+
'Note that the contents of the AMI form the root file system. Samples of',
|
30
|
+
'block-device-mappings are:',
|
31
|
+
' - "ami=sda1,root=/dev/sda1,ephemeral0=sda2,swap=sda3"',
|
32
|
+
' - "ami=0,root=/dev/dsk/c0d0s0,ephemeral0=1"'
|
33
|
+
]
|
34
|
+
|
35
|
+
attr_accessor :kernel_id,
|
36
|
+
:ramdisk_id,
|
37
|
+
:ancestor_ami_ids,
|
38
|
+
:block_device_mapping
|
39
|
+
|
40
|
+
def optional_params()
|
41
|
+
super()
|
42
|
+
on( '--kernel ID', KERNEL_DESCRIPTION ) do |id|
|
43
|
+
@kernel_id = id
|
44
|
+
end
|
45
|
+
|
46
|
+
on( '--ramdisk ID', RAMDISK_DESCRIPTION ) do |id|
|
47
|
+
@ramdisk_id = id
|
48
|
+
end
|
49
|
+
|
50
|
+
on( '-B', '--block-device-mapping MAPS', String, *BDM_DESCRIPTION ) do |bdm|
|
51
|
+
@block_device_mapping ||= {}
|
52
|
+
raise InvalidValue.new('--block-device-mapping', bdm) if bdm.to_s.empty?
|
53
|
+
bdm.split(',').each do |mapping|
|
54
|
+
raise InvalidValue.new('--block-device-mapping', bdm) unless mapping =~ /^\s*(\S)+\s*=\s*(\S)+\s*$/
|
55
|
+
virtual, device = mapping.split(/=/)
|
56
|
+
@block_device_mapping[virtual.strip] = device.strip
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# Copyright 2008-2014 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 'timeout'
|
13
|
+
require 'ec2/platform/current'
|
14
|
+
require 'ec2/amitools/syschecks'
|
15
|
+
|
16
|
+
# The Bundle command line parameters.
|
17
|
+
class BundleParameters < ParametersBase
|
18
|
+
include EC2::Platform::Current::Constants
|
19
|
+
|
20
|
+
SUPPORTED_ARCHITECTURES = ['i386', 'x86_64']
|
21
|
+
|
22
|
+
USER_DESCRIPTION = "The user's EC2 user ID (Note: AWS account number, NOT Access Key ID)."
|
23
|
+
HELP_DESCRIPTION = "Display this help message and exit."
|
24
|
+
MANUAL_DESCRIPTION = "Display the user manual and exit."
|
25
|
+
DESTINATION_DESCRIPTION = "The directory to create the bundle in. Defaults to '#{Bundling::DESTINATION}'."
|
26
|
+
DEBUG_DESCRIPTION = "Display debug messages."
|
27
|
+
EC2_CERT_PATH_DESCRIPTION = ['The path to the EC2 X509 public key certificate bundled into the AMI.',
|
28
|
+
"Defaults to '#{Bundling::EC2_X509_CERT}'."]
|
29
|
+
ARCHITECTURE_DESCRIPTION = "Specify target architecture. One of #{SUPPORTED_ARCHITECTURES.inspect}"
|
30
|
+
BATCH_DESCRIPTION = "Run in batch mode. No interactive prompts."
|
31
|
+
PRODUCT_CODES_DESCRIPTION = ['Default product codes attached to the image at registration time.',
|
32
|
+
'Comma separated list of product codes.']
|
33
|
+
SIZE_CHECKS_DESCRIPTION = 'If set, disables size checks on bundled artifacts.'
|
34
|
+
VERSION_DESCRIPTION = "Display the version and copyright notice and then exit."
|
35
|
+
|
36
|
+
attr_accessor :user_pk_path,
|
37
|
+
:user_cert_path,
|
38
|
+
:user,
|
39
|
+
:destination,
|
40
|
+
:ec2_cert_path,
|
41
|
+
:debug,
|
42
|
+
:show_help,
|
43
|
+
:manual,
|
44
|
+
:arch,
|
45
|
+
:batch_mode,
|
46
|
+
:size_checks,
|
47
|
+
:product_codes
|
48
|
+
|
49
|
+
PROMPT_TIMEOUT = 30
|
50
|
+
|
51
|
+
#----------------------------------------------------------------------------#
|
52
|
+
|
53
|
+
def mandatory_params()
|
54
|
+
on('-c', '--cert PATH', String, USER_CERT_PATH_DESCRIPTION) do |path|
|
55
|
+
assert_file_exists(path, '--cert')
|
56
|
+
@user_cert_path = path
|
57
|
+
end
|
58
|
+
|
59
|
+
on('-k', '--privatekey PATH', String, USER_PK_PATH_DESCRIPTION) do |path|
|
60
|
+
assert_file_exists(path, '--privatekey')
|
61
|
+
@user_pk_path = path
|
62
|
+
end
|
63
|
+
|
64
|
+
on('-u', '--user USER', String, USER_ACCOUNT_DESCRIPTION) do |user|
|
65
|
+
# Remove hyphens from the Account ID as presented in AWS portal.
|
66
|
+
@user = user.gsub("-", "")
|
67
|
+
# Validate the account ID looks correct (users often provide us with their akid or secret key)
|
68
|
+
unless (@user =~ /\d{12}/)
|
69
|
+
raise InvalidValue.new('--user', @user,
|
70
|
+
"the user ID should consist of 12 digits (optionally hyphenated); this should not be your Access Key ID")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
#----------------------------------------------------------------------------#
|
76
|
+
|
77
|
+
def optional_params()
|
78
|
+
on('-d', '--destination PATH', String, DESTINATION_DESCRIPTION) do |path|
|
79
|
+
assert_directory_exists(path, '--destination')
|
80
|
+
@destination = path
|
81
|
+
end
|
82
|
+
|
83
|
+
on('--ec2cert PATH', String, *BundleParameters::EC2_CERT_PATH_DESCRIPTION) do |path|
|
84
|
+
assert_file_exists(path, '--ec2cert')
|
85
|
+
@ec2_cert_path = path
|
86
|
+
end
|
87
|
+
|
88
|
+
on('-r', '--arch ARCHITECTURE', String, ARCHITECTURE_DESCRIPTION) do |arch|
|
89
|
+
@arch = arch
|
90
|
+
end
|
91
|
+
|
92
|
+
on('--productcodes PRODUCT_CODES', String, *PRODUCT_CODES_DESCRIPTION) do |pc|
|
93
|
+
@product_codes = pc
|
94
|
+
end
|
95
|
+
|
96
|
+
on('--no-size-checks', SIZE_CHECKS_DESCRIPTION ) do |o|
|
97
|
+
@size_checks = o
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
#----------------------------------------------------------------------------#
|
102
|
+
|
103
|
+
def validate_params()
|
104
|
+
unless @clone_only
|
105
|
+
raise MissingMandatory.new('--cert') unless @user_cert_path
|
106
|
+
raise MissingMandatory.new('--privatekey') unless @user_pk_path
|
107
|
+
raise MissingMandatory.new('--user') unless @user
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
#----------------------------------------------------------------------------#
|
112
|
+
|
113
|
+
def set_defaults()
|
114
|
+
@destination ||= Bundling::DESTINATION
|
115
|
+
@ec2_cert_path ||= Bundling::EC2_X509_CERT
|
116
|
+
@exclude ||= []
|
117
|
+
@size_checks = true
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,240 @@
|
|
1
|
+
# Copyright 2008-2014 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/bundle'
|
12
|
+
require 'ec2/amitools/bundlevolparameters'
|
13
|
+
require 'ec2/platform/current'
|
14
|
+
require 'ec2/amitools/syschecks'
|
15
|
+
require 'ec2/amitools/bundle_base'
|
16
|
+
|
17
|
+
BUNDLE_VOL_NAME = 'ec2-bundle-vol'
|
18
|
+
|
19
|
+
BUNDLE_VOL_MANUAL=<<TEXT
|
20
|
+
#{BUNDLE_VOL_NAME} is a command line tool that creates an Amazon Machine Image (AMI)
|
21
|
+
from an existing Fedora Core installation and bundles it. Its output is a
|
22
|
+
bundled AMI consisting of AMI parts and a manifest. Use the '--help'
|
23
|
+
option to display help on Bundle Volume parameters.
|
24
|
+
|
25
|
+
#{BUNDLE_VOL_NAME} can be run from within an installation, provided there is sufficient space
|
26
|
+
for the AMI in the destination directory. Note that running Bundle Volume from
|
27
|
+
within a running installation may be problematic because partially written files
|
28
|
+
may get copied into the AMI. To minimize this risk it is recommended that the
|
29
|
+
system is brought down to runlevel 1. Note that this will stop networking, so
|
30
|
+
only do this if you have access to the console.
|
31
|
+
|
32
|
+
If #{BUNDLE_VOL_NAME} is not run from within the installation, the volume belonging to the
|
33
|
+
installation must be mounted so that it is accessible to #{BUNDLE_VOL_NAME}.
|
34
|
+
|
35
|
+
#{BUNDLE_VOL_NAME} will:
|
36
|
+
- create a sparse filesystem image
|
37
|
+
- recursively copy the specified volume into the image
|
38
|
+
- tar -S the image to preserve the sparseness of the image file
|
39
|
+
- compress the image
|
40
|
+
- encrypt it
|
41
|
+
- split it into parts
|
42
|
+
- generate a manifest file describing the bundled AMI
|
43
|
+
|
44
|
+
Recursive Copying
|
45
|
+
|
46
|
+
The recursive copying process copies directories from the volume into the image.
|
47
|
+
The special directories:
|
48
|
+
|
49
|
+
- '/dev'
|
50
|
+
- '/media'
|
51
|
+
- '/mnt'
|
52
|
+
- '/proc'
|
53
|
+
- '/sys'
|
54
|
+
|
55
|
+
are always excluded.
|
56
|
+
|
57
|
+
Files matching the following regular expressions:
|
58
|
+
|
59
|
+
- '*/#*#'
|
60
|
+
- '*/.#*'
|
61
|
+
- '*.sw'
|
62
|
+
- '*.swo'
|
63
|
+
- '*.swp'
|
64
|
+
- '*~'
|
65
|
+
- '*.pem'
|
66
|
+
- '*.priv'
|
67
|
+
- '*id_rsa*'
|
68
|
+
- '*id_dsa*'
|
69
|
+
- '*.gpg'
|
70
|
+
- '*.jks'
|
71
|
+
- '*/.ssh/authorized_keys'
|
72
|
+
- '*/.bash_history'
|
73
|
+
|
74
|
+
are excluded by default on Linux. Individual files that match these patterns may be
|
75
|
+
included by specifying the '--include' option.
|
76
|
+
|
77
|
+
Local directories, which are copied by default, are defined to be those on
|
78
|
+
filesystems of the following types:
|
79
|
+
|
80
|
+
- ext2
|
81
|
+
- ext3
|
82
|
+
- xfs
|
83
|
+
- jfs
|
84
|
+
- reiserfs
|
85
|
+
|
86
|
+
Directories on filesystems that are not of one of the types listed above, such as
|
87
|
+
remotely mounted NFS filesystems, are excluded by default, but can be copied
|
88
|
+
by using the '--all' option.
|
89
|
+
|
90
|
+
Symbolic links are preserved by the copying process, provided the link target is
|
91
|
+
copied.
|
92
|
+
|
93
|
+
Mounted File Systems
|
94
|
+
|
95
|
+
#{BUNDLE_VOL_NAME} will default to bundling the existing /etc/fstab file.
|
96
|
+
|
97
|
+
#{BUNDLE_VOL_NAME} will create and bundle AMIs of up to 10GB.
|
98
|
+
|
99
|
+
Note:
|
100
|
+
Creating the filesystem on the image may fail in the presence of selinux.
|
101
|
+
If you are using selinux, you should disable it before using #{BUNDLE_VOL_NAME}.
|
102
|
+
TEXT
|
103
|
+
|
104
|
+
MAX_SIZE_MB = 10 * 1024 # 10 GB in MB
|
105
|
+
|
106
|
+
class VolBundler < BundleTool
|
107
|
+
|
108
|
+
def bundle_vol(p)
|
109
|
+
name = p.prefix
|
110
|
+
image_file = File::join( p.destination, name )
|
111
|
+
volume = File::join( p.volume, "" ) # Add a trailing "/" if not present.
|
112
|
+
|
113
|
+
#
|
114
|
+
# We can't bundle unless we're root.
|
115
|
+
#
|
116
|
+
raise "You need to be root to run #{$0}" unless SysChecks::root_user?
|
117
|
+
|
118
|
+
#
|
119
|
+
# Extra parameter verification.
|
120
|
+
#
|
121
|
+
raise "the specified size #{p.size}MB is too large" unless p.size <= MAX_SIZE_MB
|
122
|
+
raise "the specified image file #{image_file} already exists" if File::exist?( image_file )
|
123
|
+
|
124
|
+
#
|
125
|
+
# Create a list of files to be included in the image. This list will override any
|
126
|
+
# files that are excluded by the security filtered files list. Files are only added if
|
127
|
+
# they are under the volume root.
|
128
|
+
#
|
129
|
+
includes = []
|
130
|
+
p.includes.each do |file|
|
131
|
+
includes << file
|
132
|
+
end
|
133
|
+
#
|
134
|
+
# Create list of directories to exclude from the image. Always exclude special
|
135
|
+
# directories, directories specified by the user and the image file itself.
|
136
|
+
#
|
137
|
+
exclude = []
|
138
|
+
unless p.all
|
139
|
+
#
|
140
|
+
# Exclude mounted non-local filesystems if they are under the volume root.
|
141
|
+
#
|
142
|
+
EC2::Platform::Current::Mtab.load.entries.values.each do |entry|
|
143
|
+
unless EC2::Platform::Current::LOCAL_FS_TYPES.include? entry.fstype
|
144
|
+
exclude << entry.mpoint if entry.mpoint.index(volume) == 0
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
EC2::Platform::Current::Image::EXCLUDES.each { |dir| exclude << dir }
|
149
|
+
|
150
|
+
#
|
151
|
+
# Exclude user specified excluded directories if they are under the volume root.
|
152
|
+
#
|
153
|
+
p.exclude.each do |dir|
|
154
|
+
exclude << dir
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# Exclude the image file if it is under the volume root.
|
159
|
+
#
|
160
|
+
if image_file.index( volume ) == 0
|
161
|
+
exclude << image_file
|
162
|
+
end
|
163
|
+
|
164
|
+
# If we are inheriting instance data but can't access it we want to fail early
|
165
|
+
if p.inherit && !EC2::InstanceData.new.instance_data_accessible
|
166
|
+
raise EC2FatalError.new(12, "Can't access instance metadata. If you are not bundling on an EC2 instance use --no-inherit.")
|
167
|
+
end
|
168
|
+
|
169
|
+
#
|
170
|
+
# Create image from volume.
|
171
|
+
#
|
172
|
+
image = EC2::Platform::Current::Image.new(volume,
|
173
|
+
image_file,
|
174
|
+
p.size,
|
175
|
+
exclude,
|
176
|
+
includes,
|
177
|
+
p.filter,
|
178
|
+
p.fstab,
|
179
|
+
p.part_type,
|
180
|
+
p.arch,
|
181
|
+
p.script,
|
182
|
+
@debug,
|
183
|
+
p.grub_config)
|
184
|
+
image.make
|
185
|
+
|
186
|
+
$stdout.puts 'Image file created: %s' % [image_file]
|
187
|
+
$stdout.puts 'Volume cloning done.'
|
188
|
+
if p.clone_only
|
189
|
+
$stdout.puts 'Not bundling image file since "--clone-only" flag was specified.'
|
190
|
+
else
|
191
|
+
#
|
192
|
+
# Bundle the created image file.
|
193
|
+
#
|
194
|
+
$stdout.puts 'Bundling image file...'
|
195
|
+
optional_args = {
|
196
|
+
:kernel_id => p.kernel_id,
|
197
|
+
:ramdisk_id => p.ramdisk_id,
|
198
|
+
:product_codes => p.product_codes,
|
199
|
+
:ancestor_ami_ids => p.ancestor_ami_ids,
|
200
|
+
:block_device_mapping => p.block_device_mapping
|
201
|
+
}
|
202
|
+
Bundle.bundle_image(image_file,
|
203
|
+
p.user,
|
204
|
+
p.arch,
|
205
|
+
Bundle::ImageType::VOLUME,
|
206
|
+
p.destination,
|
207
|
+
p.user_pk_path,
|
208
|
+
p.user_cert_path,
|
209
|
+
p.ec2_cert_path,
|
210
|
+
nil, # prefix
|
211
|
+
optional_args,
|
212
|
+
@debug,
|
213
|
+
p.inherit)
|
214
|
+
end
|
215
|
+
$stdout.puts("#{BUNDLE_VOL_NAME} complete.")
|
216
|
+
end
|
217
|
+
|
218
|
+
#------------------------------------------------------------------------------#
|
219
|
+
# Overrides
|
220
|
+
#------------------------------------------------------------------------------#
|
221
|
+
|
222
|
+
def get_manual()
|
223
|
+
BUNDLE_VOL_MANUAL
|
224
|
+
end
|
225
|
+
|
226
|
+
def get_name()
|
227
|
+
BUNDLE_VOL_NAME
|
228
|
+
end
|
229
|
+
|
230
|
+
def main(p)
|
231
|
+
bundle_vol(p)
|
232
|
+
end
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
#------------------------------------------------------------------------------#
|
237
|
+
# Script entry point. Execute only if this file is being executed.
|
238
|
+
if __FILE__ == $0 || $0.match(/bin\/ec2-bundle-vol/)
|
239
|
+
VolBundler.new().run(BundleVolParameters)
|
240
|
+
end
|