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



64
65
66
67
68
69
70
71
# File 'app/controllers/api/v2/containers_controller.rb', line 64

def create
  @container = Service::Containers.new.start_container!(set_wizard_state)
  set_container_taxonomies
  process_response @container.save
rescue ActiveModel::MassAssignmentSecurity::Error => e
  render :json => { :error  => _("Wrong attributes: %s") % e.message },
         :status => :unprocessable_entity
end

#destroyObject



79
80
81
# File 'app/controllers/api/v2/containers_controller.rb', line 79

def destroy
  process_response @container.destroy
end

#indexObject



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

def index
  if params[:compute_resource_id].present?
    @containers = Container.where(:compute_resource_id => params[:compute_resource_id])
  else
    @containers = Container.all
  end
end

#logsObject



92
93
94
95
96
97
# File 'app/controllers/api/v2/containers_controller.rb', line 92

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



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'app/controllers/api/v2/containers_controller.rb', line 108

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



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

def show
end