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」の読み取りを行う必要があることを理解していませんでした。

思ったより簡単でした:)

解決策で私のコードに従います:

最初に、リストと位置、値、およびキーを使用して辞書を作成し、必要な値を読み取った後、削除する必要があります。最後に、DNS のエントリを削除するためにリスト「rrdatas」の「BODY」に挿入します。この手順は、すべてのタイプの 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 に答える