Class: Morpheus::ContainersInterface
- Inherits:
-
APIClient
- Object
- APIClient
- Morpheus::ContainersInterface
- Defined in:
- lib/morpheus/api/containers_interface.rb
Overview
Containers API interface. All of the PUT methods support passing an array of IDs.
Instance Method Summary collapse
- #action(container_id, action_code, payload = {}) ⇒ Object
- #available_actions(container_id) ⇒ Object
- #eject(container_id, payload = {}) ⇒ Object
- #get(container_id) ⇒ Object
-
#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ ContainersInterface
constructor
A new instance of ContainersInterface.
-
#list(params = {}) ⇒ Object
not used atm..
- #restart(container_id, payload = {}) ⇒ Object
- #start(container_id, payload = {}) ⇒ Object
- #stop(container_id, payload = {}) ⇒ Object
- #suspend(container_id, payload = {}) ⇒ Object
Constructor Details
#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ ContainersInterface
Returns a new instance of ContainersInterface.
6 7 8 9 10 11 |
# File 'lib/morpheus/api/containers_interface.rb', line 6 def initialize(access_token, refresh_token,expires_at = nil, base_url=nil) @access_token = access_token @refresh_token = refresh_token @base_url = base_url @expires_at = expires_at end |
Instance Method Details
#action(container_id, action_code, payload = {}) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/morpheus/api/containers_interface.rb', line 114 def action(container_id, action_code, payload={}) url, params = "", {} if container_id.is_a?(Array) url = "#{@base_url}/api/containers/action" params = {ids: container_id, code: action_code} else url = "#{@base_url}/api/containers/#{container_id}/action" params = {code: action_code} end headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } opts = {method: :put, url: url, headers: headers, payload: payload.to_json} execute(opts) end |
#available_actions(container_id) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/morpheus/api/containers_interface.rb', line 100 def available_actions(container_id) url, params = "", {} if container_id.is_a?(Array) url = "#{@base_url}/api/containers/actions" params = {ids: container_id} else url = "#{@base_url}/api/containers/#{container_id}/actions" params = {} end headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } opts = {method: :get, url: url, headers: headers} execute(opts) end |
#eject(container_id, payload = {}) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/morpheus/api/containers_interface.rb', line 86 def eject(container_id, payload={}) url, params = "", {} if container_id.is_a?(Array) url = "#{@base_url}/api/containers/eject" params = {ids: container_id} else url = "#{@base_url}/api/containers/#{container_id}/eject" params = {} end headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } opts = {method: :put, url: url, headers: headers, payload: payload.to_json} execute(opts) end |
#get(container_id) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/morpheus/api/containers_interface.rb', line 23 def get(container_id) url = "#{@base_url}/api/containers/#{container_id}" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } opts = {method: :get, url: url, headers: headers} execute(opts) end |
#list(params = {}) ⇒ Object
not used atm.. index api needs some work, we should implement it so it just paginates all containers. right now you can to pass params as => [1,2,3]
16 17 18 19 20 21 |
# File 'lib/morpheus/api/containers_interface.rb', line 16 def list(params={}) url = "#{@base_url}/api/containers" headers = { params: params, authorization: "Bearer #{@access_token}" } opts = {method: :get, url: url, headers: headers} execute(opts) end |
#restart(container_id, payload = {}) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/morpheus/api/containers_interface.rb', line 58 def restart(container_id, payload={}) url, params = "", {} if container_id.is_a?(Array) url = "#{@base_url}/api/containers/restart" params = {ids: container_id} else url = "#{@base_url}/api/containers/#{container_id}/restart" params = {} end headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } opts = {method: :put, url: url, headers: headers, payload: payload.to_json} execute(opts) end |
#start(container_id, payload = {}) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/morpheus/api/containers_interface.rb', line 44 def start(container_id, payload={}) url, params = "", {} if container_id.is_a?(Array) url = "#{@base_url}/api/containers/start" params = {ids: container_id} else url = "#{@base_url}/api/containers/#{container_id}/start" params = {} end headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } opts = {method: :put, url: url, headers: headers, payload: payload.to_json} execute(opts) end |
#stop(container_id, payload = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/morpheus/api/containers_interface.rb', line 30 def stop(container_id, payload={}) url, params = "", {} if container_id.is_a?(Array) url = "#{@base_url}/api/containers/stop" params = {ids: container_id} else url = "#{@base_url}/api/containers/#{container_id}/stop" params = {} end headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } opts = {method: :put, url: url, headers: headers, payload: payload.to_json} execute(opts) end |
#suspend(container_id, payload = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/morpheus/api/containers_interface.rb', line 72 def suspend(container_id, payload={}) url, params = "", {} if container_id.is_a?(Array) url = "#{@base_url}/api/containers/suspend" params = {ids: container_id} else url = "#{@base_url}/api/containers/#{container_id}/suspend" params = {} end headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } opts = {method: :put, url: url, headers: headers, payload: payload.to_json} execute(opts) end |