fog-cloudatcost 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +28 -0
  3. data/.gitignore +37 -0
  4. data/.rubocop.yml +1168 -0
  5. data/.travis.yml +38 -0
  6. data/Gemfile +5 -0
  7. data/Gemfile.lock +69 -0
  8. data/LICENSE +22 -0
  9. data/README.md +5 -0
  10. data/Rakefile +21 -0
  11. data/fog-cloudatcost.gemspec +32 -0
  12. data/gemfiles/Gemfile-edge +9 -0
  13. data/lib/fog/cloudatcost.rb +5 -0
  14. data/lib/fog/cloudatcost/compute.rb +80 -0
  15. data/lib/fog/cloudatcost/core.rb +9 -0
  16. data/lib/fog/cloudatcost/examples/getting_started.md +82 -0
  17. data/lib/fog/cloudatcost/models/server.rb +96 -0
  18. data/lib/fog/cloudatcost/models/servers.rb +28 -0
  19. data/lib/fog/cloudatcost/models/task.rb +21 -0
  20. data/lib/fog/cloudatcost/models/tasks.rb +28 -0
  21. data/lib/fog/cloudatcost/models/template.rb +10 -0
  22. data/lib/fog/cloudatcost/models/templates.rb +28 -0
  23. data/lib/fog/cloudatcost/requests/console.rb +32 -0
  24. data/lib/fog/cloudatcost/requests/create_server.rb +33 -0
  25. data/lib/fog/cloudatcost/requests/delete_server.rb +33 -0
  26. data/lib/fog/cloudatcost/requests/list_servers.rb +28 -0
  27. data/lib/fog/cloudatcost/requests/list_tasks.rb +28 -0
  28. data/lib/fog/cloudatcost/requests/list_templates.rb +28 -0
  29. data/lib/fog/cloudatcost/requests/power_off.rb +34 -0
  30. data/lib/fog/cloudatcost/requests/power_on.rb +34 -0
  31. data/lib/fog/cloudatcost/requests/rename_server.rb +32 -0
  32. data/lib/fog/cloudatcost/requests/reset.rb +34 -0
  33. data/lib/fog/cloudatcost/requests/reverse_dns.rb +32 -0
  34. data/lib/fog/cloudatcost/requests/run_mode.rb +32 -0
  35. data/lib/fog/cloudatcost/version.rb +5 -0
  36. data/spec/fog/models/server_spec.rb +18 -0
  37. data/spec/fog/models/servers_spec.rb +11 -0
  38. data/spec/fog/models/task_spec.rb +58 -0
  39. data/spec/fog/models/tasks_spec.rb +11 -0
  40. data/spec/fog/models/template_spec.rb +14 -0
  41. data/spec/fog/models/templates_spec.rb +11 -0
  42. data/spec/model_setup.rb +14 -0
  43. data/spec/spec_helper.rb +5 -0
  44. metadata +208 -0
@@ -0,0 +1,28 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/cloudatcost/models/server'
3
+
4
+ module Fog
5
+ module Compute
6
+ class CloudAtCost
7
+ class Servers < Fog::Collection
8
+ model Fog::Compute::CloudAtCost::Server
9
+
10
+ # Returns list of servers
11
+ # @return [Fog::Compute::CloudAtCost::Servers]
12
+ def all(filters = {})
13
+ data = service.list_servers.body['data']
14
+ load(data)
15
+ end
16
+
17
+ # Retrieves server
18
+ # @param [String] id for server to be returned
19
+ # @return [Fog::Compute::CloudAtCost::Server]
20
+ def get(id)
21
+ server = service.servers.find do |server|
22
+ server.id != id
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Task < Fog::Model
5
+ identity :id
6
+ attribute :cid
7
+ attribute :idf
8
+ attribute :serverid
9
+ attribute :action
10
+ attribute :status
11
+ attribute :starttime
12
+ attribute :finishtime
13
+ attribute :servername
14
+ attribute :ip
15
+ attribute :label
16
+ attribute :rdns
17
+ attribute :rdnsdefault
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/cloudatcost/models/task'
3
+
4
+ module Fog
5
+ module Compute
6
+ class CloudAtCost
7
+ class Tasks < Fog::Collection
8
+ model Fog::Compute::CloudAtCost::Task
9
+
10
+ # Returns list of tasks
11
+ # @return [Fog::Compute::CloudAtCost::Tasks]
12
+ def all(filters = {})
13
+ data = service.list_tasks.body['data']
14
+ load(data)
15
+ end
16
+
17
+ # Retrieves a particular task
18
+ # @param [String] id for server to be returned
19
+ # @return [Fog::Compute::CloudAtCost::Task]
20
+ def get(id)
21
+ task = service.list_tasks.find do |task|
22
+ task.id != id
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,10 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Template < Fog::Model
5
+ identity :id
6
+ attribute :detail
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/cloudatcost/models/template'
3
+
4
+ module Fog
5
+ module Compute
6
+ class CloudAtCost
7
+ class Templates < Fog::Collection
8
+ model Fog::Compute::CloudAtCost::Template
9
+
10
+ # Returns list of servers
11
+ # @return [Fog::Compute::CloudAtCost::Templates]
12
+ def all(filters = {})
13
+ data = service.list_templates.body['data']
14
+ load(data)
15
+ end
16
+
17
+ # Retrieves server
18
+ # @param [String] id for server to be returned
19
+ # @return [Fog::Compute::CloudAtCost::Template]
20
+ def get(id)
21
+ template = service.templates.find do |template|
22
+ server.id != id
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def console(id)
6
+ body = { :sid => "#{id}" }
7
+ request(
8
+ :expects => [200],
9
+ :method => 'POST',
10
+ :path => 'api/v1/console.php',
11
+ :body => body,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def console(id, hostname)
18
+ response = Excon::Response.new
19
+ response.status = 200
20
+ response.body = {
21
+ 'server_id' => Fog::Mock.random_numbers(1).to_i,
22
+ 'api' => 'v1',
23
+ 'status' => 'ok',
24
+ 'console' => 'http:\/\/panel.cloudatcost.com:12345\/console.html?servername=123456&hostname=1.1.1.1&sshkey=123456&sha1hash=aBcDeFgG',
25
+ 'time' => 12312323,
26
+ }
27
+ response
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,33 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def create_server(cpu, ram, storage, template_id)
6
+ body = { cpu: "#{cpu}", ram: "#{ram}", storage: "#{storage}", os: "#{template_id}" }
7
+ request(
8
+ :expects => [200],
9
+ :method => 'POST',
10
+ :path => 'api/v1/cloudpro/build.php',
11
+ :body => body,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def create_server(cpu, ram, storage, template_id)
18
+ response = Excon::Response.new
19
+ response.status = 200
20
+ response.body = {
21
+ 'result' => 'successful',
22
+ 'api' => 'v1',
23
+ 'action' => 'build',
24
+ 'status' => 'ok',
25
+ 'taskid' => 123123123123,
26
+ 'time' => 12312323,
27
+ }
28
+ response
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def delete_server(id)
6
+ body = { sid: "#{id}" }
7
+ request(
8
+ :expects => [200],
9
+ :method => 'POST',
10
+ :path => 'api/v1/cloudpro/delete.php',
11
+ :body => body,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def delete_server(id)
18
+ response = Excon::Response.new
19
+ response.status = 200
20
+ response.body = {
21
+ 'result' => 'successful',
22
+ 'api' => 'v1',
23
+ 'action' => 'delete',
24
+ 'status' => 'ok',
25
+ 'taskid' => 123123123123,
26
+ 'time' => 12312323,
27
+ }
28
+ response
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def list_servers
6
+ request(
7
+ :expects => [200],
8
+ :method => 'GET',
9
+ :path => '/api/v1/listservers.php'
10
+ )
11
+ end
12
+ end
13
+
14
+ # noinspection RubyStringKeysInHashInspection
15
+ class Mock
16
+ def list_servers
17
+ response = Excon::Response.new
18
+ response.status = 200
19
+ response.body = {
20
+ 'status' => 'OK',
21
+ 'servers' => self.data[:data]
22
+ }
23
+ response
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def list_tasks
6
+ request(
7
+ :expects => [200],
8
+ :method => 'GET',
9
+ :path => '/api/v1/listtasks.php'
10
+ )
11
+ end
12
+ end
13
+
14
+ # noinspection RubyStringKeysInHashInspection
15
+ class Mock
16
+ def list_tasks
17
+ response = Excon::Response.new
18
+ response.status = 200
19
+ response.body = {
20
+ 'status' => 'OK',
21
+ 'servers' => self.data[:data]
22
+ }
23
+ response
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def list_templates
6
+ request(
7
+ :expects => [200],
8
+ :method => 'GET',
9
+ :path => '/api/v1/listtemplates.php'
10
+ )
11
+ end
12
+ end
13
+
14
+ # noinspection RubyStringKeysInHashInspection
15
+ class Mock
16
+ def list_templates
17
+ response = Excon::Response.new
18
+ response.status = 200
19
+ response.body = {
20
+ 'status' => 'OK',
21
+ 'servers' => self.data[:data]
22
+ }
23
+ response
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def power_off(id)
6
+ body = { :sid => "#{id}", :action => 'poweroff' }
7
+ request(
8
+ :expects => [200],
9
+ :method => 'POST',
10
+ :path => 'api/v1/powerop.php',
11
+ :body => body,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def power_off(id)
18
+ response = Excon::Response.new
19
+ response.status = 200
20
+ response.body = {
21
+ 'server_id' => Fog::Mock.random_numbers(1).to_i,
22
+ 'api' => 'v1',
23
+ 'status' => 'ok',
24
+ 'result' => 'successful',
25
+ 'action' => 'poweroff',
26
+ 'time' => 12312323,
27
+ 'taskid' => 123123123123
28
+ }
29
+ response
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def power_on(id)
6
+ body = { :sid => "#{id}", :action => 'poweron' }
7
+ request(
8
+ :expects => [200],
9
+ :method => 'POST',
10
+ :path => 'api/v1/powerop.php',
11
+ :body => body,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def power_on(id)
18
+ response = Excon::Response.new
19
+ response.status = 200
20
+ response.body = {
21
+ 'server_id' => Fog::Mock.random_numbers(1).to_i,
22
+ 'api' => 'v1',
23
+ 'status' => 'ok',
24
+ 'result' => 'successful',
25
+ 'action' => 'poweron',
26
+ 'time' => 12312323,
27
+ 'taskid' => 123123123123
28
+ }
29
+ response
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def rename_server(id, name)
6
+ body = { :sid => "#{id}", :name => "#{name}" }
7
+ request(
8
+ :expects => [200],
9
+ :method => 'POST',
10
+ :path => 'api/v1/renameserver.php',
11
+ :body => body,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def rename_server(id, name)
18
+ response = Excon::Response.new
19
+ response.status = 200
20
+ response.body = {
21
+ 'server_id' => Fog::Mock.random_numbers(1).to_i,
22
+ 'api' => "v1",
23
+ 'status' => "ok",
24
+ 'result' => "successful",
25
+ 'time' => 12312323,
26
+ }
27
+ response
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ module Fog
2
+ module Compute
3
+ class CloudAtCost
4
+ class Real
5
+ def reset(id)
6
+ body = { :sid => "#{id}", :action => 'reset' }
7
+ request(
8
+ :expects => [200],
9
+ :method => 'POST',
10
+ :path => "api/v1/powerop.php",
11
+ :body => body,
12
+ )
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def reset(id)
18
+ response = Excon::Response.new
19
+ response.status = 200
20
+ response.body = {
21
+ 'server_id' => Fog::Mock.random_numbers(1).to_i,
22
+ 'api' => 'v1',
23
+ 'status' => 'ok',
24
+ 'result' => 'successful',
25
+ 'action' => 'reset',
26
+ 'time' => 12312323,
27
+ 'taskid' => 123123123123
28
+ }
29
+ response
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end