예제 #1
0
파일: PulpRepo.py 프로젝트: yithian/juicer
    def create(self, name, environment, checksumtype='sha256'):
        repo_id = "{0}-{1}".format(name, environment)
        relative_url = "/{0}/{1}/".format(environment, name)
        checksumtype = checksumtype

        pulp = RepositoryAPI(self.connection)
        response = pulp.create_and_configure(
            id=repo_id,
            display_name=name,
            description=repo_id,
            notes={'_repo-type': 'rpm-repo'},
            importer_type_id='yum_importer',
            importer_config={},
            distributors=[{'distributor_id': 'yum_distributor',
                           'distributor_type_id': 'yum_distributor',
                           'distributor_config': {
                               'relative_url': relative_url,
                               'http': True,
                               'https': True,
                               'checksum_type': checksumtype
                           },
                           'auto_publish': True,
                           'relative_path': relative_url
                       }]
        )

        if response.response_code == Constants.PULP_POST_CREATED:
            Log.log_info("%s created in %s", name, environment)
        else:
            Log.log_info("failed to create %s in %s", name, environment)
            Log.log_debug(response)
예제 #2
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()
예제 #3
0
    def run(self):
        from pulp.bindings.repository import RepositoryAPI

        for environment in self.args.environment:
            repo_id = "{0}-{1}".format(self.args.repo, environment)

            pulp = RepositoryAPI(self.connections[environment])
            response = pulp.delete(repo_id)

            if response.response_code == Constants.PULP_DELETE_ACCEPTED:
                Log.log_info("%s deleted in %s", self.args.repo, environment)
            else:
                Log.log_info("failed to delete %s in %s", self.args.repo, environment)
                Log.log_debug(response)
예제 #4
0
파일: RPM.py 프로젝트: yithian/juicer
    def sync(self, destination):
        dest_file = os.path.join(destination, self.name)

        # This is the case with stuff that already exists locally
        if self.synced and self.source:
            pass

        if not os.path.exists(destination):
            os.mkdir(destination)

        self.path = dest_file
        Log.log_debug("Beginning remote->local sync: %s->%s" % (self.source, self.path))
        juicer.utils.save_url_as(self.source, dest_file)
        self.modified = True
        self.synced = True
예제 #5
0
    def add_repo(self, repo_name, items):
        """
        Build up repos

        `name` - Name of this repo.
        `items` - List of paths to rpm.
        """
        Log.log_debug("[CART:%s] Adding %s items to repo '%s'" %
                      (self.name, len(items), repo_name))
        # Is some sort of validation required here?
        cart_items = []
        for item in items:
            Log.log_debug("Creating CartObject for %s" % item)
            rpm = RPM(item)
            cart_items.append(rpm)
        self.repo_items_hash[repo_name] = cart_items
예제 #6
0
    def sync(self, destination):
        dest_file = os.path.join(destination, self.name)

        # This is the case with stuff that already exists locally
        if self.synced and self.source:
            pass

        if not os.path.exists(destination):
            os.mkdir(destination)

        self.path = dest_file
        Log.log_debug("Beginning remote->local sync: %s->%s" %
                      (self.source, self.path))
        juicer.utils.save_url_as(self.source, dest_file)
        self.modified = True
        self.synced = True
예제 #7
0
    def run(self):
        from pulp.bindings.repository import RepositoryActionsAPI

        for environment in self.args.environment:
            repo_id = "{0}-{1}".format(self.args.repo, environment)
            display_name = self.args.repo

            pulp = RepositoryActionsAPI(self.connections[environment])
            response = pulp.publish(repo_id, 'yum_distributor', {})

            if response.response_code == Constants.PULP_POST_ACCEPTED:
                Log.log_info("%s published in %s", display_name, environment)
            else:
                Log.log_info("failed to publish %s in %s", display_name,
                             environment)
                Log.log_debug(response)
예제 #8
0
    def run(self):
        from pulp.bindings.repository import RepositoryAPI
        from pulp.bindings.repository import RepositoryActionsAPI

        for environment in self.args.environment:
            repo_id = "{0}-{1}".format(self.args.repo, environment)
            display_name = self.args.repo
            relative_url = "/{0}/{1}/".format(environment, self.args.repo)
            checksum_type = self.args.checksum_type

            pulp = RepositoryAPI(self.connections[environment])
            response = pulp.create_and_configure(
                id=repo_id,
                display_name=display_name,
                description=repo_id,
                notes={'_repo-type': 'rpm-repo'},
                importer_type_id='yum_importer',
                importer_config={},
                distributors=[{
                    'distributor_id': 'yum_distributor',
                    'distributor_type_id': 'yum_distributor',
                    'distributor_config': {
                        'relative_url': relative_url,
                        'http': True,
                        'https': True,
                        'checksum_type': checksum_type
                    },
                    'auto_publish': True,
                    'relative_path': relative_url
                }])

            if response.response_code == Constants.PULP_POST_CREATED:
                Log.log_info("%s created in %s", display_name, environment)
            else:
                Log.log_info("failed to create %s in %s", display_name,
                             environment)
                Log.log_debug(response)

            pulp = RepositoryActionsAPI(self.connections[environment])
            response = pulp.publish(repo_id, 'yum_distributor', {})

            if response.response_code == Constants.PULP_POST_ACCEPTED:
                Log.log_info("%s published in %s", display_name, environment)
            else:
                Log.log_info("failed to publish %s in %s", display_name,
                             environment)
                Log.log_debug(response)
예제 #9
0
    def run(self):
        from pulp.bindings.repository import RepositoryAPI
        from pulp.bindings.repository import RepositoryActionsAPI

        for environment in self.args.environment:
            repo_id = "{0}-{1}".format(self.args.repo, environment)
            display_name = self.args.repo
            relative_url = "/{0}/{1}/".format(environment, self.args.repo)
            checksum_type = self.args.checksum_type

            pulp = RepositoryAPI(self.connections[environment])
            response = pulp.create_and_configure(
                id=repo_id,
                display_name=display_name,
                description=repo_id,
                notes={'_repo-type': 'rpm-repo'},
                importer_type_id='yum_importer',
                importer_config={},
                distributors=[{'distributor_id': 'yum_distributor',
                               'distributor_type_id': 'yum_distributor',
                               'distributor_config': {
                                   'relative_url': relative_url,
                                   'http': True,
                                   'https': True,
                                   'checksum_type': checksum_type
                               },
                               'auto_publish': True,
                               'relative_path': relative_url
                           }]
            )

            if response.response_code == Constants.PULP_POST_CREATED:
                Log.log_info("%s created in %s", display_name, environment)
            else:
                Log.log_info("failed to create %s in %s", display_name, environment)
                Log.log_debug(response)

            pulp = RepositoryActionsAPI(self.connections[environment])
            response = pulp.publish(repo_id, 'yum_distributor', {})

            if response.response_code == Constants.PULP_POST_ACCEPTED:
                Log.log_info("%s published in %s", display_name, environment)
            else:
                Log.log_info("failed to publish %s in %s", display_name, environment)
                Log.log_debug(response)
예제 #10
0
파일: PulpRepo.py 프로젝트: yithian/juicer
    def create(self, name, environment, checksumtype='sha256'):
        repo_id = "{0}-{1}".format(name, environment)
        relative_url = "/{0}/{1}/".format(environment, name)
        checksumtype = checksumtype

        pulp = RepositoryAPI(self.connection)
        response = pulp.create_and_configure(id=repo_id,
                                             display_name=name,
                                             description=repo_id,
                                             notes={'_repo-type': 'rpm-repo'},
                                             importer_type_id='yum_importer',
                                             importer_config={},
                                             distributors=[{
                                                 'distributor_id':
                                                 'yum_distributor',
                                                 'distributor_type_id':
                                                 'yum_distributor',
                                                 'distributor_config': {
                                                     'relative_url':
                                                     relative_url,
                                                     'http': True,
                                                     'https': True,
                                                     'checksum_type':
                                                     checksumtype
                                                 },
                                                 'auto_publish':
                                                 True,
                                                 'relative_path':
                                                 relative_url
                                             }])

        if response.response_code == Constants.PULP_POST_CREATED:
            Log.log_info("%s created in %s", name, environment)
        else:
            Log.log_info("failed to create %s in %s", name, environment)
            Log.log_debug(response)
예제 #11
0
파일: PulpRepo.py 프로젝트: yithian/juicer
    def publish(self, name, environment):
        repo_id = "{0}-{1}".format(name, environment)
        pulp = RepositoryActionsAPI(self.connection)
        response = pulp.publish(repo_id, 'yum_distributor', {})

        if response.response_code == Constants.PULP_POST_ACCEPTED:
            Log.log_debug("%s published in %s", name, environment)
        else:
            Log.log_debug("failed to publish %s in %s", name, environment)
            Log.log_debug(response)
예제 #12
0
파일: PulpRepo.py 프로젝트: yithian/juicer
    def publish(self, name, environment):
        repo_id = "{0}-{1}".format(name, environment)
        pulp = RepositoryActionsAPI(self.connection)
        response = pulp.publish(repo_id, 'yum_distributor', {})

        if response.response_code == Constants.PULP_POST_ACCEPTED:
            Log.log_debug("%s published in %s", name, environment)
        else:
            Log.log_debug("failed to publish %s in %s", name, environment)
            Log.log_debug(response)
예제 #13
0
    def delete(self):
        """
        Remove all trace of this cart: delete the file(s) on the local
        filesystem and delete the entry from the database
        """
        Log.log_debug("Deleting cart %s" % self.name)

        # rm -r self.remotes_storage()
        if os.path.exists(self.remotes_storage):
            for item in os.listdir(self.remotes_storage):
                ipath = os.path.expanduser(self.remotes_storage + '/' + item)
                if os.path.exists(ipath):
                    Log.log_debug("removing %s" % ipath)
                    os.remove(ipath)
                Log.log_debug("removing %s's remote item storage dir" %
                              self.name)
                os.rmdir(self.remotes_storage)

        # rm cart_file()
        if os.path.exists(self.cart_file):
            Log.log_debug("removing %s's cart file" % self.name)
            os.remove(self.cart_file)
예제 #14
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)
예제 #15
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)