zoukankan      html  css  js  c++  java
  • PyVmomi 使用示例

    PyVmomi: VMware vSphere Python SDK


    一、OverView

    重点知识:
      1、view_type = [vim.VirtualMachine]
      2、content.viewManager.CreateContainerView()
      3、child.summary.config
    def print_vm_info(virtual_machine):
        """
        Print information for a particular virtual machine or recurse into a
        folder with depth protection
        """
        summary = virtual_machine.summary
        print("Name       : ", summary.config.name)
        print("Template   : ", summary.config.template)
        print("Path       : ", summary.config.vmPathName)
        print("Guest      : ", summary.config.guestFullName)
        print("Instance UUID : ", summary.config.instanceUuid)
        print("Bios UUID     : ", summary.config.uuid)
        print("State      : ", summary.runtime.powerState)
    
        # 判断是否有注释
        annotation = summary.config.annotation
        if annotation:
            print("Annotation : ", annotation)
    
        # 打印Guest OS内的信息
        if summary.guest is not None:
            ip_address = summary.guest.ipAddress
            tools_version = summary.guest.toolsStatus
            if tools_version is not None:
                print("VM-tools: ", tools_version)
            else:
                print("V-tools: None")
            if ip_address:
                print("IP         : ", ip_address)
            else:
                print("IP         : None")
    
    
    
    content = service_instance.RetrieveContent()  # 拿到vCenter的内容对象
    container = content.rootFolder  # starting point to look into
    view_type = [vim.VirtualMachine]  # object types to look for
    recursive = True  # whether we should look into it recursively
    container_view = content.viewManager.CreateContainerView(container, view_type, recursive)
    
    children = container_view.view
    for child in children:
        print_vm_info(child)

    二、虚拟机状态、配置信息

    1、runtime 虚拟机的运行状态

    runtime = (vim.vm.RuntimeInfo) {
          dynamicType = <unset>,
          host = 'vim.HostSystem:host-34',
          connectionState = 'connected',
          powerState = 'poweredOn',  // 虚拟机电源状态
          faultToleranceState = 'notConfigured',  // 是否配置FT
          dasVmProtection = <unset>,
          toolsInstallerMounted = false,
          suspendTime = <unset>,
          bootTime = 2017-08-26T06:31:27.543474Z,
          suspendInterval = 0,
          question = <unset>,
          memoryOverhead = <unset>,
          maxCpuUsage = 2808,
          maxMemoryUsage = 891,
          numMksConnections = 0,
          recordReplayState = 'inactive',
          cleanPowerOff = <unset>,
          needSecondaryReason = <unset>,
          onlineStandby = false,
          minRequiredEVCModeKey = <unset>,
          consolidationNeeded = false,
    }

    2、Guest操作系统信息(不建议使用,应为受到VMtools影响)

    guest = (vim.vm.Summary.GuestSummary) {
          dynamicType = <unset>,
          dynamicProperty = (vmodl.DynamicProperty) [],
          guestId = 'ubuntu64Guest',
          guestFullName = 'Ubuntu Linux (64-bit)',
          toolsStatus = 'toolsOk',  // VMtools状态
          toolsVersionStatus = 'guestToolsUnmanaged',
          toolsVersionStatus2 = 'guestToolsUnmanaged',
          toolsRunningStatus = 'guestToolsRunning',
          hostName = 'ubuntu001',  // hostname
          ipAddress = '172.16.65.146'  // ipaddress
    }

    3、虚拟机配置

    config = (vim.vm.Summary.ConfigSummary) {
          dynamicType = <unset>,
          dynamicProperty = (vmodl.DynamicProperty) [],
          name = 'Ubuntu16.04',
          template = false,
          vmPathName = '[datastore1] Ubuntu16.04/Ubuntu16.04.vmx',
          memorySizeMB = 1024,
          cpuReservation = 0,
          memoryReservation = 0,
          numCpu = 1,
          numEthernetCards = 1,
          numVirtualDisks = 1,
          uuid = '4239b0ea-cbb8-c0b2-56a1-0b98bdbf01dd',
          instanceUuid = '5039f07c-47c6-d77d-e793-bf1b7aee17e2',
          guestId = 'ubuntu64Guest',
          guestFullName = 'Ubuntu Linux (64-bit)',
          annotation = 'Ubuntu Server',
          product = <unset>,
          installBootRequired = false,
          ftInfo = <unset>,
          managedBy = <unset>
       },

    4、虚拟机磁盘信息

    storage = (vim.vm.Summary.StorageSummary) {
          dynamicType = <unset>,
          dynamicProperty = (vmodl.DynamicProperty) [],
          committed = 18424777995,
          uncommitted = 505,
          unshared = 17179869184,
          timestamp = 2017-08-26T08:37:37.764585Z
       },

    。。。。







  • 相关阅读:
    thinkphp自动映射分析
    thinkphp自动创建数据对象分析
    html模板输头部出现"&#65279"
    register_shutdown_function 函数详解
    mcrypt加密以及解密过程
    SVN不能解锁,报错:没有匹配的可用锁令牌的解决方法
    微信公众平台JSSDK开发
    PHP的UTF-8中文转拼音处理类
    PHP中文转拼音函数
    php生成mysql数据字典
  • 原文地址:https://www.cnblogs.com/vincenshen/p/7436042.html
Copyright © 2011-2022 走看看