Updating Servers: Changing Server Access Address Using Python

If you want to use Python to change server access IP addresses, you could start with the following script:

#!/usr/bin/python

import base64
import urllib
import httplib
import json
import os
from urlparse import urlparse

### --8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--
###
###  insert the 'Get OpenStack Credentials' snippet here
###
### --8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--

###
### Changing server name
###

# HTTP connection #2

imgID = 1               # server image ID
srvIPv4 = "192.168.100.2"       # server access IPv4
srvIPv6 = "fe80:0:0:0:0:0:c0a8:6402"    # server access IPv6
url2 = apiurlt[1]
params2 = urllib.urlencode(json.dumps({"server": {"accessIPv4": srvIPv4, "accessIPv6": srvIPv6}}))
headers2 = { "X-Auth-Token":apitoken, "Accept":"application/json", "Content-type":"application/json" }

if (usehttps == True):
    conn2 = httplib.HTTPSConnection(url2, key_file='../cert/priv.pem', cert_file='../cert/srv_test.crt')
else:
    conn2 = httplib.HTTPConnection(url2)

conn2.request("DELETE", "%s/servers/%s" % (apiurlt[2], imgID), params2, headers2)

# HTTP response #2

response2 = conn2.getresponse()
data2 = response2.read()
dd2 = json.loads(data2)

conn2.close()

print dd2


loading table of contents...