Move routines to subcommands;Add initial logic for datacenter configuration; Move code to package
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-12-28 14:41:03 +01:00
parent 103e355b8e
commit d8c361101e
5 changed files with 101 additions and 33 deletions

45
pkg/hypervisor/dc.go Normal file
View File

@ -0,0 +1,45 @@
package hypervisor
import (
"context"
"log"
"github.com/davecgh/go-spew/spew"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
"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 {
dc, err := find.NewFinder(clt, true).Datacenter(ctx, datacenter)
if err != nil {
log.Fatalf("[ERROR] Unable to determine datacenter: %s", err)
}
object.NewCommon(clt, dc.Reference())
request := &types.CreateIpPool{
This: types.ManagedObjectReference{
Type: "",
Value: "",
},
Pool: types.IpPool{
Name: "Test",
},
}
response, err := methods.CreateIpPool(ctx, clt.RoundTripper, request)
if err != nil {
log.Fatalf("Bar: %s", err)
}
spew.Dump(response)
// task := object.NewTask(clt)
// err = task.Wait(ctx)
// if err != nil {
// log.Fatalf("Foo: %s", err)
// }
return nil
}

View File

@ -3,8 +3,10 @@ package hypervisor
import (
"context"
"fmt"
"log"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/types"
)
@ -14,10 +16,18 @@ type vAPPProperty struct {
Value string
}
func SetVirtualMachineProperties(ctx context.Context, fnd *find.Finder, virtualmachine string, network string) error {
vm, err := fnd.VirtualMachine(ctx, virtualmachine)
func SetVirtualMachineProperties(ctx context.Context, clt *vim25.Client, datacenter, virtualmachine, network string) error {
finder := find.NewFinder(clt, true)
dc, err := finder.Datacenter(ctx, datacenter)
if err != nil {
return err
log.Fatalf("[ERROR] Unable to determine datacenter: %s", err)
}
finder.SetDatacenter(dc)
vm, err := finder.VirtualMachine(ctx, virtualmachine)
if err != nil {
log.Fatalf("[ERROR] Unable to determine virtual machine: %s", err)
}
var moref mo.VirtualMachine