コード例 #1
0
def getManageruser(serverxml):
    DOMTree = xml.dom.minidom.parse(serverxml)
    collection = DOMTree.documentElement
    if collection.hasAttribute("shelf"):
        print("Root element : %s" % collection.getAttribute("shelf"))
    manageruser = {"host": "127.0.0.1"}
    system = collection.getElementsByTagName('system')
    propertys = system[0].getElementsByTagName("property")
    for property in propertys:
        if property.getAttribute("name").lower() == "managerport":
            manageruser["port"] = property.childNodes[0].data
    users = collection.getElementsByTagName("user")
    for user in users:
        managerflag = 0
        usingdecrypt = 0
        manageruser["user"] = user.getAttribute("name")
        propertys = user.getElementsByTagName("property")
        for property in propertys:
            if property.getAttribute("name").lower() == "manager" \
                and property.childNodes[0].data.lower() == "true":
                managerflag = 1
            elif property.getAttribute("name").lower() == "usingdecrypt" \
                and int(property.childNodes[0].data) == 1:
                usingdecrypt = 1
            elif property.getAttribute("name").lower() == "password":
                manageruser["password"] = property.childNodes[0].data
        if usingdecrypt == 1:
            manageruser["password"] = decode.DecryptByPublicKey(
                manageruser["password"]).decrypt().split(':')[2]
        if managerflag:
            return manageruser
    log.error("Don't find manager user in server.xml")
コード例 #2
0
def getHosts(schemaxml):
    DOMTree = xml.dom.minidom.parse(schemaxml)
    collection = DOMTree.documentElement
    if collection.hasAttribute("shelf"):
        print("Root element : %s" % collection.getAttribute("shelf"))
    datahost_dict = {}
    datahosts = collection.getElementsByTagName("dataHost")
    for datahost in datahosts:
        dh_name = datahost.getAttribute("name")
        hosts_list = []
        writehosts = datahost.getElementsByTagName('writeHost')
        if writehosts:
            for writehost in writehosts:
                writehost_conn = {}
                writehost_conn["dhname"] = dh_name
                writehost_conn["name"] = writehost.getAttribute("host")
                wh_url = writehost.getAttribute("url").split(':')
                writehost_conn["host"] = wh_url[0]
                writehost_conn["port"] = wh_url[1]
                writehost_conn["user"] = writehost.getAttribute("user")
                writehost_conn["password"] = writehost.getAttribute("password")
                usingdecrypt = writehost.getAttribute("usingDecrypt")
                if usingdecrypt and int(usingdecrypt) == 1:
                    writehost_conn["password"] = \
                    decode.DecryptByPublicKey(writehost_conn["password"]).decrypt().split(':')[3]
                writehost_conn["iswritehost"] = 1
                hosts_list.append(writehost_conn)
        readhosts = writehost.getElementsByTagName('readHost')
        if readhosts:
            for readhost in readhosts:
                readhost_conn = {}
                readhost_conn["dhname"] = dh_name
                readhost_conn["name"] = readhost.getAttribute("host")
                rh_url = readhost.getAttribute("url").split(':')
                readhost_conn["host"] = rh_url[0]
                readhost_conn["port"] = rh_url[1]
                readhost_conn["user"] = readhost.getAttribute("user")
                readhost_conn["password"] = readhost.getAttribute("password")
                usingdecrypt = readhost.getAttribute("usingDecrypt")
                if usingdecrypt and int(usingdecrypt) == 1:
                    readhost_conn["password"] = \
                    decode.DecryptByPublicKey(readhost_conn["password"]).decrypt().split(':')[3]
                readhost_conn["iswritehost"] = 0
                hosts_list.append(readhost_conn)
        datahost_dict[dh_name] = hosts_list
    return datahost_dict
コード例 #3
0
def getHosts(dbXml):
    DOMTree = xml.dom.minidom.parse(dbXml)
    collection = DOMTree.documentElement
    if collection.hasAttribute("shelf"):
        print("Root element : %s" % collection.getAttribute("shelf"))
    dbgroup_dict = {}
    dbgroups = collection.getElementsByTagName("dbGroup")
    for dbgroup in dbgroups:
        dh_name = dbgroup.getAttribute("name")
        hosts_list = []
        dbinstances = dbgroup.getElementsByTagName("dbInstance")
        for dbinstance in dbinstances:
            if dbinstance.getAttribute("primary") == "true":
                writehost_conn = {}
                writehost_conn["dhname"] = dh_name
                writehost_conn["name"] = dbinstance.getAttribute("name")
                wh_url = dbinstance.getAttribute("url").split(':')
                writehost_conn["host"] = wh_url[0]
                writehost_conn["port"] = wh_url[1]
                writehost_conn["user"] = dbinstance.getAttribute("user")
                writehost_conn["password"] = dbinstance.getAttribute(
                    "password")
                usingdecrypt = dbinstance.getAttribute("usingDecrypt")
                if usingdecrypt == 'true':
                    writehost_conn["password"] = \
                    decode.DecryptByPublicKey(writehost_conn["password"]).decrypt().split(':')[3]
                writehost_conn["iswritehost"] = 1
                hosts_list.append(writehost_conn)
            else:
                readhost_conn = {}
                readhost_conn["dhname"] = dh_name
                readhost_conn["name"] = dbinstance.getAttribute("name")
                rh_url = dbinstance.getAttribute("url").split(':')
                readhost_conn["host"] = rh_url[0]
                readhost_conn["port"] = rh_url[1]
                readhost_conn["user"] = dbinstance.getAttribute("user")
                readhost_conn["password"] = dbinstance.getAttribute("password")
                usingdecrypt = dbinstance.getAttribute("usingDecrypt")
                if usingdecrypt == 'true':
                    readhost_conn["password"] = \
                    decode.DecryptByPublicKey(readhost_conn["password"]).decrypt().split(':')[3]
                readhost_conn["iswritehost"] = 0
                hosts_list.append(readhost_conn)
        dbgroup_dict[dh_name] = hosts_list
    return dbgroup_dict
コード例 #4
0
def getMangagerUser(userXml):
    DOMTree = xml.dom.minidom.parse(userXml)
    collection = DOMTree.documentElement
    if collection.hasAttribute("shelf"):
        print("Root element : %s" % collection.getAttribute("shelf"))
    managerUser = ''
    users = collection.getElementsByTagName("managerUser")
    for user in users:
        if not user.getAttribute("readOnly") == "true":
            managerUser = {"host": "127.0.0.1"}
            if user.getAttribute("usingDecrypt") == "true":
                managerUser["user"] = user.getAttribute("name")
                managerUser["password"] = user.getAttribute("password")
                managerUser["password"] = decode.DecryptByPublicKey(
                    managerUser["password"]).decrypt().split(':')[2]
            else:
                managerUser["user"] = user.getAttribute("name")
                managerUser["password"] = user.getAttribute("password")

        if not managerUser:
            log.error("Don't find manager user in xml")
        else:
            return managerUser