Skip to content

Commit 793761e

Browse files
committed
Update to work with new version of github.com/kolo/xmlrpc
1 parent 798a5d2 commit 793761e

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

helpers.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package xapi
22

33
import (
4-
"github.com/kolo/xmlrpc"
54
"log"
65
"reflect"
76
"strconv"
87
"unicode"
98
"unicode/utf8"
109
)
1110

12-
func unMarshallXmlRPC(in xmlrpc.Struct, out interface{}) {
11+
func unMarshallXmlRPC(in Struct, out interface{}) {
1312
ov := reflect.Indirect(reflect.ValueOf(out))
1413
iv := reflect.ValueOf(in["Value"])
1514

1615
if ov.Kind() == reflect.Struct {
17-
setStruct(in["Value"].(xmlrpc.Struct), ov)
16+
setStruct(in["Value"].(Struct), ov)
1817
return
1918
}
2019

@@ -31,19 +30,19 @@ func unMarshallXmlRPC(in xmlrpc.Struct, out interface{}) {
3130
}
3231

3332
if ov.Index(i).Kind() == reflect.Struct {
34-
setStruct(a.(xmlrpc.Struct), ov.Index(i))
33+
setStruct(a.(Struct), ov.Index(i))
3534
} else {
3635
ov.Index(i).Set(reflect.ValueOf(a))
3736
}
3837

3938
}
4039
return
41-
case xmlrpc.Struct:
40+
case Struct:
4241
setStruct(in, ov)
4342
}
4443
}
4544

46-
func setStruct(in xmlrpc.Struct, str reflect.Value) {
45+
func setStruct(in Struct, str reflect.Value) {
4746
for k, v := range in {
4847
field := str.FieldByName(UF(k))
4948
if !field.CanSet() || !field.IsValid() || v == nil {
@@ -61,7 +60,7 @@ func setStruct(in xmlrpc.Struct, str reflect.Value) {
6160
setString(v, field)
6261
case reflect.Map:
6362
field.Set(reflect.MakeMap(field.Type()))
64-
for a, b := range v.(xmlrpc.Struct) {
63+
for a, b := range v.(Struct) {
6564
if a == "" || b == nil {
6665
continue
6766
}

xapi.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type XapiClient struct {
1818
rpc *xmlrpc.Client
1919
}
2020

21+
type Struct map[string]interface{}
22+
2123
// Stand up a new XapiClient. Version should probably be "1.2" unless you know what you are doing.
2224
func NewXapiClient(uri, username, password, version string) (client XapiClient) {
2325
client.Uri = uri
@@ -134,7 +136,7 @@ func TimeoutDialer() func(net, addr string) (c net.Conn, err error) {
134136
}
135137
}
136138

137-
// Make a generic RPC call passing in a pointer to a struct (or xmlrpc.Struct). The call parameter
139+
// Make a generic RPC call passing in a pointer to a struct (or f). The call parameter
138140
// is a combination of class.message. For example: VIF.get_record, host.evacuate, pool.eject.
139141
// Any time the XAPI specifies a `type ref` it's really an OpaqueReference, which is a UUID, and
140142
// as far as xmlrpc and like library are concerned, a string.
@@ -145,14 +147,9 @@ func TimeoutDialer() func(net, addr string) (c net.Conn, err error) {
145147
// fmt.Printf("%v", host)
146148
// }
147149
func (client *XapiClient) RpcCall(result interface{}, call string, params ...interface{}) (err error) {
148-
response := xmlrpc.Struct{}
149-
p := xmlrpc.Params{}
150-
p.Params = make([]interface{}, len(params))
151-
for i, d := range params {
152-
p.Params[i] = d
153-
}
150+
response := Struct{}
154151

155-
err = client.rpc.Call(call, p, &response)
152+
err = client.rpc.Call(call, params, &response)
156153

157154
if err != nil {
158155
return
@@ -171,7 +168,7 @@ func (client *XapiClient) RpcCall(result interface{}, call string, params ...int
171168

172169
// checkResponse is a way to handle and return meaning status codes based on the payload since the body
173170
// of the response changes depending on if it's an error or a success. This handled for you in RpcCall
174-
func checkResponse(res xmlrpc.Struct) error {
171+
func checkResponse(res Struct) error {
175172
var success interface{}
176173
var ok bool
177174
var error_string interface{}

0 commit comments

Comments
 (0)