Changes between Initial Version and Version 1 of HowTo/GenerateRSpecUsingGENILIB


Ignore:
Timestamp:
07/16/14 15:39:01 (7 years ago)
Author:
xliu@bbn.com
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowTo/GenerateRSpecUsingGENILIB

    v1 v1  
     1[[PageOutline]]
     2
     3= How to Instsall geni-lib =
     4
     5geni-lib is a python library that can be used to create RSpec file for large topology. To use geni-lib, you will first need to download it from the [https://bitbucket.org/barnstorm/geni-lib/src geni-lib repository].
     6
     7
     8 
     9== Download geni-lib ==
     10
     11For MacOS Experimenters:
     12
     13 * Install Mercurial
     14   * If you are using !MacPort, you can Install mercurial with
     15{{{
     16sudo port install mercurial
     17}}}
     18   * You can also find the Mercurial download page [http://mercurial.selenic.com/downloads here]
     19
     20 * Configure Mercurial
     21   * Create .hg file under ~/.
     22{{{
     23[ui]
     24username = Your User Name <xxx@xxx.xxx>
     25}}}
     26
     27 * Clone geni-lib
     28{{{
     29hg clone https://bitbucket.org/barnstorm/geni-lib
     30}}}
     31
     32 * Check and Pull Update
     33{{{
     34hg pull && hg update default
     35}}}
     36
     37
     38
     39Once you have downloaded the geni-lib to your local machine, you will see two directories under ./geni-lib/
     40{{{
     41dhcp89-69-127:geni-lib xliu$ ls
     42geni    samples
     43}}}
     44
     45The 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.
     46
     47== Configure geni-lib ==
     48
     49 * Modify the configuration file
     50
     51 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
     52
     53 {{{
     54dhcp89-69-127:samples xliu$ cat example_config.py
     55from geni.aggregate import FrameworkRegistry
     56from geni.aggregate.context import Context
     57from geni.aggregate.user import User
     58
     59def buildContext ():
     60  portal = FrameworkRegistry.get("portal")()
     61  portal.cert = "/home/nbastin/.ssh/portal-nbastin.pem"
     62  portal.key = "/home/nbastin/.ssh/portal-nbastin.key"
     63
     64  nbastin = User()
     65  nbastin.name = "nbastin"
     66  nbastin.urn = "urn:publicid:IDN+ch.geni.net+user+nickbas"
     67  nbastin.addKey("/home/nbastin/.ssh/geni_dsa.pub")
     68
     69  context = Context()
     70  context.addUser(nbastin, default = True)
     71  context.cf = portal
     72  context.project = "bss-sw-test"
     73
     74  return context
     75 }}}
     76
     77 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
     78
     79
     80 * Add PYTHONPATH
     81 
     82 For MacOS experimenters, you can add following lines to the end of your ~/.profile
     83 {{{
     84 # add python path
     85 export PYTHONPATH=$PYTHONPATH:<your path to geni-lib>
     86 }}}
     87 Then, run
     88 {{{
     89 source ~/.profile
     90 }}}
     91
     92 * Install lxml python packages
     93 
     94 If you are using !MacPort, install lxml using
     95 {{{
     96 $ sudo port install python27-lxml
     97 }}}
     98
     99 * Optional Steps for Configuration
     100 
     101 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.
     102{{{
     103$ sudo port select --set python python27
     104}}}
     105
     106
     107= Examples of Using geni-lib =
     108 
     109 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.
     110
     111 * Create user context, you will need this for list resources, create slivers, etc.
     112{{{
     113import my_config
     114context = my_config.buildContext()
     115}}}
     116 
     117 * Get a list of InstaGENI aggregates or ExoGENI aggregates
     118{{{
     119import geni.aggregate.instageni as ig
     120import geni.aggregate.exogeni as eg
     121
     122def get_am_sites(am_type):
     123    """
     124    get a list of sites of a specific aggregate type
     125    ig: instageni
     126    eg: exogeni
     127    """
     128    am_list = []
     129    if am_type == 'ig':
     130        for idx, site in enumerate(ig.aggregates()):
     131            #print idx, site
     132            am_list.append(site)
     133    elif am_type == 'eg':
     134        for idx, site in enumerate(eg.aggregates()):
     135            am_list.append(site)
     136    return am_list
     137}}}
     138
     139 * Get Resource information for a specific aggregate (i.e. ig-Clemson), and print it into a file called "ig-clemson-ad.xml"
     140{{{
     141import geni.aggregate.instageni as ig
     142
     143def get_res(context, ig_site=ig.Clemson):
     144    '''Get resource of a ig site, and print to a file '''
     145    try:
     146        ad = ig_site.listresources(context)
     147        f = open("%s-ad.xml" % (ig_site.name), "w+")
     148        f.write(ad.text)
     149        f.close()
     150        print "[%s] Done" % (ig_site.name)
     151    except:
     152        print "[%s] OFFLINE" % (ig_site.name)
     153}}}
     154
     155
     156
     157 * Create RSpec Object
     158{{{
     159import geni.rspec.pg as pg
     160rspec = pg.Request()
     161}}}
     162
     163 * Create an Xen VM named "node1'"
     164{{{
     165vm = pg.XenVM("node1")
     166}}}
     167
     168 * Add interface "if0" to ''vm'' ("node1")
     169{{{
     170vm_iface = vm.addInterface("if0")
     171}}}
     172
     173 * Add custom disk image's URL to the ''vm'' ("node1")
     174{{{
     175vm.disk_image = <URL to the custom image>
     176}}}
     177
     178 * Add a Service to ''vm'' ("node1"), where service is shell script in a tarball file
     179{{{
     180vm.addService(pg.Install(url=<url to the tarball file>, path="/local"))
     181}}}
     182
     183 * Add a Execute Service to  ''vm'' ("node1"), where the execute service is a command that is to be run at ''vm''
     184{{{
     185vm.addService(pg.Execute(shell="bash", command="/bin/bash /local/<shell script>"))
     186}}}
     187
     188
     189 * Add ''vm'' ("node1") to rspec object
     190{{{
     191rspec.addResource(vm)
     192}}}
     193
     194 * Create a LAN object, and add the interfaces (vm_iface1 and vm2_iface1) associated with this link
     195{{{
     196link = pg.LAN('lan0')
     197link.addInterface(vm_iface1)
     198link.addInterface(vm2_iface1)
     199rspec.addResource(link)
     200}}}
     201
     202 * Write RSpec File
     203{{{
     204rspec.write("test.xml")
     205}}}
     206
     207 * Create Slivers, assuming you are using UtahDDC InstaGENI aggregate in the slice "myslice"
     208{{{
     209import geni.aggregate.instageni as ig
     210manifest = ig.UtahDDC.createsliver(context, "myslice", rspec)
     211}}}
     212
     213
     214 * Delete Slivers in slice "myslice"
     215{{{
     216import geni.aggregate.instageni as ig
     217ig.Clemson.deletesliver(context, "myslice")
     218}}}
     219
     220
     221 * Create EGRE Link Type
     222{{{
     223link = pg.L2GRE()
     224}}}
     225
     226 * Create Stitched Link Type
     227{{{
     228link = pg.StitchedLink()
     229}}}
     230
     231 
     232You can find the complete examples in [http://groups.geni.net/syseng/attachment/wiki/XLiuSandbox/HowToGenerateRSpecUsingGeniLib/helloworld.py here]