本文整理汇总了Python中MyRequestsClass.MyRequests类的典型用法代码示例。如果您正苦于以下问题:Python MyRequests类的具体用法?Python MyRequests怎么用?Python MyRequests使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MyRequests类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_machine
def create_machine(uri, backend_id, key_id, name, location, image, size,
script=None, disk=None, image_extra=None, cookie=None,
csrf=None):
payload = {
#'backend': backend_id,
'key': key_id,
'name': name,
'location': location,
'image': image,
'size': size,
'script': script,
'disk': disk,
'image_extra': image_extra
}
req = MyRequests(uri=uri+"/backends/"+backend_id+"/machines",
cookie=cookie, data=json.dumps(payload), timeout=600,
csrf=csrf)
response = req.post()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
try:
params = response.json()
print "Created machine with Name: %s and id %s a" % (params['name'], params['id'])
return params
except Exception as e:
assert False, u'Exception: %s' % e
示例2: create_machine
def create_machine(
uri, cloud_id, key_id, name, location, image, size, script=None, disk=None, image_extra=None, cookie=None, csrf=None
):
payload = {
#'cloud': cloud_id,
"key": key_id,
"name": name,
"location": location,
"image": image,
"size": size,
"script": script,
"disk": disk,
"image_extra": image_extra,
}
req = MyRequests(
uri=uri + "/clouds/" + cloud_id + "/machines", cookie=cookie, data=json.dumps(payload), timeout=600, csrf=csrf
)
response = req.post()
assert response.ok, u"\nGot %d Response Status: %s \n%s" % (response.status_code, response.reason, response.text)
try:
params = response.json()
print "Created machine with Name: %s and id %s a" % (params["name"], params["id"])
return params
except Exception as e:
assert False, u"Exception: %s" % e
示例3: stop_machine
def stop_machine(uri, cloud_id, machine_id, cookie=None, csrf=None):
payload = {"action": "stop"}
req = MyRequests(
uri=uri + "/clouds/" + cloud_id + "/machines/" + machine_id, data=json.dumps(payload), cookie=cookie, csrf=csrf
)
response = req.post()
assert response.ok, u"\nGot %d Response Status: %s \n%s" % (response.status_code, response.reason, response.text)
print "Stopped machine with id: %s" % machine_id
示例4: edit_key
def edit_key(uri, key_id, new_name, cookie=None):
payload = {
'key':key_id,
'newName': new_name
}
req = MyRequests(uri=uri+"/keys/" + key_id, data=json.dumps(payload), cookie=cookie)
response = req.put()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
示例5: start_machine
def start_machine(uri, backend_id, machine_id, cookie=None):
payload = {
'action':'start'
}
req = MyRequests(uri=uri+"/backends/"+backend_id+"/machines/"+machine_id, data=payload, cookie=cookie)
response = req.post()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
print "Started machine with id: %s" % machine_id
示例6: list_machines
def list_machines(uri, cloud_id, cookie=None, csrf=None):
req = MyRequests(uri=uri + "/clouds/" + cloud_id + "/machines", cookie=cookie, csrf=csrf)
response = req.get()
assert response.ok, u"\nGot %d Response Status: %s \n%s" % (response.status_code, response.reason, response.text)
try:
params = response.json()
return params
except Exception as e:
assert False, u"Exception: %s" % e
示例7: list_machines
def list_machines(uri, backend_id, cookie=None):
req = MyRequests(uri=uri+'/backends/'+backend_id+"/machines", cookie=cookie)
response = req.get()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
try:
params = response.json()
return params
except Exception as e:
assert False, u'Exception: %s' % e
示例8: reboot_machine
def reboot_machine(uri, backend_id, machine_id, cookie=None, csrf=None):
payload = {
'action': 'reboot'
}
req = MyRequests(uri=uri+"/backends/"+backend_id+"/machines/"+machine_id,
cookie=cookie, data=json.dumps(payload), csrf=csrf)
response = req.post()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
print "Rebooted machine with id: %s" % machine_id
示例9: rename_cloud
def rename_cloud(uri, cloud_id, new_name, cookie=None, csrf=None):
payload = {
'new_name': new_name
}
req = MyRequests(uri=uri+"/clouds/"+cloud_id, data=json.dumps(payload),
cookie=cookie, csrf=csrf)
response = req.put()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
示例10: list_clouds
def list_clouds(uri, cookie=None, csrf=None):
req = MyRequests(uri=uri + '/clouds', cookie=cookie, csrf=csrf)
response = req.get()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
try:
params = response.json()
return params
except Exception as e:
assert False, u'Exception: %s' %e
示例11: get_public_key
def get_public_key(uri, key_id, cookie=None):
req = MyRequests(uri=uri+"/keys/"+key_id+"?action=public", cookie=cookie)
response = req.get()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
try:
params = response.json()
return params
except Exception as e:
print response.text
assert False, u'Exception: %s' %e
示例12: delete_key
def delete_key(uri, key_id, cookie=None):
req = MyRequests(uri=uri+"/keys/"+key_id, cookie=cookie)
response = req.delete()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
try:
params = response.json()
print "Deleted Key: %s" % key_id
return params
except Exception as e:
assert False, u'Exception: %s' %e
示例13: generate_keypair
def generate_keypair(uri, cookie=None):
req = MyRequests(uri=uri+"/keys", cookie=cookie)
response = req.post()
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
try:
params = response.json()
print params
return params
except Exception as e:
assert False, u'Exception: %s' %e
示例14: start_machine
def start_machine(uri, backend_id, machine_id, cookie=None):
sleep(30)
payload = {
'action': 'start'
}
req = MyRequests(uri=uri+"/backends/"+backend_id+"/machines/"+machine_id, data=payload, cookie=cookie)
response = req.post()
if response.status_code == 503:
print "Machine state is not yet ready to be started"
return
assert response.ok, u'\nGot %d Response Status: %s \n%s' % (response.status_code, response.reason, response.text)
print "Started machine with id: %s" % machine_id
示例15: start_machine
def start_machine(uri, cloud_id, machine_id, cookie=None, csrf=None):
sleep(30)
payload = {"action": "start"}
req = MyRequests(
uri=uri + "/clouds/" + cloud_id + "/machines/" + machine_id, data=json.dumps(payload), cookie=cookie, csrf=csrf
)
response = req.post()
if response.status_code == 503:
print "Machine state is not yet ready to be started"
return
assert response.ok, u"\nGot %d Response Status: %s \n%s" % (response.status_code, response.reason, response.text)
print "Started machine with id: %s" % machine_id