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



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.full_messages
                    },
           :status => :unprocessable_entity
  else
    set_container_taxonomies
    process_response @container.save
  end
rescue ActiveModel::MassAssignmentSecurity::Error => e
  render :json => { :error  => _("Wrong attributes: %s") % e.message },
         :status => :unprocessable_entity
end

#destroyObject



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

def destroy
  process_response @container.destroy
end

#indexObject



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

#logsObject



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

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



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

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



35
36
# File 'app/controllers/api/v2/containers_controller.rb', line 35

def show
end