roark 0.1.0 → 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/CHANGELOG.md +5 -0
- data/README.md +5 -3
- data/lib/roark/ami.rb +17 -0
- data/lib/roark/ami_create_workflow.rb +6 -1
- data/lib/roark/aws/ec2/ami_tags.rb +22 -0
- data/lib/roark/aws/ec2.rb +1 -0
- data/lib/roark/cli/create.rb +12 -3
- data/lib/roark/version.rb +1 -1
- data/spec/ami_create_workflow_spec.rb +3 -0
- data/spec/ami_spec.rb +15 -0
- data/spec/aws/ec2/ami_tags_spec.rb +22 -0
- metadata +15 -12
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -41,11 +41,13 @@ Create AMI
|
|
41
41
|
|
42
42
|
roark create -n NAME_OF_AMI
|
43
43
|
-r AWS_REGION \
|
44
|
-
-
|
44
|
+
-c PATH_TO_CLOUD_FORMATION_TEMPLATE \
|
45
45
|
-p 'Parameter1=value1' \
|
46
46
|
-p 'Parameter2=value2' \
|
47
47
|
-a '123456789012' \
|
48
|
-
-a '123456789013'
|
48
|
+
-a '123456789013' \
|
49
|
+
-t 'ami_tag_1=val1' \
|
50
|
+
-t 'ami_tag_2=val2' \
|
49
51
|
|
50
52
|
Destroy AMI
|
51
53
|
|
@@ -68,7 +70,7 @@ Download the template:
|
|
68
70
|
|
69
71
|
Create an AMI:
|
70
72
|
|
71
|
-
roark create -n roark-example-ami -
|
73
|
+
roark create -n roark-example-ami -c example.json
|
72
74
|
|
73
75
|
## Contributing
|
74
76
|
|
data/lib/roark/ami.rb
CHANGED
@@ -110,6 +110,15 @@ module Roark
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
113
|
+
def add_tags(tags)
|
114
|
+
begin
|
115
|
+
tag tags
|
116
|
+
rescue AWS::Errors::Base => e
|
117
|
+
return Response.new :code => 1, :message => e.message
|
118
|
+
end
|
119
|
+
Response.new :code => 0, :message => 'Tagging completed successfully.'
|
120
|
+
end
|
121
|
+
|
113
122
|
def authorize_account_ids(account_ids)
|
114
123
|
begin
|
115
124
|
authorize account_ids
|
@@ -149,6 +158,10 @@ module Roark
|
|
149
158
|
ec2_ami_authorizations.add :ami_id => @ami_id, :account_ids => account_ids
|
150
159
|
end
|
151
160
|
|
161
|
+
def tag(tags)
|
162
|
+
ec2_ami_tags.add :ami_id => @ami_id, :tags => tags
|
163
|
+
end
|
164
|
+
|
152
165
|
def instance
|
153
166
|
@instance ||= Instance.new :aws => @aws, :name => instance_name
|
154
167
|
end
|
@@ -161,6 +174,10 @@ module Roark
|
|
161
174
|
@ec2_ami_authorizations ||= Roark::Aws::Ec2::AmiAuthorizations.new @aws
|
162
175
|
end
|
163
176
|
|
177
|
+
def ec2_ami_tags
|
178
|
+
@ec2_ami_tags ||= Roark::Aws::Ec2::AmiTags.new @aws
|
179
|
+
end
|
180
|
+
|
164
181
|
def ec2_destroy_ami
|
165
182
|
@ec2_destroy_ami ||= Roark::Aws::Ec2::DestroyAmi.new @aws
|
166
183
|
end
|
@@ -4,6 +4,7 @@ module Roark
|
|
4
4
|
def initialize(args)
|
5
5
|
@account_ids = args[:account_ids]
|
6
6
|
@ami = args[:ami]
|
7
|
+
@tags = args[:tags]
|
7
8
|
@parameters = args[:parameters]
|
8
9
|
@template = args[:template]
|
9
10
|
@logger = Roark.logger
|
@@ -11,7 +12,7 @@ module Roark
|
|
11
12
|
|
12
13
|
def execute
|
13
14
|
%w(create_instance wait_for_instance stop_instance wait_for_instance_to_stop
|
14
|
-
create_ami wait_for_ami destroy_instance authorize_account_ids).each do |m|
|
15
|
+
create_ami wait_for_ami destroy_instance add_tags authorize_account_ids).each do |m|
|
15
16
|
response = self.send m.to_sym
|
16
17
|
return response unless response.success?
|
17
18
|
end
|
@@ -47,6 +48,10 @@ module Roark
|
|
47
48
|
@ami.destroy_instance
|
48
49
|
end
|
49
50
|
|
51
|
+
def add_tags
|
52
|
+
@ami.add_tags @tags
|
53
|
+
end
|
54
|
+
|
50
55
|
def authorize_account_ids
|
51
56
|
@ami.authorize_account_ids @account_ids
|
52
57
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Roark
|
2
|
+
module Aws
|
3
|
+
module Ec2
|
4
|
+
class AmiTags
|
5
|
+
def initialize(connection)
|
6
|
+
@connection = connection
|
7
|
+
@logger = Roark.logger
|
8
|
+
end
|
9
|
+
|
10
|
+
def add(args)
|
11
|
+
ami_id = args[:ami_id]
|
12
|
+
tags = args[:tags]
|
13
|
+
|
14
|
+
tags.each_pair do |key,value|
|
15
|
+
@logger.info "Tagging AMI with '#{key}=#{value}'."
|
16
|
+
@connection.ec2.images[ami_id].tag key, :value => value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/roark/aws/ec2.rb
CHANGED
data/lib/roark/cli/create.rb
CHANGED
@@ -5,7 +5,10 @@ module Roark
|
|
5
5
|
include Shared
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@options = { :account_ids => [],
|
8
|
+
@options = { :account_ids => [],
|
9
|
+
:parameters => {},
|
10
|
+
:region => 'us-east-1',
|
11
|
+
:tags => {} }
|
9
12
|
@logger = Roark.logger
|
10
13
|
end
|
11
14
|
|
@@ -27,6 +30,7 @@ module Roark
|
|
27
30
|
|
28
31
|
ami_create_workflow = Roark::AmiCreateWorkflow.new :account_ids => @options[:account_ids],
|
29
32
|
:ami => ami,
|
33
|
+
:tags => @options[:tags],
|
30
34
|
:template => template,
|
31
35
|
:parameters => @options[:parameters]
|
32
36
|
response = ami_create_workflow.execute
|
@@ -47,6 +51,10 @@ module Roark
|
|
47
51
|
@options[:account_ids] << o
|
48
52
|
end
|
49
53
|
|
54
|
+
opts.on("-c", "--cloud_formation_template [CLOUD_FORMATION_TEMPLATE]", "Path to Cloud Formation template") do |o|
|
55
|
+
@options[:template] = o
|
56
|
+
end
|
57
|
+
|
50
58
|
opts.on("-n", "--name [NAME]", "Name of AMI") do |o|
|
51
59
|
@options[:name] = o
|
52
60
|
end
|
@@ -60,8 +68,9 @@ module Roark
|
|
60
68
|
@options[:region] = o
|
61
69
|
end
|
62
70
|
|
63
|
-
opts.on("-t", "--
|
64
|
-
|
71
|
+
opts.on("-t", "--tag [TAG]", "AMI tag name and it's value separated by '='. Can be specified multiple times.") do |o|
|
72
|
+
data = o.split('=')
|
73
|
+
@options[:tags].merge!({ data.first => data[1] })
|
65
74
|
end
|
66
75
|
|
67
76
|
opts.on("--aws-access-key [KEY]", "AWS Access Key") do |o|
|
data/lib/roark/version.rb
CHANGED
@@ -8,9 +8,11 @@ describe Roark::AmiCreateWorkflow do
|
|
8
8
|
Roark.logger.stub :info => true
|
9
9
|
@ami_mock = mock 'ami mock'
|
10
10
|
@account_ids = ['123456789012', '123456789013']
|
11
|
+
@tags = { 'tag1' => 'val1', 'tag2' => 'val2' }
|
11
12
|
@ami_create_workflow = Roark::AmiCreateWorkflow.new :account_ids => @account_ids,
|
12
13
|
:ami => @ami_mock,
|
13
14
|
:parameters => { 'key' => 'val' },
|
15
|
+
:tags => @tags,
|
14
16
|
:template => 'template'
|
15
17
|
end
|
16
18
|
|
@@ -25,6 +27,7 @@ describe Roark::AmiCreateWorkflow do
|
|
25
27
|
@ami_mock.should_receive(:wait_for_ami).and_return @response_stub
|
26
28
|
@ami_mock.should_receive(:destroy_instance).and_return @response_stub
|
27
29
|
@ami_mock.should_receive(:authorize_account_ids).with(@account_ids).and_return @response_stub
|
30
|
+
@ami_mock.should_receive(:add_tags).with(@tags).and_return @response_stub
|
28
31
|
expect(@ami_create_workflow.execute.success?).to be_true
|
29
32
|
end
|
30
33
|
|
data/spec/ami_spec.rb
CHANGED
@@ -227,6 +227,21 @@ describe Roark::Ami do
|
|
227
227
|
expect(@ami.authorize_account_ids(account_ids).success?).to be_true
|
228
228
|
end
|
229
229
|
end
|
230
|
+
|
231
|
+
describe "#add_tags" do
|
232
|
+
it "should call tag with the given tags" do
|
233
|
+
@ami.ami_id = 'ami-12345678'
|
234
|
+
tags = { 'test1' => 'val1', 'test2' => 'val2' }
|
235
|
+
ec2_ami_tags_mock = mock 'ami tags'
|
236
|
+
Roark::Aws::Ec2::AmiTags.should_receive(:new).
|
237
|
+
with(@aws_mock).
|
238
|
+
and_return ec2_ami_tags_mock
|
239
|
+
ec2_ami_tags_mock.should_receive(:add).
|
240
|
+
with :ami_id => "ami-12345678",
|
241
|
+
:tags => tags
|
242
|
+
expect(@ami.add_tags(tags).success?).to be_true
|
243
|
+
end
|
244
|
+
end
|
230
245
|
end
|
231
246
|
|
232
247
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Roark::Aws::Ec2::AmiTags do
|
4
|
+
|
5
|
+
describe "#add" do
|
6
|
+
it "should tag an image with the given hash of tags" do
|
7
|
+
Roark.logger stub 'logger stub'
|
8
|
+
Roark.logger.stub :info => true, :warn => true
|
9
|
+
tags = { 'name1' => 'val1', 'name2' => 'val2' }
|
10
|
+
image_mock = mock 'image'
|
11
|
+
images_stub = stub :images => { 'ami-12345678' => image_mock }
|
12
|
+
connection_stub = stub 'connection', :ec2 => images_stub
|
13
|
+
tags.each_pair do |key, value|
|
14
|
+
image_mock.should_receive(:tag).with(key, :value => value)
|
15
|
+
end
|
16
|
+
|
17
|
+
@ami_tags = Roark::Aws::Ec2::AmiTags.new connection_stub
|
18
|
+
@ami_tags.add :ami_id => 'ami-12345678', :tags => tags
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &70360117909580 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.3'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70360117909580
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70360117909160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70360117909160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70360117908700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70360117908700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: aws-sdk
|
49
|
-
requirement: &
|
49
|
+
requirement: &70360117908200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - =
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 1.11.2
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70360117908200
|
58
58
|
description: Library and CLI to build AMIs from Instances created via Cloud Formation.
|
59
59
|
email:
|
60
60
|
- brett@weav.net
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/roark/aws/ec2.rb
|
86
86
|
- lib/roark/aws/ec2/ami_authorizations.rb
|
87
87
|
- lib/roark/aws/ec2/ami_state.rb
|
88
|
+
- lib/roark/aws/ec2/ami_tags.rb
|
88
89
|
- lib/roark/aws/ec2/create_ami.rb
|
89
90
|
- lib/roark/aws/ec2/destroy_ami.rb
|
90
91
|
- lib/roark/aws/ec2/instance_status.rb
|
@@ -104,6 +105,7 @@ files:
|
|
104
105
|
- spec/aws/connection_spec.rb
|
105
106
|
- spec/aws/ec2/ami_authorizations_spec.rb
|
106
107
|
- spec/aws/ec2/ami_state_spec.rb
|
108
|
+
- spec/aws/ec2/ami_tags_spec.rb
|
107
109
|
- spec/aws/ec2/create_ami_spec.rb
|
108
110
|
- spec/aws/ec2/destroy_ami_spec.rb
|
109
111
|
- spec/create_stack_spec.rb
|
@@ -126,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
128
|
version: '0'
|
127
129
|
segments:
|
128
130
|
- 0
|
129
|
-
hash: -
|
131
|
+
hash: -847601442206879501
|
130
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
133
|
none: false
|
132
134
|
requirements:
|
@@ -135,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
137
|
version: '0'
|
136
138
|
segments:
|
137
139
|
- 0
|
138
|
-
hash: -
|
140
|
+
hash: -847601442206879501
|
139
141
|
requirements: []
|
140
142
|
rubyforge_project:
|
141
143
|
rubygems_version: 1.8.16
|
@@ -149,6 +151,7 @@ test_files:
|
|
149
151
|
- spec/aws/connection_spec.rb
|
150
152
|
- spec/aws/ec2/ami_authorizations_spec.rb
|
151
153
|
- spec/aws/ec2/ami_state_spec.rb
|
154
|
+
- spec/aws/ec2/ami_tags_spec.rb
|
152
155
|
- spec/aws/ec2/create_ami_spec.rb
|
153
156
|
- spec/aws/ec2/destroy_ami_spec.rb
|
154
157
|
- spec/create_stack_spec.rb
|