-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- added HideLinks node property - added another HTTP request error condition - ran gofumpt over the code base
- Loading branch information
Showing
25 changed files
with
210 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import ( | |
) | ||
|
||
func main() { | ||
|
||
// address and lab id | ||
host, found := os.LookupEnv("CML_HOST") | ||
if !found { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package cmlclient | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
/* | ||
[ | ||
{ | ||
"id": "58568fbb-e1f8-4b83-a1f8-148c656eed39", | ||
"device_name": "virbr0", | ||
"label": "NAT", | ||
"protected": false, | ||
"snooped": true, | ||
"tags": [ | ||
"NAT" | ||
], | ||
"operational": { | ||
"forwarding": "NAT", | ||
"label": "NAT", | ||
"mtu": 1500, | ||
"exists": true, | ||
"enabled": true, | ||
"protected": false, | ||
"snooped": true, | ||
"stp": false, | ||
"interface": null, | ||
"ip_networks": [] | ||
} | ||
} | ||
] | ||
*/ | ||
|
||
// Operational data struct | ||
type opdata struct { | ||
Forwarding string `json:"forwarding"` | ||
Label string `json:"label"` | ||
MTU int `json:"mtu"` | ||
Exists bool `json:"exits"` | ||
Enabled bool `json:"enabled"` | ||
Protected bool `json:"protected"` | ||
Snooped bool `json:"snooped"` | ||
STP bool `json:"stp"` | ||
// Interface string `json:"interface"` | ||
IPNetworks []string `json:"ip_networks"` | ||
} | ||
|
||
// ExtConn defines the data structure for a CML external connector | ||
type ExtConn struct { | ||
ID string `json:"id"` | ||
DeviceName string `json:"device_name"` | ||
Label string `json:"label"` | ||
Protected bool `json:"protected"` | ||
Snooped bool `json:"snooped"` | ||
Tags []string `json:"tags"` | ||
Operational opdata `json:"operational"` | ||
} | ||
|
||
// ExtConnGet returns the external connector specified by the ID given | ||
func (c *Client) ExtConnGet(ctx context.Context, extConnID string) (*ExtConn, error) { | ||
api := fmt.Sprintf("system/external_connectors/%s", extConnID) | ||
extconn := &ExtConn{} | ||
err := c.jsonGet(ctx, api, extconn, 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return extconn, err | ||
} | ||
|
||
// ExtConnectors returns all external connectors on the system | ||
func (c *Client) ExtConnectors(ctx context.Context) ([]*ExtConn, error) { | ||
api := fmt.Sprintf("system/external_connectors") | ||
extconnlist := make([]*ExtConn, 0) | ||
err := c.jsonGet(ctx, api, &extconnlist, 0) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return extconnlist, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cmlclient | ||
|
||
import ( | ||
"testing" | ||
|
||
mr "github.com/rschmied/mockresponder" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestClient_ExtConns(t *testing.T) { | ||
tc := newAuthedTestAPIclient() | ||
|
||
extConn := []byte(` | ||
{ | ||
"id": "58568fbb-e1f8-4b83-a1f8-148c656eed39", | ||
"device_name": "virbr0", | ||
"label": "NAT", | ||
"protected": false, | ||
"snooped": true, | ||
"tags": [ | ||
"NAT" | ||
], | ||
"operational": { | ||
"forwarding": "NAT", | ||
"label": "NAT", | ||
"mtu": 1500, | ||
"exists": true, | ||
"enabled": true, | ||
"protected": false, | ||
"snooped": true, | ||
"stp": false, | ||
"interface": null, | ||
"ip_networks": [] | ||
} | ||
} | ||
`) | ||
extConns := append([]byte(`[`), extConn...) | ||
extConns = append(extConns, []byte(`]`)...) | ||
|
||
tests := []struct { | ||
name string | ||
data mr.MockRespList | ||
wantErr bool | ||
}{ | ||
{"good", mr.MockRespList{mr.MockResp{Data: extConns}}, false}, | ||
{"badjson", mr.MockRespList{mr.MockResp{Data: []byte(`///`)}}, true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tc.mr.SetData(tt.data) | ||
got, err := tc.client.ExtConnectors(tc.ctx) | ||
if err != nil { | ||
if !tt.wantErr { | ||
t.Error("unexpected error!", err) | ||
} | ||
return | ||
} | ||
assert.NoError(t, err) | ||
assert.Len(t, got, 1) | ||
assert.True(t, got[0].Label == "NAT") | ||
}) | ||
} | ||
|
||
t.Run("single", func(t *testing.T) { | ||
tc.mr.SetData(mr.MockRespList{mr.MockResp{Data: extConn}}) | ||
got, err := tc.client.ExtConnGet(tc.ctx, "58568fbb-e1f8-4b83-a1f8-148c656eed39") | ||
assert.NoError(t, err) | ||
assert.Equal(t, got.ID, "58568fbb-e1f8-4b83-a1f8-148c656eed39") | ||
assert.True(t, got.Label == "NAT") | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.