Recently came across this scenario:
- I create a VM with
conn.compute.create_server(*args)
and have the server object. The server is allocated an IP over `DHCP` - I want the IPv4 address of the machine.
Seems tough ? Finally found this one:
from openstack import connection conn = connection.Connection( auth_url=configs['auth']['OS_AUTH_URL'], project_name=configs['auth']['OS_PROJECT_NAME'], username=configs['auth']['OS_USERNAME'], password=configs['auth']['OS_PASSWORD'], project_domain_name=configs['auth']['OS_PROJECT_DOMAIN_NAME'], user_domain_name=configs['auth']['OS_USER_DOMAIN_NAME'] ) # Define network, security_groups_list, user_data_file_opened # An example network config is given below network = { "name": "personal_network", "security_group":"open", "subnet": { "name": "personal_network_subnet", "ip_version": "4", "cidr": "10.10.60.0/24", "dns_servers":["8.8.8.8","8.8.8.4"], "gateway_ip": "10.10.60.1" } } network_ = [x for x in conn.network.networks(name=network['name'])][0] node = conn.compute.create_server( name=server_name, image_id=image.id, flavor_id=flavor.id, networks=[{"uuid": network_.id}], key_name=keypair.name, security_groups=security_groups_list, user_data=user_data_file_opened ) node_ = conn.compute.wait_for_server(node, wait=360) node_ip = conn.compute.get_server(node.id).to_dict()['addresses'][network['name']][0]['addr'] print(f'New node ip is {node_ip}')
I have pasted the gist here, https://gist.github.com/tonythomas01/e7cecc6c1aaa4d4ca221487659ef9f40
Tell me how it goes, good luck.