Class: Fog::Compute::CloudAtCost::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/cloudatcost/compute.rb,
lib/fog/cloudatcost/requests/reset.rb,
lib/fog/cloudatcost/requests/console.rb,
lib/fog/cloudatcost/requests/power_on.rb,
lib/fog/cloudatcost/requests/run_mode.rb,
lib/fog/cloudatcost/requests/power_off.rb,
lib/fog/cloudatcost/requests/list_tasks.rb,
lib/fog/cloudatcost/requests/reverse_dns.rb,
lib/fog/cloudatcost/requests/list_servers.rb,
lib/fog/cloudatcost/requests/create_server.rb,
lib/fog/cloudatcost/requests/delete_server.rb,
lib/fog/cloudatcost/requests/rename_server.rb,
lib/fog/cloudatcost/requests/list_templates.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



45
46
47
48
49
50
# File 'lib/fog/cloudatcost/compute.rb', line 45

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

Instance Method Details

#console(id) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/cloudatcost/requests/console.rb', line 7

def console(id)
  body = { sid: id.to_s }
  request(
    expects: [200],
    method: 'POST',
    path: 'api/v1/console.php',
    body: body
  )
end

#create_server(cpu, ram, storage, template_id) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/cloudatcost/requests/create_server.rb', line 7

def create_server(cpu, ram, storage, template_id)
  body = { cpu: cpu.to_s, ram: ram.to_s, storage: storage.to_s, os: template_id.to_s }
  request(
    expects: [200],
    method: 'POST',
    path: 'api/v1/cloudpro/build.php',
    body: body
  )
end

#delete_server(id) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/cloudatcost/requests/delete_server.rb', line 7

def delete_server(id)
  body = { sid: id.to_s }
  request(
    expects: [200],
    method: 'POST',
    path: 'api/v1/cloudpro/delete.php',
    body: body
  )
end

#list_serversObject



7
8
9
10
11
12
13
# File 'lib/fog/cloudatcost/requests/list_servers.rb', line 7

def list_servers
  request(
    expects: [200],
    method: 'GET',
    path: '/api/v1/listservers.php'
  )
end

#list_tasksObject



7
8
9
10
11
12
13
# File 'lib/fog/cloudatcost/requests/list_tasks.rb', line 7

def list_tasks
  request(
    expects: [200],
    method: 'GET',
    path: '/api/v1/listtasks.php'
  )
end

#list_templatesObject



7
8
9
10
11
12
13
# File 'lib/fog/cloudatcost/requests/list_templates.rb', line 7

def list_templates
  request(
    expects: [200],
    method: 'GET',
    path: '/api/v1/listtemplates.php'
  )
end

#power_off(id) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/cloudatcost/requests/power_off.rb', line 7

def power_off(id)
  body = { sid: id.to_s, action: 'poweroff' }
  request(
    expects: [200],
    method: 'POST',
    path: 'api/v1/powerop.php',
    body: body
  )
end

#power_on(id) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/cloudatcost/requests/power_on.rb', line 7

def power_on(id)
  body = { sid: id.to_s, action: 'poweron' }
  request(
    expects: [200],
    method: 'POST',
    path: 'api/v1/powerop.php',
    body: body
  )
end

#rename_server(id, name) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/cloudatcost/requests/rename_server.rb', line 7

def rename_server(id, name)
  body = { sid: id.to_s, name: name.to_s }
  request(
    expects: [200],
    method: 'POST',
    path: 'api/v1/renameserver.php',
    body: body
  )
end

#request(params) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fog/cloudatcost/compute.rb', line 52

def request(params)
  params[:headers] ||= { 'Content-Type' => 'application/x-www-form-urlencoded' }
  params[:query] ||= {}
  required_params = {
    key: @api_key.to_s,
    login: @email.to_s
  }
  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

  response.body = Fog::JSON.decode(response.body) unless response.body.empty?

  response
end

#reset(id) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/cloudatcost/requests/reset.rb', line 7

def reset(id)
  body = { sid: id.to_s, action: 'reset' }
  request(
    expects: [200],
    method: 'POST',
    path: 'api/v1/powerop.php',
    body: body
  )
end

#reverse_dns(id, host_name) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/cloudatcost/requests/reverse_dns.rb', line 7

def reverse_dns(id, host_name)
  body = { sid: id.to_s, hostname: host_name.to_s }
  request(
    expects: [200],
    method: 'POST',
    path: 'api/v1/rdns.php',
    body: body
  )
end

#run_mode(id, action) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/fog/cloudatcost/requests/run_mode.rb', line 7

def run_mode(id, action)
  body = { sid: id.to_s, mode: action.to_s }
  request(
    expects: [200],
    method: 'POST',
    path: 'api/v1/runmode.php',
    body: body
  )
end