def deleteSoftwareProfile(self, name): """ Delete softwareProfile from the db. Returns: None Throws: SoftwareProfileNotFound DbError """ session = DbManager().openSession() try: # This role of this lookup is twofold. One, it validates # the existence of the software profile to be deleted and # second, gets the id for looking up any associated nodes dbSwProfile = self._softwareProfilesDbHandler.\ getSoftwareProfile(session, name) if dbSwProfile.nodes: # The software profile cannot be removed while # associated # nodes exist raise TortugaException('Unable to delete software profile with' ' associated nodes') if dbSwProfile.isIdle: # Ensure this software profile is not associated with # a hardware profile if dbSwProfile.hwprofileswithidle: # This software profile is associated with one # or more hardware profiles raise TortugaException( 'Unable to delete software profile.' ' This software profile is associated' ' with one or more hardware profiles: [%s]' % (' '.join([ hwprofile.name for hwprofile in dbSwProfile.hwprofileswithidle ]))) # Proceed with software profile deletion self.getLogger().debug( 'Marking software profile [%s] for deletion' % (name)) session.delete(dbSwProfile) session.commit() except TortugaException as ex: session.rollback() raise except Exception as ex: session.rollback() self.getLogger().exception('%s' % ex) raise finally: DbManager().closeSession()
def deleteHardwareProfile(self, name): """ Delete hardwareProfile from the db. Returns: None Throws: HardwareProfileNotFound DbError TortugaException """ session = DbManager().openSession() try: hwProfile = self._hardwareProfilesDbHandler.getHardwareProfile( session, name) if hwProfile.nodes: raise TortugaException( 'Unable to remove hardware profile with associated' ' nodes') # First delete the mappings hwProfile.mappedsoftwareprofiles = [] self.getLogger().debug( 'Marking hardware profile [%s] for deletion' % (name)) session.delete(hwProfile) session.commit() except TortugaException as ex: session.rollback() raise except Exception as ex: session.rollback() self.getLogger().exception('%s' % ex) raise finally: DbManager().closeSession()
def process_delete_host_request(request): session = DbManager().openSession() try: req = NodeRequestsDbHandler().get_by_addHostSession( session, request['transaction_id']) if req is None: # Session was deleted prior to being process. Nothing to do... return ahm.update_session(request['transaction_id'], running=True) logger.debug('process_delete_host_request(): transaction_id=[{0}],' ' nodespec=[{1}]'.format(request['transaction_id'], request['nodespec'])) try: NodeApi().deleteNode(request['nodespec']) ahm.delete_session(request['transaction_id']) session.delete(req) except NodeNotFound: ahm.delete_session(request['transaction_id']) session.delete(req) except TortugaException as exc: logger.exception('Exception while deleting nodes') req.message = str(exc) req.state = 'error' req.last_update = datetime.datetime.utcnow() finally: ahm.update_session(request['transaction_id'], running=False) finally: session.commit() DbManager().closeSession()