vishesh92 commented on code in PR #284:
URL:
https://github.com/apache/cloudstack-terraform-provider/pull/284#discussion_r3086801022
##########
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:
I messed up while resolving the conflicts. @bhouse-nexthop can you please
fix this.
--
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]