Search in sources :

Example 6 with ExportsHostnameInfo

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

the class FlexFileShare method listNFSExportRules.

@SuppressWarnings("unchecked")
List<ExportsRuleInfo> listNFSExportRules(String pathName) {
    List<ExportsRuleInfo> exports = Lists.newArrayList();
    NaElement elem = new NaElement("nfs-exportfs-list-rules-2");
    // if true, returns entries from exports file; else from memory. For Cluster mode, it is always true.
    elem.addNewChild("persistent", String.valueOf(true));
    if (StringUtils.isNotBlank(pathName)) {
        elem.addNewChild("pathname", pathName);
    }
    try {
        NaElement results = server.invokeElem(elem);
        List<NaElement> rules = results.getChildByName("rules").getChildren();
        for (NaElement rule : rules) {
            ExportsRuleInfo exportsRuleInfo = new ExportsRuleInfo();
            exportsRuleInfo.setActualPathname(rule.getChildContent("actual-pathname"));
            exportsRuleInfo.setPathname(rule.getChildContent("pathname"));
            for (NaElement securityRule : (List<NaElement>) rule.getChildByName("security-rules").getChildren()) {
                SecurityRuleInfo securityRuleInfo = new SecurityRuleInfo();
                securityRuleInfo.setAnon(securityRule.getChildContent("anon"));
                // String nonsuid = securityRule.getChildContent("nonsuid"); // This is not correct.. Modified by [Gopi] as per API.
                String nonsuid = securityRule.getChildContent("nosuid");
                if (StringUtils.isNotBlank(nonsuid)) {
                    securityRuleInfo.setNosuid(Boolean.parseBoolean(nonsuid));
                }
                List<NaElement> secFlavors = (List<NaElement>) securityRule.getChildByName("sec-flavor").getChildren();
                for (NaElement secFlavor : secFlavors) {
                    if (secFlavor != null) {
                        if (securityRuleInfo.getSecFlavor() != null) {
                            securityRuleInfo.setSecFlavor(securityRuleInfo.getSecFlavor() + "," + secFlavor.getChildContent("flavor"));
                        } else {
                            securityRuleInfo.setSecFlavor(secFlavor.getChildContent("flavor"));
                        }
                    }
                }
                List<ExportsHostnameInfo> readOnly = extractExportsHostnameInfos(securityRule.getChildByName("read-only"));
                securityRuleInfo.getReadOnly().addAll(readOnly);
                List<ExportsHostnameInfo> readWrite = extractExportsHostnameInfos(securityRule.getChildByName("read-write"));
                securityRuleInfo.getReadWrite().addAll(readWrite);
                List<ExportsHostnameInfo> root = extractExportsHostnameInfos(securityRule.getChildByName("root"));
                securityRuleInfo.getRoot().addAll(root);
                exportsRuleInfo.getSecurityRuleInfos().add(securityRuleInfo);
            }
            exports.add(exportsRuleInfo);
        }
        return exports;
    } catch (Exception e) {
        String msg = "Failed to list NFS exports.";
        log.error(msg, e);
        throw new NetAppCException(msg, e);
    }
}
Also used : SecurityRuleInfo(com.iwave.ext.netapp.model.SecurityRuleInfo) ArrayList(java.util.ArrayList) List(java.util.List) ExportsRuleInfo(com.iwave.ext.netapp.model.ExportsRuleInfo) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException) ExportsHostnameInfo(com.iwave.ext.netapp.model.ExportsHostnameInfo)

Example 7 with ExportsHostnameInfo

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

the class FileShare method listNFSExportRules.

@SuppressWarnings("unchecked")
List<ExportsRuleInfo> listNFSExportRules(String pathName) {
    List<ExportsRuleInfo> exports = Lists.newArrayList();
    NaElement elem = new NaElement("nfs-exportfs-list-rules-2");
    // if true, returns entries from exports file; else from memory
    elem.addNewChild("persistent", String.valueOf(false));
    if (StringUtils.isNotBlank(pathName)) {
        elem.addNewChild("pathname", pathName);
    }
    try {
        NaElement results = server.invokeElem(elem);
        List<NaElement> rules = results.getChildByName("rules").getChildren();
        for (NaElement rule : rules) {
            ExportsRuleInfo exportsRuleInfo = new ExportsRuleInfo();
            exportsRuleInfo.setActualPathname(rule.getChildContent("actual-pathname"));
            exportsRuleInfo.setPathname(rule.getChildContent("pathname"));
            for (NaElement securityRule : (List<NaElement>) rule.getChildByName("security-rules").getChildren()) {
                SecurityRuleInfo securityRuleInfo = new SecurityRuleInfo();
                securityRuleInfo.setAnon(securityRule.getChildContent("anon"));
                // String nonsuid = securityRule.getChildContent("nonsuid"); // This is not correct.. Modified by [Gopi] as per API.
                String nonsuid = securityRule.getChildContent("nosuid");
                if (StringUtils.isNotBlank(nonsuid)) {
                    securityRuleInfo.setNosuid(Boolean.parseBoolean(nonsuid));
                }
                List<NaElement> secFlavors = (List<NaElement>) securityRule.getChildByName("sec-flavor").getChildren();
                for (NaElement secFlavor : secFlavors) {
                    if (secFlavor != null) {
                        if (securityRuleInfo.getSecFlavor() != null) {
                            securityRuleInfo.setSecFlavor(securityRuleInfo.getSecFlavor() + "," + secFlavor.getChildContent("flavor"));
                        } else {
                            securityRuleInfo.setSecFlavor(secFlavor.getChildContent("flavor"));
                        }
                    }
                }
                List<ExportsHostnameInfo> readOnly = extractExportsHostnameInfos(securityRule.getChildByName("read-only"));
                securityRuleInfo.getReadOnly().addAll(readOnly);
                List<ExportsHostnameInfo> readWrite = extractExportsHostnameInfos(securityRule.getChildByName("read-write"));
                securityRuleInfo.getReadWrite().addAll(readWrite);
                List<ExportsHostnameInfo> root = extractExportsHostnameInfos(securityRule.getChildByName("root"));
                securityRuleInfo.getRoot().addAll(root);
                exportsRuleInfo.getSecurityRuleInfos().add(securityRuleInfo);
            }
            exports.add(exportsRuleInfo);
        }
        return exports;
    } catch (Exception e) {
        String msg = "Failed to list NFS exports.";
        log.error(msg, e);
        throw new NetAppException(msg, e);
    }
}
Also used : SecurityRuleInfo(com.iwave.ext.netapp.model.SecurityRuleInfo) ArrayList(java.util.ArrayList) List(java.util.List) ExportsRuleInfo(com.iwave.ext.netapp.model.ExportsRuleInfo) NaElement(netapp.manage.NaElement) NaAPIFailedException(netapp.manage.NaAPIFailedException) ExportsHostnameInfo(com.iwave.ext.netapp.model.ExportsHostnameInfo)

Example 8 with ExportsHostnameInfo

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

the class FileShare method extractExportsHostnameInfos.

private List<ExportsHostnameInfo> extractExportsHostnameInfos(NaElement elem) {
    List<ExportsHostnameInfo> exportsHostnameInfos = Lists.newArrayList();
    if (elem != null && elem.getChildren() != null) {
        for (NaElement exportsHostname : (List<NaElement>) elem.getChildren()) {
            ExportsHostnameInfo exportsHostnameInfo = new ExportsHostnameInfo();
            String allHosts = exportsHostname.getChildContent("all-hosts");
            if (StringUtils.isNotBlank(allHosts)) {
                exportsHostnameInfo.setAllHosts(Boolean.parseBoolean(allHosts));
            }
            exportsHostnameInfo.setName(exportsHostname.getChildContent("name"));
            String negate = exportsHostname.getChildContent("negate");
            if (StringUtils.isNotBlank(negate)) {
                exportsHostnameInfo.setNegate(Boolean.parseBoolean(negate));
            }
            exportsHostnameInfos.add(exportsHostnameInfo);
        }
    }
    return exportsHostnameInfos;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) NaElement(netapp.manage.NaElement) ExportsHostnameInfo(com.iwave.ext.netapp.model.ExportsHostnameInfo)

Example 9 with ExportsHostnameInfo

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

the class MiscTests method test2.

@Test
public void test2() {
    // NaElement result = server.invoke("nfs-exportfs-list-rules");
    // NetAppUtils.output(result);
    List<ExportsRuleInfo> bla = netAppFacade.listNFSExportRules(null);
    for (ExportsRuleInfo exportsRuleInfo : bla) {
        System.out.println("Pathname: " + exportsRuleInfo.getPathname());
        System.out.println("Actual Pathname: " + exportsRuleInfo.getActualPathname());
        for (SecurityRuleInfo securityRuleInfo : exportsRuleInfo.getSecurityRuleInfos()) {
            System.out.println(" -- anon: " + securityRuleInfo.getAnon());
            System.out.println(" -- nosuid: " + securityRuleInfo.getNosuid());
            System.out.println(" -- sec-flavor: " + securityRuleInfo.getSecFlavor());
            for (ExportsHostnameInfo exportsHostnameInfo : securityRuleInfo.getReadOnly()) {
                System.out.println(" ---- ReadOnly: " + exportsHostnameInfo.getAllHosts() + " " + exportsHostnameInfo.getName() + " " + exportsHostnameInfo.getNegate());
            }
            for (ExportsHostnameInfo exportsHostnameInfo : securityRuleInfo.getReadWrite()) {
                System.out.println(" ---- ReadWrite: " + exportsHostnameInfo.getAllHosts() + " " + exportsHostnameInfo.getName() + " " + exportsHostnameInfo.getNegate());
            }
            for (ExportsHostnameInfo exportsHostnameInfo : securityRuleInfo.getRoot()) {
                System.out.println(" ---- Root: " + exportsHostnameInfo.getAllHosts() + " " + exportsHostnameInfo.getName() + " " + exportsHostnameInfo.getNegate());
            }
        }
    }
}
Also used : SecurityRuleInfo(com.iwave.ext.netapp.model.SecurityRuleInfo) ExportsRuleInfo(com.iwave.ext.netapp.model.ExportsRuleInfo) ExportsHostnameInfo(com.iwave.ext.netapp.model.ExportsHostnameInfo) Test(org.junit.Test)

Example 10 with ExportsHostnameInfo

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

the class NetAppClusterModeCommIntf method createUnManagedExport.

private UnManagedFSExport createUnManagedExport(ExportsRuleInfo export, List<ExportsHostnameInfo> typeHosts, String permission, String port) {
    List<String> clientList = new ArrayList<String>();
    UnManagedFSExport tempUnManagedFSExport = null;
    if ((null != typeHosts) && (!typeHosts.isEmpty())) {
        for (ExportsHostnameInfo client : typeHosts) {
            boolean negate = false;
            if (client.getNegate() != null) {
                negate = client.getNegate();
            }
            if (!negate) {
                if ((null != client.getName() && !(clientList.contains(client.getName())))) {
                    if (!clientList.contains(client.getName())) {
                        clientList.add(client.getName());
                    }
                } else if ((null != client.getAllHosts()) && (client.getAllHosts())) {
                    // All hosts means empty clientList in ViPR.
                    clientList.clear();
                    _logger.info("Settng ClientList to empty as the export is meant to be accsible to all hosts");
                }
            }
        }
        String anon = export.getSecurityRuleInfos().get(0).getAnon();
        if ((null != anon) && (anon.equals(ROOT_UID))) {
            anon = ROOT_USER_ACCESS;
        } else {
            anon = DEFAULT_ANONMOUS_ACCESS;
        }
        tempUnManagedFSExport = new UnManagedFSExport(clientList, port, port + ":" + export.getPathname(), export.getSecurityRuleInfos().get(0).getSecFlavor(), permission, anon, NFS, port, export.getPathname(), export.getPathname());
    }
    return tempUnManagedFSExport;
}
Also used : UnManagedFSExport(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExport) ArrayList(java.util.ArrayList) ExportsHostnameInfo(com.iwave.ext.netapp.model.ExportsHostnameInfo)

Aggregations

ExportsHostnameInfo (com.iwave.ext.netapp.model.ExportsHostnameInfo)11 ArrayList (java.util.ArrayList)8 SecurityRuleInfo (com.iwave.ext.netapp.model.SecurityRuleInfo)5 UnManagedFSExport (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExport)4 List (java.util.List)4 NaElement (netapp.manage.NaElement)4 ExportsRuleInfo (com.iwave.ext.netapp.model.ExportsRuleInfo)3 StringSet (com.emc.storageos.db.client.model.StringSet)2 UnManagedFileExportRule (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule)2 NaAPIFailedException (netapp.manage.NaAPIFailedException)2 ExportSecurityType (com.emc.storageos.model.file.FileExportUpdateParams.ExportSecurityType)1 Test (org.junit.Test)1