Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
F OpenNebula/one#5112: Update OneGate client to 5.12.6 (EE)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlastimil Holer committed Oct 29, 2020
1 parent 38633f1 commit bdc853e
Showing 1 changed file with 116 additions and 20 deletions.
136 changes: 116 additions & 20 deletions src/usr/bin/onegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
module CloudClient

# OpenNebula version
VERSION = '5.11.80'
VERSION = '5.12.6'

# #########################################################################
# Default location for the authentication file
Expand Down Expand Up @@ -220,6 +220,7 @@ module VirtualMachine
DISK_RESIZE
DISK_RESIZE_POWEROFF
DISK_RESIZE_UNDEPLOYED
HOTPLUG_NIC_POWEROFF
}

SHORT_VM_STATES={
Expand Down Expand Up @@ -300,7 +301,8 @@ module VirtualMachine
"PROLOG_MIGRATE_UNKNOWN_FAILURE" => "fail",
"DISK_RESIZE" => "drsz",
"DISK_RESIZE_POWEROFF" => "drsz",
"DISK_RESIZE_UNDEPLOYED" => "drsz"
"DISK_RESIZE_UNDEPLOYED" => "drsz",
"HOTPLUG_NIC_POWEROFF" => "hotp"
}

def self.state_to_str(id, lcm_id)
Expand Down Expand Up @@ -392,6 +394,35 @@ def self.print(json_hash, extended = false)
end
end

# Virtual Router module
module VirtualRouter

def self.print(json_hash, _extended = false)
OneGate.print_header('VROUTER ' + json_hash['VROUTER']['ID'])
OneGate.print_key_value('NAME', json_hash['VROUTER']['NAME'])

vms_ids = Array(json_hash['VROUTER']['VMS']['ID'])

vms = vms_ids.join(',')

OneGate.print_key_value('VMS', vms)
puts
end

end

# Virtual Network module
module VirtualNetwork

def self.print(json_hash, _extended = false)
OneGate.print_header('VNET')
OneGate.print_key_value('ID', json_hash['VNET']['ID'])

puts
end

end

class Client
def initialize(opts={})
@vmid = ENV["VMID"]
Expand Down Expand Up @@ -471,8 +502,8 @@ def do_request(req)

def self.parse_json(response)
if CloudClient::is_error?(response)
puts "ERROR: "
puts response.message
STDERR.puts 'ERROR: '
STDERR.puts response.message
exit -1
else
return JSON.parse(response.body)
Expand Down Expand Up @@ -535,6 +566,10 @@ def self.help_str
$ onegate service show [--json][--extended]
$ onegate service scale --role ROLE --cardinality CARDINALITY
$ onegate vrouter show [--json]
$ onegate vnet show VNETID [--json][--extended]
EOT
end
end
Expand Down Expand Up @@ -574,7 +609,7 @@ def self.help_str
end

opts.on("-h", "--help", "Show this message") do
puts OneGate.help_str
STDERR.puts OneGate.help_str
exit
end
end.parse!
Expand All @@ -599,7 +634,7 @@ def self.help_str
end
when "update"
if !options[:data] && !options[:erase]
puts "You have to provide the data as a param (--data, --erase)"
STDERR.puts 'You have to provide the data as a param (--data, --erase)'
exit -1
end

Expand All @@ -616,8 +651,8 @@ def self.help_str
end

if CloudClient::is_error?(response)
puts "ERROR: "
puts response.message
STDERR.puts 'ERROR: '
STDERR.puts response.message
exit -1
end
when "resume",
Expand Down Expand Up @@ -647,18 +682,18 @@ def self.help_str
response = client.post("/vms/"+ARGV[2]+"/action", action_hash.to_json)

if CloudClient::is_error?(response)
puts "ERROR: "
puts response.message
STDERR.puts 'ERROR: '
STDERR.puts response.message
exit -1
end
else
puts "You have to provide a VM ID"
STDERR.puts 'You have to provide a VM ID'
exit -1
end
else
puts OneGate.help_str
puts
puts "Action #{ARGV[1]} not supported"
STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit -1
end
when "service"
Expand Down Expand Up @@ -691,18 +726,79 @@ def self.help_str
}.to_json)

if CloudClient::is_error?(response)
puts "ERROR: "
puts response.message
STDERR.puts 'ERROR: '
STDERR.puts response.message
exit -1
end
else
puts OneGate.help_str
puts
puts "Action #{ARGV[1]} not supported"
STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit -1
end
when 'vrouter'
case ARGV[1]
when 'show'
if options[:extended]
extra = {}
extra['extended'] = true

extra = URI.encode_www_form(extra)
end

response = client.get('/vrouter', extra)
json_hash = OneGate.parse_json(response)

if options[:json]
puts JSON.pretty_generate(json_hash)
else
if options[:extended]
OneGate::VirtualRouter.print(json_hash, true)
else
OneGate::VirtualRouter.print(json_hash)
end
end
else
STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit(-1)
end
when 'vnet'
case ARGV[1]
when 'show'
if ARGV[2]
if options[:extended]
extra = {}
extra['extended'] = true

extra = URI.encode_www_form(extra)
end

response = client.get('/vnet/'+ARGV[2], extra)
json_hash = OneGate.parse_json(response)

if options[:json]
puts JSON.pretty_generate(json_hash)
else
if options[:extended]
OneGate::VirtualNetwork.print(json_hash, true)
else
OneGate::VirtualNetwork.print(json_hash)
end
end
else
STDERR.puts 'You have to provide a VNET ID'
exit -1
end
else
STDERR.puts OneGate.help_str
STDERR.puts
STDERR.puts "Action #{ARGV[1]} not supported"
exit(-1)
end
else
puts OneGate.help_str
STDERR.puts OneGate.help_str
exit -1
end

0 comments on commit bdc853e

Please sign in to comment.