ZStack - 全流程代码

/ 代码 /

# -*- coding: UTF-8 -*-
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":
 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ZStack新的开源 IaaS 软件,它的诞生是为了解决困绕 IaaS 软件的几大难题:复杂度、稳定性、可伸缩性和灵活性。作为这个领域的新项目,ZStack 从前辈身上学习到了很多经验,并且针对各种云的问题重头设计了整套架构。 ZStack 已经提供了大部分IaaS的基本功能,包括:虚拟机管理,存储卷管理,存储卷快照,各种网络服务(DHCP、DNS、SNAT、EIP、PortForward以及Security Group)。请访问官网网站以获取完整的功能列表:http://zstack.org/documentation/features-matrix.html ZStack非常容易安装。在快速安装说明(http://zstack.org/installation/)里,记录了如何通过两条命令,5分钟时间,完成在一台Linux机器上部署单机演示环境。或者阅读多控制节点安装手册(http://zstack.org/installation/multi-node.html),在30分钟内搭建一个可以负责管理成百上千台服务器的服务集群。 ZStack的相关公开介绍: ZStack 架构设计  为什么我们创造ZStack而不是选择OpenStack http://zstack.org/cn_blog/why-zstack.html  浅谈 CloudStack 与 ZStack 架构与性能  http://www.csdn.net/article/2015-08-24/2825516  _[CSDN]ZStack深度试用:部署、架构与网络及其与OpenStack的对比 http://www.csdn.net/article/2015-05-18/2824690 [CSDN]直戳OpenStack痛处?IaaS开源新兵ZStack架构设计解析 http://www.csdn.net/article/2015-04-10/2824443  [Infoq]私有云之殇:公有云这座大山(上)http://www.infoq.com/cn/articles/ZStack-PartI  [Infoq]为私有云结庐而做“隆中对”(下)http://www.infoq.com/cn/articles/ZStack-PartII  [英文媒体Newstacks]ZStack, an Infrastructure Software with an In-Process Microservices Architecture http://thenewstack.io/zstack-an-infrastructure-software-with-an-in-process-microservices-architecture/  标签:ZStack
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值