Skip to content

Commit ae35782

Browse files
author
Mike Tutkowski
committed
Merge from 4.3: CLOUDSTACK-5662: XenServer can't discover iSCSI targets with different credentials
1 parent bc1eec9 commit ae35782

13 files changed

Lines changed: 691 additions & 165 deletions

File tree

api/src/com/cloud/host/Host.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public static String[] toStrings(Host.Type... types) {
7878
*/
7979
String getPrivateIpAddress();
8080

81+
/**
82+
* @return the ip address of the host.
83+
*/
84+
String getStorageUrl();
85+
8186
/**
8287
* @return the ip address of the host attached to the storage network.
8388
*/

core/test/org/apache/cloudstack/api/agent/test/CheckOnHostCommandTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public String getPrivateIpAddress() {
8181
return "10.1.1.1";
8282
};
8383

84-
@Override
84+
public String getStorageUrl() {
85+
return null;
86+
}
87+
8588
public String getStorageIpAddress() {
8689
return "10.1.1.2";
8790
};

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreDriver.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@
2121
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
2222
import org.apache.cloudstack.storage.command.CommandResult;
2323

24+
import com.cloud.host.Host;
2425
import com.cloud.storage.StoragePool;
2526
import com.cloud.storage.Volume;
2627

2728
public interface PrimaryDataStoreDriver extends DataStoreDriver {
2829
public ChapInfo getChapInfo(VolumeInfo volumeInfo);
2930

31+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore);
32+
33+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore);
34+
3035
public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool);
3136

3237
public void takeSnapshot(SnapshotInfo snapshot, AsyncCompletionCallback<CreateCmdResult> callback);

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public VolumeInfo getVolume() {
4444

4545
ChapInfo getChapInfo(VolumeInfo volumeInfo, DataStore dataStore);
4646

47+
boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore);
48+
49+
void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore);
50+
4751
/**
4852
* Creates the volume based on the given criteria
4953
*

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/FakePrimaryDataStoreDriver.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,29 @@
3636

3737
import com.cloud.agent.api.to.DataStoreTO;
3838
import com.cloud.agent.api.to.DataTO;
39+
import com.cloud.host.Host;
3940
import com.cloud.storage.StoragePool;
4041
import com.cloud.storage.Volume;
4142

4243
public class FakePrimaryDataStoreDriver implements PrimaryDataStoreDriver {
4344
boolean snapshotResult = true;
4445

46+
@Override
47+
public Map<String, String> getCapabilities() {
48+
return null;
49+
}
50+
4551
@Override
4652
public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
47-
return null; //To change body of implemented methods use File | Settings | File Templates.
53+
return null; // To change body of implemented methods, use File | Settings | File Templates.
4854
}
4955

56+
@Override
57+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { return false; }
58+
59+
@Override
60+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {}
61+
5062
@Override
5163
public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) {
5264
return volume.getSize();

engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,24 @@ public ChapInfo getChapInfo(VolumeInfo volumeInfo, DataStore dataStore) {
158158
return null;
159159
}
160160

161+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {
162+
DataStoreDriver dataStoreDriver = dataStore.getDriver();
163+
164+
if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
165+
return ((PrimaryDataStoreDriver)dataStoreDriver).connectVolumeToHost(volumeInfo, host, dataStore);
166+
}
167+
168+
return false;
169+
}
170+
171+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {
172+
DataStoreDriver dataStoreDriver = dataStore.getDriver();
173+
174+
if (dataStoreDriver instanceof PrimaryDataStoreDriver) {
175+
((PrimaryDataStoreDriver)dataStoreDriver).disconnectVolumeFromHost(volumeInfo, host, dataStore);
176+
}
177+
}
178+
161179
@Override
162180
public AsyncCallFuture<VolumeApiResult> createVolumeAsync(VolumeInfo volume, DataStore dataStore) {
163181
AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<VolumeApiResult>();

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

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4800,22 +4800,26 @@ public ManagedObjectReference getVmfsDatastore(VmwareHypervisorHost hyperHost, S
48004800
target.setPort(storagePortNumber);
48014801
target.setIScsiName(iqn);
48024802

4803-
HostInternetScsiHbaAuthenticationProperties auth = new HostInternetScsiHbaAuthenticationProperties();
4803+
if (StringUtils.isNotBlank(chapName) && StringUtils.isNotBlank(chapSecret)) {
4804+
HostInternetScsiHbaAuthenticationProperties auth = new HostInternetScsiHbaAuthenticationProperties();
48044805

4805-
String strAuthType = "chapRequired";
4806+
String strAuthType = "chapRequired";
48064807

4807-
auth.setChapAuthEnabled(true);
4808-
auth.setChapInherited(false);
4809-
auth.setChapAuthenticationType(strAuthType);
4810-
auth.setChapName(chapName);
4811-
auth.setChapSecret(chapSecret);
4808+
auth.setChapAuthEnabled(true);
4809+
auth.setChapInherited(false);
4810+
auth.setChapAuthenticationType(strAuthType);
4811+
auth.setChapName(chapName);
4812+
auth.setChapSecret(chapSecret);
48124813

4813-
auth.setMutualChapInherited(false);
4814-
auth.setMutualChapAuthenticationType(strAuthType);
4815-
auth.setMutualChapName(mutualChapName);
4816-
auth.setMutualChapSecret(mutualChapSecret);
4814+
if (StringUtils.isNotBlank(mutualChapName) && StringUtils.isNotBlank(mutualChapSecret)) {
4815+
auth.setMutualChapInherited(false);
4816+
auth.setMutualChapAuthenticationType(strAuthType);
4817+
auth.setMutualChapName(mutualChapName);
4818+
auth.setMutualChapSecret(mutualChapSecret);
4819+
}
48174820

4818-
target.setAuthenticationProperties(auth);
4821+
target.setAuthenticationProperties(auth);
4822+
}
48194823

48204824
final List<HostInternetScsiHbaStaticTarget> lstTargets = new ArrayList<HostInternetScsiHbaStaticTarget>();
48214825

@@ -6052,11 +6056,34 @@ protected void fillHostInfo(StartupRoutingCommand cmd) {
60526056
cmd.setName(_url);
60536057
cmd.setGuid(_guid);
60546058
cmd.setDataCenter(_dcId);
6059+
cmd.setIqn(getIqn());
60556060
cmd.setPod(_pod);
60566061
cmd.setCluster(_cluster);
60576062
cmd.setVersion(VmwareResource.class.getPackage().getImplementationVersion());
60586063
}
60596064

6065+
private String getIqn() {
6066+
try {
6067+
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
6068+
6069+
if (hyperHost instanceof HostMO) {
6070+
HostMO host = (HostMO)hyperHost;
6071+
HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
6072+
6073+
for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
6074+
if (hba instanceof HostInternetScsiHba) {
6075+
return ((HostInternetScsiHba)hba).getIScsiName();
6076+
}
6077+
}
6078+
}
6079+
}
6080+
catch (Exception ex) {
6081+
s_logger.info("Could not locate an IQN for this host.");
6082+
}
6083+
6084+
return null;
6085+
}
6086+
60606087
private void fillHostHardwareInfo(VmwareContext serviceContext, StartupRoutingCommand cmd) throws RuntimeFaultFaultMsg, RemoteException, Exception {
60616088

60626089
VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());

plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import com.cloud.agent.api.to.StorageFilerTO;
6262
import com.cloud.configuration.Config;
6363
import com.cloud.exception.StorageUnavailableException;
64+
import com.cloud.host.Host;
6465
import com.cloud.host.dao.HostDao;
6566
import com.cloud.storage.CreateSnapshotPayload;
6667
import com.cloud.storage.DataStoreRole;
@@ -149,6 +150,12 @@ public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
149150
return null;
150151
}
151152

153+
@Override
154+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { return false; }
155+
156+
@Override
157+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {}
158+
152159
@Override
153160
public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) {
154161
return volume.getSize();

plugins/storage/volume/sample/src/org/apache/cloudstack/storage/datastore/driver/SamplePrimaryDataStoreDriverImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.cloud.agent.api.Answer;
4343
import com.cloud.agent.api.to.DataStoreTO;
4444
import com.cloud.agent.api.to.DataTO;
45+
import com.cloud.host.Host;
4546
import com.cloud.storage.StoragePool;
4647
import com.cloud.storage.Volume;
4748
import com.cloud.storage.dao.StoragePoolHostDao;
@@ -80,6 +81,12 @@ public ChapInfo getChapInfo(VolumeInfo volumeInfo) {
8081
return null;
8182
}
8283

84+
@Override
85+
public boolean connectVolumeToHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) { return false; }
86+
87+
@Override
88+
public void disconnectVolumeFromHost(VolumeInfo volumeInfo, Host host, DataStore dataStore) {}
89+
8390
@Override
8491
public long getVolumeSizeIncludingHypervisorSnapshotReserve(Volume volume, StoragePool pool) {
8592
return volume.getSize();

0 commit comments

Comments
 (0)