Changeset 10391 in genesis for tools


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

Fix typo in hostgroup.

While here, fix the wrong key autogen_fqdn and introduce autogen_realname which does this the proper way.

Related-To: beheer#176

Location:
tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10378 r10391  
    7575DOWN = 20
    7676UNKNOWN = 90
     77
     78def get_yaml(item):
     79  """ Get configuration yaml for 'item'"""
     80  gfile = os.path.join(NODE_DIR,item,'wleiden.yaml')
     81
     82  f = open(gfile, 'r')
     83  datadump = yaml.load(f,Loader=Loader)
     84  f.close()
     85
     86  # Preformat certain needed variables for formatting and push those into special object
     87  datadump['autogen_iface_keys'] = get_interface_keys(datadump)
     88
     89  wlan_count=0
     90  for key in datadump['autogen_iface_keys']:
     91    if datadump[key]['type'] in ['11a', '11b', '11g', 'wireless']:
     92      datadump[key]['autogen_ifname'] = 'wlan%i' % wlan_count
     93      wlan_count += 1
     94    else:
     95      datadump[key]['autogen_ifname'] = datadump[key]['interface'].split(':')[0]
     96
     97  dhcp_interfaces = [datadump[key]['autogen_ifname'] for key in datadump['autogen_iface_keys'] if datadump[key]['dhcp'] != 'no']
     98  datadump['autogen_dhcp_interfaces'] = ' '.join(dhcp_interfaces)
     99  datadump['autogen_item'] = item
     100
     101  datadump['autogen_realname'] = get_realname(datadump)
     102  datadump['autogen_domain'] = datadump['domain'] if datadump.has_key('domain') else 'wleiden.net.'
     103  datadump['autogen_fqdn'] = datadump['autogen_realname'] + '.' + datadump['autogen_domain']
     104  return datadump
     105
     106
     107def store_yaml(datadump, header=False):
     108  """ Store configuration yaml for 'item'"""
     109  item = datadump['autogen_item']
     110  gfile = os.path.join(NODE_DIR,item,'wleiden.yaml')
     111
     112  f = open(gfile, 'w')
     113  f.write(generate_wleiden_yaml(datadump, header))
     114  f.close()
     115
    77116
    78117
     
    302341dhcp-authoritative
    303342dhcp-fqdn
    304 domain=dhcp.{{ autogen_fqdn }}.{{ autogen_domain }}
     343domain=dhcp.{{ autogen_fqdn }}
    305344domain-needed
    306345expand-hosts
     
    353392  output = generate_header("#");
    354393  output += Template("""\
    355 hostname='{{ autogen_fqdn }}.{{ autogen_domain }}'
     394hostname='{{ autogen_fqdn }}'
    356395location='{{ location }}'
    357396nodetype="{{ nodetype }}"
     
    495534  return output
    496535
    497 
    498 
    499 def get_yaml(item):
    500   """ Get configuration yaml for 'item'"""
    501   gfile = os.path.join(NODE_DIR,item,'wleiden.yaml')
    502 
    503   f = open(gfile, 'r')
    504   datadump = yaml.load(f,Loader=Loader)
    505   f.close()
    506 
    507   # Preformat certain needed variables for formatting and push those into special object
    508   datadump['autogen_iface_keys'] = get_interface_keys(datadump)
    509 
    510   wlan_count=0
    511   for key in datadump['autogen_iface_keys']:
    512     if datadump[key]['type'] in ['11a', '11b', '11g', 'wireless']:
    513       datadump[key]['autogen_ifname'] = 'wlan%i' % wlan_count
    514       wlan_count += 1
    515     else:
    516       datadump[key]['autogen_ifname'] = datadump[key]['interface'].split(':')[0]
    517 
    518   dhcp_interfaces = [datadump[key]['autogen_ifname'] for key in datadump['autogen_iface_keys'] if datadump[key]['dhcp'] != 'no']
    519   datadump['autogen_dhcp_interfaces'] = ' '.join(dhcp_interfaces)
    520   datadump['autogen_item'] = item
    521   datadump['autogen_fqdn'] = get_fqdn(datadump)
    522 
    523   datadump['autogen_domain'] = datadump['domain'] if datadump.has_key('domain') else 'wleiden.net'
    524   return datadump
    525 
    526 
    527 def store_yaml(datadump, header=False):
    528   """ Store configuration yaml for 'item'"""
    529   item = datadump['autogen_item']
    530   gfile = os.path.join(NODE_DIR,item,'wleiden.yaml')
    531 
    532   f = open(gfile, 'w')
    533   f.write(generate_wleiden_yaml(datadump, header))
    534   f.close()
    535536
    536537
     
    607608FreeBSD 9.0-RELEASE (kernel.wleiden) #0 r230587: Sun Jan 29 17:09:57 CET 2012
    608609
    609   WWW: %(autogen_fqdn)s.wleiden.net - http://www.wirelessleiden.nl
     610  WWW: %(autogen_fqdn)s - http://www.wirelessleiden.nl
    610611  Loc: %(location)s
    611612
     
    756757  print output
    757758
    758 def get_fqdn(datadump):
     759def get_realname(datadump):
    759760  # Proxy naming convention is special, as the proxy name is also included in
    760761  # the nodename, when it comes to the numbered proxies.
    761762  if datadump['nodetype'] == 'Proxy':
    762     fqdn = datadump['nodetype'] + datadump['nodename'].replace('proxy','')
     763    realname = datadump['nodetype'] + datadump['nodename'].replace('proxy','')
    763764  else:
    764765    # By default the full name is listed and also a shortname CNAME for easy use.
    765     fqdn = datadump['nodetype'] + datadump['nodename']
    766   return(fqdn)
     766    realname = datadump['nodetype'] + datadump['nodename']
     767  return(realname)
    767768
    768769
     
    781782
    782783    # Proxy naming convention is special
    783     fqdn = get_fqdn(datadump)
     784    fqdn = datadump['autogen_realname']
    784785    if datadump['nodetype'] == 'CNode':
    785786      wleiden_cname[datadump['nodename']] = fqdn
     
    10731074        logger.info("# Processing: %s", host)
    10741075        datadump = get_yaml(host)
    1075         datadumps[get_fqdn(datadump)] = datadump
     1076        datadumps[datadump['autogen_realname']] = datadump
    10761077
    10771078      for host,datadump in datadumps.iteritems():
  • tools/yaml2nag.py

    r10388 r10391  
    3636
    3737    if datadump['ileiden']:
    38       hostgroups.append('node-ileiden')
     38      hostgroups.append('nodes-ileiden')
    3939
    4040    datadump['hostgroups'] = ','.join(hostgroups)
     
    4242define host{
    4343  use        host-pnp
    44   host_name  %(nodename)s
    45   alias      %(nodename)s
     44  host_name  %(autogen_realname)s
     45  alias      %(autogen_realname)s
    4646  address    %(masterip)s
    4747  hostgroups %(hostgroups)s
Note: See TracChangeset for help on using the changeset viewer.