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