Skip to content

Commit

Permalink
Merge pull request #24 from howbazaar/tags
Browse files Browse the repository at this point in the history
Expose tags for interfaces and machines.
  • Loading branch information
jujubot committed Apr 6, 2016
2 parents 0ff5a7f + 8bb1914 commit 0152853
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
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 @@ -59,6 +60,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 @@ -161,6 +167,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 @@ -197,6 +204,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 @@ -109,7 +110,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 @@ -232,6 +233,7 @@ type Interface interface {
Children() []string
Type() string
Enabled() bool
Tags() []string

VLAN() VLAN
Links() []Link
Expand All @@ -241,7 +243,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

0 comments on commit 0152853

Please sign in to comment.