cloud-maker 0.2.0 → 0.2.1

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 CHANGED
@@ -96,6 +96,11 @@ class CloudMakerCLI < Thor
96
96
  :type => :hash,
97
97
  :default => {},
98
98
  :desc => "Set tags for EC2, merges with and overrides the tag property in the CloudMaker config"
99
+ method_option :yes,
100
+ :alias => '-y',
101
+ :type => :boolean,
102
+ :default => false,
103
+ :desc => "Answer yes to any confirmation prompts automatically."
99
104
  def launch(instance_config_yaml)
100
105
  puts "--------------------------------------------------------------------------------".green
101
106
  puts "Launching new EC2 instance"
@@ -105,7 +110,7 @@ class CloudMakerCLI < Thor
105
110
 
106
111
  print_config_hash(config.to_hash)
107
112
 
108
- if yes?("Launch a new EC2 instance with the options above? (y/n)")
113
+ if options.yes || yes?("Launch a new EC2 instance with the options above? (y/n)")
109
114
  cloud_maker = CloudMaker::Ec2.new(
110
115
  :aws_access_key_id => options.aws_access_key_id,
111
116
  :aws_secret_access_key => options.aws_secret_access_key
@@ -162,7 +167,7 @@ class CloudMakerCLI < Thor
162
167
  end
163
168
 
164
169
  def build_config(instance_config_yaml, options)
165
- config = CloudMaker::Config.from_yaml(instance_config_yaml)
170
+ config = CloudMaker::Config.from_yaml(instance_config_yaml, 'import_ec2' => true)
166
171
  options.set.each_pair {|key, val| config[key] = val}
167
172
 
168
173
  config['tags'] ||= {}
data/lib/cloud-maker.rb CHANGED
@@ -1,5 +1,3 @@
1
- Bundler.require(ENV['CLOUDMAKER_ENV'].to_sym) if ENV['CLOUDMAKER_ENV']
2
-
3
1
  require 'yaml'
4
2
  require 'thor'
5
3
  require 'colorize'
@@ -10,4 +8,3 @@ require 'cloud_maker/config'
10
8
  require 'cloud_maker/ec2'
11
9
  require 'cloud_maker/s3_archiver'
12
10
  require 'cloud_maker/shell_executor'
13
-
@@ -61,25 +61,29 @@ module CloudMaker
61
61
  # be used. If the detailed version is used all properties
62
62
  # are optional and DEFAULT_KEY_PROPERTIES will be used to
63
63
  # fill in the blanks.
64
- #
65
64
  # 'include' - An array of URLs or a String containing 1 URL per line
66
65
  # with optional # prefixed lines as comments.
67
66
  # ... - All valid properties of a Cloud Init config
68
67
  # are also valid here. See:
69
68
  # https://help.ubuntu.com/community/CloudInit
70
- # extra_options - Extra information about the instantiation. These will not
71
- # be used to launch the instance but will be stored in the
72
- # archive describing the instance.
69
+ #
70
+ # extra_options - Options that describe the config as opposed to being part
71
+ # of the config.
72
+ # 'config_path' - The path the config was loaded from. Used for archival purposes.
73
+ # 'import_ec2' - CloudMaker::Ec2 defines properties it relies on, if this value
74
+ # is true then we pull those property definitions in.
73
75
  #
74
76
  # Returns a CloudMaker object
75
- def initialize(cloud_config, extra_options)
77
+ def initialize(cloud_config, extra_options={})
76
78
  self.extra_options = extra_options
77
79
  cloud_config = cloud_config.dup
80
+
78
81
  self.options = extract_cloudmaker_config!(cloud_config)
79
82
  self.includes = extract_includes!(cloud_config)
80
83
  self.imports = extract_imports!(cloud_config)
81
84
  self.cloud_config = cloud_config
82
85
 
86
+ self.import(self.class.new(Ec2::CLOUD_MAKER_CONFIG)) if (extra_options['import_ec2'])
83
87
  self.imports.reverse.each do |import_path|
84
88
  self.import(self.class.from_yaml(import_path))
85
89
  end
@@ -201,11 +205,12 @@ module CloudMaker
201
205
  # from it.
202
206
  #
203
207
  # instance_config_yaml - The path of the YAML file
208
+ # options - Any options to pass through as options to CloudMaker::Config::initialize
204
209
  #
205
210
  # Returns a new Config
206
211
  # Raises: Exception if the file doesn't exist.
207
212
  # Raises: SyntaxError if the YAML file is invalid.
208
- def from_yaml(instance_config_yaml)
213
+ def from_yaml(instance_config_yaml, options={})
209
214
  begin
210
215
  full_path = File.expand_path(instance_config_yaml)
211
216
  cloud_yaml = File.open(full_path, "r") #Right_AWS will base64 encode this for us
@@ -213,7 +218,11 @@ module CloudMaker
213
218
  raise "ERROR: The path to the CloudMaker config is incorrect"
214
219
  end
215
220
 
216
- CloudMaker::Config.new(YAML::load(cloud_yaml), 'config_path' => full_path)
221
+ # loading a blank config file returns false, it's an odd degenerate case but handling
222
+ # it like this makes sanity checking other missing values easy.
223
+ config = YAML::load(cloud_yaml) || {}
224
+
225
+ CloudMaker::Config.new(config, options.merge('config_path' => full_path))
217
226
  end
218
227
  end
219
228
 
@@ -9,6 +9,36 @@ module CloudMaker
9
9
  # Internal: Gets/Sets the RightAws::Ec2 instance.
10
10
  attr_accessor :ec2
11
11
 
12
+ # Public: A CloudMaker::Config hash that describes the config properties Ec2 relies on.
13
+ CLOUD_MAKER_CONFIG = {
14
+ 'cloud-maker' => {
15
+ 'ami' => {
16
+ 'required' => true,
17
+ 'description' => "The Amazon AMI ID for the instance."
18
+ },
19
+ 'instance_type' => {
20
+ 'required' => true,
21
+ 'description' => "The Amazon instance type, eg. m1.small."
22
+ },
23
+ 'availability_zone' => {
24
+ 'required' => true,
25
+ 'description' => "The Amazon availability zone, eg. us-east-1a"
26
+ },
27
+ 'key_pair' => {
28
+ 'default' => "",
29
+ 'description' => "The name of an Amazon key pair, so you can actually login to the instance."
30
+ },
31
+ 'elastic_ip' => {
32
+ 'description' => "An elastic IP address you control that you would like to associate to the instance."
33
+ },
34
+ 'security_group' => {
35
+ 'default' => 'default',
36
+ 'required' => true,
37
+ 'description' => 'The Amazon EC2 security group to launch the instance with.'
38
+ }
39
+ }
40
+ }
41
+
12
42
  # Public: The name of the tag that will be used to find the name of an s3 bucket for archiving/information retrieval
13
43
  BUCKET_TAG = 's3_archive_bucket'
14
44
 
@@ -66,6 +96,7 @@ module CloudMaker
66
96
  :group_names => cloud_maker_config['security_group'],
67
97
  :instance_type => cloud_maker_config['instance_type'],
68
98
  :key_name => cloud_maker_config['key_pair'],
99
+ :availability_zone => cloud_maker_config['availability_zone'],
69
100
  :user_data => user_data
70
101
  ).first
71
102
 
@@ -81,8 +112,18 @@ module CloudMaker
81
112
  end
82
113
 
83
114
  ec2.associate_address(instance_id, :public_ip => cloud_maker_config["elastic_ip"])
115
+ end
84
116
 
85
- instance = ec2.describe_instances([instance_id]).first # So we get the correct IP address
117
+ begin
118
+ instance = ec2.describe_instances([instance_id]).first # So we get updated tag/ip info
119
+ rescue RightAws::AwsError => e
120
+ tries ||= 0
121
+ tries += 1
122
+ if tries <= 5
123
+ sleep 2**tries
124
+ else
125
+ raise e
126
+ end
86
127
  end
87
128
 
88
129
  archiver = S3Archiver.new(
@@ -1,6 +1,3 @@
1
- require 'pry'
2
- require 'right_aws'
3
-
4
1
  module CloudMaker
5
2
  class S3Archiver
6
3
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloud-maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-03 00:00:00.000000000 Z
13
+ date: 2012-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: colorize