From 90ebef9b2396a54a5b0e16aadfd1a33c29a641c7 Mon Sep 17 00:00:00 2001 From: Simon Fuhrer Date: Wed, 1 Jul 2015 22:06:15 +0200 Subject: [PATCH 1/2] Add some funcions to get consoles, SRs. VBD Type floppy ist not correctly. Use disk instead. --- client.go | 19 +++++++++++++++++++ console.go | 21 +++++++++++++++++++++ sr.go | 14 ++++++++++++++ vm.go | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 4 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 console.go diff --git a/client.go b/client.go index 91ea6e7..26f6f39 100644 --- a/client.go +++ b/client.go @@ -123,6 +123,25 @@ 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() diff --git a/console.go b/console.go new file mode 100644 index 0000000..baca40c --- /dev/null +++ b/console.go @@ -0,0 +1,21 @@ +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 +} + diff --git a/sr.go b/sr.go index c6ba9f1..2e4c623 100644 --- a/sr.go +++ b/sr.go @@ -7,6 +7,20 @@ 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) diff --git a/vm.go b/vm.go index c733c13..96ccccd 100644 --- a/vm.go +++ b/vm.go @@ -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) @@ -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) @@ -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") vbd_rec := make(xmlrpc.Struct) vbd_rec["VM"] = self.Ref vbd_rec["VDI"] = vdi.Ref @@ -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) switch vdiType { case CD: vbd_rec["mode"] = "RO" @@ -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" } - 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. @@ -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 { From acc29c8bec04442b69255e87790d2bf7df7e27a5 Mon Sep 17 00:00:00 2001 From: Simon Fuhrer Date: Wed, 1 Jul 2015 22:35:53 +0200 Subject: [PATCH 2/2] fis travis ci build errors --- client.go | 1 - console.go | 23 +++++++++++------------ sr.go | 21 ++++++++++----------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/client.go b/client.go index 26f6f39..0c00a7c 100644 --- a/client.go +++ b/client.go @@ -141,7 +141,6 @@ func (client *XenAPIClient) GetSRs() (srs []*SR, err error) { return srs, nil } - func (client *XenAPIClient) GetDefaultSR() (sr *SR, err error) { pools, err := client.GetPools() diff --git a/console.go b/console.go index baca40c..edc097b 100644 --- a/console.go +++ b/console.go @@ -1,21 +1,20 @@ package client import ( - "github.com/nilshell/xmlrpc" + "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 + 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 } - diff --git a/sr.go b/sr.go index 2e4c623..040f686 100644 --- a/sr.go +++ b/sr.go @@ -8,19 +8,18 @@ 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 + 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)