diff --git a/IM/db.py b/IM/db.py index 4e49d6aca..7f9171c4e 100644 --- a/IM/db.py +++ b/IM/db.py @@ -38,11 +38,18 @@ SQLITE_AVAILABLE = False try: - import mysql.connector as mdb + import MySQLdb as mdb MYSQL_AVAILABLE = True except: MYSQL_AVAILABLE = False +if not MYSQL_AVAILABLE: + try: + import pymysql as mdb + MYSQL_AVAILABLE = True + except: + MYSQL_AVAILABLE = False + try: from pymongo import MongoClient MONGO_AVAILABLE = True @@ -121,11 +128,7 @@ def _connect_mysql(self, url, db): username, password, server, port = self._get_user_pass_host_port(url) if not port: port = 3306 - self.connection = mdb.connect(host=server, - port=port, - user=username, - password=password, - database=db) + self.connection = mdb.connect(server, username, password, db, port) self.db_type = DataBase.MYSQL return True else: diff --git a/README.md b/README.md index d5b241c67..4157148c0 100644 --- a/README.md +++ b/README.md @@ -143,9 +143,9 @@ distributions or ``boto`` pip package. It can also be downloaded from boto GitHu Download the file and copy the boto subdirectory into the IM install path. In case of using the a MySQL DB as the backend to store IM data. The Python interface to MySQL -must be installed, typically available as the package ``python-mysql.connector`` in Debian based -distributions or ``mysql-connector-python`` in RedHat ones. It is also available on pip as the -``mysql-connector-python`` package. +must be installed, typically available as the package ``python-mysqldb`` or ``MySQL-python`` package. +In case of using Python 3 use the PyMySQL package, available as the package ``python3-pymysql`` on +debian systems or ``PyMySQL`` package in pip. In case of using the a MongoDB as the backend to store IM data. The Python interface to MongoDB must be installed, typically available as the package ``python-pymongo``package in most distributions diff --git a/ansible_install.yaml b/ansible_install.yaml index 654184b13..f369c39f3 100644 --- a/ansible_install.yaml +++ b/ansible_install.yaml @@ -76,7 +76,7 @@ ignore_errors: yes - name: Install pip libraries - pip: executable=pip name=pycrypto,pyOpenSSL,mysql-connector-python,msrest,msrestazure,azure-common,azure-mgmt-storage,azure-mgmt-compute,azure-mgmt-network,azure-mgmt-resource,azure-mgmt-dns,azure-storage,xmltodict + pip: executable=pip name=pycrypto,pyOpenSSL,MySQL-python,msrest,msrestazure,azure-common,azure-mgmt-storage,azure-mgmt-compute,azure-mgmt-network,azure-mgmt-resource,azure-mgmt-dns,azure-storage,xmltodict - name: Install IM dependencies for CentOS 6 pip: name=pysqlite version=2.7.0 diff --git a/doc/source/manual.rst b/doc/source/manual.rst index 120bd55fe..4c09dc1f6 100644 --- a/doc/source/manual.rst +++ b/doc/source/manual.rst @@ -63,9 +63,9 @@ Optional Packages with SSL certificates (see :confval:`REST_SSL`). pyOpenSSL can be installed using pip. * `The Python interface to MySQL `_, is needed to access MySQL server as IM data - backend. It is typically available as the package as the package 'python-mysql.connector' in Debian based - distributions or 'mysql-connector-python' in RedHat ones. It is also available on pip as the - 'mysql-connector-python' package. + backend. It is typically available as the package 'python-mysqldb' or 'MySQL-python' package. In case of + using Python 3 use the PyMySQL package, available as the package 'python3-pymysql' on debian systems or PyMySQL + package in pip. *`The Python interface to MongoDB `_, is needed to access MongoDB server as IM data backend. It is typically available as the package 'python-pymongo' package in most distributions or pymongo package in pip. diff --git a/docker-devel/Dockerfile b/docker-devel/Dockerfile index 3424134a9..808041cd6 100644 --- a/docker-devel/Dockerfile +++ b/docker-devel/Dockerfile @@ -14,7 +14,7 @@ RUN cd tmp \ && pip install /tmp/im # Install pip optional libraries -RUN pip install mysql-connector-python pyOpenSSL cheroot==8.1.0 pymongo msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-dns azure-storage +RUN pip install MySQL-python pyOpenSSL cheroot==8.1.0 pymongo msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-dns azure-storage # Set the VM_NUM_USE_CTXT_DIST to 3 for the tests RUN sed -i -e 's/VM_NUM_USE_CTXT_DIST = 30/VM_NUM_USE_CTXT_DIST = 3/g' /etc/im/im.cfg diff --git a/docker-py3/Dockerfile b/docker-py3/Dockerfile index 56d683655..0b13884d2 100644 --- a/docker-py3/Dockerfile +++ b/docker-py3/Dockerfile @@ -6,7 +6,7 @@ LABEL description="Container image to run the IM service. (http://www.grycap.upv EXPOSE 8899 8800 # Ensure system is up to date with mandatory python packages installed -RUN apt-get update && apt-get install --no-install-recommends -y python3 openssh-client sshpass vim libmysqlclient20 && \ +RUN apt-get update && apt-get install --no-install-recommends -y python3 openssh-client sshpass vim libmysqlclient20 python3-mysqldb && \ apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && rm -rf ~/.cache/ # Install IM @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y gcc git python3 pip3 install setuptools --upgrade -I && \ pip3 install pip --upgrade -I && \ /usr/local/bin/pip3 install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-dns azure-storage && \ - /usr/local/bin/pip3 install mysql-connector-python pyOpenSSL pycrypto cheroot xmltodict pymongo ansible==2.7.13 && \ + /usr/local/bin/pip3 install pyOpenSSL pycrypto cheroot xmltodict pymongo ansible==2.7.13 && \ /usr/local/bin/pip3 install IM==1.8.7 && \ /usr/local/bin/pip3 uninstall pip -y && \ apt-get purge -y gcc git libssl-dev libffi-dev libsqlite3-dev python3-dev python3-pip && \ diff --git a/docker/Dockerfile b/docker/Dockerfile index 8d498e5d0..6c018a854 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -14,7 +14,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y gcc git python pip install setuptools --upgrade -I && \ pip install pip --upgrade -I && \ /usr/local/bin/pip install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-dns azure-storage && \ - /usr/local/bin/pip install mysql-connector-python pyOpenSSL pycrypto xmltodict pymongo && \ + /usr/local/bin/pip install MySQL-python pyOpenSSL pycrypto xmltodict pymongo && \ /usr/local/bin/pip install IM==1.8.7 && \ /usr/local/bin/pip uninstall pip -y && \ apt-get purge -y gcc git python-dev python-pip libmysqld-dev libssl-dev libffi-dev libsqlite3-dev && \ diff --git a/packages/generate_rpm.sh b/packages/generate_rpm.sh index 394456962..a2cc6790a 100755 --- a/packages/generate_rpm.sh +++ b/packages/generate_rpm.sh @@ -2,6 +2,6 @@ yum -y install rpm-build python-setuptools echo "%_unpackaged_files_terminate_build 0" > ~/.rpmmacros -python setup.py bdist_rpm --release="$1" --requires="which, mysql-connector-python, python-sqlite3dbm, RADL, ansible, python-paramiko, PyYAML, python-suds, python-boto >= 2.29, python-libcloud, python-bottle, python-netaddr, python-scp, python-cherrypy, python-requests, python-xmltodict, tosca-parser" +python setup.py bdist_rpm --release="$1" --requires="which, MySQL-python, python-sqlite3dbm, RADL, ansible, python-paramiko, PyYAML, python-suds, python-boto >= 2.29, python-libcloud, python-bottle, python-netaddr, python-scp, python-cherrypy, python-requests, python-xmltodict, tosca-parser" mkdir dist_pkg cp dist/*.noarch.rpm dist_pkg