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