Package com.cloud.utils.script

Examples of com.cloud.utils.script.Script





    public synchronized String savePassword(final String privateIpAddress, final String vmIpAddress, final String password, final String localPath) {
        final Script command  = new Script(_savepasswordPath, _startTimeout, s_logger);
        command.add("-r", privateIpAddress);
        command.add("-v", vmIpAddress);
        command.add("-p", password);
        command.add(localPath);

        return command.execute();
    }
View Full Code Here


        args += vlanGateway;
        return routerProxy("ipassoc.sh", privateIpAddress, args);
    }
   
    private void deleteBridge(String brName) {
        Script cmd = new Script("/bin/sh", _timeout);
        cmd.add("-c");
        cmd.add("ifconfig " + brName + " down;brctl delbr " + brName);
        cmd.execute();
    }
View Full Code Here

        cmd.add("ifconfig " + brName + " down;brctl delbr " + brName);
        cmd.execute();
    }

    private boolean isDNSmasqRunning(String dnsmasqName) {
        Script cmd = new Script("/bin/sh", _timeout);
        cmd.add("-c");
        cmd.add("ls -l /var/run/libvirt/network/" + dnsmasqName + ".pid");
        String result = cmd.execute();
        if (result != null) {
            return false;
        } else {
            return true;
        }
View Full Code Here

            return true;
        }
    }

    private void stopDnsmasq(String dnsmasqName) {
        Script cmd = new Script("/bin/sh", _timeout);
        cmd.add("-c");
        cmd.add("kill -9 `cat /var/run/libvirt/network/"  + dnsmasqName +".pid`");
        cmd.execute();
    }
View Full Code Here

        if (routerIp == null) {
            return new SetFirewallRulesAnswer(cmd, false, results);
        }

        String[][] rules = cmd.generateFwRules();
        final Script command = new Script(_firewallPath, _timeout, s_logger);
        command.add(routerIp);
        command.add("-F");
       
        StringBuilder sb = new StringBuilder();
        String[] fwRules = rules[0];
        if (fwRules.length > 0) {
            for (int i = 0; i < fwRules.length; i++) {
                sb.append(fwRules[i]).append(',');
            }
            command.add("-a", sb.toString());
        }
      
        String result = command.execute();
        if (result != null) {
            return new SetFirewallRulesAnswer(cmd, false, results);
        }
        return new SetFirewallRulesAnswer(cmd, true, null);
       
View Full Code Here

        String[] results = new String[cmd.getRules().length];
        int i = 0;
        boolean endResult = true;
        for (PortForwardingRuleTO rule : cmd.getRules()) {
            String result = null;
            final Script command = new Script(_firewallPath, _timeout, s_logger);

            command.add(routerIp);
            command.add(rule.revoked() ? "-D" : "-A");
            command.add("-P ", rule.getProtocol().toLowerCase());
            command.add("-l ", rule.getSrcIp());
            command.add("-p ", rule.getStringSrcPortRange());
            command.add("-r ", rule.getDstIp());
            command.add("-d ", rule.getStringDstPortRange());
            result = command.execute();
            if (result == null) {
                results[i++] = null;
            } else {
                results[i++] = "Failed";
                endResult = false;
View Full Code Here

        return new GetHostStatsAnswer(cmd, hostStats);
    }

    protected String networkUsage(final String privateIpAddress,
            final String option, final String vif) {
        Script getUsage = new Script(_routerProxyPath, s_logger);
        getUsage.add("netusage.sh");
        getUsage.add(privateIpAddress);
        if (option.equals("get")) {
            getUsage.add("-g");
        } else if (option.equals("create")) {
            getUsage.add("-c");
        } else if (option.equals("reset")) {
            getUsage.add("-r");
        } else if (option.equals("addVif")) {
            getUsage.add("-a", vif);
        } else if (option.equals("deleteVif")) {
            getUsage.add("-d", vif);
        }


        final OutputInterpreter.OneLineParser usageParser = new OutputInterpreter.OneLineParser();
        String result = getUsage.execute(usageParser);
        if (result != null) {
            s_logger.debug("Failed to execute networkUsage:" + result);
            return null;
        }
        return usageParser.getLine();
View Full Code Here

    protected Answer execute(ModifySshKeysCommand cmd) {
        File sshKeysDir = new File(_SSHKEYSPATH);
        String result = null;
        if (!sshKeysDir.exists()) {
            // Change permissions for the 700
            Script script = new Script("mkdir", _timeout, s_logger);
            script.add("-m","700");
            script.add(_SSHKEYSPATH);
            script.execute();
           
            if(!sshKeysDir.exists()) {
                s_logger.debug("failed to create directory " + _SSHKEYSPATH);
            }
        }

        File pubKeyFile = new File(_SSHPUBKEYPATH);
        if (!pubKeyFile.exists()) {
            try {
                pubKeyFile.createNewFile();
            } catch (IOException e) {
                result = "Failed to create file: " + e.toString();
                s_logger.debug(result);
            }
        }

        if (pubKeyFile.exists()) {
            String pubKey = cmd.getPubKey();
            try {
                FileOutputStream pubkStream = new FileOutputStream(pubKeyFile);
                pubkStream.write(pubKey.getBytes());
                pubkStream.close();
            } catch (FileNotFoundException e) {
                result = "File" + _SSHPUBKEYPATH + "is not found:"
                        + e.toString();
                s_logger.debug(result);
            } catch (IOException e) {
                result = "Write file " + _SSHPUBKEYPATH + ":" + e.toString();
                s_logger.debug(result);
            }
        }

        File prvKeyFile = new File(_SSHPRVKEYPATH);
        if (!prvKeyFile.exists()) {
            try {
                prvKeyFile.createNewFile();
            } catch (IOException e) {
                result = "Failed to create file: " + e.toString();
                s_logger.debug(result);
            }
        }

        if (prvKeyFile.exists()) {
            String prvKey = cmd.getPrvKey();
            try {
                FileOutputStream prvKStream = new FileOutputStream(prvKeyFile);
                prvKStream.write(prvKey.getBytes());
                prvKStream.close();
            } catch (FileNotFoundException e) {
                result = "File" + _SSHPRVKEYPATH + "is not found:"
                        + e.toString();
                s_logger.debug(result);
            } catch (IOException e) {
                result = "Write file " + _SSHPRVKEYPATH + ":" + e.toString();
                s_logger.debug(result);
            }

            Script script = new Script("chmod", _timeout, s_logger);
            script.add("600", _SSHPRVKEYPATH);
            script.execute();
        }

        if (result != null) {
            return new Answer(cmd, false, result);
        } else {
View Full Code Here

        } else {
            s_logger.debug("found existing patch disk at " + patchDiskPath + " using it for " + vmName);
        }

        /* Format/create fs on this disk */
        final Script command = new Script(_createvmPath, _timeout, s_logger);
        command.add("-f", patchDiskPath);
        String result = command.execute();
        if (result != null) {
            s_logger.debug("Failed to create data disk: " + result);
            throw new InternalErrorException("Failed to create data disk: "
                    + result);
        }
View Full Code Here

    public Type getType() {
        return Type.Routing;
    }

    private Map<String, String> getVersionStrings() {
        final Script command = new Script(_versionstringpath, _timeout,
                s_logger);
        KeyValueInterpreter kvi = new KeyValueInterpreter();
        String result = command.execute(kvi);
        if (result == null) {
            return kvi.getKeyValues();
        } else {
            return new HashMap<String, String>(1);
        }
View Full Code Here

TOP

Related Classes of com.cloud.utils.script.Script

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.