cloud-maker 0.2.0.pre2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/cloud-maker +50 -6
- data/lib/cloud-maker.rb +1 -0
- data/lib/cloud_maker/config.rb +4 -2
- data/lib/cloud_maker/ec2.rb +10 -1
- data/lib/cloud_maker/s3_archiver.rb +1 -0
- metadata +5 -5
data/bin/cloud-maker
CHANGED
@@ -4,6 +4,8 @@ require 'cloud-maker'
|
|
4
4
|
class CloudMakerCLI < Thor
|
5
5
|
include Thor::Actions
|
6
6
|
|
7
|
+
map "--version" => :version, "-v" => :version
|
8
|
+
|
7
9
|
desc "user_data [INSTANCE_CONFIG_YAML]", "Generate the Cloud Init user data for an instance described by INSTANCE_CONFIG_YAML"
|
8
10
|
method_option :set,
|
9
11
|
:alias => '-s',
|
@@ -21,9 +23,35 @@ class CloudMakerCLI < Thor
|
|
21
23
|
puts config.to_user_data
|
22
24
|
end
|
23
25
|
|
26
|
+
desc "version", "Report the current version of CloudMaker"
|
27
|
+
def version
|
28
|
+
say "cloud-maker #{Gem::Specification.find_by_name('cloud-maker').version.version}"
|
29
|
+
end
|
30
|
+
|
24
31
|
desc "terminate [AWS_INSTANCE_ID]", "Terminate the specified AWS instance"
|
32
|
+
method_option :aws_access_key_id,
|
33
|
+
:desc => "Your AWS access key id",
|
34
|
+
:default => ENV['AWS_ACCESS_KEY_ID'],
|
35
|
+
:required => true
|
36
|
+
method_option :aws_secret_access_key,
|
37
|
+
:desc => "Your AWS secret access key",
|
38
|
+
:default => ENV['AWS_SECRET_ACCESS_KEY'],
|
39
|
+
:required => true
|
25
40
|
def terminate(aws_instance_id)
|
26
|
-
|
41
|
+
info(aws_instance_id)
|
42
|
+
|
43
|
+
puts
|
44
|
+
|
45
|
+
if yes?("Are you sure you wish to terminate this instance?".red + " (y/n)")
|
46
|
+
cloud_maker = CloudMaker::Ec2.new(
|
47
|
+
:aws_access_key_id => options.aws_access_key_id,
|
48
|
+
:aws_secret_access_key => options.aws_secret_access_key
|
49
|
+
)
|
50
|
+
cloud_maker.terminate(aws_instance_id)
|
51
|
+
say "The instance was terminated."
|
52
|
+
else
|
53
|
+
say "Termination aborted."
|
54
|
+
end
|
27
55
|
end
|
28
56
|
|
29
57
|
desc "info [AWS_INSTANCE_ID]", "Display config info about the specified AWS instance"
|
@@ -96,10 +124,18 @@ class CloudMakerCLI < Thor
|
|
96
124
|
private
|
97
125
|
def print_colored_hash(hash, color=:cyan)
|
98
126
|
print_table hash.map {|key, val|
|
99
|
-
[key.to_s.dup.send(color), val.to_s]
|
127
|
+
[key.to_s.dup.send(color), colorize_inspection_string(val.to_s)]
|
100
128
|
}
|
101
129
|
end
|
102
130
|
|
131
|
+
def colorize_inspection_string(string)
|
132
|
+
string = string.dup
|
133
|
+
string.gsub!(/([\{\}\[\]])/, '\1'.magenta)
|
134
|
+
string.gsub!(/([\,])/, '\1'.yellow)
|
135
|
+
string.gsub!(/([\:\"\']?[0-9a-zA-Z_]*[\"\']?)=>/, '\1'.cyan + '=>')
|
136
|
+
string
|
137
|
+
end
|
138
|
+
|
103
139
|
def print_config_hash(hash)
|
104
140
|
puts
|
105
141
|
say "CloudInit configuration:".green
|
@@ -107,14 +143,13 @@ class CloudMakerCLI < Thor
|
|
107
143
|
puts
|
108
144
|
|
109
145
|
if (!hash['include'].empty?)
|
110
|
-
puts
|
111
146
|
say 'Include URLs:'.green
|
112
147
|
hash['include'].each do |url|
|
113
148
|
puts url
|
114
149
|
end
|
150
|
+
puts
|
115
151
|
end
|
116
152
|
|
117
|
-
puts
|
118
153
|
say "CloudMaker configuration:".green
|
119
154
|
print_colored_hash hash['cloud-maker']
|
120
155
|
puts
|
@@ -133,7 +168,7 @@ class CloudMakerCLI < Thor
|
|
133
168
|
config['tags'] ||= {}
|
134
169
|
config['tags'].merge!(options.tags)
|
135
170
|
|
136
|
-
if !config.
|
171
|
+
if !config.missing_values.empty?
|
137
172
|
say "Before an instance can be launched we need a few more values to be specified.".yellow
|
138
173
|
say "Currently missing: #{config.missing_values.map{|key| key.cyan}.join(', ')}"
|
139
174
|
puts
|
@@ -146,7 +181,16 @@ class CloudMakerCLI < Thor
|
|
146
181
|
if (config.options[key]["description"])
|
147
182
|
say config.options[key]["description"]
|
148
183
|
end
|
149
|
-
|
184
|
+
|
185
|
+
if config.options[key]["default"]
|
186
|
+
config[key] = ask "Please choose a value for #{key.cyan} [#{config.options[key]["default"]}]:"
|
187
|
+
else
|
188
|
+
config[key] = ask "Please choose a value for #{key.cyan}:"
|
189
|
+
end
|
190
|
+
|
191
|
+
if (config[key].empty? && config.options[key]["default"])
|
192
|
+
config[key] = config.options[key]["default"]
|
193
|
+
end
|
150
194
|
end
|
151
195
|
end
|
152
196
|
|
data/lib/cloud-maker.rb
CHANGED
data/lib/cloud_maker/config.rb
CHANGED
@@ -40,7 +40,9 @@ module CloudMaker
|
|
40
40
|
DEFAULT_KEY_PROPERTIES = {
|
41
41
|
"environment" => true,
|
42
42
|
"required" => false,
|
43
|
-
"value" => nil
|
43
|
+
"value" => nil,
|
44
|
+
"default" => nil,
|
45
|
+
"description" => nil
|
44
46
|
}
|
45
47
|
|
46
48
|
# Public: Initializes a new CloudMaker object.
|
@@ -96,7 +98,7 @@ module CloudMaker
|
|
96
98
|
#
|
97
99
|
# Returns an Array of required keys that are missing values.
|
98
100
|
def missing_values
|
99
|
-
self.options.select {|key, option| option["required"] && option["value"].nil?}.map(&:first).map(&:dup)
|
101
|
+
self.options.select {|key, option| (option["required"] || option["default"]) && option["value"].nil?}.map(&:first).map(&:dup)
|
100
102
|
end
|
101
103
|
|
102
104
|
# Returns a Hash of all of the CloudMaker specific properties in the configuration.
|
data/lib/cloud_maker/ec2.rb
CHANGED
@@ -32,9 +32,11 @@ module CloudMaker
|
|
32
32
|
self.aws_secret_access_key = options[:aws_secret_access_key]
|
33
33
|
|
34
34
|
self.ec2 = RightAws::Ec2.new(self.aws_access_key_id, self.aws_secret_access_key)
|
35
|
-
|
36
35
|
end
|
37
36
|
|
37
|
+
# Public: Fetch archived information about an instance
|
38
|
+
#
|
39
|
+
# Returns a hash of information about the instance as it was launched
|
38
40
|
def info(instance_id)
|
39
41
|
bucket = self.ec2.describe_tags(:filters => {'resource-id' => instance_id, 'key' => BUCKET_TAG}).first[:value]
|
40
42
|
archiver = S3Archiver.new(
|
@@ -46,6 +48,13 @@ module CloudMaker
|
|
46
48
|
archiver.load_archive
|
47
49
|
end
|
48
50
|
|
51
|
+
# Public: Terminates the specified EC2 instance.
|
52
|
+
#
|
53
|
+
# Returns a RightAws supplied Hash describing the terminated instance.
|
54
|
+
def terminate(instance_id)
|
55
|
+
self.ec2.terminate_instances([instance_id])
|
56
|
+
end
|
57
|
+
|
49
58
|
# Public: Launches a new EC2 instance, associates any specified elastic IPS
|
50
59
|
# with it, adds any specified tags, and archives the launch details to S3.
|
51
60
|
#
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud-maker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nathan Baxter
|
@@ -93,7 +93,7 @@ dependencies:
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
description:
|
96
|
-
email: nathan.baxter@airbnb.
|
96
|
+
email: nathan.baxter@airbnb.com
|
97
97
|
executables:
|
98
98
|
- cloud-maker
|
99
99
|
extensions: []
|
@@ -120,9 +120,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
121
|
none: false
|
122
122
|
requirements:
|
123
|
-
- - ! '
|
123
|
+
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
128
|
rubygems_version: 1.8.24
|