Next / Previous / Contents / TCC Help System / NM Tech homepage

25.7. ClientSet.__findConfig(): Look up a system in the GetHardware service

This function calls GetHardware to retrieve the configuration data for one client.

hwscan3.py
# - - -   C l i e n t S e t . _ _ f i n d C o n f i g

    def __findConfig ( self, reportInfo, rpcServer, hostName, os ):
        '''Look up one client in the GetHardware interface.

          [ (reportInfo is a ReportInfo instance) and
            (rpcServer is an xmlrpclib.ServerProxy for
            FORGE_SERVER) and
            (hostName is a client host name string) and
            (os is a tccSpecialOS value) ->
              if rpcServer returns a value for hostName ->
                self.__clientMap[hostName]  :=  a ClientConfig
                    instance made from ldapMap[hostName], os,
                    and the value returned from rpcServer,
                    using device types from reportInfo
              else -> I ]
        '''

Because GetHardware expects a dotted IP address and not a host name, we use socket to translate the qualified host name to an IP value. It should never happen that socket doesn't know about one of our clients, but in case it does, we log a message and return.

hwscan3.py
        #-- 1 --
        # [ fullName  :=  fully qualified version of hostname ]
        fullName  =  "%s.nmt.edu" % hostName

        #-- 2 --
        # [ if socket.gethostbyname() knows about fullName ->
        #     ip  :=  fullName's dotted IP address
        #   else ->
        #     sys.stderr  +:=  error message
        #     return ]
        try:
            ip  =  socket.gethostbyname ( fullName )
        except socket.gaierror, detail:
            print >>sys.stderr, ( "socket(%s): system unknown" %
                                  fullName )
            return

Next we see if GetHardware has configuration information about this IP. If not, it returns an empty list, and we return. For a successful call, a dictionary is returned, whose keys are attributes of the client.

hwscan3.py
        #-- 3 --
        # [ if rpcServer has a record for ip ->
        #     hardMap  :=  a dictionary containing hardware
        #         configuration information for ip
        #   else -> return ]
        hardMap  =  rpcServer.GetHardware ( ip )
        if type(hardMap) is list:
            print >>sys.stderr, ( "*** GetHardware has no record "
                "for host '%s'." % hostName )
            return

All that remains is to package up the host name, the os value, and the contents of hardMap into a ClientConfig instance, and add it to self.__clientMap().

hwscan3.py
        #-- 4 --
        # [ clientConfig  :=  a ClientConfig instance made from
        #       hostName, os, and hardMap, with device classes
        #       from reportInfo ]
        clientConfig  =  ClientConfig ( reportInfo, hostName,
                                        os, hardMap )

        #-- 5 --
        self.__clientMap[hostName]  =  clientConfig