func CheckVM(client *govcd.VCDClient, s types.QueryResultVMRecordType) ([]string, error) {
  if s.VAppTemplate == true {
    return nil, nil
  }

  ReturnRow := false
  // red := color.New(color.FgRed).SprintFunc()

  VM, err := client.FindVMByHREF(s.HREF)
  if err != nil {
      return nil, fmt.Errorf("Unable to load VM: %s", err)
  }

  HWVersion := fmt.Sprintf("%d", s.HardwareVersion)
  if s.HardwareVersion != 9 { 
    // HWVersion = red(HWVersion)
    ReturnRow = true
  }

  NetworkDevice := "Unknown"
  for _,v := range VM.VM.VirtualHardwareSection.Item {
    if v.ResourceType == 10 {
      NetworkDevice = v.ResourceSubType
    }
  }
  if NetworkDevice != "VMXNET3" {
    // NetworkDevice = red(NetworkDevice)
    ReturnRow = true
  }

  SnapshotCount := 0
  OldSnapshots := 0
  // CurrentTime := time.now()
  for _, snapshot := range VM.VM.Snapshots.Snapshot {
    SnapshotCount++
    Created, _ :=time.Parse("RFC3339", snapshot.Created)
    if time.Now().Sub(Created).Hours() > (7 * 24) {
      OldSnapshots++
    }
  }
  SnapshotString := fmt.Sprintf("%d", OldSnapshots)

  if OldSnapshots > 0 {
    // SnapshotString = red(SnapshotString)
    ReturnRow = true
  }

  if ReturnRow == true {
    return []string{s.Name, HWVersion, NetworkDevice, SnapshotString}, nil
  } 

  return nil, nil
}
// CheckVM is called for each search result 
CheckVM is called for each search result
// CheckVM is called for each search result
func CheckVM(client *govcd.VCDClient, s types.QueryResultVMRecordType) ([]string, error) {
  if s.VAppTemplate == true {
    return nil, nil
  }
  ReturnRow := false
  VM, err := client.FindVMByHREF(s.HREF)
  if err != nil {
      return nil, fmt.Errorf("Unable to load VM: %s", err)
  }
  HWVersion := fmt.Sprintf("%d", s.HardwareVersion)
  if s.HardwareVersion != 9 { 
    ReturnRow = true
  }
  NetworkDevice := "Unknown"
  for _,v := range VM.VM.VirtualHardwareSection.Item {
    if v.ResourceType == 10 {
      NetworkDevice = v.ResourceSubType
    }
  }
  if NetworkDevice != "VMXNET3" {
    ReturnRow = true
  }
  SnapshotCount := 0
  OldSnapshots := 0
  for _, snapshot := range VM.VM.Snapshots.Snapshot {
    SnapshotCount++
    Created, _ :=time.Parse("RFC3339", snapshot.Created)
    if time.Now().Sub(Created).Hours() > (7 * 24) {
      OldSnapshots++
    }
  }
  SnapshotString := fmt.Sprintf("%d", OldSnapshots)
  if OldSnapshots > 0 {
    ReturnRow = true
  }
  if ReturnRow == true {
    return []string{s.Name, HWVersion, NetworkDevice, SnapshotString}, nil
  } 
  return nil, nil
}
func CheckVM ( client * govcd . VCDClient , s types . QueryResultVMRecordType ) ( [ ] string , error ) { if s . VAppTemplate == true { return nil , nil } ReturnRow := false VM , err := client . FindVMByHREF ( s . HREF ) if err != nil { return nil , fmt . Errorf ( " " , err ) } HWVersion := fmt . Sprintf ( " " , s . HardwareVersion ) if s . HardwareVersion != 9 { ReturnRow = true } NetworkDevice := " " for _ , v := range VM . VM . VirtualHardwareSection . Item { if v . ResourceType == 10 { NetworkDevice = v . ResourceSubType } } if NetworkDevice != " " { ReturnRow = true } SnapshotCount := 0 OldSnapshots := 0 for _ , snapshot := range VM . VM . Snapshots . Snapshot { SnapshotCount ++ Created , _ := time . Parse ( " " , snapshot . Created ) if time . Now ( ) . Sub ( Created ) . Hours ( ) > ( 7 * 24 ) { OldSnapshots ++ } } SnapshotString := fmt . Sprintf ( " " , OldSnapshots ) if OldSnapshots > 0 { ReturnRow = true } if ReturnRow == true { return [ ] string { s . Name , HWVersion , NetworkDevice , SnapshotString } , nil } return nil , nil }
CheckVM is called for each search result
CheckVM is called for each search result
// red := color.New(color.FgRed).SprintFunc() // HWVersion = red(HWVersion) // NetworkDevice = red(NetworkDevice) // CurrentTime := time.now() // SnapshotString = red(SnapshotString)