abh1sar commented on code in PR #11601:
URL: https://github.com/apache/cloudstack/pull/11601#discussion_r2343419308


##########
extensions/Proxmox/proxmox.sh:
##########
@@ -285,6 +285,88 @@ status() {
     echo "{\"status\": \"success\", \"power_state\": \"$powerstate\"}"
 }
 
+get_node_host() {
+   check_required_fields node
+   local net_json host
+
+   if ! net_json="$(call_proxmox_api GET "/nodes/${node}/network")"; then
+     echo ""
+     return 1
+   fi
+
+   # Prefer a static non-bridge IP
+   host="$(echo "$net_json" | jq -r '
+     .data
+     | map(select(
+         (.type // "") != "bridge" and
+         (.type // "") != "bond" and
+         (.method // "") == "static" and
+         ((.address // .cidr // "") != "")
+       ))
+     | map(.address // (.cidr | split("/")[0]))
+     | .[0] // empty
+   ' 2>/dev/null)"
+
+   # Fallback: first interface with a CIDR
+   if [[ -z "$host" ]]; then
+     host="$(echo "$net_json" | jq -r '
+       .data
+       | map(select((.cidr // "") != ""))
+       | map(.cidr | split("/")[0])
+       | .[0] // empty
+     ' 2>/dev/null)"
+   fi
+
+   echo "$host"
+ }
+
+ get_console() {
+   check_required_fields node vmid
+
+   # Request VNC proxy from Proxmox
+   local api_resp port ticket
+   if ! api_resp="$(call_proxmox_api POST 
"/nodes/${node}/qemu/${vmid}/vncproxy")"; then
+     jq -n --arg msg "API call failed for node=$node vmid=$vmid" \
+       '{status:"error", message:$msg, code:"API_CALL_FAILED"}'
+     return 1
+   fi
+
+   port="$(echo "$api_resp"   | jq -re '.data.port // empty' 2>/dev/null || 
true)"
+   ticket="$(echo "$api_resp" | jq -re '.data.ticket // empty' 2>/dev/null || 
true)"
+
+   if [[ -z "$port" || -z "$ticket" ]]; then
+     jq -n --arg msg "Proxmox response missing port/ticket" \
+       --arg raw "$api_resp" \
+       '{status:"error", message:$msg, code:"BAD_UPSTREAM_RESPONSE", 
upstream:$raw}'
+     return 1
+   fi
+
+   # Derive host from node’s network info
+   local host
+   host="$(get_node_host)"
+   if [[ -z "$host" ]]; then
+     jq -n --arg msg "Could not determine host IP for node $node" \
+       '{status:"error", message:$msg, code:"HOST_RESOLUTION_ERROR"}'
+     return 1
+   fi
+
+   # Success JSON to stdout
+   jq -n \
+     --arg host "$host" \
+     --arg port "$port" \
+     --arg password "$ticket" \
+     '{
+        status: "success",
+        message: "Console retrieved",
+        console: {
+          host: $host,

Review Comment:
   You're right. Ignore this comment please.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to