Package net.augeas

Examples of net.augeas.Augeas


        // Usage of this value expects it to end with a slash, so make sure it's here
        if (!sshdPath.endsWith("/")) {
            sshdPath += "/";
        }

        Augeas augeas = new Augeas(rootPath, lensesPath, Augeas.NONE);
        try {
            return getConfig(resourceConfigurationDefinition, sshdPath, augeas);
        } finally {
            augeas.close();
        }
    }
View Full Code Here


    }

    protected AugeasNode getExistingChildNodeForListMemberPropertyMap(AugeasNode parentNode,
                                                                      PropertyDefinitionList propDefList, PropertyMap propMap) {
        // First find all child nodes with the same 'name' value as the PropertyMap.
        Augeas augeas = getAugeas();

        String nameFilter = parentNode.getPath() + "/*/name";
        String canonical = propMap.getSimple("name").getStringValue();
        List<String> namePaths = AugeasUtility.matchFilter(augeas, nameFilter, canonical);

View Full Code Here

        System.out.println(" [success!]");
    }

    public boolean isAugeasInstalled() {
        try {
            Augeas ag = new Augeas();
        } catch (Throwable e) {
            return false;
        }
        return true;
    }
View Full Code Here

        nodePaths.get(configFilePath).add(nodeSuffix);
    }

    public void mergeRawConfig(Configuration from, RawConfiguration existingConfig, RawConfiguration toUpdate)
        throws Exception {
        Augeas aug = null;
        try {
            String lens = configMap.get(existingConfig.getPath());
            aug = createAugeas(lens, existingConfig.getContents());
            String file = getFile(aug);
            for (String pathSuffix : nodePaths.get(existingConfig.getPath())) {
                String propName = ("/files" + existingConfig.getPath() + "/" + pathSuffix).substring(rootNodePath
                    .length());
                String propValue = translator.getPropertyValue(propName, from);

                aug.set("/files" + file + "/" + pathSuffix, propValue);
            }
            aug.save();

            toUpdate.setPath(existingConfig.getPath());
            String contents = FileUtils.readFileToString(new File(file));
            String sha256 = new MessageDigestGenerator(MessageDigestGenerator.SHA_256).calcDigestString(contents);
            toUpdate.setContents(contents, sha256);
        } finally {
            if (aug != null) {
                aug.close();
            }
        }
    }
View Full Code Here

            }
        }
    }

    public void mergeStructured(RawConfiguration from, Configuration toUpdate) throws Exception {
        Augeas aug = null;
        try {
            String lens = configMap.get(from.getPath());
            aug = createAugeas(lens, from.getContents());
            String file = getFile(aug);
            for (String pathSuffix : nodePaths.get(from.getPath())) {
                String propName = ("/files" + from.getPath() + "/" + pathSuffix).substring(rootNodePath.length());
                String augeasPath = "/files" + file + "/" + pathSuffix;
                Property property = translator.createProperty(propName, augeasPath, aug);
                toUpdate.put(property);
            }
        } finally {
            if (aug != null) {
                aug.close();
            }
        }
    }
View Full Code Here

    private String getFile(Augeas aug) {
        return aug.get(transformPrefix + "/incl");
    }

    private Augeas createAugeas(String lens, String contents) throws Exception {
        Augeas aug = new Augeas(rootPath, loadPath, Augeas.NO_MODL_AUTOLOAD);
        File fl = File.createTempFile("_rhq", null);
        //write the 'to' file to disk
        FileUtils.writeStringToFile(fl, contents);
        aug.set(transformPrefix + "/lens", lens);
        aug.set(transformPrefix + "/incl", fl.getAbsolutePath());
        aug.load();
        return aug;
    }
View Full Code Here

    public void deleteResource() throws Exception {
        String rootPath = getResourceConfigurationRootPath();
        initAugeas();
        try {
            Augeas augeas = getAugeas();
            augeas.remove(rootPath);
            augeas.save();
        } finally {
            close();
        }
    }
View Full Code Here

            augeas.set("/augeas/load/" + augeasModuleName + "/excl[" + (idx++) + "]", excl);
        }
    }

    protected Augeas createAugeas() {
        Augeas augeas;
        try {
            augeas = new Augeas(this.augeasRootPath, augeasLoadPath, Augeas.NO_MODL_AUTOLOAD);
            setupAugeasModules(augeas);
            checkModuleErrors(augeas);
        } catch (Throwable e) {
            augeas = null;
            String msg = "Failed to initialize Augeas Java API: " + e.getMessage();
View Full Code Here

    }

    protected AugeasNode getExistingChildNodeForListMemberPropertyMap(AugeasNode parentNode,
        PropertyDefinitionList propDefList, PropertyMap propMap) {
        // First find all child nodes with the same 'canonical' value as the PropertyMap.
        Augeas augeas = getAugeas();
        String canonicalFilter = parentNode.getPath() + "/*/canonical";
        String canonical = propMap.getSimple("canonical").getStringValue();
        List<String> canonicalPaths = AugeasUtility.matchFilter(augeas, canonicalFilter, canonical);
        if (canonicalPaths.isEmpty()) {
            return null;
        }

        // Now see if there's at least one node in this list with an 'ipaddr' value with the same IP address version as
        // the PropertyMap.
        String ipaddr = propMap.getSimple("ipaddr").getStringValue();
        int ipAddressVersion = (ipaddr.indexOf(':') == -1) ? 4 : 6;
        for (String canonicalPath : canonicalPaths) {
            AugeasNode canonicalNode = new AugeasNode(canonicalPath);
            AugeasNode childNode = canonicalNode.getParent();
            AugeasNode ipaddrNode = new AugeasNode(childNode, "ipaddr");
            String existingIpaddr = augeas.get(ipaddrNode.getPath());
            int existingIpAddressVersion = (existingIpaddr.indexOf(':') == -1) ? 4 : 6;
            if (existingIpAddressVersion == ipAddressVersion) {
                return childNode;
            }
        }
View Full Code Here

                    augeas.close();
                } catch (Exception e) {
                    log.error("Could not close augeas instance", e);
                }
            }
            augeas = new Augeas(config.getRootPath(), config.getLoadPath(), config.getMode());

            for (AugeasModuleConfig module : config.getModules()) {

                modules.add(module.getModuletName());
                augeas.set("/augeas/load/" + module.getModuletName() + "/lens", module.getLensPath());
View Full Code Here

TOP

Related Classes of net.augeas.Augeas

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.