63 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import getpass
 | 
						|
 | 
						|
import libcloud.security
 | 
						|
from libcloud.compute.providers import get_driver
 | 
						|
from libcloud.compute.types import Provider
 | 
						|
 | 
						|
auth_username = 'fdai109'
 | 
						|
auth_url = 'https://192.168.72.40:5000'
 | 
						|
project_name = 'ai-netlab-pro'
 | 
						|
region_name = 'RegionOne'
 | 
						|
domain_name = "hsfulda"
 | 
						|
 | 
						|
 | 
						|
def main():
 | 
						|
    print(auth_username)
 | 
						|
    auth_password = getpass.getpass("Enter your OpenStack password:")
 | 
						|
    libcloud.security.VERIFY_SSL_CERT = False
 | 
						|
 | 
						|
    provider = get_driver(Provider.OPENSTACK)
 | 
						|
    conn = provider(auth_username,
 | 
						|
                    auth_password,
 | 
						|
                    ex_force_auth_url=auth_url,
 | 
						|
                    ex_force_auth_version='3.x_password',
 | 
						|
                    ex_tenant_name=project_name,
 | 
						|
                    ex_force_service_region=region_name,
 | 
						|
                    ex_domain_name=domain_name)
 | 
						|
 | 
						|
    images = conn.list_images()
 | 
						|
    for image in images:
 | 
						|
        print(image)
 | 
						|
 | 
						|
    flavors = conn.list_sizes()
 | 
						|
    for flavor in flavors:
 | 
						|
        print(flavor)
 | 
						|
 | 
						|
    image_id = '95718fad-2b33-469c-a256-15888f461f66'
 | 
						|
    image = conn.get_image(image_id)
 | 
						|
    print(image)
 | 
						|
 | 
						|
    flavor_id = '2'
 | 
						|
    flavor = conn.ex_get_size(flavor_id)
 | 
						|
    print(flavor)
 | 
						|
 | 
						|
    networks = conn.ex_list_networks()
 | 
						|
    network = ''
 | 
						|
    for net in networks:
 | 
						|
        if net.name == "ai-netlab-pro-net":
 | 
						|
            network = net
 | 
						|
 | 
						|
    instance_name = 'testing'
 | 
						|
    testing_instance = conn.create_node(name=instance_name, image=image, size=flavor, networks={network})
 | 
						|
    print(testing_instance)
 | 
						|
 | 
						|
    instances = conn.list_nodes()
 | 
						|
    for instance in instances:
 | 
						|
        print(instance)
 | 
						|
 | 
						|
    conn.destroy_node(testing_instance)
 | 
						|
 | 
						|
 | 
						|
if __name__ == '__main__':
 | 
						|
    main()
 |