Skip to content

Commit

Permalink
machines: Show failure in UI when VM deletion failed
Browse files Browse the repository at this point in the history
  • Loading branch information
KKoukiou committed Sep 21, 2018
1 parent 1d03fa9 commit 9078d77
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
29 changes: 19 additions & 10 deletions pkg/machines/libvirt-dbus.es6
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,24 @@ LIBVIRT_DBUS_PROVIDER = {
id: objPath,
options
}) {
function destroy() {
return call(connectionName, objPath, 'org.libvirt.Domain', 'Destroy', [0], TIMEOUT);
function destroy(dispatch) {
return call(connectionName, objPath, 'org.libvirt.Domain', 'Destroy', [0], TIMEOUT)
.catch(exception => dispatch(vmActionFailed({
name: name,
connectionName,
message: _("VM DELETE action failed"),
detail: {exception}
})));
}

function undefine() {
function undefine(dispatch) {
let storageVolPromises = [];
let storageVolPathsPromises = [];
let flags = Enum.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE | Enum.VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA | Enum.VIR_DOMAIN_UNDEFINE_NVRAM;

for (let i = 0; i < options.storage.length; i++) {
storageVolPathsPromises.push(
call(connectionName, '/org/libvirt/QEMU', 'org.libvirt.Connect', 'StorageVolLookupByPath', [options.storage[i]], TIMEOUT)
.fail((ex) => console.error("Failed to LookupByPath", options.storage[i]))
);
}

Expand All @@ -286,22 +291,26 @@ LIBVIRT_DBUS_PROVIDER = {
for (let i = 0; i < storageVolPaths.length; i++) {
storageVolPromises.push(
call(connectionName, storageVolPaths[i][0], 'org.libvirt.StorageVol', 'Delete', [0], TIMEOUT)
.fail((ex) => console.error("Failed to Delete", storageVolPaths[i][0]))
);
}
return Promise.all(storageVolPathsPromises);
})
.then(() => {
call(connectionName, objPath, 'org.libvirt.Domain', 'Undefine', [flags], TIMEOUT)
.fail(ex => console.error("Failed to Undefine Domain %s:", name, ex));
});
call(connectionName, objPath, 'org.libvirt.Domain', 'Undefine', [flags], TIMEOUT);
})
.catch(exception => dispatch(vmActionFailed({
name: name,
connectionName,
message: _("VM DELETE action failed"),
detail: {exception}
})));
}

return dispatch => {
if (options.destroy) {
return destroy().then(undefine);
return destroy(dispatch).then(undefine(dispatch));
} else {
return undefine();
return undefine(dispatch);
}
};
},
Expand Down
36 changes: 19 additions & 17 deletions pkg/machines/libvirt-virsh.es6
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,28 @@ LIBVIRT_PROVIDER = {
DELETE_VM ({ name, connectionName, options }) {
logDebug(`${this.name}.DELETE_VM(${name}, ${JSON.stringify(options)}):`);

function destroy() {
return spawnVirsh({ connectionName,
method: 'DELETE_VM',
args: [ 'destroy', name ]
});
}
return dispatch => {
function destroy() {
return spawnVirsh({ connectionName,
method: 'DELETE_VM',
failHandler: buildFailHandler({ dispatch, name, connectionName, message: _("VM DELETE (DESTROY) action failed") }),
args: [ 'destroy', name ]
});
}

function undefine() {
let args = ['undefine', name, '--managed-save'];
if (options.storage) {
args.push('--storage');
args.push(options.storage.join(','));
function undefine() {
let args = ['undefine', name, '--managed-save'];
if (options.storage) {
args.push('--storage');
args.push(options.storage.join(','));
}
return spawnVirsh({ connectionName,
method: 'DELETE_VM',
failHandler: buildFailHandler({ dispatch, name, connectionName, message: _("VM DELETE (UNDEFINE) action failed") }),
args: args
});
}
return spawnVirsh({ connectionName,
method: 'DELETE_VM',
args: args
});
}

return dispatch => {
if (options.destroy) {
return destroy().then(undefine);
} else {
Expand Down

0 comments on commit 9078d77

Please sign in to comment.