Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fetch process table via api

  • Loading branch information...
commit c4cfd5884f2e0220268ce7a3dbc4301b7a9e2f29 1 parent 756adb7
@sosedoff authored
Showing with 40 additions and 17 deletions.
  1. +22 −17 README.md
  2. +5 −0 lib/lxc/server.rb
  3. +13 −0 spec/server_spec.rb
View
39 README.md
@@ -118,26 +118,31 @@ Usage: lxc-server [options]
-p, --port PORT Start server on port (default: 27000)
```
-API Endpoints:
+### Endpoints
-```
-GET / # Get current time
-GET /version # Current gem version
-GET /lxc_version # Installed LXC version
-GET /containers # Get container list
-GET /containers/:name # Get a single container information
-```
+General:
-Container operations:
+ GET / # Get current time
+ GET /version # Current gem version
+ GET /lxc_version # Installed LXC version
+ GET /containers # Get container list
+ GET /containers/:name # Get a single container information
-```
-POST /container/:name/create
-POST /container/:name/destroy
-POST /container/:name/start
-POST /container/:name/stop
-POST /container/:name/freeze
-POST /container/:name/unfreeze
-```
+Processes:
+
+ GET /containers/:name/processes # Get a list of all running processes
+
+Management:
+
+ POST /container/:name/create
+ POST /container/:name/destroy
+
+Status change operations:
+
+ POST /container/:name/start
+ POST /container/:name/stop
+ POST /container/:name/freeze
+ POST /container/:name/unfreeze
## Testing
View
5 lib/lxc/server.rb
@@ -59,6 +59,11 @@ def find_container
json_response(@container.to_hash)
end
+ get '/containers/:c_name/processes' do
+ find_container
+ json_response(@container.processes)
+ end
+
post '/containers/:c_name/:action' do
find_container
case params[:action]
View
13 spec/server_spec.rb
@@ -54,6 +54,19 @@
data['pid'].should eq('2125')
end
+ it 'GET /container/:name/processes returns current running processes' do
+ stub_lxc('ls') { "app" }
+ stub_lxc('info', '-n', 'app') { fixture('lxc-info-running.txt') }
+ stub_lxc('ps', '-n', 'app', '--', '-eo pid,user,%cpu,%mem,args') { fixture('lxc-ps-aux.txt') }
+
+ get '/containers/app/processes'
+ last_response.should be_ok
+
+ data = parse_json(last_response.body)
+ data.should be_an Array
+ data.first.should be_a Hash
+ end
+
context 'Errors' do
class LXC::Server
get '/exception' do
Please sign in to comment.
Something went wrong with that request. Please try again.