.done(function (reply) { var infos = {}; try { infos = JSON.parse(reply[0]); } catch (error) { /* ignore errors (same as when org.atomic doesn't exist) */ } var promises; /* Atomic sometimes returns containers for which it doesn't * have scan results. Remove those. */ var ids = Object.keys(infos).filter(function (id) { return infos[id].json_file; }); if (ids.length > 0) { promises = ids.map(function (id) { return cockpit.file(infos[id].json_file, { syntax: JSON }).read(); }); cockpit.all(promises).done(function () { var detailedInfos = {}; for (var i = 0; i < arguments.length; i++) detailedInfos[ids[i]] = sanitizeVulnerableInfo(ids[i], arguments[i]); atomic.dispatchEvent("vulnerableInfoChanged", detailedInfos); }); } });
self.change = function change(host, values) { var mod, hostnamed, call; var machine = self.lookup(host); if (values.label) { var conn_to = host; if (machine) conn_to = machine.connection_string; if (!machine || machine.label !== values.label) { hostnamed = cockpit.dbus("org.freedesktop.hostname1", { host: conn_to }); call = hostnamed.call("/org/freedesktop/hostname1", "org.freedesktop.hostname1", "SetPrettyHostname", [ values.label, true ]) .always(function() { hostnamed.close(); }) .fail(function(ex) { console.warn("couldn't set pretty host name: " + ex); }); } } if (machine && !machine.on_disk) mod = update_session_machine(machine, host, values); else mod = update_saved_machine(host, values); if (call) return cockpit.all(call, mod); return mod; };
validate: function() { var ex; var pw = $('#account-set-password-pw1').val(); if ($('#account-set-password-pw2').val() != pw) { ex = new Error(_("The passwords do not match")); ex.target = "#account-set-password-pw2"; } var dfd = cockpit.defer(); if (ex) dfd.reject(ex); else dfd.resolve(); var promise = password_quality(pw) .fail(function(ex) { ex.target = "#account-set-password-pw2"; }) .always(function(arg) { var strength = (this.state() == "resolved") ? arg : "weak"; var meter = $("#account-set-password-meter") .removeClass("weak okay good excellent"); if (pw) meter.addClass(strength); var message = $("#account-set-password-meter-message"); if (strength == "excellent") { message.text(_("Excellent password")); } else { message.text(""); } }); return cockpit.all(dfd, promise); },
function poll(tuned) { var dfd = cockpit.defer(); cockpit.all(tuned.call('/Tuned', 'com.redhat.tuned.control', 'is_running', []), tuned.call('/Tuned', 'com.redhat.tuned.control', 'active_profile', []), tuned.call('/Tuned', 'com.redhat.tuned.control', 'recommend_profile', [])) .done(function(is_running_result, active_result, recommended_result) { var is_running = is_running_result[0]; var active = is_running? active_result[0] : "none"; var recommended = recommended_result[0]; dfd.resolve("running", active, recommended); }) .fail(function(ex) { tuned_service.wait(function () { if (!tuned_service.exists) dfd.resolve("not-installed"); else if (tuned_service.state != "running") dfd.resolve("not-running"); else dfd.reject(ex); }); }); return dfd.promise(); }
function mdraid_remove(members) { // We can't use Promise.all() here until cockpit is able to dispatch es2015 promises // https://github.com/cockpit-project/cockpit/issues/10956 // eslint-disable-next-line cockpit/no-cockpit-all return cockpit.all(members.map(function (m) { return m.mdraid.RemoveDevice(m.block.path, { wipe: { t: 'b', v: true } }); })); }
function unmount(mounteds) { // We can't use Promise.all() here until cockpit is able to dispatch es2015 promises // https://github.com/cockpit-project/cockpit/issues/10956 // eslint-disable-next-line cockpit/no-cockpit-all return cockpit.all(mounteds.map(function (m) { if (m.fsys.MountPoints.length > 0) return m.fsys.Unmount({}); else return cockpit.resolve(); })); }
return cockpit.user().done(loggedUser => { const promises = Object.getOwnPropertyNames(VMS_CONFIG.Virsh.connections) .filter( // The 'root' user does not have its own qemu:///session just qemu:///system // https://bugzilla.redhat.com/show_bug.cgi?id=1045069 connectionName => canLoggedUserConnectSession(connectionName, loggedUser)) .map(connectionName => dispatch(action(connectionName, libvirtServiceName))); // We can't use Promise.all() here until cockpit is able to dispatch es2015 promises // https://github.com/cockpit-project/cockpit/issues/10956 // eslint-disable-next-line cockpit/no-cockpit-all return cockpit.all(promises); });
validate: function() { var ex, fails = []; var pw = $('#accounts-create-pw1').val(); if ($('#accounts-create-pw2').val() != pw) { ex = new Error(_("The passwords do not match")); ex.target = "#accounts-create-pw2"; fails.push(ex); } if (!$('#accounts-create-user-name').val()) { ex = new Error(_("No user name specified")); ex.target = '#accounts-create-user-name'; fails.push(ex); } if (!$('#accounts-create-real-name').val()) { ex = new Error(_("No real name specified")); ex.target = '#accounts-create-real-name'; fails.push(ex); } /* The first check is immediately complete */ var dfd = cockpit.defer(); if (fails.length) dfd.reject(fails); else dfd.resolve(); var promise_password = password_quality(pw) .fail(function(ex) { ex.target = "#accounts-create-pw2"; }) .always(function(arg) { var strength = this.state() == "resolved" ? arg : "weak"; var meter = $("#accounts-create-password-meter") .removeClass("weak okay good excellent"); if (pw) meter.addClass(strength); var message = $("#accounts-create-password-meter-message"); if (strength == "excellent") { message.text(_("Excellent password")); } else { message.text(""); } }); var promise_username = this.check_username() .fail(function(ex) { ex.target = "#accounts-create-user-name"; }); return cockpit.all(dfd, promise_password, promise_username); },
export function prepare_available_spaces(client, spcs) { function prepare(spc) { if (spc.type == 'block') return cockpit.resolve(spc.block.path); else if (spc.type == 'free') { var block_ptable = client.blocks_ptable[spc.block.path]; return block_ptable.CreatePartition(spc.start, spc.size, "", "", { }); } } // We can't use Promise.all() here until cockpit is able to dispatch es2015 promises // https://github.com/cockpit-project/cockpit/issues/10956 // eslint-disable-next-line cockpit/no-cockpit-all return cockpit.all(spcs.map(prepare)); }
function handle_vg(p) { var vg = client.vgroups[p]; var pvs = by_vgroup[p]; // If we would remove all physical volumes of a volume // group, remove the whole volume group instead. if (pvs.length == client.vgroups_pvols[p].length) { return vg.Delete({ 'tear-down': { t: 'b', v: true } }); } else { // We can't use Promise.all() here until cockpit is able to dispatch es2015 promises // https://github.com/cockpit-project/cockpit/issues/10956 // eslint-disable-next-line cockpit/no-cockpit-all return cockpit.all(pvs.map(function (pv) { return vg.RemoveDevice(pv.path, true, {}); })); } }
export function teardown_active_usage(client, usage) { // The code below is complicated by the fact that the last // physical volume of a volume group can not be removed // directly (even if it is completely empty). We want to // remove the whole volume group instead in this case. // // However, we might be removing the last two (or more) // physical volumes here, and it is easiest to catch this // condition upfront by reshuffling the data structures. function unmount(mounteds) { // We can't use Promise.all() here until cockpit is able to dispatch es2015 promises // https://github.com/cockpit-project/cockpit/issues/10956 // eslint-disable-next-line cockpit/no-cockpit-all return cockpit.all(mounteds.map(function (m) { if (m.fsys.MountPoints.length > 0) return m.fsys.Unmount({}); else return cockpit.resolve(); })); } function mdraid_remove(members) { // We can't use Promise.all() here until cockpit is able to dispatch es2015 promises // https://github.com/cockpit-project/cockpit/issues/10956 // eslint-disable-next-line cockpit/no-cockpit-all return cockpit.all(members.map(function (m) { return m.mdraid.RemoveDevice(m.block.path, { wipe: { t: 'b', v: true } }); })); } function pvol_remove(pvols) { var by_vgroup = { }; var p; pvols.forEach(function (p) { if (!by_vgroup[p.vgroup.path]) by_vgroup[p.vgroup.path] = [ ]; by_vgroup[p.vgroup.path].push(p.block); }); function handle_vg(p) { var vg = client.vgroups[p]; var pvs = by_vgroup[p]; // If we would remove all physical volumes of a volume // group, remove the whole volume group instead. if (pvs.length == client.vgroups_pvols[p].length) { return vg.Delete({ 'tear-down': { t: 'b', v: true } }); } else { // We can't use Promise.all() here until cockpit is able to dispatch es2015 promises // https://github.com/cockpit-project/cockpit/issues/10956 // eslint-disable-next-line cockpit/no-cockpit-all return cockpit.all(pvs.map(function (pv) { return vg.RemoveDevice(pv.path, true, {}); })); } } for (p in by_vgroup) handle_vg(p); } // We can't use Promise.all() here until cockpit is able to dispatch es2015 promises // https://github.com/cockpit-project/cockpit/issues/10956 // eslint-disable-next-line cockpit/no-cockpit-all return cockpit.all([ unmount(usage.raw.filter(function(use) { return use.usage == "mounted" })), mdraid_remove(usage.raw.filter(function(use) { return use.usage == "mdraid-member" })), pvol_remove(usage.raw.filter(function(use) { return use.usage == "pvol" })) ]); }