def Del_Record(self): '''删除记录''' Domains = All_params.check_input("您需要删除解析记录的域名,以便获取其子域名的记录ID,用逗号分隔:") Domains_List = Domains.split(sep=',') running = Dns_Del_Record(self.Login_Token, self.Product) running.Get_Record(Domains_List) Records = All_params.check_input( "需要删除的 域名ID 和 解析记录ID,多个记录已逗号分隔(格式,agvip2003.com=384855336):") Domains_Records_List = Records.split(sep=',') running.Del_Record(Domains_Records_List)
def Add_Record(self,Domains_List): '''添加解析''' Record_Type = 'CNAME' Record_Line = '默认' Domain_Status = 'enable' if not self.Product: print(All_params.display('产品号为空,请检查','red')) mylogger.error('产品号为空,请检查') elif self.Product: for Domain in Domains_List: for Sub_Domain in eval('self.{}'.format(self.Product)): Value = eval("self.{}['{}']".format(self.Product,Sub_Domain)) r = requests.post(self.Add_Record_URL, data={'login_token': self.Login_Token, 'format': self.Format, 'domain': Domain, 'sub_domain': Sub_Domain, 'record_type': Record_Type, 'record_line': Record_Line, 'value': Value, 'status': Domain_Status }) response_record_json = r.json() if response_record_json["status"]["code"] == "1": mylogger.info('本次操作人:--- ;域名:{} 添加记录 {} 成功'.format(Domain, response_record_json["record"]["name"])) else: mylogger.error('本次操作人:--- ;域名:{} 添加失败,错误信息:{}'.format(Domain, response_record_json["status"]["message"])) else: mylogger.error('产品号{}错误'.format(self.Product))
def Add_Record(self): '''添加解析记录''' Domains = All_params.check_input("您需要添加解析记录的域名,多个域名用逗号分隔:") Sub_Domians = All_params.check_input("需要添加的子域名,用逗号分隔:") Domains_List = Domains.split(sep=',') running = Dns_Add_Record(self.Login_Token, self.Product) Record_Type = All_params.check_input("选择记录类型,输入( A 或 CNAME ):") Value = All_params.check_input("要解析的记录值:") Record_Line = All_params.check_input("输入记录线路:输入null为默认:") if Record_Line == 'null': Record_Line_value = '默认' else: Record_Line_value = Record_Line Sub_Domian_List = Sub_Domians.split(sep=',') running.Add_Record(Domains_List, Sub_Domian_List, Record_Type, Record_Line_value, Value)
def Alter_Record(self): '''修改记录''' Domains = All_params.check_input( "您需要修改解析记录的域名,以便获取其子域名的记录ID,多个记录(只能单个域名修改)用逗号分隔:") Domains_List = Domains.split(sep=',') running = Dns_Alter_Record(self.Login_Token, self.Product) running.Get_Record(Domains_List) Records = All_params.check_input("需要修改的解析记录的ID,并且输入ID,用逗号分隔:") Records_List = Records.split(sep=',') Change = All_params.check_input( "您要修改的字段([sub_domain,record_type,area,value,mx,ttl,status]):") Change_TO = All_params.check_input( "你要修改的字段例如:record_type= A CNAME MX TTL,sub_domain= @ www test|这个值对应是你上一步选择的字段| 要修改为:" ) if Change == 'value': running.Alter_Record(Records_List, Change, Change_TO, Value='') else: Value = All_params.check_input("要修改到的记录值:") running.Alter_Record(Records_List, Change, Change_TO, Value)
def get_token(token_file): pro_name = {'1': 'your_product', '2': 'your_product', '3': 'your_product', '4': 'your_product','5':'your_product'} name_check = All_params.input_ck(pro_name,u'产品序号') product = pro_name[name_check] load_file = All_params.load(token_file) pro_token_dict = dict(load_file) Login_Token = pro_token_dict[product] try: oper_dict = {'1':'批量添加域名和记录', '2':'删除域名', '3':'添加域名解析记录', '4':'修改域名解析记录', '5':'删除域名解析记录', '6':'获取域名列表', '7':'获取域名解析记录', '8':'添加域名', '9':'查询域名日志', '10':'批量修改域名记录', '11':'获取D监控报警信息', '12':'获取监控列表'} operation_id = All_params.input_ck(oper_dict,'你的操作') fun_dict = {'1':'running.Add_Domain_And_Record()', '2':'running.Del_Domain()', '3':'running.Add_Record()', '4':'running.Alter_Record()', '5':'running.Del_Record()', '6':'running.Get_Domain_List()', '7':'running.Get_Domain_Record_Info()', '8':'running.Add_Domain()', '9':'running.Get_Domain_Log()', '10':'running.Batch_Alter_Domain_Record()', '11':'running.Get_product_monit()', '12':'running.Get_D_list()'} running = Procedure(Login_Token, product) exec(fun_dict[operation_id]) except (KeyError): print(All_params.display(u'\t\t输入的数字不在字典内', 'red')) mylogger.error(u'输入的数字不在字典内')
'9':'查询域名日志', '10':'批量修改域名记录', '11':'获取D监控报警信息', '12':'获取监控列表'} operation_id = All_params.input_ck(oper_dict,'你的操作') fun_dict = {'1':'running.Add_Domain_And_Record()', '2':'running.Del_Domain()', '3':'running.Add_Record()', '4':'running.Alter_Record()', '5':'running.Del_Record()', '6':'running.Get_Domain_List()', '7':'running.Get_Domain_Record_Info()', '8':'running.Add_Domain()', '9':'running.Get_Domain_Log()', '10':'running.Batch_Alter_Domain_Record()', '11':'running.Get_product_monit()', '12':'running.Get_D_list()'} running = Procedure(Login_Token, product) exec(fun_dict[operation_id]) except (KeyError): print(All_params.display(u'\t\t输入的数字不在字典内', 'red')) mylogger.error(u'输入的数字不在字典内') if __name__ == '__main__': if len(sys.argv) < 2: print('\t',All_params.display('token_file需要pickle.dump序列化才能读取')) print('\t',All_params.display(u'使用方法:python Main.py token_file','red')) sys.exit(0) else: get_token(sys.argv[1])
def Get_Domain_Log(self): '''查询域名日志''' Domains = All_params.check_input(u'输入查询日志的域名,用逗号分隔:') Domains_List = Domains.split(sep=',') running = Dns_Get_Domain_Log(self.Login_Token, self.Product) running.Get_Domain_Log_Info(Domains_List)
def Get_Domain_Record_Info(self): '''获取域名解析记录''' Domains = All_params.check_input("您需要查看记录的域名,以便获取其子域名的记录ID,多个域名用逗号分隔:") Domains_List = Domains.split(sep=',') running = Dns_Get_Domain_Record_Info(self.Login_Token, self.Product) running.Get_Domain_Record_Info(Domains_List)
def Del_Domain(self): '''删除域名''' Domains = All_params.check_input("您需要删除的域名,用逗号分隔:") Domains_List = Domains.split(sep=',') running = Dns_Del_Domain(self.Login_Token, self.Product) running.Del_Domain(Domains_List)