Exemplo n.º 1
0
def getBWTimerDetail(policyId, publicKey, privateKey, projectId, region):
    result = {}
    params_p = {
            "Region": region,
            "PolicyId": policyId,
            "Action": 'GetASPolicyDetail'
            }
    r_p = requestToAPI(publicKey, privateKey, projectId, params_p)
    r_p = json.loads(r_p)
    if r_p['RetCode'] != 0 :
        print(json.dumps(r_p, indent=4))
        return result

    result['EIPID'] = r_p['EIPID']

    params = {
            "Region": region,
            "ConfigId": r_p['BootupConfig'],
            "Action": 'GetASBootupConfigBandwidthPackage'
            }
    r = requestToAPI(publicKey, privateKey, projectId, params)
    r = json.loads(r)
    if r['RetCode'] != 0 :
        print(json.dumps(r, indent=4))
        return result

    result['Bandwidth'] = r['Bandwidth']
    result['TimeRange'] = r['TimeRange']
    return result
Exemplo n.º 2
0
def createBandwidthPackageTimer(args):
    with open(args.config, 'r') as f:
        config = json.load(f)

    params_b = {
            "Region": args.region,
            "Name": config['Name'],
            "Bandwidth": config['Bandwidth'],
            "TimeRange": config['TimeRange'],
            "Action": 'CreateASBootupConfigBandwidthPackage'
            }
    r_b = requestToAPI(args.publicKey, args.privateKey, args.projectId, params_b)
    r_b = json.loads(r_b)
    # print(json.dumps(r_b, indent=4))

    if r_b['RetCode'] != 0 :
        return

    params_p = {
            "Region": args.region,
            "PolicyName": config['Name'],
            "PolicyType": 5,
            "ResourceId": 'BandwidthPackage',
            "NotificationId": config['NotificationId'],
            "ScaleMax": 0,
            "ScaleMin": 0,
            "BootupConfig": r_b["ConfigId"],
            "EIPID": config['EIPID'],
            "Action": 'CreateASPolicy'
            }
    r_p = requestToAPI(args.publicKey, args.privateKey, args.projectId, params_p)
    r_p = json.loads(r_p)
    # print(json.dumps(r_p, indent=4))

    if r_p['RetCode'] != 0 :
        return

    params = {
            "Region": args.region,
            "Name": config['Name'],
            "Period": config['Period'],
            "NotificationId": config['NotificationId'],
            "StartTime": config["StartTime"],
            "EndTime": config["EndTime"],
            "TimerType": "BANDWIDTH_PACKAGE",
            "TimerActionURL": 'uas_scanner',
            "TimerActionPath": r_p["PolicyId"],
            "Action": 'CreateASTimer'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 3
0
def getTimer(args):
    params = {
            "Region": args.region,
            "TaskId": args.id,
            "Action": 'GetASTimer'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)

    if r['RetCode'] != 0 :
        print(json.dumps(result, indent=4))
        return

    result = {}
    result['Name'] = r['Name']
    result['Status'] = r['Status']
    result['Period'] = r['Period']
    result['StartTime'] = r['StartTime']
    result['EndTime'] = r['EndTime']
    result['TimerType'] = r['TimerType']
    result['NotificationId'] = r['NotificationId']

    path = {}
    if(r["TimerType"] == "INSTANCE_GROUP"):
        path = getIGTimerDetail(r["TimerActionPath"])
    elif(r["TimerType"] == "BANDWIDTH_PACKAGE"):
        path = getBWTimerDetail(r["TimerActionPath"], args.publicKey, args.privateKey, args.projectId, args.region)
    else:
        print('unkown type', r["TimerType"])
    result = dict(result, **path)
    print(json.dumps(result, indent=4))
Exemplo n.º 4
0
def getInstanceGroupList(args):
    params = {
            "Region": args.region,
            "Action": 'GetASInstanceGroupList'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 5
0
def listTimer(args):
    params = {
            "Region": args.region,
            "Action": 'GetASTimerList'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 6
0
def listRule(args):
    params = {
            "Region": args.region,
            "PolicyId": args.group_id,
            "Action": 'GetASPolicyRules'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 7
0
def removeInstanceFromGroup(args):
    params = {
            "InstanceId": args.instanceId,
            "GroupId": args.groupId,
            "Region": args.region,
            "Action": 'RemoveInstanceFromGroup'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 8
0
def deleteVServer(args):
    params = {
            "GroupId": args.groupId,
            "ULBId": args.ulbId,
            "VServerConfig": args.vserverConfig,
            "Region": args.region,
            "Action": 'DeleteASVServer'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 9
0
def updateInstanceLockState(args):
    params = {
            "InstanceId": args.instanceId,
            "GroupId": args.groupId,
            "State": args.state,
            "Region": args.region,
            "Action": 'UpdateInstanceLockState'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 10
0
def addInstanceToGroup(args):
    params = {
            "InstanceId": args.instanceId,
            "GroupId": args.groupId,
            "Region": args.region,
            "IsLock": args.isLock,
            "Action": 'AddInstanceToGroup'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 11
0
def delInstanceGroup(args):
    params = {
            "GroupId": args.groupId,
            "Region": args.region,
            "Action": 'DeleteASInstanceGroup'
            }
    if args.isKeepInstances:
       params["KeepInstances"] = args.isKeepInstances
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 12
0
def createBootupConfigBandwidthPackage(args):
    params = {
            "Region": args.region,
            "Name": args.name,
            "Bandwidth": args.bandwidth,
            "TimeRange": args.time_range,
            "Action": 'CreateASBootupConfigBandwidthPackage'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 13
0
def modifyTimerPolicy(args):
    params = {
            "Region": args.region,
            "PolicyId": args.id,
            "BootupConfig": args.bootup_config,
            "EIPID": args.eip_id,
            "Action": 'ModifyASPolicy'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 14
0
def updateTimerStatus(args):
    if (args.status != 'ON' and args.status != 'OFF') :
        print('status must be ON or OFF')
        return
    params = {
            "Region": args.region,
            "TaskId": args.id,
            "Status": args.status,
            "Action": 'UpdateASTimerStatus'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 15
0
def modifyBootupConfigBandwidthPackage(args):
    params = {
            "Region": args.region,
            "ConfigId": args.id,
            "Action": 'ModifyASBootupConfigBandwidthPackage'
            }
    if args.name:
        params["Name"] = args.name
    if args.bandwidth:
        params["Bandwidth"] = args.bandwidth
    if args.time_range:
        params["TimeRange"] = args.time_range
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 16
0
def createTimerPolicy(args):
    params = {
            "Region": args.region,
            "PolicyName": args.name,
            "PolicyType": 5,
            "ResourceId": 'BandwidthPackage',
            "NotificationId": args.notification_id,
            "ScaleMax": 0,
            "ScaleMin": 0,
            "BootupConfig": args.bootup_config,
            "EIPID": args.eip_id,
            "Action": 'CreateASPolicy'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 17
0
def createRule(args):
    params = {
            "Region": args.region,
            "PolicyId": args.group_id,
            "RuleName": args.name,
            "ScaleDirection": args.scale_diretion,
            "ScaleStep": args.scale_step,
            "CooldownTime": 300,
            "CheckPeriod": 1,
            "MetricType": args.metric_type,
            "ConditionType": args.condition_type,
            "ConsecutivePeriods": args.consecutiveperiods,
            "Thresholds": args.thresholds,
            "Action": 'CreateASPolicyRule'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 18
0
def createInstanceGroupTimer(args):
    with open(args.config, 'r') as f:
        config = json.load(f)
    params = {
            "Region": args.region,
            "Name": config["Name"],
            "Period": config["Period"],
            "StartTime": config["StartTime"],
            "EndTime": config["EndTime"],
            "NotificationId": config["NotificationId"],
            "TimerType": "INSTANCE_GROUP",
            "TimerActionURL": 'uas_scanner',
            "TimerActionPath": config["GroupId"] + '?max=' + str(config["ScaleMax"]) + '&min=' + str(config["ScaleMin"]),
            "Action": 'CreateASTimer'
            }
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 19
0
def createInstanceGroup(args):
    params = {
            "Region": args.region,
            "GroupName": args.name,
            "NotificationId": args.notification_id,
            "ScaleMax": args.scale_max,
            "ScaleMin": args.scale_min,
            "BootupConfig": args.bootup_config,
            "RemovePolicy": args.remove_policy,
            "DesiredAmount": args.desired_amount,
            "Action": 'CreateASInstanceGroup'
            }
    if args.ulb:
        params['UlbId'] = args.ulb
        for v,i in zip(args.vserver, xrange(0, len(args.vserver))):
            params['VServerConfigs.%d' %i] = v
    if args.eip:
        params['IsBindEIP'] = args.eip
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 20
0
def modifyBandwidthPackageTimer(args):
    params = {
        "Region": args.region,
        "TaskId": args.id,
        "TimerType": "BANDWIDTH_PACKAGE",
        "Action": 'ModifyASTimer'
        }
    if args.name:
        params["Name"] = args.name
    if args.period:
        params["Period"] = args.period
    if args.notification_id:
        params["NotificationId"] = args.notification_id
    if args.start_time:
        params["StartTime"] = args.start_time
    if args.end_time:
        params["EndTime"] = args.end_time
    if args.policy_id:
        params["TimerActionURL"] = 'uas_scanner'
        params["TimerActionPath"] = args.policy_id
    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))
Exemplo n.º 21
0
def modifyInstanceGroup(args):
    params = {
            "Region": args.region,
            "GroupId": args.group_id,
            "Action": 'ModifyASInstanceGroup'
            }
    if args.name:
        params["GroupName"] = args.name
    if args.notification_id:
        params["NotificationId"] = args.notification_id
    if args.scale_max:
        params["ScaleMax"] = args.scale_max
    if args.scale_min:
        params["ScaleMin"] = args.scale_min
    if args.bootup_config:
        params["BootupConfig"] = args.bootup_config
    if args.remove_policy:
        params["RemovePolicy"] = args.remove_policy
    if args.eip:
        params["IsBindEIP"] = args.eip

    r = requestToAPI(args.publicKey, args.privateKey, args.projectId, params)
    r = json.loads(r)
    print(json.dumps(r, indent=4))