亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Django封裝交互接口代碼

 更新時(shí)間:2020年07月12日 14:16:47   作者:Lx_strive  
這篇文章主要介紹了Django封裝交互接口代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

我就廢話不多說了,大家還是直接看代碼吧~

# !/usr/bin/env python 
# -*- coding:utf-8 -*-
__author__ = '_X.xx_'
__date__ = '2018/7/18 16:44'
 
from django.http import JsonResponse
 
class HttpCode(object):
 ok = 200
 paramserror = 400
 unantu = 401
 methoderror = 405
 servererror = 500
 
def ok():
 return result()
 
def result(code=HttpCode.ok, message='', data=None, kwargs=None):
 json_dict = {'code': code, 'message': message, 'data': data}
 if kwargs and isinstance(kwargs, dict) and kwargs.keys():
  json_dict.update(kwargs)
 return JsonResponse(json_dict)
 
def params_error(message='', data=None):
 return result(code=HttpCode.paramserror, message=message, data=data)
 
def unauth(message='', data=None):
 return result(code=HttpCode.unantu, message=message, data=data)
 
def method_error(message='', data=None):
 return result(code=HttpCode.methoderror, message=message, data=data)
 
def server_error(message='', data=None):
 return result(code=HttpCode.servererror, message=message, data=data)

補(bǔ)充知識(shí):python部署galery集群

galery.py文件內(nèi)容

import pexpect
import os
import configparser

HOSTNAME_DB1='db1'
HOSTNAME_DB2='db2'
HOSTNAME_DB3='db3'
DB1 = '192.168.254.24'
DB2 = '192.168.254.27'
DB3 = '192.168.254.36'
PORT = 22
USERNAME = 'root'
PASSWORD = 'root'

server3_cnf = 'sed -i "s/wsrep_node_name = db1/wsrep_node_name = db3/g" /etc/my.cnf.d/server.cnf;sed -i "s/wsrep_node_address = %s/wsrep_node_address = %s/g" /etc/my.cnf.d/server.cnf' % (DB1,DB3)
server2_cnf = 'sed -i "s/wsrep_node_name = db1/wsrep_node_name = db3/g" /etc/my.cnf.d/server.cnf;sed -i "s/wsrep_node_address = %s/wsrep_node_address = %s/g" /etc/my.cnf.d/server.cnf' % (DB1,DB3)
def config_parse():
 config = configparser.ConfigParser()
 config.read("/etc/my.cnf.d/server.cnf", encoding="utf-8")
 config.set('galera','wsrep_on','ON')
 config.set('galera','wsrep_provider','/usr/lib64/galera/libgalera_smm.so')
 config.set('galera','wsrep_cluster_address','"gcomm://%s,%s,%s"' % (DB1, DB2, DB3))
 config.set('galera','wsrep_node_name','%s' % HOSTNAME_DB1 )
 config.set('galera','wsrep_node_address','%s' % DB1)
 config.set('galera','binlog_format','row')
 config.set('galera','default_storage_engine','InnoDB')
 config.set('galera','innodb_autoinc_lock_mode','2')
 config.set('galera','wsrep_slave_threads','1')
 config.set('galera','innodb_flush_log_at_trx_commit','1')
 config.set('galera','innodb_buffer_pool_size','120M')
 config.set('galera','wsrep_sst_method','rsync')
 config.set('galera','wsrep_causal_reads','ON')
 config.write(open('/etc/my.cnf.d/server.cnf','w'))
def cp_server_cnf():
 child1 = pexpect.spawn('scp /etc/my.cnf.d/server.cnf %s@%s:/etc/my.cnf.d/server.cnf' % (USERNAME,DB2))
 child1.expect('password:')
 child1.sendline(PASSWORD)
 child1.interact()
 child1.close()
 child2 = pexpect.spawn('scp /etc/my.cnf.d/server.cnf %s@%s:/etc/my.cnf.d/server.cnf' % (USERNAME,DB3))
 child2.expect('password:')
 child2.sendline(PASSWORD)
 child2.interact()

 child2.close()
def conn_db(ip,cnf):
 child3 = pexpect.spawn('ssh %s@%s' % (USERNAME, ip))
 child3.expect('password:')
 child3.sendline('root')
 child3.expect('#')
 child3.sendline(cnf)
 child3.expect('#')
 child3.sendline('systemctl restart mariadb > /dev/null')
 child3.sendline('exit')
 child3.interact()
 child3.close()
def init_cmd():
 res1 = os.system('service mariadb stop')
 res2 = os.system('mysqld_safe --wsrep_cluster_address=gcomm://%s,%s,%s >/dev/null &' % (DB1, DB2, DB3))
 res3 = os.system('galera_new_cluster &>/dev/null')
 if res2 == 0:
  print('galera初始化完成')
  if res3 == 0:
   print('galera集群已經(jīng)啟動(dòng)')
  else:
   print('galera集群?jiǎn)?dòng)失敗')
 else:
  print('galera初始化失敗!')
def main():
 config_parse()
 cp_server_cnf()
 init_cmd()
 conn_db(DB2,server2_cnf)
 conn_db(DB3,server3_cnf)

if __name__ == '__main__':
 main()

以上這篇Django封裝交互接口代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python 用matplotlib畫以時(shí)間日期為x軸的圖像

    Python 用matplotlib畫以時(shí)間日期為x軸的圖像

    這篇文章主要介紹了Python 用matplotlib畫以時(shí)間日期為x軸的圖像,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • Python如何在循環(huán)內(nèi)使用list.remove()

    Python如何在循環(huán)內(nèi)使用list.remove()

    這篇文章主要介紹了Python如何在循環(huán)內(nèi)使用list.remove(),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • Python利用3D引擎寫一個(gè)Pong游戲

    Python利用3D引擎寫一個(gè)Pong游戲

    之前,我們嘗試過用pygame做了一個(gè)2D的Pong游戲。本文將利用強(qiáng)大的3D引擎Ursina制作一個(gè)3D版的Pong游戲。文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2023-01-01
  • 詳解如何使用python創(chuàng)建和結(jié)束線程

    詳解如何使用python創(chuàng)建和結(jié)束線程

    線程的創(chuàng)建和結(jié)束是多線程編程中的核心概念之一,在本文中,我們將學(xué)習(xí)如何使用 Python 創(chuàng)建線程,并探討如何優(yōu)雅地結(jié)束線程,需要的朋友可以參考下
    2024-04-04
  • Python+OpenCV實(shí)現(xiàn)圖像的全景拼接

    Python+OpenCV實(shí)現(xiàn)圖像的全景拼接

    這篇文章主要為大家詳細(xì)介紹了Python+OpenCV實(shí)現(xiàn)圖像的全景拼接,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • python設(shè)置值及NaN值處理方法

    python設(shè)置值及NaN值處理方法

    今天小編就為大家分享一篇python設(shè)置值及NaN值處理方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • python實(shí)現(xiàn)pdf轉(zhuǎn)換成word/txt純文本文件

    python實(shí)現(xiàn)pdf轉(zhuǎn)換成word/txt純文本文件

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)pdf轉(zhuǎn)換成word和txt純文本文件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • Python?dateutil庫簡(jiǎn)化日期時(shí)間處理利器使用場(chǎng)景實(shí)踐

    Python?dateutil庫簡(jiǎn)化日期時(shí)間處理利器使用場(chǎng)景實(shí)踐

    在Python中,處理日期和時(shí)間是常見的任務(wù)之一,dateutil庫是Python標(biāo)準(zhǔn)庫中datetime模塊的擴(kuò)展,提供了許多方便的工具和函數(shù),簡(jiǎn)化了日期和時(shí)間的操作
    2023-12-12
  • Python實(shí)現(xiàn)自定義Jupyter魔法命令

    Python實(shí)現(xiàn)自定義Jupyter魔法命令

    相信大家都用過?jupyter,也用過里面的魔法命令,這些魔法命令都以%或者%%開頭。用法還是比較簡(jiǎn)單的,但是我們能不能自定義魔法命令呢?本文就來教大家如何自定義Jupyter魔法命令
    2022-08-08
  • python實(shí)現(xiàn)跨年表白神器--你值得擁有

    python實(shí)現(xiàn)跨年表白神器--你值得擁有

    這篇文章主要介紹了python實(shí)現(xiàn)跨年表白神器的方法,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2021-01-01

最新評(píng)論