stemcell 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/bin/stem +50 -34
- data/lib/stemcell/version.rb +1 -1
- data/lib/stemcell.rb +21 -28
- metadata +1 -1
data/.gitignore
CHANGED
data/bin/stem
CHANGED
@@ -24,76 +24,82 @@ END_OF_BANNER
|
|
24
24
|
:default => ENV['AWS_SECRET_KEY']
|
25
25
|
)
|
26
26
|
|
27
|
-
opt('
|
28
|
-
'
|
27
|
+
opt('region',
|
28
|
+
'ec2 region to launch in',
|
29
29
|
:type => String,
|
30
|
-
:default => ENV['
|
30
|
+
:default => ENV['REGION'] ? ENV['REGION'] : 'us-east-1',
|
31
31
|
)
|
32
32
|
|
33
|
-
opt('
|
34
|
-
'
|
33
|
+
opt('machine_type',
|
34
|
+
'instance type to launch',
|
35
35
|
:type => String,
|
36
|
-
:default => ENV['
|
36
|
+
:default => ENV['MACHINE_TYPE'] ? ENV['MACHINE_TYPE'] : 'm1.small',
|
37
37
|
)
|
38
38
|
|
39
|
-
opt('
|
40
|
-
'
|
39
|
+
opt('image',
|
40
|
+
'ami to use for launch',
|
41
41
|
:type => String,
|
42
|
-
:default => ENV['
|
42
|
+
:default => ENV['AMI'] ? ENV['AMI'] : 'ami-d726abbe',
|
43
43
|
)
|
44
44
|
|
45
|
-
opt('
|
46
|
-
'
|
45
|
+
opt('security_group',
|
46
|
+
'security group to launch instance with',
|
47
47
|
:type => String,
|
48
|
-
:default => ENV['
|
48
|
+
:default => ENV['SECURITY_GROUP'] ? ENV['SECURITY_GROUP'] : 'default',
|
49
49
|
)
|
50
50
|
|
51
|
-
opt('
|
52
|
-
'
|
51
|
+
opt('availability-zone',
|
52
|
+
'zone in which to launch instances',
|
53
53
|
:type => String,
|
54
|
-
:default => ENV['
|
54
|
+
:default => ENV['AVAILABILITY-ZONE'],
|
55
|
+
)
|
56
|
+
|
57
|
+
opt('tags',
|
58
|
+
'tags to apply to image',
|
59
|
+
:type => String,
|
60
|
+
:default => ENV['TAGS'],
|
55
61
|
)
|
56
62
|
|
57
63
|
opt('key_name',
|
58
|
-
'ssh key
|
64
|
+
'aws ssh key name for the ubuntu user',
|
59
65
|
:type => String,
|
60
66
|
:default => ENV['KEY_NAME'],
|
61
67
|
)
|
62
68
|
|
63
|
-
opt('
|
64
|
-
'
|
69
|
+
opt('chef_data_bag_secret',
|
70
|
+
'path to secret file (or the string containing the secret)',
|
65
71
|
:type => String,
|
66
|
-
:default => ENV['
|
72
|
+
:default => ENV['CHEF_DATA_BAG_SECRET'],
|
67
73
|
)
|
68
74
|
|
69
|
-
opt('
|
70
|
-
'
|
75
|
+
opt('chef_role',
|
76
|
+
'chef role of instance to be launched',
|
71
77
|
:type => String,
|
72
|
-
:default => ENV['
|
78
|
+
:default => ENV['CHEF_ROLE'],
|
73
79
|
)
|
74
80
|
|
75
|
-
opt('
|
76
|
-
'
|
81
|
+
opt('git_origin',
|
82
|
+
'git origin to use',
|
77
83
|
:type => String,
|
78
|
-
:default => ENV['
|
84
|
+
:default => ENV['GIT_ORIGIN'],
|
79
85
|
)
|
80
86
|
|
81
|
-
opt('
|
82
|
-
'
|
87
|
+
opt('git_branch',
|
88
|
+
'git branch to run off',
|
83
89
|
:type => String,
|
84
|
-
:default => ENV['
|
90
|
+
:default => ENV['GIT_BRANCH'],
|
85
91
|
)
|
86
92
|
|
87
|
-
opt('
|
88
|
-
'
|
93
|
+
opt('git_key',
|
94
|
+
'path to the git repo deploy key (or the string containing the key)',
|
89
95
|
:type => String,
|
90
|
-
:default => ENV['
|
96
|
+
:default => ENV['GIT_KEY'],
|
91
97
|
)
|
92
98
|
|
93
|
-
opt('
|
94
|
-
'
|
99
|
+
opt('count',
|
100
|
+
'number of instances to launch',
|
95
101
|
:type => String,
|
96
|
-
:default => ENV['
|
102
|
+
:default => ENV['COUNT'],
|
97
103
|
)
|
98
104
|
|
99
105
|
end
|
@@ -114,6 +120,16 @@ by the #{arg.upcase.gsub('-','_')} environment variable" if
|
|
114
120
|
options[arg].nil? or ! options[arg]
|
115
121
|
end
|
116
122
|
|
123
|
+
# convert tags from string to ruby hash
|
124
|
+
tags = {}
|
125
|
+
if options['tags']
|
126
|
+
options['tags'].split(',').each do |tag_set|
|
127
|
+
key, value = tag_set.split('=')
|
128
|
+
tags[key] = value
|
129
|
+
end
|
130
|
+
end
|
131
|
+
options['tags'] = tags
|
132
|
+
|
117
133
|
stemcell = Stemcell::Stemcell.new(options)
|
118
134
|
stemcell.launch({'count' => options['count']})
|
119
135
|
|
data/lib/stemcell/version.rb
CHANGED
data/lib/stemcell.rb
CHANGED
@@ -11,6 +11,11 @@ module Stemcell
|
|
11
11
|
@log.debug "opts are #{opts.inspect}"
|
12
12
|
['aws_access_key',
|
13
13
|
'aws_secret_key',
|
14
|
+
'region',
|
15
|
+
'machine_type',
|
16
|
+
'image',
|
17
|
+
'security_group',
|
18
|
+
|
14
19
|
'chef_role',
|
15
20
|
'git_branch',
|
16
21
|
'git_key',
|
@@ -21,10 +26,7 @@ module Stemcell
|
|
21
26
|
instance_variable_set("@#{req}",opts[req])
|
22
27
|
end
|
23
28
|
|
24
|
-
@
|
25
|
-
@image = opts['image'] ? opts['image'] : 'ami-d726abbe'
|
26
|
-
@machine_type = opts['machine_type'] ? opts['machine_type'] : 'm1.small'
|
27
|
-
@region = opts['region'] ? opts['region'] : 'us-east-1'
|
29
|
+
@zone = opts.include?('availability_zone') ? opts['availability_zone'] : nil
|
28
30
|
@ec2_url = "ec2.#{@region}.amazonaws.com"
|
29
31
|
@timeout = 120
|
30
32
|
@start_time = Time.new
|
@@ -35,29 +37,19 @@ module Stemcell
|
|
35
37
|
'created_by' => ENV['USER'],
|
36
38
|
'stemcell' => VERSION,
|
37
39
|
}
|
38
|
-
|
39
|
-
if opts['tags']
|
40
|
-
tags = {}
|
41
|
-
opts['tags'].split(',').each do |tag_set|
|
42
|
-
key, value = tag_set.split('=')
|
43
|
-
tags[key] = value
|
44
|
-
end
|
45
|
-
@tags.merge!(tags)
|
46
|
-
end
|
40
|
+
@tags.merge!(opts['tags']) if opts['tags']
|
47
41
|
|
48
42
|
begin
|
49
43
|
@git_key_contents = File.read(@git_key)
|
50
44
|
rescue Object => e
|
51
|
-
|
52
|
-
@git_key_contents = @chef_validation_key
|
53
|
-
# raise "\ncould not open specified key #{@git_key}:\n#{e.inspect}#{e.backtrace}"
|
45
|
+
@git_key_contents = @git_key # assume content is passed in
|
54
46
|
end
|
55
47
|
|
56
|
-
if opts
|
48
|
+
if opts.include?('chef_data_bag_secret')
|
57
49
|
begin
|
58
50
|
@chef_data_bag_secret = File.read(opts['chef_data_bag_secret'])
|
59
51
|
rescue Object => e
|
60
|
-
|
52
|
+
@chef_data_bag_secret = opts['chef_data_bag_secret'] # assume secret is passed in
|
61
53
|
end
|
62
54
|
else
|
63
55
|
@chef_data_bag_secret = ''
|
@@ -91,21 +83,21 @@ module Stemcell
|
|
91
83
|
end
|
92
84
|
|
93
85
|
def wait(instances)
|
94
|
-
|
86
|
+
@log.info "Waiting for #{instances.count} instances (#{instances.inspect}):"
|
87
|
+
|
95
88
|
while true
|
89
|
+
sleep 5
|
96
90
|
if Time.now - @start_time > @timeout
|
97
91
|
bail(instances)
|
98
92
|
raise TimeoutError, "exceded timeout of #{@timeout}"
|
99
93
|
end
|
100
|
-
|
94
|
+
|
101
95
|
if instances.select{|i| i.status != :running }.empty?
|
102
|
-
|
103
|
-
return
|
96
|
+
break
|
104
97
|
end
|
105
|
-
@log.info "instances not ready yet. sleeping..."
|
106
|
-
sleep 5
|
107
|
-
return wait(instances)
|
108
98
|
end
|
99
|
+
|
100
|
+
@log.info "all instances in running state"
|
109
101
|
end
|
110
102
|
|
111
103
|
def do_launch(opts={})
|
@@ -116,8 +108,9 @@ module Stemcell
|
|
116
108
|
:instance_type => @machine_type,
|
117
109
|
:key_name => @key_name,
|
118
110
|
}
|
119
|
-
options
|
120
|
-
options
|
111
|
+
options[:availability_zone] = @zone if @zone
|
112
|
+
options[:count] = opts['count'] if opts.include?('count')
|
113
|
+
|
121
114
|
instances = @ec2_region.instances.create(options)
|
122
115
|
instances = [instances] unless instances.class == Array
|
123
116
|
instances.each do |instance|
|
@@ -145,9 +138,9 @@ module Stemcell
|
|
145
138
|
def bail(instances)
|
146
139
|
return if instances.nil?
|
147
140
|
instances.each do |instance|
|
141
|
+
log.warn "Terminating instance #{instance.instance_id}"
|
148
142
|
instance.delete
|
149
143
|
end
|
150
144
|
end
|
151
|
-
|
152
145
|
end
|
153
146
|
end
|