use of com.vmware.vim25.HostInternetScsiHbaStaticTarget in project cloudstack by apache.
the class VmwareStorageProcessor method addRemoveInternetScsiTargetsToAllHosts.
private void addRemoveInternetScsiTargetsToAllHosts(final boolean add, final List<HostInternetScsiHbaStaticTarget> targets, List<HostMO> hosts) throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(hosts.size());
final List<Exception> exceptions = new ArrayList<Exception>();
for (HostMO host : hosts) {
HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
boolean iScsiHbaConfigured = false;
for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
if (hba instanceof HostInternetScsiHba) {
// just finding an instance of HostInternetScsiHba means that we have found at least one configured iSCSI HBA
// at least one iSCSI HBA must be configured before a CloudStack user can use this host for iSCSI storage
iScsiHbaConfigured = true;
final String iScsiHbaDevice = hba.getDevice();
final HostStorageSystemMO hss = hostStorageSystem;
executorService.submit(new Thread() {
@Override
public void run() {
try {
if (add) {
hss.addInternetScsiStaticTargets(iScsiHbaDevice, targets);
} else {
hss.removeInternetScsiStaticTargets(iScsiHbaDevice, targets);
}
hss.rescanHba(iScsiHbaDevice);
hss.rescanVmfs();
} catch (Exception ex) {
synchronized (exceptions) {
exceptions.add(ex);
}
}
}
});
}
}
if (!iScsiHbaConfigured) {
throw new Exception("An iSCSI HBA must be configured before a host can use iSCSI storage.");
}
}
executorService.shutdown();
if (!executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES)) {
throw new Exception("The system timed out before completing the task 'rescanAllHosts'.");
}
if (exceptions.size() > 0) {
throw new Exception(exceptions.get(0).getMessage());
}
}
use of com.vmware.vim25.HostInternetScsiHbaStaticTarget in project cloudstack by apache.
the class VmwareStorageProcessor method handleTargetsForHost.
public void handleTargetsForHost(boolean add, List<Map<String, String>> targets, HostMO host) throws Exception {
List<HostInternetScsiHbaStaticTarget> lstTargets = new ArrayList<HostInternetScsiHbaStaticTarget>();
for (Map<String, String> mapTarget : targets) {
HostInternetScsiHbaStaticTarget target = new HostInternetScsiHbaStaticTarget();
String targetAddress = mapTarget.get(ModifyTargetsCommand.STORAGE_HOST);
Integer targetPort = Integer.parseInt(mapTarget.get(ModifyTargetsCommand.STORAGE_PORT));
String iScsiName = trimIqn(mapTarget.get(ModifyTargetsCommand.IQN));
target.setAddress(targetAddress);
target.setPort(targetPort);
target.setIScsiName(iScsiName);
String chapName = mapTarget.get(ModifyTargetsCommand.CHAP_NAME);
String chapSecret = mapTarget.get(ModifyTargetsCommand.CHAP_SECRET);
if (StringUtils.isNotBlank(chapName) && StringUtils.isNotBlank(chapSecret)) {
HostInternetScsiHbaAuthenticationProperties auth = new HostInternetScsiHbaAuthenticationProperties();
String strAuthType = "chapRequired";
auth.setChapAuthEnabled(true);
auth.setChapInherited(false);
auth.setChapAuthenticationType(strAuthType);
auth.setChapName(chapName);
auth.setChapSecret(chapSecret);
String mutualChapName = mapTarget.get(ModifyTargetsCommand.MUTUAL_CHAP_NAME);
String mutualChapSecret = mapTarget.get(ModifyTargetsCommand.MUTUAL_CHAP_SECRET);
if (StringUtils.isNotBlank(mutualChapName) && StringUtils.isNotBlank(mutualChapSecret)) {
auth.setMutualChapInherited(false);
auth.setMutualChapAuthenticationType(strAuthType);
auth.setMutualChapName(mutualChapName);
auth.setMutualChapSecret(mutualChapSecret);
}
target.setAuthenticationProperties(auth);
}
lstTargets.add(target);
}
List<HostMO> hosts = new ArrayList<>();
hosts.add(host);
addRemoveInternetScsiTargetsToAllHosts(add, lstTargets, hosts);
}
use of com.vmware.vim25.HostInternetScsiHbaStaticTarget in project cloudstack by apache.
the class VmwareStorageProcessor method addRemoveInternetScsiTargetsToAllHosts.
private void addRemoveInternetScsiTargetsToAllHosts(VmwareContext context, final boolean add, final List<HostInternetScsiHbaStaticTarget> targets, List<Pair<ManagedObjectReference, String>> hostPairs) throws Exception {
List<HostMO> hosts = new ArrayList<>();
for (Pair<ManagedObjectReference, String> hostPair : hostPairs) {
HostMO host = new HostMO(context, hostPair.first());
hosts.add(host);
}
addRemoveInternetScsiTargetsToAllHosts(add, targets, hosts);
}
use of com.vmware.vim25.HostInternetScsiHbaStaticTarget in project cloudstack by apache.
the class VmwareStorageProcessor method getVmfsDatastore.
private ManagedObjectReference getVmfsDatastore(VmwareContext context, VmwareHypervisorHost hyperHost, String datastoreName, String storageIpAddress, int storagePortNumber, String iqn, String chapName, String chapSecret, String mutualChapName, String mutualChapSecret) throws Exception {
ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
ClusterMO cluster = new ClusterMO(context, morCluster);
List<Pair<ManagedObjectReference, String>> lstHosts = cluster.getClusterHosts();
HostInternetScsiHbaStaticTarget target = new HostInternetScsiHbaStaticTarget();
target.setAddress(storageIpAddress);
target.setPort(storagePortNumber);
target.setIScsiName(iqn);
if (StringUtils.isNotBlank(chapName) && StringUtils.isNotBlank(chapSecret)) {
HostInternetScsiHbaAuthenticationProperties auth = new HostInternetScsiHbaAuthenticationProperties();
String strAuthType = "chapRequired";
auth.setChapAuthEnabled(true);
auth.setChapInherited(false);
auth.setChapAuthenticationType(strAuthType);
auth.setChapName(chapName);
auth.setChapSecret(chapSecret);
if (StringUtils.isNotBlank(mutualChapName) && StringUtils.isNotBlank(mutualChapSecret)) {
auth.setMutualChapInherited(false);
auth.setMutualChapAuthenticationType(strAuthType);
auth.setMutualChapName(mutualChapName);
auth.setMutualChapSecret(mutualChapSecret);
}
target.setAuthenticationProperties(auth);
}
final List<HostInternetScsiHbaStaticTarget> lstTargets = new ArrayList<HostInternetScsiHbaStaticTarget>();
lstTargets.add(target);
addRemoveInternetScsiTargetsToAllHosts(context, true, lstTargets, lstHosts);
rescanAllHosts(context, lstHosts);
HostMO host = new HostMO(context, lstHosts.get(0).first());
HostDatastoreSystemMO hostDatastoreSystem = host.getHostDatastoreSystemMO();
ManagedObjectReference morDs = hostDatastoreSystem.findDatastoreByName(datastoreName);
if (morDs != null) {
return morDs;
}
rescanAllHosts(context, lstHosts);
HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
List<HostScsiDisk> lstHostScsiDisks = hostDatastoreSystem.queryAvailableDisksForVmfs();
HostScsiDisk hostScsiDisk = getHostScsiDisk(hostStorageSystem.getStorageDeviceInfo().getScsiTopology(), lstHostScsiDisks, iqn);
if (hostScsiDisk == null) {
// check to see if the datastore actually does exist already
morDs = hostDatastoreSystem.findDatastoreByName(datastoreName);
if (morDs != null) {
return morDs;
}
throw new Exception("A relevant SCSI disk could not be located to use to create a datastore.");
}
morDs = hostDatastoreSystem.createVmfsDatastore(datastoreName, hostScsiDisk);
if (morDs != null) {
rescanAllHosts(context, lstHosts);
return morDs;
}
throw new Exception("Unable to create a datastore");
}
use of com.vmware.vim25.HostInternetScsiHbaStaticTarget in project cloudstack by apache.
the class VmwareStorageProcessor method removeManagedTargetsFromCluster.
private void removeManagedTargetsFromCluster(List<String> iqns) throws Exception {
List<HostInternetScsiHbaStaticTarget> lstManagedTargets = new ArrayList<HostInternetScsiHbaStaticTarget>();
VmwareContext context = hostService.getServiceContext(null);
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
ClusterMO cluster = new ClusterMO(context, morCluster);
List<Pair<ManagedObjectReference, String>> lstHosts = cluster.getClusterHosts();
HostMO host = new HostMO(context, lstHosts.get(0).first());
HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
if (hba instanceof HostInternetScsiHba) {
List<HostInternetScsiHbaStaticTarget> lstTargets = ((HostInternetScsiHba) hba).getConfiguredStaticTarget();
if (lstTargets != null) {
for (HostInternetScsiHbaStaticTarget target : lstTargets) {
if (iqns.contains(target.getIScsiName())) {
lstManagedTargets.add(target);
}
}
}
}
}
addRemoveInternetScsiTargetsToAllHosts(context, false, lstManagedTargets, lstHosts);
rescanAllHosts(context, lstHosts);
}
Aggregations