Version 3 (modified by 10 years ago) (diff) | ,
---|
How to Instsall 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 how to install and configure geni-lib, and show some examples of using geni-lib. The installation and configuration of geni-lib has been tested on MacOS 10.9.3, and python27 installed from MacPort is set to be the default python.
To use geni-lib, you will first need to download it from the geni-lib repository.
Download geni-lib
For MacOS Experimenters:
- Install Mercurial
- If you are using MacPort, you can Install mercurial with
sudo port install mercurial
- You can also find the Mercurial download page here
- If you are using MacPort, you can Install mercurial with
- Configure Mercurial
- Create .hg file under ~/.
[ui] username = Your User Name <xxx@xxx.xxx>
- Create .hg file under ~/.
- Clone geni-lib
hg clone https://bitbucket.org/barnstorm/geni-lib
- Check and Pull Update
hg pull && hg update default
Once you have downloaded the geni-lib to your local machine, you will see two directories under ./geni-lib/
dhcp89-69-127:geni-lib xliu$ ls geni samples
The directory "geni" is the library for RSpec generation and other purposes, and "samples" contains examples of using the library, as well as a sample configuration file that you need to modify it before writing and testing your scripts.
Configure geni-lib
- Modify the configuration file
To use geni-lib, you will need to create a configuration file that contains your credential to GENI and other information about your experiments. Go to ./geni-lib/samples/, and open the file
dhcp89-69-127:samples xliu$ cat example_config.py from geni.aggregate import FrameworkRegistry from geni.aggregate.context import Context from geni.aggregate.user import User def buildContext (): portal = FrameworkRegistry.get("portal")() portal.cert = "/home/nbastin/.ssh/portal-nbastin.pem" portal.key = "/home/nbastin/.ssh/portal-nbastin.key" nbastin = User() nbastin.name = "nbastin" nbastin.urn = "urn:publicid:IDN+ch.geni.net+user+nickbas" nbastin.addKey("/home/nbastin/.ssh/geni_dsa.pub") context = Context() context.addUser(nbastin, default = True) context.cf = portal context.project = "bss-sw-test" return context
You will modify this module on from line 7 to line 13, line 16 and line 18 with your own information, and you may want to save it as a different file, for example, with name <your initial>_config.py
- Add PYTHONPATH
For MacOS experimenters, you can add following lines to the end of your ~/.profile
# add python path export PYTHONPATH=$PYTHONPATH:<your path to geni-lib>Then, run
source ~/.profile
- Install lxml python packages
If you are using MacPort, install lxml using
$ sudo port install python27-lxml
- Optional Steps for Configuration
Sometimes you may have problems with python versions if you have two different versions of python installed. If you installed python27 and python modules from MacPort, so you may need to select python27 installed by MacPort as your default python.
$ sudo port select --set python python27
Examples of Using geni-lib
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
Attachments (1)
- examples.py (4.1 KB) - added by 10 years ago.
Download all attachments as: .zip