[Midnightbsd-cvs] mports [22512] trunk/Tools/magus/www/data/magus/index.cgi: add new api calls

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Sep 20 21:47:43 EDT 2017


Revision: 22512
          http://svnweb.midnightbsd.org/mports/?rev=22512
Author:   laffer1
Date:     2017-09-20 21:47:42 -0400 (Wed, 20 Sep 2017)
Log Message:
-----------
add new api calls

Modified Paths:
--------------
    trunk/Tools/magus/www/data/magus/index.cgi

Modified: trunk/Tools/magus/www/data/magus/index.cgi
===================================================================
--- trunk/Tools/magus/www/data/magus/index.cgi	2017-09-21 01:03:30 UTC (rev 22511)
+++ trunk/Tools/magus/www/data/magus/index.cgi	2017-09-21 01:47:42 UTC (rev 22512)
@@ -61,6 +61,8 @@
     port_page($p, $1);
   } elsif ($path =~ m:^/api/runs:) {
     api_runs($p);
+  } elsif ($path =~ m:^/api/run-ports-list:) {
+    api_run_port_stats($p);
   } elsif ($path =~ m:^/async/run-ports-list:) {
     async_run_port_stats($p);
   } elsif ($path =~ m:^/async/machine-events:) {
@@ -86,11 +88,44 @@
   my ($p) = @_;
 
   my @runs = Magus::Run->retrieve_all({ order_by => 'id DESC' });
- 
-  print $p->header(-type => 'application/json'), encode_json(\%runs);
+  my @runOut;
+
+  foreach my $r (@runs) {
+     push(@runOut, {"blessed", $r->{blessed}, "status", $r->{status}, "created", $r->{created},  "osversion", $r->{osversion}, "arch", $r->{arch}, "id", $r->{id}});
+  }
+
+    print $p->header(-type => 'application/json'), encode_json(\@runOut);
 }
 
+sub api_run_port_stats { 
+  my ($p) = @_;
+  
+  my $run    = $p->param('run');
+  my $status = $p->param('status');
+    
+  my %details = (run => $run, status => $status);
+  my @ports;
+      
+  if ($status eq 'ready') {
+    @ports = Magus::Port->search_ready_ports($run);
+  } else {
+    @ports = Magus::Port->search(run => $run, status => $status, { order_by=> 'name'});
+  }
 
+  my @results;
+  foreach my $port (@ports) {
+     push(@results, { version => $port->{version}, summary => $port->{status}, port => $port->{name},
+      arch      => $port->run->arch, 
+      id        => $port->{id},
+    osversion => $port->run->osversion,
+    can_reset => $port->{can_reset} eq 'active' ? 1 : 0
+     });
+  }
+      
+  print $p->header(-type => 'application/json'), encode_json(\@results);
+}
+
+
 sub run_index {
   my ($p) = @_;
   my $tmpl = template($p, 'runlist.tmpl');



More information about the Midnightbsd-cvs mailing list