########################################################################### # CLOUD SERVER API DOCUMENTATION # # Name: createServer # Language: Python # # Description: this function creates a new server ########################################################################### from urllib.request import Request, urlopen import urllib import json #ID access to API TOKEN = "{YOUR_API_TOKEN}" # e.g.: "f03c3c76cc853ee690b879909c9c6f2a" url = "https://cloudpanel-api.1and1.com/v1" def _createServer(content): #Configure the request _command = url + "/servers" _method = 'POST' request = Request(_command, data=content.encode(encoding='utf_8'), headers={'X-TOKEN':TOKEN, 'content-type':'application/json'}, method=_method) #Try to get the response try: response = urlopen(request) content = response.read() return (content.decode()) #Fetch error except urllib.error.URLError as e: return("Error " + str(e.code) + ":" + e.reason) #PARAMETERS name = 'My server' description = 'My server description' appliance_id = "{YOUR_APPLIANCE_ID}" # e.g.: "5340033E7FBBC308BC329414A0DF3C20" #Hardware resources vcore = 1 cores_per_processor = 1 ram = 2 hdds = [{'size':40, 'is_main':True},{'size':20, 'is_main':False}] hardware = {'vcore':vcore, 'cores_per_processor':cores_per_processor, 'ram':ram, 'hdds':hdds} data = json.dumps({'name':name, 'description':description, 'hardware':hardware, 'appliance_id':appliance_id}) #Create server print(_createServer(data))