2022-12-28 13:41:03 +00:00
package hypervisor
import (
"context"
"log"
2022-12-28 15:29:25 +00:00
"github.com/google/uuid"
2022-12-28 13:41:03 +00:00
"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 )
2022-12-28 13:41:03 +00:00
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)
// }
2022-12-28 13:41:03 +00:00
request := & types . CreateIpPool {
2022-12-28 15:29:25 +00:00
This : * clt . ServiceContent . IpPoolManager ,
Dc : dc . Reference ( ) ,
2022-12-28 13:41:03 +00:00
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 13:41:03 +00:00
} ,
}
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 )
}
2022-12-28 13:41:03 +00:00
return nil
}