Created
October 20, 2020 14:09
-
-
Save arso/1b4316cd5a6a069a0c5526fc330890f2 to your computer and use it in GitHub Desktop.
Sample ovirt go client
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
// USAGE: | |
//$ go build | |
//$ ./ovirt_go_client 'https://<ENGINE>/ovirt-engine/api' 'admin@internal' '<PASSWORD>' | |
package main | |
import ( | |
"fmt" | |
"os" | |
ovirtsdk4 "github.com/ovirt/go-ovirt" | |
) | |
func main() { | |
url := os.Args[1] | |
username := os.Args[2] | |
passwd := os.Args[3] | |
// Create the connection to the api server | |
conn, err := ovirtsdk4.NewConnectionBuilder(). | |
URL(url). | |
Username(username). | |
Password(passwd). | |
Insecure(true). | |
Build() | |
if err != nil { | |
fmt.Printf("Make connection failed, reason: %s", err.Error()) | |
} | |
testErr := conn.Test() | |
if testErr != nil { | |
fmt.Printf("Failed to test conn, reason: %v\n", testErr) | |
return | |
} | |
defer conn.Close() | |
// // UNCOMMENT THE CODE BELOW TO SEE THAT BESIDES Test() EVERYTHING ELSE WORKS | |
// // Get the reference to the "vms" service: | |
// vmsService := conn.SystemService().VmsService() | |
// // // Use the "list" method of the "vms" service to list all the virtual machines | |
// vmsResponse, err := vmsService.List().Send() | |
// if err != nil { | |
// fmt.Printf("Failed to get vm list, reason: %v\n", err) | |
// return | |
// } | |
// if vms, ok := vmsResponse.Vms(); ok { | |
// // Print the virtual machine names and identifiers: | |
// for _, vm := range vms.Slice() { | |
// fmt.Print("VM: (") | |
// if vmName, ok := vm.Name(); ok { | |
// fmt.Printf(" name: %v", vmName) | |
// } | |
// if vmID, ok := vm.Id(); ok { | |
// fmt.Printf(" id: %v", vmID) | |
// } | |
// fmt.Println(")") | |
// } | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment