diff --git a/proxmox/Internal/pxapi/dns/nameservers/nameservers.go b/proxmox/Internal/pve/dns/nameservers/nameservers.go similarity index 100% rename from proxmox/Internal/pxapi/dns/nameservers/nameservers.go rename to proxmox/Internal/pve/dns/nameservers/nameservers.go diff --git a/proxmox/Internal/pxapi/guest/sshkeys/sshkeys.go b/proxmox/Internal/pve/guest/sshkeys/sshkeys.go similarity index 100% rename from proxmox/Internal/pxapi/guest/sshkeys/sshkeys.go rename to proxmox/Internal/pve/guest/sshkeys/sshkeys.go diff --git a/proxmox/Internal/pxapi/guest/tags/tags.go b/proxmox/Internal/pve/guest/tags/tags.go similarity index 77% rename from proxmox/Internal/pxapi/guest/tags/tags.go rename to proxmox/Internal/pve/guest/tags/tags.go index c97e8e84..98512620 100644 --- a/proxmox/Internal/pxapi/guest/tags/tags.go +++ b/proxmox/Internal/pve/guest/tags/tags.go @@ -4,22 +4,22 @@ import ( "sort" "strings" - pxapi "github.com/Telmate/proxmox-api-go/proxmox" + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) // Returns an unordered list of unique tags -func RemoveDuplicates(tags *[]pxapi.Tag) *[]pxapi.Tag { +func RemoveDuplicates(tags *[]pveSDK.Tag) *[]pveSDK.Tag { if tags == nil || len(*tags) == 0 { return nil } - tagMap := make(map[pxapi.Tag]struct{}) + tagMap := make(map[pveSDK.Tag]struct{}) for _, tag := range *tags { tagMap[tag] = struct{}{} } - uniqueTags := make([]pxapi.Tag, len(tagMap)) + uniqueTags := make([]pveSDK.Tag, len(tagMap)) var index uint for tag := range tagMap { uniqueTags[index] = tag @@ -51,7 +51,7 @@ func Schema() *schema.Schema { } } -func sortArray(tags *[]pxapi.Tag) *[]pxapi.Tag { +func sortArray(tags *[]pveSDK.Tag) *[]pveSDK.Tag { if tags == nil || len(*tags) == 0 { return nil } @@ -61,8 +61,8 @@ func sortArray(tags *[]pxapi.Tag) *[]pxapi.Tag { return tags } -func Split(rawTags string) *[]pxapi.Tag { - tags := make([]pxapi.Tag, 0) +func Split(rawTags string) *[]pveSDK.Tag { + tags := make([]pveSDK.Tag, 0) if rawTags == "" { return &tags } @@ -70,19 +70,19 @@ func Split(rawTags string) *[]pxapi.Tag { for _, tag := range tagArrays { tagSubArrays := strings.Split(tag, ",") if len(tagSubArrays) > 1 { - tmpTags := make([]pxapi.Tag, len(tagSubArrays)) + tmpTags := make([]pveSDK.Tag, len(tagSubArrays)) for i, e := range tagSubArrays { - tmpTags[i] = pxapi.Tag(e) + tmpTags[i] = pveSDK.Tag(e) } tags = append(tags, tmpTags...) } else { - tags = append(tags, pxapi.Tag(tag)) + tags = append(tags, pveSDK.Tag(tag)) } } return &tags } -func String(tags *[]pxapi.Tag) (tagList string) { +func String(tags *[]pveSDK.Tag) (tagList string) { if tags == nil || len(*tags) == 0 { return "" } diff --git a/proxmox/Internal/pve/guest/tags/tags_test.go b/proxmox/Internal/pve/guest/tags/tags_test.go new file mode 100644 index 00000000..d1917049 --- /dev/null +++ b/proxmox/Internal/pve/guest/tags/tags_test.go @@ -0,0 +1,82 @@ +package tags + +import ( + "testing" + + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" + "github.com/stretchr/testify/require" +) + +func Test_RemoveDuplicates(t *testing.T) { + tests := []struct { + name string + input *[]pveSDK.Tag + output *[]pveSDK.Tag + }{ + {name: `nil`}, + {name: `empty`, input: &[]pveSDK.Tag{}}, + {name: `single`, input: &[]pveSDK.Tag{"a"}, output: &[]pveSDK.Tag{"a"}}, + {name: `multiple`, input: &[]pveSDK.Tag{"b", "a", "c"}, output: &[]pveSDK.Tag{"a", "b", "c"}}, + {name: `duplicate`, input: &[]pveSDK.Tag{"b", "a", "c", "b", "a"}, output: &[]pveSDK.Tag{"a", "b", "c"}}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require.Equal(t, test.output, sortArray(RemoveDuplicates(test.input))) + }) + } +} + +func Test_sort(t *testing.T) { + tests := []struct { + name string + input *[]pveSDK.Tag + output *[]pveSDK.Tag + }{ + {name: `nil`}, + {name: `empty`, input: &[]pveSDK.Tag{}}, + {name: `single`, input: &[]pveSDK.Tag{"a"}, output: &[]pveSDK.Tag{"a"}}, + {name: `multiple`, input: &[]pveSDK.Tag{"b", "a", "c"}, output: &[]pveSDK.Tag{"a", "b", "c"}}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require.Equal(t, test.output, sortArray(test.input)) + }) + } +} + +func Test_Split(t *testing.T) { + tests := []struct { + name string + input string + output *[]pveSDK.Tag + }{ + {name: `empty`, output: &[]pveSDK.Tag{}}, + {name: `single`, input: "a", output: &[]pveSDK.Tag{"a"}}, + {name: `multiple ,`, input: "b,a,c", output: &[]pveSDK.Tag{"b", "a", "c"}}, + {name: `multiple ;`, input: "b;a;c", output: &[]pveSDK.Tag{"b", "a", "c"}}, + {name: `multiple mixed`, input: "b,a;c,d;e", output: &[]pveSDK.Tag{"b", "a", "c", "d", "e"}}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require.Equal(t, test.output, Split(test.input)) + }) + } +} + +func Test_String(t *testing.T) { + tests := []struct { + name string + input *[]pveSDK.Tag + output string + }{ + {name: `nil`}, + {name: `empty`, input: &[]pveSDK.Tag{}}, + {name: `single`, input: &[]pveSDK.Tag{"a"}, output: "a"}, + {name: `multiple`, input: &[]pveSDK.Tag{"b", "a", "c"}, output: "b;a;c"}, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + require.Equal(t, test.output, String(test.input)) + }) + } +} diff --git a/proxmox/Internal/pxapi/guest/tags/tags_test.go b/proxmox/Internal/pxapi/guest/tags/tags_test.go deleted file mode 100644 index d4e314df..00000000 --- a/proxmox/Internal/pxapi/guest/tags/tags_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package tags - -import ( - "testing" - - pxapi "github.com/Telmate/proxmox-api-go/proxmox" - "github.com/stretchr/testify/require" -) - -func Test_RemoveDuplicates(t *testing.T) { - tests := []struct { - name string - input *[]pxapi.Tag - output *[]pxapi.Tag - }{ - {name: `nil`}, - {name: `empty`, input: &[]pxapi.Tag{}}, - {name: `single`, input: &[]pxapi.Tag{"a"}, output: &[]pxapi.Tag{"a"}}, - {name: `multiple`, input: &[]pxapi.Tag{"b", "a", "c"}, output: &[]pxapi.Tag{"a", "b", "c"}}, - {name: `duplicate`, input: &[]pxapi.Tag{"b", "a", "c", "b", "a"}, output: &[]pxapi.Tag{"a", "b", "c"}}, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - require.Equal(t, test.output, sortArray(RemoveDuplicates(test.input))) - }) - } -} - -func Test_sort(t *testing.T) { - tests := []struct { - name string - input *[]pxapi.Tag - output *[]pxapi.Tag - }{ - {name: `nil`}, - {name: `empty`, input: &[]pxapi.Tag{}}, - {name: `single`, input: &[]pxapi.Tag{"a"}, output: &[]pxapi.Tag{"a"}}, - {name: `multiple`, input: &[]pxapi.Tag{"b", "a", "c"}, output: &[]pxapi.Tag{"a", "b", "c"}}, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - require.Equal(t, test.output, sortArray(test.input)) - }) - } -} - -func Test_Split(t *testing.T) { - tests := []struct { - name string - input string - output *[]pxapi.Tag - }{ - {name: `empty`, output: &[]pxapi.Tag{}}, - {name: `single`, input: "a", output: &[]pxapi.Tag{"a"}}, - {name: `multiple ,`, input: "b,a,c", output: &[]pxapi.Tag{"b", "a", "c"}}, - {name: `multiple ;`, input: "b;a;c", output: &[]pxapi.Tag{"b", "a", "c"}}, - {name: `multiple mixed`, input: "b,a;c,d;e", output: &[]pxapi.Tag{"b", "a", "c", "d", "e"}}, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - require.Equal(t, test.output, Split(test.input)) - }) - } -} - -func Test_String(t *testing.T) { - tests := []struct { - name string - input *[]pxapi.Tag - output string - }{ - {name: `nil`}, - {name: `empty`, input: &[]pxapi.Tag{}}, - {name: `single`, input: &[]pxapi.Tag{"a"}, output: "a"}, - {name: `multiple`, input: &[]pxapi.Tag{"b", "a", "c"}, output: "b;a;c"}, - } - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - require.Equal(t, test.output, String(test.input)) - }) - } -} diff --git a/proxmox/heper_qemu.go b/proxmox/heper_qemu.go index 8fed5b00..efef1429 100644 --- a/proxmox/heper_qemu.go +++ b/proxmox/heper_qemu.go @@ -4,7 +4,7 @@ import ( "net" "strings" - pxapi "github.com/Telmate/proxmox-api-go/proxmox" + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" ) @@ -15,7 +15,7 @@ const ( errorGuestAgentNoIPv6Summary string = "Qemu Guest Agent is enabled but no IPv6 address is found" ) -func parseCloudInitInterface(ipConfig pxapi.CloudInitNetworkConfig, ciCustom, skipIPv4, skipIPv6 bool) (conn connectionInfo) { +func parseCloudInitInterface(ipConfig pveSDK.CloudInitNetworkConfig, ciCustom, skipIPv4, skipIPv6 bool) (conn connectionInfo) { conn.SkipIPv4 = skipIPv4 conn.SkipIPv6 = skipIPv6 if ipConfig.IPv4 != nil { @@ -80,7 +80,7 @@ func (conn connectionInfo) hasRequiredIP() bool { return true } -func (conn connectionInfo) parsePrimaryIPs(interfaces []pxapi.AgentNetworkInterface, mac net.HardwareAddr) connectionInfo { +func (conn connectionInfo) parsePrimaryIPs(interfaces []pveSDK.AgentNetworkInterface, mac net.HardwareAddr) connectionInfo { macString := mac.String() for _, iFace := range interfaces { if iFace.MacAddress.String() == macString { diff --git a/proxmox/heper_qemu_test.go b/proxmox/heper_qemu_test.go index cbc78bbe..103459ff 100644 --- a/proxmox/heper_qemu_test.go +++ b/proxmox/heper_qemu_test.go @@ -4,7 +4,7 @@ import ( "net" "testing" - pxapi "github.com/Telmate/proxmox-api-go/proxmox" + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/util" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/stretchr/testify/require" @@ -152,7 +152,7 @@ func Test_HasRequiredIP(t *testing.T) { func Test_ParseCloudInitInterface(t *testing.T) { type testInput struct { - ci pxapi.CloudInitNetworkConfig + ci pveSDK.CloudInitNetworkConfig ciCustom bool skipIPv4 bool skipIPv6 bool @@ -163,18 +163,18 @@ func Test_ParseCloudInitInterface(t *testing.T) { output connectionInfo }{ {name: `IPv4=DHCP`, - input: testInput{ci: pxapi.CloudInitNetworkConfig{IPv4: &pxapi.CloudInitIPv4Config{ + input: testInput{ci: pveSDK.CloudInitNetworkConfig{IPv4: &pveSDK.CloudInitIPv4Config{ DHCP: true}}}, output: connectionInfo{ SkipIPv6: true}}, {name: `IPv4=DHCP ciCustom`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv4: &pxapi.CloudInitIPv4Config{ + ci: pveSDK.CloudInitNetworkConfig{IPv4: &pveSDK.CloudInitIPv4Config{ DHCP: true}}, ciCustom: true}}, {name: `IPv4=DHCP SkipIPv4`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv4: &pxapi.CloudInitIPv4Config{ + ci: pveSDK.CloudInitNetworkConfig{IPv4: &pveSDK.CloudInitIPv4Config{ DHCP: true}}, skipIPv4: true}, output: connectionInfo{ @@ -182,47 +182,47 @@ func Test_ParseCloudInitInterface(t *testing.T) { SkipIPv6: true}}, {name: `IPv4=DHCP SkipIPv4 ciCustom`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv4: &pxapi.CloudInitIPv4Config{ + ci: pveSDK.CloudInitNetworkConfig{IPv4: &pveSDK.CloudInitIPv4Config{ DHCP: true}}, ciCustom: true, skipIPv4: true}, output: connectionInfo{SkipIPv4: true}}, {name: `IPv4=Static`, - input: testInput{ci: pxapi.CloudInitNetworkConfig{IPv4: &pxapi.CloudInitIPv4Config{ - Address: util.Pointer(pxapi.IPv4CIDR("192.168.1.1/24"))}}}, + input: testInput{ci: pveSDK.CloudInitNetworkConfig{IPv4: &pveSDK.CloudInitIPv4Config{ + Address: util.Pointer(pveSDK.IPv4CIDR("192.168.1.1/24"))}}}, output: connectionInfo{IPs: primaryIPs{ IPv4: "192.168.1.1"}, SkipIPv6: true}}, {name: `IPv4=Static ciCustom`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv4: &pxapi.CloudInitIPv4Config{ - Address: util.Pointer(pxapi.IPv4CIDR("192.168.1.1/24"))}}, + ci: pveSDK.CloudInitNetworkConfig{IPv4: &pveSDK.CloudInitIPv4Config{ + Address: util.Pointer(pveSDK.IPv4CIDR("192.168.1.1/24"))}}, ciCustom: true}, output: connectionInfo{IPs: primaryIPs{IPv4: "192.168.1.1"}}}, {name: `IPv4=Static IPv6=Static`, - input: testInput{ci: pxapi.CloudInitNetworkConfig{ - IPv4: &pxapi.CloudInitIPv4Config{ - Address: util.Pointer(pxapi.IPv4CIDR("192.168.1.1/24"))}, - IPv6: &pxapi.CloudInitIPv6Config{ - Address: util.Pointer(pxapi.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}}, + input: testInput{ci: pveSDK.CloudInitNetworkConfig{ + IPv4: &pveSDK.CloudInitIPv4Config{ + Address: util.Pointer(pveSDK.IPv4CIDR("192.168.1.1/24"))}, + IPv6: &pveSDK.CloudInitIPv6Config{ + Address: util.Pointer(pveSDK.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}}, output: connectionInfo{IPs: primaryIPs{ IPv4: "192.168.1.1", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"}}}, {name: `IPv4=Static IPv6=Static ciCustom`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{ - IPv4: &pxapi.CloudInitIPv4Config{ - Address: util.Pointer(pxapi.IPv4CIDR("192.168.1.1/24"))}, - IPv6: &pxapi.CloudInitIPv6Config{ - Address: util.Pointer(pxapi.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}, + ci: pveSDK.CloudInitNetworkConfig{ + IPv4: &pveSDK.CloudInitIPv4Config{ + Address: util.Pointer(pveSDK.IPv4CIDR("192.168.1.1/24"))}, + IPv6: &pveSDK.CloudInitIPv6Config{ + Address: util.Pointer(pveSDK.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}, ciCustom: true}, output: connectionInfo{IPs: primaryIPs{ IPv4: "192.168.1.1", IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"}}}, {name: `IPv4=Static SkipIPv4`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv4: &pxapi.CloudInitIPv4Config{ - Address: util.Pointer(pxapi.IPv4CIDR("192.168.1.1/24"))}}, + ci: pveSDK.CloudInitNetworkConfig{IPv4: &pveSDK.CloudInitIPv4Config{ + Address: util.Pointer(pveSDK.IPv4CIDR("192.168.1.1/24"))}}, skipIPv4: true}, output: connectionInfo{IPs: primaryIPs{ IPv4: "192.168.1.1"}, @@ -230,25 +230,25 @@ func Test_ParseCloudInitInterface(t *testing.T) { SkipIPv6: true}}, {name: `IPv4=Static SkipIPv4 ciCustom`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv4: &pxapi.CloudInitIPv4Config{ - Address: util.Pointer(pxapi.IPv4CIDR("192.168.1.1/24"))}}, + ci: pveSDK.CloudInitNetworkConfig{IPv4: &pveSDK.CloudInitIPv4Config{ + Address: util.Pointer(pveSDK.IPv4CIDR("192.168.1.1/24"))}}, ciCustom: true, skipIPv4: true}, output: connectionInfo{IPs: primaryIPs{ IPv4: "192.168.1.1"}, SkipIPv4: true}}, {name: `IPv6=DHCP`, - input: testInput{ci: pxapi.CloudInitNetworkConfig{IPv6: &pxapi.CloudInitIPv6Config{ + input: testInput{ci: pveSDK.CloudInitNetworkConfig{IPv6: &pveSDK.CloudInitIPv6Config{ DHCP: true}}}, output: connectionInfo{SkipIPv4: true}}, {name: `IPv6=DHCP ciCustom`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv6: &pxapi.CloudInitIPv6Config{ + ci: pveSDK.CloudInitNetworkConfig{IPv6: &pveSDK.CloudInitIPv6Config{ DHCP: true}}, ciCustom: true}}, {name: `IPv6=DHCP SkipIPv6`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv6: &pxapi.CloudInitIPv6Config{ + ci: pveSDK.CloudInitNetworkConfig{IPv6: &pveSDK.CloudInitIPv6Config{ DHCP: true}}, skipIPv6: true}, output: connectionInfo{ @@ -256,27 +256,27 @@ func Test_ParseCloudInitInterface(t *testing.T) { SkipIPv6: true}}, {name: `IPv6=DHCP SkipIPv6 ciCustom`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv6: &pxapi.CloudInitIPv6Config{ + ci: pveSDK.CloudInitNetworkConfig{IPv6: &pveSDK.CloudInitIPv6Config{ DHCP: true}}, ciCustom: true, skipIPv6: true}, output: connectionInfo{SkipIPv6: true}}, {name: `IPv6=Static`, - input: testInput{ci: pxapi.CloudInitNetworkConfig{IPv6: &pxapi.CloudInitIPv6Config{ - Address: util.Pointer(pxapi.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}}, + input: testInput{ci: pveSDK.CloudInitNetworkConfig{IPv6: &pveSDK.CloudInitIPv6Config{ + Address: util.Pointer(pveSDK.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}}, output: connectionInfo{IPs: primaryIPs{ IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"}, SkipIPv4: true}}, {name: `IPv6=Static ciCustom`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv6: &pxapi.CloudInitIPv6Config{ - Address: util.Pointer(pxapi.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}, + ci: pveSDK.CloudInitNetworkConfig{IPv6: &pveSDK.CloudInitIPv6Config{ + Address: util.Pointer(pveSDK.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}, ciCustom: true}, output: connectionInfo{IPs: primaryIPs{IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"}}}, {name: `IPv6=Static SkipIPv6`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv6: &pxapi.CloudInitIPv6Config{ - Address: util.Pointer(pxapi.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}, + ci: pveSDK.CloudInitNetworkConfig{IPv6: &pveSDK.CloudInitIPv6Config{ + Address: util.Pointer(pveSDK.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}, skipIPv6: true}, output: connectionInfo{IPs: primaryIPs{ IPv6: "2001:0db8:85a3:0000:0000:8a2e:0370:7334"}, @@ -284,8 +284,8 @@ func Test_ParseCloudInitInterface(t *testing.T) { SkipIPv6: true}}, {name: `IPv6=Static SkipIPv6 ciCustom`, input: testInput{ - ci: pxapi.CloudInitNetworkConfig{IPv6: &pxapi.CloudInitIPv6Config{ - Address: util.Pointer(pxapi.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}, + ci: pveSDK.CloudInitNetworkConfig{IPv6: &pveSDK.CloudInitIPv6Config{ + Address: util.Pointer(pveSDK.IPv6CIDR("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64"))}}, ciCustom: true, skipIPv6: true}, output: connectionInfo{IPs: primaryIPs{ @@ -312,7 +312,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { return net.ParseIP(ip).String() } type testInput struct { - interfaces []pxapi.AgentNetworkInterface + interfaces []pveSDK.AgentNetworkInterface mac net.HardwareAddr conn connectionInfo } @@ -324,7 +324,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { {name: `Only Loopback`, input: testInput{ mac: parseMac("9c:7a:1b:4f:3e:a2"), - interfaces: []pxapi.AgentNetworkInterface{ + interfaces: []pveSDK.AgentNetworkInterface{ { MacAddress: parseMac("9C:7A:1B:4F:3E:A2"), Name: "eth1", @@ -334,7 +334,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { {name: `Only IPv4`, input: testInput{ mac: parseMac("3A:7E:9D:1F:5B:8C"), - interfaces: []pxapi.AgentNetworkInterface{ + interfaces: []pveSDK.AgentNetworkInterface{ {MacAddress: parseMac("3A:7E:9D:1F:5B:8C"), Name: "eth1", IpAddresses: []net.IP{ @@ -345,7 +345,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { {name: `Only IPv6`, input: testInput{ mac: parseMac("6F:2C:4A:8E:7D:1B"), - interfaces: []pxapi.AgentNetworkInterface{ + interfaces: []pveSDK.AgentNetworkInterface{ {MacAddress: parseMac("6F:2C:4A:8E:7D:1B"), Name: "eth1", IpAddresses: []net.IP{ @@ -356,7 +356,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { {name: `Full test`, input: testInput{ mac: parseMac("3A:7E:9D:1F:5B:8C"), - interfaces: []pxapi.AgentNetworkInterface{ + interfaces: []pveSDK.AgentNetworkInterface{ {MacAddress: parseMac("6F:2C:4A:8E:7D:1B"), Name: "lo", IpAddresses: []net.IP{ @@ -381,7 +381,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { {name: `IPv4 Already Set`, input: testInput{ mac: parseMac("3A:7E:9D:1F:5B:8C"), - interfaces: []pxapi.AgentNetworkInterface{ + interfaces: []pveSDK.AgentNetworkInterface{ {MacAddress: parseMac("3A:7E:9D:1F:5B:8C"), IpAddresses: []net.IP{parseIP("192.168.1.1/24")}}}, conn: connectionInfo{IPs: primaryIPs{IPv4: formatIP("10.10.1.1")}}}, @@ -389,7 +389,7 @@ func Test_ParsePrimaryIPs(t *testing.T) { {name: `IPv6 Already Set`, input: testInput{ mac: parseMac("3A:7E:9D:1F:5B:8C"), - interfaces: []pxapi.AgentNetworkInterface{ + interfaces: []pveSDK.AgentNetworkInterface{ {MacAddress: parseMac("3A:7E:9D:1F:5B:8C"), IpAddresses: []net.IP{parseIP("2001:0db8:85a3:0000:0000:8a2e:0370:7334/64")}}}, conn: connectionInfo{IPs: primaryIPs{IPv6: formatIP("3ffe:1900:4545:3:200:f8ff:fe21:67cf")}}}, diff --git a/proxmox/provider.go b/proxmox/provider.go index 1090d03f..00b8ba9d 100644 --- a/proxmox/provider.go +++ b/proxmox/provider.go @@ -11,7 +11,7 @@ import ( "strings" "sync" - pxapi "github.com/Telmate/proxmox-api-go/proxmox" + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/validator" "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -38,7 +38,7 @@ const ( ) type providerConfiguration struct { - Client *pxapi.Client + Client *pveSDK.Client MaxParallel int CurrentParallel int MaxVMID int @@ -261,7 +261,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { } else if result, getok := d.GetOk(schemaPmUser); getok { id = result.(string) } - userID, err := pxapi.NewUserID(id) + userID, err := pveSDK.NewUserID(id) if err != nil { return nil, err } @@ -320,7 +320,7 @@ func getClient(pm_api_url string, pm_http_headers string, pm_timeout int, pm_debug bool, - pm_proxy_server string) (*pxapi.Client, error) { + pm_proxy_server string) (*pveSDK.Client, error) { tlsconf := &tls.Config{InsecureSkipVerify: true} if !pm_tls_insecure { @@ -345,8 +345,8 @@ func getClient(pm_api_url string, err = fmt.Errorf("your API TokenID username should contain a !, check your API credentials") } - client, _ := pxapi.NewClient(pm_api_url, nil, pm_http_headers, tlsconf, pm_proxy_server, pm_timeout) - *pxapi.Debug = pm_debug + client, _ := pveSDK.NewClient(pm_api_url, nil, pm_http_headers, tlsconf, pm_proxy_server, pm_timeout) + *pveSDK.Debug = pm_debug // User+Pass authentication if pm_user != "" && pm_password != "" { @@ -417,7 +417,7 @@ func pmParallelBegin(pconf *providerConfiguration) *pmApiLockHolder { return lock } -func resourceId(targetNode pxapi.NodeName, resType string, vmId int) string { +func resourceId(targetNode pveSDK.NodeName, resType string, vmId int) string { return fmt.Sprintf("%s/%s/%d", targetNode.String(), resType, vmId) } diff --git a/proxmox/resource_lxc.go b/proxmox/resource_lxc.go index 9524449d..cb157903 100644 --- a/proxmox/resource_lxc.go +++ b/proxmox/resource_lxc.go @@ -8,8 +8,8 @@ import ( "strings" "time" - pxapi "github.com/Telmate/proxmox-api-go/proxmox" - "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/guest/tags" + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" + "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pve/guest/tags" "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/node" "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/util" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -448,7 +448,7 @@ func resourceLxcCreate(ctx context.Context, d *schema.ResourceData, meta interfa client := pconf.Client - config := pxapi.NewConfigLxc() + config := pveSDK.NewConfigLxc() config.Ostemplate = d.Get("ostemplate").(string) config.Arch = d.Get("arch").(string) config.BWLimit = d.Get("bwlimit").(int) @@ -480,7 +480,7 @@ func resourceLxcCreate(ctx context.Context, d *schema.ResourceData, meta interfa config.OnBoot = d.Get("onboot").(bool) config.OsType = d.Get("ostype").(string) config.Password = d.Get("password").(string) - config.Pool = util.Pointer(pxapi.PoolName(d.Get("pool").(string))) + config.Pool = util.Pointer(pveSDK.PoolName(d.Get("pool").(string))) config.Protection = d.Get("protection").(bool) config.Restore = d.Get("restore").(bool) config.SearchDomain = d.Get("searchdomain").(string) @@ -494,7 +494,7 @@ func resourceLxcCreate(ctx context.Context, d *schema.ResourceData, meta interfa config.Unique = d.Get("unique").(bool) config.Unprivileged = d.Get("unprivileged").(bool) - targetNode := pxapi.NodeName(d.Get(node.RootNode).(string)) + targetNode := pveSDK.NodeName(d.Get(node.RootNode).(string)) // proxmox api allows multiple network sets, // having a unique 'id' parameter foreach set @@ -529,7 +529,7 @@ func resourceLxcCreate(ctx context.Context, d *schema.ResourceData, meta interfa } } - vmr := pxapi.NewVmRef(nextid) + vmr := pveSDK.NewVmRef(nextid) vmr.SetNode(targetNode.String()) if d.Get("clone").(string) != "" { @@ -546,10 +546,10 @@ func resourceLxcCreate(ctx context.Context, d *schema.ResourceData, meta interfa // read back all the current disk configurations from proxmox // this allows us to receive updates on the post-clone state of the container we're building log.Print("[DEBUG][LxcCreate] Waiting for clone becoming ready") - var config_post_clone *pxapi.ConfigLxc + var config_post_clone *pveSDK.ConfigLxc for { // Wait until we can actually retrieve the config from the cloned machine - config_post_clone, err = pxapi.NewConfigLxcFromApi(ctx, vmr, client) + config_post_clone, err = pveSDK.NewConfigLxcFromApi(ctx, vmr, client) if config_post_clone != nil { break // to prevent an infinite loop we check for any other error @@ -566,7 +566,7 @@ func resourceLxcCreate(ctx context.Context, d *schema.ResourceData, meta interfa log.Print("[DEBUG][LxcCreate] We must resize") processDiskResize(ctx, config_post_clone.RootFs, config.RootFs, "rootfs", pconf, vmr) } - config_post_resize, err := pxapi.NewConfigLxcFromApi(ctx, vmr, client) + config_post_resize, err := pveSDK.NewConfigLxcFromApi(ctx, vmr, client) if err != nil { return diag.FromErr(err) } @@ -616,13 +616,13 @@ func resourceLxcUpdate(ctx context.Context, d *schema.ResourceData, meta interfa if err != nil { return diag.FromErr(err) } - vmr := pxapi.NewVmRef(vmID) + vmr := pveSDK.NewVmRef(vmID) _, err = client.GetVmInfo(ctx, vmr) if err != nil { return diag.FromErr(err) } - config := pxapi.NewConfigLxc() + config := pveSDK.NewConfigLxc() config.Ostemplate = d.Get("ostemplate").(string) config.Arch = d.Get("arch").(string) config.BWLimit = d.Get("bwlimit").(int) @@ -651,7 +651,7 @@ func resourceLxcUpdate(ctx context.Context, d *schema.ResourceData, meta interfa config.OnBoot = d.Get("onboot").(bool) config.OsType = d.Get("ostype").(string) config.Password = d.Get("password").(string) - config.Pool = util.Pointer(pxapi.PoolName(d.Get("pool").(string))) + config.Pool = util.Pointer(pveSDK.PoolName(d.Get("pool").(string))) config.Protection = d.Get("protection").(bool) config.Restore = d.Get("restore").(bool) config.SearchDomain = d.Get("searchdomain").(string) @@ -683,7 +683,7 @@ func resourceLxcUpdate(ctx context.Context, d *schema.ResourceData, meta interfa // Drop all the ids since they can't be sent to the API newNetworks, _ = DropElementsFromMap([]string{"id"}, newNetworks) // Convert from []map[string]interface{} to pxapi.QemuDevices - lxcNetworks := make(pxapi.QemuDevices, 0) + lxcNetworks := make(pveSDK.QemuDevices, 0) for index, network := range newNetworks { lxcNetworks[index] = network } @@ -726,7 +726,7 @@ func resourceLxcUpdate(ctx context.Context, d *schema.ResourceData, meta interfa return a.(string), b.(string) }() - vmr := pxapi.NewVmRef(vmID) + vmr := pveSDK.NewVmRef(vmID) vmr.SetPool(oldPool) _, err := client.UpdateVMPool(ctx, vmr, newPool) @@ -773,12 +773,12 @@ func _resourceLxcRead(ctx context.Context, d *schema.ResourceData, meta interfac d.SetId("") return err } - vmr := pxapi.NewVmRef(vmID) + vmr := pveSDK.NewVmRef(vmID) _, err = client.GetVmInfo(ctx, vmr) if err != nil { return err } - config, err := pxapi.NewConfigLxcFromApi(ctx, vmr, client) + config, err := pveSDK.NewConfigLxcFromApi(ctx, vmr, client) if err != nil { return err } @@ -902,10 +902,10 @@ func _resourceLxcRead(ctx context.Context, d *schema.ResourceData, meta interfac func processLxcDiskChanges( ctx context.Context, prevDiskSet KeyedDeviceMap, newDiskSet KeyedDeviceMap, pconf *providerConfiguration, - vmr *pxapi.VmRef, + vmr *pveSDK.VmRef, ) error { // 1. Delete slots that either a. Don't exist in the new set or b. Have a different volume in the new set - deleteDisks := []pxapi.QemuDevice{} + deleteDisks := []pveSDK.QemuDevice{} for key, prevDisk := range prevDiskSet { newDisk, ok := (newDiskSet)[key] // The Rootfs can't be deleted @@ -950,7 +950,7 @@ func processLxcDiskChanges( } if !ok || newDisk["slot"] != prevDisk["slot"] { - newParams[diskName] = pxapi.FormatDiskParam(newDisk) + newParams[diskName] = pveSDK.FormatDiskParam(newDisk) } } if len(newParams) > 0 { @@ -1001,14 +1001,14 @@ func processLxcDiskChanges( for _, newDisk := range newDiskSet { diskName := diskSlotName(newDisk) apiConfigStr := apiResult[diskName].(string) - apiDevice := pxapi.ParsePMConf(apiConfigStr, "volume") + apiDevice := pveSDK.ParsePMConf(apiConfigStr, "volume") newDisk["volume"] = apiDevice["volume"] } return nil } -func diskSlotName(disk pxapi.QemuDevice) string { +func diskSlotName(disk pveSDK.QemuDevice) string { diskType, ok := disk["type"].(string) if !ok || diskType == "" { diskType = "mp" @@ -1022,9 +1022,9 @@ func diskSlotName(disk pxapi.QemuDevice) string { func processDiskResize( ctx context.Context, - prevDisk pxapi.QemuDevice, newDisk pxapi.QemuDevice, + prevDisk pveSDK.QemuDevice, newDisk pveSDK.QemuDevice, diskName string, - pconf *providerConfiguration, vmr *pxapi.VmRef, + pconf *providerConfiguration, vmr *pveSDK.VmRef, ) error { newSize, ok := newDisk["size"] if ok && newSize != prevDisk["size"] { @@ -1037,7 +1037,7 @@ func processDiskResize( return nil } -func processLxcNetworkChanges(ctx context.Context, prevNetworks []map[string]interface{}, newNetworks []map[string]interface{}, pconf *providerConfiguration, vmr *pxapi.VmRef) error { +func processLxcNetworkChanges(ctx context.Context, prevNetworks []map[string]interface{}, newNetworks []map[string]interface{}, pconf *providerConfiguration, vmr *pveSDK.VmRef) error { delNetworks := make([]map[string]interface{}, 0) // Collect the IDs of networks that exist in `prevNetworks` but not in `newNetworks`. diff --git a/proxmox/resource_lxc_disk.go b/proxmox/resource_lxc_disk.go index 16792712..40ab061f 100644 --- a/proxmox/resource_lxc_disk.go +++ b/proxmox/resource_lxc_disk.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - pxapi "github.com/Telmate/proxmox-api-go/proxmox" + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -122,7 +122,7 @@ func resourceLxcDiskCreate(ctx context.Context, d *schema.ResourceData, meta int } client := pconf.Client - vmr := pxapi.NewVmRef(vmID) + vmr := pveSDK.NewVmRef(vmID) vmr.SetVmType("lxc") _, err = client.GetVmInfo(ctx, vmr) if err != nil { @@ -141,7 +141,7 @@ func resourceLxcDiskCreate(ctx context.Context, d *schema.ResourceData, meta int params := map[string]interface{}{} mpName := fmt.Sprintf("mp%v", d.Get("slot").(int)) - params[mpName] = pxapi.FormatDiskParam(disk) + params[mpName] = pveSDK.FormatDiskParam(disk) exitStatus, err := pconf.Client.SetLxcConfig(ctx, vmr, params) if err != nil { return diag.Errorf("error updating LXC Mountpoint: %v, error status: %s (params: %v)", err, exitStatus, params) @@ -166,7 +166,7 @@ func resourceLxcDiskUpdate(ctx context.Context, d *schema.ResourceData, meta int return diag.FromErr(err) } - vmr := pxapi.NewVmRef(vmID) + vmr := pveSDK.NewVmRef(vmID) _, err = client.GetVmInfo(ctx, vmr) if err != nil { return diag.FromErr(err) @@ -201,7 +201,7 @@ func _resourceLxcDiskRead(ctx context.Context, d *schema.ResourceData, meta inte return err } - vmr := pxapi.NewVmRef(vmID) + vmr := pveSDK.NewVmRef(vmID) _, err = client.GetVmInfo(ctx, vmr) if err != nil { return err @@ -214,7 +214,7 @@ func _resourceLxcDiskRead(ctx context.Context, d *schema.ResourceData, meta inte diskName := fmt.Sprintf("mp%v", d.Get("slot").(int)) diskString := apiResult[diskName].(string) - disk := pxapi.ParseLxcDisk(diskString) + disk := pveSDK.ParseLxcDisk(diskString) disk["slot"] = d.Get("slot").(int) d.SetId(disk["volume"].(string)) @@ -244,7 +244,7 @@ func resourceLxcDiskDelete(ctx context.Context, d *schema.ResourceData, meta int } client := pconf.Client - vmr := pxapi.NewVmRef(vmID) + vmr := pveSDK.NewVmRef(vmID) _, err = client.GetVmInfo(ctx, vmr) if err != nil { return diag.FromErr(err) diff --git a/proxmox/resource_pool.go b/proxmox/resource_pool.go index 47b54154..8ce78524 100644 --- a/proxmox/resource_pool.go +++ b/proxmox/resource_pool.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - pxapi "github.com/Telmate/proxmox-api-go/proxmox" + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/util" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -50,8 +50,8 @@ func resourcePoolCreate(ctx context.Context, d *schema.ResourceData, meta interf poolid := d.Get("poolid").(string) - err := pxapi.ConfigPool{ - Name: pxapi.PoolName(poolid), + err := pveSDK.ConfigPool{ + Name: pveSDK.PoolName(poolid), Comment: util.Pointer(d.Get("comment").(string)), }.Create(ctx, client) if err != nil { @@ -80,7 +80,7 @@ func _resourcePoolRead(ctx context.Context, d *schema.ResourceData, meta interfa return fmt.Errorf("unexpected error when trying to read and parse resource id: %v", err) } - pool := pxapi.PoolName(poolID) + pool := pveSDK.PoolName(poolID) logger, _ := CreateSubLogger("resource_pool_read") logger.Info().Str("poolid", poolID).Msg("Reading configuration for poolid") @@ -118,8 +118,8 @@ func resourcePoolUpdate(ctx context.Context, d *schema.ResourceData, meta interf logger.Info().Str("poolid", poolID).Msg("Starting update of the Pool resource") if d.HasChange("comment") { - err := pxapi.ConfigPool{ - Name: pxapi.PoolName(poolID), + err := pveSDK.ConfigPool{ + Name: pveSDK.PoolName(poolID), Comment: util.Pointer(d.Get("comment").(string)), }.Update(ctx, client) if err != nil { @@ -141,7 +141,7 @@ func resourcePoolDelete(ctx context.Context, d *schema.ResourceData, meta interf if err != nil { return diag.FromErr(err) } - if err = pxapi.PoolName(poolID).Delete(ctx, client); err != nil { + if err = pveSDK.PoolName(poolID).Delete(ctx, client); err != nil { return diag.FromErr(err) } diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index 76edfdab..cd662d8d 100755 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -16,7 +16,7 @@ import ( "strings" "time" - pxapi "github.com/Telmate/proxmox-api-go/proxmox" + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" "github.com/google/uuid" "github.com/hashicorp/go-cty/cty" @@ -25,9 +25,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/dns/nameservers" - "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/guest/sshkeys" - "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pxapi/guest/tags" + "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pve/dns/nameservers" + "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pve/guest/sshkeys" + "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/pve/guest/tags" "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/node" "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/qemu/cpu" "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/qemu/disk" @@ -649,7 +649,7 @@ func resourceVmQemu() *schema.Resource { return thisResource } -func getSourceVmr(ctx context.Context, client *pxapi.Client, name string, id int, targetNode pxapi.NodeName) (*pxapi.VmRef, error) { +func getSourceVmr(ctx context.Context, client *pveSDK.Client, name string, id int, targetNode pveSDK.NodeName) (*pveSDK.VmRef, error) { if name != "" { sourceVmrs, err := client.GetVmRefsByName(ctx, name) if err != nil { @@ -691,11 +691,11 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte qemuEfiDisks, _ := ExpandDevicesList(d.Get("efidisk").([]interface{})) - config := pxapi.ConfigQemu{ + config := pveSDK.ConfigQemu{ Name: vmName, CPU: cpu.SDK(d), Description: util.Pointer(d.Get("desc").(string)), - Pool: util.Pointer(pxapi.PoolName(d.Get("pool").(string))), + Pool: util.Pointer(pveSDK.PoolName(d.Get("pool").(string))), Bios: d.Get("bios").(string), Onboot: util.Pointer(d.Get("onboot").(bool)), Startup: d.Get("startup").(string), @@ -759,12 +759,12 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte targetNodes[i] = raw.(string) } - var targetNode pxapi.NodeName + var targetNode pveSDK.NodeName if len(targetNodes) == 0 { - targetNode = pxapi.NodeName(d.Get(node.RootNode).(string)) + targetNode = pveSDK.NodeName(d.Get(node.RootNode).(string)) } else { - targetNode = pxapi.NodeName(targetNodes[rand.Intn(len(targetNodes))]) + targetNode = pveSDK.NodeName(targetNodes[rand.Intn(len(targetNodes))]) } if targetNode == "" { @@ -793,7 +793,7 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte } } - vmr = pxapi.NewVmRef(nextid) + vmr = pveSDK.NewVmRef(nextid) vmr.SetNode(targetNode.String()) config.Node = targetNode @@ -922,7 +922,7 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte logger.Info().Int("vmid", vmID).Msg("Starting update of the VM resource") - vmr := pxapi.NewVmRef(vmID) + vmr := pveSDK.NewVmRef(vmID) _, err = client.GetVmInfo(ctx, vmr) if err != nil { return diag.FromErr(err) @@ -937,11 +937,11 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte } d.Partial(false) - config := pxapi.ConfigQemu{ + config := pveSDK.ConfigQemu{ Name: d.Get("name").(string), CPU: cpu.SDK(d), Description: util.Pointer(d.Get("desc").(string)), - Pool: util.Pointer(pxapi.PoolName(d.Get("pool").(string))), + Pool: util.Pointer(pveSDK.PoolName(d.Get("pool").(string))), Bios: d.Get("bios").(string), Onboot: util.Pointer(d.Get("onboot").(bool)), Startup: d.Get("startup").(string), @@ -1163,18 +1163,18 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf } logger.Info().Int("vmid", vmID).Msg("Reading configuration for vmid") - vmr := pxapi.NewVmRef(vmID) + vmr := pveSDK.NewVmRef(vmID) // Try to get information on the vm. If this call err's out // that indicates the VM does not exist. We indicate that to terraform // by calling a SetId("") // loop through all virtual servers...? - var targetNodeVMR pxapi.NodeName + var targetNodeVMR pveSDK.NodeName targetNodesRaw := d.Get(node.RootNodes).([]interface{}) - targetNodes := make([]pxapi.NodeName, len(targetNodesRaw)) + targetNodes := make([]pveSDK.NodeName, len(targetNodesRaw)) for i := range targetNodesRaw { - targetNodes[i] = pxapi.NodeName(targetNodesRaw[i].(string)) + targetNodes[i] = pveSDK.NodeName(targetNodesRaw[i].(string)) } if len(targetNodes) == 0 { @@ -1205,7 +1205,7 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf return nil } - config, err := pxapi.NewConfigQemuFromApi(ctx, vmr, client) + config, err := pveSDK.NewConfigQemuFromApi(ctx, vmr, client) if err != nil { return diag.FromErr(err) } @@ -1325,7 +1325,7 @@ func resourceVmQemuDelete(ctx context.Context, d *schema.ResourceData, meta inte client := pconf.Client vmId, _ := strconv.Atoi(path.Base(d.Id())) - vmr := pxapi.NewVmRef(vmId) + vmr := pveSDK.NewVmRef(vmId) vmState, err := client.GetVmState(ctx, vmr) if err != nil { return diag.FromErr(err) @@ -1357,10 +1357,10 @@ func resourceVmQemuDelete(ctx context.Context, d *schema.ResourceData, meta inte // Converting from schema.TypeSet to map of id and conf for each device, // which will be sent to Proxmox API. -func DevicesSetToMap(devicesSet *schema.Set) (pxapi.QemuDevices, error) { +func DevicesSetToMap(devicesSet *schema.Set) (pveSDK.QemuDevices, error) { var err error - devicesMap := pxapi.QemuDevices{} + devicesMap := pveSDK.QemuDevices{} for _, set := range devicesSet.List() { setMap, isMap := set.(map[string]interface{}) @@ -1391,7 +1391,7 @@ func DropElementsFromMap(elements []string, mapList []map[string]interface{}) ([ // Consumes an API return (pxapi.QemuDevices) and "flattens" it into a []map[string]interface{} as // expected by the terraform interface for TypeList -func FlattenDevicesList(proxmoxDevices pxapi.QemuDevices) ([]map[string]interface{}, error) { +func FlattenDevicesList(proxmoxDevices pveSDK.QemuDevices) ([]map[string]interface{}, error) { flattenedDevices := make([]map[string]interface{}, 0, 1) numDevices := len(proxmoxDevices) @@ -1489,8 +1489,8 @@ func ReadSmbiosArgs(smbios string) []interface{} { // Consumes a terraform TypeList of a Qemu Device (network, hard drive, etc) and returns the "Expanded" // version of the equivalent configuration that the API understands (the struct pxapi.QemuDevices). // NOTE this expects the provided deviceList to be []map[string]interface{}. -func ExpandDevicesList(deviceList []interface{}) (pxapi.QemuDevices, error) { - expandedDevices := make(pxapi.QemuDevices) +func ExpandDevicesList(deviceList []interface{}) (pveSDK.QemuDevices, error) { + expandedDevices := make(pveSDK.QemuDevices) if len(deviceList) == 0 { return expandedDevices, nil @@ -1523,7 +1523,7 @@ func ExpandDevicesList(deviceList []interface{}) (pxapi.QemuDevices, error) { // TODO: remove these set functions and convert attributes using a set to a list instead. func UpdateDevicesSet( devicesSet *schema.Set, - devicesMap pxapi.QemuDevices, + devicesMap pveSDK.QemuDevices, idKey string, ) *schema.Set { @@ -1543,7 +1543,7 @@ func UpdateDevicesSet( return devicesSet } -func initConnInfo(ctx context.Context, d *schema.ResourceData, client *pxapi.Client, vmr *pxapi.VmRef, config *pxapi.ConfigQemu, hasCiDisk bool) diag.Diagnostics { +func initConnInfo(ctx context.Context, d *schema.ResourceData, client *pveSDK.Client, vmr *pveSDK.VmRef, config *pveSDK.ConfigQemu, hasCiDisk bool) diag.Diagnostics { logger, _ := CreateSubLogger("initConnInfo") var diags diag.Diagnostics // allow user to opt-out of setting the connection info for the resource @@ -1609,7 +1609,7 @@ func initConnInfo(ctx context.Context, d *schema.ResourceData, client *pxapi.Cli return diags } -func getPrimaryIP(ctx context.Context, cloudInit *pxapi.CloudInit, networks pxapi.QemuNetworkInterfaces, vmr *pxapi.VmRef, client *pxapi.Client, endTime time.Time, additionalWait, agentTimeout int, ciAgentEnabled, skipIPv4, skipIPv6, hasCiDisk bool) (primaryIPs, diag.Diagnostics) { +func getPrimaryIP(ctx context.Context, cloudInit *pveSDK.CloudInit, networks pveSDK.QemuNetworkInterfaces, vmr *pveSDK.VmRef, client *pveSDK.Client, endTime time.Time, additionalWait, agentTimeout int, ciAgentEnabled, skipIPv4, skipIPv6, hasCiDisk bool) (primaryIPs, diag.Diagnostics) { logger, _ := CreateSubLogger("getPrimaryIP") // TODO allow the primary interface to be a different one than the first @@ -1625,7 +1625,7 @@ func getPrimaryIP(ctx context.Context, cloudInit *pxapi.CloudInit, networks pxap if cloudInit.Custom != nil && cloudInit.Custom.Network != nil { cicustom = true } - conn = parseCloudInitInterface(cloudInit.NetworkInterfaces[pxapi.QemuNetworkInterfaceID0], cicustom, conn.SkipIPv4, conn.SkipIPv6) + conn = parseCloudInitInterface(cloudInit.NetworkInterfaces[pveSDK.QemuNetworkInterfaceID0], cicustom, conn.SkipIPv4, conn.SkipIPv6) // early return, we have all information we wanted if conn.hasRequiredIP() { if conn.IPs.IPv4 == "" && conn.IPs.IPv6 == "" { @@ -1651,13 +1651,13 @@ func getPrimaryIP(ctx context.Context, cloudInit *pxapi.CloudInit, networks pxap err error ) for i := 0; i < network.AmountNetworkInterfaces; i++ { - if v, ok := networks[pxapi.QemuNetworkInterfaceID(i)]; ok && v.MAC != nil { + if v, ok := networks[pveSDK.QemuNetworkInterfaceID(i)]; ok && v.MAC != nil { primaryMacAddress = *v.MAC break } } for time.Now().Before(endTime) { - var interfaces []pxapi.AgentNetworkInterface + var interfaces []pveSDK.AgentNetworkInterface interfaces, err = vmr.GetAgentInformation(ctx, client, false) if err != nil { if !strings.Contains(err.Error(), ErrorGuestAgentNotRunning) { @@ -1697,7 +1697,7 @@ func getPrimaryIP(ctx context.Context, cloudInit *pxapi.CloudInit, networks pxap // Map struct to the terraform schema -func mapToTerraform_CloudInit(config *pxapi.CloudInit, d *schema.ResourceData) { +func mapToTerraform_CloudInit(config *pveSDK.CloudInit, d *schema.ResourceData) { if config == nil { return } @@ -1713,7 +1713,7 @@ func mapToTerraform_CloudInit(config *pxapi.CloudInit, d *schema.ResourceData) { d.Set("searchdomain", config.DNS.SearchDomain) d.Set("nameserver", nameservers.String(config.DNS.NameServers)) } - for i := pxapi.QemuNetworkInterfaceID(0); i < 16; i++ { + for i := pveSDK.QemuNetworkInterfaceID(0); i < 16; i++ { if v, isSet := config.NetworkInterfaces[i]; isSet { d.Set("ipconfig"+strconv.Itoa(int(i)), mapToTerraform_CloudInitNetworkConfig(v)) } @@ -1724,7 +1724,7 @@ func mapToTerraform_CloudInit(config *pxapi.CloudInit, d *schema.ResourceData) { } } -func mapToTerraform_CloudInitNetworkConfig(config pxapi.CloudInitNetworkConfig) string { +func mapToTerraform_CloudInitNetworkConfig(config pveSDK.CloudInitNetworkConfig) string { if config.IPv4 != nil { if config.IPv6 != nil { return config.IPv4.String() + "," + config.IPv6.String() @@ -1746,7 +1746,7 @@ func mapToTerraform_Description(description *string) string { return "" } -func mapToTerraform_Memory(config *pxapi.QemuMemory, d *schema.ResourceData) { +func mapToTerraform_Memory(config *pveSDK.QemuMemory, d *schema.ResourceData) { // no nil check as pxapi.QemuMemory is always returned if config.CapacityMiB != nil { d.Set("memory", int(*config.CapacityMiB)) @@ -1756,7 +1756,7 @@ func mapToTerraform_Memory(config *pxapi.QemuMemory, d *schema.ResourceData) { } } -func mapFromStruct_QemuGuestAgent(d *schema.ResourceData, config *pxapi.QemuGuestAgent) { +func mapFromStruct_QemuGuestAgent(d *schema.ResourceData, config *pveSDK.QemuGuestAgent) { if config == nil { return } @@ -1771,19 +1771,19 @@ func mapFromStruct_QemuGuestAgent(d *schema.ResourceData, config *pxapi.QemuGues // Map the terraform schema to sdk struct -func mapToSDK_CloudInit(d *schema.ResourceData) *pxapi.CloudInit { - ci := pxapi.CloudInit{ - Custom: &pxapi.CloudInitCustom{ - Meta: &pxapi.CloudInitSnippet{}, - Network: &pxapi.CloudInitSnippet{}, - User: &pxapi.CloudInitSnippet{}, - Vendor: &pxapi.CloudInitSnippet{}, +func mapToSDK_CloudInit(d *schema.ResourceData) *pveSDK.CloudInit { + ci := pveSDK.CloudInit{ + Custom: &pveSDK.CloudInitCustom{ + Meta: &pveSDK.CloudInitSnippet{}, + Network: &pveSDK.CloudInitSnippet{}, + User: &pveSDK.CloudInitSnippet{}, + Vendor: &pveSDK.CloudInitSnippet{}, }, - DNS: &pxapi.GuestDNS{ + DNS: &pveSDK.GuestDNS{ SearchDomain: util.Pointer(d.Get("searchdomain").(string)), NameServers: nameservers.Split(d.Get("nameserver").(string)), }, - NetworkInterfaces: pxapi.CloudInitNetworkInterfaces{}, + NetworkInterfaces: pveSDK.CloudInitNetworkInterfaces{}, PublicSSHkeys: sshkeys.Split(d.Get("sshkeys").(string)), UpgradePackages: util.Pointer(d.Get("ciupgrade").(bool)), UserPassword: util.Pointer(d.Get("cipassword").(string)), @@ -1803,32 +1803,32 @@ func mapToSDK_CloudInit(d *schema.ResourceData) *pxapi.CloudInit { ci.Custom.Vendor = mapToSDK_CloudInitSnippet(v) } for i := 0; i < 16; i++ { - ci.NetworkInterfaces[pxapi.QemuNetworkInterfaceID(i)] = mapToSDK_CloudInitNetworkConfig(d.Get("ipconfig" + strconv.Itoa(i)).(string)) + ci.NetworkInterfaces[pveSDK.QemuNetworkInterfaceID(i)] = mapToSDK_CloudInitNetworkConfig(d.Get("ipconfig" + strconv.Itoa(i)).(string)) } return &ci } -func mapToSDK_CloudInitNetworkConfig(param string) pxapi.CloudInitNetworkConfig { - config := pxapi.CloudInitNetworkConfig{ - IPv4: &pxapi.CloudInitIPv4Config{ - Address: util.Pointer(pxapi.IPv4CIDR("")), +func mapToSDK_CloudInitNetworkConfig(param string) pveSDK.CloudInitNetworkConfig { + config := pveSDK.CloudInitNetworkConfig{ + IPv4: &pveSDK.CloudInitIPv4Config{ + Address: util.Pointer(pveSDK.IPv4CIDR("")), DHCP: false, - Gateway: util.Pointer(pxapi.IPv4Address(""))}, - IPv6: &pxapi.CloudInitIPv6Config{ - Address: util.Pointer(pxapi.IPv6CIDR("")), + Gateway: util.Pointer(pveSDK.IPv4Address(""))}, + IPv6: &pveSDK.CloudInitIPv6Config{ + Address: util.Pointer(pveSDK.IPv6CIDR("")), DHCP: false, - Gateway: util.Pointer(pxapi.IPv6Address("")), + Gateway: util.Pointer(pveSDK.IPv6Address("")), SLAAC: false}} params := splitStringOfSettings(param) if v, isSet := params["ip"]; isSet { if v == "dhcp" { config.IPv4.DHCP = true } else { - *config.IPv4.Address = pxapi.IPv4CIDR(v) + *config.IPv4.Address = pveSDK.IPv4CIDR(v) } } if v, isSet := params["gw"]; isSet { - *config.IPv4.Gateway = pxapi.IPv4Address(v) + *config.IPv4.Gateway = pveSDK.IPv4Address(v) } if v, isSet := params["ip6"]; isSet { switch v { @@ -1837,39 +1837,39 @@ func mapToSDK_CloudInitNetworkConfig(param string) pxapi.CloudInitNetworkConfig case "auto": config.IPv6.SLAAC = true default: - *config.IPv6.Address = pxapi.IPv6CIDR(v) + *config.IPv6.Address = pveSDK.IPv6CIDR(v) } } if v, isSet := params["gw6"]; isSet { - *config.IPv6.Gateway = pxapi.IPv6Address(v) + *config.IPv6.Gateway = pveSDK.IPv6Address(v) } return config } -func mapToSDK_CloudInitSnippet(param string) *pxapi.CloudInitSnippet { +func mapToSDK_CloudInitSnippet(param string) *pveSDK.CloudInitSnippet { file := strings.SplitN(param, ":", 2) if len(file) == 2 { - return &pxapi.CloudInitSnippet{ + return &pveSDK.CloudInitSnippet{ Storage: file[0], - FilePath: pxapi.CloudInitSnippetPath(file[1])} + FilePath: pveSDK.CloudInitSnippetPath(file[1])} } return nil } -func mapToSDK_Memory(d *schema.ResourceData) *pxapi.QemuMemory { - return &pxapi.QemuMemory{ - CapacityMiB: util.Pointer(pxapi.QemuMemoryCapacity(d.Get("memory").(int))), - MinimumCapacityMiB: util.Pointer(pxapi.QemuMemoryBalloonCapacity(d.Get("balloon").(int))), - Shares: util.Pointer(pxapi.QemuMemoryShares(0)), +func mapToSDK_Memory(d *schema.ResourceData) *pveSDK.QemuMemory { + return &pveSDK.QemuMemory{ + CapacityMiB: util.Pointer(pveSDK.QemuMemoryCapacity(d.Get("memory").(int))), + MinimumCapacityMiB: util.Pointer(pveSDK.QemuMemoryBalloonCapacity(d.Get("balloon").(int))), + Shares: util.Pointer(pveSDK.QemuMemoryShares(0)), } } -func mapToSDK_QemuGuestAgent(d *schema.ResourceData) *pxapi.QemuGuestAgent { +func mapToSDK_QemuGuestAgent(d *schema.ResourceData) *pveSDK.QemuGuestAgent { var tmpEnable bool if d.Get("agent").(int) == 1 { tmpEnable = true } - return &pxapi.QemuGuestAgent{ + return &pveSDK.QemuGuestAgent{ Enable: &tmpEnable, } } diff --git a/proxmox/util.go b/proxmox/util.go index a68bf535..352d1ba3 100644 --- a/proxmox/util.go +++ b/proxmox/util.go @@ -11,7 +11,7 @@ import ( "testing" "time" - pxapi "github.com/Telmate/proxmox-api-go/proxmox" + pveSDK "github.com/Telmate/proxmox-api-go/proxmox" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/rs/zerolog" ) @@ -221,7 +221,7 @@ func CreateSubLogger(loggerName string) (zerolog.Logger, error) { } func UpdateDeviceConfDefaults( - activeDeviceConf pxapi.QemuDevice, + activeDeviceConf pveSDK.QemuDevice, defaultDeviceConf *schema.Set, ) *schema.Set { defaultDeviceConfMap := defaultDeviceConf.List()[0].(map[string]interface{}) @@ -245,8 +245,8 @@ func UpdateDeviceConfDefaults( return defaultDeviceConf } -func DevicesSetToMapWithoutId(devicesSet *schema.Set) pxapi.QemuDevices { - devicesMap := pxapi.QemuDevices{} +func DevicesSetToMapWithoutId(devicesSet *schema.Set) pveSDK.QemuDevices { + devicesMap := pveSDK.QemuDevices{} i := 1 for _, set := range devicesSet.List() { setMap, isMap := set.(map[string]interface{}) @@ -259,7 +259,7 @@ func DevicesSetToMapWithoutId(devicesSet *schema.Set) pxapi.QemuDevices { return devicesMap } -type KeyedDeviceMap map[interface{}]pxapi.QemuDevice +type KeyedDeviceMap map[interface{}]pveSDK.QemuDevice func DevicesListToMapByKey(devicesList []interface{}, key string) KeyedDeviceMap { devicesMap := KeyedDeviceMap{} @@ -274,14 +274,14 @@ func DevicesListToMapByKey(devicesList []interface{}, key string) KeyedDeviceMap return devicesMap } -func DeviceToMap(device pxapi.QemuDevice, key interface{}) KeyedDeviceMap { +func DeviceToMap(device pveSDK.QemuDevice, key interface{}) KeyedDeviceMap { kdm := KeyedDeviceMap{} kdm[key] = device return kdm } -func DevicesListToDevices(devicesList []interface{}, key string) pxapi.QemuDevices { - devicesMap := pxapi.QemuDevices{} +func DevicesListToDevices(devicesList []interface{}, key string) pveSDK.QemuDevices { + devicesMap := pveSDK.QemuDevices{} for key, set := range DevicesListToMapByKey(devicesList, key) { devicesMap[key.(int)] = set } @@ -289,7 +289,7 @@ func DevicesListToDevices(devicesList []interface{}, key string) pxapi.QemuDevic } func AssertNoNonSchemaValues( - devices pxapi.QemuDevices, + devices pveSDK.QemuDevices, schemaDef *schema.Schema, ) error { // add an explicit check that the keys in the config.QemuNetworks map are a strict subset of @@ -311,7 +311,7 @@ func AssertNoNonSchemaValues( // Further parses a QemuDevice by normalizing types func adaptDeviceToConf( conf map[string]interface{}, - device pxapi.QemuDevice, + device pveSDK.QemuDevice, ) map[string]interface{} { // Value type should be one of types allowed by Terraform schema types. for key, value := range device {