diff --git a/main.go b/main.go
index 741bf95..8aaf5de 100644
--- a/main.go
+++ b/main.go
@@ -90,7 +90,7 @@ func processVMs(client *govmomi.Client) error {
// Retrieve all the VMs
fmt.Printf("Getting VM listing\n")
var vmList []mo.VirtualMachine
- err = vms.Retrieve(ctx, []string{"VirtualMachine"}, nil, &vmList)
+ err = vms.Retrieve(ctx, []string{"VirtualMachine"}, []string{"summary", "config", "name"}, &vmList)
if err != nil {
log.Printf("Error retrieving vm list : '%s'\n", err)
return err
@@ -100,7 +100,7 @@ func processVMs(client *govmomi.Client) error {
// Retrieve all the hosts
fmt.Printf("Getting host listing\n")
var hsList []mo.HostSystem
- err = hs.Retrieve(ctx, []string{"HostSystem"}, nil, &hsList)
+ err = hs.Retrieve(ctx, []string{"HostSystem"}, []string{"name", "parent"}, &hsList)
if err != nil {
log.Printf("Error retrieving hostsystem list : '%s'\n", err)
return err
@@ -109,7 +109,7 @@ func processVMs(client *govmomi.Client) error {
// Iterate through VMs and check for SCSI bus sharing
for _, vm := range vmList {
- //fmt.Printf("vm : %s [%s]\n", vm.Name, vm.Summary.Runtime.Host)
+ fmt.Printf("vm : %s [%s]\n", vm.Name, vm.Summary.Runtime.Host)
//fmt.Printf("vm parent: %v\n", vm.Parent)
/*
@@ -127,7 +127,7 @@ func processVMs(client *govmomi.Client) error {
// Determine cluster based on runtime host of VM based on https://github.com/vmware/govmomi/issues/1242#issuecomment-427671990
for _, host := range hsList {
if host.Reference() == *vm.Summary.Runtime.Host {
- //fmt.Printf("host %s matches, host parent %s\n", host.Name, host.Parent)
+ fmt.Printf("host %s matches, host parent %s\n", host.Name, host.Parent)
var cluster mo.ManagedEntity
err = pc.RetrieveOne(ctx, *host.Parent, []string{"name"}, &cluster)
@@ -144,7 +144,7 @@ func processVMs(client *govmomi.Client) error {
if vm.Config != nil && len(vm.Config.Hardware.Device) > 0 {
for _, device := range vm.Config.Hardware.Device {
- //fmt.Printf("device: %v\n", device)
+ fmt.Printf("device: %v\n", device)
//fmt.Println("Type of variable1:", reflect.TypeOf(device))
if scsi, ok := device.(types.BaseVirtualSCSIController); ok {
//fmt.Printf("scsi: %v\n", scsi)
@@ -174,6 +174,8 @@ func processVMs(client *govmomi.Client) error {
// Sharing can be sharingNone or sharingMultiWriter
backing := vdisk.VirtualDevice.Backing
//fmt.Println("Type of backing:", reflect.TypeOf(backing))
+
+ // make sure we have a regular disk, not an RDM which has type VirtualDiskRawDiskMappingVer1BackingInfo
if info, ok := backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
sharingType := info.Sharing
@@ -204,7 +206,7 @@ func processVMs(client *govmomi.Client) error {
func generateBusSharingTable() string {
// Define the HTML template
- htmlTemplate := `
Vm Name | Cluster Name | Controller Name | Sharing Type |
{{range .}}{{.VmName}} | {{.ClusterName}} | {{.ControllerName}} | {{.SharingType}} |
{{end}}
`
+ htmlTemplate := `VM Name | Cluster Name | Controller Name | Sharing Type |
{{range .}}{{.VmName}} | {{.ClusterName}} | {{.ControllerName}} | {{.SharingType}} |
{{end}}
`
// Create a new template and parse the HTML template
tmpl := template.Must(template.New("table").Parse(htmlTemplate))
@@ -227,7 +229,7 @@ func generateBusSharingTable() string {
func generatMultiWriterTable() string {
// Define the HTML template
- htmlTemplate := `Vm Name | Cluster Name | Disk Label | Sharing Type |
{{range .}}{{.VmName}} | {{.ClusterName}} | {{.DiskLabel}} | {{.SharingType}} |
{{end}}
`
+ htmlTemplate := `VM Name | Cluster Name | Disk Label | Sharing Type |
{{range .}}{{.VmName}} | {{.ClusterName}} | {{.DiskLabel}} | {{.SharingType}} |
{{end}}
`
// Create a new template and parse the HTML template
tmpl := template.Must(template.New("table").Parse(htmlTemplate))
@@ -458,15 +460,18 @@ func main() {
}
// Connect to confluence
- fmt.Printf("Connecting to confluence %s\n", *cURL)
- api, err := goconfluence.NewAPI(*cURL, "", *cToken)
+ if len(*cURL) > 0 && len(*cToken) > 0 {
+ fmt.Printf("Connecting to confluence %s\n", *cURL)
+ api, err := goconfluence.NewAPI(*cURL, "", *cToken)
- if err != nil {
- fmt.Println(err)
- return
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+
+ updateConfluenceBusSharing(api, vCenterHostname, *cBusSharingId, *cSpaceKey)
+ updateConfluenceMultiWriter(api, vCenterHostname, *cMultiWriterId, *cSpaceKey)
+ } else {
+ fmt.Println("Not updating confluence, no details provided")
}
-
- updateConfluenceBusSharing(api, vCenterHostname, *cBusSharingId, *cSpaceKey)
- updateConfluenceMultiWriter(api, vCenterHostname, *cMultiWriterId, *cSpaceKey)
-
}