March 15, 2017 04:21:28
Posted By Kepler Lam
|
In a customized OpenStack training, the client asked for an example of using the Python code to create an instance, here I want to share how to do it. Basically the script consists of the following steps:
Let me show you the code for each step. Import the python client library from novaclient import client Get the authentication information Create a dictionary variable and get the credential information from corresponding environment variables. def get_nova_creds(): Create a client object by passing the authentication parameters creds = get_nova_creds() Use the client object to perform different operations Once you create the Nova client object, you can use it to find out information (such as image, flavor etc.) that are required to launch a new instance. Following shows an example: image = nova.images.find(name="cirros-0.3.4-x86_64") Now you can use the client object to launch an new instance: server = nova.servers.create(name = "myinstance4",
|