Class: Api::V2::ContainersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/api/v2/containers_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/api/v2/containers_controller.rb', line 68

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.full_messages.join(', ')
                    },
           :status => :unprocessable_entity
  else
    set_container_taxonomies
    process_response @container.save
  end
end

#destroyObject



88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/api/v2/containers_controller.rb', line 88

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

#indexObject



19
20
21
22
23
24
# File 'app/controllers/api/v2/containers_controller.rb', line 19

def index
  scope = resource_scope
  scope = scope.where(:compute_resource => params[:compute_resource_id]) if params[:compute_resource_id].present?
  @containers = scope.search_for(params[:search], :order => params[:order])
                .paginate(:page => params[:page])
end

#logsObject



109
110
111
112
113
114
# File 'app/controllers/api/v2/containers_controller.rb', line 109

def logs
  render :json => { :logs => Docker::Container.get(@container.uuid)
    .logs(:stdout => (params[:stdout] || true),
          :stderr => (params[:stderr] || false),
          :tail   => (params[:tail] || 100)) }
end

#powerObject



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'app/controllers/api/v2/containers_controller.rb', line 125

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

#showObject



32
33
# File 'app/controllers/api/v2/containers_controller.rb', line 32

def show
end