@@ -246,7 +246,7 @@ def set_alias_record(
246246 Linode doesn't allow CAA and CNAME records on the same subdomain.
247247 Using A records solves this limitation.
248248 """
249-
249+ # Resolve domain to IP
250250 domain = content
251251 print (f"Trying to resolve: { domain } " )
252252 ip_address = socket .gethostbyname (domain )
@@ -255,34 +255,17 @@ def set_alias_record(
255255 if not ip_address :
256256 raise socket .gaierror ("Could not resolve any variant of the domain" )
257257
258- # Check if A record already exists with same IP
259- existing_a_records = self .get_dns_records (zone_id , name , RecordType .A )
260- for record in existing_a_records :
261- if record .content == ip_address :
262- print ("A record with the same IP already exists" )
263- return True
264-
265- # Delete any existing A or CNAME records for this name
266- for record_type in [RecordType .A , RecordType .CNAME ]:
267- existing_records = self .get_dns_records (zone_id , name , record_type )
268- for record in existing_records :
269- if record .id :
270- self .delete_dns_record (zone_id , record .id )
271-
272- # Create A record instead of CNAME
273- new_record = DNSRecord (
274- id = None ,
275- name = name ,
276- type = RecordType .A ,
277- content = ip_address ,
278- ttl = ttl ,
279- proxied = False , # Linode doesn't support proxying
280- )
258+ # Delete any existing CNAME records for this name (clean transition)
259+ existing_cname_records = self .get_dns_records (zone_id , name , RecordType .CNAME )
260+ for record in existing_cname_records :
261+ if record .id :
262+ self .delete_dns_record (zone_id , record .id )
281263
282264 print (
283265 f"Creating A record for { name } pointing to { ip_address } (instead of CNAME to { content } )"
284266 )
285- return self .create_dns_record (zone_id , new_record )
267+ # Use the base class's set_a_record method with idempotency
268+ return self .set_a_record (zone_id , name , ip_address , ttl , proxied = False )
286269
287270 def create_caa_record (self , zone_id : str , caa_record : CAARecord ) -> bool :
288271 """Create a CAA record."""
0 commit comments