1818@click .option ('--a-record' , '-a' ,
1919 is_flag = True ,
2020 help = "Sync the A record for the host" )
21+ @click .option ('--aaaa-record' ,
22+ is_flag = True ,
23+ help = "Sync the AAAA record for the host" )
2124@click .option ('--ptr' , is_flag = True , help = "Sync the PTR record for the host" )
2225@click .option ('--ttl' ,
2326 default = 7200 ,
2427 show_default = True ,
2528 type = click .INT ,
2629 help = "Sets the TTL for the A and/or PTR records" )
2730@environment .pass_env
28- def cli (env , identifier , a_record , ptr , ttl ):
31+ def cli (env , identifier , a_record , aaaa_record , ptr , ttl ):
2932 """Sync DNS records."""
3033
34+ items = ['id' ,
35+ 'globalIdentifier' ,
36+ 'fullyQualifiedDomainName' ,
37+ 'hostname' ,
38+ 'domain' ,
39+ 'primaryBackendIpAddress' ,
40+ 'primaryIpAddress' ,
41+ '''primaryNetworkComponent[
42+ id, primaryIpAddress,
43+ primaryVersion6IpAddressRecord[ipAddress]
44+ ]''' ]
45+ mask = "mask[%s]" % ',' .join (items )
3146 dns = SoftLayer .DNSManager (env .client )
3247 vsi = SoftLayer .VSManager (env .client )
3348
3449 vs_id = helpers .resolve_id (vsi .resolve_ids , identifier , 'VS' )
35- instance = vsi .get_instance (vs_id )
50+ instance = vsi .get_instance (vs_id , mask = mask )
3651 zone_id = helpers .resolve_id (dns .resolve_ids ,
3752 instance ['domain' ],
3853 name = 'zone' )
3954
4055 def sync_a_record ():
4156 """Sync A record."""
4257 records = dns .get_records (zone_id , host = instance ['hostname' ])
43-
4458 if not records :
4559 # don't have a record, lets add one to the base zone
4660 dns .create_record (zone ['id' ],
@@ -58,6 +72,38 @@ def sync_a_record():
5872 rec ['ttl' ] = ttl
5973 dns .edit_record (rec )
6074
75+ def sync_aaaa_record ():
76+ """Sync AAAA record."""
77+ records = dns .get_records (zone_id ,
78+ host = instance ['hostname' ],
79+ record_type = 'aaaa' )
80+
81+ try :
82+ # done this way to stay within 80 character lines
83+ component = instance ['primaryNetworkComponent' ]
84+ record = component ['primaryVersion6IpAddressRecord' ]
85+ ip_address = record ['ipAddress' ]
86+ except KeyError :
87+ raise exceptions .CLIAbort ("%s does not have an ipv6 address"
88+ % instance ['fullyQualifiedDomainName' ])
89+
90+ if not records :
91+ # don't have a record, lets add one to the base zone
92+ dns .create_record (zone ['id' ],
93+ instance ['hostname' ],
94+ 'aaaa' ,
95+ ip_address ,
96+ ttl = ttl )
97+ else :
98+ recs = [x for x in records if x ['type' ].lower () == 'aaaa' ]
99+ if len (recs ) != 1 :
100+ raise exceptions .CLIAbort ("Aborting A record sync, found "
101+ "%d A record exists!" % len (recs ))
102+ rec = recs [0 ]
103+ rec ['data' ] = ip_address
104+ rec ['ttl' ] = ttl
105+ dns .edit_record (rec )
106+
61107 def sync_ptr_record ():
62108 """Sync PTR record."""
63109 host_rec = instance ['primaryIpAddress' ].split ('.' )[- 1 ]
@@ -102,3 +148,6 @@ def sync_ptr_record():
102148
103149 if both or ptr :
104150 sync_ptr_record ()
151+
152+ if aaaa_record :
153+ sync_aaaa_record ()
0 commit comments