587
|
1 |
#============================================================================
|
|
2 |
#Name : gscm.py
|
|
3 |
#Part of : Helium
|
|
4 |
|
|
5 |
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
6 |
#All rights reserved.
|
|
7 |
#This component and the accompanying materials are made available
|
|
8 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
#which accompanies this distribution, and is available
|
|
10 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
#
|
|
12 |
#Initial Contributors:
|
|
13 |
#Nokia Corporation - initial contribution.
|
|
14 |
#
|
|
15 |
#Contributors:
|
|
16 |
#
|
|
17 |
#Description:
|
|
18 |
#===============================================================================
|
|
19 |
|
|
20 |
""" Wrapper module that get CCM info using GSCM framework. """
|
|
21 |
|
|
22 |
|
|
23 |
import logging
|
|
24 |
import os
|
|
25 |
import subprocess
|
|
26 |
import pkg_resources
|
|
27 |
import tempfile
|
|
28 |
|
|
29 |
# Uncomment this line to enable logging in this module, or configure logging elsewhere
|
|
30 |
#logging.basicConfig(level=logging.DEBUG)
|
|
31 |
_logger = logging.getLogger("gscm")
|
|
32 |
|
|
33 |
|
|
34 |
def _execute(command):
|
|
35 |
""" Runs a command and returns the result data. """
|
|
36 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
37 |
output = process.stdout.read()
|
|
38 |
process.poll()
|
|
39 |
status = process.returncode
|
|
40 |
return (output, status)
|
|
41 |
|
|
42 |
|
|
43 |
def __get_gscm_info(method, dbname):
|
|
44 |
""" Generic method that call function 'method' on GSCM wrapper script. """
|
|
45 |
(fd, filename) = tempfile.mkstemp()
|
|
46 |
f = os.fdopen(fd, 'w')
|
|
47 |
f.write(pkg_resources.resource_string(__name__, "get_gscm_info.pl"))# pylint: disable-msg=E1101
|
|
48 |
f.close()
|
|
49 |
command = "perl " + filename
|
|
50 |
command += " %s %s" % (method, dbname)
|
|
51 |
_logger.debug("Running command: %s" % command)
|
|
52 |
(output, status) = _execute(command)
|
|
53 |
_logger.debug("Status: %s" % status)
|
|
54 |
_logger.debug("Output: %s" % output)
|
|
55 |
if status == 0 or status == None and not ("Can't locate" in output):
|
|
56 |
return output.strip()
|
|
57 |
if not 'HLM_SUBCON' in os.environ:
|
|
58 |
raise Exception("Error retrieving get_db_path info for '%s' database.\nOUTPUT:%s" % (dbname, output.strip()))
|
|
59 |
return None
|
|
60 |
|
|
61 |
def get_db_path(dbname):
|
|
62 |
""" Returns the database path for dbname database. """
|
|
63 |
_logger.debug("get_db_path: %s" % dbname)
|
|
64 |
return __get_gscm_info('get_db_path', dbname)
|
|
65 |
|
|
66 |
|
|
67 |
def get_router_address(dbname):
|
|
68 |
""" Returns the database router address for dbname database. """
|
|
69 |
_logger.debug("get_router_address: %s" % dbname)
|
|
70 |
return __get_gscm_info('get_router_address', dbname)
|
|
71 |
|
|
72 |
|
|
73 |
def get_engine_host(dbname):
|
|
74 |
""" Returns the database engine host for dbname database. """
|
|
75 |
_logger.debug("get_engine_host: %s" % dbname)
|
|
76 |
return __get_gscm_info('get_engine_host', dbname)
|