Proxmox VE api python调用测试
2022/1/20 14:12:57
本文主要是介绍Proxmox VE api python调用测试,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
官方api文档:
https://pve.proxmox.com/pve-docs/api-viewer
# -*- coding:utf-8 -*- ''' @Author: XGL @File: pvehttp.py @CreateTime: 2022/1/20 9:43 ''' import requests from requests.cookies import cookiejar_from_dict from time import sleep import urllib3 urllib3.disable_warnings() class Pvehttp(): def __init__(self, host, username, password): self.host = host self.username = username self.password = password self.base_url = 'https://' + host + ':8006/' self.header = {'content-type': 'application/json'} self.request_data = { 'username': self.username, 'password': self.password, 'realm': 'pam' } self.csrftoken = self.baseauth().get('data').get('CSRFPreventionToken') self.ticket = self.baseauth().get('data').get('ticket') self.cookies = cookiejar_from_dict({"PVEAuthCookie": self.ticket}) self.post_header = { 'Cookie': 'PVEAuthCookie={}'.format(self.ticket), 'CSRFPreventionToken': self.csrftoken, } def baseauth(self): url = self.base_url + 'api2/json/access/ticket' response = requests.post(url, headers=self.header, json=self.request_data, verify=False).json() return response def req(self, method, apiurl, **kwargs): url = self.base_url + apiurl try: if method == 'get': response = requests.get(url, **kwargs) return response.json() elif method == 'post': response = requests.post(url, **kwargs) return response.json() except Exception as f: return f def getstatus(self, apiurl): return self.req('get', apiurl, cookies=self.cookies, verify=False) def poststatus(self, apiurl): return self.req('post',apiurl, headers=self.post_header, verify=False) if __name__ == '__main__': data = { 'username': 'root', 'password': 'password', 'host': '192.168.16.36' } pve = Pvehttp(**data) # print(pve.getstatus('api2/json/cluster/tasks')) print(pve.poststatus('api2/extjs/nodes/pve/qemu/101/status/start')) sleep(5) print(pve.getstatus('api2/json/nodes/pve/qemu/101/status/current'))
虚拟机开机测试
这篇关于Proxmox VE api python调用测试的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-23使用python部署一个usdt合约,部署自己的usdt稳定币
- 2024-12-20Python编程入门指南
- 2024-12-20Python编程基础与进阶
- 2024-12-19Python基础编程教程
- 2024-12-19python 文件的后缀名是什么 怎么运行一个python文件?-icode9专业技术文章分享
- 2024-12-19使用python 把docx转为pdf文件有哪些方法?-icode9专业技术文章分享
- 2024-12-19python怎么更换换pip的源镜像?-icode9专业技术文章分享
- 2024-12-19Python资料:新手入门的全面指南
- 2024-12-19Python股票自动化交易实战入门教程
- 2024-12-19Python股票自动化交易入门教程