def main():
    """Main program.
    """

    args = get_args()
    serviceInstance = None
    try:
        if args.disable_ssl_verification:
            serviceInstance = SmartConnectNoSSL(host=args.host,
                                                user=args.user,
                                                pwd=args.password,
                                                port=int(args.port))
        else:
            serviceInstance = SmartConnect(host=args.host,
                                           user=args.user,
                                           pwd=args.password,
                                           port=int(args.port))
        atexit.register(Disconnect, serviceInstance)
    except IOError as e:
        print(e)
        pass
    if not serviceInstance:
        raise SystemExit("Unable to connect to host with supplied info.")

    pbm_content = PbmConnect(serviceInstance._stub,
                             args.disable_ssl_verification)
    pm = pbm_content.profileManager

    vm_list = SearchVMByName(serviceInstance, args.vm_name, args.strict)
    for vm in vm_list:
        print("Virtual machine name: {}{}{}".format(bcolors.OKGREEN, vm.name,
                                                    bcolors.ENDC))
        pmObjectType = pbm.ServerObjectRef.ObjectType("virtualMachine")
        pmRef = pbm.ServerObjectRef(key=vm._moId, objectType=pmObjectType)
        profiles = GetStorageProfiles(pm, pmRef)
        if len(profiles) > 0:
            print("Home Storage Profile:")
            ShowStorageProfile(profiles)

        print("\r\nVirtual Disk Storage Profile:")
        for device in vm.config.hardware.device:
            deviceType = type(device).__name__
            if deviceType == "vim.vm.device.VirtualDisk":
                pmObjectType = pbm.ServerObjectRef.ObjectType("virtualDiskId")
                pmRef = pbm.ServerObjectRef(key="{}:{}".format(
                    vm._moId, device.key),
                                            objectType=pmObjectType)
                profiles = GetStorageProfiles(pm, pmRef)
                if len(profiles) > 0:
                    print(device.deviceInfo.label)
                    ShowStorageProfile(profiles)
                    print("")
        print("")
Beispiel #2
0
 def check_compliance_vm(self, vm):
     """
     Checks if a VM is compliant with attached profile
     """
     pbm_object_ref = pbm.ServerObjectRef(
         key=str(vm._moId),
         objectType="virtualMachine",
         serverUuid=self.vc_si.content.about.instanceUuid)
     compliance_status = {}
     compliance_status['vm_name'] = vm.name
     results = self.get_compliancemgr().PbmCheckRollupCompliance(
         entity=[pbm_object_ref])
     compliance_result = []
     for result in results:
         compliance_status[
             'overallComplianceStatus'] = result.overallComplianceStatus
         if result.result:
             subresults = result.result
             for complianceresult in subresults:
                 individual_compliance = {}
                 individual_compliance[
                     'checkTime'] = complianceresult.checkTime
                 individual_compliance[
                     'complianceStatus'] = complianceresult.complianceStatus
                 individual_compliance['key'] = complianceresult.entity.key
                 individual_compliance[
                     'objectType'] = complianceresult.entity.objectType
                 compliance_result.append(individual_compliance)
     compliance_status['result'] = compliance_result
     return compliance_status
def main():
    """Main program.
    """

    parser = cli.Parser()
    parser.add_required_arguments(cli.Argument.VM_NAME)
    parser.add_custom_argument(
        '--strict',
        required=False,
        action='store_true',
        help='Search strict virtual machine name matches')
    args = parser.get_args()
    si = service_instance.connect(args)

    pbm_content = pbm_connect(si._stub, args.disable_ssl_verification)
    pm = pbm_content.profileManager

    vm_list = search_vm_by_name(si, args.vm_name, args.strict)
    for vm in vm_list:
        print("Virtual machine name: {}{}{}".format(BColors.OKGREEN, vm.name,
                                                    BColors.ENDC))
        pm_object_type = pbm.ServerObjectRef.ObjectType("virtualMachine")
        pm_ref = pbm.ServerObjectRef(key=vm._moId, objectType=pm_object_type)
        profiles = get_storage_profiles(pm, pm_ref)
        if len(profiles) > 0:
            print("Home Storage Profile:")
            show_storage_profile(profiles)

        print("\r\nVirtual Disk Storage Profile:")
        for device in vm.config.hardware.device:
            device_type = type(device).__name__
            if device_type == "vim.vm.device.VirtualDisk":
                pm_object_type = pbm.ServerObjectRef.ObjectType(
                    "virtualDiskId")
                pm_ref = pbm.ServerObjectRef(key="{}:{}".format(
                    vm._moId, device.key),
                                             objectType=pm_object_type)
                profiles = get_storage_profiles(pm, pm_ref)
                if len(profiles) > 0:
                    print(device.deviceInfo.label)
                    show_storage_profile(profiles)
                    print("")
        print("")
Beispiel #4
0
def main():
    """Main program.
    """

    parser = cli.Parser()
    parser.add_required_arguments(cli.Argument.VM_NAME,
                                  cli.Argument.STORAGE_POLICY_NAME)
    parser.add_custom_argument(
        '--strict',
        required=False,
        action='store_true',
        help='Search strict virtual machine name matches')
    parser.add_custom_argument('--set_vm_home',
                               required=False,
                               action='store_true',
                               help='Set the specified policy for vm home.')
    parser.add_custom_argument(
        '--virtual_disk_number',
        required=False,
        nargs='+',
        metavar='int',
        help='The sequence numbers of the virtual disks for which '
        'the specified policy should be set. Space as delimiter.')
    args = parser.get_args()
    si = service_instance.connect(args)

    vd_number = args.virtual_disk_number
    policy_name = args.storage_policy_name

    pbm_content = pbm_connect(si._stub, args.disable_ssl_verification)
    pm = pbm_content.profileManager

    storage_profile = search_storage_profile_by_name(pm, policy_name)
    if not storage_profile:
        raise SystemExit('Unable to find storage profile with name '
                         '{}{}{}.'.format(BColors.FAIL, policy_name,
                                          BColors.ENDC))

    vm_list = search_vm_by_name(si, args.vm_name, args.strict)
    for vm in vm_list:
        pm_object_type = pbm.ServerObjectRef.ObjectType("virtualMachine")
        pm_ref = pbm.ServerObjectRef(key=vm._moId, objectType=pm_object_type)
        print('\r\nVirtual machine name: {}{}{}'.format(
            BColors.OKGREEN, vm.name, BColors.ENDC))

        # The implementation of idempotency for the operation of the storage
        # policy assignment for VM Home
        if args.set_vm_home:
            if not check_storage_profile_associated(pm, pm_ref, policy_name):
                print('Set VM Home policy: '
                      '{}{}{}'.format(BColors.OKGREEN, policy_name,
                                      BColors.ENDC))

                try:
                    set_vm_storage_profile(vm, storage_profile)
                except Exception as exc:
                    print('VM reconfiguration task error: '
                          '{}{}{}'.format(BColors.FAIL, exc, BColors.ENDC))
            else:
                print('Set VM Home policy: Nothing to do')

        if vd_number:
            for device in vm.config.hardware.device:
                device_type = type(device).__name__
                if device_type == "vim.vm.device.VirtualDisk" and \
                   re.search('Hard disk (.+)',
                             device.deviceInfo.label).group(1) in vd_number:
                    pm_object_type = \
                        pbm.ServerObjectRef.ObjectType("virtualDiskId")
                    pm_ref = pbm.ServerObjectRef(key="{}:{}".format(
                        vm._moId, device.key),
                                                 objectType=pm_object_type)

                    # The implementation of idempotency for the operation
                    # of the storage policy assignment for virtual disk
                    if not check_storage_profile_associated(
                            pm, pm_ref, policy_name):
                        print('Set {} policy: '
                              '{}{}{}'.format(device.deviceInfo.label,
                                              BColors.OKGREEN, policy_name,
                                              BColors.ENDC))
                        try:
                            set_virtual_disk_storage_profile(
                                vm, device, storage_profile)
                        except Exception as exc:
                            print('Virtual disk reconfiguration task error: '
                                  '{}{}{}'.format(BColors.FAIL, exc,
                                                  BColors.ENDC))
                    else:
                        print('Set {} policy: Nothing to do'.format(
                            device.deviceInfo.label))
Beispiel #5
0
    def ensure_storage_policies(self, vm_obj):
        """
        Ensure VM storage profile policies.

        :param vm_obj: VMware VM object.
        :type vm_obj: VirtualMachine
        :exits: self.module.exit_json on success, else self.module.fail_json.
        """

        disks = self.module.params.get('disk')
        vm_home = self.module.params.get('vm_home')
        success_msg = "Policies successfully set."
        result = dict(
            changed=False,
            msg="",
            changed_policies=dict(
                disk=[],
                vm_home="",
            ),
        )

        # Connect into vcenter and get the profile manager for the VM.
        self.get_spbm_connection()
        pm = self.spbm_content.profileManager

        #
        # VM HOME
        #
        if vm_home:
            policy = vm_home
            pmObjectType = pbm.ServerObjectRef.ObjectType("virtualMachine")
            pmRef = pbm.ServerObjectRef(key=vm_obj._moId,
                                        objectType=pmObjectType)
            pol_obj = self.SearchStorageProfileByName(pm, policy)

            if not pol_obj:
                result[
                    'msg'] = "Unable to find storage policy `%s' for vm_home" % policy
                self.module.fail_json(**result)

            if not self.CheckAssociatedStorageProfile(pm, pmRef, policy):
                # Existing policy is different than requested. Set, wait for
                # task success, and exit.
                if not self.module.check_mode:
                    task = self.SetVMHomeStorageProfile(vm_obj, pol_obj)
                    wait_for_task(task)  # will raise an Exception on failure
                result['changed'] = True
                result['changed_policies']['vm_home'] = policy

        #
        # DISKS
        #
        if disks is None:
            disks = list()
        # Check the requested disks[] information is sane or fail by looking up
        # and storing the object(s) in a new dict.
        disks_objs = dict()  # {unit_number: {disk: <obj>, policy: <obj>}}
        for disk in disks:
            policy = str(disk['policy'])
            unit_number = int(disk['unit_number'])
            controller_number = int(disk['controller_number'])
            disk_obj = self.GetVirtualDiskObj(vm_obj, unit_number,
                                              controller_number)
            pol_obj = self.SearchStorageProfileByName(pm, policy)
            if not pol_obj:
                result[
                    'msg'] = "Unable to find storage policy `%s' for disk %s." % (
                        policy, disk)
                self.module.fail_json(**result)
            if not disk_obj:
                errmsg = "Unable to find disk for controller_number '%s' unit_number '%s'. 7 is reserved for SCSI adapters."
                result['msg'] = errmsg % (controller_number, unit_number)
                self.module.fail_json(**result)
            disks_objs[unit_number] = dict(disk=disk_obj, policy=pol_obj)

        # All requested profiles are valid. Iterate through each disk and set
        # accordingly.
        for disk in disks:
            policy = str(disk['policy'])
            unit_number = int(disk['unit_number'])
            controller_number = int(disk['controller_number'])
            disk_obj = disks_objs[unit_number]['disk']
            pol_obj = disks_objs[unit_number]['policy']
            pmObjectType = pbm.ServerObjectRef.ObjectType("virtualDiskId")
            pmRef = pbm.ServerObjectRef(key="%s:%s" %
                                        (vm_obj._moId, disk_obj.key),
                                        objectType=pmObjectType)

            if not self.CheckAssociatedStorageProfile(pm, pmRef, policy):
                # Existing policy is different than requested. Set, wait for
                # task success, and exit.
                if not self.module.check_mode:
                    task = self.SetVMDiskStorageProfile(
                        vm_obj, unit_number, controller_number, pol_obj)
                    wait_for_task(task)
                result['changed'] = True
                result['changed_policies']['disk'].append(disk)

        #
        # END
        #
        # Check our results and exit.
        if result['changed']:
            result['msg'] = success_msg
        self.module.exit_json(**result)
Beispiel #6
0
def main():
    """Main program.
    """

    args = get_args()
    serviceInstance = None
    try:
        if args.disable_ssl_verification:
            serviceInstance = SmartConnectNoSSL(host=args.host,
                                                user=args.user,
                                                pwd=args.password,
                                                port=int(args.port))
        else:
            serviceInstance = SmartConnect(host=args.host,
                                           user=args.user,
                                           pwd=args.password,
                                           port=int(args.port))
        atexit.register(Disconnect, serviceInstance)
    except IOError as e:
        print(e)
        pass
    if not serviceInstance:
        raise SystemExit('Unable to connect to host with supplied info.')

    vdNumber = args.virtual_disk_number
    policyName = args.storage_policy_name

    pbm_content = PbmConnect(serviceInstance._stub,
                             args.disable_ssl_verification)
    pm = pbm_content.profileManager

    storageProfile = SearchStorageProfileByName(pm, policyName)
    if not storageProfile:
        raise SystemExit('Unable to find storage profile with name '
                         '{}{}{}.'.format(bcolors.FAIL, policyName,
                                          bcolors.ENDC))

    vm_list = SearchVMByName(serviceInstance, args.vm_name, args.strict)
    for vm in vm_list:
        pmObjectType = pbm.ServerObjectRef.ObjectType("virtualMachine")
        pmRef = pbm.ServerObjectRef(key=vm._moId, objectType=pmObjectType)
        print('\r\nVirtual machine name: {}{}{}'.format(
            bcolors.OKGREEN, vm.name, bcolors.ENDC))

        # The implementation of idempotency for the operation of the storage
        # policy assignment for VM Home
        if args.set_vm_home:
            if not CheckStorageProfileAssociated(pm, pmRef, policyName):
                print('Set VM Home policy: '
                      '{}{}{}'.format(bcolors.OKGREEN, policyName,
                                      bcolors.ENDC))

                try:
                    SetVMStorageProfile(vm, storageProfile)
                except Exception as exc:
                    print('VM reconfiguration task error: '
                          '{}{}{}'.format(bcolors.FAIL, exc, bcolors.ENDC))
            else:
                print('Set VM Home policy: Nothing to do')

        if vdNumber:
            for device in vm.config.hardware.device:
                deviceType = type(device).__name__
                if deviceType == "vim.vm.device.VirtualDisk" and \
                   re.search('Hard disk (.+)',
                             device.deviceInfo.label).group(1) in vdNumber:
                    pmObjectType = \
                        pbm.ServerObjectRef.ObjectType("virtualDiskId")
                    pmRef = pbm.ServerObjectRef(key="{}:{}".format(
                        vm._moId, device.key),
                                                objectType=pmObjectType)

                    # The implementation of idempotency for the operation
                    # of the storage policy assignment for virtual disk
                    if not CheckStorageProfileAssociated(
                            pm, pmRef, policyName):
                        print('Set {} policy: '
                              '{}{}{}'.format(device.deviceInfo.label,
                                              bcolors.OKGREEN, policyName,
                                              bcolors.ENDC))
                        try:
                            SetVirtualDiskStorageProfile(
                                vm, device, storageProfile)
                        except Exception as exc:
                            print('Virtual disk reconfiguration task error: '
                                  '{}{}{}'.format(bcolors.FAIL, exc,
                                                  bcolors.ENDC))
                    else:
                        print('Set {} policy: Nothing to do'.format(
                            device.deviceInfo.label))
Beispiel #7
0
    def print_vm_info(self, vm, interval=20, verbose=False):
        statInt = interval * 3  # There are 3 20s samples in each minute
        summary = vm.summary
        disk_list = []
        vm_hardware = vm.config.hardware
        for each_vm_hardware in vm_hardware.device:
            if (each_vm_hardware.key >= 2000) and (each_vm_hardware.key <
                                                   3000):
                if summary.runtime.powerState == "poweredOn" and verbose:
                    # VirtualDisk Average IO
                    statVirtualdiskIORead = self.build_perf_query(
                        self.serviceInstance.content, self.vchtime,
                        self.stat_check(
                            self.perf_dict,
                            'virtualDisk.numberReadAveraged.average'),
                        self.get_virtualdisk_scsi(vm, each_vm_hardware), vm,
                        statInt)
                    VirtualdiskIORead = (
                        float(sum(statVirtualdiskIORead[0].value[0].value)) /
                        statInt)

                    statVirtualdiskIOWrite = self.build_perf_query(
                        self.serviceInstance.content, self.vchtime,
                        self.stat_check(
                            self.perf_dict,
                            'virtualDisk.numberWriteAveraged.average'),
                        self.get_virtualdisk_scsi(vm, each_vm_hardware), vm,
                        statInt)
                    VirtualdiskIOWrite = (
                        float(sum(statVirtualdiskIOWrite[0].value[0].value)) /
                        statInt)

                    # VirtualDisk Average Latency
                    statVirtualdiskLatRead = self.build_perf_query(
                        self.serviceInstance.content, self.vchtime,
                        self.stat_check(
                            self.perf_dict,
                            'virtualDisk.totalReadLatency.average'),
                        self.get_virtualdisk_scsi(vm, each_vm_hardware), vm,
                        statInt)
                    VirtualdiskLatRead = (
                        float(sum(statVirtualdiskLatRead[0].value[0].value)) /
                        statInt)
                    VirtualdiskLatRead = "{:.0f}".format(
                        VirtualdiskLatRead
                    ) if VirtualdiskLatRead < 25 else "{}{:.0f}{}".format(
                        bcolors.FAIL, VirtualdiskLatRead, bcolors.ENDC)

                    statVirtualdiskLatWrite = self.build_perf_query(
                        self.serviceInstance.content, self.vchtime,
                        self.stat_check(
                            self.perf_dict,
                            'virtualDisk.totalWriteLatency.average'),
                        self.get_virtualdisk_scsi(vm, each_vm_hardware), vm,
                        statInt)
                    VirtualdiskLatWrite = (
                        float(sum(statVirtualdiskLatWrite[0].value[0].value)) /
                        statInt)
                    VirtualdiskLatWrite = "{:.0f}".format(
                        VirtualdiskLatWrite
                    ) if VirtualdiskLatWrite < 25 else "{}{:.0f}{}".format(
                        bcolors.FAIL, VirtualdiskLatWrite, bcolors.ENDC)

                    if each_vm_hardware.backing.datastore.summary.type != 'vsan':
                        # Datastore Average IO
                        statDatastoreIORead = self.build_perf_query(
                            self.serviceInstance.content, self.vchtime,
                            self.stat_check(
                                self.perf_dict,
                                'datastore.numberReadAveraged.average'),
                            each_vm_hardware.backing.datastore.info.vmfs.uuid,
                            vm, statInt)
                        DatastoreIORead = (
                            float(sum(statDatastoreIORead[0].value[0].value)) /
                            statInt)

                        statDatastoreIOWrite = self.build_perf_query(
                            self.serviceInstance.content, self.vchtime,
                            self.stat_check(
                                self.perf_dict,
                                'datastore.numberWriteAveraged.average'),
                            each_vm_hardware.backing.datastore.info.vmfs.uuid,
                            vm, statInt)
                        DatastoreIOWrite = (float(
                            sum(statDatastoreIOWrite[0].value[0].value)) /
                                            statInt)

                        # Datastore Average Latency
                        statDatastoreLatRead = self.build_perf_query(
                            self.serviceInstance.content, self.vchtime,
                            self.stat_check(
                                self.perf_dict,
                                'datastore.totalReadLatency.average'),
                            each_vm_hardware.backing.datastore.info.vmfs.uuid,
                            vm, statInt)
                        DatastoreLatRead = (float(
                            sum(statDatastoreLatRead[0].value[0].value)) /
                                            statInt)
                        DatastoreLatRead = "{:.0f}".format(
                            DatastoreLatRead
                        ) if DatastoreLatRead < 25 else "{}{:.0f}{}".format(
                            bcolors.FAIL, DatastoreLatRead, bcolors.ENDC)

                        statDatastoreLatWrite = self.build_perf_query(
                            self.serviceInstance.content, self.vchtime,
                            self.stat_check(
                                self.perf_dict,
                                'datastore.totalWriteLatency.average'),
                            each_vm_hardware.backing.datastore.info.vmfs.uuid,
                            vm, statInt)
                        DatastoreLatWrite = (float(
                            sum(statDatastoreLatWrite[0].value[0].value)) /
                                             statInt)
                        DatastoreLatWrite = "{:.0f}".format(
                            DatastoreLatWrite
                        ) if DatastoreLatWrite < 25 else "{}{:.0f}{}".format(
                            bcolors.FAIL, DatastoreLatWrite, bcolors.ENDC)

                        disk_list.append(
                            'Name: {} \r\n'
                            '                     Size: {:.1f} GB \r\n'
                            '                     Thin: {} \r\n'
                            '                     File: {}\r\n'
                            '                     VirtualDisk: IORead-{:.0f}, IOWrite-{:.0f}, Latency Read-{} ms, Latency Write-{} ms \r\n'
                            '                     Datastore: IORead-{:.0f}, IOWrite-{:.0f}, Latency Read-{} ms, Latency Write-{} ms'
                            .format(
                                each_vm_hardware.deviceInfo.label,
                                each_vm_hardware.capacityInKB / 1024 / 1024,
                                each_vm_hardware.backing.thinProvisioned,
                                each_vm_hardware.backing.fileName,
                                VirtualdiskIORead, VirtualdiskIOWrite,
                                VirtualdiskLatRead, VirtualdiskLatWrite,
                                DatastoreIORead, DatastoreIOWrite,
                                DatastoreLatRead, DatastoreLatWrite))

                    else:
                        pmObjectType = pbm.ServerObjectRef.ObjectType(
                            "virtualDiskId")
                        pmRef = pbm.ServerObjectRef(key="{}:{}".format(
                            vm._moId, each_vm_hardware.key),
                                                    objectType=pmObjectType)
                        profiles = vsadmin.tools.vsanStoragePolicy.GetStorageProfiles(
                            self.pm, pmRef)
                        storagePolicy = vsadmin.tools.vsanStoragePolicy.ShowStorageProfile(
                            profiles=profiles, verbose=True)
                        disk_list.append(
                            'Name: {} \r\n'
                            '                     Size: {:.1f} GB \r\n'
                            '                     Thin: {} \r\n'
                            '                     File: {} \r\n'
                            '                     Storage Policy: {}'
                            '                     VirtualDisk: IORead-{:.0f}, IOWrite-{:.0f}, Latency Read-{} ms, Latency Write-{} ms \r\n'
                            .format(
                                each_vm_hardware.deviceInfo.label,
                                each_vm_hardware.capacityInKB / 1024 / 1024,
                                each_vm_hardware.backing.thinProvisioned,
                                each_vm_hardware.backing.fileName,
                                storagePolicy, VirtualdiskIORead,
                                VirtualdiskIOWrite, VirtualdiskLatRead,
                                VirtualdiskLatWrite))
                    # Memory Balloon
                    statMemoryBalloon = self.build_perf_query(
                        self.serviceInstance.content, self.vchtime,
                        (self.stat_check(self.perf_dict,
                                         'mem.vmmemctl.average')), "", vm,
                        statInt)
                    memoryBalloon = (float(
                        sum(statMemoryBalloon[0].value[0].value) / 1024) /
                                     statInt)
                    memoryBalloon = "{:.1f}".format(
                        memoryBalloon
                    ) if memoryBalloon <= 0 else "{}{:.1f}{}".format(
                        bcolors.WARNING, memoryBalloon, bcolors.ENDC)

                    # Memory Swapped
                    statMemorySwapped = self.build_perf_query(
                        self.serviceInstance.content, self.vchtime,
                        (self.stat_check(self.perf_dict,
                                         'mem.swapped.average')), "", vm,
                        statInt)
                    memorySwapped = (float(
                        sum(statMemorySwapped[0].value[0].value) / 1024) /
                                     statInt)
                    memorySwapped = "{:.1f}".format(
                        memorySwapped
                    ) if memorySwapped <= 0 else "{}{:.1f}{}".format(
                        bcolors.FAIL, memorySwapped, bcolors.ENDC)
                    memory = "{} MB ({:.1f} GB) [Ballooned: {} MB, Swapped: {} MB]".format(
                        summary.config.memorySizeMB,
                        (float(summary.config.memorySizeMB) / 1024),
                        memoryBalloon, memorySwapped)

                else:
                    if each_vm_hardware.backing.datastore.summary.type != 'vsan':
                        disk_list.append(
                            'Name: {} \r\n'
                            '                     Size: {:.1f} GB \r\n'
                            '                     Thin: {} \r\n'
                            '                     File: {}'.format(
                                each_vm_hardware.deviceInfo.label,
                                each_vm_hardware.capacityInKB / 1024 / 1024,
                                each_vm_hardware.backing.thinProvisioned,
                                each_vm_hardware.backing.fileName))
                    else:
                        pmObjectType = pbm.ServerObjectRef.ObjectType(
                            "virtualDiskId")
                        pmRef = pbm.ServerObjectRef(key="{}:{}".format(
                            vm._moId, each_vm_hardware.key),
                                                    objectType=pmObjectType)
                        profiles = vsadmin.tools.vsanStoragePolicy.GetStorageProfiles(
                            self.pm, pmRef)
                        storagePolicy = vsadmin.tools.vsanStoragePolicy.ShowStorageProfile(
                            profiles=profiles, verbose=False)
                        disk_list.append(
                            'Name: {} \r\n'
                            '                     Size: {:.1f} GB \r\n'
                            '                     Thin: {} \r\n'
                            '                     File: {} \r\n'
                            '                     Storage Policy: {}'.format(
                                each_vm_hardware.deviceInfo.label,
                                each_vm_hardware.capacityInKB / 1024 / 1024,
                                each_vm_hardware.backing.thinProvisioned,
                                each_vm_hardware.backing.fileName,
                                storagePolicy))

                    memory = "{} MB ({:.1f} GB)".format(
                        summary.config.memorySizeMB,
                        (float(summary.config.memorySizeMB) / 1024))

        guestToolsRunningStatus = "{}{}{}".format(
            bcolors.OKGREEN, "Running", bcolors.ENDC
        ) if vm.guest.toolsRunningStatus == "guestToolsRunning" else "{}{}{}".format(
            bcolors.FAIL, "Not running", bcolors.ENDC)
        guestToolsStatus = "{}{}{}".format(
            bcolors.OKGREEN, "OK", bcolors.ENDC
        ) if vm.guest.toolsStatus == "toolsOk" else "{}{}{}".format(
            bcolors.FAIL, "Need Attention", bcolors.ENDC)
        guestToolsVersionStatus = "{}{}{}".format(
            bcolors.OKGREEN, "Current", bcolors.ENDC
        ) if vm.guest.toolsVersionStatus == "guestToolsCurrent" else "{}{}{}".format(
            bcolors.WARNING, "Need upgrade", bcolors.ENDC)
        guestToolsVersion = vm.guest.toolsVersion

        powerStatus = "{}{}{}".format(
            bcolors.OKGREEN, summary.runtime.powerState, bcolors.ENDC
        ) if summary.runtime.powerState == "poweredOn" else "{}{}{}".format(
            bcolors.FAIL, summary.runtime.powerState, bcolors.ENDC)

        print("UUID               : {}".format(summary.config.instanceUuid))
        print("Name               : {}".format(summary.config.name))
        print("VMRC               : vmrc://{}:443/?moid={}".format(
            self.server, self.get_moref(vm)))
        print("Guest              : {}".format(summary.config.guestFullName))
        print("State              : {}".format(powerStatus))
        print(
            "Guest Tools Status : Status: {} | Version Status: {} | Version: {} | Health: {}"
            .format(guestToolsRunningStatus, guestToolsVersionStatus,
                    guestToolsVersion, guestToolsStatus))
        print("Cluster            : {}".format(
            summary.runtime.host.parent.name))
        print("Host               : {}".format(summary.runtime.host.name))
        print("Folder             : {}".format(self.print_folder_tree(vm)))
        print("Number of vCPUs    : {}".format(summary.config.numCpu))
        print("Memory             : {}".format(memory))
        print("VM .vmx Path       : {}".format(summary.config.vmPathName))

        vmxDatastoreName = re.match(r'\[(.*)\]',
                                    summary.config.vmPathName).group(1)
        vmxDatastore = self.find_datastore_by_name(vmxDatastoreName)
        if vmxDatastore.summary.type == 'vsan':
            pmObjectType = pbm.ServerObjectRef.ObjectType("virtualMachine")
            pmRef = pbm.ServerObjectRef(key=vm._moId, objectType=pmObjectType)
            profiles = vsadmin.tools.vsanStoragePolicy.GetStorageProfiles(
                self.pm, pmRef)
            storagePolicy = vsadmin.tools.vsanStoragePolicy.ShowStorageProfile(
                profiles=profiles, verbose=verbose)
            print("                     Storage Policy: {}".format(
                storagePolicy))

        print("Virtual Disks      :")
        if len(disk_list) > 0:
            first = True
            for each_disk in disk_list:
                if first:
                    first = False
                else:
                    print("")
                print("                     {}".format(each_disk))

        if vm.guest.net != []:
            print("Network            : ")
            for card in vm.guest.net:
                print("                     Name: {}".format(card.network))
                if card.deviceConfigId != -1:
                    hwdevice = next((item for item in vm.config.hardware.device
                                     if item.key == card.deviceConfigId), None)
                    print("                     Connected: {}".format(
                        hwdevice.connectable.connected))
                print("                     Mac: {}".format(card.macAddress))
                if card.ipConfig is not None:
                    for ips in card.ipConfig.ipAddress:
                        print("                     IP: {}".format(
                            ips.ipAddress))
                print("")
        if vm.guest.ipStack != []:
            for gateway in vm.guest.ipStack[0].ipRouteConfig.ipRoute:
                if gateway.network == '0.0.0.0':
                    print("                     Default GW: {}".format(
                        gateway.gateway.ipAddress))
            print("")
            print("Guest Hostname     : {}".format(
                vm.guest.ipStack[0].dnsConfig.hostName))
            print("DNS                :")
            for dns in vm.guest.ipStack[0].dnsConfig.ipAddress:
                print("                     Address: {}".format(dns))
            print("                     Search Domain: {}".format(
                vm.guest.ipStack[0].dnsConfig.domainName))

        customfields = next((item for item in summary.customValue
                             if item.key == self.lastnetworkinfokey), None)
        if customfields is not None and customfields.value != "":
            print("Last Network Info  : {}".format(customfields.value))

        if summary.runtime.question is not None:
            print("Question  : {}".format(summary.runtime.question.text))

        annotation = summary.config.annotation
        if annotation is not None and annotation != "":
            print("Notes              : {}".format(annotation))