This notebook demostrates the use of the cloudbridge api to add files to buckes, list the available vm images, create networks and routers and how to create an instance. (The last step is not working completely. we will fix that one later.)
If you do not have cloudbridge installed uncomment the next line and run it.
#!pip install cloudbridge --upgrade
from cloudbridge.cloud.factory import CloudProviderFactory, ProviderList
you will want to log into the open stack portal for jetspeed to get you project name.
js_config = {"os_username": "your user name",
"os_password": "and password",
"os_auth_url": "https://jblb.jetstream-cloud.org:35357/v3",
"os_user_domain_name": "tacc",
"os_project_domain_name": "tacc",
"os_project_name": "your project (see the portal)"}
js = CloudProviderFactory().create_provider(ProviderList.OPENSTACK, js_config)
we now have a handle to jetspeed! let's look at a list of the public vm images.
js.compute.images.list()
the follow will list our current buckets and add a new one.
print js.object_store.list()
newbuck = js.object_store.create('my_new_bucket')
print(newbuck.name)
let's get a handle to another new bucket
bucket = js.object_store.create('my_new_bucket2')
print bucket
we can search for a bucket by name
buckes = js.object_store.find(name='my_new_bucket2')
buckes
Now lets's add some stuff to a blob we will call 'stuff'
buckobj = buckes[0].create_object('stuff')
now we upload a tiny file called 'stuf' it contains 2 lines
here is a file of stuff
fo = open('c:\users\dennis\documents\stuff.txt','rb')
buckobj.upload(fo)
js.object_store.list()
buckes[0].list()
stuff = buckes[0].get('stuff')
itr = stuff.iter_content()
for it in itr:
print it
now let's see if we can start up an image. This has a bug so it doesn't work, but this shows what is supposed to work. We will update when the bug is fixed.
img = js.compute.images.get('9e04c7e2-8527-4355-870a-ce825dbdcf8d')
img
inst_type = sorted([t for t in js.compute.instance_types.list()
if t.vcpus >= 4 and t.ram >= 8],
key=lambda x: x.vcpus*x.ram)[0]
inst_type
the following is how to create a key-pair. if it already exists you can grab it with the find() function.
#kp = js.security.key_pairs.create('cloudbridge_sec')
#with open('cloudbridge_sec.pem', 'w') as f:
# f.write(kp.material)
#import os
#os.chmod('cloudbridge_sec.pem', 0400)
kp = js.security.key_pairs.find(name='cloudbridge_sec')
kp
sg = js.security.security_groups.list()[0]
sg
netlist = js.network.list()
netlist
net = js.network.get('4d7cc5c5-1be2-4af3-a208-63a4cd538903')
net
net = js.network.create('scicloud2')
sn = net.create_subnet('10.0.0.0/28', 'scicloud2')
router = js.network.create_router('scicloud2')
if not net.external:
for n in js.network.list():
if n.external:
external_net = n
break
router.attach_network(external_net.id)
router.add_route(sn.id)
oops! the following doesn't work.
#inst = js.compute.instances.create(
# name='scicloud-VM', image=img, instance_type=inst_type,
# key_pair=kp, security_groups=[sg], network=net)