-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm-create.php
66 lines (55 loc) · 1.66 KB
/
vm-create.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// START CREATE SESSION
session_start();
// INCLUDE CONNECT FILE
include 'connect.php';
// SET MESSAGE VAR
$message = '';
// SET POST VARIABLES
$name = escapeshellarg($_POST['hostname']);
$arch = escapeshellarg("");
$memory = escapeshellarg($_POST['memory']);
$maxmemMB = escapeshellarg($_POST['memory']);
$vcpus = escapeshellarg($_POST['cpus']);
$newdisk = escapeshellarg($_POST['newdisk']);
$iso_image = escapeshellarg($_POST['iso']);
$network = escapeshellarg($_POST['network']);
// CHECK FOR DISK CREATION
if (isset($_POST['existdisk']) && $_POST['newdisk'] == "") {
echo "Using existing disk...";
$disk=escapeshellarg($_POST['existdisk']);
echo $disk;
}
if ($_POST['newdisk'] != "") {
echo "Creating new disk...";
$disk='/var/lib/libvirt/images/' . $name . '.qcow2,size=' . $newdisk . ' ';
echo $disk;
}
// CHECK FOR BACKUP CONFIRMATION
if (isset($_POST['backup'])) {
$backup = "true";
} else {
$backup = "false";
}
// CREATE VM DOMAIN USING USER INPUT
$command = shell_exec('
virt-install \
--connect qemu:///system \
--virt-type kvm \
--name ' . $name . '\
--ram ' . $memory . '\
--vcpus ' . $vcpus . '\
--disk path=' . $disk . '\
--vnc \
--cdrom ' . $iso_image . ' \
--network network=' . $network . ' \
--metadata description=' . $backup . ' \
--osinfo detect=on \
> /dev/null 2>/dev/null &');
// ECHO COMMAND
// echo "<pre>$command</pre>";
// CREATE INITIAL SCREENSHOT FROM SEIDR-THUMB
shell_exec('/opt/seidr/seidr-thumb.sh');
//$_SESSION['message'] = $message;
header("Location: machines.php");
?>