Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

More data methods #14

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"errors"
"fmt"

log "github.com/Sirupsen/logrus"
"github.com/nilshell/xmlrpc"
)
Expand Down Expand Up @@ -44,12 +45,20 @@ func (client *XenAPIClient) Login() (err error) {
params[1] = client.Password

err = client.RPCCall(&result, "session.login_with_password", params)
if err == nil {
// err might not be set properly, so check the reference
if result["Value"] == nil {
return errors.New("Invalid credentials supplied")
if err != nil {
return err
}
if result["Status"] == "Failure" {
if errDesc, ok := result["ErrorDescription"].([]interface{}); ok {
return fmt.Errorf("%v %v", errDesc[0], errDesc[1])
}
}

// err might not be set properly, so check the reference
if result["Value"] == nil {
return errors.New("No value returned")
}

client.Session = result["Value"]
return err
}
Expand Down
20 changes: 20 additions & 0 deletions host.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ func (self *Host) GetAddress() (address string, err error) {
return address, nil
}

func (self *Host) GetHostname() (hostname string, err error) {
result := APIResult{}
err = self.Client.APICall(&result, "host.get_hostname", self.Ref)
if err != nil {
return "", err
}
hostname = result.Value.(string)
return hostname, nil
}

func (self *Host) GetNameLabel() (nameLabel string, err error) {
result := APIResult{}
err = self.Client.APICall(&result, "host.get_name_label", self.Ref)
if err != nil {
return "", err
}
nameLabel = result.Value.(string)
return nameLabel, nil
}

func (self *Host) GetSoftwareVersion() (versions map[string]interface{}, err error) {
versions = make(map[string]interface{})

Expand Down
10 changes: 10 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ func (self *Pool) GetMaster() (host *Host, err error) {
return host, nil
}

func (self *Pool) GetNameLabel() (nameLabel string, err error) {
result := &APIResult{}
err = self.Client.APICall(result, "pool.get_name_label", self.Ref)
if err != nil {
return "", err
}
nameLabel = result.Value.(string)
return nameLabel, nil
}

func (self *Pool) GetRecord() (record map[string]interface{}, err error) {
record = make(map[string]interface{})
result := APIResult{}
Expand Down
15 changes: 15 additions & 0 deletions vdi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"encoding/xml"
"errors"
"fmt"

log "github.com/Sirupsen/logrus"
"github.com/nilshell/xmlrpc"
)

type VDI XenAPIObject
Expand All @@ -18,6 +20,19 @@ const (
Floppy
)

func (self *VDI) GetRecord() (record map[string]interface{}, err error) {
record = make(map[string]interface{})
result := APIResult{}
err = self.Client.APICall(&result, "VDI.get_record", self.Ref)
if err != nil {
return record, err
}
for k, v := range result.Value.(xmlrpc.Struct) {
record[k] = v
}
return record, nil
}

func (self *VDI) GetUuid() (vdi_uuid string, err error) {
result := APIResult{}
err = self.Client.APICall(&result, "VDI.get_uuid", self.Ref)
Expand Down
25 changes: 24 additions & 1 deletion vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package client

import (
"fmt"
"github.com/nilshell/xmlrpc"
"strconv"

"github.com/nilshell/xmlrpc"
)

type VM XenAPIObject
Expand Down Expand Up @@ -129,6 +130,15 @@ func (self *VM) HardShutdown() (err error) {
return
}

func (self *VM) Shutdown() (err error) {
result := APIResult{}
err = self.Client.APICall(&result, "VM.shutdown", self.Ref)
if err != nil {
return err
}
return
}

func (self *VM) CleanReboot() (err error) {
result := APIResult{}
err = self.Client.APICall(&result, "VM.clean_reboot", self.Ref)
Expand Down Expand Up @@ -600,6 +610,19 @@ func (self *VM) SetOtherConfig(other_config map[string]string) (err error) {
return
}

func (self *VM) GetRecord() (record map[string]interface{}, err error) {
record = make(map[string]interface{})
result := APIResult{}
err = self.Client.APICall(&result, "VM.get_record", self.Ref)
if err != nil {
return record, err
}
for k, v := range result.Value.(xmlrpc.Struct) {
record[k] = v
}
return record, nil
}

func (self *VM) SetNameLabel(name_label string) (err error) {
result := APIResult{}
err = self.Client.APICall(&result, "VM.set_name_label", self.Ref, name_label)
Expand Down