Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on importing pywbem.cim_http and pywbem.cim_operations #54

Open
moonbaseDelta opened this issue May 7, 2021 · 11 comments
Open

Error on importing pywbem.cim_http and pywbem.cim_operations #54

moonbaseDelta opened this issue May 7, 2021 · 11 comments

Comments

@moonbaseDelta
Copy link

Hi, I've got those import errors, but investigating current version of pywbem gived me a clue that those two should be pywbem._cim_http and pywbem._cim_operations. That fix inside code worked for py3 and py2.

@Napsty
Copy link
Owner

Napsty commented May 25, 2021

Sorry, not sure I understand the issue. So what is the error you experienced? Did you fix the code yourself or was something inside pywbem broken and fixed?

@philrandal
Copy link
Contributor

philrandal commented Jun 2, 2021

The API in pywbem changed in 1.0.0.

From https://pywbem.readthedocs.io/en/stable_1.1/changes.html#pywbem-1-0-0b1

"Made all sub-namespaces within the pywbem namespace private, except for pywbem.config. Specifically, renamed the following modules by prepending an underscore character: cim_constants.py, cim_http.py, cim_obj.py, cim_operations.py, cim_types.py, cim_xml.py, exceptions.py, mof_compiler.py, moflextab.py, mofparsetab.py, tupleparse.py, tupletree.py. Using these sub-namespaces had been deprecated in pywbem 0.8.0.

This change is compatible for users that followed the recommendation to import only the symbols from the pywbem namespace. Users that imported symbols from these sub-namespace should now import them from the pywbem namespace. If you miss a symbol in the pywbem namespace, it was likely a symbol that is not part of the public pywbem API. (See issue pywbem/pywbem#1925)"

@philrandal
Copy link
Contributor

workaround is to stick with an earlier version of pywbem, e.g.

pip install pywbem==0.17.6

@philrandal
Copy link
Contributor

philrandal commented Jun 3, 2021

Or apply this patch, which should work with pywbem 0.8.0 and later:

# diff -Naur check_esxi_hardware.py check_esxi_hardware.py.new
--- check_esxi_hardware.py      2021-06-03 09:01:40.092496740 +0100
+++ check_esxi_hardware.py.new  2021-06-03 08:53:03.202992912 +0100
@@ -738,7 +738,7 @@
 if vendor=='auto':
   try:
     c=wbemclient.EnumerateInstances('CIM_Chassis')
-  except pywbem.cim_operations.CIMError as args:
+  except pywbem._cim_operations.CIMError as args:
     if ( args[1].find('Socket error') >= 0 ):
       print("UNKNOWN: {}".format(args))
       sys.exit (ExitUnknown)
@@ -751,7 +751,7 @@
     GlobalStatus = ExitUnknown
     print("UNKNOWN: {}".format(args))
     sys.exit (GlobalStatus)
-  except pywbem.cim_http.AuthError as arg:
+  except pywbem._cim_http.AuthError as arg:
     verboseoutput("Global exit set to UNKNOWN")
     GlobalStatus = ExitUnknown
     print("UNKNOWN: Authentication Error")
@@ -773,7 +773,7 @@
   verboseoutput("Check classe "+classe)
   try:
     instance_list = wbemclient.EnumerateInstances(classe)
-  except pywbem.cim_operations.CIMError as args:
+  except pywbem._cim_operations.CIMError as args:
     if ( args[1].find('Socket error') >= 0 ):
       print("UNKNOWN: {}".format(args))
       sys.exit (ExitUnknown)
@@ -786,7 +786,7 @@
     GlobalStatus = ExitUnknown
     print("UNKNOWN: {}".format(args))
     sys.exit (GlobalStatus)
-  except pywbem.cim_http.AuthError as arg:
+  except pywbem._cim_http.AuthError as arg:
     verboseoutput("Global exit set to UNKNOWN")
     GlobalStatus = ExitUnknown
     print("UNKNOWN: Authentication Error")

@Napsty
Copy link
Owner

Napsty commented Jun 3, 2021

Thx @philrandal for sharing the knowledge. Will take a closer look at this. Maybe either ditch support for the old pywbem 0.7.x or have the connection check twice depending on the pywbem version.

@philrandal
Copy link
Contributor

You could have separate try ... except blocks depending on pywbem version, for backwards compatibility

@Napsty
Copy link
Owner

Napsty commented Jun 3, 2021

Yes, that's what I meant with "check twice depending on the pywbem version". It's basically only RHEL and CentOS which still ship the old pywbem :-/

@n-rodriguez
Copy link

Hi there! I think this issue can be closed.

@Napsty Napsty closed this as completed Nov 30, 2024
@n-rodriguez
Copy link

n-rodriguez commented Dec 8, 2024

@Napsty hi there! can you please reopen this issue? I thought it was fixed with the latest version but it's not the case 😢

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/nagios/plugins/check_esxi_hardware.py", line 757, in <module>
    except pywbem.cim_operations.CIMError as args:
           ^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'pywbem' has no attribute 'cim_operations'. Did you mean: '_cim_operations'?
pip list | grep pywbem
pywbem             1.7.2

@Napsty Napsty reopened this Dec 9, 2024
@Napsty
Copy link
Owner

Napsty commented Dec 9, 2024

Will look at it soon, should be easier to fix now that old version compatibilities for python2 and pywbem 0.7.0 have been removed.

@philrandal
Copy link
Contributor

philrandal commented Dec 9, 2024

Part of the code already used pywbem._cim, but two places were missed.

This patch should fix it:


# diff -Naur check_esxi_hardware.py.old check_esxi_hardware.py
--- check_esxi_hardware.py.old  2024-12-09 13:53:59.043000002 +0000
+++ check_esxi_hardware.py      2024-12-09 13:56:05.995755134 +0000
@@ -754,7 +754,7 @@
 if vendor=='auto':
   try:
     c=wbemclient.EnumerateInstances('CIM_Chassis')
-  except pywbem.cim_operations.CIMError as args:
+  except pywbem._cim_operations.CIMError as args:
     if ( args[1].find('Socket error') >= 0 ):
       print("UNKNOWN: {}".format(args))
       sys.exit (ExitUnknown)
@@ -767,7 +767,7 @@
     GlobalStatus = ExitUnknown
     print("UNKNOWN: {}".format(args))
     sys.exit (GlobalStatus)
-  except pywbem.cim_http.AuthError as arg:
+  except pywbem._cim_http.AuthError as arg:
     verboseoutput("Global exit set to UNKNOWN")
     GlobalStatus = ExitUnknown
     print("UNKNOWN: Authentication Error")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants