Examples of Using geni-lib
geni-lib is a python library written by Nick Bastin of Barnstormer Softworks. It can be used to create RSpec file for large topology. In this page, we show some examples of using geni-lib. The installation and configuration of geni-lib can be found here
Assuming the module with your credential and project information is named as my_config.py, which is modified from example_config.py under ./geni-lib/samples, we will illustrate a few examples on how to use geni-lib.
- Create user context, you will need this for list resources, create slivers, etc.
import my_config context = my_config.buildContext()
- Get a list of InstaGENI aggregates or ExoGENI aggregates
import geni.aggregate.instageni as ig import geni.aggregate.exogeni as eg def get_am_sites(am_type): """ get a list of sites of a specific aggregate type ig: instageni eg: exogeni """ am_list = [] if am_type == 'ig': for idx, site in enumerate(ig.aggregates()): #print idx, site am_list.append(site) elif am_type == 'eg': for idx, site in enumerate(eg.aggregates()): am_list.append(site) return am_list
- Get Resource information for a specific aggregate (i.e. ig-Clemson), and print it into a file called "ig-clemson-ad.xml"
import geni.aggregate.instageni as ig def get_res(context, ig_site=ig.Clemson): '''Get resource of a ig site, and print to a file ''' try: ad = ig_site.listresources(context) f = open("%s-ad.xml" % (ig_site.name), "w+") f.write(ad.text) f.close() print "[%s] Done" % (ig_site.name) except: print "[%s] OFFLINE" % (ig_site.name)
- Create RSpec Object
import geni.rspec.pg as pg rspec = pg.Request()
- Create an Xen VM named "node1'"
vm = pg.XenVM("node1")
- Add interface "if0" to vm ("node1")
vm_iface = vm.addInterface("if0")
- Add custom disk image's URL to the vm ("node1")
vm.disk_image = <URL to the custom image>
- Add a Service to vm ("node1"), where service is shell script in a tarball file
vm.addService(pg.Install(url=<url to the tarball file>, path="/local"))
- Add a Execute Service to vm ("node1"), where the execute service is a command that is to be run at vm
vm.addService(pg.Execute(shell="bash", command="/bin/bash /local/<shell script>"))
- Add vm ("node1") to rspec object
rspec.addResource(vm)
- Create a LAN object, and add the interfaces (vm_iface1 and vm2_iface1) associated with this link
link = pg.LAN('lan0') link.addInterface(vm_iface1) link.addInterface(vm2_iface1) rspec.addResource(link)
- Write RSpec File
rspec.write("test.xml")
- Create Slivers, assuming you are using UtahDDC InstaGENI aggregate in the slice "myslice"
import geni.aggregate.instageni as ig manifest = ig.UtahDDC.createsliver(context, "myslice", rspec)
- Delete Slivers in slice "myslice"
import geni.aggregate.instageni as ig ig.Clemson.deletesliver(context, "myslice")
- Create EGRE Link Type
link = pg.L2GRE()
- Create Stitched Link Type
link = pg.StitchedLink()
You can find the complete examples in here
Last modified 10 years ago
Last modified on 07/25/14 13:12:13
Attachments (1)
- examples.py (4.1 KB) - added by 10 years ago.
Download all attachments as: .zip