Class: Aspera::Cli::Plugins::Orchestrator
- Inherits:
-
BasicAuthPlugin
- Object
- Aspera::Cli::Plugin
- BasicAuthPlugin
- Aspera::Cli::Plugins::Orchestrator
- Defined in:
- lib/aspera/cli/plugins/orchestrator.rb
Constant Summary collapse
- STANDARD_PATH =
'/aspera/orchestrator'
- ACTIONS =
%i[health info workflow plugins processes].freeze
Constants inherited from Aspera::Cli::Plugin
Aspera::Cli::Plugin::ALL_OPS, Aspera::Cli::Plugin::GLOBAL_OPS, Aspera::Cli::Plugin::INIT_PARAMS, Aspera::Cli::Plugin::INSTANCE_OPS, Aspera::Cli::Plugin::MAX_ITEMS, Aspera::Cli::Plugin::MAX_PAGES, Aspera::Cli::Plugin::REGEX_LOOKUP_ID_BY_FIELD
Class Method Summary collapse
Instance Method Summary collapse
- #execute_action ⇒ Object
-
#initialize(**env) ⇒ Orchestrator
constructor
A new instance of Orchestrator.
Methods inherited from BasicAuthPlugin
#basic_auth_api, #basic_auth_params, declare_options
Methods inherited from Aspera::Cli::Plugin
declare_generic_options, #do_bulk_operation, #entity_action, #entity_command, #init_params, #instance_identifier, #query_option, #query_read_delete, #value_create_modify
Constructor Details
#initialize(**env) ⇒ Orchestrator
Returns a new instance of Orchestrator.
53 54 55 56 57 58 59 60 |
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 53 def initialize(**env) super .declare(:result, "Specify result value as: 'work_step:parameter'") .declare(:synchronous, 'Wait for completion', values: :bool, default: :no) .declare(:ret_style, 'How return type is requested in api', values: %i[header arg ext], default: :arg) .declare(:auth_style, 'Authentication type', values: %i[arg_pass head_basic apikey], default: :head_basic) . end |
Class Method Details
.detect(address_or_url) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 16 def detect(address_or_url) address_or_url = "https://#{address_or_url}" unless address_or_url.match?(%r{^[a-z]{1,6}://}) urls = [address_or_url] urls.push("#{address_or_url}#{STANDARD_PATH}") unless address_or_url.end_with?(STANDARD_PATH) error = nil urls.each do |base_url| next unless base_url.match?('https?://') api = Rest.new(base_url: base_url) test_endpoint = 'api/remote_node_ping' result = api.read(test_endpoint, {format: :json}) next unless result[:data]['remote_orchestrator_info'] url = result[:http].uri.to_s return { version: result[:data]['remote_orchestrator_info']['orchestrator-version'], url: url[0..url.index(test_endpoint) - 2] } rescue StandardError => e error = e Log.log.debug{"detect error: #{e}"} end raise error if error return nil end |
.wizard(object:, private_key_path: nil, pub_key_pem: nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 40 def wizard(object:, private_key_path: nil, pub_key_pem: nil) = object. return { preset_value: { url: .get_option(:url, mandatory: true), username: .get_option(:username, mandatory: true), password: .get_option(:password, mandatory: true) }, test_args: 'workflow list' } end |
Instance Method Details
#execute_action ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/aspera/cli/plugins/orchestrator.rb', line 99 def execute_action auth_params = case .get_option(:auth_style, mandatory: true) when :arg_pass { type: :url, url_query: { 'login' => .get_option(:username, mandatory: true), 'password' => .get_option(:password, mandatory: true) } } when :head_basic { type: :basic, username: .get_option(:username, mandatory: true), password: .get_option(:password, mandatory: true) } when :apikey raise 'Not implemented' end @api_orch = Rest.new( base_url: .get_option(:url, mandatory: true), auth: auth_params ) command1 = .get_next_command(ACTIONS) case command1 when :health nagios = Nagios.new begin info = call_ao('remote_node_ping', format: 'xml', xml_arrays: false)[:data] nagios.add_ok('api', 'accessible') nagios.check_product_version('api', 'orchestrator', info['orchestrator-version']) rescue StandardError => e nagios.add_critical('node api', e.to_s) end return nagios.result when :info result = call_ao('remote_node_ping', format: 'xml', xml_arrays: false)[:data] return {type: :single_object, data: result} when :processes # TODO: Bug ? API has only XML format result = call_ao('processes_status', format: 'xml')[:data] return {type: :object_list, data: result['process']} when :plugins # TODO: Bug ? only json format on url result = call_ao('plugin_version')[:data] return {type: :object_list, data: result['Plugin']} when :workflow command = .get_next_command(%i[list status inputs details start export]) unless [:list].include?(command) wf_id = instance_identifier end case command when :status wf_id = nil if wf_id.eql?(SpecialValues::ALL) result = call_ao('workflows_status', id: wf_id)[:data] return {type: :object_list, data: result['workflows']['workflow']} when :list result = call_ao('workflows_list', id: 0)[:data] return { type: :object_list, data: result['workflows']['workflow'], fields: %w[id portable_id name published_status published_revision_id latest_revision_id last_modification] } when :details result = call_ao('workflow_details', id: wf_id)[:data] return {type: :object_list, data: result['workflows']['workflow']['statuses']} when :inputs result = call_ao('workflow_inputs_spec', id: wf_id)[:data] return {type: :single_object, data: result['workflow_inputs_spec']} when :export result = call_ao('export_workflow', id: wf_id, format: nil)[:http] return {type: :text, data: result.body} when :start result = { type: :single_object, data: nil } call_params = {format: :json} # get external parameters if any .get_next_argument('external_parameters', mandatory: false, validation: Hash, default: {}).each do |name, value| call_params["external_parameters[#{name}]"] = value end # synchronous call ? call_params['synchronous'] = true if .get_option(:synchronous, mandatory: true) # expected result for synchro call ? result_location = .get_option(:result) unless result_location.nil? result[:type] = :status fields = result_location.split(':') raise Cli::BadArgument, "Expects: work_step:result_name : #{result_location}" if fields.length != 2 call_params['explicit_output_step'] = fields[0] call_params['explicit_output_variable'] = fields[1] # implicitly, call is synchronous call_params['synchronous'] = true end if call_params['synchronous'] result[:type] = :text end result[:data] = call_ao('initiate', id: wf_id, args: call_params)[:data] return result end else Aspera.error_unexpected_value(command) end end |