def kill_bundles(self, bundle_uuids): ''' Send a kill command to all the given bundles. ''' check_has_all_permission_on_bundles(self.model, self._current_user(), bundle_uuids) for bundle_uuid in bundle_uuids: self.model.add_bundle_action(bundle_uuid, Command.KILL)
def chown_bundles(self, bundle_uuids, user_spec): ''' Set the owner of the bundles to the user. ''' check_has_all_permission_on_bundles(self.model, self._current_user(), bundle_uuids) user_info = self.user_info(user_spec) # Update bundles for bundle_uuid in bundle_uuids: bundle = self.model.get_bundle(bundle_uuid) self.model.update_bundle(bundle, {'owner_id': user_info['id']})
def delete_bundles(self, uuids, force, recursive, data_only, dry_run): ''' Delete the bundles specified by |uuids|. If |recursive|, add all bundles downstream too. If |data_only|, only remove from the bundle store, not the bundle metadata. ''' relevant_uuids = self.model.get_self_and_descendants(uuids, depth=sys.maxint) uuids_set = set(uuids) relevant_uuids_set = set(relevant_uuids) if not recursive: # If any descendants exist, then we only delete uuids if force = True. if (not force) and uuids_set != relevant_uuids_set: relevant = self.model.batch_get_bundles(uuid=(set(relevant_uuids) - set(uuids))) raise UsageError('Can\'t delete because the following bundles depend on %s:\n %s' % ( uuids, '\n '.join(bundle.simple_str() for bundle in relevant), )) relevant_uuids = uuids check_has_all_permission_on_bundles(self.model, self._current_user(), relevant_uuids) # Get data hashes relevant_data_hashes = set(bundle.data_hash for bundle in self.model.batch_get_bundles(uuid=relevant_uuids) if bundle.data_hash) # Delete the actual bundle if not dry_run: if data_only: # Just remove references to the data hashes self.model.remove_data_hash_references(relevant_uuids) else: # Actually delete the bundle self.model.delete_bundles(relevant_uuids) # Delete the data_hash for data_hash in relevant_data_hashes: self.bundle_store.cleanup(self.model, data_hash, relevant_uuids, dry_run) return relevant_uuids
def update_bundle_metadata(self, uuid, metadata): check_has_all_permission_on_bundles(self.model, self._current_user(), [uuid]) bundle = self.model.get_bundle(uuid) self.validate_user_metadata(bundle, metadata) self.model.update_bundle(bundle, {'metadata': metadata})