Search in sources :

Example 1 with Attachment

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

the class VolumeService method getVolumeDetail.

// INTERNAL FUNCTIONS
protected VolumeDetail getVolumeDetail(Volume vol, String isV1Call, String openstackTenantId) {
    VolumeDetail detail = new VolumeDetail();
    int sizeInGB = (int) ((vol.getCapacity() + halfGB) / GB);
    detail.size = sizeInGB;
    detail.id = getCinderHelper().trimId(vol.getId().toString());
    detail.host_name = getCinderHelper().trimId(vol.getStorageController().toString());
    detail.tenant_id = openstackTenantId;
    detail.attachments = new ArrayList<Attachment>();
    if (vol.getInactive()) {
        detail.status = "deleted";
    } else {
        if (vol.getExtensions() == null) {
            vol.setExtensions(new StringMap());
        }
        if (vol.getProvisionedCapacity() == ZERO_BYTES) {
            detail.status = CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase();
        } else if (vol.getExtensions().containsKey("status") && vol.getExtensions().get("status").equals(CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase())) {
            Task taskObj = null;
            String task = vol.getExtensions().get(DELETE_TASK_ID).toString();
            taskObj = TaskUtils.findTaskForRequestId(_dbClient, vol.getId(), task);
            if (taskObj != null) {
                if (taskObj.getStatus().equals("error")) {
                    _log.info(String.format("Error Deleting volume %s, but moving volume to original state so that it will be usable:  ", detail.name));
                    vol.getExtensions().put("status", CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase());
                    vol.getExtensions().remove(DELETE_TASK_ID);
                    detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
                } else if (taskObj.getStatus().equals("pending")) {
                    detail.status = CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase();
                }
                _dbClient.updateObject(vol);
            } else {
                detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
            }
        } else if (vol.getExtensions().containsKey("status") && vol.getExtensions().get("status").equals(CinderConstants.ComponentStatus.EXTENDING.getStatus().toLowerCase())) {
            _log.info("Extending Volume {}", vol.getId().toString());
            Task taskObj = null;
            String task = vol.getExtensions().get("task_id").toString();
            taskObj = TaskUtils.findTaskForRequestId(_dbClient, vol.getId(), task);
            _log.debug("THE TASKOBJ is {}, task_id {}", taskObj.toString(), task);
            _log.debug("THE TASKOBJ STATUS is {}", taskObj.getStatus().toString());
            if (taskObj != null) {
                if (taskObj.getStatus().equals("ready")) {
                    detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
                    _log.debug(" STATUS is {}", detail.status);
                    vol.getExtensions().remove("task_id");
                    vol.getExtensions().put("status", "");
                } else if (taskObj.getStatus().equals("error")) {
                    detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
                    _log.info(String.format("Error in Extending volume %s, but moving volume to original state so that it will be usable:  ", detail.name));
                    vol.getExtensions().remove("task_id");
                    vol.getExtensions().put("status", "");
                } else {
                    detail.status = CinderConstants.ComponentStatus.EXTENDING.getStatus().toLowerCase();
                    _log.info("STATUS is {}", detail.status);
                }
            } else {
                detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
                _log.info(String.format("Error in Extending volume %s, but moving volume to original state so that it will be usable:  ", detail.name));
                vol.getExtensions().remove("task_id");
                vol.getExtensions().put("status", "");
            }
            _dbClient.updateObject(vol);
        } else if (vol.getExtensions().containsKey("status") && !vol.getExtensions().get("status").equals("")) {
            detail.status = vol.getExtensions().get("status").toString().toLowerCase();
        } else {
            detail.status = CinderConstants.ComponentStatus.AVAILABLE.getStatus().toLowerCase();
        }
    }
    detail.created_at = date(vol.getCreationTime().getTimeInMillis());
    URI vpoolUri = vol.getVirtualPool();
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolUri);
    if (vpool != null) {
        detail.volume_type = vpool.getLabel();
    }
    URI varrayUri = vol.getVirtualArray();
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, varrayUri);
    if (varray != null) {
        detail.availability_zone = varray.getLabel();
    }
    if (vol.getExtensions().containsKey("bootable") && vol.getExtensions().get("bootable").equals(TRUE)) {
        detail.bootable = true;
        _log.debug("Volumes Bootable Flag is TRUE");
    } else {
        detail.bootable = false;
        _log.debug("Volumes Bootable Flag is False");
    }
    detail.setLink(DbObjectMapper.toLink(vol));
    detail.metadata = new HashMap<String, String>();
    String description = null;
    StringMap extensions = vol.getExtensions();
    if (extensions != null) {
        description = extensions.get("display_description");
    }
    if (isV1Call != null) {
        detail.display_name = vol.getLabel();
        detail.display_description = (description == null) ? "" : description;
        detail.description = null;
        detail.name = null;
    } else {
        detail.name = vol.getLabel();
        detail.description = (description == null) ? "" : description;
        detail.display_name = null;
        detail.display_description = null;
    }
    if (vol.getExtensions().containsKey("readonly") && vol.getExtensions().get("readonly").equals(TRUE)) {
        _log.debug("Volumes Readonly Flag is TRUE");
        detail.metadata.put("readonly", "true");
    } else {
        _log.debug("Volumes Readonly Flag is FALSE");
        detail.metadata.put("readonly", "false");
    }
    if (detail.status.equals("in-use")) {
        if (vol.getExtensions() != null && vol.getExtensions().containsKey("OPENSTACK_NOVA_INSTANCE_ID")) {
            detail.metadata.put("attached_mode", vol.getExtensions().get("OPENSTACK_ATTACH_MODE"));
            detail.attachments = getVolumeAttachments(vol);
        }
    }
    if (vol.getConsistencyGroup() != null) {
        detail.consistencygroup_id = CinderApiUtils.splitString(vol.getConsistencyGroup().toString(), ":", 3);
    }
    return detail;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) VolumeDetail(com.emc.storageos.cinder.model.VolumeDetail) Attachment(com.emc.storageos.cinder.model.Attachment) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

Example 2 with Attachment

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

the class VolumeService method getVolumeAttachments.

private List<Attachment> getVolumeAttachments(Volume vol) {
    List<Attachment> attachments = new ArrayList<Attachment>();
    Attachment attachment = new Attachment();
    attachment.id = getCinderHelper().trimId(vol.getId().toString());
    attachment.volume_id = attachment.id;
    attachment.server_id = vol.getExtensions().get("OPENSTACK_NOVA_INSTANCE_ID");
    attachment.id = getCinderHelper().trimId(vol.getId().toString());
    attachment.volume_id = getCinderHelper().trimId(vol.getId().toString());
    attachment.device = vol.getExtensions().get("OPENSTACK_NOVA_INSTANCE_MOUNTPOINT");
    attachments.add(attachment);
    return attachments;
}
Also used : ArrayList(java.util.ArrayList) Attachment(com.emc.storageos.cinder.model.Attachment)

Aggregations

Attachment (com.emc.storageos.cinder.model.Attachment)2 TaskMapper.toTask (com.emc.storageos.api.mapper.TaskMapper.toTask)1 VolumeDetail (com.emc.storageos.cinder.model.VolumeDetail)1 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 StringMap (com.emc.storageos.db.client.model.StringMap)1 Task (com.emc.storageos.db.client.model.Task)1 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)1 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1