Add IP Aliasing (#72)

* complete support for IP Alias's throughout panel

Includes a database change and probably better allocation handling
anyways

closes #37
This commit is contained in:
Dane Everitt 2016-08-31 16:03:37 -04:00 committed by GitHub
parent f1a3008a50
commit e8c175f385
14 changed files with 206 additions and 76 deletions

View file

@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class FixColumnNameForDatabases extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('databases', function (Blueprint $table) {
$table->renameColumn('server', 'server_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('databases', function (Blueprint $table) {
$table->renameColumn('server_id', 'server');
});
}
}

View file

@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddIpAlias extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('allocations', function (Blueprint $table) {
$table->text('ip_alias')->nullable()->after('ip');
});
$allocations = DB::select('SELECT id, ip FROM allocations');
foreach($allocations as $allocation) {
DB::update(
'UPDATE allocations SET ip_alias = :ip WHERE id = :id',
[
'ip' => $allocation->ip,
'id' => $allocation->id
]
);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('allocations', function (Blueprint $table) {
$table->dropColumn('ip_alias');
});
}
}

View file

@ -0,0 +1,84 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ModifyIpStorageMethod extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('servers', function (Blueprint $table) {
$table->mediumInteger('allocation')->unsigned()->after('oom_disabled');
});
// Parse All Servers
$servers = DB::select('SELECT id, ip, port, node FROM servers');
foreach($servers as $server) {
$allocation = DB::select(
'SELECT id FROM allocations WHERE ip = :ip AND port = :port AND node = :node',
[
'ip' => $server->ip,
'port' => $server->port,
'node' => $server->node
]
);
if (isset($allocation[0])) {
DB::update(
'UPDATE servers SET allocation = :alocid WHERE id = :id',
[
'alocid' => $allocation[0]->id,
'id' => $server->id
]
);
}
}
// Updated the server allocations, remove old fields
Schema::table('servers', function (Blueprint $table) {
$table->dropColumn('ip');
$table->dropColumn('port');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('servers', function (Blueprint $table) {
$table->text('ip')->after('allocation');
$table->integer('port')->unsigned()->after('ip');
});
// Find the allocations and reset the servers...
$servers = DB::select('SELECT id, allocation FROM servers');
foreach($servers as $server) {
$allocation = DB::select('SELECT * FROM allocations WHERE id = :alocid', [ 'alocid' => $server->allocation ]);
if (isset($allocation[0])) {
DB::update(
'UPDATE servers SET ip = :ip, port = :port WHERE id = :id',
[
'ip' => $allocation[0]->ip,
'port' => $allocation[0]->port,
'id' => $server->id
]
);
}
}
Schema::table('servers', function (Blueprint $table) {
$table->dropColumn('allocation');
});
}
}