aboutsummaryrefslogtreecommitdiffstats
path: root/tools/control/src/org/xenoserver/cmdline/ParsePhysicalRevoke.java
blob: 8527845cdbe37f6bf16bd8d9ace371155c45b128 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.xenoserver.cmdline;

import java.util.LinkedList;

import org.xenoserver.control.CommandFailedException;
import org.xenoserver.control.CommandPhysicalRevoke;
import org.xenoserver.control.Defaults;
import org.xenoserver.control.Extent;
import org.xenoserver.control.Partition;
import org.xenoserver.control.PartitionManager;
import org.xenoserver.control.Settings;
import org.xenoserver.control.XML;

public class ParsePhysicalRevoke extends CommandParser {
  public void parse(Defaults d, LinkedList args) throws ParseFailedException, CommandFailedException {
    int domain_id = getIntParameter(args, 'n', 0);
    String partition_name = getStringParameter(args, 'p', "");
    
    if (domain_id == 0)
      throw new ParseFailedException("Expected -n<domain_id>");
    if (partition_name.equals(""))
      throw new ParseFailedException("Expected -p<partition_name>");
      
    // Initialise the partition manager and look up the partition
    XML.load_state( PartitionManager.it, Settings.STATE_INPUT_FILE );
    Partition p = PartitionManager.it.get_partition(partition_name);
    
    if ( p == null )
      throw new CommandFailedException("Partition " + partition_name + " does not exist.");

    // Convert the partition into a physical extent
    Extent e = p.toExtent();
    
    String output = new CommandPhysicalRevoke( d, domain_id, e ).execute();
    if ( output != null )
      System.out.println( output );
  }

  public String getName() {
    return "revoke";
  }

  public String getUsage() {
    return "[-n<domain_id>] [-p<partition_name>]";
  }

  public String getHelpText() {
    return "Revoke access to the given partition from the specified domain.";
  }

}