Closed anusajith closed 1 year ago
@anusajith Can you please share the error details.
import random
from cohesity_management_sdk.cohesity_client import CohesityClient
from cohesity_management_sdk.models.protection_job_request_body import (
ProtectionJobRequestBody,
)
from cohesity_management_sdk.models.create_view_request import CreateViewRequest
client = CohesityClient("x.x.x.x", admin, admin)
view_name = "View" + str(random.randint(1, 1000))
job_name = "Job" + str(random.randint(1, 1000))
view_box_id = client.view_boxes.get_view_boxes()[0].id
policy_id = client.protection_policies.get_protection_policies()[0].id
view_body = CreateViewRequest(name=view_name, view_box_id=view_box_id)
resp = client.views.create_view(view_body)
view_id = resp.view_id
print(policy_id, view_box_id)
job_body = ProtectionJobRequestBody(
name=job_name,
policy_id=policy_id,
view_box_id=view_box_id,
source_ids=[view_id],
environment="kView",
timezone="Asia/Kolkata"
)
job_resp = client.protection_jobs.create_protection_job(job_body)
print(job_resp.id)
job_id = job_resp.id
job_body.description = "Updated views"
job_body.id = job_id
job_body.source_ids.append(4874)
print(client.protection_jobs.update_protection_job(job_body, job_id))
I'm using the above code, was able to create job and update the same.
Hi @naveena-maplelabs , Here are the code snippets which I am trying :
We have an already existing protection job with name "test_view" .
from cohesity_management_sdk.models.protection_job_request_body import ProtectionJobRequestBody
1) Getting the "test_cohesity_view" protection job by name. protection_job_list = cohesity_client.protection_jobs.get_protection_jobs() for job in protection_job_list: if job.name == "test_cohesity_view": protected_view_job=job
2) Getting the view_id which has to added to "test_cohesity_view" view_name="test_smart_view" view_id=cohesity_client.views.get_view_by_name(view_name).view_id
3)Update the protection job with new description and view: job_body = ProtectionJobRequestBody( name=protected_view_job.name, policy_id=protected_view_job.policy_id, view_box_id=protected_view_job.view_box_id, source_ids=protected_view_job.source_ids, source_special_parameters=[], environment="kView", ) job_body.description = "test update view" job_body.id = protected_view_job.id job_body.source_ids.append(view_id)
cohesity_client.protection_jobs.update_protection_job(job_body, view_job.id)
Traceback (most recent call last):
File "
This is the response we are getting. Please guide me where I am going wrong here.
@anusajith Can you please make sure the view you are trying to add and the job are created using same storage domain?
@naveena-maplelabs Yes , both are in the same storage domain. This operation is working through UI. No errors thrown. Only issue when we are trying using API.
Both views belong to same storage domain?
Yes!!
Protection job View:
View to be added to protection job:
Are you using the same login credentials for both UI and SDK?
Yes I am !!
Thats strange, Can you please try the same API using postman instead of sdk and share the response here?
POST /irisservices/api/v1/public/protectionJobs Payload { "name": protected_view_job.name, "policyId": protected_view_job.policy_id, "viewBoxId" : protected_view_job.view_box_id, "sourceIds":protected_view_job.source_ids, "environment":"kView", )
To update PUT /public/protectionJobs/{id}
It is working now with the following work around:
When fetching a Protection Job , source Ids are not same as the View Ids. So When we are trying to update a protection job with 100+ views in it, we have to explicitly convert those source ids to respective View Ids and then run the update method.
Some fields are not mentioned as mandatory fields. But then when we try to PUT/POST, it throws error saying its required. eg: timezone.
Okay,
🐛 Bug Report
Hey team,
I am trying to update an existing Cohesity view under Data protection--> Protection, by adding one more view to it as shown below.
When I am doing though the api , it just throws this error message:
cohesity_management_sdk.exceptions.api_exception.APIException: Response status code: 500, Response message: Could not list all the views requested for backup. Either some do not exist, or the user does not have access to it, or all views are not in same view box.
Even tried to update just the description of the protection job, then also it threw the same error.
Steps to Reproduce:
Regarding the protection job:
When we are updating through UI , it works. But it doesn't work through the api. Can you please let me know what am I doing wrong here?