bcome 0.4.1 → 0.5.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/documentation/interactive_mode.md +36 -0
- data/lib/bcome/version.rb +1 -1
- data/lib/interactive/interactive_session_halt.rb +4 -0
- data/lib/interactive/session.rb +42 -0
- data/lib/interactive/session_item/base.rb +30 -0
- data/lib/interactive/session_item/transparent_ssh.rb +82 -0
- data/lib/stack/base.rb +6 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da26ecc8e341d6c26a8b7243903ccfb64bb90627
|
4
|
+
data.tar.gz: 91d217becd8fa055b38b85fcc205efa85728911e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08e3ea167a7bfd6a46fd00ca59d428ea46d8257a1c2dbed0c1e7e7f25d9bef25dfee264dc46e280c64ee74c069a2c9ba8bd1196af836cd4afc5ca91e7222b181
|
7
|
+
data.tar.gz: 1e097242ea3a069ebf5a80212d5817c87a92b170d7233bc06dda3804dcb0addd3fdf4082fbb1ee5b86bff6a91b87a260f963f769586a599811d2c26fee5e8413
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Interactive mode
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
|
5
|
+
Interactive mode lets you interact transparently from the shell with every machine at an Estate level, platform level, or with selections of machines (or all) at an environment level.
|
6
|
+
|
7
|
+
Put simply: One shell to control any number of machines, with input & output inline.
|
8
|
+
|
9
|
+
### Use case example
|
10
|
+
|
11
|
+
You have a platform named "wbz", and an environment named "prod", and you wish to interact with the application servers:
|
12
|
+
|
13
|
+
#### Enter the shell
|
14
|
+
|
15
|
+
```
|
16
|
+
> bundle exec bcome wbz:prod
|
17
|
+
```
|
18
|
+
|
19
|
+
#### Pick the machines you want
|
20
|
+
|
21
|
+
Add all machines
|
22
|
+
|
23
|
+
```
|
24
|
+
> add!
|
25
|
+
```
|
26
|
+
|
27
|
+
Or just add the ones you want (hit 'menu' if you're unsure how to work with machine selections)
|
28
|
+
|
29
|
+
```
|
30
|
+
> add [app_server1, app_server2, app_server3, ...]
|
31
|
+
```
|
32
|
+
|
33
|
+
And then enter interctive mode
|
34
|
+
```
|
35
|
+
> interactive
|
36
|
+
```
|
data/lib/bcome/version.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Bcome::Interactive
|
2
|
+
class Session
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def run(irb_session)
|
6
|
+
irb_pre_session_return_format = irb_session.conf.return_format
|
7
|
+
session_end_message = "\ninteractive session ended".success
|
8
|
+
begin
|
9
|
+
session = ::Bcome::Interactive::Session.new(irb_session)
|
10
|
+
irb_session.conf.return_format = ""
|
11
|
+
system("clear")
|
12
|
+
session.prompt
|
13
|
+
rescue ::Bcome::Interactive::SessionHalt
|
14
|
+
irb_session.conf.return_format = irb_pre_session_return_format
|
15
|
+
puts session_end_message
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :responses, :irb_session
|
21
|
+
|
22
|
+
def initialize(irb_session)
|
23
|
+
@irb_session = irb_session
|
24
|
+
@responses = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def prompt
|
28
|
+
item = ::Bcome::Interactive::SessionItem::TransparentSsh.new(self)
|
29
|
+
print item.start_message
|
30
|
+
process_item(item)
|
31
|
+
end
|
32
|
+
|
33
|
+
def process_item(item)
|
34
|
+
begin
|
35
|
+
item.do
|
36
|
+
rescue
|
37
|
+
raise ::Bcome::Interactive::SessionHalt.new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Bcome::Interactive::SessionItem
|
2
|
+
class Base
|
3
|
+
|
4
|
+
def initialize(session)
|
5
|
+
@session = session
|
6
|
+
@irb_session = @session.irb_session
|
7
|
+
end
|
8
|
+
|
9
|
+
def bcome_identifier
|
10
|
+
@irb_session.become_identifier
|
11
|
+
end
|
12
|
+
|
13
|
+
def irb_session
|
14
|
+
@session.irb_session
|
15
|
+
end
|
16
|
+
|
17
|
+
def options
|
18
|
+
@session.options
|
19
|
+
end
|
20
|
+
|
21
|
+
def set_response_on_session
|
22
|
+
@session.responses[@key] = @response
|
23
|
+
end
|
24
|
+
|
25
|
+
def do(*params)
|
26
|
+
raise "Should be overidden"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Bcome::Interactive::SessionItem
|
2
|
+
class TransparentSsh < ::Bcome::Interactive::SessionItem::Base
|
3
|
+
|
4
|
+
END_SESSION_KEY = "\\q"
|
5
|
+
HELP_KEY = "\\?"
|
6
|
+
LIST_KEY = "\\l"
|
7
|
+
|
8
|
+
def do
|
9
|
+
input = get_input
|
10
|
+
raise ::Bcome::Interactive::SessionHalt.new if exit?(input)
|
11
|
+
if show_menu?(input)
|
12
|
+
show_menu
|
13
|
+
elsif list_machines?(input)
|
14
|
+
list_machines
|
15
|
+
else
|
16
|
+
execute_on_machines(input)
|
17
|
+
end
|
18
|
+
send(:do)
|
19
|
+
end
|
20
|
+
|
21
|
+
def show_menu
|
22
|
+
system("clear") ; print start_message
|
23
|
+
end
|
24
|
+
|
25
|
+
def start_message
|
26
|
+
warning = "\nCommands entered here will be executed on every machine in your selection.".danger
|
27
|
+
second_warning = "\nUse with CAUTION.".danger
|
28
|
+
info = "\n\n\\l list machines\n\\q to quit\n\\? this message".informational
|
29
|
+
|
30
|
+
return "#{warning}#{second_warning}#{info}\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
def terminal_prompt
|
34
|
+
"#{bcome_identifier}>\s" + "interactive\s>\s".command # high voltage
|
35
|
+
end
|
36
|
+
|
37
|
+
def valid_response(response)
|
38
|
+
a = response.gsub("\s", "").downcase
|
39
|
+
valid_responses.include?(response)
|
40
|
+
end
|
41
|
+
|
42
|
+
def exit?(input)
|
43
|
+
input == END_SESSION_KEY
|
44
|
+
end
|
45
|
+
|
46
|
+
def show_menu?(input)
|
47
|
+
input == HELP_KEY
|
48
|
+
end
|
49
|
+
|
50
|
+
def list_machines?(input)
|
51
|
+
input == LIST_KEY
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_input
|
55
|
+
return ::Readline.readline("\n#{terminal_prompt}", true).squeeze(" " ).to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
def execute_on_machines(user_input)
|
59
|
+
machines.pmap {|machine|
|
60
|
+
machine.run(user_input)
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def list_machines
|
65
|
+
listed = "\n#{machines.collect(&:identifier).join(", ")}\n"
|
66
|
+
print listed.friendly
|
67
|
+
end
|
68
|
+
|
69
|
+
def machines
|
70
|
+
@machines ||= has_selected_machines? ? selected_machines : @irb_session.machines
|
71
|
+
end
|
72
|
+
|
73
|
+
def has_selected_machines?
|
74
|
+
selected_machines.is_a?(Array) && selected_machines.any?
|
75
|
+
end
|
76
|
+
|
77
|
+
def selected_machines
|
78
|
+
@selections ||= @irb_session.instance_variable_get(:@objects)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/lib/stack/base.rb
CHANGED
@@ -9,6 +9,10 @@ module ::Bcome::Stack
|
|
9
9
|
node.machines
|
10
10
|
end
|
11
11
|
|
12
|
+
def interactive
|
13
|
+
::Bcome::Interactive::Session.run(self)
|
14
|
+
end
|
15
|
+
|
12
16
|
def self.const_missing(constant_name)
|
13
17
|
## Hook for direct access to stack level resources by constant name where
|
14
18
|
## cd ServerName should yield the same outcome as cd "ServerName" or cd :ServerName does
|
@@ -111,7 +115,8 @@ module ::Bcome::Stack
|
|
111
115
|
{ :command => "exit", :description => "Return to the previous context" },
|
112
116
|
{ :command => "exit!", :description => "Close all contexts, and exit Become."},
|
113
117
|
{ :command => "local", :description => "Execute a shell command on your local machine.", :usage => 'local "command"'},
|
114
|
-
{ :command => "machines", :description => "Return all servers below the current level to the console. These objects can be manipulated directly" }
|
118
|
+
{ :command => "machines", :description => "Return all servers below the current level to the console. These objects can be manipulated directly" },
|
119
|
+
{ :command => "interactive", :description => "Enter an interactive where you may transparently interact with all the machines in your selection at once" },
|
115
120
|
]
|
116
121
|
end
|
117
122
|
|
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.5.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: 2016-08-
|
11
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- documentation/images/direct_cmd_execution.png
|
144
144
|
- documentation/images/direct_ssh.png
|
145
145
|
- documentation/installation.md
|
146
|
+
- documentation/interactive_mode.md
|
146
147
|
- documentation/usage.md
|
147
148
|
- filters/ec2_filter.rb
|
148
149
|
- lib/bcome.rb
|
@@ -160,6 +161,10 @@ files:
|
|
160
161
|
- lib/helpers/instance_command.rb
|
161
162
|
- lib/helpers/instance_ssh.rb
|
162
163
|
- lib/helpers/selections.rb
|
164
|
+
- lib/interactive/interactive_session_halt.rb
|
165
|
+
- lib/interactive/session.rb
|
166
|
+
- lib/interactive/session_item/base.rb
|
167
|
+
- lib/interactive/session_item/transparent_ssh.rb
|
163
168
|
- lib/nodes/base.rb
|
164
169
|
- lib/nodes/environment.rb
|
165
170
|
- lib/nodes/estate.rb
|