基於dnspod api做的dnspod類開發

# -*- coding: utf-8 -*-
'''
Created on 2015-06-19

@author: minqiang.feng
@email: [email protected]

'''
import os,sys,time
import json
import dnspod.api
from dnspod.api.rest import *
import argparse
'''
這邊可以設置一個默認的accessKeyId和accessKeySecret,當然也可以不設置
注意:默認的只需要設置一次就可以了
'''
dnspod.setDefaultAppInfo("username", "passwd")

'''
a = dnspod.api.domain20150619DomainList()
b = dnspod.api.user20150619UserDetail()
f= a.getResponse()
print b.getResponse()
try:
    print("begin");
    f= a.getResponse()
    print(f)
except Exception,e:
    print(e)
'''
class Domain(object):
    def __init__(self,domain=''):
	self.domain = domain
	self.domain_id = None

    def getidbydomain(self):
	buf=self.DomainInfo()
	self.domain_id = buf["domain"]['id']
	return self.domain_id

    def setdomain(self,domain):
	self.domain = domain
    def DomainCreate(self):
	a = domain20150619DomainCreate()
	a.domain = self.domain
	try:
	    f = a.getResponse()
	    return f
	except Exception,e:
	    print e
    def DomainInfo(self):
        a = domain20150619DomainInfo()
        a.domain = self.domain
        try:
            f = a.getResponse()
            return f
        except Exception,e:
            print e
    def DomainList(self):
        a = domain20150619DomainList()
        a.domain = self.domain
        try:
            f = a.getResponse()
            return f
        except Exception,e:
            print e
    def DomainLog(self):
        pass
    def DomainRemove(self):
        a = domain20150619DomainRemove()
        a.domain = self.domain
        try:
            f = a.getResponse()
            return f
        except Exception,e:
            print e
  
    def DomainSearchenginepush(self):
        pass
    def DomainshareCreate(self):
        pass
    def DomainshareList(self):
        pass
    def DomainStatus(self):
        pass

class Record(Domain):
    def __init__(self,domain):
	Domain.__init__(self,domain)
	self.sub_domain = None
	self.record_type = None
	self.record_id = None
	self.recordid = []
	#self.domain_id = None
	self.domain_id = self.getidbydomain()

    def RecordCreate(self,sub_domain,record_type,value,record_line="默認",mx=5,ttl=600,status="enable"):
        a = record20150619RecordCreate()
        a.domain_id = self.domain_id
	if sub_domain == '':
	    a.sub_domain = self.sub_domain
	else:
	    a.sub_domain = sub_domain
	a.record_type = record_type
	a.value = value
	a.record_line = record_line
	a.mx = mx
	a.ttl = ttl
	a.status = status
        try:
            f = a.getResponse()
            return f
        except Exception,e:
            print e
    
    def SetRecord(self,RecordName):
	self.sub_domain = RecordName

    '''判斷記錄是否存在'''
    def Istrue(self):
	self.GetRecordID()
	if len(self.recordid) >0:
	    return True
	else:
	    return False
    def Length(self):
	self.GetRecordID()
	return len(self.recordid)

    def RecordNum(self):
	self.GetRecordID()
	return len(self.recordid)
	
    def GetRecordID(self,sub_domain=''):
	buf=self.RecordList();
	self.recordid = []
	if sub_domain == '':
	    sub_domain = self.sub_domain
	for i in buf["records"]:
	    if sub_domain == i["name"]:
		self.recordid.append(i["id"])
    
    def RecordInfo(self):
	self.GetRecordID(self.sub_domain)
        a = record20150619RecordInfo()
        a.domain_id = self.domain_id
	tmp = []
	for i in self.recordid:
	    a.record_id = i
	    try:
		f = a.getResponse()
		tmp.append(f)
	    except Exception,e:
		print e
	return tmp

    def RecordList(self):
        a = record20150619RecordList()
        a.domain_id = self.domain_id
        try:
            f = a.getResponse()
            return f
        except Exception,e:
            print e

    def RecordModify(self,recordid,sub_domain,record_type,value,record_line="默認",mx=5,ttl=600,status="enable"):
        a = record20150619RecordModify()
        a.domain_id = self.domain_id
	a.record_id = recordid
        a.sub_domain = sub_domain
        a.record_type = record_type
        a.value = value
        a.record_line = record_line
        a.mx = mx
        a.ttl = ttl
        a.status = status
        try:
            f = a.getResponse()
            return f
        except Exception,e:
            print e
    def AutoRecordModify(self,sub_domain,record_type,value,record_line="默認",mx=5,ttl=600,status="enable"):
	self.GetRecordID(sub_domain)
	if len(self.recordid) >= 2:
	    return "More than 1 Records"
	if len(self.recordid) ==0:
	    return "Less than 1 Records"
        a = record20150619RecordModify()
        a.domain_id = self.domain_id
	a.record_id = self.recordid[0]
        a.sub_domain = sub_domain
        a.record_type = record_type
        a.value = value
        a.record_line = record_line
        a.mx = mx
        a.ttl = ttl
        a.status = status
        try:
            f = a.getResponse()
            return f
        except Exception,e:
            print e
    def RecordRemark(self):
        pass
    def RecordRemove(self):
        pass
    def RecordStatus(self):
        pass
        
 if __name__ == '__main__':
    Do = Domain()
    Do.setdomain("fengyunzhibo.com")
    print Do.DomainList()


該倆個class是在python的dnspod api的基礎上寫的,請下載dnspod api後使用,下載地址 http://down.51cto.com/data/2079627 




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章