Class: Api::V2::ContainersController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::V2::ContainersController
- Defined in:
- app/controllers/api/v2/containers_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/controllers/api/v2/containers_controller.rb', line 70 def create service = Service::Containers.new @container = service.start_container!(set_wizard_state) if service.errors.any? render :json => { :errors => service.errors, :full_messages => service..join(', ') }, :status => :unprocessable_entity else set_container_taxonomies process_response @container.save end end |
#destroy ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/api/v2/containers_controller.rb', line 90 def destroy deleted_identifier = ForemanDocker::ContainerRemover.remove_unmanaged( @container.compute_resource_id, @container.uuid) if deleted_identifier process_response @container.destroy else render :json => { :error => 'Could not delete container on Docker host' }, :status => :precondition_failed end end |
#index ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/controllers/api/v2/containers_controller.rb', line 19 def index compute_resource_id = params[:compute_resource_id].tap do |id| id.present? ? { :compute_resource_id => id } : nil end scoped = Container.where(compute_resource_id) @containers = scoped.search_for(params[:search], :order => params[:order]) .paginate(:page => params[:page]) end |
#logs ⇒ Object
111 112 113 114 115 116 |
# File 'app/controllers/api/v2/containers_controller.rb', line 111 def logs render :json => { :logs => Docker::Container.get(@container.uuid) .logs(:stdout => (params[:stdout] || true), :stderr => (params[:stderr] || false), :tail => (params[:tail] || 100)) } end |
#power ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/controllers/api/v2/containers_controller.rb', line 127 def power power_actions = %(start stop status) if power_actions.include? params[:power_action] response = if params[:power_action] == 'status' { :running => @container.in_fog.ready? } else { :running => @container.in_fog.send(params[:power_action]) } end render :json => response else render :json => { :error => _("Unknown method: available power operations are %s") % power_actions.join(', ') }, :status => :unprocessable_entity end end |
#show ⇒ Object
34 35 |
# File 'app/controllers/api/v2/containers_controller.rb', line 34 def show end |