Skip to content

Commit 007c48a

Browse files
authored
Merge pull request #92 from svt-vverma/feature/datastore_unshare
Added support for datastore unshare
2 parents 5d66187 + 4969cda commit 007c48a

5 files changed

Lines changed: 53 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
- endpoint support for /datastore/{datastoreId}/set_policy <POST>
2727
- endpoint support for /datastore/{datastoreId}/share <POST>
2828
- endpoint support for /datastore/{datastoreId}/standard_hosts <GET>
29+
- endpoint support for /datastore/{datastoreId}/unshare <POST>
2930
- endpoint support for /external_stores <GET>
3031
- endpoint support for /external_stores <POST>
3132
- endpoint support for /external_stores/update_credentials <POST>

endpoints-support.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Refer SimpliVity REST API doc for the resource endpoints documentation [HPE Simp
2929
|<sub>/datastores/{datastoreId}/set_policy</sub> |POST |
3030
|<sub>/datastores/{datastoreId}/share</sub> |POST |
3131
|<sub>/datastores/{datastoreId}/standard_hosts</sub> |GET |
32+
|<sub>/datastores/{datastoreId}/unshare</sub> |POST |
3233
| **External Stores**
3334
|<sub>/external_stores</sub> |GET |
3435
|<sub>/external_stores</sub> |POST |

examples/datastores.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
ovc = OVC(config)
3434
datastores = ovc.datastores
3535

36+
# variable declaration
37+
standard_host_name = "127.0.0.1"
38+
3639
print("\n\nget_all with default params")
3740
all_datastores = datastores.get_all()
3841
for datastore in all_datastores:
@@ -110,6 +113,18 @@
110113
hosts = datastore_object.standard_hosts()
111114
print(f"{pp.pformat(hosts)} \n")
112115

116+
# Share a datastore
117+
print("\n\nshare a datastore")
118+
datastore_obj = datastore_object.share(standard_host_name)
119+
print(f"{pp.pformat(datastore_obj)} \n")
120+
print(f"{pp.pformat(datastore_obj.data)} \n")
121+
122+
# Stop sharing a datastore
123+
print("\n\nstop sharing a datastore")
124+
datastore_obj = datastore_object.unshare(standard_host_name)
125+
print(f"{pp.pformat(datastore_obj)} \n")
126+
print(f"{pp.pformat(datastore_obj.data)} \n")
127+
113128
print("\n\ndatastore delete")
114129
all_datastores = datastores.get_all()
115130
count = len(all_datastores)

simplivity/resources/datastores.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,21 @@ def share(self, host_name, timeout=-1):
231231
self.__refresh()
232232

233233
return self
234+
235+
def unshare(self, host_name, timeout=-1):
236+
"""Stop sharing a datastore.
237+
238+
Args:
239+
host_name: The name of the standard host that needs to stop sharing a datastore.
240+
timeout: Time out for the request in seconds.
241+
242+
Returns:
243+
object: Datastore object.
244+
"""
245+
246+
resource_uri = "{}/{}/unshare".format(URL, self.data["id"])
247+
data = {"host_name": host_name}
248+
self._client.do_post(resource_uri, data, timeout)
249+
self.__refresh()
250+
251+
return self

tests/unit/resources/test_datastores.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,24 @@ def test_share(self, mock_get, mock_post):
238238
{'host_name': "host1"},
239239
custom_headers=None)
240240

241+
@mock.patch.object(Connection, "post")
242+
@mock.patch.object(Connection, "get")
243+
def test_unshare(self, mock_get, mock_post):
244+
resource_data = {'name': 'ds1', 'id': '12345', 'shares': [{'address': '127.0.0.1',
245+
'host': 'host1',
246+
'rw': True}]}
247+
mock_post.return_value = None, [{'object_id': '12345'}]
248+
mock_get.return_value = {'datastore': resource_data}
249+
250+
datastore_data = {'name': 'ds1', 'id': '12345'}
251+
datastore = self.datastores.get_by_data(datastore_data)
252+
datastore_obj = datastore.unshare("host1")
253+
self.assertIsInstance(datastore_obj, datastores.Datastore)
254+
self.assertEqual(datastore_obj.data, resource_data)
255+
mock_post.assert_called_once_with('/datastores/12345/unshare',
256+
{'host_name': "host1"},
257+
custom_headers=None)
258+
241259

242260
if __name__ == '__main__':
243261
unittest.main()

0 commit comments

Comments
 (0)