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

Add some functions to get consoles, SRs. #7

Open
wants to merge 2 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
18 changes: 18 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ func (client *XenAPIClient) GetPools() (pools []*Pool, err error) {
return pools, nil
}

func (client *XenAPIClient) GetSRs() (srs []*SR, err error) {
srs = make([]*SR, 0)
result := APIResult{}
err = client.APICall(&result, "SR.get_all")
if err != nil {
return nil, err
}

for _, elem := range result.Value.([]interface{}) {
sr := new(SR)
sr.Ref = elem.(string)
sr.Client = client
srs = append(srs, sr)
}

return srs, nil
}

func (client *XenAPIClient) GetDefaultSR() (sr *SR, err error) {
pools, err := client.GetPools()

Expand Down
20 changes: 20 additions & 0 deletions console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package client

import (
"github.com/nilshell/xmlrpc"
)

type Console XenAPIObject

func (self *Console) GetRecord() (record map[string]interface{}, err error) {
record = make(map[string]interface{})
result := APIResult{}
err = self.Client.APICall(&result, "console.get_record", self.Ref)
if err != nil {
return record, err
}
for k, v := range result.Value.(xmlrpc.Struct) {
record[k] = v
}
return record, nil
}
13 changes: 13 additions & 0 deletions sr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ import (

type SR XenAPIObject

func (self *SR) GetRecord() (record map[string]interface{}, err error) {
record = make(map[string]interface{})
result := APIResult{}
err = self.Client.APICall(&result, "SR.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 *SR) GetUuid() (uuid string, err error) {
result := APIResult{}
err = self.Client.APICall(&result, "SR.get_uuid", self.Ref)
Expand Down
53 changes: 43 additions & 10 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@ package client

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

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

type VM XenAPIObject

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) Clone(name_label string) (new_instance *VM, err error) {
new_instance = new(VM)

Expand Down Expand Up @@ -275,6 +291,23 @@ func (self *VM) GetVIFs() (vifs []VIF, err error) {
return vifs, nil
}

func (self *VM) GetConsoles() (consoles []Console, err error) {
consoles = make([]Console, 0)
result := APIResult{}
err = self.Client.APICall(&result, "VM.get_consoles", self.Ref)
if err != nil {
return consoles, err
}
for _, elem := range result.Value.([]interface{}) {
console := Console{}
console.Ref = elem.(string)
console.Client = self.Client
consoles = append(consoles, console)
}

return consoles, nil
}

func (self *VM) GetAllowedVIFDevices() (devices []string, err error) {
var device string
devices = make([]string, 0)
Expand Down Expand Up @@ -361,7 +394,7 @@ func (self *VM) ConnectVdi(vdi *VDI, vdiType VDIType, userdevice string) (err er
if userdevice == "" {
userdevice = "autodetect"
}

log.Debugf("RPCCall method=%v params=%v\n", "asdasd", "asdasdasd")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this?

vbd_rec := make(xmlrpc.Struct)
vbd_rec["VM"] = self.Ref
vbd_rec["VDI"] = vdi.Ref
Expand All @@ -370,7 +403,7 @@ func (self *VM) ConnectVdi(vdi *VDI, vdiType VDIType, userdevice string) (err er
vbd_rec["other_config"] = make(xmlrpc.Struct)
vbd_rec["qos_algorithm_type"] = ""
vbd_rec["qos_algorithm_params"] = make(xmlrpc.Struct)

fmt.Println(vdiType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this?

switch vdiType {
case CD:
vbd_rec["mode"] = "RO"
Expand All @@ -386,20 +419,20 @@ func (self *VM) ConnectVdi(vdi *VDI, vdiType VDIType, userdevice string) (err er
vbd_rec["mode"] = "RW"
vbd_rec["bootable"] = false
vbd_rec["unpluggable"] = true
vbd_rec["type"] = "Floppy"
vbd_rec["type"] = "Disk"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand why you've made this change?

}

result := APIResult{}
err = self.Client.APICall(&result, "VBD.create", vbd_rec)

return nil
if err != nil {
return err
}

vbd_ref := result.Value.(string)
//vbd_ref := result.Value.(string)

result = APIResult{}
err = self.Client.APICall(&result, "VBD.get_uuid", vbd_ref)
//result = APIResult{}
//err = self.Client.APICall(&result, "VBD.get_uuid", vbd_ref)
return nil

/*
// 2. Plug VBD (Non need - the VM hasn't booted.
Expand All @@ -411,7 +444,7 @@ func (self *VM) ConnectVdi(vdi *VDI, vdiType VDIType, userdevice string) (err er
return err
}
*/
return
//return
}

func (self *VM) DisconnectVdi(vdi *VDI) error {
Expand Down