Skip to content

Commit

Permalink
Python constant introduced for collection release version
Browse files Browse the repository at this point in the history
  • Loading branch information
kavinagrawalcohesity committed Dec 4, 2024
1 parent 4ea8671 commit 264c912
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 56 deletions.
3 changes: 3 additions & 0 deletions plugins/module_utils/cohesity_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2024 Cohesity Inc

RELEASE_VERSION = "1.3.0"
9 changes: 6 additions & 3 deletions plugins/module_utils/cohesity_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_utilities import (
raise__cohesity_exception__handler,
)
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_constants import (
RELEASE_VERSION,
)
except Exception:
pass

Expand Down Expand Up @@ -690,7 +693,7 @@ def unregister_source(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}

response = open_url(
Expand Down Expand Up @@ -764,7 +767,7 @@ def check__protection_group__exists(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + self["token"],
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -823,7 +826,7 @@ def get_resource_pool_id(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down
13 changes: 8 additions & 5 deletions plugins/modules/cohesity_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_auth import (
get__cohesity_auth__token,
)
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_constants import (
RELEASE_VERSION,
)
except Exception:
pass

Expand Down Expand Up @@ -307,7 +310,7 @@ def download_agent(module, path):
headers = {
"Accept": "application/octet-stream",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
elif not module.params.get("download_uri"):
os_type = "Linux"
Expand Down Expand Up @@ -336,13 +339,13 @@ def download_agent(module, path):
headers = {
"Accept": "application/octet-stream",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
else:
uri = module.params.get("download_uri")
headers = {
"Accept": "application/octet-stream",
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}

agent = open_url(
Expand Down Expand Up @@ -614,7 +617,7 @@ def get_source_details(module, source_id):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -666,7 +669,7 @@ def update_agent(module):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
payload = {"agentIds": [source_details["agent"]["id"]]}
open_url(
Expand Down
7 changes: 5 additions & 2 deletions plugins/modules/cohesity_cancel_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
get__restore_task_status__by_id,
get_cohesity_client,
)
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_constants import (
RELEASE_VERSION,
)
except ImportError:
pass

Expand All @@ -123,7 +126,7 @@ def check__protection_restore__exists(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -170,7 +173,7 @@ def cancel_migration(module, task_id):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/cohesity_clone_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_hints import (
get_cohesity_client,
)
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_constants import (
RELEASE_VERSION,
)
from cohesity_management_sdk.controllers.base_controller import BaseController
from cohesity_management_sdk.models.clone_task_request import CloneTaskRequest
from cohesity_management_sdk.models.vmware_clone_parameters import VmwareCloneParameters
Expand Down Expand Up @@ -511,7 +514,7 @@ def main():

global cohesity_client
base_controller = BaseController()
base_controller.global_headers["user-agent"] = "cohesity-ansible/v1.3.0"
base_controller.global_headers["user-agent"] = "cohesity-ansible/v{}".format(RELEASE_VERSION)
cohesity_client = get_cohesity_client(module)
clone_exists, clone_details = get_clone_task(module, False)

Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/cohesity_finalize_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@
get__restore_job__by_type,
get_cohesity_client,
)
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_constants import (
RELEASE_VERSION,
)
except ImportError:
pass

Expand Down Expand Up @@ -159,7 +162,7 @@ def finalize_migration(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
body = {
"restoreTaskId": self["task_id"],
Expand Down
21 changes: 12 additions & 9 deletions plugins/modules/cohesity_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,9 @@
get__protection_run__all__by_id,
get_cohesity_client,
)
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_constants import (
RELEASE_VERSION,
)
except Exception:
pass

Expand Down Expand Up @@ -595,7 +598,7 @@ def get_vmware_ids(module, job_meta_data, job_details, vm_names):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -633,7 +636,7 @@ def get_vmware_vm_ids(module, job_meta_data, job_details, vm_names):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -678,7 +681,7 @@ def get_view_storage_domain_id(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -743,7 +746,7 @@ def register_job(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
payload = self.copy()

Expand Down Expand Up @@ -848,7 +851,7 @@ def start_job(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
source_ids = payload.get("sourceIds", [])
payload = dict()
Expand Down Expand Up @@ -907,7 +910,7 @@ def update_job(module, job_details, update_source_ids=None):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
payload = job_details.copy()
del payload["token"]
Expand Down Expand Up @@ -969,7 +972,7 @@ def get_prot_job_details(self, module):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -1030,7 +1033,7 @@ def stop_job(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
payload = self.copy()

Expand Down Expand Up @@ -1094,7 +1097,7 @@ def unregister_job(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}

payload = dict(deleteSnapshots=self["deleteSnapshots"])
Expand Down
25 changes: 14 additions & 11 deletions plugins/modules/cohesity_migrate_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@
get__restore_job__by_type,
get_cohesity_client,
)
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_constants import (
RELEASE_VERSION,
)
except ImportError:
pass

Expand Down Expand Up @@ -286,7 +289,7 @@ def get_source_details(module):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -336,7 +339,7 @@ def get_vm_folder_id(module, source_id, resource_pool_id):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -386,7 +389,7 @@ def get_resource_pool_id(module, source_id):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -447,7 +450,7 @@ def get_datastore_id(module, source_id, resource_pool_id):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -496,7 +499,7 @@ def get_network_id(module, source_id, resource_pool_id):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -543,7 +546,7 @@ def get_backup_job_run_id(module, job_id):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -583,7 +586,7 @@ def get_backup_job_ids(module, job_names):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -627,7 +630,7 @@ def get_vmware_source_objects(module, source_id):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}

response = open_url(
Expand Down Expand Up @@ -689,7 +692,7 @@ def start_restore(module, uri, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
payload = self.copy()

Expand Down Expand Up @@ -731,7 +734,7 @@ def create_migration_task(module, body):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
# module.fail_json(msg=body)
response = open_url(
Expand Down Expand Up @@ -821,7 +824,7 @@ def get_protection_groups(module):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down
7 changes: 5 additions & 2 deletions plugins/modules/cohesity_migration_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
get__restore_job__by_type,
get_cohesity_client,
)
from ansible_collections.cohesity.dataprotect.plugins.module_utils.cohesity_constants import (
RELEASE_VERSION,
)
except ImportError:
pass

Expand Down Expand Up @@ -155,7 +158,7 @@ def get_migration_status(module, self):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down Expand Up @@ -187,7 +190,7 @@ def get_task_status(module, task_id):
headers = {
"Accept": "application/json",
"Authorization": "Bearer " + token,
"user-agent": "cohesity-ansible/v1.3.0",
"user-agent": "cohesity-ansible/v{}".format(RELEASE_VERSION),
}
response = open_url(
url=uri,
Expand Down
Loading

0 comments on commit 264c912

Please sign in to comment.