bcome 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e37ef36e32729d99fc0d22377dd1f8e3a105f654
4
- data.tar.gz: f2d3d80620f317a74aa17fe3ac0f61c56751f0ab
3
+ metadata.gz: f4b9ed597a273b6b2583fdbbe47fcf39e5f364d7
4
+ data.tar.gz: c1435dd0a9b8c642b5f685bd5d0ca691843ae4ad
5
5
  SHA512:
6
- metadata.gz: cddabfe2eb7b2cc275b0b16891cd2865016cfa5a2eb34942f1038f2606f379030257af83cf68a1675c74a39794c94c6aac3c1e0a0c5982e836e25ce733ee8281
7
- data.tar.gz: 5fe5bbb97ead4ea73ea29fe6f0b074ea0d928fe0863fc7b9af1b8ab9a045fd96575c2a6f3ffff510f590868d5e70513562d84130fce3545eae2516aec975383e
6
+ metadata.gz: 77f31f5fe23d0a3379658c8344f6ff267509d245d83130ea5a21074d6a9a4af66318bc365f37c8325472ccd216459789859a595cae4e32b73765bfe43657c990
7
+ data.tar.gz: dc8b03b7f322159c2e082df45ebbbbde4dec3f21a813d2af1953317066b974d07dea0ef1096be5753618cfef85ac6130e1eb9dce626f03f2e8faa2469600ef19
@@ -1,3 +1,3 @@
1
1
  module Bcome
2
- VERSION = "0.6.8"
2
+ VERSION = "0.6.9"
3
3
  end
@@ -14,7 +14,8 @@ module ::Bcome::FogHelper
14
14
 
15
15
  def reload!
16
16
  @unfiltered_servers = fog_client.servers.all(ec2_filters)
17
- @resources = do_load_resources
17
+ restock_inventory = true
18
+ @resources = do_load_resources(restock_inventory)
18
19
  @node = construct_node
19
20
  system("clear")
20
21
  list
@@ -96,21 +96,75 @@ module ::Bcome::Stack
96
96
  ]
97
97
  end
98
98
 
99
- def do_load_resources
100
- if dynamic_network_lookup?
101
- loaded_resources = collection_klass.collection_from_fog_data(self, servers)
102
- else
103
- path = config_path
104
- raise "Missing instances.yml configuration for your environment. You've selected a static network lookup, and yet I cannot find #{config_path}".failure unless File.exist?(config_path)
105
- config = YAML.load_file(path)
106
- loaded_resources = collection_klass.collection_from_config(self, config)
107
- end
99
+ def load_from_static_inventory
100
+ path = config_path
101
+ raise "Missing instances.yml configuration for your environment. You've selected a static network lookup, and yet I cannot find #{config_path}".failure unless File.exist?(config_path)
102
+ config = YAML.load_file(path)
103
+ return collection_klass.collection_from_config(self, config)
104
+ end
105
+
106
+ def refresh_dynamic_inventory
107
+ loaded_resources = collection_klass.collection_from_fog_data(self, servers)
108
+ loaded_resources
109
+ end
110
+
111
+
112
+ def restock
113
+ puts "\n/ Refreshing server inventory".menu_item_green
114
+ take_stock!(collection_klass.collection_from_fog_data(self, servers))
115
+ puts " Done. Inventory written to: #{config_path}\n".menu_item_green
116
+ end
117
+
118
+ def use_inventory_cache?
119
+ (dynamic_network_lookup? && self.meta_data[:inventory_cache])
120
+ end
121
+
122
+ def static_inventory_is_set?
123
+ File.exist?(config_path)
124
+ end
125
+
126
+ def load_and_take_stock
127
+ loaded_resources = refresh_dynamic_inventory
128
+ take_stock!(loaded_resources)
129
+ loaded_resources
130
+ end
131
+
132
+ def do_load_resources(restock_inventory = false)
133
+ loaded_resources = manage_inventory(restock_inventory)
108
134
  node.set_instances(loaded_resources)
109
135
  return loaded_resources
110
136
  end
111
137
 
138
+ def manage_inventory(restock_inventory = false)
139
+ return load_from_static_inventory unless dynamic_network_lookup? # No dynamic lookup, load from static
140
+ return refresh_dynamic_inventory unless use_inventory_cache? # Dynamic lookup, with no cache, just load from dynamic
141
+ return load_and_take_stock if !static_inventory_is_set? || restock_inventory # Dynamic lookup and stock, if stock not set or we're explicitly re-stocking
142
+ return load_from_static_inventory # otherwise just load from static.
143
+ end
144
+
145
+
146
+ def config_dir
147
+ "#{CONFIGS_PATH}/static_instances/"
148
+ end
149
+
112
150
  def config_path
113
- "#{CONFIGS_PATH}/static_instances/#{platform.identifier}_#{identifier}-instances.yml"
151
+ "#{config_dir}#{platform.identifier}_#{identifier}-instances.yml"
152
+ end
153
+
154
+ def take_stock!(resources)
155
+ `mkdir -p #{config_dir}`
156
+ inventory = { :instances => [] }
157
+ resources.each do |resource|
158
+ inventory[:instances] << {
159
+ :identifier => resource.identifier,
160
+ :external_network_interface_address => resource.external_network_interface_address,
161
+ :public_ip_address => resource.public_ip_address,
162
+ :role => resource.role
163
+ }
164
+ end
165
+ File.open(config_path, "w") do |file|
166
+ file.write inventory.to_yaml
167
+ end
114
168
  end
115
169
 
116
170
  def do_describe
@@ -31,11 +31,14 @@ module ::Bcome::Stack
31
31
  end
32
32
  end
33
33
 
34
- attr_reader :environment, :meta_data
35
-
34
+ attr_reader :environment, :meta_data, :external_network_interface_address, :public_ip_address, :role
35
+
36
36
  def initialize(meta_data, parent)
37
37
  @meta_data = meta_data
38
38
  @environment = parent
39
+ @external_network_interface_address = meta_data[:external_network_interface_address]
40
+ @public_ip_address = meta_data[:public_ip_address]
41
+ @role = meta_data[:role]
39
42
  end
40
43
 
41
44
  def identifier
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillaume Roderick (Webzakimbo)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk