Example #1
0
function nas_create_default_mounts($obj, $mapping = array())
{
    $mounts = nas_list_default_mounts();
    foreach ($mounts as $m) {
        $storage_export_id = $m["storage_export_id"];
        if ($storage_export_id) {
            $e = nas_get_export_by_id($storage_export_id);
            if ($e["default"] != "no") {
                $storage_export_id = $mapping[$storage_export_id];
            }
        }
        nas_mount_add($storage_export_id, $m["vps_id"] ? $m["vps_id"] : $obj["vps_id"], $m["mode"], $m["server_id"], nas_resolve_vars($m["src"], $obj), $m["dst"], $m["mount_opts"], $m["umount_opts"], $m["mount_type"], $m["cmd_premount"], $m["cmd_postmount"], $m["cmd_preumount"], $m["cmd_postumount"], false, false);
    }
}
Example #2
0
    function clone_vps($m_id, $server_id, $hostname, $configs, $features, $backuper)
    {
        global $db;
        $sql = 'INSERT INTO vps
			SET m_id = "' . $db->check($m_id) . '",
				vps_created = "' . $db->check(time()) . '",
				vps_template = "' . $db->check($this->ve["vps_template"]) . '",
				vps_info ="' . $db->check("Cloned from {$this->veid}") . '",
				vps_hostname ="' . $db->check($hostname) . '",
				dns_resolver_id ="' . $db->check($this->ve["dns_resolver_id"]) . '",
				vps_server ="' . $db->check($server_id) . '",
				vps_onboot ="' . $db->check($this->ve["vps_onboot"]) . '",
				vps_onstartall = ' . $db->check($this->ve["vps_onstartall"]) . ',
				vps_features_enabled = ' . $db->check($features ? $this->ve["vps_features_enabled"] : 0) . ',
				vps_backup_enabled = ' . $db->check($backuper ? $this->ve["vps_backup_enabled"] : 1) . ',
				vps_backup_exclude = "' . $db->check($backuper ? $this->ve["vps_backup_exclude"] : '') . '",
				vps_config = "' . $db->check($configs ? $this->ve["vps_config"] : '') . '"';
        $db->query($sql);
        $clone = vps_load($db->insert_id());
        $src_node = new cluster_node($this->ve["vps_server"]);
        $dst_node = new cluster_node($server_id);
        $params = array("src_veid" => $this->veid, "src_addr" => $this->ve["server_ip4"], "src_node_type" => $src_node->role["fstype"], "dst_node_type" => $dst_node->role["fstype"]);
        add_transaction($_SESSION["member"]["m_id"], $server_id, $clone->veid, $server_id == $this->ve["vps_server"] ? T_CLONE_VE_LOCAL : T_CLONE_VE_REMOTE, $params);
        switch ($configs) {
            case 0:
                $clone->add_default_configs("default_config_chain");
                break;
            case 1:
                $db->query("INSERT INTO vps_has_config (vps_id, config_id, `order`) SELECT '" . $db->check($clone->veid) . "' AS vps_id, config_id, `order` FROM vps_has_config WHERE vps_id = '" . $db->check($this->veid) . "'");
                if ($clone->ve["vps_config"]) {
                    $clone->update_custom_config($clone->ve["vps_config"]);
                } else {
                    $clone->applyconfigs();
                }
                break;
            case 2:
                $clone->add_default_configs("playground_default_config_chain");
                break;
        }
        // Clone mounts - exports are the same, except backup, that must be created
        $db->query("INSERT INTO vps_mount (vps_id, src, dst, mount_opts, umount_opts, type, server_id, storage_export_id, mode, cmd_premount, cmd_postmount, cmd_preumount, cmd_postumount)\n\t            SELECT " . $clone->veid . " AS vps_id, src, dst, mount_opts, umount_opts, type, server_id, storage_export_id, mode, cmd_premount, cmd_postmount, cmd_preumount, cmd_postumount\n\t            FROM vps_mount\n\t            WHERE vps_id = " . $db->check($this->veid));
        $def_exports = nas_list_default_exports("vps");
        $cloned_backup_export = 0;
        foreach ($def_exports as $e) {
            if ($e["export_type"] == "backup") {
                $cloned_backup_export = nas_export_add($clone->ve["m_id"], $e["root_id"], nas_resolve_vars($e["dataset"], $clone->ve), nas_resolve_vars($e["path"], $clone->ve), $e["export_quota"], $e["user_editable"], $e["export_type"]);
                break;
            }
        }
        if ($cloned_backup_export) {
            $db->query("UPDATE vps_mount SET storage_export_id = " . $db->check($cloned_backup_export) . "\n\t\t            WHERE vps_id = " . $db->check($clone->veid) . " AND storage_export_id = " . $db->check($this->ve["vps_backup_export"]));
            $clone->set_backuper(NULL, $cloned_backup_export, false, true);
        }
        $clone->mount_regen();
        $clone->set_hostname($hostname);
        if ($features && $this->ve["vps_features_enabled"]) {
            add_transaction($_SESSION["member"]["m_id"], $server_id, $clone->veid, T_ENABLE_FEATURES);
        }
        $this->info();
        if ($this->ve["vps_up"]) {
            $clone->start();
        }
        return $clone;
    }