Created
December 17, 2020 13:10
-
-
Save jaapbrasser/2111c28f1e9f1be396b8419b2447d48b to your computer and use it in GitHub Desktop.
Go Code Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
nodeIp := "" | |
username := "" | |
password := "" | |
rubrik := rubrikcdm.Connect(nodeIp, username, password) | |
vmName := "JBRASSER-WIN" | |
objectType := "vmware" | |
timeOut := 30 | |
hostOS := "Windows10" | |
// Get VM Object ID | |
vmID, err := rubrik.ObjectID(vmName, objectType, timeOut, hostOS) | |
// Check for error conditions | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf(vmID) | |
// Create the API endpoint address based on VM ID | |
apiPath := fmt.Sprintf("/vmware/vm/%s", vmID) | |
fmt.Printf(apiPath) | |
// Send the GET request via API and save the response | |
vmInfo, err := rubrik.Get("v1", apiPath) | |
// Check for error conditions | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Loop through the API response and print desired values | |
for key, value := range vmInfo.(map[string]interface{}) { | |
switch t := value.(type) { | |
case string: | |
fmt.Printf("%v: %v\n", key, t) | |
case float64: | |
fmt.Printf("%v: %v\n", key, t) | |
case bool: | |
fmt.Printf("%v: %v\n", key, t) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment