Module: Hyperb::Containers
Overview
wrapper for containers api
Instance Method Summary collapse
-
#container_logs(params = {}) ⇒ HTTP::Response::Body
container logs.
-
#container_stats(params = {}) ⇒ HTTP::Response::Body
container stats.
-
#containers(params = {}) ⇒ Hyperb::Container
list existing containers.
-
#create_container(params = {}) ⇒ Hash
create a container.
-
#inspect_container(params = {}) ⇒ Hash
inspect a container.
-
#kill_container(params = {}) ⇒ Object
kill a container.
-
#remove_container(params = {}) ⇒ Hash
remove the container id.
-
#rename_container(params = {}) ⇒ Object
rename a container.
-
#start_container(params = {}) ⇒ Object
start a container.
-
#stop_container(params = {}) ⇒ Object
stop the container id.
Methods included from Utils
#check_arguments, #downcase_symbolize
Instance Method Details
#container_logs(params = {}) ⇒ HTTP::Response::Body
container logs
182 183 184 185 186 187 188 189 |
# File 'lib/hyperb/containers/containers.rb', line 182 def container_logs(params = {}) raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'id') path = '/containers/' + params[:id] + '/logs' query = {} params.delete(:id) query.merge!(params) Hyperb::Request.new(self, path, query, 'get').perform end |
#container_stats(params = {}) ⇒ HTTP::Response::Body
container stats
205 206 207 208 209 210 211 |
# File 'lib/hyperb/containers/containers.rb', line 205 def container_stats(params = {}) raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'id') path = '/containers/' + params[:id] + '/stats' query = {} query[:stream] = params[:stream] if params.key?(:stream) Hyperb::Request.new(self, path, query, 'get').perform end |
#containers(params = {}) ⇒ Hyperb::Container
list existing containers
TODO: @option params [Hash] :filters JSON encoded value of the filters.
30 31 32 33 34 35 36 |
# File 'lib/hyperb/containers/containers.rb', line 30 def containers(params = {}) path = '/containers/json' query = {} query.merge!(params) response = JSON.parse(Hyperb::Request.new(self, path, query, 'get').perform) response.map { |container| Hyperb::Container.new(container) } end |
#create_container(params = {}) ⇒ Hash
create a container
108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/hyperb/containers/containers.rb', line 108 def create_container(params = {}) raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'image') path = '/containers/create' query = {} # set a default size, otherwise container can't be started body = { labels: { sh_hyper_instancetype: 's1' } } query[:name] = params[:name] if params.key?(:name) params.delete(:name) body.merge!(params) response = JSON.parse(Hyperb::Request.new(self, path, query, 'post', body).perform) downcase_symbolize(response) end |
#inspect_container(params = {}) ⇒ Hash
inspect a container
137 138 139 140 141 142 143 144 |
# File 'lib/hyperb/containers/containers.rb', line 137 def inspect_container(params = {}) raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'id') path = '/containers/' + params[:id] + '/json' query = {} query[:size] = params[:size] if params.key?(:size) response = JSON.parse(Hyperb::Request.new(self, path, query, 'get').perform) downcase_symbolize(response) end |
#kill_container(params = {}) ⇒ Object
kill a container
224 225 226 227 228 229 230 |
# File 'lib/hyperb/containers/containers.rb', line 224 def kill_container(params = {}) raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'id') path = '/containers/' + params[:id] + '/kill' query = {} query[:signal] = params[:signal] if params.key?(:signal) Hyperb::Request.new(self, path, query, 'post').perform end |
#remove_container(params = {}) ⇒ Hash
remove the container id
73 74 75 76 77 78 79 80 81 |
# File 'lib/hyperb/containers/containers.rb', line 73 def remove_container(params = {}) raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'id') path = '/containers/' + params[:id] query = {} query[:v] = params[:v] if params.key?(:v) query[:force] = params[:force] if params.key?(:force) response = JSON.parse(Hyperb::Request.new(self, path, query, 'delete').perform) downcase_symbolize(response) end |
#rename_container(params = {}) ⇒ Object
rename a container
243 244 245 246 247 248 249 |
# File 'lib/hyperb/containers/containers.rb', line 243 def rename_container(params = {}) raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'name', 'id') path = '/containers/' + params[:id] + '/rename' query = {} query[:name] = params[:name] if params.key?(:name) Hyperb::Request.new(self, path, query, 'post').perform end |
#start_container(params = {}) ⇒ Object
start a container
157 158 159 160 161 |
# File 'lib/hyperb/containers/containers.rb', line 157 def start_container(params = {}) raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'id') path = '/containers/' + params[:id] + '/start' Hyperb::Request.new(self, path, {}, 'post').perform end |
#stop_container(params = {}) ⇒ Object
stop the container id
50 51 52 53 54 55 56 |
# File 'lib/hyperb/containers/containers.rb', line 50 def stop_container(params = {}) raise ArgumentError, 'Invalid arguments.' unless check_arguments(params, 'id') path = '/containers/' + params[:id] + '/stop' query = {} query[:t] = params[:t] if params.key?(:t) Hyperb::Request.new(self, path, query, 'post').perform end |