Last active
July 11, 2018 08:29
-
-
Save tonythomas01/e7cecc6c1aaa4d4ca221487659ef9f40 to your computer and use it in GitHub Desktop.
[OpenStack] Fetch IPv4 address of a new VM through OpenStack-Python API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment