2929module CloudClient
3030
3131 # OpenNebula version
32- VERSION = '5.11.80 '
32+ VERSION = '5.12.6 '
3333
3434 # #########################################################################
3535 # Default location for the authentication file
@@ -220,6 +220,7 @@ module VirtualMachine
220220 DISK_RESIZE
221221 DISK_RESIZE_POWEROFF
222222 DISK_RESIZE_UNDEPLOYED
223+ HOTPLUG_NIC_POWEROFF
223224 }
224225
225226 SHORT_VM_STATES = {
@@ -300,7 +301,8 @@ module VirtualMachine
300301 "PROLOG_MIGRATE_UNKNOWN_FAILURE" => "fail" ,
301302 "DISK_RESIZE" => "drsz" ,
302303 "DISK_RESIZE_POWEROFF" => "drsz" ,
303- "DISK_RESIZE_UNDEPLOYED" => "drsz"
304+ "DISK_RESIZE_UNDEPLOYED" => "drsz" ,
305+ "HOTPLUG_NIC_POWEROFF" => "hotp"
304306 }
305307
306308 def self . state_to_str ( id , lcm_id )
@@ -392,6 +394,35 @@ def self.print(json_hash, extended = false)
392394 end
393395 end
394396
397+ # Virtual Router module
398+ module VirtualRouter
399+
400+ def self . print ( json_hash , _extended = false )
401+ OneGate . print_header ( 'VROUTER ' + json_hash [ 'VROUTER' ] [ 'ID' ] )
402+ OneGate . print_key_value ( 'NAME' , json_hash [ 'VROUTER' ] [ 'NAME' ] )
403+
404+ vms_ids = Array ( json_hash [ 'VROUTER' ] [ 'VMS' ] [ 'ID' ] )
405+
406+ vms = vms_ids . join ( ',' )
407+
408+ OneGate . print_key_value ( 'VMS' , vms )
409+ puts
410+ end
411+
412+ end
413+
414+ # Virtual Network module
415+ module VirtualNetwork
416+
417+ def self . print ( json_hash , _extended = false )
418+ OneGate . print_header ( 'VNET' )
419+ OneGate . print_key_value ( 'ID' , json_hash [ 'VNET' ] [ 'ID' ] )
420+
421+ puts
422+ end
423+
424+ end
425+
395426 class Client
396427 def initialize ( opts = { } )
397428 @vmid = ENV [ "VMID" ]
@@ -471,8 +502,8 @@ def do_request(req)
471502
472503 def self . parse_json ( response )
473504 if CloudClient ::is_error? ( response )
474- puts " ERROR: "
475- puts response . message
505+ STDERR . puts ' ERROR: '
506+ STDERR . puts response . message
476507 exit -1
477508 else
478509 return JSON . parse ( response . body )
@@ -535,6 +566,10 @@ def self.help_str
535566 $ onegate service show [--json][--extended]
536567
537568 $ onegate service scale --role ROLE --cardinality CARDINALITY
569+
570+ $ onegate vrouter show [--json]
571+
572+ $ onegate vnet show VNETID [--json][--extended]
538573EOT
539574 end
540575end
@@ -574,7 +609,7 @@ def self.help_str
574609 end
575610
576611 opts . on ( "-h" , "--help" , "Show this message" ) do
577- puts OneGate . help_str
612+ STDERR . puts OneGate . help_str
578613 exit
579614 end
580615end . parse!
@@ -599,7 +634,7 @@ def self.help_str
599634 end
600635 when "update"
601636 if !options [ :data ] && !options [ :erase ]
602- puts " You have to provide the data as a param (--data, --erase)"
637+ STDERR . puts ' You have to provide the data as a param (--data, --erase)'
603638 exit -1
604639 end
605640
@@ -616,8 +651,8 @@ def self.help_str
616651 end
617652
618653 if CloudClient ::is_error? ( response )
619- puts " ERROR: "
620- puts response . message
654+ STDERR . puts ' ERROR: '
655+ STDERR . puts response . message
621656 exit -1
622657 end
623658 when "resume" ,
@@ -647,18 +682,18 @@ def self.help_str
647682 response = client . post ( "/vms/" +ARGV [ 2 ] +"/action" , action_hash . to_json )
648683
649684 if CloudClient ::is_error? ( response )
650- puts " ERROR: "
651- puts response . message
685+ STDERR . puts ' ERROR: '
686+ STDERR . puts response . message
652687 exit -1
653688 end
654689 else
655- puts " You have to provide a VM ID"
690+ STDERR . puts ' You have to provide a VM ID'
656691 exit -1
657692 end
658693 else
659- puts OneGate . help_str
660- puts
661- puts "Action #{ ARGV [ 1 ] } not supported"
694+ STDERR . puts OneGate . help_str
695+ STDERR . puts
696+ STDERR . puts "Action #{ ARGV [ 1 ] } not supported"
662697 exit -1
663698 end
664699when "service"
@@ -691,18 +726,79 @@ def self.help_str
691726 } . to_json )
692727
693728 if CloudClient ::is_error? ( response )
694- puts " ERROR: "
695- puts response . message
729+ STDERR . puts ' ERROR: '
730+ STDERR . puts response . message
696731 exit -1
697732 end
698733 else
699- puts OneGate . help_str
700- puts
701- puts "Action #{ ARGV [ 1 ] } not supported"
734+ STDERR . puts OneGate . help_str
735+ STDERR . puts
736+ STDERR . puts "Action #{ ARGV [ 1 ] } not supported"
702737 exit -1
703738 end
739+ when 'vrouter'
740+ case ARGV [ 1 ]
741+ when 'show'
742+ if options [ :extended ]
743+ extra = { }
744+ extra [ 'extended' ] = true
745+
746+ extra = URI . encode_www_form ( extra )
747+ end
748+
749+ response = client . get ( '/vrouter' , extra )
750+ json_hash = OneGate . parse_json ( response )
751+
752+ if options [ :json ]
753+ puts JSON . pretty_generate ( json_hash )
754+ else
755+ if options [ :extended ]
756+ OneGate ::VirtualRouter . print ( json_hash , true )
757+ else
758+ OneGate ::VirtualRouter . print ( json_hash )
759+ end
760+ end
761+ else
762+ STDERR . puts OneGate . help_str
763+ STDERR . puts
764+ STDERR . puts "Action #{ ARGV [ 1 ] } not supported"
765+ exit ( -1 )
766+ end
767+ when 'vnet'
768+ case ARGV [ 1 ]
769+ when 'show'
770+ if ARGV [ 2 ]
771+ if options [ :extended ]
772+ extra = { }
773+ extra [ 'extended' ] = true
774+
775+ extra = URI . encode_www_form ( extra )
776+ end
777+
778+ response = client . get ( '/vnet/' +ARGV [ 2 ] , extra )
779+ json_hash = OneGate . parse_json ( response )
780+
781+ if options [ :json ]
782+ puts JSON . pretty_generate ( json_hash )
783+ else
784+ if options [ :extended ]
785+ OneGate ::VirtualNetwork . print ( json_hash , true )
786+ else
787+ OneGate ::VirtualNetwork . print ( json_hash )
788+ end
789+ end
790+ else
791+ STDERR . puts 'You have to provide a VNET ID'
792+ exit -1
793+ end
794+ else
795+ STDERR . puts OneGate . help_str
796+ STDERR . puts
797+ STDERR . puts "Action #{ ARGV [ 1 ] } not supported"
798+ exit ( -1 )
799+ end
704800else
705- puts OneGate . help_str
801+ STDERR . puts OneGate . help_str
706802 exit -1
707803end
708804
0 commit comments