Пример #1
0
def doInstall(info):
    " do install of activation info"

    logger.info("OracleDatabaseContainer: doInstall:Enter")
    hostname = "localhost"
    try:
        hostname = InetAddress.getLocalHost().getCanonicalHostName()
    except:
        type, value, traceback = sys.exc_info()
        logger.severe("Hostname error:" + ` value `)

    dbInstallOption = getVariableValue("DB_INSTALL_OPTION")
    if dbInstallOption == "INSTALL_DB_AND_CONFIG":
        globalLockString = "OracleEnabler-" + hostname
        ContainerUtils.releaseGlobalLock(globalLockString)
        logger.info("Released global lock with name: " + globalLockString)

    try:
        oracleDatabase = getVariableValue("ORACLE_DATABASE_OBJECT")
        if oracleDatabase:
            oracleDatabase.installActivationInfo(info)
    except:
        type, value, traceback = sys.exc_info()
        logger.severe(
            "Unexpected error in OracleDatabaseContainer:doInstall:" +
            ` value `)

    logger.info("OracleDatabaseContainer: doInstall:Exit")
def doInstall(info):
    " do install of activation info"

    logger.info("OracleDatabaseContainer: doInstall:Enter")
    hostname = "localhost";
    try:
        hostname = InetAddress.getLocalHost().getCanonicalHostName()
    except:
        type, value, traceback = sys.exc_info()
        logger.severe("Hostname error:" + `value`)
    
    dbInstallOption = getVariableValue("DB_INSTALL_OPTION")
    if dbInstallOption == "INSTALL_DB_AND_CONFIG":        
        globalLockString = "OracleEnabler-" + hostname
        ContainerUtils.releaseGlobalLock(globalLockString)
        logger.info("Released global lock with name: " + globalLockString)
        
    try:
        oracleDatabase = getVariableValue("ORACLE_DATABASE_OBJECT")
        if oracleDatabase:
            oracleDatabase.installActivationInfo(info)
    except:
        type, value, traceback = sys.exc_info()
        logger.severe("Unexpected error in OracleDatabaseContainer:doInstall:" + `value`)
        
    logger.info("OracleDatabaseContainer: doInstall:Exit")
Пример #3
0
def getMachineName():
    if isPython:
        from platform import uname
        return uname()[1]
    elif isJython:
        from java.net import InetAddress
        addr = InetAddress.getLocalHost()
        return str(addr.getHostName())
    return False
Пример #4
0
 def __getHostName(self):
     "get hostname"
     self.__hostname = getVariableValue("ENGINE_USERNAME");
     try:
         hostname = InetAddress.getLocalHost().getCanonicalHostName()
         if hostname != "localhost" and not re.search("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", hostname):
             self.__hostname = hostname
     except:
         type, value, traceback = sys.exc_info()
         logger.severe("get hostname error:" + `value`)
Пример #5
0
 def __getHostName(self):
     "get hostname"
     self.__hostname = getVariableValue("ENGINE_USERNAME")
     try:
         hostname = InetAddress.getLocalHost().getCanonicalHostName()
         if hostname != "localhost" and not re.search(
                 "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", hostname):
             self.__hostname = hostname
     except:
         type, value, traceback = sys.exc_info()
         logger.severe("get hostname error:" + ` value `)
Пример #6
0
def determine_local_ipaddr():
    local_address = None

    # Most portable (for modern versions of Python)
    if hasattr(socket, 'gethostbyname_ex'):
        for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
            if not ip.startswith('127.'):
                local_address = ip
                break
    # may be none still (nokia) http://www.skweezer.com/s.aspx/-/pypi~python~org/pypi/netifaces/0~4 http://www.skweezer.com/s.aspx?q=http://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib has alonger one

    if sys.platform.startswith('linux'):
        import fcntl

        def get_ip_address(ifname):
            ifname = ifname.encode('latin1')
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            return socket.inet_ntoa(fcntl.ioctl(
                s.fileno(),
                0x8915,  # SIOCGIFADDR
                struct.pack('256s', ifname[:15])
            )[20:24])

        if not local_address:
            for devname in os.listdir('/sys/class/net/'):
                try:
                    ip = get_ip_address(devname)
                    if not ip.startswith('127.'):
                        local_address = ip
                        break
                except IOError:
                    pass

    # Jython / Java approach
    if not local_address and InetAddress:
        addr = InetAddress.getLocalHost()
        hostname = addr.getHostName()
        for ip_addr in InetAddress.getAllByName(hostname):
            if not ip_addr.isLoopbackAddress():
                local_address = ip_addr.getHostAddress()
                break

    if not local_address:
        # really? Oh well lets connect to a remote socket (Google DNS server)
        # and see what IP we use them
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(('8.8.8.8', 53))
        ip = s.getsockname()[0]
        s.close()
        if not ip.startswith('127.'):
            local_address = ip

    return local_address
Пример #7
0
 def __init__(self, TCP_IP = None, TCP_PORT = 5006):
     #Automatically assign the IP if the field is left empty
     if x.getProperty("insideDev") == "false":
         # MAKE SURE THAT THE INET INTERFACE IS THE MAIN ONE
         TCP_IP = InetAddress.getLocalHost().getHostAddress()
         print("Running outside of Dev - IP = "+TCP_IP)
     else:
         TCP_IP = 'localhost'
         print("Running in Dev")
         
     self.TCP_IP = TCP_IP
     self.TCP_PORT = TCP_PORT
     self.BUFFER_SIZE = 1024  # Normally 1024, but we want fast response
Пример #8
0
def isOnDifferentHost():

    node = AdminControl.getNode()
    nodeId = AdminConfig.getid("/Node:" + node + "/")
    targetHostname = AdminConfig.showAttribute(nodeId, 'hostName')
    try:
        localHostname = InetAddress.getLocalHost().getCanonicalHostName()
    except:
        localHostname = "cannot_be_determined"

    if (localHostname.lower()) != (targetHostname.lower()):
        print "localHostname is: " + localHostname
        print "targetHostname is: " + targetHostname
        if localHostname == "cannot_be_determined":
            print "isOnDifferentHost returns false because hostname cannot be determined"
            return False
        else:
            return True
    def __init__(self, additionalVariables):
        " initialize oracle database"
        
        self.__hostname = "localhost";
        try:
            self.__hostname = InetAddress.getLocalHost().getCanonicalHostName()
        except:
            type, value, traceback = sys.exc_info()
            logger.severe("Hostname error:" + `value`)
        
        additionalVariables.add(RuntimeContextVariable("ORACLE_HOSTNAME", self.__hostname, RuntimeContextVariable.ENVIRONMENT_TYPE))

        dbPassword = getVariableValue("DB_PASSWORD_ALL")
        
        if dbPassword and dbPassword.strip():
            self.__sysPassword = dbPassword
            additionalVariables.add(RuntimeContextVariable("SYS_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE))
            additionalVariables.add(RuntimeContextVariable("DBSNMP_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE));
            additionalVariables.add(RuntimeContextVariable("SYSMAN_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE))
            additionalVariables.add(RuntimeContextVariable("SYSTEM_PWD", dbPassword, RuntimeContextVariable.ENVIRONMENT_TYPE));
        else:
            self.__sysPassword = getVariableValue("SYS_PWD")
            
        dbDataLocation = getVariableValue("DB_DATA_LOC")
        if dbDataLocation and os.path.isdir(dbDataLocation):
            dbName = getVariableValue("DB_NAME")
            
            dbDataDir = os.path.join(dbDataLocation, dbName)
            if os.path.isdir(dbDataDir):
                logger.info("DB Data directory already exists:" + dbDataDir + "; Setting DB_INSTALL_OPTION to INSTALL_DB_SWONLY")
                additionalVariables.add(RuntimeContextVariable( "DB_INSTALL_OPTION", "INSTALL_DB_SWONLY", RuntimeContextVariable.ENVIRONMENT_TYPE))
        

        tcpPort = getVariableValue("TCP_PORT");
        self.__serviceName = getVariableValue("DB_GLOBAL_NAME")

        sb = StringBuilder("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)")
        sb.append("(HOST=").append(self.__hostname).append(")")
        sb.append("(PORT=").append(tcpPort).append("))")
        sb.append("(CONNECT_DATA=(SERVICE_NAME=").append(self.__serviceName).append(")))")
        
        self.__oracleServiceUrl = sb.toString()
        
        logger.info("Oracle listener service URL:" + self.__oracleServiceUrl)
        
        self.__jdbcUrl = "jdbc:oracle:thin:@" + self.__hostname +":"+ tcpPort + ":" + self.__serviceName
        runtimeContext.addVariable(RuntimeContextVariable("JDBC_URL", self.__jdbcUrl, RuntimeContextVariable.STRING_TYPE, "Oracle Thin Driver JDBC Url", True, RuntimeContextVariable.NO_INCREMENT))
        
        
        oracleDriver = "oracle.jdbc.OracleDriver"
        runtimeContext.addVariable(RuntimeContextVariable("JDBC_DRIVER", oracleDriver, RuntimeContextVariable.STRING_TYPE, "Oracle Thin Driver class", True, RuntimeContextVariable.NO_INCREMENT))
        
        self.__dbControl = Boolean.parseBoolean(getVariableValue("CONFIG_DBCONTROL", "false"))
        
        if self.__dbControl:
            self.__dbCtrlPort = getVariableValue("DBCONTROL_HTTP_PORT")
            additionalVariables.add(RuntimeContextVariable( "HTTPS_PORT", self.__dbCtrlPort, RuntimeContextVariable.STRING_TYPE))
        
        oracleDir = getVariableValue("ORACLE_DIR")
        self.__markerFilePath = os.path.join(oracleDir, ".#dsoracle")
        
        self.__maintFilePath = getVariableValue("ORACLE_MAINT_FILE")
        
        dbInstallOption = getVariableValue("DB_INSTALL_OPTION")
        if dbInstallOption == "INSTALL_DB_AND_CONFIG":
            globalLockString = "OracleEnabler-" + self.__hostname
            logger.info("Requesting Global Lock with name: " + globalLockString)
            domain = proxy.getContainer().getCurrentDomain()
            options = domain.getOptions()
            maxActivationTimeOut = options.getProperty(Options.MAX_ACTIVATION_TIME_IN_SECONDS)
            lockTimeOut = Long.parseLong(maxActivationTimeOut) * 1000
            acquired = ContainerUtils.acquireGlobalLock(globalLockString, lockTimeOut , lockTimeOut)
            if acquired:
                logger.info("Acquired Global lock with name: " + globalLockString)
            else:
                logger.severe("Could not acquire Global lock with name: " + globalLockString)
                raise Exception("Could not acquire Global lock with name: " + globalLockString)
Пример #10
0
 def getComputerName(cls):
     """ generated source for method getComputerName """
     try:
         return InetAddress.getLocalHost().getHostName().lower()
     except Exception as e:
         return None
Пример #11
0
    def __init__(self, additionalVariables):
        " initialize oracle database"

        self.__hostname = "localhost"
        try:
            self.__hostname = InetAddress.getLocalHost().getCanonicalHostName()
        except:
            type, value, traceback = sys.exc_info()
            logger.severe("Hostname error:" + ` value `)

        additionalVariables.add(
            RuntimeContextVariable("ORACLE_HOSTNAME", self.__hostname,
                                   RuntimeContextVariable.ENVIRONMENT_TYPE,
                                   "Oracle Hostname", True,
                                   RuntimeContextVariable.NO_INCREMENT))

        listenAddress = getVariableValue("LISTEN_ADDRESS")
        additionalVariables.add(
            RuntimeContextVariable("ORACLE_LISTEN_ADDRESS", listenAddress,
                                   RuntimeContextVariable.ENVIRONMENT_TYPE,
                                   "Oracle Listen Address", True,
                                   RuntimeContextVariable.NO_INCREMENT))

        dbPassword = getVariableValue("DB_PASSWORD_ALL")

        if dbPassword and dbPassword.strip():
            self.__sysPassword = dbPassword
            additionalVariables.add(
                RuntimeContextVariable(
                    "SYS_PWD", dbPassword,
                    RuntimeContextVariable.ENVIRONMENT_TYPE))
            additionalVariables.add(
                RuntimeContextVariable(
                    "DBSNMP_PWD", dbPassword,
                    RuntimeContextVariable.ENVIRONMENT_TYPE))
            additionalVariables.add(
                RuntimeContextVariable(
                    "SYSMAN_PWD", dbPassword,
                    RuntimeContextVariable.ENVIRONMENT_TYPE))
            additionalVariables.add(
                RuntimeContextVariable(
                    "SYSTEM_PWD", dbPassword,
                    RuntimeContextVariable.ENVIRONMENT_TYPE))
        else:
            self.__sysPassword = getVariableValue("SYS_PWD")

        dbDataLocation = getVariableValue("DB_DATA_LOC")
        if dbDataLocation and os.path.isdir(dbDataLocation):
            dbName = getVariableValue("DB_NAME")

            dbDataDir = os.path.join(dbDataLocation, dbName)
            if os.path.isdir(dbDataDir):
                logger.info("DB Data directory already exists:" + dbDataDir +
                            "; Setting DB_INSTALL_OPTION to INSTALL_DB_SWONLY")
                additionalVariables.add(
                    RuntimeContextVariable(
                        "DB_INSTALL_OPTION", "INSTALL_DB_SWONLY",
                        RuntimeContextVariable.ENVIRONMENT_TYPE))

        tcpPort = getVariableValue("TCP_PORT")
        self.__serviceName = getVariableValue("DB_GLOBAL_NAME")

        sb = StringBuilder(
            "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)")
        sb.append("(HOST=").append(self.__hostname).append(")")
        sb.append("(PORT=").append(tcpPort).append("))")
        sb.append("(CONNECT_DATA=(SERVICE_NAME=").append(
            self.__serviceName).append(")))")

        self.__oracleServiceUrl = sb.toString()

        logger.info("Oracle listener service URL:" + self.__oracleServiceUrl)

        self.__jdbcUrl = "jdbc:oracle:thin:@" + self.__hostname + ":" + tcpPort + ":" + self.__serviceName
        additionalVariables.add(
            RuntimeContextVariable("JDBC_URL", self.__jdbcUrl,
                                   RuntimeContextVariable.STRING_TYPE,
                                   "Oracle Thin Driver JDBC Url", True,
                                   RuntimeContextVariable.NO_INCREMENT))

        oracleDriver = "oracle.jdbc.OracleDriver"
        additionalVariables.add(
            RuntimeContextVariable("JDBC_DRIVER", oracleDriver,
                                   RuntimeContextVariable.STRING_TYPE,
                                   "Oracle Thin Driver class", True,
                                   RuntimeContextVariable.NO_INCREMENT))

        self.__dbControl = Boolean.parseBoolean(
            getVariableValue("CONFIG_DBCONTROL", "false"))

        if self.__dbControl:
            self.__dbCtrlPort = getVariableValue("DBCONTROL_HTTP_PORT")
            additionalVariables.add(
                RuntimeContextVariable("HTTPS_PORT", self.__dbCtrlPort,
                                       RuntimeContextVariable.STRING_TYPE))

        oracleDir = getVariableValue("ORACLE_DIR")
        self.__markerFilePath = os.path.join(oracleDir, ".#dsoracle")

        self.__maintFilePath = getVariableValue("ORACLE_MAINT_FILE")

        dbInstallOption = getVariableValue("DB_INSTALL_OPTION")
        if dbInstallOption == "INSTALL_DB_AND_CONFIG":
            globalLockString = "OracleEnabler-" + self.__hostname
            logger.info("Requesting Global Lock with name: " +
                        globalLockString)
            domain = proxy.getContainer().getCurrentDomain()
            options = domain.getOptions()
            maxActivationTimeOut = options.getProperty(
                Options.MAX_ACTIVATION_TIME_IN_SECONDS)
            lockTimeOut = Long.parseLong(maxActivationTimeOut) * 1000
            acquired = ContainerUtils.acquireGlobalLock(
                globalLockString, lockTimeOut, lockTimeOut)
            if acquired:
                logger.info("Acquired Global lock with name: " +
                            globalLockString)
            else:
                logger.severe("Could not acquire Global lock with name: " +
                              globalLockString)
                raise Exception("Could not acquire Global lock with name: " +
                                globalLockString)
Пример #12
0
if __name__ == '__main__':
    from wlstModule import *  # @UnusedWildImport

from java.net import InetAddress
from java.util.logging import *
from java.util.logging import Logger
import sys

logger = Logger.getLogger("scratch")

print "" + InetAddress.getLocalHost().getHostName()