42 jdata = json.loads(mm2_config_in_json)
43 full_config = jdata[2]
44 return set([str(filt[
'name'])
for filt
in full_config[
"filters"]])
50 conn = httplib.HTTPConnection(mm2name)
51 conn.request(
"GET",
"/mm2/mpc/mm2.py/get_config_json")
52 resp = conn.getresponse()
54 if (resp.status/100) != 2:
55 raise Exception(resp.reason)
67 if (bnum <= 0)
or (bnum > 5):
68 raise ValueError(
"Band number for \"%s\" must be in range 1..5" % filtname)
75 def SetFiltMap(mm2host, a2bfilt_vals, b2afilt_vals, all_filter_names=None):
77 if all_filter_names
is None:
81 if (a2bfilt_vals
is None):
83 if (b2afilt_vals
is None):
87 for fvals
in (a2bfilt_vals, b2afilt_vals):
89 if filt.FiltName
not in all_filter_names:
90 raise ValueError(
"Filter name \"%s\" is not present" % filt.FiltName)
92 offa2b = all_filter_names.difference(set(map(
lambda x: x.FiltName, a2bfilt_vals)))
93 offb2a = all_filter_names.difference(set(map(
lambda x: x.FiltName, b2afilt_vals)))
97 fdict[
"DBNDS_%s" % fn] =
"down-band-none" 99 fdict[
"UBNDS_%s" % fn] =
"up-band-none" 101 for fs
in a2bfilt_vals:
102 fdict[
"DBNDS_%s" % fs.FiltName] =
"down-band-%d" % fs.ToBand
103 for fs
in b2afilt_vals:
104 fdict[
"UBNDS_%s" % fs.FiltName] =
"up-band-%d" % fs.ToBand
106 fdict[
"SUBMIT_FILTERMAP_BUTTON"] =
"Submit" 108 conn = httplib.HTTPConnection(mm2host)
109 params = urllib.urlencode(fdict)
110 headers = {
"Content-type":
"application/x-www-form-urlencoded",
111 "Accept":
"text/plain"}
112 conn.request(
"POST",
"/mm2/mpc/mm2.py/process_filtmap", params, headers)
113 resp = conn.getresponse()
115 if (resp.status/100) != 2:
116 raise Exception(resp.reason)
123 if __name__ ==
"__main__":
127 parser = argparse.ArgumentParser(description=
"Set classification filter map.")
129 parser.add_argument(
"-A", action=
"append", nargs=2, dest=
"a2b",
130 help=
"Specify a filter name and band number for packats flowing LanA to Lan B.")
132 parser.add_argument(
"-B", action=
"append", nargs=2, dest=
"b2a",
133 help=
"Specify a filter name and band number for packats flowing LanB to Lan A.")
135 parser.add_argument(
"-d",
"--defaults", action=
"store_true",
136 help=
"Turn all filters off (default state).")
138 parser.add_argument(
"-f",
"--filters", action=
"store_true",
139 help=
"List all the flters, do nothing else.")
141 parser.add_argument(
"mm_hostname",
142 help=
'The host name or IP address of the Mini Maxwell/Maxwell G.')
144 pargs = parser.parse_args()
146 mm_hostname = pargs.mm_hostname
153 except Exception
as err:
154 print(
"HTTP Exception occurred:", str(err))
157 for filt
in all_filter_names:
165 if a2bargs
is not None:
169 except Exception
as err:
170 print(
"Parameter error: %s - Aborting." % str(err))
173 if b2aargs
is not None:
177 except Exception
as err:
178 print(
"Parameter error: %s - Aborting." % str(err))
def __init__(self, filtname, toband)
def GetMM2ConfigInJson(mm2name)
def SetFiltMap(mm2host, a2bfilt_vals, b2afilt_vals, all_filter_names=None)
def GetAllFilterNames(mm_hostname)