xenserver / go-xenserver-client

Experimental golang bindings for XenAPI.
BSD 2-Clause "Simplified" License
37 stars 33 forks source link

Howto use go-xenserver-client #8

Open jniltinho opened 8 years ago

jniltinho commented 8 years ago

Hi @rdobson I like XenServer and Golang. Please howto use go-xenserver-client

I'm thinking of using your lib to develop a web interface to manage XenServer golang

Thanks

rdobson commented 8 years ago

Hi @jniltinho, we've not got any formal examples yet, but please check out these projects which use the library: https://github.com/xenserver/docker-machine-driver-xenserver & https://github.com/rdobson/packer-builder-xenserver which should help you see how to create a session and make various calls etc.

jniltinho commented 8 years ago

Hi @rdobson , very nice !!! :-) I'm reading the code of the projects.

Thank's

jniltinho commented 8 years ago

Hi @rdobson , Is there any example like this in Python? https://github.com/xapi-project/xen-api/tree/master/scripts/examples/python

jniltinho commented 8 years ago
func (client *XenAPIClient) GetVMAll() (vms []*VM, err error) {
    vms = make([]*VM, 0)
    result := APIResult{}
    err = client.APICall(&result, "VM.get_all")
    if err != nil {
        return vms, err
    }

    for _, elem := range result.Value.([]interface{}) {
        vm := new(VM)
        vm.Ref = elem.(string)
        vm.Client = client
        vms = append(vms, vm)
    }

    return vms, nil
}

https://github.com/xapi-project/xen-api/blob/master/scripts/examples/python/powercycle.py#L25