debuggers.hg
changeset 578:201ebe54a6ad
bitkeeper revision 1.289.1.4 (3f0ac0e2RKTYkaGxMaS0yvsU2le2uA)
Finish converting to support correct way of getting partition/disk numbers
Code cleanups
Finish converting to support correct way of getting partition/disk numbers
Code cleanups
line diff
1.1 --- a/tools/control/src/org/xenoserver/cmdline/CommandParser.java Tue Jul 08 11:08:04 2003 +0000 1.2 +++ b/tools/control/src/org/xenoserver/cmdline/CommandParser.java Tue Jul 08 13:02:26 2003 +0000 1.3 @@ -16,83 +16,127 @@ import org.xenoserver.control.XML; 1.4 * and execute it, displaying any output. 1.5 */ 1.6 public abstract class CommandParser { 1.7 - /** 1.8 - * Subclasses should implement this method such that it outputs any successful 1.9 - * output to the screen, or throws an exception if required arguments 1.10 - * are missing or malformed. It also may propagate exceptions from the 1.11 - * command execution. 1.12 - * 1.13 - * @param d The defaults object to use. 1.14 - * @param args The arguments to parse. 1.15 - * @throws ParseFailedException if the arguments are not suitable. 1.16 - * @throws CommandFailedException if the command did not execute successfully. 1.17 - */ 1.18 - public abstract void parse(Defaults d, LinkedList args) 1.19 - throws ParseFailedException, CommandFailedException; 1.20 + /** 1.21 + * Subclasses should implement this method such that it outputs any successful 1.22 + * output to the screen, or throws an exception if required arguments 1.23 + * are missing or malformed. It also may propagate exceptions from the 1.24 + * command execution. 1.25 + * 1.26 + * @param d The defaults object to use. 1.27 + * @param args The arguments to parse. 1.28 + * @throws ParseFailedException if the arguments are not suitable. 1.29 + * @throws CommandFailedException if the command did not execute successfully. 1.30 + */ 1.31 + public abstract void parse(Defaults d, LinkedList args) 1.32 + throws ParseFailedException, CommandFailedException; 1.33 + 1.34 + /** @return The command name which will be matched on the command line. */ 1.35 + public abstract String getName(); 1.36 + /** @return A usage string for this command. */ 1.37 + public abstract String getUsage(); 1.38 + /** @return The help text for this command. */ 1.39 + public abstract String getHelpText(); 1.40 + 1.41 + /** 1.42 + * Print a usage string for this command. 1.43 + * @param prefix The command prefix for this command 1.44 + */ 1.45 + public void printUsage(String prefix) { 1.46 + String name = getName(); 1.47 + if (prefix != null) { 1.48 + name = prefix + " " + name; 1.49 + } 1.50 + String usage = getUsage(); 1.51 + while (name.length() < 16) { 1.52 + name = name + " "; 1.53 + } 1.54 + System.out.println(" " + name + usage); 1.55 + } 1.56 + 1.57 + /** 1.58 + * Prints the help text for this command. 1.59 + * @param args Command arguments, ignored for normal commands. 1.60 + */ 1.61 + public void printHelpText(LinkedList args) { 1.62 + System.out.println(getName() + " " + getUsage()); 1.63 + System.out.println(); 1.64 + System.out.println(getHelpText()); 1.65 + } 1.66 + 1.67 + /** 1.68 + * Get a string parameter 1.69 + * @param args Argument list to search 1.70 + * @param key Argument key 1.71 + * @param def Default value 1.72 + * @return parameter, or default if none found 1.73 + */ 1.74 + public String getStringParameter(List args, char key, String def) { 1.75 + String r = getParameter(args, key); 1.76 + return (r == null) ? def : r; 1.77 + } 1.78 1.79 - /** Return the command name which will be matched on the command line. */ 1.80 - public abstract String getName(); 1.81 - /** Return a usage string for this command. */ 1.82 - public abstract String getUsage(); 1.83 - /** Return the help text for this command. */ 1.84 - public abstract String getHelpText(); 1.85 - 1.86 - /** Print a usage string for this command. */ 1.87 - public void printUsage(String prefix) 1.88 - { 1.89 - String name = getName(); 1.90 - if ( prefix != null ) 1.91 - name = prefix + " " + name; 1.92 - String usage = getUsage(); 1.93 - while (name.length() < 16) 1.94 - name = name + " "; 1.95 - System.out.println(" " + name + usage); 1.96 - } 1.97 - 1.98 - /** Prints the help text for this command. */ 1.99 - public void printHelpText(LinkedList args) 1.100 - { 1.101 - System.out.println(getName() + " " + getUsage()); 1.102 - System.out.println(); 1.103 - System.out.println(getHelpText()); 1.104 - } 1.105 + /** 1.106 + * Get an int parameter 1.107 + * @param args Argument list to search 1.108 + * @param key Argument key 1.109 + * @param def Default value 1.110 + * @return parameter, or default if none found 1.111 + */ 1.112 + public int getIntParameter(List args, char key, int def) { 1.113 + String r = getParameter(args, key); 1.114 + return (r == null) ? def : (Integer.parseInt(r)); 1.115 + } 1.116 1.117 - public String getStringParameter(List args, char key, String def) { 1.118 - String r = getParameter(args, key); 1.119 - return (r == null) ? def : r; 1.120 - } 1.121 + /** 1.122 + * Get a boolean parameter 1.123 + * @param args Argument list to search 1.124 + * @param key Argument key 1.125 + * @return parameter, or false if none found 1.126 + */ 1.127 + public boolean getFlagParameter(List args, char key) { 1.128 + String r = getParameter(args, key); 1.129 + return (r == null) ? false : true; 1.130 + } 1.131 1.132 - public int getIntParameter(List args, char key, int def) { 1.133 - String r = getParameter(args, key); 1.134 - return (r == null) ? def : (Integer.parseInt(r)); 1.135 - } 1.136 - 1.137 - public boolean getFlagParameter(List args, char key) { 1.138 - String r = getParameter(args, key); 1.139 - return (r == null) ? false : true; 1.140 - } 1.141 + /** 1.142 + * Get a parameter 1.143 + * @param args Argument list to search 1.144 + * @param key Key to look for 1.145 + * @return Value, or "" if no value, or null if no such argument 1.146 + */ 1.147 + protected String getParameter(List args, char key) { 1.148 + String result = null; 1.149 + Iterator i = args.iterator(); 1.150 + while (i.hasNext()) { 1.151 + String arg = (String) i.next(); 1.152 + if (arg.startsWith("-" + key)) { 1.153 + if (arg.length() > 2) { 1.154 + result = arg.substring(2); 1.155 + } else { 1.156 + result = ""; 1.157 + } 1.158 + } 1.159 + } 1.160 + return result; 1.161 + } 1.162 1.163 - protected String getParameter(List args, char key) { 1.164 - String result = null; 1.165 - Iterator i = args.iterator(); 1.166 - while ( i.hasNext() ) { 1.167 - String arg = (String) i.next(); 1.168 - if (arg.startsWith("-" + key)) { 1.169 - if (arg.length() > 2) { 1.170 - result = arg.substring(2); 1.171 - } else { 1.172 - result = ""; 1.173 - } 1.174 - } 1.175 + /** 1.176 + * Load the partition and disk manager state 1.177 + */ 1.178 + protected void loadState() { 1.179 + XML.loadState( 1.180 + PartitionManager.IT, 1.181 + VirtualDiskManager.IT, 1.182 + Settings.STATE_INPUT_FILE); 1.183 } 1.184 - return result; 1.185 - } 1.186 1.187 - protected void loadState() { 1.188 - XML.loadState( PartitionManager.IT, VirtualDiskManager.IT, Settings.STATE_INPUT_FILE ); 1.189 - } 1.190 - 1.191 - protected void saveState() { 1.192 - XML.saveState( PartitionManager.IT, VirtualDiskManager.IT, Settings.STATE_OUTPUT_FILE ); 1.193 - } 1.194 + /** 1.195 + * Save the partition and disk manager state 1.196 + */ 1.197 + protected void saveState() { 1.198 + XML.saveState( 1.199 + PartitionManager.IT, 1.200 + VirtualDiskManager.IT, 1.201 + Settings.STATE_OUTPUT_FILE); 1.202 + } 1.203 }
2.1 --- a/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java Tue Jul 08 11:08:04 2003 +0000 2.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParseDomainNew.java Tue Jul 08 13:02:26 2003 +0000 2.3 @@ -16,12 +16,12 @@ public class ParseDomainNew extends Comm 2.4 int vifs = getIntParameter(args, 'v', d.domainVIFs); 2.5 String bargs = getStringParameter (args, 'a', d.args) + " "; 2.6 String root_dev = getStringParameter (args, 'd', d.rootDevice); 2.7 - String nfs_root_path = getStringParameter (args, 'f', d.NWNFSRoot); 2.8 - String nw_ip = getStringParameter (args, '4', d.NWIP); 2.9 - String nw_gw = getStringParameter (args, 'g', d.NWGW); 2.10 - String nw_mask = getStringParameter (args, 'm', d.NWMask); 2.11 - String nw_nfs_server = getStringParameter (args, 's', d.NWNFSServer); 2.12 - String nw_host = getStringParameter (args, 'h', d.NWHost); 2.13 + String nfs_root_path = getStringParameter (args, 'f', d.nwNFSRoot); 2.14 + String nw_ip = getStringParameter (args, '4', d.nwIP); 2.15 + String nw_gw = getStringParameter (args, 'g', d.nwGateway); 2.16 + String nw_mask = getStringParameter (args, 'm', d.nwMask); 2.17 + String nw_nfs_server = getStringParameter (args, 's', d.nwNFSServer); 2.18 + String nw_host = getStringParameter (args, 'h', d.nwHost); 2.19 2.20 d.describe(); 2.21
3.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java Tue Jul 08 11:08:04 2003 +0000 3.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java Tue Jul 08 13:02:26 2003 +0000 3.3 @@ -5,7 +5,6 @@ import java.util.LinkedList; 3.4 import org.xenoserver.control.CommandFailedException; 3.5 import org.xenoserver.control.CommandPhysicalGrant; 3.6 import org.xenoserver.control.Defaults; 3.7 -import org.xenoserver.control.Extent; 3.8 import org.xenoserver.control.Mode; 3.9 import org.xenoserver.control.Partition; 3.10 import org.xenoserver.control.PartitionManager; 3.11 @@ -39,11 +38,7 @@ public class ParsePhysicalGrant extends 3.12 if (p.isXeno() && !force) 3.13 throw new CommandFailedException("Refusing to grant physical access as the given partition is allocated to the virtual disk manager. Use -f if you are sure."); 3.14 3.15 - // Convert the partition into a physical extent 3.16 - Extent e = p.toExtent(); 3.17 - int partition_no = p.getMinor() & 0x1F; 3.18 - 3.19 - String output = new CommandPhysicalGrant( d, domain_id, e, mode, partition_no ).execute(); 3.20 + String output = new CommandPhysicalGrant( d, domain_id, p, mode ).execute(); 3.21 if ( output != null ) 3.22 System.out.println( output ); 3.23 }
4.1 --- a/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java Tue Jul 08 11:08:04 2003 +0000 4.2 +++ b/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java Tue Jul 08 13:02:26 2003 +0000 4.3 @@ -5,7 +5,6 @@ import java.util.LinkedList; 4.4 import org.xenoserver.control.CommandFailedException; 4.5 import org.xenoserver.control.CommandPhysicalRevoke; 4.6 import org.xenoserver.control.Defaults; 4.7 -import org.xenoserver.control.Extent; 4.8 import org.xenoserver.control.Partition; 4.9 import org.xenoserver.control.PartitionManager; 4.10 4.11 @@ -26,10 +25,7 @@ public class ParsePhysicalRevoke extends 4.12 if ( p == null ) 4.13 throw new CommandFailedException("Partition " + partition_name + " does not exist."); 4.14 4.15 - // Convert the partition into a physical extent 4.16 - Extent e = p.toExtent(); 4.17 - 4.18 - String output = new CommandPhysicalRevoke( d, domain_id, e ).execute(); 4.19 + String output = new CommandPhysicalRevoke( d, domain_id, p ).execute(); 4.20 if ( output != null ) 4.21 System.out.println( output ); 4.22 }
5.1 --- a/tools/control/src/org/xenoserver/control/Command.java Tue Jul 08 11:08:04 2003 +0000 5.2 +++ b/tools/control/src/org/xenoserver/control/Command.java Tue Jul 08 13:02:26 2003 +0000 5.3 @@ -5,23 +5,27 @@ package org.xenoserver.control; 5.4 * and virtual disk settings. 5.5 */ 5.6 public abstract class Command { 5.7 - /** 5.8 - * Subclasses should define an execute method which will apply the 5.9 - * relevant change, if possible. 5.10 - * 5.11 - * @return The results of executing the command, if successful, or null if 5.12 - * the command does not need to return results. 5.13 - * @throws CommandFailedException if the command could not be completed. 5.14 - */ 5.15 - public abstract String execute() throws CommandFailedException; 5.16 + /** 5.17 + * Subclasses should define an execute method which will apply the 5.18 + * relevant change, if possible. 5.19 + * 5.20 + * @return The results of executing the command, if successful, or null if 5.21 + * the command does not need to return results. 5.22 + * @throws CommandFailedException if the command could not be completed. 5.23 + */ 5.24 + public abstract String execute() throws CommandFailedException; 5.25 5.26 - protected String reportCommand (String cmd_array[]) 5.27 - { 5.28 - StringBuffer sb = new StringBuffer(); 5.29 - int i; 5.30 - for (i = 0; i < cmd_array.length; i ++) { 5.31 - sb.append (cmd_array[i] + " "); 5.32 + /** 5.33 + * Construct a string to report the execution of a command. 5.34 + * @param cmd_array The array of command parameters. 5.35 + * @return The report string. 5.36 + */ 5.37 + protected String reportCommand(String[] cmd_array) { 5.38 + StringBuffer sb = new StringBuffer(); 5.39 + int i; 5.40 + for (i = 0; i < cmd_array.length; i++) { 5.41 + sb.append(cmd_array[i] + " "); 5.42 + } 5.43 + return sb.toString(); 5.44 } 5.45 - return sb.toString(); 5.46 - } 5.47 }
6.1 --- a/tools/control/src/org/xenoserver/control/CommandDomainDestroy.java Tue Jul 08 11:08:04 2003 +0000 6.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainDestroy.java Tue Jul 08 13:02:26 2003 +0000 6.3 @@ -4,55 +4,65 @@ package org.xenoserver.control; 6.4 * Destroys a domain. 6.5 */ 6.6 public class CommandDomainDestroy extends Command { 6.7 - private Defaults d; 6.8 - private int domain_id; 6.9 - private boolean force; 6.10 - 6.11 - /** 6.12 - * Constructor for CommandDomainDestroy. 6.13 - * 6.14 - * @param d Defaults object to use. 6.15 - * @param domain_id Domain ID number to destroy. 6.16 - * @param force Force destruction. 6.17 - */ 6.18 - public CommandDomainDestroy(Defaults d, int domain_id, boolean force) { 6.19 - this.d = d; 6.20 - this.domain_id = domain_id; 6.21 - this.force = force; 6.22 - } 6.23 - 6.24 - public String execute() throws CommandFailedException { 6.25 - Runtime r = Runtime.getRuntime(); 6.26 - String output = null; 6.27 + /** Defaults instance in use. */ 6.28 + private Defaults d; 6.29 + /** Domain ID to destroy. */ 6.30 + private int domain_id; 6.31 + /** Force destruction? */ 6.32 + private boolean force; 6.33 6.34 - try { 6.35 - Process destroy_p; 6.36 - String destroy_cmdarray[] = force ? new String[3] : new String[2]; 6.37 - int destroy_rc; 6.38 - int idx = 0; 6.39 - destroy_cmdarray[idx++] = d.XIToolsDir + "xi_destroy"; 6.40 - if (force) { 6.41 - destroy_cmdarray[idx++] = "-f"; 6.42 - } 6.43 - destroy_cmdarray[idx++] = "" + domain_id; 6.44 - 6.45 - if (Settings.TEST) { 6.46 - output = reportCommand(destroy_cmdarray); 6.47 - } else { 6.48 - destroy_p = r.exec(destroy_cmdarray); 6.49 - destroy_rc = destroy_p.waitFor(); 6.50 - 6.51 - if (destroy_rc != 0) { 6.52 - throw CommandFailedException.XICommandFailed("Could not destroy domain", destroy_cmdarray); 6.53 - } 6.54 - output = "Destroyed domain " + domain_id; 6.55 - } 6.56 - } catch (CommandFailedException e) { 6.57 - throw e; 6.58 - } catch (Exception e) { 6.59 - throw new CommandFailedException("Could not destroy domain (" + e + ")", e); 6.60 + /** 6.61 + * Constructor for CommandDomainDestroy. 6.62 + * 6.63 + * @param d Defaults object to use. 6.64 + * @param domain_id Domain ID number to destroy. 6.65 + * @param force Force destruction. 6.66 + */ 6.67 + public CommandDomainDestroy(Defaults d, int domain_id, boolean force) { 6.68 + this.d = d; 6.69 + this.domain_id = domain_id; 6.70 + this.force = force; 6.71 } 6.72 6.73 - return output; 6.74 - } 6.75 + /** 6.76 + * @see org.xenoserver.control.Command#execute() 6.77 + */ 6.78 + public String execute() throws CommandFailedException { 6.79 + Runtime r = Runtime.getRuntime(); 6.80 + String output = null; 6.81 + 6.82 + try { 6.83 + Process destroy_p; 6.84 + String destroy_cmdarray[] = force ? new String[3] : new String[2]; 6.85 + int destroy_rc; 6.86 + int idx = 0; 6.87 + destroy_cmdarray[idx++] = d.xiToolsDir + "xi_destroy"; 6.88 + if (force) { 6.89 + destroy_cmdarray[idx++] = "-f"; 6.90 + } 6.91 + destroy_cmdarray[idx++] = "" + domain_id; 6.92 + 6.93 + if (Settings.TEST) { 6.94 + output = reportCommand(destroy_cmdarray); 6.95 + } else { 6.96 + destroy_p = r.exec(destroy_cmdarray); 6.97 + destroy_rc = destroy_p.waitFor(); 6.98 + 6.99 + if (destroy_rc != 0) { 6.100 + throw CommandFailedException.xiCommandFailed( 6.101 + "Could not destroy domain", 6.102 + destroy_cmdarray); 6.103 + } 6.104 + output = "Destroyed domain " + domain_id; 6.105 + } 6.106 + } catch (CommandFailedException e) { 6.107 + throw e; 6.108 + } catch (Exception e) { 6.109 + throw new CommandFailedException( 6.110 + "Could not destroy domain (" + e + ")", 6.111 + e); 6.112 + } 6.113 + 6.114 + return output; 6.115 + } 6.116 }
7.1 --- a/tools/control/src/org/xenoserver/control/CommandDomainList.java Tue Jul 08 11:08:04 2003 +0000 7.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainList.java Tue Jul 08 13:02:26 2003 +0000 7.3 @@ -10,98 +10,109 @@ import java.util.Vector; 7.4 * domains() to get the array of domains. 7.5 */ 7.6 public class CommandDomainList extends Command { 7.7 - private Defaults d; 7.8 - private Domain[] array; 7.9 + /** Defaults instance in use. */ 7.10 + private Defaults d; 7.11 + /** Array of domains returned. */ 7.12 + private Domain[] array; 7.13 + 7.14 + /** 7.15 + * Constructor for CommandDomainList. 7.16 + * @param d Defaults object to use. 7.17 + */ 7.18 + public CommandDomainList(Defaults d) { 7.19 + this.d = d; 7.20 + } 7.21 7.22 - /** 7.23 - * Constructor for CommandDomainList. 7.24 - * @param d Defaults object to use. 7.25 - */ 7.26 - public CommandDomainList(Defaults d) { 7.27 - this.d = d; 7.28 - } 7.29 + /** 7.30 + * Retrieves the list of domains. 7.31 + * @return null, call domains() to get the list. 7.32 + * @throws CommandFailedException if the list could not be retrieved. 7.33 + */ 7.34 + public String execute() throws CommandFailedException { 7.35 + Runtime r = Runtime.getRuntime(); 7.36 + Vector v = new Vector(); 7.37 + String outline; 7.38 + BufferedReader in; 7.39 + String output = null; 7.40 + 7.41 + try { 7.42 + Process start_p; 7.43 + String start_cmdarray[] = new String[1]; 7.44 + int start_rc; 7.45 + start_cmdarray[0] = d.xiToolsDir + "xi_list"; 7.46 + 7.47 + if (Settings.TEST) { 7.48 + output = reportCommand(start_cmdarray); 7.49 + } else { 7.50 + start_p = r.exec(start_cmdarray); 7.51 + start_rc = start_p.waitFor(); 7.52 + if (start_rc != 0) { 7.53 + throw CommandFailedException.xiCommandFailed( 7.54 + "Could not get domain list", 7.55 + start_cmdarray); 7.56 + } 7.57 + 7.58 + in = 7.59 + new BufferedReader( 7.60 + new InputStreamReader(start_p.getInputStream())); 7.61 7.62 - /** 7.63 - * Retrieves the list of domains. 7.64 - * @return null, call domains() to get the list. 7.65 - */ 7.66 - public String execute() throws CommandFailedException { 7.67 - Runtime r = Runtime.getRuntime(); 7.68 - Vector v = new Vector(); 7.69 - String outline; 7.70 - BufferedReader in; 7.71 - String output = null; 7.72 + outline = in.readLine(); 7.73 + while (outline != null) { 7.74 + Domain domain = new Domain(); 7.75 7.76 - try { 7.77 - Process start_p; 7.78 - String start_cmdarray[] = new String[1]; 7.79 - int start_rc; 7.80 - start_cmdarray[0] = d.XIToolsDir + "xi_list"; 7.81 + StringTokenizer st = new StringTokenizer(outline); 7.82 + if (st.hasMoreTokens()) { 7.83 + domain.id = Integer.parseInt(st.nextToken()); 7.84 + } 7.85 + if (st.hasMoreTokens()) { 7.86 + domain.processor = Integer.parseInt(st.nextToken()); 7.87 + } 7.88 + if (st.hasMoreTokens()) { 7.89 + if (st.nextToken().equals("1")) { 7.90 + domain.cpu = true; 7.91 + } else { 7.92 + domain.cpu = false; 7.93 + } 7.94 + } 7.95 + if (st.hasMoreTokens()) { 7.96 + domain.nstate = Integer.parseInt(st.nextToken()); 7.97 + } 7.98 + if (st.hasMoreTokens()) { 7.99 + domain.state = st.nextToken().toLowerCase(); 7.100 + } 7.101 + if (st.hasMoreTokens()) { 7.102 + domain.mcu = Integer.parseInt(st.nextToken()); 7.103 + } 7.104 + if (st.hasMoreTokens()) { 7.105 + domain.pages = Integer.parseInt(st.nextToken()); 7.106 + } 7.107 + if (st.hasMoreTokens()) { 7.108 + domain.name = st.nextToken(); 7.109 + } 7.110 7.111 - if (Settings.TEST) { 7.112 - output = reportCommand(start_cmdarray); 7.113 - } else { 7.114 - start_p = r.exec(start_cmdarray); 7.115 - start_rc = start_p.waitFor(); 7.116 - if (start_rc != 0) { 7.117 - throw CommandFailedException.XICommandFailed("Could not get domain list", start_cmdarray); 7.118 + v.add(domain); 7.119 + 7.120 + outline = in.readLine(); 7.121 + } 7.122 + 7.123 + } 7.124 + } catch (CommandFailedException e) { 7.125 + throw e; 7.126 + } catch (Exception e) { 7.127 + throw new CommandFailedException( 7.128 + "Could not get domain list(" + e + ")", 7.129 + e); 7.130 } 7.131 7.132 - in = 7.133 - new BufferedReader(new InputStreamReader(start_p.getInputStream())); 7.134 - 7.135 - outline = in.readLine(); 7.136 - while (outline != null) { 7.137 - Domain domain = new Domain(); 7.138 - 7.139 - StringTokenizer st = new StringTokenizer(outline); 7.140 - if (st.hasMoreTokens()) { 7.141 - domain.id = Integer.parseInt(st.nextToken()); 7.142 - } 7.143 - if (st.hasMoreTokens()) { 7.144 - domain.processor = Integer.parseInt(st.nextToken()); 7.145 - } 7.146 - if (st.hasMoreTokens()) { 7.147 - if (st.nextToken().equals("1")) { 7.148 - domain.cpu = true; 7.149 - } else { 7.150 - domain.cpu = false; 7.151 - } 7.152 - } 7.153 - if (st.hasMoreTokens()) { 7.154 - domain.nstate = Integer.parseInt(st.nextToken()); 7.155 - } 7.156 - if (st.hasMoreTokens()) { 7.157 - domain.state = st.nextToken().toLowerCase(); 7.158 - } 7.159 - if (st.hasMoreTokens()) { 7.160 - domain.mcu = Integer.parseInt(st.nextToken()); 7.161 - } 7.162 - if (st.hasMoreTokens()) { 7.163 - domain.pages = Integer.parseInt(st.nextToken()); 7.164 - } 7.165 - if (st.hasMoreTokens()) { 7.166 - domain.name = st.nextToken(); 7.167 - } 7.168 - 7.169 - v.add(domain); 7.170 - 7.171 - outline = in.readLine(); 7.172 - } 7.173 - 7.174 - } 7.175 - } catch (CommandFailedException e) { 7.176 - throw e; 7.177 - } catch (Exception e) { 7.178 - throw new CommandFailedException("Could not get domain list(" + e + ")", e); 7.179 + array = new Domain[v.size()]; 7.180 + v.toArray(array); 7.181 + return output; 7.182 } 7.183 7.184 - array = new Domain[v.size()]; 7.185 - v.toArray(array); 7.186 - return output; 7.187 - } 7.188 - 7.189 - public Domain[] domains() { 7.190 - return array; 7.191 - } 7.192 + /** 7.193 + * @return Array of domains. 7.194 + */ 7.195 + public Domain[] domains() { 7.196 + return array; 7.197 + } 7.198 }
8.1 --- a/tools/control/src/org/xenoserver/control/CommandDomainNew.java Tue Jul 08 11:08:04 2003 +0000 8.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainNew.java Tue Jul 08 13:02:26 2003 +0000 8.3 @@ -15,287 +15,339 @@ import java.util.zip.GZIPInputStream; 8.4 * call output() to get an array of strings. 8.5 */ 8.6 public class CommandDomainNew extends Command { 8.7 - private Defaults d; 8.8 - private String name; 8.9 - private int size; 8.10 - private String image; 8.11 - private String initrd; 8.12 - private int vifs; 8.13 - private String bargs; 8.14 - private String root_dev; 8.15 - private String nfs_root_path; 8.16 - private String nw_ip; 8.17 - private String nw_gw; 8.18 - private String nw_mask; 8.19 - private String nw_nfs_server; 8.20 - private String nw_host; 8.21 - private String[] output; 8.22 - 8.23 - public String[] output() { 8.24 - return output; 8.25 - } 8.26 - 8.27 - /** 8.28 - * Constructor for CommandDomainNew. 8.29 - * @param d Defaults object to use. 8.30 - * @param name Name for the domain. 8.31 - * @param size Memory size for the domain. 8.32 - * @param image Image to boot domain from. 8.33 - * @param initrd Initrd to boot domain with. 8.34 - * @param vifs Number of virtual interfaces for the domain. 8.35 - * @param bargs Boot arguments for the domain. 8.36 - * @param root_dev Root device for the domain. 8.37 - * @param nfs_root_path NFS root to be used by the domain. 8.38 - * @param nw_ip IP address pattern to use for the domain's interfaces. 8.39 - * @param nw_gw Gateway to configure the domain for. 8.40 - * @param nw_mask Network mask to configure the domain for. 8.41 - * @param nw_nfs_server NFS server to be used by the domain. 8.42 - * @param nw_host Hostname to be used by the domain. 8.43 - */ 8.44 - public CommandDomainNew( 8.45 - Defaults d, 8.46 - String name, 8.47 - int size, 8.48 - String image, 8.49 - String initrd, 8.50 - int vifs, 8.51 - String bargs, 8.52 - String root_dev, 8.53 - String nfs_root_path, 8.54 - String nw_ip, 8.55 - String nw_gw, 8.56 - String nw_mask, 8.57 - String nw_nfs_server, 8.58 - String nw_host) { 8.59 - this.d = d; 8.60 - this.name = name; 8.61 - this.size = size; 8.62 - this.image = image; 8.63 - this.initrd = initrd; 8.64 - this.vifs = vifs; 8.65 - this.bargs = bargs; 8.66 - this.root_dev = root_dev; 8.67 - this.nfs_root_path = nfs_root_path; 8.68 - this.nw_ip = nw_ip; 8.69 - this.nw_gw = nw_gw; 8.70 - this.nw_mask = nw_mask; 8.71 - this.nw_nfs_server = nw_nfs_server; 8.72 - this.nw_host = nw_host; 8.73 - } 8.74 + /** Defaults instance in use. */ 8.75 + private Defaults d; 8.76 + /** Name of new domain. */ 8.77 + private String name; 8.78 + /** Memory size for new domain. */ 8.79 + private int size; 8.80 + /** Kernel image */ 8.81 + private String image; 8.82 + /** Initial ramdisk */ 8.83 + private String initrd; 8.84 + /** Num of virtual interfaces */ 8.85 + private int vifs; 8.86 + /** Boot arguments */ 8.87 + private String bargs; 8.88 + /** Root device */ 8.89 + private String root_dev; 8.90 + /** NFS root path */ 8.91 + private String nfs_root_path; 8.92 + /** IP address */ 8.93 + private String nw_ip; 8.94 + /** Gateway */ 8.95 + private String nw_gw; 8.96 + /** netmask */ 8.97 + private String nw_mask; 8.98 + /** NFS server */ 8.99 + private String nw_nfs_server; 8.100 + /** Hostname */ 8.101 + private String nw_host; 8.102 + /** Output from domain creation */ 8.103 + private String[] output; 8.104 + 8.105 + /** 8.106 + * @return Output from domain creation. 8.107 + */ 8.108 + public String[] output() { 8.109 + return output; 8.110 + } 8.111 + 8.112 + /** 8.113 + * Constructor for CommandDomainNew. 8.114 + * @param d Defaults object to use. 8.115 + * @param name Name for the domain. 8.116 + * @param size Memory size for the domain. 8.117 + * @param image Image to boot domain from. 8.118 + * @param initrd Initrd to boot domain with. 8.119 + * @param vifs Number of virtual interfaces for the domain. 8.120 + * @param bargs Boot arguments for the domain. 8.121 + * @param root_dev Root device for the domain. 8.122 + * @param nfs_root_path NFS root to be used by the domain. 8.123 + * @param nw_ip IP address pattern to use for the domain's interfaces. 8.124 + * @param nw_gw Gateway to configure the domain for. 8.125 + * @param nw_mask Network mask to configure the domain for. 8.126 + * @param nw_nfs_server NFS server to be used by the domain. 8.127 + * @param nw_host Hostname to be used by the domain. 8.128 + */ 8.129 + public CommandDomainNew( 8.130 + Defaults d, 8.131 + String name, 8.132 + int size, 8.133 + String image, 8.134 + String initrd, 8.135 + int vifs, 8.136 + String bargs, 8.137 + String root_dev, 8.138 + String nfs_root_path, 8.139 + String nw_ip, 8.140 + String nw_gw, 8.141 + String nw_mask, 8.142 + String nw_nfs_server, 8.143 + String nw_host) { 8.144 + this.d = d; 8.145 + this.name = name; 8.146 + this.size = size; 8.147 + this.image = image; 8.148 + this.initrd = initrd; 8.149 + this.vifs = vifs; 8.150 + this.bargs = bargs; 8.151 + this.root_dev = root_dev; 8.152 + this.nfs_root_path = nfs_root_path; 8.153 + this.nw_ip = nw_ip; 8.154 + this.nw_gw = nw_gw; 8.155 + this.nw_mask = nw_mask; 8.156 + this.nw_nfs_server = nw_nfs_server; 8.157 + this.nw_host = nw_host; 8.158 + } 8.159 + 8.160 + /** 8.161 + * @see org.xenoserver.control.Command#execute() 8.162 + */ 8.163 + public String execute() throws CommandFailedException { 8.164 + Runtime r = Runtime.getRuntime(); 8.165 + int domain_id = -1; 8.166 + BufferedReader br; 8.167 + int idx; 8.168 + int i; 8.169 + File image_tmp = null; 8.170 + File initrd_tmp = null; 8.171 + String domain_ip = ""; 8.172 + 8.173 + String create_cmdarray[] = new String[3]; 8.174 + String build_cmdarray[] = new String[6]; 8.175 + String vifinit_cmdarray[] = new String[4]; 8.176 + 8.177 + try { 8.178 + try { 8.179 + /* Some initial sanity checks */ 8.180 + if (root_dev.equals("/dev/nfs") && (vifs == 0)) { 8.181 + throw new CommandFailedException("Cannot use NFS root without VIFs configured"); 8.182 + } 8.183 + 8.184 + /* Uncompress the image and initrd */ 8.185 + if (image.endsWith(".gz")) { 8.186 + image_tmp = getUncompressed("xen-image-", image); 8.187 + image = image_tmp.getPath(); 8.188 + } 8.189 + 8.190 + if (initrd != null && initrd.endsWith(".gz")) { 8.191 + initrd_tmp = getUncompressed("xen-initrd-", initrd); 8.192 + initrd = initrd_tmp.getPath(); 8.193 + } 8.194 + 8.195 + /* Create a new empty domain */ 8.196 + Process create_p; 8.197 + int create_rc; 8.198 + create_cmdarray[0] = d.xiToolsDir + "xi_create"; 8.199 + create_cmdarray[1] = "" + size; 8.200 + create_cmdarray[2] = name; 8.201 + if (Settings.TEST) { 8.202 + reportCommand(create_cmdarray); 8.203 + domain_id = 1; 8.204 + create_rc = 0; 8.205 + } else { 8.206 + create_p = r.exec(create_cmdarray); 8.207 + br = 8.208 + new BufferedReader( 8.209 + new InputStreamReader(create_p.getInputStream())); 8.210 + domain_id = Integer.parseInt(br.readLine()); 8.211 + create_rc = create_p.waitFor(); 8.212 + } 8.213 8.214 - public String execute() throws CommandFailedException { 8.215 - Runtime r = Runtime.getRuntime(); 8.216 - int domain_id = -1; 8.217 - BufferedReader br; 8.218 - int idx; 8.219 - int i; 8.220 - File image_tmp = null; 8.221 - File initrd_tmp = null; 8.222 - String domain_ip = ""; 8.223 - 8.224 - String create_cmdarray[] = new String[3]; 8.225 - String build_cmdarray[] = new String[6]; 8.226 - String vifinit_cmdarray[] = new String[4]; 8.227 + if (create_rc != 0) { 8.228 + throw CommandFailedException.xiCommandFailed( 8.229 + "Failed to create domain", 8.230 + create_cmdarray); 8.231 + } else if (domain_id > d.maxDomainNumber) { 8.232 + throw new CommandFailedException( 8.233 + "Cannot configure more than " 8.234 + + d.maxDomainNumber 8.235 + + " domains"); 8.236 + } 8.237 8.238 - try { 8.239 - try { 8.240 - /* Some initial sanity checks */ 8.241 - if (root_dev.equals("/dev/nfs") && (vifs == 0)) { 8.242 - throw new CommandFailedException("Cannot use NFS root without VIFs configured"); 8.243 - } 8.244 + /* Set up boot parameters to pass to xi_build. */ 8.245 + if (root_dev.equals("/dev/nfs")) { 8.246 + if (vifs == 0) { 8.247 + throw new CommandFailedException("Cannot use NFS root without VIFs configured"); 8.248 + } 8.249 + if (nfs_root_path == null) { 8.250 + throw new CommandFailedException("No NFS root specified"); 8.251 + } 8.252 + if (nw_nfs_server == null) { 8.253 + throw new CommandFailedException("No NFS server specified"); 8.254 + } 8.255 + bargs = 8.256 + (bargs 8.257 + + " root=/dev/nfs " 8.258 + + "nfsroot=" 8.259 + + StringPattern.parse(nfs_root_path).resolve( 8.260 + domain_id) 8.261 + + " "); 8.262 + } else { 8.263 + bargs = 8.264 + (bargs 8.265 + + " root=" 8.266 + + StringPattern.parse(root_dev).resolve(domain_id) 8.267 + + " "); 8.268 8.269 - /* Uncompress the image and initrd */ 8.270 - if (image.endsWith(".gz")) { 8.271 - image_tmp = getUncompressed("xen-image-", image); 8.272 - image = image_tmp.getPath(); 8.273 - } 8.274 + } 8.275 + 8.276 + if (vifs > 0) { 8.277 + domain_ip = 8.278 + InetAddressPattern.parse(nw_ip).resolve(domain_id); 8.279 + if (nw_host == null) { 8.280 + try { 8.281 + nw_host = 8.282 + InetAddress.getByName(domain_ip).getHostName(); 8.283 + } catch (UnknownHostException uhe) { 8.284 + nw_host = "" + nw_ip; 8.285 + } 8.286 8.287 - if (initrd != null && initrd.endsWith(".gz")) { 8.288 - initrd_tmp = getUncompressed("xen-initrd-", initrd); 8.289 - initrd = initrd_tmp.getPath(); 8.290 - } 8.291 + } 8.292 + bargs = 8.293 + ("ip=" 8.294 + + domain_ip 8.295 + + ":" 8.296 + + ((nw_nfs_server == null) 8.297 + ? "" 8.298 + : (InetAddressPattern 8.299 + .parse(nw_nfs_server) 8.300 + .resolve(domain_id))) 8.301 + + ":" 8.302 + + ((nw_gw == null) 8.303 + ? "" 8.304 + : (InetAddressPattern 8.305 + .parse(nw_gw) 8.306 + .resolve(domain_id))) 8.307 + + ":" 8.308 + + ((nw_mask == null) 8.309 + ? "" 8.310 + : InetAddressPattern.parse(nw_mask).resolve( 8.311 + domain_id)) 8.312 + + ":" 8.313 + + ((nw_host == null) ? "" : nw_host) 8.314 + + ":eth0:off " 8.315 + + bargs); 8.316 + } 8.317 8.318 - /* Create a new empty domain */ 8.319 - Process create_p; 8.320 - int create_rc; 8.321 - create_cmdarray[0] = d.XIToolsDir + "xi_create"; 8.322 - create_cmdarray[1] = "" + size; 8.323 - create_cmdarray[2] = name; 8.324 - if (Settings.TEST) { 8.325 - reportCommand(create_cmdarray); 8.326 - domain_id = 1; 8.327 - create_rc = 0; 8.328 - } else { 8.329 - create_p = r.exec(create_cmdarray); 8.330 - br = 8.331 - new BufferedReader( 8.332 - new InputStreamReader(create_p.getInputStream())); 8.333 - domain_id = Integer.parseInt(br.readLine()); 8.334 - create_rc = create_p.waitFor(); 8.335 - } 8.336 + /* Build the domain */ 8.337 + Process build_p; 8.338 + int build_rc; 8.339 + idx = 0; 8.340 + for (i = 0; i < build_cmdarray.length; i++) { 8.341 + build_cmdarray[i] = ""; 8.342 + } 8.343 + build_cmdarray[idx++] = d.xiToolsDir + "xi_build"; 8.344 + build_cmdarray[idx++] = "" + domain_id; 8.345 + build_cmdarray[idx++] = "" + image; 8.346 + build_cmdarray[idx++] = "" + vifs; 8.347 + if (initrd != null) { 8.348 + build_cmdarray[idx++] = "initrd=" + initrd; 8.349 + } 8.350 + build_cmdarray[idx++] = "" + bargs; 8.351 + if (Settings.TEST) { 8.352 + reportCommand(build_cmdarray); 8.353 + build_rc = 0; 8.354 + } else { 8.355 + build_p = r.exec(build_cmdarray); 8.356 + build_rc = build_p.waitFor(); 8.357 + } 8.358 + 8.359 + if (build_rc != 0) { 8.360 + throw CommandFailedException.xiCommandFailed( 8.361 + "Failed to build domain", 8.362 + build_cmdarray); 8.363 + } 8.364 8.365 - if (create_rc != 0) { 8.366 - throw CommandFailedException.XICommandFailed("Failed to create domain", create_cmdarray); 8.367 - } else if (domain_id > d.MaxDomainNumber) { 8.368 - throw new CommandFailedException( 8.369 - "Cannot configure more than " + d.MaxDomainNumber + " domains"); 8.370 + /* Set up the first VIF if necessary */ 8.371 + if (vifs > 0) { 8.372 + Process vifinit_p; 8.373 + int vifinit_rc; 8.374 + vifinit_cmdarray[0] = d.xiToolsDir + "xi_vifinit"; 8.375 + vifinit_cmdarray[1] = "" + domain_id; 8.376 + vifinit_cmdarray[2] = "0"; 8.377 + vifinit_cmdarray[3] = domain_ip; 8.378 + if (Settings.TEST) { 8.379 + reportCommand(vifinit_cmdarray); 8.380 + vifinit_rc = 0; 8.381 + } else { 8.382 + vifinit_p = r.exec(vifinit_cmdarray); 8.383 + vifinit_rc = vifinit_p.waitFor(); 8.384 + } 8.385 + 8.386 + if (vifinit_rc != 0) { 8.387 + throw CommandFailedException.xiCommandFailed( 8.388 + "Failed to initialise VIF 0", 8.389 + vifinit_cmdarray); 8.390 + } 8.391 + } 8.392 + } finally { 8.393 + if (image_tmp != null) { 8.394 + image_tmp.delete(); 8.395 + } 8.396 + if (initrd_tmp != null) { 8.397 + initrd_tmp.delete(); 8.398 + } 8.399 + } 8.400 + } catch (CommandFailedException e) { 8.401 + throw e; 8.402 + } catch (Exception e) { 8.403 + throw new CommandFailedException( 8.404 + "Could not create new domain (" + e + ")", 8.405 + e); 8.406 } 8.407 8.408 - /* Set up boot parameters to pass to xi_build. */ 8.409 - if (root_dev.equals("/dev/nfs")) { 8.410 - if (vifs == 0) { 8.411 - throw new CommandFailedException("Cannot use NFS root without VIFs configured"); 8.412 - } 8.413 - if (nfs_root_path == null) { 8.414 - throw new CommandFailedException("No NFS root specified"); 8.415 - } 8.416 - if (nw_nfs_server == null) { 8.417 - throw new CommandFailedException("No NFS server specified"); 8.418 - } 8.419 - bargs = 8.420 - (bargs 8.421 - + " root=/dev/nfs " 8.422 - + "nfsroot=" 8.423 - + StringPattern.parse(nfs_root_path).resolve(domain_id) 8.424 - + " "); 8.425 - } else { 8.426 - bargs = 8.427 - (bargs 8.428 - + " root=" 8.429 - + StringPattern.parse(root_dev).resolve(domain_id) 8.430 - + " "); 8.431 - 8.432 + output = new String[vifs > 0 ? 6 : 4]; 8.433 + output[0] = "Domain created with arguments:"; 8.434 + output[1] = ""; 8.435 + for (i = 0; i < create_cmdarray.length; i++) { 8.436 + output[1] += create_cmdarray[i] + " "; 8.437 } 8.438 - 8.439 + output[2] = "Domain built with arguments:"; 8.440 + output[3] = ""; 8.441 + for (i = 0; i < build_cmdarray.length; i++) { 8.442 + output[3] += build_cmdarray[i] + " "; 8.443 + } 8.444 if (vifs > 0) { 8.445 - domain_ip = InetAddressPattern.parse(nw_ip).resolve(domain_id); 8.446 - if (nw_host == null) { 8.447 - try { 8.448 - nw_host = InetAddress.getByName(domain_ip).getHostName(); 8.449 - } catch (UnknownHostException uhe) { 8.450 - nw_host = "" + nw_ip; 8.451 + output[4] = "VIF 0 initialized with arguments:"; 8.452 + output[5] = ""; 8.453 + for (i = 0; i < vifinit_cmdarray.length; i++) { 8.454 + output[5] += vifinit_cmdarray[i] + " "; 8.455 } 8.456 - 8.457 - } 8.458 - bargs = 8.459 - ("ip=" 8.460 - + domain_ip 8.461 - + ":" 8.462 - + ((nw_nfs_server == null) 8.463 - ? "" 8.464 - : (InetAddressPattern.parse(nw_nfs_server).resolve(domain_id))) 8.465 - + ":" 8.466 - + ((nw_gw == null) 8.467 - ? "" 8.468 - : (InetAddressPattern.parse(nw_gw).resolve(domain_id))) 8.469 - + ":" 8.470 - + ((nw_mask == null) 8.471 - ? "" 8.472 - : InetAddressPattern.parse(nw_mask).resolve(domain_id)) 8.473 - + ":" 8.474 - + ((nw_host == null) ? "" : nw_host) 8.475 - + ":eth0:off " 8.476 - + bargs); 8.477 - } 8.478 - 8.479 - /* Build the domain */ 8.480 - Process build_p; 8.481 - int build_rc; 8.482 - idx = 0; 8.483 - for (i = 0; i < build_cmdarray.length; i++) 8.484 - build_cmdarray[i] = ""; 8.485 - build_cmdarray[idx++] = d.XIToolsDir + "xi_build"; 8.486 - build_cmdarray[idx++] = "" + domain_id; 8.487 - build_cmdarray[idx++] = "" + image; 8.488 - build_cmdarray[idx++] = "" + vifs; 8.489 - if (initrd != null) 8.490 - build_cmdarray[idx++] = "initrd=" + initrd; 8.491 - build_cmdarray[idx++] = "" + bargs; 8.492 - if (Settings.TEST) { 8.493 - reportCommand(build_cmdarray); 8.494 - build_rc = 0; 8.495 - } else { 8.496 - build_p = r.exec(build_cmdarray); 8.497 - build_rc = build_p.waitFor(); 8.498 } 8.499 8.500 - if (build_rc != 0) { 8.501 - throw CommandFailedException.XICommandFailed("Failed to build domain", build_cmdarray); 8.502 - } 8.503 - 8.504 - /* Set up the first VIF if necessary */ 8.505 - if (vifs > 0) { 8.506 - Process vifinit_p; 8.507 - int vifinit_rc; 8.508 - vifinit_cmdarray[0] = d.XIToolsDir + "xi_vifinit"; 8.509 - vifinit_cmdarray[1] = "" + domain_id; 8.510 - vifinit_cmdarray[2] = "0"; 8.511 - vifinit_cmdarray[3] = domain_ip; 8.512 - if (Settings.TEST) { 8.513 - reportCommand(vifinit_cmdarray); 8.514 - vifinit_rc = 0; 8.515 - } else { 8.516 - vifinit_p = r.exec(vifinit_cmdarray); 8.517 - vifinit_rc = vifinit_p.waitFor(); 8.518 - } 8.519 - 8.520 - if (vifinit_rc != 0) { 8.521 - throw CommandFailedException.XICommandFailed( 8.522 - "Failed to initialise VIF 0", 8.523 - vifinit_cmdarray); 8.524 - } 8.525 - } 8.526 - } finally { 8.527 - if (image_tmp != null) 8.528 - image_tmp.delete(); 8.529 - if (initrd_tmp != null) 8.530 - initrd_tmp.delete(); 8.531 - } 8.532 - } catch (CommandFailedException e) { 8.533 - throw e; 8.534 - } catch (Exception e) { 8.535 - throw new CommandFailedException("Could not create new domain (" + e + ")", e); 8.536 + return null; 8.537 } 8.538 8.539 - output = new String[ vifs > 0 ? 6 : 4 ]; 8.540 - output[0] = "Domain created with arguments:"; 8.541 - output[1] = ""; 8.542 - for (i = 0; i < create_cmdarray.length; i++) 8.543 - output[1] += create_cmdarray[i] + " "; 8.544 - output[2] = "Domain built with arguments:"; 8.545 - output[3] = ""; 8.546 - for (i = 0; i < build_cmdarray.length; i++) 8.547 - output[3] += build_cmdarray[i] + " "; 8.548 - if ( vifs > 0 ) { 8.549 - output[4] = "VIF 0 initialized with arguments:"; 8.550 - output[5] = ""; 8.551 - for (i = 0; i < vifinit_cmdarray.length; i++) 8.552 - output[5] += vifinit_cmdarray[i] + " "; 8.553 - } 8.554 + /** 8.555 + * Get uncompressed version of file. 8.556 + * @param prefix Temp file prefix. 8.557 + * @param original Original filename. 8.558 + * @return Uncompressed file. 8.559 + * @throws IOException if decompression failed. 8.560 + */ 8.561 + private File getUncompressed(String prefix, String original) 8.562 + throws IOException { 8.563 + FileOutputStream fos; 8.564 + GZIPInputStream gis; 8.565 + File result; 8.566 + byte buffer[] = new byte[1024]; 8.567 + int l; 8.568 8.569 - return null; 8.570 - } 8.571 - 8.572 - private File getUncompressed (String prefix, String original) throws IOException { 8.573 - FileOutputStream fos; 8.574 - GZIPInputStream gis; 8.575 - File result; 8.576 - byte buffer[] = new byte[1024]; 8.577 - int l; 8.578 - 8.579 - result = File.createTempFile (prefix, null); 8.580 - 8.581 - try { 8.582 - fos = new FileOutputStream (result); 8.583 - gis = new GZIPInputStream (new FileInputStream (original)); 8.584 - while ((l = gis.read(buffer, 0, buffer.length)) != -1) { 8.585 - fos.write (buffer, 0, l); 8.586 - } 8.587 - } catch (IOException ioe) { 8.588 - result.delete (); 8.589 - throw ioe; 8.590 + result = File.createTempFile(prefix, null); 8.591 + 8.592 + try { 8.593 + fos = new FileOutputStream(result); 8.594 + gis = new GZIPInputStream(new FileInputStream(original)); 8.595 + while ((l = gis.read(buffer, 0, buffer.length)) != -1) { 8.596 + fos.write(buffer, 0, l); 8.597 + } 8.598 + } catch (IOException ioe) { 8.599 + result.delete(); 8.600 + throw ioe; 8.601 + } 8.602 + 8.603 + return result; 8.604 } 8.605 - 8.606 - return result; 8.607 - } 8.608 }
9.1 --- a/tools/control/src/org/xenoserver/control/CommandDomainStart.java Tue Jul 08 11:08:04 2003 +0000 9.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainStart.java Tue Jul 08 13:02:26 2003 +0000 9.3 @@ -4,46 +4,55 @@ package org.xenoserver.control; 9.4 * Starts a domain. 9.5 */ 9.6 public class CommandDomainStart extends Command { 9.7 - private Defaults d; 9.8 - private int domain_id; 9.9 - 9.10 - /** 9.11 - * Constructor for CommandDomainStart. 9.12 - * @param d Defaults object to use. 9.13 - * @param domain_id Domain to start. 9.14 - */ 9.15 - public CommandDomainStart(Defaults d, int domain_id) { 9.16 - this.d = d; 9.17 - this.domain_id = domain_id; 9.18 - } 9.19 - 9.20 - public String execute() throws CommandFailedException { 9.21 - Runtime r = Runtime.getRuntime(); 9.22 - String output = null; 9.23 - 9.24 - try { 9.25 - Process start_p; 9.26 - String start_cmdarray[] = new String[2]; 9.27 - int start_rc; 9.28 - start_cmdarray[0] = d.XIToolsDir + "xi_start"; 9.29 - start_cmdarray[1] = "" + domain_id; 9.30 - 9.31 - if (Settings.TEST) { 9.32 - output = reportCommand(start_cmdarray); 9.33 - } else { 9.34 - start_p = r.exec(start_cmdarray); 9.35 - start_rc = start_p.waitFor(); 9.36 - if (start_rc != 0) { 9.37 - throw CommandFailedException.XICommandFailed("Could not start domain", start_cmdarray); 9.38 - } 9.39 - output = "Started domain " + domain_id; 9.40 - } 9.41 - } catch (CommandFailedException e) { 9.42 - throw e; 9.43 - } catch (Exception e) { 9.44 - throw new CommandFailedException("Could not start new domain (" + e + ")", e); 9.45 + /** Defaults instance in use. */ 9.46 + private Defaults d; 9.47 + /** Domain ID to start */ 9.48 + private int domain_id; 9.49 + 9.50 + /** 9.51 + * Constructor for CommandDomainStart. 9.52 + * @param d Defaults object to use. 9.53 + * @param domain_id Domain to start. 9.54 + */ 9.55 + public CommandDomainStart(Defaults d, int domain_id) { 9.56 + this.d = d; 9.57 + this.domain_id = domain_id; 9.58 } 9.59 9.60 - return output; 9.61 - } 9.62 + /** 9.63 + * @see org.xenoserver.control.Command#execute() 9.64 + */ 9.65 + public String execute() throws CommandFailedException { 9.66 + Runtime r = Runtime.getRuntime(); 9.67 + String output = null; 9.68 + 9.69 + try { 9.70 + Process start_p; 9.71 + String start_cmdarray[] = new String[2]; 9.72 + int start_rc; 9.73 + start_cmdarray[0] = d.xiToolsDir + "xi_start"; 9.74 + start_cmdarray[1] = "" + domain_id; 9.75 + 9.76 + if (Settings.TEST) { 9.77 + output = reportCommand(start_cmdarray); 9.78 + } else { 9.79 + start_p = r.exec(start_cmdarray); 9.80 + start_rc = start_p.waitFor(); 9.81 + if (start_rc != 0) { 9.82 + throw CommandFailedException.xiCommandFailed( 9.83 + "Could not start domain", 9.84 + start_cmdarray); 9.85 + } 9.86 + output = "Started domain " + domain_id; 9.87 + } 9.88 + } catch (CommandFailedException e) { 9.89 + throw e; 9.90 + } catch (Exception e) { 9.91 + throw new CommandFailedException( 9.92 + "Could not start new domain (" + e + ")", 9.93 + e); 9.94 + } 9.95 + 9.96 + return output; 9.97 + } 9.98 }
10.1 --- a/tools/control/src/org/xenoserver/control/CommandDomainStop.java Tue Jul 08 11:08:04 2003 +0000 10.2 +++ b/tools/control/src/org/xenoserver/control/CommandDomainStop.java Tue Jul 08 13:02:26 2003 +0000 10.3 @@ -4,47 +4,56 @@ package org.xenoserver.control; 10.4 * Stops a domain. 10.5 */ 10.6 public class CommandDomainStop extends Command { 10.7 - private Defaults d; 10.8 - private int domain_id; 10.9 - 10.10 - /** 10.11 - * Constructor for CommandDomainStop. 10.12 - * @param d The defaults object to use. 10.13 - * @param domain_id The domain to stop. 10.14 - */ 10.15 - public CommandDomainStop(Defaults d, int domain_id) { 10.16 - this.d = d; 10.17 - this.domain_id = domain_id; 10.18 - } 10.19 - 10.20 - public String execute() throws CommandFailedException { 10.21 - Runtime r = Runtime.getRuntime(); 10.22 - String output = null; 10.23 + /** Defaults instance in use */ 10.24 + private Defaults d; 10.25 + /** Domain ID to stop */ 10.26 + private int domain_id; 10.27 10.28 - try { 10.29 - Process stop_p; 10.30 - String stop_cmdarray[] = new String[2]; 10.31 - int stop_rc; 10.32 - stop_cmdarray[0] = d.XIToolsDir + "xi_stop"; 10.33 - stop_cmdarray[1] = "" + domain_id; 10.34 - 10.35 - if (Settings.TEST) { 10.36 - output = reportCommand(stop_cmdarray); 10.37 - } else { 10.38 - stop_p = r.exec(stop_cmdarray); 10.39 - stop_rc = stop_p.waitFor(); 10.40 - 10.41 - if (stop_rc != 0) { 10.42 - throw CommandFailedException.XICommandFailed("Could not stop domain", stop_cmdarray); 10.43 - } 10.44 - output = "Stopped domain " + domain_id; 10.45 - } 10.46 - } catch (CommandFailedException e) { 10.47 - throw e; 10.48 - } catch (Exception e) { 10.49 - throw new CommandFailedException("Could not stop new domain (" + e + ")", e); 10.50 + /** 10.51 + * Constructor for CommandDomainStop. 10.52 + * @param d The defaults object to use. 10.53 + * @param domain_id The domain to stop. 10.54 + */ 10.55 + public CommandDomainStop(Defaults d, int domain_id) { 10.56 + this.d = d; 10.57 + this.domain_id = domain_id; 10.58 } 10.59 10.60 - return output; 10.61 - } 10.62 + /** 10.63 + * @see org.xenoserver.control.Command#execute() 10.64 + */ 10.65 + public String execute() throws CommandFailedException { 10.66 + Runtime r = Runtime.getRuntime(); 10.67 + String output = null; 10.68 + 10.69 + try { 10.70 + Process stop_p; 10.71 + String stop_cmdarray[] = new String[2]; 10.72 + int stop_rc; 10.73 + stop_cmdarray[0] = d.xiToolsDir + "xi_stop"; 10.74 + stop_cmdarray[1] = "" + domain_id; 10.75 + 10.76 + if (Settings.TEST) { 10.77 + output = reportCommand(stop_cmdarray); 10.78 + } else { 10.79 + stop_p = r.exec(stop_cmdarray); 10.80 + stop_rc = stop_p.waitFor(); 10.81 + 10.82 + if (stop_rc != 0) { 10.83 + throw CommandFailedException.xiCommandFailed( 10.84 + "Could not stop domain", 10.85 + stop_cmdarray); 10.86 + } 10.87 + output = "Stopped domain " + domain_id; 10.88 + } 10.89 + } catch (CommandFailedException e) { 10.90 + throw e; 10.91 + } catch (Exception e) { 10.92 + throw new CommandFailedException( 10.93 + "Could not stop new domain (" + e + ")", 10.94 + e); 10.95 + } 10.96 + 10.97 + return output; 10.98 + } 10.99 }
11.1 --- a/tools/control/src/org/xenoserver/control/CommandFailedException.java Tue Jul 08 11:08:04 2003 +0000 11.2 +++ b/tools/control/src/org/xenoserver/control/CommandFailedException.java Tue Jul 08 13:02:26 2003 +0000 11.3 @@ -4,29 +4,38 @@ package org.xenoserver.control; 11.4 * Thrown to indicate that a command failed to execute. 11.5 */ 11.6 public class CommandFailedException extends Exception { 11.7 - public CommandFailedException() { 11.8 - super(); 11.9 - } 11.10 + /** 11.11 + * Construct an exception with a message. 11.12 + * @param message Message to use. 11.13 + */ 11.14 + public CommandFailedException(String message) { 11.15 + super(message); 11.16 + } 11.17 11.18 - public CommandFailedException(String message) { 11.19 - super(message); 11.20 - } 11.21 - 11.22 - public CommandFailedException(String message, Throwable cause) { 11.23 - super(message, cause); 11.24 - } 11.25 + /** 11.26 + * Construct an exception with a message and cause. 11.27 + * @param message Message to use. 11.28 + * @param cause Throwable cause. 11.29 + */ 11.30 + public CommandFailedException(String message, Throwable cause) { 11.31 + super(message, cause); 11.32 + } 11.33 11.34 - public CommandFailedException(Throwable cause) { 11.35 - super(cause); 11.36 - } 11.37 - 11.38 - public static CommandFailedException XICommandFailed(String message, String cmd_array[]) { 11.39 - StringBuffer sb = new StringBuffer(); 11.40 - int i; 11.41 - sb.append (message + " using: "); 11.42 - for (i = 0; i < cmd_array.length; i ++) { 11.43 - sb.append (cmd_array[i] + " "); 11.44 + /** 11.45 + * Construct an exception for an XI command failure. 11.46 + * @param message Message to use 11.47 + * @param cmd_array Command array used to invoke xi command 11.48 + * @return Suitable exception. 11.49 + */ 11.50 + public static CommandFailedException xiCommandFailed( 11.51 + String message, 11.52 + String cmd_array[]) { 11.53 + StringBuffer sb = new StringBuffer(); 11.54 + int i; 11.55 + sb.append(message + " using: "); 11.56 + for (i = 0; i < cmd_array.length; i++) { 11.57 + sb.append(cmd_array[i] + " "); 11.58 + } 11.59 + return new CommandFailedException(sb.toString()); 11.60 } 11.61 - return new CommandFailedException( sb.toString() ); 11.62 - } 11.63 }
12.1 --- a/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java Tue Jul 08 11:08:04 2003 +0000 12.2 +++ b/tools/control/src/org/xenoserver/control/CommandPartitionAdd.java Tue Jul 08 13:02:26 2003 +0000 12.3 @@ -1,22 +1,30 @@ 12.4 package org.xenoserver.control; 12.5 12.6 +/** 12.7 + * Add a disk partition to the VirtualDiskManager as a XenoPartition. 12.8 + */ 12.9 public class CommandPartitionAdd extends Command { 12.10 - private Partition partition; 12.11 - private long chunksize; 12.12 - 12.13 - /** 12.14 - * Constructor for CommandPartitionAdd. 12.15 - * @param partition Partition to add. 12.16 - * @param chunksize Chunk size to split partition into (in sectors). 12.17 - */ 12.18 - public CommandPartitionAdd(Partition partition, long chunksize) { 12.19 - this.partition = partition; 12.20 - this.chunksize = chunksize; 12.21 - } 12.22 + /** Partition to add as a XenoPartition. */ 12.23 + private Partition partition; 12.24 + /** Chunk size to split partition into (in sectors). */ 12.25 + private long chunksize; 12.26 12.27 - public String execute() throws CommandFailedException { 12.28 - VirtualDiskManager.IT.addPartition(partition,chunksize); 12.29 - PartitionManager.IT.addXenoPartition(partition); 12.30 - return "Added partition " + partition.getName(); 12.31 - } 12.32 + /** 12.33 + * Constructor for CommandPartitionAdd. 12.34 + * @param partition Partition to add. 12.35 + * @param chunksize Chunk size to split partition into (in sectors). 12.36 + */ 12.37 + public CommandPartitionAdd(Partition partition, long chunksize) { 12.38 + this.partition = partition; 12.39 + this.chunksize = chunksize; 12.40 + } 12.41 + 12.42 + /** 12.43 + * @see org.xenoserver.control.Command#execute() 12.44 + */ 12.45 + public String execute() throws CommandFailedException { 12.46 + VirtualDiskManager.IT.addPartition(partition, chunksize); 12.47 + PartitionManager.IT.addXenoPartition(partition); 12.48 + return "Added partition " + partition.getName(); 12.49 + } 12.50 }
13.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java Tue Jul 08 11:08:04 2003 +0000 13.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalGrant.java Tue Jul 08 13:02:26 2003 +0000 13.3 @@ -1,71 +1,84 @@ 13.4 package org.xenoserver.control; 13.5 13.6 +/** 13.7 + * Grant physical access to a partition for a given domain. 13.8 + */ 13.9 public class CommandPhysicalGrant extends Command { 13.10 - private Defaults d; 13.11 - private int domain_id; 13.12 - private Extent extent; 13.13 - private Mode mode; 13.14 - private int partition_no; 13.15 - 13.16 - /** 13.17 - * Constructor for CommandPhysicalGrant. 13.18 - * @param d Defaults object to use. 13.19 - * @param domain_id Domain to grant access for. 13.20 - * @param extent Extent to grant access to. 13.21 - * @param mode Access mode to grant. 13.22 - * @param partition_no Partition number to use (or zero for none). 13.23 - */ 13.24 - public CommandPhysicalGrant( 13.25 - Defaults d, 13.26 - int domain_id, 13.27 - Extent extent, 13.28 - Mode mode, 13.29 - int partition_no) { 13.30 - this.d = d; 13.31 - this.domain_id = domain_id; 13.32 - this.extent = extent; 13.33 - this.mode = mode; 13.34 - this.partition_no = partition_no; 13.35 - } 13.36 - 13.37 - public String execute() throws CommandFailedException { 13.38 - Runtime r = Runtime.getRuntime(); 13.39 - String output = null; 13.40 + /** Defaults instance to use */ 13.41 + private Defaults d; 13.42 + /** Domain ID to grant access for */ 13.43 + private int domain_id; 13.44 + /** Partition to grant access to */ 13.45 + private Partition partition; 13.46 + /** Access mode to grant */ 13.47 + private Mode mode; 13.48 13.49 - try { 13.50 - Process start_p; 13.51 - String start_cmdarray[] = new String[7]; 13.52 - int start_rc; 13.53 - start_cmdarray[0] = d.XIToolsDir + "xi_phys_grant"; 13.54 - if ( mode == Mode.READ_WRITE ) 13.55 - start_cmdarray[1] = "rw"; 13.56 - else if ( mode == Mode.READ_ONLY ) 13.57 - start_cmdarray[1] = "ro"; 13.58 - else 13.59 - throw new CommandFailedException( "Unknown access mode '" + mode + "'" ); 13.60 - start_cmdarray[2] = Integer.toString( domain_id ); 13.61 - start_cmdarray[3] = Integer.toString( extent.getDisk() ); 13.62 - start_cmdarray[4] = Long.toString( extent.getOffset() ); 13.63 - start_cmdarray[5] = Long.toString( extent.getSize() ); 13.64 - start_cmdarray[6] = Integer.toString( partition_no ); 13.65 - 13.66 - if (Settings.TEST) { 13.67 - output = reportCommand(start_cmdarray); 13.68 - } else { 13.69 - start_p = r.exec(start_cmdarray); 13.70 - start_rc = start_p.waitFor(); 13.71 - if (start_rc != 0) { 13.72 - throw CommandFailedException.XICommandFailed("Could not grant physical access", start_cmdarray); 13.73 - } 13.74 - output = "Granted physical access to domain " + domain_id; 13.75 - } 13.76 - } catch (CommandFailedException e) { 13.77 - throw e; 13.78 - } catch (Exception e) { 13.79 - throw new CommandFailedException("Could not grant physical access (" + e + ")", e); 13.80 + /** 13.81 + * Constructor for CommandPhysicalGrant. 13.82 + * @param d Defaults object to use. 13.83 + * @param domain_id Domain to grant access for. 13.84 + * @param partition Partition to grant access to. 13.85 + * @param mode Access mode to grant. 13.86 + */ 13.87 + public CommandPhysicalGrant( 13.88 + Defaults d, 13.89 + int domain_id, 13.90 + Partition partition, 13.91 + Mode mode) { 13.92 + this.d = d; 13.93 + this.domain_id = domain_id; 13.94 + this.partition = partition; 13.95 + this.mode = mode; 13.96 } 13.97 13.98 - return output; 13.99 - } 13.100 + /** 13.101 + * @see org.xenoserver.control.Command#execute() 13.102 + */ 13.103 + public String execute() throws CommandFailedException { 13.104 + Runtime r = Runtime.getRuntime(); 13.105 + String output = null; 13.106 + 13.107 + try { 13.108 + Process start_p; 13.109 + String start_cmdarray[] = new String[7]; 13.110 + int start_rc; 13.111 + start_cmdarray[0] = d.xiToolsDir + "xi_phys_grant"; 13.112 + if (mode == Mode.READ_WRITE) { 13.113 + start_cmdarray[1] = "rw"; 13.114 + } else if (mode == Mode.READ_ONLY) { 13.115 + start_cmdarray[1] = "ro"; 13.116 + } else { 13.117 + throw new CommandFailedException( 13.118 + "Unknown access mode '" + mode + "'"); 13.119 + } 13.120 + start_cmdarray[2] = Integer.toString(domain_id); 13.121 + Extent e = partition.toExtent(); 13.122 + start_cmdarray[3] = Integer.toString(e.getDisk()); 13.123 + start_cmdarray[4] = Long.toString(e.getOffset()); 13.124 + start_cmdarray[5] = Long.toString(e.getSize()); 13.125 + start_cmdarray[6] = Integer.toString(partition.getPartitionIndex()); 13.126 + 13.127 + if (Settings.TEST) { 13.128 + output = reportCommand(start_cmdarray); 13.129 + } else { 13.130 + start_p = r.exec(start_cmdarray); 13.131 + start_rc = start_p.waitFor(); 13.132 + if (start_rc != 0) { 13.133 + throw CommandFailedException.xiCommandFailed( 13.134 + "Could not grant physical access", 13.135 + start_cmdarray); 13.136 + } 13.137 + output = "Granted physical access to domain " + domain_id; 13.138 + } 13.139 + } catch (CommandFailedException e) { 13.140 + throw e; 13.141 + } catch (Exception e) { 13.142 + throw new CommandFailedException( 13.143 + "Could not grant physical access (" + e + ")", 13.144 + e); 13.145 + } 13.146 + 13.147 + return output; 13.148 + } 13.149 13.150 }
14.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalList.java Tue Jul 08 11:08:04 2003 +0000 14.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalList.java Tue Jul 08 13:02:26 2003 +0000 14.3 @@ -12,13 +12,17 @@ import java.util.StringTokenizer; 14.4 * to modes. 14.5 */ 14.6 public class CommandPhysicalList extends Command { 14.7 + /** Domain to list details for */ 14.8 private int domain_id; 14.9 + /** Defaults instance to use. */ 14.10 private Defaults d; 14.11 + /** Map of extents to access modes */ 14.12 private Map map = new HashMap(); 14.13 14.14 /** 14.15 * Constructor for CommandDomainList. 14.16 * @param d Defaults object to use. 14.17 + * @param domain_id Domain ID to query for 14.18 */ 14.19 public CommandPhysicalList(Defaults d, int domain_id) { 14.20 this.d = d; 14.21 @@ -28,6 +32,7 @@ public class CommandPhysicalList extends 14.22 /** 14.23 * Retrieves the list of extents. 14.24 * @return null, call extents() to get the list. 14.25 + * @throws CommandFailedException if the list could not be retrieved. 14.26 */ 14.27 public String execute() throws CommandFailedException { 14.28 Runtime r = Runtime.getRuntime(); 14.29 @@ -39,7 +44,7 @@ public class CommandPhysicalList extends 14.30 Process start_p; 14.31 String start_cmdarray[] = new String[2]; 14.32 int start_rc; 14.33 - start_cmdarray[0] = d.XIToolsDir + "xi_phys_probe"; 14.34 + start_cmdarray[0] = d.xiToolsDir + "xi_phys_probe"; 14.35 start_cmdarray[1] = Integer.toString(domain_id); 14.36 14.37 if (Settings.TEST) { 14.38 @@ -48,7 +53,7 @@ public class CommandPhysicalList extends 14.39 start_p = r.exec(start_cmdarray); 14.40 start_rc = start_p.waitFor(); 14.41 if (start_rc != 0) { 14.42 - throw CommandFailedException.XICommandFailed( 14.43 + throw CommandFailedException.xiCommandFailed( 14.44 "Could not get extent list", 14.45 start_cmdarray); 14.46 } 14.47 @@ -62,7 +67,7 @@ public class CommandPhysicalList extends 14.48 int disk = -1; 14.49 long offset = -1; 14.50 long size = -1; 14.51 - 14.52 + 14.53 StringTokenizer st = new StringTokenizer(outline); 14.54 if (st.hasMoreTokens()) { 14.55 disk = Short.parseShort(st.nextToken(), 16); 14.56 @@ -75,14 +80,15 @@ public class CommandPhysicalList extends 14.57 } 14.58 if (st.hasMoreTokens()) { 14.59 String mode = st.nextToken(); 14.60 - Extent extent = new Extent(disk,offset,size); 14.61 - if (mode.equals("rw")) 14.62 + Extent extent = new Extent(disk, offset, size); 14.63 + if (mode.equals("rw")) { 14.64 map.put(extent, Mode.READ_WRITE); 14.65 - else if (mode.equals("r")) 14.66 + } else if (mode.equals("r")) { 14.67 map.put(extent, Mode.READ_ONLY); 14.68 - else 14.69 + } else { 14.70 throw new CommandFailedException( 14.71 "Could not parse access mode " + mode); 14.72 + } 14.73 } 14.74 14.75 outline = in.readLine(); 14.76 @@ -100,6 +106,9 @@ public class CommandPhysicalList extends 14.77 return output; 14.78 } 14.79 14.80 + /** 14.81 + * @return Map of extents to access modes. 14.82 + */ 14.83 public Map extents() { 14.84 return map; 14.85 }
15.1 --- a/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java Tue Jul 08 11:08:04 2003 +0000 15.2 +++ b/tools/control/src/org/xenoserver/control/CommandPhysicalRevoke.java Tue Jul 08 13:02:26 2003 +0000 15.3 @@ -1,56 +1,67 @@ 15.4 package org.xenoserver.control; 15.5 15.6 +/** 15.7 + * Revoke physical access to a partition from a domain. 15.8 + */ 15.9 public class CommandPhysicalRevoke extends Command { 15.10 - private Defaults d; 15.11 - private int domain_id; 15.12 - private Extent extent; 15.13 - 15.14 - /** 15.15 - * Constructor for CommandPhysicalRevoke. 15.16 - * @param d Defaults object to use. 15.17 - * @param domain_id Domain to revoke access from. 15.18 - * @param extent Extent to revoke access from. 15.19 - */ 15.20 - public CommandPhysicalRevoke( 15.21 - Defaults d, 15.22 - int domain_id, 15.23 - Extent extent) { 15.24 - this.d = d; 15.25 - this.domain_id = domain_id; 15.26 - this.extent = extent; 15.27 - } 15.28 - 15.29 - public String execute() throws CommandFailedException { 15.30 - Runtime r = Runtime.getRuntime(); 15.31 - String output = null; 15.32 + /** Defaults instance to use. */ 15.33 + private Defaults d; 15.34 + /** Domain to revoke access from */ 15.35 + private int domain_id; 15.36 + /** Partition to revoke access to */ 15.37 + private Partition partition; 15.38 15.39 - try { 15.40 - Process start_p; 15.41 - String start_cmdarray[] = new String[5]; 15.42 - int start_rc; 15.43 - start_cmdarray[0] = d.XIToolsDir + "xi_phys_revoke"; 15.44 - start_cmdarray[1] = Integer.toString( domain_id ); 15.45 - start_cmdarray[2] = Integer.toString( extent.getDisk() ); 15.46 - start_cmdarray[3] = Long.toString( extent.getOffset() ); 15.47 - start_cmdarray[4] = Long.toString( extent.getSize() ); 15.48 - 15.49 - if (Settings.TEST) { 15.50 - output = reportCommand(start_cmdarray); 15.51 - } else { 15.52 - start_p = r.exec(start_cmdarray); 15.53 - start_rc = start_p.waitFor(); 15.54 - if (start_rc != 0) { 15.55 - throw CommandFailedException.XICommandFailed("Could not revoke physical access", start_cmdarray); 15.56 - } 15.57 - output = "Revoked physical access from domain " + domain_id; 15.58 - } 15.59 - } catch (CommandFailedException e) { 15.60 - throw e; 15.61 - } catch (Exception e) { 15.62 - throw new CommandFailedException("Could not revoke physical access (" + e + ")", e); 15.63 + /** 15.64 + * Constructor for CommandPhysicalRevoke. 15.65 + * @param d Defaults object to use. 15.66 + * @param domain_id Domain to revoke access from. 15.67 + * @param partition Partition to revoke access to. 15.68 + */ 15.69 + public CommandPhysicalRevoke(Defaults d, int domain_id, Partition partition) { 15.70 + this.d = d; 15.71 + this.domain_id = domain_id; 15.72 + this.partition = partition; 15.73 } 15.74 15.75 - return output; 15.76 - } 15.77 + /** 15.78 + * @see org.xenoserver.control.Command#execute() 15.79 + */ 15.80 + public String execute() throws CommandFailedException { 15.81 + Runtime r = Runtime.getRuntime(); 15.82 + String output = null; 15.83 + 15.84 + try { 15.85 + Process start_p; 15.86 + String start_cmdarray[] = new String[5]; 15.87 + int start_rc; 15.88 + start_cmdarray[0] = d.xiToolsDir + "xi_phys_revoke"; 15.89 + start_cmdarray[1] = Integer.toString(domain_id); 15.90 + Extent e = partition.toExtent(); 15.91 + start_cmdarray[2] = Integer.toString(e.getDisk()); 15.92 + start_cmdarray[3] = Long.toString(e.getOffset()); 15.93 + start_cmdarray[4] = Long.toString(e.getSize()); 15.94 + 15.95 + if (Settings.TEST) { 15.96 + output = reportCommand(start_cmdarray); 15.97 + } else { 15.98 + start_p = r.exec(start_cmdarray); 15.99 + start_rc = start_p.waitFor(); 15.100 + if (start_rc != 0) { 15.101 + throw CommandFailedException.xiCommandFailed( 15.102 + "Could not revoke physical access", 15.103 + start_cmdarray); 15.104 + } 15.105 + output = "Revoked physical access from domain " + domain_id; 15.106 + } 15.107 + } catch (CommandFailedException e) { 15.108 + throw e; 15.109 + } catch (Exception e) { 15.110 + throw new CommandFailedException( 15.111 + "Could not revoke physical access (" + e + ")", 15.112 + e); 15.113 + } 15.114 + 15.115 + return output; 15.116 + } 15.117 15.118 }
16.1 --- a/tools/control/src/org/xenoserver/control/CommandVdCreate.java Tue Jul 08 11:08:04 2003 +0000 16.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdCreate.java Tue Jul 08 13:02:26 2003 +0000 16.3 @@ -2,27 +2,38 @@ package org.xenoserver.control; 16.4 16.5 import java.util.Date; 16.6 16.7 +/** 16.8 + * Create a virtual disk. 16.9 + */ 16.10 public class CommandVdCreate extends Command { 16.11 - private String name; 16.12 - private long size; 16.13 - private Date expiry; 16.14 + /** Name of new disk. */ 16.15 + private String name; 16.16 + /** Size of new disk in sectors. */ 16.17 + private long size; 16.18 + /** Expiry date of new disk. */ 16.19 + private Date expiry; 16.20 16.21 - /** 16.22 - * Constructor for CommandVdCreate. 16.23 - * @param name Name of new virtual disk. 16.24 - * @param size Size in sectors. 16.25 - * @param expiry Expiry time, or null for never. 16.26 - */ 16.27 - public CommandVdCreate(String name, long size, Date expiry) { 16.28 - this.name = name; 16.29 - this.size = size; 16.30 - this.expiry = expiry; 16.31 - } 16.32 + /** 16.33 + * Constructor for CommandVdCreate. 16.34 + * @param name Name of new virtual disk. 16.35 + * @param size Size in sectors. 16.36 + * @param expiry Expiry time, or null for never. 16.37 + */ 16.38 + public CommandVdCreate(String name, long size, Date expiry) { 16.39 + this.name = name; 16.40 + this.size = size; 16.41 + this.expiry = expiry; 16.42 + } 16.43 16.44 - public String execute() throws CommandFailedException { 16.45 - VirtualDisk vd = VirtualDiskManager.IT.createVirtualDisk(name,size,expiry); 16.46 - if ( vd == null ) 16.47 - throw new CommandFailedException( "Not enough free space to create disk" ); 16.48 - return "Virtual Disk created with key: " + vd.getKey(); 16.49 - } 16.50 + /** 16.51 + * @see org.xenoserver.control.Command#execute() 16.52 + */ 16.53 + public String execute() throws CommandFailedException { 16.54 + VirtualDisk vd = 16.55 + VirtualDiskManager.IT.createVirtualDisk(name, size, expiry); 16.56 + if (vd == null) { 16.57 + throw new CommandFailedException("Not enough free space to create disk"); 16.58 + } 16.59 + return "Virtual Disk created with key: " + vd.getKey(); 16.60 + } 16.61 }
17.1 --- a/tools/control/src/org/xenoserver/control/CommandVdDelete.java Tue Jul 08 11:08:04 2003 +0000 17.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdDelete.java Tue Jul 08 13:02:26 2003 +0000 17.3 @@ -1,18 +1,25 @@ 17.4 package org.xenoserver.control; 17.5 17.6 +/** 17.7 + * Delete virtual disk. 17.8 + */ 17.9 public class CommandVdDelete extends Command { 17.10 - private String key; 17.11 - 17.12 - /** 17.13 - * Constructor for CommandVdDelete. 17.14 - * @param key The key of the disk to delete. 17.15 - */ 17.16 - public CommandVdDelete(String key) { 17.17 - this.key = key; 17.18 - } 17.19 + /** Key of disk to delete. */ 17.20 + private String key; 17.21 17.22 - public String execute() throws CommandFailedException { 17.23 - VirtualDiskManager.IT.deleteVirtualDisk(key); 17.24 - return "Deleted virtual disk " + key; 17.25 - } 17.26 + /** 17.27 + * Constructor for CommandVdDelete. 17.28 + * @param key The key of the disk to delete. 17.29 + */ 17.30 + public CommandVdDelete(String key) { 17.31 + this.key = key; 17.32 + } 17.33 + 17.34 + /** 17.35 + * @see org.xenoserver.control.Command#execute() 17.36 + */ 17.37 + public String execute() throws CommandFailedException { 17.38 + VirtualDiskManager.IT.deleteVirtualDisk(key); 17.39 + return "Deleted virtual disk " + key; 17.40 + } 17.41 }
18.1 --- a/tools/control/src/org/xenoserver/control/CommandVdRefresh.java Tue Jul 08 11:08:04 2003 +0000 18.2 +++ b/tools/control/src/org/xenoserver/control/CommandVdRefresh.java Tue Jul 08 13:02:26 2003 +0000 18.3 @@ -2,25 +2,34 @@ package org.xenoserver.control; 18.4 18.5 import java.util.Date; 18.6 18.7 +/** 18.8 + * Refresh the expiry time on a virtual disk. 18.9 + */ 18.10 public class CommandVdRefresh extends Command { 18.11 - private String key; 18.12 - private Date expiry; 18.13 - 18.14 - /** 18.15 - * Constructor for CommandVdRefresh. 18.16 - * @param key Key to refresh. 18.17 - * @param expiry New expiry (null for no expiry). 18.18 - */ 18.19 - public CommandVdRefresh(String key, Date expiry) { 18.20 - this.key = key; 18.21 - this.expiry = expiry; 18.22 - } 18.23 + /** Key of disk to refresh */ 18.24 + private String key; 18.25 + /** New expiry */ 18.26 + private Date expiry; 18.27 18.28 - public String execute() throws CommandFailedException { 18.29 - VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key); 18.30 - if ( vd == null ) 18.31 - throw new CommandFailedException( "No such virtual disk " + key ); 18.32 - vd.refreshExpiry(expiry); 18.33 - return "Refreshed virtual disk " + key; 18.34 - } 18.35 + /** 18.36 + * Constructor for CommandVdRefresh. 18.37 + * @param key Key to refresh. 18.38 + * @param expiry New expiry (null for no expiry). 18.39 + */ 18.40 + public CommandVdRefresh(String key, Date expiry) { 18.41 + this.key = key; 18.42 + this.expiry = expiry; 18.43 + } 18.44 + 18.45 + /** 18.46 + * @see org.xenoserver.control.Command#execute() 18.47 + */ 18.48 + public String execute() throws CommandFailedException { 18.49 + VirtualDisk vd = VirtualDiskManager.IT.getVirtualDisk(key); 18.50 + if (vd == null) { 18.51 + throw new CommandFailedException("No such virtual disk " + key); 18.52 + } 18.53 + vd.refreshExpiry(expiry); 18.54 + return "Refreshed virtual disk " + key; 18.55 + } 18.56 }
19.1 --- a/tools/control/src/org/xenoserver/control/Defaults.java Tue Jul 08 11:08:04 2003 +0000 19.2 +++ b/tools/control/src/org/xenoserver/control/Defaults.java Tue Jul 08 13:02:26 2003 +0000 19.3 @@ -16,190 +16,217 @@ import org.xml.sax.helpers.DefaultHandle 19.4 * management utilities. On construction it parses the defaults file 19.5 * located through the Settings class. 19.6 */ 19.7 -public class Defaults 19.8 -{ 19.9 - public String domainName; 19.10 - 19.11 - public int domainSizeKB; 19.12 - public String domainImage; 19.13 - public String domainInitRD; 19.14 - public int domainVIFs; 19.15 - 19.16 - public String rootDevice; 19.17 - 19.18 - public String NWIP; 19.19 - public String NWGW; 19.20 - public String NWMask; 19.21 - public String NWHost; 19.22 +public class Defaults { 19.23 + /** Default domain name. */ 19.24 + public String domainName; 19.25 + /** Default domain memory size in KB. */ 19.26 + public int domainSizeKB; 19.27 + /** Default domain kernel image. */ 19.28 + public String domainImage; 19.29 + /** Default domain initrd. */ 19.30 + public String domainInitRD; 19.31 + /** Default number of virtual interfaces. */ 19.32 + public int domainVIFs; 19.33 + /** Default root device. */ 19.34 + public String rootDevice; 19.35 + /** Default IP address pattern. */ 19.36 + public String nwIP; 19.37 + /** Default gateway pattern. */ 19.38 + public String nwGateway; 19.39 + /** Default netmask patterh. */ 19.40 + public String nwMask; 19.41 + /** Default hostname pattern. */ 19.42 + public String nwHost; 19.43 + /** Default NFS server pattern. */ 19.44 + public String nwNFSServer; 19.45 + /** Default NFS root pattern. */ 19.46 + public String nwNFSRoot; 19.47 + /** Maximum domain number. */ 19.48 + public int maxDomainNumber = Integer.MAX_VALUE; 19.49 + /** Default boot arguments. */ 19.50 + public String args = ""; 19.51 + /** Directory to find XI tools. */ 19.52 + public String xiToolsDir = ""; 19.53 19.54 - public String NWNFSServer; 19.55 - public String NWNFSRoot; 19.56 + 19.57 + /** 19.58 + * Create defaults instance and parse the defaults file. 19.59 + */ 19.60 + public Defaults() { 19.61 + File f = Settings.getDefaultsFile(); 19.62 19.63 - public int MaxDomainNumber = Integer.MAX_VALUE; 19.64 - public String args = ""; 19.65 - 19.66 - public String XIToolsDir = ""; 19.67 + if (f == null) { 19.68 + return; 19.69 + } 19.70 19.71 - /***********************************************************************/ 19.72 - 19.73 - public Defaults () 19.74 - { 19.75 - File f = Settings.getDefaultsFile (); 19.76 - 19.77 - if (f == null) 19.78 - { 19.79 - return; 19.80 + try { 19.81 + XMLReader xr = new org.apache.crimson.parser.XMLReaderImpl(); 19.82 + Handler handler = new Handler(); 19.83 + xr.setContentHandler(handler); 19.84 + xr.setErrorHandler(handler); 19.85 + xr.parse(new InputSource(new FileReader(f))); 19.86 + } catch (Exception e) { 19.87 + System.err.println( 19.88 + "Could not read defaults file " + f + "\nException: " + e); 19.89 + e.printStackTrace(); 19.90 + return; 19.91 + } 19.92 } 19.93 19.94 - try 19.95 - { 19.96 - XMLReader xr = new org.apache.crimson.parser.XMLReaderImpl(); 19.97 - Handler handler = new Handler (); 19.98 - xr.setContentHandler (handler); 19.99 - xr.setErrorHandler (handler); 19.100 - xr.parse (new InputSource(new FileReader (f))); 19.101 - } 19.102 - catch (Exception e) 19.103 - { 19.104 - System.err.println ("Could not read defaults file " + f + 19.105 - "\nException: " + e); 19.106 - e.printStackTrace(); 19.107 - return; 19.108 - } 19.109 - } 19.110 - 19.111 - public void describe () { 19.112 - System.out.println ("Domain defaults:"); 19.113 - System.out.println (" name " + domainName); 19.114 - System.out.println (" size " + domainSizeKB); 19.115 - System.out.println (" vifs " + domainVIFs); 19.116 - System.out.println (" domainImage " + domainImage); 19.117 - System.out.println (" domainInitRD " + domainInitRD); 19.118 - System.out.println (" rootDevice " + rootDevice); 19.119 - System.out.println (" NWIP " + NWIP); 19.120 - System.out.println (" NWGW " + NWGW); 19.121 - System.out.println (" NWMask " + NWMask); 19.122 - System.out.println (" MaxDomainNumber " + MaxDomainNumber); 19.123 - System.out.println (" NWNFSServer " + NWNFSServer); 19.124 - System.out.println (" NWNFSRoot " + NWNFSRoot); 19.125 - System.out.println (" XIToolsDir " + XIToolsDir); 19.126 - System.out.println (" args " + args); 19.127 - } 19.128 - 19.129 - /***********************************************************************/ 19.130 - 19.131 - class Handler extends DefaultHandler 19.132 - { 19.133 - boolean inDomctlDefaults; 19.134 - String lastName; 19.135 - 19.136 - public void startDocument () 19.137 - { 19.138 - } 19.139 - 19.140 - public void endDocument () 19.141 - { 19.142 + /** 19.143 + * Describe the defaults to System.out 19.144 + */ 19.145 + public void describe() { 19.146 + System.out.println("Domain defaults:"); 19.147 + System.out.println(" name " + domainName); 19.148 + System.out.println(" size " + domainSizeKB); 19.149 + System.out.println(" vifs " + domainVIFs); 19.150 + System.out.println(" domainImage " + domainImage); 19.151 + System.out.println(" domainInitRD " + domainInitRD); 19.152 + System.out.println(" rootDevice " + rootDevice); 19.153 + System.out.println(" NWIP " + nwIP); 19.154 + System.out.println(" NWGW " + nwGateway); 19.155 + System.out.println(" NWMask " + nwMask); 19.156 + System.out.println(" MaxDomainNumber " + maxDomainNumber); 19.157 + System.out.println(" NWNFSServer " + nwNFSServer); 19.158 + System.out.println(" NWNFSRoot " + nwNFSRoot); 19.159 + System.out.println(" XIToolsDir " + xiToolsDir); 19.160 + System.out.println(" args " + args); 19.161 } 19.162 19.163 - public void startElement (String uri, String name, 19.164 - String qname, Attributes atts) 19.165 - { 19.166 - if (qname.equals ("domctl_defaults")) { 19.167 - inDomctlDefaults = true; 19.168 - } else { 19.169 - lastName = qname; 19.170 - } 19.171 + /** 19.172 + * SAX event handler. 19.173 + */ 19.174 + private class Handler extends DefaultHandler { 19.175 + /** Are we inside the defaults node. */ 19.176 + boolean inDomctlDefaults; 19.177 + /** Last element name read. */ 19.178 + String lastName; 19.179 + 19.180 + /** 19.181 + * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) 19.182 + */ 19.183 + public void startElement( 19.184 + String uri, 19.185 + String name, 19.186 + String qname, 19.187 + Attributes atts) { 19.188 + if (qname.equals("domctl_defaults")) { 19.189 + inDomctlDefaults = true; 19.190 + } else { 19.191 + lastName = qname; 19.192 + } 19.193 + } 19.194 + 19.195 + /** 19.196 + * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) 19.197 + */ 19.198 + public void endElement(String uri, String name, String qname) { 19.199 + lastName = ""; 19.200 + if (qname.equals("domctl_defaults")) { 19.201 + inDomctlDefaults = false; 19.202 + } 19.203 + } 19.204 + 19.205 + /** 19.206 + * @see org.xml.sax.ContentHandler#characters(char[], int, int) 19.207 + */ 19.208 + public void characters(char ch[], int start, int length) { 19.209 + String s = new String(ch, start, length); 19.210 + if (lastName != null) { 19.211 + if (lastName.equals("domain_size_kb")) { 19.212 + domainSizeKB = Integer.parseInt(s); 19.213 + } else if (lastName.equals("domain_image")) { 19.214 + domainImage = s; 19.215 + } else if (lastName.equals("domain_name")) { 19.216 + domainName = s; 19.217 + } else if (lastName.equals("domain_init_rd")) { 19.218 + domainInitRD = s; 19.219 + } else if (lastName.equals("domain_vifs")) { 19.220 + domainVIFs = Integer.parseInt(s); 19.221 + } else if (lastName.equals("root_device")) { 19.222 + rootDevice = s; 19.223 + } else if (lastName.equals("nw_ip")) { 19.224 + nwIP = 19.225 + expandDefault( 19.226 + s, 19.227 + runCommand(xiToolsDir + Settings.XI_HELPER + " ip") 19.228 + .trim()); 19.229 + } else if (lastName.equals("nw_gw")) { 19.230 + nwGateway = 19.231 + expandDefault( 19.232 + s, 19.233 + runCommand( 19.234 + xiToolsDir + Settings.XI_HELPER + " route") 19.235 + .trim()); 19.236 + } else if (lastName.equals("nw_mask")) { 19.237 + nwMask = 19.238 + expandDefault( 19.239 + s, 19.240 + runCommand( 19.241 + xiToolsDir + Settings.XI_HELPER + " mask") 19.242 + .trim()); 19.243 + } else if (lastName.equals("nw_host")) { 19.244 + nwHost = s; 19.245 + } else if (lastName.equals("nw_nfs_server")) { 19.246 + nwNFSServer = s; 19.247 + } else if (lastName.equals("nw_nfs_root")) { 19.248 + nwNFSRoot = s; 19.249 + } else if (lastName.equals("args")) { 19.250 + args = s; 19.251 + } else if (lastName.equals("max_domain_number")) { 19.252 + maxDomainNumber = Integer.parseInt(s); 19.253 + } else if (lastName.equals("xi_tools_dir")) { 19.254 + xiToolsDir = s; 19.255 + } 19.256 + } 19.257 + } 19.258 } 19.259 19.260 - public void endElement (String uri, String name, String qname) 19.261 - { 19.262 - lastName = ""; 19.263 - if (qname.equals ("domctl_defaults")) { 19.264 - inDomctlDefaults = false; 19.265 - } 19.266 - } 19.267 - 19.268 - public void characters (char ch[], int start, int length) 19.269 - { 19.270 - String s = new String (ch, start, length); 19.271 - if (lastName != null) 19.272 - { 19.273 - if (lastName.equals ("domain_size_kb")) { 19.274 - domainSizeKB = Integer.parseInt (s); 19.275 - } else if (lastName.equals ("domain_image")) { 19.276 - domainImage = s; 19.277 - } else if (lastName.equals ("domain_name")) { 19.278 - domainName = s; 19.279 - } else if (lastName.equals ("domain_init_rd")) { 19.280 - domainInitRD = s; 19.281 - } else if (lastName.equals ("domain_vifs")) { 19.282 - domainVIFs = Integer.parseInt (s); 19.283 - } else if (lastName.equals ("root_device")) { 19.284 - rootDevice = s; 19.285 - } else if (lastName.equals ("nw_ip")) { 19.286 - NWIP = expandDefault (s, runCommand(XIToolsDir+Settings.XI_HELPER+" ip").trim()); 19.287 - } else if (lastName.equals ("nw_gw")) { 19.288 - NWGW = expandDefault (s, runCommand(XIToolsDir+Settings.XI_HELPER+" route").trim()); 19.289 - } else if (lastName.equals ("nw_mask")) { 19.290 - NWMask = expandDefault (s, runCommand(XIToolsDir+Settings.XI_HELPER+" mask").trim()); 19.291 - } else if (lastName.equals ("nw_host")) { 19.292 - NWHost = s; 19.293 - } else if (lastName.equals ("nw_nfs_server")) { 19.294 - NWNFSServer = s; 19.295 - } else if (lastName.equals ("nw_nfs_root")) { 19.296 - NWNFSRoot = s; 19.297 - } else if (lastName.equals ("args")) { 19.298 - args = s; 19.299 - } else if (lastName.equals ("max_domain_number")) { 19.300 - MaxDomainNumber = Integer.parseInt(s); 19.301 - } else if (lastName.equals ("xi_tools_dir")) { 19.302 - XIToolsDir = s; 19.303 - } 19.304 - } 19.305 - } 19.306 - } 19.307 - 19.308 - public String expandDefault (String supplied, String self) 19.309 - { 19.310 - if (supplied.startsWith ("=")) { 19.311 - if (supplied.length() > 1) { 19.312 - return self + supplied.substring (1, supplied.length()); 19.313 - } else { 19.314 - return self; 19.315 - } 19.316 - } else { 19.317 - return supplied; 19.318 - } 19.319 - } 19.320 - 19.321 - 19.322 - public String 19.323 - runCommand (String command) 19.324 - { 19.325 - Runtime runtime = Runtime.getRuntime(); 19.326 - String outline; 19.327 - StringBuffer output = new StringBuffer(); 19.328 - 19.329 - try 19.330 - { 19.331 - Process process = runtime.exec(command); 19.332 - BufferedReader in = new BufferedReader( 19.333 - new InputStreamReader(process.getInputStream())); 19.334 - 19.335 - outline = in.readLine(); 19.336 - while (outline != null) 19.337 - { 19.338 - output.append("\n" + outline); 19.339 - outline = in.readLine(); 19.340 - } 19.341 - } 19.342 - catch (IOException e) 19.343 - { 19.344 - return e.toString(); 19.345 + /** 19.346 + * Expand a defaults pattern. 19.347 + * @param supplied Supplied pattern. 19.348 + * @param self Own value for variable. 19.349 + * @return Appropriate value. 19.350 + */ 19.351 + private String expandDefault(String supplied, String self) { 19.352 + if (supplied.startsWith("=")) { 19.353 + if (supplied.length() > 1) { 19.354 + return self + supplied.substring(1, supplied.length()); 19.355 + } else { 19.356 + return self; 19.357 + } 19.358 + } else { 19.359 + return supplied; 19.360 + } 19.361 } 19.362 19.363 - return output.toString(); 19.364 - } 19.365 + /** 19.366 + * Run a command for the Defaults object. 19.367 + * @param command Command string to run. 19.368 + * @return Command's output. 19.369 + */ 19.370 + private String runCommand(String command) { 19.371 + Runtime runtime = Runtime.getRuntime(); 19.372 + String outline; 19.373 + StringBuffer output = new StringBuffer(); 19.374 19.375 + try { 19.376 + Process process = runtime.exec(command); 19.377 + BufferedReader in = 19.378 + new BufferedReader( 19.379 + new InputStreamReader(process.getInputStream())); 19.380 + 19.381 + outline = in.readLine(); 19.382 + while (outline != null) { 19.383 + output.append("\n" + outline); 19.384 + outline = in.readLine(); 19.385 + } 19.386 + } catch (IOException e) { 19.387 + return e.toString(); 19.388 + } 19.389 + 19.390 + return output.toString(); 19.391 + } 19.392 19.393 }
20.1 --- a/tools/control/src/org/xenoserver/control/Domain.java Tue Jul 08 11:08:04 2003 +0000 20.2 +++ b/tools/control/src/org/xenoserver/control/Domain.java Tue Jul 08 13:02:26 2003 +0000 20.3 @@ -2,30 +2,39 @@ package org.xenoserver.control; 20.4 20.5 /** 20.6 * A Domain object holds the details of one domain suitable for returning 20.7 - * from methods enquiring about domain status. 20.8 + * from methods enquiring about domain status. As it's only used to pass 20.9 + * return values back from DomainList, the fields are left public for 20.10 + * convenience. 20.11 */ 20.12 -public class 20.13 -Domain 20.14 -{ 20.15 - public int id; /* domain id */ 20.16 - public int processor; /* processor */ 20.17 - public boolean cpu; /* has cpu */ 20.18 - public int nstate; /* state */ 20.19 - public String state; /* running, interruptable, uninterruptable, 20.20 - wait, suspended, dying */ 20.21 - public int mcu; /* mcu advances */ 20.22 - public int pages; /* total pages */ 20.23 - public String name; /* name */ 20.24 +public class Domain { 20.25 + /** Domain ID. */ 20.26 + public int id; 20.27 + /** Processor index. */ 20.28 + public int processor; 20.29 + /** Has the CPU at the moment? */ 20.30 + public boolean cpu; 20.31 + /** State index. */ 20.32 + public int nstate; 20.33 + /** State string. */ 20.34 + public String state; 20.35 + /** MCU advances. */ 20.36 + public int mcu; 20.37 + /** Total pages. */ 20.38 + public int pages; 20.39 + /** Name. */ 20.40 + public String name; 20.41 20.42 - Domain() 20.43 - { 20.44 - id = 0; 20.45 - processor = 0; 20.46 - cpu = false; 20.47 - nstate = 0; 20.48 - state = ""; 20.49 - mcu = 0; 20.50 - pages = 0; 20.51 - name = "none"; 20.52 - } 20.53 + /** 20.54 + * Domain constructor, with default values. 20.55 + */ 20.56 + Domain() { 20.57 + id = 0; 20.58 + processor = 0; 20.59 + cpu = false; 20.60 + nstate = 0; 20.61 + state = ""; 20.62 + mcu = 0; 20.63 + pages = 0; 20.64 + name = "none"; 20.65 + } 20.66 }
21.1 --- a/tools/control/src/org/xenoserver/control/Partition.java Tue Jul 08 11:08:04 2003 +0000 21.2 +++ b/tools/control/src/org/xenoserver/control/Partition.java Tue Jul 08 13:02:26 2003 +0000 21.3 @@ -182,4 +182,19 @@ public class Partition { 21.4 throw new IllegalArgumentException("Don't know how to convert " + name + "into a disk number"); 21.5 } 21.6 } 21.7 + 21.8 + /** 21.9 + * @return Partition index on disk for this partition. 21.10 + */ 21.11 + public int getPartitionIndex() { 21.12 + if ( name.startsWith("hd") ) { 21.13 + // low 6 bits of minor are partition no 21.14 + return minor & 0x3F; 21.15 + } else if ( name.startsWith("sd") ) { 21.16 + // low 4 bits of minor are partition no 21.17 + return minor & 0x0F; 21.18 + } else { 21.19 + throw new IllegalArgumentException("Don't know how to convert " + name + "into a partition number"); 21.20 + } 21.21 + } 21.22 }