Skip to content

Commit c8563be

Browse files
committed
B #-: adds content-type:text/plain header in onegate requests
Signed-off-by: Aleix Ramírez <[email protected]>
1 parent 4f011fd commit c8563be

File tree

4 files changed

+44
-85
lines changed

4 files changed

+44
-85
lines changed

appliances/VRouter/vrouter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def initialize
1919
@uri = URI.parse(ENV['ONEGATE_ENDPOINT'])
2020
@vmid = ENV['VMID']
2121
@token = ENV['TOKENTXT']
22+
@req_content_type = 'text/plain'
2223

2324
@http = Net::HTTP.new(@uri.host, @uri.port)
2425
@http.use_ssl = @uri.scheme == 'https'
@@ -65,6 +66,7 @@ def do_request(req, keep_alive, expect_json: true)
6566

6667
req['X-ONEGATE-VMID'] = @vmid
6768
req['X-ONEGATE-TOKEN'] = @token
69+
req['Content-Type'] = @req_content_type
6870

6971
expect_json ? JSON.parse(@http.request(req).body) : @http.request(req).body
7072
rescue StandardError => e

appliances/scripts/net-99-report-ready

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,15 @@ if [[ -x '/etc/one-appliance/service' ]]; then
2121
fi
2222
fi
2323

24-
###
24+
if ! command -v onegate ; then
25+
echo "ERROR: No way to signal READY=YES (onegate binary not found)" >&2
26+
exit 1
27+
fi > /dev/null # this will not drop the error message which goes to stderr
2528

26-
if which onegate >/dev/null 2>&1; then
27-
if onegate vm update --data READY=YES; then
28-
exit
29-
fi
30-
fi
31-
32-
if which curl >/dev/null 2>&1; then
33-
if curl -X PUT "$ONEGATE_ENDPOINT/vm" \
34-
--header "X-ONEGATE-TOKEN: $TOKENTXT" \
35-
--header "X-ONEGATE-VMID: $VMID" \
36-
-d READY=YES; then
37-
exit
38-
fi
29+
if onegate vm update --data READY=YES; then
30+
echo "Reported READY"
31+
exit
3932
fi
4033

41-
if which wget >/dev/null 2>&1; then
42-
if wget --method PUT "$ONEGATE_ENDPOINT/vm" \
43-
--header "X-ONEGATE-TOKEN: $TOKENTXT" \
44-
--header "X-ONEGATE-VMID: $VMID" \
45-
--body-data READY=YES; then
46-
exit
47-
fi
48-
fi
34+
echo "ERROR: Failed to report READY" >&2
35+
exit 1

context-linux/src/etc/one-context.d/net-99-report-ready

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,43 +32,13 @@ fi
3232

3333
###
3434

35-
if command -v curl ; then
36-
_command=curl
37-
elif command -v wget && ! wget --help 2>&1 | grep -q BusyBox; then
38-
_command=wget
39-
elif command -v onegate ; then
40-
_command=onegate
41-
else
42-
echo "ERROR: No way to signal READY=YES (no usable binary)" >&2
35+
if ! command -v onegate ; then
36+
echo "ERROR: No way to signal READY=YES (onegate binary not found)" >&2
4337
exit 1
4438
fi > /dev/null # this will not drop the error message which goes to stderr
4539

4640
report_ready() {
47-
case "$_command" in
48-
curl)
49-
curl -X "PUT" "${ONEGATE_ENDPOINT}/vm" \
50-
--header "X-ONEGATE-TOKEN: $TOKENTXT" \
51-
--header "X-ONEGATE-VMID: $VMID" \
52-
--max-time 10 \
53-
--insecure \
54-
-d "READY=YES"
55-
;;
56-
wget)
57-
wget --method=PUT "${ONEGATE_ENDPOINT}/vm" \
58-
--body-data="READY=YES" \
59-
--header "X-ONEGATE-TOKEN: $TOKENTXT" \
60-
--header "X-ONEGATE-VMID: $VMID" \
61-
--timeout=10 \
62-
--no-check-certificate
63-
;;
64-
onegate)
65-
if command -v timeout >/dev/null; then
66-
timeout 10 onegate vm update --data "READY=YES"
67-
else
68-
onegate vm update --data "READY=YES"
69-
fi
70-
;;
71-
esac
41+
onegate vm update --data "READY=YES"
7242
}
7343

7444
is_base64() {

context-linux/src/usr/bin/onegate.rb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env ruby
22

33
# -------------------------------------------------------------------------- #
4-
# Copyright 2002-2022, OpenNebula Project, OpenNebula Systems #
4+
# Copyright 2002-2025, OpenNebula Project, OpenNebula Systems #
55
# #
66
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
77
# not use this file except in compliance with the License. You may obtain #
@@ -29,7 +29,7 @@
2929
module CloudClient
3030

3131
# OpenNebula version
32-
VERSION = '6.6.1'
32+
VERSION = '6.10.0'
3333

3434
# #########################################################################
3535
# Default location for the authentication file
@@ -359,7 +359,8 @@ module Service
359359
'DEPLOYING_NETS' => 11,
360360
'UNDEPLOYING_NETS' => 12,
361361
'FAILED_DEPLOYING_NETS' => 13,
362-
'FAILED_UNDEPLOYING_NETS' => 14
362+
'FAILED_UNDEPLOYING_NETS' => 14,
363+
'HOLD' => 15
363364
}
364365

365366
STATE_STR = [
@@ -377,7 +378,8 @@ module Service
377378
'DEPLOYING_NETS',
378379
'UNDEPLOYING_NETS',
379380
'FAILED_DEPLOYING_NETS',
380-
'FAILED_UNDEPLOYING_NETS'
381+
'FAILED_UNDEPLOYING_NETS',
382+
'HOLD'
381383
]
382384

383385
# Returns the string representation of the service state
@@ -448,6 +450,8 @@ def initialize(opts={})
448450
@user_agent = "OpenNebula #{CloudClient::VERSION} " <<
449451
"(#{opts[:user_agent]||"Ruby"})"
450452

453+
@req_content_type = opts[:req_content_type] || "text/plain"
454+
451455
@host = nil
452456
@port = nil
453457

@@ -505,6 +509,7 @@ def do_request(req)
505509
req['User-Agent'] = @user_agent
506510
req['X-ONEGATE-TOKEN'] = @token
507511
req['X-ONEGATE-VMID'] = @vmid
512+
req['Content-Type'] = @req_content_type
508513

509514
res = CloudClient::http_start(@uri, @timeout) do |http|
510515
http.request(req)
@@ -558,32 +563,26 @@ def self.print_key_value(key, value)
558563

559564
def self.help_str
560565
return <<-EOT
561-
Available commands
562-
$ onegate vm show [VMID] [--json]
563-
564-
$ onegate vm update [VMID] --data KEY=VALUE\\nKEY2=VALUE2
565-
566-
$ onegate vm update [VMID] --erase KEY
567-
568-
$ onegate vm ACTION VMID
569-
$ onegate resume [VMID]
570-
$ onegate stop [VMID]
571-
$ onegate suspend [VMID]
572-
$ onegate terminate [VMID] [--hard]
573-
$ onegate reboot [VMID] [--hard]
574-
$ onegate poweroff [VMID] [--hard]
575-
$ onegate resched [VMID]
576-
$ onegate unresched [VMID]
577-
$ onegate hold [VMID]
578-
$ onegate release [VMID]
579-
580-
$ onegate service show [--json][--extended]
581-
582-
$ onegate service scale --role ROLE --cardinality CARDINALITY
583-
584-
$ onegate vrouter show [--json]
585-
586-
$ onegate vnet show VNETID [--json][--extended]
566+
## COMMANDS
567+
568+
* onegate vm show [VMID] [--json]
569+
* onegate vm update [VMID] --data KEY=VALUE\\nKEY2=VALUE2
570+
* onegate vm update [VMID] --erase KEY
571+
* onegate vm ACTION VMID
572+
* onegate resume [VMID]
573+
* onegate stop [VMID]
574+
* onegate suspend [VMID]
575+
* onegate terminate [VMID] [--hard]
576+
* onegate reboot [VMID] [--hard]
577+
* onegate poweroff [VMID] [--hard]
578+
* onegate resched [VMID]
579+
* onegate unresched [VMID]
580+
* onegate hold [VMID]
581+
* onegate release [VMID]
582+
* onegate service show [--json][--extended]
583+
* onegate service scale --role ROLE --cardinality CARDINALITY
584+
* onegate vrouter show [--json]
585+
* onegate vnet show VNETID [--json][--extended]
587586
EOT
588587
end
589588
end
@@ -815,3 +814,4 @@ def self.help_str
815814
STDERR.puts OneGate.help_str
816815
exit -1
817816
end
817+

0 commit comments

Comments
 (0)