/ 代码 /
import requests
import json
import hashlib
user_name = 'admin'
user_password = 'password'
host = 'http://localhost:8080/'
def login():
sha512 = hashlib.sha512()
sha512.update(user_password)
password = sha512.hexdigest()
content = {
"logInByAccount": {
"password": password,
"accountName": user_name}
}
data = json.dumps(content)
url = host + 'zstack/v1/accounts/login'
headers = {
"Content-Type": "application/json"}
response = requests.put(url, data, headers=headers)
text = response.text
rsp = json.loads(text)
if rsp:
return rsp['inventory']['uuid']
def create_zone(session_uuid):
content = {
"params":
{
"name": "Zone",
"description": "zone"}
}
data = json.dumps(content)
url = host + 'zstack/v1/zones'
headers = {
"Content-Type": "application/json", "Authorization": "OAuth " + session_uuid}
response = requests.post(url, data, headers=headers)
zone_uuid = deal_response(response, True)
if zone_uuid:
return zone_uuid
def create_clusters(session_uuid, zone_uuid):
content = {
"params":
{
"zoneUuid": zone_uuid,
"name": "cluster",
"description": "cluster",
"hypervisorType": "KVM"}
}
data = json.dumps(content)
url = host + 'zstack/v1/clusters'
headers = {
"Content-Type": "application/json", "Authorization": "OAuth " + session_uuid}
response = requests.post(url, data, headers=headers)
cluster_uuid = deal_response(response, True)
if cluster_uuid:
return cluster_uuid
def create_host(cluster_uuid, session_uuid):
print('cluster_uuid : %s' % cluster_uuid)
content = {
"params": {
"username": "root",
"password": "password",
"name": "Host",
"sshPort": 22,
"managementIp": "192.168.0.101",
"clusterUuid": cluster_uuid,
"hostType": "kvm",
"description": "host_des"
}
}
data = json.dumps(content)
url = host + 'zstack/v1/hosts/kvm'
headers = {
"Content-Type": "application/json", "Authorization": "OAuth " + session_uuid}
response = requests.post(url, data, headers=headers)
host_uuid = deal_response(response, True)
if host_uuid:
return host_uuid
def create_image_store(session_uuid):
data = json.dumps({
"params":