Skip to content

Commit

Permalink
Merge 99c44e2 into 83ee3bd
Browse files Browse the repository at this point in the history
  • Loading branch information
svt-pchavan committed Aug 28, 2020
2 parents 83ee3bd + 99c44e2 commit 5fb7793
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- endpoint support for /backups/{bkpId}/copy <POST>
- endpoint support for /backups/{bkpId}/rename <POST>
- endpoint support for /backups/{bkpId}/restore <POST>
- endpoint support for /backups/{bkpId}/restore_files <POST>
- endpoint support for /backups/{bkpId}/virtual_disk_partitions <GET>
- endpoint support for /backups/{bkpId}/virtual_disk_partition_files <GET>
- endpoint support for /cluster_groups <GET>
Expand Down
1 change: 1 addition & 0 deletions endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Refer SimpliVity REST API doc for the resource endpoints documentation [HPE Simp
|<sub>/backups/{bkpId}/lock</sub> |POST |
|<sub>/backups/{bkpId}/rename</sub> |POST |
|<sub>/backups/{bkpId}/restore</sub> |POST |
|<sub>/backups/{bkpId}/restore_files</sub> |POST |
|<sub>/backups/{bkpId}/virtual_disk_partitions</sub> |GET |
|<sub>/backups/{bkpId}/virtual_disk_partition_files</sub> |GET |
| **Cluster Groups**
Expand Down
17 changes: 17 additions & 0 deletions examples/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
cluster1_name = "CC_Virt_0001"
cluster2_name = "CC_Virt_0000"
virtual_disk = "tinyvm32_ATF_0.vmdk"
# The virtual machine where you want to restore the files
target_vm_name = "win2k8_template"
# List of paths to the files in this format: virtual_machine_disk_name/partition_number/path_to_file
paths = ['win2k8_template_test.vmdk/2/Users/desktop.ini', 'win2k8_template_test.vmdk/2/guestvmtest.csv', 'win2k8_template_test.vmdk/2/Windows/win.ini']

print("\n\nget_all with default params")
all_backups = backups.get_all()
Expand Down Expand Up @@ -177,3 +181,16 @@
print("\n\nget virtual disk partition files")
partition_data = backup_object.get_virtual_disk_partition_files(virtual_disk, 1, "/")
print(f"{pp.pformat(partition_data)}")

vm = machines.get_by_name(test_vm_name)
backup = vm.create_backup("backup_test_from_sdk_" + str(time.time()))
print(f"{backup}")
print(f"{pp.pformat(backup.data)} \n")
try:
print("\n\nbackup restore files")
target_vm = machines.get_by_name(target_vm_name)
target_vm_id = target_vm.data["id"]
backup.restore_files(target_vm_id, paths)
except HPESimpliVityException as e:
print(f"{e}")
backup.delete()
17 changes: 17 additions & 0 deletions simplivity/resources/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,20 @@ def get_virtual_disk_partition_files(self, virtual_disk, partition_number, file_
'file_path': file_path}

return self._client.do_get(resource_uri, data)

def restore_files(self, virtual_machine_id, paths, timeout=-1):
"""Restores files from specific partition
Args:
virtual_machine_id: The identification number of the virtual machine where you want to restore the files.
paths: List of path to the files in this format: virtual_machine_disk_name/partition_number/path_to_file.
Returns:
None
"""
resource_uri = "{}/{}/restore_files".format(URL, self.data["id"])
custom_headers = {'Content-type': 'application/vnd.simplivity.v1.9+json'}
data = {"virtual_machine_id": virtual_machine_id,
"paths": paths}

self._client.do_post(resource_uri, data, timeout, custom_headers)
13 changes: 13 additions & 0 deletions tests/unit/resources/test_backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,19 @@ def test_get_virtual_disk_partition_files(self, mock_get):
self.assertEqual(partition_data, resource_data)
mock_get.assert_has_calls([call('/backups/12345/virtual_disk_partition_files?file_path=%2F&partition_number=1&virtual_disk=tinyvm32_ATF_0.vmdk')])

@mock.patch.object(Connection, "post")
@mock.patch.object(Connection, "get")
def test_restore_files(self, mock_get, mock_post):
mock_post.return_value = None, [{'object_id': '12345'}]
resource_data = {'name': 'name1', 'id': '12345', 'state': 'PROTECTED'}
mock_get.return_value = {backups.DATA_FIELD: [resource_data]}
backup_data = {'name': 'name1', 'id': '12345', 'state': 'PROTECTED'}
backup = self.backups.get_by_data(backup_data)
paths = ['vmdkName/partition/file1', 'vmdkName/partition/directory/file2']
backup.restore_files("12345", paths)
data = {"virtual_machine_id": "12345", "paths": ['vmdkName/partition/file1', 'vmdkName/partition/directory/file2']}
mock_post.assert_called_once_with('/backups/12345/restore_files', data, custom_headers={'Content-type': 'application/vnd.simplivity.v1.9+json'})


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

0 comments on commit 5fb7793

Please sign in to comment.