Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #133 from indigo-dc/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer committed Jan 27, 2017
2 parents 1bc7829 + 0995993 commit e2e81e2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
28 changes: 20 additions & 8 deletions IM/InfrastructureList.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def remove_inf(del_inf):
@staticmethod
def get_inf_ids():
""" Get the IDs of the Infrastructures """
return InfrastructureList._get_data_from_db(Config.DATA_DB)
return InfrastructureList._get_inf_ids_from_db()

@staticmethod
def get_infrastructure(inf_id):
Expand Down Expand Up @@ -119,15 +119,27 @@ def save_data(inf_id=None):
sys.stderr.write("ERROR saving data: " + str(ex) + ".\nChanges not stored!!")

@staticmethod
def _get_data_from_db(db_url, inf_id=None):
db = DataBase(db_url)
def init_table():
""" Creates de database """
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)")
db.close()
return {}
else:
return True
else:
InfrastructureList.logger.error("ERROR connecting with the database!.")

return False

@staticmethod
def _get_data_from_db(db_url, inf_id=None):
if InfrastructureList.init_table():
return {}
else:
db = DataBase(db_url)
if db.connect():
inf_list = {}
if inf_id:
res = db.select("select * from inf_list where id = '%s'" % inf_id)
Expand All @@ -149,9 +161,9 @@ def _get_data_from_db(db_url, inf_id=None):

db.close()
return inf_list
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
6 changes: 4 additions & 2 deletions IM/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ def table_exists(self, table_name):
res = self.select(
'select name from sqlite_master where type="table" and name="' + table_name + '"')
elif self.db_type == "MySQL":
res = self.select(
'SELECT * FROM information_schema.tables WHERE table_name ="' + table_name + '"')
uri = uriparse(self.db_url)
db = uri[2][1:]
res = self.select('SELECT * FROM information_schema.tables WHERE table_name ="' +
table_name + '" and table_schema = "' + db + '"')
else:
return False

Expand Down
3 changes: 3 additions & 0 deletions IM/tosca/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ def _add_node_nets(node, radl, system, nodetemplates):
public_ip = True
parts = cap_props["network_name"].value.split(".")
net_provider_id = ".".join(parts[:-1])
elif str(cap_props["network_name"].value).endswith(".PRIVATE"):
parts = cap_props["network_name"].value.split(".")
net_provider_id = ".".join(parts[:-1])
if cap_props and "dns_name" in cap_props:
dns_name = cap_props["dns_name"].value
if cap_props and "ports" in cap_props:
Expand Down
2 changes: 1 addition & 1 deletion im_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def launch_daemon():
"""
Launch the IM daemon
"""
InfrastructureList.load_data()
InfrastructureList.init_table()

if Config.XMLRCP_SSL:
# if specified launch the secure version
Expand Down
6 changes: 5 additions & 1 deletion scripts/db_1_4_to_1_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
# 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
import cPickle as pickle
import sys
import time
import threading

Expand Down

0 comments on commit e2e81e2

Please sign in to comment.