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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 56d7c39794b25233e7aaa863d457f412a671af87
4
- data.tar.gz: b2c478a22092ab58ad2ba8981cd28b317d83a611
2
+ SHA256:
3
+ metadata.gz: f373bf00aa4accd5cfc0f5cb70ba5c64e7a4d7b21a2ba1ec69abafcf74fe4d81
4
+ data.tar.gz: b5d9f9dd6516e9a97ded3f3d57d000c0de120c8ee73e28df15500851d45f6d8e
5
5
  SHA512:
6
- metadata.gz: a067ef076c2893ded4479444789baf5fd6cf9cd768d9d772a2f30e91c392c4d1e6c90a84c5544d62288e5b15d5e58db0638dbebd37c05eb1d3bb3482c2535dd1
7
- data.tar.gz: 959e2eda82a1a0e56550fff4ad9020eb016c002c3e80af37cfef55db86e085e1b1bc870f27f6080bb52ddecfe280e7c4c28ddc05f1697a000f123d1b611ca344
6
+ metadata.gz: ff99d22c4ec2285d479c73027f18d443200b3675c3033e9c18e5d0901f87dc4fbe5f03124303aa8cd56fbdfc4a37c2df1520e495c17764d2c6aa8d863c9b7317
7
+ data.tar.gz: 36bef36cf89ddf299c767dd1d2c93ecbd225fb7fde5fbd5448f9821aa6f2c2486d89291006362f987f008590cc862988a18c405ec7aa07954b0ec074200541b3
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/tjb1019/fog.svg?branch=master)](https://travis-ci.org/tjb1019/fog)
4
4
 
5
- Fog is an open-source, community Ruby library used for interacting with popular cloud infrastructure providers through a single, unified API.
5
+ Fog is an open-source, community Ruby library used for interacting with popular cloud infrastructure providers through a single, unified API. For more information on the Fog plug-in see the [1&1 Community Portal](https://www.1and1.com/cloud-community/).
6
6
 
7
7
  This guide will show you how to programmatically use the 1&1 provider in Fog to perform common management tasks available in the 1&1 Cloud Panel.
8
8
 
@@ -187,6 +187,8 @@ public_ips
187
187
  private_networks
188
188
  monitoring_policies
189
189
  vpns
190
+ block_storages
191
+ ssh_keys
190
192
  ```
191
193
 
192
194
  Each collection comes equipped with the `create`, `all`, and `get` methods. You've seen how the `create` method works in our server example above. `all` will fetch every object of that type from the provider, and generate a model for each of those objects. Here's an example:
@@ -0,0 +1,24 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ task :default => :travis
5
+ task :travis => ["test", "test:travis"]
6
+ task :console do
7
+ exec "pry -r fog/oneandone -I ./lib"
8
+ end
9
+
10
+ Rake::TestTask.new do |t|
11
+ t.libs.push %w(spec)
12
+ t.test_files = FileList["tests/**/**.rb"]
13
+ t.verbose = true
14
+ end
15
+
16
+ namespace :test do
17
+ mock = ENV["FOG_MOCK"] || "true"
18
+ task :travis do
19
+ sh("export FOG_MOCK=#{mock} && bundle exec shindont")
20
+ end
21
+ end
22
+
23
+ desc "Default Task"
24
+ task :default => [:test]
@@ -4,11 +4,18 @@ compute = Fog::Compute::OneAndOne.new({
4
4
  :oneandone_api_key => '<API-TOKEN>'
5
5
  })
6
6
 
7
+ # Create SSH Key
8
+ my_ssh_key = compute.ssh_keys.create(name: 'Fog Example App Ssh Key',
9
+ description: 'My Fog SSH Key Description',
10
+ public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCezYMOgAan+JmatgFJ+Q1FUNjrqNVgAvcTkjYJwHVcQaolq9f9qB7tEeUPDNj2oNN49joAmTcllDcPIxryT5PnQUaaUhu4ZJ9+bRtXCyhnf2LJQdVfzBFEBJX9fW4RiV1XtSAtLRBrbrCb4JjHmhIYpvhBHC29Ve+g64nhdvBhqyLZ3SLI2U/opEmt5u2xftWGl0TBSQYveqc4ntz3fe+f9XlBHvK3Nw12bCLmLle7jQuZ4lXyAYqNAfdOMTs2zMTk422Dl/h4+zRh1h4rM9zaCk4+g3kdugJm7Vul03wm43cHmHsJv51R3XKSHzgb7q/eNj+YdMi5Ndt0Bm+bLjw4")
11
+ puts 'Creating ssh key...'
12
+
7
13
  # Create Server
8
- my_server = compute.servers.create(name: 'Example App Server',
9
- fixed_instance_id: '65929629F35BBFBA63022008F773F3EB',
10
- appliance_id: '6C902E5899CC6F7ED18595EBEB542EE1',
11
- datacenter_id: '5091F6D8CBFEF9C26ACE957C652D5D49')
14
+ my_server = compute.servers.create(name: 'Fog Example App Server',
15
+ fixed_instance_id: 'CCC1C54896223068E05EFC17614EE690',
16
+ appliance_id: 'C572494C271ED64142E5FD93E084BBFC',
17
+ datacenter_id: '4EFAD5836CE43ACA502FD5B99BEE44EF',
18
+ public_key: [my_ssh_key.id])
12
19
 
13
20
  puts 'Creating server...'
14
21
  puts my_server.wait_for { ready? }
@@ -17,15 +24,21 @@ puts my_server.wait_for { ready? }
17
24
  # Create Firewall
18
25
  puts "----------"
19
26
  rule1 = {
20
- 'protocol' => 'TCP',
21
- 'port_from' => 80,
22
- 'port_to' => 80,
23
- 'source' => '0.0.0.0'
27
+ 'description' => 'Testing firewall improvements fog',
28
+ 'protocol' => 'TCP',
29
+ 'port' => '90',
30
+ 'source' => '0.0.0.0'
31
+ }
32
+ rule2 = {
33
+ 'protocol' => 'TCP',
34
+ 'port_from' => 80,
35
+ 'port_to' => 80,
36
+ 'source' => '0.0.0.0'
24
37
  }
25
38
 
26
- rules = [rule1]
39
+ rules = [rule1, rule2]
27
40
 
28
- my_firewall = compute.firewalls.create(name: 'Example App Firewall',
41
+ my_firewall = compute.firewalls.create(name: 'Fog Example App Firewall',
29
42
  rules: rules)
30
43
  puts 'Creating Firewall...'
31
44
  puts my_firewall.wait_for { ready? }
@@ -42,10 +55,10 @@ rule1 = {
42
55
 
43
56
  rules = [rule1]
44
57
 
45
- my_load_balancer = compute.load_balancers.create(name: 'Example App LB',
58
+ my_load_balancer = compute.load_balancers.create(name: 'Fog Example App LB',
46
59
  rules: rules, health_check_test: 'TCP', health_check_interval: 40,
47
60
  persistence: true, persistence_time: 1200, method: 'ROUND_ROBIN',
48
- datacenter_id: '5091F6D8CBFEF9C26ACE957C652D5D49')
61
+ datacenter_id: '4EFAD5836CE43ACA502FD5B99BEE44EF')
49
62
  puts 'Creating Load Balancer...'
50
63
  puts my_load_balancer.wait_for { ready? }
51
64
 
@@ -65,6 +78,15 @@ my_server.add_load_balancer(ip_id: my_server.ips[0]['id'],
65
78
  load_balancer_id: my_load_balancer.id)
66
79
  puts my_server.wait_for { ready? }
67
80
 
81
+ # Create Block Storage
82
+ my_block_storage = compute.block_storages.create(
83
+ name: 'My Fog Block Storage', size: 20,
84
+ description: 'Testing fog block storage',
85
+ datacenter_id: '4EFAD5836CE43ACA502FD5B99BEE44EF',
86
+ server_id: my_server.id
87
+ )
88
+ puts 'Creating Block Storage...'
89
+ puts my_block_storage.wait_for { ready? }
68
90
 
69
91
  # Cleanup
70
92
  puts "----------"
@@ -76,5 +98,10 @@ puts 'Destroying load balancer...'
76
98
  puts my_load_balancer.destroy
77
99
 
78
100
  puts "----------"
101
+ puts my_firewall.wait_for { ready? }
79
102
  puts 'Destroying firewall...'
80
103
  puts my_firewall.destroy
104
+
105
+ puts "----------"
106
+ puts 'Destroying SSH key...'
107
+ puts my_ssh_key.destroy
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fog-oneandone"
7
- spec.version = "1.0"
7
+ spec.version = "1.2"
8
8
  spec.authors = ["Tyler Burkhardt (stackpointcloud.com)"]
9
9
  spec.email = "tyler@stackpointcloud.com"
10
10
  spec.summary = "Module for the 'fog' gem to support 1and1."
@@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
19
19
  spec.add_runtime_dependency "fog-core"
20
20
  spec.add_runtime_dependency "fog-json"
21
21
  spec.add_development_dependency "minitest"
22
+ spec.add_development_dependency "pry", "~> 0.10"
22
23
  end
@@ -38,6 +38,21 @@ module Fog
38
38
  model :vpn
39
39
  collection :vpns
40
40
 
41
+ model :block_storage
42
+ collection :block_storages
43
+
44
+ model :ssh_key
45
+ collection :ssh_keys
46
+
47
+ model :baremetal_model
48
+ collection :baremetal_models
49
+
50
+ model :server_appliance
51
+ collection :server_appliances
52
+
53
+ model :recovery_appliance
54
+ collection :recovery_appliances
55
+
41
56
  # Requests
42
57
  request_path 'oneandone/requests/compute'
43
58
 
@@ -94,14 +109,12 @@ module Fog
94
109
 
95
110
  request :clone_server
96
111
 
97
-
98
112
  request :list_images
99
113
  request :create_image
100
114
  request :get_image
101
115
  request :update_image
102
116
  request :delete_image
103
117
 
104
-
105
118
  request :list_shared_storages
106
119
  request :create_shared_storage
107
120
  request :get_shared_storage
@@ -116,7 +129,6 @@ module Fog
116
129
  request :access
117
130
  request :change_password
118
131
 
119
-
120
132
  request :list_firewalls
121
133
  request :get_firewall
122
134
  request :create_firewall
@@ -125,7 +137,6 @@ module Fog
125
137
 
126
138
  request :list_firewall_ips
127
139
  request :get_firewall_ip
128
- request :remove_firewall_ip
129
140
  request :add_firewall_ips
130
141
 
131
142
  request :list_firewall_rules
@@ -133,7 +144,6 @@ module Fog
133
144
  request :add_firewall_rules
134
145
  request :delete_firewall_rule
135
146
 
136
-
137
147
  request :list_load_balancers
138
148
  request :create_load_balancer
139
149
  request :get_load_balancer
@@ -150,14 +160,12 @@ module Fog
150
160
  request :get_load_balancer_rule
151
161
  request :delete_load_balancer_rule
152
162
 
153
-
154
163
  request :list_public_ips
155
164
  request :create_public_ip
156
165
  request :get_public_ip
157
166
  request :update_public_ip
158
167
  request :delete_public_ip
159
168
 
160
-
161
169
  request :list_private_networks
162
170
  request :create_private_network
163
171
  request :get_private_network
@@ -169,11 +177,9 @@ module Fog
169
177
  request :remove_private_network_server
170
178
  request :add_private_network_servers
171
179
 
172
-
173
180
  request :list_monitored_servers
174
181
  request :get_monitored_server
175
182
 
176
-
177
183
  request :list_monitoring_policies
178
184
  request :get_monitoring_policy
179
185
  request :create_monitoring_policy
@@ -197,36 +203,51 @@ module Fog
197
203
  request :remove_mp_server
198
204
  request :add_mp_servers
199
205
 
200
-
201
206
  request :list_logs
202
207
  request :get_log
203
208
 
204
-
205
209
  request :list_usages
206
210
 
207
-
208
211
  request :list_server_appliances
209
212
  request :get_server_appliance
210
213
 
211
-
212
214
  request :list_dvds
213
215
  request :get_dvd_iso
214
216
 
215
-
216
217
  request :list_vpns
217
218
  request :create_vpn
218
219
  request :get_vpn
219
220
  request :update_vpn
220
221
  request :delete_vpn
221
222
 
222
-
223
223
  request :ping
224
224
  request :ping_auth
225
225
 
226
-
227
226
  request :list_datacenters
228
227
  request :get_datacenter
229
228
 
229
+ request :list_block_storages
230
+ request :create_block_storage
231
+ request :get_block_storage
232
+ request :update_block_storage
233
+ request :delete_block_storage
234
+
235
+ request :get_block_storage_server
236
+ request :add_block_storage_server
237
+ request :remove_block_storage_server
238
+
239
+ request :list_ssh_keys
240
+ request :create_ssh_key
241
+ request :get_ssh_key
242
+ request :update_ssh_key
243
+ request :delete_ssh_key
244
+
245
+ request :list_baremetal_models
246
+ request :get_baremetal_model
247
+
248
+ request :list_recovery_appliances
249
+ request :get_recovery_appliance
250
+
230
251
  class Real
231
252
 
232
253
  def initialize(options = {})
@@ -296,6 +317,44 @@ module Fog
296
317
  :private_networks => [],
297
318
  :monitoring_policies => [],
298
319
  :vpns => [],
320
+ :ssh_keys => [],
321
+ :block_storages => [],
322
+ :baremetal_models => [
323
+ {
324
+ "name" => "baremetal_1_name",
325
+ "id" => "8C626C1A7005D0D1F527143C413D461E",
326
+ "hardware" => {
327
+ "cores" => 1,
328
+ "cores_per_processor" => 4,
329
+ "ram" => 16,
330
+ "unit" => "GB",
331
+ "hdds" => [
332
+ {
333
+ "size" => 480,
334
+ "unit" => "GB",
335
+ "is_main" => true
336
+ }
337
+ ]
338
+ }
339
+ },
340
+ {
341
+ "name" => "baremetal_2_name",
342
+ "id" => "8C626C1A7005D0D1F5271434563D461A",
343
+ "hardware" => {
344
+ "cores" => 1,
345
+ "cores_per_processor" => 4,
346
+ "ram" => 64,
347
+ "unit" => "GB",
348
+ "hdds" => [
349
+ {
350
+ "size" => 800,
351
+ "unit" => "GB",
352
+ "is_main" => true
353
+ }
354
+ ]
355
+ }
356
+ }
357
+ ],
299
358
  :datacenters => [
300
359
  {
301
360
  "id" => "81DEF28500FBC2A973FC0C620DF5B721",
@@ -679,6 +738,34 @@ module Fog
679
738
  "os_architecture" => 64,
680
739
  "type" => "OS"
681
740
  }
741
+ ],
742
+ :recovery_appliances => [
743
+ {
744
+ "id" => "81504C620D98BCEBAA5202D145203B4B",
745
+ "name" => "Recovery image name",
746
+ "available_datacenters" => [
747
+ "DA41201B4A006EDE6DA62A5A62A658E7",
748
+ "47FA5A2D251AE57935E30F9D5AB4F817",
749
+ "7C5FA1D21B98DE39D7516333AAB7DA54"
750
+ ],
751
+ "os_family" => "Linux",
752
+ "os" => "CentOS",
753
+ "os_version" => "CentOS 7",
754
+ "architecture" => 64
755
+ },
756
+ {
757
+ "id" => "81504C620D98BCEB5646987545203B42",
758
+ "name" => "Recovery image name",
759
+ "available_datacenters" => [
760
+ "DA41201B4A006EDE6DA62A5A62A658E7",
761
+ "47FA5A2D251AE57935E30F9D5AB4F817",
762
+ "7C5FA1D21B98DE39D7516333AAB7DA54"
763
+ ],
764
+ "os_family" => "Windows",
765
+ "os" => "Windows",
766
+ "os_version" => "Windows 2012",
767
+ "architecture" => 64
768
+ }
682
769
  ]
683
770
  }
684
771
  end
@@ -0,0 +1,15 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+ class BaremetalModel < Fog::Model
5
+
6
+ # Declare Model Attributes
7
+ identity :id
8
+
9
+ attribute :name
10
+ attribute :hardware
11
+
12
+ end # BaremetalModel
13
+ end # OneAndOne
14
+ end # Compute
15
+ end # Fog
@@ -0,0 +1,24 @@
1
+ require_relative 'baremetal_model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class OneAndOne
6
+ class BaremetalModels < Fog::Collection
7
+ model Fog::Compute::OneAndOne::BaremetalModel
8
+
9
+ def all
10
+ response = service.list_baremetal_models
11
+ load(response.body)
12
+ end
13
+
14
+ def get(id)
15
+ response = service.get_server(id)
16
+ new(response.body)
17
+ rescue Excon::Errors::NotFound
18
+ nil
19
+ end
20
+
21
+ end # BaremetalModels
22
+ end # OneAndOne
23
+ end # Compute
24
+ end # Fog
@@ -0,0 +1,100 @@
1
+ module Fog
2
+ module Compute
3
+ class OneAndOne
4
+ class BlockStorage < Fog::Model
5
+
6
+ # Declare Model Attributes
7
+ identity :id
8
+
9
+ attribute :size
10
+ attribute :state
11
+ attribute :description
12
+ attribute :name
13
+ attribute :datacenter_id
14
+ attribute :datacenter
15
+ attribute :creation_date
16
+ attribute :server
17
+ attribute :server_id
18
+
19
+
20
+ def save
21
+
22
+ # Perform Request
23
+ response = service.create_block_storage(name: name, size: size,
24
+ description: description, datacenter_id: datacenter_id,
25
+ server_id: server_id)
26
+
27
+ # Merge Attributes
28
+ merge_attributes(response.body)
29
+
30
+ true
31
+
32
+ end
33
+
34
+
35
+ def update(options = {})
36
+
37
+ requires :id
38
+
39
+ response = service.update_block_storage(block_storage_id: id,
40
+ name: options[:name], description: options[:description],
41
+ size: options[:size])
42
+
43
+ # Merge Attributes
44
+ merge_attributes(response.body)
45
+
46
+ true
47
+
48
+ end
49
+
50
+
51
+ def add_server(options = {})
52
+
53
+ requires :id
54
+
55
+ response = service.add_block_storage_server(block_storage_id: id,
56
+ server_id: options[:server_id])
57
+
58
+ # Merge Attributes
59
+ merge_attributes(response.body)
60
+
61
+ true
62
+
63
+ end
64
+
65
+
66
+ def remove_server()
67
+
68
+ requires :id
69
+
70
+ response = service.remove_block_storage_server(block_storage_id: id)
71
+
72
+ # Merge Attributes
73
+ merge_attributes(response.body)
74
+
75
+ true
76
+
77
+ end
78
+
79
+
80
+ def destroy
81
+
82
+ requires :id
83
+
84
+ service.delete_block_storage(id)
85
+
86
+ true
87
+
88
+ end
89
+
90
+
91
+ def ready?
92
+
93
+ state == 'POWERED_ON'
94
+
95
+ end
96
+
97
+ end # BlockStorage
98
+ end # OneAndOne
99
+ end # Compute
100
+ end # Fog