Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cloud-computing-msc-ai-examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Rieger
cloud-computing-msc-ai-examples
Commits
d8367991
Commit
d8367991
authored
Apr 16, 2018
by
Sebastian Rieger
Browse files
Options
Downloads
Patches
Plain Diff
changed image search for ubuntu image
parent
01937c66
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
demo1-getting-started.py
+36
-7
36 additions, 7 deletions
demo1-getting-started.py
with
36 additions
and
7 deletions
demo1-getting-started.py
+
36
−
7
View file @
d8367991
# Example for Cloud Computing Course Master AI / GSD
#
# based on the tutorial: https://developer.openstack.org/firstapp-libcloud/
# uses libCloud: https://libcloud.apache.org/
# libCloud API documentation: https://libcloud.readthedocs.io/en/latest/
# OpenStack API documentation: https://developer.openstack.org/
import
getpass
import
libcloud.security
from
libcloud.compute.providers
import
get_driver
from
libcloud.compute.types
import
Provider
auth_username
=
'
fdai109
'
# Please use 1-25 for X, as coordinated in the lab sessions
# web service endpoint of the private cloud infrastructure
auth_url
=
'
https://private-cloud2.informatik.hs-fulda.de:5000
'
project_name
=
'
ai-netlab-pro
'
# your username in OpenStack
auth_username
=
'
CloudCompX
'
# your project in OpenStack
project_name
=
'
CloudCompGrpX
'
# default region
region_name
=
'
RegionOne
'
domain_name
=
"
hsfulda
"
# domain to use, "default" for local accounts, "hsfulda" for LDAP of DVZ, e.g., using fdaiXXXX as auth_username
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
():
print
(
auth_username
)
# get the password from user
auth_password
=
getpass
.
getpass
(
"
Enter your OpenStack password:
"
)
#
libcloud.security.VERIFY_SSL_CERT = False
#
auth_password = "demo"
# instantiate a connection to the OpenStack private cloud
# make sure to include ex_domain_name and ex_force_auth_version='3.x_password', as they are needed in our
# environment
provider
=
get_driver
(
Provider
.
OPENSTACK
)
conn
=
provider
(
auth_username
,
auth_password
,
...
...
@@ -27,6 +47,7 @@ def main():
ex_force_service_region
=
region_name
,
ex_domain_name
=
domain_name
)
# get a list of images offered in the cloud context (e.g. Ubuntu 14.04, Ubuntu 16.04, cirros, ...)
images
=
conn
.
list_images
()
image
=
''
for
img
in
images
:
...
...
@@ -34,30 +55,38 @@ def main():
image
=
img
print
(
img
)
# get a list of flavors offered in the cloud context (e.g. m1.small, m1.medium, ...)
flavors
=
conn
.
list_sizes
()
for
flavor
in
flavors
:
print
(
flavor
)
# get the flavor with id 2
flavor_id
=
'
2
'
flavor
=
conn
.
ex_get_size
(
flavor_id
)
print
(
flavor
)
# get a list of networks in the cloud context
networks
=
conn
.
ex_list_networks
()
network
=
''
for
net
in
networks
:
if
net
.
name
==
"
ai-netlab-pro-net
"
:
if
net
.
name
==
project_network
:
network
=
net
# create a new instance with the name "testing"
# make sure to provide networks (networks={network}) the instance should be attached to
instance_name
=
'
testing
'
testing_instance
=
conn
.
create_node
(
name
=
instance_name
,
image
=
image
,
size
=
flavor
,
networks
=
{
network
})
print
(
testing_instance
)
# show all instances (running nodes) in the cloud context
instances
=
conn
.
list_nodes
()
for
instance
in
instances
:
print
(
instance
)
# destroy the instance we have just created
conn
.
destroy_node
(
testing_instance
)
# method that is called when the script is started from the command line
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment