roark 0.0.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.
Files changed (47) hide show
  1. data/.gitignore +19 -0
  2. data/.travis.yml +5 -0
  3. data/CHANGELOG.md +3 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +75 -0
  7. data/Rakefile +8 -0
  8. data/bin/roark +6 -0
  9. data/examples/example.json +52 -0
  10. data/lib/roark/ami.rb +148 -0
  11. data/lib/roark/ami_create_workflow.rb +50 -0
  12. data/lib/roark/aws/cloud_formation/create_stack.rb +35 -0
  13. data/lib/roark/aws/cloud_formation/destroy_stack.rb +17 -0
  14. data/lib/roark/aws/cloud_formation/stack_outputs.rb +17 -0
  15. data/lib/roark/aws/cloud_formation/stack_status.rb +21 -0
  16. data/lib/roark/aws/cloud_formation.rb +4 -0
  17. data/lib/roark/aws/connection.rb +27 -0
  18. data/lib/roark/aws/ec2/ami_state.rb +19 -0
  19. data/lib/roark/aws/ec2/create_ami.rb +20 -0
  20. data/lib/roark/aws/ec2/destroy_ami.rb +34 -0
  21. data/lib/roark/aws/ec2/instance_status.rb +15 -0
  22. data/lib/roark/aws/ec2/stop_instance.rb +15 -0
  23. data/lib/roark/aws/ec2.rb +5 -0
  24. data/lib/roark/aws.rb +5 -0
  25. data/lib/roark/cli/create.rb +76 -0
  26. data/lib/roark/cli/destroy.rb +53 -0
  27. data/lib/roark/cli/shared.rb +28 -0
  28. data/lib/roark/cli.rb +66 -0
  29. data/lib/roark/instance.rb +56 -0
  30. data/lib/roark/response.rb +15 -0
  31. data/lib/roark/stack.rb +63 -0
  32. data/lib/roark/version.rb +3 -0
  33. data/lib/roark.rb +17 -0
  34. data/roark.gemspec +26 -0
  35. data/spec/ami_create_workflow_spec.rb +34 -0
  36. data/spec/ami_spec.rb +217 -0
  37. data/spec/aws/cloud_formation/create_stack_spec.rb +20 -0
  38. data/spec/aws/connection_spec.rb +26 -0
  39. data/spec/aws/ec2/ami_state_spec.rb +11 -0
  40. data/spec/aws/ec2/create_ami_spec.rb +17 -0
  41. data/spec/aws/ec2/destroy_ami_spec.rb +32 -0
  42. data/spec/create_stack_spec.rb +20 -0
  43. data/spec/instance_spec.rb +80 -0
  44. data/spec/response_spec.rb +21 -0
  45. data/spec/spec_helper.rb +4 -0
  46. data/spec/stack_spec.rb +99 -0
  47. metadata +155 -0
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roark::Aws::Connection do
4
+ before do
5
+ @args = { :access_key_id => 'abc',
6
+ :secret_access_key => '123',
7
+ :region => 'us-west-1' }
8
+ @connection = Roark::Aws::Connection.new @args
9
+ end
10
+
11
+ describe "#cf" do
12
+ it "should create and AWS::CloudFormation connection" do
13
+ cf_mock = mock 'cf'
14
+ AWS::CloudFormation.should_receive(:new).with(@args).and_return cf_mock
15
+ expect(@connection.cf).to eq(cf_mock)
16
+ end
17
+ end
18
+
19
+ describe "#ec2" do
20
+ it "should create and AWS::EC2 connection" do
21
+ ec2_mock = mock 'ec2'
22
+ AWS::EC2.should_receive(:new).with(@args).and_return ec2_mock
23
+ expect(@connection.ec2).to eq(ec2_mock)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roark::Aws::Ec2::AmiState do
4
+ it "should return the state of the given ami" do
5
+ image_stub = stub 'image', :state => :available
6
+ images_stub = stub :images => { 'ami-12345678' => image_stub }
7
+ connection_stub = stub 'connection', :ec2 => images_stub
8
+ ami_state = Roark::Aws::Ec2::AmiState.new connection_stub
9
+ expect(ami_state.state('ami-12345678')).to eq(:available)
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roark::Aws::Ec2::CreateAmi do
4
+ it "should return the state of the given ami" do
5
+ image_stub = stub 'image', :state => :available
6
+ images_mock = mock 'images'
7
+ ec2_stub = stub :images => images_mock
8
+ connection_stub = stub 'connection', :ec2 => ec2_stub
9
+ images_mock.should_receive(:create).
10
+ with(:instance_id => 'i-12345678',
11
+ :name => 'test123').
12
+ and_return 'an_image'
13
+ create_ami = Roark::Aws::Ec2::CreateAmi.new connection_stub
14
+ expect(create_ami.create(:instance_id => 'i-12345678',
15
+ :name => 'test123')).to eq('an_image')
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roark::Aws::Ec2::DestroyAmi do
4
+
5
+ before do
6
+ Roark.logger stub('logger')
7
+ Roark.logger.stub :info => true, :warn => true
8
+ @image_mock = mock 'image'
9
+ @snapshot_mock = mock 'snapshot'
10
+ images_mock = mock 'images'
11
+ ec2_stub = stub :images => { 'ami-12345678' => @image_mock },
12
+ :snapshots => { 'snap-4417c64c' => @snapshot_mock }
13
+ @mappings = { "/dev/sda1" =>
14
+ { :snapshot_id => "snap-4417c64c",
15
+ :volume_size => 30,
16
+ :delete_on_termination => true,
17
+ :volume_type => "standard"
18
+ }
19
+ }
20
+ connection_stub = stub 'connection', :ec2 => ec2_stub
21
+ @destroy_ami = Roark::Aws::Ec2::DestroyAmi.new connection_stub
22
+ end
23
+
24
+ it "should deregister the given ami and destroy it's snapshots " do
25
+ @image_mock.stub :exists? => true
26
+ @image_mock.stub :block_device_mappings => @mappings
27
+ @image_mock.should_receive :delete
28
+ @snapshot_mock.should_receive :delete
29
+ @destroy_ami.destroy 'ami-12345678'
30
+ end
31
+
32
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roark::Aws::CloudFormation::CreateStack do
4
+ it "should create a stack" do
5
+ stack_mock = mock 'stack mock'
6
+ cf_stub = stub 'cf stub', :stacks => stack_mock
7
+ connection_stub = stub 'connection stub', :cf => cf_stub
8
+
9
+ parameters = [ { :parameter_key => "key", :parameter_value => 'a_val' } ]
10
+ capabilities = ["CAPABILITY_IAM"]
11
+ stack_mock.should_receive(:create).
12
+ with("test123", "some json",
13
+ :capabilities => capabilities,
14
+ :parameters => parameters)
15
+ create_stack = Roark::Aws::CloudFormation::CreateStack.new connection_stub
16
+ create_stack.create :name => 'test123',
17
+ :template => 'some json',
18
+ :parameters => { 'key' => 'a_val' }
19
+ end
20
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roark::Instance do
4
+ before do
5
+ @aws_stub = stub 'aws'
6
+ logger_stub = stub 'logger stub', :info => true
7
+ Roark.logger logger_stub
8
+ @instance = Roark::Instance.new :aws => @aws_stub,
9
+ :name => 'test-ami'
10
+ end
11
+
12
+ %w(destroy exists? in_progress? instance_id success?).each do |method|
13
+ describe "##{method}" do
14
+ it "should call stack #{method}" do
15
+ stack_mock = mock 'stack mock'
16
+ stack_mock.should_receive method.to_sym
17
+ Stack.should_receive(:new).
18
+ with(:aws => @aws_stub, :name => 'test-ami').
19
+ and_return stack_mock
20
+ @instance.send method.to_sym
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "instance management" do
26
+ before do
27
+ @stack_mock = mock 'stack mock'
28
+ @stack_mock.stub :instance_id => 'i-12345678'
29
+ Stack.should_receive(:new).
30
+ with(:aws => @aws_stub, :name => 'test-ami').
31
+ and_return @stack_mock
32
+ end
33
+
34
+ describe "#create" do
35
+ it "should create an instance" do
36
+ @stack_mock.should_receive(:create).
37
+ with(:name => 'test-ami',
38
+ :parameters => 'params',
39
+ :template => 'template')
40
+ @instance.create :parameters => 'params',
41
+ :template => 'template'
42
+ end
43
+ end
44
+
45
+ describe "#create_ami_from_instance" do
46
+ it "should create an ami from instance" do
47
+ create_ami_mock = mock 'create ami mock'
48
+ Roark::Aws::Ec2::CreateAmi.should_receive(:new).
49
+ with(@aws_stub).
50
+ and_return create_ami_mock
51
+ create_ami_mock.should_receive(:create).
52
+ with(:name => 'test-ami',
53
+ :instance_id => 'i-12345678')
54
+ @instance.create_ami_from_instance
55
+ end
56
+ end
57
+
58
+ describe "#stop" do
59
+ it "should stop the instance" do
60
+ stop_instance_mock = mock 'stop instance mock'
61
+ Roark::Aws::Ec2::StopInstance.should_receive(:new).
62
+ with(@aws_stub).
63
+ and_return stop_instance_mock
64
+ stop_instance_mock.should_receive(:stop).with 'i-12345678'
65
+ @instance.stop
66
+ end
67
+ end
68
+
69
+ describe "#status" do
70
+ it "should return the status of the instance" do
71
+ instance_status_mock = mock 'instance status mock'
72
+ Roark::Aws::Ec2::InstanceStatus.should_receive(:new).
73
+ with(@aws_stub).
74
+ and_return instance_status_mock
75
+ instance_status_mock.should_receive(:status).with 'i-12345678'
76
+ @instance.status
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Roark::Response do
4
+ it "should set code to 1 if not specified" do
5
+ expect(subject.code).to eq(1)
6
+ end
7
+
8
+ it "should set message to '' if not specified" do
9
+ expect(subject.message).to eq('')
10
+ end
11
+
12
+ it "should return true if code eq 0" do
13
+ response = subject
14
+ response.code = 0
15
+ expect(response.success?).to be_true
16
+ end
17
+
18
+ it "should return false if code is not 0" do
19
+ expect(subject.success?).to be_false
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'roark'
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stack do
4
+ before do
5
+ logger_stub = stub 'logger stub'
6
+ Roark.logger logger_stub
7
+ Roark.logger.stub :info => true
8
+ @aws_stub = stub 'aws', :region => 'us-west-1'
9
+ @stack = Stack.new :aws => @aws_stub,
10
+ :name => 'test-ami'
11
+ end
12
+
13
+ describe "#create" do
14
+ it "should call create stack" do
15
+ create_stack_mock = mock 'create stack'
16
+ Roark::Aws::CloudFormation::CreateStack.should_receive(:new).
17
+ with(@aws_stub).
18
+ and_return create_stack_mock
19
+ create_stack_mock.should_receive(:create).
20
+ with(:name => 'test-ami',
21
+ :parameters => 'params',
22
+ :template => 'template')
23
+ @stack.create :parameters => 'params',
24
+ :template => 'template'
25
+ end
26
+ end
27
+
28
+ describe "#destroy" do
29
+ it "should call destroy stack" do
30
+ destroy_stack_mock = mock 'destroy stack'
31
+ Roark::Aws::CloudFormation::DestroyStack.should_receive(:new).
32
+ with(@aws_stub).
33
+ and_return destroy_stack_mock
34
+ destroy_stack_mock.should_receive(:destroy).with('test-ami')
35
+ @stack.destroy
36
+ end
37
+ end
38
+
39
+ context "status" do
40
+ before do
41
+ @stack_status_mock = mock 'status'
42
+ Roark::Aws::CloudFormation::StackStatus.should_receive(:new).
43
+ with(@aws_stub).
44
+ and_return @stack_status_mock
45
+ end
46
+
47
+ describe "#exists?" do
48
+ it "should return true if stack exists" do
49
+ @stack_status_mock.stub :exists? => true
50
+ expect(@stack.exists?).to be_true
51
+ end
52
+ it "should return false if stack does not exists" do
53
+ @stack_status_mock.stub :exists? => false
54
+ expect(@stack.exists?).to be_false
55
+ end
56
+ end
57
+
58
+ describe "#success?" do
59
+ it "should return true if stack status is CREATE_COMPLETE" do
60
+ @stack_status_mock.stub :status => 'CREATE_COMPLETE'
61
+ expect(@stack.success?).to be_true
62
+ end
63
+ it "should return false if stack status is not CREATE_COMPLETE" do
64
+ @stack_status_mock.stub :status => 'CREATE_IN_PROGRESS'
65
+ expect(@stack.success?).to be_false
66
+ end
67
+ end
68
+
69
+ describe "#in_progress?" do
70
+ it "should return true if stack status is CREATE_IN_PROGRESS" do
71
+ @stack_status_mock.stub :status => 'CREATE_IN_PROGRESS'
72
+ expect(@stack.in_progress?).to be_true
73
+ end
74
+ it "should return false if stack status is not CREATE_IN_PROGRESS" do
75
+ @stack_status_mock.stub :status => 'CREATE_COMPLETE'
76
+ expect(@stack.in_progress?).to be_false
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ describe "#instance_id" do
83
+ before do
84
+ @stack_output_mock = mock 'stack output'
85
+ @stack_outputs_mock = mock 'stack output mock'
86
+ Roark::Aws::CloudFormation::StackOutputs.should_receive(:new).
87
+ with(@aws_stub).
88
+ and_return @stack_outputs_mock
89
+ end
90
+
91
+ it "should return the instance_id from the stack output" do
92
+ @stack_outputs_mock.stub :outputs => [ @stack_output_mock ]
93
+ @stack_output_mock.stub :key => 'InstanceId', :value => 'i-12345678'
94
+ expect(@stack.instance_id).to eq('i-12345678')
95
+ end
96
+
97
+ end
98
+
99
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roark
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brett Weaver
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70138264485580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70138264485580
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70138264485160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70138264485160
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70138264484700 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70138264484700
47
+ - !ruby/object:Gem::Dependency
48
+ name: aws-sdk
49
+ requirement: &70138264484200 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - =
53
+ - !ruby/object:Gem::Version
54
+ version: 1.11.2
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70138264484200
58
+ description: Library and CLI to build AMIs from Instances created via Cloud Formation.
59
+ email:
60
+ - brett@weav.net
61
+ executables:
62
+ - roark
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - .travis.yml
68
+ - CHANGELOG.md
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - bin/roark
74
+ - examples/example.json
75
+ - lib/roark.rb
76
+ - lib/roark/ami.rb
77
+ - lib/roark/ami_create_workflow.rb
78
+ - lib/roark/aws.rb
79
+ - lib/roark/aws/cloud_formation.rb
80
+ - lib/roark/aws/cloud_formation/create_stack.rb
81
+ - lib/roark/aws/cloud_formation/destroy_stack.rb
82
+ - lib/roark/aws/cloud_formation/stack_outputs.rb
83
+ - lib/roark/aws/cloud_formation/stack_status.rb
84
+ - lib/roark/aws/connection.rb
85
+ - lib/roark/aws/ec2.rb
86
+ - lib/roark/aws/ec2/ami_state.rb
87
+ - lib/roark/aws/ec2/create_ami.rb
88
+ - lib/roark/aws/ec2/destroy_ami.rb
89
+ - lib/roark/aws/ec2/instance_status.rb
90
+ - lib/roark/aws/ec2/stop_instance.rb
91
+ - lib/roark/cli.rb
92
+ - lib/roark/cli/create.rb
93
+ - lib/roark/cli/destroy.rb
94
+ - lib/roark/cli/shared.rb
95
+ - lib/roark/instance.rb
96
+ - lib/roark/response.rb
97
+ - lib/roark/stack.rb
98
+ - lib/roark/version.rb
99
+ - roark.gemspec
100
+ - spec/ami_create_workflow_spec.rb
101
+ - spec/ami_spec.rb
102
+ - spec/aws/cloud_formation/create_stack_spec.rb
103
+ - spec/aws/connection_spec.rb
104
+ - spec/aws/ec2/ami_state_spec.rb
105
+ - spec/aws/ec2/create_ami_spec.rb
106
+ - spec/aws/ec2/destroy_ami_spec.rb
107
+ - spec/create_stack_spec.rb
108
+ - spec/instance_spec.rb
109
+ - spec/response_spec.rb
110
+ - spec/spec_helper.rb
111
+ - spec/stack_spec.rb
112
+ homepage: ''
113
+ licenses:
114
+ - MIT
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ segments:
126
+ - 0
127
+ hash: 3230223580493760541
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
135
+ - 0
136
+ hash: 3230223580493760541
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.16
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Howard Roark, master architect and builder of AMIs.
143
+ test_files:
144
+ - spec/ami_create_workflow_spec.rb
145
+ - spec/ami_spec.rb
146
+ - spec/aws/cloud_formation/create_stack_spec.rb
147
+ - spec/aws/connection_spec.rb
148
+ - spec/aws/ec2/ami_state_spec.rb
149
+ - spec/aws/ec2/create_ami_spec.rb
150
+ - spec/aws/ec2/destroy_ami_spec.rb
151
+ - spec/create_stack_spec.rb
152
+ - spec/instance_spec.rb
153
+ - spec/response_spec.rb
154
+ - spec/spec_helper.rb
155
+ - spec/stack_spec.rb