Skip to content

Commit

Permalink
add get ip addresses by nodeID to client (#37)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Siwiec <[email protected]>
  • Loading branch information
rizzza authored Jul 3, 2023
1 parent 58f5035 commit fe8a2f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
3 changes: 1 addition & 2 deletions pkg/ipamclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ipamclient

import (
"context"
"fmt"
"net/http"

"github.com/3th1nk/cidr"
Expand Down Expand Up @@ -195,7 +194,7 @@ func (c *Client) GetIPAddresses(ctx context.Context, nodeID string) (*GetIPAddre
}

vars := map[string]interface{}{
"representations": fmt.Sprintf(`{"__typename": "IPAddressable", "id": "%s"}`, nodeID),
"id": nodeID,
}

var ipas GetIPAddressesByNode
Expand Down
17 changes: 8 additions & 9 deletions pkg/ipamclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ func TestGetIPAddressesByNodeID(t *testing.T) {
"data": {
"_entities": [
{
"id": "loadbal-randovalue",
"IPAddresses": [
{
"id": "ipamipa-8IPzP37YJ1iTxJdMrCods",
Expand Down Expand Up @@ -193,16 +192,16 @@ func TestGetIPAddressesByNodeID(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, ips)

require.Len(t, ips.IPAddressableEntities.Entities, 1)
require.Len(t, ips.IPAddressableEntities.Entities[0].IPAddresses, 2)
require.Len(t, ips.Entities, 1)
require.Len(t, ips.Entities[0].IPAddresses, 2)

assert.Equal(t, "ipamipa-8IPzP37YJ1iTxJdMrCods", ips.IPAddressableEntities.Entities[0].IPAddresses[0].ID)
assert.Equal(t, "192.168.1.142", ips.IPAddressableEntities.Entities[0].IPAddresses[0].IP)
assert.False(t, ips.IPAddressableEntities.Entities[0].IPAddresses[0].Reserved)
assert.Equal(t, "ipamipa-8IPzP37YJ1iTxJdMrCods", ips.Entities[0].IPAddresses[0].ID)
assert.Equal(t, "192.168.1.142", ips.Entities[0].IPAddresses[0].IP)
assert.False(t, ips.Entities[0].IPAddresses[0].Reserved)

assert.Equal(t, "ipamipa-rPBY83fPw6Ll5sueCMpDr", ips.IPAddressableEntities.Entities[0].IPAddresses[1].ID)
assert.Equal(t, "192.168.1.1", ips.IPAddressableEntities.Entities[0].IPAddresses[1].IP)
assert.True(t, ips.IPAddressableEntities.Entities[0].IPAddresses[1].Reserved)
assert.Equal(t, "ipamipa-rPBY83fPw6Ll5sueCMpDr", ips.Entities[0].IPAddresses[1].ID)
assert.Equal(t, "192.168.1.1", ips.Entities[0].IPAddresses[1].IP)
assert.True(t, ips.Entities[0].IPAddresses[1].Reserved)
})
}

Expand Down
14 changes: 4 additions & 10 deletions pkg/ipamclient/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,12 @@ type DeleteIPAddressResult struct {

// IPAddressableFragment fragment for getting IP Addresses by node
type IPAddressableFragment struct {
IPAddresses []IPAddressNode
}

// IPAddressableEntities query result for getting IP Addresses by node
type IPAddressableEntities struct {
Entities []struct {
ID string
IPAddressableFragment `graphql:"... on IPAddressable"`
} `graphql:"_entities"`
IPAddresses []IPAddressNode `graphql:"IPAddresses"`
}

// GetIPAddressesByNode query for getting IP Addresses by node
type GetIPAddressesByNode struct {
IPAddressableEntities `graphql:"_entities(representations: $representations)"`
Entities []struct {
IPAddressableFragment `graphql:"... on IPAddressable"`
} `graphql:"_entities(representations: {__typename:\"IPAddressable\", id:$id})"`
}

0 comments on commit fe8a2f9

Please sign in to comment.