lavatory.utils package¶
Submodules¶
lavatory.utils.artifactory module¶
Artifactory purger module.
-
class
lavatory.utils.artifactory.
Artifactory
(repo_name=None)[source]¶ Bases:
object
Artifactory purger class.
-
count_based_retention
(retention_count=None, project_depth=2, artifact_depth=3, item_type='folder', extra_aql=None)[source]¶ Return all artifacts except the <count> most recent.
Parameters: - retention_count (int) – Number of artifacts to keep.
- project_depth (int) – how far down the Artifactory folder hierarchy to look for projects.
- artifact_depth (int) – how far down the Artifactory folder hierarchy to look for specific artifacts.
- item_type (str) – The item type to search for (file/folder/any).
- extra_aql (list) –
Returns: List of all artifacts to delete.
Return type: list
-
filter
(terms=None, depth=3, sort=None, offset=0, limit=0, fields=None, item_type='folder')[source]¶ Get a subset of artifacts from the specified repo. This looks at the project level, but actually need to iterate lower at project level
This method does not use pagination. It assumes that this utility will be called on a repo sufficiently frequently that removing just the default n items will be enough.
Parameters: - terms (list) – an array of jql snippets that will be ANDed together
- depth (int, optional) – how far down the folder hierarchy to look
- fields (list) – Fields
- sort (dict) – How to sort Artifactory results
- offset (int) – how many items from the beginning of the list should be skipped (optional)
- limit (int) – the maximum number of entries to return (optional)
- item_type (str) – The item type to search for (file/folder/any).
Returns: List of artifacts returned from query
Return type: list
-
get_all_repo_artifacts
(depth=None, item_type='file', with_properties=True)[source]¶ returns all artifacts in a repo with metadata
Parameters: - depth (int) – How far down Artifactory folder to look. None will go to bottom of folder.
- item_type (str) – The item type to search for (file/folder/any).
- with_properties (bool) – Include artifact properties or not.
Returns: List of all artifacts in a repository.
Return type: list
-
get_artifact_properties
(artifact)[source]¶ Given an artifact, queries for properties from artifact URL
Parameters: artifact (dict) – Dictionary of artifact info. Needs artifact[‘name’] and [‘path’]. Returns: Dictionary of all properties on specific artifact Return type: dict
-
move_artifacts
(artifacts=None, dest_repository=None)[source]¶ Moves a list of artifacts to dest_repository.
Parameters: - artifacts (list) – List of artifacts to move.
- dest_repository (str) – The name of the destination repo.
-
purge
(dry_run, artifacts)[source]¶ Purge artifacts from the specified repo.
Parameters: - dry_run (bool) – Dry run mode True/False
- artifacts (list) – Artifacts.
Returns: Count purged.
Return type: purged (int)
-
repos
(repo_type='local')[source]¶ Return a dictionary of repos with basic info about each.
Parameters: repo_type (str) – Type of repository to list. (local/virtual/cache/any) Returns: Dictionary of repos. Return type: repos (dict)
-
time_based_retention
(keep_days=None, time_field='created', item_type='file', extra_aql=None)[source]¶ Retains artifacts based on number of days since creation.
extra_aql example: [{“@deployed”: {“$match”: “dev”}}, {“@deployed”: {“$nmatch”: “prod”}}] This would search for artifacts that were created after <keep_days> with property “deployed” equal to dev and not equal to prod.Parameters: - keep_days (int) – Number of days to keep an artifact.
- time_field (str) – The field of time to look at (created, modified, stat.downloaded).
- item_type (str) – The item type to search for (file/folder/any).
- extra_aql (list) –
Returns: List of artifacts matching retention policy
Return type: list
-
lavatory.utils.get_artifactory_info module¶
Helper method for getting artifactory information.
-
lavatory.utils.get_artifactory_info.
get_artifactory_info
(repo_names=None, repo_type='local')[source]¶ Get storage info from Artifactory.
Parameters: - repo_names (tuple, optional) – Name of artifactory repo.
- repo_type (str) – Type of artifactory repo.
Returns: Dictionary of repo data. storage_info (dict): Storage information api call.
Return type: keys (dict, optional)
lavatory.utils.performance module¶
Performance comparison
-
lavatory.utils.performance.
get_percentage
(old, new)[source]¶ Gets percentage from old and new values
Parameters: - old (num) – old value
- new (num) – new value
Returns: Percentage, or zero if none
Return type: number
-
lavatory.utils.performance.
get_performance_report
(repo_name, old_info, new_info)[source]¶ compares retention policy performance, showing old amount of space and new.
Parameters: - repo_name (str) – Name of repository
- old_info (dict) – Metadata of repository before run
- new_info (dict) – Metadata of repository after run
lavatory.utils.setup_pluginbase module¶
-
lavatory.utils.setup_pluginbase.
get_directory_path
(directory)[source]¶ Gets policy from plugin_source.
Parameters: directory (Path) – Directory path Returns: The full expanded directory path Return type: full_path (Path)
-
lavatory.utils.setup_pluginbase.
get_policy
(plugin_source, repository, default=True)[source]¶ Gets policy from plugin_source.
Parameters: - plugin_source (PluginBase) – the plugin source from loading plugin_base.
- repository (string) – Name of repository.
- default (bool) – If to load the default policy.
Returns: The policy python module.
Return type: policy (func)