Sha256: 1ea2afb52e5d5dbecfbf6d49a45ba65796928773c6f2bc36c910481e423caea4

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

class Nodectl::Webapp::Instances < Nodectl::Webapp::Base
  get '/' do
    if params[:ids]
      select_id = params[:ids].map(&:to_i)
      instances = Nodectl::Instance.all.select { |i| select_id.include?(i.pid) }
    else
      instances = Nodectl::Instance.all
    end

    json instances: instances.map(&:as_json)
  end

  get '/:pid' do
    instance = Nodectl::Instance.find!(params[:pid].to_i)
    json instance: instance.as_json
  end

  post '/' do
    service = Nodectl::Service.find(params[:instance][:service_id])

    if service
      instance = service.recipe_binding.run_slot :start, params[:instance][:options]
      status 201
      json instance: instance.as_json
    else
      json errors: {service_name: "service not found"}
      status 422
    end
  end

  put '/:pid' do
    instance = Nodectl::Instance.find!(params[:pid].to_i)

    if params[:instance][:status] == "stopping"
      if params[:instance][:force_stop]
        instance.stop(force: true)
      else
        instance.stop
      end
    elsif params[:instance][:status] == "restarting"
      instance.restart(force: true)
    end

    json instance: instance.as_json
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nodectl-0.2.4 lib/nodectl/webapp/instances.rb