Copilot commented on code in PR #13832:
URL: https://github.com/apache/cloudstack/pull/13832#discussion_r3765642485


##########
extensions/Proxmox/proxmox.py:
##########
@@ -0,0 +1,701 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+import datetime as _dt
+import json
+import re
+import ssl
+import sys
+import time
+from dataclasses import dataclass
+from pathlib import Path
+from typing import Any
+from urllib import error, parse, request
+
+DEFAULT_WAIT_SECONDS = 600
+PROXMOX_API_PREFIX = "/api2/json"
+VM_NAME_PATTERN = re.compile(r"^[a-zA-Z0-9-]+$")
+
+
+class ProxmoxError(RuntimeError):
+    """Raised when the Proxmox API or payload validation fails."""
+
+
+def fail(message: str) -> None:
+    print(json.dumps({"status": "error", "error": message}))
+    raise SystemExit(1)
+
+
+def succeed(data: dict[str, Any]) -> None:
+    print(json.dumps(data))
+    raise SystemExit(0)
+
+
+def _is_mapping(value: Any) -> bool:
+    return isinstance(value, dict)
+
+
+def _mapping(value: Any) -> dict[str, Any]:
+    return value if isinstance(value, dict) else {}
+
+
+def _string(value: Any, default: str = "") -> str:
+    if value is None:
+        return default
+    if isinstance(value, str):
+        return value
+    return str(value)
+
+
+def _bool_text(value: Any, default: bool = False) -> bool:
+    if value is None:
+        return default
+    if isinstance(value, bool):
+        return value
+    return _string(value).strip().lower() in {"1", "true", "yes", "on"}
+
+
+def _int_text(value: Any, default: int = 0) -> int:
+    if value is None or value == "":
+        return default
+    try:
+        return int(value)
+    except (TypeError, ValueError):
+        return default
+
+
+def _normalize_url(url: str) -> str:
+    url = url.strip()
+    if not url.startswith(("http://";, "https://";)):
+        url = "https://"; + url
+    return url.rstrip("/")

Review Comment:
   The previous implementation always called the Proxmox API on port 8006 
("https://${url}:8006/...";). call_api() now uses self.data.url as-is, so a 
typical host value like "pve.example.com" will produce 
"https://pve.example.com/api2/json..."; and fail. Consider normalizing the base 
URL to include :8006 when no port is provided.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to