diff --git a/containers.go b/containers.go index 82859e1..9b1f409 100644 --- a/containers.go +++ b/containers.go @@ -115,12 +115,10 @@ func (c *Container) Feature(ctx context.Context) (hasFeature bool, err error) { return feature.HasFeature, err } -// This seems broken on the proxmox side: https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/lxc/{vmid}/interfaces -// I wasn't able to make it work with the API. Tested on {"release":"7.3","repoid":"c3928077","version":"7.3-3"} -// func (c *Container) Interfaces(ctx context.Context) (interfaces []string, err error) { -// err = c.client.Get(ctx, fmt.Sprintf("/nodes/%s/lxc/%d/interfaces", c.Node, c.VMID), &interfaces) -// return interfaces, err -// } +func (c *Container) Interfaces(ctx context.Context) (interfaces ContainerInterfaces, err error) { + err = c.client.Get(ctx, fmt.Sprintf("/nodes/%s/lxc/%d/interfaces", c.Node, c.VMID), &interfaces) + return interfaces, err +} func (c *Container) Migrate(ctx context.Context, params *ContainerMigrateOptions) (task *Task, err error) { var upid UPID diff --git a/containers_test.go b/containers_test.go index 246cf53..7afa253 100644 --- a/containers_test.go +++ b/containers_test.go @@ -247,3 +247,19 @@ func TestContainerRollbackSnapshot(t *testing.T) { assert.Nil(t, err) assert.NotEmpty(t, task) } + +func TestContainerInterfaces(t *testing.T) { + mocks.On(mockConfig) + defer mocks.Off() + client := mockClient() + ctx := context.Background() + container := Container{ + client: client, + Node: "node1", + VMID: 101, + } + interfaces, err := container.Interfaces(ctx) + assert.Nil(t, err) + assert.NotEmpty(t, interfaces) + assert.Equal(t, interfaces, ContainerInterfaces{{HWAddr: "00:00:00:00:00:00", Inet: "127.0.0.1/8", Name: "lo", Inet6: "::1/128"}, {Inet6: "fe80::be24:11ff:fe89:6707/64", Name: "eth0", HWAddr: "bc:24:11:89:67:07", Inet: "192.168.3.95/22"}}) +} diff --git a/tests/mocks/pve7x/nodes.go b/tests/mocks/pve7x/nodes.go index 6b97e64..62dd4d5 100644 --- a/tests/mocks/pve7x/nodes.go +++ b/tests/mocks/pve7x/nodes.go @@ -889,6 +889,25 @@ func nodes() { }`) // LXC + gock.New(config.C.URI). + Get("^/nodes/node1/lxc/101/interfaces"). + Reply(200). + JSON(`{ + "data": [ + { + "inet":"127.0.0.1/8", + "hwaddr":"00:00:00:00:00:00", + "name":"lo", + "inet6":"::1/128" + }, + { + "inet6":"fe80::be24:11ff:fe89:6707/64", + "name":"eth0", + "hwaddr":"bc:24:11:89:67:07", + "inet":"192.168.3.95/22" + } + ] +}`) gock.New(config.C.URI). Get("^/nodes/node1/lxc"). diff --git a/types.go b/types.go index 0d02b4e..63f9651 100644 --- a/types.go +++ b/types.go @@ -666,6 +666,15 @@ type Container struct { Tags string } +type ContainerInterfaces []*ContainerInterface + +type ContainerInterface struct { + HWAddr string `json:"hwaddr,omitempty"` + Name string `json:"name,omitempty"` + Inet string `json:"inet,omitempty"` + Inet6 string `json:"inet6,omitempty"` +} + type ContainerCloneOptions struct { NewID int `json:"newid"` BWLimit uint64 `json:"bwlimit,omitempty"`