🎉 Finishes server creation 🎉
This commit is contained in:
parent
a7fdb9618c
commit
9d2d726992
5 changed files with 136 additions and 17 deletions
|
@ -62,6 +62,7 @@ class ServersController extends Controller
|
||||||
->join('locations', 'nodes.location', '=', 'locations.id')
|
->join('locations', 'nodes.location', '=', 'locations.id')
|
||||||
->join('services', 'servers.service', '=', 'services.id')
|
->join('services', 'servers.service', '=', 'services.id')
|
||||||
->join('service_options', 'servers.option', '=', 'service_options.id')
|
->join('service_options', 'servers.option', '=', 'service_options.id')
|
||||||
|
->where('servers.id', $id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
return view('admin.servers.view', [
|
return view('admin.servers.view', [
|
||||||
|
|
|
@ -77,7 +77,7 @@ class ServerRepository
|
||||||
|
|
||||||
// Verify IP & Port are a.) free and b.) assigned to the node.
|
// Verify IP & Port are a.) free and b.) assigned to the node.
|
||||||
// We know the node exists because of 'exists:nodes,id' in the validation
|
// We know the node exists because of 'exists:nodes,id' in the validation
|
||||||
$node = Models\Node::find($data['node']);
|
$node = Models\Node::getByID($data['node']);
|
||||||
$allocation = Models\Allocation::where('ip', $data['ip'])->where('port', $data['port'])->where('node', $data['node'])->whereNull('assigned_to')->first();
|
$allocation = Models\Allocation::where('ip', $data['ip'])->where('port', $data['port'])->where('node', $data['node'])->whereNull('assigned_to')->first();
|
||||||
|
|
||||||
// Something failed in the query, either that combo doesn't exist, or it is in use.
|
// Something failed in the query, either that combo doesn't exist, or it is in use.
|
||||||
|
@ -94,6 +94,9 @@ class ServerRepository
|
||||||
throw new DisplayException('The requested service option does not exist for the specified service.');
|
throw new DisplayException('The requested service option does not exist for the specified service.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load up the Service Information
|
||||||
|
$service = Models\Service::find($option->parent_service);
|
||||||
|
|
||||||
// Check those Variables
|
// Check those Variables
|
||||||
$variables = Models\ServiceVariables::where('option_id', $data['option'])->get();
|
$variables = Models\ServiceVariables::where('option_id', $data['option'])->get();
|
||||||
$variableList = [];
|
$variableList = [];
|
||||||
|
@ -105,12 +108,11 @@ class ServerRepository
|
||||||
if ($variable->required === 1) {
|
if ($variable->required === 1) {
|
||||||
throw new DisplayException('A required service option variable field (env_' . $variable->env_variable . ') was missing from the request.');
|
throw new DisplayException('A required service option variable field (env_' . $variable->env_variable . ') was missing from the request.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$variableList = array_merge($variableList, [[
|
$variableList = array_merge($variableList, [[
|
||||||
'var_id' => $variable->id,
|
'id' => $variable->id,
|
||||||
'var_val' => $variable->default_value
|
'env' => $variable->env_variable,
|
||||||
|
'val' => $variable->default_value
|
||||||
]]);
|
]]);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,10 +122,10 @@ class ServerRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
$variableList = array_merge($variableList, [[
|
$variableList = array_merge($variableList, [[
|
||||||
'var_id' => $variable->id,
|
'id' => $variable->id,
|
||||||
'var_val' => $data['env_' . $variable->env_variable]
|
'env' => $variable->env_variable,
|
||||||
|
'val' => $data['env_' . $variable->env_variable]
|
||||||
]]);
|
]]);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,25 +190,78 @@ class ServerRepository
|
||||||
$allocation->save();
|
$allocation->save();
|
||||||
|
|
||||||
// Add Variables
|
// Add Variables
|
||||||
|
$environmentVariables = [];
|
||||||
|
$environmentVariables = array_merge($environmentVariables, [
|
||||||
|
'STARTUP' => $data['startup']
|
||||||
|
]);
|
||||||
foreach($variableList as $item) {
|
foreach($variableList as $item) {
|
||||||
|
$environmentVariables = array_merge($environmentVariables, [
|
||||||
|
$item['env'] => $item['val']
|
||||||
|
]);
|
||||||
Models\ServerVariables::create([
|
Models\ServerVariables::create([
|
||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'variable_id' => $item['var_id'],
|
'variable_id' => $item['id'],
|
||||||
'variable_value' => $item['var_val']
|
'variable_value' => $item['val']
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Add logic for communicating with Wings to make the server in here.
|
$client = Models\Node::guzzleRequest($node->id);
|
||||||
// We should add the server regardless of the Wings response, but
|
$client->request('POST', '/servers', [
|
||||||
// handle the error and then allow the server to be re-deployed.
|
'headers' => [
|
||||||
|
'X-Access-Token' => $node->daemonSecret
|
||||||
|
],
|
||||||
|
'json' => [
|
||||||
|
'uuid' => (string) $server->uuid,
|
||||||
|
'user' => $server->username,
|
||||||
|
'build' => [
|
||||||
|
'default' => [
|
||||||
|
'ip' => $server->ip,
|
||||||
|
'port' => (int) $server->port
|
||||||
|
],
|
||||||
|
'ports' => [
|
||||||
|
(string) $server->ip => [ (int) $server->port ]
|
||||||
|
],
|
||||||
|
'env' => $environmentVariables,
|
||||||
|
'memory' => (int) $server->memory,
|
||||||
|
'swap' => (int) $server->swap,
|
||||||
|
'io' => (int) $server->io,
|
||||||
|
'cpu' => (int) $server->cpu,
|
||||||
|
'disk' => (int) $server->disk,
|
||||||
|
'image' => (isset($data['custom_image_name'])) ? $data['custom_image_name'] : $option->docker_image
|
||||||
|
],
|
||||||
|
'service' => [
|
||||||
|
'type' => $service->file,
|
||||||
|
'option' => $option->tag
|
||||||
|
],
|
||||||
|
'keys' => [
|
||||||
|
(string) $server->daemonSecret => [
|
||||||
|
's:get',
|
||||||
|
's:power',
|
||||||
|
's:console',
|
||||||
|
's:command',
|
||||||
|
's:files:get',
|
||||||
|
's:files:read',
|
||||||
|
's:files:post',
|
||||||
|
's:files:delete',
|
||||||
|
's:files:upload',
|
||||||
|
's:set-password'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'rebuild' => false
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
return $server->id;
|
return $server->id;
|
||||||
} catch (\Exception $e) {
|
} catch (\GuzzleHttp\Exception\TransferException $ex) {
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
throw $e;
|
throw new DisplayException('An error occured while attempting to update the configuration: ' . $ex->getMessage());
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
DB::rollBack();
|
||||||
|
Log:error($ex);
|
||||||
|
throw $ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
31
database/migrations/2016_01_03_204358_add_service_file.php
Normal file
31
database/migrations/2016_01_03_204358_add_service_file.php
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class AddServiceFile extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('services', function (Blueprint $table) {
|
||||||
|
$table->string('file')->after('description');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('services', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('file');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class AddServiceOptionTag extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('service_options', function (Blueprint $table) {
|
||||||
|
$table->string('tag')->after('description');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('service_options', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('tag');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -212,14 +212,15 @@
|
||||||
<span class="input-group-addon" id="startupExec"></span>
|
<span class="input-group-addon" id="startupExec"></span>
|
||||||
<input type="text" class="form-control" name="startup" value="{{ old('startup') }}" />
|
<input type="text" class="form-control" name="startup" value="{{ old('startup') }}" />
|
||||||
</div>
|
</div>
|
||||||
|
<p class="text-muted"><small>The following data replacers are avaliable for the startup command: <code>@{{SERVER_MEMORY}}</code>, <code>@{{SERVER_IP}}</code>, and <code>@{{SERVER_PORT}}</code>. They will be replaced with the allocated memory, server ip, and server port respectively.</small></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="alert alert-info">Some service options have additional environment variables that you can define for a given instance. They will show up below when you select a service option. If none show up, chances are that none were defined, and there is nothing to worry about.</div>
|
<div class="alert alert-info">Some service options have additional environment variables that you can define for a given instance. They will show up below when you select a service option. If none show up, chances are that none were defined, and there is nothing to worry about.</div>
|
||||||
<span id="serverVariables"></span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row" id="serverVariables"></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -402,7 +403,7 @@ $(document).ready(function () {
|
||||||
<input type="text" autocomplete="off" name="env_' + item.env_variable + '" class="form-control" value="' + item.default_value + '" />\
|
<input type="text" autocomplete="off" name="env_' + item.env_variable + '" class="form-control" value="' + item.default_value + '" />\
|
||||||
<p class="text-muted"><small>' + item.description + '</small></p>\
|
<p class="text-muted"><small>' + item.description + '</small></p>\
|
||||||
<p class="text-muted"><small>Regex Requirements for Input: <code>' + item.regex + '</code></small></p>\
|
<p class="text-muted"><small>Regex Requirements for Input: <code>' + item.regex + '</code></small></p>\
|
||||||
<p class="text-muted"><small>Access in Startup: <code>${' + item.env_variable + '}</code></small></p>\
|
<p class="text-muted"><small>Access in Startup: <code>@{{' + item.env_variable + '}}</code></small></p>\
|
||||||
</div>\
|
</div>\
|
||||||
</div>\
|
</div>\
|
||||||
';
|
';
|
||||||
|
|
Loading…
Reference in a new issue