pagkage /etc/sfa/api_versions.xml
[sfa.git] / sfa / client / sfaadmin.py
index c1738cd..9f5fa0f 100755 (executable)
@@ -12,6 +12,8 @@ from sfa.client.sfi import save_records_to_file
 from sfa.trust.hierarchy import Hierarchy
 from sfa.trust.gid import GID
 
+from sfa.client.candidates import Candidates
+
 pprinter = PrettyPrinter(indent=4)
 
 try:
@@ -28,21 +30,6 @@ def args(*args, **kwargs):
         return func
     return _decorator
 
-### utility to match command-line args to names
-class Candidates:
-    def __init__ (self, names):
-        self.names=names
-    # is an input string acceptable for one of the known names?
-    @staticmethod
-    def fits (input, name):
-        return name.find(input)==0
-    # returns one of the names if the input name has a unique match
-    # or None otherwise
-    def only_match (self, input):
-        matches=[ name for name in self.names if Candidates.fits(input,name) ]
-        if len(matches)==1: return matches[0]
-        else: return None
-
 class Commands(object):
     def _get_commands(self):
         command_names = []
@@ -190,6 +177,12 @@ class RegistryCommands(Commands):
         from sfa.importer import Importer
         importer = Importer()
         importer.run()
+
+    def sync_db(self):
+        """Initiailize or upgrade the db"""
+        from sfa.storage.dbschema import DBSchema
+        dbschema=DBSchema()
+        dbschema.init_or_upgrade
     
     @args('-a', '--all', dest='all', metavar='<all>', action='store_true', default=False,
           help='Remove all registry records and all files in %s area' % help_basedir)
@@ -287,66 +280,81 @@ class AggregateCommands(Commands):
         version = self.api.manager.GetVersion(self.api, {})
         pprinter.pprint(version)
 
-    def slices(self):
-        """List the running slices at this Aggregate"""
-        print self.api.manager.ListSlices(self.api, [], {})
 
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn (mandatory)') 
     def status(self, xrn):
         """Display the status of a slice or slivers"""
         urn = Xrn(xrn, 'slice').get_urn()
-        status = self.api.manager.SliverStatus(self.api, urn, [], {})
+        status = self.api.manager.SliverStatus(self.api, [urn], {}, {})
         pprinter.pprint(status)
  
-    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn', default=None)
     @args('-r', '--rspec-version', dest='rspec_version', metavar='<rspec_version>', 
           default='GENI', help='version/format of the resulting rspec response')  
-    def resources(self, xrn=None, rspec_version='GENI'):
-        """Display the available resources at an aggregate 
-or the resources allocated by a slice"""  
+    def resources(self, rspec_version='GENI'):
+        """Display the available resources at an aggregate"""  
         options = {'geni_rspec_version': rspec_version}
         if xrn:
             options['geni_slice_urn'] = Xrn(xrn, 'slice').get_urn()
-        print options
-        resources = self.api.manager.ListResources(self.api, [], options)
+        resources = self.api.manager.ListResources(self.api, {}, options)
         print resources
-        
+    
+    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn', default=None)
+    @args('-r', '--rspec-version', dest='rspec_version', metavar='<rspec_version>', 
+          default='GENI', help='version/format of the resulting rspec response')  
+    def describe(self, xrn, rspec_version='GENI'):
+        """Display the resources allocated by a slice or slivers"""
+        urn = Xrn(xrn, 'slice').get_urn()
+        options = {'geni_rspec_version': rspec_version}
+        status = self.api.manager.Describe(self.api, {}, [urn], options)      
+        print status
+    
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
     @args('-r', '--rspec', dest='rspec', metavar='<rspec>', help='rspec file (mandatory)')  
     @args('-u', '--user', dest='user', metavar='<user>', help='hrn/urn of slice user (mandatory)')  
     @args('-k', '--key', dest='key', metavar='<key>', help="path to user's public key file (mandatory)")  
-    def create(self, xrn, rspec, user, key):
+    def allocate(self, xrn, rspec, user, key):
         """Allocate slivers"""
         xrn = Xrn(xrn, 'slice')
-        slice_urn=xrn.get_urn()
+        urn=xrn.get_urn()
         rspec_string = open(rspec).read()
         user_xrn = Xrn(user, 'user')
         user_urn = user_xrn.get_urn()
         user_key_string = open(key).read()
         users = [{'urn': user_urn, 'keys': [user_key_string]}]
-        options={}
-        self.api.manager.CreateSliver(self, slice_urn, [], rspec_string, users, options) 
+        options={'geni_users': users}
+        status = self.api.manager.Allocate(self.api, urn, {}, rspec_string, options) 
+        print status
+
+    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
+    def provision(self, xrns):
+        status = self.api.manager.Provision(self.api, [xrns], {}, {})
+        print status         
 
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
     def delete(self, xrn):
         """Delete slivers""" 
-        self.api.manager.DeleteSliver(self.api, xrn, [], {})
+        result = self.api.manager.DeleteSliver(self.api, [xrn], {}, {})
+        print result
+
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
-    def start(self, xrn):
+    @args('-e', '--expiration', dest='expiration', metavar='<expiration>', help='Expiration date (mandatory)')
+    def renew(self, xrn, expiration):
         """Start slivers"""
-        self.api.manager.start_slice(self.api, xrn, [])
+        result = self.api.manager.start_slice(self.api, xrn, {}, expiration, {})
+        print result
 
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
-    def stop(self, xrn):
+    def shutdown(self, xrn):
         """Stop slivers"""
-        self.api.manager.stop_slice(self.api, xrn, [])      
+        result = self.api.manager.Shutdown(self.api, xrn, {}, {})      
+        print result
 
     @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='slice hrn/urn (mandatory)')
-    def reset(self, xrn):
+    @args('-a', '--action', dest='action', metavar='<action>', help='Action name (mandatory)')
+    def operation(self, xrn, action):
         """Reset sliver"""
-        self.api.manager.reset_slice(self.api, xrn)
-
+        result = self.api.manager.PerformOperationalAction(self.api, [xrn], {}, action, {})
+        print result
 
 #    @args('-x', '--xrn', dest='xrn', metavar='<xrn>', help='object hrn/urn', default=None)
 #    @args('-r', '--rspec', dest='rspec', metavar='<rspec>', help='request rspec', default=None)
@@ -462,30 +470,3 @@ class SfaAdmin:
             print "Command failed, please check log for more info"
             raise
 
-candidates_specs=[
-('create delete reset resources slices start status stop version', 
-  [ ('ver','version'),
-    ('r',None),
-    ('re',None),
-    ('res',None),
-    ('rese','reset'),
-    ('reset','reset'),
-    ('reso','resources'),
-    ('sli','slices'),
-    ('st',None),
-    ('sta',None),
-    ('stop','stop'),
-    ('a',None),
-])
-]
-
-def test_candidates ():
-    for (names, tuples) in candidates_specs:
-        names=names.split()
-        for (input,expected) in tuples:
-            got=Candidates(names).only_match(input)
-            if got==expected: print '.',
-            else: print 'X FAIL','names[',names,'] input',input,'expected',expected,'got',got
-
-if __name__ == '__main__':
-    test_candidates()