All Projects → oVirt → go-ovirt

oVirt / go-ovirt

Licence: Apache-2.0 license
Go SDK Source-Code for oVirt 4.x, generated by ovirt/ovirt-engine-sdk-go.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-ovirt

ovirt-engine-sdk-go
The generator of Go SDK for oVirt v4.0+
Stars: ✭ 20 (-25.93%)
Mutual labels:  ovirt, ovirt-engine, ovirt-management
ovirt-ansible
Ansible playbooks for ovirt management
Stars: ✭ 26 (-3.7%)
Mutual labels:  ovirt-engine, ovirt-management
go-opendota
Go client library for accessing the OpenDota API
Stars: ✭ 34 (+25.93%)
Mutual labels:  go-library
ovirt-ansible-collection
Ansible collection with official oVirt modules and roles
Stars: ✭ 53 (+96.3%)
Mutual labels:  ovirt
connect
CLI tool and Go client library for the Kafka Connect REST API
Stars: ✭ 45 (+66.67%)
Mutual labels:  go-library
telegram
📚 Golang bindings for Telegram API
Stars: ✭ 15 (-44.44%)
Mutual labels:  go-library
ovirt-provider-ovn
This is a repository for ovirt-provider-ovn.
Stars: ✭ 19 (-29.63%)
Mutual labels:  ovirt
veryfi-go
Go module for communicating with the Veryfi OCR API
Stars: ✭ 18 (-33.33%)
Mutual labels:  go-library
moVirt
A mobile client for oVirt
Stars: ✭ 47 (+74.07%)
Mutual labels:  ovirt
echotron
An elegant and concurrent library for Telegram bots in Go.
Stars: ✭ 95 (+251.85%)
Mutual labels:  go-library
ovirt-site
oVirt website
Stars: ✭ 74 (+174.07%)
Mutual labels:  ovirt
fastget
⚡ A CLI tool and Go library to ultra fast download files over HTTP(S)
Stars: ✭ 25 (-7.41%)
Mutual labels:  go-library
go-httpheader
A Go library for encoding structs into Header fields.
Stars: ✭ 38 (+40.74%)
Mutual labels:  go-library
random
Random data generator AKA faker
Stars: ✭ 14 (-48.15%)
Mutual labels:  go-library
ovirt-web-ui
Modern lightweight UI for standard (non-admin) oVirt users
Stars: ✭ 87 (+222.22%)
Mutual labels:  ovirt
froggit-go
Froggit-Go is a universal Go library, allowing to perform actions on VCS providers.
Stars: ✭ 19 (-29.63%)
Mutual labels:  go-library
streams
Simple Go stream processor
Stars: ✭ 20 (-25.93%)
Mutual labels:  go-library
Goxygen
Generate a modern Web project with Go and Angular, React or Vue in seconds 🚀
Stars: ✭ 2,318 (+8485.19%)
Mutual labels:  go-library
ovirt-openshift-extensions
Implementation of flexvolume driver and provisioner for oVirt
Stars: ✭ 32 (+18.52%)
Mutual labels:  ovirt
terraform-provider-ovirt
Terraform provider for oVirt 4.x
Stars: ✭ 125 (+362.96%)
Mutual labels:  ovirt

oVirt Go SDK

Build Status Go Report Card

Introduction

The oVirt Go SDK is a Go package that simplifies access to the oVirt Engine API.

IMPORTANT: The code in this project is generated automatically by the oVirt/ovirt-engine-sdk-go. So if you want to know how to generate the code, please read the README.md in the oVirt/ovirt-engine-sdk-go repository instead.

Usage

To use the SDK you should import ovirtsdk package as follows:

import (
    ovirtsdk4 "github.com/ovirt/go-ovirt"
)

IMPORTANT: To make it easy to manage dependencies on stable go-ovirt releases, starting with go-ovirt 4.2.2, we will move to semantic versioning. If you are still using v4.0.x via importing gopkg.in/ovirt/go-ovirt.v4 or 4.2.1, we highly recommend you to update to 4.2.2 or above. In product environment, please NEVER adopt the master branch which will always be under heavy development.

That will give you access to all the classes of the SDK, and in particular to the Connection class. This is the entry point of the SDK, and gives you access to the root of the tree of services of the API:

import (
    "fmt"
    "time"
    ovirtsdk4 "github.com/ovirt/go-ovirt"
)

// Create the connection to the api server
inputRawURL := "https://10.1.111.229/ovirt-engine/api"
conn, err := ovirtsdk4.NewConnectionBuilder().
	URL(inputRawURL).
	Username("admin@internal").
	Password("qwer1234").
	Insecure(true).
	Compress(true).
	Timeout(time.Second * 10).
	Build()
if err != nil {
	t.Fatalf("Make connection failed, reason: %s", err.Error())
}

// Never forget to close connection
defer conn.Close()

There are two ways of using the SDK, one is calling regular functions, which should check if error returned, the other is calling functions prefixed with Must, which is short and chain-function calling supported.

Calling the regular functions is recommended, because it is more accurate for catching errors.

IMPORTANT: you should catch the panic errors by defining the recover-defer function.

Regular Recommended

import (
    "fmt"
    "time"
    ovirtsdk4 "github.com/ovirt/go-ovirt"
)

// Create the connection to the api server
inputRawURL := "https://10.1.111.229/ovirt-engine/api"
conn, err := ovirtsdk4.NewConnectionBuilder().
	URL(inputRawURL).
	Username("admin@internal").
	Password("qwer1234").
	Insecure(true).
	Compress(true).
	Timeout(time.Second * 10).
	Build()
if err != nil {
	t.Fatalf("Make connection failed, reason: %s", err.Error())
}

defer conn.Close()

// Get the reference to the "clusters" service
clustersService := conn.SystemService().ClustersService()

// Use the "list" method of the "clusters" service to list all the clusters of the system
clustersResponse, err := clustersService.List().Send()
if err != nil {
	fmt.Printf("Failed to get cluster list, reason: %v\n", err)
	return
}

if clusters, ok := clustersResponse.Clusters(); ok {
	// Print the datacenter names and identifiers
	fmt.Printf("Cluster: (")
	for _, cluster := range clusters.Slice() {
		if clusterName, ok := cluster.Name(); ok {
			fmt.Printf(" name: %v", clusterName)
		}
		if clusterId, ok := cluster.Id(); ok {
			fmt.Printf(" id: %v", clusterId)
		}
	}
	fmt.Println(")")
}

Must Not-Recommended

import (
    "fmt"
    "time"
    ovirtsdk4 "github.com/ovirt/go-ovirt"
)

// Create the connection to the api server
inputRawURL := "https://10.1.111.229/ovirt-engine/api"
conn, err := ovirtsdk4.NewConnectionBuilder().
	URL(inputRawURL).
	Username("admin@internal").
	Password("qwer1234").
	Insecure(true).
	Compress(true).
	Timeout(time.Second * 10).
	Build()
if err != nil {
	t.Fatalf("Make connection failed, reason: %s", err.Error())
}

defer conn.Close()

// To use `Must` methods, you should recover it if panics
defer func() {
	if err := recover(); err != nil {
		fmt.Printf("Panics occurs %v, try the non-Must methods to find the reason", err)
	}
}()

// Get the reference to the "clusters" service
clustersService := conn.SystemService().ClustersService()

// Use the "list" method of the "clusters" service to list all the clusters of the system
clustersResponse := clustersService.List().MustSend()

clusters := clustersResponse.MustClusters()

// Print the datacenter names and identifiers
fmt.Printf("Cluster: (")
for _, cluster := range clusters.Slice() {
	fmt.Printf(" name: %v", cluster.MustName())
	fmt.Printf(" id: %v", cluster.MustId())
}
fmt.Println(")")

More examples

You could refer to more examples under examples/ directory.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].