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
|
// Retrieve all the VMs
|
||||||
fmt.Printf("Getting VM listing\n")
|
fmt.Printf("Getting VM listing\n")
|
||||||
var vmList []mo.VirtualMachine
|
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 {
|
if err != nil {
|
||||||
log.Printf("Error retrieving vm list : '%s'\n", err)
|
log.Printf("Error retrieving vm list : '%s'\n", err)
|
||||||
return err
|
return err
|
||||||
@@ -100,7 +100,7 @@ func processVMs(client *govmomi.Client) error {
|
|||||||
// Retrieve all the hosts
|
// Retrieve all the hosts
|
||||||
fmt.Printf("Getting host listing\n")
|
fmt.Printf("Getting host listing\n")
|
||||||
var hsList []mo.HostSystem
|
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 {
|
if err != nil {
|
||||||
log.Printf("Error retrieving hostsystem list : '%s'\n", err)
|
log.Printf("Error retrieving hostsystem list : '%s'\n", err)
|
||||||
return err
|
return err
|
||||||
@@ -109,7 +109,7 @@ func processVMs(client *govmomi.Client) error {
|
|||||||
|
|
||||||
// Iterate through VMs and check for SCSI bus sharing
|
// Iterate through VMs and check for SCSI bus sharing
|
||||||
for _, vm := range vmList {
|
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)
|
//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
|
// Determine cluster based on runtime host of VM based on https://github.com/vmware/govmomi/issues/1242#issuecomment-427671990
|
||||||
for _, host := range hsList {
|
for _, host := range hsList {
|
||||||
if host.Reference() == *vm.Summary.Runtime.Host {
|
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
|
var cluster mo.ManagedEntity
|
||||||
err = pc.RetrieveOne(ctx, *host.Parent, []string{"name"}, &cluster)
|
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 {
|
if vm.Config != nil && len(vm.Config.Hardware.Device) > 0 {
|
||||||
for _, device := range vm.Config.Hardware.Device {
|
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))
|
//fmt.Println("Type of variable1:", reflect.TypeOf(device))
|
||||||
if scsi, ok := device.(types.BaseVirtualSCSIController); ok {
|
if scsi, ok := device.(types.BaseVirtualSCSIController); ok {
|
||||||
//fmt.Printf("scsi: %v\n", scsi)
|
//fmt.Printf("scsi: %v\n", scsi)
|
||||||
@@ -174,6 +174,8 @@ func processVMs(client *govmomi.Client) error {
|
|||||||
// Sharing can be sharingNone or sharingMultiWriter
|
// Sharing can be sharingNone or sharingMultiWriter
|
||||||
backing := vdisk.VirtualDevice.Backing
|
backing := vdisk.VirtualDevice.Backing
|
||||||
//fmt.Println("Type of backing:", reflect.TypeOf(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 {
|
if info, ok := backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
|
||||||
sharingType := info.Sharing
|
sharingType := info.Sharing
|
||||||
|
|
||||||
@@ -204,7 +206,7 @@ func processVMs(client *govmomi.Client) error {
|
|||||||
|
|
||||||
func generateBusSharingTable() string {
|
func generateBusSharingTable() string {
|
||||||
// Define the HTML template
|
// 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
|
// Create a new template and parse the HTML template
|
||||||
tmpl := template.Must(template.New("table").Parse(htmlTemplate))
|
tmpl := template.Must(template.New("table").Parse(htmlTemplate))
|
||||||
@@ -227,7 +229,7 @@ func generateBusSharingTable() string {
|
|||||||
|
|
||||||
func generatMultiWriterTable() string {
|
func generatMultiWriterTable() string {
|
||||||
// Define the HTML template
|
// 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
|
// Create a new template and parse the HTML template
|
||||||
tmpl := template.Must(template.New("table").Parse(htmlTemplate))
|
tmpl := template.Must(template.New("table").Parse(htmlTemplate))
|
||||||
@@ -458,15 +460,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connect to confluence
|
// Connect to confluence
|
||||||
fmt.Printf("Connecting to confluence %s\n", *cURL)
|
if len(*cURL) > 0 && len(*cToken) > 0 {
|
||||||
api, err := goconfluence.NewAPI(*cURL, "", *cToken)
|
fmt.Printf("Connecting to confluence %s\n", *cURL)
|
||||||
|
api, err := goconfluence.NewAPI(*cURL, "", *cToken)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
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