ia64/xen-unstable

changeset 486:1f82aa25c8c7

bitkeeper revision 1.260 (3f042d1dYDmgfLY_ZLTlHlDZ45a_hA)

Refactor domctl into new tool, xenctl-cmdline, ready for combining with vd manager (and future porting of xenctl web interface to new backend)
author rac61@labyrinth.cl.cam.ac.uk
date Thu Jul 03 13:18:21 2003 +0000 (2003-07-03)
parents c6258eb58cde
children 09249a3c5206
files .rootkeys BitKeeper/etc/logging_ok tools/control/Makefile tools/control/build-cmdline.xml tools/control/src/org/xenoserver/cmdline/CommandParser.java tools/control/src/org/xenoserver/cmdline/Main.java tools/control/src/org/xenoserver/cmdline/ParseDestroy.java tools/control/src/org/xenoserver/cmdline/ParseFailedException.java tools/control/src/org/xenoserver/cmdline/ParseHelp.java tools/control/src/org/xenoserver/cmdline/ParseList.java tools/control/src/org/xenoserver/cmdline/ParseNew.java tools/control/src/org/xenoserver/cmdline/ParseStart.java tools/control/src/org/xenoserver/cmdline/ParseStop.java tools/control/src/org/xenoserver/control/Command.java tools/control/src/org/xenoserver/control/CommandDestroy.java tools/control/src/org/xenoserver/control/CommandFailedException.java tools/control/src/org/xenoserver/control/CommandList.java tools/control/src/org/xenoserver/control/CommandNew.java tools/control/src/org/xenoserver/control/CommandStart.java tools/control/src/org/xenoserver/control/CommandStop.java tools/control/src/org/xenoserver/control/Defaults.java tools/control/src/org/xenoserver/control/Domain.java tools/control/src/org/xenoserver/control/InetAddressPattern.java tools/control/src/org/xenoserver/control/Settings.java tools/control/src/org/xenoserver/control/StringPattern.java tools/control/xenctl
line diff
     1.1 --- a/.rootkeys	Tue Jul 01 14:17:01 2003 +0000
     1.2 +++ b/.rootkeys	Thu Jul 03 13:18:21 2003 +0000
     1.3 @@ -8,12 +8,34 @@ 3e6377d6eiFjF1hHIS6JEIOFk62xSA tools/bal
     1.4  3e6377dbGcgnisKw16DPCaND7oGO3Q tools/balloon/balloon.c
     1.5  3eb781edFwm_pW9FwnQACIe68viLOw tools/control/Makefile
     1.6  3eca6a96a31IwaKtkEa4jmzwTWlm8Q tools/control/README-xenctl
     1.7 +3eb781fceEYkUi1XHKf2V0KX7si2JA tools/control/build-cmdline.xml
     1.8  3eb781fcTp_LPQwaot3SSSehkaf4eg tools/control/build-dom.xml
     1.9  3ec41f7cWCxQ8pdH8ZWqhhv-38qQ1w tools/control/build-xen.xml
    1.10  3ec41f7ca6IBXDSe0HVcMPp3PPloOQ tools/control/build.properties
    1.11  3ec4ebe0g_MI1VqkbbyNB8gt6m0Adg tools/control/docs/empty_dir
    1.12  3eb781fcXf-WczEdAhnTpWfbR55jqA tools/control/domctl
    1.13  3eb781fcabCKRogwxJA3-jJKstw9Vg tools/control/domctl.xml
    1.14 +3f042c35FzVap5QW0UBPnZ2ZM0l3QA tools/control/src/org/xenoserver/cmdline/CommandParser.java
    1.15 +3eb781fdNQvEJW3tNvovjqoN7GlePA tools/control/src/org/xenoserver/cmdline/Main.java
    1.16 +3f042c35-TPgpCQViIaJzLts2-CnBw tools/control/src/org/xenoserver/cmdline/ParseDestroy.java
    1.17 +3f042c35UhRkvblwKSx0KW2QHUn3Fw tools/control/src/org/xenoserver/cmdline/ParseFailedException.java
    1.18 +3f042c35Inw0LzkOzXo9ncbEHZzUHA tools/control/src/org/xenoserver/cmdline/ParseHelp.java
    1.19 +3f042c35h9GAWRu7wimPjBpCi09nUA tools/control/src/org/xenoserver/cmdline/ParseList.java
    1.20 +3f042c359mRNaxBYXFwVsmv5-J_DJA tools/control/src/org/xenoserver/cmdline/ParseNew.java
    1.21 +3f042c35bMvqLB4Yc-0Dxs4WlYHHpw tools/control/src/org/xenoserver/cmdline/ParseStart.java
    1.22 +3f042c35Lc-JegNavF6Bj6coM486Ig tools/control/src/org/xenoserver/cmdline/ParseStop.java
    1.23 +3f042c35V-Bf3dlIe1r5mZs8ZTPSvA tools/control/src/org/xenoserver/control/Command.java
    1.24 +3f042c35U_4O2eovLKUgo2avPPHKUw tools/control/src/org/xenoserver/control/CommandDestroy.java
    1.25 +3f042c35hdwL__Airzyz4HutOgGRqQ tools/control/src/org/xenoserver/control/CommandFailedException.java
    1.26 +3f042c3570VRwuzl94tEozOIVBycNg tools/control/src/org/xenoserver/control/CommandList.java
    1.27 +3f042c35xVm-ucJAVdvC3acD6ZEe2Q tools/control/src/org/xenoserver/control/CommandNew.java
    1.28 +3f042c36GqoXJJj_BvWGwBeKwEzgvg tools/control/src/org/xenoserver/control/CommandStart.java
    1.29 +3f042c36bmZJD0xrxURD075avUlIUg tools/control/src/org/xenoserver/control/CommandStop.java
    1.30 +3eb781fdBRXfSlWzK6GXlIQIlHFoaQ tools/control/src/org/xenoserver/control/Defaults.java
    1.31 +3ec41f7cQ7Ug739JBDrsVH-7KJ5MvQ tools/control/src/org/xenoserver/control/Domain.java
    1.32 +3eb781fdDeZEopemXIVg_ARCGKSmBw tools/control/src/org/xenoserver/control/InetAddressPattern.java
    1.33 +3eb781fdmMkFbyb2SAGR0vsuFtl9Lw tools/control/src/org/xenoserver/control/Settings.java
    1.34 +3eb781fdpgi83RpUvQWVccWjsDJK7w tools/control/src/org/xenoserver/control/StringPattern.java
    1.35  3eb781fcffCXkrcWLBxUTOfQFa3Saw tools/control/src/uk/ac/cam/cl/xeno/domctl/Command.java
    1.36  3eb781fcOLcVAcqnZOAikur6sAP0rA tools/control/src/uk/ac/cam/cl/xeno/domctl/CommandDestroy.java
    1.37  3eb781fcQuQVSKxKtp4fBgPOwx7DDw tools/control/src/uk/ac/cam/cl/xeno/domctl/CommandHelp.java
    1.38 @@ -87,6 +109,7 @@ 3ec41f7e6SAwV8ebs9Be7zV2LV92oQ tools/con
    1.39  3ec41f7ecn3uvsSrOVxKC8G8ACuulg tools/control/web/tmpl/xenofoot.def
    1.40  3ec41f7ek1RffqN2yRUzSTkD5m1J6w tools/control/web/tmpl/xenohead.def
    1.41  3ec41f7e1ZpfCsgQ2qRJBooBn_iRtA tools/control/web/tmpl/xenostyle.css
    1.42 +3eb781fc6vgq5yhkJRGDLY9gWWRY2A tools/control/xenctl
    1.43  3e4d00468-FN2VDeEHo96zxrMHK_mA tools/domain_builder/Makefile
    1.44  3e4d0046SPau_y0sw2WLJz8QkqNoRA tools/domain_builder/README
    1.45  3e4d0046bbdH0GsI9J_1Eb4ZQHfIiQ tools/domain_builder/dom0_defs.h
     2.1 --- a/BitKeeper/etc/logging_ok	Tue Jul 01 14:17:01 2003 +0000
     2.2 +++ b/BitKeeper/etc/logging_ok	Thu Jul 03 13:18:21 2003 +0000
     2.3 @@ -15,6 +15,7 @@ kaf24@plym.cl.cam.ac.uk
     2.4  kaf24@scramble.cl.cam.ac.uk
     2.5  kaf24@striker.cl.cam.ac.uk
     2.6  lynx@idefix.cl.cam.ac.uk
     2.7 +rac61@labyrinth.cl.cam.ac.uk
     2.8  rgr22@boulderdash.cl.cam.ac.uk
     2.9  rn@wyvis.camb.intel-research.net
    2.10  rn@wyvis.research.intel-research.net
     3.1 --- a/tools/control/Makefile	Tue Jul 01 14:17:01 2003 +0000
     3.2 +++ b/tools/control/Makefile	Thu Jul 03 13:18:21 2003 +0000
     3.3 @@ -1,8 +1,21 @@
     3.4 -default: domctl xenctl
     3.5 +default: cmdline
     3.6 +
     3.7 +install: install-cmdline
     3.8 +
     3.9 +clean: clean-cmdline
    3.10 +
    3.11 +
    3.12  
    3.13 -install: install-domctl install-xenctl
    3.14 +cmdline: FORCE
    3.15 +	ant -buildfile build-cmdline.xml dist
    3.16  
    3.17 -clean: clean-domctl clean-xenctl
    3.18 +install-cmdline: domctl
    3.19 +	cp xenctl-cmdline.jar xenctl ../../../install/bin
    3.20 +	chmod 755 ../../../install/bin/xenctl
    3.21 +
    3.22 +clean-cmdline:
    3.23 +	ant -buildfile build-cmdline.xml clean
    3.24 +	rm -f xenctl-cmdline.jar
    3.25  
    3.26  
    3.27  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/control/build-cmdline.xml	Thu Jul 03 13:18:21 2003 +0000
     4.3 @@ -0,0 +1,50 @@
     4.4 +<project name="xenctl cmdline project" default="compile">
     4.5 +  <property name="src" location="src"/>
     4.6 +  <property name="build" location="build-cmdline"/>
     4.7 +
     4.8 +  <target name="init">
     4.9 +    <tstamp/>
    4.10 +    <mkdir dir="${build}"/>     
    4.11 +  </target>
    4.12 +
    4.13 +  <target name="compile" depends="init">
    4.14 +    <javac srcdir="${src}" destdir="${build}" debug="on">
    4.15 +      <include name="org/xenoserver/cmdline/**"/>
    4.16 +      <include name="org/xenoserver/control/**"/>
    4.17 +    </javac>
    4.18 +  </target>
    4.19 +
    4.20 +  <target name="dist" depends="compile">
    4.21 +    <jar jarfile="xenctl-cmdline.jar"
    4.22 +         excludes="*~"
    4.23 +	 basedir="${build}">
    4.24 +      <fileset dir="${src}">
    4.25 +        <include name="org/xenoserver/cmdline/**"/>
    4.26 +        <include name="org/xenoserver/control/**"/>
    4.27 +      </fileset>
    4.28 +      <fileset dir=".">
    4.29 +        <include name="build-cmdline.xml"/>
    4.30 +        <include name="xenctl"/>
    4.31 +        <include name="domctl.xml"/>
    4.32 +        <include name="Makefile"/>
    4.33 +      </fileset>
    4.34 +      <manifest>
    4.35 +        <attribute name="Built-By" value="${user.name}"/>
    4.36 +	<attribute name="Main-Class" value="org.xenoserver.cmdline.Main"/>
    4.37 +	<attribute name="Sealed" value="true"/>
    4.38 +      </manifest>
    4.39 +    </jar>
    4.40 +  </target>
    4.41 +
    4.42 +  <target name="test" depends="compile">
    4.43 +    <java fork="true" classname="org.xenoserver.cmdline.Main">
    4.44 +      <classpath>
    4.45 +        <pathelement path="${build}"/>
    4.46 +      </classpath>
    4.47 +    </java>
    4.48 +  </target>
    4.49 +
    4.50 +  <target name="clean">
    4.51 +    <delete dir="${build}"/>
    4.52 +  </target>
    4.53 +</project>
    4.54 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/control/src/org/xenoserver/cmdline/CommandParser.java	Thu Jul 03 13:18:21 2003 +0000
     5.3 @@ -0,0 +1,70 @@
     5.4 +package org.xenoserver.cmdline;
     5.5 +
     5.6 +import org.xenoserver.control.Command;
     5.7 +import org.xenoserver.control.CommandFailedException;
     5.8 +import org.xenoserver.control.Defaults;
     5.9 +
    5.10 +/**
    5.11 + * Subclasses of Parser know how to parse arguments for a given command
    5.12 + * and execute it, displaying any output.
    5.13 + */
    5.14 +public abstract class CommandParser {
    5.15 +  /**
    5.16 +   * Subclasses should implement this method such that it outputs any successful
    5.17 +   * output to the screen, or throws an exception if required arguments
    5.18 +   * are missing or malformed. It also may propagate exceptions from the
    5.19 +   * command execution.
    5.20 +   * 
    5.21 +   * @param d The defaults object to use.
    5.22 +   * @param args The arguments to parse.
    5.23 +   * @throws ParseFailedException if the arguments are not suitable.
    5.24 +   * @throws CommandFailedException if the command did not execute successfully.
    5.25 +   */
    5.26 +  public abstract void parse(Defaults d, String args[]) throws ParseFailedException, CommandFailedException;
    5.27 +
    5.28 +  /** Return the command name which will be matched on the command line. */  
    5.29 +  public abstract String getName();     
    5.30 +  /** Return a usage string for this command. */
    5.31 +  public abstract String getUsage();
    5.32 +  /** Return the help text for this command. */
    5.33 +  public abstract String getHelpText();
    5.34 +
    5.35 +  public String getStringParameter(String args[], char key, String def)
    5.36 +  {
    5.37 +    String r = getParameter (args, key);
    5.38 +    return (r == null) ? def : r;
    5.39 +  }
    5.40 +
    5.41 +  public int getIntParameter(String args[], char key, int def)
    5.42 +  {
    5.43 +    String r = getParameter (args, key);
    5.44 +    return (r == null) ? def : (Integer.parseInt (r));
    5.45 +  }
    5.46 +
    5.47 +  public boolean getFlagParameter(String args[], char key)
    5.48 +  {
    5.49 +    String r = getParameter (args, key);
    5.50 +    return (r == null) ? false : true;
    5.51 +  }
    5.52 +
    5.53 +  protected String getParameter (String args[], char key)
    5.54 +  {
    5.55 +    int i;
    5.56 +    String result = null;
    5.57 +    for (i = 0; i < args.length; i ++)
    5.58 +      {
    5.59 +  if (args[i].startsWith("-" + key)) 
    5.60 +    {
    5.61 +      if (args[i].length() > 2)
    5.62 +        {
    5.63 +    result = args[i].substring(2, args[i].length());
    5.64 +        }
    5.65 +      else
    5.66 +        {
    5.67 +    result = "";
    5.68 +        }
    5.69 +    }
    5.70 +      }
    5.71 +    return result;
    5.72 +  }
    5.73 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/control/src/org/xenoserver/cmdline/Main.java	Thu Jul 03 13:18:21 2003 +0000
     6.3 @@ -0,0 +1,49 @@
     6.4 +package org.xenoserver.cmdline;
     6.5 +
     6.6 +import org.xenoserver.control.CommandFailedException;
     6.7 +import org.xenoserver.control.Defaults;
     6.8 +
     6.9 +public class Main {
    6.10 +  private static ParseHelp help = new ParseHelp();
    6.11 +  static CommandParser commands[] =
    6.12 +    { help,
    6.13 +      new ParseNew(),
    6.14 +      new ParseStart(),
    6.15 +      new ParseStop(),
    6.16 +      new ParseDestroy(),
    6.17 +      new ParseList() };
    6.18 +
    6.19 +  public static void main(String[] args) {
    6.20 +    Defaults d = new Defaults();
    6.21 +    int ec = -1;
    6.22 +
    6.23 +    if (args.length == 0) {
    6.24 +      help.parse(d, args);
    6.25 +    } else {
    6.26 +      String c = args[0];
    6.27 +      int i;
    6.28 +      for (i = 0; i < commands.length; i++) {
    6.29 +        if (commands[i].getName().equals(c)) {
    6.30 +          if (commands[i].getFlagParameter(args, '?')) {
    6.31 +            help.doHelpFor(commands[i]);
    6.32 +          } else {
    6.33 +            try {
    6.34 +              commands[i].parse(d, args);
    6.35 +              ec = 0;
    6.36 +            } catch (ParseFailedException e) {
    6.37 +              System.err.println( e.getMessage() );
    6.38 +            } catch (CommandFailedException e) {
    6.39 +              System.err.println( e.getMessage() );
    6.40 +            }
    6.41 +          }
    6.42 +          break;
    6.43 +        }
    6.44 +      }
    6.45 +      if (i == commands.length) {
    6.46 +        System.out.println("Unknown command " + c);
    6.47 +      }
    6.48 +    }
    6.49 +
    6.50 +    System.exit(ec);
    6.51 +  }
    6.52 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDestroy.java	Thu Jul 03 13:18:21 2003 +0000
     7.3 @@ -0,0 +1,37 @@
     7.4 +package org.xenoserver.cmdline;
     7.5 +
     7.6 +import org.xenoserver.control.Command;
     7.7 +import org.xenoserver.control.CommandDestroy;
     7.8 +import org.xenoserver.control.CommandFailedException;
     7.9 +import org.xenoserver.control.Defaults;
    7.10 +
    7.11 +public class ParseDestroy extends CommandParser {
    7.12 +  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
    7.13 +    int domain_id = getIntParameter(args, 'n', 0);
    7.14 +    boolean force = getFlagParameter(args, 'f');
    7.15 +
    7.16 +    if (domain_id == 0) {
    7.17 +      throw new ParseFailedException("Expected -n<domain_id>");
    7.18 +    }
    7.19 +
    7.20 +    String output = new CommandDestroy(d, domain_id, force).execute();
    7.21 +    if ( output != null )
    7.22 +      System.out.println( output );
    7.23 +  }
    7.24 +  
    7.25 +  public String getName()
    7.26 +  {
    7.27 +    return "destroy";
    7.28 +  }
    7.29 +
    7.30 +  public String getUsage()
    7.31 +  {
    7.32 +    return "[-f] [-n<domain_id>]";
    7.33 +  }
    7.34 +
    7.35 +  public String getHelpText()
    7.36 +  {
    7.37 +    return
    7.38 +      "Destory the specified domain.  -f forcibly destroys it.";
    7.39 +  }
    7.40 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseFailedException.java	Thu Jul 03 13:18:21 2003 +0000
     8.3 @@ -0,0 +1,22 @@
     8.4 +package org.xenoserver.cmdline;
     8.5 +
     8.6 +/**
     8.7 + * Thrown when a command line could not be parsed.
     8.8 + */
     8.9 +public class ParseFailedException extends Exception {
    8.10 +  public ParseFailedException() {
    8.11 +    super();
    8.12 +  }
    8.13 +
    8.14 +  public ParseFailedException(String message) {
    8.15 +    super(message);
    8.16 +  }
    8.17 +
    8.18 +  public ParseFailedException(String message, Throwable cause) {
    8.19 +    super(message, cause);
    8.20 +  }
    8.21 +
    8.22 +  public ParseFailedException(Throwable cause) {
    8.23 +    super(cause);
    8.24 +  }
    8.25 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseHelp.java	Thu Jul 03 13:18:21 2003 +0000
     9.3 @@ -0,0 +1,53 @@
     9.4 +package org.xenoserver.cmdline;
     9.5 +
     9.6 +import org.xenoserver.control.Command;
     9.7 +import org.xenoserver.control.Defaults;
     9.8 +
     9.9 +public class ParseHelp extends CommandParser {
    9.10 +
    9.11 +  public void parse(Defaults d, String[] args) {
    9.12 +    if (args.length <= 1) {
    9.13 +      System.out.println("Usage:");
    9.14 +      for (int i = 0; i < Main.commands.length; i++) {
    9.15 +        String name = Main.commands[i].getName();
    9.16 +        String usage = Main.commands[i].getUsage();
    9.17 +        while (name.length() < 12)
    9.18 +          name = name + " ";
    9.19 +        System.out.println("   " + name + usage);
    9.20 +      }
    9.21 +    } else {
    9.22 +      for (int i = 0; i < Main.commands.length; i++) {
    9.23 +        String name = Main.commands[i].getName();
    9.24 +        String usage = Main.commands[i].getUsage();
    9.25 +        if (name.equals(args[1])) {
    9.26 +          doHelpFor(Main.commands[i]);
    9.27 +          break;
    9.28 +        }
    9.29 +      }
    9.30 +    }
    9.31 +
    9.32 +    System.out.println("");
    9.33 +  }
    9.34 +  
    9.35 +  public void doHelpFor(CommandParser c)
    9.36 +  {
    9.37 +    System.out.println ("xenctl " + c.getName() + " " + c.getUsage());
    9.38 +    System.out.println ();
    9.39 +    System.out.println (c.getHelpText ());
    9.40 +  }
    9.41 +
    9.42 +  public String getName()
    9.43 +  {
    9.44 +    return "help";
    9.45 +  }
    9.46 +
    9.47 +  public String getUsage()
    9.48 +  {
    9.49 +    return "";
    9.50 +  }
    9.51 +
    9.52 +  public String getHelpText()
    9.53 +  {
    9.54 +    return "This message";
    9.55 +  }  
    9.56 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseList.java	Thu Jul 03 13:18:21 2003 +0000
    10.3 @@ -0,0 +1,46 @@
    10.4 +package org.xenoserver.cmdline;
    10.5 +
    10.6 +import org.xenoserver.control.Command;
    10.7 +import org.xenoserver.control.CommandFailedException;
    10.8 +import org.xenoserver.control.CommandList;
    10.9 +import org.xenoserver.control.Defaults;
   10.10 +import org.xenoserver.control.Domain;
   10.11 +
   10.12 +public class ParseList extends CommandParser {
   10.13 +
   10.14 +  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
   10.15 +    CommandList list = new CommandList(d);
   10.16 +    String output = list.execute();
   10.17 +    if ( output != null )
   10.18 +      System.out.println( output );
   10.19 +    Domain[] domains = list.domains();
   10.20 +
   10.21 +    for (int loop = 0; loop < domains.length; loop++)
   10.22 +    {
   10.23 +      System.out.println ("id: " + domains[loop].id + 
   10.24 +        " (" + domains[loop].name+ ")");
   10.25 +      System.out.println ("  processor: " + domains[loop].processor);
   10.26 +      System.out.println ("  has cpu: " + domains[loop].cpu);
   10.27 +      System.out.println ("  state: " + domains[loop].nstate + " " +
   10.28 +        domains[loop].state);
   10.29 +      System.out.println ("  mcu advance: " + domains[loop].mcu);
   10.30 +      System.out.println ("  total pages: " + domains[loop].pages);
   10.31 +    }
   10.32 +  }
   10.33 +
   10.34 +  public String getName()
   10.35 +  {
   10.36 +    return "list";
   10.37 +  }
   10.38 +
   10.39 +  public String getUsage()
   10.40 +  {
   10.41 +    return "";
   10.42 +  }
   10.43 +
   10.44 +  public String getHelpText()
   10.45 +  {
   10.46 +    return
   10.47 +      "List domain information";
   10.48 +  }
   10.49 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseNew.java	Thu Jul 03 13:18:21 2003 +0000
    11.3 @@ -0,0 +1,81 @@
    11.4 +package org.xenoserver.cmdline;
    11.5 +
    11.6 +import org.xenoserver.control.Command;
    11.7 +import org.xenoserver.control.CommandFailedException;
    11.8 +import org.xenoserver.control.CommandNew;
    11.9 +import org.xenoserver.control.Defaults;
   11.10 +
   11.11 +public class ParseNew extends CommandParser {
   11.12 +
   11.13 +  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
   11.14 +    String name = getStringParameter(args, 'n', d.domainName);
   11.15 +    int size = getIntParameter(args, 'k', d.domainSizeKB);
   11.16 +    String image = getStringParameter(args, 'i', d.domainImage);
   11.17 +    String initrd = getStringParameter (args, 'r', d.domainInitRD);
   11.18 +    int vifs = getIntParameter(args, 'v', d.domainVIFs);
   11.19 +    String bargs = getStringParameter (args, 'a', d.args) + " ";
   11.20 +    String root_dev = getStringParameter (args, 'd', d.rootDevice);
   11.21 +    String nfs_root_path = getStringParameter (args, 'f', d.NWNFSRoot);
   11.22 +    String nw_ip = getStringParameter (args, '4', d.NWIP);
   11.23 +    String nw_gw = getStringParameter (args, 'g', d.NWGW);
   11.24 +    String nw_mask = getStringParameter (args, 'm', d.NWMask);
   11.25 +    String nw_nfs_server = getStringParameter (args, 's', d.NWNFSServer);
   11.26 +    String nw_host = getStringParameter (args, 'h', d.NWHost);
   11.27 +
   11.28 +    d.describe();
   11.29 +
   11.30 +    CommandNew c = new CommandNew(d, name, size, image, initrd, vifs,
   11.31 +                                  bargs, root_dev, nfs_root_path,
   11.32 +                                  nw_ip, nw_gw, nw_mask, nw_nfs_server, nw_host);
   11.33 +    c.execute();
   11.34 +    String[] output = c.output();
   11.35 +    for ( int i = 0; i < output.length; i++ )
   11.36 +      System.out.println( output[i] ); 
   11.37 +  }
   11.38 +
   11.39 +  public String getName()
   11.40 +  {
   11.41 +    return "new";
   11.42 +  }
   11.43 +
   11.44 +  public String getUsage()
   11.45 +  {
   11.46 +    return "[-n<domain_name>] [-k<size>] [-i<image>] [-v<num_vifs>] [-r<initrd>] [-d<root_device>] [-f<nfs_root>] [-s<nfs_boot_server>] [-4<ipv4_boot_address>] [-g<ipv4_boot_gateway>] [-m<ipv4_boot_netmask>] [-h<hostname>] [-a<args>]";
   11.47 +  }
   11.48 +
   11.49 +  public String getHelpText()
   11.50 +  {
   11.51 +    return
   11.52 +      "Create a new domain.  Note that most of the parameters will assume\n" +
   11.53 +      "default values: it should not be necessary to specify them all. See\n" +
   11.54 +      "domctl.xml for the current default settings.\n" +
   11.55 +      "\n" +
   11.56 +      "General command line options:\n" +
   11.57 +      "  -n  Domain name                              domain_name\n" +
   11.58 +      "  -k  Domain size (kb)                         domain_size_kb\n" +
   11.59 +      "  -i  Domain image name                        domain_image\n" +
   11.60 +      "  -v  Number of VIFs                           domain_vifs\n" +
   11.61 +      "  -r  InitRD (if required)                     domain_init_rd\n" +
   11.62 +      "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n" +
   11.63 +      "  -a  Additional boot parameters\n" +
   11.64 +      "\n" +
   11.65 +      "Networking options:\n" +
   11.66 +      "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n" +
   11.67 +      "  -s  NFS server                               nw_nfs_server\n" +
   11.68 +      "  -4  Domain IPv4 address                      nw_ip\n" +
   11.69 +      "  -g  Domain gateway                           nw_gw\n" +
   11.70 +      "  -m  Domain net mask                          nw_mask\n" +
   11.71 +      "  -h  Domain hostname                          nw_host\n" +
   11.72 +      "\n" +
   11.73 +      "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" +
   11.74 +      "which the allocated domain ID will be incorporated.  e.g.  for\n" +
   11.75 +      "domain 1 patterns would expand as follows:\n" +
   11.76 +      "\n" +
   11.77 +      "  /dev/hda+       /dev/hda1\n" +
   11.78 +      "  /dev/hda7+      /dev/hda8\n" +
   11.79 +      "  128.232.8.50+   128.232.8.51\n" +
   11.80 +      "\n" +
   11.81 +      "Additionally, patterns for -4 -g -m can include an = which is\n" + 
   11.82 +      "expanded to the corresponding setting from the calling domain.\n";
   11.83 +  }
   11.84 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseStart.java	Thu Jul 03 13:18:21 2003 +0000
    12.3 @@ -0,0 +1,37 @@
    12.4 +package org.xenoserver.cmdline;
    12.5 +
    12.6 +import org.xenoserver.control.Command;
    12.7 +import org.xenoserver.control.CommandFailedException;
    12.8 +import org.xenoserver.control.CommandStart;
    12.9 +import org.xenoserver.control.Defaults;
   12.10 +
   12.11 +public class ParseStart extends CommandParser {
   12.12 +
   12.13 +  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
   12.14 +    int domain_id = getIntParameter(args, 'n', 0);
   12.15 +    
   12.16 +    if (domain_id == 0) {
   12.17 +      throw new ParseFailedException("Expected -n<domain_id>");
   12.18 +    }
   12.19 +
   12.20 +    String output = new CommandStart(d, domain_id).execute();
   12.21 +    if ( output != null )
   12.22 +      System.out.println( output );
   12.23 +  }
   12.24 +
   12.25 +  public String getName()
   12.26 +  {
   12.27 +    return "start";
   12.28 +  }
   12.29 +
   12.30 +  public String getUsage()
   12.31 +  {
   12.32 +    return "[-n<domain_id>]";
   12.33 +  }
   12.34 +
   12.35 +  public String getHelpText()
   12.36 +  {
   12.37 +    return
   12.38 +      "Start the specified domain.";
   12.39 +  }
   12.40 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseStop.java	Thu Jul 03 13:18:21 2003 +0000
    13.3 @@ -0,0 +1,37 @@
    13.4 +package org.xenoserver.cmdline;
    13.5 +
    13.6 +import org.xenoserver.control.Command;
    13.7 +import org.xenoserver.control.CommandFailedException;
    13.8 +import org.xenoserver.control.CommandStop;
    13.9 +import org.xenoserver.control.Defaults;
   13.10 +
   13.11 +public class ParseStop extends CommandParser {
   13.12 +
   13.13 +  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
   13.14 +    int domain_id = getIntParameter(args, 'n', 0);
   13.15 +    
   13.16 +    if (domain_id == 0) {
   13.17 +      throw new ParseFailedException("Expected -n<domain_id>");
   13.18 +    }
   13.19 +
   13.20 +    String output = new CommandStop(d, domain_id).execute();
   13.21 +    if ( output != null )
   13.22 +      System.out.println( output );
   13.23 +  }
   13.24 +
   13.25 +  public String getName()
   13.26 +  {
   13.27 +    return "stop";
   13.28 +  }
   13.29 +
   13.30 +  public String getUsage()
   13.31 +  {
   13.32 +    return "[-n<domain_id>]";
   13.33 +  }
   13.34 +
   13.35 +  public String getHelpText()
   13.36 +  {
   13.37 +    return
   13.38 +      "Stop the specified domain.";
   13.39 +  }
   13.40 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tools/control/src/org/xenoserver/control/Command.java	Thu Jul 03 13:18:21 2003 +0000
    14.3 @@ -0,0 +1,27 @@
    14.4 +package org.xenoserver.control;
    14.5 +
    14.6 +/**
    14.7 + * Subclasses of Command are responsible for applying changes to domain
    14.8 + * and virtual disk settings.
    14.9 + */
   14.10 +public abstract class Command {
   14.11 +  /**
   14.12 +   * Subclasses should define an execute method which will apply the
   14.13 +   * relevant change, if possible.
   14.14 +   * 
   14.15 +   * @return The results of executing the command, if successful, or null if
   14.16 +   *         the command does not need to return results.
   14.17 +   * @throws CommandFailedException if the command could not be completed.
   14.18 +   */
   14.19 +  public abstract String execute() throws CommandFailedException;
   14.20 +
   14.21 +  protected String reportCommand (String cmd_array[])
   14.22 +  {
   14.23 +    StringBuffer sb = new StringBuffer();
   14.24 +    int i;
   14.25 +    for (i = 0; i < cmd_array.length; i ++) {
   14.26 +      sb.append (cmd_array[i] + " ");
   14.27 +    }
   14.28 +    return sb.toString();
   14.29 +  }
   14.30 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tools/control/src/org/xenoserver/control/CommandDestroy.java	Thu Jul 03 13:18:21 2003 +0000
    15.3 @@ -0,0 +1,58 @@
    15.4 +package org.xenoserver.control;
    15.5 +
    15.6 +/**
    15.7 + * Destroys a domain.
    15.8 + */
    15.9 +public class CommandDestroy extends Command {
   15.10 +  private Defaults d;
   15.11 +  private int domain_id;
   15.12 +  private boolean force;
   15.13 +
   15.14 +  /**
   15.15 +   * Constructor for CommandDestroy.
   15.16 +   * 
   15.17 +   * @param d Defaults object to use.
   15.18 +   * @param domain_id Domain ID number to destroy.
   15.19 +   * @param force Force destruction.
   15.20 +   */
   15.21 +  public CommandDestroy(Defaults d, int domain_id, boolean force) {
   15.22 +    this.d = d;
   15.23 +    this.domain_id = domain_id;
   15.24 +    this.force = force;
   15.25 +  }
   15.26 +
   15.27 +  public String execute() throws CommandFailedException {
   15.28 +    Runtime r = Runtime.getRuntime();
   15.29 +    String output = null;
   15.30 +
   15.31 +    try {
   15.32 +      Process destroy_p;
   15.33 +      String destroy_cmdarray[] = force ? new String[3] : new String[2];
   15.34 +      int destroy_rc;
   15.35 +      int idx = 0;
   15.36 +      destroy_cmdarray[idx++] = d.XIToolsDir + "xi_destroy";
   15.37 +      if (force) {
   15.38 +        destroy_cmdarray[idx++] = "-f";
   15.39 +      }
   15.40 +      destroy_cmdarray[idx++] = "" + domain_id;
   15.41 +
   15.42 +      if (Settings.TEST) {
   15.43 +        output = reportCommand(destroy_cmdarray);
   15.44 +      } else {
   15.45 +        destroy_p = r.exec(destroy_cmdarray);
   15.46 +        destroy_rc = destroy_p.waitFor();
   15.47 +
   15.48 +        if (destroy_rc != 0) {
   15.49 +          throw CommandFailedException.XICommandFailed("Could not destroy domain", destroy_cmdarray);
   15.50 +        }
   15.51 +        output = "Destroyed domain " + domain_id;
   15.52 +      }
   15.53 +    } catch (CommandFailedException e) {
   15.54 +      throw e;
   15.55 +    } catch (Exception e) {
   15.56 +      throw new CommandFailedException("Could not destroy domain (" + e + ")", e);
   15.57 +    }
   15.58 +
   15.59 +    return output;
   15.60 +  }
   15.61 +}
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tools/control/src/org/xenoserver/control/CommandFailedException.java	Thu Jul 03 13:18:21 2003 +0000
    16.3 @@ -0,0 +1,32 @@
    16.4 +package org.xenoserver.control;
    16.5 +
    16.6 +/**
    16.7 + * Thrown to indicate that a command failed to execute.
    16.8 + */
    16.9 +public class CommandFailedException extends Exception {
   16.10 +  public CommandFailedException() {
   16.11 +    super();
   16.12 +  }
   16.13 +
   16.14 +  public CommandFailedException(String message) {
   16.15 +    super(message);
   16.16 +  }
   16.17 +
   16.18 +  public CommandFailedException(String message, Throwable cause) {
   16.19 +    super(message, cause);
   16.20 +  }
   16.21 +
   16.22 +  public CommandFailedException(Throwable cause) {
   16.23 +    super(cause);
   16.24 +  }
   16.25 +  
   16.26 +  public static CommandFailedException XICommandFailed(String message, String cmd_array[]) {
   16.27 +    StringBuffer sb = new StringBuffer();
   16.28 +    int i;
   16.29 +    sb.append (message + " using: ");
   16.30 +    for (i = 0; i < cmd_array.length; i ++) {
   16.31 +      sb.append (cmd_array[i] + " ");
   16.32 +    }
   16.33 +    return new CommandFailedException( sb.toString() );    
   16.34 +  }
   16.35 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/control/src/org/xenoserver/control/CommandList.java	Thu Jul 03 13:18:21 2003 +0000
    17.3 @@ -0,0 +1,108 @@
    17.4 +package org.xenoserver.control;
    17.5 +
    17.6 +import java.io.BufferedReader;
    17.7 +import java.io.InputStreamReader;
    17.8 +import java.util.StringTokenizer;
    17.9 +import java.util.Vector;
   17.10 +
   17.11 +/**
   17.12 + * Lists details of all domains. After execute() has been called, call
   17.13 + * domains() to get the array of domains.
   17.14 + */
   17.15 +public class CommandList extends Command {
   17.16 +  private Defaults d;
   17.17 +  private Domain[] array;
   17.18 +
   17.19 +  /**
   17.20 +   * Constructor for CommandList.
   17.21 +   * @param d Defaults object to use.
   17.22 +   */
   17.23 +  public CommandList(Defaults d) {
   17.24 +    this.d = d;
   17.25 +  }
   17.26 +
   17.27 +  /**
   17.28 +   * Retrieves the list of domains.
   17.29 +   * @return null, call domains() to get the list.
   17.30 +   */
   17.31 +  public String execute() throws CommandFailedException {
   17.32 +    Runtime r = Runtime.getRuntime();
   17.33 +    int rc = 0;
   17.34 +    Vector v = new Vector();
   17.35 +    String outline;
   17.36 +    BufferedReader in;
   17.37 +    String output = null;
   17.38 +
   17.39 +    try {
   17.40 +      Process start_p;
   17.41 +      String start_cmdarray[] = new String[1];
   17.42 +      int start_rc;
   17.43 +      start_cmdarray[0] = d.XIToolsDir + "xi_list";
   17.44 +
   17.45 +      if (Settings.TEST) {
   17.46 +        output = reportCommand(start_cmdarray);
   17.47 +      } else {
   17.48 +        start_p = r.exec(start_cmdarray);
   17.49 +        start_rc = start_p.waitFor();
   17.50 +        if (start_rc != 0) {
   17.51 +          throw CommandFailedException.XICommandFailed("Could not get domain list", start_cmdarray);
   17.52 +        }
   17.53 +
   17.54 +        in =
   17.55 +          new BufferedReader(new InputStreamReader(start_p.getInputStream()));
   17.56 +
   17.57 +        outline = in.readLine();
   17.58 +        while (outline != null) {
   17.59 +          Domain domain = new Domain();
   17.60 +
   17.61 +          StringTokenizer st = new StringTokenizer(outline);
   17.62 +          if (st.hasMoreTokens()) {
   17.63 +            domain.id = Integer.parseInt(st.nextToken());
   17.64 +          }
   17.65 +          if (st.hasMoreTokens()) {
   17.66 +            domain.processor = Integer.parseInt(st.nextToken());
   17.67 +          }
   17.68 +          if (st.hasMoreTokens()) {
   17.69 +            if (st.nextToken().equals("1")) {
   17.70 +              domain.cpu = true;
   17.71 +            } else {
   17.72 +              domain.cpu = false;
   17.73 +            }
   17.74 +          }
   17.75 +          if (st.hasMoreTokens()) {
   17.76 +            domain.nstate = Integer.parseInt(st.nextToken());
   17.77 +          }
   17.78 +          if (st.hasMoreTokens()) {
   17.79 +            domain.state = st.nextToken().toLowerCase();
   17.80 +          }
   17.81 +          if (st.hasMoreTokens()) {
   17.82 +            domain.mcu = Integer.parseInt(st.nextToken());
   17.83 +          }
   17.84 +          if (st.hasMoreTokens()) {
   17.85 +            domain.pages = Integer.parseInt(st.nextToken());
   17.86 +          }
   17.87 +          if (st.hasMoreTokens()) {
   17.88 +            domain.name = st.nextToken();
   17.89 +          }
   17.90 +
   17.91 +          v.add(domain);
   17.92 +
   17.93 +          outline = in.readLine();
   17.94 +        }
   17.95 +
   17.96 +      }
   17.97 +    } catch (CommandFailedException e) {
   17.98 +      throw e;
   17.99 +    } catch (Exception e) {
  17.100 +      throw new CommandFailedException("Could not get domain list(" + e + ")", e);
  17.101 +    }
  17.102 +
  17.103 +    array = new Domain[v.size()];
  17.104 +    v.toArray(array);
  17.105 +    return output;
  17.106 +  }
  17.107 +  
  17.108 +  public Domain[] domains() {
  17.109 +    return array;
  17.110 +  }
  17.111 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/control/src/org/xenoserver/control/CommandNew.java	Thu Jul 03 13:18:21 2003 +0000
    18.3 @@ -0,0 +1,301 @@
    18.4 +package org.xenoserver.control;
    18.5 +
    18.6 +import java.io.BufferedReader;
    18.7 +import java.io.File;
    18.8 +import java.io.FileInputStream;
    18.9 +import java.io.FileOutputStream;
   18.10 +import java.io.IOException;
   18.11 +import java.io.InputStreamReader;
   18.12 +import java.net.InetAddress;
   18.13 +import java.net.UnknownHostException;
   18.14 +import java.util.zip.GZIPInputStream;
   18.15 +
   18.16 +/**
   18.17 + * Creates a new domain. As this command returns a multi-line result,
   18.18 + * call output() to get an array of strings.
   18.19 + */
   18.20 +public class CommandNew extends Command {
   18.21 +  private Defaults d;
   18.22 +  private String name;
   18.23 +  private int size;
   18.24 +  private String image;
   18.25 +  private String initrd;
   18.26 +  private int vifs;
   18.27 +  private String bargs;
   18.28 +  private String root_dev;
   18.29 +  private String nfs_root_path;
   18.30 +  private String nw_ip;
   18.31 +  private String nw_gw;
   18.32 +  private String nw_mask;
   18.33 +  private String nw_nfs_server;
   18.34 +  private String nw_host;
   18.35 +  private String[] output;
   18.36 +  
   18.37 +  public String[] output() {
   18.38 +    return output;
   18.39 +  }
   18.40 +  
   18.41 +  /**
   18.42 +   * Constructor for CommandNew.
   18.43 +   * @param d Defaults object to use.
   18.44 +   * @param name Name for the domain.
   18.45 +   * @param size Memory size for the domain.
   18.46 +   * @param image Image to boot domain from.
   18.47 +   * @param initrd Initrd to boot domain with.
   18.48 +   * @param vifs Number of virtual interfaces for the domain.
   18.49 +   * @param bargs Boot arguments for the domain.
   18.50 +   * @param root_dev Root device for the domain.
   18.51 +   * @param nfs_root_path NFS root to be used by the domain.
   18.52 +   * @param nw_ip IP address pattern to use for the domain's interfaces.
   18.53 +   * @param nw_gw Gateway to configure the domain for.
   18.54 +   * @param nw_mask Network mask to configure the domain for.
   18.55 +   * @param nw_nfs_server NFS server to be used by the domain.
   18.56 +   * @param nw_host Hostname to be used by the domain.
   18.57 +   */
   18.58 +  public CommandNew(
   18.59 +    Defaults d,
   18.60 +    String name,
   18.61 +    int size,
   18.62 +    String image,
   18.63 +    String initrd,
   18.64 +    int vifs,
   18.65 +    String bargs,
   18.66 +    String root_dev,
   18.67 +    String nfs_root_path,
   18.68 +    String nw_ip,
   18.69 +    String nw_gw,
   18.70 +    String nw_mask,
   18.71 +    String nw_nfs_server,
   18.72 +    String nw_host) {
   18.73 +    this.d = d;
   18.74 +    this.name = name;
   18.75 +    this.size = size;
   18.76 +    this.image = image;
   18.77 +    this.initrd = initrd;
   18.78 +    this.vifs = vifs;
   18.79 +    this.bargs = bargs;
   18.80 +    this.root_dev = root_dev;
   18.81 +    this.nfs_root_path = nfs_root_path;
   18.82 +    this.nw_ip = nw_ip;
   18.83 +    this.nw_gw = nw_gw;
   18.84 +    this.nw_mask = nw_mask;
   18.85 +    this.nw_nfs_server = nw_nfs_server;
   18.86 +    this.nw_host = nw_host;
   18.87 +  }
   18.88 +
   18.89 +  public String execute() throws CommandFailedException {
   18.90 +    Runtime r = Runtime.getRuntime();
   18.91 +    int domain_id = -1;
   18.92 +    BufferedReader br;
   18.93 +    int idx;
   18.94 +    int i;
   18.95 +    File image_tmp = null;
   18.96 +    File initrd_tmp = null;
   18.97 +    String domain_ip = "";
   18.98 +    
   18.99 +    String create_cmdarray[] = new String[3];
  18.100 +    String build_cmdarray[] = new String[6];
  18.101 +    String vifinit_cmdarray[] = new String[4];
  18.102 +
  18.103 +    try {
  18.104 +      try {
  18.105 +        /* Some initial sanity checks */
  18.106 +        if (root_dev.equals("/dev/nfs") && (vifs == 0)) {
  18.107 +          throw new CommandFailedException("Cannot use NFS root without VIFs configured");
  18.108 +        }
  18.109 +
  18.110 +        /* Uncompress the image and initrd */
  18.111 +        if (image.endsWith(".gz")) {
  18.112 +          image_tmp = getUncompressed("xen-image-", image);
  18.113 +          image = image_tmp.getPath();
  18.114 +        }
  18.115 +
  18.116 +        if (initrd != null && initrd.endsWith(".gz")) {
  18.117 +          initrd_tmp = getUncompressed("xen-initrd-", initrd);
  18.118 +          initrd = initrd_tmp.getPath();
  18.119 +        }
  18.120 +
  18.121 +        /* Create a new empty domain */
  18.122 +        Process create_p;
  18.123 +        int create_rc;
  18.124 +        create_cmdarray[0] = d.XIToolsDir + "xi_create";
  18.125 +        create_cmdarray[1] = "" + size;
  18.126 +        create_cmdarray[2] = name;
  18.127 +        if (Settings.TEST) {
  18.128 +          reportCommand(create_cmdarray);
  18.129 +          domain_id = 1;
  18.130 +          create_rc = 0;
  18.131 +        } else {
  18.132 +          create_p = r.exec(create_cmdarray);
  18.133 +          br =
  18.134 +            new BufferedReader(
  18.135 +              new InputStreamReader(create_p.getInputStream()));
  18.136 +          domain_id = Integer.parseInt(br.readLine());
  18.137 +          create_rc = create_p.waitFor();
  18.138 +        }
  18.139 +
  18.140 +        if (create_rc != 0) {
  18.141 +          throw CommandFailedException.XICommandFailed("Failed to create domain", create_cmdarray);
  18.142 +        } else if (domain_id > d.MaxDomainNumber) {
  18.143 +          throw new CommandFailedException(
  18.144 +            "Cannot configure more than " + d.MaxDomainNumber + " domains");
  18.145 +        }
  18.146 +
  18.147 +        /* Set up boot parameters to pass to xi_build. */
  18.148 +        if (root_dev.equals("/dev/nfs")) {
  18.149 +          if (vifs == 0) {
  18.150 +            throw new CommandFailedException("Cannot use NFS root without VIFs configured");
  18.151 +          }
  18.152 +          if (nfs_root_path == null) {
  18.153 +            throw new CommandFailedException("No NFS root specified");
  18.154 +          }
  18.155 +          if (nw_nfs_server == null) {
  18.156 +            throw new CommandFailedException("No NFS server specified");
  18.157 +          }
  18.158 +          bargs =
  18.159 +            (bargs
  18.160 +              + " root=/dev/nfs "
  18.161 +              + "nfsroot="
  18.162 +              + StringPattern.parse(nfs_root_path).resolve(domain_id)
  18.163 +              + " ");
  18.164 +        } else {
  18.165 +          bargs =
  18.166 +            (bargs
  18.167 +              + " root="
  18.168 +              + StringPattern.parse(root_dev).resolve(domain_id)
  18.169 +              + " ");
  18.170 +
  18.171 +        }
  18.172 +
  18.173 +        if (vifs > 0) {
  18.174 +          domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id);
  18.175 +          if (nw_host == null) {
  18.176 +            try {
  18.177 +              nw_host = InetAddress.getByName(domain_ip).getHostName();
  18.178 +            } catch (UnknownHostException uhe) {
  18.179 +              nw_host = "" + nw_ip;
  18.180 +            }
  18.181 +
  18.182 +          }
  18.183 +          bargs =
  18.184 +            ("ip="
  18.185 +              + domain_ip
  18.186 +              + ":"
  18.187 +              + ((nw_nfs_server == null)
  18.188 +                ? ""
  18.189 +                : (InetAddressPattern.parse(nw_nfs_server).resolve(domain_id)))
  18.190 +              + ":"
  18.191 +              + ((nw_gw == null)
  18.192 +                ? ""
  18.193 +                : (InetAddressPattern.parse(nw_gw).resolve(domain_id)))
  18.194 +              + ":"
  18.195 +              + ((nw_mask == null)
  18.196 +                ? ""
  18.197 +                : InetAddressPattern.parse(nw_mask).resolve(domain_id))
  18.198 +              + ":"
  18.199 +              + ((nw_host == null) ? "" : nw_host)
  18.200 +              + ":eth0:off "
  18.201 +              + bargs);
  18.202 +        }
  18.203 +
  18.204 +        /* Build the domain */
  18.205 +        Process build_p;
  18.206 +        int build_rc;
  18.207 +        idx = 0;
  18.208 +        for (i = 0; i < build_cmdarray.length; i++)
  18.209 +          build_cmdarray[i] = "";
  18.210 +        build_cmdarray[idx++] = d.XIToolsDir + "xi_build";
  18.211 +        build_cmdarray[idx++] = "" + domain_id;
  18.212 +        build_cmdarray[idx++] = "" + image;
  18.213 +        build_cmdarray[idx++] = "" + vifs;
  18.214 +        if (initrd != null)
  18.215 +          build_cmdarray[idx++] = "initrd=" + initrd;
  18.216 +        build_cmdarray[idx++] = "" + bargs;
  18.217 +        if (Settings.TEST) {
  18.218 +          reportCommand(build_cmdarray);
  18.219 +          build_rc = 0;
  18.220 +        } else {
  18.221 +          build_p = r.exec(build_cmdarray);
  18.222 +          build_rc = build_p.waitFor();
  18.223 +        }
  18.224 +
  18.225 +        if (build_rc != 0) {
  18.226 +          throw CommandFailedException.XICommandFailed("Failed to build domain", build_cmdarray);
  18.227 +        }
  18.228 +
  18.229 +        /* Set up the first VIF if necessary */
  18.230 +        if (vifs > 0) {
  18.231 +          Process vifinit_p;
  18.232 +          int vifinit_rc;
  18.233 +          vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit";
  18.234 +          vifinit_cmdarray[1] = "" + domain_id;
  18.235 +          vifinit_cmdarray[2] = "0";
  18.236 +          vifinit_cmdarray[3] = domain_ip;
  18.237 +          if (Settings.TEST) {
  18.238 +            reportCommand(vifinit_cmdarray);
  18.239 +            vifinit_rc = 0;
  18.240 +          } else {
  18.241 +            vifinit_p = r.exec(vifinit_cmdarray);
  18.242 +            vifinit_rc = vifinit_p.waitFor();
  18.243 +          }
  18.244 +
  18.245 +          if (vifinit_rc != 0) {
  18.246 +            throw CommandFailedException.XICommandFailed(
  18.247 +              "Failed to initialise VIF 0",
  18.248 +              vifinit_cmdarray);
  18.249 +          }
  18.250 +        }
  18.251 +      } finally {
  18.252 +        if (image_tmp != null)
  18.253 +          image_tmp.delete();
  18.254 +        if (initrd_tmp != null)
  18.255 +          initrd_tmp.delete();
  18.256 +      }
  18.257 +    } catch (CommandFailedException e) {
  18.258 +      throw e;
  18.259 +    } catch (Exception e) {
  18.260 +      throw new CommandFailedException("Could not create new domain (" + e + ")", e);
  18.261 +    }
  18.262 +
  18.263 +    output = new String[ vifs > 0 ? 6 : 4 ];
  18.264 +    output[0] = "Domain created with arguments:";
  18.265 +    output[1] = "";
  18.266 +    for (i = 0; i < create_cmdarray.length; i++)
  18.267 +      output[1] += create_cmdarray[i] + " ";
  18.268 +    output[2] = "Domain built with arguments:";
  18.269 +    output[3] = "";
  18.270 +    for (i = 0; i < build_cmdarray.length; i++)
  18.271 +      output[3] += build_cmdarray[i] + " ";
  18.272 +    if ( vifs > 0 ) {
  18.273 +      output[4] = "VIF 0 initialized with arguments:";
  18.274 +      output[5] = "";
  18.275 +      for (i = 0; i < vifinit_cmdarray.length; i++)
  18.276 +        output[5] += vifinit_cmdarray[i] + " ";
  18.277 +    }
  18.278 +
  18.279 +    return null;
  18.280 +  }
  18.281 +  
  18.282 +  private File getUncompressed (String prefix, String original) throws IOException {
  18.283 +    FileOutputStream fos;
  18.284 +    GZIPInputStream gis;
  18.285 +    File result;
  18.286 +    byte buffer[] = new byte[1024];
  18.287 +    int l;
  18.288 +    
  18.289 +    result = File.createTempFile (prefix, null);
  18.290 +    
  18.291 +    try {
  18.292 +      fos = new FileOutputStream (result);
  18.293 +      gis = new GZIPInputStream (new FileInputStream (original));
  18.294 +      while ((l = gis.read(buffer, 0, buffer.length)) != -1) {
  18.295 +  fos.write (buffer, 0, l);
  18.296 +      }   
  18.297 +    } catch (IOException ioe) {
  18.298 +      result.delete ();
  18.299 +      throw ioe;
  18.300 +    }
  18.301 +
  18.302 +    return result;
  18.303 +  }
  18.304 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tools/control/src/org/xenoserver/control/CommandStart.java	Thu Jul 03 13:18:21 2003 +0000
    19.3 @@ -0,0 +1,49 @@
    19.4 +package org.xenoserver.control;
    19.5 +
    19.6 +/**
    19.7 + * Starts a domain.
    19.8 + */
    19.9 +public class CommandStart extends Command {
   19.10 +  private Defaults d;
   19.11 +  private int domain_id;
   19.12 +  
   19.13 +  /**
   19.14 +   * Constructor for CommandStart.
   19.15 +   * @param d Defaults object to use.
   19.16 +   * @param domain_id Domain to start.
   19.17 +   */
   19.18 +  public CommandStart(Defaults d, int domain_id) {
   19.19 +    this.d = d;
   19.20 +    this.domain_id = domain_id;
   19.21 +  }
   19.22 +
   19.23 +  public String execute() throws CommandFailedException {
   19.24 +    Runtime r = Runtime.getRuntime();
   19.25 +    String output = null;
   19.26 +
   19.27 +    try {
   19.28 +      Process start_p;
   19.29 +      String start_cmdarray[] = new String[2];
   19.30 +      int start_rc;
   19.31 +      start_cmdarray[0] = d.XIToolsDir + "xi_start";
   19.32 +      start_cmdarray[1] = "" + domain_id;
   19.33 +
   19.34 +      if (Settings.TEST) {
   19.35 +        output = reportCommand(start_cmdarray);
   19.36 +      } else {
   19.37 +        start_p = r.exec(start_cmdarray);
   19.38 +        start_rc = start_p.waitFor();
   19.39 +        if (start_rc != 0) {
   19.40 +          throw CommandFailedException.XICommandFailed("Could not start domain", start_cmdarray);
   19.41 +        }
   19.42 +        output = "Started domain " + domain_id;
   19.43 +      }
   19.44 +    } catch (CommandFailedException e) {
   19.45 +      throw e;
   19.46 +    } catch (Exception e) {
   19.47 +      throw new CommandFailedException("Could not start new domain (" + e + ")", e);
   19.48 +    }
   19.49 +
   19.50 +    return output;
   19.51 +  }
   19.52 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/tools/control/src/org/xenoserver/control/CommandStop.java	Thu Jul 03 13:18:21 2003 +0000
    20.3 @@ -0,0 +1,50 @@
    20.4 +package org.xenoserver.control;
    20.5 +
    20.6 +/**
    20.7 + * Stops a domain.
    20.8 + */
    20.9 +public class CommandStop extends Command {
   20.10 +  private Defaults d;
   20.11 +  private int domain_id;
   20.12 +  
   20.13 +  /**
   20.14 +   * Constructor for CommandStop.
   20.15 +   * @param d The defaults object to use.
   20.16 +   * @param domain_id The domain to stop.
   20.17 +   */
   20.18 +  public CommandStop(Defaults d, int domain_id) {
   20.19 +    this.d = d;
   20.20 +    this.domain_id = domain_id;
   20.21 +  }
   20.22 +
   20.23 +  public String execute() throws CommandFailedException {
   20.24 +    Runtime r = Runtime.getRuntime();
   20.25 +    String output = null;
   20.26 +
   20.27 +    try {
   20.28 +      Process stop_p;
   20.29 +      String stop_cmdarray[] = new String[2];
   20.30 +      int stop_rc;
   20.31 +      stop_cmdarray[0] = d.XIToolsDir + "xi_stop";
   20.32 +      stop_cmdarray[1] = "" + domain_id;
   20.33 +
   20.34 +      if (Settings.TEST) {
   20.35 +        output = reportCommand(stop_cmdarray);
   20.36 +      } else {
   20.37 +        stop_p = r.exec(stop_cmdarray);
   20.38 +        stop_rc = stop_p.waitFor();
   20.39 +
   20.40 +        if (stop_rc != 0) {
   20.41 +          throw CommandFailedException.XICommandFailed("Could not stop domain", stop_cmdarray);
   20.42 +        }
   20.43 +        output = "Stopped domain " + domain_id;
   20.44 +      }
   20.45 +    } catch (CommandFailedException e) {
   20.46 +      throw e;
   20.47 +    } catch (Exception e) {
   20.48 +      throw new CommandFailedException("Could not stop new domain (" + e + ")", e);
   20.49 +    }
   20.50 +
   20.51 +    return output;
   20.52 +  }
   20.53 +}
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/tools/control/src/org/xenoserver/control/Defaults.java	Thu Jul 03 13:18:21 2003 +0000
    21.3 @@ -0,0 +1,205 @@
    21.4 +package org.xenoserver.control;
    21.5 +
    21.6 +import java.io.BufferedReader;
    21.7 +import java.io.File;
    21.8 +import java.io.FileReader;
    21.9 +import java.io.IOException;
   21.10 +import java.io.InputStreamReader;
   21.11 +
   21.12 +import org.xml.sax.Attributes;
   21.13 +import org.xml.sax.InputSource;
   21.14 +import org.xml.sax.XMLReader;
   21.15 +import org.xml.sax.helpers.DefaultHandler;
   21.16 +
   21.17 +/**
   21.18 + * The Defaults class stores the default settings to be used by the
   21.19 + * management utilities. On construction it parses the defaults file
   21.20 + * located through the Settings class.
   21.21 + */
   21.22 +public class Defaults
   21.23 +{
   21.24 +  public String domainName;
   21.25 +
   21.26 +  public int domainSizeKB;
   21.27 +  public String domainImage;
   21.28 +  public String domainInitRD;
   21.29 +  public int domainVIFs;
   21.30 +
   21.31 +  public String rootDevice;
   21.32 +
   21.33 +  public String NWIP;
   21.34 +  public String NWGW;
   21.35 +  public String NWMask;
   21.36 +  public String NWHost;
   21.37 +
   21.38 +  public String NWNFSServer;
   21.39 +  public String NWNFSRoot;
   21.40 +
   21.41 +  public int MaxDomainNumber = Integer.MAX_VALUE;
   21.42 +  public String args = "";
   21.43 +
   21.44 +  public String XIToolsDir = "";
   21.45 +
   21.46 +  /***********************************************************************/
   21.47 +
   21.48 +  public Defaults ()
   21.49 +  {
   21.50 +    File f = Settings.getDefaultsFile ();
   21.51 +
   21.52 +    if (f == null)
   21.53 +    {
   21.54 +      return;
   21.55 +    }
   21.56 +
   21.57 +    try
   21.58 +      {
   21.59 +	XMLReader xr = new org.apache.crimson.parser.XMLReaderImpl();
   21.60 +	Handler handler = new Handler ();
   21.61 +	xr.setContentHandler (handler);
   21.62 +	xr.setErrorHandler (handler);
   21.63 +	xr.parse (new InputSource(new FileReader (f)));
   21.64 +      }
   21.65 +    catch (Exception e) 
   21.66 +      {
   21.67 +	System.err.println ("Could not read defaults file " + f +
   21.68 +			    "\nException: " + e);
   21.69 +	e.printStackTrace();
   21.70 +	return;
   21.71 +      }
   21.72 +  }
   21.73 +
   21.74 +  public void describe () {
   21.75 +    System.out.println ("Domain defaults:");
   21.76 +    System.out.println ("   name            " + domainName);
   21.77 +    System.out.println ("   size            " + domainSizeKB);
   21.78 +    System.out.println ("   vifs            " + domainVIFs);
   21.79 +    System.out.println ("   domainImage     " + domainImage);
   21.80 +    System.out.println ("   domainInitRD    " + domainInitRD);
   21.81 +    System.out.println ("   rootDevice      " + rootDevice);
   21.82 +    System.out.println ("   NWIP            " + NWIP);
   21.83 +    System.out.println ("   NWGW            " + NWGW);
   21.84 +    System.out.println ("   NWMask          " + NWMask);
   21.85 +    System.out.println ("   MaxDomainNumber " + MaxDomainNumber);
   21.86 +    System.out.println ("   NWNFSServer     " + NWNFSServer);
   21.87 +    System.out.println ("   NWNFSRoot       " + NWNFSRoot);
   21.88 +    System.out.println ("   XIToolsDir      " + XIToolsDir);
   21.89 +    System.out.println ("   args            " + args);
   21.90 +  }
   21.91 +
   21.92 +  /***********************************************************************/
   21.93 +
   21.94 +  class Handler extends DefaultHandler
   21.95 +  {
   21.96 +    boolean inDomctlDefaults;
   21.97 +    String lastName;
   21.98 +
   21.99 +    public void startDocument ()
  21.100 +    {
  21.101 +    }
  21.102 +
  21.103 +    public void endDocument ()
  21.104 +    {
  21.105 +    }
  21.106 +
  21.107 +    public void startElement (String uri, String name,
  21.108 +			      String qname, Attributes atts)
  21.109 +    {
  21.110 +      if (qname.equals ("domctl_defaults")) {
  21.111 +	inDomctlDefaults = true;
  21.112 +      } else {
  21.113 +	lastName = qname;
  21.114 +      }
  21.115 +    }
  21.116 +
  21.117 +    public void endElement (String uri, String name, String qname)
  21.118 +    {
  21.119 +      lastName = "";
  21.120 +      if (qname.equals ("domctl_defaults")) {
  21.121 +	inDomctlDefaults = false;
  21.122 +      }
  21.123 +    }
  21.124 +    
  21.125 +    public void characters (char ch[], int start, int length)
  21.126 +    {
  21.127 +      String s = new String (ch, start, length);
  21.128 +      if (lastName != null)
  21.129 +	{
  21.130 +	  if (lastName.equals ("domain_size_kb")) {
  21.131 +	    domainSizeKB = Integer.parseInt (s);
  21.132 +	  } else if (lastName.equals ("domain_image")) {
  21.133 +	    domainImage = s;
  21.134 +	  } else if (lastName.equals ("domain_name")) {
  21.135 +	    domainName = s;
  21.136 +	  } else if (lastName.equals ("domain_init_rd")) {
  21.137 +	    domainInitRD = s;
  21.138 +	  } else if (lastName.equals ("domain_vifs")) {
  21.139 +	    domainVIFs = Integer.parseInt (s);
  21.140 +	  } else if (lastName.equals ("root_device")) {
  21.141 +	    rootDevice = s;
  21.142 +	  } else if (lastName.equals ("nw_ip")) {
  21.143 +	    NWIP = expandDefault (s, runCommand(XIToolsDir+Settings.XI_HELPER+" ip").trim());
  21.144 +	  } else if (lastName.equals ("nw_gw")) {
  21.145 +	    NWGW = expandDefault (s, runCommand(XIToolsDir+Settings.XI_HELPER+" route").trim());
  21.146 +	  } else if (lastName.equals ("nw_mask")) {
  21.147 +	    NWMask = expandDefault (s, runCommand(XIToolsDir+Settings.XI_HELPER+" mask").trim());
  21.148 +	  } else if (lastName.equals ("nw_host")) {
  21.149 +	    NWHost = s;
  21.150 +	  } else if (lastName.equals ("nw_nfs_server")) {
  21.151 +	    NWNFSServer = s;
  21.152 +	  } else if (lastName.equals ("nw_nfs_root")) {
  21.153 +	    NWNFSRoot = s;
  21.154 +	  } else if (lastName.equals ("args")) {
  21.155 +	    args = s;
  21.156 +	  } else if (lastName.equals ("max_domain_number")) {
  21.157 +	    MaxDomainNumber = Integer.parseInt(s);
  21.158 +	  } else if (lastName.equals ("xi_tools_dir")) {
  21.159 +	    XIToolsDir = s;
  21.160 +	  }
  21.161 +	}
  21.162 +    }
  21.163 +  }
  21.164 +
  21.165 +  public String expandDefault (String supplied, String self)
  21.166 +  {
  21.167 +    if (supplied.startsWith ("=")) {
  21.168 +      if (supplied.length() > 1) {
  21.169 +	return self + supplied.substring (1, supplied.length());
  21.170 +      } else {
  21.171 +	return self;
  21.172 +      }
  21.173 +    } else {
  21.174 +      return supplied;
  21.175 +    }
  21.176 +  }
  21.177 +
  21.178 +  
  21.179 +  public String
  21.180 +    runCommand (String command)
  21.181 +  {
  21.182 +    Runtime runtime = Runtime.getRuntime();
  21.183 +    String outline;
  21.184 +    StringBuffer output = new StringBuffer();
  21.185 +
  21.186 +    try
  21.187 +    {
  21.188 +      Process process = runtime.exec(command);
  21.189 +      BufferedReader in = new BufferedReader(
  21.190 +                         new InputStreamReader(process.getInputStream()));
  21.191 +
  21.192 +      outline = in.readLine();
  21.193 +      while (outline != null)
  21.194 +      {
  21.195 +        output.append("\n" + outline);
  21.196 +        outline = in.readLine();
  21.197 +      }
  21.198 +    }
  21.199 +    catch (IOException e)
  21.200 +    {
  21.201 +      return e.toString();
  21.202 +    }
  21.203 +
  21.204 +    return output.toString();
  21.205 +  }
  21.206 +
  21.207 +
  21.208 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/tools/control/src/org/xenoserver/control/Domain.java	Thu Jul 03 13:18:21 2003 +0000
    22.3 @@ -0,0 +1,31 @@
    22.4 +package org.xenoserver.control;
    22.5 +
    22.6 +/**
    22.7 + * A Domain object holds the details of one domain suitable for returning
    22.8 + * from methods enquiring about domain status.
    22.9 + */
   22.10 +public class
   22.11 +Domain
   22.12 +{
   22.13 +  public int id;                                                /* domain id */
   22.14 +  public int processor;                                         /* processor */
   22.15 +  public boolean cpu;                                             /* has cpu */
   22.16 +  public int   nstate;                                              /* state */
   22.17 +  public String state;            /* running, interruptable, uninterruptable,
   22.18 +				                      wait, suspended, dying */
   22.19 +  public int mcu;                                            /* mcu advances */
   22.20 +  public int pages;                                           /* total pages */
   22.21 +  public String name;                                                /* name */
   22.22 +
   22.23 +  Domain()
   22.24 +  {
   22.25 +    id = 0;
   22.26 +    processor = 0;
   22.27 +    cpu = false;
   22.28 +    nstate = 0;
   22.29 +    state = "";
   22.30 +    mcu = 0;
   22.31 +    pages = 0;
   22.32 +    name = "none";
   22.33 +  }
   22.34 +}
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/tools/control/src/org/xenoserver/control/InetAddressPattern.java	Thu Jul 03 13:18:21 2003 +0000
    23.3 @@ -0,0 +1,60 @@
    23.4 +package org.xenoserver.control;
    23.5 +
    23.6 +import java.net.*;
    23.7 +
    23.8 +public class InetAddressPattern
    23.9 +{
   23.10 +  InetAddress base;
   23.11 +  boolean addDom;
   23.12 +
   23.13 +  static InetAddressPattern parse (String t)
   23.14 +  {
   23.15 +    InetAddressPattern result = new InetAddressPattern ();
   23.16 +    char[] ca = t.toCharArray ();
   23.17 +    int idx = 0;
   23.18 +    int len = ca.length;
   23.19 +
   23.20 +    try {
   23.21 +      if (len == 0) {
   23.22 +	result.base = null;
   23.23 +	result.addDom = false;
   23.24 +      } else if (ca[len - 1] == '+') {
   23.25 +	result.base = InetAddress.getByName(t.substring(0, len - 1));
   23.26 +	result.addDom = true;
   23.27 +      } else {
   23.28 +	result.base = InetAddress.getByName(t);
   23.29 +	result.addDom = false;
   23.30 +      }
   23.31 +    } catch (UnknownHostException uhe) {
   23.32 +      result.base = null;
   23.33 +      result.addDom = false;
   23.34 +    }
   23.35 +
   23.36 +    return result;
   23.37 +  }
   23.38 +
   23.39 +  public String resolve (int domain_id) {
   23.40 +    byte b[] = base.getAddress ();
   23.41 +    if (addDom) {
   23.42 +      if (((int)b[3]) + domain_id > 255) {
   23.43 +	if (((int)b[2]) + domain_id > 255) {
   23.44 +	  if (((int)b[1]) + domain_id > 255) {
   23.45 +	    b[0] ++;
   23.46 +	  }
   23.47 +	  b[1] ++;
   23.48 +	}
   23.49 +	b[2] ++;
   23.50 +      }
   23.51 +      b[3] += domain_id;
   23.52 +    }
   23.53 +    return "" + 
   23.54 +      (b[0] + (b[0] < 0 ? 256 : 0)) + "." + 
   23.55 +      (b[1] + (b[1] < 0 ? 256 : 0)) + "." + 
   23.56 +      (b[2] + (b[2] < 0 ? 256 : 0)) + "." + 
   23.57 +      (b[3] + (b[3] < 0 ? 256 : 0));
   23.58 +  }
   23.59 +
   23.60 +  public String toString () {
   23.61 +    return "[" + base + (addDom ? "+dom_id" : "") + "]";
   23.62 +  }
   23.63 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/tools/control/src/org/xenoserver/control/Settings.java	Thu Jul 03 13:18:21 2003 +0000
    24.3 @@ -0,0 +1,41 @@
    24.4 +package org.xenoserver.control;
    24.5 +
    24.6 +import java.io.File;
    24.7 +import java.util.StringTokenizer;
    24.8 +
    24.9 +/**
   24.10 + * The Settings class is a repository for global settings such as the IP of
   24.11 + * the machine and the location of the defaults file.
   24.12 + */
   24.13 +public final class Settings
   24.14 +{
   24.15 +  public static final String DEFAULTS_FILE = System.getProperty ("DEFAULTS_FILE", "domctl.xml");
   24.16 +  public static final String DEFAULTS_PATH = System.getProperty ("DEFAULTS_PATH", ".:/etc:/var/lib/xen");
   24.17 +  public static final String LOCAL_IP = System.getProperty ("LOCAL_IP");
   24.18 +  public static final String LOCAL_MASK = System.getProperty ("LOCAL_MASK");
   24.19 +  public static final String LOCAL_GW = System.getProperty ("LOCAL_ROUTE");
   24.20 +  public static final boolean TEST = (System.getProperty ("TEST") != null);
   24.21 +  public static final String XI_HELPER = System.getProperty ("XI_HELPER", "xi_helper");
   24.22 +
   24.23 +
   24.24 +  public static File getDefaultsFile() {
   24.25 +    StringTokenizer tok = new StringTokenizer (DEFAULTS_PATH, ":");
   24.26 +    File result = null;
   24.27 +    File probe;
   24.28 +
   24.29 +    while (tok.hasMoreTokens ()) {
   24.30 +      String probe_dir = tok.nextToken ();
   24.31 +      probe = new File (probe_dir, DEFAULTS_FILE);
   24.32 +      if (probe.exists ()) {
   24.33 +	result = probe;
   24.34 +	break;
   24.35 +      }
   24.36 +    }
   24.37 +
   24.38 +    if (result == null) {
   24.39 +      System.err.println ("Could not find " + DEFAULTS_FILE + " in path " + DEFAULTS_PATH);
   24.40 +    }
   24.41 +
   24.42 +    return result;
   24.43 +  }
   24.44 +}
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/tools/control/src/org/xenoserver/control/StringPattern.java	Thu Jul 03 13:18:21 2003 +0000
    25.3 @@ -0,0 +1,59 @@
    25.4 +package org.xenoserver.control;
    25.5 +
    25.6 +public class StringPattern
    25.7 +{
    25.8 +  String base;
    25.9 +  int bn;
   25.10 +  boolean addDom;
   25.11 +  boolean appendDom;
   25.12 +
   25.13 +  static StringPattern parse (String t)
   25.14 +  {
   25.15 +    StringPattern result = new StringPattern ();
   25.16 +    char[] ca = t.toCharArray ();
   25.17 +    int idx = 0;
   25.18 +    int len = ca.length;
   25.19 +
   25.20 +    if (len == 0) {
   25.21 +      result.base = "";
   25.22 +      result.bn = 0;
   25.23 +      result.addDom = false;
   25.24 +    } else if (ca[len - 1] == '+') {
   25.25 +      idx = len - 2;
   25.26 +      if ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) {
   25.27 +	while ((idx >= 0) && (ca[idx] >= '0') && (ca[idx] <= '9')) {
   25.28 +	  idx --;
   25.29 +	}
   25.30 +	result.base = t.substring(0, idx + 1);
   25.31 +	result.bn = Integer.parseInt (t.substring (idx + 1, len - 1));
   25.32 +	result.addDom = true;
   25.33 +      } else {
   25.34 +	result.base = t.substring(0, len - 1);
   25.35 +	result.appendDom = true;
   25.36 +      }
   25.37 +    } else {
   25.38 +      result.base = t;
   25.39 +    }
   25.40 +
   25.41 +    return result;
   25.42 +  }
   25.43 +
   25.44 +  public String resolve (int domain_id) {
   25.45 +    if (addDom) {
   25.46 +      return base + (bn + domain_id);
   25.47 +    } else if (appendDom) {
   25.48 +      return base + domain_id;
   25.49 +    } else {
   25.50 +      return base;
   25.51 +    }
   25.52 +  }
   25.53 +
   25.54 +  public String toString () {
   25.55 +    return ("[" + 
   25.56 +	    base + 
   25.57 +	    (addDom ? "+" + bn : "") + 
   25.58 +	    ((addDom || appendDom) ? "+ID" : "") + 
   25.59 +	    "]");
   25.60 +  }
   25.61 +
   25.62 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/tools/control/xenctl	Thu Jul 03 13:18:21 2003 +0000
    26.3 @@ -0,0 +1,33 @@
    26.4 +#!/bin/bash 
    26.5 +
    26.6 +if [ -z "$DEFAULTS_FILE" ] ; then DEFAULTS_FILE=domctl.xml ; fi
    26.7 +if [ -z "$DEFAULTS_PATH" ] ; then DEFAULTS_PATH=.:/etc:/var/lib/xen ; fi
    26.8 +if [ -z "$QUERY_DEV" ] ; then QUERY_DEV=eth0 ; fi
    26.9 +if [ -z "$IFCONFIG" ] ; then IFCONFIG=/sbin/ifconfig ; fi
   26.10 +if [ -z "$ROUTE" ] ; then ROUTE=/sbin/route ; fi
   26.11 +if [ -z "$JAVA" ] ; then JAVA=java ; fi
   26.12 +
   26.13 +if [ "$1" = "new" ] ; then
   26.14 +  if [ ! -x "$IFCONFIG" ]; then  
   26.15 +    echo Could not find executable $IFCONFIG
   26.16 +    exit 1
   26.17 +  fi
   26.18 +
   26.19 +  if [ ! -x "$ROUTE" ]; then
   26.20 +    echo Could not find executable $ROUTE
   26.21 +    exit 1
   26.22 +  fi
   26.23 +
   26.24 +  # Try to determine dom0 network settings to avoid hard-coding
   26.25 +  # particular machines in the defaults file
   26.26 +  LOCAL_IP=$(/sbin/ifconfig $QUERY_DEV | grep 'inet addr' | tr ':' '\t' | awk '{print $3}')
   26.27 +  LOCAL_MASK=$(/sbin/ifconfig $QUERY_DEV | grep 'Mask' | tr ':' '\t' | awk '{print $7}')
   26.28 +  LOCAL_ROUTE=$(/sbin/route -n | grep $QUERY_DEV | grep 'G' | awk '{print $2}')
   26.29 +fi
   26.30 +
   26.31 +
   26.32 +#ARGS="-DTEST -DDEFAULTS_FILE=$DEFAULTS_FILE -DDEFAULTS_PATH=$DEFAULTS_PATH -DLOCAL_IP=$LOCAL_IP -DLOCAL_MASK=$LOCAL_MASK -DLOCAL_ROUTE=$LOCAL_ROUTE"
   26.33 +ARGS="-DDEFAULTS_FILE=$DEFAULTS_FILE -DDEFAULTS_PATH=$DEFAULTS_PATH -DLOCAL_IP=$LOCAL_IP -DLOCAL_MASK=$LOCAL_MASK -DLOCAL_ROUTE=$LOCAL_ROUTE"
   26.34 +
   26.35 +
   26.36 +$JAVA $ARGS -jar $(dirname $0)/xenctl-cmdline.jar $*