Skip to content

Commit b05d7ed

Browse files
committed
Merge branch 'feature/assaf_GetVmDetails' of https://github.com/QualiSystems/vCenterShell into feature/assaf_GetVmDetails
2 parents 699f119 + c3e864a commit b05d7ed

8 files changed

Lines changed: 47 additions & 14 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ install:
77
- pip install "cloudshell-core>=2.2.0,<2.3.0" --extra-index-url https://testpypi.python.org/simple
88
- chmod 777 ./cloudshell_shell_core_install.sh
99
- ./cloudshell_shell_core_install.sh
10-
- pip install "cloudshell-automation-api>=8.2.0.0,<8.3.0.0" --extra-index-url https://testpypi.python.org/simple
10+
- pip install "cloudshell-automation-api>=8.3.0.0,<8.3.1.0" --extra-index-url https://testpypi.python.org/simple
1111
language: python
1212
notifications:
1313
webhools: "https://qualisystems.getbadges.io/api/app/webhook/63350e33-4119-49c3-8127-075aaa022926"

package/cloudshell/cp/vcenter/commands/command_orchestrator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,23 @@ def get_vm_details(self, context,cancellation_context, requests_json):
411411
cancellation_context)
412412
return set_command_result(result=res, unpicklable=False)
413413

414-
def save_snapshot(self, context, snapshot_name):
414+
def save_snapshot(self, context, snapshot_name, save_memory='No'):
415415
"""
416416
Saves virtual machine to a snapshot
417417
:param context: resource context of the vCenterShell
418418
:type context: models.QualiDriverModels.ResourceCommandContext
419419
:param snapshot_name: snapshot name to save to
420420
:type snapshot_name: str
421+
:param save_memory: Snapshot the virtual machine's memory. Lookup, Yes / No
422+
:type save_memory: str
421423
:return:
422424
"""
423425
resource_details = self._parse_remote_model(context)
424426
created_snapshot_path = self.command_wrapper.execute_command_with_connection(context,
425427
self.snapshot_saver.save_snapshot,
426428
resource_details.vm_uuid,
427-
snapshot_name)
429+
snapshot_name,
430+
save_memory)
428431
return set_command_result(created_snapshot_path)
429432

430433
def restore_snapshot(self, context, snapshot_name):

package/cloudshell/cp/vcenter/commands/save_snapshot.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, pyvmomi_service, task_waiter):
1919
self.pyvmomi_service = pyvmomi_service
2020
self.task_waiter = task_waiter
2121

22-
def save_snapshot(self, si, logger, vm_uuid, snapshot_name):
22+
def save_snapshot(self, si, logger, vm_uuid, snapshot_name, save_memory):
2323
"""
2424
Creates a snapshot of the current state of the virtual machine
2525
@@ -31,21 +31,33 @@ def save_snapshot(self, si, logger, vm_uuid, snapshot_name):
3131
:type vm_uuid: str
3232
:param snapshot_name: Snapshot name to save the snapshot to
3333
:type snapshot_name: str
34+
:param save_memory: Snapshot the virtual machine's memory. Lookup, Yes / No
35+
:type save_memory: str
3436
"""
3537
vm = self.pyvmomi_service.find_by_uuid(si, vm_uuid)
3638

3739
snapshot_path_to_be_created = SaveSnapshotCommand._get_snapshot_name_to_be_created(snapshot_name, vm)
40+
41+
save_vm_memory_to_snapshot = SaveSnapshotCommand._get_save_vm_memory_to_snapshot(save_memory)
42+
3843
SaveSnapshotCommand._verify_snapshot_uniquness(snapshot_path_to_be_created, vm)
3944

40-
task = self._create_snapshot(logger, snapshot_name, vm)
45+
task = self._create_snapshot(logger, snapshot_name, vm, save_vm_memory_to_snapshot)
4146

4247
self.task_waiter.wait_for_task(task=task, logger=logger, action_name='Create Snapshot')
4348
return snapshot_path_to_be_created
4449

4550
@staticmethod
46-
def _create_snapshot(logger, snapshot_name, vm):
51+
def _get_save_vm_memory_to_snapshot(save_memory):
52+
return True if save_memory is not None and save_memory.lower() == 'yes' else False
53+
54+
@staticmethod
55+
def _create_snapshot(logger, snapshot_name, vm, save_vm_memory_to_snapshot):
56+
"""
57+
:type save_vm_memory_to_snapshot: bool
58+
"""
4759
logger.info("Create virtual machine snapshot")
48-
dump_memory = False
60+
dump_memory = save_vm_memory_to_snapshot
4961
quiesce = True
5062
task = vm.CreateSnapshot(snapshot_name, 'Created by CloudShell vCenterShell', dump_memory, quiesce)
5163
return task

package/cloudshell/tests/test_commands/test_save_snapshot.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def test_save_snapshot_should_succeed_when_there_is_no_snapshot(self):
2828
save_snapshot_command.save_snapshot(si=si,
2929
logger=Mock(),
3030
vm_uuid='machine1',
31-
snapshot_name='new_snapshot')
31+
snapshot_name='new_snapshot',
32+
save_memory='No')
3233

3334
# Assert
3435
vm.CreateSnapshot.called_with('new_snapshot', 'Created by CloudShell vCenterShell', False, True)
@@ -50,7 +51,8 @@ def test_save_snapshot_should_succeed_when_snapshot_with_the_same_name_does_not_
5051
save_snapshot_command.save_snapshot(si=si,
5152
logger=Mock(),
5253
vm_uuid='machine1',
53-
snapshot_name='new_snapshot')
54+
snapshot_name='new_snapshot',
55+
save_memory='No')
5456

5557
# Assert
5658
vm.CreateSnapshot.called_with('new_snapshot', 'Created by CloudShell vCenterShell', False, True)
@@ -74,4 +76,17 @@ def test_save_snapshot_should_fail_if_snaphost_exists(self):
7476
save_snapshot_command.save_snapshot(si=si,
7577
logger=Mock(),
7678
vm_uuid='machine1',
77-
snapshot_name='snapshot2')
79+
snapshot_name='snapshot2',
80+
save_memory='No')
81+
82+
def test_save_memory_yes(self):
83+
save_memory_string = 'Yes'
84+
self.assertTrue(SaveSnapshotCommand._get_save_vm_memory_to_snapshot(save_memory_string))
85+
save_memory_string = 'yEs'
86+
self.assertTrue(SaveSnapshotCommand._get_save_vm_memory_to_snapshot(save_memory_string))
87+
88+
def test_save_memory_no(self):
89+
save_memory_string = 'No'
90+
self.assertTrue(not SaveSnapshotCommand._get_save_vm_memory_to_snapshot(save_memory_string))
91+
save_memory_string = 'nO'
92+
self.assertTrue(not SaveSnapshotCommand._get_save_vm_memory_to_snapshot(save_memory_string))

package/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
lxml==3.8.0
22
requests==2.18.4
3-
cloudshell-automation-api>=8.2.0.0,<8.2.1.0
3+
cloudshell-automation-api>=8.3.0.0,<8.3.1.0
44
cloudshell-shell-core>=3.1.0,<3.2.0
55
pyvmomi==6.5.0
66
jsonpickle==0.9.3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cloudshell-core>=2.0.0,<2.1.0
22
cloudshell-cp-vcenter>=1.10.0,<1.11.0
3-
cloudshell-automation-api>=8.2.0.0,<8.2.1.0
3+
cloudshell-automation-api>=8.3.0.0,<8.3.1.0
44
cloudshell-shell-core>=3.1.0,<3.2.0

vcentershell_driver/driver.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def get_inventory(self, context):
8686
validator = VCenterAutoModelDiscovery()
8787
return validator.validate_and_discover(context)
8888

89-
def remote_save_snapshot(self, context, ports, snapshot_name):
89+
def remote_save_snapshot(self, context, ports, snapshot_name, save_memory):
9090
"""
9191
Saves virtual machine to a snapshot
9292
:param context: resource context of the vCenterShell
@@ -95,9 +95,11 @@ def remote_save_snapshot(self, context, ports, snapshot_name):
9595
:type ports: list[string]
9696
:param snapshot_name: snapshot name to save to
9797
:type snapshot_name: str
98+
:param save_memory: Snapshot the virtual machine's memory. Lookup, Yes / No
99+
:type save_memory: str
98100
:return:
99101
"""
100-
return self.command_orchestrator.save_snapshot(context, snapshot_name)
102+
return self.command_orchestrator.save_snapshot(context, snapshot_name, save_memory)
101103

102104
def remote_restore_snapshot(self, context, ports, snapshot_name):
103105
"""

vcentershell_driver/drivermetadata.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<Command Description="" DisplayName="Save Snapshot" Name="remote_save_snapshot" Tags="remote_connectivity,allow_unreserved">
1818
<Parameters>
1919
<Parameter DefaultValue="" Description="Please enter the VM snapshot name, for example Snapshot1" DisplayName="Snapshot Name" Mandatory="True" Name="snapshot_name" Type="String" />
20+
<Parameter DefaultValue="No" Description="Snapshot the virtual machine's memory" DisplayName="Save Memory" Mandatory="True" Name="save_memory" Type="Lookup" AllowedValues="Yes,No" />
2021
</Parameters>
2122
</Command>
2223
<Command Description="" DisplayName="Restore Snapshot" Name="remote_restore_snapshot" Tags="remote_connectivity,allow_unreserved">

0 commit comments

Comments
 (0)