cloud-maker 0.0.0 → 0.1.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cloud-maker +54 -26
- data/lib/cloud_maker/ec2.rb +0 -4
- metadata +4 -4
data/bin/cloud-maker
CHANGED
@@ -2,11 +2,28 @@
|
|
2
2
|
require 'thor'
|
3
3
|
require 'colorize'
|
4
4
|
require 'cloud-maker'
|
5
|
-
|
5
|
+
require 'pry'
|
6
6
|
|
7
7
|
class CloudMakerCLI < Thor
|
8
8
|
include Thor::Actions
|
9
9
|
|
10
|
+
desc "user_data [INSTANCE_CONFIG_YAML]", "Generate the Cloud Init user data for an instance described by INSTANCE_CONFIG_YAML"
|
11
|
+
method_option :set,
|
12
|
+
:alias => '-s',
|
13
|
+
:type => :hash,
|
14
|
+
:default => {},
|
15
|
+
:desc => "Set parameters in the CloudMaker config"
|
16
|
+
method_option :tags,
|
17
|
+
:alias => '-t',
|
18
|
+
:type => :hash,
|
19
|
+
:default => {},
|
20
|
+
:desc => "Set tags for EC2, merges with and overrides the tag property in the CloudMaker config"
|
21
|
+
def user_data(instance_config_yaml)
|
22
|
+
config = build_config(instance_config_yaml, options)
|
23
|
+
say "User Data:".green
|
24
|
+
puts config.to_user_data
|
25
|
+
end
|
26
|
+
|
10
27
|
desc "launch [INSTANCE_CONFIG_YAML]", "Launch a new EC2 instance as described by INSTANCE_CONFIG_YAML"
|
11
28
|
method_option :aws_access_key_id,
|
12
29
|
:desc => "Your AWS access key id",
|
@@ -21,30 +38,17 @@ class CloudMakerCLI < Thor
|
|
21
38
|
:type => :hash,
|
22
39
|
:default => {},
|
23
40
|
:desc => "Set parameters in the CloudMaker config"
|
41
|
+
method_option :tags,
|
42
|
+
:alias => '-t',
|
43
|
+
:type => :hash,
|
44
|
+
:default => {},
|
45
|
+
:desc => "Set tags for EC2, merges with and overrides the tag property in the CloudMaker config"
|
24
46
|
def launch(instance_config_yaml)
|
25
|
-
puts "
|
47
|
+
puts "--------------------------------------------------------------------------------".green
|
26
48
|
puts "Launching new EC2 instance"
|
27
|
-
puts "
|
49
|
+
puts "--------------------------------------------------------------------------------\n".green
|
28
50
|
|
29
|
-
config =
|
30
|
-
options.set.each_pair {|key, val| config[key] = val}
|
31
|
-
|
32
|
-
if !config.valid?
|
33
|
-
say "Before an instance can be launched we need a few more values to be specified.".yellow
|
34
|
-
say "Currently missing: #{config.missing_values.map{|key| key.cyan}.join(', ')}"
|
35
|
-
puts
|
36
|
-
|
37
|
-
config.missing_values.each do |key|
|
38
|
-
config[key] = ENV[key] if ENV[key]
|
39
|
-
end
|
40
|
-
|
41
|
-
config.missing_values.each do |key|
|
42
|
-
if (config.options[key]["description"])
|
43
|
-
say config.options[key]["description"]
|
44
|
-
end
|
45
|
-
config[key] = ask "Please choose a value for #{key.cyan}: "
|
46
|
-
end
|
47
|
-
end
|
51
|
+
config = build_config(instance_config_yaml, options)
|
48
52
|
|
49
53
|
cloud_maker = CloudMaker::Ec2.new(config,
|
50
54
|
:aws_access_key_id => options.aws_access_key_id,
|
@@ -80,11 +84,35 @@ class CloudMakerCLI < Thor
|
|
80
84
|
end
|
81
85
|
end
|
82
86
|
|
83
|
-
|
84
|
-
def
|
85
|
-
|
86
|
-
|
87
|
+
private
|
88
|
+
def build_config(instance_config_yaml, options)
|
89
|
+
config = CloudMaker::Config.from_yaml(instance_config_yaml)
|
90
|
+
options.set.each_pair {|key, val| config[key] = val}
|
91
|
+
|
92
|
+
config['tags'] ||= {}
|
93
|
+
config['tags'].merge!(options.tags)
|
94
|
+
|
95
|
+
if !config.valid?
|
96
|
+
say "Before an instance can be launched we need a few more values to be specified.".yellow
|
97
|
+
say "Currently missing: #{config.missing_values.map{|key| key.cyan}.join(', ')}"
|
98
|
+
puts
|
99
|
+
|
100
|
+
config.missing_values.each do |key|
|
101
|
+
config[key] = ENV[key] if ENV[key]
|
102
|
+
end
|
103
|
+
|
104
|
+
config.missing_values.each do |key|
|
105
|
+
if (config.options[key]["description"])
|
106
|
+
say config.options[key]["description"]
|
107
|
+
end
|
108
|
+
config[key] = ask "Please choose a value for #{key.cyan}: "
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
config
|
87
113
|
end
|
88
114
|
end
|
89
115
|
|
116
|
+
|
117
|
+
|
90
118
|
CloudMakerCLI.start
|
data/lib/cloud_maker/ec2.rb
CHANGED
@@ -48,15 +48,11 @@ module CloudMaker
|
|
48
48
|
|
49
49
|
instance_id = instance[:aws_instance_id]
|
50
50
|
|
51
|
-
puts "Launched instance: #{instance_id.to_s.on_light_blue}"
|
52
|
-
|
53
51
|
ec2.create_tags(instance_id, self.config["tags"]) if self.config["tags"]
|
54
52
|
|
55
53
|
if (self.config["elastic_ip"])
|
56
54
|
#we can't associate IPs while the state is pending
|
57
55
|
while instance[:aws_state] == 'pending'
|
58
|
-
print '.'
|
59
|
-
STDOUT.flush
|
60
56
|
#this is going to hammer EC2 a bit, it might be necessary to add some delay in here
|
61
57
|
instance = ec2.describe_instances([instance_id]).first
|
62
58
|
end
|
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.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0.pre
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Nathan Baxter
|
@@ -88,9 +88,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
90
90
|
requirements:
|
91
|
-
- - ! '
|
91
|
+
- - ! '>'
|
92
92
|
- !ruby/object:Gem::Version
|
93
|
-
version:
|
93
|
+
version: 1.3.1
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
96
|
rubygems_version: 1.8.24
|