better port checking, don't send rebuild unless things are changed.

This commit is contained in:
Dane Everitt 2016-10-23 19:07:29 -04:00
parent 0b044b3cc6
commit 08b236ac1d
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -532,7 +532,6 @@ class ServerRepository
$newPorts = false; $newPorts = false;
// Remove Assignments // Remove Assignments
if (isset($data['remove_additional'])) { if (isset($data['remove_additional'])) {
$newPorts = true;
foreach ($data['remove_additional'] as $id => $combo) { foreach ($data['remove_additional'] as $id => $combo) {
list($ip, $port) = explode(':', $combo); list($ip, $port) = explode(':', $combo);
// Invalid, not worth killing the whole thing, we'll just skip over it. // Invalid, not worth killing the whole thing, we'll just skip over it.
@ -541,10 +540,11 @@ class ServerRepository
} }
// Can't remove the assigned IP/Port combo // Can't remove the assigned IP/Port combo
if ($ip === $allocation->ip && $port === $allocation->port) { if ($ip === $allocation->ip && (int) $port === (int) $allocation->port) {
break; break;
} }
$newPorts = true;
Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->update([ Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->update([
'assigned_to' => null 'assigned_to' => null
]); ]);
@ -553,7 +553,6 @@ class ServerRepository
// Add Assignments // Add Assignments
if (isset($data['add_additional'])) { if (isset($data['add_additional'])) {
$newPorts = true;
foreach ($data['add_additional'] as $id => $combo) { foreach ($data['add_additional'] as $id => $combo) {
list($ip, $port) = explode(':', $combo); list($ip, $port) = explode(':', $combo);
// Invalid, not worth killing the whole thing, we'll just skip over it. // Invalid, not worth killing the whole thing, we'll just skip over it.
@ -566,6 +565,7 @@ class ServerRepository
break; break;
} }
$newPorts = true;
Models\Allocation::where('ip', $ip)->where('port', $port)->whereNull('assigned_to')->update([ Models\Allocation::where('ip', $ip)->where('port', $port)->whereNull('assigned_to')->update([
'assigned_to' => $server->id 'assigned_to' => $server->id
]); ]);
@ -589,50 +589,51 @@ class ServerRepository
// @TODO: verify that server can be set to this much memory without // @TODO: verify that server can be set to this much memory without
// going over node limits. // going over node limits.
if (isset($data['memory'])) { if (isset($data['memory']) && $server->memory !== (int) $data['memory']) {
$server->memory = $data['memory']; $server->memory = $data['memory'];
$newBuild['memory'] = (int) $server->memory;
} }
if (isset($data['swap'])) { if (isset($data['swap']) && $server->swap !== (int) $data['swap']) {
$server->swap = $data['swap']; $server->swap = $data['swap'];
$newBuild['swap'] = (int) $server->swap;
} }
// @TODO: verify that server can be set to this much disk without // @TODO: verify that server can be set to this much disk without
// going over node limits. // going over node limits.
if (isset($data['disk'])) { if (isset($data['disk']) && $server->disk !== (int) $data['disk']) {
$server->disk = $data['disk']; $server->disk = $data['disk'];
$newBuild['disk'] = (int) $server->disk;
} }
if (isset($data['cpu'])) { if (isset($data['cpu']) && $server->cpu !== (int) $data['cpu']) {
$server->cpu = $data['cpu']; $server->cpu = $data['cpu'];
$newBuild['cpu'] = (int) $server->cpu;
} }
if (isset($data['io'])) { if (isset($data['io']) && $server->io !== (int) $data['io']) {
$server->io = $data['io']; $server->io = $data['io'];
$newBuild['io'] = (int) $server->io;
} }
// Try save() here so if it fails we haven't contacted the daemon // Try save() here so if it fails we haven't contacted the daemon
// This won't be committed unless the HTTP request succeedes anyways // This won't be committed unless the HTTP request succeedes anyways
$server->save(); $server->save();
$newBuild['memory'] = (int) $server->memory; if (!empty($newBuild)) {
$newBuild['swap'] = (int) $server->swap; $node = Models\Node::getByID($server->node);
$newBuild['io'] = (int) $server->io; $client = Models\Node::guzzleRequest($server->node);
$newBuild['cpu'] = (int) $server->cpu;
$newBuild['disk'] = (int) $server->disk;
$node = Models\Node::getByID($server->node); $client->request('PATCH', '/server', [
$client = Models\Node::guzzleRequest($server->node); 'headers' => [
'X-Access-Server' => $server->uuid,
$client->request('PATCH', '/server', [ 'X-Access-Token' => $node->daemonSecret
'headers' => [ ],
'X-Access-Server' => $server->uuid, 'json' => [
'X-Access-Token' => $node->daemonSecret 'build' => $newBuild
], ]
'json' => [ ]);
'build' => $newBuild }
]
]);
DB::commit(); DB::commit();
return true; return true;