@@ -287,7 +287,7 @@ class PulpContext:
287287 It is an abstraction layer for api access and output handling.
288288
289289 Parameters:
290- api_root: The base url (excluding "api/v3 /") to the servers api.
290+ api_root: The base url (excluding "api/{version} /") to the servers api.
291291 api_kwargs: Extra arguments to pass to the wrapped `OpenAPI` object.
292292 background_tasks: Whether to wait for tasks. If `True`, all tasks triggered will
293293 immediately raise `PulpNoWait`.
@@ -297,6 +297,7 @@ class PulpContext:
297297 Where possible, instead of failing, the requested result will be faked.
298298 This implies `dry_run=True` on the `api_kwargs`.
299299 verify_ssl: A boolean or a path to the CA bundle.
300+ api-version: Version of the Pulp API to talk to (e.g., "v3")
300301 """
301302
302303 def echo (self , message : str , nl : bool = True , err : bool = False ) -> None :
@@ -328,8 +329,10 @@ def __init__(
328329 verify_ssl : bool | str | None = None ,
329330 verify : bool | str | None = None , # Deprecated
330331 chunk_size : int | None = None ,
332+ api_version : str | None = "v3" ,
331333 ) -> None :
332334 self ._api : OpenAPI | None = None
335+ self ._api_version = api_version
333336 self ._api_root : str = api_root
334337 self ._api_kwargs = api_kwargs
335338 self .verify_ssl = verify_ssl
@@ -353,6 +356,7 @@ def __init__(
353356 self .fake_mode : bool = fake_mode
354357 if self .fake_mode :
355358 self ._api_kwargs ["dry_run" ] = True
359+ self ._api_kwargs ["api_version" ] = self ._api_version
356360 self .chunk_size = chunk_size
357361
358362 @classmethod
@@ -435,6 +439,7 @@ def from_config(cls, config: dict[str, t.Any]) -> "t.Self":
435439 api_root = config .get ("api_root" , "/pulp/" ),
436440 domain = config .get ("domain" , "default" ),
437441 verify_ssl = config .get ("verify_ssl" , True ),
442+ api_version = config .get ("api_version" , "v3" ),
438443 api_kwargs = api_kwargs ,
439444 )
440445
@@ -453,8 +458,8 @@ def domain_enabled(self) -> bool:
453458 @property
454459 def api_path (self ) -> str :
455460 if self .domain_enabled :
456- return self ._api_root + self .pulp_domain + " /api/v3 /"
457- return self ._api_root + " api/v3 /"
461+ return f" { self ._api_root } { self .pulp_domain } /api/{ self . _api_version } /"
462+ return f" { self ._api_root } api/{ self . _api_version } /"
458463
459464 @property
460465 def api (self ) -> OpenAPI :
@@ -481,7 +486,7 @@ def api(self) -> OpenAPI:
481486 )
482487 try :
483488 self ._api = OpenAPI (
484- doc_path = f"{ self ._api_root } api/v3 /docs/api.json" ,
489+ doc_path = f"{ self ._api_root } api/{ self . _api_version } /docs/api.json" ,
485490 verify_ssl = self .verify_ssl ,
486491 patch_api_hook = _patch_api_hook ,
487492 ** self ._api_kwargs ,
@@ -535,6 +540,7 @@ def call(
535540 if "pulp_domain" in self .api .param_spec (operation_id , "path" , required = True ):
536541 parameters ["pulp_domain" ] = self .pulp_domain
537542 parameters = preprocess_payload (parameters )
543+
538544 if body is not None :
539545 body = preprocess_payload (body )
540546 try :
0 commit comments