forked from Seitanas/kvm-vdi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_vm.php
263 lines (258 loc) · 10.5 KB
/
new_vm.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
/*
KVM-VDI
Tadas Ustinavičius
Vilnius University.
Center of Information Technology Development.
Vilnius,Lithuania.
2016-10-20
*/
include ('functions/config.php');
require_once('functions/functions.php');
if (!check_session()){
header ("Location: $serviceurl/?error=1");
exit;
}
$h_reply=get_SQL_array("SELECT * FROM hypervisors WHERE maintenance=0");
set_lang();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="inc/js/kvm-vdi.js"></script>
</head>
<body>
<style>
.input-group-addon {
min-width:80px;
}
</style>
<form id="new_vm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><?php echo _("Create virtual machine(s)");?></h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-5">
<label><?php echo _("Machine type:");?></label>
<select class="form-control selectClass" name="machine_type" id="machine_type" required tabindex="1">
<option selected value=""><?php echo _("Please select machine type");?></option>
<option value="simplemachine"><?php echo _("Simple machine");?></option>
<option value="initialmachine"><?php echo _("Initial machine");?></option>
<option value="sourcemachine"><?php echo _("Source machine");?></option>
<option value="vdimachine"><?php echo _("VDI machine");?></option>
</select>
</div>
<div class="col-md-5">
<label><?php echo _("Target hypervisor:");?></label>
<select class="form-control selectClass" name="hypervisor" id="hypervisor" required tabindex="2">
<option selected value=""><?php echo _("Please select hypervisor");?></option>
<?php
$x=0;
while ($x<sizeof($h_reply)){
echo '<option value="' . $h_reply[$x]['id'] . '">' . $h_reply[$x]['ip'] . '</option>';
++$x;
}?>
</select>
</div>
</div>
<div class="row">
<?php
echo '<div class="col-md-5 hide" id="hypervisor-sourceimage">
<label>' . _("Use volume from:") . '</label>';
$v_reply=get_SQL_array("SELECT id,name,machine_type,hypervisor FROM vms WHERE (machine_type='sourcemachine' OR machine_type='initialmachine') ORDER By name");
$y=0;
echo '<select class="form-control" name="source_volume" id="source_volume">' ."\n";
echo '<option selected value="">' . _("Please select source") . '</option>'."\n";
while ($y<sizeof($v_reply)){
echo '<option class="' . $v_reply[$y]['machine_type'] . ' hypervisor-' . $v_reply[$y]['hypervisor'] . '" value="' . $v_reply[$y]['id'] . '">' . $v_reply[$y]['name'] . '</option>' ."\n";
++$y;
}
echo '</select>' . "\n";
echo '</div>' . "\n";
?>
<div id="hypervisor-manualpath" class="hide">
<div class="col-md-5">
<label><?php echo _("Specify disk path:");?></label>
<input type="text" name="source_drivepath" class="form-control" id="source_drivepath" value="<?php echo $default_imagepath; ?>">
</div>
<div class="col-md-4">
<label><?php echo _("Disk size");?></label>
<div class="input-group">
<input type="number" min="1" value="10" name="source_drive_size" id="source_drive_size" class="form-control" type="number">
<span class="input-group-addon">GB</span>
</div>
</div>
</div>
</div>
<div class="hide" id="hypervisor-imagepath">
<div class="row">
<div class="col-md-9">
<label><?php echo _("Mount CD iso:");?></label>
<div class="input-group">
<span class="input-group-addon" style="min-width:40px;">
<input type="checkbox" name="iso_image" id="iso_image">
</span>
<select class="form-control" name="iso_path" id="iso_path" disabled>
<option value=""><?php echo _("Select ISO image");?></option>
<?php
$x=0;
while ($x<sizeof($h_reply)){
ssh_connect($h_reply[$x]['ip'].":".$h_reply[$x]['port']);
$files=explode("\n",ssh_command("sudo ls " . $default_iso_path . "|grep -i .iso", true));
foreach ($files as &$value) {
if (!empty($value))
echo '<option class="iso_option hypervisor_iso-' . $h_reply[$x]['id'] . '" value="' . $value . '">' . $value . '</option>'."\n";
}
++$x;
}
?>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo _("Hardware info:");?></label>
<div class="input-group">
<input type="number" min="1" value="1" class="form-control" name="numsock" id="numsock">
<span class="input-group-addon"><?php echo _("Sockets");?></span>
</div>
<div class="input-group">
<input type="number" min="1" value="1" class="form-control" name="numcore" id="numcore">
<span class="input-group-addon"><?php echo _("Cores");?></span>
</div>
<div class="input-group">
<input type="number" min="1" value="1" class="form-control" name="numram" id="numram">
<span class="input-group-addon"><?php echo _("GB RAM");?></span>
</div>
<div class="input-group">
<input type="text" value="<?php echo $default_bridge; ?>" class="form-control" name="network" id="network">
<span class="input-group-addon"><?php echo _("Network");?></span>
</div>
</div>
<div class="col-md-8" id="newmachine-os">
<label>System info:</label>
<div class="input-group">
<span class="input-group-addon"><?php echo _("OS type");?></span>
<select class="form-control osselection" name="os_type" id="os_type" tabindex="3" required type="number">
<option selected value=""><?php echo _("Please select OS type");?></option>
<option value="linux"><?php echo _("Linux");?></option>
<option value="windows"><?php echo _("Windows");?></option>
</select>
</div>
<div class="input-group hide" id="os">
<span class="input-group-addon"><?php echo _("Version");?></span>
<select class="form-control osselection" name="os_version" id="os_version" tabindex="4" required>
<option selected value=""><?php echo _("Please select version");?></option>
<option class="linux" value="debiansqueeze">Debian Squeeze (or newer)</option>
<option class="linux" value="debianlenny">Debian Lenny</option>
<option class="linux" value="debianetch">Debian Etch</option>
<option class="linux" value="ubuntuprecise">Ubuntu 12.04 LTS</option>
<option class="linux" value="ubuntusaucy">Ubuntu 13.10 (or newer)</option>
<option class="linux" value="fedora18">Fedora 18</option>
<option class="linux" value="fedora19">Fedora 19</option>
<option class="linux" value="fedora20">Fedora 20</option>
<option class="windows" value="win7">Microsoft Windows 7 (or newer)</option>
<option class="windows" value="vista">Microsoft Windows Vista</option>
<option class="windows" value="winxp">Microsoft Windows XP</option>
<option class="windows" value="win2k8">Microsoft Windows Server 2008</option>
<option class="windows" value="win2k3">Microsoft Windows Server 2003</option>
</select>
</div>
</div>
</div>
<div class="row">
<hr class="divider">
<div class="col-md-5">
<label><?php echo _("Mass deployment");?></label>
</div>
</div>
<div class="row">
<div class="col-md-5">
<label><?php echo _("Prepend machine name:");?></label>
<input type="text" name="machinename" id="machinename" placeholder="somename-" class="form-control" required pattern="[a-zA-Z0-9-]+" oninvalid="setCustomValidity(<?php echo ("'Illegal characters detected'");?>)" onchange="try{setCustomValidity('')}catch(e){}" >
</div>
<div class="col-md-5">
<label><?php echo _("Number of machines to create:");?></label>
<input type="number" name="machinecount" id="machinecount" min="1" value="1" class="form-control" required>
</div>
</div>
</div>
<div class="modal-footer">
<div class="row">
<div class="col-md-7">
<div class="alert hide text-left" id="new_vm_creation_info_box"></div>
</div>
<div class="col-md-5">
<button type="button" class="btn btn-default create_vm_buttons" data-dismiss="modal"><?php echo _("Close");?></button>
<button type="button" class="btn btn-primary create_vm_buttons" id="create-vm-button-click"><?php echo _("Create VMs");?></button>
<input type="submit" class="hide">
</div>
</div>
</div>
</div>
</form>
<script>
$('.selectClass').on('change', function(){
$('#hypervisor-sourceimage').addClass('hide');
$('#hypervisor-imagepath').addClass('hide');
$('.sourcemachine').hide();
$('.initialmachine').hide();
$('.iso_option').hide();
$hypervisor_id=$('#hypervisor').val();
if (($('#machine_type').val() == 'initialmachine' || $('#machine_type').val() == 'vdimachine') && $hypervisor_id!='') {
$('#hypervisor-sourceimage').removeClass('hide');
$('.hypervisor-'+$hypervisor_id).show();
if ($('#machine_type').val() == 'initialmachine'){
$('.initialmachine').hide();
$('#source_volume').prop('selectedIndex',0);
}
if ($('#machine_type').val() == 'vdimachine'){
$('.sourcemachine').hide();
$('#source_volume').prop('selectedIndex',0);
}
$('#hypervisor-'+$hypervisor_id).removeClass('hide');
$('#hypervisor-manualpath').removeAttr('required');
$('#source_drivepath').prop('required',false);
$('#source_volume').prop('required',true);
$('.osselection').prop('required',false);
}
if (($('#machine_type').val() == 'simplemachine' || $('#machine_type').val() == 'sourcemachine') && $hypervisor_id!='') {
$('.hypervisor_iso-'+$hypervisor_id).show();
$('#hypervisor-manualpath').removeClass('hide');
$('#hypervisor-imagepath').removeClass('hide');
$('#source_drivepath').prop('required',true);
$('#source_volume').prop('required',false);
$('.osselection').prop('required',true);
}
})
$('#os_type').on('change', function(){
if ($('#os_type').val()=='linux'){
$('#os_version').prop('selectedIndex',0);
$('#os').removeClass('hide');
$('.windows').hide();
$('.linux').show();
}
if ($('#os_type').val()=='windows'){
$('#os_version').prop('selectedIndex',0);
$('#os').removeClass('hide');
$('.windows').show();
$('.linux').hide();
}
})
$('#iso_image').on('change', function(){
if (this.checked) {
$('#iso_path').prop('disabled', false);
}
else {
$('#iso_path').prop('disabled', true);
}
})
</script>
</body>
</html>