1and1 1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (290) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/1and1-1.0.gem +0 -0
  4. data/1and1.gemspec +20 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +201 -0
  7. data/README.md +499 -0
  8. data/docs/reference.md +2447 -0
  9. data/examples/dvd_examples.rb +15 -0
  10. data/examples/example_app.rb +100 -0
  11. data/examples/firewall_examples.rb +137 -0
  12. data/examples/image_examples.rb +48 -0
  13. data/examples/load_balancer_examples.rb +145 -0
  14. data/examples/log_examples.rb +15 -0
  15. data/examples/monitoring_center_examples.rb +15 -0
  16. data/examples/monitoring_policy_examples.rb +343 -0
  17. data/examples/private_network_examples.rb +86 -0
  18. data/examples/public_ip_examples.rb +42 -0
  19. data/examples/role_examples.rb +113 -0
  20. data/examples/server_appliance_examples.rb +15 -0
  21. data/examples/server_examples.rb +438 -0
  22. data/examples/shared_storage_examples.rb +108 -0
  23. data/examples/usage_examples.rb +6 -0
  24. data/examples/user_examples.rb +113 -0
  25. data/examples/vpn_examples.rb +56 -0
  26. data/lib/1and1/datacenter.rb +73 -0
  27. data/lib/1and1/dvd.rb +73 -0
  28. data/lib/1and1/firewall.rb +427 -0
  29. data/lib/1and1/image.rb +231 -0
  30. data/lib/1and1/load_balancer.rb +448 -0
  31. data/lib/1and1/log.rb +77 -0
  32. data/lib/1and1/monitoring_center.rb +84 -0
  33. data/lib/1and1/monitoring_policy.rb +598 -0
  34. data/lib/1and1/oneandone.rb +57 -0
  35. data/lib/1and1/ping.rb +41 -0
  36. data/lib/1and1/ping_auth.rb +41 -0
  37. data/lib/1and1/pricing.rb +41 -0
  38. data/lib/1and1/private_network.rb +333 -0
  39. data/lib/1and1/public_ip.rb +192 -0
  40. data/lib/1and1/role.rb +381 -0
  41. data/lib/1and1/server.rb +1208 -0
  42. data/lib/1and1/server_appliance.rb +73 -0
  43. data/lib/1and1/shared_storage.rb +379 -0
  44. data/lib/1and1/usage.rb +58 -0
  45. data/lib/1and1/user.rb +374 -0
  46. data/lib/1and1/vpn.rb +249 -0
  47. data/lib/oneandone.rb +27 -0
  48. data/sphinx/Makefile +192 -0
  49. data/sphinx/_build/doctrees/dvds.doctree +0 -0
  50. data/sphinx/_build/doctrees/environment.pickle +0 -0
  51. data/sphinx/_build/doctrees/firewalls.doctree +0 -0
  52. data/sphinx/_build/doctrees/images.doctree +0 -0
  53. data/sphinx/_build/doctrees/index.doctree +0 -0
  54. data/sphinx/_build/doctrees/load_balancers.doctree +0 -0
  55. data/sphinx/_build/doctrees/logs.doctree +0 -0
  56. data/sphinx/_build/doctrees/monitoring_center.doctree +0 -0
  57. data/sphinx/_build/doctrees/monitoring_policies.doctree +0 -0
  58. data/sphinx/_build/doctrees/private_networks.doctree +0 -0
  59. data/sphinx/_build/doctrees/public_ips.doctree +0 -0
  60. data/sphinx/_build/doctrees/server_appliances.doctree +0 -0
  61. data/sphinx/_build/doctrees/servers.doctree +0 -0
  62. data/sphinx/_build/doctrees/shared_storages.doctree +0 -0
  63. data/sphinx/_build/doctrees/usages.doctree +0 -0
  64. data/sphinx/_build/doctrees/users.doctree +0 -0
  65. data/sphinx/_build/html/.buildinfo +4 -0
  66. data/sphinx/_build/html/_sources/dvds.txt +42 -0
  67. data/sphinx/_build/html/_sources/firewalls.txt +189 -0
  68. data/sphinx/_build/html/_sources/images.txt +101 -0
  69. data/sphinx/_build/html/_sources/index.txt +499 -0
  70. data/sphinx/_build/html/_sources/load_balancers.txt +231 -0
  71. data/sphinx/_build/html/_sources/logs.txt +55 -0
  72. data/sphinx/_build/html/_sources/monitoring_center.txt +55 -0
  73. data/sphinx/_build/html/_sources/monitoring_policies.txt +288 -0
  74. data/sphinx/_build/html/_sources/private_networks.txt +146 -0
  75. data/sphinx/_build/html/_sources/public_ips.txt +78 -0
  76. data/sphinx/_build/html/_sources/server_appliances.txt +42 -0
  77. data/sphinx/_build/html/_sources/servers.txt +630 -0
  78. data/sphinx/_build/html/_sources/shared_storages.txt +160 -0
  79. data/sphinx/_build/html/_sources/usages.txt +45 -0
  80. data/sphinx/_build/html/_sources/users.txt +172 -0
  81. data/sphinx/_build/html/_static/ajax-loader.gif +0 -0
  82. data/sphinx/_build/html/_static/alabaster.css +585 -0
  83. data/sphinx/_build/html/_static/basic.css +599 -0
  84. data/sphinx/_build/html/_static/comment-bright.png +0 -0
  85. data/sphinx/_build/html/_static/comment-close.png +0 -0
  86. data/sphinx/_build/html/_static/comment.png +0 -0
  87. data/sphinx/_build/html/_static/doctools.js +263 -0
  88. data/sphinx/_build/html/_static/down-pressed.png +0 -0
  89. data/sphinx/_build/html/_static/down.png +0 -0
  90. data/sphinx/_build/html/_static/file.png +0 -0
  91. data/sphinx/_build/html/_static/jquery-1.11.1.js +10308 -0
  92. data/sphinx/_build/html/_static/jquery.js +4 -0
  93. data/sphinx/_build/html/_static/minus.png +0 -0
  94. data/sphinx/_build/html/_static/plus.png +0 -0
  95. data/sphinx/_build/html/_static/pygments.css +63 -0
  96. data/sphinx/_build/html/_static/searchtools.js +651 -0
  97. data/sphinx/_build/html/_static/underscore-1.3.1.js +999 -0
  98. data/sphinx/_build/html/_static/underscore.js +31 -0
  99. data/sphinx/_build/html/_static/up-pressed.png +0 -0
  100. data/sphinx/_build/html/_static/up.png +0 -0
  101. data/sphinx/_build/html/_static/websupport.js +808 -0
  102. data/sphinx/_build/html/dvds.html +151 -0
  103. data/sphinx/_build/html/firewalls.html +397 -0
  104. data/sphinx/_build/html/genindex.html +114 -0
  105. data/sphinx/_build/html/images.html +236 -0
  106. data/sphinx/_build/html/index.html +571 -0
  107. data/sphinx/_build/html/load_balancers.html +409 -0
  108. data/sphinx/_build/html/logs.html +160 -0
  109. data/sphinx/_build/html/monitoring_center.html +160 -0
  110. data/sphinx/_build/html/monitoring_policies.html +530 -0
  111. data/sphinx/_build/html/objects.inv +0 -0
  112. data/sphinx/_build/html/private_networks.html +316 -0
  113. data/sphinx/_build/html/public_ips.html +215 -0
  114. data/sphinx/_build/html/rb-modindex.html +106 -0
  115. data/sphinx/_build/html/search.html +99 -0
  116. data/sphinx/_build/html/searchindex.js +1 -0
  117. data/sphinx/_build/html/server_appliances.html +153 -0
  118. data/sphinx/_build/html/servers.html +994 -0
  119. data/sphinx/_build/html/shared_storages.html +349 -0
  120. data/sphinx/_build/html/usages.html +140 -0
  121. data/sphinx/_build/html/users.html +363 -0
  122. data/sphinx/conf.py +287 -0
  123. data/sphinx/dvds.rst +42 -0
  124. data/sphinx/firewalls.rst +189 -0
  125. data/sphinx/images.rst +101 -0
  126. data/sphinx/index.rst +499 -0
  127. data/sphinx/load_balancers.rst +231 -0
  128. data/sphinx/logs.rst +55 -0
  129. data/sphinx/make.bat +263 -0
  130. data/sphinx/monitoring_center.rst +55 -0
  131. data/sphinx/monitoring_policies.rst +288 -0
  132. data/sphinx/private_networks.rst +146 -0
  133. data/sphinx/public_ips.rst +78 -0
  134. data/sphinx/server_appliances.rst +42 -0
  135. data/sphinx/servers.rst +630 -0
  136. data/sphinx/shared_storages.rst +160 -0
  137. data/sphinx/usages.rst +45 -0
  138. data/sphinx/users.rst +172 -0
  139. data/test/mock-api/add-firewall.json +66 -0
  140. data/test/mock-api/add-hdd.json +49 -0
  141. data/test/mock-api/add-lb.json +71 -0
  142. data/test/mock-api/add-new-ip.json +18 -0
  143. data/test/mock-api/add-pn.json +66 -0
  144. data/test/mock-api/add-port-mp.json +81 -0
  145. data/test/mock-api/add-process-mp.json +20 -0
  146. data/test/mock-api/add-rule-fp.json +33 -0
  147. data/test/mock-api/add-rule-lb.json +40 -0
  148. data/test/mock-api/add-server-ip.json +66 -0
  149. data/test/mock-api/add-server-mp.json +66 -0
  150. data/test/mock-api/assign-ip-fp.json +32 -0
  151. data/test/mock-api/assign-server-lb.json +39 -0
  152. data/test/mock-api/attach-server-pn.json +14 -0
  153. data/test/mock-api/attach-server-storage.json +24 -0
  154. data/test/mock-api/change-api-key.json +15 -0
  155. data/test/mock-api/change-password.json +5 -0
  156. data/test/mock-api/change-server-status.json +70 -0
  157. data/test/mock-api/clone-server.json +29 -0
  158. data/test/mock-api/create-fp.json +26 -0
  159. data/test/mock-api/create-image.json +30 -0
  160. data/test/mock-api/create-lb.json +33 -0
  161. data/test/mock-api/create-mp.json +81 -0
  162. data/test/mock-api/create-pn.json +11 -0
  163. data/test/mock-api/create-public-ip.json +10 -0
  164. data/test/mock-api/create-server.json +34 -0
  165. data/test/mock-api/create-snapshot.json +74 -0
  166. data/test/mock-api/create-storage.json +13 -0
  167. data/test/mock-api/create-user.json +14 -0
  168. data/test/mock-api/delete-fp.json +26 -0
  169. data/test/mock-api/delete-image.json +26 -0
  170. data/test/mock-api/delete-ip.json +15 -0
  171. data/test/mock-api/delete-lb.json +33 -0
  172. data/test/mock-api/delete-mp.json +71 -0
  173. data/test/mock-api/delete-pn.json +11 -0
  174. data/test/mock-api/delete-public-ip.json +10 -0
  175. data/test/mock-api/delete-rule-fp.json +26 -0
  176. data/test/mock-api/delete-server.json +50 -0
  177. data/test/mock-api/delete-snapshot.json +74 -0
  178. data/test/mock-api/delete-storage.json +24 -0
  179. data/test/mock-api/delete-user.json +15 -0
  180. data/test/mock-api/detach-server-lb.json +33 -0
  181. data/test/mock-api/detach-server-mp.json +65 -0
  182. data/test/mock-api/detach-server-storage.json +19 -0
  183. data/test/mock-api/edit-image.json +26 -0
  184. data/test/mock-api/eject-dvd.json +66 -0
  185. data/test/mock-api/fixed-server-flavors.json +70 -0
  186. data/test/mock-api/get-appliance.json +16 -0
  187. data/test/mock-api/get-dvd.json +9 -0
  188. data/test/mock-api/get-firewall.json +26 -0
  189. data/test/mock-api/get-fixed-server.json +17 -0
  190. data/test/mock-api/get-fp-rule.json +7 -0
  191. data/test/mock-api/get-hardware.json +13 -0
  192. data/test/mock-api/get-hdd.json +5 -0
  193. data/test/mock-api/get-image.json +26 -0
  194. data/test/mock-api/get-lb-rule.json +7 -0
  195. data/test/mock-api/get-lb-server.json +5 -0
  196. data/test/mock-api/get-load-balancer.json +33 -0
  197. data/test/mock-api/get-log.json +23 -0
  198. data/test/mock-api/get-monitoring-center.json +161 -0
  199. data/test/mock-api/get-mp-port.json +7 -0
  200. data/test/mock-api/get-mp-process.json +6 -0
  201. data/test/mock-api/get-mp-server.json +4 -0
  202. data/test/mock-api/get-mp.json +65 -0
  203. data/test/mock-api/get-pn-server.json +4 -0
  204. data/test/mock-api/get-private-network.json +20 -0
  205. data/test/mock-api/get-public-ip.json +10 -0
  206. data/test/mock-api/get-server-dvd.json +4 -0
  207. data/test/mock-api/get-server-image.json +4 -0
  208. data/test/mock-api/get-server-ip-fp.json +4 -0
  209. data/test/mock-api/get-server-ip.json +8 -0
  210. data/test/mock-api/get-server-pn.json +16 -0
  211. data/test/mock-api/get-server-status.json +4 -0
  212. data/test/mock-api/get-server-storage.json +5 -0
  213. data/test/mock-api/get-server.json +44 -0
  214. data/test/mock-api/get-storage.json +19 -0
  215. data/test/mock-api/get-usage.json +161 -0
  216. data/test/mock-api/get-user-api-key.json +3 -0
  217. data/test/mock-api/get-user-api.json +7 -0
  218. data/test/mock-api/get-user.json +15 -0
  219. data/test/mock-api/list-appliances.json +66 -0
  220. data/test/mock-api/list-credentials.json +5 -0
  221. data/test/mock-api/list-dvds.json +128 -0
  222. data/test/mock-api/list-firewalls.json +54 -0
  223. data/test/mock-api/list-fp-rules.json +16 -0
  224. data/test/mock-api/list-hdds.json +7 -0
  225. data/test/mock-api/list-images.json +54 -0
  226. data/test/mock-api/list-lb-rules.json +16 -0
  227. data/test/mock-api/list-lb-servers.json +12 -0
  228. data/test/mock-api/list-load-balancers.json +68 -0
  229. data/test/mock-api/list-logs.json +49 -0
  230. data/test/mock-api/list-monitoring-center-usages.json +90 -0
  231. data/test/mock-api/list-mp-ports.json +16 -0
  232. data/test/mock-api/list-mp-processes.json +14 -0
  233. data/test/mock-api/list-mp-servers.json +10 -0
  234. data/test/mock-api/list-mps.json +152 -0
  235. data/test/mock-api/list-pn-servers.json +10 -0
  236. data/test/mock-api/list-private-networks.json +24 -0
  237. data/test/mock-api/list-public-ips.json +44 -0
  238. data/test/mock-api/list-server-fps.json +4 -0
  239. data/test/mock-api/list-server-ips-fp.json +7 -0
  240. data/test/mock-api/list-server-ips.json +10 -0
  241. data/test/mock-api/list-server-lbs.json +6 -0
  242. data/test/mock-api/list-server-pns.json +6 -0
  243. data/test/mock-api/list-servers.json +66 -0
  244. data/test/mock-api/list-snapshots.json +7 -0
  245. data/test/mock-api/list-storages.json +47 -0
  246. data/test/mock-api/list-usages.json +144 -0
  247. data/test/mock-api/list-user-ips.json +5 -0
  248. data/test/mock-api/list-users.json +31 -0
  249. data/test/mock-api/load-dvd.json +63 -0
  250. data/test/mock-api/modify-fp.json +26 -0
  251. data/test/mock-api/modify-lb.json +33 -0
  252. data/test/mock-api/modify-mp.json +81 -0
  253. data/test/mock-api/modify-pn.json +20 -0
  254. data/test/mock-api/modify-port-mp.json +81 -0
  255. data/test/mock-api/modify-process-mp.json +73 -0
  256. data/test/mock-api/modify-public-ip.json +10 -0
  257. data/test/mock-api/modify-server-hardware.json +44 -0
  258. data/test/mock-api/modify-server-hdd.json +54 -0
  259. data/test/mock-api/modify-server.json +44 -0
  260. data/test/mock-api/modify-storage.json +19 -0
  261. data/test/mock-api/modify-user-api.json +15 -0
  262. data/test/mock-api/modify-user.json +15 -0
  263. data/test/mock-api/reinstall-image.json +52 -0
  264. data/test/mock-api/remove-firewall-policy.json +26 -0
  265. data/test/mock-api/remove-hdd.json +54 -0
  266. data/test/mock-api/remove-ip-fp.json +26 -0
  267. data/test/mock-api/remove-lb.json +66 -0
  268. data/test/mock-api/remove-pn.json +71 -0
  269. data/test/mock-api/remove-port-mp.json +73 -0
  270. data/test/mock-api/remove-process-mp.json +66 -0
  271. data/test/mock-api/remove-rule-lb.json +33 -0
  272. data/test/mock-api/remove-server-ip.json +58 -0
  273. data/test/mock-api/remove-server-pn.json +16 -0
  274. data/test/mock-api/restore-snapshot.json +55 -0
  275. data/test/mock-api/storage-servers.json +12 -0
  276. data/test/test_mock_dvd.rb +55 -0
  277. data/test/test_mock_firewall.rb +309 -0
  278. data/test/test_mock_image.rb +123 -0
  279. data/test/test_mock_load_balancer.rb +312 -0
  280. data/test/test_mock_log.rb +55 -0
  281. data/test/test_mock_monitoring_center.rb +55 -0
  282. data/test/test_mock_monitoring_policy.rb +587 -0
  283. data/test/test_mock_private_network.rb +206 -0
  284. data/test/test_mock_public_ip.rb +118 -0
  285. data/test/test_mock_server.rb +929 -0
  286. data/test/test_mock_server_appliance.rb +55 -0
  287. data/test/test_mock_shared_storage.rb +256 -0
  288. data/test/test_mock_usage.rb +34 -0
  289. data/test/test_mock_user.rb +270 -0
  290. metadata +360 -0
@@ -0,0 +1,231 @@
1
+ module OneAndOne
2
+
3
+
4
+ class Image
5
+
6
+
7
+ attr_accessor :id
8
+ attr_accessor :specs
9
+
10
+
11
+ def initialize(test: false)
12
+ @id = nil
13
+ @specs = nil
14
+
15
+ # Check if hitting mock api or live api
16
+ if test
17
+ @connection = Excon.new($base_url, :mock => true)
18
+ else
19
+ @connection = Excon.new($base_url)
20
+ end
21
+
22
+ end
23
+
24
+
25
+ def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
26
+
27
+ # Build hash for query parameters
28
+ keyword_args = {
29
+ :page => page,
30
+ :per_page => per_page,
31
+ :sort => sort,
32
+ :q => q,
33
+ :fields => fields
34
+ }
35
+
36
+ # Clean out null query parameters
37
+ params = OneAndOne.clean_hash(keyword_args)
38
+
39
+ # Build URL
40
+ path = OneAndOne.build_url('/images')
41
+
42
+ # Perform request
43
+ response = @connection.request(:method => :get,
44
+ :path => path,
45
+ :headers => $header,
46
+ :query => params)
47
+
48
+ # Check response status
49
+ OneAndOne.check_response(response.body, response.status)
50
+
51
+ #JSON-ify the response string
52
+ JSON.parse(response.body)
53
+
54
+ end
55
+
56
+
57
+ def get(image_id: @id)
58
+
59
+ # If user passed in image ID, reassign
60
+ @id = image_id
61
+
62
+ # Build URL
63
+ path = OneAndOne.build_url("/images/#{@id}")
64
+
65
+ # Perform request
66
+ response = @connection.request(:method => :get,
67
+ :path => path,
68
+ :headers => $header)
69
+
70
+ # Check response status
71
+ OneAndOne.check_response(response.body, response.status)
72
+
73
+ #JSON-ify the response string
74
+ json = JSON.parse(response.body)
75
+
76
+ # Reload specs attribute
77
+ @specs = json
78
+
79
+ # If all good, return JSON
80
+ json
81
+
82
+ end
83
+
84
+
85
+ def create(server_id: nil, name: nil, description: nil, frequency: nil,
86
+ num_images: nil)
87
+
88
+ # Build POST body
89
+ new_image = {
90
+ 'server_id' => server_id,
91
+ 'name' => name,
92
+ 'description' => description,
93
+ 'frequency' => frequency,
94
+ 'num_images' => num_images
95
+ }
96
+
97
+ # Clean out null keys in POST body
98
+ body = OneAndOne.clean_hash(new_image)
99
+
100
+ # Stringify the POST body
101
+ string_body = body.to_json
102
+
103
+ # Build URL
104
+ path = OneAndOne.build_url('/images')
105
+
106
+ # Perform request
107
+ response = @connection.request(:method => :post,
108
+ :path => path,
109
+ :headers => $header,
110
+ :body => string_body)
111
+
112
+ # Check response status
113
+ OneAndOne.check_response(response.body, response.status)
114
+
115
+ #JSON-ify the response string
116
+ json = JSON.parse(response.body)
117
+
118
+ # Save new image ID to Image instance
119
+ @id = json['id']
120
+ @specs = json
121
+
122
+ # If all good, return JSON
123
+ json
124
+
125
+ end
126
+
127
+
128
+ def modify(image_id: @id, name: nil, description: nil, frequency: nil)
129
+
130
+ # If user passed in image ID, reassign
131
+ @id = image_id
132
+
133
+ # Build PUT body
134
+ image_specs = {
135
+ 'name' => name,
136
+ 'description' => description,
137
+ 'frequency' => frequency
138
+ }
139
+
140
+ # Clean out null keys in PUT body
141
+ body = OneAndOne.clean_hash(image_specs)
142
+
143
+ # Stringify the PUT body
144
+ string_body = body.to_json
145
+
146
+ # Build URL
147
+ path = OneAndOne.build_url("/images/#{@id}")
148
+
149
+ # Perform Request
150
+ response = @connection.request(:method => :put,
151
+ :path => path,
152
+ :headers => $header,
153
+ :body => string_body)
154
+
155
+ # Check response status
156
+ OneAndOne.check_response(response.body, response.status)
157
+
158
+ #JSON-ify the response string
159
+ JSON.parse(response.body)
160
+
161
+ end
162
+
163
+
164
+ def delete(image_id: @id)
165
+
166
+ # If user passed in image ID, reassign
167
+ @id = image_id
168
+
169
+ # Build URL
170
+ path = OneAndOne.build_url("/images/#{@id}")
171
+
172
+ # Perform request
173
+ response = @connection.request(:method => :delete,
174
+ :path => path,
175
+ :headers => $header)
176
+
177
+ # Check response status
178
+ OneAndOne.check_response(response.body, response.status)
179
+
180
+ #JSON-ify the response string
181
+ JSON.parse(response.body)
182
+
183
+ end
184
+
185
+
186
+ def reload
187
+
188
+ # This reload fx is just a wrapper for the get fx
189
+ get
190
+
191
+ end
192
+
193
+
194
+ def wait_for(timeout: 25, interval: 15)
195
+
196
+ # Capture start time
197
+ start = Time.now
198
+
199
+ # Poll image and check initial state
200
+ initial_response = get
201
+ image_state = initial_response['state']
202
+
203
+ # Keep polling the image's state until good
204
+ until $good_states.include? image_state
205
+
206
+ # Wait 15 seconds before polling again
207
+ sleep interval
208
+
209
+ # Check image state again
210
+ current_response = get
211
+ image_state = current_response['state']
212
+
213
+ # Calculate current duration and check for timeout
214
+ duration = (Time.now - start) / 60
215
+ if duration > timeout
216
+ puts "The operation timed out after #{timeout} minutes.\n"
217
+ return
218
+ end
219
+
220
+ end
221
+
222
+ # Return Duration
223
+ {:duration => duration}
224
+
225
+ end
226
+
227
+
228
+ end
229
+
230
+
231
+ end
@@ -0,0 +1,448 @@
1
+ module OneAndOne
2
+
3
+
4
+ class LoadBalancer
5
+
6
+
7
+ attr_accessor :id
8
+ attr_accessor :specs
9
+
10
+
11
+ def initialize(test: false)
12
+ @id = nil
13
+ @specs = nil
14
+
15
+ # Check if hitting mock api or live api
16
+ if test
17
+ @connection = Excon.new($base_url, :mock => true)
18
+ else
19
+ @connection = Excon.new($base_url)
20
+ end
21
+
22
+ end
23
+
24
+
25
+ def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
26
+
27
+ # Build hash for query parameters
28
+ keyword_args = {
29
+ :page => page,
30
+ :per_page => per_page,
31
+ :sort => sort,
32
+ :q => q,
33
+ :fields => fields
34
+ }
35
+
36
+ # Clean out null query parameters
37
+ params = OneAndOne.clean_hash(keyword_args)
38
+
39
+ # Build URL
40
+ path = OneAndOne.build_url('/load_balancers')
41
+
42
+ # Perform request
43
+ response = @connection.request(:method => :get,
44
+ :path => path,
45
+ :headers => $header,
46
+ :query => params)
47
+
48
+ # Check response status
49
+ OneAndOne.check_response(response.body, response.status)
50
+
51
+ #JSON-ify the response string
52
+ JSON.parse(response.body)
53
+
54
+ end
55
+
56
+
57
+ def create(name: nil, description: nil, health_check_test: nil,
58
+ health_check_interval: nil, persistence: nil, persistence_time: nil,
59
+ method: nil, rules: nil, health_check_path: nil, health_check_parse: nil,
60
+ datacenter_id: nil)
61
+
62
+ # Build POST body
63
+ new_load_balancer = {
64
+ 'name' => name,
65
+ 'description' => description,
66
+ 'health_check_test' => health_check_test,
67
+ 'health_check_interval' => health_check_interval,
68
+ 'persistence' => persistence,
69
+ 'persistence_time' => persistence_time,
70
+ 'method' => method,
71
+ 'rules' => rules,
72
+ 'health_check_path' => health_check_path,
73
+ 'health_check_parse' => health_check_parse,
74
+ 'datacenter_id' => datacenter_id
75
+ }
76
+
77
+ # Clean out null keys in POST body
78
+ body = OneAndOne.clean_hash(new_load_balancer)
79
+
80
+ # Stringify the POST body
81
+ string_body = body.to_json
82
+
83
+ # Build URL
84
+ path = OneAndOne.build_url('/load_balancers')
85
+
86
+ # Perform request
87
+ response = @connection.request(:method => :post,
88
+ :path => path,
89
+ :headers => $header,
90
+ :body => string_body)
91
+
92
+ # Check response status
93
+ OneAndOne.check_response(response.body, response.status)
94
+
95
+ #JSON-ify the response string
96
+ json = JSON.parse(response.body)
97
+
98
+ # Save new load balancer ID to LoadBalancer instance
99
+ @id = json['id']
100
+ @specs = json
101
+
102
+ # If all good, return JSON
103
+ json
104
+
105
+ end
106
+
107
+
108
+ def get(load_balancer_id: @id)
109
+
110
+ # If user passed in load balancer ID, reassign
111
+ @id = load_balancer_id
112
+
113
+ # Build URL
114
+ path = OneAndOne.build_url("/load_balancers/#{@id}")
115
+
116
+ # Perform request
117
+ response = @connection.request(:method => :get,
118
+ :path => path,
119
+ :headers => $header)
120
+
121
+ # Check response status
122
+ OneAndOne.check_response(response.body, response.status)
123
+
124
+ #JSON-ify the response string
125
+ json = JSON.parse(response.body)
126
+
127
+ # Reload specs attribute
128
+ @specs = json
129
+
130
+ # If all good, return JSON
131
+ json
132
+
133
+ end
134
+
135
+
136
+ def modify(load_balancer_id: @id, name: nil, description: nil,
137
+ health_check_test: nil, health_check_interval: nil, persistence: nil,
138
+ persistence_time: nil, method: nil, health_check_path: nil,
139
+ health_check_parse: nil)
140
+
141
+ # If user passed in load balancer ID, reassign
142
+ @id = load_balancer_id
143
+
144
+ # Build PUT body
145
+ new_load_balancer = {
146
+ 'name' => name,
147
+ 'description' => description,
148
+ 'health_check_test' => health_check_test,
149
+ 'health_check_interval' => health_check_interval,
150
+ 'persistence' => persistence,
151
+ 'persistence_time' => persistence_time,
152
+ 'method' => method,
153
+ 'health_check_path' => health_check_path,
154
+ 'health_check_parse' => health_check_parse
155
+ }
156
+
157
+ # Clean out null keys in PUT body
158
+ body = OneAndOne.clean_hash(new_load_balancer)
159
+
160
+ # Stringify the POST body
161
+ string_body = body.to_json
162
+
163
+ # Build URL
164
+ path = OneAndOne.build_url("/load_balancers/#{@id}")
165
+
166
+ # Perform request
167
+ response = @connection.request(:method => :put,
168
+ :path => path,
169
+ :headers => $header,
170
+ :body => string_body)
171
+
172
+ # Check response status
173
+ OneAndOne.check_response(response.body, response.status)
174
+
175
+ #JSON-ify the response string
176
+ JSON.parse(response.body)
177
+
178
+ end
179
+
180
+
181
+ def delete(load_balancer_id: @id)
182
+
183
+ # If user passed in load balancer ID, reassign
184
+ @id = load_balancer_id
185
+
186
+ # Build URL
187
+ path = OneAndOne.build_url("/load_balancers/#{@id}")
188
+
189
+ # Perform request
190
+ response = @connection.request(:method => :delete,
191
+ :path => path,
192
+ :headers => $header)
193
+
194
+ # Check response status
195
+ OneAndOne.check_response(response.body, response.status)
196
+
197
+ #JSON-ify the response string
198
+ JSON.parse(response.body)
199
+
200
+ end
201
+
202
+
203
+ def ips(load_balancer_id: @id)
204
+
205
+ # If user passed in load balancer ID, reassign
206
+ @id = load_balancer_id
207
+
208
+ # Build URL
209
+ path = OneAndOne.build_url("/load_balancers/#{@id}/server_ips")
210
+
211
+ # Perform request
212
+ response = @connection.request(:method => :get,
213
+ :path => path,
214
+ :headers => $header)
215
+
216
+ # Check response status
217
+ OneAndOne.check_response(response.body, response.status)
218
+
219
+ #JSON-ify the response string
220
+ JSON.parse(response.body)
221
+
222
+ end
223
+
224
+
225
+ def ip(load_balancer_id: @id, ip_id: nil)
226
+
227
+ # If user passed in load balancer ID, reassign
228
+ @id = load_balancer_id
229
+
230
+ # Build URL
231
+ path = OneAndOne.build_url("/load_balancers/#{@id}/server_ips/#{ip_id}")
232
+
233
+ # Perform request
234
+ response = @connection.request(:method => :get,
235
+ :path => path,
236
+ :headers => $header)
237
+
238
+ # Check response status
239
+ OneAndOne.check_response(response.body, response.status)
240
+
241
+ #JSON-ify the response string
242
+ JSON.parse(response.body)
243
+
244
+ end
245
+
246
+
247
+ def remove_ip(load_balancer_id: @id, ip_id: nil)
248
+
249
+ # If user passed in load balancer ID, reassign
250
+ @id = load_balancer_id
251
+
252
+ # Build URL
253
+ path = OneAndOne.build_url("/load_balancers/#{@id}/server_ips/#{ip_id}")
254
+
255
+ # Perform request
256
+ response = @connection.request(:method => :delete,
257
+ :path => path,
258
+ :headers => $header)
259
+
260
+ # Check response status
261
+ OneAndOne.check_response(response.body, response.status)
262
+
263
+ #JSON-ify the response string
264
+ JSON.parse(response.body)
265
+
266
+ end
267
+
268
+
269
+ def add_ips(load_balancer_id: @id, ips: nil)
270
+
271
+ # If user passed in load balancer ID, reassign
272
+ @id = load_balancer_id
273
+
274
+ # Build POST body
275
+ new_ips = {
276
+ 'server_ips' => ips
277
+ }
278
+
279
+ # Clean out null keys in POST body
280
+ body = OneAndOne.clean_hash(new_ips)
281
+
282
+ # Stringify the POST body
283
+ string_body = body.to_json
284
+
285
+ # Build URL
286
+ path = OneAndOne.build_url("/load_balancers/#{@id}/server_ips")
287
+
288
+ # Perform request
289
+ response = @connection.request(:method => :post,
290
+ :path => path,
291
+ :headers => $header,
292
+ :body => string_body)
293
+
294
+ # Check response status
295
+ OneAndOne.check_response(response.body, response.status)
296
+
297
+ #JSON-ify the response string
298
+ JSON.parse(response.body)
299
+
300
+ end
301
+
302
+
303
+ def rules(load_balancer_id: @id)
304
+
305
+ # If user passed in load balancer ID, reassign
306
+ @id = load_balancer_id
307
+
308
+ # Build URL
309
+ path = OneAndOne.build_url("/load_balancers/#{@id}/rules")
310
+
311
+ # Perform request
312
+ response = @connection.request(:method => :get,
313
+ :path => path,
314
+ :headers => $header)
315
+
316
+ # Check response status
317
+ OneAndOne.check_response(response.body, response.status)
318
+
319
+ #JSON-ify the response string
320
+ JSON.parse(response.body)
321
+
322
+ end
323
+
324
+
325
+ def rule(load_balancer_id: @id, rule_id: nil)
326
+
327
+ # If user passed in load balancer ID, reassign
328
+ @id = load_balancer_id
329
+
330
+ # Build URL
331
+ path = OneAndOne.build_url("/load_balancers/#{@id}/rules/#{rule_id}")
332
+
333
+ # Perform request
334
+ response = @connection.request(:method => :get,
335
+ :path => path,
336
+ :headers => $header)
337
+
338
+ # Check response status
339
+ OneAndOne.check_response(response.body, response.status)
340
+
341
+ #JSON-ify the response string
342
+ JSON.parse(response.body)
343
+
344
+ end
345
+
346
+
347
+ def add_rules(load_balancer_id: @id, rules: nil)
348
+
349
+ # If user passed in load balancer ID, reassign
350
+ @id = load_balancer_id
351
+
352
+ # Build POST body
353
+ new_rules = {
354
+ 'rules' => rules
355
+ }
356
+
357
+ # Clean out null keys in POST body
358
+ body = OneAndOne.clean_hash(new_rules)
359
+
360
+ # Stringify the POST body
361
+ string_body = body.to_json
362
+
363
+ # Build URL
364
+ path = OneAndOne.build_url("/load_balancers/#{@id}/rules")
365
+
366
+ # Perform request
367
+ response = @connection.request(:method => :post,
368
+ :path => path,
369
+ :headers => $header,
370
+ :body => string_body)
371
+
372
+ # Check response status
373
+ OneAndOne.check_response(response.body, response.status)
374
+
375
+ #JSON-ify the response string
376
+ JSON.parse(response.body)
377
+
378
+ end
379
+
380
+
381
+ def remove_rule(load_balancer_id: @id, rule_id: nil)
382
+
383
+ # If user passed in load balancer ID, reassign
384
+ @id = load_balancer_id
385
+
386
+ # Build URL
387
+ path = OneAndOne.build_url("/load_balancers/#{@id}/rules/#{rule_id}")
388
+
389
+ # Perform request
390
+ response = @connection.request(:method => :delete,
391
+ :path => path,
392
+ :headers => $header)
393
+
394
+ # Check response status
395
+ OneAndOne.check_response(response.body, response.status)
396
+
397
+ #JSON-ify the response string
398
+ JSON.parse(response.body)
399
+
400
+ end
401
+
402
+
403
+ def reload
404
+
405
+ # This reload fx is just a wrapper for the get fx
406
+ get
407
+
408
+ end
409
+
410
+
411
+ def wait_for(timeout: 25, interval: 5)
412
+
413
+ # Capture start time
414
+ start = Time.now
415
+
416
+ # Poll load balancer and check initial state
417
+ initial_response = get
418
+ load_balancer_state = initial_response['state']
419
+
420
+ # Keep polling the load balancer's state until good
421
+ until $good_states.include? load_balancer_state
422
+
423
+ # Wait 5 seconds before polling again
424
+ sleep interval
425
+
426
+ # Check load balancer state again
427
+ current_response = get
428
+ load_balancer_state = current_response['state']
429
+
430
+ # Calculate current duration and check for timeout
431
+ duration = (Time.now - start) / 60
432
+ if duration > timeout
433
+ puts "The operation timed out after #{timeout} minutes.\n"
434
+ return
435
+ end
436
+
437
+ end
438
+
439
+ # Return Duration
440
+ {:duration => duration}
441
+
442
+ end
443
+
444
+
445
+ end
446
+
447
+
448
+ end