Search in sources :

Example 1 with QuotaUser

use of com.iwave.ext.netapp.model.QuotaUser in project coprhd-controller by CoprHD.

the class QuotaCommands method quotaReport.

public List<Quota> quotaReport(String path, String volume) {
    NaElement elem = new NaElement("quota-report");
    if (StringUtils.isNotBlank(path)) {
        elem.addNewChild("path", path);
    }
    if (StringUtils.isNotBlank(volume)) {
        elem.addNewChild("volume", volume);
    }
    NaElement resultElem = null;
    try {
        resultElem = server.invokeElem(elem);
    } catch (Exception e) {
        throw createError(elem, e);
    }
    List<Quota> quotas = Lists.newArrayList();
    for (NaElement e : (List<NaElement>) resultElem.getChildren()) {
        if ("error".equalsIgnoreCase(e.getName())) {
            String errno = e.getChildContent("errno");
            String reason = e.getChildContent("reason");
            String message = String.format("%s: %s", errno, reason);
            throw new NetAppException(message);
        } else if ("quotas".equalsIgnoreCase(e.getName())) {
            for (NaElement quotaElem : (List<NaElement>) e.getChildren()) {
                Quota quota = new Quota();
                quota.setQtree(quotaElem.getChildContent("tree"));
                quota.setDiskLimit(quotaElem.getChildContent("disk-limit"));
                quota.setDiskUsed(quotaElem.getChildContent("disk-used"));
                quota.setFileLimit(quotaElem.getChildContent("file-limit"));
                quota.setFilesUsed(quotaElem.getChildContent("files-used"));
                quota.setQuotaTarget(quotaElem.getChildContent("quota-target"));
                quota.setQuotaType(quotaElem.getChildContent("quota-type"));
                quota.setSoftDiskLimit(quotaElem.getChildContent("soft-disk-limit"));
                quota.setSoftFileLimit(quotaElem.getChildContent("soft-file-limit"));
                quota.setThreshold(quotaElem.getChildContent("threshold"));
                quota.setVfiler(quotaElem.getChildContent("vfiler"));
                quota.setVolume(quotaElem.getChildContent("volume"));
                // users
                NaElement quotaUsersElem = (NaElement) quotaElem.getChildByName("quota-users");
                if (quotaUsersElem != null) {
                    for (NaElement quotaUserElem : (List<NaElement>) quotaUsersElem.getChildren()) {
                        QuotaUser quotaUser = new QuotaUser();
                        quotaUser.setUserId(quotaUserElem.getChildContent("quota-user-id"));
                        quotaUser.setUserName(quotaUserElem.getChildContent("quota-user-name"));
                        quotaUser.setUserType(quotaUserElem.getChildContent("quota-user-type"));
                        quota.getQuotaUsers().add(quotaUser);
                    }
                }
                quotas.add(quota);
            }
        }
    }
    return quotas;
}
Also used : Quota(com.iwave.ext.netapp.model.Quota) QuotaUser(com.iwave.ext.netapp.model.QuotaUser) List(java.util.List) ArrayList(java.util.ArrayList) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException)

Aggregations

Quota (com.iwave.ext.netapp.model.Quota)1 QuotaUser (com.iwave.ext.netapp.model.QuotaUser)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NaAPIFailedException (netapp.manage.NaAPIFailedException)1 NaElement (netapp.manage.NaElement)1