Create Protection Domain Schedule via API/Python | Nutanix Community
Skip to main content
Solved

Create Protection Domain Schedule via API/Python

  • February 6, 2019
  • 1 reply
  • 1586 views

Hi,

I'm trying to create a schedule for an existing Protection Domain like this:

code:
def createProtectionDomainSchedule(self,pdname):
# Set the schedule for the protection domain
try:
policy = {"retention_policy": {"remote_retention_type": None, "remote_max_snapshots": {}, "local_retention_period": None, "local_max_snapshots": 1, "remote_retention_period": {}, "local_retention_type": None}, "start_times_in_usecs": [1549477620000000L], "rollup_schedule_uuid": None, "user_start_time_in_usecs": 1549477620000000L, "is_rollup_sched": None, "pd_name": pdname, "values": None, "suspended": False, "app_consistent": False, "end_time_in_usecs": None, "type": "DAILY", "id": "63c037e5-41e4-4630-8641-23509a5360a1gg", "every_nth": 1}

protectionDomainURL = self.base_url + "/protection_domains/"+pdname+"/schedules"

serverResponse = self.session.post(protectionDomainURL, policy )
print serverResponse.text
return json.loads(serverResponse.text)
except Exception as e:
errorhandler(e)



However, this returns:

{"message":"Unexpected character ('r' (code 114)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')","detailed_message":"java.io.IOException: Unexpected character ('r' (code 114)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n\tat com.nutanix.prism.web.providers.ProtobufJsonProvider.getInputObject(ProtobufJsonProvider.java:204)\n\tat


I'm wondering if someone has a working example to do this?

Thanks!

Michel

Best answer by Chandru

@Michelp_be One issue i see in your code is that the last two characters in the id contains letter `g` any UUID only contains characters a to f. But this doesn't seem to be causing the error and yoou can ignore the id altogether it will still update.

The error may be caused by the payload getting passed in non-json format. This could be because you are not setting header "content-type:application/json" or the data payload is being converted to string instead of being passed as dictionary.

I tried your payload exactly and i'm able to successfully create the schedule
View original
Did this topic help you find an answer to your question?
This topic has been closed for comments

1 reply

Forum|alt.badge.img+13
  • Nutanix Employee
  • 44 replies
  • Answer
  • February 8, 2019
@Michelp_be One issue i see in your code is that the last two characters in the id contains letter `g` any UUID only contains characters a to f. But this doesn't seem to be causing the error and yoou can ignore the id altogether it will still update.

The error may be caused by the payload getting passed in non-json format. This could be because you are not setting header "content-type:application/json" or the data payload is being converted to string instead of being passed as dictionary.

I tried your payload exactly and i'm able to successfully create the schedule