Skip to content
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

VM migration code changes #40

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions plugins/module_utils/cohesity_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import json
import socket
import traceback

from datetime import datetime, timedelta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this in requirements this library ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I didnt see timedelta used anywhere ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timedelta is used at line number 587. datetime is inbuilt package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, just make sure the package is autoinstalled on upgrade .

try:
from urllib import quote
except ImportError:
Expand Down Expand Up @@ -577,10 +577,23 @@ def get__restore_job__by_type(module, self):
+ "/irisservices/api/v1/public/restore/tasks?taskTypes="
+ self["restore_type"]
)
# Restore tasks will be filtered based on start time and end time if
# provided externally.
# By default, last one week retore task list will be returned.
start_time = module.params.get("start_time")
end_time = module.params.get("end_time")
today = datetime.now()
start_time = datetime.strptime(
start_time,"%d/%m/%Y") if start_time else today - timedelta(7)
end_time = datetime.strptime(
end_time,"%d/%m/%Y") if end_time else today
start_time_usecs = int(start_time.timestamp() * 1000 * 1000)
end_time_usecs = int(end_time.timestamp() * 1000 * 1000)
uri += "&startTimeUsecs=%s&endTimeUsecs=%s" % (
start_time_usecs, end_time_usecs)

if "count" in self:
uri = uri + "&pageCount=" + str(self["count"])

headers = {"Accept": "application/json", "Authorization": "Bearer " + token}
objects = open_url(
url=uri, headers=headers, validate_certs=validate_certs, timeout=120
Expand Down
22 changes: 17 additions & 5 deletions plugins/modules/cohesity_migrate_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@
- Specifies the resource pool name where the migrated objects are attached.
type: str
required: true
start_time:
description:
- Restore tasks will be filtered by a start time specified. If not
provided the start time is set to the last week.
type: str
end_time:
description:
- Restore tasks will be filtered by a start time specified. If not
provided the end time is the current time.
type: str
state:
choices:
- present
Expand Down Expand Up @@ -255,9 +265,9 @@ def check__protection_restore__exists(module, self):
if restore_tasks:
task_list = [task for task in restore_tasks if task["name"] == self["name"]]
for task in task_list:
if task["status"] != "kFinished":
return True
return False
if task["status"] not in ["kFinished", "kCancelled"]:
return True, task["status"]
return False, None


def get_source_details(module):
Expand Down Expand Up @@ -856,6 +866,8 @@ def main():
enable_network=dict(type="bool", default=True),
detach_network=dict(type="bool", default=False),
prefix=dict(type="str"),
start_time=dict(type="str"),
end_time=dict(type="str"),
resource_pool_name=dict(type="str", required=True),
recovery_process_type=dict(
type="str",
Expand Down Expand Up @@ -884,7 +896,7 @@ def main():
)
job_details["name"] = module.params.get("name")

job_exists = check__protection_restore__exists(module, job_details)
job_exists, task_status = check__protection_restore__exists(module, job_details)
source_details = get_source_details(module)
source_id = source_details["id"] if source_details else None
if not source_id:
Expand Down Expand Up @@ -996,7 +1008,7 @@ def main():
if job_exists:
results = dict(
changed=False,
msg="The Migrate Job for is already registered",
msg="The Migrate Job for is already registered, task status %s" % task_status,
id=job_exists,
name=job_details["name"],
)
Expand Down
Loading