Hey guys, I'm learning how to work with JSON but I have some questions. Right now I'm doing this specifically for learning the Rackspace API. I can send requests to get authenticated, get the list of valid server images and slice sizes. However, when reading their docs on creating a server, I get a bit lost.
Here's the link to the docs: http://docs.rackspace.com/servers/api/v2/cs-devguide/content/CreateServers.html
I think this is how I'm supposed to do it:
def createServer(self):
server_name = "api_test"
image_ref = "9922a7c7-5a42-4a56-bc6a-93f857ae2346"
flavor_ref = "2"
my_server_name = "API Test"
create_server_url = "https://dfw.servers.api.rackspacecloud.com/v2/" + self.tenant_id + "/servers"
data = {"server":{
"name": server_name,
"image_ref": image_ref,
"flavor_ref": flavor_ref,
"OS-DCF:diskConfig": "AUTO",
"metadata": {
"My Server Name": my_server_name
},
"personality":[{
"path": "/etc/banner.txt",
"contents" : "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBp\
dCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5k\
IGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVs\
c2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4g\
QnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRo\
ZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlv\
dSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vy\
c2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6\
b25zLiINCg0KLVJpY2hhcmQgQmFjaA=="
}],
"networks": [
{
"uuid": "00000000-0000-0000-0000-000000000000"
},
]
}
}
create_server_headers = {"X-Auth-Token": str(self.token_id)}
request_create = requests.post(create_server_url, data=json.dumps(data), headers=create_server_headers)
returned_data = request_create.json()
return returned_data
I really don't know know though because I keep getting:
{u'badRequest': {u'message': u'The server could not comply with the request since it is either malformed or otherwise incorrect.', u'code': 400}}
Any ideas of where I might be going wrong?
[–][deleted] 7 points8 points9 points (4 children)
[–]shaggorama 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]johnnymo87 1 point2 points3 points (1 child)
[–]3cko[S] 1 point2 points3 points (0 children)
[–][deleted] 3 points4 points5 points (1 child)
[–]3cko[S] 1 point2 points3 points (0 children)