Go OpenNebula Cloud API

This page contains the OpenNebula Cloud API Specification for Go. It has been designed as a wrapper for the XML-RPC methods, with some basic helpers. This means that you should be familiar with the XML-RPC API and the XML formats returned by the OpenNebula core. As stated in the XML-RPC documentation, you can download the XML Schemas (XSD) here.

Go OpenNebula Cloud API covers the resources lists below:

ResourceURL
ACLacl.go
Clustercluster.go
Datastoredatastore.go
Documentdocument.go
Groupgroup.go
Hosthost.go
Hookhook.go
Imageimage.go
Market Placemarketplace.go
Market Place Appmarketplaceapp.go
Templatetemplate.go
Security Groupservice_template.go
Serviceservice.go
Service Templateservice_template.go
Useruser.go
VDCvdc.go
Vnetvirtualnetwork.go
Vroutervirtualrouter.go
VMsvm.go
VM Groupsvmgroup.go
VN templatevntemplate.go
Zonezone.go

Download

The source code can be downloaded from the OpenNebula repository.

Usage

To use the OpenNebula Cloud API for Go in your Go project, you have to import GOCA into your project as the example below and make a go get.

Code Sample

The example below shows how to poweroff a running VM. You need to pass the VM ID argument to the program:

package main

import (
    "fmt"
    "log"
    "os"
    "strconv"

    "github.com/OpenNebula/one/src/oca/go/src/goca"
)

func main() {
    // Initialize connection with OpenNebula
    con := map[string]string{
        "user":     "user",
        "password": "password",
        "endpoint": "XMLRPC address",
    }

    client := goca.NewDefaultClient(
        goca.NewConfig(con["user"], con["password"], con["endpoint"]),
    )

    controller := goca.NewController(client)

    // Read VM ID from arguments
    id, _ := strconv.Atoi(os.Args[1])

    vmctrl := controller.VM(id)

    // Fetch informations of the created VM
    vm, err := vmctrl.Info(false)

    if err != nil {
        log.Fatal(err)
    }

    fmt.Printf("Shutting down %+v\n", vm.Name)

    // Poweroff the VM
    err = vmctrl.Poweroff()
    if err != nil {
        log.Fatal(err)
    }

}

Take a look at these examples in order to get a more in-depth usage of GOCA.

Error handling

In the file errors.go, two errors types are defined:

  • ClientError: errors on client side implying that we can’t have a complete and well formed OpenNebula response (request building, network errors …).
  • ResponseError: We have a well formed response, but there is an OpenNebula error (resource does not exist, can’t perform the action, rights problems …).

Each of theses types has several error codes allowing you fine-grained error handling. If we have an HTTP response, ClientError returns it.

Extend the client

The provided client is a basic XML-RPC client for OpenNebula, without any complex features. It’s possible to use another client or enhance the basic client with Goca if it implements the RPCCaller interface.