Skip to content

Commit

Permalink
Merge pull request #595 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored Apr 27, 2018
2 parents 5ad9d06 + 21fb0a3 commit 10217ab
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
16 changes: 11 additions & 5 deletions IM/InfrastructureList.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,15 @@ def init_table():
db = DataBase(Config.DATA_DB)
if db.connect():
if not db.table_exists("inf_list"):
db.execute("CREATE TABLE inf_list(id VARCHAR(255) PRIMARY KEY, deleted INTEGER,"
" date TIMESTAMP, data LONGBLOB)")
InfrastructureList.logger.debug("Creating the IM database!.")
if db.db_type == DataBase.MYSQL:
db.execute("CREATE TABLE inf_list(rowid INTEGER NOT NULL AUTO_INCREMENT UNIQUE,"
" id VARCHAR(255) PRIMARY KEY, deleted INTEGER, date TIMESTAMP, data LONGBLOB)")
else:
db.execute("CREATE TABLE inf_list(id VARCHAR(255) PRIMARY KEY, deleted INTEGER,"
" date TIMESTAMP, data LONGBLOB)")
db.close()
return True
return True
else:
InfrastructureList.logger.error("ERROR connecting with the database!.")

Expand All @@ -165,8 +170,6 @@ def _get_data_from_db(db_url, inf_id=None, auth=None):
If auth is specified only auth data will be loaded.
"""
if InfrastructureList.init_table():
return {}
else:
db = DataBase(db_url)
if db.connect():
inf_list = {}
Expand Down Expand Up @@ -196,6 +199,9 @@ def _get_data_from_db(db_url, inf_id=None, auth=None):
else:
InfrastructureList.logger.error("ERROR connecting with the database!.")
return {}
else:
InfrastructureList.logger.error("ERROR connecting with the database!.")
return {}

@staticmethod
def _save_data_to_db(db_url, inf_list, inf_id=None):
Expand Down
3 changes: 2 additions & 1 deletion contextualization/conf-ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@
# - name: Install Pip (alternative)
# shell: wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py

# do not upgrade to 10 as it is failing
- name: Upgrade pip
pip: name=pip extra_args="-I" state=latest
pip: name=pip extra_args="-I" version=9.0.3

- name: Upgrade setuptools with Pip
pip: name=setuptools state=latest
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dockerfile to create a container with the IM service
FROM ubuntu:16.04
FROM ubuntu:18.04
LABEL maintainer="Miguel Caballer <[email protected]>"
LABEL version="1.7.0"
LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)"
Expand All @@ -15,7 +15,7 @@ RUN pip install pyOpenSSL --upgrade -I
RUN pip install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-compute azure-mgmt-network azure-mgmt-resource azure-mgmt-dns cheroot xmltodict

# Install IM
RUN apt-get update && apt-get install --no-install-recommends -y gcc libmysqld-dev libssl-dev libffi-dev libsqlite3-dev && \
RUN apt-get update && apt-get install --no-install-recommends -y gcc libmysqld-dev libssl-dev libffi-dev libsqlite3-dev libmysqlclient20 && \
pip install pycrypto && \
pip install MySQL-python && \
pip install IM==1.7.0 && \
Expand Down
4 changes: 3 additions & 1 deletion im_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def launch_daemon():
"""
Launch the IM daemon
"""
InfrastructureList.init_table()
if not InfrastructureList.init_table():
print("Error connecting with the DB!!.")
sys.exit(2)

if Config.XMLRCP_SSL:
# if specified launch the secure version
Expand Down
46 changes: 46 additions & 0 deletions scripts/db_1_5_0_to_1_7_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# IM - Infrastructure Manager
# Copyright (C) 2011 - GRyCAP - Universitat Politecnica de Valencia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import sys

sys.path.append("..")
sys.path.append(".")

from IM.config import Config
from IM.db import DataBase


if __name__ == "__main__":
if not Config.DATA_DB:
sys.stderr.write("No DATA_DB defined in the im.cfg file!!")
sys.exit(-1)

db = DataBase(Config.DATA_DB)
if db.connect():
if db.table_exists("inf_list"):
if db.db_type == DataBase.MYSQL:
sys.stdout.write("Updating DB: %s.\n" % Config.DATA_DB)
db.execute("ALTER TABLE `inf_list` ADD COLUMN `rowid` INT AUTO_INCREMENT UNIQUE FIRST;")
else:
sys.stdout.write("SQLite DB does not need to be updated.")
db.close()
else:
sys.stdout.write("There are no inf_list table. Do not need to update.")
else:
sys.stderr.write("Error connecting with DB: %s\n" % Config.DATA_DB)
sys.exit(-1)

sys.exit(0)

0 comments on commit 10217ab

Please sign in to comment.