Example #1
0
def register_templates(template_registry, config_opts):
    '''
    Register the common templates.
    Params
    ------
    template_registry : `TemplateRegistry`
        Registry to update.

    config_opts : `hod.mpiservice.ConfigOptsParams`
        Configuration structure holding our config options.
    '''
    workdir = config_opts.workdir
    modules = config_opts.modules
    local_data_network = node.sorted_network(node.get_networks())[0]
    templates = [
        _config_template_stub('masterhostname', 'Hostname bound to the Fully Qualified Domain Name (FQDN) of the master node.'),
        _config_template_stub('masterhostaddress', 'Address bound to the Fully Qualified Domain Name (FQDN) of the master node.'),
        _config_template_stub('masterdataname', 'Hostname bound to the Infiniband adaptor on the master node if available'),
        _config_template_stub('masterdataaddress', 'Address bound to the Infiniband adaptor on the master node if available'),
        ConfigTemplate('hostname', socket.getfqdn, 'Fully Qualified Domain Name (FQDN)'),
        ConfigTemplate('hostaddress', lambda: socket.gethostbyname(socket.getfqdn()), 'IP address registered as the FQDN'),
        ConfigTemplate('dataname', local_data_network.hostname, 'Infiniband hostname if available'),
        ConfigTemplate('dataaddress', local_data_network.addr, 'Infiniband address if available'),
        ConfigTemplate('workdir', workdir, 'Base directory for configuration and logging, e.g. /tmp, or somewhere on a shared file system.'),
        ConfigTemplate('localworkdir', lambda: mklocalworkdir(workdir), 'Subdirectory of workdir with user, host, and pid in the name to make it distinct from other workdirs for use on shared file systems'),
        ConfigTemplate('user', _current_user, 'Current user'),
        ConfigTemplate('pid', os.getpid, 'PID for the current process'),
        ConfigTemplate('modules', lambda: ' '.join(modules), 'Modules listed in the hod.conf'),
        ]

    for ct in templates:
        template_registry.register(ct)
def register_templates(template_registry, config_opts):
    '''
    Register the common templates.
    Params
    ------
    template_registry : `TemplateRegistry`
        Registry to update.

    config_opts : `hod.mpiservice.ConfigOptsParams`
        Configuration structure holding our config options.
    '''
    workdir = config_opts.workdir
    modules = config_opts.modules
    local_data_network = node.sorted_network(node.get_networks())[0]
    templates = [
        _config_template_stub(
            'masterhostname',
            'Hostname bound to the Fully Qualified Domain Name (FQDN) of the master node.'
        ),
        _config_template_stub(
            'masterhostaddress',
            'Address bound to the Fully Qualified Domain Name (FQDN) of the master node.'
        ),
        _config_template_stub(
            'masterdataname',
            'Hostname bound to the Infiniband adaptor on the master node if available'
        ),
        _config_template_stub(
            'masterdataaddress',
            'Address bound to the Infiniband adaptor on the master node if available'
        ),
        ConfigTemplate('hostname', socket.getfqdn,
                       'Fully Qualified Domain Name (FQDN)'),
        ConfigTemplate('hostaddress',
                       lambda: socket.gethostbyname(socket.getfqdn()),
                       'IP address registered as the FQDN'),
        ConfigTemplate('dataname', local_data_network.hostname,
                       'Infiniband hostname if available'),
        ConfigTemplate('dataaddress', local_data_network.addr,
                       'Infiniband address if available'),
        ConfigTemplate(
            'workdir', workdir,
            'Base directory for configuration and logging, e.g. /tmp, or somewhere on a shared file system.'
        ),
        ConfigTemplate(
            'localworkdir', lambda: mklocalworkdir(workdir),
            'Subdirectory of workdir with user, host, and pid in the name to make it distinct from other workdirs for use on shared file systems'
        ),
        ConfigTemplate('user', _current_user, 'Current user'),
        ConfigTemplate('pid', os.getpid, 'PID for the current process'),
        ConfigTemplate('modules', lambda: ' '.join(modules),
                       'Modules listed in the hod.conf'),
    ]

    for ct in templates:
        template_registry.register(ct)
Example #3
0
 def test_get_networks_single(self):
     '''
 $ ip addr show
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 inet 127.0.0.1/8 scope host lo
 inet6 ::1/128 scope host
 valid_lft forever preferred_lft forever
 '''
     with patch('netifaces.interfaces', return_value=['lo']):
         with patch('netifaces.ifaddresses', return_value={2:[{'addr':'127.0.0.1', 'netmask':'255.0.0.0'}]}):
             with patch('socket.getfqdn', return_value='localhost'):
                 network = hn.get_networks()
                 self.assertEqual(network, [hn.NetworkInterface('localhost', '127.0.0.1', 'lo', 8)])
def master_template_opts(stub_config_opts=None):
    '''
    Generate template options for the master node.

    If stub_config_opts is given, this function pulls the doctrings from the existing
    configuration
    '''
    data_interface = node.sorted_network(node.get_networks())[0]
    master_dataname = data_interface.hostname
    master_dataaddress = data_interface.addr
    fqdn = socket.getfqdn()
    docs = dict()
    if stub_config_opts is not None:
        docs = dict([(opt.name, opt.doc) for opt in stub_config_opts])
    return [
        ConfigTemplate('masterhostname', fqdn, docs.get('masterhostname', '')),
        ConfigTemplate('masterhostaddress', socket.gethostbyname(fqdn), docs.get('masterhostaddress', '')),
        ConfigTemplate('masterdataname', master_dataname, docs.get('masterdataname', '')),
        ConfigTemplate('masterdataaddress', master_dataaddress, docs.get('masterdataaddress', '')),
        ]
Example #5
0
 def test_get_networks_multiple(self):
     '''
 $ ip addr show
 1: lo: --blah blah UP blah--
 link/loopback ---
 inet 127.0.0.1/8 scope host lo
 inet6 ::1/128 scope host
 valid_lft forever preferred_lft forever
 2: em1: --blah blah UP blah--
 link/ether ---
 inet 10.1.1.2/16 brd 255.255.255.128 scope global em1
 inet6 fe80::be30:5bff:fef7:7be8/64 scope link
 valid_lft forever preferred_lft forever
 3: em2: --blah blah DOWN blah--
 link/ether ---
 4: em3: --blah blah UP blah--
 link/ether ---
 inet 157.193.16.9/25 brd 157.193.16.127 scope global em3
 inet6 fe80::be30:5bff:fef7:7bec/64 scope link
 valid_lft forever preferred_lft forever
 5: em4: --blah blah DOWN blah--
 link/ether bc:30:5b:f7:7b:ed brd ff:ff:ff:ff:ff:ff
 6: ib0: --blah blah UP blah--
 link/infiniband ---
 inet 10.143.13.2/16 brd 10.143.255.255 scope global ib0
 inet6 fe80::202:c903:ea:98e1/64 scope link
 valid_lft ---
 7: em1.295@em1: --blah blah UP blah--
 link/ether bc: ---
 inet 172.24.13.2/16 brd 172.24.255.255 scope global em1.295
 inet6 fe80::be30:5bff:fef7:7be8/64 scope link
 valid_lft ---
 '''
     _interfaces = lambda: ['lo', 'em1', 'em2', 'em3', 'em4', 'ib0', 'em1.295@em1']
     _ifaddresses = lambda x: {
             'lo': {2:[{'addr':'127.0.0.1', 'netmask':'255.0.0.0'}]},
             'em1': {2:[{'addr':'10.1.1.2', 'netmask':'255.255.0.0'}]},
             'em2': {1:[{}]},
             'em3': {2:[{'addr':'157.193.16.9', 'netmask':'255.255.255.128'}]},
             'em4': {1:[]},
             'ib0': {2:[{'addr':'10.143.13.2', 'netmask':'255.255.0.0'}]},
             'em1.295@em1': {2:[{'addr':'172.24.13.2', 'netmask':'255.255.0.0'}]}
         }[x]
     _hostname = lambda x: {
             '127.0.0.1': 'localhost',
             '10.1.1.2': 'wibble01.wibble.os',
             '157.193.16.9': 'wibble01.sitename.tld',
             '10.143.13.2': 'wibble01.wibble.data',
             '172.24.13.2': 'wibble.sitename.nat'
         }[x]
     from hod.node.node import get_networks
     with patch('netifaces.interfaces', side_effect=_interfaces):
         with patch('netifaces.ifaddresses', side_effect=_ifaddresses):
             with patch('socket.getfqdn', side_effect=_hostname):
                 network = get_networks()
                 self.assertEqual(network, [
                         hn.NetworkInterface('localhost', '127.0.0.1', 'lo', 8),
                         hn.NetworkInterface('wibble01.wibble.os', '10.1.1.2', 'em1', 16),
                         hn.NetworkInterface('wibble01.sitename.tld', '157.193.16.9', 'em3', 25),
                         hn.NetworkInterface('wibble01.wibble.data', '10.143.13.2', 'ib0', 16),
                         hn.NetworkInterface('wibble.sitename.nat', '172.24.13.2', 'em1.295@em1', 16),
                         ])