def doIt(): clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # print type(p.accessKeyId()) # print type( p.accessSecret()) # print type(p.regionId()) # 设置参数 request = StopInstanceRequest.StopInstanceRequest() request.set_accept_format('json') # print type(p.instanceId()) request.add_query_param('InstanceId', p.instanceId()) # print type(request) # 发起请求 response = clt.do_action_with_exception(request) # 输出结果 print print json.loads(response) print "Stopping Server" i = 1 while True: status = diaDescribeInstanceAttribute.status() if status != 'Stopped': print 'Stopping... ' + str(i) i += 1 time.sleep(1) else: print 'Stopped' break
def doIt(): clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # 设置参数 request = StartInstanceRequest.StartInstanceRequest() request.set_accept_format('json') request.add_query_param('InstanceId', p.instanceId()) # 发起请求 response = clt.do_action_with_exception(request) # 输出结果 print print json.loads(response) print "Starting Server" pingTarget = p.pingTarget() i = 1 while True: response = os.system("ping -c 1 -W 1 " + pingTarget + ' >/dev/null') if response == 0: print 'Ready for ssh' break else: print "Starting... " + str(i) i += 1 time.sleep(0.5)
def doIt(): clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) request = ReInitDiskRequest.ReInitDiskRequest() request.set_accept_format('json') request.add_query_param('DiskId', p.diskId()) response = clt.do_action(request) print print json.loads(response) print "Server Reinitializing"
def status(): clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # 设置参数 request = DescribeInstanceAttributeRequest.DescribeInstanceAttributeRequest( ) request.set_accept_format('json') request.add_query_param('InstanceId', p.instanceId()) # 发起请求 response = clt.do_action(request) return json.loads(response)['Status']
def doIt(): clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # 设置参数 request = DescribeKeyPairsRequest.DescribeKeyPairsRequest() request.set_accept_format('json') # 发起请求 response = clt.do_action(request) # 输出结果 print json.dumps(json.loads(response), indent=2)
def doIt(): clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # 设置参数 request = ResetDiskRequest.ResetDiskRequest() request.set_accept_format('json') request.add_query_param('DiskId', p.diskId()) request.add_query_param('SnapshotId', p.snapshotId()) # 发起请求 response = clt.do_action(request) # 输出结果 print json.dumps(json.loads(response), indent=2)
def doIt(): clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # 设置参数 request = DescribeSnapshotsRequest.DescribeSnapshotsRequest() request.set_accept_format('json') # 发起请求 response = clt.do_action(request) # 输出结果 snapshots = json.loads(response)['Snapshots']['Snapshot'] totalCount = len(snapshots) for i in range(totalCount): snapshotName = snapshots[i]['SnapshotName'] if (snapshotName != '') and not (str(snapshotName).startswith('auto')): print json.dumps(snapshots[i]['SnapshotName']) print json.dumps(snapshots[i]['SnapshotId']) # print json.dumps(snapshots[i]['SourceDiskId']) print
def allAttributes(): clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # 设置参数 request = DescribeInstanceAttributeRequest.DescribeInstanceAttributeRequest( ) request.set_accept_format('json') request.add_query_param('InstanceId', p.instanceId()) # 发起请求 response = clt.do_action(request) # 输出结果 # if __name__ == "__main__": # print json.dumps(json.loads(response), indent=2) print print json.loads(response)['InstanceName'] print json.loads(response)['EipAddress']['IpAddress'] print json.loads(response)['Status'] print json.loads(response)['RegionId'] print json.loads(response)['InstanceId'] print json.loads(response)['ImageId'] print
# coding=utf-8 #!/usr/bin/env python from lib.aliyunsdkcore import client from lib.aliyunsdkecs.request.v20140526 import DescribeInstancesRequest import PropertiesUtils as p import json clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # 设置参数 request = DescribeInstancesRequest.DescribeInstancesRequest() request.set_accept_format('json') request.add_query_param('RegionId', p.regionId()) # 发起请求 response = clt.do_action(request) # 输出结果 # print json.dumps(json.loads(response), indent=2) totalCount = json.loads(response)['TotalCount'] for i in range(totalCount): try: print 'Eip: ' + json.loads( response)['Instances']['Instance'][i]['EipAddress']['IpAddress'] print 'PublicIp: ' + json.loads(response)['Instances']['Instance'][i][ 'PublicIpAddress']['IpAddress'][0] print 'Status: ' + json.loads(