Ignore:
Timestamp:
May 18, 2010 12:25:25 PM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
f1550c8
Parents:
85bba36
Message:

Totally refactor fedd_client.py into component scripts. The previous layout
have become a twisty hell of misdirected OOP and learning python run amok.
This version is actually pretty readable and will be much easier to build on.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd_client.py

    r85bba36 rd743d60  
    8282        self.add_option("--trace", action="store_const", dest="tracefile",
    8383                const=sys.stderr, help="Print SOAP exchange to stderr")
    84 class fedd_new_opts(fedd_client_opts):
     84
     85class fedd_access_opts(fedd_client_opts):
    8586    def __init__(self):
    8687        fedd_client_opts.__init__(self)
     
    8990        self.add_option("--experiment_name", dest="exp_name",
    9091                type="string", help="Suggested experiment name")
    91 
    92 class fedd_create_opts(fedd_new_opts):
    93     def __init__(self):
    94         fedd_new_opts.__init__(self)
     92        self.add_option("--label", action="store", dest="label",
     93                type="string", help="Label for output")
     94        # Access has been busted for a while.
     95        #if add_node_callback:
     96        #    self.add_option("--node", action="callback", type="string",
     97        #            callback=add_node_callback, callback_args=(node_descs,),
     98        #            help="Node description: image:hardware[:count]")
     99        self.add_option("--testbed", action="store", dest="testbed",
     100                type="string",
     101                help="Testbed identifier (URI) to contact (required)")
    95102        self.add_option("--file", dest="file",
    96103                help="experiment description file")
     
    104111                help="Service description name:exporters:importers:attrs")
    105112
    106 class fedd_split_opts(fedd_create_opts):
    107     def __init__(self ):
    108         fedd_create_opts.__init__(self)
    109         self.add_option('--fedkit', action='store_true', dest='fedkit',
    110                 default=False,
    111                 help="get output suitable for federation kit install")
    112         self.add_option('--gatewaykit', action='store_true',
    113                 dest='gatewaykit', default=False,
    114                 help="get output suitable for federation gateway kit install")
    115 
    116 
    117 class fedd_access_opts(fedd_create_opts):
    118     def __init__(self):
    119         fedd_create_opts.__init__(self)
    120         self.add_option("--label", action="store", dest="label",
    121                 type="string", help="Label for output")
    122         if add_node_callback:
    123             self.add_option("--node", action="callback", type="string",
    124                     callback=add_node_callback, callback_args=(node_descs,),
    125                     help="Node description: image:hardware[:count]")
    126         self.add_option("--testbed", action="store", dest="testbed",
    127                 type="string",
    128                 help="Testbed identifier (URI) to contact (required)")
    129 
    130 class fedd_exp_data_opts(fedd_client_opts):
     113class fedd_terminate_opts(fedd_client_opts):
    131114    def __init__(self):
    132115        fedd_client_opts.__init__(self)
     116        self.add_option("--force", dest="force",
     117                action="store_true", default=False,
     118                help="Force termination if experiment is in strange state")
     119        self.add_option("--logfile", dest="logfile", default=None,
     120                help="File to write log to")
     121        self.add_option("--print_log", dest="print_log", default=False,
     122                action="store_true",
     123                help="Print deallocation log to standard output")
    133124        self.add_option("--experiment_cert", dest="exp_certfile",
    134125                type="string", help="experiment certificate file")
     
    141132                help="data to extract")
    142133
    143 class fedd_terminate_opts(fedd_exp_data_opts):
    144     def __init__(self):
    145         fedd_exp_data_opts.__init__(self)
    146         self.add_option("--force", dest="force",
    147                 action="store_true", default=False,
    148                 help="Force termination if experiment is in strange state")
    149         self.add_option("--logfile", dest="logfile", default=None,
    150                 help="File to write log to")
    151         self.add_option("--print_log", dest="print_log", default=False,
    152                 action="store_true",
    153                 help="Print deallocation log to standard output")
    154 
    155 class fedd_multi_exp_data_opts(fedd_client_opts):
    156     def __init__(self):
    157         fedd_client_opts.__init__(self)
    158         self.add_option("--data", dest="data", default=[],
    159                 action="append", type="choice",
    160                 choices=("id", "federant", "vtopo", "vis", "log", "status"),
    161                 help="data to extract")
    162 
    163 class fedd_spew_opts(fedd_client_opts):
    164     def __init__(self):
    165         fedd_client_opts.__init__(self)
    166         self.add_option("--experiment_cert", dest="exp_certfile",
    167                 type="string", help="experiment name certificate file")
    168         self.add_option("--experiment_name", dest="exp_name",
    169                 type="string", help="human readable experiment name")
    170         self.add_option("--logfile", dest="logfile", default=None,
    171                 help="File to write log to")
    172         self.add_option('--update_time', dest='update', type='int', default=10,
    173                 help='how often to update the printed log')
    174 
    175 class fedd_image_opts(fedd_exp_data_opts):
    176     def __init__(self):
    177         fedd_exp_data_opts.__init__(self)
    178         self.add_option("--output", dest="outfile", type="string",
    179                 help="output image file")
    180         self.add_option("--format", dest="format", type="choice",
    181                 choices=("jpg", "png", "dot", "svg"),
    182                 help="Output file format override")
    183         self.add_option("--program", dest="neato", default=None,
    184                 type="string",
    185                 help="Program compatible with dot (from graphviz) used to " + \
    186                         "render image")
    187         self.add_option("--labels", dest='labels', action='store_true',
    188                 default=True, help='Label nodes and edges')
    189         self.add_option("--no_labels", dest='labels',
    190                 default=True, action='store_false',
    191                 help='Label nodes and edges')
    192         self.add_option('--pixels', dest="pixels", default=None,
    193                 type="int",
    194                 help="Size of output in pixels (diagrams are square")
    195 
    196 class fedd_ns_image_opts(fedd_split_opts):
    197     def __init__(self):
    198         fedd_split_opts.__init__(self)
    199         self.add_option("--output", dest="outfile", type="string",
    200                 help="output image file")
    201         self.add_option("--format", dest="format", type="choice",
    202                 choices=("jpg", "png", "dot", "svg"),
    203                 help="Output file format override")
    204         self.add_option("--program", dest="neato", default=None,
    205                 type="string",
    206                 help="Program compatible with dot (from graphviz) used to " + \
    207                         "render image")
    208         self.add_option("--labels", dest='labels', action='store_true',
    209                 default=True, help='Label nodes and edges')
    210         self.add_option("--no_labels", dest='labels',
    211                 default=True, action='store_false',
    212                 help='Label nodes and edges')
    213         self.add_option('--pixels', dest="pixels", default=None,
    214                 type="int",
    215                 help="Size of output in pixels (diagrams are square")
    216 
    217134class fedd_start_opts(fedd_client_opts):
    218135    def __init__(self):
     
    221138                help="experiment description file")
    222139
    223 class fedd_ns_topdl_opts(fedd_client_opts):
    224     def __init__(self):
    225         fedd_client_opts.__init__(self)
    226         self.add_option("--file", dest="file",
    227                 help="experiment description file")
    228         self.add_option("--output", dest="outfile", type="string",
    229                 help="output topdl file")
    230140
    231141def exit_with_fault(dict, out=sys.stderr):
     
    247157    print>>out, "Description: %s" % dict['desc']
    248158    sys.exit(dict.get('code', 20))
     159
    249160# Base class for the various client operations.  It includes some commonly used
    250161# functions and classes the most important of which are the exception classes
     
    362273            raise RuntimeError("No body in response??")
    363274
    364 class exp_data_base(fedd_rpc):
    365     def __init__(self):
    366         """
    367         Init the various conversions
    368         """
    369 
    370         fedd_rpc.__init__(self)
    371         # List of things one could ask for and what formatting routine is
    372         # called.
    373         self.params = {
    374                 'vis': ('vis', self.print_vis_or_vtopo('vis')),
    375                 'vtopo': ('vtopo', self.print_vis_or_vtopo('vtopo')),
    376                 'federant': ('federant', self.print_xml),
    377                 'experimentdescription': \
    378                         ('experimentdescription', self.print_xml),
    379                 'id': ('experimentID', self.print_id),
    380                 'status': ('experimentStatus', self.print_string),
    381                 'log': ('allocationLog', self.print_string),
    382                 'access': ('experimentAccess', self.print_string),
    383             }
    384 
    385     # Utility functions
    386     def print_string(self, d, out=sys.stdout):
    387         print >>out, d
    388 
    389     def print_id(self, d, out=sys.stdout):
    390         if d:
    391             for id in d:
    392                 for k in id.keys():
    393                     print >>out, "%s: %s" % (k, id[k])
    394 
    395     def print_xml(self, d, out=sys.stdout):
    396         """
    397         Very simple ugly xml formatter of the kinds of dicts that come back
    398         from services.
    399         """
    400         if isinstance(d, dict):
    401             for k, v in d.items():
    402                 print >>out, "<%s>" % k
    403                 self.print_xml(v, out)
    404                 print >>out, "</%s>" % k
    405         elif isinstance(d, list):
    406             for x in d:
    407                 self.print_xml(x, out)
    408         else:
    409             print >>out, d
    410 
    411 
    412     class print_vis_or_vtopo:
    413         """
    414         Print the retrieved data is a simple xml representation of the dict.
    415         """
    416         def __init__(self, top):
    417             self.xml = top
    418 
    419         def __call__(self, d, out=sys.stdout):
    420             str = "<%s>\n" % self.xml
    421             for t in ('node', 'lan'):
    422                 if d.has_key(t):
    423                     for x in d[t]:
    424                         str += "<%s>" % t
    425                         for k in x.keys():
    426                             str += "<%s>%s</%s>" % (k, x[k],k)
    427                         str += "</%s>\n" % t
    428             str+= "</%s>" % self.xml
    429             print >>out, str
    430 
    431        
    432     def __call__(self):
    433         """
    434         The control flow.  Compose the request and print the response.
    435         """
    436         # Process the options using the customized option parser defined above
    437         parser = fedd_exp_data_opts()
    438 
    439         (opts, args) = parser.parse_args()
    440 
    441         if opts.trusted:
    442             if ( not os.access(opts.trusted, os.R_OK) ) :
    443                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    444 
    445         if opts.debug > 0: opts.tracefile=sys.stderr
    446 
    447         (user, cert) = self.get_user_info()
    448 
    449         if opts.cert != None: cert = opts.cert
    450 
    451         if cert == None:
    452             sys.exit("No certificate given (--cert) or found")
    453 
    454         if os.access(cert, os.R_OK):
    455             fid = fedid(file=cert)
    456         else:
    457             sys.exit("Cannot read certificate (%s)" % cert)
    458 
    459         if opts.exp_name and opts.exp_certfile:
    460             sys.exit("Only one of --experiment_cert and " +\
    461                     "--experiment_name permitted");
    462 
    463         exp_id = None
    464         if opts.exp_certfile:
    465             exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
    466 
    467         if opts.exp_name:
    468             exp_id = { 'localname' : opts.exp_name }
    469 
    470         if not exp_id:
    471             sys.exit("specify one of --experiment_cert and --experiment_name")
    472 
    473 
    474         req = { 'experiment': exp_id }
    475 
    476         try:
    477             resp_dict = self.do_rpc(req,
    478                     opts.url, opts.transport, cert, opts.trusted,
    479                     serialize_only=opts.serialize_only,
    480                     tracefile=opts.tracefile,
    481                     caller=self.caller('Info'))
    482         except self.RPCException, e:
    483             exit_with_fault(\
    484                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    485         except RuntimeError, e:
    486             sys.exit("Error processing RPC: %s" % e)
    487 
    488         return (resp_dict, opts)
    489 
    490 
    491 # Querying experiment data follows the same control flow regardless of the
    492 # specific data retrieved.  This class encapsulates that control flow.
    493 class exp_data(exp_data_base):
    494     def __init__(self):
    495         exp_data_base.__init__(self)
    496 
    497     def __call__(self):
    498         """
    499         The control flow.  Compose the request and print the response.
    500         """
    501 
    502         resp_dict, opts = exp_data_base.__call__(self)
    503 
    504         for d in opts.data:
    505             key, output = self.params[d]
    506             try:
    507                 if resp_dict.has_key(key):
    508                     output(resp_dict[key])
    509             except RuntimeError, e:
    510                 sys.exit("Bad response. %s" % e.message)
    511 
    512 class ftopo(exp_data_base):
    513     """
    514     ftopo returns the mapping from logical name to local hostname
    515     """
    516     def __init__(self):
    517         exp_data_base.__init__(self)
    518     def __call__(self):
    519         sys.argv.append('--data=experimentdescription')
    520         resp, opts = exp_data_base.__call__(self)
    521         if 'experimentdescription' in resp and \
    522                 'topdldescription' in resp['experimentdescription']:
    523             top = \
    524                 topdl.Topology(\
    525                 **resp['experimentdescription']['topdldescription'])
    526 
    527             for e in [ e for e in top.elements \
    528                     if isinstance(e, topdl.Computer)]:
    529                 hn = e.get_attribute('hostname')
    530                 tb = e.get_attribute('testbed')
    531                 if hn and tb:
    532                     print ":".join([",".join(e.name), hn, tb])
    533 
    534 
    535 
    536 
    537 class vtopo(exp_data_base):
    538     """
    539     vtopo is just an info --data=vtopo request, so this adds that parameter to
    540     the arguments and executes exp_info when called.
    541     """
    542     def __init__(self):
    543         exp_data_base.__init__(self)
    544     def __call__(self):
    545         sys.argv.append('--data=vtopo')
    546         resp, opts = exp_data_base.__call__(self)
    547         if 'vtopo' in resp:
    548             self.print_vis_or_vtopo('vtopo')(resp['vtopo'])
    549 
    550 
    551 class vis(exp_data_base):
    552     """
    553     vis is just an info --data=vis request, so this adds that parameter to
    554     the arguments and executes exp_info when called.
    555     """
    556     def __init__(self):
    557         exp_data_base.__init__(self)
    558     def __call__(self):
    559         sys.argv.append('--data=vis')
    560         resp, opts = exp_data_base.__call__(self)
    561         if 'vis' in resp:
    562             self.print_vis_or_vtopo('vis')(resp['vis'])
    563 
    564 class status(exp_data_base):
    565     """
    566     status is just an info --data=status request, so this adds that parameter
    567     to the arguments and executes exp_info when called.
    568     """
    569     def __init__(self):
    570         exp_data_base.__init__(self)
    571     def __call__(self):
    572         sys.argv.append('--data=status')
    573         resp, opts = exp_data_base.__call__(self)
    574         if 'experimentStatus' in resp:
    575             self.print_string(resp['experimentStatus'])
    576 
    577 class multi_exp_data(exp_data_base):
    578     def __init__(self):
    579         exp_data_base.__init__(self)
    580 
    581 
    582     def __call__(self):
    583         """
    584         The control flow.  Compose the request and print the response.
    585         """
    586         # Process the options using the customized option parser defined above
    587         parser = fedd_multi_exp_data_opts()
    588 
    589         (opts, args) = parser.parse_args()
    590 
    591         if opts.trusted:
    592             if ( not os.access(opts.trusted, os.R_OK) ) :
    593                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    594 
    595         if opts.debug > 0: opts.tracefile=sys.stderr
    596 
    597         (user, cert) = self.get_user_info()
    598 
    599         if opts.cert != None: cert = opts.cert
    600 
    601         if cert == None:
    602             sys.exit("No certificate given (--cert) or found")
    603 
    604         if os.access(cert, os.R_OK):
    605             fid = fedid(file=cert)
    606         else:
    607             sys.exit("Cannot read certificate (%s)" % cert)
    608 
    609         req = { }
    610 
    611         try:
    612             resp_dict = self.do_rpc(req,
    613                     opts.url, opts.transport, cert, opts.trusted,
    614                     serialize_only=opts.serialize_only,
    615                     tracefile=opts.tracefile,
    616                     caller=self.caller('MultiInfo'))
    617         except self.RPCException, e:
    618             exit_with_fault(\
    619                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    620         except RuntimeError, e:
    621             sys.exit("Error processing RPC: %s" % e)
    622 
    623         exps = resp_dict.get('info', [])
    624         if exps:
    625             print '---'
    626             for exp in exps:
    627                 for d in opts.data:
    628                     key, output = self.params[d]
    629                     try:
    630                         if exp.has_key(key):
    631                             output(exp[key])
    632                     except RuntimeError, e:
    633                         sys.exit("Bad response. %s" % e.message)
    634                 print '---'
    635 
    636 
    637 class multi_status(exp_data_base):
    638     def __init__(self):
    639         exp_data_base.__init__(self)
    640 
    641 
    642     def __call__(self):
    643         """
    644         The control flow.  Compose the request and print the response.
    645         """
    646         # Process the options using the customized option parser defined above
    647         parser = fedd_client_opts()
    648 
    649         (opts, args) = parser.parse_args()
    650 
    651         if opts.trusted:
    652             if ( not os.access(opts.trusted, os.R_OK) ) :
    653                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    654 
    655         if opts.debug > 0: opts.tracefile=sys.stderr
    656 
    657         (user, cert) = self.get_user_info()
    658 
    659         if opts.cert != None: cert = opts.cert
    660 
    661         if cert == None:
    662             sys.exit("No certificate given (--cert) or found")
    663 
    664         if os.access(cert, os.R_OK):
    665             fid = fedid(file=cert)
    666         else:
    667             sys.exit("Cannot read certificate (%s)" % cert)
    668 
    669         req = { }
    670 
    671         try:
    672             resp_dict = self.do_rpc(req,
    673                     opts.url, opts.transport, cert, opts.trusted,
    674                     serialize_only=opts.serialize_only,
    675                     tracefile=opts.tracefile,
    676                     caller=self.caller('MultiInfo'))
    677         except self.RPCException, e:
    678             exit_with_fault(\
    679                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    680         except RuntimeError, e:
    681             sys.exit("Error processing RPC: %s" % e)
    682 
    683         for exp in resp_dict.get('info', []):
    684             out = []
    685             for eid in exp.get('experimentID', []):
    686                 if eid.has_key('localname'):
    687                     out.append(eid['localname'])
    688                     break
    689             else:
    690                 out.append("")
    691             for eid in exp.get('experimentID', []):
    692                 if eid.has_key('fedid'):
    693                     out.append("%s" % eid['fedid'])
    694                     break
    695             else:
    696                 out.append("")
    697 
    698             out.append(exp.get('experimentStatus', ""))
    699 
    700             for f in exp.get('federant', []):
    701                 if f.get('master', False):
    702                     em = f.get('emulab', None)
    703                     if em:
    704                         project = em.get('project', None)
    705                         if project:
    706                             tb = project.get('testbed', None)
    707                             if tb and tb.has_key('localname'):
    708                                 out.append(tb['localname'])
    709                             else:
    710                                 out.append("")
    711                             pn = project.get('name', None)
    712                             if pn and pn.has_key('localname'):
    713                                 out.append(pn['localname'])
    714                             else:
    715                                 out.append("")
    716                         else:
    717                             out.extend(("", ""))
    718                     else:
    719                         out.extend(("", ""))
    720                     break
    721             else:
    722                 out.extend(("",""))
    723 
    724             print ":".join(out)
    725 
    726 class image(fedd_rpc):
    727     def __init__(self):
    728         """
    729         Null constructor
    730         """
    731 
    732         fedd_rpc.__init__(self)
    733 
    734     @staticmethod
    735     def gen_dot_topo(d, labels, dotfile):
    736         lans = { }
    737         links = { }
    738 
    739         for n in d.get('node', []):
    740             print >>dotfile, '\t"%s" [shape=box,style=filled,\\' % n['vname']
    741             print >>dotfile, '\t\tcolor=black,fillcolor="#60f8c0",regular=1]'
    742 
    743         # Collect lan members (we have to draw extra stuff for these)
    744         for n in d.get('lan', []):
    745             v = n['vname']
    746             m = n['member']
    747             i = n['ip']
    748             if m.find(':') != -1:
    749                 m = m[0:m.find(':')]
    750             if lans.has_key(v):
    751                 lans[v].append((m, i))
    752             elif links.has_key(v):
    753                 links[v].append((m, i))
    754                 if len(links[v]) > 2:
    755                     lans[v] = links[v]
    756                     del links[v]
    757             else:
    758                 links[v] = [(m, i)]
    759 
    760         # Encode the lans and the links
    761         for l in lans.keys():
    762             print >>dotfile, '\t"%s" [shape=ellipse, style=filled,\\' % l
    763             print >>dotfile,'\t\tcolor=black,fillcolor="#80c0f8",regular=1]'
    764             for n in lans[l]:
    765                 if labels:
    766                     print >>dotfile, '\t"%s" -- "%s" [headlabel="%s"]' % \
    767                             (l, n[0], n[1])
    768                 else:
    769                     print >>dotfile, '\t"%s" -- "%s"' % (l, n[0])
    770 
    771         for k, l in links.items():
    772             if len(l) == 2:
    773                 if labels:
    774                     print >>dotfile, \
    775                             ('\t"%s" -- "%s" [label="%s",taillabel="%s",' + \
    776                             'headlabel="%s"]') % \
    777                             (l[0][0], l[1][0], k, l[0][1], l[1][1])
    778                 else:
    779                     print >>dotfile, '\t"%s" -- "%s" ' % (l[0][0], l[1][0])
    780 
    781 
    782     def gen_image(self, d, nodes, file, fmt, neato, labels, pix=None):
    783 
    784         # Open up a temporary file for dot to turn into a visualization
    785         try:
    786             df, dotname = tempfile.mkstemp(prefix='fedd_client', suffix=".dot")
    787             dotfile = os.fdopen(df, 'w')
    788         except IOError:
    789             raise service_error(service_error.internal,
    790                     "Failed to open file in genviz")
    791 
    792         if not neato:
    793             for f in ['/usr/bin/neato', '/usr/local/bin/neato',
    794                     '/usr/bin/dot', '/usr/local/bin/dot']:
    795                 if os.access(f, os.X_OK):
    796                     neato = f
    797                     break
    798             else:
    799                 sys.exit("Cannot find graph rendering program")
    800 
    801         cmd = [neato, '-Gsplines=true']
    802         if fmt != 'dot': cmd.append('-T%s' % fmt)
    803         if file:
    804             cmd.append('-o')
    805             cmd.append(file)
    806         cmd.append(dotname)
    807 
    808         #nodes = d.get('node',[])
    809 
    810         if nodes < 10: size = 5
    811         elif nodes < 50: size = 10
    812         else: size = 18
    813 
    814         if pix:
    815             dpi = pix / size
    816         else:
    817             dpi = None
    818 
    819 
    820         print >>dotfile, "graph G {"
    821         if dpi:
    822             print >>dotfile, '\tgraph [size="%i,%i", dpi="%i", ratio=fill];' \
    823                     % (size, size, dpi)
    824         else:
    825             print >>dotfile, '\tgraph [size="%i,%i", ratio=fill];' \
    826                     % (size, size)
    827 
    828         if labels:
    829             print >>dotfile, '\tnode [fontname=arial,fontsize=9,label="\N"];'
    830             print >>dotfile, '\tedge [fontname=arial,fontsize=9];\n'
    831         else:
    832             print >>dotfile, '\tnode [label=""];'
    833 
    834 
    835         self.gen_dot_topo(d, labels, dotfile)
    836         print >>dotfile, "}"
    837         dotfile.close()
    838 
    839         # Redirect the drawing program stderr
    840         dev_null = open("/dev/null", "w")
    841         rv = subprocess.call(cmd, stderr=dev_null)
    842         os.remove(dotname)
    843         dev_null.close()
    844         if rv != 0:
    845             sys.exit("Error creating graph")
    846 
    847 
    848 
    849     def __call__(self):
    850         """
    851         The control flow.  Compose the request and print the response.
    852         """
    853         # Process the options using the customized option parser defined above
    854         parser = fedd_image_opts()
    855 
    856         (opts, args) = parser.parse_args()
    857 
    858         if opts.trusted:
    859             if ( not os.access(opts.trusted, os.R_OK) ) :
    860                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    861 
    862         if opts.debug > 0: opts.tracefile=sys.stderr
    863 
    864         (user, cert) = self.get_user_info()
    865 
    866         if opts.cert != None: cert = opts.cert
    867 
    868         if cert == None:
    869             sys.exit("No certificate given (--cert) or found")
    870 
    871         if os.access(cert, os.R_OK):
    872             fid = fedid(file=cert)
    873         else:
    874             sys.exit("Cannot read certificate (%s)" % cert)
    875 
    876         if opts.exp_name and opts.exp_certfile:
    877             sys.exit("Only one of --experiment_cert and " +\
    878                     "--experiment_name permitted");
    879 
    880         if opts.exp_certfile:
    881             exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
    882 
    883         if opts.exp_name:
    884             exp_id = { 'localname' : opts.exp_name }
    885 
    886         if opts.format and opts.outfile:
    887             fmt = opts.format
    888             file = opts.outfile
    889         elif not opts.format and opts.outfile:
    890             fmt = opts.outfile[-3:]
    891             if fmt not in ("png", "jpg", "dot", "svg"):
    892                 sys.exit("Unexpected file type and no format specified")
    893             file = opts.outfile
    894         elif opts.format and not opts.outfile:
    895             fmt = opts.format
    896             file = None
    897         else:
    898             fmt="dot"
    899             file = None
    900 
    901 
    902         req = { 'experiment': exp_id }
    903 
    904         try:
    905             resp_dict = self.do_rpc(req,
    906                     opts.url, opts.transport, cert, opts.trusted,
    907                     serialize_only=opts.serialize_only,
    908                     tracefile=opts.tracefile,
    909                     caller=self.caller('Vtopo'))
    910         except self.RPCException, e:
    911             exit_with_fault(\
    912                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    913         except RuntimeError, e:
    914             sys.exit("Error processing RPC: %s" % e)
    915 
    916 
    917         if resp_dict.has_key('vtopo'):
    918             self.gen_image(resp_dict['vtopo'],
    919                     len(resp_dict['vtopo'].get('node', [])),
    920                     file, fmt, opts.neato, opts.labels, opts.pixels)
    921         elif opts.serialze_only:
    922             sys.exit(0)
    923         else:
    924             sys.exit("Bad response. %s" % e.message)
    925 
    926 class topdl_image(image):
    927     def __init__(self):
    928         """
    929         Null constructor
    930         """
    931 
    932         image.__init__(self)
    933 
    934     @staticmethod
    935     def gen_dot_topo(t, labels, dotfile):
    936         lans = [ s for s in t.substrates if len(s.interfaces) != 2]
    937         links = [ s for s in t.substrates if len(s.interfaces) == 2]
    938 
    939         i = 0
    940         for n in t.elements:
    941             if n.name:
    942                 print >>dotfile, '\t"%s" [shape=box,style=filled,\\' % n.name
    943             else:
    944                 print >>dotfile, \
    945                         '\t"unnamed_node%d" [shape=box,style=filled,\\' % i
    946                 i += 1
    947             print >>dotfile, '\t\tcolor=black,fillcolor="#60f8c0",regular=1]'
    948 
    949         # Encode the lans and the links
    950         for l in lans:
    951             print >>dotfile, '\t"%s" [shape=ellipse, style=filled,\\' % l.name
    952             print >>dotfile,'\t\tcolor=black,fillcolor="#80c0f8",regular=1]'
    953             for i in l.interfaces:
    954                 ip = i.get_attribute('ip4_address')
    955                 if labels and ip:
    956                     print >>dotfile, '\t"%s" -- "%s" [headlabel="%s"]' % \
    957                             (l.name, i.element.name, ip)
    958                 else:
    959                     print >>dotfile, '\t"%s" -- "%s"' % \
    960                             (l.name, i.element.name)
    961 
    962         for l in links:
    963             s, d = l.interfaces[0:2]
    964             sip = s.get_attribute('ip4_address')
    965             dip = d.get_attribute('ip4_address')
    966             if labels and sip and dip:
    967                 print >>dotfile, \
    968                         ('\t"%s" -- "%s" [label="%s",taillabel="%s",' + \
    969                         'headlabel="%s"]') % \
    970                         (s.element.name, d.element.name, l.name,
    971                             sip, dip)
    972             else:
    973                 print >>dotfile, '\t"%s" -- "%s" ' % \
    974                         (s.element.name, d.element.name)
    975     def __call__(self):
    976         """
    977         The control flow.  Compose the request and print the response.
    978         """
    979         # Process the options using the customized option parser defined above
    980         parser = fedd_ns_image_opts()
    981 
    982         (opts, args) = parser.parse_args()
    983 
    984         if opts.trusted:
    985             if ( not os.access(opts.trusted, os.R_OK) ) :
    986                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    987 
    988         if opts.debug > 0: opts.tracefile=sys.stderr
    989 
    990         (user, cert) = self.get_user_info()
    991 
    992         if opts.cert != None: cert = opts.cert
    993 
    994         if cert == None:
    995             sys.exit("No certificate given (--cert) or found")
    996 
    997         if os.access(cert, os.R_OK):
    998             fid = fedid(file=cert)
    999         else:
    1000             sys.exit("Cannot read certificate (%s)" % cert)
    1001 
    1002         if opts.file:
    1003             exp_desc = ""
    1004             try:
    1005                 top = topdl.topology_from_xml(filename=opts.file,
    1006                         top="experiment")
    1007             except IOError:
    1008                 sys.exit("Cannot read description file (%s)" % opts.file)
    1009         else:
    1010             sys.exit("Must specify an experiment description (--file)")
    1011 
    1012         if not opts.master:
    1013             opts.master="dummy"
    1014 
    1015 
    1016         if opts.format and opts.outfile:
    1017             fmt = opts.format
    1018             file = opts.outfile
    1019         elif not opts.format and opts.outfile:
    1020             fmt = opts.outfile[-3:]
    1021             if fmt not in ("png", "jpg", "dot", "svg"):
    1022                 sys.exit("Unexpected file type and no format specified")
    1023             file = opts.outfile
    1024         elif opts.format and not opts.outfile:
    1025             fmt = opts.format
    1026             file = None
    1027         else:
    1028             fmt="dot"
    1029             file = None
    1030 
    1031         self.gen_image(top, len(top.elements), file, fmt, opts.neato,
    1032                 opts.labels, opts.pixels)
    1033 
    1034 class ns_image(topdl_image):
    1035     def __init__(self):
    1036         """
    1037         Null constructor
    1038         """
    1039 
    1040         topdl_image.__init__(self)
    1041 
    1042     def __call__(self):
    1043         """
    1044         The control flow.  Compose the request and print the response.
    1045         """
    1046         # Process the options using the customized option parser defined above
    1047         parser = fedd_ns_image_opts()
    1048 
    1049         (opts, args) = parser.parse_args()
    1050 
    1051         if opts.trusted:
    1052             if ( not os.access(opts.trusted, os.R_OK) ) :
    1053                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    1054 
    1055         if opts.debug > 0: opts.tracefile=sys.stderr
    1056 
    1057         (user, cert) = self.get_user_info()
    1058 
    1059         if opts.cert != None: cert = opts.cert
    1060 
    1061         if cert == None:
    1062             sys.exit("No certificate given (--cert) or found")
    1063 
    1064         if os.access(cert, os.R_OK):
    1065             fid = fedid(file=cert)
    1066         else:
    1067             sys.exit("Cannot read certificate (%s)" % cert)
    1068 
    1069         if opts.file:
    1070             exp_desc = ""
    1071             try:
    1072                 f = open(opts.file, 'r')
    1073                 for line in f:
    1074                     exp_desc += line
    1075                 f.close()
    1076             except IOError:
    1077                 sys.exit("Cannot read description file (%s)" %opts.file)
    1078         else:
    1079             sys.exit("Must specify an experiment description (--file)")
    1080 
    1081         if not opts.master:
    1082             opts.master="dummy"
    1083 
    1084         req = { 'description': { 'ns2description': exp_desc }, }
    1085 
    1086         if opts.format and opts.outfile:
    1087             fmt = opts.format
    1088             file = opts.outfile
    1089         elif not opts.format and opts.outfile:
    1090             fmt = opts.outfile[-3:]
    1091             if fmt not in ("png", "jpg", "dot", "svg"):
    1092                 sys.exit("Unexpected file type and no format specified")
    1093             file = opts.outfile
    1094         elif opts.format and not opts.outfile:
    1095             fmt = opts.format
    1096             file = None
    1097         else:
    1098             fmt="dot"
    1099             file = None
    1100 
    1101         try:
    1102             resp_dict = self.do_rpc(req,
    1103                     opts.url, opts.transport, cert, opts.trusted,
    1104                     serialize_only=opts.serialize_only,
    1105                     tracefile=opts.tracefile,
    1106                     caller=self.caller('Ns2Topdl'))
    1107         except self.RPCException, e:
    1108             exit_with_fault(\
    1109                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    1110         except RuntimeError, e:
    1111             sys.exit("Error processing RPC: %s" % e)
    1112 
    1113 
    1114         if 'experimentdescription' in resp_dict:
    1115             if 'topdldescription' in resp_dict['experimentdescription']:
    1116                 exp = resp_dict['experimentdescription']['topdldescription']
    1117                 top = topdl.Topology(**exp)
    1118                 self.gen_image(top, len(top.elements), file, fmt, opts.neato,
    1119                         opts.labels, opts.pixels)
    1120             else:
    1121                 sys.exit("Bad response: could not translate")
    1122         elif opts.serialze_only:
    1123             sys.exit(0)
    1124         else:
    1125             sys.exit("Bad response. %s" % e.message)
    1126 
    1127 class terminate(fedd_rpc):
    1128     def __init__(self):
    1129         """
    1130         Termination request
    1131         """
    1132 
    1133         fedd_rpc.__init__(self)
    1134 
    1135     def __call__(self):
    1136         """
    1137         The control flow.  Compose the request and print the response.
    1138         """
    1139         # Process the options using the customized option parser defined above
    1140         parser = fedd_terminate_opts()
    1141 
    1142         (opts, args) = parser.parse_args()
    1143 
    1144         (user, cert) = self.get_user_info()
    1145         if opts.trusted:
    1146             if ( not os.access(opts.trusted, os.R_OK) ) :
    1147                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    1148 
    1149         if opts.debug > 0: opts.tracefile=sys.stderr
    1150 
    1151         if opts.cert != None: cert = opts.cert
    1152 
    1153         if cert == None:
    1154             sys.exit("No certificate given (--cert) or found")
    1155 
    1156         if os.access(cert, os.R_OK):
    1157             fid = fedid(file=cert)
    1158         else:
    1159             sys.exit("Cannot read certificate (%s)" % cert)
    1160 
    1161         if opts.exp_name and opts.exp_certfile:
    1162             sys.exit("Only one of --experiment_cert and " +\
    1163                     "--experiment_name permitted")
    1164 
    1165         if opts.print_log and opts.logfile:
    1166             sys.exit("Only one of --logfile and --print_log is permitted")
    1167         elif opts.print_log:
    1168             out = sys.stdout
    1169         elif opts.logfile:
    1170             try:
    1171                 out = open(opts.logfile, "w")
    1172             except IOError,e:
    1173                 sys.exit("Cannot open logfile: %s" %e)
    1174         else:
    1175             out = None
    1176 
    1177         exp_id = None
    1178 
    1179         if opts.exp_certfile:
    1180             exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
    1181 
    1182         if opts.exp_name:
    1183             exp_id = { 'localname' : opts.exp_name }
    1184 
    1185         if not exp_id:
    1186             sys.exit("Must give one of --experiment_cert and " +\
    1187                     "--experiment_name");
    1188 
    1189         req = { 'experiment': exp_id, 'force': opts.force }
    1190 
    1191         try:
    1192             resp_dict = self.do_rpc(req,
    1193                     opts.url, opts.transport, cert, opts.trusted,
    1194                     serialize_only=opts.serialize_only,
    1195                     tracefile=opts.tracefile,
    1196                     caller=self.caller('Terminate'))
    1197         except self.RPCException, e:
    1198             exit_with_fault(\
    1199                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    1200         except RuntimeError, e:
    1201             print e
    1202             sys.exit("Error processing RPC: %s" % e)
    1203 
    1204         if out:
    1205             log = resp_dict.get('deallocationLog', None)
    1206             if log:
    1207                 print >>out, log
    1208                 out.close()
    1209             else:
    1210                 out.close()
    1211                 sys.exit("No log returned")
    1212 
    1213275class terminate_segment(fedd_rpc):
    1214276    def __init__(self):
     
    1297359                sys.exit("No log returned")
    1298360
    1299 class new(fedd_rpc):
    1300     def __init__(self):
    1301         fedd_rpc.__init__(self)
    1302     def __call__(self):
    1303         # Process the options using the customized option parser defined above
    1304         parser = fedd_new_opts()
    1305 
    1306         (opts, args) = parser.parse_args()
    1307 
    1308         if opts.trusted:
    1309             if ( not os.access(opts.trusted, os.R_OK) ) :
    1310                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    1311 
    1312         if opts.debug > 0: opts.tracefile=sys.stderr
    1313 
    1314         (user, cert) = self.get_user_info()
    1315 
    1316         if opts.cert != None: cert = opts.cert
    1317 
    1318         if cert == None:
    1319             sys.exit("No certificate given (--cert) or found")
    1320 
    1321         if os.access(cert, os.R_OK):
    1322             fid = fedid(file=cert)
    1323         else:
    1324             sys.exit("Cannot read certificate (%s)" % cert)
    1325 
    1326         out_certfile = opts.out_certfile
    1327 
    1328         msg = { }
    1329 
    1330         if opts.exp_name:
    1331             msg['experimentID'] = { 'localname': opts.exp_name }
    1332 
    1333         if opts.debug > 1: print >>sys.stderr, msg
    1334 
    1335         try:
    1336             resp_dict = self.do_rpc(msg,
    1337                     opts.url, opts.transport, cert, opts.trusted,
    1338                     serialize_only=opts.serialize_only,
    1339                     tracefile=opts.tracefile,
    1340                     caller=self.caller("New"))
    1341         except self.RPCException, e:
    1342             exit_with_fault(\
    1343                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    1344         except RuntimeError, e:
    1345             sys.exit("Error processing RPC: %s" % e)
    1346 
    1347         if opts.debug > 1: print >>sys.stderr, resp_dict
    1348 
    1349         ea = resp_dict.get('experimentAccess', None)
    1350         if out_certfile and ea and ea.has_key('X509'):
    1351             try:
    1352                 f = open(out_certfile, "w")
    1353                 print >>f, ea['X509']
    1354                 f.close()
    1355             except IOError:
    1356                 sys.exit('Could not write to %s' %  out_certfile)
    1357         eid = resp_dict.get('experimentID', None)
    1358         if eid:
    1359             for id in eid:
    1360                 for k in id.keys():
    1361                     print "%s: %s" % (k, id[k])
    1362         st = resp_dict.get('experimentStatus', None)
    1363         if st:
    1364             print "status: %s" % st
    1365 
    1366 
    1367 class create(fedd_rpc):
    1368     def __init__(self):
    1369         fedd_rpc.__init__(self)
    1370 
    1371     @staticmethod
    1372     def parse_service(svc):
    1373         terms = svc.split(':')
    1374         svcd = { }
    1375         if len(terms) < 2 or len(terms[0]) == 0 or len(terms[1]) == 0:
    1376             sys.exit("Bad service description '%s': Not enough terms" % svc)
    1377        
    1378         svcd['name'] = terms[0]
    1379         svcd['export'] = terms[1].split(",")
    1380         if len(terms) > 2 and len(terms[2]) > 0:
    1381             svcd['import'] = terms[2].split(",")
    1382         if len(terms) > 3 and len(terms[3]) > 0:
    1383             svcd['fedAttr'] = [ ]
    1384             for t in terms[3].split(","):
    1385                 i = t.find("=")
    1386                 if i != -1 :
    1387                     svcd['fedAttr'].append(
    1388                             {'attribute': t[0:i], 'value': t[i+1:]})
    1389                 else:
    1390                     sys.exit("Bad service attribute '%s': no equals sign" % t)
    1391         return svcd
    1392 
    1393     def __call__(self):
    1394         parser = fedd_create_opts()
    1395 
    1396         (opts, args) = parser.parse_args()
    1397 
    1398         svcs = []
    1399 
    1400         if opts.trusted:
    1401             if ( not os.access(opts.trusted, os.R_OK) ) :
    1402                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    1403 
    1404         if not (opts.project and opts.master) and not opts.service:
    1405             print >>sys.stderr, "Neither master/project nor services requested"
    1406 
    1407         if opts.debug > 0: opts.tracefile=sys.stderr
    1408 
    1409         (user, cert) = self.get_user_info()
    1410 
    1411         if opts.cert != None: cert = opts.cert
    1412 
    1413         if cert == None:
    1414             sys.exit("No certificate given (--cert) or found")
    1415 
    1416         if os.access(cert, os.R_OK):
    1417             fid = fedid(file=cert)
    1418         else:
    1419             sys.exit("Cannot read certificate (%s)" % cert)
    1420 
    1421         if opts.file:
    1422             exp_desc = ""
    1423             try:
    1424                 f = open(opts.file, 'r')
    1425                 for line in f:
    1426                     exp_desc += line
    1427                 f.close()
    1428             except IOError:
    1429                 sys.exit("Cannot read description file (%s)" %opts.file)
    1430         else:
    1431             sys.exit("Must specify an experiment description (--file)")
    1432 
    1433         out_certfile = opts.out_certfile
    1434        
    1435         # Fill in svcs here so errors in service specification come before the
    1436         # New call is made
    1437         if opts.master and opts.project:
    1438             svcs.append({
    1439                     'name': 'project_export',
    1440                     'export': [opts.master],
    1441                     'importall': True,
    1442                     'fedAttr': [
    1443                         { 'attribute': 'project', 'value': opts.project },
    1444                         ],
    1445                     })
    1446 
    1447         svcs.extend([ self.parse_service(s) for s in opts.service])
    1448         msg = { }
    1449 
    1450         if opts.exp_name:
    1451             msg['experimentID'] = { 'localname': opts.exp_name }
    1452 
    1453         if opts.debug > 1: print >>sys.stderr, msg
    1454 
    1455         try:
    1456             resp_dict = self.do_rpc(msg,
    1457                     opts.url, opts.transport, cert, opts.trusted,
    1458                     serialize_only=opts.serialize_only,
    1459                     tracefile=opts.tracefile,
    1460                     caller=self.caller('New'))
    1461         except self.RPCException, e:
    1462             exit_with_fault(\
    1463                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    1464         except RuntimeError, e:
    1465             sys.exit("Error processing RPC: %s" % e)
    1466 
    1467         if opts.debug > 1: print >>sys.stderr, resp_dict
    1468 
    1469         ea = resp_dict.get('experimentAccess', None)
    1470         if out_certfile and ea and ea.has_key('X509'):
    1471             try:
    1472                 f = open(out_certfile, "w")
    1473                 print >>f, ea['X509']
    1474                 f.close()
    1475             except IOError:
    1476                 sys.exit('Could not write to %s' %  out_certfile)
    1477         eid = resp_dict.get('experimentID', None)
    1478         e_fedid = None
    1479         e_local = None
    1480         if eid:
    1481             for id in eid:
    1482                 for k in id.keys():
    1483                     if k =='fedid':
    1484                         e_fedid = id[k]
    1485                     elif k =='localname':
    1486                         e_local = id[k]
    1487         elif opts.serialize_only:
    1488             e_local = "serialize"
    1489         msg = { 'experimentdescription': { 'ns2description': exp_desc }, }
    1490 
    1491         if svcs:
    1492             msg['service'] = svcs
    1493 
    1494         if e_fedid:
    1495             msg['experimentID'] = { 'fedid': e_fedid }
    1496         elif e_local:
    1497             msg['experimentID'] = { 'localname': e_local }
    1498         else:
    1499             sys.exit("New did not return an experiment ID??")
    1500 
    1501         if opts.debug > 1: print >>sys.stderr, msg
    1502 
    1503         try:
    1504             resp_dict = self.do_rpc(msg,
    1505                     opts.url, opts.transport, cert, opts.trusted,
    1506                     serialize_only=opts.serialize_only,
    1507                     tracefile=opts.tracefile,
    1508                     caller=self.caller('Create'))
    1509         except self.RPCException, e:
    1510             exit_with_fault(\
    1511                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    1512         except RuntimeError, e:
    1513             sys.exit("Error processing RPC: %s" % e)
    1514 
    1515         if opts.debug > 1: print >>sys.stderr, resp_dict
    1516 
    1517         ea = resp_dict.get('experimentAccess', None)
    1518         if out_certfile and ea and ea.has_key('X509'):
    1519             try:
    1520                 f = open(out_certfile, "w")
    1521                 print >>f, ea['X509']
    1522                 f.close()
    1523             except IOError:
    1524                 sys.exit('Could not write to %s' %  out_certfile)
    1525         eid = resp_dict.get('experimentID', None)
    1526         if eid:
    1527             for id in eid:
    1528                 for k in id.keys():
    1529                     print "%s: %s" % (k, id[k])
    1530         st = resp_dict.get('experimentStatus', None)
    1531         if st:
    1532             print "status: %s" % st
    1533 
    1534 class split(fedd_rpc):
    1535     def __init__(self):
    1536         fedd_rpc.__init__(self)
    1537     def __call__(self):
    1538         # Process the options using the customized option parser defined above
    1539         parser = fedd_split_opts()
    1540 
    1541         (opts, args) = parser.parse_args()
    1542 
    1543         if opts.trusted:
    1544             if ( not os.access(opts.trusted, os.R_OK) ) :
    1545                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    1546 
    1547         if opts.debug > 0: opts.tracefile=sys.stderr
    1548 
    1549         (user, cert) = self.get_user_info()
    1550 
    1551         if opts.cert != None: cert = opts.cert
    1552 
    1553         if cert == None:
    1554             sys.exit("No certificate given (--cert) or found")
    1555 
    1556         if os.access(cert, os.R_OK):
    1557             fid = fedid(file=cert)
    1558         else:
    1559             sys.exit("Cannot read certificate (%s)" % cert)
    1560 
    1561         if opts.file:
    1562             exp_desc = ""
    1563             try:
    1564                 f = open(opts.file, 'r')
    1565                 for line in f:
    1566                     exp_desc += line
    1567                 f.close()
    1568             except IOError:
    1569                 sys.exit("Cannot read description file (%s)" %opts.file)
    1570         else:
    1571             sys.exit("Must specify an experiment description (--file)")
    1572 
    1573         if not opts.master:
    1574             sys.exit("Must specify a master testbed (--master)")
    1575 
    1576         out_certfile = opts.out_certfile
    1577 
    1578         msg = {
    1579                 'description': { 'ns2description': exp_desc },
    1580                 'master': opts.master,
    1581                 'include_fedkit': opts.fedkit,
    1582                 'include_gatewaykit': opts.gatewaykit,
    1583                 }
    1584 
    1585         if opts.debug > 1: print >>sys.stderr, msg
    1586 
    1587         try:
    1588             resp_dict = self.do_rpc(msg,
    1589                     opts.url, opts.transport, cert, opts.trusted,
    1590                     serialize_only=opts.serialize_only,
    1591                     tracefile=opts.tracefile,
    1592                     caller=self.caller('Ns2Split'))
    1593         except self.RPCException, e:
    1594             exit_with_fault(\
    1595                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    1596         except RuntimeError, e:
    1597             sys.exit("Error processing RPC: %s" % e)
    1598 
    1599         if opts.debug > 1: print >>sys.stderr, resp_dict
    1600 
    1601         ed = resp_dict.get('experimentdescription', None)
    1602         if ed:
    1603             if ed.has_key('topdldescription'):
    1604                 topo = topdl.Topology(**ed['topdldescription'])
    1605                 print topdl.topology_to_xml(topo, 'experiment')
    1606 
    1607361class access(fedd_rpc):
    1608362    def __init__(self):
     
    1699453            self.print_response_as_testbed(resp_dict, opts.label)
    1700454
    1701 # Keep requesting experiment status and printing updates to the log until the
    1702 # experiment is done being created.
    1703 class spew_log(fedd_rpc):
    1704     def __init__(self):
    1705         """
    1706         Init the superclass
    1707         """
    1708 
    1709         fedd_rpc.__init__(self)
    1710 
    1711     def __call__(self):
    1712         """
    1713         The control flow.  Compose the request and print the response.
    1714         """
    1715         # Process the options using the customized option parser defined above
    1716         parser = fedd_spew_opts()
    1717 
    1718         (opts, args) = parser.parse_args()
    1719 
    1720         if opts.trusted:
    1721             if ( not os.access(opts.trusted, os.R_OK) ) :
    1722                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    1723 
    1724         if opts.debug > 0: opts.tracefile=sys.stderr
    1725 
    1726         (user, cert) = self.get_user_info()
    1727 
    1728         if opts.cert != None: cert = opts.cert
    1729 
    1730         if cert == None:
    1731             sys.exit("No certificate given (--cert) or found")
    1732 
    1733         if os.access(cert, os.R_OK):
    1734             fid = fedid(file=cert)
    1735         else:
    1736             sys.exit("Cannot read certificate (%s)" % cert)
    1737 
    1738         if opts.exp_name and opts.exp_certfile:
    1739             sys.exit("Only one of --experiment_cert and " +\
    1740                     "--experiment_name permitted");
    1741 
    1742         if opts.exp_certfile:
    1743             exp_id = { 'fedid': fedid(file=opts.exp_certfile) }
    1744 
    1745         if opts.exp_name:
    1746             exp_id = { 'localname' : opts.exp_name }
    1747 
    1748         if opts.logfile:
    1749             try:
    1750                 out = open(opts.logfile, "w")
    1751             except IOError,e:
    1752                 sys.exit("Cannot open logfile: %s" %e)
    1753         else:
    1754             out = sys.stdout
    1755 
    1756         req = { 'experiment': exp_id }
    1757 
    1758         status = "starting"
    1759         log = ""
    1760         log_offset = 0
    1761         update = opts.update
    1762         while status == 'starting':
    1763             try:
    1764                 resp_dict = self.do_rpc(req,
    1765                         opts.url, opts.transport, cert, opts.trusted,
    1766                         serialize_only=opts.serialize_only,
    1767                         tracefile=opts.tracefile,
    1768                         caller=self.caller('Info'))
    1769             except self.RPCException, e:
    1770                 exit_with_fault(\
    1771                         {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    1772             except RuntimeError, e:
    1773                 sys.exit("Error processing RPC: %s" % e)
    1774 
    1775             if not opts.serialize_only:
    1776                 status = resp_dict.get('experimentStatus', None)
    1777             else:
    1778                 status = "active"
    1779             log = resp_dict.get('allocationLog', None)
    1780             if not status:
    1781                 sys.exit("No status in Info response??")
    1782             if log:
    1783                 if len(log) > log_offset:
    1784                     print >>out, log[log_offset:],
    1785                     out.flush()
    1786                     log_offset = len(log)
    1787             if status == 'starting':
    1788                 time.sleep(update)
    1789 
    1790         print >>out
    1791         print >>out, status
    1792         out.close()
    1793 
    1794455class start_segment(fedd_rpc):
    1795456    def __init__(self):
     
    1852513            print resp_dict
    1853514
    1854 class ns_topdl(fedd_rpc):
    1855     def __init__(self):
    1856         fedd_rpc.__init__(self)
    1857     def __call__(self):
    1858         # Process the options using the customized option parser defined above
    1859         parser = fedd_ns_topdl_opts()
    1860 
    1861         (opts, args) = parser.parse_args()
    1862 
    1863         if opts.trusted:
    1864             if ( not os.access(opts.trusted, os.R_OK) ) :
    1865                 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    1866 
    1867         if opts.debug > 0: opts.tracefile=sys.stderr
    1868 
    1869         (user, cert) = self.get_user_info()
    1870 
    1871         if opts.cert != None: cert = opts.cert
    1872 
    1873         if cert == None:
    1874             sys.exit("No certificate given (--cert) or found")
    1875 
    1876         if os.access(cert, os.R_OK):
    1877             fid = fedid(file=cert)
    1878         else:
    1879             sys.exit("Cannot read certificate (%s)" % cert)
    1880 
    1881         if opts.file:
    1882             try:
    1883                 f = open(opts.file,"r")
    1884                 contents = "".join(f)
    1885                 f.close()
    1886             except EnvironmentError, e:
    1887                 sys.exit("Can't read %s: %s" % (opts.file, e))
    1888         else:
    1889             sys.exit("Must specify an experiment description (--file)")
    1890 
    1891         msg = { 'description': { 'ns2description': contents }, }
    1892 
    1893         if opts.debug > 1: print >>sys.stderr, msg
    1894 
    1895         try:
    1896             resp_dict = self.do_rpc(msg,
    1897                     opts.url, opts.transport, cert, opts.trusted,
    1898                     serialize_only=opts.serialize_only,
    1899                     tracefile=opts.tracefile,
    1900                     caller=self.caller('Ns2Topdl'))
    1901         except self.RPCException, e:
    1902             exit_with_fault(\
    1903                     {'desc': e.desc, 'errstr': e.errstr, 'code': e.code})
    1904         except RuntimeError, e:
    1905             sys.exit("Error processing RPC: %s" % e)
    1906 
    1907         if 'experimentdescription' in resp_dict:
    1908             if 'topdldescription' in resp_dict['experimentdescription']:
    1909                 exp = resp_dict['experimentdescription']['topdldescription']
    1910                 top = topdl.Topology(**exp)
    1911             else:
    1912                 sys.exit("Bad response: could not translate")
    1913         elif opts.serialze_only:
    1914             sys.exit(0)
    1915         else:
    1916             sys.exit("Bad response. %s" % e.message)
    1917 
    1918         if opts.outfile:
    1919             try:
    1920                 f = open(opts.outfile, "w")
    1921                 print >>f, topdl.topology_to_xml(top, top="experiment")
    1922                 f.close()
    1923             except EnvironmentError, e:
    1924                 sys.exit("Can't write to %s: %s" % (opts.outfile, e))
    1925         else:
    1926             print topdl.topology_to_xml(top, top="experiment")
     515class ftopo:
     516    def __call__(self):
     517        sys.exit("Use fedd_ftopo.py")
     518
     519class exp_data:
     520    def __call__(self):
     521        sys.exit("Use fedd_info.py")
     522
     523class vtopo:
     524    def __call__(self):
     525        sys.exit("Use fedd_info.py --data=vtopo")
     526
     527class vis:
     528    def __call__(self):
     529        sys.exit("Use fedd_info.py --data=vis")
     530
     531class status:
     532    def __call__(self):
     533        sys.exit("Use fedd_info.py --data=status")
     534
     535class multi_exp_data:
     536    def __call__(self):
     537        sys.exit("Use fedd_multiinfo")
     538
     539class multi_status:
     540    def __call__(self):
     541        sys.exit("Use fedd_multistatus")
     542
     543class image:
     544    def __call__(self):
     545        sys.exit("Use fedd_image.py")
     546
     547class topdl_image:
     548    def __call__(self):
     549        sys.exit("Use fedd_image.py")
     550
     551class ns_image:
     552    def __call__(self):
     553        sys.exit("Use fedd_image.py")
     554
     555class terminate:
     556    def __call__(self):
     557        sys.exit("Use fedd_terminate.py")
     558
     559class new:
     560    def __call__(self):
     561        sys.exit("Use fedd_new.py")
     562
     563class create:
     564    def __call__(self):
     565        sys.exit("Use fedd_create.py")
     566
     567class split:
     568    def __call__(self):
     569        sys.exit("Discontinued function")
     570
     571class spew_log:
     572    def __call__(self):
     573        sys.exit("Use fedd_spewlog.py")
     574
     575class ns_topdl:
     576    def __call__(self):
     577        sys.exit("Use fedd_ns2topdl.py")
    1927578
    1928579cmds = {\
Note: See TracChangeset for help on using the changeset viewer.