updated demo1
This commit is contained in:
parent
5b953bb5ed
commit
f1f463314a
@ -1,34 +1,43 @@
|
|||||||
# Example for Cloud Computing Course Master AI / GSD
|
# Example for Cloud Computing Course Master AI / GSD
|
||||||
#
|
#
|
||||||
# based on the tutorial: https://developer.openstack.org/firstapp-libcloud/
|
|
||||||
# uses libCloud: https://libcloud.apache.org/
|
# uses libCloud: https://libcloud.apache.org/
|
||||||
# libCloud API documentation: https://libcloud.readthedocs.io/en/latest/
|
# libCloud API documentation: https://libcloud.readthedocs.io/en/latest/
|
||||||
# OpenStack API documentation: https://developer.openstack.org/
|
# OpenStack API documentation: https://developer.openstack.org/
|
||||||
|
# this code was initially based on the former tutorial: https://developer.openstack.org/firstapp-libcloud/
|
||||||
|
|
||||||
import getpass
|
import getpass
|
||||||
|
|
||||||
from libcloud.compute.providers import get_driver
|
from libcloud.compute.providers import get_driver
|
||||||
from libcloud.compute.types import Provider
|
from libcloud.compute.types import Provider
|
||||||
|
|
||||||
# Please use 1-25 for X in username, project etc., as coordinated in the lab sessions
|
# Please use 1-29 for X in the following variable to specify your group number. (will be used for the username,
|
||||||
|
# project etc., as coordinated in the lab sessions)
|
||||||
|
|
||||||
|
group_number = 30
|
||||||
|
|
||||||
|
########################################################################################################################
|
||||||
|
#
|
||||||
|
# no changes necessary below this line
|
||||||
|
#
|
||||||
|
########################################################################################################################
|
||||||
|
|
||||||
# web service endpoint of the private cloud infrastructure
|
# web service endpoint of the private cloud infrastructure
|
||||||
auth_url = 'https://private-cloud2.informatik.hs-fulda.de:5000'
|
auth_url = 'https://private-cloud.informatik.hs-fulda.de:5000'
|
||||||
# your username in OpenStack
|
# your username in OpenStack
|
||||||
auth_username = 'CloudCompX'
|
auth_username = 'CloudComp' + str(group_number)
|
||||||
# your project in OpenStack
|
# your project in OpenStack
|
||||||
project_name = 'CloudCompGrpX'
|
project_name = 'CloudComp' + str(group_number)
|
||||||
|
# A network in the project the started instance will be attached to
|
||||||
|
project_network = 'CloudComp' + str(group_number) + '-net'
|
||||||
|
|
||||||
|
# The image to look for and use for the started instance
|
||||||
|
ubuntu_image_name = "Ubuntu 18.04 - Bionic Beaver - 64-bit - Cloud Based Image"
|
||||||
|
|
||||||
# default region
|
# default region
|
||||||
region_name = 'RegionOne'
|
region_name = 'RegionOne'
|
||||||
# domain to use, "default" for local accounts, "hsfulda" for LDAP of DVZ, e.g., using fdaiXXXX as auth_username
|
# domain to use, "default" for local accounts, "hsfulda" for LDAP of DVZ, e.g., using fdaiXXXX as auth_username
|
||||||
domain_name = "default"
|
domain_name = "default"
|
||||||
|
|
||||||
# The image to look for and use for the started instance
|
|
||||||
ubuntu_image_name = "Ubuntu 14.04 - Trusty Tahr - 64-bit - Cloud Based Image"
|
|
||||||
# A network in the project the started instance will be attached to
|
|
||||||
project_network = "CloudCompGrpX-net"
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# get the password from user
|
# get the password from user
|
||||||
@ -39,6 +48,9 @@ def main():
|
|||||||
# make sure to include ex_domain_name and ex_force_auth_version='3.x_password', as they are needed in our
|
# make sure to include ex_domain_name and ex_force_auth_version='3.x_password', as they are needed in our
|
||||||
# environment
|
# environment
|
||||||
provider = get_driver(Provider.OPENSTACK)
|
provider = get_driver(Provider.OPENSTACK)
|
||||||
|
|
||||||
|
print("Opening connection to %s as %s..." % (auth_url, auth_username))
|
||||||
|
|
||||||
conn = provider(auth_username,
|
conn = provider(auth_username,
|
||||||
auth_password,
|
auth_password,
|
||||||
ex_force_auth_url=auth_url,
|
ex_force_auth_url=auth_url,
|
||||||
@ -47,6 +59,9 @@ def main():
|
|||||||
ex_force_service_region=region_name,
|
ex_force_service_region=region_name,
|
||||||
ex_domain_name=domain_name)
|
ex_domain_name=domain_name)
|
||||||
|
|
||||||
|
print("Getting images and selecting desired one...")
|
||||||
|
print("=========================================================================")
|
||||||
|
|
||||||
# get a list of images offered in the cloud context (e.g. Ubuntu 14.04, Ubuntu 16.04, cirros, ...)
|
# get a list of images offered in the cloud context (e.g. Ubuntu 14.04, Ubuntu 16.04, cirros, ...)
|
||||||
images = conn.list_images()
|
images = conn.list_images()
|
||||||
image = ''
|
image = ''
|
||||||
@ -55,16 +70,25 @@ def main():
|
|||||||
image = img
|
image = img
|
||||||
print(img)
|
print(img)
|
||||||
|
|
||||||
|
print("Getting flavors...")
|
||||||
|
print("=========================================================================")
|
||||||
|
|
||||||
# get a list of flavors offered in the cloud context (e.g. m1.small, m1.medium, ...)
|
# get a list of flavors offered in the cloud context (e.g. m1.small, m1.medium, ...)
|
||||||
flavors = conn.list_sizes()
|
flavors = conn.list_sizes()
|
||||||
for flavor in flavors:
|
for flavor in flavors:
|
||||||
print(flavor)
|
print(flavor)
|
||||||
|
|
||||||
|
print("Selecting desired flavor...")
|
||||||
|
print("=========================================================================")
|
||||||
|
|
||||||
# get the flavor with id 2
|
# get the flavor with id 2
|
||||||
flavor_id = '2'
|
flavor_id = '2'
|
||||||
flavor = conn.ex_get_size(flavor_id)
|
flavor = conn.ex_get_size(flavor_id)
|
||||||
print(flavor)
|
print(flavor)
|
||||||
|
|
||||||
|
print("Selecting desired network...")
|
||||||
|
print("=========================================================================")
|
||||||
|
|
||||||
# get a list of networks in the cloud context
|
# get a list of networks in the cloud context
|
||||||
networks = conn.ex_list_networks()
|
networks = conn.ex_list_networks()
|
||||||
network = ''
|
network = ''
|
||||||
@ -72,17 +96,26 @@ def main():
|
|||||||
if net.name == project_network:
|
if net.name == project_network:
|
||||||
network = net
|
network = net
|
||||||
|
|
||||||
|
print("Create instance 'testing'...")
|
||||||
|
print("=========================================================================")
|
||||||
|
|
||||||
# create a new instance with the name "testing"
|
# create a new instance with the name "testing"
|
||||||
# make sure to provide networks (networks={network}) the instance should be attached to
|
# make sure to provide networks (networks={network}) the instance should be attached to
|
||||||
instance_name = 'testing'
|
instance_name = 'testing'
|
||||||
testing_instance = conn.create_node(name=instance_name, image=image, size=flavor, networks={network})
|
testing_instance = conn.create_node(name=instance_name, image=image, size=flavor, networks={network})
|
||||||
print(testing_instance)
|
print(testing_instance)
|
||||||
|
|
||||||
|
print("Showing all running instances...")
|
||||||
|
print("=========================================================================")
|
||||||
|
|
||||||
# show all instances (running nodes) in the cloud context
|
# show all instances (running nodes) in the cloud context
|
||||||
instances = conn.list_nodes()
|
instances = conn.list_nodes()
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
print(instance)
|
print(instance)
|
||||||
|
|
||||||
|
print("Destroying instance...")
|
||||||
|
print("=========================================================================")
|
||||||
|
|
||||||
# destroy the instance we have just created
|
# destroy the instance we have just created
|
||||||
conn.destroy_node(testing_instance)
|
conn.destroy_node(testing_instance)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user