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 cover the resources lists below:

Resource

URL

ACL

acl.go

Cluster

cluster.go

Datastore

datastore.go

Document

document.go

Group

group.go

Host

host.go

Hook

hook.go

Image

image.go

Market Place

marketplace.go

Market Place App

marketplaceapp.go

Template

template.go

Security Group

service_template.go

Service

service.go

Service Template

service_template.go

User

user.go

VDC

vdc.go

Vnet

virtualnetwork.go

Vrouter

virtualrouter.go

VMs

vm.go

VM Groups

vmgroup.go

VN template

vntemplate.go

Zone

zone.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 at 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 exists, 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.