Move all config to flags;DRY;fixed vApptransport case
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:
@ -1,51 +0,0 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Hypervisor struct {
|
||||
Url string `yaml:"url"`
|
||||
Username string `yaml:"username"`
|
||||
Password string `yaml:"password"`
|
||||
|
||||
Datacenter string `yaml:"datacenter"`
|
||||
} `yaml:"hypervisor"`
|
||||
}
|
||||
|
||||
func NewConfig() (*Config, error) {
|
||||
var configPath string
|
||||
|
||||
flag.StringVar(&configPath, "config", "./config.yml", "path to config file")
|
||||
flag.Parse()
|
||||
|
||||
s, err := os.Stat(configPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.IsDir() {
|
||||
return nil, fmt.Errorf("'%s' is a directory, not a regular file", configPath)
|
||||
}
|
||||
|
||||
|
||||
config := &Config{}
|
||||
|
||||
file, err := os.Open(configPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
d := yaml.NewDecoder(file)
|
||||
|
||||
if err := d.Decode(&config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
@ -22,28 +22,28 @@ func SetVirtualMachineProperties(ctx context.Context, fnd *find.Finder, virtualm
|
||||
vappproperties := []vAPPProperty{
|
||||
{
|
||||
Key: "guestinfo.dns.domains",
|
||||
Value: fmt.Sprintf("${searchPath:%s}", network),
|
||||
Value: "${searchPath:%s}",
|
||||
},
|
||||
{
|
||||
Key: "guestinfo.dns.servers",
|
||||
Value: fmt.Sprintf("${dns:%s}", network),
|
||||
Value: "${dns:%s}",
|
||||
},
|
||||
{
|
||||
Key: "guestinfo.interface.0.ip.0.address",
|
||||
Value: fmt.Sprintf("${autoIp:%s}", network),
|
||||
Value: "${autoIp:%s}",
|
||||
},
|
||||
{
|
||||
Key: "guestinfo.interface.0.ip.0.netmask",
|
||||
Value: fmt.Sprintf("${netmask:%s}", network),
|
||||
Value: "${netmask:%s}",
|
||||
},
|
||||
{
|
||||
Key: "guestinfo.interface.0.route.0.gateway",
|
||||
Value: fmt.Sprintf("${gateway:%s}", network),
|
||||
Value: "${gateway:%s}",
|
||||
},
|
||||
}
|
||||
|
||||
vappconfig := &types.VmConfigSpec{
|
||||
// OvfEnvironmentTransport: []string{"com.vmware.guestinfo"},
|
||||
OvfEnvironmentTransport: []string{"com.vmware.guestInfo"},
|
||||
}
|
||||
|
||||
for i, vappproperty := range vappproperties {
|
||||
@ -54,12 +54,14 @@ func SetVirtualMachineProperties(ctx context.Context, fnd *find.Finder, virtualm
|
||||
Info: &types.VAppPropertyInfo{
|
||||
Key: int32(i),
|
||||
Id: vappproperty.Key,
|
||||
DefaultValue: vappproperty.Value,
|
||||
DefaultValue: fmt.Sprintf(vappproperty.Value, network),
|
||||
Type: "expression",
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// spew.Dump(vappconfig)
|
||||
|
||||
task, err := vm.Reconfigure(ctx, types.VirtualMachineConfigSpec{
|
||||
VAppConfig: vappconfig,
|
||||
})
|
||||
|
Reference in New Issue
Block a user