Skip to content
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

Expose tags for interfaces and machines. #24

Merged
merged 1 commit into from
Apr 6, 2016
Merged
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
8 changes: 8 additions & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type interface_ struct {
name string
type_ string
enabled bool
tags []string

vlan *vlan
links []*link
Expand Down Expand Up @@ -46,6 +47,11 @@ func (i *interface_) Enabled() bool {
return i.enabled
}

// Tags implements Interface.
func (i *interface_) Tags() []string {
return i.tags
}

// VLAN implements Interface.
func (i *interface_) VLAN() VLAN {
return i.vlan
Expand Down Expand Up @@ -148,6 +154,7 @@ func interface_2_0(source map[string]interface{}) (*interface_, error) {
"name": schema.String(),
"type": schema.String(),
"enabled": schema.Bool(),
"tags": schema.List(schema.String()),

"vlan": schema.StringMap(schema.Any()),
"links": schema.List(schema.StringMap(schema.Any())),
Expand Down Expand Up @@ -181,6 +188,7 @@ func interface_2_0(source map[string]interface{}) (*interface_, error) {
name: valid["name"].(string),
type_: valid["type"].(string),
enabled: valid["enabled"].(bool),
tags: convertToStringSlice(valid["tags"]),

vlan: vlan,
links: links,
Expand Down
3 changes: 2 additions & 1 deletion interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (s *interfaceSuite) checkInterface(c *gc.C, iface *interface_) {
c.Check(iface.Name(), gc.Equals, "eth0")
c.Check(iface.Type(), gc.Equals, "physical")
c.Check(iface.Enabled(), jc.IsTrue)
c.Check(iface.Tags(), jc.DeepEquals, []string{"foo", "bar"})

c.Check(iface.MACAddress(), gc.Equals, "52:54:00:c9:6a:45")
c.Check(iface.EffectiveMTU(), gc.Equals, 1500)
Expand Down Expand Up @@ -106,7 +107,7 @@ const (
"id": 40,
"type": "physical",
"resource_uri": "/MAAS/api/2.0/nodes/4y3ha6/interfaces/40/",
"tags": [],
"tags": ["foo", "bar"],
"links": [
{
"id": 69,
Expand Down
3 changes: 2 additions & 1 deletion interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ type Machine interface {
SystemID() string
Hostname() string
FQDN() string
Tags() []string

OperatingSystem() string
DistroSeries() string
Expand Down Expand Up @@ -221,6 +222,7 @@ type Interface interface {
Name() string
Type() string
Enabled() bool
Tags() []string

VLAN() VLAN
Links() []Link
Expand All @@ -230,7 +232,6 @@ type Interface interface {
Params() string

// Need to work out types for children, discovered, parents
// Tags?
}

// Link represents a network link between an Interface and a Subnet.
Expand Down
8 changes: 8 additions & 0 deletions machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type machine struct {
systemID string
hostname string
fqdn string
tags []string

operatingSystem string
distroSeries string
Expand Down Expand Up @@ -71,6 +72,11 @@ func (m *machine) FQDN() string {
return m.fqdn
}

// Tags implements Machine.
func (m *machine) Tags() []string {
return m.tags
}

// IPAddresses implements Machine.
func (m *machine) IPAddresses() []string {
return m.ipAddresses
Expand Down Expand Up @@ -250,6 +256,7 @@ func machine_2_0(source map[string]interface{}) (*machine, error) {
"system_id": schema.String(),
"hostname": schema.String(),
"fqdn": schema.String(),
"tag_names": schema.List(schema.String()),

"osystem": schema.String(),
"distro_series": schema.String(),
Expand Down Expand Up @@ -295,6 +302,7 @@ func machine_2_0(source map[string]interface{}) (*machine, error) {
systemID: valid["system_id"].(string),
hostname: valid["hostname"].(string),
fqdn: valid["fqdn"].(string),
tags: convertToStringSlice(valid["tag_names"]),

operatingSystem: valid["osystem"].(string),
distroSeries: valid["distro_series"].(string),
Expand Down
4 changes: 3 additions & 1 deletion machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func (*machineSuite) TestReadMachines(c *gc.C) {
c.Check(machine.SystemID(), gc.Equals, "4y3ha3")
c.Check(machine.Hostname(), gc.Equals, "untasted-markita")
c.Check(machine.FQDN(), gc.Equals, "untasted-markita.maas")
c.Check(machine.Tags(), jc.DeepEquals, []string{"virtual", "magic"})

c.Check(machine.IPAddresses(), jc.DeepEquals, []string{"192.168.100.4"})
c.Check(machine.Memory(), gc.Equals, 1024)
c.Check(machine.CPUCount(), gc.Equals, 1)
Expand Down Expand Up @@ -337,7 +339,7 @@ const (
"power_type": "virsh",
"distro_series": "trusty",
"tag_names": [
"virtual"
"virtual", "magic"
],
"disable_ipv4": false,
"status_message": "From 'Deploying' to 'Deployed'",
Expand Down