class Fog::Compute::CloudAtCost::Real

Public Class Methods

new(options={}) click to toggle source
# File lib/fog/cloudatcost/compute.rb, line 42
def initialize(options={})
  @api_key = options[:api_key]
  @email   = options[:email]
  persistent         = false
  @connection        = Fog::Core::Connection.new 'https://panel.cloudatcost.com', persistent, options
end

Public Instance Methods

console(id) click to toggle source
# File lib/fog/cloudatcost/requests/console.rb, line 5
def console(id)
  body = { :sid => "#{id}" }
  request(
    :expects => [200],
    :method  => 'POST',
    :path    => 'api/v1/console.php',
    :body    => body,
  )
end
create_server(cpu, ram, storage, template_id) click to toggle source
# File lib/fog/cloudatcost/requests/create_server.rb, line 5
def create_server(cpu, ram, storage, template_id)
  body = { cpu: "#{cpu}", ram: "#{ram}", storage: "#{storage}", os: "#{template_id}" }
  request(
    :expects => [200],
    :method  => 'POST',
    :path    => 'api/v1/cloudpro/build.php',
    :body    => body,
  )
end
delete_server(id) click to toggle source
# File lib/fog/cloudatcost/requests/delete_server.rb, line 5
def delete_server(id)
  body = { sid: "#{id}" }
  request(
    :expects => [200],
    :method  => 'POST',
    :path    => 'api/v1/cloudpro/delete.php',
    :body    => body,
  )
end
list_servers() click to toggle source
# File lib/fog/cloudatcost/requests/list_servers.rb, line 5
def list_servers
  request(
    :expects => [200],
    :method => 'GET',
    :path => '/api/v1/listservers.php'
  )
end
list_tasks() click to toggle source
# File lib/fog/cloudatcost/requests/list_tasks.rb, line 5
def list_tasks
  request(
    :expects => [200],
    :method => 'GET',
    :path => '/api/v1/listtasks.php'
  )
end
list_templates() click to toggle source
# File lib/fog/cloudatcost/requests/list_templates.rb, line 5
def list_templates
  request(
    :expects => [200],
    :method => 'GET',
    :path => '/api/v1/listtemplates.php'
  )
end
power_off(id) click to toggle source
# File lib/fog/cloudatcost/requests/power_off.rb, line 5
def power_off(id)
  body = { :sid => "#{id}", :action => 'poweroff' }
  request(
    :expects => [200],
    :method  => 'POST',
    :path    => 'api/v1/powerop.php',
    :body    => body,
  )
end
power_on(id) click to toggle source
# File lib/fog/cloudatcost/requests/power_on.rb, line 5
def power_on(id)
  body = { :sid => "#{id}", :action => 'poweron' }
  request(
    :expects => [200],
    :method  => 'POST',
    :path    => 'api/v1/powerop.php',
    :body    => body,
  )
end
rename_server(id, name) click to toggle source
# File lib/fog/cloudatcost/requests/rename_server.rb, line 5
def rename_server(id, name)
  body = { :sid => "#{id}", :name => "#{name}" }
  request(
    :expects => [200],
    :method  => 'POST',
    :path    => 'api/v1/renameserver.php',
    :body    => body,
  )
end
request(params) click to toggle source
# File lib/fog/cloudatcost/compute.rb, line 49
def request(params)
  params[:headers] ||= { 'Content-Type' => 'application/x-www-form-urlencoded' }
  params[:query] ||= {}
  required_params = {
    key: "#{@api_key}",
    login: "#{@email}"
  }
  begin
    if params[:method] == 'POST' 
      params_body = required_params.merge(params[:body])
      params[:body] = params_body.reduce(""){ |acc,(x,y)| "#{acc}&#{x}=#{y}" }
    else
      params[:query] = required_params.merge(params[:query])
    end
    response = @connection.request(params)
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
          when Excon::Errors::NotFound
            Fog::Compute::Bluebox::NotFound.slurp(error)
          else
            error
          end
  end
  unless response.body.empty?
    response.body = Fog::JSON.decode(response.body)
  end
  response
end
reset(id) click to toggle source
# File lib/fog/cloudatcost/requests/reset.rb, line 5
def reset(id)
  body = { :sid => "#{id}", :action => 'reset' }
  request(
    :expects => [200],
    :method  => 'POST',
    :path    => "api/v1/powerop.php",
    :body    => body,
  )
end
reverse_dns(id, host_name) click to toggle source
# File lib/fog/cloudatcost/requests/reverse_dns.rb, line 5
def reverse_dns(id, host_name)
  body = { :sid => "#{id}", :hostname => "#{host_name}" }
  request(
    :expects => [200],
    :method  => 'POST',
    :path    => 'api/v1/rdns.php',
    :body    => body,
  )
end
run_mode(id, action) click to toggle source
# File lib/fog/cloudatcost/requests/run_mode.rb, line 5
def run_mode(id, action)
  body = { :sid => "#{id}", :mode => "#{action}" }
  request(
    :expects => [200],
    :method  => 'POST',
    :path    => 'api/v1/runmode.php',
    :body    => body,
  )
end