Prevent overwriting existing properties
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
46ff2a0f99
commit
103e355b8e
@ -3,7 +3,7 @@ type: kubernetes
|
||||
name: 'Golang Build'
|
||||
|
||||
environment:
|
||||
BINARY_VERSION: v0.3.1
|
||||
BINARY_VERSION: v0.3.2
|
||||
|
||||
clone:
|
||||
disable: true
|
||||
|
5
go.mod
5
go.mod
@ -7,4 +7,7 @@ require (
|
||||
github.com/vmware/govmomi v0.30.0
|
||||
)
|
||||
|
||||
require golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -1,3 +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/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc=
|
||||
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/find"
|
||||
"github.com/vmware/govmomi/vim25/mo"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
@ -19,7 +20,37 @@ func SetVirtualMachineProperties(ctx context.Context, fnd *find.Finder, virtualm
|
||||
return err
|
||||
}
|
||||
|
||||
vappproperties := []vAPPProperty{
|
||||
var moref mo.VirtualMachine
|
||||
vm.Properties(ctx, vm.Reference(), []string{"config.vAppConfig"}, &moref)
|
||||
|
||||
vappconfig := &types.VmConfigSpec{
|
||||
OvfEnvironmentTransport: []string{"com.vmware.guestInfo"},
|
||||
}
|
||||
|
||||
currentvappproperties := moref.Config.VAppConfig.GetVmConfigInfo().Property
|
||||
for _, vappproperty := range currentvappproperties {
|
||||
vappconfig.Property = append(vappconfig.Property, types.VAppPropertySpec{
|
||||
ArrayUpdateSpec: types.ArrayUpdateSpec{
|
||||
Operation: types.ArrayUpdateOperationAdd,
|
||||
},
|
||||
Info: &types.VAppPropertyInfo{
|
||||
Key: vappproperty.Key,
|
||||
ClassId: vappproperty.ClassId,
|
||||
InstanceId: vappproperty.InstanceId,
|
||||
Id: vappproperty.Id,
|
||||
Category: vappproperty.Category,
|
||||
Label: vappproperty.Label,
|
||||
Type: vappproperty.Type,
|
||||
TypeReference: vappproperty.TypeReference,
|
||||
UserConfigurable: vappproperty.UserConfigurable,
|
||||
DefaultValue: vappproperty.DefaultValue,
|
||||
Value: vappproperty.Value,
|
||||
Description: vappproperty.Description,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
newvappproperties := []vAPPProperty{
|
||||
{
|
||||
Key: "guestinfo.dns.domains",
|
||||
Value: "${searchPath:%s}",
|
||||
@ -42,17 +73,13 @@ func SetVirtualMachineProperties(ctx context.Context, fnd *find.Finder, virtualm
|
||||
},
|
||||
}
|
||||
|
||||
vappconfig := &types.VmConfigSpec{
|
||||
OvfEnvironmentTransport: []string{"com.vmware.guestInfo"},
|
||||
}
|
||||
|
||||
for i, vappproperty := range vappproperties {
|
||||
for i, vappproperty := range newvappproperties {
|
||||
vappconfig.Property = append(vappconfig.Property, types.VAppPropertySpec{
|
||||
ArrayUpdateSpec: types.ArrayUpdateSpec{
|
||||
Operation: types.ArrayUpdateOperationAdd,
|
||||
},
|
||||
Info: &types.VAppPropertyInfo{
|
||||
Key: int32(i),
|
||||
Key: int32(i + len(currentvappproperties)),
|
||||
Id: vappproperty.Key,
|
||||
DefaultValue: fmt.Sprintf(vappproperty.Value, network),
|
||||
Type: "expression",
|
||||
@ -60,8 +87,6 @@ func SetVirtualMachineProperties(ctx context.Context, fnd *find.Finder, virtualm
|
||||
})
|
||||
}
|
||||
|
||||
// spew.Dump(vappconfig)
|
||||
|
||||
task, err := vm.Reconfigure(ctx, types.VirtualMachineConfigSpec{
|
||||
VAppConfig: vappconfig,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user