backing,
'snapshot')
+ def test_snapshot_exists(self):
+ backing = mock.sentinel.backing
+ invoke_api = self.session.invoke_api
+ invoke_api.return_value = None
+
+ self.assertFalse(self.vops.snapshot_exists(backing))
+ invoke_api.assert_called_once_with(vim_util,
+ 'get_object_property',
+ self.session.vim,
+ backing,
+ 'snapshot')
+
+ snapshot = mock.Mock()
+ invoke_api.return_value = snapshot
+ snapshot.rootSnapshotList = None
+ self.assertFalse(self.vops.snapshot_exists(backing))
+
+ snapshot.rootSnapshotList = [mock.Mock()]
+ self.assertTrue(self.vops.snapshot_exists(backing))
+
def test_delete_snapshot(self):
backing = mock.sentinel.backing
snapshot_name = mock.sentinel.snapshot_name
spec=reconfig_spec)
self.session.wait_for_task.assert_called_once_with(task)
+ def test_rename_backing(self):
+ task = mock.sentinel.task
+ self.session.invoke_api.return_value = task
+
+ backing = mock.sentinel.backing
+ new_name = mock.sentinel.new_name
+ self.vops.rename_backing(backing, new_name)
+
+ self.session.invoke_api.assert_called_once_with(self.session.vim,
+ "Rename_Task",
+ backing,
+ newName=new_name)
+ self.session.wait_for_task.assert_called_once_with(task)
+
def test_delete_file(self):
file_mgr = mock.sentinel.file_manager
self.session.vim.service_content.fileManager = file_mgr
for root in snapshot.rootSnapshotList:
return VMwareVolumeOps._get_snapshot_from_tree(name, root)
+ def snapshot_exists(self, backing):
+ """Check if the given backing contains snapshots."""
+ snapshot = self._session.invoke_api(vim_util, 'get_object_property',
+ self._session.vim, backing,
+ 'snapshot')
+ if snapshot is None or snapshot.rootSnapshotList is None:
+ return False
+ return len(snapshot.rootSnapshotList) != 0
+
def delete_snapshot(self, backing, name):
"""Delete a given snapshot from volume backing.
self._session.wait_for_task(reconfig_task)
LOG.debug("Backing VM: %s reconfigured with new disk.", backing)
+ def rename_backing(self, backing, new_name):
+ """Rename backing VM.
+
+ :param backing: VM to be renamed
+ :param new_name: new VM name
+ """
+ LOG.info(_("Renaming backing VM: %(backing)s to %(new_name)s."),
+ {'backing': backing,
+ 'new_name': new_name})
+ rename_task = self._session.invoke_api(self._session.vim,
+ "Rename_Task",
+ backing,
+ newName=new_name)
+ LOG.debug("Task: %s created for renaming VM.", rename_task)
+ self._session.wait_for_task(rename_task)
+ LOG.info(_("Backing VM: %(backing)s renamed to %(new_name)s."),
+ {'backing': backing,
+ 'new_name': new_name})
+
def delete_file(self, file_path, datacenter=None):
"""Delete file or folder on the datastore.