Create bare minimum IpPool
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d8c361101e
commit
7df925ad61
@ -3,7 +3,7 @@ type: kubernetes
|
|||||||
name: 'Golang Build'
|
name: 'Golang Build'
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
BINARY_VERSION: v0.4.0
|
BINARY_VERSION: v0.4.1
|
||||||
|
|
||||||
clone:
|
clone:
|
||||||
disable: true
|
disable: true
|
||||||
|
@ -56,12 +56,12 @@ func main() {
|
|||||||
log.Fatalf("[ERROR] Could not create network protocol profile: %s", err)
|
log.Fatalf("[ERROR] Could not create network protocol profile: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[SUCCESS] Hurray! We did it!")
|
log.Printf("[SUCCESS] New network protocol profile created within datacenter '%s' (associated with network '%s')", Commands.Datacenter.Name, Commands.Datacenter.Network)
|
||||||
case "virtualmachine", "vm":
|
case "virtualmachine", "vm":
|
||||||
if err := hypervisor.SetVirtualMachineProperties(ctx, clt, Commands.VirtualMachine.Datacenter, Commands.VirtualMachine.Name, Commands.VirtualMachine.Network); err != nil {
|
if err := hypervisor.SetVirtualMachineProperties(ctx, clt, Commands.VirtualMachine.Datacenter, Commands.VirtualMachine.Name, Commands.VirtualMachine.Network); err != nil {
|
||||||
log.Fatalf("[ERROR] Could not apply vApp properties: %s", err)
|
log.Fatalf("[ERROR] Could not apply vApp properties: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("[SUCCESS] Network protocol profile properties added to virtual machine '%s' and configured for network '%s'", Commands.VirtualMachine.Name, Commands.VirtualMachine.Network)
|
log.Printf("[SUCCESS] Network protocol profile properties added to virtual machine '%s' (configured for network '%s')", Commands.VirtualMachine.Name, Commands.VirtualMachine.Network)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module spamasaurus.com/m
|
|||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1
|
github.com/google/uuid v1.3.0
|
||||||
github.com/jessevdk/go-flags v1.5.0
|
github.com/jessevdk/go-flags v1.5.0
|
||||||
github.com/vmware/govmomi v0.30.0
|
github.com/vmware/govmomi v0.30.0
|
||||||
)
|
)
|
||||||
|
3
go.sum
3
go.sum
@ -1,6 +1,5 @@
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
|
github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
|
||||||
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
||||||
github.com/vmware/govmomi v0.30.0 h1:Fm8ugPnnlMSTSceDKY9goGvjmqc6eQLPUSUeNXdpeXA=
|
github.com/vmware/govmomi v0.30.0 h1:Fm8ugPnnlMSTSceDKY9goGvjmqc6eQLPUSUeNXdpeXA=
|
||||||
|
@ -4,42 +4,45 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/vmware/govmomi/find"
|
"github.com/vmware/govmomi/find"
|
||||||
"github.com/vmware/govmomi/object"
|
|
||||||
"github.com/vmware/govmomi/vim25"
|
"github.com/vmware/govmomi/vim25"
|
||||||
"github.com/vmware/govmomi/vim25/methods"
|
"github.com/vmware/govmomi/vim25/methods"
|
||||||
"github.com/vmware/govmomi/vim25/types"
|
"github.com/vmware/govmomi/vim25/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateNetworkProtocolProfile(ctx context.Context, clt *vim25.Client, datacenter, network string) error {
|
func CreateNetworkProtocolProfile(ctx context.Context, clt *vim25.Client, datacenter, network string) error {
|
||||||
dc, err := find.NewFinder(clt, true).Datacenter(ctx, datacenter)
|
finder := find.NewFinder(clt, true)
|
||||||
|
dc, err := finder.Datacenter(ctx, datacenter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("[ERROR] Unable to determine datacenter: %s", err)
|
log.Fatalf("[ERROR] Unable to determine datacenter: %s", err)
|
||||||
}
|
}
|
||||||
|
finder.SetDatacenter(dc)
|
||||||
object.NewCommon(clt, dc.Reference())
|
// nw, err := finder.Network(ctx, network)
|
||||||
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 {
|
// if err != nil {
|
||||||
// log.Fatalf("Foo: %s", err)
|
// log.Fatalf("[ERROR] Unable to determine network: %s", err)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
request := &types.CreateIpPool{
|
||||||
|
This: *clt.ServiceContent.IpPoolManager,
|
||||||
|
Dc: dc.Reference(),
|
||||||
|
Pool: types.IpPool{
|
||||||
|
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,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user