Exemplo n.º 1
0
def main(options, args):

    ro.init()

    auth = None
    if options.auth:
        auth = options.auth.split(':')
    elif os.environ.has_key('LTCSAUTH'):
        auth = os.environ['LTCSAUTH'].split(':')

    if options.rohost:
        (rohost, roport) = options.rohost.split(':')
        roport = int(roport)
        ro_svc = ro.remoteObjectClient(rohost, roport, auth=auth)
        #ro_svc = ro.remoteObjectClient(rohost, roport, auth=auth,
        #                               secure=True)

    if options.laserimpacted:
        val = options.laserimpacted.upper()
        if not val in ('NO', 'YES', 'CALC'):
            raise Exception(
                "Valid values for --laser_impacted are NO|YES|CALC")

        ro_svc.set('laserimpacted', val)

    if options.laserstate:
        val = options.laserstate.upper()
        if not val in ('OFF', 'ON', 'ON-SKY'):
            raise Exception("Valid values for --laser_state are OFF|ON|ON-SKY")

        ro_svc.set('laserstate', val)

    sys.exit(0)
Exemplo n.º 2
0
    def _getProxy(self, subscriber, options):
        """Internal method to create & cache remoteObject proxies to remote
        pubsubs (subscribers).
        """
        try:
            # If we already have a proxy for the _svcname_, return it.
            return self._proxyCache[subscriber]

        except KeyError:
            # Create a new proxy to the external pubsub and cache it

            # Fill in possible authentication and security params
            kwdargs = { 'timeout': self.remote_timeout }
            #kwdargs = {}
            if options.has_key('auth'):
                kwdargs['auth'] = options['auth']
            if options.has_key('secure'):
                kwdargs['secure'] = options['secure']

            # subscriber can be a service name or a host:port
            if not (':' in subscriber):
                proxy_obj = ro.remoteObjectProxy(subscriber, **kwdargs)
            else:
                (host, port) = subscriber.split(':')
                port = int(port)
                proxy_obj = ro.remoteObjectClient(host, port, **kwdargs)
                
            self._proxyCache[subscriber] = proxy_obj
            self.logger.debug("Created proxy for '%s'" % (subscriber))

            return proxy_obj
Exemplo n.º 3
0
def client(logger, options, args):

    import pyfits

    if options.host:
        auth = (options.svcname, options.svcname)
        svc = ro.remoteObjectClient(options.host,
                                    options.port,
                                    name=options.svcname,
                                    auth=auth)
    else:
        svc = ro.remoteObjectProxy(options.svcname)

    if options.framelist:
        # If --framelist=FILE was specified, then read FILE and make a
        # list of fits files from it.
        try:
            in_f = open(options.framelist, 'r')
            buf = in_f.read()
            args = buf.split()

            args = map(lambda fid: options.fitsdir + '/' + fid + '.fits', args)
        except IOError, e:
            raise DAQerror("Failed to open '%s': %s" %
                           (options.framelist, str(e)))
Exemplo n.º 4
0
def get_ms_handle(host=None):
    if not host:
        host = ro.get_myhost()

    # Create a handle to the manager service
    ms = ro.remoteObjectClient(host, ro.managerServicePort)
    
    return ms
Exemplo n.º 5
0
def get_handle(ns, name):
    l = ns.getHosts(name)
    if len(l) > 0:
        tup = l.pop()
        (host, port) = tup
        return ro.remoteObjectClient(host, port, auth=(name, name))

    return None
Exemplo n.º 6
0
        options.pullname = 'gen2'
    elif options.gen2host == 'simulator':
        logger.debug('setting gen2 host<%s>' % options.gen2host)
        options.pullhost = 'g2sim'
        options.host = 'g2sim'
        options.pullname = 'gen2'
    else:
        logger.warn('you need to specify host, pullhost, and pullname')
        sys.exit(1)

    if options.appstr == 'fitsviewer':

        try:
            ro.init()
            options.appstr = ro.remoteObjectClient('localhost',
                                                   22020,
                                                   auth=('fitsview_ana',
                                                         'fitsview_ana'))
        except ro.remoteObjectError, e:
            logger.error("Error initializing remote objects subsystem: %s" %
                         str(e))
            sys.exit(1)

    # Compute hmac
    hmac_digest = hmac.new(key, passphrase, digest_algorithm).hexdigest()

    queue = Queue.Queue(1)
    ev_queue = threading.Event()

    sink = AnaSink(logger,
                   options.datadir,
                   options.appstr,
Exemplo n.º 7
0
def main(options, args):

    logger = ssdlog.make_logger('relay', options)

    ro.init()

    myhost = ro.get_myhost(short=False)
    myport = options.port
    myself = "%s:%d" % (myhost, myport)

    ev_quit = threading.Event()
    queue = Queue.Queue()

    # make a name for our monitor
    myMonName = options.name

    # monitor channels we are interested in
    channels = options.channels.split(',')

    sum_ns = ro.remoteObjectClient(options.gen2host, 7075)
    sum_ns.ro_echo(99)

    loc_status = ro.remoteObjectProxy('status')

    # Get a status dict of all aliases
    statusInfo = Convert.statusInfo()
    aliases = statusInfo.getAliasNames()
    # remove troublesome aliases
    for alias in (
            'CXWS.TSCV.OBE_INR',
            'STATL.OBJKIND',
            'TSCV.OBJKIND',
            'TSCV.ZERNIKE_RMS',
            'TSCV.ZERNIKE_RMS_WOA20',
    ):
        aliases.remove(alias)
    sum_status = get_handle(sum_ns, 'status')

    statusDict = dict.fromkeys(aliases, None)
    fetchDict = sum_status.fetch(statusDict)
    #print fetchDict
    loc_status.store(fetchDict)

    # Create a local monitor
    mymon = Monitor.Monitor(myMonName, logger, numthreads=20)

    # Make our callback functions
    m = Make_cb(logger=logger,
                monitor=mymon,
                queue=queue,
                monpath='mon.status')

    # Subscribe our callback functions to the local monitor
    mymon.subscribe_cb(m.anon_arr, channels)

    server_started = False
    try:
        # Startup monitor threadpool
        mymon.start(wait=True)
        # start_server is necessary if we are subscribing, but not if only
        # publishing
        mymon.start_server(wait=True,
                           port=options.port,
                           authDict={myMonName: myMonName})
        server_started = True

        # subscribe our monitor to the summit monitor hub

        summit = get_handle(sum_ns, 'monitor')

        summit.subscribe(myself, channels,
                         {'auth': "%s:%s" % (myMonName, myMonName)})

        while not ev_quit.isSet():
            try:
                (path, tree, time) = queue.get(block=True, timeout=1.0)

                #print tree
                try:
                    loc_status.store(tree)
                except Exception, e:
                    logger.error("Error relaying status: %s" % (str(e)))
                #printTree(path, tree, time)

            except Queue.Empty:
                continue

            except KeyboardInterrupt:
                logger.error("Received keyboard interrupt!")
                ev_quit.set()

    finally:
        if server_started:
            mymon.stop_server(wait=True)
        mymon.stop(wait=True)
Exemplo n.º 8
0
    ev_quit = threading.Event()

    auth = None
    if options.auth:
        auth = options.auth.split(':')
    elif os.environ.has_key('LTCSAUTH'):
        auth = os.environ['LTCSAUTH'].split(':')

    # Special option to use the remoteObjects framework to communicate
    # with a remote daemon that will write the file.
    ro_svc = None
    if options.rohost:
        (rohost, roport) = options.rohost.split(':')
        roport = int(roport)
        ro_svc = ro.remoteObjectClient(rohost, roport, auth=auth,
                                       secure=options.secure)

    if options.svcname:
        tmp = options.svcname.split(':')
        if len(tmp) == 2:
            svcname = tmp[0]
            port = int(tmp[1])
        else:
            svcname = tmp[0]
            port = 8212

        authDict = {}
        if auth:
            authDict[auth[0]] = auth[1]

        logger.info("Starting '%s' service..." % svcname)