-
Notifications
You must be signed in to change notification settings - Fork 25
Support pulp sync repository operation #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
20ca414
46a8bcb
90c1034
117aa49
9493d86
b19e954
665d3dd
3f174ee
ed53060
80a3887
54c2cad
a385ae1
e578582
aa040a8
13bd181
55d50ea
d207a3e
40fbdea
cd2bda0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -229,7 +229,7 @@ def _search( | |
| search_type="search", | ||
| search_options=None, | ||
| criteria=None, | ||
| ): | ||
| ): # pylint:disable = too-many-arguments | ||
| url = os.path.join( | ||
| self._url, "pulp/api/v2/%s/%s/" % (resource_type, search_type) | ||
| ) | ||
|
|
@@ -565,3 +565,18 @@ def map_404_to_none(exception): | |
| ) | ||
|
|
||
| return f_map(response, error_fn=map_404_to_none) | ||
|
|
||
| def _do_sync(self, repo_id, sync_options): | ||
| if not sync_options["feed"]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have this check actually?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, I wanted to do this "user-friendly" and fails asap if there's obvious error. As you said feed can be used from importer but to do that I would have to implement the model and another support code, which is something I'm not that much willing to do now due lots of changes needed in another projects right now. So I thought we still override feed everytime so let's check that feed is not empty here and in the future we can implement importer model in repository model.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't mean that this library needs to fetch the importer and use it to initialize feed - I meant that you can just do a sync request to Pulp without including any feed, and it'll work if the importer already has a feed or it'll return a meaningful error if it doesn't. So you wouldn't have to add Importer models yet. In any case though, I don't consider this a blocker for the merge request, seeing as it can be easily changed later without breaking compatibility. |
||
| raise ValueError("Cannot sync with empty feed: '%s'" % sync_options["feed"]) | ||
|
|
||
| url = os.path.join( | ||
| self._url, "pulp/api/v2/repositories/%s/actions/sync/" % repo_id | ||
| ) | ||
|
|
||
| body = {"override_config": sync_options} | ||
|
|
||
| LOG.debug("Syncing repository %s with feed %s", repo_id, sync_options["feed"]) | ||
| return self._task_executor.submit( | ||
| self._do_request, method="POST", url=url, json=body | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| from .base import Repository, PublishOptions | ||
| from .container import ContainerImageRepository | ||
| from .yum import YumRepository | ||
| from .file import FileRepository | ||
| from .base import Repository, PublishOptions, SyncOptions | ||
| from .container import ContainerImageRepository, ContainerSyncOptions | ||
| from .yum import YumRepository, YumSyncOptions | ||
| from .file import FileRepository, FileSyncOptions |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,10 @@ | ||
| import datetime | ||
| import logging | ||
|
|
||
| from attr import validators | ||
| from attr import validators, asdict | ||
| from more_executors.futures import f_proxy | ||
|
|
||
| from ..common import ( | ||
| PulpObject, | ||
| Deletable, | ||
| DetachedException, | ||
| ) | ||
| from ..common import PulpObject, Deletable, DetachedException | ||
| from ..attr import pulp_attrib | ||
| from ..distributor import Distributor | ||
| from ..frozenlist import FrozenList | ||
|
|
@@ -62,6 +58,55 @@ class PublishOptions(object): | |
| """ | ||
|
|
||
|
|
||
| @attr.s(kw_only=True, frozen=True) | ||
| class SyncOptions(object): | ||
| """Options controlling a repository | ||
| :meth:`~pubtools.pulplib.Repository.sync`. | ||
| """ | ||
|
|
||
| feed = pulp_attrib(type=str) | ||
rohanpm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """URL where the repository's content will be synchronized from. | ||
| """ | ||
|
|
||
| ssl_validation = pulp_attrib(default=None, type=bool) | ||
| """Indicates if the server's SSL certificate is verified against the CA certificate uploaded. | ||
| """ | ||
|
|
||
| ssl_ca_cert = pulp_attrib(default=None, type=str) | ||
| """CA certificate string used to validate the feed source's SSL certificate | ||
| """ | ||
|
|
||
| ssl_client_cert = pulp_attrib(default=None, type=str) | ||
| """Certificate used as the client certificate when synchronizing the repository | ||
| """ | ||
|
|
||
| ssl_client_key = pulp_attrib(default=None, type=str) | ||
| """Private key to the certificate specified in ssl_client_cert | ||
| """ | ||
|
|
||
| max_speed = pulp_attrib(default=None, type=int) | ||
| """The maximum download speed in bytes/sec for a task (such as a sync). | ||
|
|
||
| Default is None | ||
| """ | ||
|
|
||
| proxy_host = pulp_attrib(default=None, type=str) | ||
| """A string representing the URL of the proxy server that should be used when synchronizing | ||
| """ | ||
|
|
||
| proxy_port = pulp_attrib(default=None, type=int) | ||
| """An integer representing the port that should be used when connecting to proxy_host. | ||
| """ | ||
|
|
||
| proxy_username = pulp_attrib(default=None, type=str) | ||
| """A string representing the username that should be used to authenticate with the proxy server | ||
| """ | ||
|
|
||
| proxy_password = pulp_attrib(default=None, type=str) | ||
| """A string representing the password that should be used to authenticate with the proxy server | ||
| """ | ||
|
|
||
|
|
||
| @attr.s(kw_only=True, frozen=True) | ||
| class Repository(PulpObject, Deletable): | ||
| """Represents a Pulp repository.""" | ||
|
|
@@ -168,7 +213,7 @@ def _check_repo_id(self, _, value): | |
| for distributor in value: | ||
| if not distributor.repo_id: | ||
| return | ||
| elif distributor.repo_id == self.id: | ||
| if distributor.repo_id == self.id: | ||
| return | ||
| raise ValueError( | ||
| "repo_id doesn't match for %s. repo_id: %s, distributor.repo_id: %s" | ||
|
|
@@ -343,6 +388,34 @@ def publish(self, options=PublishOptions()): | |
|
|
||
| return f_proxy(self._client._publish_repository(self, to_publish)) | ||
|
|
||
| def sync(self, options=SyncOptions(feed="")): | ||
| """Sync repository with feed | ||
|
|
||
| Args: | ||
| options (SyncOptions) | ||
| Options used to customize the behavior of sync process. | ||
| If omitted, the Pulp server's defaults apply. | ||
|
|
||
| Returns: | ||
| Future[list[:class:`~pubtools.pulplib.Task`]] | ||
| A future which is resolved when sync succeeds. | ||
|
|
||
| The future contains a list of zero or more tasks triggered and awaited | ||
| during the sync operation. | ||
|
|
||
| Raises: | ||
| DetachedException | ||
| If this instance is not attached to a Pulp client. | ||
| """ | ||
| if not self._client: | ||
| raise DetachedException() | ||
|
|
||
| return f_proxy( | ||
| self._client._do_sync( | ||
| self.id, asdict(options, filter=lambda name, val: val is not None) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not wrong or anything, but kinda curious why you chose to convert to dict here and not when you set override_config.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in all _do method I observed (and maybe I'm wrong) that all arguments are basic types (str, int, dict,...) so I wanted to stick with that. |
||
| ) | ||
| ) | ||
|
|
||
| def remove_content(self, **kwargs): | ||
| """Remove all content of requested types from this repository. | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.