function docker_add_container_public_ip($host, $containerID, $ip)
{
    $pipework = get_config()->pipework_path;
    $bridge = get_config()->wanbridge;
    $cmd = "{$pipework} {$bridge} {$containerID} {$ip}";
    dbg_log("get_container_details: {$cmd}");
    $ssh = ssh_connect($host);
    $json = $ssh->exec($cmd);
    dbg_log($json);
}
Example #2
0
Vilnius, Lithuania.
*/
include 'functions/config.php';
require_once 'functions/functions.php';
if (!check_session()) {
    header("Location: {$serviceurl}/?error=1");
    exit;
}
$vm = addslashes($_GET['vm']);
$hypervisor = addslashes($_GET['hypervisor']);
$action = addslashes($_GET['action']);
if (empty($vm) || empty($hypervisor)) {
    exit;
}
$h_reply = get_SQL_line("SELECT * FROM hypervisors WHERE id='{$hypervisor}'");
ssh_connect($h_reply[2] . ":" . $h_reply[3]);
if ($action == "mass_on" || $action == "mass_off" || $action == "mass_destroy") {
    $child_vms = get_SQL_array("SELECT name FROM vms WHERE source_volume='{$vm}'");
    $x = 0;
    while ($child_vms[$x]['name']) {
        if ($action == "mass_on") {
            ssh_command("sudo virsh start " . $child_vms[$x]['name'], true);
        }
        if ($action == "mass_off") {
            ssh_command("sudo virsh shutdown " . $child_vms[$x]['name'], true);
        }
        if ($action == "mass_destroy") {
            ssh_command("sudo virsh destroy " . $child_vms[$x]['name'], true);
        }
        ++$x;
    }
Example #3
0
function reload_vm_info()
{
    include 'config.php';
    $x = 0;
    while ($hypervizors[$x]) {
        $tmp = explode(":", $hypervizors[$x]);
        $ip = $tmp[0];
        $port = $tmp[1];
        $sql_reply = get_SQL_line("SELECT id FROM hypervisors WHERE ip='{$ip}'");
        if (empty($sql_reply[0])) {
            add_SQL_line("INSERT INTO  hypervisors (ip,port) VALUES ('{$ip}','{$port}')");
        } else {
            add_SQL_line("UPDATE hypervisors SET ip='{$ip}', port='{$port}' WHERE id='{$sql_reply['0']}'");
        }
        $sql_reply = get_SQL_line("SELECT id FROM hypervisors WHERE ip='{$ip}'");
        $hyper_id = $sql_reply[0];
        ssh_connect($ip . ":" . $port);
        $output = ssh_command("sudo virsh list --all |tail -n +3|head -n -1|awk '{print \$2" . '" "' . "\$3}'", true);
        $vms = array();
        $output = str_replace("\n", " ", $output);
        $vms = explode(" ", $output);
        $y = 0;
        while ($vms[$y]) {
            $sql_reply = get_SQL_line("SELECT id FROM vms WHERE name='{$vms[$y]}' AND hypervisor='{$hyper_id}'");
            $state = $vms[$y + 1];
            if (empty($sql_reply[0])) {
                add_SQL_line("INSERT INTO  vms (name,hypervisor,state) VALUES ('{$vms[$y]}','{$hyper_id}','{$state}')");
            } else {
                add_SQL_line("UPDATE vms SET name='{$vms[$y]}', hypervisor='{$hyper_id}', state='{$state}' WHERE id='{$sql_reply['0']}'");
            }
            $y = $y + 2;
        }
        ++$x;
    }
}
Example #4
0
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 ($h_reply[$x]['id']) {
    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">
<?php

include_once dirname(__FILE__) . "/../lib/docker_api.php";
include_once dirname(__FILE__) . "/../lib/utilities.php";
$ssh = ssh_connect("instance-11842.bigstep.io");
dbg_log($ssh->exec("ls /"));
Example #6
0
$numram = 1024 * $_POST['numram'];
$network = $_POST['network'];
$machinename = $_POST['machinename'];
$machinecount = $_POST['machinecount'];
$os_type = $_POST['os_type'];
$os_version = $_POST['os_version'];
if (check_empty($machine_type, $hypervisor, $numcpu, $numcore, $numram, $network, $machinename, $machinecount)) {
    header("Location: {$serviceurl}/dashboard.php");
    exit;
}
$cdrom_cmd = "";
if ($iso_image == 'on') {
    $cdrom_cmd = "--cdrom " . $default_iso_path . '/' . $iso_path;
}
$h_reply = get_SQL_line("SELECT ip, port FROM hypervisors WHERE id='{$hypervisor}'");
ssh_connect($h_reply[0] . ":" . $h_reply[1]);
if ($machine_type == 'simplemachine' || $machine_type == 'sourcemachine') {
    echo $h_reply[0] . "ddd";
    $x = 0;
    while ($x < $machinecount) {
        $name = $machinename . sprintf("%0" . strlen($machinecount) . "s", $x + 1);
        $disk = $source_drivepath . '/' . $name . "-" . uniqid() . ".qcow2";
        $vm_cmd = "sudo virt-install --name=" . $name . " --disk path=" . $disk . ",format=qcow2,bus=virtio,cache=none --soundhw=ac97 --vcpus=" . $numcpu . ",cores=" . $numcore . " --ram=" . $numram . " --network bridge=" . $network . ",model=virtio --os-type=" . $os_type . " --os-variant=" . $os_version . " --graphics spice,listen=0.0.0.0 --redirdev usb,type=spicevmc --video qxl --noreboot " . $cdrom_cmd;
        $drive_cmd = "sudo qemu-img create -f qcow2 -o size=" . $source_drive_size . "G " . $disk;
        add_SQL_line("INSERT INTO  vms (name,hypervisor,machine_type) VALUES ('{$name}','{$hypervisor}','{$machine_type}')");
        ssh_command($drive_cmd, true);
        ssh_command($vm_cmd, true);
        ++$x;
    }
}
if ($machine_type == 'initialmachine') {