コード例 #1
0
def getHostProfileEngine():
    options = get_options()
    global _si
    if _si:
        Disconnect(_si)
    _si = Connect(host=options.host,
                  user=options.user,
                  version="vim.version.version9",
                  pwd=options.password)
    return _si.RetrieveInternalContent().hostProfileEngine
コード例 #2
0
ファイル: compareStats.py プロジェクト: free-Zen/pvc
def GetParams(hostName, userName, password):
    try:
        siHost = Connect(host=hostName,
                         user=userName,
                         pwd=password,
                         version="vim.version.version9")
    except vim.fault.HostConnectFault:
        Log("Failed to connect to %s" % hostName)
        raise

    atexit.register(Disconnect, siHost)
    perfManager = siHost.RetrieveContent().perfManager
    hostSystem = host.GetHostSystem(siHost)
    hbrManager = siHost.RetrieveInternalContent().hbrManager
    return siHost, perfManager, hostSystem, hbrManager
コード例 #3
0
def main():
    # Process command line
    global options
    options = GetOptions()

    si = Connect(host=options.host,
                 user=options.user,
                 namespace=newestVersions.GetNamespace('vim'),
                 pwd=options.password)

    if not options.keep:
        # If we are going to keep the queries we should not disconnect
        # because the sessions will be destroyed together with all queries.
        atexit.register(Disconnect, si)

    hsi = si.RetrieveInternalContent()
    srEndpoints = hsi.GetStatsRegistry()
    for sr in srEndpoints:
        if options.endpoint is None or sr._GetMoId() == options.endpoint:
            TestStatsRegistryEndpoint(sr)
            if not options.keep:
                ClearQueries(sr)
コード例 #4
0
ファイル: TestApplyHostConfig.py プロジェクト: free-Zen/pvc
class TestApplyHostConfig(unittest.TestCase):
    def setOptions(self, options):
        """
      Command line options
      """
        self.options = options

    def setUp(self):
        """
      Setting test suite
      """
        options = get_options()

        self.si = Connect(host=self.options.host,
                          user=self.options.user,
                          version="vim.version.version9",
                          pwd=self.options.password)
        self.content = self.si.RetrieveContent()
        self.internalContent = self.si.RetrieveInternalContent()
        rootFolder = self.content.GetRootFolder()
        dataCenter = rootFolder.GetChildEntity()[0]
        hostFolder = dataCenter.hostFolder
        host = hostFolder.childEntity[0]
        self.hostSystem = host.host[0]
        configManager = self.hostSystem.GetConfigManager()
        self.cacheConfigManager = configManager.cacheConfigurationManager
        self.hostProfileEngine = self.internalContent.hostProfileEngine
        self.profileManager = self.hostProfileEngine.hostProfileManager

    def tearDown(self):
        """
      Reset test suite
      """
        Disconnect(self.si)

    def runTest(self):
        self.TestApplyEmptyConfig()

    def TestApplyEmptyConfig(self):
        """
      Applies an empty config and check if property update on
      CacheConfigurationManager is fired.
      """

        self.assertTrue(self.cacheConfigManager != None,
                        "cacheConfigManager should not be None")

        self.assertTrue(self.profileManager != None,
                        "profileManager should not be None")

        # Prepare property collector

        objSpec = Vmodl.Query.PropertyCollector.ObjectSpec(
            obj=self.cacheConfigManager, skip=False, selectSet=[])
        propSpec = Vmodl.Query.PropertyCollector.PropertySpec(
            type=self.cacheConfigManager.__class__,
            all=False,
            pathSet=["cacheConfigurationInfo"])
        filterSpec = Vmodl.Query.PropertyCollector.FilterSpec(
            propSet=[propSpec], objectSet=[objSpec])
        filter = self.content.propertyCollector.CreateFilter(filterSpec, False)

        # First initial call
        updateSet = self.content.propertyCollector.WaitForUpdates()
        version = updateSet.version

        # ApplyHostConfig

        spec = Vim.Host.ConfigSpec()
        task = self.profileManager.ApplyHostConfig(configSpec=spec)
        WaitForTask(task)

        self.assertTrue(task.info.state == 'success',
                        "Reconfiguration task should succeed")

        # Set up wait time and trigger update
        waitSpec = Vmodl.Query.PropertyCollector.WaitOptions()
        waitSpec.maxWaitSeconds = 5
        updateSet = self.content.propertyCollector.WaitForUpdatesEx(
            version, waitSpec)
        self.assertTrue(updateSet != None,
                        "we should get property collector update")
コード例 #5
0
ファイル: HostDvsOps.py プロジェクト: free-Zen/pvc
def main():
    """
    Simple command-line program for doing DVS operations on a host.
    """

    options = get_options()

    si = Connect(host=options.host,
                 user=options.user,
                 namespace="vim25/5.5",
                 pwd=options.password)

    dvsManager = si.RetrieveInternalContent(
    ).hostDistributedVirtualSwitchManager

    if options.operation == "list":
        print dvsManager.distributedVirtualSwitch
    elif options.operation == "print":
        dvsConfig = dvsManager.RetrieveDvsConfigSpec(options.uuid)
        print "" + str(dvsConfig)
    elif options.operation == "create":
        if options.name == "":
            print "switch name needed for DVS creation"
            exit(1)

        prodSpec = Vim.Dvs.ProductSpec(vendor="VMware")
        port1 = Vim.Dvs.HostDistributedVirtualSwitchManager.PortData(
            portKey="1000", name="1000", connectionCookie=5)
        port2 = Vim.Dvs.HostDistributedVirtualSwitchManager.PortData(
            portKey="1001", name="1001", connectionCookie=2)
        port3 = Vim.Dvs.HostDistributedVirtualSwitchManager.PortData(
            portKey="1009", name="1009", connectionCookie=12)

        nicBacking = GetPnicBacking(options.pnicBacking)
        createSpec = Vim.Dvs.HostDistributedVirtualSwitchManager.DVSCreateSpec(
            uuid=options.uuid,
            name=options.name,
            backing=nicBacking,
            productSpec=prodSpec,
            maxProxySwitchPorts=options.numPorts,
            port=[
                port1,
                port2,
                port3,
            ],
            uplinkPortKey=["1000", "1001"],
            modifyVendorSpecificDvsConfig=False,
            modifyVendorSpecificHostMemberConfig=False)
        #        print SerializeToConfig(createSpec)
        dvsManager.CreateDistributedVirtualSwitch(createSpec)
    elif options.operation == "delete":
        dvsManager.RemoveDistributedVirtualSwitch(options.uuid)
    elif options.operation == "updatePorts":
        if options.portSpec == "":
            print "portSpec needed for DVPort updates"
            exit(1)

        portList = options.portSpec.split(',')
        portDataList = []
        for port in portList:
            (pk, name, cid) = port.split(':')
            portData = Vim.Dvs.HostDistributedVirtualSwitchManager.PortData(
                portKey=pk, name=name, connectionCookie=int(cid))
            portDataList.append(portData)

        dvsManager.UpdatePorts(options.uuid, portDataList)

    elif options.operation == "delPorts":
        if options.portList == "":
            print "Port list needed for DVPort deletion"
            exit(1)

        portList = options.portList.split(',')
        dvsManager.DeletePorts(options.uuid, portList)
    elif options.operation == "updateNics":
        nicBacking = GetPnicBacking(options.pnicBacking)

        configSpec = Vim.Dvs.HostDistributedVirtualSwitchManager.DVSConfigSpec(
            uuid=options.uuid, backing=nicBacking)

        #print configSpec
        dvsManager.ReconfigureDistributedVirtualSwitch(configSpec)
    elif options.operation == "printPortData":
        if (options.portList == ""):
            portList = None
        else:
            portList = options.portList.split(',')
        print dvsManager.FetchPortState(options.uuid, portList)
    print("DONE.")
コード例 #6
0
class TestEsxCLI(unittest.TestCase):

   def setOptions(self, options):
      """
      Command line options
      """
      self.options = options

   def run_command(self, cmdLine):
      """
      Executes a local shell command.
      """
      print("\nRunning " + cmdLine)
      p = subprocess.Popen(cmdLine, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      outdata, errdata = p.communicate()
      self.assertTrue(errdata != None,
                      "Error running remote esxcli command (%s):\n%s" % (cmdLine,errdata))
      return outdata

   def run_remote_command(self, cmd):
      """
      Executes a command remotely via ssh.
      Assumes you've got password-less login already set up.
      """
      return self.run_command("ssh %s@%s 'sh -lc \"%s\"'" % (self.options.user, self.options.host, cmd))

   def setUp(self):
      """
      Setting test suite
      """
      options = get_options()

      self.si = Connect(host=self.options.host,
                        user=self.options.user,
                        version="vim.version.version9",
                        pwd=self.options.password)
      self.content = self.si.RetrieveContent()
      self.internalContent = self.si.RetrieveInternalContent()
      rootFolder = self.content.GetRootFolder()
      dataCenter = rootFolder.GetChildEntity()[0]
      hostFolder = dataCenter.hostFolder
      host = hostFolder.childEntity[0]
      self.hostSystem = host.host[0]
      configManager = self.hostSystem.GetConfigManager()
      self.advOptions = configManager.advancedOption

   def tearDown(self):
      """
      Reset test suite
      """
      Disconnect(self.si)

   def runTest(self):
      self.test_esx_cli()

   def test_esx_cli(self):
      """
      Applies an empty config and check if property update on
      CacheConfigurationManager is fired.
      """

      self.assertTrue(self.advOptions != None,
                      "cacheConfigManager should not be None")

      # Prepare property collector

      objSpec = Vmodl.Query.PropertyCollector.ObjectSpec(
                     obj = self.advOptions,
                     skip = False,
                     selectSet = [])
      propSpec = Vmodl.Query.PropertyCollector.PropertySpec(
                     type = self.advOptions.__class__,
                     all = False,
                     pathSet = ["setting"])
      filterSpec = Vmodl.Query.PropertyCollector.FilterSpec(
                     propSet = [ propSpec ],
                     objectSet = [ objSpec ])
      pc_filter = self.content.propertyCollector.CreateFilter(filterSpec, False)

      # First initial call
      updateSet = self.content.propertyCollector.WaitForUpdates()
      version = updateSet.version

      option_key = "Disk.MaxLUN"
      option_value = filter(lambda x: x.key == option_key, self.advOptions.setting)[0]
      value =int(option_value.value)

      cmd = "esxcli system settings advanced set -o /%s -i %d" %\
            (option_key.replace(".","/"), value-1)
      self.run_remote_command(cmd)

      # Set up wait time and trigger update
      waitSpec = Vmodl.Query.PropertyCollector.WaitOptions()
      waitSpec.maxWaitSeconds = 5
      updateSet = self.content.propertyCollector.WaitForUpdatesEx(version,
                                                                  waitSpec)
      # restores old value regardless of outcome
      cmd = "esxcli system settings advanced set -o /%s -i %d" %\
            (option_key.replace(".","/"), value)
      self.run_remote_command(cmd)

      self.assertTrue(updateSet != None,
                      "we should get property collector update")

      object_set = filter(lambda x: x.obj._wsdlName == "OptionManager",
                       updateSet.filterSet[0].objectSet)[0]

      option_value = filter(lambda x: x.key == option_key, object_set.changeSet[0].val)[0]
      self.assertTrue(option_value.value == value-1)