Infinidat / infinisdk

Python SDK for INFINIDAT storage products
https://infinisdk.readthedocs.org
Other
9 stars 5 forks source link

HTTP status 415 when calling "replicas/{id}/change_role" #3

Closed techguydave closed 6 years ago

techguydave commented 6 years ago

I'm trying to recreate the "Change Role" menu option in the replication GUI in a script, either through an SDK function or manually. From what I can tell, the switch_role() function doesn't work for async (as the documentation states). So I tried to call the API through the SDK at api/rest/replicas/{id}/change_role, but that returns a 415. I can confirm that I receive the same result in Postman.

I don't claim to be a Python guru, so let me know if I'm doing something wrong in my script.

Script:

from infinisdk import InfiniBox

system = InfiniBox("hostname", auth=("user", "password"))
system.login()

replica_id = system.replicas.get(remote_entity_name = "content_library").get_id()

change_role = system.api.post('replicas/' + str(replica_id) + '/change_role')
change_role.get_result()

Response:

Traceback (most recent call last):
  File "main.py", line 13, in <module>
    change_role = system.api.post('replicas/' + str(test_replica.get_id()) + '/change_role')
  File "/usr/lib/python2.7/site-packages/infinisdk/core/api/api.py", line 34, in returned
    return self.request(http_method, path=path, **kwargs)
  File "/usr/lib/python2.7/site-packages/infinisdk/core/api/api.py", line 516, in request
    returned.assert_success()
  File "/usr/lib/python2.7/site-packages/infinisdk/core/api/api.py", line 655, in assert_success
    raise APICommandFailed.raise_from_response(self)
  File "/usr/lib/python2.7/site-packages/infinisdk/core/exceptions.py", line 83, in raise_from_response
    raise cls(response)
infinisdk.core.exceptions.APICommandFailed: API Command Failed
        Request: POST http://<hostname>:80/api/rest/replicas/93067/change_role?approved=true
        Request Timestamp: 2018-05-15T11:26:26.943272-04:00
        Response Timestamp: 2018-05-15T11:26:26.985322-04:00
        Data: <NOTHING>
        Status: 415
        Code: UNSUPPORTED_MEDIA_TYPE
        Message: The media type of the request is not supported
        Cookies: JSESSIONID=<nom_nom_cookies>
techguydave commented 6 years ago

I should have searched the repo for examples/tests before filing the issue! It looks like changing

change_role = system.api.post('replicas/' + str(replica_id) + '/change_role')

to

change_role = system.api.post('replicas/' + str(replica_id) + '/change_role', data={})

solved it! This was omitted from the InfiniSDK documentation and might be a helpful addition on the Getting Started page.

vmalloc commented 6 years ago

@synth3tk replica objects have a change_role() method. Due to a mistake on our part it does not appear in the API documentation page (will be fixed in the next release).

This means you just have to write replica.change_role() and everything works.

techguydave commented 6 years ago

@vmalloc Thank you very much, that worked!