36 jdata = json.loads(mm2_config_in_json)
37 full_config = jdata[2]
38 return set([str(filt[
'name'])
for filt
in full_config[
"filters"]])
44 conn = httplib.HTTPConnection(mm2name)
45 conn.request(
"GET",
"/mm2/mpc/mm2.py/get_config_json")
46 resp = conn.getresponse()
48 if (resp.status/100) != 2:
49 raise Exception(resp.reason)
61 if (bnum <= 0)
or (bnum > 5):
62 raise ValueError(
"Band number for \"%s\" must be in range 1..5" % filtname)
69 def SetFiltMap(mm2host, a2bfilt_vals, b2afilt_vals, all_filter_names=None):
71 if all_filter_names
is None:
75 if (a2bfilt_vals
is None):
77 if (b2afilt_vals
is None):
81 for fvals
in (a2bfilt_vals, b2afilt_vals):
83 if filt.FiltName
not in all_filter_names:
84 raise ValueError(
"Filter name \"%s\" is not present" % filt.FiltName)
86 offa2b = all_filter_names.difference(set(map(
lambda x: x.FiltName, a2bfilt_vals)))
87 offb2a = all_filter_names.difference(set(map(
lambda x: x.FiltName, b2afilt_vals)))
91 fdict[
"DBNDS_%s" % fn] =
"down-band-none" 93 fdict[
"UBNDS_%s" % fn] =
"up-band-none" 95 for fs
in a2bfilt_vals:
96 fdict[
"DBNDS_%s" % fs.FiltName] =
"down-band-%d" % fs.ToBand
97 for fs
in b2afilt_vals:
98 fdict[
"UBNDS_%s" % fs.FiltName] =
"up-band-%d" % fs.ToBand
100 fdict[
"SUBMIT_FILTERMAP_BUTTON"] =
"Submit" 102 conn = httplib.HTTPConnection(mm2host)
103 params = urllib.urlencode(fdict)
104 headers = {
"Content-type":
"application/x-www-form-urlencoded",
105 "Accept":
"text/plain"}
106 conn.request(
"POST",
"/mm2/mpc/mm2.py/process_filtmap", params, headers)
107 resp = conn.getresponse()
109 if (resp.status/100) != 2:
110 raise Exception(resp.reason)
117 if __name__ ==
"__main__":
121 parser = argparse.ArgumentParser(description=
"Set classification filter map.")
123 parser.add_argument(
"-A", action=
"append", nargs=2, dest=
"a2b",
124 help=
"Specify a filter name and band number for packats flowing LanA to Lan B.")
126 parser.add_argument(
"-B", action=
"append", nargs=2, dest=
"b2a",
127 help=
"Specify a filter name and band number for packats flowing LanB to Lan A.")
129 parser.add_argument(
"-d",
"--defaults", action=
"store_true",
130 help=
"Turn all filters off (default state).")
132 parser.add_argument(
"-f",
"--filters", action=
"store_true",
133 help=
"List all the flters, do nothing else.")
135 parser.add_argument(
"mm_hostname",
136 help=
'The host name or IP address of the Mini Maxwell/Maxwell G.')
138 pargs = parser.parse_args()
140 mm_hostname = pargs.mm_hostname
147 except Exception
as err:
148 print(
"HTTP Exception occurred:", str(err))
151 for filt
in all_filter_names:
159 if a2bargs
is not None:
163 except Exception
as err:
164 print(
"Parameter error: %s - Aborting." % str(err))
167 if b2aargs
is not None:
171 except Exception
as err:
172 print(
"Parameter error: %s - Aborting." % str(err))
def GetAllFilterNames(mm_hostname)
def __init__(self, filtname, toband)
def GetMM2ConfigInJson(mm2name)
def SetFiltMap(mm2host, a2bfilt_vals, b2afilt_vals, all_filter_names=None)