@Override public List<Command> finalizeExpungeVolumes(VirtualMachine vm) { List<Command> commands = new ArrayList<Command>(); List<VolumeVO> volumes = volumeDao.findByInstance(vm.getId()); // it's OK in this case to send a detach command to the host for a root volume as this // will simply lead to the SR that supports the root volume being removed if (volumes != null) { for (VolumeVO volume : volumes) { StoragePoolVO storagePool = storagePoolDao.findById(volume.getPoolId()); // storagePool should be null if we are expunging a volume that was never // attached to a VM that was started (the "trick" for storagePool to be null // is that none of the VMs this volume may have been attached to were ever started, // so the volume was never assigned to a storage pool) if (storagePool != null && storagePool.isManaged()) { DataTO volTO = volFactory.getVolume(volume.getId()).getTO(); DiskTO disk = new DiskTO(volTO, volume.getDeviceId(), volume.getPath(), volume.getVolumeType()); DettachCommand cmd = new DettachCommand(disk, vm.getInstanceName()); cmd.setManaged(true); cmd.setStorageHost(storagePool.getHostAddress()); cmd.setStoragePort(storagePool.getPort()); cmd.set_iScsiName(volume.get_iScsiName()); commands.add(cmd); } } } return commands; }
detachCommand.setStorageHost(storagePool.getHostAddress()); detachCommand.setStoragePort(storagePool.getPort());
cmd.setStorageHost(storagePool.getHostAddress()); cmd.setStoragePort(storagePool.getPort());
cmd.setStorageHost(volumePool.getHostAddress()); cmd.setStoragePort(volumePool.getPort());