bcome 0.7.0 → 1.0.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 +8 -39
- data/lib/bcome.rb +12 -3
- data/lib/objects/bcome/version.rb +3 -0
- data/lib/objects/bootup.rb +81 -0
- data/lib/objects/command/local.rb +40 -0
- data/lib/objects/config_factory.rb +36 -0
- data/lib/objects/driver/base.rb +30 -0
- data/lib/objects/driver/bucket.rb +20 -0
- data/lib/objects/driver/ec2.rb +44 -0
- data/lib/objects/driver/static.rb +4 -0
- data/lib/objects/exception/argument_error_invoking_method_from_command_line.rb +7 -0
- data/lib/objects/exception/base.rb +15 -0
- data/lib/objects/exception/can_only_subselect_on_inventory.rb +7 -0
- data/lib/objects/exception/cannot_find_internal_registry_klass.rb +7 -0
- data/lib/objects/exception/cannot_find_subselection_parent.rb +7 -0
- data/lib/objects/exception/cant_find_key_in_cloud_tags.rb +7 -0
- data/lib/objects/exception/cant_find_key_in_metadata.rb +7 -0
- data/lib/objects/exception/cant_find_proxy_host_by_identifier.rb +7 -0
- data/lib/objects/exception/cant_find_proxy_host_by_namespace.rb +7 -0
- data/lib/objects/exception/could_not_initiate_ssh_connection.rb +7 -0
- data/lib/objects/exception/could_not_initiate_ssh_connection_through_backend_proxy.rb +7 -0
- data/lib/objects/exception/deprecation_warning.rb +11 -0
- data/lib/objects/exception/duplicate_command_line_argument_key.rb +7 -0
- data/lib/objects/exception/ec2_driver_missing_provisioning_region.rb +7 -0
- data/lib/objects/exception/failed_to_run_local_command.rb +7 -0
- data/lib/objects/exception/interactive_session_halt.rb +4 -0
- data/lib/objects/exception/invalid_bcome_breadcrumb.rb +7 -0
- data/lib/objects/exception/invalid_breadcrumb.rb +7 -0
- data/lib/objects/exception/invalid_context_command.rb +7 -0
- data/lib/objects/exception/invalid_identifier.rb +7 -0
- data/lib/objects/exception/invalid_machines_cache_config.rb +7 -0
- data/lib/objects/exception/invalid_matcher_query.rb +7 -0
- data/lib/objects/exception/invalid_meta_data_config.rb +7 -0
- data/lib/objects/exception/invalid_network_config.rb +7 -0
- data/lib/objects/exception/invalid_network_driver_type.rb +7 -0
- data/lib/objects/exception/invalid_proxy_config.rb +7 -0
- data/lib/objects/exception/invalid_regexp_matcher_in_registry.rb +7 -0
- data/lib/objects/exception/invalid_registry_arguments_type.rb +7 -0
- data/lib/objects/exception/invalid_registry_data_config.rb +7 -0
- data/lib/objects/exception/invalid_restriction_key_in_registry.rb +7 -0
- data/lib/objects/exception/invalid_ssh_config.rb +7 -0
- data/lib/objects/exception/inventories_cannot_have_subviews.rb +7 -0
- data/lib/objects/exception/malformed_command_line_arguments.rb +7 -0
- data/lib/objects/exception/method_invocation_requires_parameter.rb +7 -0
- data/lib/objects/exception/method_name_conflict_in_registry.rb +7 -0
- data/lib/objects/exception/missing_argument_for_registry_command.rb +7 -0
- data/lib/objects/exception/missing_description_on_view.rb +7 -0
- data/lib/objects/exception/missing_execute_on_registry_object.rb +7 -0
- data/lib/objects/exception/missing_identifier_on_view.rb +7 -0
- data/lib/objects/exception/missing_ip_address_on_server.rb +7 -0
- data/lib/objects/exception/missing_network_config.rb +7 -0
- data/lib/objects/exception/missing_params_for_rsync.rb +7 -0
- data/lib/objects/exception/missing_params_for_scp.rb +7 -0
- data/lib/objects/exception/missing_subselection_key.rb +7 -0
- data/lib/objects/exception/missing_type_on_view.rb +7 -0
- data/lib/objects/exception/no_node_found_for_breadcrumb.rb +7 -0
- data/lib/objects/exception/no_node_named_by_identifier.rb +7 -0
- data/lib/objects/exception/node_identifiers_must_be_unique.rb +7 -0
- data/lib/objects/exception/orchestration_script_does_not_exist.rb +7 -0
- data/lib/objects/exception/proxy_host_node_does_not_have_public_ip_address.rb +7 -0
- data/lib/objects/exception/unknown_method_for_namespace.rb +7 -0
- data/lib/objects/interactive/session.rb +45 -0
- data/lib/objects/interactive/session_item/base.rb +36 -0
- data/lib/objects/interactive/session_item/capture_input.rb +20 -0
- data/lib/objects/interactive/session_item/transparent_ssh.rb +111 -0
- data/lib/objects/modules/context.rb +13 -0
- data/lib/objects/modules/registry_management.rb +14 -0
- data/lib/objects/modules/ui_output.rb +9 -0
- data/lib/objects/modules/workspace_commands.rb +198 -0
- data/lib/objects/modules/workspace_menu.rb +128 -0
- data/lib/objects/node/attributes.rb +47 -0
- data/lib/objects/node/base.rb +248 -0
- data/lib/objects/node/cache_handler.rb +24 -0
- data/lib/objects/node/collection.rb +51 -0
- data/lib/objects/node/factory.rb +108 -0
- data/lib/objects/node/inventory/base.rb +88 -0
- data/lib/objects/node/inventory/defined.rb +112 -0
- data/lib/objects/node/inventory/subselect.rb +54 -0
- data/lib/objects/node/meta/base.rb +36 -0
- data/lib/objects/node/meta/cloud.rb +4 -0
- data/lib/objects/node/meta/local.rb +4 -0
- data/lib/objects/node/meta_data_factory.rb +23 -0
- data/lib/objects/node/meta_data_loader.rb +32 -0
- data/lib/objects/node/resources/base.rb +98 -0
- data/lib/objects/node/resources/inventory.rb +25 -0
- data/lib/objects/node/resources/sub_inventory.rb +56 -0
- data/lib/objects/node/server/base.rb +218 -0
- data/lib/objects/node/server/dynamic.rb +39 -0
- data/lib/objects/node/server/static.rb +31 -0
- data/lib/objects/orchestration/base.rb +13 -0
- data/lib/objects/orchestrator.rb +24 -0
- data/lib/objects/parser/bread_crumb.rb +31 -0
- data/lib/objects/progress_bar.rb +30 -0
- data/lib/objects/registry/arguments/base.rb +36 -0
- data/lib/objects/registry/arguments/command_line.rb +35 -0
- data/lib/objects/registry/arguments/console.rb +15 -0
- data/lib/objects/registry/command/base.rb +66 -0
- data/lib/objects/registry/command/external.rb +55 -0
- data/lib/objects/registry/command/group.rb +76 -0
- data/lib/objects/registry/command/internal.rb +34 -0
- data/lib/objects/registry/command_list.rb +33 -0
- data/lib/objects/registry/loader.rb +70 -0
- data/lib/objects/ssh/bootstrap.rb +19 -0
- data/lib/objects/ssh/command.rb +46 -0
- data/lib/objects/ssh/command_exec.rb +65 -0
- data/lib/objects/ssh/connection_handler.rb +101 -0
- data/lib/objects/ssh/driver.rb +204 -0
- data/lib/objects/ssh/proxy_data.rb +56 -0
- data/lib/objects/ssh/script_exec.rb +43 -0
- data/lib/objects/system/local.rb +30 -0
- data/lib/objects/workspace.rb +75 -0
- data/patches/irb.rb +20 -7
- data/patches/string.rb +75 -0
- data/patches/string_stylesheet.rb +61 -0
- metadata +175 -93
- data/bin/bcome-bash-setup +0 -18
- data/bin/bcome-setup +0 -43
- data/bin/boot.rb +0 -148
- data/bin/boot_no_shell.rb +0 -3
- data/filters/ec2_filter.rb +0 -12
- data/lib/bcome/version.rb +0 -3
- data/lib/become_object.rb +0 -111
- data/lib/boot.rb +0 -13
- data/lib/command.rb +0 -56
- data/lib/context_functions.rb +0 -65
- data/lib/filters/base.rb +0 -10
- data/lib/filters/ec2_filter.rb +0 -4
- data/lib/functions.rb +0 -70
- data/lib/helpers/command_helper.rb +0 -13
- data/lib/helpers/environment_ssh.rb +0 -122
- data/lib/helpers/fog_helper.rb +0 -108
- data/lib/helpers/instance_command.rb +0 -71
- data/lib/helpers/instance_ssh.rb +0 -83
- data/lib/helpers/selections.rb +0 -117
- data/lib/interactive/interactive_session_halt.rb +0 -4
- data/lib/interactive/session.rb +0 -44
- data/lib/interactive/session_item/base.rb +0 -30
- data/lib/interactive/session_item/transparent_ssh.rb +0 -133
- data/lib/nodes/base.rb +0 -60
- data/lib/nodes/environment.rb +0 -30
- data/lib/nodes/estate.rb +0 -44
- data/lib/nodes/instance.rb +0 -94
- data/lib/nodes/platform.rb +0 -17
- data/lib/nodes/view.rb +0 -31
- data/lib/object.rb +0 -21
- data/lib/orchestrator/command_group/base.rb +0 -56
- data/lib/orchestrator/command_group/custom.rb +0 -13
- data/lib/orchestrator/command_group/direct.rb +0 -53
- data/lib/orchestrator/direct_command/group.rb +0 -21
- data/lib/orchestrator/direct_command/instance.rb +0 -19
- data/lib/orchestrator/factory.rb +0 -38
- data/lib/orchestrator/loader.rb +0 -47
- data/lib/orchestrator/node_target/all.rb +0 -14
- data/lib/orchestrator/node_target/all_excluding_roles.rb +0 -14
- data/lib/orchestrator/node_target/all_with_roles.rb +0 -14
- data/lib/orchestrator/node_target/base.rb +0 -43
- data/lib/orchestrator/node_target/single.rb +0 -12
- data/lib/orchestrator/recipe.rb +0 -60
- data/lib/orchestrator/registry.rb +0 -37
- data/lib/orchestrator/validate_and_set.rb +0 -10
- data/lib/patches/string.rb +0 -86
- data/lib/progress_bar.rb +0 -31
- data/lib/render_irb.rb +0 -53
- data/lib/scp.rb +0 -40
- data/lib/ssh.rb +0 -51
- data/lib/stack/base.rb +0 -148
- data/lib/stack/environment.rb +0 -222
- data/lib/stack/estate.rb +0 -50
- data/lib/stack/instance.rb +0 -130
- data/lib/stack/platform.rb +0 -74
- data/lib/stack/view.rb +0 -56
- data/lib/workspace_context.rb +0 -40
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Bcome::Interactive::SessionItem
|
|
2
|
+
class Base
|
|
3
|
+
def initialize(session, init_data)
|
|
4
|
+
@session = session
|
|
5
|
+
@init_data = init_data
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def bcome_identifier
|
|
9
|
+
node.namespace
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def node
|
|
13
|
+
@session.node
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def options
|
|
17
|
+
@session.options
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def set_response_on_session
|
|
21
|
+
@session.responses[@key] = @response
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def do(*_params)
|
|
25
|
+
raise 'Should be overidden'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def has_start_message?
|
|
29
|
+
true
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_input(message = terminal_prompt)
|
|
33
|
+
::Readline.readline("\n#{message}", true).squeeze('').to_s
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Bcome::Interactive::SessionItem
|
|
2
|
+
class CaptureInput < ::Bcome::Interactive::SessionItem::Base
|
|
3
|
+
def do
|
|
4
|
+
action
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def terminal_prompt
|
|
8
|
+
"\n" + @init_data[:terminal_prompt].informational
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def action
|
|
12
|
+
input = get_input
|
|
13
|
+
input.empty? ? get_input : input
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def has_start_message?
|
|
17
|
+
false
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
module Bcome::Interactive::SessionItem
|
|
2
|
+
class TransparentSsh < ::Bcome::Interactive::SessionItem::Base
|
|
3
|
+
END_SESSION_KEY = '\\q'.freeze
|
|
4
|
+
HELP_KEY = '\\?'.freeze
|
|
5
|
+
LIST_KEY = '\\l'.freeze
|
|
6
|
+
|
|
7
|
+
DANGER_CMD = "rm\s+-r|rm\s+-f|rm\s+-fr|rm\s+-rf|rm".freeze
|
|
8
|
+
|
|
9
|
+
def machines
|
|
10
|
+
node.server? ? [node] : node.machines
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def do
|
|
14
|
+
puts ''
|
|
15
|
+
open_ssh_connections
|
|
16
|
+
show_menu
|
|
17
|
+
puts ''
|
|
18
|
+
list_machines
|
|
19
|
+
action
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def action
|
|
23
|
+
input = get_input
|
|
24
|
+
|
|
25
|
+
if exit?(input)
|
|
26
|
+
close_ssh_connections
|
|
27
|
+
return
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if show_menu?(input)
|
|
31
|
+
show_menu
|
|
32
|
+
elsif list_machines?(input)
|
|
33
|
+
list_machines
|
|
34
|
+
elsif command_may_be_unwise?(input)
|
|
35
|
+
handle_the_unwise(input)
|
|
36
|
+
else
|
|
37
|
+
execute_on_machines(input)
|
|
38
|
+
end
|
|
39
|
+
action
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def show_menu
|
|
43
|
+
warning = "\n\sCommands entered here will be executed on " + 'EVERY'.underline + ' machine in your selection.'
|
|
44
|
+
second_warning = "\n\n\s" + 'Use with CAUTION.'.warning
|
|
45
|
+
info = "\n\n\s\\l list machines\n\s\\q to quit\n\s\\? this message".informational
|
|
46
|
+
puts "#{warning}#{second_warning}#{info}\n"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def handle_the_unwise(input)
|
|
50
|
+
if prompt_for_confirmation('Command may be dangerous to run on all machines. Are you sure you want to proceed? [Y|N] > '.error)
|
|
51
|
+
execute_on_machines(input)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def command_may_be_unwise?(input)
|
|
56
|
+
input =~ /#{DANGER_CMD}/
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def prompt_for_confirmation(message)
|
|
60
|
+
answer = get_input(message)
|
|
61
|
+
prompt_for_confirmation(message) unless %w[Y N].include?(answer)
|
|
62
|
+
answer == 'Y'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def start_message; end
|
|
66
|
+
|
|
67
|
+
def terminal_prompt
|
|
68
|
+
">\s".bold.terminal_prompt
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def exit?(input)
|
|
72
|
+
input == END_SESSION_KEY
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def show_menu?(input)
|
|
76
|
+
input == HELP_KEY
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def list_machines?(input)
|
|
80
|
+
input == LIST_KEY
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def open_ssh_connections
|
|
84
|
+
::Bcome::Ssh::ConnectionHandler.connect(node, show_progress: true)
|
|
85
|
+
system('clear')
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def close_ssh_connections
|
|
89
|
+
node.close_ssh_connections
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def indicate_failed_nodes(unconnected_nodes)
|
|
93
|
+
unconnected_nodes.each do |node|
|
|
94
|
+
puts "\s\s - #{node.namespace}".bc_cyan
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def list_machines
|
|
99
|
+
puts "\n"
|
|
100
|
+
machines.each do |machine|
|
|
101
|
+
puts "\s- #{machine.namespace}"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def execute_on_machines(user_input)
|
|
106
|
+
machines.pmap do |machine|
|
|
107
|
+
machine.run(user_input)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Bcome::Context
|
|
2
|
+
def is_current_context?
|
|
3
|
+
::Bcome::Workspace.instance.object_is_current_context?(self)
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def irb_workspace=(workspace)
|
|
7
|
+
@irb_workspace = workspace
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def previous_irb_workspace=(workspace)
|
|
11
|
+
@previous_workspace = workspace
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Bcome::Node::RegistryManagement
|
|
2
|
+
def user_command_wrapper
|
|
3
|
+
@user_command_wrapper ||= ::Bcome::Registry::CommandList.instance.group_for_node(self)
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def registry
|
|
7
|
+
command_group = user_command_wrapper
|
|
8
|
+
if command_group && command_group.has_commands?
|
|
9
|
+
command_group.pretty_print
|
|
10
|
+
else
|
|
11
|
+
puts "\nYou have no registry commands configured for this namespace.\n".warning
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
module Bcome::WorkspaceCommands
|
|
2
|
+
def ls(active_only = false)
|
|
3
|
+
puts "\n\n" + visual_hierarchy.hierarchy + "\n"
|
|
4
|
+
puts "\t" + "Available #{list_key}s:".title + "\n\n"
|
|
5
|
+
|
|
6
|
+
iterate_over = active_only ? @resources.active : @resources
|
|
7
|
+
|
|
8
|
+
if iterate_over.any?
|
|
9
|
+
iterate_over.sort_by(&:identifier).each do |resource|
|
|
10
|
+
is_active = @resources.is_active_resource?(resource)
|
|
11
|
+
puts resource.pretty_description(is_active)
|
|
12
|
+
puts "\n"
|
|
13
|
+
end
|
|
14
|
+
else
|
|
15
|
+
puts "\tNo resources found".informational
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
new_line
|
|
19
|
+
nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def lsa
|
|
23
|
+
show_active_only = true
|
|
24
|
+
ls(show_active_only)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def interactive
|
|
28
|
+
::Bcome::Interactive::Session.run(self, :interactive_ssh)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def tree
|
|
32
|
+
puts "\nTree view\n".title
|
|
33
|
+
tab = ''
|
|
34
|
+
parents.reverse.each do |p|
|
|
35
|
+
print_tree_view_for_resource(tab, p)
|
|
36
|
+
tab = "#{tab}\t"
|
|
37
|
+
end
|
|
38
|
+
print_tree_view_for_resource(tab, self)
|
|
39
|
+
list_in_tree("#{tab}\t", resources)
|
|
40
|
+
print "\n"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def parents
|
|
44
|
+
ps = []
|
|
45
|
+
ps << [parent, parent.parents] if has_parent?
|
|
46
|
+
ps.flatten
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def list_in_tree(tab, resources)
|
|
50
|
+
resources.sort_by(&:identifier).each do |resource|
|
|
51
|
+
next if resource.parent && !resource.parent.resources.is_active_resource?(resource)
|
|
52
|
+
resource.load_nodes if resource.inventory? && !resource.nodes_loaded?
|
|
53
|
+
print_tree_view_for_resource(tab, resource)
|
|
54
|
+
list_in_tree("#{tab}\t", resource.resources)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def print_tree_view_for_resource(tab, resource)
|
|
59
|
+
separator = '-'
|
|
60
|
+
tree_item = tab.to_s + separator.resource_key + " #{resource.type.resource_key} \s#{resource.identifier.resource_value}"
|
|
61
|
+
tree_item += ' (empty set)' if !resource.server? && !resource.resources.has_active_nodes?
|
|
62
|
+
puts tree_item
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def cd(identifier)
|
|
66
|
+
if resource = resources.for_identifier(identifier)
|
|
67
|
+
if resource.parent.resources.is_active_resource?(resource)
|
|
68
|
+
::Bcome::Workspace.instance.set(current_context: self, context: resource)
|
|
69
|
+
else
|
|
70
|
+
puts "\nCannot enter context - #{identifier} is disabled. To enable enter 'enable #{identifier}'\n".error
|
|
71
|
+
end
|
|
72
|
+
else
|
|
73
|
+
raise Bcome::Exception::InvalidBreadcrumb, "Cannot find a node named '#{identifier}'"
|
|
74
|
+
puts "#{identifier} not found"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def run(*raw_commands)
|
|
79
|
+
raise Bcome::Exception::MethodInvocationRequiresParameter, "Please specify commands when invoking 'run'" if raw_commands.empty?
|
|
80
|
+
results = {}
|
|
81
|
+
|
|
82
|
+
::Bcome::Ssh::ConnectionHandler.connect(self, {})
|
|
83
|
+
|
|
84
|
+
machines.pmap do |machine|
|
|
85
|
+
commands = machine.do_run(raw_commands)
|
|
86
|
+
results[machine.namespace] = commands
|
|
87
|
+
end
|
|
88
|
+
results
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def ping
|
|
92
|
+
::Bcome::Ssh::ConnectionHandler.connect(self, is_ping: true)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def pretty_description(is_active = true)
|
|
96
|
+
desc = ''
|
|
97
|
+
list_attributes.each do |key, value|
|
|
98
|
+
next unless respond_to?(value) || instance_variable_defined?("@#{value}")
|
|
99
|
+
attribute_value = send(value)
|
|
100
|
+
next unless attribute_value
|
|
101
|
+
|
|
102
|
+
desc += "\t"
|
|
103
|
+
desc += is_active ? key.to_s.resource_key : key.to_s.resource_key_inactive
|
|
104
|
+
desc += "\s" * (12 - key.length)
|
|
105
|
+
attribute_value = value == :identifier ? attribute_value.underline : attribute_value
|
|
106
|
+
desc += is_active ? attribute_value.resource_value : attribute_value.resource_value_inactive
|
|
107
|
+
desc += "\n"
|
|
108
|
+
desc = desc unless is_active
|
|
109
|
+
end
|
|
110
|
+
desc
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def back
|
|
114
|
+
exit
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def disable(*ids)
|
|
118
|
+
ids.each { |id| resources.do_disable(id) }
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def enable(*ids)
|
|
122
|
+
ids.each { |id| resources.do_enable(id) }
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def clear!
|
|
126
|
+
# Clear any disabled selection at this level and at all levels below
|
|
127
|
+
resources.clear!
|
|
128
|
+
resources.each(&:clear!)
|
|
129
|
+
nil
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def workon(*ids)
|
|
133
|
+
resources.disable!
|
|
134
|
+
ids.each { |id| resources.do_enable(id) }
|
|
135
|
+
puts "\nYou are now working on '#{ids.join(', ')}\n".informational
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def disable!
|
|
139
|
+
resources.disable!
|
|
140
|
+
resources.each(&:disable!)
|
|
141
|
+
nil
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def enable!
|
|
145
|
+
resources.enable!
|
|
146
|
+
resources.each(&:enable!)
|
|
147
|
+
nil
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
## Helpers --
|
|
151
|
+
|
|
152
|
+
def resource_identifiers
|
|
153
|
+
resources.collect(&:identifier)
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def is_node_level_method?(method_sym)
|
|
157
|
+
respond_to?(method_sym) || method_is_available_on_node?(method_sym)
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def method_missing(method_sym, *arguments)
|
|
161
|
+
unless method_is_available_on_node?(method_sym)
|
|
162
|
+
raise NameError, "NameError: undefined local variable or method '#{method_sym}'"
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
if resource_identifiers.include?(method_sym.to_s)
|
|
166
|
+
method_sym.to_s
|
|
167
|
+
elsif instance_variable_defined?("@#{method_sym}")
|
|
168
|
+
instance_variable_get("@#{method_sym}")
|
|
169
|
+
else
|
|
170
|
+
command = user_command_wrapper.command_for_console_command_name(method_sym)
|
|
171
|
+
command.execute(self, arguments)
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def method_in_registry?(method_sym)
|
|
176
|
+
::Bcome::Registry::CommandList.instance.command_in_list?(self, method_sym)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def method_is_available_on_node?(method_sym)
|
|
180
|
+
resource_identifiers.include?(method_sym.to_s) || instance_variable_defined?("@#{method_sym}") || method_in_registry?(method_sym) || respond_to?(method_sym)
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def visual_hierarchy
|
|
184
|
+
tabs = 0
|
|
185
|
+
hierarchy = ''
|
|
186
|
+
tree_descriptions.each { |d| hierarchy += "#{"\s\s\s" * tabs}|- #{d}\n"; tabs += 1; }
|
|
187
|
+
hierarchy
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def tree_descriptions
|
|
191
|
+
d = parent ? parent.tree_descriptions + [description] : [description]
|
|
192
|
+
d.flatten
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def new_line
|
|
196
|
+
puts "\n"
|
|
197
|
+
end
|
|
198
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
module Bcome::WorkspaceMenu
|
|
2
|
+
def menu
|
|
3
|
+
print "\n\n"
|
|
4
|
+
puts "#{mode} menu".title + "\sfor #{self.class} #{namespace}".resource_value + "\n\n"
|
|
5
|
+
enabled_menu_items.each_with_index do |menu_item, _index|
|
|
6
|
+
item = menu_items[menu_item]
|
|
7
|
+
next if !::Bcome::System::Local.instance.in_console_session? && item[:console_only]
|
|
8
|
+
puts tab_spacing + menu_item.to_s.resource_key + item_spacing(menu_item) + (menu_items[menu_item][:description]).to_s.resource_value
|
|
9
|
+
if item[:usage] || item[:terminal_usage]
|
|
10
|
+
usage_string = ::Bcome::System::Local.instance.in_console_session? ? item[:usage] : "bcome #{keyed_namespace.empty? ? '' : "#{keyed_namespace}:"}#{item[:terminal_usage]}"
|
|
11
|
+
puts tab_spacing + ("\s" * menu_item_spacing_length) + 'usage: '.instructional + usage_string
|
|
12
|
+
end
|
|
13
|
+
puts "\n"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
nil
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def mode
|
|
20
|
+
::Bcome::System::Local.instance.in_console_session? ? 'Console' : 'Terminal'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def item_spacing(item)
|
|
24
|
+
"\s" * (menu_item_spacing_length - item.length)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def menu_item_spacing_length
|
|
28
|
+
16
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def tab_spacing
|
|
32
|
+
"\s" * 3
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def menu_items
|
|
36
|
+
{
|
|
37
|
+
ls: {
|
|
38
|
+
description: 'list all available resources',
|
|
39
|
+
console_only: false
|
|
40
|
+
},
|
|
41
|
+
lsa: {
|
|
42
|
+
description: 'list all active resources',
|
|
43
|
+
console_only: true
|
|
44
|
+
},
|
|
45
|
+
workon: {
|
|
46
|
+
description: 'work on specific resources only, inactivating all others from this selection',
|
|
47
|
+
usage: 'workon identifier1, identifier2 ...',
|
|
48
|
+
console_only: true
|
|
49
|
+
},
|
|
50
|
+
disable: {
|
|
51
|
+
description: 'remove a resource from this selection',
|
|
52
|
+
usage: 'disable identifier1, identifier2 ...',
|
|
53
|
+
console_only: true
|
|
54
|
+
},
|
|
55
|
+
enable: {
|
|
56
|
+
description: 're-enable a resource within this selection',
|
|
57
|
+
usage: 'enable identifier1, identifier2 ...',
|
|
58
|
+
console_only: true
|
|
59
|
+
},
|
|
60
|
+
enable!: {
|
|
61
|
+
description: 'enable all resources within this selection',
|
|
62
|
+
console_only: true
|
|
63
|
+
},
|
|
64
|
+
disable!: {
|
|
65
|
+
description: 'disable all resources within this selection',
|
|
66
|
+
console_only: true
|
|
67
|
+
},
|
|
68
|
+
run: {
|
|
69
|
+
description: 'execute a command to be run over ssh against all active resources',
|
|
70
|
+
usage: "run 'command1', 'command2', ...",
|
|
71
|
+
console_only: false,
|
|
72
|
+
terminal_usage: "run 'command1' 'command2' ..."
|
|
73
|
+
},
|
|
74
|
+
interactive: {
|
|
75
|
+
description: 'enter an interactive command session for all active resources',
|
|
76
|
+
console_only: false
|
|
77
|
+
},
|
|
78
|
+
tree: {
|
|
79
|
+
description: 'print a tree view for all resources and their sub-resources',
|
|
80
|
+
console_only: false
|
|
81
|
+
},
|
|
82
|
+
ping: {
|
|
83
|
+
description: 'ping all resources to test connectivity',
|
|
84
|
+
console_only: false
|
|
85
|
+
},
|
|
86
|
+
put: {
|
|
87
|
+
description: 'upload a file or directory using scp',
|
|
88
|
+
usage: "put 'local/path','remote/path'",
|
|
89
|
+
console_only: false,
|
|
90
|
+
terminal_usage: "put 'local/path' 'remote/path'"
|
|
91
|
+
},
|
|
92
|
+
rsync: {
|
|
93
|
+
description: 'upload a file or directory using rsync (faster)',
|
|
94
|
+
usage: "rsync 'local/path','remote/path'",
|
|
95
|
+
console_only: false,
|
|
96
|
+
terminal_usage: "rsync 'local/path' 'remote/path'"
|
|
97
|
+
},
|
|
98
|
+
get: {
|
|
99
|
+
description: 'download a file',
|
|
100
|
+
usage: "get 'remote/path', 'local/path'",
|
|
101
|
+
console_only: false,
|
|
102
|
+
terminal_usage: "get 'remote/path' 'local/path"
|
|
103
|
+
},
|
|
104
|
+
cd: {
|
|
105
|
+
description: 'enter the namespace for a resource from this selection',
|
|
106
|
+
usage: 'cd identifier',
|
|
107
|
+
console_only: true
|
|
108
|
+
},
|
|
109
|
+
save: {
|
|
110
|
+
description: 'Save the current tree state',
|
|
111
|
+
console_only: true
|
|
112
|
+
},
|
|
113
|
+
meta: {
|
|
114
|
+
description: 'Print out all metadata related to this node'
|
|
115
|
+
},
|
|
116
|
+
registry: {
|
|
117
|
+
description: 'List all user defined commands present in your registry, and available to this namespace',
|
|
118
|
+
console_only: false
|
|
119
|
+
},
|
|
120
|
+
execute_script: {
|
|
121
|
+
description: 'execute a bash script',
|
|
122
|
+
console_only: false,
|
|
123
|
+
usage: 'execute_script "script_name"',
|
|
124
|
+
terminal_usage: 'execute_script script_name'
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
end
|
|
128
|
+
end
|