Upgrade to 0.9.0 and add python3 pacakge -- python3-pywbem.

This commit is contained in:
Gris Ge 2016-09-27 20:32:50 +08:00
parent 5175cbbab0
commit 2329bade8e
7 changed files with 61 additions and 505 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/pywbem-20131121.tar.xz
/v0.9.0.tar.gz

View File

@ -1,22 +0,0 @@
diff -up pywbem-20130411/mof_compiler.py.bak pywbem-20130411/mof_compiler.py
--- pywbem-20130411/mof_compiler.py.bak 2009-07-30 00:55:26.000000000 +0200
+++ pywbem-20130411/mof_compiler.py 2013-05-24 17:40:16.684813502 +0200
@@ -20,12 +20,12 @@
import sys
import os
-import lex
-import yacc
-from lex import TOKEN
-from cim_operations import CIMError, WBEMConnection
-from cim_obj import *
-from cim_constants import *
+from pywbem import lex
+from pywbem import yacc
+from pywbem.lex import TOKEN
+from pywbem.cim_operations import CIMError, WBEMConnection
+from pywbem.cim_obj import *
+from pywbem.cim_constants import *
from getpass import getpass
_optimize = 1

View File

@ -1,50 +0,0 @@
Index: pywbem-20131121/cim_http.py
===================================================================
--- pywbem-20131121.orig/cim_http.py
+++ pywbem-20131121/cim_http.py
@@ -42,6 +42,33 @@ class AuthError(Error):
"""This exception is raised when an authentication error (401) occurs."""
pass
+try:
+ import pwd
+ def get_user_name(uid=None):
+ """Return user name for given uid.
+ :param int uid: User id of user whose name is desired.
+ If not given, current user will be assumed.
+ """
+ try:
+ if uid is None:
+ uid = os.getuid()
+ return pwd.getpwuid(uid).pw_name
+ except KeyError:
+ pass
+except ImportError: # pwd is available only on *nix
+ def get_user_name(uid=None):
+ """
+ Return user name of current user.
+ :param int uid: Optional argument. Note that uid may be equal only
+ to current user's id, otherwise an exception will be raised.
+ """
+ if uid is not None and uid != os.getuid():
+ raise ValueError("Can not get user name for other user.")
+ try:
+ return getpass.getuser()
+ except KeyError:
+ pass
+
def parse_url(url):
"""Return a tuple of (host, port, ssl) from the URL parameter.
The returned port defaults to 5988 if not specified. SSL supports
@@ -226,10 +253,7 @@ def wbem_request(url, data, creds, heade
local = True
if local:
uid = os.getuid()
- try:
- locallogin = getpass.getuser()
- except KeyError:
- locallogin = None
+ locallogin = get_user_name(uid)
while numTries < tryLimit:
numTries = numTries + 1

View File

@ -1,270 +0,0 @@
Index: pywbem-20131121/cim_http.py
===================================================================
--- pywbem-20131121.orig/cim_http.py
+++ pywbem-20131121/cim_http.py
@@ -28,6 +28,7 @@ being transferred is XML. It is up to t
data and interpret the result.
'''
+from M2Crypto import SSL, Err
import sys, string, re, os, socket, getpass
from stat import S_ISSOCK
import cim_obj
@@ -74,8 +75,26 @@ def parse_url(url):
return host, port, ssl
+def get_default_ca_certs():
+ """
+ Try to find out system path with ca certificates. This path is cached and
+ returned. If no path is found out, None is returned.
+ """
+ if not hasattr(get_default_ca_certs, '_path'):
+ for path in (
+ '/etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt',
+ '/etc/ssl/certs',
+ '/etc/ssl/certificates'):
+ if os.path.exists(path):
+ get_default_ca_certs._path = path
+ break
+ else:
+ get_default_ca_certs._path = None
+ return get_default_ca_certs._path
+
def wbem_request(url, data, creds, headers = [], debug = 0, x509 = None,
- verify_callback = None):
+ verify_callback = None, ca_certs = None,
+ no_verification = False):
"""Send XML data over HTTP to the specified url. Return the
response in XML. Uses Python's build-in httplib. x509 may be a
dictionary containing the location of the SSL certificate and key
@@ -105,10 +124,49 @@ def wbem_request(url, data, creds, heade
class HTTPSConnection(HTTPBaseConnection, httplib.HTTPSConnection):
def __init__(self, host, port=None, key_file=None, cert_file=None,
- strict=None):
+ strict=None, ca_certs=None, verify_callback=None):
httplib.HTTPSConnection.__init__(self, host, port, key_file,
cert_file, strict)
-
+ self.ca_certs = ca_certs
+ self.verify_callback = verify_callback
+
+ def connect(self):
+ "Connect to a host on a given (SSL) port."
+ self.sock = socket.create_connection((self.host, self.port),
+ self.timeout, self.source_address)
+ if self._tunnel_host:
+ self.sock = sock
+ self._tunnel()
+ ctx = SSL.Context('sslv23')
+ if self.cert_file:
+ ctx.load_cert(self.cert_file, keyfile=self.key_file)
+ if self.ca_certs:
+ ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert,
+ depth=9, callback=verify_callback)
+ if os.path.isdir(self.ca_certs):
+ ctx.load_verify_locations(capath=self.ca_certs)
+ else:
+ ctx.load_verify_locations(cafile=self.ca_certs)
+ try:
+ self.sock = SSL.Connection(ctx, self.sock)
+ # Below is a body of SSL.Connection.connect() method
+ # except for the first line (socket connection). We want to preserve
+ # tunneling ability.
+ self.sock.addr = (self.host, self.port)
+ self.sock.setup_ssl()
+ self.sock.set_connect_state()
+ ret = self.sock.connect_ssl()
+ if self.ca_certs:
+ check = getattr(self.sock, 'postConnectionCheck',
+ self.sock.clientPostConnectionCheck)
+ if check is not None:
+ if not check(self.sock.get_peer_cert(), self.host):
+ raise Error('SSL error: post connection check failed')
+ return ret
+ except ( Err.SSLError, SSL.SSLError, SSL.SSLTimeoutError
+ , SSL.Checker.WrongHost), arg:
+ raise Error("SSL error: %s" % arg)
+
class FileHTTPConnection(HTTPBaseConnection, httplib.HTTPConnection):
def __init__(self, uds_path):
httplib.HTTPConnection.__init__(self, 'localhost')
@@ -117,64 +175,36 @@ def wbem_request(url, data, creds, heade
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.sock.connect(self.uds_path)
- host, port, ssl = parse_url(url)
+ host, port, use_ssl = parse_url(url)
key_file = None
cert_file = None
- if ssl:
-
- if x509 is not None:
- cert_file = x509.get('cert_file')
- key_file = x509.get('key_file')
-
- if verify_callback is not None:
- addr_ind = 0
- # Temporary exception store
- addr_exc = None
- # Get a list of arguments for socket().
- addr_list = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
- for addr_ind in xrange(len(addr_list)):
- family, socktype, proto, canonname, sockaddr = addr_list[addr_ind]
- try:
- from OpenSSL import SSL
- ctx = SSL.Context(SSL.SSLv3_METHOD)
- ctx.set_verify(SSL.VERIFY_PEER, verify_callback)
- ctx.set_default_verify_paths()
- # Add the key and certificate to the session
- if cert_file is not None and key_file is not None:
- ctx.use_certificate_file(cert_file)
- ctx.use_privatekey_file(key_file)
- s = SSL.Connection(ctx, socket.socket(family, socktype, proto))
- s.connect((host, port))
- s.do_handshake()
- s.shutdown()
- s.close()
- addr_exc = None
- break
- except (socket.gaierror, socket.error), arg:
- # Could not perform connect() call, store the exception object for
- # later use.
- addr_exc = arg
- continue
- except socket.sslerror, arg:
- raise Error("SSL error: %s" % (arg,))
-
- # Did we try all the addresses from getaddrinfo() and no successful
- # connection performed?
- if addr_exc:
- raise Error("Socket error: %s" % (addr_exc),)
+ if use_ssl and x509 is not None:
+ cert_file = x509.get('cert_file')
+ key_file = x509.get('key_file')
numTries = 0
localAuthHeader = None
tryLimit = 5
+ if isinstance(data, unicode):
+ data = data.encode('utf-8')
data = '<?xml version="1.0" encoding="utf-8" ?>\n' + data
+ if not no_verification and ca_certs is None:
+ ca_certs = get_default_ca_certs()
+ elif no_verification:
+ ca_certs = None
+
local = False
- if ssl:
- h = HTTPSConnection(host, port = port, key_file = key_file,
- cert_file = cert_file)
+ if use_ssl:
+ h = HTTPSConnection(host,
+ port = port,
+ key_file = key_file,
+ cert_file = cert_file,
+ ca_certs = ca_certs,
+ verify_callback = verify_callback)
else:
if url.startswith('http'):
h = HTTPConnection(host, port = port)
@@ -216,6 +246,8 @@ def wbem_request(url, data, creds, heade
h.putheader('PegasusAuthorization', 'Local "%s"' % locallogin)
for hdr in headers:
+ if isinstance(hdr, unicode):
+ hdr = hdr.encode('utf-8')
s = map(lambda x: string.strip(x), string.split(hdr, ":", 1))
h.putheader(urllib.quote(s[0]), urllib.quote(s[1]))
Index: pywbem-20131121/cim_operations.py
===================================================================
--- pywbem-20131121.orig/cim_operations.py
+++ pywbem-20131121/cim_operations.py
@@ -78,12 +78,12 @@ class WBEMConnection(object):
the request before it is sent, and the reply before it is
unpacked.
- verify_callback is used to verify the server certificate.
- It is passed to OpenSSL.SSL.set_verify, and is called during the SSL
- handshake. verify_callback should take five arguments: A Connection
- object, an X509 object, and three integer variables, which are in turn
- potential error number, error depth and return code. verify_callback
- should return True if verification passes and False otherwise.
+ verify_callback is used to verify the server certificate. It is passed to
+ M2Crypto.SSL.Context.set_verify, and is called during the SSL handshake.
+ verify_callback should take five arguments: An SSL Context object, an X509
+ object, and three integer variables, which are in turn potential error
+ number, error depth and return code. verify_callback should return True if
+ verification passes and False otherwise.
The value of the x509 argument is used only when the url contains
'https'. x509 must be a dictionary containing the keys 'cert_file'
@@ -91,14 +91,27 @@ class WBEMConnection(object):
filename of an certificate and the value of 'key_file' must consist
of a filename containing the private key belonging to the public key
that is part of the certificate in cert_file.
+
+ ca_certs specifies where CA certificates for verification purposes are
+ located. These are trusted certificates. Note that the certificates have to
+ be in PEM format. Either it is a directory prepared using the c_rehash tool
+ included with OpenSSL or an pemfile. If None, default system path will be
+ used.
+
+ no_verification allows to disable peer's verification. This is insecure and
+ should be avoided. If True, peer's certificate is not verified and ca_certs
+ argument is ignored.
"""
def __init__(self, url, creds = None, default_namespace = DEFAULT_NAMESPACE,
- x509 = None, verify_callback = None):
+ x509 = None, verify_callback = None, ca_certs = None,
+ no_verification = False):
self.url = url
self.creds = creds
self.x509 = x509
self.verify_callback = verify_callback
+ self.ca_certs = ca_certs
+ self.no_verification = no_verification
self.last_request = self.last_reply = ''
self.default_namespace = default_namespace
self.debug = False
@@ -164,7 +177,9 @@ class WBEMConnection(object):
resp_xml = cim_http.wbem_request(self.url, req_xml.toxml(),
self.creds, headers,
x509 = self.x509,
- verify_callback = self.verify_callback)
+ verify_callback = self.verify_callback,
+ ca_certs = self.ca_certs,
+ no_verification = self.no_verification)
except cim_http.AuthError:
raise
except cim_http.Error, arg:
@@ -321,7 +336,9 @@ class WBEMConnection(object):
resp_xml = cim_http.wbem_request(self.url, req_xml.toxml(),
self.creds, headers,
x509 = self.x509,
- verify_callback = self.verify_callback)
+ verify_callback = self.verify_callback,
+ ca_certs = self.ca_certs,
+ no_verification = self.no_verification)
except cim_http.Error, arg:
# Convert cim_http exceptions to CIMError exceptions
raise CIMError(0, str(arg))
Index: pywbem-20131121/setup.py
===================================================================
--- pywbem-20131121.orig/setup.py
+++ pywbem-20131121/setup.py
@@ -37,6 +37,7 @@ args = {'name': 'pywbem',
'version': '0.7.0',
'license': 'LGPLv2',
'packages': ['pywbem'],
+ 'install_requires': ['M2Crypto'],
# Make packages in root dir appear in pywbem module
'package_dir': {'pywbem': ''},
# Make extensions in root dir appear in pywbem module

View File

@ -1,112 +0,0 @@
Index: pywbem-20130827/cim_obj.py
===================================================================
--- pywbem-20130827.orig/cim_obj.py
+++ pywbem-20130827/cim_obj.py
@@ -391,7 +391,7 @@ class CIMProperty(object):
if value is not None:
if value:
if self.embedded_object is not None:
- value = [v.tocimxml().toxml() for v in value]
+ value = [v.tocimxml().toxml(encoding='utf-8') for v in value]
value = VALUE_ARRAY([VALUE(atomic_to_cim_xml(v)) for v in value])
return PROPERTY_ARRAY(
@@ -422,7 +422,7 @@ class CIMProperty(object):
value = self.value
if value is not None:
if self.embedded_object is not None:
- value = value.tocimxml().toxml()
+ value = value.tocimxml().toxml(encoding='utf-8')
else:
value = atomic_to_cim_xml(value)
value = VALUE(value)
@@ -599,9 +599,9 @@ class CIMInstanceName(object):
# long or float
_type = 'numeric'
value = str(kb[1])
- elif type(kb[1]) == str or type(kb[1]) == unicode:
+ elif isinstance(kb[1], basestring):
_type = 'string'
- value = kb[1]
+ value = kb[1].decode('utf-8') if isinstance(kb[1], str) else kb[1]
else:
raise TypeError(
'Invalid keybinding type for keybinding ' '%s: %s' % (kb[0],`type(kb[1])`))
@@ -1341,7 +1341,8 @@ def tocimxml(value):
if isinstance(value, cim_types.CIMType) or \
type(value) in (str, unicode, int):
- return cim_xml.VALUE(unicode(value))
+ value = value.decode('utf-8') if isinstance(value, str) else unicode(value)
+ return cim_xml.VALUE(value)
if isinstance(value, bool):
if value:
Index: pywbem-20130827/cim_operations.py
===================================================================
--- pywbem-20130827.orig/cim_operations.py
+++ pywbem-20130827/cim_operations.py
@@ -165,8 +165,8 @@ class WBEMConnection(object):
'2.0', '2.0')
if self.debug:
- self.last_raw_request = req_xml.toxml()
- self.last_request = req_xml.toprettyxml(indent=' ')
+ self.last_raw_request = req_xml.toxml(encoding='utf-8')
+ self.last_request = req_xml.toprettyxml(indent=' ', encoding='utf-8')
self.last_reply = None
self.last_raw_reply = None
@@ -174,7 +174,7 @@ class WBEMConnection(object):
# Get XML response
try:
- resp_xml = cim_http.wbem_request(self.url, req_xml.toxml(),
+ resp_xml = cim_http.wbem_request(self.url, req_xml.toxml(encoding='utf-8'),
self.creds, headers,
x509 = self.x509,
verify_callback = self.verify_callback,
@@ -192,7 +192,7 @@ class WBEMConnection(object):
reply_dom = minidom.parseString(resp_xml)
if self.debug:
- self.last_reply = reply_dom.toprettyxml(indent=' ')
+ self.last_reply = reply_dom.toprettyxml(indent=' ', encoding='utf-8')
self.last_raw_reply = resp_xml
# Parse response
@@ -292,7 +292,7 @@ class WBEMConnection(object):
if isinstance(obj, (CIMClassName, CIMInstanceName)):
return cim_xml.VALUE_REFERENCE(obj.tocimxml())
if isinstance(obj, (CIMClass, CIMInstance)):
- return cim_xml.VALUE(obj.tocimxml().toxml())
+ return cim_xml.VALUE(obj.tocimxml().toxml(encoding='utf-8'))
if isinstance(obj, list):
if obj and isinstance(obj[0], (CIMClassName, CIMInstanceName)):
return cim_xml.VALUE_REFARRAY([paramvalue(x) for x in obj])
@@ -328,12 +328,12 @@ class WBEMConnection(object):
'2.0', '2.0')
if self.debug:
- self.last_request = req_xml.toprettyxml(indent=' ')
+ self.last_request = req_xml.toprettyxml(indent=' ', encoding='utf-8')
# Get XML response
try:
- resp_xml = cim_http.wbem_request(self.url, req_xml.toxml(),
+ resp_xml = cim_http.wbem_request(self.url, req_xml.toxml(encoding='utf-8'),
self.creds, headers,
x509 = self.x509,
verify_callback = self.verify_callback,
Index: pywbem-20130827/cim_types.py
===================================================================
--- pywbem-20130827.orig/cim_types.py
+++ pywbem-20130827/cim_types.py
@@ -258,5 +258,5 @@ def atomic_to_cim_xml(obj):
elif cimtype(obj) == 'real64':
return u'%.16E' % obj
else:
- return unicode(obj)
+ return obj.decode('utf-8') if isinstance(obj, str) else unicode(obj)

View File

@ -1,44 +1,44 @@
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%global svnrev 626
%global revdate 20131121
%global py3_build_dir %{_builddir}/%{name}-%{version}-%{release}-python3
Name: pywbem
Version: 0.7.0
Release: 30.%{revdate}svn%{svnrev}%{?dist}
Summary: Python WBEM Client and Provider Interface
Name: pywbem
Version: 0.9.0
Release: 1%{?dist}
Summary: Python2 WBEM Client and Provider Interface
Group: Development/Libraries
License: LGPLv2
URL: http://pywbem.sourceforge.net
# The source for this package was pulled from upstream svn repository.
# Use the following commands to get the archive:
# svn export -r 613 svn://svn.code.sf.net/p/pywbem/code/pywbem/trunk pywbem-20130128
# tar -cJvf pywbem-20130128.tar.xz pywbem-20130128
Source0: %{name}-%{revdate}.tar.xz
BuildRequires: python-setuptools
BuildRequires: m2crypto
URL: https://github.com/pywbem/pywbem
Source0: https://github.com/pywbem/pywbem/archive/v%{version}.tar.gz
BuildRequires: python-pip PyYAML python-ply python2-rpm-macros
BuildRequires: python3-pip python3-PyYAML python3-ply python3-rpm-macros
BuildArch: noarch
Requires: m2crypto
# fix module imports in /usr/bin/mofcomp
Patch0: pywbem-20130411-mof_compiler-import.patch
Patch1: pywbem-20131121-ssl_verify_host.patch
Patch2: pywbem-20131121-utf_encoding.patch
Patch3: pywbem-20131121-local_root_auth.patch
%description
A Python library for making CIM (Common Information Model) operations over HTTP
using the WBEM CIM-XML protocol. It is based on the idea that a good WBEM
client should be easy to use and not necessarily require a large amount of
programming knowledge. It is suitable for a large range of tasks from simply
poking around to writing web and GUI applications.
A Python library for making CIM (Common Information Model) operations over HTTP
using the WBEM CIM-XML protocol. It is based on the idea that a good WBEM
client should be easy to use and not necessarily require a large amount of
programming knowledge. It is suitable for a large range of tasks from simply
poking around to writing web and GUI applications.
WBEM, or Web Based Enterprise Management is a manageability protocol, like
SNMP, standardised by the Distributed Management Task Force (DMTF) available
WBEM, or Web Based Enterprise Management is a manageability protocol, like
SNMP, standardised by the Distributed Management Task Force (DMTF) available
at http://www.dmtf.org/standards/wbem.
It also provides a Python provider interface, and is the fastest and
It also provides a Python provider interface, and is the fastest and
easiest way to write providers on the planet.
%package -n python3-pywbem
Group: Development/Libraries
Summary: Python3 WBEM Client and Provider Interface
BuildArch: noarch
%description -n python3-pywbem
A WBEM client allows issuing operations to a WBEM server, using the CIM
operations over HTTP (CIM-XML) protocol defined in the DMTF standards DSP0200
and DSP0201. The CIM/WBEM infrastructure is used for a wide variety of systems
management tasks supported by systems running WBEM servers. See WBEM Standards
for more information about WBEM.
%package twisted
Group: Development/Libraries
Summary: WBEM client bindings for Twisted Python
@ -53,41 +53,50 @@ that perform WBEM requests over HTTP using the
twisted.protocols.http.HTTPClient base class.
%prep
%setup -q -n %{name}-%{revdate}
%patch0 -p1 -b .mofcomp-imports
%patch1 -p1 -b .ssl_verify_host
%patch2 -p1 -b .utf_encoding
%patch3 -p1 -b .local_root_auth
%setup -q -n %{name}-%{version}
%build
# dirty workaround to fix the mof_compiler.py module path
ln -s . pywbem
CFLAGS="%{optflags}" %{__python} setup.py build
cp -a . %{py3_build_dir}
CFLAGS="%{optflags}" %{__python2} setup.py build
pushd %{py3_build_dir}
CFLAGS="%{optflags}" %{__python3} setup.py build
popd
%install
rm -rf %{buildroot}
%{__python} setup.py install -O1 --skip-build --root %{buildroot}
mkdir -p -m755 %{buildroot}%{_bindir}
mv %{buildroot}/%{python_sitelib}/%{name}/wbemcli.py %{buildroot}/%{_bindir}/pywbemcli
mv %{buildroot}/%{python_sitelib}/%{name}/mof_compiler.py %{buildroot}/%{_bindir}/mofcomp
rm %{buildroot}/%{python_sitelib}/%{name}/wbemcli.py[co]
rm %{buildroot}/%{python_sitelib}/%{name}/mof_compiler.py[co]
env PYTHONPATH=%{buildroot}/%{python2_sitelib} %{__python2} setup.py install -O1 --skip-build --root %{buildroot}
rm -rf %{buildroot}/usr/bin/
install -m644 attic/twisted_client.py %{buildroot}/%{python2_sitelib}/pywbem/twisted_client.py
%clean
pushd %{py3_build_dir}
env PYTHONPATH=%{buildroot}/%{python3_sitelib} %{__python3} setup.py install -O1 --skip-build --root %{buildroot}
rm -rf %{buildroot}/usr/bin/*.bat
popd
%clean
rm -rf %{buildroot}
%files
# everything except twisted_client.py*
%{python_sitelib}/*.egg-info
%{python_sitelib}/pywbem/?[^w]*.py*
%attr(755,root,root) %{_bindir}/mofcomp
%attr(755,root,root) %{_bindir}/pywbemcli
%doc README
%{python2_sitelib}/*.egg-info
%{python2_sitelib}/pywbem/*.py*
%{python2_sitelib}/pywbem/LICENSE.txt
%files -n python3-pywbem
%{python3_sitelib}/*.egg-info
%{python3_sitelib}/pywbem/*.py*
%{python3_sitelib}/pywbem/LICENSE.txt
%{python3_sitelib}/pywbem/__pycache__/*
%{_bindir}/mof_compiler
%{_bindir}/wbemcli
%doc README.md
%files twisted
%{python_sitelib}/pywbem/twisted_client.py*
%changelog
* Wed Sep 14 2016 Gris Ge <fge@redhat.com> - 0.9.0-1
- Upgrade to 0.9.0 and add python3 pacakge -- python3-pywbem.
* Tue Jul 19 2016 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 0.7.0-30.20131121svn626
- https://fedoraproject.org/wiki/Changes/Automatic_Provides_for_Python_RPM_Packages

View File

@ -1 +1 @@
7101377e20bd66194f8feabe3e753069 pywbem-20131121.tar.xz
17552a10c01842c3771e58404273dc91 v0.9.0.tar.gz