Ejemplo n.º 1
0
def SubNamespace( rootNode, grph, nskey, cimomUrl, nsDepth = 1 ):

	# TODO: VERY PRIMITIVE HARD-CODE TO UNDERSTAND WHY IT RETURNS THE SAME SUB-SUB-NAMESPACES
	# BEYOND LEVEL TWO.
	if nsDepth > 2:
		return

	try:
		# connWMI = lib_wmi.WmiConnect(cimomUrl,nskey)
		# connWMI = lib_wmi.WmiConnect(cimomUrl,"root\\" + nskey, False)
		connWMI = lib_wmi.WmiConnect(cimomUrl,nskey, False)
		# With the last flag, it does not throw if it cannot connect.
		if not connWMI:
			return
	except wmi.x_wmi:
		exc = sys.exc_info()[1]
		# lib_common.ErrorMessageHtml("EXCEPT WMI nskey=%s Caught:%s" % ( nskey , str(exc) ) )
		sys.stderr.write("WMI: Cannot connect to nskey=%s Caught:%s" % ( nskey , str(exc) ) )
		return

	# If the mximum level is not controlled, it loops endlessly.
	# SubNamespace cimomUrl=rchateau-HP nskey=aspnet\Security\Security\Security\Security\Security\Security\Security\Security\Security\Secu
	sys.stderr.write("SubNamespace cimomUrl=%s nskey=%s\n" % (cimomUrl,nskey))

	# connWMI = lib_wmi.WmiConnect(cimomUrl,nskey)

	wmiUrl = lib_wmi.NamespaceUrl( "root\\" + nskey, cimomUrl )
	wmiNode = lib_common.NodeUrl( wmiUrl )

	grph.add( ( rootNode, pc.property_cim_subnamespace, wmiNode ) )

	try:
		lstNamespaces = connWMI.__NAMESPACE()
		sys.stderr.write("lstNamespaces=%s\n"%lstNamespaces)
		# lstNamespaces=[<_wmi_object: \\RCHATEAU-HP\ROOT\cimv2:__NAMESPACE.Name="Security">, <_wmi_object: \\RCHATEAU-HP\ROOT\cimv2:__NAMESPA
		# CE.Name="power">, <_wmi_object: \\RCHATEAU-HP\ROOT\cimv2:__NAMESPACE.Name="ms_409">, <_wmi_object: \\RCHATEAU-HP\ROOT\cimv2:__NAMESP
		# ACE.Name="TerminalServices">, <_wmi_object: \\RCHATEAU-HP\ROOT\cimv2:__NAMESPACE.Name="Applications">]

		for subnamespace in lstNamespaces:
			SubNamespace( wmiNode, grph, nskey + "\\" + subnamespace.Name, cimomUrl, nsDepth +1 )
	except Exception:
		exc = sys.exc_info()[1]
		grph.add( ( wmiNode, pc.property_information, lib_common.NodeLiteral("Caught:%s" % str(exc) ) ) )
Ejemplo n.º 2
0
def _create_wmi_node(grph, root_node, entity_host, name_space, class_name,
                     entity_id):
    """Adds a WMI node and other stuff, for the class name."""
    wmiurl = lib_wmi.GetWmiUrl(entity_host, name_space, class_name, entity_id)
    if wmiurl is None:
        return

    # There might be "http:" or the port number around the host.
    wmi_node = lib_common.NodeUrl(wmiurl)
    grph.add((root_node, pc.property_wmi_data, wmi_node))

    # TODO: Shame, we just did it in GetWmiUrl.
    ip_only = lib_util.EntHostToIp(entity_host)
    try:
        # It simply returns if it cannot connect.
        conn_wmi = lib_wmi.WmiConnect(ip_only, name_space, False)
        if not conn_wmi:
            raise Exception("Cannot connect")
        lib_wmi.WmiAddClassQualifiers(grph, conn_wmi, wmi_node, class_name,
                                      False)

        # Now displays the base classes, to the top of the inheritance tree.
        pair_name_node = lib_wmi.WmiAddBaseClasses(grph, conn_wmi, wmi_node,
                                                   ip_only, name_space,
                                                   class_name)

    except Exception as exc:
        pair_name_node = None
        # TODO: If the class is not defined, maybe do not display it.
        err_msg = "WMI connection %s: %s" % (ip_only, str(exc))
        grph.add((wmi_node, lib_common.MakeProp("WMI Error"),
                  lib_util.NodeLiteral(err_msg)))

    url_name_space = lib_wmi.NamespaceUrl(name_space, ip_only, class_name)
    grph.add((wmi_node, pc.property_information,
              lib_common.NodeUrl(url_name_space)))

    return pair_name_node
Ejemplo n.º 3
0
def _sub_namespace(root_node, grph, nskey, cimom_url, ns_depth=1):

    # TODO: VERY PRIMITIVE HARD-CODE TO UNDERSTAND WHY IT RETURNS THE SAME SUB-SUB-NAMESPACES
    # BEYOND LEVEL TWO.
    if ns_depth > 2:
        return

    try:
        conn_wmi = lib_wmi.WmiConnect(cimom_url, nskey, False)
        # With the last flag, it does not throw if it cannot connect.
        if not conn_wmi:
            return
    except wmi.x_wmi as exc:
        logging.warning("WMI: Cannot connect to nskey=%s Caught:%s", nskey, str(exc))
        return

    # If the maximum level is not controlled, it loops endlessly.
    # _sub_namespace cimomUrl=mymachine nskey=aspnet\Security\Security\Security\Security\Security\Security\Security\Security\Security\Secu
    logging.debug("_sub_namespace cimomUrl=%s nskey=%s", cimom_url, nskey)

    wmi_url = lib_wmi.NamespaceUrl("root\\" + nskey, cimom_url)
    wmi_node = lib_common.NodeUrl( wmi_url)

    grph.add((root_node, pc.property_cim_subnamespace, wmi_node))

    try:
        lst_namespaces = conn_wmi.__NAMESPACE()
        logging.debug("lst_namespaces=%s", lst_namespaces)
        # lst_namespaces=[<_wmi_object: \\MYMACHINE\ROOT\cimv2:__NAMESPACE.Name="Security">, <_wmi_object: \\MYMACHINE\ROOT\cimv2:__NAMESPA
        # CE.Name="power">, <_wmi_object: \\MYMACHINE\ROOT\cimv2:__NAMESPACE.Name="ms_409">, <_wmi_object: \\MYMACHINE\ROOT\cimv2:__NAMESP
        # ACE.Name="TerminalServices">, <_wmi_object: \\MYMACHINE\ROOT\cimv2:__NAMESPACE.Name="Applications">]

        for subnamespace in lst_namespaces:
            _sub_namespace(wmi_node, grph, nskey + "\\" + subnamespace.Name, cimom_url, ns_depth + 1)
    except Exception as exc:
        grph.add((wmi_node, pc.property_information, lib_util.NodeLiteral("Caught:%s" % str(exc))))
Ejemplo n.º 4
0
def CreateWmiNode(grph, rootNode, entity_host, nameSpace, className,
                  entity_id):
    wmiurl = lib_wmi.GetWmiUrl(entity_host, nameSpace, className, entity_id)
    if wmiurl is None:
        return

    # There might be "http:" or the port number around the host.
    # hostOnly = lib_util.EntHostToIp(entity_host)
    # sys.stderr.write("entity_host=%s nameSpace=%s entity_type=%s className=%s wmiurl=%s\n" % ( entity_host, nameSpace, entity_type, className, str(wmiurl) ) )
    wmiNode = lib_common.NodeUrl(wmiurl)
    grph.add((rootNode, pc.property_wmi_data, wmiNode))

    # TODO: Shame, we just did it in GetWmiUrl.
    ipOnly = lib_util.EntHostToIp(entity_host)
    try:
        # It simply returns if it cannot connect.
        connWmi = lib_wmi.WmiConnect(ipOnly, nameSpace, False)
        lib_wmi.WmiAddClassQualifiers(grph, connWmi, wmiNode, className, False)

        # Now displays the base classes, to the top of the inheritance tree.
        pairNameNode = lib_wmi.WmiAddBaseClasses(grph, connWmi, wmiNode,
                                                 ipOnly, nameSpace, className)

    except Exception:
        pairNameNode = None
        # TODO: If the class is not defined, maybe do not display it.
        exc = sys.exc_info()[1]
        grph.add((wmiNode, lib_common.MakeProp("WMI Error"),
                  lib_common.NodeLiteral(str(exc))))

    urlNameSpace = lib_wmi.NamespaceUrl(nameSpace, ipOnly, className)
    # sys.stderr.write("entity_host=%s urlNameSpace=%s\n"%(entity_host,urlNameSpace))
    grph.add(
        (wmiNode, pc.property_information, lib_common.NodeUrl(urlNameSpace)))

    return pairNameNode
Ejemplo n.º 5
0
def WmiNamespaceNode(wmiNamespace, cimomUrl, clsNam):
    # objtypes_wmi.py
    wmiUrl = lib_wmi.NamespaceUrl(wmiNamespace, cimomUrl, clsNam)
    return lib_common.NodeUrl(wmiUrl)
Ejemplo n.º 6
0
def _wmi_namespace_node(wmi_namespace, cimom_url, cls_nam):
    wmi_url = lib_wmi.NamespaceUrl(wmi_namespace, cimom_url, cls_nam)
    return lib_common.NodeUrl(wmi_url)