Python对接openstack接口案例--用户、容器、flavor、镜像、网络、云主机、安全组
技能大赛openstack全套python-api对接代码自创
·
这里小编先给大家一个用户的案例,自我感觉有参考价值,如需要更多可私信哦:
#coding=utf-8
import json
import requests
headers={}
headers['Content-Type']='application/json'
headers['Accept']='*/*'
url='http://172.24.111.10:'
url1=url+'35357/v3/auth/tokens'
def get_token():
body={'auth':{'identity':{'methods':['password'],'password':{'user':{'id':'68225936bb7c428aab19164edc048664','password':'000000'}}},'scope':{'project':{'id':'66b1811ff76b4dab9f083dcee1afe8e3'}}}}
result=requests.post(url=url1,headers=headers,data=json.dumps(body)).headers['X-Subject-Token']
return result
headers['X-Auth-Token']=get_token()
url2=url+'35357/v3/users'
def create():
body={'user':{'name':'testuser','description':'python api','domain_id':'5662c87c08ed4dc0b1f3f35426185341'}}
result=requests.post(url=url2,headers=headers,data=json.dumps(body)).status_code
if result ==201:
print('用户创建成功')
else:
print('失败')
create()
更多推荐
已为社区贡献1条内容
所有评论(0)