reduce properties retrieved, try to reduce memory usage
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:
37
main.go
37
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 := `<table><tbody><tr><th>Vm Name</th><th>Cluster Name</th><th>Controller Name</th><th>Sharing Type</th></tr>{{range .}}<tr><td>{{.VmName}}</td><td>{{.ClusterName}}</td><td>{{.ControllerName}}</td><td>{{.SharingType}}</td></tr>{{end}}</tbody></table>`
|
||||
htmlTemplate := `<table><tbody><tr><th>VM Name</th><th>Cluster Name</th><th>Controller Name</th><th>Sharing Type</th></tr>{{range .}}<tr><td>{{.VmName}}</td><td>{{.ClusterName}}</td><td>{{.ControllerName}}</td><td>{{.SharingType}}</td></tr>{{end}}</tbody></table>`
|
||||
|
||||
// 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 := `<table><tbody><tr><th>Vm Name</th><th>Cluster Name</th><th>Disk Label</th><th>Sharing Type</th></tr>{{range .}}<tr><td>{{.VmName}}</td><td>{{.ClusterName}}</td><td>{{.DiskLabel}}</td><td>{{.SharingType}}</td></tr>{{end}}</tbody></table>`
|
||||
htmlTemplate := `<table><tbody><tr><th>VM Name</th><th>Cluster Name</th><th>Disk Label</th><th>Sharing Type</th></tr>{{range .}}<tr><td>{{.VmName}}</td><td>{{.ClusterName}}</td><td>{{.DiskLabel}}</td><td>{{.SharingType}}</td></tr>{{end}}</tbody></table>`
|
||||
|
||||
// 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)
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user