use of com.iwave.ext.windows.model.Volume in project coprhd-controller by CoprHD.
the class VolumeParser method parseVolumes.
public List<Volume> parseVolumes(String text) {
List<Volume> volumes = Lists.newArrayList();
List<String> textBlocks = parseTextBlocks(text);
for (String textBlock : textBlocks) {
Volume volume = parseVolume(textBlock);
if (volume != null) {
volumes.add(volume);
}
}
return volumes;
}
use of com.iwave.ext.windows.model.Volume in project coprhd-controller by CoprHD.
the class VolumeParserTest method testParseVolumes.
@Test
public void testParseVolumes() {
String text = " Volume ### Ltr Label Fs Type Size Status Info\r\n" + " ---------- --- ----------- ----- ---------- ------- --------- --------\r\n" + " Volume 1 System Rese NTFS Partition 100 MB Healthy System \r\n" + " Volume 2 C NTFS Partition 67 GB Healthy Boot \r\n" + "DISKPART> ";
List<Volume> volumes = parser.parseVolumes(text);
assertEquals(2, volumes.size());
Volume volume1 = volumes.get(0);
assertEquals(1, volume1.getNumber());
assertEquals("", volume1.getMountPoint());
assertEquals("System Rese", volume1.getLabel());
assertEquals("NTFS", volume1.getFileSystem());
assertEquals("Partition", volume1.getType());
assertEquals("100 MB", volume1.getSize());
assertEquals("Healthy", volume1.getStatus());
assertEquals("System", volume1.getInfo());
Volume volume2 = volumes.get(1);
assertEquals(2, volume2.getNumber());
assertEquals("C", volume2.getMountPoint());
assertEquals("", volume2.getLabel());
assertEquals("NTFS", volume2.getFileSystem());
assertEquals("Partition", volume2.getType());
assertEquals("67 GB", volume2.getSize());
assertEquals("Healthy", volume2.getStatus());
assertEquals("Boot", volume2.getInfo());
}
use of com.iwave.ext.windows.model.Volume in project coprhd-controller by CoprHD.
the class UnmountBlockVolumeHelper method unmountVolumes.
public void unmountVolumes() {
for (BlockObjectRestRep volume : volumes) {
DiskDrive disk = volume2disk.get(volume);
Disk diskDetail = windows.getDiskDetail(disk);
if (diskDetail.getVolumes() != null) {
for (Volume diskVolume : diskDetail.getVolumes()) {
windows.unmountVolume(diskVolume.getNumber(), diskVolume.getMountPoint());
boolean isDriveLetterOnly = WindowsUtils.isMountPointDriveLetterOnly(diskVolume.getMountPoint());
if (!isDriveLetterOnly && windows.isDirectoryEmpty(diskVolume.getMountPoint())) {
windows.deleteDirectory(diskVolume.getMountPoint());
}
}
}
if (diskDetail.isOnline()) {
windows.offlineDisk(disk);
} else {
logInfo("win.unmount.block.volume.disk.offline", disk.getNumber(), volume.getWwn());
}
windows.removeVolumeMountPoint(volume);
}
}
use of com.iwave.ext.windows.model.Volume in project coprhd-controller by CoprHD.
the class VolumeParser method parseVolume.
private Volume parseVolume(String text) {
String line = StringUtils.substringBefore(text, "\n");
Volume volume = new Volume();
volume.setNumber(getInteger(findMatch(VOLUME_PATTERN, line)));
volume.setMountPoint(getColumnText(line, 12, 3));
volume.setLabel(getColumnText(line, 17, 11));
// set offset for labels that overflows 11 characters
int offset = (line.length() - MAX_VOLUME_LINE_LENGTH);
volume.setFileSystem(getColumnText(line, offset + 30, 5));
volume.setType(getColumnText(line, offset + 37, 10));
volume.setSize(getColumnText(line, offset + 49, 7));
volume.setStatus(getColumnText(line, offset + 58, 9));
volume.setInfo(getColumnText(line, offset + 69, 8));
// and the mountpoint info is actually on the next line.
if (StringUtils.isBlank(volume.getMountPoint())) {
String line2 = StringUtils.substringAfter(text, "\n");
volume.setMountPoint(line2.trim());
}
return volume;
}
use of com.iwave.ext.windows.model.Volume in project coprhd-controller by CoprHD.
the class MountBlockVolumeHelper method mount.
/**
* Mounts the volume. If {@link #doFormat} is true, the volume is formatted first.
*
* @param volume
* the volume to mount.
* @param mountPoint
* the mount point to assign the volume. An empty mount point will cause the system to auto-assign a
* drive letter.
*/
public void mount(BlockObjectRestRep volume, DiskDrive disk, String mountPoint) {
Disk diskDetail = detailDisk(disk);
boolean isOnline = diskDetail.isOnline();
if (!isOnline) {
logInfo("win.mount.block.volume.disk.online", hostname, disk.getNumber(), volume.getWwn());
windows.onlineDisk(diskDetail);
}
if (doFormat) {
logInfo("win.mount.block.volume.format", hostname, disk.getNumber(), fileSystemType, volume.getWwn());
windows.formatAndMount(disk, fileSystemType, getBlockSize(), getActualLabel(volume), mountPoint, partitionType);
} else {
// If the disk was not online, detail it again since no volume information would have been available
if (!isOnline) {
diskDetail = detailDisk(disk);
}
if (diskDetail.getVolumes() == null || diskDetail.getVolumes().isEmpty()) {
ExecutionUtils.fail("failTask.MountBlockVolumeHelper.noVolumes", disk.getName(), hostname, disk.getName(), disk.getNumber());
}
// Mount the first volume only
Volume diskVolume = diskDetail.getVolumes().get(0);
int volumeNumber = diskVolume.getNumber();
String label = StringUtils.defaultIfBlank(diskVolume.getLabel(), ExecutionUtils.getMessage("MountBlockVolumeHelper.label.none"));
String fs = diskVolume.getFileSystem();
logInfo("win.mount.block.volume.mount", hostname, volumeNumber, label, fs, volume.getWwn());
windows.mountVolume(volumeNumber, mountPoint);
}
// Refresh the disk details
diskDetail = detailDisk(disk);
String assignedMountpoint = windows.getAssignedMountPoint(disk, diskDetail);
assignedMountpoints.add(assignedMountpoint);
logInfo(ExecutionUtils.getMessage("MountBlockVolumeHelper.log.mountpointToVolume", hostname, assignedMountpoint, volume.getWwn()));
// Check to see if the the desired volume label is different than the actual label if it wasn't formatted
if (!doFormat) {
Volume diskVolume = diskDetail.getVolumes().get(0);
String desiredLabel = getActualLabel(volume);
if (!StringUtils.defaultString(diskVolume.getLabel()).equals(desiredLabel)) {
windows.assignLabel(diskVolume, label);
}
}
windows.addVolumeMountPoint(volume, assignedMountpoint);
}
Aggregations