0

我正在使用库“resourceRecordSets()”来列出我的条目并删除一些记录(例如:“Type MX”)。

但我尝试删除它:

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

并且也在做记录 SOA 的增量。

但我有这是错误:

"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.'

但是如果我插入这个语法:

'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.'

在我的“身体”中,我取得了成功。

按照我的代码:

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) 

和:

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

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

没有成功:(

和:

{
        '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    
    }

成功 :)

但我需要它是自动的。

有人可以帮助我吗?

谢谢

4

1 回答 1

1

我不明白需要在列表中字典的每个位置插入值,读取“rrdatas”。

比我想的更容易:)

以分辨率遵循我的代码:

首先,我使用列表以及位置、值和键创建字典,在读取需要删除的值之后,最后,我在列表“rrdatas”中的“BODY”中插入以删除 DNS 的条目。此步骤可用于删除所有类型的 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()

**并遵循我的完整功能,想法,请发送评论。**

    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)
于 2014-04-22T13:06:36.507 回答