def get_or_create_hosted_zone(zone_name):
 zone = r53.get_hosted_zone_by_name(zone_name)
 parent_zone_name = '.'.join(zone_name.split('.')[1:])
 parent_zone = r53.get_hosted_zone_by_name(parent_zone_name)
 if args.noop:
  if parent_zone:
   print 'Would have created/updated zone: {} parent: {}'.format(zone_name, parent_zone_name)
  else:
   print 'Would have created/updated zone: {}'.format(zone_name, parent_zone_name)
  return zone
 if (not zone):
  print 'zone {} does not exist, creating'.format(zone_name)
  ts = datetime.datetime.utcnow().strftime('%Y-%m-%d-%H:%M:%SUTC')
  zone = r53.create_hosted_zone(zone_name, comment='Created by vpc_dns script - {}'.format(ts))
 if parent_zone:
  print 'Updating parent zone {}'.format(parent_zone_name)
  dns_records = set()
  dns_records.add(DNSRecord(parent_zone, zone_name, 'NS', 900, zone.NameServers))
  add_or_update_record(dns_records)
 return zone

def get_or_create_hosted_zone ( zone_name ) : zone = r53 . get_hosted_zone_by_name ( zone_name ) parent_zone_name = '.' . join ( zone_name . split ( '.' ) [ 1 : ] ) parent_zone = r53 . get_hosted_zone_by_name ( parent_zone_name ) if args . noop : if parent_zone : print 'Would have created/updated zone: {} parent: {}' . format ( zone_name , parent_zone_name ) else : print 'Would have created/updated zone: {}' . format ( zone_name , parent_zone_name ) return zone if ( not zone ) : print 'zone {} does not exist, creating' . format ( zone_name ) ts = datetime . datetime . utcnow ( ) . strftime ( '%Y-%m-%d-%H:%M:%SUTC' ) zone = r53 . create_hosted_zone ( zone_name , comment = 'Created by vpc_dns script - {}' . format ( ts ) ) if parent_zone : print 'Updating parent zone {}' . format ( parent_zone_name ) dns_records = set ( ) dns_records . add ( DNSRecord ( parent_zone , zone_name , 'NS' , 900 , zone . NameServers ) ) add_or_update_record ( dns_records ) return zone
creates the zone and updates the parent with the ns information in the zone returns: created zone .