fog-oneandone 1.0 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +3 -1
  3. data/Rakefile +24 -0
  4. data/examples/example_app.rb +39 -12
  5. data/fog-oneandone.gemspec +2 -1
  6. data/lib/oneandone/compute.rb +103 -16
  7. data/lib/oneandone/models/compute/baremetal_model.rb +15 -0
  8. data/lib/oneandone/models/compute/baremetal_models.rb +24 -0
  9. data/lib/oneandone/models/compute/block_storage.rb +100 -0
  10. data/lib/oneandone/models/compute/block_storages.rb +24 -0
  11. data/lib/oneandone/models/compute/firewall.rb +0 -15
  12. data/lib/oneandone/models/compute/image.rb +6 -1
  13. data/lib/oneandone/models/compute/public_ip.rb +2 -1
  14. data/lib/oneandone/models/compute/recovery_appliance.rb +18 -0
  15. data/lib/oneandone/models/compute/recovery_appliances.rb +24 -0
  16. data/lib/oneandone/models/compute/server.rb +44 -105
  17. data/lib/oneandone/models/compute/server_appliance.rb +25 -0
  18. data/lib/oneandone/models/compute/server_appliances.rb +24 -0
  19. data/lib/oneandone/models/compute/ssh_key.rb +67 -0
  20. data/lib/oneandone/models/compute/ssh_keys.rb +24 -0
  21. data/lib/oneandone/requests/compute/add_block_storage_server.rb +61 -0
  22. data/lib/oneandone/requests/compute/add_ports.rb +1 -1
  23. data/lib/oneandone/requests/compute/create_block_storage.rb +80 -0
  24. data/lib/oneandone/requests/compute/create_image.rb +9 -3
  25. data/lib/oneandone/requests/compute/create_server.rb +11 -5
  26. data/lib/oneandone/requests/compute/create_ssh_key.rb +74 -0
  27. data/lib/oneandone/requests/compute/delete_block_storage.rb +51 -0
  28. data/lib/oneandone/requests/compute/delete_ssh_key.rb +51 -0
  29. data/lib/oneandone/requests/compute/get_baremetal_model.rb +42 -0
  30. data/lib/oneandone/requests/compute/get_block_storage.rb +50 -0
  31. data/lib/oneandone/requests/compute/get_block_storage_server.rb +50 -0
  32. data/lib/oneandone/requests/compute/get_recovery_appliance.rb +41 -0
  33. data/lib/oneandone/requests/compute/get_ssh_key.rb +50 -0
  34. data/lib/oneandone/requests/compute/list_baremetal_models.rb +49 -0
  35. data/lib/oneandone/requests/compute/list_block_storages.rb +56 -0
  36. data/lib/oneandone/requests/compute/list_recovery_appliances.rb +47 -0
  37. data/lib/oneandone/requests/compute/list_ssh_keys.rb +56 -0
  38. data/lib/oneandone/requests/compute/remove_block_storage_server.rb +50 -0
  39. data/lib/oneandone/requests/compute/update_block_storage.rb +80 -0
  40. data/lib/oneandone/requests/compute/update_ssh_key.rb +78 -0
  41. data/tests/oneandone/test_block_storages.rb +82 -0
  42. data/tests/oneandone/test_firewalls.rb +5 -16
  43. data/tests/oneandone/test_recovery_appliances.rb +34 -0
  44. data/tests/oneandone/test_server_appliances.rb +34 -0
  45. data/tests/oneandone/test_ssh_keys.rb +82 -0
  46. metadata +58 -13
  47. data/lib/oneandone/requests/compute/remove_firewall_ip.rb +0 -60
@@ -0,0 +1,56 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+
5
+ class Real
6
+
7
+ ##
8
+ # Returns a list of all ssh keys on your account
9
+ # URL: [https://cloudpanel-api.1and1.com/documentation/v1/en/api/documentation.html#ssh_keys_get]
10
+ ##
11
+ def list_ssh_keys(page: nil, per_page: nil, sort: nil, q: nil,
12
+ fields: nil)
13
+
14
+ # Build hash for query parameters
15
+ keyword_args = {
16
+ :page => page,
17
+ :per_page => per_page,
18
+ :sort => sort,
19
+ :q => q,
20
+ :fields => fields
21
+ }
22
+
23
+ # Clean out null query parameters
24
+ query = clean_hash(keyword_args)
25
+
26
+ # Request
27
+ params = {
28
+ 'method' => :get,
29
+ 'endpoint' => '/ssh_keys',
30
+ 'params' => query
31
+ }
32
+
33
+ request(params)
34
+
35
+ end
36
+
37
+ end # Real
38
+
39
+
40
+ class Mock
41
+
42
+ def list_ssh_keys(page: nil, per_page: nil, sort: nil, q: nil,
43
+ fields: nil)
44
+
45
+ response = Excon::Response.new
46
+ response.status = 200
47
+ response.body = self.data[:ssh_keys]
48
+ response
49
+
50
+ end
51
+
52
+ end # Mock
53
+
54
+ end # OneAndOne
55
+ end # Compute
56
+ end # Fog
@@ -0,0 +1,50 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+
5
+ class Real
6
+
7
+ ##
8
+ # Removes a server from a block storage
9
+ # URL: [https://cloudpanel-api.1and1.com/documentation/v1/en/api/documentation.html#]
10
+ ##
11
+ def remove_block_storage_server(block_storage_id: nil)
12
+
13
+ params = {
14
+ 'method' => :delete,
15
+ 'endpoint' => "/block_storages/#{block_storage_id}/server"
16
+ }
17
+
18
+ request(params)
19
+
20
+ end
21
+
22
+ end # Real
23
+
24
+
25
+ class Mock
26
+
27
+ def remove_block_storage_server(block_storage_id: nil)
28
+
29
+ # Search for block storage
30
+ if block_storage = self.data[:block_storages].find {
31
+ |hash| hash['id'] == block_storage_id
32
+ }
33
+ else
34
+ raise Fog::Errors::NotFound.new('The requested resource could
35
+ not be found.')
36
+ end
37
+
38
+ # Return Response Object to User
39
+ response = Excon::Response.new
40
+ response.status = 202
41
+ response.body = block_storage
42
+ response
43
+
44
+ end
45
+
46
+ end # Mock
47
+
48
+ end # OneAndOne
49
+ end # Compute
50
+ end # Fog
@@ -0,0 +1,80 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+
5
+ class Real
6
+
7
+ ##
8
+ # Modify a block storage
9
+ # URL: [https://cloudpanel-api.1and1.com/documentation/v1/en/api/documentation.html#block_storages__block_storage_id__put]
10
+ ##
11
+ def update_block_storage(block_storage_id: nil, name: nil,
12
+ description: nil, size: nil)
13
+
14
+ # Build PUT body
15
+ new_block_storage = {
16
+ 'name' => name,
17
+ 'description' => description,
18
+ 'size' => size
19
+ }
20
+
21
+ # Clean out null values from PUT body
22
+ body = clean_hash(new_block_storage)
23
+
24
+ # Stringify the PUT body
25
+ string_body = Fog::JSON.encode(body)
26
+
27
+ # Request
28
+ params = {
29
+ 'method' => :put,
30
+ 'endpoint' => "/block_storages/#{block_storage_id}",
31
+ 'body' => string_body
32
+ }
33
+
34
+ request(params)
35
+
36
+ end
37
+
38
+ end # Real
39
+
40
+
41
+ class Mock
42
+
43
+ def update_block_storage(block_storage_id: nil, name: nil,
44
+ description: nil, size: nil)
45
+
46
+ # Search for block storage to update
47
+ if block_storage = self.data[:block_storages].find {
48
+ |hash| hash['id'] == block_storage_id
49
+ }
50
+ # Create parameter hash
51
+ params = {
52
+ 'name' => name,
53
+ 'description' => description,
54
+ 'size' => size
55
+ }
56
+
57
+ # Update the block storage we found with new values
58
+ params.each do |key, value|
59
+ if value
60
+ block_storage[key] = value
61
+ end
62
+ end
63
+ else
64
+ raise Fog::Errors::NotFound.new('The requested resource could
65
+ not be found.')
66
+ end
67
+
68
+ # Return Response Object to User
69
+ response = Excon::Response.new
70
+ response.status = 202
71
+ response.body = block_storage
72
+ response
73
+
74
+ end
75
+
76
+ end # Mock
77
+
78
+ end # OneAndOne
79
+ end # Compute
80
+ end # Fog
@@ -0,0 +1,78 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+
5
+ class Real
6
+
7
+ ##
8
+ # Modify a ssh key
9
+ # URL: [https://cloudpanel-api.1and1.com/documentation/v1/en/api/documentation.html#ssh_keys__ssh_key_id__put]
10
+ ##
11
+ def update_ssh_key(ssh_key_id: nil, name: nil,
12
+ description: nil)
13
+
14
+ # Build PUT body
15
+ new_ssh_key = {
16
+ 'name' => name,
17
+ 'description' => description
18
+ }
19
+
20
+ # Clean out null values from PUT body
21
+ body = clean_hash(new_ssh_key)
22
+
23
+ # Stringify the PUT body
24
+ string_body = Fog::JSON.encode(body)
25
+
26
+ # Request
27
+ params = {
28
+ 'method' => :put,
29
+ 'endpoint' => "/ssh_keys/#{ssh_key_id}",
30
+ 'body' => string_body
31
+ }
32
+
33
+ request(params)
34
+
35
+ end
36
+
37
+ end # Real
38
+
39
+
40
+ class Mock
41
+
42
+ def update_ssh_key(ssh_key_id: nil, name: nil,
43
+ description: nil)
44
+
45
+ # Search for ssh key to update
46
+ if ssh_key = self.data[:ssh_keys].find {
47
+ |hash| hash['id'] == ssh_key_id
48
+ }
49
+ # Create parameter hash
50
+ params = {
51
+ 'name' => name,
52
+ 'description' => description
53
+ }
54
+
55
+ # Update the ssh key we found with new values
56
+ params.each do |key, value|
57
+ if value
58
+ ssh_key[key] = value
59
+ end
60
+ end
61
+ else
62
+ raise Fog::Errors::NotFound.new('The requested resource could
63
+ not be found.')
64
+ end
65
+
66
+ # Return Response Object to User
67
+ response = Excon::Response.new
68
+ response.status = 202
69
+ response.body = ssh_key
70
+ response
71
+
72
+ end
73
+
74
+ end # Mock
75
+
76
+ end # OneAndOne
77
+ end # Compute
78
+ end # Fog
@@ -0,0 +1,82 @@
1
+ require_relative '../../lib/fog-oneandone'
2
+ require 'minitest/autorun'
3
+
4
+ Fog.mock!
5
+
6
+ class TestBlockStorage < Minitest::Test
7
+
8
+ def self.test_order
9
+ :alpha
10
+ end
11
+
12
+ def setup
13
+
14
+ # Establish Connection
15
+ @compute = Fog::Compute::OneAndOne.new({
16
+ :oneandone_api_key => '<API-TOKEN>'
17
+ })
18
+
19
+ end
20
+
21
+
22
+ def test_a_create_block_storage
23
+
24
+ # Perform Request
25
+ response = @compute.create_block_storage(name: 'Test Block Storage',
26
+ description: 'Example Desc', size: 20,
27
+ datacenter_id: '4EFAD5836CE43ACA502FD5B99BEE44EF')
28
+
29
+ @@block_storage_id = response.body['id']
30
+
31
+ # Assertions
32
+ assert_equal response.body['name'], 'Test Block Storage'
33
+ assert_equal response.body['description'], 'Example Desc'
34
+ assert_equal response.body['size'], 20
35
+
36
+ end
37
+
38
+ def test_b_list_block_storages
39
+
40
+ # Perform Request
41
+ response = @compute.list_block_storages
42
+
43
+ # Assertions
44
+ assert_equal response.body.length, 1
45
+
46
+ end
47
+
48
+ def test_c_update_block_storage
49
+
50
+ # Perform Request
51
+ response = @compute.update_block_storage(block_storage_id: @@block_storage_id,
52
+ name: 'New Name', description: 'New Desc')
53
+
54
+ # Assertions
55
+ assert_equal response.body['name'], 'New Name'
56
+ assert_equal response.body['description'], 'New Desc'
57
+
58
+ end
59
+
60
+ def test_d_get_block_storage
61
+
62
+ # Perform Request
63
+ response = @compute.get_block_storage(@@block_storage_id)
64
+
65
+ # Assertions
66
+ assert_equal response.body['id'], @@block_storage_id
67
+
68
+ end
69
+
70
+ def test_i_delete_block_storage
71
+
72
+ # Perform Request
73
+ response = @compute.delete_block_storage(@@block_storage_id)
74
+
75
+ puts "response.body: #{response.body}"
76
+
77
+ # Assertions
78
+ assert_equal response.body, []
79
+
80
+ end
81
+
82
+ end
@@ -110,18 +110,7 @@ class TestFirewall < Minitest::Test
110
110
 
111
111
  end
112
112
 
113
- def test_h_remove_firewall_ip
114
-
115
- # Perform Request
116
- response = @compute.remove_firewall_ip(firewall_id: @@firewall_id,
117
- ip_id: '<IP-ID>')
118
-
119
- # Assertions
120
- assert_equal response.body['server_ips'].length, 0
121
-
122
- end
123
-
124
- def test_i_add_firewall_rules
113
+ def test_h_add_firewall_rules
125
114
 
126
115
  # Perform Request
127
116
  rule2 = {
@@ -143,7 +132,7 @@ class TestFirewall < Minitest::Test
143
132
 
144
133
  end
145
134
 
146
- def test_j_list_firewall_rules
135
+ def test_i_list_firewall_rules
147
136
 
148
137
  # Perform Request
149
138
  response = @compute.list_firewall_rules(@@firewall_id)
@@ -153,7 +142,7 @@ class TestFirewall < Minitest::Test
153
142
 
154
143
  end
155
144
 
156
- def test_k_get_firewall_rule
145
+ def test_j_get_firewall_rule
157
146
 
158
147
  # Perform Request
159
148
  response = @compute.get_firewall_rule(firewall_id: @@firewall_id,
@@ -164,7 +153,7 @@ class TestFirewall < Minitest::Test
164
153
 
165
154
  end
166
155
 
167
- def test_l_delete_firewall_rule
156
+ def test_k_delete_firewall_rule
168
157
 
169
158
  # Perform Request
170
159
  response = @compute.delete_firewall_rule(firewall_id: @@firewall_id,
@@ -175,7 +164,7 @@ class TestFirewall < Minitest::Test
175
164
 
176
165
  end
177
166
 
178
- def test_m_delete_firewall
167
+ def test_l_delete_firewall
179
168
 
180
169
  # Perform Request
181
170
  response = @compute.delete_firewall(@@firewall_id)
@@ -0,0 +1,34 @@
1
+ require_relative '../../lib/fog-oneandone'
2
+ require 'minitest/autorun'
3
+
4
+ Fog.mock!
5
+
6
+ class TestRecoveryAppliance < Minitest::Test
7
+ def self.test_order
8
+ :alpha
9
+ end
10
+
11
+ def setup
12
+ # Establish Connection
13
+ @compute = Fog::Compute::OneAndOne.new({
14
+ :oneandone_api_key => 'APIKEY'
15
+ })
16
+ end
17
+
18
+ def test_a_list_recovery_appliances
19
+ # Perform Request
20
+ response = @compute.list_recovery_appliances
21
+
22
+ @@appliance_id = response.body[0]['id']
23
+ # Assertions
24
+ assert_equal response.body.length, 2
25
+ end
26
+
27
+ def test_b_get_recovery_appliance
28
+ # Perform Request
29
+ response = @compute.get_recovery_appliance(@@appliance_id)
30
+
31
+ # Assertions
32
+ assert_equal response.body['id'], @@appliance_id
33
+ end
34
+ end
@@ -0,0 +1,34 @@
1
+ require_relative '../../lib/fog-oneandone'
2
+ require 'minitest/autorun'
3
+
4
+ Fog.mock!
5
+
6
+ class TestServerAppliance < Minitest::Test
7
+ def self.test_order
8
+ :alpha
9
+ end
10
+
11
+ def setup
12
+ # Establish Connection
13
+ @compute = Fog::Compute::OneAndOne.new({
14
+ :oneandone_api_key => 'APIKEY'
15
+ })
16
+ end
17
+
18
+ def test_a_list_server_appliances
19
+ # Perform Request
20
+ response = @compute.list_server_appliances
21
+
22
+ @@appliance_id = response.body[0]['id']
23
+ # Assertions
24
+ assert_equal response.body.length, 2
25
+ end
26
+
27
+ def test_b_get_server_appliance
28
+ # Perform Request
29
+ response = @compute.get_server_appliance(@@appliance_id)
30
+
31
+ # Assertions
32
+ assert_equal response.body['id'], @@appliance_id
33
+ end
34
+ end