Skip to content

Commit 1ef1b2a

Browse files
committed
Adds drive-letter options when adding additional hard disk on Windows
1 parent 63e8be6 commit 1ef1b2a

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

blockstore/src/main/java/brooklyn/location/blockstore/AbstractVolumeManager.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,28 @@ public void createFilesystem(AttachedBlockDevice attachedDevice, FilesystemOptio
9494
machine, osDeviceName, filesystemType));
9595
}
9696
} else if (machine instanceof WinRmMachineLocation) {
97+
String driveLetter = filesystemOptions.getMountPoint();
98+
String driveLetterParam = Strings.isNullOrEmpty(driveLetter) ? "-AssignDriveLetter" : "-DriveLetter " + driveLetter;
99+
String volumeLabel = filesystemOptions.getVolumeLabel();
100+
String volumeLabelParam = Strings.isNullOrEmpty(volumeLabel) ? "datadisk" : volumeLabel;
97101
WinRmToolResponse response = ((WinRmMachineLocation)machine).executePsScript("Get-Disk | Where partitionstyle -eq 'raw' | " +
98-
"Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | " +
99-
"Format-Volume -FileSystem NTFS -NewFileSystemLabel \"datadisk\" -Confirm:$false");
102+
"Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition " + driveLetterParam + " -UseMaximumSize | " +
103+
"Format-Volume -FileSystem " + filesystemOptions.getFilesystemType() +" -NewFileSystemLabel \"" + volumeLabelParam + "\" -Confirm:$false");
100104
if (response.getStatusCode() != 0) {
101-
throw new RuntimeException(format("Failed to initialize disk. machine=%s; filesystemType=%s",
102-
machine, filesystemOptions.getFilesystemType()));
105+
throw new RuntimeException(format("Failed to initialize disk. machine=%s; filesystemType=%s; stdErr=%s;",
106+
machine, filesystemOptions.getFilesystemType(), response.getStdErr()));
103107
}
108+
} else {
109+
throw new IllegalStateException("Cannot create filesystem for " + machine + " of type "
110+
+ machine.getClass().getName() + "; expected " + SshMachineLocation.class.getSimpleName()
111+
+ " or " + WinRmMachineLocation.class.getSimpleName());
104112
}
105113
}
106114

107115
@Override
108116
public MountedBlockDevice mountFilesystem(AttachedBlockDevice attachedDevice, FilesystemOptions options) {
109117
JcloudsMachineLocation machine = attachedDevice.getMachine();
110118
if (machine instanceof SshMachineLocation) {
111-
112119
LOG.debug("Mounting filesystem: device={}; options={}", attachedDevice, options);
113120
String osDeviceName = getOSDeviceName(attachedDevice.getDeviceSuffix());
114121
String mountPoint = options.getMountPoint();
@@ -132,6 +139,12 @@ public MountedBlockDevice mountFilesystem(AttachedBlockDevice attachedDevice, Fi
132139
throw new RuntimeException(format("Failed to mount file system. machine=%s; osDeviceName=%s; mountPoint=%s; filesystemType=%s",
133140
attachedDevice.getMachine(), osDeviceName, mountPoint, filesystemType));
134141
}
142+
} else if (machine instanceof WinRmMachineLocation) {
143+
LOG.debug("Ignoring mounting of filesystem on WinRmMachineLocation: device={}; options={}", attachedDevice, options);
144+
} else {
145+
throw new IllegalStateException("Cannot mount filesystem for " + machine + " of type "
146+
+ machine.getClass().getName() + "; expected " + SshMachineLocation.class.getSimpleName()
147+
+ " or " + WinRmMachineLocation.class.getSimpleName());
135148
}
136149

137150
return attachedDevice.mountedAt(options.getMountPoint());

blockstore/src/main/java/brooklyn/location/blockstore/FilesystemOptions.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
import java.util.Map;
66

77
import com.google.common.base.MoreObjects;
8+
import com.google.common.base.Optional;
89

910
public class FilesystemOptions {
1011

1112
private String mountPoint;
1213
private String filesystemType;
14+
private String volumeLabel;
1315

1416
// For more convenient yaml input
1517
public static FilesystemOptions fromMap(Map<String, ?> map) {
1618
FilesystemOptions result = new FilesystemOptions();
1719
result.mountPoint = (String) map.get("mountPoint");
1820
result.filesystemType = (String) map.get("filesystemType");
21+
result.volumeLabel = (String) map.get("volumeLabel");
1922
return result;
2023
}
2124

@@ -31,23 +34,42 @@ public FilesystemOptions(String mountPoint) {
3134
}
3235

3336
public FilesystemOptions(String mountPoint, String filesystemType) {
37+
this(mountPoint, filesystemType, "");
38+
}
39+
40+
public FilesystemOptions(String mountPoint, String filesystemType, String volumeLabel) {
3441
this.filesystemType = checkNotNull(filesystemType, "filesystemType");
3542
this.mountPoint = checkNotNull(mountPoint, "mountPoint");
43+
this.volumeLabel = Optional.fromNullable(volumeLabel).or("");
3644
}
3745

46+
/*
47+
For Linux machines, this will be the mount point, e.g. /data. For Windows systems, this is the drive letter, e.g. "G". A colon should not be included
48+
*/
3849
public String getMountPoint() {
3950
return mountPoint;
4051
}
4152

53+
/*
54+
For Linux machines, this will be the file system type, e.g. ext3. For Windows system, this is the `-FileSystem` parameter passed to the `Format-Volume` cmdlet, e.g. NTFS
55+
*/
4256
public String getFilesystemType() {
4357
return filesystemType;
4458
}
4559

60+
/*
61+
Windows only. The volume label to be assigned to the volume, e.g. "MyDataDrive"
62+
*/
63+
public String getVolumeLabel() {
64+
return volumeLabel;
65+
}
66+
4667
@Override
4768
public String toString() {
4869
return MoreObjects.toStringHelper(this)
4970
.add("mountPoint", mountPoint)
5071
.add("filesystemType", filesystemType)
72+
.add("volumeLabel", volumeLabel)
5173
.toString();
5274
}
5375
}

0 commit comments

Comments
 (0)