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