Version 9 (modified by, 10 years ago) (diff)


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, which is modified from 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
        elif am_type == 'eg':
            for idx, site in enumerate(eg.aggregates()):
        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 '''
            ad = ig_site.listresources(context)
            f = open("%s-ad.xml" % (, "w+")
            print "[%s] Done" % (
            print "[%s] OFFLINE" % (
  • Create RSpec Object
    import 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
  • Create a LAN object, and add the interfaces (vm_iface1 and vm2_iface1) associated with this link
    link = pg.LAN('lan0')
  • Write RSpec File
  • 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)

Download all attachments as: .zip