Giter Club home page Giter Club logo

go-xen-api-client's Introduction

Go XenAPI client library

This is a client library for the Xapi toolstack (http://xapi-project.github.io/).

This library covers the entire XenAPI and I have successfully used it to implement a Terraform plugin that interfaces Citrix XenServer. That being said, this library is not production-ready yet. Use it at your own risk, and don't expect everything in this library to work out of the box.

Usage example

The following example demonstrates how to instruct XenServer to start a VM with a given name label:

package main

import (
    "fmt"
    "github.com/amfranz/go-xen-api-client"
)

const XEN_API_URL string = "https://IP.OF.XEN.SERVER"
const XEN_API_USERNAME string = "USERNAME"
const XEN_API_PASSWORD string = "PASSWORD"
const VM_NAME_LABEL = "VM NAME LABEL"

func main() {
    xapi, err := xenAPI.NewClient(XEN_API_URL, nil)
    if err != nil {
        panic(err)
    }

    session, err := xapi.Session.LoginWithPassword(XEN_API_USERNAME, XEN_API_PASSWORD, "1.0", "example")
    if err != nil {
        panic(err)
    }

    vms, err := xapi.VM.GetByNameLabel(session, VM_NAME_LABEL)
    if err != nil {
        panic(err)
    }

    if len(vms) == 0 {
        panic(fmt.Errorf("No VM template with name label %q has been found", VM_NAME_LABEL))
    }

    if len(vms) > 1 {
        panic(fmt.Errorf("More than one VM with name label %q has been found", VM_NAME_LABEL))
    }

    vm := vms[0]

    xapi.VM.Start(session, vm, false, false)
    if err != nil {
        panic(err)
    }

    err = xapi.Session.Logout(session)
    if err != nil {
        panic(err)
    }
}

Project status

The most important missing pieces before this library is production-ready are:

  • A strategy how to handle the differences in the XenAPI versions.
  • Tests, at least for the various data type conversions.
  • Embed XenAPI documentation as GoDoc in the generated code.
  • Better error messages.
  • Usage examples.

Contributions welcome!

Please note that I want to keep this library lean. I envision it to merely provide a one-to-one mapping of XenAPI functions to Go functions. Because of this, I will likely not accept pull requests that implement higher level functionality.

Implementation notes

Most of the code in this library is generated from a description of the XenAPI. This description is the file xenapi.json, the source of which is the XenAPI documentation at http://xapi-project.github.io/:

The list of error code constants in error.go is borrowed from xapi-projects OCaml client:

go-xen-api-client's People

Contributors

amfranz avatar mborodin avatar tustvold avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.