def update_ocm_share(self, share_id, field, value): share_id_obj = sharing_res.ShareId(opaque_id=share_id) ref = sharing_res.ShareReference(id=share_id_obj) if field == 'permissions': request = ocm_api.UpdateOCMShareRequest(ref=ref, field=ocm_api.UpdateOCMShareRequest.UpdateField( permissions=sharing_res.SharePermissions( permissions=ShareUtils.get_resource_permissions(value[0]), reshare=bool(value[1])) )) elif field == 'display_name': request = ocm_api.UpdateOCMShareRequest(ref=ref, field=ocm_api.UpdateOCMShareRequest.UpdateField( display_name=value )) else: raise ValueError('Unknown field to update') response = self.ocm_share_api.UpdateOCMShare(request=request, metadata=self._token()) if self._is_code_ok(response): self.log.info("OCM share updated:\n" + response) return else: self._handle_error(response, "Error updating OCM share:")
def update_received_ocm_share(self, share_id, field, value): share_id_obj = sharing_res.ShareId(opaque_id=share_id) ref = sharing_res.ShareReference(id=share_id_obj) if field == 'display_name': request = ocm_api.UpdateReceivedOCMShareRequest(ref=ref, field=ocm_api.UpdateReceivedOCMShareRequest .UpdateField( display_name=value )) elif field == 'state': request = ocm_api.UpdateReceivedOCMShareRequest(ref=ref, field=ocm_api.UpdateReceivedOCMShareRequest .UpdateField( state=ShareUtils.map_state(value) )) else: raise ValueError("Unknown field to update") response = self.ocm_share_api.UpdateReceivedOCMShare(request=request, metadata=self._token()) if self._is_code_ok(response): self.log.info("OCM received share updated:\n" + response) return else: self._handle_error(response, "Error updating OCM received share:") return response
def _get_ocm_share(self, share_id): share_id_obj = sharing_res.ShareId(opaque_id=share_id) ref = sharing_res.ShareReference(id=share_id_obj) request = ocm_api.GetOCMShareRequest(ref=ref) response = self.ocm_share_api.GetOCMShare(request=request, metadata=self._token()) return self._map_share(response.share)
def _get_received_share(self, share_id): share_id_obj = sharing_res.ShareId(opaque_id=share_id) ref = sharing_res.ShareReference(id=share_id_obj) request = ocm_api.GetReceivedOCMShareRequest(ref=ref) response = self.ocm_share_api.GetReceivedOCMShare(request=request, metadata=self._token()) if not self._is_code_ok(response): self._handle_error("Error listing OCM received share:", response) return self._map_share(response.share.share, response.share.state)
def remove_ocm_share(self, share_id): share_id_obj = sharing_res.ShareId(opaque_id=share_id) ref = sharing_res.ShareReference(id=share_id_obj) request = ocm_api.RemoveOCMShareRequest(ref=ref) response = self.ocm_share_api.RemoveOCMShare(request=request, metadata=self._token()) if self._is_code_ok(response): self.log.info("OCM share deleted:\n" + response) return else: self._handle_error(response, "Error removing OCM share")