Eduardo Duarte
Eduardo Duarte

Reputation: 11

Error the deleting records in Google Cloud DNS

I am using the library 'resourceRecordSets()' for list my entries and , delete some record (eg: 'Type MX').

But I try to remove it with:

response = service.changes().create(project=PROJECT_NAME,managedZone=ZONE_NAME, body=BODY).execute()

and too doing increment of record SOA .

But I have this is error :

"Invalid value for 'entity.change.deletions[1].rrdata[0]': '1 aspmx.l.google.com.','5 alt1.aspmx.l.google.com.','5 alt2.aspmx.l.google.com.','10 aspmx2.googlemail.com.','10 aspmx3.googlemail.com.','10 aspmx4.googlemail.com.','10 aspmx5.googlemail.com.'

But if I insert this syntax:

'5 alt1.aspmx.l.google.com.','5 alt2.aspmx.l.google.com.','10 aspmx2.googlemail.com.','10 aspmx3.googlemail.com.','10 aspmx4.googlemail.com.','10 aspmx5.googlemail.com.'

in my 'BODY' I have success.

Follow my code:

class DeleteRecordDNS(webapp2.RequestHandler):

  @decorator.oauth_aware   
  def get(self,name,ttl,rrdata,type,ZONE_NAME):
    PROJECT_NAME = 'avian-mile-538'
    service = managerdns.authenticate()
    #Lista records, pega o SOA para fazer incremento[inc] para deletions e addtions    
    soa = service.resourceRecordSets().list(project=PROJECT_NAME,managedZone=ZONE_NAME).execute()
    mxsmod=''
    #acertando os caracters
    for records in soa['rrsets']:

        if records['type'] == type:
            entmx =  records['rrdatas']
    for mxs in entmx:  
        mxsmod = mxsmod + ","+"'"+mxs +"'"
    moddata = mxsmod[2:len(mxsmod)-1]
    strmoddata=str(moddata)
    txt = strmoddata[2:len(strmoddata)-1]
    #incrementando SOA
    for records in soa['rrsets']:
        if records['type'] == 'SOA':
            entsoa =  records['rrdatas']

    modstr = str(entsoa)
    mod = modstr.split()
    #removendo o 'u' e '[]'

    modsem = mod[6]
    modsenM = modsem[0:3]

    modU = mod[0]
    modsU = modU[3:34]
    inc = int(mod[2])
    final = inc+1 
    res = str(final)
    #rdata soa modificado
    soainc = modsU + ' '+ mod[1] + ' '+ res + ' '+ mod[3] + ' '+ mod[4] + ' '+ mod[5] + ' '+ modsenM
    soaorig = modsU + ' '+ mod[1] + ' '+ mod[2] + ' '+ mod[3] + ' '+ mod[4] + ' '+ mod[5] + ' '+ modsenM

    BODY =  {
    'additions': [
        {
            'kind': 'dns#resourceRecordSet',
            'name': name,

            'rrdatas': [
                soainc #rrdata SOA com inc
            ],
            'ttl': 21600,
            'type': "SOA"
        }
    ],
    'deletions': [
        {
            'kind': 'dns#resourceRecordSet',
            'name': name,
            "rrdatas": [
                soaorig #rrdata SOA original
            ],
            'ttl': 21600,
            'type': 'SOA'
        },
        {
            'kind': 'dns#resourceRecordSet',
            'name': name,
            'rrdatas': [
               moddata# record the deleting
            ],
            'ttl': ttl,
            'type': type    
        }
    ]
    }


    response = service.changes().create(project=PROJECT_NAME,
                                        managedZone=ZONE_NAME,
                                        body=BODY).execute()



self.redirect('/listadns/' + ZONE_NAME) 

With:

{
            'kind': 'dns#resourceRecordSet',
            'name': name,
            'rrdatas': [
               moddata# record the deleting

            ],
            'ttl': ttl,
            'type': type    
        }

no success :(

With:

{
        'kind': 'dns#resourceRecordSet',
        'name': name,
        'rrdatas': [
           '1 aspmx.l.google.com.','5 alt1.aspmx.l.google.com.','5 alt2.aspmx.l.google.com.','10 aspmx2.googlemail.com.','10 aspmx3.googlemail.com.','10 aspmx4.googlemail.com.','10 aspmx5.googlemail.com.'


        ],
        'ttl': ttl,
        'type': type    
    }

success :)

But I need that is automatic.

Someone can help me?

Thanks

Upvotes: 0

Views: 1215

Answers (1)

Eduardo Duarte
Eduardo Duarte

Reputation: 11

I had not understood that was need insert the values in each position of dictionary within of list, doing reading of ""rrdatas".

Was more easy that I thinking :)

Follows my code with resolution:

First I create the dictionary with the list and the position, values and keys and after I read the values the I need remove and finally, I insert in my "BODY" in list "rrdatas" for remove the entries of DNS. This step can used for delete all types of DNS.

BODY =  {
    'additions': [
        {
            'kind': 'dns#resourceRecordSet',
            'name': nomesoa['dnsName'],

            'rrdatas': [
                soainc #rrdata SOA com inc
            ],
            'ttl': 21600,
            'type': "SOA"
        }
    ],
    'deletions': [
        {
            'kind': 'dns#resourceRecordSet',
            'name': nomesoa['dnsName'],
            "rrdatas": [
                soaorig #rrdata SOA original
            ],
            'ttl': 21600,
            'type': 'SOA'
        },
        {
            'kind': 'dns#resourceRecordSet',
            'name': name,
            'rrdatas': [


            ],
            'ttl': ttl,
            'type': type    
        }
    ]
    }
    #Lendo a lista que contem os reccords    
    for records in soa['rrsets']:

        if records['type'] == type:
            #inserindo no body acima
            BODY['deletions'][1]['rrdatas']=records['rrdatas']
    #Removendo Record
    response = service.changes().create(project=PROJECT_NAME,
                                      managedZone=ZONE_NAME,
                                      body=BODY).execute()

**And follows my complete function, ideas, please send comments. **

    class DeleteRecordDNS(webapp2.RequestHandler):

  @decorator.oauth_aware   
  def get(self,name,ttl,rrdata,type,ZONE_NAME):
    PROJECT_NAME = 'avian-mile-538'
    service = managerdns.authenticate()
    #Lista records, pega o SOA para fazer incremento[inc] para deletions e addtions    
    soa = service.resourceRecordSets().list(project=PROJECT_NAME,managedZone=ZONE_NAME).execute()
    #para pegar nome da domain para record SOA
    nomesoa = service.managedZones().get(project=PROJECT_NAME,managedZone=ZONE_NAME).execute()


    #incrementando SOA
    for records in soa['rrsets']:
        if records['type'] == 'SOA':
            entsoa =  records['rrdatas']

    modstr = str(entsoa)
    mod = modstr.split()
    #removendo o 'u' e '[]'

    modsem = mod[6]
    modsenM = modsem[0:3]

    modU = mod[0]
    modsU = modU[3:34]
    inc = int(mod[2])
    final = inc+1 
    res = str(final)
    #rdata soa modificado
    soainc = modsU + ' '+ mod[1] + ' '+ res + ' '+ mod[3] + ' '+ mod[4] + ' '+ mod[5] + ' '+ modsenM
    soaorig = modsU + ' '+ mod[1] + ' '+ mod[2] + ' '+ mod[3] + ' '+ mod[4] + ' '+ mod[5] + ' '+ modsenM

    BODY =  {
    'additions': [
        {
            'kind': 'dns#resourceRecordSet',
            'name': nomesoa['dnsName'],

            'rrdatas': [
                soainc #rrdata SOA com inc
            ],
            'ttl': 21600,
            'type': "SOA"
        }
    ],
    'deletions': [
        {
            'kind': 'dns#resourceRecordSet',
            'name': nomesoa['dnsName'],
            "rrdatas": [
                soaorig #rrdata SOA original
            ],
            'ttl': 21600,
            'type': 'SOA'
        },
        {
            'kind': 'dns#resourceRecordSet',
            'name': name,
            'rrdatas': [


            ],
            'ttl': ttl,
            'type': type    
        }
    ]
    }
    #Lendo a lista que contem os reccords    
    for records in soa['rrsets']:

        if records['type'] == type:
            #inserindo no body acima
            BODY['deletions'][1]['rrdatas']=records['rrdatas']
    #Removendo Record
    response = service.changes().create(project=PROJECT_NAME,
                                      managedZone=ZONE_NAME,
                                      body=BODY).execute()



    self.redirect('/listadns/' + ZONE_NAME)

Upvotes: 1

Related Questions