another pass onf shebangs
[sfa.git] / sfa / client / sfi_commands.py
1 #!/usr/bin/env python3
2
3 import sys
4 from optparse import OptionParser
5
6
7 class Commands:
8
9     def __init__(self, usage, description, epilog=None):
10         self.parser = OptionParser(usage=usage, description=description,
11                                    epilog=epilog)
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)")
16         self.nodefile = False
17         self.linkfile = False
18         self.attributes = {}
19
20     def add_nodefile_option(self):
21         self.nodefile = True
22         self.parser.add_option("-n", "", dest="nodefile",
23                                metavar="FILE",
24                                help="read node list from FILE"),
25
26     def add_linkfile_option(self):
27         self.linkfile = True
28         self.parser.add_option("-l", "", dest="linkfile",
29                                metavar="FILE",
30                                help="read link list from FILE")
31
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")
36
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 " +
44                                "localhost ports")
45         self.parser.add_option("", "--cpu-pct", action="append",
46                                metavar="<num>",
47                                help="Reserved CPU percent (e.g., 25)")
48         self.parser.add_option("", "--cpu-share", action="append",
49                                metavar="<num>",
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",
61                                metavar="<IP addr>",
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 " +
66                                "to I2 hosts.")
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, " +
79                                "throttling")
80         self.parser.add_option("", "--net-max-kbyte",
81                                metavar="<KBytes>", action="append",
82                                help="Maximum daily network Tx limit " +
83                                "to non-I2 hosts.")
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 " +
93                                "routes")
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")
104
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',
112                     'vsys', 'vsys_vnet']
113         attrdict = {}
114         for attr in attrlist:
115             value = getattr(self.opts, attr, None)
116             if value is not None:
117                 attrdict[attr] = value
118         return attrdict
119
120     def prep(self):
121         (self.opts, self.args) = self.parser.parse_args()
122
123         # if self.opts.infile:
124         #    sys.stdin = open(self.opts.infile, "r")
125         #xml = sys.stdin.read()
126         #self.rspec = RSpec(xml)
127         #
128         # if self.nodefile:
129         #    if self.opts.nodefile:
130         #        f = open(self.opts.nodefile, "r")
131         #        self.nodes = f.read().split()
132         #        f.close()
133         #    else:
134         #        self.nodes = self.args
135         #
136         # if self.opts.outfile:
137         #    sys.stdout = open(self.opts.outfile, "w")