From 50d1846e482d81827d0e3e1b2f407d1ff1d41a6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Ram=C3=ADrez?= Date: Thu, 24 Apr 2025 14:00:56 +0200 Subject: [PATCH 1/2] B #-: Fixes onegate client vm update method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Aleix Ramírez --- appliances/scripts/net-99-report-ready | 31 +++------ .../src/etc/one-context.d/net-99-report-ready | 36 +--------- context-linux/src/usr/bin/onegate.rb | 65 +++++++++---------- 3 files changed, 41 insertions(+), 91 deletions(-) diff --git a/appliances/scripts/net-99-report-ready b/appliances/scripts/net-99-report-ready index b60ad38f..1e29daca 100644 --- a/appliances/scripts/net-99-report-ready +++ b/appliances/scripts/net-99-report-ready @@ -21,28 +21,15 @@ if [[ -x '/etc/one-appliance/service' ]]; then fi fi -### +if ! command -v onegate ; then + echo "ERROR: No way to signal READY=YES (onegate binary not found)" >&2 + exit 1 +fi > /dev/null # this will not drop the error message which goes to stderr -if which onegate >/dev/null 2>&1; then - if onegate vm update --data READY=YES; then - exit - fi -fi - -if which curl >/dev/null 2>&1; then - if curl -X PUT "$ONEGATE_ENDPOINT/vm" \ - --header "X-ONEGATE-TOKEN: $TOKENTXT" \ - --header "X-ONEGATE-VMID: $VMID" \ - -d READY=YES; then - exit - fi +if onegate vm update --data READY=YES; then + echo "Reported READY" + exit fi -if which wget >/dev/null 2>&1; then - if wget --method PUT "$ONEGATE_ENDPOINT/vm" \ - --header "X-ONEGATE-TOKEN: $TOKENTXT" \ - --header "X-ONEGATE-VMID: $VMID" \ - --body-data READY=YES; then - exit - fi -fi +echo "ERROR: Failed to report READY" >&2 +exit 1 diff --git a/context-linux/src/etc/one-context.d/net-99-report-ready b/context-linux/src/etc/one-context.d/net-99-report-ready index 2e75af0b..389ffc56 100755 --- a/context-linux/src/etc/one-context.d/net-99-report-ready +++ b/context-linux/src/etc/one-context.d/net-99-report-ready @@ -32,43 +32,13 @@ fi ### -if command -v curl ; then - _command=curl -elif command -v wget && ! wget --help 2>&1 | grep -q BusyBox; then - _command=wget -elif command -v onegate ; then - _command=onegate -else - echo "ERROR: No way to signal READY=YES (no usable binary)" >&2 +if ! command -v onegate ; then + echo "ERROR: No way to signal READY=YES (onegate binary not found)" >&2 exit 1 fi > /dev/null # this will not drop the error message which goes to stderr report_ready() { - case "$_command" in - curl) - curl -X "PUT" "${ONEGATE_ENDPOINT}/vm" \ - --header "X-ONEGATE-TOKEN: $TOKENTXT" \ - --header "X-ONEGATE-VMID: $VMID" \ - --max-time 10 \ - --insecure \ - -d "READY=YES" - ;; - wget) - wget --method=PUT "${ONEGATE_ENDPOINT}/vm" \ - --body-data="READY=YES" \ - --header "X-ONEGATE-TOKEN: $TOKENTXT" \ - --header "X-ONEGATE-VMID: $VMID" \ - --timeout=10 \ - --no-check-certificate - ;; - onegate) - if command -v timeout >/dev/null; then - timeout 10 onegate vm update --data "READY=YES" - else - onegate vm update --data "READY=YES" - fi - ;; - esac + onegate vm update --data "READY=YES" } is_base64() { diff --git a/context-linux/src/usr/bin/onegate.rb b/context-linux/src/usr/bin/onegate.rb index 019aef69..8b552595 100755 --- a/context-linux/src/usr/bin/onegate.rb +++ b/context-linux/src/usr/bin/onegate.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # -------------------------------------------------------------------------- # -# Copyright 2002-2022, OpenNebula Project, OpenNebula Systems # +# Copyright 2002-2025, OpenNebula Project, OpenNebula Systems # # # # Licensed under the Apache License, Version 2.0 (the "License"); you may # # not use this file except in compliance with the License. You may obtain # @@ -29,7 +29,7 @@ module CloudClient # OpenNebula version - VERSION = '6.6.1' + VERSION = '6.10.0' # ######################################################################### # Default location for the authentication file @@ -359,7 +359,8 @@ module Service 'DEPLOYING_NETS' => 11, 'UNDEPLOYING_NETS' => 12, 'FAILED_DEPLOYING_NETS' => 13, - 'FAILED_UNDEPLOYING_NETS' => 14 + 'FAILED_UNDEPLOYING_NETS' => 14, + 'HOLD' => 15 } STATE_STR = [ @@ -377,7 +378,8 @@ module Service 'DEPLOYING_NETS', 'UNDEPLOYING_NETS', 'FAILED_DEPLOYING_NETS', - 'FAILED_UNDEPLOYING_NETS' + 'FAILED_UNDEPLOYING_NETS', + 'HOLD' ] # Returns the string representation of the service state @@ -558,32 +560,26 @@ def self.print_key_value(key, value) def self.help_str return <<-EOT -Available commands - $ onegate vm show [VMID] [--json] - - $ onegate vm update [VMID] --data KEY=VALUE\\nKEY2=VALUE2 - - $ onegate vm update [VMID] --erase KEY - - $ onegate vm ACTION VMID - $ onegate resume [VMID] - $ onegate stop [VMID] - $ onegate suspend [VMID] - $ onegate terminate [VMID] [--hard] - $ onegate reboot [VMID] [--hard] - $ onegate poweroff [VMID] [--hard] - $ onegate resched [VMID] - $ onegate unresched [VMID] - $ onegate hold [VMID] - $ onegate release [VMID] - - $ onegate service show [--json][--extended] - - $ onegate service scale --role ROLE --cardinality CARDINALITY - - $ onegate vrouter show [--json] - - $ onegate vnet show VNETID [--json][--extended] +## COMMANDS + + * onegate vm show [VMID] [--json] + * onegate vm update [VMID] --data KEY=VALUE\\nKEY2=VALUE2 + * onegate vm update [VMID] --erase KEY + * onegate vm ACTION VMID + * onegate resume [VMID] + * onegate stop [VMID] + * onegate suspend [VMID] + * onegate terminate [VMID] [--hard] + * onegate reboot [VMID] [--hard] + * onegate poweroff [VMID] [--hard] + * onegate resched [VMID] + * onegate unresched [VMID] + * onegate hold [VMID] + * onegate release [VMID] + * 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 @@ -595,6 +591,7 @@ def self.help_str OptionParser.new do |opts| opts.on("-d", "--data DATA", "Data to be included in the VM") do |data| options[:data] = data + options[:type] = 1 end opts.on("-e", "--erase DATA", "Data to be removed from the VM") do |data| @@ -647,16 +644,12 @@ def self.help_str OneGate::VirtualMachine.print(json_hash) end when "update" - if !options[:data] && !options[:erase] + if !options[:data] && !options[:type] STDERR.puts 'You have to provide the data as a param (--data, --erase)' exit -1 end - if options[:type] - data = URI.encode_www_form(options) - else - data = options[:data] - end + data = URI.encode_www_form(options) if ARGV[2] response = client.put("/vms/" + ARGV[2], data) From 233a16bfca8cd39426b38bcb6c52079339352d19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Ram=C3=ADrez?= Date: Thu, 24 Apr 2025 16:39:09 +0200 Subject: [PATCH 2/2] B #-: Fixes vrouter onegate vm_update method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Aleix Ramírez --- appliances/VRouter/vrouter.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appliances/VRouter/vrouter.rb b/appliances/VRouter/vrouter.rb index 6550a1c7..c9b0a9e1 100644 --- a/appliances/VRouter/vrouter.rb +++ b/appliances/VRouter/vrouter.rb @@ -53,8 +53,9 @@ def vm_show(vmid = nil, keep_alive: false) def vm_update(data, vmid = nil, erase: false, keep_alive: false) path = vmid.nil? ? '/vm' : "/vms/#{vmid}" + type = erase ? 2 : 1 # 1 = update, 2 = delete_element -> https://github.com/OpenNebula/one-ee/blob/7299692415b6bdf9acb6e7789ec241e1b93adb59/src/onegate/onegate-server.rb#L589-L593 req = Net::HTTP::Put.new(path) - req.body = erase ? URI.encode_www_form('type' => 2, 'data' => data) : data + req.body = URI.encode_www_form('type' => type, 'data' => data) do_request req, keep_alive, expect_json: false end