-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Device.InterfaceSet to not return an error. #34
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,12 @@ type device struct { | |
hostname string | ||
fqdn string | ||
|
||
ipAddresses []string | ||
zone *zone | ||
parent string | ||
owner string | ||
|
||
ipAddresses []string | ||
interfaceSet []*interface_ | ||
zone *zone | ||
} | ||
|
||
// SystemID implements Device. | ||
|
@@ -41,6 +45,16 @@ func (d *device) FQDN() string { | |
return d.fqdn | ||
} | ||
|
||
// Parent implements Device. | ||
func (d *device) Parent() string { | ||
return d.parent | ||
} | ||
|
||
// Owner implements Device. | ||
func (d *device) Owner() string { | ||
return d.owner | ||
} | ||
|
||
// IPAddresses implements Device. | ||
func (d *device) IPAddresses() []string { | ||
return d.ipAddresses | ||
|
@@ -52,24 +66,13 @@ func (d *device) Zone() Zone { | |
} | ||
|
||
// InterfaceSet implements Device. | ||
func (d *device) InterfaceSet() ([]Interface, error) { | ||
// NOTE: the get and extra parse will not be necessary | ||
// when r4900 of maas has been packaged and released. | ||
source, err := d.controller.get(d.interfacesURI()) | ||
if err != nil { | ||
return nil, NewUnexpectedError(err) | ||
} | ||
ifaces, err := readInterfaces(d.controller.apiVersion, source) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
result := make([]Interface, len(ifaces)) | ||
for i, v := range ifaces { | ||
func (d *device) InterfaceSet() []Interface { | ||
result := make([]Interface, len(d.interfaceSet)) | ||
for i, v := range d.interfaceSet { | ||
v.controller = d.controller | ||
result[i] = v | ||
} | ||
return result, nil | ||
return result | ||
} | ||
|
||
// CreateInterfaceArgs is an argument struct for passing parameters to | ||
|
@@ -240,9 +243,12 @@ func device_2_0(source map[string]interface{}) (*device, error) { | |
"system_id": schema.String(), | ||
"hostname": schema.String(), | ||
"fqdn": schema.String(), | ||
"parent": schema.String(), | ||
"owner": schema.String(), | ||
|
||
"ip_addresses": schema.List(schema.String()), | ||
"zone": schema.StringMap(schema.Any()), | ||
"ip_addresses": schema.List(schema.String()), | ||
"interface_set": schema.List(schema.StringMap(schema.Any())), | ||
"zone": schema.StringMap(schema.Any()), | ||
} | ||
checker := schema.FieldMap(fields, nil) // no defaults | ||
coerced, err := checker.Coerce(source, nil) | ||
|
@@ -253,6 +259,10 @@ func device_2_0(source map[string]interface{}) (*device, error) { | |
// From here we know that the map returned from the schema coercion | ||
// contains fields of the right type. | ||
|
||
interfaceSet, err := readInterfaceList(valid["interface_set"].([]interface{}), interface_2_0) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
zone, err := zone_2_0(valid["zone"].(map[string]interface{})) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same again |
||
|
@@ -264,9 +274,12 @@ func device_2_0(source map[string]interface{}) (*device, error) { | |
systemID: valid["system_id"].(string), | ||
hostname: valid["hostname"].(string), | ||
fqdn: valid["fqdn"].(string), | ||
parent: valid["parent"].(string), | ||
owner: valid["owner"].(string), | ||
|
||
ipAddresses: convertToStringSlice(valid["ip_addresses"]), | ||
zone: zone, | ||
ipAddresses: convertToStringSlice(valid["ip_addresses"]), | ||
interfaceSet: interfaceSet, | ||
zone: zone, | ||
} | ||
return result, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,13 +158,15 @@ type Device interface { | |
IPAddresses() []string | ||
Zone() Zone | ||
|
||
// Parent, Owner, MAC Addresses if needed | ||
// Parent returns the SystemID of the Parent. Most often this will be a | ||
// Machine. | ||
Parent() string | ||
|
||
// InterfaceSet returns all the interfaces for the Device. This is an | ||
// interim call until r4900 is packaged, when we will be able to remove the | ||
// error response as the device JSON will include the interface set which | ||
// will be able to be parsed at object creation time. | ||
InterfaceSet() ([]Interface, error) | ||
// Owner is the username of the user that created the device. | ||
Owner() string | ||
|
||
// InterfaceSet returns all the interfaces for the Device. | ||
InterfaceSet() []Interface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why InterfaceSet instead of Interfaces? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because it was called "interface_set" in the JSON response. That is the only reason I chose that name. |
||
|
||
// CreateInterface will create a physical interface for this machine. | ||
CreateInterface(CreateInterfaceArgs) (Interface, error) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap with a gomaasapi error type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readInterfaceList already returns gomaasapi error types.