Search in sources :

Example 1 with HostInternetScsiHbaAuthenticationProperties

use of com.vmware.vim25.HostInternetScsiHbaAuthenticationProperties 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);
}
Also used : HostInternetScsiHbaAuthenticationProperties(com.vmware.vim25.HostInternetScsiHbaAuthenticationProperties) HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostInternetScsiHbaStaticTarget(com.vmware.vim25.HostInternetScsiHbaStaticTarget) ArrayList(java.util.ArrayList)

Example 2 with HostInternetScsiHbaAuthenticationProperties

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

Aggregations

HostMO (com.cloud.hypervisor.vmware.mo.HostMO)2 HostInternetScsiHbaAuthenticationProperties (com.vmware.vim25.HostInternetScsiHbaAuthenticationProperties)2 HostInternetScsiHbaStaticTarget (com.vmware.vim25.HostInternetScsiHbaStaticTarget)2 ArrayList (java.util.ArrayList)2 ClusterMO (com.cloud.hypervisor.vmware.mo.ClusterMO)1 HostDatastoreSystemMO (com.cloud.hypervisor.vmware.mo.HostDatastoreSystemMO)1 HostStorageSystemMO (com.cloud.hypervisor.vmware.mo.HostStorageSystemMO)1 Pair (com.cloud.utils.Pair)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 HostScsiDisk (com.vmware.vim25.HostScsiDisk)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 RemoteException (java.rmi.RemoteException)1