def save(self): if self.is_empty(): Log.log_error('Cart is empty, not saving anything') return None json_body = json.dumps(self._cart_dict()) if os.path.exists(self.cart_file): Log.log_warn( "Cart file '%s' already exists, overwriting with new data." % self.cart_file) f = open(self.cart_file, 'w') f.write(json_body) f.flush() f.close() Log.log_info("Saved cart '%s'." % self.name)
def upload(self, path, repo, environment): pulp = UploadAPI(self.connection) unit_key, unit_metadata = self.generate_upload_data(path) name = os.path.basename(path) repo_id = "{0}-{1}".format(repo, environment) ################################################################ # Initialize upload ################################################################ response = pulp.initialize_upload() if response.response_code == Constants.PULP_POST_CREATED: Log.log_debug("Initialized upload process for %s" % name) else: raise SystemError("Failed to initialize upload process for %s" % name) upload_id = response.response_body['upload_id'] ################################################################ # Upload chunks w/ Constants.UPLOAD_AT_ONCE size ################################################################ size = os.path.getsize(path) rpm_fd = open(path, 'rb') total_seeked = 0 rpm_fd.seek(0) while total_seeked < size: chunk = rpm_fd.read(Constants.UPLOAD_AT_ONCE) last_offset = total_seeked total_seeked += len(chunk) Log.log_notice("Seeked %s data... (total seeked: %s)" % (len(chunk), total_seeked)) response = pulp.upload_segment(upload_id, last_offset, chunk) if response.response_code is not Constants.PULP_PUT_OK: Log.log_debug("Failed to upload %s" % name) raise SystemError("Failed to upload %s" % name) ################################################################ # Import upload ################################################################ response = pulp.import_upload(upload_id, repo_id, 'rpm', unit_key, unit_metadata) if response.response_code not in [ Constants.PULP_POST_OK, Constants.PULP_POST_ACCEPTED ]: Log.log_error("Failed to import upload for %s" % name) raise SystemError("Failed to import upload for %s" % name) Log.log_debug("RPM upload %s complete" % name) ################################################################ # Finalize upload by cleaning up request on server ################################################################ response = pulp.delete_upload(upload_id) if response.response_code != Constants.PULP_DELETE_OK: Log.log_error("Failed to clean up upload for %s" % name) raise SystemError("Failed to clean up upload for %s" % name) ################################################################ # Publish the repo ################################################################ pulp_repo = PulpRepo(self.connection) pulp_repo.publish(name=repo, environment=environment) ################################################################ # FIN ################################################################ Log.log_info("successfully uploaded %s" % name)
def upload(self, path, repo, environment): pulp = UploadAPI(self.connection) unit_key, unit_metadata = self.generate_upload_data(path) name = os.path.basename(path) repo_id = "{0}-{1}".format(repo, environment) ################################################################ # Initialize upload ################################################################ response = pulp.initialize_upload() if response.response_code == Constants.PULP_POST_CREATED: Log.log_debug("Initialized upload process for %s" % name) else: raise SystemError("Failed to initialize upload process for %s" % name) upload_id = response.response_body['upload_id'] ################################################################ # Upload chunks w/ Constants.UPLOAD_AT_ONCE size ################################################################ size = os.path.getsize(path) rpm_fd = open(path, 'rb') total_seeked = 0 rpm_fd.seek(0) while total_seeked < size: chunk = rpm_fd.read(Constants.UPLOAD_AT_ONCE) last_offset = total_seeked total_seeked += len(chunk) Log.log_notice("Seeked %s data... (total seeked: %s)" % (len(chunk), total_seeked)) response = pulp.upload_segment(upload_id, last_offset, chunk) if response.response_code is not Constants.PULP_PUT_OK: Log.log_debug("Failed to upload %s" % name) raise SystemError("Failed to upload %s" % name) ################################################################ # Import upload ################################################################ response = pulp.import_upload(upload_id, repo_id, 'rpm', unit_key, unit_metadata) if response.response_code not in [Constants.PULP_POST_OK, Constants.PULP_POST_ACCEPTED]: Log.log_error("Failed to import upload for %s" % name) raise SystemError("Failed to import upload for %s" % name) Log.log_debug("RPM upload %s complete" % name) ################################################################ # Finalize upload by cleaning up request on server ################################################################ response = pulp.delete_upload(upload_id) if response.response_code != Constants.PULP_DELETE_OK: Log.log_error("Failed to clean up upload for %s" % name) raise SystemError("Failed to clean up upload for %s" % name) ################################################################ # Publish the repo ################################################################ pulp_repo = PulpRepo(self.connection) pulp_repo.publish(name=repo, environment=environment) ################################################################ # FIN ################################################################ Log.log_info("successfully uploaded %s" % name)