Пример #1
0
def addRdmDisk(options, machine, shared):
    cspec = Vim.Vm.ConfigSpec()
    diskDev = VirtualDisk()
    diskDev.key = vmconfig.GetFreeKey(cspec)
    diskDev.controllerKey = 1000
    diskDev.capacityInKB = long(1024)
    diskDev.unitNumber = -1

    diskBacking = VirtualDisk.RawDiskMappingVer1BackingInfo()
    diskBacking.fileName = ""
    diskBacking.diskMode = VirtualDiskOption.DiskMode.persistent
    diskBacking.deviceName = options.disk
    if shared:
        diskBacking.sharing = VirtualDisk.Sharing.sharingMultiWriter
    diskBacking.compatibilityMode = VirtualDiskOption.CompatibilityMode.physicalMode
    diskDev.backing = diskBacking

    vmconfig.AddDeviceToSpec(cspec, diskDev, VirtualDeviceSpec.Operation.add,
                             VirtualDeviceSpec.FileOperation.create)

    vm.Reconfigure(machine, cspec)
    Log("Reconfigure(%s) - add RDM disk" % machine.name)
Пример #2
0
def addFlatDisk(options, machine, shared):
    cspec = Vim.Vm.ConfigSpec()
    diskDev = VirtualDisk()
    diskDev.key = vmconfig.GetFreeKey(cspec)
    diskDev.controllerKey = 1000
    diskDev.capacityInKB = long(1024)
    diskDev.unitNumber = -1

    diskBacking = VirtualDisk.FlatVer2BackingInfo()
    diskBacking.fileName = "[" + options.datastore + "]"
    diskBacking.diskMode = VirtualDiskOption.DiskMode.persistent
    if shared:
        diskBacking.sharing = VirtualDisk.Sharing.sharingMultiWriter
    diskBacking.thinProvisioned = False
    diskBacking.eagerlyScrub = True
    diskDev.backing = diskBacking

    vmconfig.AddDeviceToSpec(cspec, diskDev, VirtualDeviceSpec.Operation.add,
                             VirtualDeviceSpec.FileOperation.create)

    vm.Reconfigure(machine, cspec)
    Log("Reconfigure(%s) -> add flat disk" % machine.name)
Пример #3
0
def main():
   supportedArgs = [ (["h:", "host="], "localhost", "Host name", "host"),
                     (["u:", "user="******"root", "User name", "user"),
                     (["p:", "pwd="], "ca$hc0w", "Password", "pwd"),
                     (["d:", "disk="], "/vmfs/devices/", "Disk", "disk"),
                     (["s:", "ds="], "storage1", "Datastore 1", "ds"),
                     (["f:", "file="], "[datastore1] rdm/rdm.vmdk", "Virtual Disk", "file"),
                     (["v:", "vmname="], "RdmVM", "Name of the virtual machine", "vmname"),
                     (["i:", "numiter="], "1", "Number of iterations", "iter") ]

   supportedToggles = [ (["usage", "help"], False, "Show usage information", "usage"),
                        (["runall", "r"], True, "Run all the tests", "runall"),
                        (["nodelete"], False, "Dont delete vm on completion", "nodelete") ]

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

   # Connect
   si = SmartConnect(host=args.GetKeyValue("host"),
                     user=args.GetKeyValue("user"),
                     pwd=args.GetKeyValue("pwd"))
   atexit.register(Disconnect, si)

   # Process command line
   vmname = args.GetKeyValue("vmname")
   numiter = int(args.GetKeyValue("iter"))
   runall = args.GetKeyValue("runall")
   noDelete = args.GetKeyValue("nodelete")
   disk = args.GetKeyValue("disk")
   ds = args.GetKeyValue("ds")
   rdmDiskFile = args.GetKeyValue("file")


   status = "PASS"

   for i in range(numiter):
       bigClock = StopWatch()
       vm1 = None
       try:
           ## Cleanup old VMs
           vm1 = folder.Find(vmname)
           if vm1 != None:
               vm1.Destroy()

           Log("Creating VM: " + str(vmname))

           ## Add scsi disk
           Log("Adding a new rdm disk to VM: " + str(vmname))
           cspec = Vim.Vm.ConfigSpec()
           cspec = vmconfig.CreateDefaultSpec(name = vmname, datastoreName = ds)
           cspec = vmconfig.AddScsiCtlr(cspec)

           # Get config options and targets
           cfgOption = vmconfig.GetCfgOption(None)
           cfgTarget = vmconfig.GetCfgTarget(None)

           rdmBacking = Vim.Vm.Device.VirtualDisk.RawDiskMappingVer1BackingInfo()
           rdmBacking.SetFileName("");
           rdmBacking.SetDeviceName(disk);
           rdmBacking.SetCompatibilityMode("physicalMode");
           rdmBacking.SetDiskMode("");
           rdmBacking.SetParent(None);

           diskDev = Vim.Vm.Device.VirtualDisk()
           diskDev.SetKey(vmconfig.GetFreeKey(cspec))
           diskDev.SetBacking(rdmBacking)
           ctlrs = vmconfig.GetControllers(cfgOption, Vim.Vm.Device.VirtualSCSIController, None, cspec)

           # XXX Fix this up
           for ctlrIdx in range(len(ctlrs)):
              freeSlot = vmconfig.GetFreeSlot(cspec, None, cfgOption, ctlrs[ctlrIdx])
              if (freeSlot >= 0):
                 diskDev.SetControllerKey(ctlrs[ctlrIdx].GetKey())
                 diskDev.SetUnitNumber(-1)
                 diskDev.SetCapacityInKB(long(4096))
                 break


           vmconfig.AddDeviceToSpec(cspec, diskDev, \
                    Vim.Vm.Device.VirtualDeviceSpec.Operation.add, \
                    Vim.Vm.Device.VirtualDeviceSpec.FileOperation.create)

           Log("create VM: " + str(vmname) + " with the RDM disk")
           vmFolder = vm.GetVmFolder()
           resPool = vm.GetResourcePool()

           task = vmFolder.CreateVm(cspec, resPool)
           WaitForTask(task)
           Log("Finished Reconfiguring VM: " + str(vmname));
           vm1 = task.info.result

           Log("Now reconfiguring VM: " + str(vmname));

           cspec = Vim.Vm.ConfigSpec()

           rdmBacking = Vim.Vm.Device.VirtualDisk.RawDiskMappingVer1BackingInfo()
           rdmBacking.SetFileName(rdmDiskFile);
           rdmBacking.SetCompatibilityMode("physicalMode");
           rdmBacking.SetDiskMode("persistent");
           rdmBacking.SetParent(None);

           diskDev = Vim.Vm.Device.VirtualDisk()
           diskDev.SetKey(vmconfig.GetFreeKey(cspec))
           diskDev.SetBacking(rdmBacking)
           ctlrs = vmconfig.GetControllers(cfgOption, Vim.Vm.Device.VirtualSCSIController, vm1.GetConfig(), cspec)
           # XXX Fix this up
           for ctlrIdx in range(len(ctlrs)):
              freeSlot = vmconfig.GetFreeSlot(cspec, vm1.GetConfig(), cfgOption, ctlrs[ctlrIdx])
              if (freeSlot >= 0):
                 diskDev.SetControllerKey(ctlrs[ctlrIdx].GetKey())
                 diskDev.SetUnitNumber(-1)
                 diskDev.SetCapacityInKB(long(4096))
                 break


           vmconfig.AddDeviceToSpec(cspec, diskDev, \
                    Vim.Vm.Device.VirtualDeviceSpec.Operation.add, \
                    Vim.Vm.Device.VirtualDeviceSpec.FileOperation.create)
           vm.Reconfigure(vm1, cspec)
           task = vmFolder.ReconfigVm(cspec, resPool)
           WaitForTask(task)
           Log("Finished Reconfiguring VM: " + str(vmname));


       except Exception as e:
           status = "FAIL"
           Log("Caught exception : " + str(e))
   Log("TEST RUN COMPLETE: " + status)
Пример #4
0
def AddVTPM(cspec, key=None):
    if key is None:
        key = vmconfig.GetFreeKey(cspec)
    tpm = CreateVTPM(key)
    vmconfig.AddDeviceToSpec(cspec, tpm,
                             vim.vm.device.VirtualDeviceSpec.Operation.add)
Пример #5
0
def AddVQAT(cspec, key=None, deviceType="C62XVF"):
    if key is None:
        key = vmconfig.GetFreeKey(cspec)
    qat = CreateVQAT(key, deviceType)
    vmconfig.AddDeviceToSpec(cspec, qat,
                             vim.vm.device.VirtualDeviceSpec.Operation.add)
Пример #6
0
def AddVWDT(cspec, key=None, runOnBoot=None):
    if key is None:
        key = vmconfig.GetFreeKey(cspec)
    wdt = CreateVWDT(key, runOnBoot)
    vmconfig.AddDeviceToSpec(cspec, wdt,
                             vim.vm.device.VirtualDeviceSpec.Operation.add)