Ejemplo n.º 1
0
 def _copyHostProfile(self, hostProfile):
     """Helper function that makes a copy of the host profile document.
   """
     # TBD: Is there a better way than serializing/deserializing?
     serializedProf = SoapAdapter.Serialize(
         hostProfile, version=newestVersions.get('vim'))
     deserializedProf = SoapAdapter.Deserialize(serializedProf)
     return deserializedProf
Ejemplo n.º 2
0
 def __init__(self,
              version=newestVersions.get('vim'),
              printRequest=False,
              printResponse=False):
     SoapAdapter.SoapStubAdapter.__init__(self, version=version)
     self.ns = VmomiSupport.GetVersionNamespace(version)
     self.soapHandler = SoapHandler.SoapHandler()
     self.soapDeserializer = SoapAdapter.SoapResponseDeserializer(self)
     self.printRequest = printRequest
     self.printResponse = printResponse
     ImportTypesAndManagedObjects()
Ejemplo n.º 3
0
def main():
    # connect to vc, host
    vc = "10.161.250.162"
    user1 = "*****@*****.**"
    pwd1 = "Admin!23"
    si = Connect(host=vc,
                 user=user1,
                 pwd=pwd1,
                 version=newestVersions.get('vim'))
    print("Connected to VC: " + vc)
    host, hostSystem, dc = VerifySetup(si)
    vimInternalNs = newestVersions.GetInternalNamespace('vim')
    session = CreateSession(vc, '443', user1, pwd1, vimInternalNs)
    # ds0 should be a vmfs 6 datastore
    ds0 = session.GetDatastore(host, "ds0")

    #hwversion test
    hwVersionTest(host, hostSystem, ds0, dc, session)
Ejemplo n.º 4
0
    def setUp(self):
        """
      Setting test suite
      """
        options = get_options()

        self.si = Connect(host=self.options.host,
                          user=self.options.user,
                          version=newestVersions.get("vim"),
                          pwd=self.options.password)
        content = self.si.RetrieveContent()
        rootFolder = content.GetRootFolder()
        dataCenter = rootFolder.GetChildEntity()[0]
        hostFolder = dataCenter.hostFolder
        host = hostFolder.childEntity[0]
        self.hostSystem = host.host[0]
        configManager = self.hostSystem.GetConfigManager()
        self.imageConfigManager = configManager.GetImageConfigManager()
        self.hostConfigInfo = self.hostSystem.config
Ejemplo n.º 5
0
 def setUp(self):
    self.version = newestVersions.get('vim')
    self.versionUri = VmomiSupport.GetVersionNamespace(self.version)
    self.futureVersionUri = "vim25/foo"
    self.badVersionUri = "notvim/foo"
    self.stub = SoapAdapter.SoapStubAdapter(version=self.version)
    self.deserializer = SoapAdapter.SoapResponseDeserializer(self.stub)
    self.soapHeaderBegin = \
       """<?xml version="1.0" encoding="UTF-8"?>
          <soapenv:Envelope
             xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
             xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
             xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <soapenv:Body>"""
    self.soapHeaderEnd = \
       """</soapenv:Body>
          </soapenv:Envelope>"""
    ImportTypesAndManagedObjects()
Ejemplo n.º 6
0
def main():
   supportedArgs = [ (["h:", "host="], "localhost", "Host name", "host"),
                    (["u:", "user="******"root", "User name", "user"),
                    (["p:", "pwd="], "", "password", "pwd"),
                    (("t:", "test="), "lun", "test lun, vmfs, or nas", "test")
                    ]

   supportedToggles = [ (["usage", "help"], False, "Show usage information", "usage") ]

   args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
   if args.GetKeyValue("usage") == True:
      args.Usage()
      sys.exit(0)

   si = Connect(host=args.GetKeyValue("host"),
                user=args.GetKeyValue("user"),
                pwd=args.GetKeyValue("pwd"),
                version=newestVersions.get('vim'))

   atexit.register(Disconnect, si)
   global datastoreSystem
   datastoreSystem = host.GetHostConfigManager(si).GetDatastoreSystem()
   global storageSystem
   storageSystem = host.GetHostConfigManager(si).GetStorageSystem()
   test = args.GetKeyValue("test")
   if test == "lun":
      LunVerify()
      LunSimpleTest()
      LunNegativeTest()
   elif test == "vmfs":
      VmfsVerify()
      VmfsSimpleTest()
      VmfsNegativeTest()
   elif test == "nas":
      NasVerify()
      NasSimpleTest()
      NasNegativeTest()
   else:
      raise Exception("Unsupported test = " + test)
Ejemplo n.º 7
0
 def setUp(self):
     self.stub = StubsCommon.GetStub(self, newestVersions.get('vim'))
     self.moId = "ha-dynamic-type-manager-python"
Ejemplo n.º 8
0
from pyVim.connect import VimSessionOrientedStub, SmartStubAdapter
from pyVmomi import Hbr
from pyVmomi import Hostd
from pyVmomi import Vim
from pyVmomi import Vmodl, SoapStubAdapter, SessionOrientedStub
from pyVmomi.VmomiSupport import newestVersions

logger = logging.getLogger('pyHbr.servercnx')

DEFAULT_VMODL_PORT = 8123

#
# This corresponds to the HBR VMODL API version that will be used to connect
# to the hbrsrv.
#
HBR_CURRENT_VMODL_VERSION = newestVersions.get('hbr.replica')

#
# This is the list of vim versions that we'll connect to in order
# of most to least preference. The current version should always
# be first so we can use it if it's available.
#
# When new vim versions are added we need to add them here.
#
# See $VMTREE/vim/vmodl/vim/version/version<latest num>.java
#
HBR_VIM_VERSIONS = [
        newestVersions.get('vim'),
        "vim.version.version12",
        "vim.version.version11",
        "vim.version.version10",
Ejemplo n.º 9
0
def main():
    # Process command line
    supportedArgs = [(["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "", "Password", "pwd")]

    supportedToggles = [(["usage",
                          "help"], False, "Show usage information", "usage")]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    si = Connect(host=args.GetKeyValue("host"),
                 user=args.GetKeyValue("user"),
                 pwd=args.GetKeyValue("pwd"),
                 version=newestVersions.get('vim'))
    dc, ds, host, srcHost = VerifySetup(si)
    global destResPool
    destResPool = host.GetParent().GetResourcePool()
    test = 'postive flat 2TB+ test: '
    BaseTest(dc, ds.GetName(), None, 'flat', None, TWOTB_IN_MB, True, test)
    test = 'postive sesparse 2TB+ test: '
    BaseTest(dc, ds.GetName(), None, 'seSparse', None, TWOTB_IN_MB, True, test)
    test = 'postive flat 2TB+ vm version test: '
    BaseTest(dc, ds.GetName(), None, 'flat', 'vmx-08', TWOTB_IN_MB, True, test)
    test = 'postive sesparse 2TB+ vm version test: '
    BaseTest(dc, ds.GetName(), None, 'seSparse', 'vmx-08', TWOTB_IN_MB, True,
             test)
    test = 'postive flat < 2TB test: '
    BaseTest(dc, ds.GetName(), host, 'flat', None, TWOGB_IN_MB, True, test)
    test = 'postive sesparse < 2TB test: '
    BaseTest(dc, ds.GetName(), host, 'seSparse', None, TWOGB_IN_MB, True, test)
    test = 'positive flat < 2TB, vm version test: '
    BaseTest(dc, ds.GetName(), host, 'flat', 'vmx-08', TWOGB_IN_MB, True, test)
    test = 'Negative sesparse < 2TB, vm version test: '
    BaseTest(dc, ds.GetName(), host, 'seSparse', 'vmx-08', TWOGB_IN_MB, False,
             test)

    test = 'positive delta flat 2TB+ test: '
    DeltaTest(dc, ds.GetName(), None, 'flat', None, TWOTB_IN_MB, None, True,
              test)
    test = 'positive delta sesparse 2TB+ test: '
    DeltaTest(dc, ds.GetName(), None, 'seSparse', None, TWOTB_IN_MB, None,
              True, test)
    test = 'positive delta flat 2TB+ vm version test: '
    DeltaTest(dc, ds.GetName(), None, 'flat', None, TWOTB_IN_MB, 'vmx-08',
              True, test)
    test = 'positive delta sesparse 2TB+ vm version test: '
    DeltaTest(dc, ds.GetName(), None, 'seSparse', None, TWOTB_IN_MB, 'vmx-08',
              True, test)
    test = 'negative delta flat 2TB+ redolog test: '
    DeltaTest(dc, ds.GetName(), None, 'flat', 'redoLogFormat', TWOTB_IN_MB,
              None, False, test)
    test = 'positive delta flat < 2TB test: '
    DeltaTest(dc, ds.GetName(), host, 'flat', None, TWOGB_IN_MB, None, True,
              test)
    test = 'positive delta sesparse < 2TB test: '
    DeltaTest(dc, ds.GetName(), host, 'seSparse', None, TWOGB_IN_MB, None,
              True, test)
    test = 'positive delta flat < 2TB vm version test: '
    DeltaTest(dc, ds.GetName(), host, 'flat', None, TWOGB_IN_MB, 'vmx-08',
              True, test)
    test = 'negative delta sesparse < 2TB test: '
    DeltaTest(dc, ds.GetName(), host, 'seSparse', 'seSparseFormat',
              TWOGB_IN_MB, 'vmx-08', False, test)
    test = 'negative delta sesparse < 2TB test 2: '
    DeltaTest(dc, ds.GetName(), host, 'flat', 'seSparseFormat', TWOGB_IN_MB,
              'vmx-08', False, test)
    test = 'postive relocate 2TB+ test: '
    RelocateTest(srcHost, dc, ds.GetName(), host, 'flat', None, TWOTB_IN_MB,
                 None, True, test)
Ejemplo n.º 10
0
Archivo: vcFT.py Proyecto: free-Zen/pvc
def main():
    supportedArgs = [
        (["H:", "hosts="], "", "List of hosts (comma separated)", "hosts"),
        (["D:", "dcName="], "Datacenter", "datacenter name", "dcName"),
        (["d:", "dsName="], "storage1", "shared datastore name", "dsName"),
        (["dsMount="], "", "server:path of datastore to mount", "dsMount"),
        (["k:", "keep="], "0", "Keep configs", "keep"),
        (["l:",
          "leaveRunning="], False, "Leave FT VMs running", "leaveRunning"),
        (["L:", "leaveRegistered="], False,
         "Leave FT VMs configured but not powered on", "leaveRegistered"),
        (["e:", "useExistingVm="], False, "Use existing VM", "useExistingVm"),
        (["r:", "checkRRState="], "True", "Validate Record/Replay states",
         "checkRRState"), (["V:", "vc="], "", "VC Server name", "vc"),
        (["u:", "user="******"root", "User name", "user"),
        (["p:", "pwd="], "vmware", "Password", "pwd"),
        (["v:", "vmname="], "vmFT", "Name of the virtual machine", "vmname")
    ]

    supportedToggles = [(["usage",
                          "help"], False, "Show usage information", "usage")]

    args = arguments.Arguments(sys.argv, supportedArgs, supportedToggles)
    if args.GetKeyValue("usage") == True:
        args.Usage()
        sys.exit(0)

    # Process command line
    primaryName = args.GetKeyValue("vmname")
    keep = int(args.GetKeyValue("keep"))
    vc = args.GetKeyValue("vc")
    leaveRegistered = bool(args.GetKeyValue("leaveRegistered"))
    leaveRunning = bool(args.GetKeyValue("leaveRunning"))
    useExistingVm = bool(args.GetKeyValue("useExistingVm"))
    global checkRRState
    checkRRState = eval(args.GetKeyValue("checkRRState"))
    dsName = args.GetKeyValue("dsName")
    dsMount = args.GetKeyValue("dsMount")
    dcName = args.GetKeyValue("dcName")
    hostList = args.GetKeyValue("hosts")
    hosts = re.split('\s*,\s*', hostList)
    hostSystems = []

    # Connect to VC server
    global si
    Log("Connecting to %s" % vc)
    si = connect.Connect(host=vc,
                         user=args.GetKeyValue("user"),
                         pwd=args.GetKeyValue("pwd"),
                         version=newestVersions.get('vim'))
    if si is None:
        raise Exception("Failed to connect to VC")
    connect.SetSi(si)
    Log("Connected to VC Server")

    dc = CreateOrUseDC(si, dcName)
    cluster = CreateOrUseCluster(dc, "HA")

    for host in hosts:
        hostSystem = GetHostByName(si, host)
        if hostSystem is not None and hostSystem.runtime.connectionState != "connected":
            task.WaitForTask(hostSystem.Destroy())
            hostSystem = None
        if hostSystem == None:
            Log("Failed to find %s" % host)
            hostSystem = AddHostToCluster(si, cluster, host)
        hostSystems.append(hostSystem)
        if len(FindNicType(si, hostSystem, ftLoggingNicType)) == 0:
            SelectVnic(si, hostSystem, "vmk0", ftLoggingNicType)
        if len(FindNicType(si, hostSystem, vmotionNicType)) == 0:
            SelectVnic(si, hostSystem, "vmk0", vmotionNicType)
        ds = FindDS(hostSystem, dsName)
        if ds is None and dsMount:
            MountNas(hostSystem, dsName, dsMount, accessMode="readWrite")

    secondaryName = primaryName
    orphanedSecondaryName = primaryName + "_orphaned"

    global primaryVm
    global secondaryVm

    primaryVm = None
    si = None
    try:
        CleanupVm(primaryName)

        # Create new VM
        primaryVm = None
        if useExistingVm:
            primaryVm = folder.Find(primaryName)
            if primaryVm == None:
                raise Exception("No primary VM with name " + primaryName +
                                " found!")
            Log("Using primary VM " + primaryName)
        else:
            Log("Creating primary VM " + primaryName)
            # Short delay to avoid colliding with a cleanup.
            time.sleep(5)
            primaryVm = vm.CreateQuickDummy(primaryName,
                                            guest="winXPProGuest",
                                            cdrom=0,
                                            numScsiDisks=2,
                                            scrubDisks=False,
                                            datastoreName=dsName,
                                            vmxVersion="vmx-09",
                                            dc=dcName)
            spec = vim.vm.ConfigSpec(numCPUs=2)
            task.WaitForTask(primaryVm.Reconfigure(spec))

        # Get details about primary VM
        primaryUuid = primaryVm.GetConfig().GetInstanceUuid()
        primaryCfgPath = primaryVm.GetConfig().GetFiles().GetVmPathName()
        primaryDir = primaryCfgPath[:primaryCfgPath.rfind("/")]
        Log("Using VM : " + primaryVm.GetName() + " with instanceUuid " +
            primaryUuid)
        CheckFTState(primaryVm, FTState.notConfigured)

        # Create secondary VM
        Log("Creating secondary VM " + secondaryName)
        HandleAction("on")

        if secondaryVm == None:
            raise "Secondary VM creation failed"

        ##  Configure some additional config variables needed for FT
        ##  This should eventually be done automatically at FT Vmotion time
        Log("Setting up extra config settings for the primary VM...")
        extraCfgs = primaryVm.GetConfig().GetExtraConfig()
        #      AddExtraConfig(extraCfgs, "replay.allowBTOnly", "TRUE")
        #      AddExtraConfig(extraCfgs, "replay.allowFT", "TRUE")
        cSpec = vim.Vm.ConfigSpec()
        cSpec.SetExtraConfig(extraCfgs)
        task.WaitForTask(primaryVm.Reconfigure(cSpec))

        Log("FT configured successfully.")

        # Test snapshot
        #SnapshotTests(primaryVm)

        Log("PowerOn")
        task.WaitForTask(primaryVm.PowerOn())

        WaitForRunning()
        time.sleep(5)

        # We are now in a good known state, start random testing
        while True:
            action = random.choice(ACTION_LIST)
            revAction = REV_ACTION[action]
            HandleActions(action, revAction)

    except Exception as e:
        Log("Caught exception : " + str(e))
        traceback.print_exc()
        global status
        status = "FAIL"
    finally:
        connect.Disconnect(si)