bcome 1.3.4 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/bin/bcome +13 -8
- data/lib/bcome.rb +14 -11
- data/lib/objects/bcome/version.rb +19 -1
- data/lib/objects/bootup.rb +16 -7
- data/lib/objects/command/local.rb +2 -0
- data/lib/objects/config_factory.rb +3 -0
- data/lib/objects/driver/base.rb +52 -6
- data/lib/objects/driver/bucket.rb +6 -4
- data/lib/objects/driver/ec2.rb +45 -5
- data/lib/objects/driver/gcp.rb +168 -0
- data/lib/objects/driver/gcp/authentication/api_key.rb +6 -0
- data/lib/objects/driver/gcp/authentication/base.rb +36 -0
- data/lib/objects/driver/gcp/authentication/oauth.rb +96 -0
- data/lib/objects/driver/gcp/authentication/oauth_client_config.rb +22 -0
- data/lib/objects/driver/gcp/authentication/oauth_session_store.rb +22 -0
- data/lib/objects/driver/gcp/authentication/service_account.rb +62 -0
- data/lib/objects/driver/gcp/authentication/signet/service_account.rb +27 -0
- data/lib/objects/driver/gcp/authentication/utilities.rb +42 -0
- data/lib/objects/encryptor.rb +109 -24
- data/lib/objects/exception/argument_error_invoking_method_from_command_line.rb +8 -4
- data/lib/objects/exception/base.rb +21 -10
- data/lib/objects/exception/can_only_subselect_on_inventory.rb +8 -4
- data/lib/objects/exception/cannot_authenticate_to_gcp.rb +11 -0
- data/lib/objects/exception/cannot_find_internal_registry_klass.rb +8 -4
- data/lib/objects/exception/cannot_find_inventory.rb +11 -0
- data/lib/objects/exception/cannot_find_subselection_parent.rb +8 -4
- data/lib/objects/exception/cant_find_key_in_cloud_tags.rb +8 -4
- data/lib/objects/exception/cant_find_key_in_metadata.rb +8 -4
- data/lib/objects/exception/cant_find_proxy_host_by_identifier.rb +8 -4
- data/lib/objects/exception/cant_find_proxy_host_by_namespace.rb +8 -4
- data/lib/objects/exception/could_not_initiate_ssh_connection.rb +8 -4
- data/lib/objects/exception/could_not_initiate_ssh_connection_through_backend_proxy.rb +8 -4
- data/lib/objects/exception/could_not_retrieve_terraform_output.rb +11 -0
- data/lib/objects/exception/deprecation_warning.rb +9 -7
- data/lib/objects/exception/duplicate_command_line_argument_key.rb +8 -4
- data/lib/objects/exception/ec2_driver_missing_authorization_keys.rb +11 -0
- data/lib/objects/exception/ec2_driver_missing_provisioning_region.rb +8 -4
- data/lib/objects/exception/empty_namespace_tree.rb +11 -0
- data/lib/objects/exception/failed_to_run_local_command.rb +8 -4
- data/lib/objects/exception/gcp_auth_service_account_missing_credentials.rb +11 -0
- data/lib/objects/exception/generic.rb +11 -0
- data/lib/objects/exception/interactive_session_halt.rb +6 -2
- data/lib/objects/exception/invalid_bcome_breadcrumb.rb +8 -4
- data/lib/objects/exception/invalid_breadcrumb.rb +8 -4
- data/lib/objects/exception/invalid_context_command.rb +8 -4
- data/lib/objects/exception/invalid_gcp_authentication_scheme.rb +11 -0
- data/lib/objects/exception/invalid_identifier.rb +8 -4
- data/lib/objects/exception/invalid_machines_cache_config.rb +8 -4
- data/lib/objects/exception/invalid_matcher_query.rb +8 -4
- data/lib/objects/exception/invalid_meta_data_config.rb +8 -4
- data/lib/objects/exception/invalid_metadata_encryption_key.rb +8 -4
- data/lib/objects/exception/invalid_network_config.rb +8 -4
- data/lib/objects/exception/invalid_network_driver_type.rb +8 -4
- data/lib/objects/exception/invalid_port_forward_request.rb +11 -0
- data/lib/objects/exception/invalid_proxy_config.rb +8 -4
- data/lib/objects/exception/invalid_regexp_matcher_in_registry.rb +8 -4
- data/lib/objects/exception/invalid_registry_arguments_type.rb +8 -4
- data/lib/objects/exception/invalid_registry_command_name_length.rb +8 -4
- data/lib/objects/exception/invalid_registry_data_config.rb +8 -4
- data/lib/objects/exception/invalid_restriction_key_in_registry.rb +8 -4
- data/lib/objects/exception/invalid_ssh_config.rb +8 -4
- data/lib/objects/exception/inventories_cannot_have_subviews.rb +8 -4
- data/lib/objects/exception/malformed_command_line_arguments.rb +8 -4
- data/lib/objects/exception/method_invocation_requires_parameter.rb +8 -4
- data/lib/objects/exception/method_name_conflict_in_registry.rb +8 -4
- data/lib/objects/exception/missing_argument_for_registry_command.rb +8 -4
- data/lib/objects/exception/missing_description_on_view.rb +8 -4
- data/lib/objects/exception/missing_execute_on_registry_object.rb +8 -4
- data/lib/objects/exception/missing_gcp_authentication_scheme.rb +11 -0
- data/lib/objects/exception/missing_gcp_service_account_credentials_filename.rb +11 -0
- data/lib/objects/exception/missing_gcp_service_scopes.rb +11 -0
- data/lib/objects/exception/missing_identifier_on_view.rb +8 -4
- data/lib/objects/exception/missing_inventory_contributors.rb +11 -0
- data/lib/objects/exception/missing_ip_address_on_server.rb +8 -4
- data/lib/objects/exception/missing_network_config.rb +8 -4
- data/lib/objects/exception/missing_or_invalid_client_secrets.rb +11 -0
- data/lib/objects/exception/missing_params_for_rsync.rb +8 -4
- data/lib/objects/exception/missing_params_for_scp.rb +8 -4
- data/lib/objects/exception/missing_subselection_key.rb +8 -4
- data/lib/objects/exception/missing_type_on_view.rb +8 -4
- data/lib/objects/exception/no_node_found_for_breadcrumb.rb +8 -4
- data/lib/objects/exception/no_node_named_by_identifier.rb +8 -4
- data/lib/objects/exception/node_identifiers_must_be_unique.rb +8 -4
- data/lib/objects/exception/orchestration_script_does_not_exist.rb +8 -4
- data/lib/objects/exception/proxy_host_node_does_not_have_public_ip_address.rb +8 -4
- data/lib/objects/exception/unknown_dynamic_server_type.rb +11 -0
- data/lib/objects/exception/unknown_method_for_namespace.rb +8 -4
- data/lib/objects/exception/user_orchestration_error.rb +11 -0
- data/lib/objects/initialization/factory.rb +36 -0
- data/lib/objects/initialization/structure.rb +18 -0
- data/lib/objects/initialization/utils.rb +20 -0
- data/lib/objects/interactive/session.rb +4 -1
- data/lib/objects/interactive/session_item/base.rb +2 -0
- data/lib/objects/interactive/session_item/capture_input.rb +2 -0
- data/lib/objects/interactive/session_item/transparent_ssh.rb +29 -23
- data/lib/objects/loading_bar/handler.rb +80 -0
- data/lib/objects/loading_bar/indicator/base.rb +65 -0
- data/lib/objects/loading_bar/indicator/basic.rb +34 -0
- data/lib/objects/loading_bar/indicator/progress.rb +26 -0
- data/lib/objects/loading_bar/pid_bucket.rb +27 -0
- data/lib/objects/modules/context.rb +13 -9
- data/lib/objects/modules/draw.rb +49 -0
- data/lib/objects/modules/registry_management.rb +16 -10
- data/lib/objects/modules/tree.rb +157 -0
- data/lib/objects/modules/ui_output.rb +10 -6
- data/lib/objects/modules/workspace_commands.rb +131 -157
- data/lib/objects/modules/workspace_menu.rb +193 -129
- data/lib/objects/node/attributes.rb +17 -19
- data/lib/objects/node/base.rb +136 -74
- data/lib/objects/node/cache_handler.rb +3 -1
- data/lib/objects/node/collection.rb +10 -9
- data/lib/objects/node/factory.rb +47 -36
- data/lib/objects/node/inventory/base.rb +106 -100
- data/lib/objects/node/inventory/defined.rb +113 -89
- data/lib/objects/node/inventory/merge.rb +51 -0
- data/lib/objects/node/inventory/subselect.rb +66 -46
- data/lib/objects/node/kube/base.rb +51 -0
- data/lib/objects/node/kube/container.rb +9 -0
- data/lib/objects/node/kube/estate.rb +19 -0
- data/lib/objects/node/kube/namespace.rb +24 -0
- data/lib/objects/node/kube/pod.rb +24 -0
- data/lib/objects/node/kube_wrap.rb +26 -0
- data/lib/objects/node/meta/base.rb +8 -1
- data/lib/objects/node/meta/cloud.rb +2 -0
- data/lib/objects/node/meta/local.rb +2 -0
- data/lib/objects/node/meta_data_factory.rb +4 -2
- data/lib/objects/node/meta_data_loader.rb +28 -29
- data/lib/objects/node/resources/base.rb +5 -1
- data/lib/objects/node/resources/inventory.rb +26 -5
- data/lib/objects/node/resources/merged.rb +47 -0
- data/lib/objects/node/resources/sub_inventory.rb +12 -8
- data/lib/objects/node/server/base.rb +105 -70
- data/lib/objects/node/server/dynamic/base.rb +23 -0
- data/lib/objects/node/server/{dynamic.rb → dynamic/ec2.rb} +13 -13
- data/lib/objects/node/server/dynamic/gcp.rb +46 -0
- data/lib/objects/node/server/static.rb +34 -10
- data/lib/objects/orchestration/base.rb +17 -1
- data/lib/objects/orchestration/interactive_terraform.rb +59 -30
- data/lib/objects/orchestrator.rb +22 -0
- data/lib/objects/parser/bread_crumb.rb +3 -1
- data/lib/objects/registry/arguments/base.rb +3 -1
- data/lib/objects/registry/arguments/command_line.rb +6 -1
- data/lib/objects/registry/arguments/console.rb +4 -1
- data/lib/objects/registry/command/base.rb +3 -0
- data/lib/objects/registry/command/external.rb +9 -3
- data/lib/objects/registry/command/group.rb +11 -4
- data/lib/objects/registry/command/internal.rb +3 -1
- data/lib/objects/registry/command/shortcut.rb +17 -9
- data/lib/objects/registry/command_list.rb +2 -0
- data/lib/objects/registry/loader.rb +13 -10
- data/lib/objects/ssh/bootstrap.rb +3 -1
- data/lib/objects/ssh/command.rb +9 -8
- data/lib/objects/ssh/command_exec.rb +16 -10
- data/lib/objects/ssh/connection_wrangler.rb +124 -0
- data/lib/objects/ssh/connector.rb +108 -0
- data/lib/objects/ssh/driver.rb +28 -242
- data/lib/objects/ssh/driver_concerns/command_strings.rb +17 -0
- data/lib/objects/ssh/driver_concerns/connection.rb +75 -0
- data/lib/objects/ssh/driver_concerns/functions.rb +89 -0
- data/lib/objects/ssh/driver_concerns/user.rb +32 -0
- data/lib/objects/ssh/proxy_chain.rb +19 -0
- data/lib/objects/ssh/proxy_chain_link.rb +26 -0
- data/lib/objects/ssh/proxy_hop.rb +130 -0
- data/lib/objects/ssh/script_exec.rb +12 -11
- data/lib/objects/ssh/tunnel/local_port_forward.rb +5 -6
- data/lib/objects/ssh/tunnel_keeper.rb +21 -0
- data/lib/objects/ssh/window.rb +31 -0
- data/lib/objects/startup.rb +58 -0
- data/lib/objects/system/local.rb +3 -0
- data/lib/objects/terraform/output.rb +45 -0
- data/lib/objects/workspace.rb +13 -14
- data/patches/irb.rb +63 -6
- data/patches/string-encrypt.rb +20 -23
- data/patches/string.rb +18 -1
- data/patches/string_stylesheet.rb +2 -0
- metadata +157 -33
- data/lib/objects/driver/static.rb +0 -4
- data/lib/objects/progress_bar.rb +0 -30
- data/lib/objects/ssh/connection_handler.rb +0 -101
- data/lib/objects/ssh/proxy_data.rb +0 -56
- data/lib/objects/terraform/parser.rb +0 -23
- data/lib/objects/terraform/state.rb +0 -40
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Node::Resources
|
2
4
|
class Base
|
3
5
|
include Enumerable
|
@@ -23,7 +25,7 @@ module Bcome::Node::Resources
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def should_rename_initial_duplicate?
|
26
|
-
|
28
|
+
false
|
27
29
|
end
|
28
30
|
|
29
31
|
def clear!
|
@@ -56,12 +58,14 @@ module Bcome::Node::Resources
|
|
56
58
|
def disable(identifier)
|
57
59
|
resource = for_identifier(identifier)
|
58
60
|
raise Bcome::Exception::NoNodeNamedByIdentifier, identifier unless resource
|
61
|
+
|
59
62
|
@disabled_resources << resource unless @disabled_resources.include?(resource)
|
60
63
|
end
|
61
64
|
|
62
65
|
def enable(identifier)
|
63
66
|
resource = for_identifier(identifier)
|
64
67
|
raise Bcome::Exception::NoNodeNamedByIdentifier, identifier unless resource
|
68
|
+
|
65
69
|
@disabled_resources -= [resource]
|
66
70
|
end
|
67
71
|
|
@@ -1,6 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Node::Resources
|
2
4
|
class Inventory < Bcome::Node::Resources::Base
|
5
|
+
def initialize(inventory)
|
6
|
+
@inventory = inventory
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def set_overrides(inventory, node)
|
11
|
+
override_server_identifier(inventory, node)
|
12
|
+
node.set_network_configuration_overrides
|
13
|
+
end
|
14
|
+
|
15
|
+
def override_server_identifier(inventory, node)
|
16
|
+
if inventory.override_server_identifier?
|
17
|
+
node.identifier =~ /#{inventory.override_identifier}/
|
18
|
+
node.update_identifier(Regexp.last_match(1)) if Regexp.last_match(1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
3
22
|
def <<(node)
|
23
|
+
set_overrides(@inventory, node)
|
24
|
+
|
4
25
|
if existing_node = for_identifier(node.identifier)
|
5
26
|
if existing_node.static_server? && node.dynamic_server?
|
6
27
|
# We've got a duplicate, but we'll treat the remote node as authoritative
|
@@ -16,14 +37,14 @@ module Bcome::Node::Resources
|
|
16
37
|
end
|
17
38
|
|
18
39
|
def should_rename_initial_duplicate?
|
19
|
-
|
20
|
-
end
|
40
|
+
true
|
41
|
+
end
|
21
42
|
|
22
43
|
def rename_initial_duplicate
|
23
|
-
duplicate_nodes.each do |node_identifier,
|
44
|
+
duplicate_nodes.each do |node_identifier, _count|
|
24
45
|
node = for_identifier(node_identifier)
|
25
46
|
node.identifier = "#{node.identifier}_1"
|
26
|
-
end
|
47
|
+
end
|
27
48
|
end
|
28
49
|
|
29
50
|
def duplicate_nodes
|
@@ -32,7 +53,7 @@ module Bcome::Node::Resources
|
|
32
53
|
|
33
54
|
def reset_duplicate_nodes!
|
34
55
|
@duplicate_nodes = {}
|
35
|
-
end
|
56
|
+
end
|
36
57
|
|
37
58
|
def dynamic_nodes
|
38
59
|
active.select(&:dynamic_server?)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bcome::Node::Resources
|
4
|
+
class Merged < Bcome::Node::Resources::Inventory
|
5
|
+
def initialize(config)
|
6
|
+
super
|
7
|
+
@inventory = config[:inventory]
|
8
|
+
@nodes = []
|
9
|
+
run_select
|
10
|
+
end
|
11
|
+
|
12
|
+
def run_select
|
13
|
+
@inventory.contributing_inventories.each do |inventory|
|
14
|
+
raise ::Bcome::Exception::Generic, "#{inventory.namespace} is not an inventory, and cannot be merged." unless inventory.is_a?(::Bcome::Node::Inventory::Base)
|
15
|
+
|
16
|
+
inventory.load_nodes unless inventory.nodes_loaded?
|
17
|
+
end
|
18
|
+
|
19
|
+
contributing_nodes = @inventory.contributing_inventories.collect { |inv| inv.resources.nodes }.flatten
|
20
|
+
dup_nodes(contributing_nodes)
|
21
|
+
|
22
|
+
@nodes
|
23
|
+
end
|
24
|
+
|
25
|
+
def dup_nodes(contributing_nodes)
|
26
|
+
contributing_nodes.each do |original_node|
|
27
|
+
# Duplicate the node, setting its origin inventory to this one, and
|
28
|
+
# resetting its ssh_driver to the original node's driver.
|
29
|
+
new_node = original_node.dup_with_new_parent(@inventory)
|
30
|
+
set_overrides(@inventory, new_node)
|
31
|
+
new_node.ssh_driver = original_node.ssh_driver
|
32
|
+
|
33
|
+
# Rename the node as contributing inventories may provide duplicate node names
|
34
|
+
rename_node_for_merged_inventory(original_node, new_node)
|
35
|
+
|
36
|
+
# Register the new node with the registry
|
37
|
+
::Bcome::Registry::Loader.instance.set_command_group_for_node(new_node)
|
38
|
+
|
39
|
+
@nodes << new_node
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def rename_node_for_merged_inventory(original_node, new_node)
|
44
|
+
new_node.identifier = original_node.namespace.gsub(':', '_')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Bcome::Node::Resources
|
2
4
|
class SubselectInventory < Bcome::Node::Resources::Inventory
|
3
5
|
def initialize(config)
|
@@ -10,8 +12,9 @@ module Bcome::Node::Resources
|
|
10
12
|
parent_inventory.load_nodes unless parent_inventory.nodes_loaded?
|
11
13
|
new_set = parent_inventory.resources.nodes
|
12
14
|
|
13
|
-
#
|
14
|
-
|
15
|
+
# ...by_tags: ec2
|
16
|
+
# ...by_label: gcp
|
17
|
+
new_set = filter_by_tags_or_label(new_set)
|
15
18
|
|
16
19
|
@nodes = new_set
|
17
20
|
end
|
@@ -21,10 +24,7 @@ module Bcome::Node::Resources
|
|
21
24
|
|
22
25
|
@nodes.collect do |node|
|
23
26
|
new_node = node.dup_with_new_parent(inventory)
|
24
|
-
|
25
|
-
new_node.identifier =~ /#{inventory.override_identifier}/
|
26
|
-
new_node.update_identifier(Regexp.last_match(1)) if Regexp.last_match(1)
|
27
|
-
end
|
27
|
+
set_overrides(inventory, new_node)
|
28
28
|
|
29
29
|
# Register the new node with the registry
|
30
30
|
::Bcome::Registry::Loader.instance.set_command_group_for_node(new_node)
|
@@ -34,7 +34,7 @@ module Bcome::Node::Resources
|
|
34
34
|
@nodes = new_set
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
37
|
+
def filter_by_tags_or_label(nodes)
|
38
38
|
tag_filters.each do |key, values|
|
39
39
|
nodes = nodes.select { |node| node.has_tagged_value?(key, values) }
|
40
40
|
end
|
@@ -50,11 +50,15 @@ module Bcome::Node::Resources
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def tag_filters
|
53
|
-
filters[:by_tag]
|
53
|
+
filters[:by_tag] || filters[:by_label] || filters
|
54
54
|
end
|
55
55
|
|
56
56
|
def parent_inventory
|
57
57
|
@config[:parent_inventory]
|
58
58
|
end
|
59
|
+
|
60
|
+
def origin_inventory
|
61
|
+
@config[:origin_inventory]
|
62
|
+
end
|
59
63
|
end
|
60
64
|
end
|
@@ -1,55 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Bcome::Node::Server
|
2
3
|
class Base < Bcome::Node::Base
|
3
|
-
|
4
4
|
attr_reader :origin_object_id
|
5
5
|
|
6
6
|
def initialize(*params)
|
7
7
|
super
|
8
8
|
# Set the object_id - sub inventories dup servers into new collections. This allows us to spot duplicates when interacting with collections
|
9
9
|
@origin_object_id = object_id
|
10
|
-
@bootstrap = false
|
11
10
|
end
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
def is_same_machine?(other)
|
13
|
+
origin_object_id == other.origin_object_id
|
14
|
+
end
|
15
|
+
|
16
|
+
def host
|
17
|
+
raise 'Should be overidden'
|
18
|
+
end
|
19
|
+
|
15
20
|
def set_view_attributes
|
16
21
|
super
|
22
|
+
end
|
23
|
+
|
24
|
+
# Override a server's namespace parameters. Enabled features such as specific SSH config for a particular server, i.e. overidding that of it's parent
|
25
|
+
# inventory namespace.
|
26
|
+
def set_network_configuration_overrides
|
17
27
|
overridden_attributes = ::Bcome::Node::Factory.instance.machines_data_for_namespace(namespace.to_sym)
|
18
28
|
overridden_attributes.each do |override_key, override_value|
|
19
|
-
|
20
|
-
|
29
|
+
singleton_class.class_eval do
|
30
|
+
define_method(override_key) do
|
31
|
+
override_value
|
32
|
+
end
|
33
|
+
end
|
21
34
|
end
|
22
35
|
end
|
23
36
|
|
24
|
-
def
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def toggle_bootstrap(set_to = (@bootstrap ? false : true))
|
29
|
-
@bootstrap = set_to
|
30
|
-
puts "Bootstrap #{bootstrap? ? "on" : "off" } for #{namespace}".informational
|
37
|
+
def local_network?
|
38
|
+
defined?(local_network) && local_network
|
31
39
|
end
|
32
40
|
|
33
41
|
def dup_with_new_parent(new_parent)
|
34
|
-
new_node =
|
42
|
+
new_node = clone
|
35
43
|
new_node.update_parent(new_parent)
|
36
44
|
new_node
|
37
|
-
end
|
45
|
+
end
|
38
46
|
|
39
47
|
def update_parent(new_parent)
|
40
48
|
@parent = new_parent
|
41
49
|
end
|
42
50
|
|
43
51
|
def tags
|
44
|
-
data_print_from_hash(cloud_tags.data,
|
52
|
+
data_print_from_hash(cloud_tags.data, 'Tags')
|
45
53
|
end
|
46
|
-
|
54
|
+
|
55
|
+
def tags_h
|
56
|
+
cloud_tags.data
|
57
|
+
end
|
58
|
+
|
47
59
|
def cloud_tags
|
48
60
|
@generated_tags ||= do_generate_cloud_tags
|
49
61
|
end
|
50
62
|
|
51
63
|
def has_tagged_value?(key, values)
|
52
|
-
matchers = { :
|
64
|
+
matchers = { key: key, values: values }
|
53
65
|
cloud_tags.has_key_and_value?(matchers)
|
54
66
|
end
|
55
67
|
|
@@ -58,11 +70,11 @@ module Bcome::Node::Server
|
|
58
70
|
end
|
59
71
|
|
60
72
|
def do_generate_cloud_tags
|
61
|
-
raise
|
73
|
+
raise 'Should be overidden'
|
62
74
|
end
|
63
75
|
|
64
76
|
def type
|
65
|
-
|
77
|
+
'server'
|
66
78
|
end
|
67
79
|
|
68
80
|
def machines
|
@@ -82,28 +94,39 @@ module Bcome::Node::Server
|
|
82
94
|
end
|
83
95
|
|
84
96
|
def enabled_menu_items
|
85
|
-
(super + [
|
97
|
+
(super + %i[get ssh tags pseudo_tty tunnel]) - %i[workon enable disable enable! disable!]
|
86
98
|
end
|
87
99
|
|
88
100
|
def menu_items
|
89
101
|
base_items = super.dup
|
90
102
|
base_items[:tags] = {
|
91
|
-
description:
|
103
|
+
description: 'print out server tags/labels',
|
104
|
+
group: :informational
|
92
105
|
}
|
93
106
|
base_items[:ssh] = {
|
94
|
-
description:
|
107
|
+
description: 'initiate an ssh connection to this server',
|
108
|
+
group: :ssh
|
95
109
|
}
|
96
110
|
base_items[:get] = {
|
97
|
-
description:
|
111
|
+
description: 'Download a file or directory',
|
98
112
|
console_only: false,
|
99
|
-
usage:
|
100
|
-
terminal_usage:
|
113
|
+
usage: 'get "/remote/path", "/local/path"',
|
114
|
+
terminal_usage: 'get "/remote/path" "/local/path"',
|
115
|
+
group: :file
|
101
116
|
}
|
102
117
|
base_items[:pseudo_tty] = {
|
103
|
-
description:
|
118
|
+
description: 'Invoke a pseudo-tty session',
|
104
119
|
console_only: false,
|
105
|
-
usage:
|
106
|
-
terminal_usage:
|
120
|
+
usage: 'pseudo_tty "your command"',
|
121
|
+
terminal_usage: 'pseudo_tty "your command"',
|
122
|
+
group: :ssh
|
123
|
+
}
|
124
|
+
base_items[:tunnel] = {
|
125
|
+
description: 'Create a Tunnel over SSH',
|
126
|
+
console_only: false,
|
127
|
+
usage: 'tunnel(local_port, destination_port)',
|
128
|
+
terminal_usage: 'tunnel local_port destination_port',
|
129
|
+
group: :ssh
|
107
130
|
}
|
108
131
|
|
109
132
|
base_items
|
@@ -112,9 +135,16 @@ module Bcome::Node::Server
|
|
112
135
|
def local_port_forward(start_port, end_port)
|
113
136
|
ssh_driver.local_port_forward(start_port, end_port)
|
114
137
|
end
|
138
|
+
alias tunnel local_port_forward
|
139
|
+
|
140
|
+
def reopen_ssh_connection
|
141
|
+
puts "Connecting\s".informational + identifier
|
142
|
+
close_ssh_connection
|
143
|
+
open_ssh_connection
|
144
|
+
end
|
115
145
|
|
116
|
-
def open_ssh_connection
|
117
|
-
ssh_driver.ssh_connection
|
146
|
+
def open_ssh_connection(ping = false)
|
147
|
+
ssh_driver.ssh_connection(ping)
|
118
148
|
end
|
119
149
|
|
120
150
|
def close_ssh_connection
|
@@ -128,7 +158,7 @@ module Bcome::Node::Server
|
|
128
158
|
def has_no_ssh_connection?
|
129
159
|
!has_ssh_connection?
|
130
160
|
end
|
131
|
-
|
161
|
+
|
132
162
|
def ssh
|
133
163
|
ssh_driver.do_ssh
|
134
164
|
end
|
@@ -142,18 +172,18 @@ module Bcome::Node::Server
|
|
142
172
|
|
143
173
|
def execute_script(script_name)
|
144
174
|
command_result = ::Bcome::Ssh::ScriptExec.execute(self, script_name)
|
145
|
-
|
175
|
+
command_result
|
146
176
|
end
|
147
177
|
|
148
178
|
def rsync(local_path, remote_path)
|
149
179
|
ssh_driver.rsync(local_path, remote_path)
|
150
180
|
end
|
151
|
-
|
152
|
-
def put(local_path, remote_path)
|
181
|
+
|
182
|
+
def put(local_path, remote_path, *_params)
|
153
183
|
ssh_driver.put(local_path, remote_path)
|
154
184
|
end
|
155
185
|
|
156
|
-
def put_str(string, remote_path)
|
186
|
+
def put_str(string, remote_path, *_params)
|
157
187
|
ssh_driver.put_str(string, remote_path)
|
158
188
|
end
|
159
189
|
|
@@ -165,7 +195,7 @@ module Bcome::Node::Server
|
|
165
195
|
puts "\n" + visual_hierarchy.hierarchy + "\n"
|
166
196
|
puts pretty_description
|
167
197
|
end
|
168
|
-
alias
|
198
|
+
alias lsa ls
|
169
199
|
|
170
200
|
def ping
|
171
201
|
ping_result = ssh_driver.ping
|
@@ -173,68 +203,74 @@ module Bcome::Node::Server
|
|
173
203
|
end
|
174
204
|
|
175
205
|
def print_ping_result(ping_result = { success: true })
|
176
|
-
|
177
|
-
namespace => {
|
178
|
-
"connection" => ping_result[:success] ? "success" : "failed",
|
179
|
-
"ssh_config" => ssh_driver.pretty_config_details
|
180
|
-
}
|
181
|
-
}
|
206
|
+
result_string = ping_result[:success] ? 'success'.success : 'failed'.error
|
182
207
|
|
183
|
-
|
184
|
-
|
185
|
-
|
208
|
+
pretty_ping_result = "\n#{namespace.bc_cyan}:\s#{result_string.bold}\n"
|
209
|
+
pretty_ping_result += "Error:\s".bc_cyan + "#{ping_result[:error].message.bc_red}\n" if !ping_result[:success] && ping_result[:error]
|
210
|
+
# pretty_ping_result += ping_result[:backtrace] if ping_result[:backtrace]
|
211
|
+
pretty_ping_result += "config:\s".bc_cyan + JSON.pretty_generate(ssh_driver.pretty_ssh_config)
|
212
|
+
puts pretty_ping_result
|
213
|
+
end
|
186
214
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
string: colour,
|
194
|
-
keyword: colour,
|
195
|
-
variable: colour,
|
196
|
-
array: colour
|
197
|
-
}
|
198
|
-
}
|
215
|
+
def add_list_attributes(attrs)
|
216
|
+
@attribs = list_attributes.merge(attrs)
|
217
|
+
end
|
218
|
+
|
219
|
+
def origin_namespace
|
220
|
+
parent.namespace
|
199
221
|
end
|
200
222
|
|
201
223
|
def list_attributes
|
224
|
+
@attribs ||= set_list_attributes
|
225
|
+
end
|
226
|
+
|
227
|
+
def set_list_attributes
|
202
228
|
attribs = {
|
203
229
|
"identifier": :identifier,
|
204
230
|
"internal ip": :internal_ip_address,
|
205
231
|
"public ip": :public_ip_address,
|
232
|
+
"host": :host
|
206
233
|
}
|
207
234
|
|
208
|
-
attribs.merge!("description": :description ) if has_description?
|
209
235
|
attribs
|
210
236
|
end
|
211
237
|
|
212
238
|
def cache_data
|
213
|
-
d = { identifier:
|
239
|
+
d = { identifier: @original_identifier }
|
214
240
|
d[:internal_ip_address] = internal_ip_address if internal_ip_address
|
215
241
|
d[:public_ip_address] = public_ip_address if public_ip_address
|
216
242
|
d[:description] = description if description
|
217
|
-
d[:cloud_tags] = cloud_tags
|
243
|
+
d[:cloud_tags] = cloud_tags
|
218
244
|
d
|
219
245
|
end
|
220
246
|
|
221
247
|
def do_run(raw_commands)
|
222
248
|
raw_commands = raw_commands.is_a?(String) ? [raw_commands] : raw_commands
|
223
|
-
commands = raw_commands.collect{|raw_command| ::Bcome::Ssh::Command.new(
|
249
|
+
commands = raw_commands.collect { |raw_command| ::Bcome::Ssh::Command.new(node: self, raw: raw_command) }
|
224
250
|
command_exec = ::Bcome::Ssh::CommandExec.new(commands)
|
225
251
|
command_exec.execute!
|
226
|
-
commands.each
|
227
|
-
|
252
|
+
commands.each(&:unset_node)
|
253
|
+
commands
|
228
254
|
end
|
229
255
|
|
230
256
|
def run(*raw_commands)
|
231
|
-
raise ::Bcome::Exception::MethodInvocationRequiresParameter
|
232
|
-
|
233
|
-
|
257
|
+
raise ::Bcome::Exception::MethodInvocationRequiresParameter, "Please specify commands when invoking 'run'" if raw_commands.empty?
|
258
|
+
|
259
|
+
do_run(raw_commands)
|
260
|
+
rescue IOError, Errno::EBADF
|
261
|
+
reopen_ssh_connection
|
262
|
+
do_run(raw_commands)
|
263
|
+
rescue Exception => e
|
264
|
+
if e.message == 'Unexpected spurious read wakeup'
|
265
|
+
reopen_ssh_connection
|
266
|
+
do_run(raw_commands)
|
267
|
+
else
|
268
|
+
raise e
|
269
|
+
end
|
234
270
|
end
|
235
271
|
|
236
272
|
def has_description?
|
237
|
-
|
273
|
+
!description.nil?
|
238
274
|
end
|
239
275
|
|
240
276
|
def static_server?
|
@@ -244,6 +280,5 @@ module Bcome::Node::Server
|
|
244
280
|
def dynamic_server?
|
245
281
|
!static_server?
|
246
282
|
end
|
247
|
-
|
248
|
-
end
|
283
|
+
end
|
249
284
|
end
|