Search in sources :

Example 1 with VolumeAttachResponse

use of com.emc.storageos.cinder.model.VolumeAttachResponse in project coprhd-controller by CoprHD.

the class CinderApi method attachVolume.

/**
 * Attaches specified volume to the specified initiator on the host.
 * It is a synchronous operation.
 *
 * @param volumeId the volume id
 * @param initiator the initiator
 * @param host the host
 * @return the volume attachment response
 * @throws Exception the exception
 */
public VolumeAttachResponse attachVolume(String volumeId, String initiator, String[] wwpns, String[] wwnns, String host) throws Exception {
    _log.info("CinderApi - start attachVolume");
    Gson gson = new Gson();
    VolumeAttachRequest volumeAttach = new VolumeAttachRequest();
    if (initiator != null) {
        volumeAttach.initializeConnection.connector.initiator = initiator;
    } else {
        if (wwpns != null) {
            volumeAttach.initializeConnection.connector.wwpns = Arrays.copyOf(wwpns, wwpns.length);
        }
        if (null != wwnns) {
            volumeAttach.initializeConnection.connector.wwnns = Arrays.copyOf(wwnns, wwnns.length);
        }
    }
    volumeAttach.initializeConnection.connector.host = host;
    String volumeAttachmentUri = endPoint.getBaseUri() + String.format(CinderConstants.URI_VOLUME_ACTION, new Object[] { endPoint.getCinderTenantId(), volumeId });
    _log.debug("attaching volume to initiator with uri {}", volumeAttachmentUri);
    String json = gson.toJson(volumeAttach);
    _log.info("attaching volume with body {}", json);
    ClientResponse js_response = getClient().postWithHeader(URI.create(volumeAttachmentUri), json);
    String s = js_response.getEntity(String.class);
    _log.debug("Got the response {}", s);
    VolumeAttachResponse response = null;
    _log.debug("Response status {}", String.valueOf(js_response.getStatus()));
    if (js_response.getStatus() == ClientResponse.Status.OK.getStatusCode()) {
        // This means volume attachment request accepted and being processed (Synch opr)
        try {
            response = gson.fromJson(SecurityUtils.sanitizeJsonString(s), VolumeAttachResponse.class);
        } catch (JsonSyntaxException ex) {
            /**
             * Some drivers return 'target_wwn' as a string list but some returns it as string.
             * We observed in practice that IBM SVC returning string which could be a faulty one.
             * In such a case, we capture the response string in an Alternate Java object and
             * return the details in default response object.
             */
            VolumeAttachResponseAlt altResponse = gson.fromJson(SecurityUtils.sanitizeJsonString(s), VolumeAttachResponseAlt.class);
            response = getResponseInVolumeAttachResponseFormat(altResponse);
        }
    } else {
        throw CinderException.exceptions.volumeAttachFailed(s);
    }
    _log.info("CinderApi - end attachVolume");
    return response;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VolumeAttachResponse(com.emc.storageos.cinder.model.VolumeAttachResponse) JsonSyntaxException(com.google.gson.JsonSyntaxException) VolumeAttachResponseAlt(com.emc.storageos.cinder.model.VolumeAttachResponseAlt) Gson(com.google.gson.Gson) VolumeAttachRequest(com.emc.storageos.cinder.model.VolumeAttachRequest)

Example 2 with VolumeAttachResponse

use of com.emc.storageos.cinder.model.VolumeAttachResponse in project coprhd-controller by CoprHD.

the class CinderApi method getResponseInVolumeAttachResponseFormat.

/**
 * Copies data from VolumeAttachResponseAlt object to VolumeAttachResponse object.
 *
 * @param altResponse the VolumeAttachResponseAlt
 * @return the response in VolumeAttachResponse format
 */
private VolumeAttachResponse getResponseInVolumeAttachResponseFormat(VolumeAttachResponseAlt altResponse) {
    VolumeAttachResponse response = new VolumeAttachResponse();
    response.connection_info = response.new ConnectionInfo();
    response.connection_info.driver_volume_type = altResponse.connection_info.driver_volume_type;
    response.connection_info.data = response.new Data();
    response.connection_info.data.target_discovered = altResponse.connection_info.data.target_discovered;
    response.connection_info.data.qos_spec = altResponse.connection_info.data.qos_spec;
    response.connection_info.data.target_iqn = altResponse.connection_info.data.target_iqn;
    response.connection_info.data.target_portal = altResponse.connection_info.data.target_portal;
    // convert string to string list
    response.connection_info.data.target_wwn = Arrays.asList(altResponse.connection_info.data.target_wwn);
    response.connection_info.data.initiator_target_map = altResponse.connection_info.data.initiator_target_map;
    response.connection_info.data.volume_id = altResponse.connection_info.data.volume_id;
    response.connection_info.data.target_lun = altResponse.connection_info.data.target_lun;
    response.connection_info.data.access_mode = altResponse.connection_info.data.access_mode;
    return response;
}
Also used : VolumeAttachResponse(com.emc.storageos.cinder.model.VolumeAttachResponse)

Example 3 with VolumeAttachResponse

use of com.emc.storageos.cinder.model.VolumeAttachResponse in project coprhd-controller by CoprHD.

the class CinderExportOperations method attachVolumesToInitiators.

/**
 * Attaches volumes to initiators.
 *
 * @param storage
 *            the storage
 * @param volumes
 *            the volumes
 * @param initiators
 *            the initiators
 * @param volumeToTargetLunMap
 *            the volume to target lun map
 * @throws Exception
 *             the exception
 */
private void attachVolumesToInitiators(StorageSystem storage, List<Volume> volumes, List<Initiator> initiators, Map<URI, Integer> volumeToTargetLunMap, Map<Volume, Map<String, List<String>>> volumeToInitiatorTargetMap, ExportMask exportMask) throws Exception {
    CinderEndPointInfo ep = CinderUtils.getCinderEndPoint(storage.getActiveProviderURI(), dbClient);
    log.debug("Getting the cinder APi for the provider with id  {}", storage.getActiveProviderURI());
    CinderApi cinderApi = cinderApiFactory.getApi(storage.getActiveProviderURI(), ep);
    List<Initiator> iSCSIInitiators = new ArrayList<Initiator>();
    List<Initiator> fcInitiators = new ArrayList<Initiator>();
    splitInitiatorsByProtocol(initiators, iSCSIInitiators, fcInitiators);
    String host = getHostNameFromInitiators(initiators);
    Map<String, String[]> mapSettingVsValues = getFCInitiatorsArray(fcInitiators);
    String[] fcInitiatorsWwpns = mapSettingVsValues.get(WWPNS);
    String[] fcInitiatorsWwnns = mapSettingVsValues.get(WWNNS);
    for (Volume volume : volumes) {
        // cinder generated volume ID
        String volumeId = volume.getNativeId();
        int targetLunId = -1;
        VolumeAttachResponse attachResponse = null;
        // for iSCSI
        for (Initiator initiator : iSCSIInitiators) {
            String initiatorPort = initiator.getInitiatorPort();
            log.debug(String.format("Attaching volume %s ( %s ) to initiator %s on Openstack cinder node", volumeId, volume.getId(), initiatorPort));
            attachResponse = cinderApi.attachVolume(volumeId, initiatorPort, null, null, host);
            log.info("Got response : {}", attachResponse.connection_info.toString());
            targetLunId = attachResponse.connection_info.data.target_lun;
        }
        // for FC
        if (fcInitiatorsWwpns.length > 0) {
            log.debug(String.format("Attaching volume %s ( %s ) to initiators %s on Openstack cinder node", volumeId, volume.getId(), fcInitiatorsWwpns));
            attachResponse = cinderApi.attachVolume(volumeId, null, fcInitiatorsWwpns, fcInitiatorsWwnns, host);
            log.info("Got response : {}", attachResponse.connection_info.toString());
            targetLunId = attachResponse.connection_info.data.target_lun;
            Map<String, List<String>> initTargetMap = attachResponse.connection_info.data.initiator_target_map;
            if (null != initTargetMap && !initTargetMap.isEmpty()) {
                volumeToInitiatorTargetMap.put(volume, attachResponse.connection_info.data.initiator_target_map);
            }
        }
        volumeToTargetLunMap.put(volume.getId(), targetLunId);
        // After the successful export, create or modify the storage ports
        CinderStoragePortOperations storagePortOperationsInstance = CinderStoragePortOperations.getInstance(storage, dbClient);
        storagePortOperationsInstance.invoke(attachResponse);
    }
    // Add ITLs to volume objects
    storeITLMappingInVolume(volumeToTargetLunMap, exportMask);
}
Also used : ArrayList(java.util.ArrayList) CinderApi(com.emc.storageos.cinder.api.CinderApi) VolumeAttachResponse(com.emc.storageos.cinder.model.VolumeAttachResponse) Initiator(com.emc.storageos.db.client.model.Initiator) Volume(com.emc.storageos.db.client.model.Volume) CinderEndPointInfo(com.emc.storageos.cinder.CinderEndPointInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with VolumeAttachResponse

use of com.emc.storageos.cinder.model.VolumeAttachResponse in project coprhd-controller by CoprHD.

the class ExportService method populateIscsiConnectionInfo.

/*
     * Populate the connection info of the ISCSI volume after completing the 
     * export of volume to the host in ViPR
     */
private VolumeAttachResponse populateIscsiConnectionInfo(Volume vol) throws InterruptedException {
    ITLRestRepList listOfItls = ExportUtils.getBlockObjectInitiatorTargets(vol.getId(), _dbClient, isIdEmbeddedInURL(vol.getId()));
    VolumeAttachResponse objCinderInit = new VolumeAttachResponse();
    objCinderInit.connection_info = objCinderInit.new ConnectionInfo();
    objCinderInit.connection_info.data = objCinderInit.new Data();
    objCinderInit.connection_info.driver_volume_type = "iscsi";
    objCinderInit.connection_info.data.access_mode = "rw";
    objCinderInit.connection_info.data.target_discovered = false;
    for (ITLRestRep itl : listOfItls.getExportList()) {
        // TODO: user setter methods to set the values of object below.
        objCinderInit.connection_info.data.target_iqn = itl.getStoragePort().getPort();
        objCinderInit.connection_info.data.target_portal = itl.getStoragePort().getIpAddress() + ":" + itl.getStoragePort().getTcpPort();
        objCinderInit.connection_info.data.volume_id = getCinderHelper().trimId(vol.getId().toString());
        objCinderInit.connection_info.data.target_lun = itl.getHlu();
        _log.info(String.format("itl.getStoragePort().getPort() is %s: itl.getStoragePort().getIpAddress():%s,itl.getHlu() :%s, objCinderInit.toString():%s", itl.getStoragePort().getPort(), itl.getStoragePort().getIpAddress() + ":" + itl.getStoragePort().getTcpPort(), itl.getHlu(), objCinderInit.toString()));
        return objCinderInit;
    }
    return objCinderInit;
}
Also used : VolumeAttachResponse(com.emc.storageos.cinder.model.VolumeAttachResponse) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) ITLRestRep(com.emc.storageos.model.block.export.ITLRestRep)

Example 5 with VolumeAttachResponse

use of com.emc.storageos.cinder.model.VolumeAttachResponse in project coprhd-controller by CoprHD.

the class ExportService method populateFcConnectionInfo.

/*
     * Populate the connection info of the FC volume after completing the 
     * export of volume to the host in ViPR
     */
private VolumeAttachResponse populateFcConnectionInfo(String chosenProtocol, Volume vol, VolumeActionRequest action, String openstackTenantId) throws InterruptedException {
    // After the exportt ask is complete, sometimes there is a delay in the info being reflected in ITL's. So, we are adding a
    // small delay here.
    Thread.sleep(100000);
    ITLRestRepList listOfItls = ExportUtils.getBlockObjectInitiatorTargets(vol.getId(), _dbClient, isIdEmbeddedInURL(vol.getId()));
    VolumeAttachResponse objCinderInit = new VolumeAttachResponse();
    objCinderInit.connection_info = objCinderInit.new ConnectionInfo();
    objCinderInit.connection_info.data = objCinderInit.new Data();
    objCinderInit.connection_info.data.target_wwn = new ArrayList<String>();
    objCinderInit.connection_info.data.initiator_target_map = new HashMap<String, List<String>>();
    objCinderInit.connection_info.driver_volume_type = "fibre_channel";
    objCinderInit.connection_info.data.access_mode = "rw";
    objCinderInit.connection_info.data.target_discovered = true;
    for (ITLRestRep itl : listOfItls.getExportList()) {
        // TODO: user setter methods to set the values of object below.
        _log.info("itl.getStoragePort().getPort() is {}", itl.getStoragePort().getPort());
        if (itl.getStoragePort().getPort() == null)
            continue;
        objCinderInit.connection_info.data.target_wwn.add(itl.getStoragePort().getPort().toString().replace(":", "").toLowerCase());
        objCinderInit.connection_info.data.volume_id = getCinderHelper().trimId(vol.getId().toString());
        objCinderInit.connection_info.data.target_lun = itl.getHlu();
        _log.info(String.format("itl.getStoragePort().getPort() is %s: itl.getStoragePort().getIpAddress():%s,itl.getHlu() :%s, objCinderInit.toString():%s", itl.getStoragePort().getPort(), itl.getStoragePort().getIpAddress() + ":" + itl.getStoragePort().getTcpPort(), itl.getHlu(), objCinderInit.connection_info.data.toString()));
    }
    List<Initiator> lstInitiators = getListOfInitiators(action.attach.connector, openstackTenantId, chosenProtocol, vol);
    for (Initiator iter : lstInitiators) {
        _log.info("iter.getInitiatorPort() {}", iter.getInitiatorPort());
        _log.info("objCinderInit.connection_info.data.target_wwn {}", objCinderInit.connection_info.data.target_wwn);
        objCinderInit.connection_info.data.initiator_target_map.put(iter.getInitiatorPort().replace(":", "").toLowerCase(), objCinderInit.connection_info.data.target_wwn);
    }
    return objCinderInit;
}
Also used : VolumeAttachResponse(com.emc.storageos.cinder.model.VolumeAttachResponse) Initiator(com.emc.storageos.db.client.model.Initiator) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) ITLRestRep(com.emc.storageos.model.block.export.ITLRestRep) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) ArrayList(java.util.ArrayList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList)

Aggregations

VolumeAttachResponse (com.emc.storageos.cinder.model.VolumeAttachResponse)5 Initiator (com.emc.storageos.db.client.model.Initiator)2 ITLRestRep (com.emc.storageos.model.block.export.ITLRestRep)2 ITLRestRepList (com.emc.storageos.model.block.export.ITLRestRepList)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)1 CinderEndPointInfo (com.emc.storageos.cinder.CinderEndPointInfo)1 CinderApi (com.emc.storageos.cinder.api.CinderApi)1 VolumeAttachRequest (com.emc.storageos.cinder.model.VolumeAttachRequest)1 VolumeAttachResponseAlt (com.emc.storageos.cinder.model.VolumeAttachResponseAlt)1 Volume (com.emc.storageos.db.client.model.Volume)1 Gson (com.google.gson.Gson)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1