Configure CI;Add network name flag;Add list of properties
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Danny Bessems 2022-12-22 14:16:44 +01:00
parent c8483de7a9
commit b85fd3946e
5 changed files with 69 additions and 16 deletions

34
.drone.yml Normal file
View File

@ -0,0 +1,34 @@
kind: pipeline
type: kubernetes
name: 'Golang Build'
environment:
SKOPEO_VERSION: v1.10.0
clone:
disable: true
steps:
- name: Clone vappproperty-manager source repository
image: bv11-cr01.bessems.eu/proxy/alpine/git
commands:
- git clone https://code.spamasaurus.com/djpbessems/Go.vAppPropertyManager.git .
# - git checkout tags/$SKOPEO_VERSION
- git checkout HEAD
when:
status:
- success
- name: Build binary
image: bv11-cr01.bessems.eu/proxy/library/golang
commands:
- |
go build -o ./bin/vappprop-manager ./cmd/vappprop-manager/main.go
- |
curl \
--header "Authorization: token $GIT_APIKEY" \
--upload-file bin/vappprop-manager \
https://code.spamasaurus.com/api/packages/$GIT_USERNAME/generic/vappprop-manager/v0.1.0/vappprop-manager
environment:
GIT_APIKEY:
from_secret: git_apikey
GIT_USERNAME: djpbessems

View File

@ -9,19 +9,21 @@ import (
"spamasaurus.com/m/pkg/hypervisor"
)
func main() {
var virtualmachine string
flag.StringVar(&virtualmachine, "vm", "", "name of VM")
flag.Parse()
if virtualmachine == "" {
log.Fatalf("Name of vm is required")
type Input struct {
VirtualMachine string
Network string
}
func main() {
var input Input
flag.StringVar(&input.VirtualMachine, "vm", "", "name of VM")
flag.StringVar(&input.Network, "network", "", "name of network portgroup")
flag.Parse()
cfg, err := config.NewConfig()
if err != nil {
log.Fatal(err)
log.Fatalf("Invalid configuration: %s", err)
}
ctx, cancel := context.WithCancel(context.Background())
@ -37,7 +39,7 @@ func main() {
log.Fatalf("Foo indeed: %s", err)
}
if err := hypervisor.SetVirtualMachineProperties(ctx, fnd, virtualmachine); err != nil {
if err := hypervisor.SetVirtualMachineProperties(ctx, fnd, input.VirtualMachine, input.Network); err != nil {
log.Fatalf("Could not apply vApp properties: %s", err)
}
}

5
go.mod
View File

@ -4,4 +4,7 @@ go 1.19
require github.com/vmware/govmomi v0.30.0
require gopkg.in/yaml.v2 v2.4.0 // indirect
require (
github.com/davecgh/go-spew v1.1.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

2
go.sum
View File

@ -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/vmware/govmomi v0.30.0 h1:Fm8ugPnnlMSTSceDKY9goGvjmqc6eQLPUSUeNXdpeXA=
github.com/vmware/govmomi v0.30.0/go.mod h1:F7adsVewLNHsW/IIm7ziFURaXDaHEwcc+ym4r3INMdY=

View File

@ -13,20 +13,32 @@ type vAPPProperty struct {
Value string
}
func SetVirtualMachineProperties(ctx context.Context, fnd *find.Finder, name string) error {
vm, err := fnd.VirtualMachine(ctx, name)
func SetVirtualMachineProperties(ctx context.Context, fnd *find.Finder, virtualmachine string, network string) error {
vm, err := fnd.VirtualMachine(ctx, virtualmachine)
if err != nil {
return err
}
vappproperties := []vAPPProperty{
{
Key: "foo",
Value: "bar",
Key: "guestinfo.dns.domains",
Value: fmt.Sprintf("${searchPath:%s}", network),
},
{
Key: "woot",
Value: "dude",
Key: "guestinfo.dns.servers",
Value: fmt.Sprintf("${dns:%s}", network),
},
{
Key: "guestinfo.interface.0.ip.0.address",
Value: fmt.Sprintf("${autoIp:%s}", network),
},
{
Key: "guestinfo.interface.0.ip.0.netmask",
Value: fmt.Sprintf("${netmask:%s}", network),
},
{
Key: "guestinfo.interface.0.route.0.gateway",
Value: fmt.Sprintf("${gateway:%s}", network),
},
}
@ -42,7 +54,7 @@ func SetVirtualMachineProperties(ctx context.Context, fnd *find.Finder, name str
Info: &types.VAppPropertyInfo{
Key: int32(i),
Id: vappproperty.Key,
DefaultValue: fmt.Sprintf("${%v}", vappproperty.Value),
DefaultValue: vappproperty.Value,
Type: "expression",
},
})