Search in sources :

Example 6 with HostStorageSystem

use of com.vmware.vim25.mo.HostStorageSystem in project coprhd-controller by CoprHD.

the class HostStorageAPI method rescanHBAs.

/**
 * Rescans the HBAs on the host.
 */
public void rescanHBAs() {
    try {
        HostStorageSystem storageSystem = getStorageSystem();
        storageSystem.rescanAllHba();
    } catch (HostConfigFault e) {
        throw new VMWareException(e);
    } catch (RuntimeFault e) {
        throw new VMWareException(e);
    } catch (RemoteException e) {
        throw new VMWareException(e);
    }
}
Also used : HostStorageSystem(com.vmware.vim25.mo.HostStorageSystem) RuntimeFault(com.vmware.vim25.RuntimeFault) RemoteException(java.rmi.RemoteException) HostConfigFault(com.vmware.vim25.HostConfigFault)

Example 7 with HostStorageSystem

use of com.vmware.vim25.mo.HostStorageSystem in project coprhd-controller by CoprHD.

the class HostStorageAPI method mountDatastore.

/**
 * Attaches the datastore.
 */
public void mountDatastore(Datastore datastore) {
    try {
        HostStorageSystem storageSystem = getStorageSystem();
        String vmfsUuid = getVmfsVolumeUuid(datastore);
        storageSystem.mountVmfsVolume(vmfsUuid);
    } catch (HostConfigFault e) {
        throw new VMWareException(e);
    } catch (RuntimeFault e) {
        throw new VMWareException(e);
    } catch (RemoteException e) {
        throw new VMWareException(e);
    }
}
Also used : HostStorageSystem(com.vmware.vim25.mo.HostStorageSystem) RuntimeFault(com.vmware.vim25.RuntimeFault) RemoteException(java.rmi.RemoteException) HostConfigFault(com.vmware.vim25.HostConfigFault)

Example 8 with HostStorageSystem

use of com.vmware.vim25.mo.HostStorageSystem 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)

Example 9 with HostStorageSystem

use of com.vmware.vim25.mo.HostStorageSystem 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");
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostInternetScsiHbaStaticTarget(com.vmware.vim25.HostInternetScsiHbaStaticTarget) ArrayList(java.util.ArrayList) HostDatastoreSystemMO(com.cloud.hypervisor.vmware.mo.HostDatastoreSystemMO) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostInternetScsiHbaAuthenticationProperties(com.vmware.vim25.HostInternetScsiHbaAuthenticationProperties) HostScsiDisk(com.vmware.vim25.HostScsiDisk) HostStorageSystemMO(com.cloud.hypervisor.vmware.mo.HostStorageSystemMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 10 with HostStorageSystem

use of com.vmware.vim25.mo.HostStorageSystem 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)

Aggregations

RemoteException (java.rmi.RemoteException)10 HostStorageSystem (com.vmware.vim25.mo.HostStorageSystem)8 HostConfigFault (com.vmware.vim25.HostConfigFault)7 RuntimeFault (com.vmware.vim25.RuntimeFault)6 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)5 HostStorageSystemMO (com.cloud.hypervisor.vmware.mo.HostStorageSystemMO)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 HostHostBusAdapter (com.vmware.vim25.HostHostBusAdapter)4 HostInternetScsiHba (com.vmware.vim25.HostInternetScsiHba)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ArrayList (java.util.ArrayList)4 HostScsiDisk (com.vmware.vim25.HostScsiDisk)3 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)3 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)2 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)2 Pair (com.cloud.utils.Pair)2 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)2 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)2 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)2 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)2