| 1 |
/* |
| 2 |
* Copyright (C) 2023 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
import cockpit from "cockpit"; |
| 7 |
import client from "../client.js"; |
| 8 |
|
| 9 |
import { dialog_open, TextInput, SelectSpaces } from "../dialog.jsx"; |
| 10 |
import { validate_lvm2_name, get_available_spaces, prepare_available_spaces } from "../utils.js"; |
| 11 |
|
| 12 |
const _ = cockpit.gettext; |
| 13 |
|
| 14 |
export function create_vgroup() { |
| 15 |
function find_vgroup(name) { |
| 16 |
for (const p in client.vgroups) { |
| 17 |
if (client.vgroups[p].Name == name) |
| 18 |
return client.vgroups[p]; |
| 19 |
} |
| 20 |
return null; |
| 21 |
} |
| 22 |
|
| 23 |
let name; |
| 24 |
for (let i = 0; i < 1000; i++) { |
| 25 |
name = "vgroup" + i.toFixed(); |
| 26 |
if (!find_vgroup(name)) |
| 27 |
break; |
| 28 |
} |
| 29 |
|
| 30 |
dialog_open({ |
| 31 |
Title: _("Create volume group"), |
| 32 |
Fields: [ |
| 33 |
TextInput("name", _("Name"), |
| 34 |
{ |
| 35 |
value: name, |
| 36 |
validate: validate_lvm2_name |
| 37 |
}), |
| 38 |
SelectSpaces("disks", _("Disks"), |
| 39 |
{ |
| 40 |
empty_warning: _("No disks are available."), |
| 41 |
validate: function (disks) { |
| 42 |
if (disks.length === 0) |
| 43 |
return _("At least one disk is needed."); |
| 44 |
}, |
| 45 |
spaces: get_available_spaces() |
| 46 |
}) |
| 47 |
], |
| 48 |
Action: { |
| 49 |
Title: _("Create"), |
| 50 |
action: function (vals) { |
| 51 |
return prepare_available_spaces(client, vals.disks).then(paths => { |
| 52 |
client.manager_lvm2.VolumeGroupCreate(vals.name, paths, { }); |
| 53 |
}); |
| 54 |
} |
| 55 |
} |
| 56 |
}); |
| 57 |
} |