GeezerVison is showing github.com — CLOUDSTACK-8818: Use MySQL native connector with Python · asdnf/cloudstack@92e3ba2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: client/bindir/cloud-update-xenserver-licenses.in +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,7 +24,7 @@ import glob | 24 | 24 | from random import choice | 25 | 25 | import string | 26 | 26 | from optparse import OptionParser | 27 | | -import MySQLdb | | 27 | +import mysql.connector | 28 | 28 | import paramiko | 29 | 29 | from threading import Thread | 30 | 30 |
| @@ -59,7 +59,7 @@ parser.add_option("-a", "--all", action="store_true", dest="all", default=False, | 59 | 59 | def e(msg): parser.error(msg) | 60 | 60 |
| 61 | 61 | def getknownhosts(host,username,password): | 62 | | - conn = MySQLdb.connect(host=host,user=username,passwd=password) | | 62 | + conn = mysql.connector.connect(host=host, user=username, password=password) | 63 | 63 | cur = conn.cursor() | 64 | 64 | cur.execute("SELECT h.private_ip_address,d.value FROM cloud.host h inner join cloud.host_details d on (h.id = d.host_id) where d.name = 'username' and setup = 1") | 65 | 65 | usernames = dict(cur.fetchall()) | |
Collapse file Copy file name to clipboardExpand all lines: debian/control +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ Section: libs | 3 | 3 | Priority: extra | 4 | 4 | | 5 | 5 | Build-Depends: debhelper (>= 9), openjdk-8-jdk | openjdk-7-jdk, genisoimage, | 6 | | - python-mysqldb, maven (>= 3) | maven3, python (>= 2.7) | | 6 | + python-mysql.connector, maven (>= 3) | maven3, python (>= 2.7) | 7 | 7 | Standards-Version: 3.8.1 | 8 | 8 | Homepage: http://www.cloudstack.org/ | 9 | 9 |
| @@ -15,7 +15,7 @@ Description: A common package which contains files which are shared by several C | 15 | 15 |
| 16 | 16 | Package: cloudstack-management | 17 | 17 | Architecture: all | 18 | | -Depends: ${misc:Depends}, ${python:Depends}, cloudstack-common (= ${source:Version}), tomcat6, sudo, jsvc, python-mysqldb, libmysql-java, augeas-tools, mysql-client, adduser, bzip2 | | 18 | +Depends: ${misc:Depends}, ${python:Depends}, cloudstack-common (= ${source:Version}), tomcat6, sudo, jsvc, python-mysql.connector, libmysql-java, augeas-tools, mysql-client, adduser, bzip2 | 19 | 19 | Conflicts: cloud-server, cloud-client, cloud-client-ui | 20 | 20 | Description: CloudStack server library | 21 | 21 | The CloudStack management server | |
Collapse file Copy file name to clipboardExpand all lines: packaging/centos63/cloud.spec +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,7 +50,7 @@ BuildRequires: jpackage-utils | 50 | 50 | BuildRequires: gcc | 51 | 51 | BuildRequires: glibc-devel | 52 | 52 | BuildRequires: /usr/bin/mkisofs | 53 | | -BuildRequires: MySQL-python | | 53 | +BuildRequires: mysql-connector-python | 54 | 54 | #BuildRequires: maven => 3.0.0 | 55 | 55 |
| 56 | 56 | %description | @@ -79,7 +79,7 @@ Requires: /sbin/service | 79 | 79 | Requires: /sbin/chkconfig | 80 | 80 | Requires: /usr/bin/ssh-keygen | 81 | 81 | Requires: mkisofs | 82 | | -Requires: MySQL-python | | 82 | +Requires: mysql-connector-python | 83 | 83 | Requires: python-paramiko | 84 | 84 | Requires: ipmitool | 85 | 85 | Requires: %{name}-common = %{_ver} | |
Collapse file Copy file name to clipboardExpand all lines: packaging/centos7/cloud.spec +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,7 +50,7 @@ BuildRequires: jpackage-utils | 50 | 50 | BuildRequires: gcc | 51 | 51 | BuildRequires: glibc-devel | 52 | 52 | BuildRequires: /usr/bin/mkisofs | 53 | | -BuildRequires: MySQL-python | | 53 | +BuildRequires: mysql-connector-python | 54 | 54 | BuildRequires: maven => 3.0.0 | 55 | 55 |
| 56 | 56 | %description | @@ -79,7 +79,7 @@ Requires: /sbin/service | 79 | 79 | Requires: /sbin/chkconfig | 80 | 80 | Requires: /usr/bin/ssh-keygen | 81 | 81 | Requires: mkisofs | 82 | | -Requires: MySQL-python | | 82 | +Requires: mysql-connector-python | 83 | 83 | Requires: ipmitool | 84 | 84 | Requires: %{name}-common = %{_ver} | 85 | 85 | Requires: iptables-services | |
Collapse file Copy file name to clipboardExpand all lines: packaging/fedora20/cloud.spec +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,7 +50,7 @@ BuildRequires: jpackage-utils | 50 | 50 | BuildRequires: gcc | 51 | 51 | BuildRequires: glibc-devel | 52 | 52 | BuildRequires: /usr/bin/mkisofs | 53 | | -BuildRequires: MySQL-python | | 53 | +BuildRequires: mysql-connector-python | 54 | 54 | #BuildRequires: maven => 3.0.0 | 55 | 55 |
| 56 | 56 | %description | @@ -79,7 +79,7 @@ Requires: /sbin/service | 79 | 79 | Requires: /sbin/chkconfig | 80 | 80 | Requires: /usr/bin/ssh-keygen | 81 | 81 | Requires: mkisofs | 82 | | -Requires: MySQL-python | | 82 | +Requires: mysql-connector-python | 83 | 83 | Requires: python-paramiko | 84 | 84 | Requires: ipmitool | 85 | 85 | Requires: %{name}-common = %{_ver} | |
Collapse file Copy file name to clipboardExpand all lines: packaging/fedora21/cloud.spec +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -50,7 +50,7 @@ BuildRequires: jpackage-utils | 50 | 50 | BuildRequires: gcc | 51 | 51 | BuildRequires: glibc-devel | 52 | 52 | BuildRequires: /usr/bin/mkisofs | 53 | | -BuildRequires: MySQL-python | | 53 | +BuildRequires: mysql-connector-python | 54 | 54 | #BuildRequires: maven => 3.0.0 | 55 | 55 |
| 56 | 56 | %description | @@ -79,7 +79,7 @@ Requires: /sbin/service | 79 | 79 | Requires: /sbin/chkconfig | 80 | 80 | Requires: /usr/bin/ssh-keygen | 81 | 81 | Requires: mkisofs | 82 | | -Requires: MySQL-python | | 82 | +Requires: mysql-connector-python | 83 | 83 | Requires: python-paramiko | 84 | 84 | Requires: ipmitool | 85 | 85 | Requires: %{name}-common = %{_ver} | |
Collapse file Copy file name to clipboardExpand all lines: python/lib/cloudutils/db.py +22-23Lines changed: 22 additions & 23 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | # to you under the Apache License, Version 2.0 (the | 6 | 6 | # "License"); you may not use this file except in compliance | 7 | 7 | # with the License. You may obtain a copy of the License at | 8 | | -# | | 8 | +# | 9 | 9 | # http://www.apache.org/licenses/LICENSE-2.0 | 10 | | -# | | 10 | +# | 11 | 11 | # Unless required by applicable law or agreed to in writing, | 12 | 12 | # software distributed under the License is distributed on an | 13 | 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 14 | 14 | # KIND, either express or implied. See the License for the | 15 | 15 | # specific language governing permissions and limitations | 16 | 16 | # under the License. | 17 | | -import MySQLdb | 18 | 17 | import os | 19 | 18 | from utilities import bash | 20 | 19 | from cloudException import CloudRuntimeException | 21 | | -import sys | 22 | | -class Database: | | 20 | +import mysql.connector | | 21 | + | | 22 | +class Database(object): | 23 | 23 | """Database connection""" | 24 | 24 | def __init__(self, username, password=None, host='localhost', port='3306', db="cloud"): | 25 | 25 | self.host = host | @@ -28,15 +28,16 @@ def __init__(self, username, password=None, host='localhost', port='3306', db="c | 28 | 28 | self.port = port | 29 | 29 | self.db = db | 30 | 30 |
| | 31 | + def connect(self): | | 32 | + return mysql.connector.connect(host=self.host, | | 33 | + user=self.username, | | 34 | + password=self.password, | | 35 | + database=self.db) | | 36 | + | 31 | 37 | def execute(self, statement): | 32 | 38 | txn = None | 33 | 39 | try: | 34 | | - if self.password is not None: | 35 | | - txn = MySQLdb.Connect(host=self.host, user=self.username, | 36 | | - passwd=self.password, db=self.db) | 37 | | - else: | 38 | | - txn = MySQLdb.Connect(host=self.host, user=self.username, | 39 | | - db=self.db) | | 40 | + txn = self.connect() | 40 | 41 | cursor = txn.cursor() | 41 | 42 | cursor.execute(statement) | 42 | 43 | cursor.close() | @@ -47,35 +48,33 @@ def execute(self, statement): | 47 | 48 | except: | 48 | 49 | pass | 49 | 50 | except: | | 51 | + raise CloudRuntimeException("Failed to execute: %s " % statement) | | 52 | + finally: | 50 | 53 | if txn is not None: | 51 | 54 | try: | 52 | 55 | txn.close() | 53 | 56 | except: | 54 | 57 | pass | 55 | | - raise CloudRuntimeException("Failed to execute:%s"%statement) | 56 | | - | | 58 | + | 57 | 59 | def testConnection(self): | 58 | 60 | try: | 59 | | - if self.password is not None: | 60 | | - db = MySQLdb.Connect(host=self.host, user=self.username, | 61 | | - passwd=self.password, db=self.db) | 62 | | - else: | 63 | | - db = MySQLdb.Connect(host=self.host, user=self.username, | 64 | | - db=self.db) | | 61 | + conn = self.connect() | | 62 | + conn.ping() | | 63 | + conn.close() | 65 | 64 | return True | 66 | 65 | except: | 67 | 66 | raise CloudRuntimeException("Failed to Connect to DB") | 68 | | - | | 67 | + | 69 | 68 | def executeFromFile(self, file): | 70 | 69 | if not os.path.exists(file): | 71 | 70 | return False | 72 | | - | | 71 | + | 73 | 72 | cmdLine = "mysql --host=" + self.host + " --port=" + str(self.port) + " --user=" + self.username | 74 | 73 | if self.password is not None: | 75 | 74 | cmdLine += " --password=" + self.password | 76 | | - | | 75 | + | 77 | 76 | cmdLine += " < " + file | 78 | | - | | 77 | + | 79 | 78 | try: | 80 | 79 | bash(cmdLine) | 81 | 80 | except: | |
Collapse file Copy file name to clipboardExpand all lines: setup/bindir/cloud-migrate-databases.in +4-4Lines changed: 4 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 |
| 21 | 21 | import os,logging,sys | 22 | 22 | from optparse import OptionParser | 23 | | -import MySQLdb | | 23 | +import mysql.connector | 24 | 24 | import subprocess | 25 | 25 | import glob | 26 | 26 |
| @@ -72,10 +72,10 @@ class CloudContext(cloud_utils.MigrationContext): | 72 | 72 | self.database = database | 73 | 73 | self.configdir = configdir | 74 | 74 | self.resourcedir = resourcedir | 75 | | - self.conn = MySQLdb.connect(host=self.host, | | 75 | + self.conn = mysql.connector.connect(host=self.host, | 76 | 76 | user=self.username, | 77 | | - passwd=self.password, | 78 | | - db=self.database, | | 77 | + password=self.password, | | 78 | + database=self.database, | 79 | 79 | port=self.port) | 80 | 80 | self.conn.autocommit(False) | 81 | 81 | self.db = self.conn.cursor() | |
|