code tao vps

 avatar
user_8607526207
python
2 years ago
1.3 kB
7
Indexable
import requests
api = "3LQH7PQ2LATEMYY6UVWF63LLNQE7YF5LZAWQ"
url_instance = "https://api.vultr.com/v2/instances"
url_plan = "https://api.vultr.com/v2/plans"
url_snap = "https://api.vultr.com/v2/snapshots"
headers = {"Authorization": "Bearer {}".format(api),"Content-Type": "application/json"}
data = {
"region":"ewr",
"plan":"vc2-1c-1gb",
"label":"Tao tu server",
"os_id":"387"
}
#response = requests.post(url,json=data,headers=headers)
reponse = requests.get(url_plan,json=data,headers=headers)
nhanto  =reponse.json()
#print(type(nhanto['plans']))
'''
for curlist in nhanto['plans']:
	print(curlist['id'])
'''
#rams = list(map(lambda x: x["ram"], nhanto))
#print(rams)
reponse_snap = requests.get(url_snap,json = data,headers = headers)
#print(reponse_snap.json()['snapshots'])
#print(type(reponse_snap.json()['snapshots']))
list_snap = reponse_snap.json()['snapshots']
def WriteFile(path,value):
	f = open(path,'w')
	f.write(value)
def ReadFile(path,value):
	f= open(path,'r')
	return f.readlines()
path = "snapshot.txt"
'''
for cur_snap in list_snap:
	WriteFile(path,cur_snap["id"])
'''
reponse_instane = requests.get(url_instance,json =data, headers=headers)

print(reponse_instane.json()['instances'])




Editor is loading...