aboutsummaryrefslogtreecommitdiffstats
path: root/tools/control/src/org/xenoserver/cmdline/ParsePhysicalGrant.java
blob: f332d5c698b7931d7c7299b72da0b326f34f2bb9 (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
52
53
54
55
package org.xenoserver.cmdline;

import java.util.LinkedList;

import org.xenoserver.control.CommandFailedException;
import org.xenoserver.control.CommandPhysicalGrant;
import org.xenoserver.control.Defaults;
import org.xenoserver.control.Mode;

public class ParsePhysicalGrant extends CommandParser {
    public void parse(Defaults d, LinkedList args)
        throws ParseFailedException, CommandFailedException {
        int domain_id = getIntParameter(args, 'n', 0);
        boolean force = getFlagParameter(args, 'f');
        String partition_name = getStringParameter(args, 'p', "");
        boolean write = getFlagParameter(args, 'w');

        if (domain_id == 0) {
            throw new ParseFailedException("Expected -n<domain_id>");
        }
        if (partition_name.equals("")) {
            throw new ParseFailedException("Expected -p<partition_name>");
        }

        Mode mode;
        if (write) {
            mode = Mode.READ_WRITE;
        } else {
            mode = Mode.READ_ONLY;
        }

        // Initialise the partition manager and look up the partition
        loadState();
        String output =
            new CommandPhysicalGrant(d, domain_id, partition_name, mode, force)
                .execute();
        if (output != null) {
            System.out.println(output);
        }
    }

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

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

    public String getHelpText() {
        return "Grant the specified domain access to the given partition.  -w grants"
            + " read-write instead of read-only.  -f forcibly grants access.";
    }

}