bcome 0.6.12 → 0.7.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 +4 -4
- data/bin/bcome-bash-setup +18 -0
- data/lib/bcome/version.rb +1 -1
- data/lib/become_object.rb +1 -1
- data/lib/command.rb +0 -12
- data/lib/helpers/environment_ssh.rb +1 -1
- data/lib/helpers/instance_command.rb +4 -1
- data/lib/helpers/instance_ssh.rb +2 -3
- data/lib/helpers/selections.rb +0 -2
- data/lib/interactive/session.rb +4 -2
- data/lib/interactive/session_item/transparent_ssh.rb +31 -11
- data/lib/nodes/instance.rb +32 -1
- data/lib/nodes/view.rb +31 -0
- data/lib/progress_bar.rb +31 -0
- data/lib/ssh.rb +4 -13
- data/lib/stack/base.rb +1 -1
- data/lib/stack/environment.rb +1 -1
- data/lib/stack/instance.rb +1 -1
- data/lib/stack/view.rb +1 -1
- data/lib/workspace_context.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75e06da0e2c27915d8ca0a306ef24c0ce217c0f7
|
4
|
+
data.tar.gz: ec8e78f0956c494335ea297d32f86917b827ce43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da2ca953c5f9d2c6d3778e68311f61b0e7e74f6cc512819c231d89595349f76e5beb25900888db306d4ea3f51cb3003ae83de1737547973d0e83cb94b3feea9e
|
7
|
+
data.tar.gz: 7a7587be892d152d337f81b112926ed5c075391c27b80e92fa74571f2b2605c44f53af0c2a93532a2ae7b0f9a98dbbf8bf2c0ce46fa476526ac81f45ce435fa4
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# (C) Guillaume Roderick (webzakimbo)
|
4
|
+
# MIT licence.
|
5
|
+
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
gem_install_path = File.dirname(__FILE__)
|
9
|
+
|
10
|
+
FileUtils::mkdir_p("#{ENV["HOME"]}/.bcome")
|
11
|
+
FileUtils::mkdir_p("#{ENV["HOME"]}/.bcome/bin")
|
12
|
+
|
13
|
+
cp_bcome_bash = "cp #{gem_install_path}/../bash/experimental_shortcuts.sh ~/.bcome/bin"
|
14
|
+
system(cp_bcome_bash)
|
15
|
+
|
16
|
+
puts "\nExperimental bash shortcuts installed. Please ensure you add the bcome bash files to $PATH in your .bashrc"
|
17
|
+
puts "\ne.g. export PATH=\"$PATH:$HOME/.bcome/bin\""
|
18
|
+
exit 0
|
data/lib/bcome/version.rb
CHANGED
data/lib/become_object.rb
CHANGED
data/lib/command.rb
CHANGED
@@ -20,22 +20,10 @@ class ::Bcome::Command
|
|
20
20
|
return is_success? ? "success".success : "failure".failure
|
21
21
|
end
|
22
22
|
|
23
|
-
def ssh_user
|
24
|
-
@bootstrap ? instance.bootstrap_settings[:ssh_user] : instance.ssh_user
|
25
|
-
end
|
26
|
-
|
27
23
|
def bootstrap=(bootstrap_value)
|
28
24
|
@bootstrap = bootstrap_value
|
29
25
|
end
|
30
26
|
|
31
|
-
def ssh_keys
|
32
|
-
@bootstrap ? [instance.bootstrap_settings[:key]] : instance.keys
|
33
|
-
end
|
34
|
-
|
35
|
-
def proxy
|
36
|
-
@bootstrap ? instance.proxy(true) : instance.proxy
|
37
|
-
end
|
38
|
-
|
39
27
|
def output
|
40
28
|
command_output = is_success? ? @stdout : "Exit code: #{@exit_code}\n\nSTDERR: #{@stderr}"
|
41
29
|
return "\n#{command_output}"
|
@@ -92,7 +92,7 @@ module ::Bcome::EnvironmentSSH
|
|
92
92
|
|
93
93
|
def bastion_ip_address
|
94
94
|
unless bastion_server
|
95
|
-
raise "Unable to find
|
95
|
+
raise "Unable to find jump host for #{self.namespace}. No instance found with identifier '#{@ssh_mode[:jump_host_identifier]}'. Check your network.yml config for this stack, and ensure that you've got the correct value for key 'jump_host_identifier'"
|
96
96
|
end
|
97
97
|
|
98
98
|
if dynamic_network_lookup?
|
@@ -8,7 +8,10 @@ module ::Bcome::InstanceCommand
|
|
8
8
|
def execute_command(commands, bootstrap = false)
|
9
9
|
begin
|
10
10
|
return environment.execute_command(commands, self, bootstrap)
|
11
|
-
rescue
|
11
|
+
rescue Exception => e
|
12
|
+
puts e.message
|
13
|
+
puts e.backtrace.join(", ")
|
14
|
+
|
12
15
|
if bootstrap_settings ### Try bootstrap fallback
|
13
16
|
puts "\n failed to connect. Attempting bootstrap connection".informational
|
14
17
|
bootstrap = true
|
data/lib/helpers/instance_ssh.rb
CHANGED
@@ -35,9 +35,8 @@ module ::Bcome::InstanceSsh
|
|
35
35
|
return environment.ssh_nat_user ? environment.ssh_nat_user : ssh_user
|
36
36
|
end
|
37
37
|
|
38
|
-
def ssh_user
|
39
|
-
|
40
|
-
return environment.ssh_mode_user ? environment.ssh_mode_user : `whoami`.gsub("\n","")
|
38
|
+
def ssh_user(bootstrap = false)
|
39
|
+
bootstrap ? bootstrap_settings[:ssh_user] : (environment.ssh_mode_user ? environment.ssh_mode_user : `whoami`.gsub("\n",""))
|
41
40
|
end
|
42
41
|
|
43
42
|
def ssh_key_path
|
data/lib/helpers/selections.rb
CHANGED
data/lib/interactive/session.rb
CHANGED
@@ -10,7 +10,7 @@ module Bcome::Interactive
|
|
10
10
|
irb_session.conf.return_format = ""
|
11
11
|
system("clear")
|
12
12
|
session.prompt
|
13
|
-
rescue ::Bcome::Interactive::SessionHalt
|
13
|
+
rescue ::Bcome::Interactive::SessionHalt => e
|
14
14
|
irb_session.conf.return_format = irb_pre_session_return_format
|
15
15
|
puts session_end_message
|
16
16
|
end
|
@@ -33,7 +33,9 @@ module Bcome::Interactive
|
|
33
33
|
def process_item(item)
|
34
34
|
begin
|
35
35
|
item.do
|
36
|
-
rescue
|
36
|
+
rescue Exception => e
|
37
|
+
puts "Exception: #{e.message}"
|
38
|
+
puts e.backtrace.join("\n")
|
37
39
|
raise ::Bcome::Interactive::SessionHalt.new
|
38
40
|
end
|
39
41
|
end
|
@@ -6,9 +6,19 @@ module Bcome::Interactive::SessionItem
|
|
6
6
|
LIST_KEY = "\\l"
|
7
7
|
|
8
8
|
DANGER_CMD = "rm\s+-r|rm\s+-f|rm\s+-fr|rm\s+-rf|rm"
|
9
|
+
|
9
10
|
def do
|
11
|
+
show_menu
|
12
|
+
puts ""
|
13
|
+
open_ssh_connections!
|
14
|
+
puts ""
|
15
|
+
list_machines
|
16
|
+
action
|
17
|
+
end
|
18
|
+
|
19
|
+
def action
|
10
20
|
input = get_input
|
11
|
-
|
21
|
+
return if exit?(input)
|
12
22
|
if show_menu?(input)
|
13
23
|
show_menu
|
14
24
|
elsif list_machines?(input)
|
@@ -18,7 +28,7 @@ module Bcome::Interactive::SessionItem
|
|
18
28
|
else
|
19
29
|
execute_on_machines(input)
|
20
30
|
end
|
21
|
-
|
31
|
+
action
|
22
32
|
end
|
23
33
|
|
24
34
|
def show_menu
|
@@ -70,6 +80,24 @@ module Bcome::Interactive::SessionItem
|
|
70
80
|
def list_machines?(input)
|
71
81
|
input == LIST_KEY
|
72
82
|
end
|
83
|
+
|
84
|
+
def open_ssh_connections!
|
85
|
+
ProgressBar.instance.reset!
|
86
|
+
machines.pmap {|machine|
|
87
|
+
ProgressBar.instance.indicate_and_increment!("init ssh: ","~~~", "connections")
|
88
|
+
machine.ssh_connect!
|
89
|
+
}
|
90
|
+
ProgressBar.instance.reset!
|
91
|
+
end
|
92
|
+
|
93
|
+
def list_machines
|
94
|
+
puts "\n"
|
95
|
+
machines.each do |machine|
|
96
|
+
env = machine.environment
|
97
|
+
platform = env.platform
|
98
|
+
puts "#{platform.identifier.cyan}:#{env.identifier.orange}:#{machine.identifier.yellow}"
|
99
|
+
end
|
100
|
+
end
|
73
101
|
|
74
102
|
def get_input(message = terminal_prompt)
|
75
103
|
return ::Readline.readline("\n#{message}", true).squeeze(" " ).to_s
|
@@ -81,16 +109,8 @@ module Bcome::Interactive::SessionItem
|
|
81
109
|
}
|
82
110
|
end
|
83
111
|
|
84
|
-
def list_machines
|
85
|
-
puts "\n" + machines.collect {|m|
|
86
|
-
env = m.environment
|
87
|
-
platform = env.platform
|
88
|
-
"* #{platform.identifier.cyan}:#{env.identifier.orange}:#{m.identifier.yellow}"
|
89
|
-
}.join("\n")
|
90
|
-
end
|
91
|
-
|
92
112
|
def machines
|
93
|
-
@machines ||= has_selected_machines? ? selected_machines : flat_list_of_machines
|
113
|
+
@machines ||= has_selected_machines? ? selected_machines.collect(&:node) : flat_list_of_machines
|
94
114
|
end
|
95
115
|
|
96
116
|
def flat_list_of_machines
|
data/lib/nodes/instance.rb
CHANGED
@@ -17,6 +17,32 @@ module ::Bcome::Node
|
|
17
17
|
stack_peer.override_instance_identifier_for_wbz_stacks? ? wbz_overriden_identifier : @identifier
|
18
18
|
end
|
19
19
|
|
20
|
+
## START SSH CONNECTION STUFF --
|
21
|
+
def ssh_connect!(bootstrap = false)
|
22
|
+
|
23
|
+
net_ssh_params = { :keys => ssh_keys(bootstrap), :paranoid => false }
|
24
|
+
net_ssh_params[:proxy] = proxy(bootstrap) if proxy(bootstrap)
|
25
|
+
begin
|
26
|
+
@ssh_con = ::Net::SSH.start(ip_address, ssh_user(bootstrap), net_ssh_params)
|
27
|
+
rescue Net::SSH::ConnectionTimeout
|
28
|
+
raise "Could not initiate connection to #{self.namespace}"
|
29
|
+
end
|
30
|
+
return @ssh_con
|
31
|
+
end
|
32
|
+
|
33
|
+
def ssh_connection(bootstrap = false)
|
34
|
+
return has_open_ssh_con? ? @ssh_con : ssh_connect!(bootstrap)
|
35
|
+
end
|
36
|
+
|
37
|
+
def has_open_ssh_con?
|
38
|
+
@ssh_con && !@ssh_con.closed?
|
39
|
+
end
|
40
|
+
|
41
|
+
def ssh_keys(bootstrap = false)
|
42
|
+
bootstrap ? [bootstrap_settings[:key]] : keys
|
43
|
+
end
|
44
|
+
######## END SSH CONNECTION STUFF --
|
45
|
+
|
20
46
|
def wbz_overriden_identifier
|
21
47
|
prefix = stack_peer.overriden_identifier_prefix
|
22
48
|
@identifier =~ /#{prefix}(.+)/
|
@@ -35,8 +61,13 @@ module ::Bcome::Node
|
|
35
61
|
environment.proxy(bootstrap)
|
36
62
|
end
|
37
63
|
|
64
|
+
def display_ip_address
|
65
|
+
return "xxx.xxx.xxx.xx" if @identifier == "bastionserver"
|
66
|
+
return @public_ip_address
|
67
|
+
end
|
68
|
+
|
38
69
|
def public_ip_address
|
39
|
-
@public_ip_address
|
70
|
+
return @public_ip_address
|
40
71
|
end
|
41
72
|
|
42
73
|
def hostname_map
|
data/lib/nodes/view.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module ::Bcome::Node
|
2
|
+
class View < ::Bcome::Node::Base
|
3
|
+
|
4
|
+
include ::Bcome::EnvironmentSSH
|
5
|
+
|
6
|
+
def machines
|
7
|
+
if instances.empty?
|
8
|
+
stack_peer.do_load_resources
|
9
|
+
end
|
10
|
+
instances
|
11
|
+
end
|
12
|
+
|
13
|
+
def identifier
|
14
|
+
@environment
|
15
|
+
end
|
16
|
+
|
17
|
+
def bootstrap_settings
|
18
|
+
@bootstrap_settings
|
19
|
+
end
|
20
|
+
|
21
|
+
def namespace
|
22
|
+
"#{platform.namespace}/#{@environment.identifier}/#{identifier}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def set_instances(loaded_resources)
|
26
|
+
@instances = loaded_resources.collect(&:node)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
data/lib/progress_bar.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
class ProgressBar
|
4
|
+
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_reader :count
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@count = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def increment!
|
14
|
+
@count += 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset!
|
18
|
+
@count = 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def indicate(bar_prefix, bar_indice, indice_descriptor)
|
22
|
+
bar = "#{bar_prefix}" + "#{bar_indice * @count}>".cyan + " (#{@count} #{indice_descriptor})" + "\r"
|
23
|
+
print bar
|
24
|
+
end
|
25
|
+
|
26
|
+
def indicate_and_increment!(bar_prefix, bar_indice, indice_descriptor)
|
27
|
+
increment!
|
28
|
+
indicate(bar_prefix, bar_indice, indice_descriptor)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/ssh.rb
CHANGED
@@ -17,19 +17,10 @@ class ::Bcome::Ssh
|
|
17
17
|
def execute!
|
18
18
|
@commands.each do |command|
|
19
19
|
instance = command.instance
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
net_ssh_params = { :keys => ssh_keys, :paranoid => false }
|
25
|
-
net_ssh_params[:proxy] = proxy if proxy
|
26
|
-
|
27
|
-
::Net::SSH.start(instance.ip_address, ssh_user, net_ssh_params) do |ssh|
|
28
|
-
ssh_exec!(ssh, command)
|
29
|
-
output_append("\n(#{instance.identifier})$".cyan + ">\s#{command.command} (#{command.pretty_result})\n")
|
30
|
-
output_append("#{command.output}")
|
31
|
-
ssh.close
|
32
|
-
end
|
20
|
+
ssh = instance.ssh_connection(command.bootstrap)
|
21
|
+
ssh_exec!(ssh, command)
|
22
|
+
output_append("\n(#{instance.identifier})$".cyan + ">\s#{command.command} (#{command.pretty_result})\n")
|
23
|
+
output_append("#{command.output}")
|
33
24
|
print_output
|
34
25
|
end
|
35
26
|
end
|
data/lib/stack/base.rb
CHANGED
@@ -120,7 +120,7 @@ module ::Bcome::Stack
|
|
120
120
|
{ :command => "describe", :description => "Describe the resource object at the current context." },
|
121
121
|
{ :command => "cd NodeName", :description => "Select a resource object, and switch to its context.", :usage => "cd YourServerName" },
|
122
122
|
{ :command => "exit", :description => "Return to the previous context" },
|
123
|
-
{ :command => "exit!", :description => "Close all contexts, and exit
|
123
|
+
{ :command => "exit!", :description => "Close all contexts, and exit bcome."},
|
124
124
|
{ :command => "local", :description => "Execute a shell command on your local machine.", :usage => 'local "command"'},
|
125
125
|
{ :command => "machines", :description => "Return all servers below the current level to the console. These objects can be manipulated directly" },
|
126
126
|
{ :command => "interactive", :description => "Enter an interactive where you may transparently interact with all the machines in your selection at once" },
|
data/lib/stack/environment.rb
CHANGED
data/lib/stack/instance.rb
CHANGED
@@ -116,7 +116,7 @@ module ::Bcome::Stack
|
|
116
116
|
def do_describe
|
117
117
|
description = "\tNode Id:".menu_item_cyan + "\s\s#{node.identifier.menu_item_yellow}"
|
118
118
|
description += "\n\t" + "Internal IP: ".menu_item_cyan + "#{@meta_data[:external_network_interface_address]}".menu_item_white
|
119
|
-
description += "\n\t" + "External IP: ".menu_item_cyan + "#{node.
|
119
|
+
description += "\n\t" + "External IP: ".menu_item_cyan + "#{node.display_ip_address}".menu_item_white if node.public_ip_address
|
120
120
|
description += "\n\t" + "Role: ".menu_item_cyan + "#{node.role}".menu_item_white if node.role
|
121
121
|
description += "\n\n"
|
122
122
|
return description
|
data/lib/stack/view.rb
CHANGED
data/lib/workspace_context.rb
CHANGED
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.
|
4
|
+
version: 0.7.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: 2017-
|
11
|
+
date: 2017-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -124,10 +124,12 @@ email:
|
|
124
124
|
executables:
|
125
125
|
- bcome
|
126
126
|
- bcome-setup
|
127
|
+
- bcome-bash-setup
|
127
128
|
extensions: []
|
128
129
|
extra_rdoc_files: []
|
129
130
|
files:
|
130
131
|
- bin/bcome
|
132
|
+
- bin/bcome-bash-setup
|
131
133
|
- bin/bcome-setup
|
132
134
|
- bin/boot.rb
|
133
135
|
- bin/boot_no_shell.rb
|
@@ -156,6 +158,7 @@ files:
|
|
156
158
|
- lib/nodes/estate.rb
|
157
159
|
- lib/nodes/instance.rb
|
158
160
|
- lib/nodes/platform.rb
|
161
|
+
- lib/nodes/view.rb
|
159
162
|
- lib/object.rb
|
160
163
|
- lib/orchestrator/command_group/base.rb
|
161
164
|
- lib/orchestrator/command_group/custom.rb
|
@@ -173,6 +176,7 @@ files:
|
|
173
176
|
- lib/orchestrator/registry.rb
|
174
177
|
- lib/orchestrator/validate_and_set.rb
|
175
178
|
- lib/patches/string.rb
|
179
|
+
- lib/progress_bar.rb
|
176
180
|
- lib/render_irb.rb
|
177
181
|
- lib/scp.rb
|
178
182
|
- lib/ssh.rb
|