awsome 0.0.33 → 0.0.34

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/bin/awsome CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'awsome'
4
4
  require 'optparse'
5
+ require 'terminal-table'
5
6
 
6
7
  requirements_file = 'requirements.yml'
7
8
  OptionParser.new do |opts|
@@ -20,10 +21,35 @@ OptionParser.new do |opts|
20
21
  end
21
22
  end.parse!
22
23
 
23
- requirements = Awsome::Requirements.from_yaml_file(requirements_file)
24
- filters = {'instance-state-name' => 'running'}.merge(requirements.filters)
25
- instances = Awsome::Ec2.describe_instances(filters)
26
- matchmaker = Awsome::Matchmaker.new(instances, requirements)
27
- executor = Awsome::Executor.new(matchmaker.matches)
24
+ def perform_task(task, &block)
25
+ puts Terminal::Table.new(:rows => ["[#{task}] Started"])
26
+ retval = yield task
27
+ puts Terminal::Table.new(:rows => ["[#{task}] Complete"])
28
+ retval
29
+ end
28
30
 
29
- executor.execute
31
+ requirements = perform_task "Gathering Instance Requirements" do
32
+ Awsome::Requirements.from_yaml_file(requirements_file)
33
+ end
34
+
35
+ # print out the required instances
36
+ puts Awsome::Requirements.to_table(requirements.instances)
37
+
38
+ instances = perform_task "Analyzing Running Instances" do
39
+ filters = {'instance-state-name' => 'running'}.merge(requirements.filters)
40
+ Awsome::Ec2.describe_instances(filters)
41
+ end
42
+
43
+ # print out the scouted instances
44
+ puts Awsome::Ec2::Instance.to_table(instances)
45
+
46
+ matches = perform_task "Matching Requirements to Instances" do
47
+ Awsome::Matchmaker.new(instances, requirements).matches
48
+ end
49
+
50
+ # print out the matches
51
+ puts Awsome::Matchmaker.to_table(matches)
52
+
53
+ perform_task "Executing Plan" do
54
+ Awsome::Executor.new(matches).execute
55
+ end
@@ -1,3 +1,5 @@
1
+ require 'terminal-table'
2
+
1
3
  module Awsome
2
4
  module Ec2
3
5
  class Instance
@@ -81,7 +83,53 @@ module Awsome
81
83
  Awsome::Ec2.create_tags(@properties['instance_id'], tags)
82
84
  end
83
85
 
86
+ def self.to_table(instances)
87
+ headings = %w(tags packages volumes elbs elasticips cnames ami key type zone secgroup)
88
+ Terminal::Table.new :headings => headings do |t|
89
+ instances.each do |instance|
90
+ t << [
91
+ 'Not built', #req.tags.join("\n"),
92
+ instance.packages.join("\n"),
93
+ instance.volumes.join("\n"),
94
+ instance.elbs.join("\n"),
95
+ 'Not built', #req.elastic_ips.join("\n"),
96
+ 'Not built', #req.cnames.collect{|c|c['names']}.flatten.join("\n"),
97
+ instance.ami_id,
98
+ instance.key,
99
+ instance.instance_type,
100
+ instance.availability_zone,
101
+ instance.security_group_ids
102
+ ]
103
+ t << :separator
104
+ end
105
+ end
106
+ end
107
+
84
108
  private
109
+ def id
110
+ properties['instance_id']
111
+ end
112
+
113
+ def ami_id
114
+ properties['ami_id']
115
+ end
116
+
117
+ def key
118
+ properties['key']
119
+ end
120
+
121
+ def instance_type
122
+ properties['instance_type']
123
+ end
124
+
125
+ def availability_zone
126
+ properties['availability_zone']
127
+ end
128
+
129
+ def security_group_ids
130
+ properties['security_group_ids']
131
+ end
132
+
85
133
  def reload!
86
134
  instance = Awsome::Ec2.describe_instances('instance-id' => @properties['instance_id']).first
87
135
  raise "instance #{@properties['instance_id']} not found" if instance.nil?
@@ -24,6 +24,26 @@ module Awsome
24
24
  @properties['tags'] || {}
25
25
  end
26
26
 
27
+ def ami_id
28
+ @properties['ami_id']
29
+ end
30
+
31
+ def key
32
+ @properties['key']
33
+ end
34
+
35
+ def instance_type
36
+ @properties['instance_type']
37
+ end
38
+
39
+ def availability_zone
40
+ @properties['availability_zone']
41
+ end
42
+
43
+ def security_group_ids
44
+ @properties['security_group_ids']
45
+ end
46
+
27
47
  def volumes_to_attach(instance)
28
48
  (volumes - volumes_attached_to(instance)).collect { |v| @options.find_volume(v) }
29
49
  end
@@ -48,14 +68,15 @@ module Awsome
48
68
  packages_to_install(instance).size + packages_to_remove(instance).size
49
69
  end
50
70
 
51
- private
52
- def packages
53
- (@properties['packages'] || []).to_set
54
- end
71
+ def packages
72
+ (@properties['packages'] || []).to_set
73
+ end
55
74
 
56
- def volumes
57
- @options.filter_volume_ids(@properties['volumes'] || [])
58
- end
75
+ def volumes
76
+ @options.filter_volume_ids(@properties['volumes'] || [])
77
+ end
78
+
79
+ private
59
80
 
60
81
  def packages_installed_on(instance)
61
82
  instance ? instance.packages : Set[]
@@ -1,3 +1,5 @@
1
+ require 'terminal-table'
2
+
1
3
  module Awsome
2
4
  class Matchmaker
3
5
  def initialize(instances, requirements)
@@ -31,6 +33,29 @@ module Awsome
31
33
  @signatures.reduce({}) { |memo, s| memo.merge(s => best_match(s)) }
32
34
  end
33
35
 
36
+ def self.to_table(matches)
37
+ headings = %w(instance packages volumes elbs ami key type zone secgroup)
38
+ Terminal::Table.new :headings => headings do |t|
39
+ matches.each do |match|
40
+ 1.upto(match['i_pool'].length) do |idx|
41
+ i = match['i_pool'][idx]
42
+ r = match['r_pool'][idx]
43
+ t << [
44
+ i.nil? ? '(new)' : i.id,
45
+ r.packages.join("\n"),
46
+ r.volumes.join("\n"),
47
+ r.elbs.join("\n"),
48
+ r.ami_id,
49
+ r.key,
50
+ r.instance_type,
51
+ r.availability_zone,
52
+ r.security_group_ids,
53
+ ]
54
+ end
55
+ end
56
+ end
57
+ end
58
+
34
59
  private
35
60
 
36
61
  def best_match(signature)
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'terminal-table'
2
3
 
3
4
  module Awsome
4
5
  class Requirements
@@ -14,7 +15,7 @@ module Awsome
14
15
  end
15
16
 
16
17
  def instances
17
- @requirements['instances'].collect do |req|
18
+ @instances ||= @requirements['instances'].collect do |req|
18
19
  instance = req.clone
19
20
  instance = inflate(instance, instance.delete('traits'))
20
21
  Awsome::InstanceRequirement.new(instance, @options)
@@ -29,6 +30,28 @@ module Awsome
29
30
  @requirements['traits'] || {}
30
31
  end
31
32
 
33
+ def self.to_table(requirements)
34
+ headings = %w(tags packages volumes elbs elasticips cnames ami key type zone secgroup)
35
+ Terminal::Table.new :headings => headings do |t|
36
+ requirements.each do |req|
37
+ t << [
38
+ req.tags.join("\n"),
39
+ req.packages.join("\n"),
40
+ req.volumes.join("\n"),
41
+ req.elbs.join("\n"),
42
+ req.elastic_ips.join("\n"),
43
+ req.cnames.collect{|c|c['names']}.flatten.join("\n"),
44
+ req.ami_id,
45
+ req.key,
46
+ req.instance_type,
47
+ req.availability_zone,
48
+ req.security_group_ids
49
+ ]
50
+ t << :separator
51
+ end
52
+ end
53
+ end
54
+
32
55
  private
33
56
 
34
57
  def find_trait(name)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awsome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33
4
+ version: 0.0.34
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: terminal-table
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: AWS library targeted specifically for continuous integration.
47
63
  email: sebastian@foodocs.com
48
64
  executables: