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,30 @@
|
|
|
1
|
+
module Bcome
|
|
2
|
+
class ProgressBar
|
|
3
|
+
include Singleton
|
|
4
|
+
|
|
5
|
+
attr_reader :count
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
@count = 0
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def increment!
|
|
12
|
+
@count += 1
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def reset!
|
|
16
|
+
@count = 0
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def indicate(config, in_progress)
|
|
20
|
+
prefix = in_progress ? config[:prefix].progress : config[:prefix].progress
|
|
21
|
+
bar = prefix + "#{config[:indice] * @count}>" + " (#{@count} #{config[:indice_descriptor]})".progress + "\r"
|
|
22
|
+
print bar
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def indicate_and_increment!(config, in_progress)
|
|
26
|
+
increment!
|
|
27
|
+
indicate(config, in_progress)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Bcome::Registry::Arguments
|
|
2
|
+
class Base
|
|
3
|
+
attr_reader :arguments, :defaults, :processed_arguments, :merged_arguments
|
|
4
|
+
|
|
5
|
+
class << self
|
|
6
|
+
def process(arguments, defaults)
|
|
7
|
+
processor = new(arguments, defaults)
|
|
8
|
+
processor.do_process
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initialize(_arguments, defaults)
|
|
13
|
+
@defaults = defaults ? defaults : {}
|
|
14
|
+
validate
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def do_process
|
|
18
|
+
merge_arguments_with_defaults
|
|
19
|
+
@merged_arguments
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def merge_arguments_with_defaults
|
|
25
|
+
@merged_arguments = @defaults.symbolize_keys.merge(arguments_to_merge.symbolize_keys)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def arguments_to_merge
|
|
29
|
+
@arguments
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def validate
|
|
33
|
+
raise Bcome::Exception::InvalidRegistryArgumentType, 'invalid default registry argument format' unless @defaults.is_a?(Hash)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Bcome::Registry::Arguments
|
|
2
|
+
class CommandLine < Base
|
|
3
|
+
def initialize(arguments, defaults)
|
|
4
|
+
@arguments = arguments ? arguments : []
|
|
5
|
+
@processed_arguments = {}
|
|
6
|
+
super
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def do_process
|
|
10
|
+
parse_arguments
|
|
11
|
+
super
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def arguments_to_merge
|
|
15
|
+
@processed_arguments
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def parse_arguments
|
|
21
|
+
@arguments.each do |argument|
|
|
22
|
+
argument =~ /^(.+)=(.+)$/
|
|
23
|
+
raise Bcome::Exception::MalformedCommandLineArguments, argument unless Regexp.last_match(1) || Regexp.last_match(2)
|
|
24
|
+
key = Regexp.last_match(1).to_sym; value = Regexp.last_match(2)
|
|
25
|
+
raise Bcome::Exception::DuplicateCommandLineArgumentKey, "'#{key}'" if @processed_arguments.key?(key)
|
|
26
|
+
@processed_arguments[key] = value
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def validate
|
|
31
|
+
raise Bcome::Exception::InvalidRegistryArgumentType, 'invalid argument format' unless @arguments.is_a?(Array)
|
|
32
|
+
super
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Bcome::Registry::Arguments
|
|
2
|
+
class Console < Base
|
|
3
|
+
def initialize(arguments, defaults)
|
|
4
|
+
@arguments = arguments ? arguments : {}
|
|
5
|
+
super
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def validate
|
|
11
|
+
raise Bcome::Exception::InvalidRegistryArgumentType, 'invalid argument format' unless @arguments.is_a?(Hash)
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module Bcome::Registry::Command
|
|
2
|
+
class Base
|
|
3
|
+
class << self
|
|
4
|
+
def new_from_raw_command(data)
|
|
5
|
+
raise Bcome::Exception::InvalidContextCommand, "#{data.inspect} is missing key type" unless data[:type]
|
|
6
|
+
raise Bcome::Exception::InvalidContextCommand, "#{data.inspect} has invalid type '#{data[:type]}'" unless is_valid_type?(data[:type])
|
|
7
|
+
valid_types[data[:type].to_sym].new(data)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def is_valid_type?(type)
|
|
11
|
+
valid_types.keys.include?(type.to_sym)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def valid_types
|
|
15
|
+
{
|
|
16
|
+
external: ::Bcome::Registry::Command::External,
|
|
17
|
+
internal: ::Bcome::Registry::Command::Internal
|
|
18
|
+
}
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def initialize(data)
|
|
23
|
+
@data = data
|
|
24
|
+
@data[:defaults] = {} unless @data[:defaults]
|
|
25
|
+
validate
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def defaults
|
|
29
|
+
@data[:defaults]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def process_arguments(arguments)
|
|
33
|
+
merged_arguments = {}
|
|
34
|
+
|
|
35
|
+
if [Array, Hash].include?(arguments.class)
|
|
36
|
+
processor_klass = arguments.is_a?(Array) ? ::Bcome::Registry::Arguments::CommandLine : ::Bcome::Registry::Arguments::Console
|
|
37
|
+
merged_arguments = processor_klass.process(arguments, defaults)
|
|
38
|
+
elsif defaults
|
|
39
|
+
merged_arguments = defaults
|
|
40
|
+
end
|
|
41
|
+
merged_arguments
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def execute(*_params)
|
|
45
|
+
raise 'Should be overriden'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def expected_keys
|
|
49
|
+
%i[console_command group description]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def method_missing(method_sym, *arguments, &block)
|
|
53
|
+
@data.key?(method_sym) ? @data[method_sym] : super
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def validate
|
|
57
|
+
expected_keys.each do |key|
|
|
58
|
+
validation_error "#{@data.inspect} is missing key #{key}" unless @data.key?(key)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def validation_error(message)
|
|
63
|
+
raise Bcome::Exception::InvalidContextCommand, message
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
module Bcome::Registry::Command
|
|
2
|
+
class External < Base
|
|
3
|
+
# In which the bcome context is passed to an external call
|
|
4
|
+
|
|
5
|
+
def execute(node, arguments)
|
|
6
|
+
full_command = construct_full_command(node, arguments)
|
|
7
|
+
begin
|
|
8
|
+
puts "\n(external) > #{full_command}".bc_blue + "\n\n"
|
|
9
|
+
system(full_command)
|
|
10
|
+
rescue Interrupt
|
|
11
|
+
puts "\nExiting gracefully from interrupt\n".warning
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def construct_full_command(node, arguments)
|
|
16
|
+
substituted_command = construct_substituted_command(arguments)
|
|
17
|
+
namespaced_command = namespace_command(node, substituted_command)
|
|
18
|
+
namespaced_command
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def construct_substituted_command(arguments)
|
|
22
|
+
substituted_command = local_command.dup
|
|
23
|
+
merged_arguments = process_arguments(arguments)
|
|
24
|
+
|
|
25
|
+
local_command_substitutions.each do |substitution|
|
|
26
|
+
substitute_with = merged_arguments[substitution.to_sym]
|
|
27
|
+
unless substitute_with
|
|
28
|
+
error_message_suffix = "- missing '#{substitution}' from command '#{local_command}'"
|
|
29
|
+
raise Bcome::Exception::MissingArgumentForRegistryCommand, error_message_suffix
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
substituted_command.gsub!("%#{substitution}%", substitute_with)
|
|
33
|
+
end
|
|
34
|
+
substituted_command
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def namespace_command(node, command)
|
|
38
|
+
"#{command} bcome_context=\"#{node.keyed_namespace}\""
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def local_command_substitutions
|
|
42
|
+
local_command.scan(/%([^%]*)%/).flatten.uniq
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def expected_keys
|
|
46
|
+
super + [:local_command]
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def do_pretty_print
|
|
50
|
+
menu_str = super + "\n\s\s\s\slocal command:\s".resource_key + local_command.resource_value
|
|
51
|
+
menu_str += "\n\s\s\s\sdefaults:\s".resource_key + defaults.inspect.resource_value
|
|
52
|
+
menu_str + "\n\n"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
module Bcome::Registry::Command
|
|
2
|
+
class Group
|
|
3
|
+
def initialize(node)
|
|
4
|
+
@all_commands = {}
|
|
5
|
+
@node = node
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
attr_reader :all_commands
|
|
9
|
+
|
|
10
|
+
def <<(command)
|
|
11
|
+
all_commands[command.group] ? (all_commands[command.group] << command) : (all_commands[command.group] = [command])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def has_commands?
|
|
15
|
+
all_commands.keys.any?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def console_method_name_exists?(proposed_name)
|
|
19
|
+
user_registered_console_command_names.include?(proposed_name)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def user_registered_console_command_names
|
|
23
|
+
user_registered_console_commands.collect(&:console_command)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def user_registered_console_commands
|
|
27
|
+
all_commands.collect { |_group, commands| commands }.flatten
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def command_for_console_command_name(command_name)
|
|
31
|
+
user_registered_console_commands.select { |command| command.console_command.to_sym == command_name }.first
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def item_spacing(item)
|
|
35
|
+
"\s" * (menu_item_spacing_length - item.length)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def menu_item_spacing_length
|
|
39
|
+
16
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def tab_spacing
|
|
43
|
+
"\s" * 3
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def in_console_session?
|
|
47
|
+
::Bcome::System::Local.instance.in_console_session?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def pretty_print ## TODO - revisit. This is a mess
|
|
51
|
+
puts "\nRegistry commands".title + "\sfor #{@node.class} #{@node.keyed_namespace}".resource_value + "\n\n"
|
|
52
|
+
all_commands.sort.each do |group_name, commands|
|
|
53
|
+
puts tab_spacing + group_name.title + "\n\n"
|
|
54
|
+
commands.each do |command|
|
|
55
|
+
command_key = command.console_command
|
|
56
|
+
description = command.description
|
|
57
|
+
defaults = command.defaults
|
|
58
|
+
|
|
59
|
+
puts tab_spacing + command_key.resource_key + item_spacing(command_key) + description.resource_value
|
|
60
|
+
|
|
61
|
+
usage_string = in_console_session? ? command_key.to_s : "bcome #{@node.keyed_namespace.empty? ? '' : "#{@node.keyed_namespace}:"}#{command_key}"
|
|
62
|
+
puts tab_spacing + ("\s" * menu_item_spacing_length) + 'usage: '.instructional + usage_string
|
|
63
|
+
|
|
64
|
+
if defaults.keys.any?
|
|
65
|
+
defaults_usage = in_console_session? ? "\s\"#{defaults.collect { |key, _value| "#{key}=your-value" }.join(',')}\"" : "\s" + defaults.collect { |key, _value| "#{key}=your-value" }.join("\s")
|
|
66
|
+
puts tab_spacing + ("\s" * menu_item_spacing_length) + "defaults:\s".instructional + defaults.collect { |k, v| "#{k}=#{v}" }.join(', ')
|
|
67
|
+
puts tab_spacing + ("\s" * menu_item_spacing_length) + "override:\s".instructional + usage_string + defaults_usage
|
|
68
|
+
end
|
|
69
|
+
puts "\n"
|
|
70
|
+
end
|
|
71
|
+
puts "\n"
|
|
72
|
+
end
|
|
73
|
+
nil
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Bcome::Registry::Command
|
|
2
|
+
class Internal < Base
|
|
3
|
+
# In which the bcome context is an external (extended framework) call
|
|
4
|
+
|
|
5
|
+
def execute(node, arguments)
|
|
6
|
+
merged_arguments = process_arguments(arguments)
|
|
7
|
+
orchestrator = orch_klass.new(node, merged_arguments)
|
|
8
|
+
orchestrator.do_execute
|
|
9
|
+
rescue Interrupt
|
|
10
|
+
puts "\nExiting gracefully from interrupt\n".warning
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def validate(*params)
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def orch_klass
|
|
18
|
+
@orch_klass ||= do_constantize_orch_klass
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def do_constantize_orch_klass
|
|
22
|
+
klass_name = "Bcome::Orchestration::#{@data[:orch_klass]}"
|
|
23
|
+
begin
|
|
24
|
+
klass_name.constantize
|
|
25
|
+
rescue NameError
|
|
26
|
+
raise Bcome::Exception::CannotFindInternalRegistryKlass, "'#{@data[:console_command]}'. #{klass_name} does not exist. Make sure you've created this class inside your orchestration folder in bcome/orchestration"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def expected_keys
|
|
31
|
+
super + [:orch_klass]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Bcome::Registry
|
|
2
|
+
class CommandList
|
|
3
|
+
include Singleton
|
|
4
|
+
|
|
5
|
+
attr_reader :list
|
|
6
|
+
|
|
7
|
+
def initialize
|
|
8
|
+
@list = {}
|
|
9
|
+
@groups_for_nodes = {}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_group_for_node(node, group)
|
|
13
|
+
@groups_for_nodes[node.keyed_namespace] = group
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def group_for_node(node)
|
|
17
|
+
@groups_for_nodes[node.keyed_namespace]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def register(node, command_name)
|
|
21
|
+
@list[node.keyed_namespace] ? (@list[node.keyed_namespace] << command_name) : (@list[node.keyed_namespace] = [command_name])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def command_in_list?(node, command_name)
|
|
25
|
+
@list.key?(node.keyed_namespace) && @list[node.keyed_namespace].include?(command_name.to_sym)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def teardown!
|
|
29
|
+
@groups_for_nodes = {}
|
|
30
|
+
@list = {}
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Bcome::Registry
|
|
2
|
+
class Loader
|
|
3
|
+
include ::Singleton
|
|
4
|
+
|
|
5
|
+
FILE_PATH = 'bcome/registry.yml'.freeze
|
|
6
|
+
|
|
7
|
+
def data
|
|
8
|
+
@data ||= do_load
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def set_command_group_for_node(node)
|
|
12
|
+
if group_for_node = ::Bcome::Registry::CommandList.instance.group_for_node(node)
|
|
13
|
+
return group_for_node
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
command_group = init_new_command_group(node)
|
|
17
|
+
|
|
18
|
+
data.each do |key, commands|
|
|
19
|
+
begin
|
|
20
|
+
if /^#{key.to_s}$/.match(node.keyed_namespace)
|
|
21
|
+
commands.each do |c|
|
|
22
|
+
# Verify that the proposed user registered method does not conflict with either an existing method name, instance var, or other registry command name for this node
|
|
23
|
+
if node.is_node_level_method?(c[:console_command]) || command_group.console_method_name_exists?(c[:console_command])
|
|
24
|
+
raise Bcome::Exception::MethodNameConflictInRegistry, "'#{c[:console_command]}'"
|
|
25
|
+
end
|
|
26
|
+
command_group << ::Bcome::Registry::Command::Base.new_from_raw_command(c) unless restrict_config?(node, c)
|
|
27
|
+
::Bcome::Registry::CommandList.instance.register(node, c[:console_command].to_sym)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
rescue RegexpError => e
|
|
31
|
+
raise Bcome::Exception::InvalidRegexpMatcherInRegistry, e.message
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
::Bcome::Registry::CommandList.instance.add_group_for_node(node, command_group)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def init_new_command_group(node)
|
|
38
|
+
::Bcome::Registry::Command::Group.new(node)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def restrict_config?(node, command_config)
|
|
42
|
+
return false unless command_config.key?(:restrict_to_node)
|
|
43
|
+
node_klass_mapping = restriction_to_node_klass_mappings[command_config[:restrict_to_node].to_sym]
|
|
44
|
+
|
|
45
|
+
unless node_klass_mapping
|
|
46
|
+
raise Bcome::Exception::InvalidRestrictionKeyInRegistry, "'#{command_config[:restrict_to_node]}' is invalid. Valid keys: #{restriction_to_node_klass_mappings.keys.join(', ')}"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
!node.is_a?(node_klass_mapping)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def restriction_to_node_klass_mappings
|
|
53
|
+
{
|
|
54
|
+
server: ::Bcome::Node::Server::Base,
|
|
55
|
+
inventory: ::Bcome::Node::Inventory,
|
|
56
|
+
collection: ::Bcome::Node::Collection
|
|
57
|
+
}
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def do_load
|
|
61
|
+
return {} unless File.exist?(FILE_PATH)
|
|
62
|
+
begin
|
|
63
|
+
file_data = YAML.load_file(FILE_PATH).deep_symbolize_keys
|
|
64
|
+
rescue Psych::SyntaxError => e
|
|
65
|
+
raise Bcome::Exception::InvalidRegistryDataConfig, "Error: #{e.message}"
|
|
66
|
+
end
|
|
67
|
+
file_data
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|