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()) # 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 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 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 aliyunsdkcore import client from aliyunsdkecs.request.v20140526 import AssociateEipAddressRequest import PropertiesUtils as p import json clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # 设置参数 request = AssociateEipAddressRequest.AssociateEipAddressRequest() request.set_accept_format('json') request.add_query_param('InstanceId', p.instanceId()) request.add_query_param('AllocationId', p.allocationId()) # 发起请求 response = clt.do_action(request) # 输出结果 print json.dumps(json.loads(response), indent=2)
#coding=utf-8 #!/usr/bin/env python from aliyunsdkcore import client from aliyunsdkecs.request.v20140526 import AttachKeyPairRequest import PropertiesUtils as p import json clt = client.AcsClient(p.accessKeyId(), p.accessSecret(), p.regionId()) # 奇怪的type转换,[]里面只能是str,不能是unicode string = p.instanceId().encode('utf-8') instanceId = [string] # 设置参数 request = AttachKeyPairRequest.AttachKeyPairRequest() request.set_accept_format('json') request.add_query_param('RegionId', p.regionId()) request.add_query_param('KeyPairName', p.keyPairName()) request.add_query_param('InstanceIds', instanceId) # 发起请求 response = clt.do_action(request) # 输出结果 print json.dumps(json.loads(response), indent=2)