Esempio n. 1
0
def scan( host=get_hostname(), db=None, pyro_timeout=None, verbose=False, silent=False ):
    #print 'SCANNING PORTS'
    # scan all cylc Pyro ports for cylc suites

    gcfg = get_global_cfg(verbose=verbose)
    pyro_base_port = gcfg.cfg['pyro']['base port']
    pyro_port_range = gcfg.cfg['pyro']['maximum number of ports']

    # In non-verbose mode print nothing (scan is used by cylc db viewer).

    # load my suite passphrases 
    reg = localdb(db)
    reg_suites = reg.get_list()
    my_passphrases = {}
    for item in reg_suites:
        rg = item[0]
        di = item[1]
        try:
            pp = passphrase( rg, user, host ).get( suitedir=di )
        except Exception, x:
            #print >> sys.stderr, x
            # no passphrase defined for this suite
            pass
        else:
            my_passphrases[ rg ] = pp
Esempio n. 2
0
def get_host_ip_address( verbose=False ):
    global host_ip_address
    if host_ip_address is None:
        gcfg = get_global_cfg( verbose=verbose )
        target = gcfg.cfg['suite host self-identification']['target']
        # external IP address of the suite host:
        host_ip_address = get_local_ip_address( target )
    return host_ip_address
Esempio n. 3
0
 def __init__( self, suite ):
     gcfg = get_global_cfg()
     self.ldir = gcfg.get_derived_host_item( suite, 'suite log directory' )
     self.path = os.path.join( self.ldir, 'log' ) 
     self.err_path = os.path.join( self.ldir, 'err' )
     self.roll_at_startup = gcfg.cfg['suite logging']['roll over at start-up']
     self.n_keep = gcfg.cfg['suite logging']['rolling archive length']
     self.max_bytes = gcfg.cfg['suite logging']['maximum size in bytes']
Esempio n. 4
0
def get_host_ip_address(verbose=False):
    global host_ip_address
    if host_ip_address is None:
        gcfg = get_global_cfg(verbose=verbose)
        target = gcfg.cfg['suite host self-identification']['target']
        # external IP address of the suite host:
        host_ip_address = get_local_ip_address(target)
    return host_ip_address
Esempio n. 5
0
def prompt( reason, force=False ):
    gcfg = get_global_cfg()
    if force or gcfg.cfg['disable interactive command prompts']:
        return
    response = raw_input( reason + ' (y/n)? ' )
    if response == 'y':
        return
    else:
        sys.exit(0)
Esempio n. 6
0
    def __init__(self, suite, host, owner, verbose=False):
        self.verbose = verbose
        self.suite = suite
        self.host = host
        self.owner = owner
        self.locn = None

        gcfg = get_global_cfg()
        self.local_path = os.path.join( gcfg.cfg['pyro']['ports directory'], suite )
Esempio n. 7
0
    def __init__( self, suite ):
        gcfg = get_global_cfg()

        sodir = gcfg.get_derived_host_item( suite, 'suite log directory' )
        self.opath = os.path.join( sodir, 'out' ) 
        self.epath = os.path.join( sodir, 'err' ) 

        # use same archive length as logging (TODO: document this)
        self.roll_at_startup = gcfg.cfg['suite logging']['roll over at start-up']
        self.arclen = gcfg.cfg['suite logging']['rolling archive length']
Esempio n. 8
0
    def __init__(self, suite):
        gcfg = get_global_cfg()

        sodir = gcfg.get_derived_host_item(suite, 'suite log directory')
        self.opath = os.path.join(sodir, 'out')
        self.epath = os.path.join(sodir, 'err')

        # use same archive length as logging (TODO: document this)
        self.roll_at_startup = gcfg.cfg['suite logging'][
            'roll over at start-up']
        self.arclen = gcfg.cfg['suite logging']['rolling archive length']
Esempio n. 9
0
def get_port( suite, owner=user, host=get_hostname(), pphrase=None, pyro_timeout=None, verbose=False ):
    # Scan ports until a particular suite is found.

    gcfg = get_global_cfg(verbose=verbose)
    pyro_base_port = gcfg.cfg['pyro']['base port']
    pyro_port_range = gcfg.cfg['pyro']['maximum number of ports']

    for port in range( pyro_base_port, pyro_base_port + pyro_port_range ):
        uri = cylcid_uri( host, port )
        try:
            proxy = Pyro.core.getProxyForURI(uri)
        except Pyro.errors.URIError, x:
            # No such host?
            raise SuiteNotFoundError, x

        if pyro_timeout: # convert from string
            pyro_timeout = float( pyro_timeout )

        proxy._setTimeout(pyro_timeout)
        proxy._setIdentification( pphrase )

        before = datetime.datetime.now()
        try:
            name, xowner = proxy.id()
        except Pyro.errors.TimeoutError:
            warn_timeout( host, port, pyro_timeout )
            pass
        except Pyro.errors.ConnectionDeniedError:
            #print >> sys.stderr, "Wrong suite or wrong passphrase at " + portid( host, port )
            pass
        except Pyro.errors.ProtocolError:
            #print >> sys.stderr, "No Suite Found at " + portid( host, port )
            pass
        except Pyro.errors.NamingError:
            #print >> sys.stderr, "Non-cylc pyro server found at " + portid( host, port )
            pass
        else:
            if verbose:
                after = datetime.datetime.now()
                print "Pyro connection on port " +str(port) + " took: " + str( after - before )
            if name == suite and xowner == owner:
                if verbose:
                    print suite, owner, host, port
                # RESULT
                return port
            else:
                # ID'd some other suite.
                #print 'OTHER SUITE:', name, xowner, host, port
                pass
Esempio n. 10
0
 def __init__(self,
              suite,
              run_mode='live',
              clock=None,
              ict=None,
              stop_tag=None):
     self.run_mode = run_mode
     self.clock = clock
     self.ict = ict
     self.stop_tag = stop_tag
     gcfg = get_global_cfg()
     self.dir = gcfg.get_derived_host_item(suite, 'suite state directory')
     self.path = os.path.join(self.dir, 'state')
     arclen = gcfg.cfg['state dump rolling archive length']
     self.archive = rolling_archive(self.path, arclen)
Esempio n. 11
0
    def __init__(self, suite, port, verbose=False):
        self.verbose = verbose
        self.suite = suite 

        # the ports directory is assumed to exist
        gcfg = get_global_cfg()
        pdir = gcfg.cfg['pyro']['ports directory']
 
        self.local_path = os.path.join( pdir, suite )

        try:
            self.port = str(int(port))
        except ValueError, x:
            print >> sys.stderr, x
            raise PortFileError( "ERROR, illegal port number: " + str(port) )
Esempio n. 12
0
def get_suite_host( verbose=False ):
    global suite_host
    if suite_host is None:
        gcfg = get_global_cfg( verbose=verbose )
        hardwired = gcfg.cfg['suite host self-identification']['host']
        method = gcfg.cfg['suite host self-identification']['method']
        # the following is for suite host self-identfication in task job scripts:
        if method == 'name':
            suite_host = hostname
        elif method == 'address':
            suite_host = host_ip_address
        elif method == 'hardwired':
            if not hardwired:
                sys.exit( 'ERROR, no hardwired hostname is configured' )
            suite_host = hardwired
        else:
            sys.exit( 'ERROR, unknown host method: ' + method )
    return suite_host
Esempio n. 13
0
def get_suite_host(verbose=False):
    global suite_host
    if suite_host is None:
        gcfg = get_global_cfg(verbose=verbose)
        hardwired = gcfg.cfg['suite host self-identification']['host']
        method = gcfg.cfg['suite host self-identification']['method']
        # the following is for suite host self-identfication in task job scripts:
        if method == 'name':
            suite_host = hostname
        elif method == 'address':
            suite_host = host_ip_address
        elif method == 'hardwired':
            if not hardwired:
                sys.exit('ERROR, no hardwired hostname is configured')
            suite_host = hardwired
        else:
            sys.exit('ERROR, unknown host method: ' + method)
    return suite_host
Esempio n. 14
0
def main(name, start):

    # Parse the command line:
    server = start()

    # Print copyright and license information
    print_blurb()

    # Before daemonizing attempt to create the suite output tree and get
    # the suite port file.

    try:
        if server.__class__.__name__ != 'restart':
            gcfg = get_global_cfg()
            gcfg.create_cylc_run_tree(server.suite, server.options.verbose)
        server.configure_pyro()
    except Exception, x:
        if server.options.debug:
            raise
        else:
            print >> sys.stderr, x
            sys.exit(1)
Esempio n. 15
0
def main(name, start):

    # Parse the command line:
    server = start()

    # Print copyright and license information
    print_blurb()

    # Before daemonizing attempt to create the suite output tree and get
    # the suite port file.

    try:
        if server.__class__.__name__ != "restart":
            gcfg = get_global_cfg()
            gcfg.create_cylc_run_tree(server.suite, server.options.verbose)
        server.configure_pyro()
    except Exception, x:
        if server.options.debug:
            raise
        else:
            print >> sys.stderr, x
            sys.exit(1)