本文整理汇总了Python中MyRequestsClass.MyRequests.post方法的典型用法代码示例。如果您正苦于以下问题:Python MyRequests.post方法的具体用法?Python MyRequests.post怎么用?Python MyRequests.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyRequestsClass.MyRequests
的用法示例。
在下文中一共展示了MyRequests.post方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_machine
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
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
示例2: create_machine
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
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
示例3: stop_machine
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
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: start_machine
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
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
示例5: reboot_machine
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
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
示例6: generate_keypair
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
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
示例7: start_machine
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
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
示例8: start_machine
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
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
示例9: list_images
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
def list_images(uri, backend_id, search_term=None, cookie=None):
payload = {
'search_term': search_term
}
if not search_term:
req = MyRequests(uri=uri+"/backends/"+backend_id+"/images", cookie=cookie)
response = req.post()
else:
req = MyRequests(uri=uri+"/backends/"+backend_id+"/images", data=json.dumps(payload), 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
示例10: add_backend
# 需要导入模块: from MyRequestsClass import MyRequests [as 别名]
# 或者: from MyRequestsClass.MyRequests import post [as 别名]
def add_backend(uri, title, provider, apikey, apisecret, apiurl=None, tenant_name=None, cookie=None):
payload = {
'title': title,
'provider': provider,
'apikey': apikey,
'apisecret': apisecret,
'apiurl': apiurl,
'tenant_name': tenant_name
}
req = MyRequests(uri=uri+'/backends', data=json.dumps(payload), 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()
return params
except Exception as e:
assert False, u'Exception: %s' % e