Exemplo n.º 1
0
    def __init__(self,
                 name,
                 description=None,
                 autoload=False,
                 autosync=False,
                 autosave=False):
        self.name = name
        self.cart_file = os.path.join(Constants.CART_LOCATION,
                                      "%s.json" % self.name)
        self.repo_items_hash = {}
        self.remotes_storage = os.path.expanduser(
            os.path.join(Constants.CART_LOCATION, "%s-remotes" % self.name))

        if autoload:
            Log.log_notice("[CART:%s] Auto-loading cart items" % self.name)
            self.load()

        if description is not None:
            for repo_items in description:
                (repo, items) = (repo_items[0], repo_items[1:])
                Log.log_debug("Processing %s input items for repo %s" %
                              (len(items), repo))
                self[repo] = items
            if autosave:
                self.save()
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)