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
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/api/v2/containers_controller.rb', line 71 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. }, :status => :unprocessable_entity else set_container_taxonomies process_response @container.save end rescue ActiveModel::MassAssignmentSecurity::Error => e render :json => { :error => _("Wrong attributes: %s") % e. }, :status => :unprocessable_entity end |
#destroy ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/api/v2/containers_controller.rb', line 94 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 27 |
# File 'app/controllers/api/v2/containers_controller.rb', line 19 def index if params[:compute_resource_id].present? scoped = Container.where(:compute_resource_id => params[:compute_resource_id]) else scoped = Container.where(nil) end @containers = scoped.search_for(params[:search], :order => params[:order]) .paginate(:page => params[:page]) end |
#logs ⇒ Object
115 116 117 118 119 120 |
# File 'app/controllers/api/v2/containers_controller.rb', line 115 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
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'app/controllers/api/v2/containers_controller.rb', line 131 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
35 36 |
# File 'app/controllers/api/v2/containers_controller.rb', line 35 def show end |