Esempio n. 1
0
def WbemAddBaseClass(grph, connWbem, wbemNode, entity_host, wbemNamespace,
                     entity_type):
    wbemKlass = lib_wbem.WbemGetClassObj(connWbem, entity_type, wbemNamespace)
    if not wbemKlass:
        return (None, None)

    superKlassName = wbemKlass.superclass

    # sys.stderr.write("WBEM superKlassName=%s\n" % superKlassName)
    # An empty string or None.
    if not superKlassName:
        return (None, None)

    # TODO: Should be changed, this is slow and inconvenient.
    wbemSuperUrlsList = lib_wbem.GetWbemUrls(entity_host, wbemNamespace,
                                             superKlassName, "")
    if not wbemSuperUrlsList:
        return (None, None)

    # TODO: Which one should we take, http or https ???
    wbemSuperUrl = wbemSuperUrlsList[0][0]
    sys.stderr.write("WBEM wbemSuperUrl=%s\n" % wbemSuperUrl)

    wbemSuperNode = lib_common.NodeUrl(wbemSuperUrl)

    grph.add((wbemSuperNode, pc.property_cim_subclass, wbemNode))
    klaDescrip = lib_wbem.WbemClassDescription(connWbem, superKlassName,
                                               wbemNamespace)
    if not klaDescrip:
        klaDescrip = "Undefined class %s %s" % (wbemNamespace, superKlassName)
    grph.add((wbemSuperNode, pc.property_information,
              lib_common.NodeLiteral(klaDescrip)))

    return (wbemSuperNode, superKlassName)
Esempio n. 2
0
def _create_wbem_node(grph, root_node, entity_host, name_space, class_name,
                      entity_id):
    wbem_namespace = name_space.replace("\\", "/")
    wbem_servers_desc_list = lib_wbem.GetWbemUrls(entity_host, wbem_namespace,
                                                  class_name, entity_id)

    # If there are no servers.
    pair_name_node = None

    for url_server in wbem_servers_desc_list:
        wbem_node = lib_common.NodeUrl(url_server[0])
        grph.add((root_node, pc.property_wbem_data, wbem_node))

        wbemHostNode = lib_uris.gUriGen.HostnameUri(url_server[1])
        grph.add((wbem_node, pc.property_host, wbemHostNode))

        # TODO: Add a Yawn server ??
        grph.add((wbem_node, pc.property_wbem_server,
                  lib_util.NodeLiteral(url_server[1])))

        # Now adds the description of the class.
        try:
            conn_wbem = lib_wbem.WbemConnection(entity_host)
        except Exception as exc:
            logging.error("WbemConnection throw:%s" % str(exc))
            continue

        kla_descrip = lib_wbem.WbemClassDescription(conn_wbem, class_name,
                                                    wbem_namespace)
        ok_wbem_class = True
        if not kla_descrip:
            ok_wbem_class = False
            kla_descrip = "Undefined class %s %s" % (wbem_namespace,
                                                     class_name)
        grph.add((wbem_node, pc.property_information,
                  lib_util.NodeLiteral(kla_descrip)))

        # Maybe this class is not Known in WBEM.
        try:
            pair_name_node = _wbem_add_all_base_classes(
                grph, conn_wbem, wbem_node, entity_host, name_space,
                class_name)
        except:
            pair_name_node = None

        if ok_wbem_class and wbem_ok and name_space != "" and entity_host != "":
            namespace_url = lib_wbem.NamespaceUrl(name_space, entity_host,
                                                  class_name)
            namespace_node = lib_common.NodeUrl(namespace_url)
            grph.add((wbem_node, pc.property_information, namespace_node))

    # TODO: This is a bit absurd because we return just one list.
    return pair_name_node
Esempio n. 3
0
def CreateWbemNode(grph, rootNode, entity_host, nameSpace, className,
                   entity_id):
    wbemNamespace = nameSpace.replace("\\", "/")
    wbem_servers_desc_list = lib_wbem.GetWbemUrls(entity_host, wbemNamespace,
                                                  className, entity_id)

    # If there are no servers.
    pairNameNode = None

    for url_server in wbem_servers_desc_list:
        wbemNode = lib_common.NodeUrl(url_server[0])
        grph.add((rootNode, pc.property_wbem_data, wbemNode))

        # Le naming est idiot: "rchateau-HP at localhost"
        wbemHostNode = lib_common.gUriGen.HostnameUri(url_server[1])
        grph.add((wbemNode, pc.property_host, wbemHostNode))

        # TODO: Add a Yawn server ??
        grph.add((wbemNode, pc.property_wbem_server,
                  lib_common.NodeLiteral(url_server[1])))

        # Now adds the description of the class.
        connWbem = lib_wbem.WbemConnection(entity_host)
        klaDescrip = lib_wbem.WbemClassDescription(connWbem, className,
                                                   wbemNamespace)
        okWbemClass = True
        if not klaDescrip:
            okWbemClass = False
            klaDescrip = "Undefined class %s %s" % (wbemNamespace, className)
        grph.add((wbemNode, pc.property_information,
                  lib_common.NodeLiteral(klaDescrip)))

        # Maybe this class is not Known in WBEM.
        try:
            pairNameNode = WbemAddBaseClasses(grph, connWbem, wbemNode,
                                              entity_host, nameSpace,
                                              className)
        except:
            pairNameNode = None

        if okWbemClass and wbemOk and nameSpace != "" and entity_host != "":
            namespaceUrl = lib_wbem.NamespaceUrl(nameSpace, entity_host,
                                                 className)
            namespaceNode = lib_common.NodeUrl(namespaceUrl)
            grph.add((wbemNode, pc.property_information, namespaceNode))

    # TODO: This is a bit absurd because we return just one list.
    return pairNameNode
Esempio n. 4
0
def _wbem_add_base_class(grph, conn_wbem, wbem_node, entity_host,
                         wbem_namespace, entity_type):
    # Adds the base classes of this one, at least one one level."""
    wbem_klass = lib_wbem.WbemGetClassObj(conn_wbem, entity_type,
                                          wbem_namespace)
    if not wbem_klass:
        return None, None

    super_klass_name = wbem_klass.superclass

    # An empty string or None.
    if not super_klass_name:
        return None, None

    # TODO: Should be changed, this is slow and inconvenient.
    wbem_super_urls_list = lib_wbem.GetWbemUrls(entity_host, wbem_namespace,
                                                super_klass_name, "")
    if not wbem_super_urls_list:
        return None, None

    # TODO: Which one should we take, http or https ???
    wbem_super_url = wbem_super_urls_list[0][0]
    logging.debug("WBEM wbem_super_url=%s", wbem_super_url)

    wbem_super_node = lib_common.NodeUrl(wbem_super_url)

    grph.add((wbem_super_node, pc.property_cim_subclass, wbem_node))
    kla_descrip = lib_wbem.WbemClassDescription(conn_wbem, super_klass_name,
                                                wbem_namespace)
    if not kla_descrip:
        kla_descrip = "Undefined class %s %s" % (wbem_namespace,
                                                 super_klass_name)
    grph.add((wbem_super_node, pc.property_information,
              lib_util.NodeLiteral(kla_descrip)))

    return wbem_super_node, super_klass_name
Esempio n. 5
0
def Main():
    paramkeyMaxDepth = "Maximum depth"
    paramkeyYawnUrls = "Yawn urls"

    # TODO: The type should really be an integer.
    cgiEnv = lib_common.CgiEnv(can_process_remote=True,
                               parameters={
                                   paramkeyMaxDepth: 2,
                                   paramkeyYawnUrls: False
                               })

    wbemNamespace, entity_type = cgiEnv.get_namespace_type()

    maxDepth = int(cgiEnv.get_parameters(paramkeyMaxDepth))
    withYawnUrls = int(cgiEnv.get_parameters(paramkeyYawnUrls))

    DEBUG("wbemNamespace=%s entity_type=%s maxDepth=%d", wbemNamespace,
          entity_type, maxDepth)

    cimomUrl = cgiEnv.GetHost()

    if str(wbemNamespace) == "":
        lib_common.ErrorMessageHtml("namespace should not be empty.")

    grph = cgiEnv.GetGraph()

    connWbem = lib_wbem.WbemConnection(cimomUrl)

    # entity_type might an empty string.
    rootNode = WbemNamespaceNode(wbemNamespace, cimomUrl, entity_type)

    DEBUG("objtypes_wmi.py cimomUrl=%s entity_type=%s", cimomUrl, entity_type)

    treeClassesFiltered = lib_wbem.GetClassesTreeInstrumented(
        connWbem, wbemNamespace)

    PrintClassRecu(grph, rootNode, treeClassesFiltered, entity_type, 0,
                   wbemNamespace, cimomUrl, maxDepth, withYawnUrls)

    DEBUG("entity_type=%s", entity_type)

    # If we are not at the top of the tree:
    if entity_type != "":
        # Now, adds the base classes of this one, at least one one level.
        wbemKlass = lib_wbem.WbemGetClassObj(connWbem, entity_type,
                                             wbemNamespace)
        if wbemKlass:
            superKlassName = wbemKlass.superclass

            DEBUG("superKlassName=%s", superKlassName)
            # An empty string or None.
            if superKlassName:
                wbemSuperNode = WbemNamespaceNode(wbemNamespace, cimomUrl,
                                                  superKlassName)
                grph.add((wbemSuperNode, pc.property_cim_subclass, rootNode))
                klaDescrip = lib_wbem.WbemClassDescription(
                    connWbem, superKlassName, wbemNamespace)
                if not klaDescrip:
                    klaDescrip = "Undefined class %s %s" % (wbemNamespace,
                                                            superKlassName)
                grph.add((wbemSuperNode, pc.property_information,
                          lib_common.NodeLiteral(klaDescrip)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT_TB", [pc.property_cim_subclass])
Esempio n. 6
0
def Main():

    cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True)

    entity_id = cgiEnv.GetId()
    logging.debug("entity_id=%s", entity_id)
    if entity_id == "":
        lib_common.ErrorMessageHtml("No entity_id")

    # Just the path, shorter than cgiEnv.get_parameters("xid")
    cimom_url = cgiEnv.GetHost()

    name_space, class_name = cgiEnv.get_namespace_type()
    logging.debug("cimom_url=%s name_space=%s class_name=%s", cimom_url,
                  name_space, class_name)

    if name_space == "":
        name_space = "root/cimv2"
        logging.info("Setting namespace to default value.")

    if class_name == "":
        lib_common.ErrorMessageHtml("No class name. entity_id=%s" % entity_id)

    grph = cgiEnv.GetGraph()

    try:
        conn = lib_wbem.WbemConnection(cimom_url)
    except Exception as exc:
        lib_common.ErrorMessageHtml("Connecting to :" + cimom_url +
                                    " Caught:" + str(exc))

    root_node = lib_util.EntityClassNode(class_name, name_space, cimom_url,
                                         "WBEM")
    kla_descrip = lib_wbem.WbemClassDescription(conn, class_name, name_space)
    if not kla_descrip:
        kla_descrip = "Undefined class %s %s" % (name_space, class_name)
    grph.add((root_node, pc.property_information,
              lib_util.NodeLiteral(kla_descrip)))

    split_monik = cgiEnv.m_entity_id_dict

    logging.debug("entity_wbem.py name_space=%s class_name=%s cimom_url=%s",
                  name_space, class_name, cimom_url)

    # This works:
    # conn = pywbem.WBEMConnection("http://192.168.0.17:5988",("pegasus","toto"))
    # conn.ExecQuery("WQL","select * from CIM_System","root/cimv2")
    # conn.ExecQuery("WQL",'select * from CIM_Process  where Handle="4125"',"root/cimv2")
    #
    # select * from CIM_Directory or CIM_DataFile does not return anything.

    inst_lists = WbemPlainExecQuery(conn, class_name, split_monik, name_space)
    logging.debug("inst_lists=%s", str(inst_lists))
    if inst_lists is None:
        inst_lists = WbemNoQueryOneInst(conn, class_name, split_monik,
                                        name_space)
        if inst_lists is None:
            inst_lists = WbemNoQueryFilterInstances(conn, class_name,
                                                    split_monik, name_space)

    # TODO: Some objects are duplicated.
    # 'CSCreationClassName'   CIM_UnitaryComputerSystem Linux_ComputerSystem
    # 'CreationClassName'     PG_UnixProcess            TUT_UnixProcess
    num_insts = len(inst_lists)

    # If there are duplicates, adds a property which we hope is different.
    prop_discrim = "CreationClassName"

    # TODO!! WHAT OF THIS IS NOT THE RIGHT ORDER ???
    # Remove the double-quotes around the argument. WHAT IF THEY ARE NOT THERE ??

    for an_inst in inst_lists:

        # TODO: Use the right accessor for better performance.
        # On peut peut etre mettre tout ca dans une fonction sauf l execution de la query.
        dict_inst = dict(an_inst)

        # This differentiates several instance with the same properties.
        if num_insts > 1:
            # TODO: Should check if this property is different for all instances !!!
            with_extra_args = {prop_discrim: dict_inst[prop_discrim]}
            all_args = split_monik.copy()
            all_args.update(with_extra_args)
            dict_props = all_args
        else:
            dict_props = split_monik

        host_only = lib_util.EntHostToIp(cimom_url)
        uri_inst = lib_common.MachineBox(host_only).node_from_dict(
            class_name, dict_props)

        grph.add((root_node, lib_common.MakeProp(class_name), uri_inst))

        AddNamespaceLink(grph, root_node, name_space, cimom_url, class_name)

        # None properties are not printed.
        for iname_key in dict_inst:
            # Do not print twice values which are in the name.
            if iname_key in split_monik:
                continue
            iname_val = dict_inst[iname_key]
            # TODO: If this is a reference, create a Node !!!!!!!
            if not iname_val is None:
                grph.add((uri_inst, lib_common.MakeProp(iname_key),
                          lib_util.NodeLiteral(iname_val)))

        # TODO: Should call Associators(). Same for References().

    cgiEnv.OutCgiRdf()
Esempio n. 7
0
sys.stderr.write("entity_wbem.py cimomUrl=%s nameSpace=%s className=%s\n" %
                 (cimomUrl, nameSpace, className))

if nameSpace == "":
    nameSpace = "root/cimv2"
    sys.stderr.write("Setting namespace to default value\n")

if className == "":
    lib_common.ErrorMessageHtml("No class name. entity_id=%s" % entity_id)

grph = cgiEnv.GetGraph()

conn = lib_wbem.WbemConnection(cimomUrl)

rootNode = lib_util.EntityClassNode(className, nameSpace, cimomUrl, "WBEM")
klaDescrip = lib_wbem.WbemClassDescription(conn, className, nameSpace)
if not klaDescrip:
    klaDescrip = "Undefined class %s %s" % (nameSpace, className)
grph.add(
    (rootNode, pc.property_information, lib_common.NodeLiteral(klaDescrip)))

splitMonik = lib_util.SplitMoniker(cgiEnv.m_entity_id)

sys.stderr.write("entity_wbem.py nameSpace=%s className=%s cimomUrl=%s\n" %
                 (nameSpace, className, cimomUrl))

# This works:
# conn = pywbem.WBEMConnection("http://192.168.0.17:5988",("pegasus","toto"))
# conn.ExecQuery("WQL","select * from CIM_System","root/cimv2")
# conn.ExecQuery("WQL",'select * from CIM_Process  where Handle="4125"',"root/cimv2")
#
Esempio n. 8
0
def Main():

	cgiEnv = lib_common.CgiEnv(can_process_remote = True)

	entity_id = cgiEnv.GetId()
	DEBUG("entity_id=%s", entity_id)
	if entity_id == "":
		lib_common.ErrorMessageHtml("No entity_id")


	# Just the path, shorter than cgiEnv.get_parameters("xid")
	cimomUrl = cgiEnv.GetHost()

	nameSpace, className = cgiEnv.get_namespace_type()
	DEBUG("entity_wbem.py cimomUrl=%s nameSpace=%s className=%s", cimomUrl,nameSpace,className)

	if nameSpace == "":
		nameSpace = "root/cimv2"
		INFO("Setting namespace to default value\n")


	if className == "":
		lib_common.ErrorMessageHtml("No class name. entity_id=%s" % entity_id)

	grph = cgiEnv.GetGraph()

	conn = lib_wbem.WbemConnection(cimomUrl)

	rootNode = lib_util.EntityClassNode( className, nameSpace, cimomUrl, "WBEM" )
	klaDescrip = lib_wbem.WbemClassDescription(conn,className,nameSpace)
	if not klaDescrip:
		klaDescrip = "Undefined class %s %s" % ( nameSpace, className )
	grph.add( ( rootNode, pc.property_information, lib_common.NodeLiteral(klaDescrip ) ) )

	splitMonik = lib_util.SplitMoniker( cgiEnv.m_entity_id )

	DEBUG("entity_wbem.py nameSpace=%s className=%s cimomUrl=%s",nameSpace,className,cimomUrl)

	# This works:
	# conn = pywbem.WBEMConnection("http://192.168.0.17:5988",("pegasus","toto"))
	# conn.ExecQuery("WQL","select * from CIM_System","root/cimv2")
	# conn.ExecQuery("WQL",'select * from CIM_Process  where Handle="4125"',"root/cimv2")
	#
	# select * from CIM_Directory or CIM_DataFile does not return anything.


	instLists = WbemPlainExecQuery( conn, className, splitMonik, nameSpace )
	DEBUG("entity_wbem.py instLists=%s",str(instLists))
	if instLists is None:
		instLists = WbemNoQueryOneInst( conn, className, splitMonik, nameSpace )
		if instLists is None:
			instLists = WbemNoQueryFilterInstances( conn, className, splitMonik, nameSpace )

	# TODO: Some objects are duplicated.
	# 'CSCreationClassName'   CIM_UnitaryComputerSystem Linux_ComputerSystem
	# 'CreationClassName'     PG_UnixProcess            TUT_UnixProcess
	numInsts = len(instLists)

	# If there are duplicates, adds a property which we hope is different.
	propDiscrim = "CreationClassName"

	# TODO!! WHAT OF THIS IS NOT THE RIGHT ORDER ???
	# Remove the double-quotes around the argument. WHAT IF THEY ARE NOT THERE ??
	# arrVals = [ ChopEnclosingParentheses( splitMonik[qryKey] ) for qryKey in splitMonik ]

	for anInst in instLists:

		# TODO: Use the right accessor for better performance.
		# On peut peut etre mettre tout ca dans une fonction sauf l execution de la query.
		dictInst = dict(anInst)

		# This differentiates several instance with the same properties.


		if numInsts > 1:
			# TODO: Should check if this property is different for all instances !!!
			withExtraArgs = { propDiscrim : dictInst[ propDiscrim ] }
			allArgs = splitMonik.copy()
			allArgs.update(withExtraArgs)
			dictProps = allArgs
		else:
			dictProps = splitMonik

		hostOnly = lib_util.EntHostToIp(cimomUrl)
		if lib_util.IsLocalAddress(hostOnly):
			uriInst = lib_common.gUriGen.UriMakeFromDict(className, dictProps)
		else:
			uriInst = lib_common.RemoteBox(hostOnly).UriMakeFromDict(className, dictProps)

		grph.add( ( rootNode, lib_common.MakeProp(className), uriInst ) )

		AddNamespaceLink(grph, rootNode, nameSpace, cimomUrl, className)

		# None properties are not printed.
		for inameKey in dictInst:
			# Do not print twice values which are in the name.
			if inameKey in splitMonik:
				continue
			inameVal = dictInst[inameKey]
			# TODO: If this is a reference, create a Node !!!!!!!
			if not inameVal is None:
				grph.add( ( uriInst, lib_common.MakeProp(inameKey), lib_common.NodeLiteral(inameVal) ) )

		# TODO: Should call Associators(). Same for References().

	cgiEnv.OutCgiRdf()
Esempio n. 9
0
def Main():
    paramkey_max_depth = "Maximum depth"
    paramkey_yawn_urls = "Yawn urls"

    # TODO: The type should really be an integer.
    cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True,
                                          parameters={
                                              paramkey_max_depth: 2,
                                              paramkey_yawn_urls: False
                                          })

    wbem_namespace, entity_type = cgiEnv.get_namespace_type()

    max_depth = int(cgiEnv.get_parameters(paramkey_max_depth))
    with_yawn_urls = int(cgiEnv.get_parameters(paramkey_yawn_urls))

    logging.debug("wbem_namespace=%s entity_type=%s max_depth=%d",
                  wbem_namespace, entity_type, max_depth)

    cimom_url = cgiEnv.GetHost()

    if str(wbem_namespace) == "":
        lib_common.ErrorMessageHtml("namespace should not be empty.")

    grph = cgiEnv.GetGraph()

    try:
        conn_wbem = lib_wbem.WbemConnection(cimom_url)
    except Exception as exc:
        lib_common.ErrorMessageHtml("Connecting to :" + cimom_url +
                                    " Caught:" + str(exc))

    # entity_type might an empty string.
    root_node = _wbem_namespace_node(wbem_namespace, cimom_url, entity_type)

    logging.debug("cimom_url=%s entity_type=%s", cimom_url, entity_type)

    tree_classes_filtered = lib_wbem.GetClassesTreeInstrumented(
        conn_wbem, wbem_namespace)

    _print_class_recu(grph, root_node, tree_classes_filtered, entity_type, 0,
                      wbem_namespace, cimom_url, max_depth, with_yawn_urls)

    logging.debug("entity_type=%s", entity_type)

    # If we are not at the top of the tree:
    if entity_type != "":
        # Now, adds the base classes of this one, at least one one level.
        wbem_klass = lib_wbem.WbemGetClassObj(conn_wbem, entity_type,
                                              wbem_namespace)
        if wbem_klass:
            super_klass_name = wbem_klass.superclass

            logging.debug("super_klass_name=%s", super_klass_name)
            # An empty string or None.
            if super_klass_name:
                wbem_super_node = _wbem_namespace_node(wbem_namespace,
                                                       cimom_url,
                                                       super_klass_name)
                grph.add(
                    (wbem_super_node, pc.property_cim_subclass, root_node))
                kla_descrip = lib_wbem.WbemClassDescription(
                    conn_wbem, super_klass_name, wbem_namespace)
                if not kla_descrip:
                    kla_descrip = "Undefined class %s %s" % (wbem_namespace,
                                                             super_klass_name)
                grph.add((wbem_super_node, pc.property_information,
                          lib_util.NodeLiteral(kla_descrip)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT_TB", [pc.property_cim_subclass])