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
data/lib/filters/base.rb
DELETED
data/lib/filters/ec2_filter.rb
DELETED
data/lib/functions.rb
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
module Bcome::Functions
|
|
2
|
-
|
|
3
|
-
CONFIGS_PATH = "bcome/config"
|
|
4
|
-
|
|
5
|
-
def functions
|
|
6
|
-
unless cmd_functions
|
|
7
|
-
puts "\n\n" + "You don't yet have any custom functions defined. Have a read of the docs and define some. They're pretty useful.".warning + "\n\n"
|
|
8
|
-
else
|
|
9
|
-
puts "\n\n\s\s" + "Functions".menu_title_green + "\n\n"
|
|
10
|
-
cmd_functions.each_with_index do |cmd_function, i|
|
|
11
|
-
puts "\tShortcut: ".menu_item_cyan + "\s#{cmd_function[:ref].informational}"
|
|
12
|
-
puts "\tDescription:".menu_item_cyan + "\s#{cmd_function[:description]}"
|
|
13
|
-
puts "\tCommand:".menu_item_cyan + "\s#{cmd_function[:command]}"
|
|
14
|
-
puts "\tUsage:".menu_item_cyan + "\sF \"#{cmd_function[:ref]}\""
|
|
15
|
-
puts
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
return
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def F(reference)
|
|
22
|
-
if self.is_a?(Bcome::Stack::Environment) && no_selections?
|
|
23
|
-
puts "\n\n" + "You are an an Environment level, and have not selected any nodes to workon.".warning + "\n\n"
|
|
24
|
-
else
|
|
25
|
-
command = cmd_for_ref(reference)
|
|
26
|
-
if command
|
|
27
|
-
#puts "#{"Executing command '#{command[:ref]}': ".informational} > #{command[:command].command}"
|
|
28
|
-
puts run command[:command]
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def cmd_for_ref(reference)
|
|
34
|
-
commands = cmd_functions.select{|command| command[:ref].to_s == reference.to_s }
|
|
35
|
-
raise "Multiple commands found for reference '#{reference}'. Your functions list is ambiguous.".failure if commands.size > 1
|
|
36
|
-
unless commands.any?
|
|
37
|
-
puts "No command found for reference '#{reference}'".failure
|
|
38
|
-
return nil
|
|
39
|
-
end
|
|
40
|
-
return commands.first
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def cmd_functions
|
|
44
|
-
return unless has_functions_config?
|
|
45
|
-
@cmd_functions ||= load_cmd_functions
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def has_cmd_functions?
|
|
49
|
-
!cmd_functions.nil?
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def load_cmd_functions
|
|
53
|
-
configs = YAML.load_file(cmd_config_path)
|
|
54
|
-
unless configs.has_key?(:single_functions)
|
|
55
|
-
raise "Invalid functions configuration. Please check your yaml".failure
|
|
56
|
-
else
|
|
57
|
-
return configs[:single_functions]
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def cmd_config_path
|
|
62
|
-
"#{CONFIGS_PATH}/functions.yml"
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def has_functions_config?
|
|
66
|
-
File.exist?(cmd_config_path)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module ::Bcome::CommandHelper
|
|
2
|
-
|
|
3
|
-
def run_local(command, silent = false)
|
|
4
|
-
begin
|
|
5
|
-
puts "(local) > #{command}" if !silent && ::VERBOSE
|
|
6
|
-
system(command)
|
|
7
|
-
rescue Interrupt
|
|
8
|
-
puts "Exiting gracefully from interrupt".warning
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
alias :local :run_local
|
|
12
|
-
|
|
13
|
-
end
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
module ::Bcome::EnvironmentSSH
|
|
2
|
-
|
|
3
|
-
def proxy(bootstrap = false)
|
|
4
|
-
return nil unless ssh_mode_type == ::SSH_JUMP_MODE_IDENTIFIER
|
|
5
|
-
|
|
6
|
-
unless bootstrap
|
|
7
|
-
return Net::SSH::Proxy::Command.new(proxy_command)
|
|
8
|
-
else
|
|
9
|
-
return Net::SSH::Proxy::Command.new(bootstrap_proxy_command)
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def proxy_command
|
|
14
|
-
return "ssh -W %h:%p #{bastion_ip_address}"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def bootstrap_proxy_command
|
|
18
|
-
return "ssh -i #{bootstrap_settings[:key]} -o StrictHostKeyChecking=no -W %h:%p #{bootstrap_settings[:ssh_user]}@#{bastion_ip_address}"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def execute_command(commands, instance, bootstrap = false)
|
|
22
|
-
begin
|
|
23
|
-
return execute_cmd(commands, instance, proxy(bootstrap), bootstrap)
|
|
24
|
-
rescue Net::SSH::AuthenticationFailed
|
|
25
|
-
raise "Could not authenticate connection to #{instance.identifier}".failure
|
|
26
|
-
rescue Net::SSH::Disconnect
|
|
27
|
-
raise "SSH connection to #{instance.identifier} was disconnected".failure
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def execute_cmd(raw_commands, instance, proxy, bootstrap = false)
|
|
32
|
-
commands = raw_commands.collect{|raw_command|
|
|
33
|
-
raw_command.is_a?(::Bcome::Command) ? raw_command : ::Bcome::Command.new(:command => raw_command, :instance => instance, :bootstrap => bootstrap)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
ssh = ::Bcome::Ssh.new(commands)
|
|
37
|
-
ssh.execute!
|
|
38
|
-
return commands
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def execute_scp_upload(files, remote_path, instance)
|
|
42
|
-
begin
|
|
43
|
-
scp = ::Bcome::Scp.new(proxy, instance)
|
|
44
|
-
scp.upload!(files, remote_path)
|
|
45
|
-
rescue Net::SSH::AuthenticationFailed
|
|
46
|
-
raise "Could not authenticate connection to #{instance.identifier}".failure
|
|
47
|
-
rescue Net::SSH::Disconnect
|
|
48
|
-
raise "SSH connection to #{instance.identifier} was disconnected".failure
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def execute_scp_download(remote_path, local_path, instance)
|
|
53
|
-
begin
|
|
54
|
-
scp = ::Bcome::Scp.new(proxy, instance)
|
|
55
|
-
scp.download!(remote_path, local_path)
|
|
56
|
-
rescue Net::SSH::AuthenticationFailed
|
|
57
|
-
raise "Could not authenticate connection to #{instance.identifier}".failure
|
|
58
|
-
rescue Net::SSH::Disconnect
|
|
59
|
-
raise "SSH connection to #{instance.identifier} was disconnected".failure
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def bastion_server
|
|
64
|
-
machines.select{|instance| instance.identifier == @ssh_mode[:jump_host_identifier] }.first
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def ssh_mode_type
|
|
68
|
-
ssh_mode_type = @ssh_mode[:type]
|
|
69
|
-
raise "Invalid ssh mode type #{ssh_mode_type}. Should be one of #{valid_ssh_modes.join(", ")}".failure unless valid_ssh_modes.include?(ssh_mode_type)
|
|
70
|
-
return @ssh_mode[:type]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def ssh_mode_user
|
|
74
|
-
return @ssh_mode[:ssh_user]
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def ssh_user
|
|
78
|
-
(@ssh_mode && ssh_mode_user) ? ssh_mode_user : `whoami`.gsub("\n","")
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def ssh_nat_user
|
|
82
|
-
return @ssh_mode[:nat_user]
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def ssh_key_path
|
|
86
|
-
return @ssh_mode[:ssh_key_path]
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def valid_ssh_modes
|
|
90
|
-
[::SSH_JUMP_MODE_IDENTIFIER, ::SSH_DIRECT_MODE_IDENTIFIER]
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def bastion_ip_address
|
|
94
|
-
unless bastion_server
|
|
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
|
-
end
|
|
97
|
-
|
|
98
|
-
if dynamic_network_lookup?
|
|
99
|
-
return bastion_server.public_ip_address
|
|
100
|
-
else
|
|
101
|
-
bastion_ip_address = @ssh_mode[:jump_host_ip_address]
|
|
102
|
-
raise "No jump_host_ip_address specified in your configuration.".failure unless bastion_ip_address
|
|
103
|
-
return bastion_ip_address
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def network_lookup
|
|
108
|
-
raise "Missing network lookup in networks_environment configuration".failure unless @network_lookup
|
|
109
|
-
return @network_lookup
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def network_lookup_type
|
|
113
|
-
type = network_lookup[:type]
|
|
114
|
-
raise "Unknown network lookup type '#{type}" unless ["dynamic", "static"].include?(type)
|
|
115
|
-
return type
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def dynamic_network_lookup?
|
|
119
|
-
return network_lookup_type == "dynamic"
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
end
|
data/lib/helpers/fog_helper.rb
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
module ::Bcome::FogHelper
|
|
2
|
-
|
|
3
|
-
def credentials_key
|
|
4
|
-
network_lookup[:credentials_key]
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def fog_client
|
|
8
|
-
@fog_client ||= get_fog_client
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def ec2_filters
|
|
12
|
-
network_lookup[:ec2_server_lookup_filters] ? network_lookup[:ec2_server_lookup_filters] : unfiltered_search_params
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def reload!
|
|
16
|
-
@unfiltered_servers = fog_client.servers.all(ec2_filters)
|
|
17
|
-
restock_inventory = true
|
|
18
|
-
@resources = do_load_resources(restock_inventory)
|
|
19
|
-
@node = construct_node
|
|
20
|
-
system("clear")
|
|
21
|
-
list
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def unfiltered_search_params
|
|
25
|
-
{ 'instance-id' => [] }
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
## FOG filter lookups - TODO: misnomers & good intentions ------------
|
|
29
|
-
|
|
30
|
-
## smell
|
|
31
|
-
def render_servers_not_returned_by_filtered_lookup
|
|
32
|
-
return unless show_all_unfiltered_status?
|
|
33
|
-
unfiltered_servers = servers(servers_not_returned_by_filtered_lookup)
|
|
34
|
-
if unfiltered_servers.any?
|
|
35
|
-
puts "\n#{network_lookup[:show_all_unfiltered_title]}".informational
|
|
36
|
-
puts unfiltered_servers.collect{|server|
|
|
37
|
-
"#{server.tags["Name"].menu_item_cyan} - #{server.state.send(colour_code_for_server_status[server.state])}"
|
|
38
|
-
}.join("\n")
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def colour_code_for_server_status
|
|
43
|
-
{
|
|
44
|
-
"pending" => :headsup,
|
|
45
|
-
"running" => :friendly,
|
|
46
|
-
"terminated" => :menu_item_white, #durr
|
|
47
|
-
"stopping" => :headsup,
|
|
48
|
-
"stopped" => :danger
|
|
49
|
-
}
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def servers_not_returned_by_filtered_lookup
|
|
53
|
-
filtered_lookup_names = resources.collect(&:identifier)
|
|
54
|
-
return unfiltered_fog_lookup.select{|server| !filtered_lookup_names.include?(server.tags["Name"]) }
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def unfiltered_fog_lookup
|
|
58
|
-
fog_client.servers.all(unfiltered_search_params)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def show_all_unfiltered_status?
|
|
62
|
-
self.network_lookup[:show_all_unfiltered]
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def unfiltered_servers ### Misnomer - these are filtered
|
|
66
|
-
@unfiltered_servers ||= fog_client.servers.all(ec2_filters)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
## ---------------------------------------------------------------------
|
|
70
|
-
|
|
71
|
-
def ec2_tags
|
|
72
|
-
network_lookup[:ec2_tag_filter]
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def servers(all = unfiltered_servers)
|
|
76
|
-
filtered_by_tags = ec2_tags ? filter_by_tags(all) : all
|
|
77
|
-
custom_filter_method = @meta_data[:network_lookup][:custom_post_process_filter_method]
|
|
78
|
-
|
|
79
|
-
if custom_filter_method
|
|
80
|
-
filter = ::Bcome::Filter::Ec2Filter.new(filtered_by_tags, self)
|
|
81
|
-
raise "Custom filter method #{custom_filter_method} is missing. Make sure you've added it".failure unless filter.respond_to?(custom_filter_method.to_sym)
|
|
82
|
-
return filter.send(custom_filter_method.to_sym)
|
|
83
|
-
else
|
|
84
|
-
return filtered_by_tags
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def filter_by_tags(instances)
|
|
89
|
-
return instances.select{|instance| instance_matches_tags?(instance)}
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def instance_matches_tags?(instance)
|
|
93
|
-
tags = instance.tags
|
|
94
|
-
return ec2_tags.select{|key, value| tags[key.to_s] == value }.size == ec2_tags.keys.size
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
private
|
|
98
|
-
|
|
99
|
-
def get_fog_client
|
|
100
|
-
::Fog.credential = credentials_key
|
|
101
|
-
client = ::Fog::Compute.new(
|
|
102
|
-
:provider => "AWS",
|
|
103
|
-
:region => network_lookup[:provisioning_region]
|
|
104
|
-
)
|
|
105
|
-
return client
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
end
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
module ::Bcome::InstanceCommand
|
|
2
|
-
|
|
3
|
-
def run(raw_commands, bootstrap = false)
|
|
4
|
-
commands = raw_commands.is_a?(String) ? [raw_commands] : raw_commands
|
|
5
|
-
return execute_command(commands, bootstrap)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def execute_command(commands, bootstrap = false)
|
|
9
|
-
begin
|
|
10
|
-
return environment.execute_command(commands, self, bootstrap)
|
|
11
|
-
rescue Exception => e
|
|
12
|
-
puts e.message
|
|
13
|
-
puts e.backtrace.join(", ")
|
|
14
|
-
|
|
15
|
-
if bootstrap_settings ### Try bootstrap fallback
|
|
16
|
-
puts "\n failed to connect. Attempting bootstrap connection".informational
|
|
17
|
-
bootstrap = true
|
|
18
|
-
return environment.execute_command(commands, self, bootstrap)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def put(local_path, remote_path, bootstrap = false)
|
|
24
|
-
puts "rsync> #{self.identifier}".informational
|
|
25
|
-
if environment.ssh_mode_type == ::SSH_DIRECT_MODE_IDENTIFIER
|
|
26
|
-
## DIRECT MODE
|
|
27
|
-
rsync_command = bootstrap ? direct_rsync_bootstrap(local_path, remote_path) : direct_rsync(local_path, remote_path)
|
|
28
|
-
else
|
|
29
|
-
## JUMP HOST MODE
|
|
30
|
-
rsync_command = bootstrap ? jump_host_rsync_bootstrap(local_path, remote_path) : jump_host_rsync(local_path, remote_path)
|
|
31
|
-
end
|
|
32
|
-
run_local(rsync_command)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def direct_rsync(local_path, remote_path)
|
|
36
|
-
"rsync #{rsync_is_sudo}-av #{local_path} #{self.ssh_user}@#{self.ip_address}:#{remote_path}"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def jump_host_rsync(local_path, remote_path)
|
|
40
|
-
"rsync -av -e \"ssh -A #{self.nat_user}@#{environment.bastion_ip_address} ssh -o StrictHostKeyChecking=no\" #{rsync_is_sudo}#{local_path} #{self.ssh_user}@#{self.ip_address}:#{remote_path}"
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def direct_rsync_bootstrap(local_path, remote_path)
|
|
44
|
-
"rsync -i #{bootstrap_settings[:key]} #{rsync_is_sudo}-av #{local_path} #{bootstrap_settings[:ssh_user]}@#{self.ip_address}:#{remote_path}"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def jump_host_rsync_bootstrap(local_path, remote_path)
|
|
48
|
-
"rsync -av -e \"ssh -i #{bootstrap_settings[:key]} -A #{bootstrap_settings[:ssh_user]}@#{environment.bastion_ip_address} ssh -o StrictHostKeyChecking=no\" #{rsync_is_sudo}#{local_path} #{bootstrap_settings[:ssh_user]}@#{self.ip_address}:#{remote_path}"
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def get(remote_path, local_path = local_download_path)
|
|
52
|
-
raise "No local path specified" unless local_path
|
|
53
|
-
raise "No remote_path specified" unless remote_path
|
|
54
|
-
|
|
55
|
-
if environment.ssh_mode_type == ::SSH_DIRECT_MODE_IDENTIFIER
|
|
56
|
-
rsync_command = "rsync #{rsync_is_sudo} -chavzP #{self.ssh_user}@#{self.ip_address}:#{remote_path} #{local_path}"
|
|
57
|
-
else
|
|
58
|
-
rsync_command = "rsync -chavzP -av -e \"ssh -A #{self.nat_user}@#{environment.bastion_ip_address} ssh -o StrictHostKeyChecking=no\" #{rsync_is_sudo}#{self.ssh_user}@#{self.ip_address}:#{remote_path} #{local_path}"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
silent = true
|
|
62
|
-
local("mkdir -p #{local_path}", silent)
|
|
63
|
-
run_local(rsync_command)
|
|
64
|
-
puts "done: files copied to #{local_path}".informational
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def rsync_is_sudo
|
|
68
|
-
is_sudo? ? " --rsync-path=\"sudo rsync\" " : ""
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
end
|
data/lib/helpers/instance_ssh.rb
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
module ::Bcome::InstanceSsh
|
|
2
|
-
|
|
3
|
-
def execute_task(task_name, *args)
|
|
4
|
-
begin
|
|
5
|
-
public_send(task_name, *args)
|
|
6
|
-
rescue ::Seahorse::Client::NetworkingError
|
|
7
|
-
puts "Could not execute '#{task_name}'. Cannot initiate connection - check your network connection and try again.".failure
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def do_ssh(command)
|
|
12
|
-
result = execute_task(:run_local, command)
|
|
13
|
-
unless result
|
|
14
|
-
if bootstrap_settings
|
|
15
|
-
puts "\n BOOTSTRAP MODE".informational
|
|
16
|
-
execute_task(:run_local, non_bootstrapped_ssh_command)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
return result
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def ssh_jump_command_to_bastion
|
|
23
|
-
command = "ssh -o UserKnownHostsFile=/dev/null -i #{ssh_key_path} #{nat_user}@#{bastion_ip_address}"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def ssh_jump_command_to_internal_node
|
|
27
|
-
command = "ssh -o UserKnownHostsFile=/dev/null -i #{ssh_key_path} -o \"ProxyCommand ssh -W %h:%p -i #{ssh_key_path} #{nat_user}@#{bastion_ip_address}\" #{ssh_user}@#{ip_address}"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def direct_ssh_command
|
|
31
|
-
command = "ssh #{environment.ssh_mode_user}@#{public_ip_address}"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def nat_user
|
|
35
|
-
return environment.ssh_nat_user ? environment.ssh_nat_user : ssh_user
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def ssh_user(bootstrap = false)
|
|
39
|
-
bootstrap ? bootstrap_settings[:ssh_user] : (environment.ssh_mode_user ? environment.ssh_mode_user : `whoami`.gsub("\n",""))
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def ssh_key_path
|
|
43
|
-
return environment.ssh_key_path ? environment.ssh_key_path : "~/.ssh/id_rsa"
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def keys
|
|
47
|
-
[ssh_key_path]
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def bastion_ip_address
|
|
51
|
-
return environment.bastion_ip_address
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def is_direct_ssh?
|
|
55
|
-
environment.ssh_mode_type == ::SSH_DIRECT_MODE_IDENTIFIER
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def is_jump_ssh?
|
|
59
|
-
environment.ssh_mode_type == ::SSH_JUMP_MODE_IDENTIFIER
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def ssh
|
|
63
|
-
is_jump_ssh? ? (is_ssh_jump_host? ? do_ssh(ssh_jump_command_to_bastion) : do_ssh(ssh_jump_command_to_internal_node)) : do_ssh(direct_ssh_command)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def non_bootstrapped_ssh_command
|
|
67
|
-
command = is_jump_ssh? ? (
|
|
68
|
-
is_ssh_jump_host? ? (
|
|
69
|
-
"ssh -i #{bootstrap_settings[:key]} #{bootstrap_settings[:ssh_user]}@#{bastion_ip_address}"
|
|
70
|
-
) : (
|
|
71
|
-
"ssh -i #{bootstrap_settings[:key]} -t #{bootstrap_settings[:ssh_user]}@#{bastion_ip_address} ssh -t #{ip_address}"
|
|
72
|
-
)
|
|
73
|
-
) : (
|
|
74
|
-
"ssh -i #{bootstrap_settings[:key]} #{bootstrap_settings[:ssh_user]}@#{ip_address}"
|
|
75
|
-
)
|
|
76
|
-
return command
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def is_ssh_jump_host?
|
|
80
|
-
@role == ::SSH_JUMP_HOST_ROLE_IDENTIFIER
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
end
|