def delete_pool(pool_name): """ Deletes a system pool :param pool_name: System pool's name """ pool = _get_pool_by_name(pool_name, lockmode='update') u = identity.current.user if not pool.can_edit(u): raise Forbidden403('Cannot delete pool %s' % pool_name) systems = System.query.filter(System.pools.contains(pool)) System.record_bulk_activity(systems, user=identity.current.user, service=u'HTTP', action=u'Removed', field=u'Pool', old=unicode(pool), new=None) # Since we are deleting the pool, we will have to change the active # access policy for all systems using the pool's policy to their # custom policy systems = System.query.filter(System.active_access_policy == pool.access_policy) for system in systems: system.active_access_policy = system.custom_access_policy System.record_bulk_activity(systems, user=identity.current.user, service=u'HTTP', field=u'Active Access Policy', action=u'Changed', old = 'Pool policy: %s' % pool_name, new = 'Custom access policy') session.delete(pool) activity = Activity(u, u'HTTP', u'Deleted', u'Pool', pool_name) session.add(activity) return '', 204
def remove(self, id, *args, **kw): labcontroller = LabController.by_id(id) labcontroller.removed = datetime.utcnow() # de-associate systems systems = System.query.filter(System.lab_controller == labcontroller) System.record_bulk_activity(systems, user=identity.current.user, service=u'WEBUI', action=u'Changed', field=u'lab_controller', old=labcontroller.fqdn, new=None) systems.update({'lab_controller_id': None}, synchronize_session=False) # cancel running recipes watchdogs = Watchdog.by_status(labcontroller=labcontroller, status='active') for w in watchdogs: w.recipe.recipeset.job.cancel(msg='LabController %s has been deleted' % labcontroller.fqdn) # remove distro trees distro_tree_assocs = LabControllerDistroTree.query\ .filter(LabControllerDistroTree.lab_controller == labcontroller)\ .join(LabControllerDistroTree.distro_tree) DistroTree.record_bulk_activity(distro_tree_assocs, user=identity.current.user, service=u'WEBUI', action=u'Removed', field=u'lab_controller_assocs', old=labcontroller.fqdn, new=None) distro_tree_assocs.delete(synchronize_session=False) labcontroller.disabled = True labcontroller.record_activity(user=identity.current.user, service=u'WEBUI', field=u'Disabled', action=u'Changed', old=unicode(False), new=unicode(True)) labcontroller.record_activity(user=identity.current.user, service=u'WEBUI', field=u'Removed', action=u'Changed', old=unicode(False), new=unicode(True)) flash( _(u"%s removed") % labcontroller.fqdn ) raise redirect(".")
def remove_labcontroller(labcontroller): """ Disables and marks a lab controller as removed. """ labcontroller.removed = datetime.utcnow() systems = System.query.filter(System.lab_controller == labcontroller) # Record systems set to status=broken. Trigger any event listener listening # for status changes. for sys in systems: sys.mark_broken('Lab controller de-associated') sys.abort_queued_commands("System disassociated from lab controller") # de-associate systems System.record_bulk_activity(systems, user=identity.current.user, service=u'HTTP', action=u'Changed', field=u'Lab Controller', old=labcontroller.fqdn, new=None) systems.update({'lab_controller_id': None}, synchronize_session=False) # cancel running recipes watchdogs = Watchdog.by_status(labcontroller=labcontroller, status='active') for w in watchdogs: w.recipe.recipeset.job.cancel( msg='Lab controller %s has been deleted' % labcontroller.fqdn) # remove distro trees distro_tree_assocs = LabControllerDistroTree.query\ .filter(LabControllerDistroTree.lab_controller == labcontroller) DistroTree.record_bulk_activity(distro_tree_assocs.join( LabControllerDistroTree.distro_tree), user=identity.current.user, service=u'HTTP', action=u'Removed', field=u'lab_controller_assocs', old=labcontroller.fqdn, new=None) distro_tree_assocs.delete(synchronize_session=False) labcontroller.disabled = True labcontroller.record_activity(user=identity.current.user, service=u'HTTP', field=u'Disabled', action=u'Changed', old=unicode(False), new=unicode(True)) labcontroller.record_activity(user=identity.current.user, service=u'HTTP', field=u'Removed', action=u'Changed', old=unicode(False), new=unicode(True))
def remove_labcontroller(labcontroller): """ Disables and marks a lab controller as removed. """ labcontroller.removed = datetime.utcnow() # de-associate systems systems = System.query.filter(System.lab_controller == labcontroller) System.record_bulk_activity(systems, user=identity.current.user, service=u'HTTP', action=u'Changed', field=u'lab_controller', old=labcontroller.fqdn, new=None) systems.update({'lab_controller_id': None}, synchronize_session=False) # cancel running recipes watchdogs = Watchdog.by_status(labcontroller=labcontroller, status='active') for w in watchdogs: w.recipe.recipeset.job.cancel(msg='LabController %s has been deleted' % labcontroller.fqdn) # remove distro trees distro_tree_assocs = LabControllerDistroTree.query\ .filter(LabControllerDistroTree.lab_controller == labcontroller)\ .join(LabControllerDistroTree.distro_tree) DistroTree.record_bulk_activity(distro_tree_assocs, user=identity.current.user, service=u'HTTP', action=u'Removed', field=u'lab_controller_assocs', old=labcontroller.fqdn, new=None) distro_tree_assocs.delete(synchronize_session=False) labcontroller.disabled = True labcontroller.record_activity(user=identity.current.user, service=u'HTTP', field=u'Disabled', action=u'Changed', old=unicode(False), new=unicode(True)) labcontroller.record_activity(user=identity.current.user, service=u'HTTP', field=u'Removed', action=u'Changed', old=unicode(False), new=unicode(True))
def remove_labcontroller(labcontroller): """ Disables and marks a lab controller as removed. """ labcontroller.removed = datetime.utcnow() systems = System.query.filter(System.lab_controller == labcontroller) # Record systems set to status=broken. Trigger any event listener listening # for status changes. for sys in systems: sys.mark_broken('Lab controller de-associated') # de-associate systems System.record_bulk_activity(systems, user=identity.current.user, service=u'HTTP', action=u'Changed', field=u'Lab Controller', old=labcontroller.fqdn, new=None) systems.update({'lab_controller_id': None}, synchronize_session=False) # cancel running recipes watchdogs = Watchdog.by_status(labcontroller=labcontroller, status='active') for w in watchdogs: w.recipe.recipeset.job.cancel(msg='Lab controller %s has been deleted' % labcontroller.fqdn) # remove distro trees distro_tree_assocs = LabControllerDistroTree.query\ .filter(LabControllerDistroTree.lab_controller == labcontroller)\ .join(LabControllerDistroTree.distro_tree) DistroTree.record_bulk_activity( distro_tree_assocs, user=identity.current.user, service=u'HTTP', action=u'Removed', field=u'lab_controller_assocs', old=labcontroller.fqdn, new=None) distro_tree_assocs.delete(synchronize_session=False) labcontroller.disabled = True labcontroller.record_activity( user=identity.current.user, service=u'HTTP', field=u'Disabled', action=u'Changed', old=unicode(False), new=unicode(True)) labcontroller.record_activity( user=identity.current.user, service=u'HTTP', field=u'Removed', action=u'Changed', old=unicode(False), new=unicode(True))