Exemplo n.º 1
0
def Main():
    cgiEnv = lib_common.ScriptEnvironment(can_process_remote=True)

    cimom_url = cgiEnv.GetHost()

    grph = cgiEnv.GetGraph()

    # There is no consensus on the WBEM class for namespaces,
    # so we have ours which must be correctly mapped.
    namespace_class = "wbem_namespace"
    root_node = lib_util.EntityUri(namespace_class, "")

    try:
        conn_wbem = lib_wbem.WbemConnection(cimom_url)
        nsd = lib_wbem.EnumNamespacesCapabilities(conn_wbem)
    except Exception as exc:
        lib_common.ErrorMessageHtml("Namespaces from :" + cimom_url +
                                    " Caught:" + str(exc))

    # TODO: We should draw a namespaces tree but more examples needed.
    for nskey in nsd:

        cnt = nsd[nskey]
        wbem_url = lib_wbem.NamespaceUrl(nskey, cimom_url)
        wbem_node = lib_common.NodeUrl(wbem_url)

        grph.add((root_node, pc.property_cim_subnamespace, wbem_node))
        grph.add(
            (wbem_node, pc.property_information, lib_util.NodeLiteral(nskey)))
        grph.add(
            (wbem_node, pc.property_information, lib_util.NodeLiteral(cnt)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT")
Exemplo n.º 2
0
def Main():
    # TODO: can_process_remote should be suppressed because it duplicates CanProcessRemote
    cgiEnv = lib_common.CgiEnv(can_process_remote=True)
    pid = int(cgiEnv.GetId())
    machine_name = cgiEnv.GetHost()

    grph = cgiEnv.GetGraph()

    cimom_url = lib_wbem.HostnameToWbemServer(machine_name)

    DEBUG(
        "wbem_process_info.py currentHostname=%s pid=%d machine_name=%s cimom_url=%s",
        lib_util.currentHostname, pid, machine_name, cimom_url)

    conn_wbem = lib_wbem.WbemConnection(cimom_url)

    name_space = "root/cimv2"
    try:
        inst_lists = conn_wbem.ExecQuery(
            "WQL", 'select * from CIM_Process  where Handle="%s"' % pid,
            name_space)
    except:
        lib_common.ErrorMessageHtml("Error:" + str(sys.exc_info()))

    class_name = "CIM_Process"
    dict_props = {"Handle": pid}

    root_node = lib_util.EntityClassNode(class_name, name_space, cimom_url,
                                         "WBEM")

    # There should be only one object, hopefully.
    for an_inst in inst_lists:
        dict_inst = dict(an_inst)

        host_only = lib_util.EntHostToIp(cimom_url)
        if lib_util.IsLocalAddress(host_only):
            uri_inst = lib_common.gUriGen.UriMakeFromDict(
                class_name, dict_props)
        else:
            uri_inst = lib_common.RemoteBox(host_only).UriMakeFromDict(
                class_name, dict_props)

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

        url_namespace = lib_wbem.NamespaceUrl(name_space, cimom_url,
                                              class_name)
        nod_namespace = lib_common.NodeUrl(url_namespace)
        grph.add((root_node, pc.property_cim_subnamespace, nod_namespace))

        # None properties are not printed.
        for iname_key in dict_inst:
            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_common.NodeLiteral(iname_val)))

        # TODO: Call the method Associators(). Idem References().

    cgiEnv.OutCgiRdf()
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
def Main():
    cgiEnv = lib_common.CgiEnv(can_process_remote=True)

    cimomUrl = cgiEnv.GetHost()

    grph = cgiEnv.GetGraph()

    # There is no consensus on the WBEM class for namespaces,
    # so we have ours which must be correctly mapped.
    namespace_class = "wbem_namespace"
    rootNode = lib_util.EntityUri(namespace_class, "")

    connWbem = lib_wbem.WbemConnection(cimomUrl)

    try:
        nsd = lib_wbem.EnumNamespacesCapabilities(connWbem)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Namespaces from :" + cimomUrl +
                                    " Caught:" + str(exc))

    # TODO: We should draw a namespaces tree but more examples needed.
    for nskey in nsd:

        cnt = nsd[nskey]
        # Special case because it is not displayed like a normal entity.
        # Oui mais ca marche aussi avec wmi ?
        # Pourrait-on combiner namespace+classe ? entity_type="root/cim_v2/CIM_Process" ?
        # Si l'entity_type termine par un slash, donc c'est un namespace ?
        # Ca nous permettrait de creer des namespaces dans notre ontologie,
        # par exemple pour Oracle. Ce serait simplement un directory.
        # ATTENTION: Avoir la liste de nos entity_types sera moins immediat.
        wbemUrl = lib_wbem.NamespaceUrl(nskey, cimomUrl)
        wbemNode = lib_common.NodeUrl(wbemUrl)

        grph.add((rootNode, pc.property_cim_subnamespace, wbemNode))
        grph.add(
            (wbemNode, pc.property_information, lib_common.NodeLiteral(nskey)))
        grph.add(
            (wbemNode, pc.property_information, lib_common.NodeLiteral(cnt)))

    cgiEnv.OutCgiRdf("LAYOUT_RECT")
Exemplo n.º 6
0
def WbemNamespaceNode(wbemNamespace, cimomUrl, clsNam):
    wbemUrl = lib_wbem.NamespaceUrl(wbemNamespace, cimomUrl, clsNam)
    return lib_common.NodeUrl(wbemUrl)
Exemplo n.º 7
0
def AddNamespaceLink(grph, root_node, name_space, cimom_url, class_name):
    url_namespace = lib_wbem.NamespaceUrl(name_space, cimom_url, class_name)
    nod_namespace = lib_common.NodeUrl(url_namespace)
    grph.add((root_node, pc.property_cim_subnamespace, nod_namespace))
Exemplo n.º 8
0
def Main():
    paramkeyMaxInstances = "Max instances"
    paramkeyStartIndex = "Start index"

    # This can process remote hosts because it does not call any script, just shows them.
    cgiEnv = lib_common.CgiEnv(can_process_remote=True,
                               parameters={
                                   paramkeyMaxInstances: 80,
                                   paramkeyStartIndex: 0
                               })

    maxInstances = cgiEnv.get_parameters(paramkeyMaxInstances)
    startIndex = cgiEnv.get_parameters(paramkeyStartIndex)

    grph = cgiEnv.GetGraph()

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

    entity_host = cgiEnv.GetHost()

    rootNode = lib_util.EntityClassNode(className, nameSpace, entity_host,
                                        "WBEM")

    # Hard-coded default namespace.
    if nameSpace == "":
        nameSpace = "root/CIMV2"

    # This adds a link to the namespace of this WBEM class: It shows its inheritance graph.
    urlNamespace = lib_wbem.NamespaceUrl(nameSpace, entity_host, className)
    nodNamespace = lib_common.NodeUrl(urlNamespace)
    grph.add((rootNode, pc.property_cim_subnamespace, nodNamespace))

    try:
        connWbem = lib_wbem.WbemConnection(entity_host)
        wbemKlass = connWbem.GetClass(className,
                                      namespace=nameSpace,
                                      LocalOnly=False,
                                      IncludeQualifiers=True)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("EnumerateInstanceNames: entity_host=" +
                                    entity_host + " nameSpace=" + nameSpace +
                                    " className=" + className + ". Caught:" +
                                    str(exc))

    klaDescrip = lib_wbem.WbemClassDescrFromClass(wbemKlass)
    grph.add((rootNode, pc.property_information,
              lib_common.NodeLiteral("WBEM description: " + klaDescrip)))

    # Pour afficher du texte: Remplacer le help statique.
    # offset va etre un parametre. Helas ne pas se fairew d illusions sur "offset"

    # WBEM and WMI both have the annoying limitation that it is not possible to select only a range of instances.
    try:
        inst_names = connWbem.EnumerateInstanceNames(ClassName=className,
                                                     namespace=nameSpace)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("EnumerateInstanceNames: entity_host=" +
                                    entity_host + " nameSpace=" + nameSpace +
                                    " className=" + className + ". Caught:" +
                                    str(exc))

    try:
        isAssociation = wbemKlass.qualifiers['Association'].value
    except KeyError:
        isAssociation = False

    # It is possible to display an association like a normal class but it is useless.
    if isAssociation:
        if True:
            DisplayAssociatorsAsNetwork(grph, inst_names, rootNode, nameSpace,
                                        entity_host, maxInstances, startIndex)
        else:
            DisplayAssociatorsAsList(grph, inst_names, rootNode, nameSpace,
                                     entity_host, className, maxInstances,
                                     startIndex)
    else:
        DisplayPlainClass(grph, inst_names, rootNode, nameSpace, entity_host,
                          className, maxInstances, startIndex)

    numInstances = len(inst_names)
    DEBUG("numInstances=%d startIndex=%d", numInstances, startIndex)

    # This displays one link on the same page, with specific values of these parameters.
    # The other parameters are not changed.
    # TODO, BEWARE: What is the total number of elements ?
    if startIndex + maxInstances < numInstances:
        cgiEnv.add_parameterized_links(
            "Next", {paramkeyStartIndex: startIndex + maxInstances})
    if startIndex > 0:
        cgiEnv.add_parameterized_links(
            "Previous",
            {paramkeyStartIndex: max(startIndex - maxInstances, 0)})

    # TODO: On pourrait rassembler par classes,
    # et aussi afficher les liens d'heritages des classes.

    # cgiEnv.OutCgiRdf()
    cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_class_instance])
Exemplo n.º 9
0
def _wbem_namespace_node(wbem_namespace, cimom_url, cls_nam):
    wbemUrl = lib_wbem.NamespaceUrl(wbem_namespace, cimom_url, cls_nam)
    return lib_common.NodeUrl(wbemUrl)