Go.NPP-Prepper/pkg/hypervisor/dc.go

49 lines
1.4 KiB
Go
Raw Normal View History

package hypervisor
import (
"context"
"log"
2022-12-28 15:29:25 +00:00
"github.com/google/uuid"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/types"
)
func CreateNetworkProtocolProfile(ctx context.Context, clt *vim25.Client, datacenter, network string) error {
2022-12-28 15:29:25 +00:00
finder := find.NewFinder(clt, true)
dc, err := finder.Datacenter(ctx, datacenter)
if err != nil {
log.Fatalf("[ERROR] Unable to determine datacenter: %s", err)
}
2022-12-28 15:29:25 +00:00
finder.SetDatacenter(dc)
// nw, err := finder.Network(ctx, network)
// if err != nil {
// log.Fatalf("[ERROR] Unable to determine network: %s", err)
// }
request := &types.CreateIpPool{
2022-12-28 15:29:25 +00:00
This: *clt.ServiceContent.IpPoolManager,
Dc: dc.Reference(),
Pool: types.IpPool{
2022-12-28 15:29:25 +00:00
Name: "ippool-" + (uuid.New().String()),
DnsDomain: "meta.k8s.cluster",
DnsSearchPath: "meta.k8s.cluster",
// NetworkAssociation: []types.IpPoolAssociation{{
// // This generates the error 'cannot use nw.Reference() (value of type types.ManagedObjectReference) as type *types.ManagedObjectReference in struct literal'
// Network: nw.Reference(),
// NetworkName: network,
// },
// },
},
}
2022-12-28 15:29:25 +00:00
if _, err := methods.CreateIpPool(ctx, clt.RoundTripper, request); err != nil {
log.Fatalf("[ERROR]: Failed creating new network protocol profile (for network '%s' within datacenter '%s'): %s", network, datacenter, err)
}
return nil
}