Skip to content

Commit 63fddf2

Browse files
author
Mike Tutkowski
committed
VMware iSCSI discovery
1 parent fa0a67f commit 63fddf2

10 files changed

Lines changed: 138 additions & 146 deletions

File tree

core/src/com/cloud/agent/api/ModifyTargetsCommand.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.Map;
2424

2525
public class ModifyTargetsCommand extends Command {
26+
public enum TargetTypeToRemove { BOTH, NEITHER, STATIC, DYNAMIC }
27+
2628
public static final String IQN = "iqn";
2729
public static final String STORAGE_TYPE = "storageType";
2830
public static final String STORAGE_UUID = "storageUuid";
@@ -35,7 +37,7 @@ public class ModifyTargetsCommand extends Command {
3537

3638
private boolean add;
3739
private boolean applyToAllHostsInCluster;
38-
private boolean removeDynamicTargets;
40+
private TargetTypeToRemove targetTypeToRemove = TargetTypeToRemove.BOTH;
3941
private List<Map<String, String>> targets;
4042

4143
public void setAdd(boolean add) {
@@ -54,12 +56,12 @@ public boolean getApplyToAllHostsInCluster() {
5456
return applyToAllHostsInCluster;
5557
}
5658

57-
public void setRemoveDynamicTargets(boolean removeDynamicTargets) {
58-
this.removeDynamicTargets = removeDynamicTargets;
59+
public void setTargetTypeToRemove(TargetTypeToRemove targetTypeToRemove) {
60+
this.targetTypeToRemove = targetTypeToRemove;
5961
}
6062

61-
public boolean isRemoveDynamicTargets() {
62-
return removeDynamicTargets;
63+
public TargetTypeToRemove getTargetTypeToRemove() {
64+
return targetTypeToRemove;
6365
}
6466

6567
public void setTargets(List<Map<String, String>> targets) {

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,9 @@ private void removeDynamicTargets(long hostId, List<Map<String, String>> targets
621621
ModifyTargetsCommand cmd = new ModifyTargetsCommand();
622622

623623
cmd.setTargets(targets);
624-
cmd.setRemoveDynamicTargets(true);
624+
cmd.setApplyToAllHostsInCluster(true);
625+
cmd.setAdd(false);
626+
cmd.setTargetTypeToRemove(ModifyTargetsCommand.TargetTypeToRemove.DYNAMIC);
625627

626628
sendModifyTargetsCommand(cmd, hostId);
627629
}

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,11 @@ public boolean revertSnapshot(SnapshotInfo snapshotInfo) {
318318
hostId = getHostId(volumeInfo);
319319

320320
if (hostId != null) {
321-
/** @todo Mike T. For VMware dynamic discovery, we need to remove this volume from any VAG prior to sending this command */
321+
HostVO hostVO = hostDao.findById(hostId);
322+
DataStore dataStore = dataStoreMgr.getDataStore(volumeInfo.getPoolId(), DataStoreRole.Primary);
323+
324+
volService.revokeAccess(volumeInfo, hostVO, dataStore);
325+
322326
modifyTarget(false, volumeInfo, hostId);
323327
}
324328
}
@@ -336,8 +340,12 @@ public boolean revertSnapshot(SnapshotInfo snapshotInfo) {
336340
finally {
337341
if (getHypervisorRequiresResignature(volumeInfo)) {
338342
if (hostId != null) {
343+
HostVO hostVO = hostDao.findById(hostId);
344+
DataStore dataStore = dataStoreMgr.getDataStore(volumeInfo.getPoolId(), DataStoreRole.Primary);
345+
346+
volService.grantAccess(volumeInfo, hostVO, dataStore);
347+
339348
modifyTarget(true, volumeInfo, hostId);
340-
/** @todo Mike T. For VMware dynamic discovery, we needed to remove this volume from any VAG. Put it back now */
341349
}
342350
}
343351

@@ -385,9 +393,10 @@ private void modifyTarget(boolean add, VolumeInfo volumeInfo, long hostId) {
385393

386394
ModifyTargetsCommand cmd = new ModifyTargetsCommand();
387395

388-
cmd.setAdd(add);
389-
cmd.setApplyToAllHostsInCluster(true);
390396
cmd.setTargets(targets);
397+
cmd.setApplyToAllHostsInCluster(true);
398+
cmd.setAdd(add);
399+
cmd.setTargetTypeToRemove(ModifyTargetsCommand.TargetTypeToRemove.BOTH);
391400

392401
sendModifyTargetsCommand(cmd, hostId);
393402
}

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4126,37 +4126,32 @@ protected Answer execute(ModifyTargetsCommand cmd) {
41264126
VmwareContext context = getServiceContext(cmd);
41274127
VmwareHypervisorHost hyperHost = getHyperHost(context);
41284128

4129-
if (cmd.isRemoveDynamicTargets()) {
4130-
handleRemoveDynamicTargets(cmd.getTargets(), hyperHost);
4131-
}
4132-
else {
4133-
List<HostMO> hostMOs = new ArrayList<>();
4129+
List<HostMO> hostMOs = new ArrayList<>();
41344130

4135-
if (cmd.getApplyToAllHostsInCluster()) {
4136-
try {
4137-
ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
4138-
ClusterMO clusterMO = new ClusterMO(context, morCluster);
4131+
if (cmd.getApplyToAllHostsInCluster()) {
4132+
try {
4133+
ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
4134+
ClusterMO clusterMO = new ClusterMO(context, morCluster);
41394135

4140-
List<Pair<ManagedObjectReference, String>> hosts = clusterMO.getClusterHosts();
4136+
List<Pair<ManagedObjectReference, String>> hosts = clusterMO.getClusterHosts();
41414137

4142-
for (Pair<ManagedObjectReference, String> host : hosts) {
4143-
HostMO hostMO = new HostMO(context, host.first());
4138+
for (Pair<ManagedObjectReference, String> host : hosts) {
4139+
HostMO hostMO = new HostMO(context, host.first());
41444140

4145-
hostMOs.add(hostMO);
4146-
}
4141+
hostMOs.add(hostMO);
41474142
}
4148-
catch (Exception ex) {
4149-
s_logger.error(ex.getMessage(), ex);
4150-
4151-
throw new CloudRuntimeException(ex.getMessage(), ex);
4152-
}
4153-
}
4154-
else {
4155-
hostMOs.add((HostMO)hyperHost);
41564143
}
4144+
catch (Exception ex) {
4145+
s_logger.error(ex.getMessage(), ex);
41574146

4158-
handleTargets(cmd.getAdd(), cmd.getTargets(), hostMOs);
4147+
throw new CloudRuntimeException(ex.getMessage(), ex);
4148+
}
41594149
}
4150+
else {
4151+
hostMOs.add((HostMO)hyperHost);
4152+
}
4153+
4154+
handleTargets(cmd.getAdd(), cmd.getTargetTypeToRemove(), cmd.getTargets(), hostMOs);
41604155

41614156
return new ModifyTargetsAnswer();
41624157
}
@@ -4210,21 +4205,10 @@ protected Answer execute(ModifyStoragePoolCommand cmd) {
42104205
}
42114206
}
42124207

4213-
private void handleTargets(boolean add, List<Map<String, String>> targets, List<HostMO> hosts) {
4214-
if (targets != null && targets.size() > 0) {
4215-
try {
4216-
_storageProcessor.handleTargetsForHosts(add, targets, hosts);
4217-
}
4218-
catch (Exception ex) {
4219-
s_logger.warn(ex.getMessage());
4220-
}
4221-
}
4222-
}
4223-
4224-
private void handleRemoveDynamicTargets(List<Map<String, String>> targets, VmwareHypervisorHost hyperHost) {
4208+
private void handleTargets(boolean add, ModifyTargetsCommand.TargetTypeToRemove targetTypeToRemove, List<Map<String, String>> targets, List<HostMO> hosts) {
42254209
if (targets != null && targets.size() > 0) {
42264210
try {
4227-
_storageProcessor.handleRemoveTargets(targets, hyperHost);
4211+
_storageProcessor.handleTargets(add, targetTypeToRemove, targets, hosts);
42284212
}
42294213
catch (Exception ex) {
42304214
s_logger.warn(ex.getMessage());

0 commit comments

Comments
 (0)