You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/04/15 13:23:40 UTC

Re: [PR] Add nexthop parameter to cloudstack_static_route resource [cloudstack-terraform-provider]

Copilot commented on code in PR #284:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/284#discussion_r3086778306


##########
cloudstack/provider_test.go:
##########
@@ -147,6 +150,91 @@ func testAccPreCheck(t *testing.T) {
 	}
 }
 
+// parseCloudStackVersion parses a CloudStack version string (e.g., "4.22.0.0")
+// and returns a numeric value for comparison (e.g., 4.22 -> 4022).
+// The numeric value is calculated as: major * 1000 + minor.
+// Returns 0 if the version string cannot be parsed.
+func parseCloudStackVersion(version string) int {
+	parts := strings.Split(version, ".")
+	if len(parts) < 2 {
+		return 0
+	}
+
+	major := 0
+	minor := 0
+
+	// Parse major version - extract first numeric part
+	majorStr := regexp.MustCompile(`^\d+`).FindString(parts[0])
+	if majorStr != "" {
+		major, _ = strconv.Atoi(majorStr)
+	}
+
+	// Parse minor version - extract first numeric part
+	minorStr := regexp.MustCompile(`^\d+`).FindString(parts[1])
+	if minorStr != "" {
+		minor, _ = strconv.Atoi(minorStr)
+	}
+
+	return major*1000 + minor
+}
+
+// getCloudStackVersion retrieves the CloudStack version from the API.
+// Returns the version string and any error encountered.
+func getCloudStackVersion(cs *cloudstack.CloudStackClient) (string, error) {
+	p := cs.Configuration.NewListCapabilitiesParams()
+	caps, err := cs.Configuration.ListCapabilities(p)
+	if err != nil {
+		return "", err
+	}
+
+	if caps != nil && caps.Capabilities != nil && caps.Capabilities.Cloudstackversion != "" {
+		return caps.Capabilities.Cloudstackversion, nil
+	}
+
+	return "", fmt.Errorf("unable to determine CloudStack version")
+}

Review Comment:
   `getCloudStackVersion` is declared here with signature `(cs *cloudstack.CloudStackClient) (string, error)`, but the same file already defines `getCloudStackVersion(t *testing.T) string` further down. Go doesn't support function overloading, so this will not compile. Rename this new helper (e.g., `getCloudStackVersionFromClient`) or reuse the existing `newTestClient` + `getCloudStackVersion(t)` helpers for the nexthop precheck.



-- 
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: dev-unsubscribe@cloudstack.apache.org

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