Package com.cloud.utils.script

Examples of com.cloud.utils.script.Script


              if (pidLine == null) {
                  throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
              }
              try {
                  final long pid = Long.parseLong(pidLine);
                  final Script script = new Script("bash", 120000, s_logger);
                  script.add("-c", "ps -p " + pid);
                  final String result = script.execute();
                  if (result == null) {
                      throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
                  }
                  if (!pidFile.delete()) {
                      throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
                  }
                  if (!pidFile.createNewFile()) {
                      throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
                  }
              } catch (final NumberFormatException e) {
                  throw new ConfigurationException("Java process is being started twice.  If this is not true, remove " + pidFile.getAbsolutePath());
              }
          }
          pidFile.deleteOnExit();
 
          final Script script = new Script("bash", 120000, s_logger);
          script.add("-c", "echo $PPID");
          final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
          script.execute(parser);
 
          final String pid = parser.getLine();
 
          final FileOutputStream strm = new FileOutputStream(pidFile);
          strm.write((pid + "\n").getBytes());
View Full Code Here


        return new Answer(cmd, result==null, result);
    }

    protected Answer execute(final CreateIpAliasCommand cmd) {
        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
        final Script command  = new Script(_createIpAliasPath, _timeout, s_logger);
        List<IpAliasTO> ipAliasTOs = cmd.getIpAliasList();
        String args = "";
        command.add(routerIp);
        for (IpAliasTO ipaliasto : ipAliasTOs) {
            args = args + ipaliasto.getAlias_count()+":"+ipaliasto.getRouterip()+":"+ipaliasto.getNetmask()+"-";
        }
        command.add(args);
        final String result = command.execute();
        return new Answer(cmd, result==null, result);
    }
View Full Code Here

        final String result = command.execute();
        return new Answer(cmd, result==null, result);
    }

    protected Answer execute(final DeleteIpAliasCommand cmd) {
        final Script command  = new Script(_deleteIpAliasPath, _timeout, s_logger);
        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
        String args ="";
        command.add(routerIp);
        List<IpAliasTO> revokedIpAliasTOs = cmd.getDeleteIpAliasTos();
        for (IpAliasTO ipAliasTO : revokedIpAliasTOs) {
            args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
        }
        args = args + "- " ;
        List<IpAliasTO> activeIpAliasTOs = cmd.getCreateIpAliasTos();
        for (IpAliasTO ipAliasTO : activeIpAliasTOs) {
            args = args + ipAliasTO.getAlias_count()+":"+ipAliasTO.getRouterip()+":"+ipAliasTO.getNetmask()+"-";
        }
        command.add(args);
        final String result = command.execute();
        return new Answer(cmd, result==null, result);
    }
View Full Code Here

        final String result = command.execute();
        return new Answer(cmd, result==null, result);
    }

    protected Answer execute(final DnsMasqConfigCommand cmd) {
        final Script command  = new Script(_callDnsMasqPath, _timeout, s_logger);
        String routerIp = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
        List<DhcpTO> dhcpTos = cmd.getIps();
        String args ="";
        for(DhcpTO dhcpTo : dhcpTos) {
            args = args + dhcpTo.getRouterIp()+":"+dhcpTo.getGateway()+":"+dhcpTo.getNetmask()+":"+dhcpTo.getStartIpOfSubnet()+"-";
        }
        command.add(routerIp);
        command.add(args);
        final String result = command.execute();
        return new Answer(cmd, result == null, result);
    }
View Full Code Here

        return routerProxyWithParser("checkrouter.sh", routerIP, null);
    }
   
   
    public String routerProxyWithParser(String script, String routerIP, String args) {
        final Script command  = new Script(_routerProxyPath, _timeout, s_logger);
        final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
        command.add(script);
        command.add(routerIP);
        if ( args != null ) {
            command.add(args);
        }
        String result = command.execute(parser);
        if (result == null) {
            return parser.getLine();
        }
        return null;
    }
View Full Code Here

        }
        return new CheckS2SVpnConnectionsAnswer(cmd, true, result);
    }
   
    public String routerProxy(String script, String routerIP, String args) {
        final Script command  = new Script(_routerProxyPath, _timeout, s_logger);
        command.add(script);
        command.add(routerIP);
        if ( args != null ) {
            command.add(args);
        }
        return command.execute();
    }
View Full Code Here

        return new CheckRouterAnswer(cmd, result, true);
    }

    protected Answer execute(BumpUpPriorityCommand cmd) {
        final String routerPrivateIPAddress = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
        final Script command  = new Script(_bumpUpPriorityPath, _timeout, s_logger);
        final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
        command.add(routerPrivateIPAddress);
        String result = command.execute(parser);
        if (result != null) {
            return new Answer(cmd, false, "BumpUpPriorityCommand failed: " + result);
        }
        return new Answer(cmd, true, null);
    }
View Full Code Here




    public 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

        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

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.