module Service
Constants
- DEFAULT_OPTIONS
CLI options
- FORCE
- JSON_FORMAT
- NUMBER
- PERIOD
- STATE
- STATE_STR
- TOP
Public Class Methods
build_json_action(perform, params=nil)
click to toggle source
Build a json specifying an action @param [String] perform action to be performed (i.e: shutdowm) @param [Hash, nil] params contains the params for the action @return [String] json representing the action
# File lib/opennebula/oneflow_client.rb, line 121 def self.build_json_action(perform, params=nil) body = Hash.new body['perform'] = perform body['params'] = params if params action = Hash.new action['action'] = body JSON.pretty_generate action end
list_to_id(names, poolname)
click to toggle source
# File lib/opennebula/oneflow_client.rb, line 243 def self.list_to_id(names, poolname) client = Service::Client.new() resource_path = case poolname when "SERVICE" then "/service" when "SERVICE TEMPLATE" then "/service_template" end response = client.get(resource_path) if CloudClient::is_error?(response) return -1, "OpenNebula #{poolname} name not found," << " use the ID instead" end pool = JSON.parse(response.body) result = names.split(',').collect { |name| if name.match(/^[0123456789]+$/) name.to_i else rc = name_to_id(name, pool, poolname) if rc.first == -1 return rc[0], rc[1] end rc[1] end } return 0, result end
list_to_id_desc(poolname)
click to toggle source
# File lib/opennebula/oneflow_client.rb, line 278 def self.list_to_id_desc(poolname) "Comma-separated list of OpenNebula #{poolname} names or ids" end
name_to_id(name, pool, ename)
click to toggle source
# File lib/opennebula/oneflow_client.rb, line 223 def self.name_to_id(name, pool, ename) if pool['DOCUMENT_POOL']['DOCUMENT'].nil? return -1, "#{ename} named #{name} not found." end objects = pool['DOCUMENT_POOL']['DOCUMENT'].select {|object| object['NAME'] == name } if objects.length>0 if objects.length>1 return -1, "There are multiple #{ename}s with name #{name}." else result = objects.first['ID'] end else return -1, "#{ename} named #{name} not found." end return 0, result end
perform_actions(ids, &block)
click to toggle source
Perform an action on several resources @param [Array] ids resources ids @param [Block] block action to be performed @return [Integer] exit_code
# File lib/opennebula/oneflow_client.rb, line 286 def self.perform_actions(ids, &block) exit_code = 0 ids.each do |id| response = block.call(id) if CloudClient::is_error?(response) puts response.to_s exit_code = response.code.to_i end end exit_code end
rname_to_id(name, poolname)
click to toggle source
def self.rname_to_id(name, poolname, options)
# File lib/opennebula/oneflow_client.rb, line 198 def self.rname_to_id(name, poolname) return 0, name.to_i if name.match(/^[0123456789]+$/) client = Service::Client.new() resource_path = case poolname when "SERVICE" then "/service" when "SERVICE TEMPLATE" then "/service_template" end response = client.get(resource_path) if CloudClient::is_error?(response) return -1, "OpenNebula #{poolname} name not found," << " use the ID instead" end pool = JSON.parse(response.body) name_to_id(name, pool, poolname) end
rname_to_id_desc(poolname)
click to toggle source
# File lib/opennebula/oneflow_client.rb, line 219 def self.rname_to_id_desc(poolname) "OpenNebula #{poolname} name or id" end
state_str(state_number)
click to toggle source
Returns the string representation of the service state @param [String] state String number representing the state @return the state string
# File lib/opennebula/oneflow_client.rb, line 113 def self.state_str(state_number) return STATE_STR[state_number.to_i] end