示例#1
0
def create_instance_with_data(conf, data, chargeMode='postpaid_by_duration', redisVersion='4.0',
                    ipv6On=None, shardNumber=None):
    client = setClient(conf)
    header = getHeader(conf)
    instance_id = None
    resp = None
    name = "auto_test_" + str(int(time.time()))
    shardNumber = data["shardNumber"] if shardNumber is None else shardNumber
    try:
        azId = AzIdSpec(data["azId"]["master"], data["azId"]["slave"])
        cacheInstance = CacheInstanceSpec(data["vpcId"], data["subnetId"]
                                          , data["cacheInstanceName"]
                                          , data["cacheInstanceClass"]
                                          , azId, conf["instance_password"]
                                          , conf["instance"]["cacheInstanceDescription"]
                                          , redisVersion
                                          , ipv6On
                                          , shardNumber)
        params = CreateCacheInstanceParameters(str(conf["region"]), cacheInstance)
        charge = ChargeSpec(chargeMode, 'month', 1)
        params.setCharge(charge)
        req = CreateCacheInstanceRequest(params, header)
        resp = client_send(client, req)
        if resp.result is not None:
            instance_id = str(resp.result["cacheInstanceId"])
    except Exception, e:
        print e
        assert False
 def setChargeSpec(self,
                   chargeMode=None,
                   chargeUnit=None,
                   chargeDuration=None):
     # chargeMode:  prepaid_by_duration:预付费,postpaid_by_usage:按用量后付费,postpaid_by_duration:按配置后付费,默认为postpaid_by_duration
     self.chargeSpec = ChargeSpec(chargeMode, chargeUnit, chargeDuration)
     print 'ChargeSpec created...'
     print 'ChargeMode: ' + self.chargeSpec.chargeMode
 def auto_createInstanceWithoutPassword(self, config):
     client = setClient(config)
     header = getHeader(config)
     name = "auto_test_" + str(int(time.time()))
     try:
         charge = ChargeSpec('postpaid_by_duration', 'year', 1)
         instance = InstanceSpec('MC-S-1C1G', 'single', config["az"],
                                 config["vpc"], config["subnet"], name,
                                 config["version"], False, "desc", None,
                                 charge)
         parameters = CreateInstanceParameters(config["region"], instance)
         request = CreateInstanceRequest(parameters, header)
         resp = client.send(request)
         if resp.error is not None:
             assert False
     except Exception, e:
         print e
az = 'cn-north-1a'
# 云盘name前缀
namePrefix = 'libing-disk'
# 云盘类型:ssd/premium-hdd
type = 'ssd'
# 描述
description = 'SSD Disk testing'
# 云盘大小(GiB)
size = 20
# 创建云硬盘数量
count = 2
# clientToken:短随机数
clientToken = str(uuid.uuid4())[:5]
# 计费模式:按配置后付费
chargeMode = 'postpaid_by_duration'
myChargeSpec = ChargeSpec(chargeMode=chargeMode)
# Disk spec
myDiskSpec = DiskSpec(az=az,
                      name=namePrefix,
                      diskType=type,
                      diskSizeGB=size,
                      description=description,
                      charge=myChargeSpec)
myParam = CreateDisksParameters(regionId=regionId,
                                diskSpec=myDiskSpec,
                                maxCount=count,
                                clientToken=clientToken)
myRequest = CreateDisksRequest(myParam)

myCredential = Credential(access_key, secret_key)
myClient = DiskClient(myCredential)