def signin(user, name): try: # global api #定义一个全局变量 try: user_in = models.CloudUser.objects.get( Q(user__username=user.username), Q(datecenter__name=name)) except: return 'err' # print user_in.datecenter # print uer_in.datecenter if user_in and user_in.api_key and user_in.secretkey: url = user_in.datecenter.url api_key = user_in.api_key secretkey = user_in.secretkey # print url # print user_in.api_key # print user_in.secretkey api = cloudstackapi.CloudStackAPI(url.encode('utf-8'), api_key.encode('utf-8'), secretkey.encode('utf-8')) # print api if api: return api else: return 'err' else: return 'err' except: print traceback.format_exc() return 'err'
def signin(user): try: global api #定义一个全局变量 user_in = models.AuthUser.objects.get(user__username=user.username) api = cloudstackapi.CloudStackAPI("http://172.16.105.230:8080/client/api",user_in.api_key,user_in.secretkey) request = {'install':'True'} result = api.listVirtualMachines(request) print result['virtualmachine'] return 'ok' except: return 'err'
def test(): try: global api #定义一个全局变量 api_key = 'zWwNIDGCAYkJLpeO_XIPPP7bBbInZz9uhdTNYc0s9pLQLmy4qD41mr7mhEa6BzF-DuYwDHwARfoAfkHZNHsvDA' secretkey = '1JekGnijShz8cFO7IsZHg0JrABRlXpoG4XvNzhb9GX-E4unGgXFc7OEamifRf_lXj-GiEaEHFWjBAmiU6p81XA' api = cloudstackapi.CloudStackAPI("http://172.16.105.230:8080/client/api",api_key,secretkey) request = {'install':'True'} result = api.listVirtualMachines(request) print result['virtualmachine'] return 'ok' except: return 'err'