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

Update NetworkAdapter attributes #116

Merged
merged 2 commits into from
Sep 5, 2024
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
5 changes: 5 additions & 0 deletions networkadapters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type NetworkAdapter struct {
AdapterType string `json:"adaptertype,omitempty"`
Bandwidth int `json:"bandwidth"`
ID string `json:"networkadapterid"`
IsConnected bool `json:"isconnected,omitempty"`
IsPrimary bool `json:"isprimary,omitempty"`
MacAddress string `json:"macaddress,omitempty"`
Name string `json:"name"`
NetworkID string `json:"networkid"`
ServerID string `json:"serverid"`
Expand All @@ -35,13 +38,15 @@ func (na *NetworkAdapter) IsReady() bool {
type CreateNetworkAdapterParams struct {
AdapterType string `json:"adaptertype,omitempty"`
Bandwidth int `json:"bandwidth,omitempty"`
Name string `json:"name,omitempty"`
NetworkID string `json:"networkid,omitempty"`
ServerID string `json:"serverid"`
}

// EditNetworkAdapterParams is used when editing an existing network adapter
type EditNetworkAdapterParams struct {
Bandwidth int `json:"bandwidth,omitempty"`
Name string `json:"name,omitempty"`
NetworkID string `json:"networkid,omitempty"`
}

Expand Down
28 changes: 27 additions & 1 deletion networkadapters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,33 @@ func TestNetworkAdaptersCreate(t *testing.T) {
assert.Equal(t, "networkadapter/create", c.lastPath, "path used is correct")
assert.Equal(t, "wps123456", networkadapter.ServerID, "networkadapter ServerID is correct")
assert.Equal(t, "Network Adapter 2", networkadapter.Name, "networkadapter Name is correct")
assert.Equal(t, "mynetwork", networkadapter.NetworkID, "networkadapter Description is correct")
assert.Equal(t, "mynetwork", networkadapter.NetworkID, "networkadapter NetworkID is correct")
}

func TestNetworkAdaptersCreate_KVM(t *testing.T) {
c := &mockClient{body: `{ "response": { "networkadapter":
{ "bandwidth": 1000, "name": "Adapter Example", "isprimary": false, "isconnected": true,
"networkid": "79c67265-a9a8-4607-b2b5-7377a6b6ebf7",
"networkadapterid": "ab12cd34-dcba-0123-abcd-abc123456789",
"serverid": "kvm123456" }}}`}
n := NetworkAdapterService{client: c}

params := CreateNetworkAdapterParams{
Bandwidth: 1000,
NetworkID: "79c67265-a9a8-4607-b2b5-7377a6b6ebf7",
ServerID: "kvm123456",
Name: "Adapter Example",
}

networkadapter, _ := n.Create(context.Background(), params)

assert.Equal(t, "POST", c.lastMethod, "method is used correct")
assert.Equal(t, "networkadapter/create", c.lastPath, "path used is correct")
assert.Equal(t, "kvm123456", networkadapter.ServerID, "networkadapter ServerID is correct")
assert.Equal(t, "Adapter Example", networkadapter.Name, "networkadapter Name is correct")
assert.Equal(t, true, networkadapter.IsConnected, "networkadapter IsConnected is correct")
assert.Equal(t, false, networkadapter.IsPrimary, "networkadapter IsPrimary is correct")
assert.Equal(t, "79c67265-a9a8-4607-b2b5-7377a6b6ebf7", networkadapter.NetworkID, "networkadapter networkID is correct")
}

func TestNetworkAdaptersDestroy(t *testing.T) {
Expand Down
Loading