Class: DTK::CLIRerouter
- Inherits:
-
Object
- Object
- DTK::CLIRerouter
- Defined in:
- lib/execute/cli_pure/cli_rerouter.rb
Constant Summary collapse
- ROUTER_DATA =
{ :service_module => [ { :regex => /service-module (?<service_module_id>[\w:\-]+) (?<method_name>stage) (?<assembly_id>[\w:\-]+) (?<instance_name>[\w:\-\.\:]+)/, :entity => 'assembly' }, { :regex => /service-module (?<service_module_id>[\w:\-]+) (?<method_name>deploy) (?<assembly_id>[\w:\-]+) (?<instance_name>[\w:\-\.\:]+)/ } ], :component_module => [ { :regex => /component-module (?<component_module_id>[\w:\-]+) (?<method_name>clone)/ } ], :service => [ { :regex => /service (?<service_id>[\w:\-]+) (?<method_name>set-attribute) (?<name>[\w:\-\.\:]+) (?<value>[\w:\-\.\:]+)/ }, { :regex => /service (?<service_id>[\w:\-]+) (?<method_name>converge)/ }, { :regex => /service (?<method_name>delete-and-destroy) (?<instance_name>[\w:\-]+)/ } ] }
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(entity_name, args) ⇒ CLIRerouter
constructor
A new instance of CLIRerouter.
- #run ⇒ Object
Constructor Details
#initialize(entity_name, args) ⇒ CLIRerouter
Returns a new instance of CLIRerouter.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/execute/cli_pure/cli_rerouter.rb', line 36 def initialize(entity_name, args) @cli_string = CLIRerouter.formulate_command_string(entity_name, args) @entity_name = CLIRerouter.norm(entity_name) ROUTER_DATA[@entity_name].each do |defintion| if match = @cli_string.match(defintion[:regex]) @method_name = CLIRerouter.norm(match[:method_name]) # sometimes we need to override entity @entity_name = defintion[:entity] if defintion[:entity] # we need to filter out IDs @entity_ids = match.names.collect { |k| k.to_s.end_with?('_id') ? { k => match[k] } : nil }.compact if @entity_ids.empty? # match 1 is method name, there is no id @args = match[2, match.size] else # match 1, 2 are id and method name rest are args @args = match[@entity_ids.size + 2, match.size] end break end end @conn = ::DTK::Client::Session.get_connection() exit if validate_connection(@conn) end |
Class Method Details
.is_candidate?(entity_name, args) ⇒ Boolean
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/execute/cli_pure/cli_rerouter.rb', line 81 def self.is_candidate?(entity_name, args) cli = formulate_command_string(entity_name, args) if definitions = ROUTER_DATA[norm(entity_name)] is_match = definitions.find { |d| cli.match(d[:regex]) } return true if is_match end return false end |
Instance Method Details
#run ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/execute/cli_pure/cli_rerouter.rb', line 66 def run new_context_params = DTK::Shell::ContextParams.new @entity_ids.each do |value_hash| key = value_hash.keys.first value = value_hash.values.first entity_name_of_param = key.gsub('_id', '') new_context_params.add_context_name_to_params(entity_name_of_param, entity_name_of_param, value) end new_context_params.method_arguments = @args new_context_params.pure_cli_mode = true DTK::Client::ContextRouter.routeTask(@entity_name, @method_name, new_context_params, @conn) end |