我正在寻找'openstack usage list --start <start_time>'--end <end_time> -f'的python OpenStack SDK版本,它返回给定时间段内的每个项目使用情况。我找到了 conn.get_compute_usage(),它为用户返回?
问问题
162 次
1 回答
0
你有get_compute_usage(projectName)
这将为项目提供详细信息。start
它承认时间的争论end
。
import openstack
from pprint import pprint
from datetime import datetime
os_connect = openstack.connect(
auth_url=AUTH_URL,
project_name=PROJECT_NAME,
username=USERNAME,
password=PASSWORD,
region_name=REGION_NAME,
user_domain_name=USER_DOMAIN_NAME,
project_domain_name=PROJECT_DOMAIN_ID,
app_version='1.0')
for p in os_connect.list_projects() :
usage=os_connect.get_compute_usage(p['name'], start=datetime.strptime("2021-06-01","%Y-%m-%d"), end=datetime.strptime("2021-07-01","%Y-%m-%d"))
#pprint(usage) #Probably too detailed
print("Project:", p['name'])
print("vcpus_usage", usage["total_vcpus_usage"])
print("total_hours", usage["total_hours"])
于 2021-09-16T08:10:02.130 回答