diff --git a/cobblerclient.go b/cobblerclient.go
index 5a3f0ca..a72b2f8 100644
--- a/cobblerclient.go
+++ b/cobblerclient.go
@@ -311,7 +311,7 @@ func cobblerDataHacks(fromType, targetType reflect.Kind, data interface{}) (inte
valueStruct.RawData = data
return valueStruct, nil
case reflect.Map:
- // This can be: Top-level Map, paged search results, page-info struct or an inherited struct
+ // This can be: Top-level Map, paged search results, page-info struct, network interface or an inherited struct
mapKeys := dataVal.MapKeys()
sort.SliceStable(mapKeys, func(i, j int) bool {
return mapKeys[i].String() < mapKeys[j].String()
@@ -324,6 +324,10 @@ func cobblerDataHacks(fromType, targetType reflect.Kind, data interface{}) (inte
// Page-Info struct
return data, nil
}
+ if len(mapKeys) == 23 && mapKeys[0].String() == "bonding_opts" {
+ // Network Interface struct
+ return data, nil
+ }
for _, key := range mapKeys {
// If the uid key is in the map then it is the top level Map
if key.String() == "uid" {
@@ -340,23 +344,25 @@ func cobblerDataHacks(fromType, targetType reflect.Kind, data interface{}) (inte
integerValue, err := convertToInt(data)
valueStruct.Data = integerValue
valueStruct.RawData = data
- if err == nil {
+ if err != nil {
return Value[int]{}, err
}
return valueStruct, nil
+ case reflect.Float64:
+ // Float that may or may not be inherited
+ valueStruct := Value[float64]{}
+ floatValue, err := convertToFloat(data)
+ valueStruct.Data = floatValue
+ valueStruct.RawData = data
+ if err != nil {
+ return Value[float64]{}, err
+ }
+ return valueStruct, nil
case reflect.Bool:
// Bool that may or may not be inherited
valueStruct := Value[bool]{}
- integerBoolean, err := convertToInt(data)
- if err == nil {
- return Value[bool]{}, err
- }
- boolValue, err := convertIntBool(integerBoolean)
- valueStruct.Data = boolValue
+ valueStruct.Data = data.(bool)
valueStruct.RawData = data
- if err == nil {
- return Value[bool]{}, err
- }
return valueStruct, nil
default:
return nil, fmt.Errorf("unknown type %s fromType for Inherited or Flattened Value", fromType)
@@ -380,7 +386,7 @@ func decodeCobblerItem(raw interface{}, result interface{}) (interface{}, error)
return nil, err
}
- if err := decoder.Decode(raw); err != nil {
+ if err = decoder.Decode(raw); err != nil {
return nil, err
}
diff --git a/fixtures/get-interfaces-get-system-res.xml b/fixtures/get-interfaces-get-system-res.xml
index 33ca1c7..9f973dd 100644
--- a/fixtures/get-interfaces-get-system-res.xml
+++ b/fixtures/get-interfaces-get-system-res.xml
@@ -175,7 +175,7 @@
ip_address
-
+ 10.1.0.1
diff --git a/system_test.go b/system_test.go
index 86e48fe..a2e8d68 100644
--- a/system_test.go
+++ b/system_test.go
@@ -17,6 +17,7 @@ limitations under the License.
package cobblerclient
import (
+ "fmt"
"github.com/go-test/deep"
"testing"
"time"
@@ -263,6 +264,9 @@ func TestGetInterfaces(t *testing.T) {
if len(interfaces) < 1 {
t.Fatal("there should be at least one interface")
}
+ if interfaces["default"].IPAddress != "10.1.0.1" {
+ t.Fatal("incorrect IP address")
+ }
FailOnError(t, err)
}
@@ -279,7 +283,11 @@ func TestGetInterface(t *testing.T) {
nic, err := testsys.GetInterface("default")
// Assert
- if len(deep.Equal(nic, Interface{})) > 0 {
+ expectedInterface := NewInterface()
+ expectedInterface.IPAddress = "10.1.0.1"
+ differences := deep.Equal(nic, expectedInterface)
+ if len(differences) > 0 {
+ fmt.Println(differences)
t.Fatal("interfaces non-equal")
}
FailOnError(t, err)
diff --git a/utils.go b/utils.go
index 86215f0..8c9a49f 100644
--- a/utils.go
+++ b/utils.go
@@ -88,6 +88,17 @@ func convertIntBool(integer int) (bool, error) {
return false, errors.New("integer was neither 0 nor 1")
}
+func convertToFloat(float interface{}) (float64, error) {
+ switch v := float.(type) {
+ case float64:
+ return v, nil
+ case float32:
+ return float64(v), nil
+ default:
+ return -1, errors.New("float could not be converted")
+ }
+}
+
func convertToInt(integer interface{}) (int, error) {
switch integer.(type) {
case int8: