+def dp_list():
+ output = StringIO.StringIO()
+ procs = [ProcOutput([OVS_DPCTL, 'dump-dps'], caps[CAP_NETWORK_STATUS][MAX_TIME], output)]
+
+ run_procs([procs])
+
+ if not procs[0].timed_out:
+ return output.getvalue().splitlines()
+ return []
+
+def bond_list(pid):
+ output = StringIO.StringIO()
+ procs = [ProcOutput([OVS_APPCTL, '-t', '/var/run/ovs-vswitchd.%s.ctl' % pid, '-e' 'bond/list'], caps[CAP_NETWORK_STATUS][MAX_TIME], output)]
+
+ run_procs([procs])
+
+ if not procs[0].timed_out:
+ bonds = output.getvalue().splitlines()[1:]
+ return [x.split('\t')[1] for x in bonds]
+ return []
+
+def fd_usage(cap):
+ output = ''
+ fd_dict = {}
+ for d in [p for p in os.listdir('/proc') if p.isdigit()]:
+ try:
+ fh = open('/proc/'+d+'/cmdline')
+ name = fh.readline()
+ num_fds = len(os.listdir(os.path.join('/proc/'+d+'/fd')))
+ if num_fds > 0:
+ if not num_fds in fd_dict:
+ fd_dict[num_fds] = []
+ fd_dict[num_fds].append(name.replace('\0', ' ').strip())
+ finally:
+ fh.close()
+ keys = fd_dict.keys()
+ keys.sort(lambda a, b: int(b) - int(a))
+ for k in keys:
+ output += "%s: %s\n" % (k, str(fd_dict[k]))
+ return output
+
+def load_plugins(just_capabilities = False):
+ def getText(nodelist):
+ rc = ""
+ for node in nodelist:
+ if node.nodeType == node.TEXT_NODE:
+ rc += node.data
+ return rc.encode()
+
+ def getBoolAttr(el, attr, default = False):
+ ret = default
+ val = el.getAttribute(attr).lower()
+ if val in ['true', 'false', 'yes', 'no']:
+ ret = val in ['true', 'yes']
+ return ret
+
+ for dir in [d for d in os.listdir(PLUGIN_DIR) if os.path.isdir(os.path.join(PLUGIN_DIR, d))]:
+ if not caps.has_key(dir):
+ if not os.path.exists("%s/%s.xml" % (PLUGIN_DIR, dir)):
+ continue
+ xmldoc = parse("%s/%s.xml" % (PLUGIN_DIR, dir))
+ assert xmldoc.documentElement.tagName == "capability"
+
+ pii, min_size, max_size, min_time, max_time, mime = \
+ PII_MAYBE, -1,-1,-1,-1, MIME_TEXT
+
+ if xmldoc.documentElement.getAttribute("pii") in [PII_NO, PII_YES, PII_MAYBE, PII_IF_CUSTOMIZED]:
+ pii = xmldoc.documentElement.getAttribute("pii")
+ if xmldoc.documentElement.getAttribute("min_size") != '':
+ min_size = long(xmldoc.documentElement.getAttribute("min_size"))
+ if xmldoc.documentElement.getAttribute("max_size") != '':
+ max_size = long(xmldoc.documentElement.getAttribute("max_size"))
+ if xmldoc.documentElement.getAttribute("min_time") != '':
+ min_time = int(xmldoc.documentElement.getAttribute("min_time"))
+ if xmldoc.documentElement.getAttribute("max_time") != '':
+ max_time = int(xmldoc.documentElement.getAttribute("max_time"))
+ if xmldoc.documentElement.getAttribute("mime") in [MIME_DATA, MIME_TEXT]:
+ mime = xmldoc.documentElement.getAttribute("mime")
+ checked = getBoolAttr(xmldoc.documentElement, 'checked', True)
+ hidden = getBoolAttr(xmldoc.documentElement, 'hidden', False)
+
+ cap(dir, pii, min_size, max_size, min_time, max_time, mime, checked, hidden)
+
+ if just_capabilities:
+ continue
+
+ plugdir = os.path.join(PLUGIN_DIR, dir)
+ for file in [f for f in os.listdir(plugdir) if f.endswith('.xml')]:
+ xmldoc = parse(os.path.join(plugdir, file))
+ assert xmldoc.documentElement.tagName == "collect"
+
+ for el in xmldoc.documentElement.getElementsByTagName("*"):
+ if el.tagName == "files":
+ file_output(dir, getText(el.childNodes).split())
+ elif el.tagName == "directory":
+ pattern = el.getAttribute("pattern")
+ if pattern == '': pattern = None
+ negate = getBoolAttr(el, 'negate')
+ tree_output(dir, getText(el.childNodes), pattern and re.compile(pattern) or None, negate)
+ elif el.tagName == "command":
+ label = el.getAttribute("label")
+ if label == '': label = None
+ cmd_output(dir, getText(el.childNodes), label)
+