/** * Capture virtual cdrom attributes in the disk state for reference. */ public static void updateDiskStateFromVirtualDevice(VirtualDevice vd, DiskService.DiskState disk, VirtualDeviceBackingInfo backing) { fillInControllerUnitNumber(disk, vd.getUnitNumber()); if (backing != null && backing instanceof VirtualDeviceFileBackingInfo) { disk.sourceImageReference = VimUtils .datastorePathToUri(((VirtualDeviceFileBackingInfo) backing).getFileName()); } disk.status = DiskService.DiskStatus.ATTACHED; CustomProperties.of(disk) .put(PROVIDER_DISK_UNIQUE_ID, vd.getDeviceInfo().getLabel()); if (vd.getConnectable() != null) { CustomProperties.of(disk) .put(DEVICE_CONNECTED, vd.getConnectable().isConnected()) .put(DEVICE_STATUS, vd.getConnectable().getStatus()); } }
/** * Update the details of the disk into compute state after the provisioning is successful */ private void updateDiskLinksAfterProvisionSuccess(ComputeState state, List<VirtualDevice> disks, ProvisionContext ctx) { ArrayList<String> diskLinks = new ArrayList<>(disks.size()); // Fill in the disk links from the input to the ComputeState, as it may contain non hdd // disk as well. For ex, Floppy or CD-Rom ctx.disks.stream().forEach(ds -> diskLinks.add(ds.documentSelfLink)); // Handle all the HDD disk for (VirtualDevice disk : disks) { DiskStateExpanded matchedDs = findMatchingDiskState(disk, ctx.disks); if (disk.getBacking() instanceof VirtualDeviceFileBackingInfo) { handleVirtualDiskUpdate(matchedDs, (VirtualDisk) disk, diskLinks, ctx); } else if (disk instanceof VirtualCdrom) { handleVirtualDeviceUpdate(matchedDs, DiskType.CDROM, disk, diskLinks, ctx); } else if (disk instanceof VirtualFloppy) { handleVirtualDeviceUpdate(matchedDs, DiskType.FLOPPY, disk, diskLinks, ctx); } else { continue; } } state.diskLinks = diskLinks; }
public VirtualDevice getDeviceByBackingFileName(String name) { if(name==null) { throw new IllegalArgumentException("name must not be null!"); } VirtualDevice[] devices = this.getAllVirtualDevices(); for(VirtualDevice device : devices) { VirtualDeviceBackingInfo bi = device.getBacking(); if(bi instanceof VirtualDeviceFileBackingInfo) { String fileName = ((VirtualDeviceFileBackingInfo)bi).getFileName(); if(name.equals(fileName)) return device; } } return null; }
private VirtualDeviceConfigSpec createNewDataDisk(VirtualDisk vdSystemDisk, long newDiskSpace, int deviceKey, int unitNumber) throws Exception { logger.info("reconfigureDisks() create data disk space with " + newDiskSpace + " KB"); ManagedObjectReference vmDatastore = ((VirtualDeviceFileBackingInfo) vdSystemDisk .getBacking()).getDatastore(); String vmDatastoreName = (String) vmw.getServiceUtil() .getDynamicProperty(vmDatastore, "summary.name"); VirtualDisk vdDataDisk = new VirtualDisk(); VirtualDiskFlatVer2BackingInfo diskfileBacking = new VirtualDiskFlatVer2BackingInfo(); diskfileBacking.setFileName("[" + vmDatastoreName + "]"); diskfileBacking.setDiskMode("persistent"); vdDataDisk.setKey(deviceKey); vdDataDisk.setControllerKey(vdSystemDisk.getControllerKey()); vdDataDisk.setUnitNumber(new Integer(unitNumber)); vdDataDisk.setBacking(diskfileBacking); vdDataDisk.setCapacityInKB(newDiskSpace); VirtualDeviceConfigSpec vmDeviceSpec = new VirtualDeviceConfigSpec(); vmDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD); vmDeviceSpec .setFileOperation(VirtualDeviceConfigSpecFileOperation.CREATE); vmDeviceSpec.setDevice(vdDataDisk); return vmDeviceSpec; }
/** * Process VirtualDisk and update the details in the diskLinks of the provisioned compute */ private void handleVirtualDiskUpdate(DiskStateExpanded matchedDs, VirtualDisk disk, ArrayList<String> diskLinks, ProvisionContext ctx) { VirtualDeviceFileBackingInfo backing = (VirtualDeviceFileBackingInfo) disk.getBacking(); if (matchedDs == null) { // This is the new disk, hence add it to the list DiskState ds = new DiskState(); ds.documentSelfLink = UriUtils.buildUriPath( DiskService.FACTORY_LINK, getHost().nextUUID()); ds.name = disk.getDeviceInfo().getLabel(); ds.creationTimeMicros = Utils.getNowMicrosUtc(); ds.type = DiskType.HDD; ds.regionId = ctx.parent.description.regionId; ds.capacityMBytes = disk.getCapacityInKB() / 1024; ds.sourceImageReference = VimUtils.datastorePathToUri(backing.getFileName()); updateDiskStateFromVirtualDisk(disk, ds); if (disk.getStorageIOAllocation() != null) { StorageIOAllocationInfo storageInfo = disk.getStorageIOAllocation(); CustomProperties.of(ds) .put(SHARES, storageInfo.getShares().getShares()) .put(LIMIT_IOPS, storageInfo.getLimit()) .put(SHARES_LEVEL, storageInfo.getShares().getLevel().value()); } fillInControllerUnitNumber(ds, disk.getUnitNumber()); createDiskOnDemand(ds); diskLinks.add(ds.documentSelfLink); } else { // This is known disk, hence update with the provisioned attributes. matchedDs.sourceImageReference = VimUtils.datastorePathToUri(backing.getFileName()); updateDiskStateFromVirtualDisk(disk, matchedDs); createDiskPatch(matchedDs); } }
/** * TODO: メソッドコメントを記述 * * @param vmwareProcessClient * @param instanceNo * @param diskNo */ public void attachDisk(VmwareProcessClient vmwareProcessClient, Long instanceNo, Long diskNo) { VmwareDisk vmwareDisk = vmwareDiskDao.read(diskNo); if (BooleanUtils.isTrue(vmwareDisk.getAttached())) { // ディスクがアタッチ済みの場合はスキップ return; } VmwareInstance vmwareInstance = vmwareInstanceDao.read(instanceNo); //イベントログ出力 Component component = componentDao.read(vmwareDisk.getComponentNo()); Instance instance = instanceDao.read(instanceNo); Platform platform = platformDao.read(vmwareProcessClient.getPlatformNo()); if (StringUtils.isEmpty(vmwareDisk.getFileName())) { processLogger.debug(component, instance, "VmwareDiskCreate", new Object[] { platform.getPlatformName() }); } else { processLogger.debug(component, instance, "VmwareDiskAttach", new Object[] { platform.getPlatformName(), vmwareDisk.getFileName() }); } // ディスクのアタッチ VirtualDisk disk = vmwareProcessClient.attachDisk(vmwareInstance.getMachineName(), vmwareDisk.getScsiId(), vmwareDisk.getSize(), vmwareDisk.getFileName()); // ディスク情報の取得 VirtualDeviceFileBackingInfo backingInfo = VirtualDeviceFileBackingInfo.class.cast(disk.getBacking()); Datastore datastore = new Datastore(vmwareProcessClient.getVmwareClient().getServiceInstance() .getServerConnection(), backingInfo.getDatastore()); //イベントログ出力 if (StringUtils.isEmpty(vmwareDisk.getFileName())) { processLogger.debug(component, instance, "VmwareDiskCreateFinish", new Object[] { platform.getPlatformName(), backingInfo.getFileName(), vmwareDisk.getSize() }); } else { processLogger.debug(component, instance, "VmwareDiskAttachFinish", new Object[] { platform.getPlatformName(), vmwareDisk.getFileName(), vmwareDisk.getSize() }); } // データベース更新 vmwareDisk = vmwareDiskDao.read(diskNo); vmwareDisk.setAttached(true); vmwareDisk.setDatastore(datastore.getName()); vmwareDisk.setFileName(backingInfo.getFileName()); vmwareDiskDao.update(vmwareDisk); }
private ResultWrapper updateSiocInfoForWorkerVM(VMwareUtil.VMwareConnection connection, ManagedObjectReference morVm, String datastoreName, int limitIopsPerGB) throws Exception { int limitIopsTotal = 0; List<ManagedObjectReference> tasks = new ArrayList<>(); VirtualMachineConfigInfo vmci = (VirtualMachineConfigInfo)VMwareUtil.getEntityProps(connection, morVm, new String[] { "config" }).get("config"); List<VirtualDevice> devices = vmci.getHardware().getDevice(); for (VirtualDevice device : devices) { if (device instanceof VirtualDisk) { VirtualDisk disk = (VirtualDisk)device; if (disk.getBacking() instanceof VirtualDeviceFileBackingInfo) { VirtualDeviceFileBackingInfo backingInfo = (VirtualDeviceFileBackingInfo)disk.getBacking(); if (backingInfo.getFileName().contains(datastoreName)) { boolean diskUpdated = false; StorageIOAllocationInfo sioai = disk.getStorageIOAllocation(); long currentLimitIops = sioai.getLimit() != null ? sioai.getLimit() : Long.MIN_VALUE; long newLimitIops = getNewLimitIopsBasedOnVolumeSize(disk.getCapacityInBytes(), limitIopsPerGB); limitIopsTotal += newLimitIops; if (currentLimitIops != newLimitIops) { sioai.setLimit(newLimitIops); diskUpdated = true; } if (diskUpdated) { VirtualDeviceConfigSpec vdcs = new VirtualDeviceConfigSpec(); vdcs.setDevice(disk); vdcs.setOperation(VirtualDeviceConfigSpecOperation.EDIT); VirtualMachineConfigSpec vmcs = new VirtualMachineConfigSpec(); vmcs.getDeviceChange().add(vdcs); try { ManagedObjectReference task = VMwareUtil.reconfigureVm(connection, morVm, vmcs); tasks.add(task); LOGGER.info(getInfoMsgForWorkerVm(newLimitIops)); } catch (Exception ex) { throw new Exception("Error: " + ex.getMessage()); } } } } } } return new ResultWrapper(limitIopsTotal, tasks); }