bbc-cosmos-tools 0.2.3 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b42388dc7af41203718c1212144d3a9e2fb3026f
4
- data.tar.gz: fbd13b866a6c7f2de4f0853d6f86521bbc8ac93c
3
+ metadata.gz: 21ba8909836b6347a925fdc991daf90efb59c70d
4
+ data.tar.gz: 7c093ee45354fc8e7ef1f88210f0c626fe78b8e2
5
5
  SHA512:
6
- metadata.gz: be4d9b3ca1e6d859dc9b49f68bebdfb12107e1f0a61094b7ed0e500ab0b7c31e93762c14716155c241c92aca4c4d588fb74c5128933e3d16f4975f8b8609d875
7
- data.tar.gz: e50fb0ed537be62c3f3d3e7a94ef18b7614c91fe6f2fb2c0f3a493bfbb9fb01e913ccf6a33cca44c5f6ca8196b5fc1d9598eddc767ddf2e3897537f62915453b
6
+ metadata.gz: 0844acbe58f48e69bca59276e64a1150bd9d0f77dc3a4a7ba9ff1077bc8c4c650bd3d582c1f56508db31c3babe9b5993e9127330401699248bfefd27fa3b5d68
7
+ data.tar.gz: 95241b7c557623899745e1959c9f0e5ed973dc027ba5a15d1371f96b2a56a4d8953fe5ea6cafb8e0aad7a24426cff898509a5205edad399367b5369072634579
@@ -2,6 +2,7 @@ require "thor"
2
2
  require 'bbc/cosmos/tools/commands/config'
3
3
  require 'bbc/cosmos/tools/commands/release'
4
4
  require 'bbc/cosmos/tools/commands/stack'
5
+ require 'bbc/cosmos/tools/commands/component'
5
6
 
6
7
  module BBC
7
8
  module Cosmos
@@ -18,6 +19,8 @@ module BBC
18
19
  desc "stack", "Cosmos stack sub commands"
19
20
  subcommand "stack", Commands::Stack
20
21
 
22
+ desc "component", "Cosmos component sub commands"
23
+ subcommand "component", Commands::Component
21
24
  end
22
25
  end
23
26
  end
@@ -0,0 +1,67 @@
1
+ require "bbc/cosmos/tools/api"
2
+ require "aws-sdk"
3
+ require "json"
4
+
5
+ module BBC
6
+ module Cosmos
7
+ module Tools
8
+ module Commands
9
+ class Component < Base
10
+
11
+ desc "instances <COMPONENT>", "Show instances of the given component"
12
+ method_option :show_tag, :type => :string, :desc => "Show tag"
13
+ def instances(component)
14
+ say banner + "\n"
15
+
16
+ ec2 = AWS::EC2.new aws_credentials
17
+
18
+ tag = options[:show_tag]
19
+
20
+ rows = instance_ids(component).map do |id|
21
+ [id].tap { |row|
22
+ row << ec2.instances[id].tags[tag] if tag
23
+ }
24
+ end
25
+
26
+ headers = ['Instance ID']
27
+ headers << tag if tag
28
+
29
+ print_table build_table(headers, rows)
30
+ end
31
+
32
+ private
33
+ def instance_ids(component)
34
+ response = BBC::Cosmos::Tools::API.new(
35
+ config.app['api'],
36
+ options[:key_path]
37
+ )
38
+ .get "/cosmos/env/#{options[:env]}/component/#{component}/instances"
39
+
40
+ raise Exception, response.body if response.status != 200
41
+
42
+ JSON.parse(response.body).map { |instance|
43
+ instance.fetch "id"
44
+ }
45
+ end
46
+
47
+ def aws_credentials
48
+ response = BBC::Cosmos::Tools::API.new(
49
+ "https://wormhole.cloud.bbc.co.uk",
50
+ options[:key_path]
51
+ )
52
+ .get "/login/credentials"
53
+
54
+ raise Exception, response.body if response.status != 200
55
+
56
+ credentials = JSON.parse response.body
57
+
58
+ { :access_key_id => credentials["accessKeyId"],
59
+ :secret_access_key => credentials['secretAccessKey'],
60
+ :session_token => credentials['sessionToken'],
61
+ :region => "eu-west-1" }
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -1,7 +1,7 @@
1
1
  module BBC
2
2
  module Cosmos
3
3
  module Tools
4
- VERSION = "0.2.3"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbc-cosmos-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Jack
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-17 00:00:00.000000000 Z
11
+ date: 2014-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,6 +100,7 @@ files:
100
100
  - lib/bbc/cosmos/tools/app.rb
101
101
  - lib/bbc/cosmos/tools/cloudformation/generator.rb
102
102
  - lib/bbc/cosmos/tools/commands/base.rb
103
+ - lib/bbc/cosmos/tools/commands/component.rb
103
104
  - lib/bbc/cosmos/tools/commands/config.rb
104
105
  - lib/bbc/cosmos/tools/commands/release.rb
105
106
  - lib/bbc/cosmos/tools/commands/stack.rb
@@ -126,8 +127,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  version: '0'
127
128
  requirements: []
128
129
  rubyforge_project:
129
- rubygems_version: 2.0.3
130
+ rubygems_version: 2.0.14
130
131
  signing_key:
131
132
  specification_version: 4
132
133
  summary: Tool for pusing config to cosmos and controlling cloudformation templates
133
134
  test_files: []
135
+ has_rdoc: