Ejemplo n.º 1
0
def WmiReadWithQuery(cgiEnv, conn_wmi, class_name):
    """
        Maybe reading with the moniker does not work because properties are missing.
    """
    split_monik = cgiEnv.m_entity_id_dict
    a_qry = lib_util.SplitMonikToWQL(split_monik, class_name)

    try:
        return conn_wmi.query(a_qry)
    except Exception as exc:
        lib_common.ErrorMessageHtml("Query=%s Caught:%s" % (a_qry, str(exc)))
Ejemplo n.º 2
0
def WmiReadWithQuery(cgiEnv, connWmi, className):
    """
		Maybe reading with the moniker does not work because not all properties.
		This splits the moniker into key value paris, and uses a WQL query.
	"""
    splitMonik = lib_util.SplitMoniker(cgiEnv.m_entity_id)
    aQry = lib_util.SplitMonikToWQL(splitMonik, className)

    try:
        return connWmi.query(aQry)
    except Exception:
        exc = sys.exc_info()[1]
        lib_common.ErrorMessageHtml("Query=%s Caught:%s" % (aQry, str(exc)))
Ejemplo n.º 3
0
    def CallbackSelect(self, grph, class_name, predicate_prefix,
                       filtered_where_key_values):
        INFO(
            "WbemSparqlCallbackApi.CallbackSelect class_name=%s where_key_values=%s",
            class_name, filtered_where_key_values)
        assert class_name

        # This comes from such a Sparql triple: " ?variable rdf:type rdf:type"
        if class_name == "type":
            return

        wbem_query = lib_util.SplitMonikToWQL(filtered_where_key_values,
                                              class_name)
        DEBUG("WbemSparqlCallbackApi.CallbackSelect wbem_query=%s", wbem_query)

        wbem_objects = self.m_wbem_connection.ExecQuery(
            "WQL", wbem_query, "root/cimv2")

        # This returns a list of CIMInstance.
        for one_wbem_object in wbem_objects:
            # dir(one_wbem_object)
            # ['_CIMComparisonMixin__ordering_deprecated', '__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_classname', '_cmp', '_path', '_properties', '_property_list', '_qualifiers', 'classname', 'copy', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys', 'path', 'properties', 'property_list', 'qualifiers', 'tocimxml', 'tocimxmlstr', 'tomof', 'update', 'update_existing', 'values']

            # one_wbem_object is a CIMInstanceName
            # dir(one_wbem_object.path)
            # ['_CIMComparisonMixin__ordering_deprecated', '__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__slotnames__', '__str__', '__subclasshook__', '__weakref__', '_classname', '_cmp', '_host', '_kbstr_to_cimval', '_keybindings', '_namespace', 'classname', 'copy', 'from_instance', 'from_wbem_uri', 'get', 'has_key', 'host', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keybindings', 'keys', 'namespace', 'to_wbem_uri', 'tocimxml', 'tocimxmlstr', 'update', 'values']

            object_path = one_wbem_object.path.to_wbem_uri()
            # u'//vps516494.ovh.net/root/cimv2:PG_UnixProcess.CSName="vps516494.localdomain",Handle="1",OSCreationClassName="CIM_OperatingSystem",CreationClassName="PG_UnixProcess",CSCreationClassName="CIM_UnitaryComputerSystem",OSName="Fedora"'

            DEBUG("object.path=%s", object_path)
            dict_key_values = WbemKeyValues(one_wbem_object.iteritems())

            dict_key_values[
                lib_kbase.PredicateIsDefinedBy] = lib_common.NodeLiteral(
                    "WBEM")
            # Add it again, so the original Sparql query will work.
            dict_key_values[
                lib_kbase.PredicateSeeAlso] = lib_common.NodeLiteral("WBEM")

            #     # s=\\RCHATEAU-HP\root\cimv2:Win32_UserAccount.Domain="rchateau-HP",Name="rchateau" phttp://www.w3.org/1999/02/22-rdf-syntax-ns#type o=Win32_UserAccount
            dict_key_values[lib_kbase.PredicateType] = lib_properties.MakeProp(
                class_name)

            DEBUG("dict_key_values=%s", dict_key_values)
            lib_util.PathAndKeyValuePairsToRdf(grph, object_path,
                                               dict_key_values)
            yield (object_path, dict_key_values)
Ejemplo n.º 4
0
def WbemPlainExecQuery( conn, className, splitMonik, nameSpace ):
	aQry = lib_util.SplitMonikToWQL(splitMonik,className)
	DEBUG("WbemPlainExecQuery nameSpace=%s aQry=%s", nameSpace,aQry)
	# aQry = 'select * from CIM_System'
	# aQry = 'select * from CIM_ComputerSystem'
	try:
		# This does not work on OpenPegasus.
		return conn.ExecQuery("WQL", aQry, nameSpace)
	except Exception:
		exc = sys.exc_info()[1]

		# Problem on Windows with OpenPegasus.
		# aQry=select * from CIM_UnitaryComputerSystem where CreationClassName="PG_ComputerSystem"and Name="rchateau-HP". ns=root/cimv2. Caught:(7, u'CIM_ERR_NOT_SUPPORTED')
		msgExcFirst = str(exc)
		WARNING("WbemPlainExecQuery aQry=%s Exc=%s", aQry, msgExcFirst )
		return None
Ejemplo n.º 5
0
def WbemPlainExecQuery(conn, class_name, split_monik, name_space):
    a_qry = lib_util.SplitMonikToWQL(split_monik, class_name)
    logging.debug("WbemPlainExecQuery nameSpace=%s a_qry=%s", name_space,
                  a_qry)
    # a_qry = 'select * from CIM_System'
    # a_qry = 'select * from CIM_ComputerSystem'
    try:
        # This does not work on OpenPegasus.
        return conn.ExecQuery("WQL", a_qry, name_space)
    except Exception as exc:
        # Problem on Windows with OpenPegasus.
        # a_qry=select * from CIM_UnitaryComputerSystem ...
        # where CreationClassName="PG_ComputerSystem" ...
        # and Name="mymachine". ns=root/cimv2. Caught:(7, u'CIM_ERR_NOT_SUPPORTED')
        msg_exc_first = str(exc)
        logging.warning("WbemPlainExecQuery a_qry=%s Exc=%s", a_qry,
                        msg_exc_first)
        return None