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