stackster 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,11 +4,11 @@ module Stackster
4
4
  class AWS
5
5
  class CloudFormation
6
6
 
7
- def initialize(environment)
8
- c = Config.environment environment
9
- @connect = Fog::AWS::CloudFormation.new :aws_access_key_id => c['access_key'],
10
- :aws_secret_access_key => c['secret_key'],
11
- :region => c['region']
7
+ def initialize(args)
8
+ c = args[:config]
9
+ @connect = Fog::AWS::CloudFormation.new :aws_access_key_id => c.access_key,
10
+ :aws_secret_access_key => c.secret_key,
11
+ :region => c.region
12
12
  end
13
13
 
14
14
  def create(args)
@@ -42,7 +42,7 @@ module Stackster
42
42
  end
43
43
 
44
44
  def template(name)
45
- @connect.get_template(name)
45
+ @connect.get_template(name).body['TemplateBody']
46
46
  end
47
47
 
48
48
  end
@@ -4,11 +4,11 @@ module Stackster
4
4
  class AWS
5
5
  class EC2
6
6
 
7
- def initialize(environment)
8
- c = Config.environment environment
9
- @connect = Fog::Compute::AWS.new :aws_access_key_id => c['access_key'],
10
- :aws_secret_access_key => c['secret_key'],
11
- :region => c['region']
7
+ def initialize(args)
8
+ c = args[:config]
9
+ @connect = Fog::Compute::AWS.new :aws_access_key_id => c.access_key,
10
+ :aws_secret_access_key => c.secret_key,
11
+ :region => c.region
12
12
  end
13
13
 
14
14
  def describe_instances
@@ -4,11 +4,11 @@ module Stackster
4
4
  class AWS
5
5
  class SimpleDB
6
6
 
7
- def initialize(environment)
8
- c = Config.environment environment
9
- @connect = Fog::AWS::SimpleDB.new :aws_access_key_id => c['access_key'],
10
- :aws_secret_access_key => c['secret_key'],
11
- :region => c['region']
7
+ def initialize(args)
8
+ c = args[:config]
9
+ @connect = Fog::AWS::SimpleDB.new :aws_access_key_id => c.access_key,
10
+ :aws_secret_access_key => c.secret_key,
11
+ :region => c.region
12
12
  end
13
13
 
14
14
  def domains
data/lib/stackster/cli.rb CHANGED
@@ -5,11 +5,18 @@ module Stackster
5
5
  def self.start
6
6
  @opts = Trollop::options do
7
7
  banner <<-EOS
8
- build and manage stacks
8
+
9
+ I build and manage AWS Cloud Formation Stacks
10
+
11
+ stackster list
12
+ stackster create -n STACK_NAME -a ATTRIBUTES -t TEMPLATE_PATH
13
+ stackster update -n STACK_NAME -a ATTRIBUTES
14
+ stackster show -n STACK_NAME
15
+ stackster destroy -n STACK_NAME
16
+
9
17
  EOS
10
18
  opt :help, "Display Help"
11
19
  opt :attributes, "CSV list of = seperated attributes to set", :type => :string
12
- opt :environment, "Set the target environment", :type => :string
13
20
  opt :name, "Stack name to manage", :type => :string
14
21
  opt :template, "Path to the template file", :type => :string
15
22
  end
@@ -17,13 +24,9 @@ EOS
17
24
  @cmd = ARGV.shift
18
25
 
19
26
  case @cmd
20
- when 'create', 'destroy', 'delete', 'list', 'update'
21
- unless EnvironmentLister.all.include? @opts[:environment]
22
- puts "Please specify a valid environment: #{EnvironmentLister.all}"
23
- exit 1
24
- end
25
- @s = Stack.new :environment => @opts[:environment],
26
- :name => @opts[:name]
27
+ when 'create', 'destroy', 'delete', 'list', 'update', 'show'
28
+ @s = Stack.new :name => @opts[:name],
29
+ :config => nil
27
30
  end
28
31
 
29
32
  read_attributes
@@ -39,15 +42,10 @@ EOS
39
42
  when 'destroy', 'delete'
40
43
  @s.destroy
41
44
  puts "#{@opts[:name]} destroyed."
42
- when 'environments'
43
- puts EnvironmentLister.all
44
45
  when 'show'
45
- sf = StackFormater.new :environment => @opts[:environment],
46
- :name => @opts[:name]
47
- puts sf.display.to_yaml
46
+ puts @s.display.to_yaml
48
47
  when 'list'
49
- s = StackLister.new @opts[:environment]
50
- puts s.all
48
+ puts Stack.list(:config => nil)
51
49
  else
52
50
  puts "Unkown command '#{@cmd}'"
53
51
  end
@@ -1,19 +1,25 @@
1
1
  module Stackster
2
2
  class Config
3
- def self.load_config_file(config_file = "#{ENV['HOME']}/.stackster.yml")
4
- YAML::load File.open( config_file )
3
+
4
+ def initialize(args = {})
5
+ @config = args[:config]
6
+ end
7
+
8
+ def load_config_file
9
+ config_file = "#{ENV['HOME']}/.stackster.yml"
10
+ @config ? @config : (YAML::load File.open( config_file ))
5
11
  end
6
12
 
7
- def self.environment(environment)
8
- load_config_file[environment]
13
+ def access_key
14
+ load_config_file['access_key']
9
15
  end
10
16
 
11
- def self.region(environment)
12
- load_config_file[environment]['region']
17
+ def secret_key
18
+ load_config_file['secret_key']
13
19
  end
14
20
 
15
- def self.environments
16
- load_config_file.keys
21
+ def region
22
+ load_config_file['region']
17
23
  end
18
24
 
19
25
  end
@@ -1,10 +1,10 @@
1
1
  module Stackster
2
2
  class EntryLister
3
3
 
4
- def initialize(environment)
5
- @environment = environment
4
+ def initialize(args)
6
5
  @domain = 'stacks'
7
- @sdb_connect = AWS::SimpleDB.new @environment
6
+ @config = args[:config]
7
+ @sdb_connect = AWS::SimpleDB.new :config => args[:config]
8
8
  end
9
9
 
10
10
  def all
@@ -5,28 +5,26 @@ module Stackster
5
5
  attr_accessor :name, :attributes
6
6
 
7
7
  def initialize(args)
8
- @environment = args[:environment]
9
8
  @domain = 'stacks'
10
- @sdb_connect = AWS::SimpleDB.new @environment
11
- self.name = "#{args[:name]}-#{Config.region @environment}"
12
- create_domain
9
+ @config = args[:config]
10
+ self.name = "#{args[:name]}-#{@config.region}"
13
11
  get_attributes
14
12
  end
15
13
 
16
14
  def self.find(args)
17
15
  e = Entry.new :name => args[:name],
18
- :environment => args[:environment]
16
+ :config => args[:config]
19
17
  e.get_attributes
20
18
  e
21
19
  end
22
20
 
23
21
  def create_domain
24
- @sdb_connect.create_domain(@domain)
22
+ sdb_connect.create_domain @domain
25
23
  end
26
24
 
27
25
  def get_attributes
28
26
  u = {}
29
- attrs = @sdb_connect.select("select * from stacks where itemName() = '#{name}'")
27
+ attrs = sdb_connect.select("select * from stacks where itemName() = '#{name}'")
30
28
  if attrs[name]
31
29
  attrs[name].each_pair do |k, v|
32
30
  u[k] = v.first
@@ -37,7 +35,7 @@ module Stackster
37
35
 
38
36
  def save
39
37
  attributes.each_pair do |k,v|
40
- @sdb_connect.put_attributes('stacks', name, { k => v }, { :replace => k })
38
+ sdb_connect.put_attributes('stacks', name, { k => v }, { :replace => k })
41
39
  end
42
40
  end
43
41
 
@@ -46,11 +44,18 @@ module Stackster
46
44
  end
47
45
 
48
46
  def set_attribute(attribute)
47
+ create_domain
49
48
  self.attributes = attributes.merge(attribute)
50
49
  end
51
50
 
52
51
  def delete_attributes
53
- @sdb_connect.delete('stacks', name)
52
+ sdb_connect.delete('stacks', name)
53
+ end
54
+
55
+ private
56
+
57
+ def sdb_connect
58
+ @sdb_connect ||= AWS::SimpleDB.new :config => @config
54
59
  end
55
60
 
56
61
  end
@@ -1,9 +1,8 @@
1
1
  module Stackster
2
2
  class InstanceReader
3
3
 
4
- def initialize(environment)
5
- @environment = environment
6
- @ec2 = AWS::EC2.new @environment
4
+ def initialize(args)
5
+ @ec2 = AWS::EC2.new :config => args[:config]
7
6
  end
8
7
 
9
8
  # Data structure is return deffernelty for class
@@ -4,10 +4,11 @@ module Stackster
4
4
  class StackCreater
5
5
 
6
6
  def initialize(args)
7
- @cf = AWS::CloudFormation.new args[:environment]
7
+ @config = args[:config]
8
8
  @entry = args[:entry]
9
9
  @name = args[:name]
10
10
  @template = read_template_from_file args[:template]
11
+ @cf = AWS::CloudFormation.new :config => @config
11
12
  end
12
13
 
13
14
  def read_template_from_file(template_file)
@@ -2,8 +2,9 @@ module Stackster
2
2
  class StackDestroyer
3
3
 
4
4
  def initialize(args)
5
- @cf = AWS::CloudFormation.new args[:environment]
5
+ @config = args[:config]
6
6
  @name = args[:name]
7
+ @cf = AWS::CloudFormation.new :config => @config
7
8
  end
8
9
 
9
10
  def destroy
@@ -2,23 +2,23 @@ module Stackster
2
2
  class StackFormater
3
3
 
4
4
  def initialize(args)
5
- @sr = StackReader.new :name => args[:name],
6
- :environment => args[:environment]
5
+ @name = args[:name]
6
+ @config = args[:config]
7
7
  end
8
8
 
9
9
  def display
10
10
  {
11
- 'attributes' => @sr.attributes,
12
- 'status' => @sr.status,
13
- 'outputs' => @sr.outputs,
14
- 'events' => @sr.events,
15
- 'resources' => @sr.resources,
11
+ 'attributes' => stack_reader.attributes,
12
+ 'status' => stack_reader.status,
13
+ 'outputs' => stack_reader.outputs,
14
+ 'events' => stack_reader.events,
15
+ 'resources' => stack_reader.resources,
16
16
  'instances' => instances_public_ip_addresses
17
17
  }
18
18
  end
19
19
 
20
20
  def instances_public_ip_addresses
21
- @sr.instances.map { |i| i['instancesSet'].first['ipAddress'] }
21
+ stack_reader.instances.map { |i| i['instancesSet'].first['ipAddress'] }
22
22
  end
23
23
 
24
24
  def attribute_names
@@ -26,22 +26,29 @@ module Stackster
26
26
  end
27
27
 
28
28
  def attributes
29
- @sr.attributes
29
+ stack_reader.attributes
30
30
  end
31
31
 
32
32
  def resources_summary
33
- @sr.resources.map do |i|
33
+ stack_reader.resources.map do |i|
34
34
  { 'LogicalResourceId' => i['LogicalResourceId'],
35
35
  'PhysicalResourceId' => i['PhysicalResourceId'] }
36
36
  end
37
37
  end
38
38
 
39
39
  def events_summary
40
- @sr.events.map do |i|
40
+ stack_reader.events.map do |i|
41
41
  { 'ResourceStatus' => i['ResourceStatus'],
42
42
  'LogicalResourceId' => i['LogicalResourceId'] }
43
43
  end
44
44
  end
45
45
 
46
+ private
47
+
48
+ def stack_reader
49
+ @stack_reader ||= StackReader.new :name => @name,
50
+ :config => @config
51
+ end
52
+
46
53
  end
47
54
  end
@@ -1,13 +1,12 @@
1
1
  module Stackster
2
2
  class StackLister
3
3
 
4
- def initialize(environment)
5
- @environment = environment
6
- @cf = AWS::CloudFormation.new @environment
4
+ def initialize(args={})
5
+ @config = args[:config]
7
6
  end
8
7
 
9
8
  def all
10
- e = EntryLister.new @environment
9
+ e = EntryLister.new :config => @config
11
10
  e.all
12
11
  end
13
12
 
@@ -3,10 +3,10 @@ module Stackster
3
3
 
4
4
  def initialize(args)
5
5
  @name = args[:name]
6
- @environment = args[:environment]
7
- @cf = AWS::CloudFormation.new @environment
6
+ @config = args[:config]
7
+ @cf = AWS::CloudFormation.new :config => @config
8
8
  @entry = Entry.find :name => @name,
9
- :environment => @environment
9
+ :config => @config
10
10
  end
11
11
 
12
12
  def attributes
@@ -33,12 +33,8 @@ module Stackster
33
33
  @cf.template @name
34
34
  end
35
35
 
36
- def last_event
37
- events.first
38
- end
39
-
40
36
  def instances
41
- ir = InstanceReader.new @environment
37
+ ir = InstanceReader.new :config => @config
42
38
  ir.list_stack_instances @name
43
39
  end
44
40
 
@@ -8,27 +8,22 @@ module Stackster
8
8
  class Stack
9
9
 
10
10
  def initialize(args)
11
+ @config = Config.new :config => args[:config]
11
12
  @name = args[:name]
12
- @environment = args[:environment]
13
13
  @entry = Entry.new :name => @name,
14
- :environment => @environment
14
+ :config => @config
15
+ end
16
+
17
+ def self.list(args)
18
+ @config = Config.new :config => args[:config]
19
+ StackLister.new(:config => @config).all
15
20
  end
16
21
 
17
22
  def create(args)
23
+ @template = args[:template]
18
24
  @entry.set_attributes args[:attributes]
19
25
  @entry.save
20
-
21
- s = StackCreater.new :name => @name,
22
- :environment => @environment,
23
- :entry => @entry,
24
- :template => args[:template]
25
- s.create
26
- end
27
-
28
- def show
29
- s = StackReader.new :name => @name,
30
- :environment => @environment
31
- s.show
26
+ stack_creater.create
32
27
  end
33
28
 
34
29
  def update(args)
@@ -37,11 +32,73 @@ module Stackster
37
32
  end
38
33
 
39
34
  def destroy
40
- s = StackDestroyer.new :name => @name,
41
- :environment => @environment
42
- s.destroy
35
+ stack_destroyer.destroy
43
36
  @entry.delete_attributes
44
37
  end
38
+
39
+ def attributes
40
+ stack_formater.attributes
41
+ end
42
+
43
+ def display
44
+ stack_formater.display
45
+ end
46
+
47
+ def show
48
+ stack_reader.show
49
+ end
50
+
51
+ def outputs
52
+ stack_reader.outputs
53
+ end
54
+
55
+ def status
56
+ stack_reader.status
57
+ end
58
+
59
+ def events
60
+ stack_reader.events
61
+ end
62
+
63
+ def instances
64
+ stack_reader.instances
65
+ end
66
+
67
+ def instances_public_ip_addresses
68
+ stack_formater.instances_public_ip_addresses
69
+ end
70
+
71
+ def resources
72
+ stack_reader.resources
73
+ end
74
+
75
+ def template
76
+ stack_reader.template
77
+ end
78
+
79
+ private
80
+
81
+ def stack_creater
82
+ @stack_creater ||= StackCreater.new :name => @name,
83
+ :entry => @entry,
84
+ :template => @template,
85
+ :config => @config
86
+ end
87
+
88
+ def stack_destroyer
89
+ @stack_destroyer ||= StackDestroyer.new :name => @name,
90
+ :config => @config
91
+ end
92
+
93
+ def stack_reader
94
+ @stack_reader ||= StackReader.new :name => @name,
95
+ :config => @config
96
+ end
97
+
98
+ def stack_formater
99
+ @stack_formater ||= StackFormater.new :name => @name,
100
+ :config => @config
101
+ end
45
102
 
46
103
  end
47
104
  end
@@ -1,3 +1,3 @@
1
1
  module Stackster
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/stackster.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require "stackster/aws"
2
2
  require "stackster/entry"
3
- require "stackster/environment"
4
3
  require "stackster/stack"
5
4
  require "stackster/instance"
6
5
  require "stackster/config"
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Config do
4
+
5
+ it "should create a new config object" do
6
+ config = Stackster::Config.new
7
+ config.class.should == Stackster::Config
8
+ end
9
+
10
+ end
11
+
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'stackster'
5
+
6
+ RSpec.configure do |config|
7
+ #spec config
8
+ end
data/stackster.gemspec CHANGED
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
- # s.add_development_dependency "rspec"
22
+ s.add_development_dependency "rspec"
23
+
23
24
  s.add_runtime_dependency "fog"
24
25
  s.add_runtime_dependency "trollop"
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-12 00:00:00.000000000 Z
12
+ date: 2012-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70184879147220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70184879147220
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: fog
16
- requirement: &70121554327040 !ruby/object:Gem::Requirement
27
+ requirement: &70184879146560 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: '0'
22
33
  type: :runtime
23
34
  prerelease: false
24
- version_requirements: *70121554327040
35
+ version_requirements: *70184879146560
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: trollop
27
- requirement: &70121554326620 !ruby/object:Gem::Requirement
38
+ requirement: &70184879145980 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,7 +43,7 @@ dependencies:
32
43
  version: '0'
33
44
  type: :runtime
34
45
  prerelease: false
35
- version_requirements: *70121554326620
46
+ version_requirements: *70184879145980
36
47
  description: Thats what I do
37
48
  email:
38
49
  - brett@weav.net
@@ -54,8 +65,6 @@ files:
54
65
  - lib/stackster/config.rb
55
66
  - lib/stackster/entry.rb
56
67
  - lib/stackster/entry/entry_lister.rb
57
- - lib/stackster/environment.rb
58
- - lib/stackster/environment/environment_lister.rb
59
68
  - lib/stackster/instance.rb
60
69
  - lib/stackster/instance/instance_reader.rb
61
70
  - lib/stackster/stack.rb
@@ -65,6 +74,8 @@ files:
65
74
  - lib/stackster/stack/stack_lister.rb
66
75
  - lib/stackster/stack/stack_reader.rb
67
76
  - lib/stackster/version.rb
77
+ - spec/config_spec.rb
78
+ - spec/spec_helper.rb
68
79
  - stackster.gemspec
69
80
  homepage: ''
70
81
  licenses: []
@@ -80,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
91
  version: '0'
81
92
  segments:
82
93
  - 0
83
- hash: -2367294800001160910
94
+ hash: -4572547021873888246
84
95
  required_rubygems_version: !ruby/object:Gem::Requirement
85
96
  none: false
86
97
  requirements:
@@ -89,11 +100,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
100
  version: '0'
90
101
  segments:
91
102
  - 0
92
- hash: -2367294800001160910
103
+ hash: -4572547021873888246
93
104
  requirements: []
94
105
  rubyforge_project: stackster
95
106
  rubygems_version: 1.8.16
96
107
  signing_key:
97
108
  specification_version: 3
98
109
  summary: I make deployments easier
99
- test_files: []
110
+ test_files:
111
+ - spec/config_spec.rb
112
+ - spec/spec_helper.rb
@@ -1,9 +0,0 @@
1
- module Stackster
2
- class EnvironmentLister
3
-
4
- def self.all
5
- Config.environments
6
- end
7
-
8
- end
9
- end
@@ -1 +0,0 @@
1
- require 'stackster/environment/environment_lister'