From 232170e301d3a0f55c0224b41fa62fb965f7870d Mon Sep 17 00:00:00 2001 From: Shea Levy Date: Mon, 4 Mar 2013 16:05:50 -0500 Subject: [PATCH] Remove all entry points to modify machines --- src/lib/Hydra/Controller/Admin.pm | 147 ------------------------------ src/root/machine.tt | 88 ------------------ 2 files changed, 235 deletions(-) delete mode 100644 src/root/machine.tt diff --git a/src/lib/Hydra/Controller/Admin.pm b/src/lib/Hydra/Controller/Admin.pm index 3b935956..839e2d14 100644 --- a/src/lib/Hydra/Controller/Admin.pm +++ b/src/lib/Hydra/Controller/Admin.pm @@ -11,35 +11,6 @@ use Digest::SHA1 qw(sha1_hex); use Config::General; -sub nixMachines { - my ($c) = @_; - my $result = "# GENERATED BY HYDRA\n"; - - foreach my $machine ($c->model("DB::BuildMachines")->all) { - if($machine->enabled) { - $result = $result . $machine->username . '@'. $machine->hostname . ' '; - foreach my $system ($machine->buildmachinesystemtypes) { - $result = $result . $system->system .','; - } - chop $result; - $result = $result . ' '. $machine->ssh_key . ' ' . $machine->maxconcurrent . ' '. $machine->speedfactor . ' ' . $machine->options . "\n"; - } - } - return $result; -} - - -sub saveNixMachines { - my ($c) = @_; - - die("File not writable: /etc/nix.machines") if ! -w "/etc/nix.machines" ; - - open (NIXMACHINES, '>/etc/nix.machines') or die("Could not write to /etc/nix.machines"); - print NIXMACHINES nixMachines($c); - close (NIXMACHINES); -} - - sub admin : Chained('/') PathPart('admin') CaptureArgs(0) { my ($self, $c) = @_; requireAdmin($c); @@ -61,124 +32,6 @@ sub machines : Chained('admin') PathPart('machines') Args(0) { } -sub machine : Chained('admin') PathPart('machine') CaptureArgs(1) { - my ($self, $c, $machineName) = @_; - - requireAdmin($c); - - my $machine = $c->model('DB::BuildMachines')->find($machineName) - or notFound($c, "Machine $machineName doesn't exist."); - - $c->stash->{machine} = $machine; -} - - -sub machine_edit : Chained('machine') PathPart('edit') Args(0) { - my ($self, $c) = @_; - $c->stash->{template} = 'machine.tt'; - $c->stash->{systemtypes} = [$c->model('DB::SystemTypes')->search({}, {order_by => "system"})]; - $c->stash->{edit} = 1; -} - - -sub machine_edit_submit : Chained('machine') PathPart('submit') Args(0) { - my ($self, $c) = @_; - requirePost($c); - - txn_do($c->model('DB')->schema, sub { - if (($c->request->params->{submit} || "") eq "delete") { - $c->stash->{machine}->delete; - } else { - updateMachine($c, $c->stash->{machine}); - } - }); - - saveNixMachines($c); - - $c->res->redirect("/admin/machines"); -} - - -sub updateMachine { - my ($c, $machine) = @_; - - my $hostname = trim $c->request->params->{"hostname"}; - my $username = trim $c->request->params->{"username"}; - my $maxconcurrent = trim $c->request->params->{"maxconcurrent"}; - my $speedfactor = trim $c->request->params->{"speedfactor"}; - my $ssh_key = trim $c->request->params->{"ssh_key"}; - my $options = trim $c->request->params->{"options"}; - my $systems = $c->request->params->{"systems"} ; - - error($c, "Invalid or empty username.") if $username eq ""; - error($c, "Max concurrent builds should be an integer > 0.") if $maxconcurrent eq "" || ! $maxconcurrent =~ m/[0-9]+/; - error($c, "Speed factor should be an integer > 0.") if $speedfactor eq "" || ! $speedfactor =~ m/[0-9]+/; - error($c, "Invalid or empty SSH key.") if $ssh_key eq ""; - - $machine->update( - { username => $username - , maxconcurrent => $maxconcurrent - , speedfactor => $speedfactor - , ssh_key => $ssh_key - , options => $options - }); - $machine->buildmachinesystemtypes->delete_all; - if(ref($systems) eq 'ARRAY') { - for my $s (@$systems) { - $machine->buildmachinesystemtypes->create({ system => $s}) ; - } - } else { - $machine->buildmachinesystemtypes->create({ system => $systems}) ; - } -} - - -sub create_machine : Chained('admin') PathPart('create-machine') Args(0) { - my ($self, $c) = @_; - - requireAdmin($c); - - $c->stash->{template} = 'machine.tt'; - $c->stash->{systemtypes} = [$c->model('DB::SystemTypes')->search({}, {order_by => "system"})]; - $c->stash->{edit} = 1; - $c->stash->{create} = 1; -} - - -sub create_machine_submit : Chained('admin') PathPart('create-machine/submit') Args(0) { - my ($self, $c) = @_; - - requireAdmin($c); - - my $hostname = trim $c->request->params->{"hostname"}; - error($c, "Invalid or empty hostname.") if $hostname eq ""; - - txn_do($c->model('DB')->schema, sub { - my $machine = $c->model('DB::BuildMachines')->create( - { hostname => $hostname }); - updateMachine($c, $machine); - }); - saveNixMachines($c); - $c->res->redirect("/admin/machines"); -} - - -sub machine_enable : Chained('machine') PathPart('enable') Args(0) { - my ($self, $c) = @_; - $c->stash->{machine}->update({ enabled => 1}); - saveNixMachines($c); - $c->res->redirect("/admin/machines"); -} - - -sub machine_disable : Chained('machine') PathPart('disable') Args(0) { - my ($self, $c) = @_; - $c->stash->{machine}->update({ enabled => 0}); - saveNixMachines($c); - $c->res->redirect("/admin/machines"); -} - - sub clear_queue_non_current : Chained('admin') Path('clear-queue-non-current') Args(0) { my ($self, $c) = @_; $c->model('DB::Builds')->search({finished => 0, iscurrent => 0, busy => 0})->update({ finished => 1, buildstatus => 4, timestamp => time}); diff --git a/src/root/machine.tt b/src/root/machine.tt deleted file mode 100644 index 1fe68bcd..00000000 --- a/src/root/machine.tt +++ /dev/null @@ -1,88 +0,0 @@ -[% WRAPPER layout.tt title=(create ? "New machine" : "Machine $machine.hostname") %] -[% PROCESS common.tt %] - -
- -
- [% IF create %] -
- -
- -
-
- [% END %] - -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- - [% IF !create %] - - - [% END %] -
- -
- -[% END %]