initial checkin
[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.attributes = {}
16
17     def add_nodefile_option(self):
18         self.nodefile = True
19         self.parser.add_option("-n", "", dest="nodefile", 
20                                metavar="FILE",
21                                help="read node list from FILE"),
22
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")
27
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 " +
35                                "localhost ports")
36         self.parser.add_option("", "--cpu-pct", action="append",
37                                metavar="<num>", 
38                                help="Reserved CPU percent (e.g., 25)")
39         self.parser.add_option("", "--cpu-share", action="append",
40                                metavar="<num>", 
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",
52                                metavar="<IP addr>", 
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 " +
57                                "to I2 hosts.")
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, " +
70                                "throttling")
71         self.parser.add_option("", "--net-max-kbyte", 
72                                metavar="<KBytes>", action="append",
73                                help="Maximum daily network Tx limit " +
74                                "to non-I2 hosts.")
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 " +
84                                "routes")
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")
95
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',
103                     'vsys','vsys_vnet']
104         attrdict = {}
105         for attr in attrlist:
106             value = getattr(self.opts, attr, None)
107             if value is not None:
108                 attrdict[attr] = value
109         return attrdict
110
111     def prep(self):
112         (self.opts, self.args) = self.parser.parse_args()
113
114         #if self.opts.infile:
115         #    sys.stdin = open(self.opts.infile, "r")
116         #xml = sys.stdin.read()
117         #self.rspec = RSpec(xml)
118         #    
119         #if self.nodefile:
120         #    if self.opts.nodefile:
121         #        f = open(self.opts.nodefile, "r")
122         #        self.nodes = f.read().split()
123         #        f.close()
124         #    else:
125         #        self.nodes = self.args
126         #
127         #if self.opts.outfile:
128         #    sys.stdout = open(self.opts.outfile, "w")
129
130
131
132
133
134
135