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.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bcome +8 -39
  3. data/lib/bcome.rb +12 -3
  4. data/lib/objects/bcome/version.rb +3 -0
  5. data/lib/objects/bootup.rb +81 -0
  6. data/lib/objects/command/local.rb +40 -0
  7. data/lib/objects/config_factory.rb +36 -0
  8. data/lib/objects/driver/base.rb +30 -0
  9. data/lib/objects/driver/bucket.rb +20 -0
  10. data/lib/objects/driver/ec2.rb +44 -0
  11. data/lib/objects/driver/static.rb +4 -0
  12. data/lib/objects/exception/argument_error_invoking_method_from_command_line.rb +7 -0
  13. data/lib/objects/exception/base.rb +15 -0
  14. data/lib/objects/exception/can_only_subselect_on_inventory.rb +7 -0
  15. data/lib/objects/exception/cannot_find_internal_registry_klass.rb +7 -0
  16. data/lib/objects/exception/cannot_find_subselection_parent.rb +7 -0
  17. data/lib/objects/exception/cant_find_key_in_cloud_tags.rb +7 -0
  18. data/lib/objects/exception/cant_find_key_in_metadata.rb +7 -0
  19. data/lib/objects/exception/cant_find_proxy_host_by_identifier.rb +7 -0
  20. data/lib/objects/exception/cant_find_proxy_host_by_namespace.rb +7 -0
  21. data/lib/objects/exception/could_not_initiate_ssh_connection.rb +7 -0
  22. data/lib/objects/exception/could_not_initiate_ssh_connection_through_backend_proxy.rb +7 -0
  23. data/lib/objects/exception/deprecation_warning.rb +11 -0
  24. data/lib/objects/exception/duplicate_command_line_argument_key.rb +7 -0
  25. data/lib/objects/exception/ec2_driver_missing_provisioning_region.rb +7 -0
  26. data/lib/objects/exception/failed_to_run_local_command.rb +7 -0
  27. data/lib/objects/exception/interactive_session_halt.rb +4 -0
  28. data/lib/objects/exception/invalid_bcome_breadcrumb.rb +7 -0
  29. data/lib/objects/exception/invalid_breadcrumb.rb +7 -0
  30. data/lib/objects/exception/invalid_context_command.rb +7 -0
  31. data/lib/objects/exception/invalid_identifier.rb +7 -0
  32. data/lib/objects/exception/invalid_machines_cache_config.rb +7 -0
  33. data/lib/objects/exception/invalid_matcher_query.rb +7 -0
  34. data/lib/objects/exception/invalid_meta_data_config.rb +7 -0
  35. data/lib/objects/exception/invalid_network_config.rb +7 -0
  36. data/lib/objects/exception/invalid_network_driver_type.rb +7 -0
  37. data/lib/objects/exception/invalid_proxy_config.rb +7 -0
  38. data/lib/objects/exception/invalid_regexp_matcher_in_registry.rb +7 -0
  39. data/lib/objects/exception/invalid_registry_arguments_type.rb +7 -0
  40. data/lib/objects/exception/invalid_registry_data_config.rb +7 -0
  41. data/lib/objects/exception/invalid_restriction_key_in_registry.rb +7 -0
  42. data/lib/objects/exception/invalid_ssh_config.rb +7 -0
  43. data/lib/objects/exception/inventories_cannot_have_subviews.rb +7 -0
  44. data/lib/objects/exception/malformed_command_line_arguments.rb +7 -0
  45. data/lib/objects/exception/method_invocation_requires_parameter.rb +7 -0
  46. data/lib/objects/exception/method_name_conflict_in_registry.rb +7 -0
  47. data/lib/objects/exception/missing_argument_for_registry_command.rb +7 -0
  48. data/lib/objects/exception/missing_description_on_view.rb +7 -0
  49. data/lib/objects/exception/missing_execute_on_registry_object.rb +7 -0
  50. data/lib/objects/exception/missing_identifier_on_view.rb +7 -0
  51. data/lib/objects/exception/missing_ip_address_on_server.rb +7 -0
  52. data/lib/objects/exception/missing_network_config.rb +7 -0
  53. data/lib/objects/exception/missing_params_for_rsync.rb +7 -0
  54. data/lib/objects/exception/missing_params_for_scp.rb +7 -0
  55. data/lib/objects/exception/missing_subselection_key.rb +7 -0
  56. data/lib/objects/exception/missing_type_on_view.rb +7 -0
  57. data/lib/objects/exception/no_node_found_for_breadcrumb.rb +7 -0
  58. data/lib/objects/exception/no_node_named_by_identifier.rb +7 -0
  59. data/lib/objects/exception/node_identifiers_must_be_unique.rb +7 -0
  60. data/lib/objects/exception/orchestration_script_does_not_exist.rb +7 -0
  61. data/lib/objects/exception/proxy_host_node_does_not_have_public_ip_address.rb +7 -0
  62. data/lib/objects/exception/unknown_method_for_namespace.rb +7 -0
  63. data/lib/objects/interactive/session.rb +45 -0
  64. data/lib/objects/interactive/session_item/base.rb +36 -0
  65. data/lib/objects/interactive/session_item/capture_input.rb +20 -0
  66. data/lib/objects/interactive/session_item/transparent_ssh.rb +111 -0
  67. data/lib/objects/modules/context.rb +13 -0
  68. data/lib/objects/modules/registry_management.rb +14 -0
  69. data/lib/objects/modules/ui_output.rb +9 -0
  70. data/lib/objects/modules/workspace_commands.rb +198 -0
  71. data/lib/objects/modules/workspace_menu.rb +128 -0
  72. data/lib/objects/node/attributes.rb +47 -0
  73. data/lib/objects/node/base.rb +248 -0
  74. data/lib/objects/node/cache_handler.rb +24 -0
  75. data/lib/objects/node/collection.rb +51 -0
  76. data/lib/objects/node/factory.rb +108 -0
  77. data/lib/objects/node/inventory/base.rb +88 -0
  78. data/lib/objects/node/inventory/defined.rb +112 -0
  79. data/lib/objects/node/inventory/subselect.rb +54 -0
  80. data/lib/objects/node/meta/base.rb +36 -0
  81. data/lib/objects/node/meta/cloud.rb +4 -0
  82. data/lib/objects/node/meta/local.rb +4 -0
  83. data/lib/objects/node/meta_data_factory.rb +23 -0
  84. data/lib/objects/node/meta_data_loader.rb +32 -0
  85. data/lib/objects/node/resources/base.rb +98 -0
  86. data/lib/objects/node/resources/inventory.rb +25 -0
  87. data/lib/objects/node/resources/sub_inventory.rb +56 -0
  88. data/lib/objects/node/server/base.rb +218 -0
  89. data/lib/objects/node/server/dynamic.rb +39 -0
  90. data/lib/objects/node/server/static.rb +31 -0
  91. data/lib/objects/orchestration/base.rb +13 -0
  92. data/lib/objects/orchestrator.rb +24 -0
  93. data/lib/objects/parser/bread_crumb.rb +31 -0
  94. data/lib/objects/progress_bar.rb +30 -0
  95. data/lib/objects/registry/arguments/base.rb +36 -0
  96. data/lib/objects/registry/arguments/command_line.rb +35 -0
  97. data/lib/objects/registry/arguments/console.rb +15 -0
  98. data/lib/objects/registry/command/base.rb +66 -0
  99. data/lib/objects/registry/command/external.rb +55 -0
  100. data/lib/objects/registry/command/group.rb +76 -0
  101. data/lib/objects/registry/command/internal.rb +34 -0
  102. data/lib/objects/registry/command_list.rb +33 -0
  103. data/lib/objects/registry/loader.rb +70 -0
  104. data/lib/objects/ssh/bootstrap.rb +19 -0
  105. data/lib/objects/ssh/command.rb +46 -0
  106. data/lib/objects/ssh/command_exec.rb +65 -0
  107. data/lib/objects/ssh/connection_handler.rb +101 -0
  108. data/lib/objects/ssh/driver.rb +204 -0
  109. data/lib/objects/ssh/proxy_data.rb +56 -0
  110. data/lib/objects/ssh/script_exec.rb +43 -0
  111. data/lib/objects/system/local.rb +30 -0
  112. data/lib/objects/workspace.rb +75 -0
  113. data/patches/irb.rb +20 -7
  114. data/patches/string.rb +75 -0
  115. data/patches/string_stylesheet.rb +61 -0
  116. metadata +175 -93
  117. data/bin/bcome-bash-setup +0 -18
  118. data/bin/bcome-setup +0 -43
  119. data/bin/boot.rb +0 -148
  120. data/bin/boot_no_shell.rb +0 -3
  121. data/filters/ec2_filter.rb +0 -12
  122. data/lib/bcome/version.rb +0 -3
  123. data/lib/become_object.rb +0 -111
  124. data/lib/boot.rb +0 -13
  125. data/lib/command.rb +0 -56
  126. data/lib/context_functions.rb +0 -65
  127. data/lib/filters/base.rb +0 -10
  128. data/lib/filters/ec2_filter.rb +0 -4
  129. data/lib/functions.rb +0 -70
  130. data/lib/helpers/command_helper.rb +0 -13
  131. data/lib/helpers/environment_ssh.rb +0 -122
  132. data/lib/helpers/fog_helper.rb +0 -108
  133. data/lib/helpers/instance_command.rb +0 -71
  134. data/lib/helpers/instance_ssh.rb +0 -83
  135. data/lib/helpers/selections.rb +0 -117
  136. data/lib/interactive/interactive_session_halt.rb +0 -4
  137. data/lib/interactive/session.rb +0 -44
  138. data/lib/interactive/session_item/base.rb +0 -30
  139. data/lib/interactive/session_item/transparent_ssh.rb +0 -133
  140. data/lib/nodes/base.rb +0 -60
  141. data/lib/nodes/environment.rb +0 -30
  142. data/lib/nodes/estate.rb +0 -44
  143. data/lib/nodes/instance.rb +0 -94
  144. data/lib/nodes/platform.rb +0 -17
  145. data/lib/nodes/view.rb +0 -31
  146. data/lib/object.rb +0 -21
  147. data/lib/orchestrator/command_group/base.rb +0 -56
  148. data/lib/orchestrator/command_group/custom.rb +0 -13
  149. data/lib/orchestrator/command_group/direct.rb +0 -53
  150. data/lib/orchestrator/direct_command/group.rb +0 -21
  151. data/lib/orchestrator/direct_command/instance.rb +0 -19
  152. data/lib/orchestrator/factory.rb +0 -38
  153. data/lib/orchestrator/loader.rb +0 -47
  154. data/lib/orchestrator/node_target/all.rb +0 -14
  155. data/lib/orchestrator/node_target/all_excluding_roles.rb +0 -14
  156. data/lib/orchestrator/node_target/all_with_roles.rb +0 -14
  157. data/lib/orchestrator/node_target/base.rb +0 -43
  158. data/lib/orchestrator/node_target/single.rb +0 -12
  159. data/lib/orchestrator/recipe.rb +0 -60
  160. data/lib/orchestrator/registry.rb +0 -37
  161. data/lib/orchestrator/validate_and_set.rb +0 -10
  162. data/lib/patches/string.rb +0 -86
  163. data/lib/progress_bar.rb +0 -31
  164. data/lib/render_irb.rb +0 -53
  165. data/lib/scp.rb +0 -40
  166. data/lib/ssh.rb +0 -51
  167. data/lib/stack/base.rb +0 -148
  168. data/lib/stack/environment.rb +0 -222
  169. data/lib/stack/estate.rb +0 -50
  170. data/lib/stack/instance.rb +0 -130
  171. data/lib/stack/platform.rb +0 -74
  172. data/lib/stack/view.rb +0 -56
  173. data/lib/workspace_context.rb +0 -40
@@ -1,14 +0,0 @@
1
- module ::Bcome::Orchestrator::NodeTarget
2
- class AllWithRoles < ::Bcome::Orchestrator::NodeTarget::Base
3
-
4
- def set_machines(machines)
5
- inclusion_roles = @selectors[:inclusion_roles]
6
- raise "No exclusion roles set for node target of type all_with_roles" unless inclusion_roles
7
-
8
- @node_selections = machines.select{|machine|
9
- inclusion_roles.include?(machine.role)
10
- }
11
- end
12
-
13
- end
14
- end
@@ -1,43 +0,0 @@
1
- module ::Bcome::Orchestrator::NodeTarget
2
- class Base
3
-
4
- class << self
5
- def new_of_type_from(json, machines)
6
- raise "Missing node target type in #{json.inspect}" unless json.has_key?(:type)
7
- raise "Invalid node target of type #{json[:type]} in #{json.inspect}" unless klass_for_type.keys.include?(json[:type])
8
- node_target = klass_for_type[json[:type]].new(json)
9
- node_target.set_machines(machines)
10
- return node_target
11
- end
12
-
13
- def klass_for_type
14
- {
15
- "single" => ::Bcome::Orchestrator::NodeTarget::Single,
16
- "all_excluding_roles" => ::Bcome::Orchestrator::NodeTarget::AllExcludingRoles,
17
- "all_with_roles" => ::Bcome::Orchestrator::NodeTarget::AllWithRoles
18
- }
19
- end
20
- end
21
-
22
- include ::Bcome::Orchestrator::ValidateAndSet
23
-
24
- attr_reader :node_selections, :target_key
25
-
26
- def initialize(json)
27
- validate_and_set(json) unless override_validate_and_set?
28
- end
29
-
30
- def override_validate_and_set?
31
- false
32
- end
33
-
34
- def json_attributes
35
- [:target_key, :selectors]
36
- end
37
-
38
- def set_machines(*params)
39
- raise "Override set_machines in derived types - each type has its own distinct selector, and is passed an array of machines available at the current bcome context."
40
- end
41
-
42
- end
43
- end
@@ -1,12 +0,0 @@
1
- module ::Bcome::Orchestrator::NodeTarget
2
- class Single < ::Bcome::Orchestrator::NodeTarget::Base
3
-
4
- def set_machines(machines)
5
- machine_role = @selectors[:role]
6
- raise "No machine role set for node target of type single" unless machine_role
7
- @node_selections = machines.select{|machine| machine.role == machine_role }
8
- raise "Multiple machines found with role #{machine_role}. Selection is ambiguous. Maybe you meant to use the 'all_with_roles' node_target type?" if @node_selections.size > 1
9
- end
10
-
11
- end
12
- end
@@ -1,60 +0,0 @@
1
- module ::Bcome::Orchestrator
2
- class Recipe
3
-
4
- class << self
5
- def execute!(params)
6
- raise "No recipe name provided" unless params && params.is_a?(Hash) && params[:name]
7
- recipe = by_identifier(params[:name])
8
- raise "No recipe found matching #{params[:name]}" unless recipe
9
- recipe.execute!
10
- return
11
- end
12
-
13
- def by_identifier(identifier, stack_level_instance)
14
- all_recipes = stack_level_instance.recipes
15
- return all_recipes.select{|recipe| recipe.recipe_identifier == identifier }.first
16
- end
17
-
18
- def as_menu_items(stack_level_instance)
19
- stack_level_instance.recipes.collect {|recipe| { :command => recipe.recipe_identifier, :description => recipe.description } }
20
- end
21
-
22
- end
23
-
24
- attr_reader :command_groups, :recipe_identifier, :description, :bootstrap
25
-
26
- include ::Bcome::Orchestrator::ValidateAndSet
27
-
28
- def initialize(json, node_targets, all_machines, direct_commands)
29
- validate_and_set(json)
30
- set_command_groups(json, node_targets, all_machines, direct_commands)
31
- end
32
-
33
- def json_attributes
34
- [:recipe_identifier, :description, :bootstrap]
35
- end
36
-
37
- def optional_json_attributes
38
- [:bootstrap]
39
- end
40
-
41
- def execute!(current_context_machines)
42
- @command_groups.each do |command_group|
43
- puts "\nExecuting command group".informational
44
- command_group.execute!(current_context_machines, as_bootstrap)
45
- puts "\n"
46
- end
47
- end
48
-
49
- def as_bootstrap
50
- bootstrap ? true : false
51
- end
52
-
53
- def set_command_groups(json, node_targets, all_machines, direct_commands)
54
- commands_json = json[:commands]
55
- raise "Expecting commands within an Orchestrator recipe as an Array" unless commands_json.is_a?(Array)
56
- @command_groups = ::Bcome::Orchestrator::Factory.create_command_groups_from_json(commands_json, node_targets, all_machines, direct_commands)
57
- end
58
-
59
- end
60
- end
@@ -1,37 +0,0 @@
1
- module Bcome::Orchestrator::Registry
2
-
3
- CONFIGS_PATH = "bcome/config/orchestration"
4
-
5
- def do_load_recipes
6
- return [] unless config_for_registry.any?
7
- ::Bcome::Orchestrator::Loader.new(machines, config_for_registry).recipes
8
- end
9
-
10
- def config_for_registry
11
- return [] unless has_registry_config?
12
-
13
- matching_keys = []
14
- recipe_registry.keys.each {|registry_key|
15
- matching_keys << registry_key if /^#{registry_key}$/.match(context_breadcrumb)
16
- }
17
-
18
- return matching_keys.collect{|registry_key| recipe_registry[registry_key] }.flatten
19
- end
20
-
21
- def recipe_registry
22
- load_recipe_registry
23
- end
24
-
25
- def load_recipe_registry
26
- return YAML.load_file(registry_configs_path)
27
- end
28
-
29
- def registry_configs_path
30
- "#{CONFIGS_PATH}/registry.yml"
31
- end
32
-
33
- def has_registry_config?
34
- File.exist?(registry_configs_path)
35
- end
36
-
37
- end
@@ -1,10 +0,0 @@
1
- module ::Bcome::Orchestrator::ValidateAndSet
2
-
3
- def validate_and_set(json)
4
- json_attributes.each{|attribute|
5
- raise "Missing attribute #{attribute} in #{json.inspect}" unless json.has_key?(attribute) if !json.has_key?(attribute) && !optional_json_attributes.include?(attribute)
6
- instance_variable_set("@#{attribute}".to_sym, json[attribute])
7
- }
8
- end
9
-
10
- end
@@ -1,86 +0,0 @@
1
- class String
2
-
3
- # with thanks to http://simianuprising.com/wp-content/uploads/2012/08/solarized-reference-horizontal.png
4
- def colour_codes
5
- {
6
- :yellow => "#b58900",
7
- :orange => "#cb4b16",
8
- :red => "#dc322f",
9
- :magenta => "#d33682",
10
- :violet => "#6c71c4",
11
- :blue => "#268bd2",
12
- :cyan => "#2aa198",
13
- :green => "#859900",
14
- :white => "#ffffff"
15
- }
16
- end
17
-
18
- def highlight_colour_codes
19
- {
20
- :yellow => "#002b36",
21
- :orange => "#073642",
22
- :red => "#586e75",
23
- :magenta => "#657b83",
24
- :violet => "#839496",
25
- :blue => "#93a1a1",
26
- :cyan => "#eee8d5",
27
- :green => "#fdf6e3"
28
- }
29
- end
30
-
31
- def colours
32
- {
33
- :informational => { :colour => :yellow },
34
- :failure => { :colour => :red },
35
- :success => { :colour => :green },
36
- :title => { :colour => :green },
37
- :command => { :colour => :cyan, :highlight => true },
38
- :danger => { :colour => :red },
39
- :warning => { :colour => :orange },
40
- :friendly => { :colour => :green },
41
- :menu_item_green => { :colour => :green },
42
- :menu_title_orange => { :colour => :orange, :highlight => true },
43
- :menu_item_orange => { :colour => :orange },
44
- :menu_title_green => { :colour => :green, :highlight => true },
45
- :menu_item_white => { :colour => :white },
46
- :menu_item_yellow => { :colour => :yellow },
47
- :menu_item_cyan => { :colour => :cyan },
48
- :selections => { :colour => :cyan },
49
- :menu_title_cyan => { :colour => :cyan, :highlight => true },
50
- :headsup => { :colour => :orange, :highlight => true },
51
- :menu_item_magenta => { :colour => :magenta },
52
- :cyan => { :colour => :cyan },
53
- :yellow => { :colour => :yellow },
54
- :orange => { :colour => :orange }
55
- }
56
- end
57
-
58
- def has_colour?(colour_key)
59
- colours.has_key?(colour_key)
60
- end
61
-
62
- def method_missing(method_sym, *arguments, &black)
63
- super unless has_colour?(method_sym)
64
- colour_data = colours[method_sym]
65
-
66
- colour = colour_codes[colour_data[:colour]]
67
-
68
- unless colour_data[:highlight]
69
- return Rainbow(self).color(colour)
70
- else
71
- coloured_string = Rainbow(self).color(colour)
72
- return "\e[1m#{coloured_string}\033[0m"
73
-
74
- #highlight_colour = highlight_colour_codes[colour_data[:colour]]
75
- #highlight_string = Rainbow(self).color(highlight_colour).bg(colour)
76
- return "\e[1m#{highlight_string}\033[0m"
77
- end
78
- end
79
-
80
- def swatch
81
- colours.each { |colour_key, colour_attributes|
82
- puts "#{colour_key} : #{send(colour_key)}"
83
- }
84
- end
85
-
86
- end
data/lib/progress_bar.rb DELETED
@@ -1,31 +0,0 @@
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/render_irb.rb DELETED
@@ -1,53 +0,0 @@
1
- class ::Bcome::RenderIrb
2
-
3
- def list_items(parent_collection, items)
4
- if !items || !items.any?
5
- print "\nNo active resource collections found.\n".headsup
6
- else
7
- print "\n\s"
8
- puts "#{parent_collection.to_s.menu_title_green}\n".menu_title_green
9
- items.sort_by {|item| item.identifier }.each do |item|
10
- puts "\t*/added".danger + "\n" if item.highlight?
11
- print item.do_describe
12
- end
13
- print "\n\s\sTo work on any given node, use the cd command e.g. cd #{items.first.identifier}\n\n"
14
- end
15
- end
16
-
17
- def menu(menu_items, stack_level_instance)
18
- menu_str = "\n\s#{"Basic Commands".menu_title_green}\n\n"
19
- menu_items.each_with_index do |item, index|
20
- menu_str += construct_menu_item_string(item, index, :menu_item_green)
21
- end
22
-
23
- recipe_menu_items = ::Bcome::Orchestrator::Recipe.as_menu_items(stack_level_instance)
24
- if recipe_menu_items.any?
25
- menu_str += "\n\s#{"Orchestration Menu".menu_title_orange}\n\n"
26
- recipe_menu_items.each_with_index do |item, index|
27
- menu_str += construct_menu_item_string(item, index, :menu_item_orange)
28
- end
29
- end
30
-
31
- menu_str += stack_level_instance.context_commands if stack_level_instance.context_commands
32
-
33
- menu_str += "\n\n"
34
- print menu_str
35
- return
36
- end
37
-
38
- def construct_menu_item_string(item, index, colour)
39
- command = item[:command]
40
- description = item[:description]
41
- usage = item[:usage]
42
- menu_str = "#{tab}#{index+1}. #{description}".send(colour) + "\n"
43
- menu_str += "#{tab}" + "Command: ".menu_item_cyan + "#{command}\n".menu_item_white
44
- menu_str += "#{tab}" + "Usage: ".menu_item_cyan + "#{usage}\n".menu_item_white if usage
45
- menu_str += "\n"
46
- return menu_str
47
- end
48
-
49
- def tab
50
- "\s\s\s"
51
- end
52
-
53
- end
data/lib/scp.rb DELETED
@@ -1,40 +0,0 @@
1
- class ::Bcome::Scp
2
-
3
- def initialize(proxy, node)
4
- @proxy = proxy
5
- @node = node
6
- end
7
-
8
- def download!(remote_path, local_path = @node.local_download_path)
9
- local("mkdir -p #{local_path}", true)
10
- ::Net::SCP.start(@node.ip_address, @node.ssh_user, { :proxy => @proxy, :keys => @node.keys, :paranoid => false }) do |scp|
11
- scp.download!(remote_path, local_path, { :recursive => true, :preserve => true, :verbose => true }) do |cha, name, received, total|
12
- pct = received / total.to_f
13
- cnt = ( 72 * pct ).ceil
14
- print "%-72s %.2f%%\r" % [ ("#" * cnt), ( pct * 100 ) ]
15
- end
16
- end
17
- puts "done: files copied to #{local_path}".informational
18
- end
19
-
20
- def upload!(files, remote_path)
21
- puts "scp> #{@node.identifier}".informational
22
- ::Net::SCP.start(@node.ip_address, @node.ssh_user, { :proxy => @proxy, :keys => @node.keys, :paranoid => false }) do |scp|
23
- files = files.is_a?(Array) ? files : [files]
24
- files.each do |local_path|
25
- name_old = ""
26
- scp.upload!(local_path, remote_path, { :recursive => true }) do |ch, name, sent, total|
27
- log_string = "#{name}: #{sent}/#{total}"
28
- if name_old == name
29
- STDOUT.write "\r#{log_string}"
30
- else
31
- STDOUT.write "\n\r#{log_string}"
32
- end
33
- name_old = name
34
- end
35
- end
36
- end
37
- puts # we don't control the output here, this moves us down a line:
38
- end
39
-
40
- end
data/lib/ssh.rb DELETED
@@ -1,51 +0,0 @@
1
- class ::Bcome::Ssh
2
-
3
- attr_reader :commands
4
-
5
- def initialize(commands)
6
- @commands = commands
7
- end
8
-
9
- def output_append(output_string)
10
- @output_string = "#{@output_string}#{output_string}"
11
- end
12
-
13
- def print_output
14
- print "#{@output_string}\n"
15
- end
16
-
17
- def execute!
18
- @commands.each do |command|
19
- instance = command.instance
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}")
24
- print_output
25
- end
26
- end
27
-
28
- def ssh_exec!(ssh, command)
29
- ssh.open_channel do |channel|
30
- channel.exec(command.command) do |ch, success|
31
- unless success
32
- abort "FAILED: couldn't execute command (ssh.channel.exec)"
33
- end
34
- channel.on_data do |ch,data|
35
- command.stdout +=data
36
- end
37
- channel.on_extended_data do |ch,type,data|
38
- command.stderr +=data
39
- end
40
- channel.on_request("exit-status") do |ch,data|
41
- command.exit_code = data.read_long
42
- end
43
- channel.on_request("exit-signal") do |ch, data|
44
- command.exit_signal = data.read_long
45
- end
46
- end
47
- end
48
- ssh.loop
49
- end
50
-
51
- end