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
Image image.go
Template template.go
User user.go
VDC vdc.go
Vnet virtualnetwork.go
VMs vm.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 show how get the information of a running VM, print its name, and power it off. It then builds a new OpenNebula template and prints its string representation.

package main

import (
    "fmt"
    "github.com/OpenNebula/one/src/oca/go/src/goca"
    "log"
    "os"
    "strconv"
)

func main() {
    id, _ := strconv.Atoi(os.Args[1])

    vm := goca.NewVM(uint(id))

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

    name, _ := vm.XPath("/VM/NAME")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(name)

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

    // Create a new Template
    template := goca.NewTemplateBuilder()

    template.AddValue("cpu", 1)
    template.AddValue("memory", "64")
    vector := template.NewVector("disk")
    vector.AddValue("image_id", "119")
    vector.AddValue("dev_prefix", "vd")
    vector = template.NewVector("nic")
    vector.AddValue("network_id", "3")
    vector.AddValue("model", "virtio")
    template.AddValue("vcpu", "2")

    fmt.Println(template)
}

Limitations

Go OpenNebula Cloud API doesn’t cover the resources list below:

Resource URL
Marketplace http://docs.opennebula.org/5.8/integration/system_interfaces/api.html#onemarket
Marketapp http://docs.opennebula.org/5.8/integration/system_interfaces/api.html#onemarketapp
Security Groups http://docs.opennebula.org/5.8/integration/system_interfaces/api.html#onesecgroup
VM Groups http://docs.opennebula.org/5.8/integration/system_interfaces/api.html#onevmgroup
Virtual Router http://docs.opennebula.org/5.8/integration/system_interfaces/api.html#onevrouter