Example #1
0
    def __discoverIPInfo(self):
        '''
        Gets Network information for connected host
        @types AS400Client -> list(NetworkInfo)
        '''
        networkList = []
        intips = 0;
        sizeofentry = 0;
        listoffset = 0;
        txt10 = AS400Text(10);
        txt20 = AS400Text(20);
        txt50 = AS400Text(50);
        txt8 = AS400Text(8);
        txt1 = AS400Text(1);
        bin4 = AS400Bin4();
        userspacename = "UCMDBIPINFQTEMP".ljust(20)
        extendattr = " "*10
        initialvalue = " "
        publicauthority = "*ALL"
        txtdescription = "List Network Interfaces"
        replacecode = "*YES"
        format = "NIFC0100"
        
        parmList = []
        parmList.append(ProgramParameter(txt20.toBytes(userspacename), 20))
        parmList.append(ProgramParameter(bin4.toBytes(0)))
        queryConfig = ProgramCallQueryConfig("/QSYS.LIB/QUSDLTUS.PGM", parmList)
        self.__client.initQuery(queryConfig)
        self.__executeQuery()
    
        parmList = []
        parmList.append(ProgramParameter(txt20.toBytes(userspacename), 20))
        parmList.append(ProgramParameter(txt10.toBytes(extendattr), 10))
        parmList.append(ProgramParameter(bin4.toBytes(5000)))
        parmList.append(ProgramParameter(txt1.toBytes(initialvalue), 1))
        parmList.append(ProgramParameter(txt10.toBytes(publicauthority), 10))
        parmList.append(ProgramParameter(txt50.toBytes(txtdescription), 50))
        parmList.append(ProgramParameter(txt10.toBytes(replacecode), 10))
        parmList.append(ProgramParameter(bin4.toBytes(0)))
        queryConfig = ProgramCallQueryConfig("/QSYS.LIB/QUSCRTUS.PGM", parmList)
        self.__client.initQuery(queryConfig)
        self.__executeQuery()
        
        param0 = ProgramParameter(txt20.toBytes(userspacename), 20)
        param0.setParameterType(2);
        param1 = ProgramParameter(txt8.toBytes(format), 8);
        param1.setParameterType(2);
        param2 = ProgramParameter(bin4.toBytes(0));
        netparmList = [param0, param1, param2]
        queryConfig = ServiceProgramCallQueryConfig("/QSYS.LIB/QTOCNETSTS.SRVPGM", "QtocLstNetIfc", 0, netparmList)
        self.__client.initQuery(queryConfig)
        self.__executeQuery()

        queryConfig = ProgramCallDocumentQueryConfig("QUSRTVUS.pcml", "QUSRTVUS")
        self.__client.initQuery(queryConfig)
        if self.__executeQuery():
            ipsInfo = self.__client.getProperties(["QUSRTVUS.receiver.numentries", "QUSRTVUS.receiver.sizeofentry", "QUSRTVUS.receiver.listoffset"])
            intips = int(ipsInfo.getProperty("QUSRTVUS.receiver.numentries"))
            sizeofentry = int(ipsInfo.getProperty("QUSRTVUS.receiver.sizeofentry"))
            listoffset = int(ipsInfo.getProperty("QUSRTVUS.receiver.listoffset"))
            for m in xrange(intips):
                queryConfig = ProgramCallDocumentQueryConfig("QUSRTVUS2.pcml", "QUSRTVUS")
                self.__client.initQuery(queryConfig)
                values = HashMap()
                values.put("QUSRTVUS.start", Integer(int(listoffset) + 1))
                values.put("QUSRTVUS.length", Integer(int(sizeofentry)))
                self.__client.initPresetValues(values)
                if self.__executeQuery():
                    props = self.__client.getProperties(["QUSRTVUS.receiver.internetaddr", "QUSRTVUS.receiver.networkaddr", "QUSRTVUS.receiver.linedesc", "QUSRTVUS.receiver.interfacesubnetmask", "QUSRTVUS.receiver.interfacename"])
                    ip = props.getProperty("QUSRTVUS.receiver.internetaddr")
                    networkAddr = props.getProperty("QUSRTVUS.receiver.networkaddr")
                    interfaceDescr = props.getProperty("QUSRTVUS.receiver.linedesc")
                    interfaceName = props.getProperty("QUSRTVUS.receiver.interfacename")
                    networkMask = props.getProperty("QUSRTVUS.receiver.interfacesubnetmask")
                    if not isIpInList(networkList, ip):
                        try:
                            networkInfo = NetworkInfo(ip, networkAddr, interfaceName, interfaceDescr, networkMask)
                        except IllegalArgumentException, e:
                            logger.debugException(str(e))
                        else:
                            networkList.append(networkInfo);  
                    listoffset += sizeofentry;
Example #2
0
 def __getMACsData(self):
     '''
     Return list of macs which exists on connected host
     @types AS400Client, list(NetworkInfo), str -> list(string) 
     '''
     
     nummacs = 0;
     sizeofentry = 0;
     listoffset = 0;
     txt10 = AS400Text(10)
     txt20 = AS400Text(20)
     txt50 = AS400Text(50)
     txt8 = AS400Text(8)
     txt1 = AS400Text(1)
     bin4 = AS400Bin4()
     userspacename = "UCMDBIPINFQTEMP".ljust(20);
     extendattr = " "*10;
     initialvalue = " ";
     publicauthority = "*ALL";
     txtdescription = "Get Phy Int Data";
     replacecode = "*YES";
     format = "IFCD0100";
     
     parmList = []
     parmList.append(ProgramParameter(txt20.toBytes(userspacename), 20))
     parmList.append(ProgramParameter(bin4.toBytes(0)))
     queryConfig = ProgramCallQueryConfig("/QSYS.LIB/QUSDLTUS.PGM", parmList)
     self.__client.initQuery(queryConfig)
     self.__executeQuery()
 
     parmList = []
     parmList.append(ProgramParameter(txt20.toBytes(userspacename), 20))
     parmList.append(ProgramParameter(txt10.toBytes(extendattr), 10))
     parmList.append(ProgramParameter(bin4.toBytes(5000)))
     parmList.append(ProgramParameter(txt1.toBytes(initialvalue), 1))
     parmList.append(ProgramParameter(txt10.toBytes(publicauthority), 10))
     parmList.append(ProgramParameter(txt50.toBytes(txtdescription), 50))
     parmList.append(ProgramParameter(txt10.toBytes(replacecode), 10))
     parmList.append(ProgramParameter(bin4.toBytes(0)))
     queryConfig = ProgramCallQueryConfig("/QSYS.LIB/QUSCRTUS.PGM", parmList)
     self.__client.initQuery(queryConfig)
     self.__executeQuery()
 
     netparmList = [];
     param0 = ProgramParameter(txt20.toBytes(userspacename), 20)
     param0.setParameterType(2)
     param1 = ProgramParameter(txt8.toBytes(format), 8)
     param1.setParameterType(2)
     param2 = ProgramParameter(bin4.toBytes(0))
     param2.setParameterType(2)
 
     netparmList.append(param0)
     netparmList.append(param1)
     netparmList.append(param2)
 
     queryConfig = ServiceProgramCallQueryConfig("/QSYS.LIB/QTOCNETSTS.SRVPGM", "QtocLstPhyIfcDta", 0, netparmList)
     self.__client.initQuery(queryConfig)
     self.__executeQuery()
 
     props = HashMap()
     queryConfig = ProgramCallDocumentQueryConfig("QUSRTVUS.pcml", "QUSRTVUS")
     self.__client.initQuery(queryConfig)
     macs = {}
     if self.__executeQuery():
         props = self.__client.getProperties(["QUSRTVUS.receiver.numentries", "QUSRTVUS.receiver.sizeofentry", "QUSRTVUS.receiver.listoffset"])
         nummacs = int(props.getProperty("QUSRTVUS.receiver.numentries"))
         sizeofentry = int(props.getProperty("QUSRTVUS.receiver.sizeofentry"))
         listoffset = int(props.getProperty("QUSRTVUS.receiver.listoffset"))
         for m in xrange(0, nummacs):
             props = HashMap()
             queryConfig = ProgramCallDocumentQueryConfig("QUSRTVUS4.pcml", "QUSRTVUS")
             self.__client.initQuery(queryConfig)
             values = HashMap()
             values.put("QUSRTVUS.start", Integer(int(listoffset) + 1))
             values.put("QUSRTVUS.length", Integer(int(sizeofentry)))
             self.__client.initPresetValues(values)
             if self.__executeQuery():
                 props = self.__client.getProperties(["QUSRTVUS.receiver.linetype", "QUSRTVUS.receiver.phyintstatus", "QUSRTVUS.receiver.physicaladdress", "QUSRTVUS.receiver.linedesc"])
                 linedesc = props.getProperty("QUSRTVUS.receiver.linedesc")
                 inttype = int(props.getProperty("QUSRTVUS.receiver.linetype"))
                 intstatus = int(props.getProperty("QUSRTVUS.receiver.phyintstatus"))
                 mac = props.getProperty("QUSRTVUS.receiver.physicaladdress")
                 if (inttype == 1) and (intstatus == 1):
                     logger.debug("Found MAC: %s" % mac)
                     macs[linedesc] = mac;
                 listoffset += sizeofentry;
     return macs;