fog-oneandone 1.0 → 1.2

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 (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,25 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+ class ServerAppliance < Fog::Model
5
+
6
+ # Declare Model Attributes
7
+ identity :id
8
+
9
+ attribute :name
10
+ attribute :os_family
11
+ attribute :os
12
+ attribute :os_version
13
+ attribute :os_architecture
14
+ attribute :os_image_type
15
+ attribute :type
16
+ attribute :server_type_compatibility
17
+ attribute :min_hdd_size
18
+ attribute :licenses
19
+ attribute :version
20
+ attribute :categories
21
+
22
+ end # ServerAppliance
23
+ end # OneAndOne
24
+ end # Compute
25
+ end # Fog
@@ -0,0 +1,24 @@
1
+ require_relative 'server_appliance'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OneAndOne
6
+ class ServerAppliances < Fog::Collection
7
+ model Fog::Compute::OneAndOne::ServerAppliance
8
+
9
+ def all
10
+ response = service.list_server_appliances
11
+ load(response.body)
12
+ end
13
+
14
+ def get(id)
15
+ response = service.get_server_appliance(id)
16
+ new(response.body)
17
+ rescue Excon::Errors::NotFound
18
+ nil
19
+ end
20
+
21
+ end # ServerAppliances
22
+ end # OneAndOne
23
+ end # Compute
24
+ end # Fog
@@ -0,0 +1,67 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+ class SshKey < Fog::Model
5
+
6
+ # Declare Model Attributes
7
+ identity :id
8
+
9
+ attribute :name
10
+ attribute :description
11
+ attribute :state
12
+ attribute :servers
13
+ attribute :md5
14
+ attribute :public_key
15
+ attribute :creation_date
16
+
17
+
18
+ def save
19
+
20
+ # Perform Request
21
+ response = service.create_ssh_key(name: name, description: description,
22
+ public_key: public_key)
23
+
24
+ # Merge Attributes
25
+ merge_attributes(response.body)
26
+
27
+ true
28
+
29
+ end
30
+
31
+
32
+ def update(options = {})
33
+
34
+ requires :id
35
+
36
+ response = service.update_ssh_key(ssh_key_id: id,
37
+ name: options[:name], description: options[:description])
38
+
39
+ # Merge Attributes
40
+ merge_attributes(response.body)
41
+
42
+ true
43
+
44
+ end
45
+
46
+
47
+ def destroy
48
+
49
+ requires :id
50
+
51
+ service.delete_ssh_key(id)
52
+
53
+ true
54
+
55
+ end
56
+
57
+
58
+ def ready?
59
+
60
+ state == 'ACTIVE'
61
+
62
+ end
63
+
64
+ end # SshKey
65
+ end # OneAndOne
66
+ end # Compute
67
+ end # Fog
@@ -0,0 +1,24 @@
1
+ require_relative 'ssh_key'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OneAndOne
6
+ class SshKeys < Fog::Collection
7
+ model Fog::Compute::OneAndOne::SshKey
8
+
9
+ def all
10
+ response = service.list_ssh_keys
11
+ load(response.body)
12
+ end
13
+
14
+ def get(id)
15
+ response = service.get_ssh_key(id)
16
+ new(response.body)
17
+ rescue Excon::Errors::NotFound
18
+ nil
19
+ end
20
+
21
+ end # SshKeys
22
+ end # OneAndOne
23
+ end # Compute
24
+ end # Fog
@@ -0,0 +1,61 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+
5
+ class Real
6
+
7
+ ##
8
+ # Attach a server to a block storage
9
+ # URL: [https://cloudpanel-api.1and1.com/documentation/v1/en/api/documentation.html#block_storages__block_storage_id__server_post]
10
+ ##
11
+ def add_block_storage_server(block_storage_id: nil, server_id: nil)
12
+
13
+ # Build POST body
14
+ add_server = {
15
+ 'server_id' => server_id
16
+ }
17
+
18
+ # Stringify the POST body
19
+ string_body = Fog::JSON.encode(add_server)
20
+
21
+ # Request
22
+ params = {
23
+ 'method' => :post,
24
+ 'endpoint' => "/block_storages/#{block_storage_id}/server",
25
+ 'body' => string_body
26
+ }
27
+
28
+ request(params)
29
+
30
+ end
31
+
32
+ end # Real
33
+
34
+
35
+ class Mock
36
+
37
+ def add_block_storage_server(block_storage_id: nil, server_id: nil)
38
+
39
+ # Search for block storage to return
40
+ if block_storage = self.data[:block_storages].find {
41
+ |hash| hash['id'] == block_storage_id
42
+ }
43
+ block_storage['server'] << {"id" => server_id}
44
+ else
45
+ raise Fog::Errors::NotFound.new('The requested resource could
46
+ not be found.')
47
+ end
48
+
49
+ # Return Response Object to User
50
+ response = Excon::Response.new
51
+ response.status = 202
52
+ response.body = block_storage
53
+ response
54
+
55
+ end
56
+
57
+ end # Mock
58
+
59
+ end # OneAndOne
60
+ end # Compute
61
+ end # Fog
@@ -16,7 +16,7 @@ module Fog
16
16
  }
17
17
 
18
18
  # Stringify the POST body
19
- string_body = Fog::JSON.encode(body)
19
+ string_body = Fog::JSON.encode(new_ports)
20
20
 
21
21
  # Request
22
22
  params = {
@@ -0,0 +1,80 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+
5
+ class Real
6
+
7
+ ##
8
+ # Creates a new block storage
9
+ # URL: [https://cloudpanel-api.1and1.com/documentation/v1/en/api/documentation.html#block_storages_post]
10
+ ##
11
+ def create_block_storage(name: nil, description: nil,
12
+ size: nil, datacenter_id: nil, server_id: nil)
13
+
14
+ # Build POST body
15
+ new_block_storage = {
16
+ 'name' => name,
17
+ 'description' => description,
18
+ 'size' => size,
19
+ 'datacenter_id' => datacenter_id,
20
+ 'server' => server_id
21
+ }
22
+
23
+ # Clean out null values from POST body
24
+ body = clean_hash(new_block_storage)
25
+
26
+ # Stringify the POST body
27
+ string_body = Fog::JSON.encode(body)
28
+
29
+ # Request
30
+ params = {
31
+ 'method' => :post,
32
+ 'endpoint' => '/block_storages',
33
+ 'body' => string_body
34
+ }
35
+
36
+ request(params)
37
+
38
+ end
39
+
40
+ end # Real
41
+
42
+
43
+ class Mock
44
+
45
+ def create_block_storage(name: nil, description: nil,
46
+ size: nil, datacenter_id: nil, server_id: nil)
47
+
48
+ # Create mock block storage hash
49
+ mock_block_storage = {
50
+ "id" => Fog::UUID.uuid,
51
+ "size" => size,
52
+ "state" => "ACTIVE",
53
+ "description" => description,
54
+ "datacenter" => {
55
+ "id" => datacenter_id,
56
+ "location" => "USA",
57
+ "country_code" => "US"
58
+ },
59
+ "name" => name,
60
+ "creation_date" => "2018-01-06T08:33:25+00:00",
61
+ "server" => server_id
62
+ }
63
+
64
+ # Save mock block storage to list
65
+ self.data[:block_storages] << mock_block_storage
66
+
67
+ # Return mock response to user
68
+ response = Excon::Response.new
69
+ response.status = 202
70
+ response.body = mock_block_storage
71
+
72
+ response
73
+
74
+ end
75
+
76
+ end # Mock
77
+
78
+ end # OneAndOne
79
+ end # Compute
80
+ end # Fog
@@ -9,7 +9,8 @@ module Fog
9
9
  # URL: [https://cloudpanel-api.1and1.com/documentation/1and1/v1/en/documentation.html#images_post]
10
10
  ##
11
11
  def create_image(server_id: nil, name: nil, description: nil,
12
- frequency: nil, num_images: nil)
12
+ frequency: nil, num_images: nil, source: nil, url: nil,
13
+ os_id: nil, type: nil)
13
14
 
14
15
  # Build POST body
15
16
  new_image = {
@@ -17,7 +18,11 @@ module Fog
17
18
  'name' => name,
18
19
  'description' => description,
19
20
  'frequency' => frequency,
20
- 'num_images' => num_images
21
+ 'num_images' => num_images,
22
+ 'source' => source,
23
+ 'url' => url,
24
+ 'os_id' => os_id,
25
+ 'type' => type
21
26
  }
22
27
 
23
28
  # Clean out null values from POST body
@@ -43,7 +48,8 @@ module Fog
43
48
  class Mock
44
49
 
45
50
  def create_image(server_id: nil, name: nil, description: nil,
46
- frequency: nil, num_images: nil)
51
+ frequency: nil, num_images: nil, source: nil, url: nil,
52
+ os_id: nil, type: nil)
47
53
 
48
54
  # Create mock image hash
49
55
  mock_image = {
@@ -12,8 +12,9 @@ module Fog
12
12
  fixed_instance_id: nil, vcore: nil, cores_per_processor: nil,
13
13
  ram: nil, appliance_id: nil, datacenter_id: nil, hdds: nil,
14
14
  password: nil, power_on: nil, firewall_id: nil, ip_id: nil,
15
- load_balancer_id: nil, monitoring_policy_id: nil)
16
-
15
+ load_balancer_id: nil, monitoring_policy_id: nil, public_key: nil,
16
+ server_type: nil, baremetal_model_id: nil)
17
+
17
18
  # Build hardware hash
18
19
  hardware_params = {
19
20
  'fixed_instance_size_id' => fixed_instance_id,
@@ -39,9 +40,13 @@ module Fog
39
40
  'firewall_policy_id' => firewall_id,
40
41
  'ip_id' => ip_id,
41
42
  'load_balancer_id' => load_balancer_id,
42
- 'monitoring_policy_id' => monitoring_policy_id
43
+ 'monitoring_policy_id' => monitoring_policy_id,
44
+ 'public_key' => public_key,
45
+ 'server_type' => server_type
43
46
  }
44
47
 
48
+ new_server['baremetal_model_id'] = baremetal_model_id if baremetal_model_id
49
+
45
50
  # Clean out null values from POST body
46
51
  body = clean_hash(new_server)
47
52
 
@@ -68,8 +73,9 @@ module Fog
68
73
  fixed_instance_id: nil, vcore: nil, cores_per_processor: nil,
69
74
  ram: nil, appliance_id: nil, datacenter_id: nil, hdds: nil,
70
75
  password: nil, power_on: nil, firewall_id: nil, ip_id: nil,
71
- load_balancer_id: nil, monitoring_policy_id: nil)
72
-
76
+ load_balancer_id: nil, monitoring_policy_id: nil, public_key: nil,
77
+ server_type: nil, baremetal_model_id: nil)
78
+
73
79
  # Add UUID to hdds being passed in
74
80
  if hdds
75
81
  hdds.each do |hdd|
@@ -0,0 +1,74 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+
5
+ class Real
6
+
7
+ ##
8
+ # Creates a new ssh key
9
+ # URL: [https://cloudpanel-api.1and1.com/documentation/v1/en/api/documentation.html#ssh_keys_post]
10
+ ##
11
+ def create_ssh_key(name: nil, description: nil,
12
+ public_key: nil)
13
+
14
+ # Build POST body
15
+ new_ssh_key = {
16
+ 'name' => name,
17
+ 'description' => description,
18
+ 'public_key' => public_key
19
+ }
20
+
21
+ # Clean out null values from POST body
22
+ body = clean_hash(new_ssh_key)
23
+
24
+ # Stringify the POST body
25
+ string_body = Fog::JSON.encode(body)
26
+
27
+ # Request
28
+ params = {
29
+ 'method' => :post,
30
+ 'endpoint' => '/ssh_keys',
31
+ 'body' => string_body
32
+ }
33
+
34
+ request(params)
35
+
36
+ end
37
+
38
+ end # Real
39
+
40
+
41
+ class Mock
42
+
43
+ def create_ssh_key(name: nil, description: nil,
44
+ public_key: nil)
45
+
46
+ # Create mock ssh key hash
47
+ mock_ssh_key = {
48
+ "id" => Fog::UUID.uuid,
49
+ "name" => name,
50
+ "description" => description,
51
+ "state" => "ACTIVE",
52
+ "servers" => [],
53
+ "md5" => "5df9f63916ebf8528697b629022993e8",
54
+ "creation_date" => "2018-01-06T08:33:25+00:00",
55
+ "public_key" => public_key
56
+ }
57
+
58
+ # Save mock ssh key to list
59
+ self.data[:ssh_keys] << mock_ssh_key
60
+
61
+ # Return mock response to user
62
+ response = Excon::Response.new
63
+ response.status = 202
64
+ response.body = mock_ssh_key
65
+
66
+ response
67
+
68
+ end
69
+
70
+ end # Mock
71
+
72
+ end # OneAndOne
73
+ end # Compute
74
+ end # Fog
@@ -0,0 +1,51 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+
5
+ class Real
6
+
7
+ ##
8
+ # Returns information about a block storage
9
+ # URL: https://cloudpanel-api.1and1.com/documentation/v1/en/api/documentation.html#block_storages__block_storage_id__delete
10
+ ##
11
+ def delete_block_storage(block_storage_id)
12
+
13
+ params = {
14
+ 'method' => :delete,
15
+ 'endpoint' => "/block_storages/#{block_storage_id}"
16
+ }
17
+
18
+ request(params)
19
+
20
+ end
21
+
22
+ end # Real
23
+
24
+
25
+ class Mock
26
+
27
+ def delete_block_storage(block_storage_id)
28
+
29
+ # Search for block storage to delete
30
+ if block_storage = self.data[:block_storages].find {
31
+ |hash| hash['id'] == block_storage_id
32
+ }
33
+ self.data[:block_storages].delete(block_storage)
34
+ else
35
+ raise Fog::Errors::NotFound.new('The requested resource could
36
+ not be found.')
37
+ end
38
+
39
+ # Return Response Object to User
40
+ response = Excon::Response.new
41
+ response.status = 202
42
+ response.body = []
43
+ response
44
+
45
+ end
46
+
47
+ end # Mock
48
+
49
+ end # OneAndOne
50
+ end # Compute
51
+ end # Fog