bcome 1.1.4 → 1.2.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: cdf4b817e9c7afb1b0b5508a811e2e74a71a6b97
4
- data.tar.gz: 881ae215c6873cc81b5214f2876cd13833ce1ae1
3
+ metadata.gz: 815c945bf4581f86eb3b246bc8c3c2f50590722e
4
+ data.tar.gz: fc57c0bd29952acb549553a5a421523b8e02ce83
5
5
  SHA512:
6
- metadata.gz: c67f27ca6e33d761311f9bf8c226e774b10516b9f14d2bade52e8d04e2e9df35b48e0e8ad53c1199b4fa18381e8e7a3fe51ddf9e52d05035aab15024be5c4472
7
- data.tar.gz: c610e971283f6cc178d746a4eb1ceca8b619ac66d4a76bd1353eb2c999ab5da48c4075d7d02f7da4197ac253ab928a02c31a5e4f9cb6ce0a0032017fc73df5ec
6
+ metadata.gz: 211fdcf4946327294f6562bc386de71ace4261754a92311221984d5180608299e9088320709906658d8dc2dac4d1599502536b8d9f4c4b84290ca07c42266030
7
+ data.tar.gz: 778cede06f00dc1e154aab3c65f531d8a171c5d298f5b162ecf219df42efad388508513c69576a817abf06b63591be4ee8d708cf2193b5cb5616eb7c5bafd82e
@@ -1,3 +1,3 @@
1
1
  module Bcome
2
- VERSION = '1.1.4'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -8,7 +8,7 @@ module Bcome::Command
8
8
  command
9
9
  end
10
10
 
11
- attr_reader :stdout, :stderr
11
+ attr_reader :stdout, :stderr, :process_status
12
12
 
13
13
  def initialize(command, success_exit_codes = [0])
14
14
  @command = command
@@ -1,5 +1,8 @@
1
1
  module Bcome::Driver
2
2
  class Ec2 < Bcome::Driver::Base
3
+
4
+ PATH_TO_FOG_CREDENTIALS = "#{ENV['HOME']}/.fog".freeze
5
+
3
6
  def initialize(*params)
4
7
  super
5
8
  raise Bcome::Exception::Ec2DriverMissingProvisioningRegion, params.inspect unless provisioning_region
@@ -22,6 +25,10 @@ module Bcome::Driver
22
25
  fog_client.servers.all({})
23
26
  end
24
27
 
28
+ def raw_fog_credentials
29
+ @raw_fog_credentials ||= YAML.load_file(PATH_TO_FOG_CREDENTIALS)[credentials_key]
30
+ end
31
+
25
32
  def credentials_key
26
33
  @params[:credentials_key]
27
34
  end
@@ -41,7 +41,7 @@ module Bcome::Node::Attributes
41
41
  def recurse_hash_data_for_instance_var(instance_var_name, parent_key)
42
42
  instance_data = instance_variable_defined?(instance_var_name) ? instance_variable_get(instance_var_name) : {}
43
43
  instance_data ||= {}
44
- instance_data = parent.send(parent_key).merge(instance_data) if has_parent?
44
+ instance_data = parent.send(parent_key).deep_merge(instance_data) if has_parent?
45
45
  instance_data
46
46
  end
47
47
  end
@@ -6,6 +6,8 @@ module Bcome::Node
6
6
 
7
7
  CONFIG_PATH = 'bcome'.freeze
8
8
  DEFAULT_CONFIG_NAME = 'networks.yml'.freeze
9
+ SERVER_OVERRIDE_CONFIG_NAME = 'machines-data.yml'.freeze
10
+
9
11
  INVENTORY_KEY = 'inventory'.freeze
10
12
  COLLECTION_KEY = 'collection'.freeze
11
13
  SUBSELECT_KEY = 'inventory-subselect'.freeze
@@ -24,6 +26,10 @@ module Bcome::Node
24
26
  "#{CONFIG_PATH}/#{config_file_name}"
25
27
  end
26
28
 
29
+ def machines_data_path
30
+ "#{CONFIG_PATH}/#{SERVER_OVERRIDE_CONFIG_NAME}"
31
+ end
32
+
27
33
  def config_file_name
28
34
  @config_file_name ||= ENV['CONF'] ? ENV['CONF'] : DEFAULT_CONFIG_NAME
29
35
  end
@@ -46,7 +52,7 @@ module Bcome::Node
46
52
  raise Bcome::Exception::InvalidNetworkConfig, 'missing config type' unless config[:type]
47
53
 
48
54
  klass = klass_for_view_type[config[:type]]
49
-
55
+
50
56
  raise Bcome::Exception::InvalidNetworkConfig, "invalid config type #{config[:type]}" unless klass
51
57
 
52
58
  node = klass.new(views: config, parent: parent)
@@ -84,6 +90,14 @@ module Bcome::Node
84
90
  @estate_config ||= reformat_config(load_estate_config)
85
91
  end
86
92
 
93
+ def machines_data
94
+ @machines_data ||= load_machines_data
95
+ end
96
+
97
+ def machines_data_for_namespace(namespace)
98
+ machines_data[namespace] ? machines_data[namespace] : {}
99
+ end
100
+
87
101
  def rewrite_estate_config(data)
88
102
  File.open(config_path, 'w') do |file|
89
103
  file.write data.to_yaml
@@ -94,12 +108,20 @@ module Bcome::Node
94
108
  config = YAML.load_file(config_path).deep_symbolize_keys
95
109
  return config
96
110
  rescue ArgumentError, Psych::SyntaxError => e
97
- raise Bcome::Exception::InvalidNetworkConfig, 'Invalid yaml in config' + e.message
111
+ raise Bcome::Exception::InvalidNetworkConfig, 'Invalid yaml in network config' + e.message
98
112
  rescue Errno::ENOENT
99
113
  raise Bcome::Exception::DeprecationWarning if is_running_deprecated_configs?
100
114
  raise Bcome::Exception::MissingNetworkConfig, config_path
101
115
  end
102
116
 
117
+ def load_machines_data
118
+ return {} unless File.exist?(machines_data_path)
119
+ config = YAML.load_file(machines_data_path).deep_symbolize_keys
120
+ return config
121
+ rescue ArgumentError, Psych::SyntaxError => e
122
+ raise Bcome::Exception::InvalidNetworkConfig, 'Invalid yaml in machines data config' + e.message
123
+ end
124
+
103
125
  def is_running_deprecated_configs?
104
126
  File.exist?("bcome/config/platform.yml")
105
127
  end
@@ -25,9 +25,11 @@ module Bcome::Node::Meta
25
25
  @data
26
26
  end
27
27
 
28
- def fetch(key)
28
+ def fetch(key, default = nil)
29
29
  if @data.key?(key)
30
30
  @data[key]
31
+ elsif default
32
+ return default
31
33
  else
32
34
  raise Bcome::Exception::CantFindKeyInMetadata, key unless @data.key?(key)
33
35
  end
@@ -10,6 +10,17 @@ module Bcome::Node::Server
10
10
  @bootstrap = false
11
11
  end
12
12
 
13
+ # override a server namespace's parameters. This enables features such as specific SSH parameters for a specific server, e.g. my use case was a
14
+ # single debian box within an ubuntu network, where I needed to access the machine bootstrapping mode with the 'admin' rather 'ubuntu' username.
15
+ def set_view_attributes
16
+ super
17
+ overridden_attributes = ::Bcome::Node::Factory.instance.machines_data_for_namespace(namespace.to_sym)
18
+ overridden_attributes.each do |override_key, override_value|
19
+ instance_variable_name = "@#{override_key}"
20
+ instance_variable_set(instance_variable_name, override_value)
21
+ end
22
+ end
23
+
13
24
  def bootstrap?
14
25
  @bootstrap ? true : false
15
26
  end
@@ -98,6 +109,10 @@ module Bcome::Node::Server
98
109
  base_items
99
110
  end
100
111
 
112
+ def local_port_forward(start_port, end_port)
113
+ ssh_driver.local_port_forward(start_port, end_port)
114
+ end
115
+
101
116
  def open_ssh_connection
102
117
  ssh_driver.ssh_connection
103
118
  end
@@ -79,6 +79,27 @@ module Bcome::Ssh
79
79
  end
80
80
  end
81
81
 
82
+ def local_port_forward(start_port, end_port)
83
+ if has_proxy?
84
+
85
+ if bootstrap?
86
+ tunnel_command = "ssh -N -L #{start_port}:#{@context_node.internal_ip_address}:#{end_port} -i #{@bootstrap_settings.ssh_key_path} #{bastion_host_user}@#{@proxy_data.host}"
87
+ else
88
+ tunnel_command = "ssh -N -L #{start_port}:#{@context_node.internal_ip_address}:#{end_port} #{bastion_host_user}@#{@proxy_data.host}"
89
+ end
90
+ else
91
+ if bootstrap?
92
+ tunnel_command = "ssh -i #{@bootstrap_settings.ssh_key_path} -N -L #{start_port}:#{@context_node.public_ip_address}:#{end_port}"
93
+ else
94
+ tunnel_command = "ssh -N -L #{start_port}:#{@context_node.public_ip_address}:#{end_port}"
95
+ end
96
+ end
97
+
98
+ tunnel = ::Bcome::Ssh::Tunnel::LocalPortForward.new(tunnel_command)
99
+ tunnel.open!
100
+ return tunnel
101
+ end
102
+
82
103
  def bootstrap_ssh_command
83
104
  if has_proxy?
84
105
  "ssh -i #{@bootstrap_settings.ssh_key_path} -t #{bastion_host_user}@#{@proxy_data.host} ssh -t #{user}@#{@context_node.internal_ip_address}"
@@ -0,0 +1,20 @@
1
+ module Bcome::Ssh::Tunnel
2
+ class LocalPortForward
3
+
4
+ def initialize(tunnel_command)
5
+ @tunnel_command = tunnel_command
6
+ @process_pid = nil
7
+ end
8
+
9
+ def open!
10
+ puts "Opening tunnel: #{@tunnel_command}".informational
11
+ @process_pid = spawn(@tunnel_command)
12
+ end
13
+
14
+ def close!
15
+ puts "Closing tunnel with process pid ##{@process_pid}: #{@tunnel_command}".informational
16
+ ::Process.kill("HUP", @process_pid)
17
+ end
18
+
19
+ end
20
+ end
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: 1.1.4
4
+ version: 1.2.0
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: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2018-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -264,6 +264,7 @@ files:
264
264
  - lib/objects/ssh/driver.rb
265
265
  - lib/objects/ssh/proxy_data.rb
266
266
  - lib/objects/ssh/script_exec.rb
267
+ - lib/objects/ssh/tunnel/local_port_forward.rb
267
268
  - lib/objects/system/local.rb
268
269
  - lib/objects/workspace.rb
269
270
  - patches/irb.rb