def Destroy(sliver_name): """Destroy a non-PLC-instantiated sliver""" rec = sliver_name if rec["instantiation"] == "delegated": account.get(rec["name"]).ensure_destroyed() logger.log("api_calls: Destroy %s" % rec["name"]) else: raise Exception, "Only PLC can destroy non delegated slivers."
def Create(sliver_name): """Create a non-PLC-instantiated sliver""" rec = sliver_name if rec['instantiation'] == 'delegated': account.get(rec['name']).ensure_created(rec) logger.log("api_calls: Create %s" % rec['name']) else: raise Exception, "Only PLC can create non delegated slivers."
def Destroy(sliver_name): """Destroy a non-PLC-instantiated sliver""" rec = sliver_name if rec['instantiation'] == 'delegated': account.get(rec['name']).ensure_destroyed() logger.log("api_calls: Destroy %s"%rec['name']) else: raise Exception("Only PLC can destroy non delegated slivers.")
def Create(sliver_name): """Create a non-PLC-instantiated sliver""" rec = sliver_name if rec["instantiation"] == "delegated": account.get(rec["name"]).ensure_created(rec) logger.log("api_calls: Create %s" % rec["name"]) else: raise Exception, "Only PLC can create non delegated slivers."
def Create(sliver_name): """Create a non-PLC-instantiated sliver""" rec = sliver_name if rec['instantiation'] == 'delegated': account.get(rec['name']).ensure_created(rec) logger.log("api_calls: Create %s"%rec['name']) else: raise Exception("Only PLC can create non delegated slivers.")
def Destroy(sliver_name): """Destroy a non-PLC-instantiated sliver""" rec = sliver_name if rec['instantiation'] == 'delegated': account.get(rec['name']).ensure_destroyed() logger.log("api_calls: Destroy %s" % rec['name']) else: raise Exception, "Only PLC can destroy non delegated slivers."
def sync(self): """Synchronize reality with the database contents. This method does a lot of things, and it's currently called after every single batch of database changes (a GetSlivers(), a loan, a record). It may be necessary in the future to do something smarter.""" # delete expired records now = time.time() for name, rec in list(self.items()): if rec.get('expires', now) < now: del self[name] self._compute_effective_rspecs() try: coresched = CoreSched() coresched.adjustCores(self) except: logger.log_exc("database: exception while doing core sched") # create and destroy accounts as needed logger.verbose("database: sync : fetching accounts") existing_acct_names = account.all() for name in existing_acct_names: if name not in self: logger.verbose("database: sync : ensure_destroy'ing %s"%name) account.get(name).ensure_destroyed() for name, rec in self.items(): # protect this; if anything fails for a given sliver # we still need the other ones to be handled try: sliver = account.get(name) logger.verbose("database: sync : looping on %s (shell account class from pwd %s)" %(name, sliver._get_class())) # Make sure we refresh accounts that are running if rec['instantiation'] == 'plc-instantiated': logger.verbose ("database: sync : ensure_create'ing 'instantiation' sliver %s"%name) sliver.ensure_created(rec) elif rec['instantiation'] == 'nm-controller': logger.verbose ("database: sync : ensure_create'ing 'nm-controller' sliver %s"%name) sliver.ensure_created(rec) # Back door to ensure PLC overrides Ticket in delegation. elif rec['instantiation'] == 'delegated' and sliver._get_class() != None: # if the ticket has been delivered and the nm-controller started the slice # update rspecs and keep them up to date. if sliver.is_running(): logger.verbose ("database: sync : ensure_create'ing 'delegated' sliver %s"%name) sliver.ensure_created(rec) except SystemExit as e: sys.exit(e) except: logger.log_exc("database: sync failed to handle sliver", name=name) # Wake up bwmom to update limits. bwmon.lock.set() global dump_requested dump_requested = True db_cond.notify()
def ReCreate(sliver_name): """Stop, Destroy, Create, Start sliver in order to reinstall it.""" rec = sliver_name account.get(rec["name"]).stop() account.get(rec["name"]).ensure_created(rec) account.get(rec["name"]).start(rec) logger.log("api_calls: ReCreate %s" % rec["name"])
def ReCreate(sliver_name): """Stop, Destroy, Create, Start sliver in order to reinstall it.""" rec = sliver_name account.get(rec['name']).stop() account.get(rec['name']).ensure_created(rec) account.get(rec['name']).start(rec) logger.log("api_calls: ReCreate %s" % rec['name'])
def suspend_slice(self, slicename): logger.log('reservation: Suspending slice %s'%(slicename)) self.debug_box('before suspending',slicename) worker=account.get(slicename) try: logger.log("reservation: Located worker object %r"%worker) worker.stop() except AttributeError: # when the underlying worker is not entirely initialized yet pass except: logger.log_exc("reservation.suspend_slice: Could not stop slice %s through its worker"%slicename) # we hope the status line won't return anything self.debug_box('after suspending',slicename)
def suspend_slice(self, slicename): logger.log('reservation: Suspending slice %s' % (slicename)) self.debug_box('before suspending', slicename) worker = account.get(slicename) try: logger.log("reservation: Located worker object %r" % worker) worker.stop() except AttributeError: # when the underlying worker is not entirely initialized yet pass except: logger.log_exc( "reservation.suspend_slice: Could not stop slice %s through its worker" % slicename) # we hope the status line won't return anything self.debug_box('after suspending', slicename)
def restart_slice(self, slicename): logger.log('reservation: Restarting slice %s'%(slicename)) self.debug_box('before restarting',slicename) worker=account.get(slicename) try: # dig in self.data to retrieve corresponding rec slivers = [ sliver for sliver in self.data['slivers'] if sliver['name']==slicename ] sliver=slivers[0] record=database.db.get(slicename) record['enabled']=True # logger.log("reservation: Located worker object %r"%worker) logger.log("reservation: Located record at the db %r"%record) worker.start(record) except: logger.log_exc("reservation.restart_slice: Could not start slice %s through its worker"%slicename) # we hope the status line won't return anything self.debug_box('after restarting',slicename)
def restart_slice(self, slicename): logger.log('reservation: Restarting slice %s' % (slicename)) self.debug_box('before restarting', slicename) worker = account.get(slicename) try: # dig in self.data to retrieve corresponding rec slivers = [ sliver for sliver in self.data['slivers'] if sliver['name'] == slicename ] sliver = slivers[0] record = database.db.get(slicename) record['enabled'] = True # logger.log("reservation: Located worker object %r" % worker) logger.log("reservation: Located record at the db %r" % record) worker.start(record) except: logger.log_exc( "reservation.restart_slice: Could not start slice %s through its worker" % slicename) # we hope the status line won't return anything self.debug_box('after restarting', slicename)
def is_running (self, slicename): try: return account.get(slicename).is_running() except: return False
def testget_account_exists(self): account.session = self.ses account.add(account.Account("spiritic", "123")) self.assert_(account.get("spiritic"))
def testget_account_doesnt_exist(self): account.session = self.ses self.assert_(not account.get("spiritic"))
def is_running(self, slicename): try: return account.get(slicename).is_running() except: return False
def testget_account_exists(self): account.session = self.ses account.add(account.Account("spiritic", "123" )) self.assert_( account.get("spiritic") )
def testget_account_doesnt_exist(self): account.session = self.ses self.assert_( not account.get("spiritic") )
def Stop(sliver_name): """Kill all processes belonging to the specified sliver""" rec = sliver_name account.get(rec["name"]).stop() logger.log("api_calls: Stop %s" % rec["name"])
def Stop(sliver_name): """Kill all processes belonging to the specified sliver""" rec = sliver_name account.get(rec['name']).stop() logger.log("api_calls: Stop %s" % rec['name'])
def sync(self): """Synchronize reality with the database contents. This method does a lot of things, and it's currently called after every single batch of database changes (a GetSlivers(), a loan, a record). It may be necessary in the future to do something smarter.""" # delete expired records now = time.time() for name, rec in self.items(): if rec.get('expires', now) < now: del self[name] self._compute_effective_rspecs() try: coresched = CoreSched() coresched.adjustCores(self) except: logger.log_exc("database: exception while doing core sched") # create and destroy accounts as needed logger.verbose("database: sync : fetching accounts") existing_acct_names = account.all() for name in existing_acct_names: if name not in self: logger.verbose("database: sync : ensure_destroy'ing %s" % name) account.get(name).ensure_destroyed() for name, rec in self.iteritems(): # protect this; if anything fails for a given sliver # we still need the other ones to be handled try: sliver = account.get(name) logger.verbose( "database: sync : looping on %s (shell account class from pwd %s)" % (name, sliver._get_class())) # Make sure we refresh accounts that are running if rec['instantiation'] == 'plc-instantiated': logger.verbose( "database: sync : ensure_create'ing 'instantiation' sliver %s" % name) sliver.ensure_created(rec) elif rec['instantiation'] == 'nm-controller': logger.verbose( "database: sync : ensure_create'ing 'nm-controller' sliver %s" % name) sliver.ensure_created(rec) # Back door to ensure PLC overrides Ticket in delegation. elif rec['instantiation'] == 'delegated' and sliver._get_class( ) != None: # if the ticket has been delivered and the nm-controller started the slice # update rspecs and keep them up to date. if sliver.is_running(): logger.verbose( "database: sync : ensure_create'ing 'delegated' sliver %s" % name) sliver.ensure_created(rec) except: logger.log_exc("database: sync failed to handle sliver", name=name) # Wake up bwmom to update limits. bwmon.lock.set() global dump_requested dump_requested = True db_cond.notify()
def Start(sliver_name): """Configure and start sliver.""" rec = sliver_name account.get(rec["name"]).start(rec) logger.log("api_calls: Start %s" % rec["name"])
def Start(sliver_name): """Configure and start sliver.""" rec = sliver_name account.get(rec['name']).start(rec) logger.log("api_calls: Start %s" % rec['name'])