Skip to content
Discussion options

You must be logged in to vote

Firstly, to create interfaces, you have to post to /api/virtualization/interfaces/ (note the trailing slash). And you need to POST not PATCH.

Secondly, data=str(interfaces) won't work. That will give you a Python string representation - in this case of a list of strings (which is also wrong). Use json=interfaces instead, and get rid of the json.dumps.

Something like this (untested):

interfaces = []
for vm in json_dict['results']:
    if vm['primary_ip'] is None:
        interfaces.append({
            "name": "veth0",
            "virtual_machine": vm['id']
        })

response = requests.post(headers=header,url=base_url+'/virtualization/interfaces/',verify=False,json=interfaces)
print(re…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Mailstorm-ctrl
Comment options

@candlerb
Comment options

@Mailstorm-ctrl
Comment options

Answer selected by Mailstorm-ctrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants