最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)Kerberos用戶的增刪改查操作

 更新時(shí)間:2020年12月14日 09:07:52   作者:源神  
這篇文章主要介紹了Python實(shí)現(xiàn)Kerberos用戶的增刪改查操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧

1、首先模擬python類似shell命令行操作的接口:

python安裝subprocess(本地)、paramiko(SSH遠(yuǎn)程)

#-*- coding: UTF-8 -*-
#!/usr/bin/python
import os, sys
import subprocess
import paramiko
import settings
 
class RunCmd(object):
 def __init__(self):
  self.cmd = 'ls'
 
 @staticmethod
 def local_run(cmd):
  print('start executing...')
  print('cmd is -------> %s' % str(cmd))
  s = subprocess.Popen(str(cmd), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  out, err = s.communicate()
  print("outinfo is -------> %s" % out)
  print("errinfo is -------> %s" % err)
  print('finish executing...')
  print('result:------> %s' % s.returncode)
  return s.returncode
 
 @staticmethod
 def remote_run(host, username, password, port, cmd):
  client = paramiko.SSHClient()
  client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  client.connect(hostname=host, port=int(port), username=username, password=password, timeout=5)
  stdin, stdout, stderr = client.exec_command(cmd)
  result = stdout.read()
  client.close()
  return result
 
 @staticmethod
 def krb_run(cmd):
  print('krb_run start...')
  print('cmd is -------> %s' % str(cmd))
  result = RunCmd.remote_run(settings.KRB_HOST, settings.USERNAME, settings.PASSWORD, settings.PORT, cmd)
  print('result:------> %s' % result)
  print('krb_run finish...')
  return result

2、Kerberos常用的命令操作封裝成接口,其他簡單。但需要交互的是刪除 principal

 def delete_user(self, username):
  cmd = r"""
   expect -c "
   set timeout 1;
   spawn kadmin.local -q \"delete_principal {principal}\" ;
   expect yes/no {{ send \"yes\r\" }} ;
   expect *\r
   expect \r
   expect eof
   "
  """.format(principal=username)
  RunCmd.krb_run(cmd)

補(bǔ)充知識:python操作有Kerberos認(rèn)證的hive庫

之前訪問hive都比較簡單,直接用pyhive連接即可。

但是最近遇到了一個(gè)問題,hive有了Kerberosren認(rèn)證。

最終經(jīng)過各種嘗試和靈感迸發(fā),終于解決了這個(gè)問題,遂記錄之。

代碼

from pyhive.hive import connect
con = connect(host='XXXX',port=10000,auth='KERBEROS',kerberos_service_name="hive")
cursor = con.cursor()
cursor.execute('select * from tmp.pricing_calculate_result_spark where time_id="201907171355" limit 10,1')
datas = cursor.fetchall()
print(datas)
cursor.close()
con.close()

端口和ip都換成自己的,auth和kerberos_service_name不要改

運(yùn)行效果

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

  • scrapy處理python爬蟲調(diào)度詳解

    scrapy處理python爬蟲調(diào)度詳解

    在本篇文章里小編給大家整理的是一篇關(guān)于scrapy處理python爬蟲調(diào)度的相關(guān)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2020-11-11
  • Python筆記(叁)繼續(xù)學(xué)習(xí)

    Python筆記(叁)繼續(xù)學(xué)習(xí)

    最近時(shí)間擠來擠去,看英文的文檔,順便熟悉英語,需要反復(fù)好幾遍,才能做點(diǎn)筆記。讀的是《Beginning.Python.From.Novice.to.Professional》,大家可以下載看一下
    2012-10-10
  • Python批量查詢關(guān)鍵詞微信指數(shù)實(shí)例方法

    Python批量查詢關(guān)鍵詞微信指數(shù)實(shí)例方法

    在本篇文章中小編給大家整理的是關(guān)于Python批量查詢關(guān)鍵詞微信指數(shù)實(shí)例方法以及相關(guān)代碼,需要的朋友們可以跟著學(xué)習(xí)下。
    2019-06-06
  • Python中用Decorator來簡化元編程的教程

    Python中用Decorator來簡化元編程的教程

    這篇文章主要介紹了Python中用Decorator來簡化元編程的教程,來自于IBM官方開發(fā)者技術(shù)文檔,需要的朋友可以參考下
    2015-04-04
  • Python 整行讀取文本方法并去掉readlines換行\(zhòng)n操作

    Python 整行讀取文本方法并去掉readlines換行\(zhòng)n操作

    這篇文章主要介紹了Python 整行讀取文本方法并去掉readlines換行\(zhòng)n操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • 一文帶你了解Python枚舉類enum的使用

    一文帶你了解Python枚舉類enum的使用

    枚舉是與多個(gè)唯一常量綁定的一組符號,因?yàn)槊杜e表示的是常量,建議枚舉成員名用大寫 IntEnum 便于進(jìn)行系統(tǒng)交互。本文將通過一些示例代碼講解Python枚舉類的使用,需要的可以參考一下
    2022-10-10
  • 對Python中range()函數(shù)和list的比較

    對Python中range()函數(shù)和list的比較

    下面小編就為大家分享一篇對Python中range()函數(shù)和list的比較,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • python使用urllib2提交http post請求的方法

    python使用urllib2提交http post請求的方法

    這篇文章主要介紹了python使用urllib2提交http post請求的方法,涉及Python使用urllib2模塊的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • Python讀取ini文件、操作mysql、發(fā)送郵件實(shí)例

    Python讀取ini文件、操作mysql、發(fā)送郵件實(shí)例

    這篇文章主要介紹了Python讀取ini文件、操作mysql、發(fā)送郵件實(shí)例,本文重點(diǎn)在Mysql操作的講解上,包含查詢、插入、更新和刪除操作,需要的朋友可以參考下
    2015-01-01
  • scrapy實(shí)踐之翻頁爬取的實(shí)現(xiàn)

    scrapy實(shí)踐之翻頁爬取的實(shí)現(xiàn)

    這篇文章主要介紹了scrapy實(shí)踐之翻頁爬取的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01

最新評論

惠水县| 望奎县| 平顺县| 丰宁| 东海县| 象山县| 潜山县| 连城县| 建平县| 瓮安县| 宜阳县| 涟水县| 花垣县| 秦安县| 会同县| 青海省| 红安县| 青铜峡市| 宁南县| 灌云县| 临湘市| 永仁县| 鸡西市| 抚松县| 威海市| 汉寿县| 金堂县| 澄江县| 馆陶县| 岳普湖县| 彰武县| 栾城县| 蓝田县| 三都| 曲沃县| 西宁市| 桐乡市| 阜宁县| 泗洪县| 偏关县| 岳阳县|