Search in sources :

Example 1 with HostHostBusAdapter

use of com.vmware.vim25.HostHostBusAdapter 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());
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostInternetScsiHba(com.vmware.vim25.HostInternetScsiHba) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) HostStorageSystemMO(com.cloud.hypervisor.vmware.mo.HostStorageSystemMO) HostHostBusAdapter(com.vmware.vim25.HostHostBusAdapter) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 2 with HostHostBusAdapter

use of com.vmware.vim25.HostHostBusAdapter in project cloudstack by apache.

the class VmwareResource method getIqn.

private String getIqn() {
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        if (hyperHost instanceof HostMO) {
            HostMO host = (HostMO) hyperHost;
            HostStorageSystemMO hostStorageSystem = host.getHostStorageSystemMO();
            for (HostHostBusAdapter hba : hostStorageSystem.getStorageDeviceInfo().getHostBusAdapter()) {
                if (hba instanceof HostInternetScsiHba) {
                    return ((HostInternetScsiHba) hba).getIScsiName();
                }
            }
        }
    } catch (Exception ex) {
        s_logger.info("Could not locate an IQN for this host.");
    }
    return null;
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostInternetScsiHba(com.vmware.vim25.HostInternetScsiHba) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) HostStorageSystemMO(com.cloud.hypervisor.vmware.mo.HostStorageSystemMO) HostHostBusAdapter(com.vmware.vim25.HostHostBusAdapter) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 3 with HostHostBusAdapter

use of com.vmware.vim25.HostHostBusAdapter in project cloudstack by apache.

the class VmwareStorageProcessor method rescanAllHosts.

private void rescanAllHosts(VmwareContext context, List<Pair<ManagedObjectReference, String>> lstHosts) throws Exception {
    ExecutorService executorService = Executors.newFixedThreadPool(lstHosts.size());
    final List<Exception> exceptions = new ArrayList<Exception>();
    for (Pair<ManagedObjectReference, String> hostPair : lstHosts) {
        HostMO host = new HostMO(context, hostPair.first());
        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 {
                            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());
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) ArrayList(java.util.ArrayList) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostInternetScsiHba(com.vmware.vim25.HostInternetScsiHba) ExecutorService(java.util.concurrent.ExecutorService) HostStorageSystemMO(com.cloud.hypervisor.vmware.mo.HostStorageSystemMO) HostHostBusAdapter(com.vmware.vim25.HostHostBusAdapter) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with HostHostBusAdapter

use of com.vmware.vim25.HostHostBusAdapter 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);
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostInternetScsiHbaStaticTarget(com.vmware.vim25.HostInternetScsiHbaStaticTarget) ArrayList(java.util.ArrayList) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) HostInternetScsiHba(com.vmware.vim25.HostInternetScsiHba) HostStorageSystemMO(com.cloud.hypervisor.vmware.mo.HostStorageSystemMO) HostHostBusAdapter(com.vmware.vim25.HostHostBusAdapter) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Aggregations

HostMO (com.cloud.hypervisor.vmware.mo.HostMO)4 HostStorageSystemMO (com.cloud.hypervisor.vmware.mo.HostStorageSystemMO)4 HostHostBusAdapter (com.vmware.vim25.HostHostBusAdapter)4 HostInternetScsiHba (com.vmware.vim25.HostInternetScsiHba)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 RemoteException (java.rmi.RemoteException)3 ArrayList (java.util.ArrayList)3 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 ExecutorService (java.util.concurrent.ExecutorService)2 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)1 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)1 Pair (com.cloud.utils.Pair)1 HostInternetScsiHbaStaticTarget (com.vmware.vim25.HostInternetScsiHbaStaticTarget)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 ConfigurationException (javax.naming.ConfigurationException)1