ia64/xen-unstable

changeset 489:3eeebe63afee

bitkeeper revision 1.263 (3f044553Casub9OwqMoobhkY4qWGpQ)

Apply Composite pattern to add recursive command parsing; this allows commands to be in groups so that the user interface isn't quite so unwieldy.
In order to make this sensible, rename the domain classes to indicate better what they are.
author rac61@labyrinth.cl.cam.ac.uk
date Thu Jul 03 15:01:39 2003 +0000 (2003-07-03)
parents fd8bf35bb913
children 690dd12296b6
files .rootkeys 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/ParseDomainDestroy.java tools/control/src/org/xenoserver/cmdline/ParseDomainList.java tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java tools/control/src/org/xenoserver/cmdline/ParseGroup.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/CommandDestroy.java tools/control/src/org/xenoserver/control/CommandDomainDestroy.java tools/control/src/org/xenoserver/control/CommandDomainList.java tools/control/src/org/xenoserver/control/CommandDomainNew.java tools/control/src/org/xenoserver/control/CommandDomainStart.java tools/control/src/org/xenoserver/control/CommandDomainStop.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
line diff
     1.1 --- a/.rootkeys	Thu Jul 03 13:36:35 2003 +0000
     1.2 +++ b/.rootkeys	Thu Jul 03 15:01:39 2003 +0000
     1.3 @@ -17,20 +17,21 @@ 3eb781fcXf-WczEdAhnTpWfbR55jqA tools/con
     1.4  3eb781fcabCKRogwxJA3-jJKstw9Vg tools/control/domctl.xml
     1.5  3f042c35FzVap5QW0UBPnZ2ZM0l3QA tools/control/src/org/xenoserver/cmdline/CommandParser.java
     1.6  3eb781fdNQvEJW3tNvovjqoN7GlePA tools/control/src/org/xenoserver/cmdline/Main.java
     1.7 -3f042c35-TPgpCQViIaJzLts2-CnBw tools/control/src/org/xenoserver/cmdline/ParseDestroy.java
     1.8 +3f042c35-TPgpCQViIaJzLts2-CnBw tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java
     1.9 +3f042c35h9GAWRu7wimPjBpCi09nUA tools/control/src/org/xenoserver/cmdline/ParseDomainList.java
    1.10 +3f042c359mRNaxBYXFwVsmv5-J_DJA tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java
    1.11 +3f042c35bMvqLB4Yc-0Dxs4WlYHHpw tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java
    1.12 +3f042c35Lc-JegNavF6Bj6coM486Ig tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java
    1.13  3f042c35UhRkvblwKSx0KW2QHUn3Fw tools/control/src/org/xenoserver/cmdline/ParseFailedException.java
    1.14 +3f0445524oTSyogDGmCAyKMM665Rxg tools/control/src/org/xenoserver/cmdline/ParseGroup.java
    1.15  3f042c35Inw0LzkOzXo9ncbEHZzUHA tools/control/src/org/xenoserver/cmdline/ParseHelp.java
    1.16 -3f042c35h9GAWRu7wimPjBpCi09nUA tools/control/src/org/xenoserver/cmdline/ParseList.java
    1.17 -3f042c359mRNaxBYXFwVsmv5-J_DJA tools/control/src/org/xenoserver/cmdline/ParseNew.java
    1.18 -3f042c35bMvqLB4Yc-0Dxs4WlYHHpw tools/control/src/org/xenoserver/cmdline/ParseStart.java
    1.19 -3f042c35Lc-JegNavF6Bj6coM486Ig tools/control/src/org/xenoserver/cmdline/ParseStop.java
    1.20  3f042c35V-Bf3dlIe1r5mZs8ZTPSvA tools/control/src/org/xenoserver/control/Command.java
    1.21 -3f042c35U_4O2eovLKUgo2avPPHKUw tools/control/src/org/xenoserver/control/CommandDestroy.java
    1.22 +3f042c35U_4O2eovLKUgo2avPPHKUw tools/control/src/org/xenoserver/control/CommandDomainDestroy.java
    1.23 +3f042c3570VRwuzl94tEozOIVBycNg tools/control/src/org/xenoserver/control/CommandDomainList.java
    1.24 +3f042c35xVm-ucJAVdvC3acD6ZEe2Q tools/control/src/org/xenoserver/control/CommandDomainNew.java
    1.25 +3f042c36GqoXJJj_BvWGwBeKwEzgvg tools/control/src/org/xenoserver/control/CommandDomainStart.java
    1.26 +3f042c36bmZJD0xrxURD075avUlIUg tools/control/src/org/xenoserver/control/CommandDomainStop.java
    1.27  3f042c35hdwL__Airzyz4HutOgGRqQ tools/control/src/org/xenoserver/control/CommandFailedException.java
    1.28 -3f042c3570VRwuzl94tEozOIVBycNg tools/control/src/org/xenoserver/control/CommandList.java
    1.29 -3f042c35xVm-ucJAVdvC3acD6ZEe2Q tools/control/src/org/xenoserver/control/CommandNew.java
    1.30 -3f042c36GqoXJJj_BvWGwBeKwEzgvg tools/control/src/org/xenoserver/control/CommandStart.java
    1.31 -3f042c36bmZJD0xrxURD075avUlIUg tools/control/src/org/xenoserver/control/CommandStop.java
    1.32  3eb781fdBRXfSlWzK6GXlIQIlHFoaQ tools/control/src/org/xenoserver/control/Defaults.java
    1.33  3ec41f7cQ7Ug739JBDrsVH-7KJ5MvQ tools/control/src/org/xenoserver/control/Domain.java
    1.34  3eb781fdDeZEopemXIVg_ARCGKSmBw tools/control/src/org/xenoserver/control/InetAddressPattern.java
     2.1 --- a/tools/control/src/org/xenoserver/cmdline/CommandParser.java	Thu Jul 03 13:36:35 2003 +0000
     2.2 +++ b/tools/control/src/org/xenoserver/cmdline/CommandParser.java	Thu Jul 03 15:01:39 2003 +0000
     2.3 @@ -1,5 +1,9 @@
     2.4  package org.xenoserver.cmdline;
     2.5  
     2.6 +import java.util.Iterator;
     2.7 +import java.util.LinkedList;
     2.8 +import java.util.List;
     2.9 +
    2.10  import org.xenoserver.control.Command;
    2.11  import org.xenoserver.control.CommandFailedException;
    2.12  import org.xenoserver.control.Defaults;
    2.13 @@ -20,51 +24,64 @@ public abstract class CommandParser {
    2.14     * @throws ParseFailedException if the arguments are not suitable.
    2.15     * @throws CommandFailedException if the command did not execute successfully.
    2.16     */
    2.17 -  public abstract void parse(Defaults d, String args[]) throws ParseFailedException, CommandFailedException;
    2.18 +  public abstract void parse(Defaults d, LinkedList args)
    2.19 +    throws ParseFailedException, CommandFailedException;
    2.20  
    2.21 -  /** Return the command name which will be matched on the command line. */  
    2.22 -  public abstract String getName();     
    2.23 +  /** Return the command name which will be matched on the command line. */
    2.24 +  public abstract String getName();
    2.25    /** Return a usage string for this command. */
    2.26    public abstract String getUsage();
    2.27    /** Return the help text for this command. */
    2.28    public abstract String getHelpText();
    2.29 +  
    2.30 +  /** Print a usage string for this command. */
    2.31 +  public void printUsage(String prefix)
    2.32 +  {
    2.33 +    String name = getName();
    2.34 +    if ( prefix != null )
    2.35 +      name = prefix + " " + name;
    2.36 +    String usage = getUsage();
    2.37 +    while (name.length() < 16)
    2.38 +      name = name + " ";
    2.39 +    System.out.println("   " + name + usage);
    2.40 +  }
    2.41 +  
    2.42 +  /** Prints the help text for this command. */
    2.43 +  public void printHelpText(LinkedList args)
    2.44 +  {
    2.45 +    System.out.println(getName() + " " + getUsage());
    2.46 +    System.out.println();
    2.47 +    System.out.println(getHelpText());
    2.48 +  }
    2.49  
    2.50 -  public String getStringParameter(String args[], char key, String def)
    2.51 -  {
    2.52 -    String r = getParameter (args, key);
    2.53 +  public String getStringParameter(List args, char key, String def) {
    2.54 +    String r = getParameter(args, key);
    2.55      return (r == null) ? def : r;
    2.56    }
    2.57  
    2.58 -  public int getIntParameter(String args[], char key, int def)
    2.59 -  {
    2.60 -    String r = getParameter (args, key);
    2.61 -    return (r == null) ? def : (Integer.parseInt (r));
    2.62 +  public int getIntParameter(List args, char key, int def) {
    2.63 +    String r = getParameter(args, key);
    2.64 +    return (r == null) ? def : (Integer.parseInt(r));
    2.65    }
    2.66  
    2.67 -  public boolean getFlagParameter(String args[], char key)
    2.68 -  {
    2.69 -    String r = getParameter (args, key);
    2.70 +  public boolean getFlagParameter(List args, char key) {
    2.71 +    String r = getParameter(args, key);
    2.72      return (r == null) ? false : true;
    2.73    }
    2.74  
    2.75 -  protected String getParameter (String args[], char key)
    2.76 -  {
    2.77 -    int i;
    2.78 +  protected String getParameter(List args, char key) {
    2.79      String result = null;
    2.80 -    for (i = 0; i < args.length; i ++)
    2.81 -      {
    2.82 -  if (args[i].startsWith("-" + key)) 
    2.83 -    {
    2.84 -      if (args[i].length() > 2)
    2.85 -        {
    2.86 -    result = args[i].substring(2, args[i].length());
    2.87 +    Iterator i = args.iterator();
    2.88 +    while ( i.hasNext() ) {
    2.89 +      String arg = (String) i.next();
    2.90 +      if (arg.startsWith("-" + key)) {
    2.91 +        if (arg.length() > 2) {
    2.92 +          result = arg.substring(2);
    2.93 +        } else {
    2.94 +          result = "";
    2.95          }
    2.96 -      else
    2.97 -        {
    2.98 -    result = "";
    2.99 -        }
   2.100 +      }
   2.101      }
   2.102 -      }
   2.103      return result;
   2.104    }
   2.105  }
     3.1 --- a/tools/control/src/org/xenoserver/cmdline/Main.java	Thu Jul 03 13:36:35 2003 +0000
     3.2 +++ b/tools/control/src/org/xenoserver/cmdline/Main.java	Thu Jul 03 15:01:39 2003 +0000
     3.3 @@ -1,46 +1,46 @@
     3.4  package org.xenoserver.cmdline;
     3.5  
     3.6 +import java.util.Arrays;
     3.7 +import java.util.Collections;
     3.8 +import java.util.LinkedList;
     3.9 +import java.util.List;
    3.10 +
    3.11  import org.xenoserver.control.CommandFailedException;
    3.12  import org.xenoserver.control.Defaults;
    3.13  
    3.14  public class Main {
    3.15 -  private static ParseHelp help = new ParseHelp();
    3.16 -  static CommandParser commands[] =
    3.17 +  static final ParseHelp help = new ParseHelp();
    3.18 +  static final CommandParser domaincommands[] =
    3.19 +    { new ParseDomainNew(),
    3.20 +      new ParseDomainStart(),
    3.21 +      new ParseDomainStop(),
    3.22 +      new ParseDomainDestroy(),
    3.23 +      new ParseDomainList()
    3.24 +    };
    3.25 +  static final CommandParser commands[] =
    3.26      { help,
    3.27 -      new ParseNew(),
    3.28 -      new ParseStart(),
    3.29 -      new ParseStop(),
    3.30 -      new ParseDestroy(),
    3.31 -      new ParseList() };
    3.32 +      new ParseGroup( "domain", domaincommands )
    3.33 +    };
    3.34 +  static final CommandParser parser = new ParseGroup( null, commands );
    3.35  
    3.36    public static void main(String[] args) {
    3.37      Defaults d = new Defaults();
    3.38      int ec = -1;
    3.39 +    LinkedList arglist = new LinkedList();
    3.40 +    for ( int i=0; i<args.length; i++ )
    3.41 +      arglist.add( args[i] );
    3.42  
    3.43      if (args.length == 0) {
    3.44 -      help.parse(d, args);
    3.45 +      help.parse(d, arglist);
    3.46      } else {
    3.47 -      String c = args[0];
    3.48 -      int i;
    3.49 -      for (i = 0; i < commands.length; i++) {
    3.50 -        if (commands[i].getName().equals(c)) {
    3.51 -          if (commands[i].getFlagParameter(args, '?')) {
    3.52 -            help.doHelpFor(commands[i]);
    3.53 -          } else {
    3.54 -            try {
    3.55 -              commands[i].parse(d, args);
    3.56 -              ec = 0;
    3.57 -            } catch (ParseFailedException e) {
    3.58 -              System.err.println( e.getMessage() );
    3.59 -            } catch (CommandFailedException e) {
    3.60 -              System.err.println( e.getMessage() );
    3.61 -            }
    3.62 -          }
    3.63 -          break;
    3.64 -        }
    3.65 -      }
    3.66 -      if (i == commands.length) {
    3.67 -        System.out.println("Unknown command " + c);
    3.68 +      try
    3.69 +      {
    3.70 +        parser.parse(d, arglist);
    3.71 +        ec = 0;
    3.72 +      } catch (ParseFailedException e) {
    3.73 +        System.err.println( e.getMessage() );
    3.74 +      } catch (CommandFailedException e) {
    3.75 +        System.err.println( e.getMessage() );
    3.76        }
    3.77      }
    3.78  
     4.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDestroy.java	Thu Jul 03 13:36:35 2003 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,37 +0,0 @@
     4.4 -package org.xenoserver.cmdline;
     4.5 -
     4.6 -import org.xenoserver.control.Command;
     4.7 -import org.xenoserver.control.CommandDestroy;
     4.8 -import org.xenoserver.control.CommandFailedException;
     4.9 -import org.xenoserver.control.Defaults;
    4.10 -
    4.11 -public class ParseDestroy extends CommandParser {
    4.12 -  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
    4.13 -    int domain_id = getIntParameter(args, 'n', 0);
    4.14 -    boolean force = getFlagParameter(args, 'f');
    4.15 -
    4.16 -    if (domain_id == 0) {
    4.17 -      throw new ParseFailedException("Expected -n<domain_id>");
    4.18 -    }
    4.19 -
    4.20 -    String output = new CommandDestroy(d, domain_id, force).execute();
    4.21 -    if ( output != null )
    4.22 -      System.out.println( output );
    4.23 -  }
    4.24 -  
    4.25 -  public String getName()
    4.26 -  {
    4.27 -    return "destroy";
    4.28 -  }
    4.29 -
    4.30 -  public String getUsage()
    4.31 -  {
    4.32 -    return "[-f] [-n<domain_id>]";
    4.33 -  }
    4.34 -
    4.35 -  public String getHelpText()
    4.36 -  {
    4.37 -    return
    4.38 -      "Destory the specified domain.  -f forcibly destroys it.";
    4.39 -  }
    4.40 -}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainDestroy.java	Thu Jul 03 15:01:39 2003 +0000
     5.3 @@ -0,0 +1,40 @@
     5.4 +package org.xenoserver.cmdline;
     5.5 +
     5.6 +import java.util.LinkedList;
     5.7 +import java.util.List;
     5.8 +
     5.9 +import org.xenoserver.control.Command;
    5.10 +import org.xenoserver.control.CommandDomainDestroy;
    5.11 +import org.xenoserver.control.CommandFailedException;
    5.12 +import org.xenoserver.control.Defaults;
    5.13 +
    5.14 +public class ParseDomainDestroy extends CommandParser {
    5.15 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    5.16 +    int domain_id = getIntParameter(args, 'n', 0);
    5.17 +    boolean force = getFlagParameter(args, 'f');
    5.18 +
    5.19 +    if (domain_id == 0) {
    5.20 +      throw new ParseFailedException("Expected -n<domain_id>");
    5.21 +    }
    5.22 +
    5.23 +    String output = new CommandDomainDestroy(d, domain_id, force).execute();
    5.24 +    if ( output != null )
    5.25 +      System.out.println( output );
    5.26 +  }
    5.27 +  
    5.28 +  public String getName()
    5.29 +  {
    5.30 +    return "destroy";
    5.31 +  }
    5.32 +
    5.33 +  public String getUsage()
    5.34 +  {
    5.35 +    return "[-f] [-n<domain_id>]";
    5.36 +  }
    5.37 +
    5.38 +  public String getHelpText()
    5.39 +  {
    5.40 +    return
    5.41 +      "Destory the specified domain.  -f forcibly destroys it.";
    5.42 +  }
    5.43 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainList.java	Thu Jul 03 15:01:39 2003 +0000
     6.3 @@ -0,0 +1,49 @@
     6.4 +package org.xenoserver.cmdline;
     6.5 +
     6.6 +import java.util.LinkedList;
     6.7 +import java.util.List;
     6.8 +
     6.9 +import org.xenoserver.control.Command;
    6.10 +import org.xenoserver.control.CommandFailedException;
    6.11 +import org.xenoserver.control.CommandDomainList;
    6.12 +import org.xenoserver.control.Defaults;
    6.13 +import org.xenoserver.control.Domain;
    6.14 +
    6.15 +public class ParseDomainList extends CommandParser {
    6.16 +
    6.17 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    6.18 +    CommandDomainList list = new CommandDomainList(d);
    6.19 +    String output = list.execute();
    6.20 +    if ( output != null )
    6.21 +      System.out.println( output );
    6.22 +    Domain[] domains = list.domains();
    6.23 +
    6.24 +    for (int loop = 0; loop < domains.length; loop++)
    6.25 +    {
    6.26 +      System.out.println ("id: " + domains[loop].id + 
    6.27 +        " (" + domains[loop].name+ ")");
    6.28 +      System.out.println ("  processor: " + domains[loop].processor);
    6.29 +      System.out.println ("  has cpu: " + domains[loop].cpu);
    6.30 +      System.out.println ("  state: " + domains[loop].nstate + " " +
    6.31 +        domains[loop].state);
    6.32 +      System.out.println ("  mcu advance: " + domains[loop].mcu);
    6.33 +      System.out.println ("  total pages: " + domains[loop].pages);
    6.34 +    }
    6.35 +  }
    6.36 +
    6.37 +  public String getName()
    6.38 +  {
    6.39 +    return "list";
    6.40 +  }
    6.41 +
    6.42 +  public String getUsage()
    6.43 +  {
    6.44 +    return "";
    6.45 +  }
    6.46 +
    6.47 +  public String getHelpText()
    6.48 +  {
    6.49 +    return
    6.50 +      "List domain information";
    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/ParseDomainNew.java	Thu Jul 03 15:01:39 2003 +0000
     7.3 @@ -0,0 +1,84 @@
     7.4 +package org.xenoserver.cmdline;
     7.5 +
     7.6 +import java.util.LinkedList;
     7.7 +import java.util.List;
     7.8 +
     7.9 +import org.xenoserver.control.Command;
    7.10 +import org.xenoserver.control.CommandFailedException;
    7.11 +import org.xenoserver.control.CommandDomainNew;
    7.12 +import org.xenoserver.control.Defaults;
    7.13 +
    7.14 +public class ParseDomainNew extends CommandParser {
    7.15 +
    7.16 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    7.17 +    String name = getStringParameter(args, 'n', d.domainName);
    7.18 +    int size = getIntParameter(args, 'k', d.domainSizeKB);
    7.19 +    String image = getStringParameter(args, 'i', d.domainImage);
    7.20 +    String initrd = getStringParameter (args, 'r', d.domainInitRD);
    7.21 +    int vifs = getIntParameter(args, 'v', d.domainVIFs);
    7.22 +    String bargs = getStringParameter (args, 'a', d.args) + " ";
    7.23 +    String root_dev = getStringParameter (args, 'd', d.rootDevice);
    7.24 +    String nfs_root_path = getStringParameter (args, 'f', d.NWNFSRoot);
    7.25 +    String nw_ip = getStringParameter (args, '4', d.NWIP);
    7.26 +    String nw_gw = getStringParameter (args, 'g', d.NWGW);
    7.27 +    String nw_mask = getStringParameter (args, 'm', d.NWMask);
    7.28 +    String nw_nfs_server = getStringParameter (args, 's', d.NWNFSServer);
    7.29 +    String nw_host = getStringParameter (args, 'h', d.NWHost);
    7.30 +
    7.31 +    d.describe();
    7.32 +
    7.33 +    CommandDomainNew c = new CommandDomainNew(d, name, size, image, initrd, vifs,
    7.34 +                                  bargs, root_dev, nfs_root_path,
    7.35 +                                  nw_ip, nw_gw, nw_mask, nw_nfs_server, nw_host);
    7.36 +    c.execute();
    7.37 +    String[] output = c.output();
    7.38 +    for ( int i = 0; i < output.length; i++ )
    7.39 +      System.out.println( output[i] ); 
    7.40 +  }
    7.41 +
    7.42 +  public String getName()
    7.43 +  {
    7.44 +    return "new";
    7.45 +  }
    7.46 +
    7.47 +  public String getUsage()
    7.48 +  {
    7.49 +    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>]";
    7.50 +  }
    7.51 +
    7.52 +  public String getHelpText()
    7.53 +  {
    7.54 +    return
    7.55 +      "Create a new domain.  Note that most of the parameters will assume\n" +
    7.56 +      "default values: it should not be necessary to specify them all. See\n" +
    7.57 +      "domctl.xml for the current default settings.\n" +
    7.58 +      "\n" +
    7.59 +      "General command line options:\n" +
    7.60 +      "  -n  Domain name                              domain_name\n" +
    7.61 +      "  -k  Domain size (kb)                         domain_size_kb\n" +
    7.62 +      "  -i  Domain image name                        domain_image\n" +
    7.63 +      "  -v  Number of VIFs                           domain_vifs\n" +
    7.64 +      "  -r  InitRD (if required)                     domain_init_rd\n" +
    7.65 +      "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n" +
    7.66 +      "  -a  Additional boot parameters\n" +
    7.67 +      "\n" +
    7.68 +      "Networking options:\n" +
    7.69 +      "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n" +
    7.70 +      "  -s  NFS server                               nw_nfs_server\n" +
    7.71 +      "  -4  Domain IPv4 address                      nw_ip\n" +
    7.72 +      "  -g  Domain gateway                           nw_gw\n" +
    7.73 +      "  -m  Domain net mask                          nw_mask\n" +
    7.74 +      "  -h  Domain hostname                          nw_host\n" +
    7.75 +      "\n" +
    7.76 +      "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" +
    7.77 +      "which the allocated domain ID will be incorporated.  e.g.  for\n" +
    7.78 +      "domain 1 patterns would expand as follows:\n" +
    7.79 +      "\n" +
    7.80 +      "  /dev/hda+       /dev/hda1\n" +
    7.81 +      "  /dev/hda7+      /dev/hda8\n" +
    7.82 +      "  128.232.8.50+   128.232.8.51\n" +
    7.83 +      "\n" +
    7.84 +      "Additionally, patterns for -4 -g -m can include an = which is\n" + 
    7.85 +      "expanded to the corresponding setting from the calling domain.\n";
    7.86 +  }
    7.87 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainStart.java	Thu Jul 03 15:01:39 2003 +0000
     8.3 @@ -0,0 +1,40 @@
     8.4 +package org.xenoserver.cmdline;
     8.5 +
     8.6 +import java.util.LinkedList;
     8.7 +import java.util.List;
     8.8 +
     8.9 +import org.xenoserver.control.Command;
    8.10 +import org.xenoserver.control.CommandFailedException;
    8.11 +import org.xenoserver.control.CommandDomainStart;
    8.12 +import org.xenoserver.control.Defaults;
    8.13 +
    8.14 +public class ParseDomainStart extends CommandParser {
    8.15 +
    8.16 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    8.17 +    int domain_id = getIntParameter(args, 'n', 0);
    8.18 +    
    8.19 +    if (domain_id == 0) {
    8.20 +      throw new ParseFailedException("Expected -n<domain_id>");
    8.21 +    }
    8.22 +
    8.23 +    String output = new CommandDomainStart(d, domain_id).execute();
    8.24 +    if ( output != null )
    8.25 +      System.out.println( output );
    8.26 +  }
    8.27 +
    8.28 +  public String getName()
    8.29 +  {
    8.30 +    return "start";
    8.31 +  }
    8.32 +
    8.33 +  public String getUsage()
    8.34 +  {
    8.35 +    return "[-n<domain_id>]";
    8.36 +  }
    8.37 +
    8.38 +  public String getHelpText()
    8.39 +  {
    8.40 +    return
    8.41 +      "Start the specified domain.";
    8.42 +  }
    8.43 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainStop.java	Thu Jul 03 15:01:39 2003 +0000
     9.3 @@ -0,0 +1,40 @@
     9.4 +package org.xenoserver.cmdline;
     9.5 +
     9.6 +import java.util.LinkedList;
     9.7 +import java.util.List;
     9.8 +
     9.9 +import org.xenoserver.control.Command;
    9.10 +import org.xenoserver.control.CommandFailedException;
    9.11 +import org.xenoserver.control.CommandDomainStop;
    9.12 +import org.xenoserver.control.Defaults;
    9.13 +
    9.14 +public class ParseDomainStop extends CommandParser {
    9.15 +
    9.16 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    9.17 +    int domain_id = getIntParameter(args, 'n', 0);
    9.18 +    
    9.19 +    if (domain_id == 0) {
    9.20 +      throw new ParseFailedException("Expected -n<domain_id>");
    9.21 +    }
    9.22 +
    9.23 +    String output = new CommandDomainStop(d, domain_id).execute();
    9.24 +    if ( output != null )
    9.25 +      System.out.println( output );
    9.26 +  }
    9.27 +
    9.28 +  public String getName()
    9.29 +  {
    9.30 +    return "stop";
    9.31 +  }
    9.32 +
    9.33 +  public String getUsage()
    9.34 +  {
    9.35 +    return "[-n<domain_id>]";
    9.36 +  }
    9.37 +
    9.38 +  public String getHelpText()
    9.39 +  {
    9.40 +    return
    9.41 +      "Stop the specified domain.";
    9.42 +  }
    9.43 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseGroup.java	Thu Jul 03 15:01:39 2003 +0000
    10.3 @@ -0,0 +1,77 @@
    10.4 +package org.xenoserver.cmdline;
    10.5 +
    10.6 +import java.util.Arrays;
    10.7 +import java.util.LinkedList;
    10.8 +import java.util.List;
    10.9 +
   10.10 +import org.xenoserver.control.CommandFailedException;
   10.11 +import org.xenoserver.control.Defaults;
   10.12 +
   10.13 +public class ParseGroup extends CommandParser {
   10.14 +  private final String name;
   10.15 +  private final CommandParser[] commands;
   10.16 +  
   10.17 +  /**
   10.18 +   * Constructor for ParseGroup.
   10.19 +   * @param name Name of this group of commands
   10.20 +   * @param commands Array of commands to include
   10.21 +   */
   10.22 +  public ParseGroup(String name, CommandParser[] commands) {
   10.23 +    this.name = name;
   10.24 +    this.commands = commands;
   10.25 +  }
   10.26 +
   10.27 +  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
   10.28 +    int i;
   10.29 +    String c = (String) args.removeFirst();
   10.30 +    for (i = 0; i < commands.length; i++) {
   10.31 +      if (commands[i].getName().equals(c)) {
   10.32 +        if (getFlagParameter(args, '?')) {
   10.33 +          commands[i].printHelpText(null);
   10.34 +        } else {
   10.35 +          commands[i].parse(d, args);
   10.36 +        }
   10.37 +        break;
   10.38 +      }
   10.39 +    }
   10.40 +    if (i == commands.length) {
   10.41 +      throw new ParseFailedException("Unknown command " + c);
   10.42 +    }
   10.43 +  }
   10.44 +
   10.45 +  public String getName() {
   10.46 +    return name;
   10.47 +  }
   10.48 +
   10.49 +  public String getUsage() {
   10.50 +    // TODO Auto-generated method stub
   10.51 +    return null;
   10.52 +  }
   10.53 +
   10.54 +  public String getHelpText() {
   10.55 +    // TODO Auto-generated method stub
   10.56 +    return null;
   10.57 +  }
   10.58 +
   10.59 +  public void printUsage(String prefix) {
   10.60 +    if ( prefix == null )
   10.61 +      prefix = name;
   10.62 +    else
   10.63 +      prefix += " " + name;
   10.64 +    for ( int i=0; i<commands.length; i++ )
   10.65 +      commands[i].printUsage(prefix);
   10.66 +  }
   10.67 +
   10.68 +  public void printHelpText(LinkedList args) {
   10.69 +    if ( name != null )
   10.70 +      System.out.print( name + " " );
   10.71 +    int i;
   10.72 +    String c = (String) args.removeFirst();
   10.73 +    for (i = 0; i < commands.length; i++) {
   10.74 +      if (commands[i].getName().equals(c)) {
   10.75 +        commands[i].printHelpText(args);
   10.76 +        break;
   10.77 +      }
   10.78 +    }
   10.79 +  }
   10.80 +}
    11.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseHelp.java	Thu Jul 03 13:36:35 2003 +0000
    11.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseHelp.java	Thu Jul 03 15:01:39 2003 +0000
    11.3 @@ -1,41 +1,25 @@
    11.4  package org.xenoserver.cmdline;
    11.5  
    11.6 +import java.util.LinkedList;
    11.7 +import java.util.List;
    11.8 +
    11.9  import org.xenoserver.control.Command;
   11.10  import org.xenoserver.control.Defaults;
   11.11  
   11.12  public class ParseHelp extends CommandParser {
   11.13  
   11.14 -  public void parse(Defaults d, String[] args) {
   11.15 -    if (args.length <= 1) {
   11.16 +  public void parse(Defaults d, LinkedList args) {
   11.17 +    if (args.size() == 0) {
   11.18        System.out.println("Usage:");
   11.19 -      for (int i = 0; i < Main.commands.length; i++) {
   11.20 -        String name = Main.commands[i].getName();
   11.21 -        String usage = Main.commands[i].getUsage();
   11.22 -        while (name.length() < 12)
   11.23 -          name = name + " ";
   11.24 -        System.out.println("   " + name + usage);
   11.25 -      }
   11.26 +      Main.parser.printUsage(null);
   11.27      } else {
   11.28 -      for (int i = 0; i < Main.commands.length; i++) {
   11.29 -        String name = Main.commands[i].getName();
   11.30 -        String usage = Main.commands[i].getUsage();
   11.31 -        if (name.equals(args[1])) {
   11.32 -          doHelpFor(Main.commands[i]);
   11.33 -          break;
   11.34 -        }
   11.35 -      }
   11.36 +      System.out.print("xenctl ");
   11.37 +      Main.parser.printHelpText(args);
   11.38      }
   11.39  
   11.40      System.out.println("");
   11.41    }
   11.42    
   11.43 -  public void doHelpFor(CommandParser c)
   11.44 -  {
   11.45 -    System.out.println ("xenctl " + c.getName() + " " + c.getUsage());
   11.46 -    System.out.println ();
   11.47 -    System.out.println (c.getHelpText ());
   11.48 -  }
   11.49 -
   11.50    public String getName()
   11.51    {
   11.52      return "help";
    12.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseList.java	Thu Jul 03 13:36:35 2003 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,46 +0,0 @@
    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.CommandList;
    12.9 -import org.xenoserver.control.Defaults;
   12.10 -import org.xenoserver.control.Domain;
   12.11 -
   12.12 -public class ParseList extends CommandParser {
   12.13 -
   12.14 -  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
   12.15 -    CommandList list = new CommandList(d);
   12.16 -    String output = list.execute();
   12.17 -    if ( output != null )
   12.18 -      System.out.println( output );
   12.19 -    Domain[] domains = list.domains();
   12.20 -
   12.21 -    for (int loop = 0; loop < domains.length; loop++)
   12.22 -    {
   12.23 -      System.out.println ("id: " + domains[loop].id + 
   12.24 -        " (" + domains[loop].name+ ")");
   12.25 -      System.out.println ("  processor: " + domains[loop].processor);
   12.26 -      System.out.println ("  has cpu: " + domains[loop].cpu);
   12.27 -      System.out.println ("  state: " + domains[loop].nstate + " " +
   12.28 -        domains[loop].state);
   12.29 -      System.out.println ("  mcu advance: " + domains[loop].mcu);
   12.30 -      System.out.println ("  total pages: " + domains[loop].pages);
   12.31 -    }
   12.32 -  }
   12.33 -
   12.34 -  public String getName()
   12.35 -  {
   12.36 -    return "list";
   12.37 -  }
   12.38 -
   12.39 -  public String getUsage()
   12.40 -  {
   12.41 -    return "";
   12.42 -  }
   12.43 -
   12.44 -  public String getHelpText()
   12.45 -  {
   12.46 -    return
   12.47 -      "List domain information";
   12.48 -  }
   12.49 -}
    13.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseNew.java	Thu Jul 03 13:36:35 2003 +0000
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,81 +0,0 @@
    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.CommandNew;
    13.9 -import org.xenoserver.control.Defaults;
   13.10 -
   13.11 -public class ParseNew extends CommandParser {
   13.12 -
   13.13 -  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
   13.14 -    String name = getStringParameter(args, 'n', d.domainName);
   13.15 -    int size = getIntParameter(args, 'k', d.domainSizeKB);
   13.16 -    String image = getStringParameter(args, 'i', d.domainImage);
   13.17 -    String initrd = getStringParameter (args, 'r', d.domainInitRD);
   13.18 -    int vifs = getIntParameter(args, 'v', d.domainVIFs);
   13.19 -    String bargs = getStringParameter (args, 'a', d.args) + " ";
   13.20 -    String root_dev = getStringParameter (args, 'd', d.rootDevice);
   13.21 -    String nfs_root_path = getStringParameter (args, 'f', d.NWNFSRoot);
   13.22 -    String nw_ip = getStringParameter (args, '4', d.NWIP);
   13.23 -    String nw_gw = getStringParameter (args, 'g', d.NWGW);
   13.24 -    String nw_mask = getStringParameter (args, 'm', d.NWMask);
   13.25 -    String nw_nfs_server = getStringParameter (args, 's', d.NWNFSServer);
   13.26 -    String nw_host = getStringParameter (args, 'h', d.NWHost);
   13.27 -
   13.28 -    d.describe();
   13.29 -
   13.30 -    CommandNew c = new CommandNew(d, name, size, image, initrd, vifs,
   13.31 -                                  bargs, root_dev, nfs_root_path,
   13.32 -                                  nw_ip, nw_gw, nw_mask, nw_nfs_server, nw_host);
   13.33 -    c.execute();
   13.34 -    String[] output = c.output();
   13.35 -    for ( int i = 0; i < output.length; i++ )
   13.36 -      System.out.println( output[i] ); 
   13.37 -  }
   13.38 -
   13.39 -  public String getName()
   13.40 -  {
   13.41 -    return "new";
   13.42 -  }
   13.43 -
   13.44 -  public String getUsage()
   13.45 -  {
   13.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>]";
   13.47 -  }
   13.48 -
   13.49 -  public String getHelpText()
   13.50 -  {
   13.51 -    return
   13.52 -      "Create a new domain.  Note that most of the parameters will assume\n" +
   13.53 -      "default values: it should not be necessary to specify them all. See\n" +
   13.54 -      "domctl.xml for the current default settings.\n" +
   13.55 -      "\n" +
   13.56 -      "General command line options:\n" +
   13.57 -      "  -n  Domain name                              domain_name\n" +
   13.58 -      "  -k  Domain size (kb)                         domain_size_kb\n" +
   13.59 -      "  -i  Domain image name                        domain_image\n" +
   13.60 -      "  -v  Number of VIFs                           domain_vifs\n" +
   13.61 -      "  -r  InitRD (if required)                     domain_init_rd\n" +
   13.62 -      "  -d  Root device (e.g /dev/nfs, /dev/hda3)    root_device\n" +
   13.63 -      "  -a  Additional boot parameters\n" +
   13.64 -      "\n" +
   13.65 -      "Networking options:\n" +
   13.66 -      "  -f  NFS root (if /dev/nfs specified)         nw_nfs_root\n" +
   13.67 -      "  -s  NFS server                               nw_nfs_server\n" +
   13.68 -      "  -4  Domain IPv4 address                      nw_ip\n" +
   13.69 -      "  -g  Domain gateway                           nw_gw\n" +
   13.70 -      "  -m  Domain net mask                          nw_mask\n" +
   13.71 -      "  -h  Domain hostname                          nw_host\n" +
   13.72 -      "\n" +
   13.73 -      "Parameters to -d, -f, -4, -g, -h can be specified as patterns into\n" +
   13.74 -      "which the allocated domain ID will be incorporated.  e.g.  for\n" +
   13.75 -      "domain 1 patterns would expand as follows:\n" +
   13.76 -      "\n" +
   13.77 -      "  /dev/hda+       /dev/hda1\n" +
   13.78 -      "  /dev/hda7+      /dev/hda8\n" +
   13.79 -      "  128.232.8.50+   128.232.8.51\n" +
   13.80 -      "\n" +
   13.81 -      "Additionally, patterns for -4 -g -m can include an = which is\n" + 
   13.82 -      "expanded to the corresponding setting from the calling domain.\n";
   13.83 -  }
   13.84 -}
    14.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseStart.java	Thu Jul 03 13:36:35 2003 +0000
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,37 +0,0 @@
    14.4 -package org.xenoserver.cmdline;
    14.5 -
    14.6 -import org.xenoserver.control.Command;
    14.7 -import org.xenoserver.control.CommandFailedException;
    14.8 -import org.xenoserver.control.CommandStart;
    14.9 -import org.xenoserver.control.Defaults;
   14.10 -
   14.11 -public class ParseStart extends CommandParser {
   14.12 -
   14.13 -  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
   14.14 -    int domain_id = getIntParameter(args, 'n', 0);
   14.15 -    
   14.16 -    if (domain_id == 0) {
   14.17 -      throw new ParseFailedException("Expected -n<domain_id>");
   14.18 -    }
   14.19 -
   14.20 -    String output = new CommandStart(d, domain_id).execute();
   14.21 -    if ( output != null )
   14.22 -      System.out.println( output );
   14.23 -  }
   14.24 -
   14.25 -  public String getName()
   14.26 -  {
   14.27 -    return "start";
   14.28 -  }
   14.29 -
   14.30 -  public String getUsage()
   14.31 -  {
   14.32 -    return "[-n<domain_id>]";
   14.33 -  }
   14.34 -
   14.35 -  public String getHelpText()
   14.36 -  {
   14.37 -    return
   14.38 -      "Start the specified domain.";
   14.39 -  }
   14.40 -}
    15.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseStop.java	Thu Jul 03 13:36:35 2003 +0000
    15.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.3 @@ -1,37 +0,0 @@
    15.4 -package org.xenoserver.cmdline;
    15.5 -
    15.6 -import org.xenoserver.control.Command;
    15.7 -import org.xenoserver.control.CommandFailedException;
    15.8 -import org.xenoserver.control.CommandStop;
    15.9 -import org.xenoserver.control.Defaults;
   15.10 -
   15.11 -public class ParseStop extends CommandParser {
   15.12 -
   15.13 -  public void parse(Defaults d, String[] args) throws ParseFailedException, CommandFailedException {
   15.14 -    int domain_id = getIntParameter(args, 'n', 0);
   15.15 -    
   15.16 -    if (domain_id == 0) {
   15.17 -      throw new ParseFailedException("Expected -n<domain_id>");
   15.18 -    }
   15.19 -
   15.20 -    String output = new CommandStop(d, domain_id).execute();
   15.21 -    if ( output != null )
   15.22 -      System.out.println( output );
   15.23 -  }
   15.24 -
   15.25 -  public String getName()
   15.26 -  {
   15.27 -    return "stop";
   15.28 -  }
   15.29 -
   15.30 -  public String getUsage()
   15.31 -  {
   15.32 -    return "[-n<domain_id>]";
   15.33 -  }
   15.34 -
   15.35 -  public String getHelpText()
   15.36 -  {
   15.37 -    return
   15.38 -      "Stop the specified domain.";
   15.39 -  }
   15.40 -}
    16.1 --- a/tools/control/src/org/xenoserver/control/CommandDestroy.java	Thu Jul 03 13:36:35 2003 +0000
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,58 +0,0 @@
    16.4 -package org.xenoserver.control;
    16.5 -
    16.6 -/**
    16.7 - * Destroys a domain.
    16.8 - */
    16.9 -public class CommandDestroy extends Command {
   16.10 -  private Defaults d;
   16.11 -  private int domain_id;
   16.12 -  private boolean force;
   16.13 -
   16.14 -  /**
   16.15 -   * Constructor for CommandDestroy.
   16.16 -   * 
   16.17 -   * @param d Defaults object to use.
   16.18 -   * @param domain_id Domain ID number to destroy.
   16.19 -   * @param force Force destruction.
   16.20 -   */
   16.21 -  public CommandDestroy(Defaults d, int domain_id, boolean force) {
   16.22 -    this.d = d;
   16.23 -    this.domain_id = domain_id;
   16.24 -    this.force = force;
   16.25 -  }
   16.26 -
   16.27 -  public String execute() throws CommandFailedException {
   16.28 -    Runtime r = Runtime.getRuntime();
   16.29 -    String output = null;
   16.30 -
   16.31 -    try {
   16.32 -      Process destroy_p;
   16.33 -      String destroy_cmdarray[] = force ? new String[3] : new String[2];
   16.34 -      int destroy_rc;
   16.35 -      int idx = 0;
   16.36 -      destroy_cmdarray[idx++] = d.XIToolsDir + "xi_destroy";
   16.37 -      if (force) {
   16.38 -        destroy_cmdarray[idx++] = "-f";
   16.39 -      }
   16.40 -      destroy_cmdarray[idx++] = "" + domain_id;
   16.41 -
   16.42 -      if (Settings.TEST) {
   16.43 -        output = reportCommand(destroy_cmdarray);
   16.44 -      } else {
   16.45 -        destroy_p = r.exec(destroy_cmdarray);
   16.46 -        destroy_rc = destroy_p.waitFor();
   16.47 -
   16.48 -        if (destroy_rc != 0) {
   16.49 -          throw CommandFailedException.XICommandFailed("Could not destroy domain", destroy_cmdarray);
   16.50 -        }
   16.51 -        output = "Destroyed domain " + domain_id;
   16.52 -      }
   16.53 -    } catch (CommandFailedException e) {
   16.54 -      throw e;
   16.55 -    } catch (Exception e) {
   16.56 -      throw new CommandFailedException("Could not destroy domain (" + e + ")", e);
   16.57 -    }
   16.58 -
   16.59 -    return output;
   16.60 -  }
   16.61 -}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainDestroy.java	Thu Jul 03 15:01:39 2003 +0000
    17.3 @@ -0,0 +1,58 @@
    17.4 +package org.xenoserver.control;
    17.5 +
    17.6 +/**
    17.7 + * Destroys a domain.
    17.8 + */
    17.9 +public class CommandDomainDestroy extends Command {
   17.10 +  private Defaults d;
   17.11 +  private int domain_id;
   17.12 +  private boolean force;
   17.13 +
   17.14 +  /**
   17.15 +   * Constructor for CommandDomainDestroy.
   17.16 +   * 
   17.17 +   * @param d Defaults object to use.
   17.18 +   * @param domain_id Domain ID number to destroy.
   17.19 +   * @param force Force destruction.
   17.20 +   */
   17.21 +  public CommandDomainDestroy(Defaults d, int domain_id, boolean force) {
   17.22 +    this.d = d;
   17.23 +    this.domain_id = domain_id;
   17.24 +    this.force = force;
   17.25 +  }
   17.26 +
   17.27 +  public String execute() throws CommandFailedException {
   17.28 +    Runtime r = Runtime.getRuntime();
   17.29 +    String output = null;
   17.30 +
   17.31 +    try {
   17.32 +      Process destroy_p;
   17.33 +      String destroy_cmdarray[] = force ? new String[3] : new String[2];
   17.34 +      int destroy_rc;
   17.35 +      int idx = 0;
   17.36 +      destroy_cmdarray[idx++] = d.XIToolsDir + "xi_destroy";
   17.37 +      if (force) {
   17.38 +        destroy_cmdarray[idx++] = "-f";
   17.39 +      }
   17.40 +      destroy_cmdarray[idx++] = "" + domain_id;
   17.41 +
   17.42 +      if (Settings.TEST) {
   17.43 +        output = reportCommand(destroy_cmdarray);
   17.44 +      } else {
   17.45 +        destroy_p = r.exec(destroy_cmdarray);
   17.46 +        destroy_rc = destroy_p.waitFor();
   17.47 +
   17.48 +        if (destroy_rc != 0) {
   17.49 +          throw CommandFailedException.XICommandFailed("Could not destroy domain", destroy_cmdarray);
   17.50 +        }
   17.51 +        output = "Destroyed domain " + domain_id;
   17.52 +      }
   17.53 +    } catch (CommandFailedException e) {
   17.54 +      throw e;
   17.55 +    } catch (Exception e) {
   17.56 +      throw new CommandFailedException("Could not destroy domain (" + e + ")", e);
   17.57 +    }
   17.58 +
   17.59 +    return output;
   17.60 +  }
   17.61 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainList.java	Thu Jul 03 15:01:39 2003 +0000
    18.3 @@ -0,0 +1,108 @@
    18.4 +package org.xenoserver.control;
    18.5 +
    18.6 +import java.io.BufferedReader;
    18.7 +import java.io.InputStreamReader;
    18.8 +import java.util.StringTokenizer;
    18.9 +import java.util.Vector;
   18.10 +
   18.11 +/**
   18.12 + * Lists details of all domains. After execute() has been called, call
   18.13 + * domains() to get the array of domains.
   18.14 + */
   18.15 +public class CommandDomainList extends Command {
   18.16 +  private Defaults d;
   18.17 +  private Domain[] array;
   18.18 +
   18.19 +  /**
   18.20 +   * Constructor for CommandDomainList.
   18.21 +   * @param d Defaults object to use.
   18.22 +   */
   18.23 +  public CommandDomainList(Defaults d) {
   18.24 +    this.d = d;
   18.25 +  }
   18.26 +
   18.27 +  /**
   18.28 +   * Retrieves the list of domains.
   18.29 +   * @return null, call domains() to get the list.
   18.30 +   */
   18.31 +  public String execute() throws CommandFailedException {
   18.32 +    Runtime r = Runtime.getRuntime();
   18.33 +    int rc = 0;
   18.34 +    Vector v = new Vector();
   18.35 +    String outline;
   18.36 +    BufferedReader in;
   18.37 +    String output = null;
   18.38 +
   18.39 +    try {
   18.40 +      Process start_p;
   18.41 +      String start_cmdarray[] = new String[1];
   18.42 +      int start_rc;
   18.43 +      start_cmdarray[0] = d.XIToolsDir + "xi_list";
   18.44 +
   18.45 +      if (Settings.TEST) {
   18.46 +        output = reportCommand(start_cmdarray);
   18.47 +      } else {
   18.48 +        start_p = r.exec(start_cmdarray);
   18.49 +        start_rc = start_p.waitFor();
   18.50 +        if (start_rc != 0) {
   18.51 +          throw CommandFailedException.XICommandFailed("Could not get domain list", start_cmdarray);
   18.52 +        }
   18.53 +
   18.54 +        in =
   18.55 +          new BufferedReader(new InputStreamReader(start_p.getInputStream()));
   18.56 +
   18.57 +        outline = in.readLine();
   18.58 +        while (outline != null) {
   18.59 +          Domain domain = new Domain();
   18.60 +
   18.61 +          StringTokenizer st = new StringTokenizer(outline);
   18.62 +          if (st.hasMoreTokens()) {
   18.63 +            domain.id = Integer.parseInt(st.nextToken());
   18.64 +          }
   18.65 +          if (st.hasMoreTokens()) {
   18.66 +            domain.processor = Integer.parseInt(st.nextToken());
   18.67 +          }
   18.68 +          if (st.hasMoreTokens()) {
   18.69 +            if (st.nextToken().equals("1")) {
   18.70 +              domain.cpu = true;
   18.71 +            } else {
   18.72 +              domain.cpu = false;
   18.73 +            }
   18.74 +          }
   18.75 +          if (st.hasMoreTokens()) {
   18.76 +            domain.nstate = Integer.parseInt(st.nextToken());
   18.77 +          }
   18.78 +          if (st.hasMoreTokens()) {
   18.79 +            domain.state = st.nextToken().toLowerCase();
   18.80 +          }
   18.81 +          if (st.hasMoreTokens()) {
   18.82 +            domain.mcu = Integer.parseInt(st.nextToken());
   18.83 +          }
   18.84 +          if (st.hasMoreTokens()) {
   18.85 +            domain.pages = Integer.parseInt(st.nextToken());
   18.86 +          }
   18.87 +          if (st.hasMoreTokens()) {
   18.88 +            domain.name = st.nextToken();
   18.89 +          }
   18.90 +
   18.91 +          v.add(domain);
   18.92 +
   18.93 +          outline = in.readLine();
   18.94 +        }
   18.95 +
   18.96 +      }
   18.97 +    } catch (CommandFailedException e) {
   18.98 +      throw e;
   18.99 +    } catch (Exception e) {
  18.100 +      throw new CommandFailedException("Could not get domain list(" + e + ")", e);
  18.101 +    }
  18.102 +
  18.103 +    array = new Domain[v.size()];
  18.104 +    v.toArray(array);
  18.105 +    return output;
  18.106 +  }
  18.107 +  
  18.108 +  public Domain[] domains() {
  18.109 +    return array;
  18.110 +  }
  18.111 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainNew.java	Thu Jul 03 15:01:39 2003 +0000
    19.3 @@ -0,0 +1,301 @@
    19.4 +package org.xenoserver.control;
    19.5 +
    19.6 +import java.io.BufferedReader;
    19.7 +import java.io.File;
    19.8 +import java.io.FileInputStream;
    19.9 +import java.io.FileOutputStream;
   19.10 +import java.io.IOException;
   19.11 +import java.io.InputStreamReader;
   19.12 +import java.net.InetAddress;
   19.13 +import java.net.UnknownHostException;
   19.14 +import java.util.zip.GZIPInputStream;
   19.15 +
   19.16 +/**
   19.17 + * Creates a new domain. As this command returns a multi-line result,
   19.18 + * call output() to get an array of strings.
   19.19 + */
   19.20 +public class CommandDomainNew extends Command {
   19.21 +  private Defaults d;
   19.22 +  private String name;
   19.23 +  private int size;
   19.24 +  private String image;
   19.25 +  private String initrd;
   19.26 +  private int vifs;
   19.27 +  private String bargs;
   19.28 +  private String root_dev;
   19.29 +  private String nfs_root_path;
   19.30 +  private String nw_ip;
   19.31 +  private String nw_gw;
   19.32 +  private String nw_mask;
   19.33 +  private String nw_nfs_server;
   19.34 +  private String nw_host;
   19.35 +  private String[] output;
   19.36 +  
   19.37 +  public String[] output() {
   19.38 +    return output;
   19.39 +  }
   19.40 +  
   19.41 +  /**
   19.42 +   * Constructor for CommandDomainNew.
   19.43 +   * @param d Defaults object to use.
   19.44 +   * @param name Name for the domain.
   19.45 +   * @param size Memory size for the domain.
   19.46 +   * @param image Image to boot domain from.
   19.47 +   * @param initrd Initrd to boot domain with.
   19.48 +   * @param vifs Number of virtual interfaces for the domain.
   19.49 +   * @param bargs Boot arguments for the domain.
   19.50 +   * @param root_dev Root device for the domain.
   19.51 +   * @param nfs_root_path NFS root to be used by the domain.
   19.52 +   * @param nw_ip IP address pattern to use for the domain's interfaces.
   19.53 +   * @param nw_gw Gateway to configure the domain for.
   19.54 +   * @param nw_mask Network mask to configure the domain for.
   19.55 +   * @param nw_nfs_server NFS server to be used by the domain.
   19.56 +   * @param nw_host Hostname to be used by the domain.
   19.57 +   */
   19.58 +  public CommandDomainNew(
   19.59 +    Defaults d,
   19.60 +    String name,
   19.61 +    int size,
   19.62 +    String image,
   19.63 +    String initrd,
   19.64 +    int vifs,
   19.65 +    String bargs,
   19.66 +    String root_dev,
   19.67 +    String nfs_root_path,
   19.68 +    String nw_ip,
   19.69 +    String nw_gw,
   19.70 +    String nw_mask,
   19.71 +    String nw_nfs_server,
   19.72 +    String nw_host) {
   19.73 +    this.d = d;
   19.74 +    this.name = name;
   19.75 +    this.size = size;
   19.76 +    this.image = image;
   19.77 +    this.initrd = initrd;
   19.78 +    this.vifs = vifs;
   19.79 +    this.bargs = bargs;
   19.80 +    this.root_dev = root_dev;
   19.81 +    this.nfs_root_path = nfs_root_path;
   19.82 +    this.nw_ip = nw_ip;
   19.83 +    this.nw_gw = nw_gw;
   19.84 +    this.nw_mask = nw_mask;
   19.85 +    this.nw_nfs_server = nw_nfs_server;
   19.86 +    this.nw_host = nw_host;
   19.87 +  }
   19.88 +
   19.89 +  public String execute() throws CommandFailedException {
   19.90 +    Runtime r = Runtime.getRuntime();
   19.91 +    int domain_id = -1;
   19.92 +    BufferedReader br;
   19.93 +    int idx;
   19.94 +    int i;
   19.95 +    File image_tmp = null;
   19.96 +    File initrd_tmp = null;
   19.97 +    String domain_ip = "";
   19.98 +    
   19.99 +    String create_cmdarray[] = new String[3];
  19.100 +    String build_cmdarray[] = new String[6];
  19.101 +    String vifinit_cmdarray[] = new String[4];
  19.102 +
  19.103 +    try {
  19.104 +      try {
  19.105 +        /* Some initial sanity checks */
  19.106 +        if (root_dev.equals("/dev/nfs") && (vifs == 0)) {
  19.107 +          throw new CommandFailedException("Cannot use NFS root without VIFs configured");
  19.108 +        }
  19.109 +
  19.110 +        /* Uncompress the image and initrd */
  19.111 +        if (image.endsWith(".gz")) {
  19.112 +          image_tmp = getUncompressed("xen-image-", image);
  19.113 +          image = image_tmp.getPath();
  19.114 +        }
  19.115 +
  19.116 +        if (initrd != null && initrd.endsWith(".gz")) {
  19.117 +          initrd_tmp = getUncompressed("xen-initrd-", initrd);
  19.118 +          initrd = initrd_tmp.getPath();
  19.119 +        }
  19.120 +
  19.121 +        /* Create a new empty domain */
  19.122 +        Process create_p;
  19.123 +        int create_rc;
  19.124 +        create_cmdarray[0] = d.XIToolsDir + "xi_create";
  19.125 +        create_cmdarray[1] = "" + size;
  19.126 +        create_cmdarray[2] = name;
  19.127 +        if (Settings.TEST) {
  19.128 +          reportCommand(create_cmdarray);
  19.129 +          domain_id = 1;
  19.130 +          create_rc = 0;
  19.131 +        } else {
  19.132 +          create_p = r.exec(create_cmdarray);
  19.133 +          br =
  19.134 +            new BufferedReader(
  19.135 +              new InputStreamReader(create_p.getInputStream()));
  19.136 +          domain_id = Integer.parseInt(br.readLine());
  19.137 +          create_rc = create_p.waitFor();
  19.138 +        }
  19.139 +
  19.140 +        if (create_rc != 0) {
  19.141 +          throw CommandFailedException.XICommandFailed("Failed to create domain", create_cmdarray);
  19.142 +        } else if (domain_id > d.MaxDomainNumber) {
  19.143 +          throw new CommandFailedException(
  19.144 +            "Cannot configure more than " + d.MaxDomainNumber + " domains");
  19.145 +        }
  19.146 +
  19.147 +        /* Set up boot parameters to pass to xi_build. */
  19.148 +        if (root_dev.equals("/dev/nfs")) {
  19.149 +          if (vifs == 0) {
  19.150 +            throw new CommandFailedException("Cannot use NFS root without VIFs configured");
  19.151 +          }
  19.152 +          if (nfs_root_path == null) {
  19.153 +            throw new CommandFailedException("No NFS root specified");
  19.154 +          }
  19.155 +          if (nw_nfs_server == null) {
  19.156 +            throw new CommandFailedException("No NFS server specified");
  19.157 +          }
  19.158 +          bargs =
  19.159 +            (bargs
  19.160 +              + " root=/dev/nfs "
  19.161 +              + "nfsroot="
  19.162 +              + StringPattern.parse(nfs_root_path).resolve(domain_id)
  19.163 +              + " ");
  19.164 +        } else {
  19.165 +          bargs =
  19.166 +            (bargs
  19.167 +              + " root="
  19.168 +              + StringPattern.parse(root_dev).resolve(domain_id)
  19.169 +              + " ");
  19.170 +
  19.171 +        }
  19.172 +
  19.173 +        if (vifs > 0) {
  19.174 +          domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id);
  19.175 +          if (nw_host == null) {
  19.176 +            try {
  19.177 +              nw_host = InetAddress.getByName(domain_ip).getHostName();
  19.178 +            } catch (UnknownHostException uhe) {
  19.179 +              nw_host = "" + nw_ip;
  19.180 +            }
  19.181 +
  19.182 +          }
  19.183 +          bargs =
  19.184 +            ("ip="
  19.185 +              + domain_ip
  19.186 +              + ":"
  19.187 +              + ((nw_nfs_server == null)
  19.188 +                ? ""
  19.189 +                : (InetAddressPattern.parse(nw_nfs_server).resolve(domain_id)))
  19.190 +              + ":"
  19.191 +              + ((nw_gw == null)
  19.192 +                ? ""
  19.193 +                : (InetAddressPattern.parse(nw_gw).resolve(domain_id)))
  19.194 +              + ":"
  19.195 +              + ((nw_mask == null)
  19.196 +                ? ""
  19.197 +                : InetAddressPattern.parse(nw_mask).resolve(domain_id))
  19.198 +              + ":"
  19.199 +              + ((nw_host == null) ? "" : nw_host)
  19.200 +              + ":eth0:off "
  19.201 +              + bargs);
  19.202 +        }
  19.203 +
  19.204 +        /* Build the domain */
  19.205 +        Process build_p;
  19.206 +        int build_rc;
  19.207 +        idx = 0;
  19.208 +        for (i = 0; i < build_cmdarray.length; i++)
  19.209 +          build_cmdarray[i] = "";
  19.210 +        build_cmdarray[idx++] = d.XIToolsDir + "xi_build";
  19.211 +        build_cmdarray[idx++] = "" + domain_id;
  19.212 +        build_cmdarray[idx++] = "" + image;
  19.213 +        build_cmdarray[idx++] = "" + vifs;
  19.214 +        if (initrd != null)
  19.215 +          build_cmdarray[idx++] = "initrd=" + initrd;
  19.216 +        build_cmdarray[idx++] = "" + bargs;
  19.217 +        if (Settings.TEST) {
  19.218 +          reportCommand(build_cmdarray);
  19.219 +          build_rc = 0;
  19.220 +        } else {
  19.221 +          build_p = r.exec(build_cmdarray);
  19.222 +          build_rc = build_p.waitFor();
  19.223 +        }
  19.224 +
  19.225 +        if (build_rc != 0) {
  19.226 +          throw CommandFailedException.XICommandFailed("Failed to build domain", build_cmdarray);
  19.227 +        }
  19.228 +
  19.229 +        /* Set up the first VIF if necessary */
  19.230 +        if (vifs > 0) {
  19.231 +          Process vifinit_p;
  19.232 +          int vifinit_rc;
  19.233 +          vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit";
  19.234 +          vifinit_cmdarray[1] = "" + domain_id;
  19.235 +          vifinit_cmdarray[2] = "0";
  19.236 +          vifinit_cmdarray[3] = domain_ip;
  19.237 +          if (Settings.TEST) {
  19.238 +            reportCommand(vifinit_cmdarray);
  19.239 +            vifinit_rc = 0;
  19.240 +          } else {
  19.241 +            vifinit_p = r.exec(vifinit_cmdarray);
  19.242 +            vifinit_rc = vifinit_p.waitFor();
  19.243 +          }
  19.244 +
  19.245 +          if (vifinit_rc != 0) {
  19.246 +            throw CommandFailedException.XICommandFailed(
  19.247 +              "Failed to initialise VIF 0",
  19.248 +              vifinit_cmdarray);
  19.249 +          }
  19.250 +        }
  19.251 +      } finally {
  19.252 +        if (image_tmp != null)
  19.253 +          image_tmp.delete();
  19.254 +        if (initrd_tmp != null)
  19.255 +          initrd_tmp.delete();
  19.256 +      }
  19.257 +    } catch (CommandFailedException e) {
  19.258 +      throw e;
  19.259 +    } catch (Exception e) {
  19.260 +      throw new CommandFailedException("Could not create new domain (" + e + ")", e);
  19.261 +    }
  19.262 +
  19.263 +    output = new String[ vifs > 0 ? 6 : 4 ];
  19.264 +    output[0] = "Domain created with arguments:";
  19.265 +    output[1] = "";
  19.266 +    for (i = 0; i < create_cmdarray.length; i++)
  19.267 +      output[1] += create_cmdarray[i] + " ";
  19.268 +    output[2] = "Domain built with arguments:";
  19.269 +    output[3] = "";
  19.270 +    for (i = 0; i < build_cmdarray.length; i++)
  19.271 +      output[3] += build_cmdarray[i] + " ";
  19.272 +    if ( vifs > 0 ) {
  19.273 +      output[4] = "VIF 0 initialized with arguments:";
  19.274 +      output[5] = "";
  19.275 +      for (i = 0; i < vifinit_cmdarray.length; i++)
  19.276 +        output[5] += vifinit_cmdarray[i] + " ";
  19.277 +    }
  19.278 +
  19.279 +    return null;
  19.280 +  }
  19.281 +  
  19.282 +  private File getUncompressed (String prefix, String original) throws IOException {
  19.283 +    FileOutputStream fos;
  19.284 +    GZIPInputStream gis;
  19.285 +    File result;
  19.286 +    byte buffer[] = new byte[1024];
  19.287 +    int l;
  19.288 +    
  19.289 +    result = File.createTempFile (prefix, null);
  19.290 +    
  19.291 +    try {
  19.292 +      fos = new FileOutputStream (result);
  19.293 +      gis = new GZIPInputStream (new FileInputStream (original));
  19.294 +      while ((l = gis.read(buffer, 0, buffer.length)) != -1) {
  19.295 +  fos.write (buffer, 0, l);
  19.296 +      }   
  19.297 +    } catch (IOException ioe) {
  19.298 +      result.delete ();
  19.299 +      throw ioe;
  19.300 +    }
  19.301 +
  19.302 +    return result;
  19.303 +  }
  19.304 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainStart.java	Thu Jul 03 15:01:39 2003 +0000
    20.3 @@ -0,0 +1,49 @@
    20.4 +package org.xenoserver.control;
    20.5 +
    20.6 +/**
    20.7 + * Starts a domain.
    20.8 + */
    20.9 +public class CommandDomainStart extends Command {
   20.10 +  private Defaults d;
   20.11 +  private int domain_id;
   20.12 +  
   20.13 +  /**
   20.14 +   * Constructor for CommandDomainStart.
   20.15 +   * @param d Defaults object to use.
   20.16 +   * @param domain_id Domain to start.
   20.17 +   */
   20.18 +  public CommandDomainStart(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 start_p;
   20.29 +      String start_cmdarray[] = new String[2];
   20.30 +      int start_rc;
   20.31 +      start_cmdarray[0] = d.XIToolsDir + "xi_start";
   20.32 +      start_cmdarray[1] = "" + domain_id;
   20.33 +
   20.34 +      if (Settings.TEST) {
   20.35 +        output = reportCommand(start_cmdarray);
   20.36 +      } else {
   20.37 +        start_p = r.exec(start_cmdarray);
   20.38 +        start_rc = start_p.waitFor();
   20.39 +        if (start_rc != 0) {
   20.40 +          throw CommandFailedException.XICommandFailed("Could not start domain", start_cmdarray);
   20.41 +        }
   20.42 +        output = "Started domain " + domain_id;
   20.43 +      }
   20.44 +    } catch (CommandFailedException e) {
   20.45 +      throw e;
   20.46 +    } catch (Exception e) {
   20.47 +      throw new CommandFailedException("Could not start new domain (" + e + ")", e);
   20.48 +    }
   20.49 +
   20.50 +    return output;
   20.51 +  }
   20.52 +}
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainStop.java	Thu Jul 03 15:01:39 2003 +0000
    21.3 @@ -0,0 +1,50 @@
    21.4 +package org.xenoserver.control;
    21.5 +
    21.6 +/**
    21.7 + * Stops a domain.
    21.8 + */
    21.9 +public class CommandDomainStop extends Command {
   21.10 +  private Defaults d;
   21.11 +  private int domain_id;
   21.12 +  
   21.13 +  /**
   21.14 +   * Constructor for CommandDomainStop.
   21.15 +   * @param d The defaults object to use.
   21.16 +   * @param domain_id The domain to stop.
   21.17 +   */
   21.18 +  public CommandDomainStop(Defaults d, int domain_id) {
   21.19 +    this.d = d;
   21.20 +    this.domain_id = domain_id;
   21.21 +  }
   21.22 +
   21.23 +  public String execute() throws CommandFailedException {
   21.24 +    Runtime r = Runtime.getRuntime();
   21.25 +    String output = null;
   21.26 +
   21.27 +    try {
   21.28 +      Process stop_p;
   21.29 +      String stop_cmdarray[] = new String[2];
   21.30 +      int stop_rc;
   21.31 +      stop_cmdarray[0] = d.XIToolsDir + "xi_stop";
   21.32 +      stop_cmdarray[1] = "" + domain_id;
   21.33 +
   21.34 +      if (Settings.TEST) {
   21.35 +        output = reportCommand(stop_cmdarray);
   21.36 +      } else {
   21.37 +        stop_p = r.exec(stop_cmdarray);
   21.38 +        stop_rc = stop_p.waitFor();
   21.39 +
   21.40 +        if (stop_rc != 0) {
   21.41 +          throw CommandFailedException.XICommandFailed("Could not stop domain", stop_cmdarray);
   21.42 +        }
   21.43 +        output = "Stopped domain " + domain_id;
   21.44 +      }
   21.45 +    } catch (CommandFailedException e) {
   21.46 +      throw e;
   21.47 +    } catch (Exception e) {
   21.48 +      throw new CommandFailedException("Could not stop new domain (" + e + ")", e);
   21.49 +    }
   21.50 +
   21.51 +    return output;
   21.52 +  }
   21.53 +}
    22.1 --- a/tools/control/src/org/xenoserver/control/CommandList.java	Thu Jul 03 13:36:35 2003 +0000
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,108 +0,0 @@
    22.4 -package org.xenoserver.control;
    22.5 -
    22.6 -import java.io.BufferedReader;
    22.7 -import java.io.InputStreamReader;
    22.8 -import java.util.StringTokenizer;
    22.9 -import java.util.Vector;
   22.10 -
   22.11 -/**
   22.12 - * Lists details of all domains. After execute() has been called, call
   22.13 - * domains() to get the array of domains.
   22.14 - */
   22.15 -public class CommandList extends Command {
   22.16 -  private Defaults d;
   22.17 -  private Domain[] array;
   22.18 -
   22.19 -  /**
   22.20 -   * Constructor for CommandList.
   22.21 -   * @param d Defaults object to use.
   22.22 -   */
   22.23 -  public CommandList(Defaults d) {
   22.24 -    this.d = d;
   22.25 -  }
   22.26 -
   22.27 -  /**
   22.28 -   * Retrieves the list of domains.
   22.29 -   * @return null, call domains() to get the list.
   22.30 -   */
   22.31 -  public String execute() throws CommandFailedException {
   22.32 -    Runtime r = Runtime.getRuntime();
   22.33 -    int rc = 0;
   22.34 -    Vector v = new Vector();
   22.35 -    String outline;
   22.36 -    BufferedReader in;
   22.37 -    String output = null;
   22.38 -
   22.39 -    try {
   22.40 -      Process start_p;
   22.41 -      String start_cmdarray[] = new String[1];
   22.42 -      int start_rc;
   22.43 -      start_cmdarray[0] = d.XIToolsDir + "xi_list";
   22.44 -
   22.45 -      if (Settings.TEST) {
   22.46 -        output = reportCommand(start_cmdarray);
   22.47 -      } else {
   22.48 -        start_p = r.exec(start_cmdarray);
   22.49 -        start_rc = start_p.waitFor();
   22.50 -        if (start_rc != 0) {
   22.51 -          throw CommandFailedException.XICommandFailed("Could not get domain list", start_cmdarray);
   22.52 -        }
   22.53 -
   22.54 -        in =
   22.55 -          new BufferedReader(new InputStreamReader(start_p.getInputStream()));
   22.56 -
   22.57 -        outline = in.readLine();
   22.58 -        while (outline != null) {
   22.59 -          Domain domain = new Domain();
   22.60 -
   22.61 -          StringTokenizer st = new StringTokenizer(outline);
   22.62 -          if (st.hasMoreTokens()) {
   22.63 -            domain.id = Integer.parseInt(st.nextToken());
   22.64 -          }
   22.65 -          if (st.hasMoreTokens()) {
   22.66 -            domain.processor = Integer.parseInt(st.nextToken());
   22.67 -          }
   22.68 -          if (st.hasMoreTokens()) {
   22.69 -            if (st.nextToken().equals("1")) {
   22.70 -              domain.cpu = true;
   22.71 -            } else {
   22.72 -              domain.cpu = false;
   22.73 -            }
   22.74 -          }
   22.75 -          if (st.hasMoreTokens()) {
   22.76 -            domain.nstate = Integer.parseInt(st.nextToken());
   22.77 -          }
   22.78 -          if (st.hasMoreTokens()) {
   22.79 -            domain.state = st.nextToken().toLowerCase();
   22.80 -          }
   22.81 -          if (st.hasMoreTokens()) {
   22.82 -            domain.mcu = Integer.parseInt(st.nextToken());
   22.83 -          }
   22.84 -          if (st.hasMoreTokens()) {
   22.85 -            domain.pages = Integer.parseInt(st.nextToken());
   22.86 -          }
   22.87 -          if (st.hasMoreTokens()) {
   22.88 -            domain.name = st.nextToken();
   22.89 -          }
   22.90 -
   22.91 -          v.add(domain);
   22.92 -
   22.93 -          outline = in.readLine();
   22.94 -        }
   22.95 -
   22.96 -      }
   22.97 -    } catch (CommandFailedException e) {
   22.98 -      throw e;
   22.99 -    } catch (Exception e) {
  22.100 -      throw new CommandFailedException("Could not get domain list(" + e + ")", e);
  22.101 -    }
  22.102 -
  22.103 -    array = new Domain[v.size()];
  22.104 -    v.toArray(array);
  22.105 -    return output;
  22.106 -  }
  22.107 -  
  22.108 -  public Domain[] domains() {
  22.109 -    return array;
  22.110 -  }
  22.111 -}
    23.1 --- a/tools/control/src/org/xenoserver/control/CommandNew.java	Thu Jul 03 13:36:35 2003 +0000
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,301 +0,0 @@
    23.4 -package org.xenoserver.control;
    23.5 -
    23.6 -import java.io.BufferedReader;
    23.7 -import java.io.File;
    23.8 -import java.io.FileInputStream;
    23.9 -import java.io.FileOutputStream;
   23.10 -import java.io.IOException;
   23.11 -import java.io.InputStreamReader;
   23.12 -import java.net.InetAddress;
   23.13 -import java.net.UnknownHostException;
   23.14 -import java.util.zip.GZIPInputStream;
   23.15 -
   23.16 -/**
   23.17 - * Creates a new domain. As this command returns a multi-line result,
   23.18 - * call output() to get an array of strings.
   23.19 - */
   23.20 -public class CommandNew extends Command {
   23.21 -  private Defaults d;
   23.22 -  private String name;
   23.23 -  private int size;
   23.24 -  private String image;
   23.25 -  private String initrd;
   23.26 -  private int vifs;
   23.27 -  private String bargs;
   23.28 -  private String root_dev;
   23.29 -  private String nfs_root_path;
   23.30 -  private String nw_ip;
   23.31 -  private String nw_gw;
   23.32 -  private String nw_mask;
   23.33 -  private String nw_nfs_server;
   23.34 -  private String nw_host;
   23.35 -  private String[] output;
   23.36 -  
   23.37 -  public String[] output() {
   23.38 -    return output;
   23.39 -  }
   23.40 -  
   23.41 -  /**
   23.42 -   * Constructor for CommandNew.
   23.43 -   * @param d Defaults object to use.
   23.44 -   * @param name Name for the domain.
   23.45 -   * @param size Memory size for the domain.
   23.46 -   * @param image Image to boot domain from.
   23.47 -   * @param initrd Initrd to boot domain with.
   23.48 -   * @param vifs Number of virtual interfaces for the domain.
   23.49 -   * @param bargs Boot arguments for the domain.
   23.50 -   * @param root_dev Root device for the domain.
   23.51 -   * @param nfs_root_path NFS root to be used by the domain.
   23.52 -   * @param nw_ip IP address pattern to use for the domain's interfaces.
   23.53 -   * @param nw_gw Gateway to configure the domain for.
   23.54 -   * @param nw_mask Network mask to configure the domain for.
   23.55 -   * @param nw_nfs_server NFS server to be used by the domain.
   23.56 -   * @param nw_host Hostname to be used by the domain.
   23.57 -   */
   23.58 -  public CommandNew(
   23.59 -    Defaults d,
   23.60 -    String name,
   23.61 -    int size,
   23.62 -    String image,
   23.63 -    String initrd,
   23.64 -    int vifs,
   23.65 -    String bargs,
   23.66 -    String root_dev,
   23.67 -    String nfs_root_path,
   23.68 -    String nw_ip,
   23.69 -    String nw_gw,
   23.70 -    String nw_mask,
   23.71 -    String nw_nfs_server,
   23.72 -    String nw_host) {
   23.73 -    this.d = d;
   23.74 -    this.name = name;
   23.75 -    this.size = size;
   23.76 -    this.image = image;
   23.77 -    this.initrd = initrd;
   23.78 -    this.vifs = vifs;
   23.79 -    this.bargs = bargs;
   23.80 -    this.root_dev = root_dev;
   23.81 -    this.nfs_root_path = nfs_root_path;
   23.82 -    this.nw_ip = nw_ip;
   23.83 -    this.nw_gw = nw_gw;
   23.84 -    this.nw_mask = nw_mask;
   23.85 -    this.nw_nfs_server = nw_nfs_server;
   23.86 -    this.nw_host = nw_host;
   23.87 -  }
   23.88 -
   23.89 -  public String execute() throws CommandFailedException {
   23.90 -    Runtime r = Runtime.getRuntime();
   23.91 -    int domain_id = -1;
   23.92 -    BufferedReader br;
   23.93 -    int idx;
   23.94 -    int i;
   23.95 -    File image_tmp = null;
   23.96 -    File initrd_tmp = null;
   23.97 -    String domain_ip = "";
   23.98 -    
   23.99 -    String create_cmdarray[] = new String[3];
  23.100 -    String build_cmdarray[] = new String[6];
  23.101 -    String vifinit_cmdarray[] = new String[4];
  23.102 -
  23.103 -    try {
  23.104 -      try {
  23.105 -        /* Some initial sanity checks */
  23.106 -        if (root_dev.equals("/dev/nfs") && (vifs == 0)) {
  23.107 -          throw new CommandFailedException("Cannot use NFS root without VIFs configured");
  23.108 -        }
  23.109 -
  23.110 -        /* Uncompress the image and initrd */
  23.111 -        if (image.endsWith(".gz")) {
  23.112 -          image_tmp = getUncompressed("xen-image-", image);
  23.113 -          image = image_tmp.getPath();
  23.114 -        }
  23.115 -
  23.116 -        if (initrd != null && initrd.endsWith(".gz")) {
  23.117 -          initrd_tmp = getUncompressed("xen-initrd-", initrd);
  23.118 -          initrd = initrd_tmp.getPath();
  23.119 -        }
  23.120 -
  23.121 -        /* Create a new empty domain */
  23.122 -        Process create_p;
  23.123 -        int create_rc;
  23.124 -        create_cmdarray[0] = d.XIToolsDir + "xi_create";
  23.125 -        create_cmdarray[1] = "" + size;
  23.126 -        create_cmdarray[2] = name;
  23.127 -        if (Settings.TEST) {
  23.128 -          reportCommand(create_cmdarray);
  23.129 -          domain_id = 1;
  23.130 -          create_rc = 0;
  23.131 -        } else {
  23.132 -          create_p = r.exec(create_cmdarray);
  23.133 -          br =
  23.134 -            new BufferedReader(
  23.135 -              new InputStreamReader(create_p.getInputStream()));
  23.136 -          domain_id = Integer.parseInt(br.readLine());
  23.137 -          create_rc = create_p.waitFor();
  23.138 -        }
  23.139 -
  23.140 -        if (create_rc != 0) {
  23.141 -          throw CommandFailedException.XICommandFailed("Failed to create domain", create_cmdarray);
  23.142 -        } else if (domain_id > d.MaxDomainNumber) {
  23.143 -          throw new CommandFailedException(
  23.144 -            "Cannot configure more than " + d.MaxDomainNumber + " domains");
  23.145 -        }
  23.146 -
  23.147 -        /* Set up boot parameters to pass to xi_build. */
  23.148 -        if (root_dev.equals("/dev/nfs")) {
  23.149 -          if (vifs == 0) {
  23.150 -            throw new CommandFailedException("Cannot use NFS root without VIFs configured");
  23.151 -          }
  23.152 -          if (nfs_root_path == null) {
  23.153 -            throw new CommandFailedException("No NFS root specified");
  23.154 -          }
  23.155 -          if (nw_nfs_server == null) {
  23.156 -            throw new CommandFailedException("No NFS server specified");
  23.157 -          }
  23.158 -          bargs =
  23.159 -            (bargs
  23.160 -              + " root=/dev/nfs "
  23.161 -              + "nfsroot="
  23.162 -              + StringPattern.parse(nfs_root_path).resolve(domain_id)
  23.163 -              + " ");
  23.164 -        } else {
  23.165 -          bargs =
  23.166 -            (bargs
  23.167 -              + " root="
  23.168 -              + StringPattern.parse(root_dev).resolve(domain_id)
  23.169 -              + " ");
  23.170 -
  23.171 -        }
  23.172 -
  23.173 -        if (vifs > 0) {
  23.174 -          domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id);
  23.175 -          if (nw_host == null) {
  23.176 -            try {
  23.177 -              nw_host = InetAddress.getByName(domain_ip).getHostName();
  23.178 -            } catch (UnknownHostException uhe) {
  23.179 -              nw_host = "" + nw_ip;
  23.180 -            }
  23.181 -
  23.182 -          }
  23.183 -          bargs =
  23.184 -            ("ip="
  23.185 -              + domain_ip
  23.186 -              + ":"
  23.187 -              + ((nw_nfs_server == null)
  23.188 -                ? ""
  23.189 -                : (InetAddressPattern.parse(nw_nfs_server).resolve(domain_id)))
  23.190 -              + ":"
  23.191 -              + ((nw_gw == null)
  23.192 -                ? ""
  23.193 -                : (InetAddressPattern.parse(nw_gw).resolve(domain_id)))
  23.194 -              + ":"
  23.195 -              + ((nw_mask == null)
  23.196 -                ? ""
  23.197 -                : InetAddressPattern.parse(nw_mask).resolve(domain_id))
  23.198 -              + ":"
  23.199 -              + ((nw_host == null) ? "" : nw_host)
  23.200 -              + ":eth0:off "
  23.201 -              + bargs);
  23.202 -        }
  23.203 -
  23.204 -        /* Build the domain */
  23.205 -        Process build_p;
  23.206 -        int build_rc;
  23.207 -        idx = 0;
  23.208 -        for (i = 0; i < build_cmdarray.length; i++)
  23.209 -          build_cmdarray[i] = "";
  23.210 -        build_cmdarray[idx++] = d.XIToolsDir + "xi_build";
  23.211 -        build_cmdarray[idx++] = "" + domain_id;
  23.212 -        build_cmdarray[idx++] = "" + image;
  23.213 -        build_cmdarray[idx++] = "" + vifs;
  23.214 -        if (initrd != null)
  23.215 -          build_cmdarray[idx++] = "initrd=" + initrd;
  23.216 -        build_cmdarray[idx++] = "" + bargs;
  23.217 -        if (Settings.TEST) {
  23.218 -          reportCommand(build_cmdarray);
  23.219 -          build_rc = 0;
  23.220 -        } else {
  23.221 -          build_p = r.exec(build_cmdarray);
  23.222 -          build_rc = build_p.waitFor();
  23.223 -        }
  23.224 -
  23.225 -        if (build_rc != 0) {
  23.226 -          throw CommandFailedException.XICommandFailed("Failed to build domain", build_cmdarray);
  23.227 -        }
  23.228 -
  23.229 -        /* Set up the first VIF if necessary */
  23.230 -        if (vifs > 0) {
  23.231 -          Process vifinit_p;
  23.232 -          int vifinit_rc;
  23.233 -          vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit";
  23.234 -          vifinit_cmdarray[1] = "" + domain_id;
  23.235 -          vifinit_cmdarray[2] = "0";
  23.236 -          vifinit_cmdarray[3] = domain_ip;
  23.237 -          if (Settings.TEST) {
  23.238 -            reportCommand(vifinit_cmdarray);
  23.239 -            vifinit_rc = 0;
  23.240 -          } else {
  23.241 -            vifinit_p = r.exec(vifinit_cmdarray);
  23.242 -            vifinit_rc = vifinit_p.waitFor();
  23.243 -          }
  23.244 -
  23.245 -          if (vifinit_rc != 0) {
  23.246 -            throw CommandFailedException.XICommandFailed(
  23.247 -              "Failed to initialise VIF 0",
  23.248 -              vifinit_cmdarray);
  23.249 -          }
  23.250 -        }
  23.251 -      } finally {
  23.252 -        if (image_tmp != null)
  23.253 -          image_tmp.delete();
  23.254 -        if (initrd_tmp != null)
  23.255 -          initrd_tmp.delete();
  23.256 -      }
  23.257 -    } catch (CommandFailedException e) {
  23.258 -      throw e;
  23.259 -    } catch (Exception e) {
  23.260 -      throw new CommandFailedException("Could not create new domain (" + e + ")", e);
  23.261 -    }
  23.262 -
  23.263 -    output = new String[ vifs > 0 ? 6 : 4 ];
  23.264 -    output[0] = "Domain created with arguments:";
  23.265 -    output[1] = "";
  23.266 -    for (i = 0; i < create_cmdarray.length; i++)
  23.267 -      output[1] += create_cmdarray[i] + " ";
  23.268 -    output[2] = "Domain built with arguments:";
  23.269 -    output[3] = "";
  23.270 -    for (i = 0; i < build_cmdarray.length; i++)
  23.271 -      output[3] += build_cmdarray[i] + " ";
  23.272 -    if ( vifs > 0 ) {
  23.273 -      output[4] = "VIF 0 initialized with arguments:";
  23.274 -      output[5] = "";
  23.275 -      for (i = 0; i < vifinit_cmdarray.length; i++)
  23.276 -        output[5] += vifinit_cmdarray[i] + " ";
  23.277 -    }
  23.278 -
  23.279 -    return null;
  23.280 -  }
  23.281 -  
  23.282 -  private File getUncompressed (String prefix, String original) throws IOException {
  23.283 -    FileOutputStream fos;
  23.284 -    GZIPInputStream gis;
  23.285 -    File result;
  23.286 -    byte buffer[] = new byte[1024];
  23.287 -    int l;
  23.288 -    
  23.289 -    result = File.createTempFile (prefix, null);
  23.290 -    
  23.291 -    try {
  23.292 -      fos = new FileOutputStream (result);
  23.293 -      gis = new GZIPInputStream (new FileInputStream (original));
  23.294 -      while ((l = gis.read(buffer, 0, buffer.length)) != -1) {
  23.295 -  fos.write (buffer, 0, l);
  23.296 -      }   
  23.297 -    } catch (IOException ioe) {
  23.298 -      result.delete ();
  23.299 -      throw ioe;
  23.300 -    }
  23.301 -
  23.302 -    return result;
  23.303 -  }
  23.304 -}
    24.1 --- a/tools/control/src/org/xenoserver/control/CommandStart.java	Thu Jul 03 13:36:35 2003 +0000
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,49 +0,0 @@
    24.4 -package org.xenoserver.control;
    24.5 -
    24.6 -/**
    24.7 - * Starts a domain.
    24.8 - */
    24.9 -public class CommandStart extends Command {
   24.10 -  private Defaults d;
   24.11 -  private int domain_id;
   24.12 -  
   24.13 -  /**
   24.14 -   * Constructor for CommandStart.
   24.15 -   * @param d Defaults object to use.
   24.16 -   * @param domain_id Domain to start.
   24.17 -   */
   24.18 -  public CommandStart(Defaults d, int domain_id) {
   24.19 -    this.d = d;
   24.20 -    this.domain_id = domain_id;
   24.21 -  }
   24.22 -
   24.23 -  public String execute() throws CommandFailedException {
   24.24 -    Runtime r = Runtime.getRuntime();
   24.25 -    String output = null;
   24.26 -
   24.27 -    try {
   24.28 -      Process start_p;
   24.29 -      String start_cmdarray[] = new String[2];
   24.30 -      int start_rc;
   24.31 -      start_cmdarray[0] = d.XIToolsDir + "xi_start";
   24.32 -      start_cmdarray[1] = "" + domain_id;
   24.33 -
   24.34 -      if (Settings.TEST) {
   24.35 -        output = reportCommand(start_cmdarray);
   24.36 -      } else {
   24.37 -        start_p = r.exec(start_cmdarray);
   24.38 -        start_rc = start_p.waitFor();
   24.39 -        if (start_rc != 0) {
   24.40 -          throw CommandFailedException.XICommandFailed("Could not start domain", start_cmdarray);
   24.41 -        }
   24.42 -        output = "Started domain " + domain_id;
   24.43 -      }
   24.44 -    } catch (CommandFailedException e) {
   24.45 -      throw e;
   24.46 -    } catch (Exception e) {
   24.47 -      throw new CommandFailedException("Could not start new domain (" + e + ")", e);
   24.48 -    }
   24.49 -
   24.50 -    return output;
   24.51 -  }
   24.52 -}
    25.1 --- a/tools/control/src/org/xenoserver/control/CommandStop.java	Thu Jul 03 13:36:35 2003 +0000
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,50 +0,0 @@
    25.4 -package org.xenoserver.control;
    25.5 -
    25.6 -/**
    25.7 - * Stops a domain.
    25.8 - */
    25.9 -public class CommandStop extends Command {
   25.10 -  private Defaults d;
   25.11 -  private int domain_id;
   25.12 -  
   25.13 -  /**
   25.14 -   * Constructor for CommandStop.
   25.15 -   * @param d The defaults object to use.
   25.16 -   * @param domain_id The domain to stop.
   25.17 -   */
   25.18 -  public CommandStop(Defaults d, int domain_id) {
   25.19 -    this.d = d;
   25.20 -    this.domain_id = domain_id;
   25.21 -  }
   25.22 -
   25.23 -  public String execute() throws CommandFailedException {
   25.24 -    Runtime r = Runtime.getRuntime();
   25.25 -    String output = null;
   25.26 -
   25.27 -    try {
   25.28 -      Process stop_p;
   25.29 -      String stop_cmdarray[] = new String[2];
   25.30 -      int stop_rc;
   25.31 -      stop_cmdarray[0] = d.XIToolsDir + "xi_stop";
   25.32 -      stop_cmdarray[1] = "" + domain_id;
   25.33 -
   25.34 -      if (Settings.TEST) {
   25.35 -        output = reportCommand(stop_cmdarray);
   25.36 -      } else {
   25.37 -        stop_p = r.exec(stop_cmdarray);
   25.38 -        stop_rc = stop_p.waitFor();
   25.39 -
   25.40 -        if (stop_rc != 0) {
   25.41 -          throw CommandFailedException.XICommandFailed("Could not stop domain", stop_cmdarray);
   25.42 -        }
   25.43 -        output = "Stopped domain " + domain_id;
   25.44 -      }
   25.45 -    } catch (CommandFailedException e) {
   25.46 -      throw e;
   25.47 -    } catch (Exception e) {
   25.48 -      throw new CommandFailedException("Could not stop new domain (" + e + ")", e);
   25.49 -    }
   25.50 -
   25.51 -    return output;
   25.52 -  }
   25.53 -}