Beispiel #1
0
def GenerateNetRMSpec(poolKey, shareLevel, limit, shareVal = 0):
    allocInfo = Vim.Dvs.NetworkResourcePool.AllocationInfo()
    shares = Vim.SharesInfo(level = shareLevel,
                            shares = shareVal)
    allocInfo.SetLimit(limit)
    allocInfo.SetShares(shares)
    spec = Vim.Dvs.NetworkResourcePool.ConfigSpec()
    spec.SetKey(poolKey)
    spec.SetAllocationInfo(allocInfo)
    return spec
Beispiel #2
0
    def createResourceConfigSpec(self):
        spec = Vim.ResourceConfigSpec()
        spec.cpuAllocation = Vim.ResourceAllocationInfo()
        spec.cpuAllocation.shares = Vim.SharesInfo()
        spec.cpuAllocation.shares.level = Vim.SharesInfo.Level.normal
        spec.cpuAllocation.shares.shares = 4000
        spec.cpuAllocation.reservation = long(0)
        spec.cpuAllocation.limit = long(-1)
        spec.cpuAllocation.expandableReservation = True

        spec.memoryAllocation = Vim.ResourceAllocationInfo()
        spec.memoryAllocation.shares = Vim.SharesInfo()
        spec.memoryAllocation.shares.level = Vim.SharesInfo.Level.normal
        spec.memoryAllocation.shares.shares = 4000
        spec.memoryAllocation.reservation = long(0)
        spec.memoryAllocation.limit = long(-1)
        spec.memoryAllocation.expandableReservation = True

        return spec
Beispiel #3
0
def AddDisk(cspec,
            diskType="scsi",
            backingType="flat",
            fileName=None,
            cfgOption=None,
            cfgTarget=None,
            datastorename=None,
            diskmode="persistent",
            capacity=4096,
            cfgInfo=None,
            diskUuid=None,
            unitNumber=-1,
            thin=False,
            scrub=False,
            grainSize=-1,
            policy=None,
            crypto=None,
            deviceName=None,
            createNamedFile=False,
            capacityInBytes=None,
            reservedIOPS=0,
            compatibilityMode="virtualMode",
            reserveUnitNumber=False):
    """ Add a disk to the config spec """
    # Get config options and targets
    cfgOption = GetCfgOption(cfgOption)
    cfgTarget = GetCfgTarget(cfgTarget)

    if backingType == "flat":
        diskBacking = Vim.Vm.Device.VirtualDisk.FlatVer2BackingInfo()
        diskBacking.SetThinProvisioned(thin)
        diskBacking.SetEagerlyScrub(scrub)
    elif backingType == "sparse":
        diskBacking = Vim.Vm.Device.VirtualDisk.SparseVer2BackingInfo()
    elif backingType == "seSparse":
        diskBacking = Vim.Vm.Device.VirtualDisk.SeSparseBackingInfo()
        if grainSize != -1:
            diskBacking.SetGrainSize(grainSize)
    elif backingType == "pmem":
        diskBacking = Vim.Vm.Device.VirtualDisk.LocalPMemBackingInfo()
    elif backingType == "rdm":
        diskBacking = Vim.Vm.Device.VirtualDisk.RawDiskMappingVer1BackingInfo(
            deviceName=deviceName,
            lunUuid=diskUuid,
            compatibilityMode=compatibilityMode)
    else:
        print("Adding of " + backingType + " backing not implemented")
        return

    diskBacking.SetDiskMode(diskmode)
    if datastorename == None:
        datastore = FindDatastoreWithSpace(cfgTarget, capacity)
        datastorename = datastore.GetName()

    if fileName != None:
        diskBacking.SetFileName("[" + datastorename + "]" + " " + fileName)
    else:
        diskBacking.SetFileName("[" + datastorename + "]")

    if diskUuid != None:
        diskBacking.SetUuid(diskUuid)

    diskDev = Vim.Vm.Device.VirtualDisk()
    diskDev.SetKey(GetFreeKey(cspec))
    diskDev.SetBacking(diskBacking)
    diskDev.SetCapacityInKB(long(capacity))
    diskDev.SetCapacityInBytes(capacityInBytes)
    if cfgOption.GetCapabilities().GetDiskSharesSupported() == True \
      and diskType == "scsi":
        ioAllocation = Vim.StorageResourceManager.IOAllocationInfo()
        shares = Vim.SharesInfo()
        shares.SetShares(2000)
        shares.SetLevel(Vim.SharesInfo.Level.high)
        ioAllocation.SetShares(shares)
        ioAllocation.SetReservation(reservedIOPS)
        diskDev.SetStorageIOAllocation(ioAllocation)

    if diskType == "scsi":
        ctlrs = GetControllers(cfgOption, Vim.Vm.Device.VirtualSCSIController, \
                               cfgInfo, cspec)
    elif diskType == "ide":
        ctlrs = GetControllers(cfgOption, Vim.Vm.Device.VirtualIDEController, \
                              cfgInfo, cspec)

    elif diskType == "sata":
        ctlrs = GetControllers(cfgOption, Vim.Vm.Device.VirtualSATAController, \
                               cfgInfo, cspec)
    else:
        raise Exception(
            "Invalid disk type. Please specify 'ide', 'sata' or 'scsi'")

    # XXX Fix this up
    for ctlrIdx in range(len(ctlrs)):
        if reserveUnitNumber:
            try:
                assert cfgInfo != None
                unitNumber = GetFreeDiskUnitNumber(cspec, cfgInfo, cfgOption,
                                                   ctlrs[ctlrIdx], unitNumber)
            except Vim.Fault.InvalidController as err:
                # Ignore the controller with no available slots
                continue
        else:
            # In this branch we rely on Reconfigure to choose a slot.
            # Each AddDisk should be followed by Reconfigure.
            hasFreeSlot = GetFreeSlot(cspec, cfgInfo, cfgOption,
                                      ctlrs[ctlrIdx]) >= 0

        if reserveUnitNumber or hasFreeSlot:
            diskDev.SetControllerKey(ctlrs[ctlrIdx].GetKey())
            diskDev.SetUnitNumber(unitNumber)
            if fileName == None or createNamedFile == True:
                return AddDeviceToSpec(cspec, diskDev, \
                         Vim.Vm.Device.VirtualDeviceSpec.Operation.add, \
                         Vim.Vm.Device.VirtualDeviceSpec.FileOperation.create, \
                         policy, crypto)
            else:
                return AddDeviceToSpec(cspec, diskDev, \
                         Vim.Vm.Device.VirtualDeviceSpec.Operation.add, \
                         None, policy, crypto)

    raise Exception("Unable to add device as there are no available slots")