4 from optparse import OptionParser
7 def __init__(self, usage, description, epilog=None):
8 self.parser = OptionParser(usage=usage, description=description,
10 self.parser.add_option("-i", "", dest="infile", metavar="FILE",
11 help="read RSpec from FILE (default is stdin)")
12 self.parser.add_option("-o", "", dest="outfile", metavar="FILE",
13 help="write output to FILE (default is stdout)")
17 def add_nodefile_option(self):
19 self.parser.add_option("-n", "", dest="nodefile",
21 help="read node list from FILE"),
23 def add_show_attributes_option(self):
24 self.parser.add_option("-s", "--show-attributes", action="store_true",
25 dest="showatt", default=False,
26 help="show sliver attributes")
28 def add_attribute_options(self):
29 self.parser.add_option("", "--capabilities", action="append",
30 metavar="<cap1,cap2,...>",
31 help="Vserver bcapabilities")
32 self.parser.add_option("", "--codemux", action="append",
33 metavar="<host,local-port>",
34 help="Demux HTTP between slices using " +
36 self.parser.add_option("", "--cpu-pct", action="append",
38 help="Reserved CPU percent (e.g., 25)")
39 self.parser.add_option("", "--cpu-share", action="append",
41 help="Number of CPU shares (e.g., 5)")
42 self.parser.add_option("", "--delegations",
43 metavar="<slice1,slice2,...>", action="append",
44 help="List of slices with delegation authority")
45 self.parser.add_option("", "--disk-max",
46 metavar="<num>", action="append",
47 help="Disk quota (1k disk blocks)")
48 self.parser.add_option("", "--initscript",
49 metavar="<name>", action="append",
50 help="Slice initialization script (e.g., stork)")
51 self.parser.add_option("", "--ip-addresses", action="append",
53 help="Add an IP address to a sliver")
54 self.parser.add_option("", "--net-i2-max-kbyte",
55 metavar="<KBytes>", action="append",
56 help="Maximum daily network Tx limit " +
58 self.parser.add_option("", "--net-i2-max-rate",
59 metavar="<Kbps>", action="append",
60 help="Maximum bandwidth over I2 routes")
61 self.parser.add_option("", "--net-i2-min-rate",
62 metavar="<Kbps>", action="append",
63 help="Minimum bandwidth over I2 routes")
64 self.parser.add_option("", "--net-i2-share",
65 metavar="<num>", action="append",
66 help="Number of bandwidth shares over I2 routes")
67 self.parser.add_option("", "--net-i2-thresh-kbyte",
68 metavar="<KBytes>", action="append",
69 help="Limit sent to I2 hosts before warning, " +
71 self.parser.add_option("", "--net-max-kbyte",
72 metavar="<KBytes>", action="append",
73 help="Maximum daily network Tx limit " +
75 self.parser.add_option("", "--net-max-rate",
76 metavar="<Kbps>", action="append",
77 help="Maximum bandwidth over non-I2 routes")
78 self.parser.add_option("", "--net-min-rate",
79 metavar="<Kbps>", action="append",
80 help="Minimum bandwidth over non-I2 routes")
81 self.parser.add_option("", "--net-share",
82 metavar="<num>", action="append",
83 help="Number of bandwidth shares over non-I2 " +
85 self.parser.add_option("", "--net-thresh-kbyte",
86 metavar="<KBytes>", action="append",
87 help="Limit sent to non-I2 hosts before " +
88 "warning, throttling")
89 self.parser.add_option("", "--vsys",
90 metavar="<name>", action="append",
91 help="Vsys script (e.g., fd_fusemount)")
92 self.parser.add_option("", "--vsys-vnet",
93 metavar="<IP network>", action="append",
94 help="Allocate a virtual private network")
96 def get_attribute_dict(self):
97 attrlist = ['capabilities','codemux','cpu_pct','cpu_share',
98 'delegations','disk_max','initscript','ip_addresses',
99 'net_i2_max_kbyte','net_i2_max_rate','net_i2_min_rate',
100 'net_i2_share','net_i2_thresh_kbyte',
101 'net_max_kbyte','net_max_rate','net_min_rate',
102 'net_share','net_thresh_kbyte',
105 for attr in attrlist:
106 value = getattr(self.opts, attr, None)
107 if value is not None:
108 attrdict[attr] = value
112 (self.opts, self.args) = self.parser.parse_args()
114 #if self.opts.infile:
115 # sys.stdin = open(self.opts.infile, "r")
116 #xml = sys.stdin.read()
117 #self.rspec = RSpec(xml)
120 # if self.opts.nodefile:
121 # f = open(self.opts.nodefile, "r")
122 # self.nodes = f.read().split()
125 # self.nodes = self.args
127 #if self.opts.outfile:
128 # sys.stdout = open(self.opts.outfile, "w")