Changeset 10393 in genesis for tools


Ignore:
Timestamp:
Apr 8, 2012, 11:22:53 AM (13 years ago)
Author:
rick
Message:

Include proxies.cfg in the autogenerator as well, makes parsing more easy.

Related-To beheer#176

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/yaml2nag.py

    r10391 r10393  
    88import gformat
    99
    10 NODE_PREFIX = 'nodes-7-2'
    11 
    1210def is_ap(ifacedump):
    1311  return ifacedump.has_key('dhcp') and not ifacedump['dhcp'] == 'no'
    1412
    1513def is_iris(node):
    16  return node.has_key('release') and node['release'] in ['8.0-RELEASE', '7.2-RELEASE', '8.1-RELEASE', '8.2-RELEASE']
     14  return node.has_key('release') and node['release'] in ['8.0-RELEASE', '7.2-RELEASE', '8.1-RELEASE', '8.2-RELEASE']
    1715
    18 if __name__ == '__main__':
    19   for host in gformat.get_hostlist():
    20     datadump = gformat.get_yaml(host)
     16def is_up(datadump):
     17  return datadump['status'] == 'up'
    2118
    22     # Make sure to process only active IRIS nodes
    23     if not is_iris(datadump) or not datadump['status'] == 'up':
    24       continue
    2519
    26     # Default hostgroup
    27     hostgroups = [NODE_PREFIX,]
    2820
    29     # Interface groups
    30     for iface in datadump['autogen_iface_keys']:
    31       ifacedump = datadump[iface]
    32       if (ifacedump['status'] == 'up' and not is_ap(ifacedump)):
    33         key = 'iface-%s' % ifacedump['autogen_ifname']
    34         if not key in hostgroups:
    35           hostgroups.append(key)
    36 
    37     if datadump['ileiden']:
    38       hostgroups.append('nodes-ileiden')
    39 
    40     datadump['hostgroups'] = ','.join(hostgroups)
    41     print """
     21def print_host(datadump, hostgroups):
     22  datadump['hostgroups'] = ','.join(hostgroups)
     23  print """
    4224define host{
    43   use        host-pnp
     25  use        %(use)s
    4426  host_name  %(autogen_realname)s
    4527  alias      %(autogen_realname)s
     
    4729  hostgroups %(hostgroups)s
    4830}
    49  
    50     """ % datadump
     31""" % datadump
     32
     33
     34if __name__ == '__main__':
     35  # Process all hosts
     36  for host in gformat.get_hostlist():
     37    datadump = gformat.get_yaml(host)
     38
     39    # Make sure to process only active IRIS nodes
     40    if not is_iris(datadump) or not is_up(datadump):
     41      continue
     42
     43    hostgroups = []
     44    if datadump['nodetype'] == 'CNode':
     45      datadump['use'] = 'host-pnp'
     46      hostgroups.append('nodes-7-2')
     47
     48      # Interface groups
     49      for iface in datadump['autogen_iface_keys']:
     50        ifacedump = datadump[iface]
     51        if is_up(ifacedump) and not is_ap(ifacedump):
     52          key = 'iface-%s' % ifacedump['autogen_ifname']
     53          if not key in hostgroups:
     54            hostgroups.append(key)
     55
     56      # ileiden groups
     57      if datadump['ileiden']:
     58        hostgroups.append('nodes-ileiden')
     59
     60      print_host(datadump, hostgroups)
     61    elif datadump['nodetype'] == 'Proxy':
     62      datadump['use'] = 'host-proxy'
     63      hostgroups.append('proxies')
     64
     65      print_host(datadump, hostgroups)
     66    else:
     67      print "# ERROR: nodetype %(nodetype)s for %(autogen_realname)s not defined" % datadump
     68
     69
     70
Note: See TracChangeset for help on using the changeset viewer.