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,206 @@
1
+ require_relative '../lib/oneandone'
2
+ require 'minitest/autorun'
3
+
4
+ class TestPrivateNetwork < Minitest::Test
5
+ def setup
6
+
7
+ OneAndOne.start('TEST-API-KEY')
8
+ @private_network = OneAndOne::PrivateNetwork.new(test: true)
9
+
10
+ end
11
+
12
+
13
+ def test_list
14
+
15
+ # Read in mock JSON
16
+ file = File.read('mock-api/list-private-networks.json')
17
+ data = JSON.parse(file)
18
+
19
+ # Create stub and perform call
20
+ Excon.stub({:method => :get, :path => '/v1/private_networks'},
21
+ {:body => JSON.generate(data), :status => 200})
22
+
23
+ response = @private_network.list
24
+
25
+ # Assertions
26
+ assert_equal response[0]['id'], data[0]['id']
27
+
28
+ # Clear out stubs
29
+ Excon.stubs.clear
30
+
31
+ end
32
+
33
+
34
+ def test_create
35
+
36
+ # Read in mock JSON
37
+ file = File.read('mock-api/create-pn.json')
38
+ data = JSON.parse(file)
39
+
40
+ # Create stub and perform call
41
+ Excon.stub({:method => :post, :path => '/v1/private_networks'},
42
+ {:body => JSON.generate(data), :status => 202})
43
+
44
+ response = @private_network.create(name: data['name'])
45
+
46
+ # Assertions
47
+ assert_equal response['name'], data['name']
48
+
49
+ # Clear out stubs
50
+ Excon.stubs.clear
51
+
52
+ end
53
+
54
+
55
+ def test_get
56
+
57
+ # Read in mock JSON
58
+ file = File.read('mock-api/get-private-network.json')
59
+ data = JSON.parse(file)
60
+
61
+ # Create stub and perform call
62
+ Excon.stub({:method => :get, :path => "/v1/private_networks/#{data['id']}"},
63
+ {:body => JSON.generate(data), :status => 200})
64
+
65
+ response = @private_network.get(private_network_id: data['id'])
66
+
67
+ # Assertions
68
+ assert_equal response['id'], data['id']
69
+
70
+ # Clear out stubs
71
+ Excon.stubs.clear
72
+
73
+ end
74
+
75
+
76
+ def test_modify
77
+
78
+ # Read in mock JSON
79
+ file = File.read('mock-api/modify-pn.json')
80
+ data = JSON.parse(file)
81
+
82
+ # Create stub and perform call
83
+ Excon.stub({:method => :put, :path => "/v1/private_networks/#{data['id']}"},
84
+ {:body => JSON.generate(data), :status => 202})
85
+
86
+ response = @private_network.modify(private_network_id: data['id'], name: 'New Name')
87
+
88
+ # Assertions
89
+ assert_equal response['name'], data['name']
90
+
91
+ # Clear out stubs
92
+ Excon.stubs.clear
93
+
94
+ end
95
+
96
+
97
+ def test_delete
98
+
99
+ # Read in mock JSON
100
+ file = File.read('mock-api/delete-pn.json')
101
+ data = JSON.parse(file)
102
+
103
+ # Create stub and perform call
104
+ Excon.stub({:method => :delete, :path => "/v1/private_networks/#{data['id']}"},
105
+ {:body => JSON.generate(data), :status => 202})
106
+
107
+ response = @private_network.delete(private_network_id: data['id'])
108
+
109
+ # Assertions
110
+ assert_equal response['state'], 'REMOVING'
111
+
112
+ # Clear out stubs
113
+ Excon.stubs.clear
114
+
115
+ end
116
+
117
+
118
+ def test_servers
119
+
120
+ # Read in mock JSON
121
+ file = File.read('mock-api/list-pn-servers.json')
122
+ data = JSON.parse(file)
123
+
124
+ # Create stub and perform call
125
+ Excon.stub({:method => :get, :path => "/v1/private_networks/PN-ID/servers"},
126
+ {:body => JSON.generate(data), :status => 200})
127
+
128
+ response = @private_network.servers(private_network_id: 'PN-ID')
129
+
130
+ # Assertions
131
+ assert_equal response.length, 2
132
+
133
+ # Clear out stubs
134
+ Excon.stubs.clear
135
+
136
+ end
137
+
138
+
139
+ def test_server
140
+
141
+ # Read in mock JSON
142
+ file = File.read('mock-api/get-pn-server.json')
143
+ data = JSON.parse(file)
144
+
145
+ # Create stub and perform call
146
+ Excon.stub({:method => :get, :path => "/v1/private_networks/PN-ID/servers/#{data['id']}"},
147
+ {:body => JSON.generate(data), :status => 200})
148
+
149
+ response = @private_network.server(private_network_id: 'PN-ID', server_id: data['id'])
150
+
151
+ # Assertions
152
+ assert_equal response['id'], data['id']
153
+
154
+ # Clear out stubs
155
+ Excon.stubs.clear
156
+
157
+ end
158
+
159
+
160
+ def test_remove_server
161
+
162
+ # Read in mock JSON
163
+ file = File.read('mock-api/remove-server-pn.json')
164
+ data = JSON.parse(file)
165
+
166
+ # Create stub and perform call
167
+ Excon.stub({:method => :delete, :path => "/v1/private_networks/#{data['id']}/servers/SERVER-ID"},
168
+ {:body => JSON.generate(data), :status => 200})
169
+
170
+ response = @private_network.remove_server(private_network_id: data['id'], server_id: 'SERVER-ID')
171
+
172
+ # Assertions
173
+ assert_equal response['state'], 'CONFIGURING'
174
+
175
+ # Clear out stubs
176
+ Excon.stubs.clear
177
+
178
+ end
179
+
180
+
181
+ def test_add_servers
182
+
183
+ # Read in mock JSON
184
+ file = File.read('mock-api/attach-server-pn.json')
185
+ data = JSON.parse(file)
186
+
187
+ # Create stub and perform call
188
+ Excon.stub({:method => :post, :path => "/v1/private_networks/PN-ID/servers"},
189
+ {:body => JSON.generate(data), :status => 202})
190
+
191
+ server1 = '<SERVER-ID>'
192
+
193
+ servers = [server1]
194
+
195
+ response = @private_network.add_servers(private_network_id: 'PN-ID', servers: servers)
196
+
197
+ # Assertions
198
+ assert_equal response[0]['name'], data[0]['name']
199
+
200
+ # Clear out stubs
201
+ Excon.stubs.clear
202
+
203
+ end
204
+
205
+
206
+ end
@@ -0,0 +1,118 @@
1
+ require_relative '../lib/oneandone'
2
+ require 'minitest/autorun'
3
+
4
+ class TestPublicIP < Minitest::Test
5
+ def setup
6
+
7
+ OneAndOne.start('TEST-API-KEY')
8
+ @public_ip = OneAndOne::PublicIP.new(test: true)
9
+
10
+ end
11
+
12
+
13
+ def test_list
14
+
15
+ # Read in mock JSON
16
+ file = File.read('mock-api/list-public-ips.json')
17
+ data = JSON.parse(file)
18
+
19
+ # Create stub and perform call
20
+ Excon.stub({:method => :get, :path => '/v1/public_ips'},
21
+ {:body => JSON.generate(data), :status => 200})
22
+
23
+ response = @public_ip.list
24
+
25
+ # Assertions
26
+ assert_equal response[0]['id'], data[0]['id']
27
+
28
+ # Clear out stubs
29
+ Excon.stubs.clear
30
+
31
+ end
32
+
33
+
34
+ def test_create
35
+
36
+ # Read in mock JSON
37
+ file = File.read('mock-api/create-public-ip.json')
38
+ data = JSON.parse(file)
39
+
40
+ # Create stub and perform call
41
+ Excon.stub({:method => :post, :path => '/v1/public_ips'},
42
+ {:body => JSON.generate(data), :status => 202})
43
+
44
+ response = @public_ip.create(reverse_dns: data['reverse_dns'])
45
+
46
+ # Assertions
47
+ assert_equal response['reverse_dns'], 'example.com'
48
+
49
+ # Clear out stubs
50
+ Excon.stubs.clear
51
+
52
+ end
53
+
54
+
55
+ def test_get
56
+
57
+ # Read in mock JSON
58
+ file = File.read('mock-api/get-public-ip.json')
59
+ data = JSON.parse(file)
60
+
61
+ # Create stub and perform call
62
+ Excon.stub({:method => :get, :path => "/v1/public_ips/#{data['id']}"},
63
+ {:body => JSON.generate(data), :status => 200})
64
+
65
+ response = @public_ip.get(ip_id: data['id'])
66
+
67
+ # Assertions
68
+ assert_equal response['id'], data['id']
69
+
70
+ # Clear out stubs
71
+ Excon.stubs.clear
72
+
73
+ end
74
+
75
+
76
+ def test_modify
77
+
78
+ # Read in mock JSON
79
+ file = File.read('mock-api/modify-public-ip.json')
80
+ data = JSON.parse(file)
81
+
82
+ # Create stub and perform call
83
+ Excon.stub({:method => :put, :path => "/v1/public_ips/#{data['id']}"},
84
+ {:body => JSON.generate(data), :status => 202})
85
+
86
+ response = @public_ip.modify(ip_id: data['id'], reverse_dns: 'example.es')
87
+
88
+ # Assertions
89
+ assert_equal response['reverse_dns'], 'example.es'
90
+
91
+ # Clear out stubs
92
+ Excon.stubs.clear
93
+
94
+ end
95
+
96
+
97
+ def test_delete
98
+
99
+ # Read in mock JSON
100
+ file = File.read('mock-api/delete-public-ip.json')
101
+ data = JSON.parse(file)
102
+
103
+ # Create stub and perform call
104
+ Excon.stub({:method => :delete, :path => "/v1/public_ips/#{data['id']}"},
105
+ {:body => JSON.generate(data), :status => 202})
106
+
107
+ response = @public_ip.delete(ip_id: data['id'])
108
+
109
+ # Assertions
110
+ assert_equal response['state'], 'CONFIGURING'
111
+
112
+ # Clear out stubs
113
+ Excon.stubs.clear
114
+
115
+ end
116
+
117
+
118
+ end
@@ -0,0 +1,929 @@
1
+ require_relative '../lib/oneandone'
2
+ require 'minitest/autorun'
3
+
4
+ class TestServer < Minitest::Test
5
+ def setup
6
+
7
+ OneAndOne.start('TEST-API-KEY')
8
+ @server = OneAndOne::Server.new(test: true)
9
+
10
+ end
11
+
12
+
13
+ def test_list
14
+
15
+ # Read in mock JSON
16
+ file = File.read('mock-api/list-servers.json')
17
+ data = JSON.parse(file)
18
+
19
+ # Create stub and perform call
20
+ Excon.stub({:method => :get, :path => '/v1/servers'},
21
+ {:body => JSON.generate(data), :status => 200})
22
+
23
+ response = @server.list
24
+
25
+ # Assertions
26
+ assert_equal response[0]['id'], data[0]['id']
27
+
28
+ # Clear out stubs
29
+ Excon.stubs.clear
30
+
31
+ end
32
+
33
+
34
+ def test_create
35
+
36
+ # Read in mock JSON
37
+ file = File.read('mock-api/create-server.json')
38
+ data = JSON.parse(file)
39
+
40
+ # Create stub and perform call
41
+ Excon.stub({:method => :post, :path => '/v1/servers'},
42
+ {:body => JSON.generate(data), :status => 202})
43
+
44
+ hdd1 = {
45
+ 'size' => 120,
46
+ 'is_main' => true
47
+ }
48
+
49
+ hdds = [hdd1]
50
+
51
+ response = @server.create(name: 'My server', vcore: 1,
52
+ cores_per_processor: 1, ram: 1, appliance_id: '<IMAGE-ID>', hdds: hdds,
53
+ datacenter_id: 'D0F6D8C8ED29D3036F94C27BBB7BAD36', rsa_key: '<PUB-KEY>')
54
+
55
+ # Assertions
56
+ assert_equal response['name'], 'My server'
57
+ assert_equal response['datacenter']['country_code'], 'US'
58
+
59
+ # Clear out stubs
60
+ Excon.stubs.clear
61
+
62
+ end
63
+
64
+
65
+ def test_list_fixed
66
+
67
+ # Read in mock JSON
68
+ file = File.read('mock-api/fixed-server-flavors.json')
69
+ data = JSON.parse(file)
70
+
71
+ # Create stub and perform call
72
+ Excon.stub({:method => :get, :path => '/v1/servers/fixed_instance_sizes'},
73
+ {:body => JSON.generate(data), :status => 200})
74
+
75
+ response = @server.list_fixed
76
+
77
+ # Assertions
78
+ assert_equal response[0]['id'], data[0]['id']
79
+
80
+ # Clear out stubs
81
+ Excon.stubs.clear
82
+
83
+ end
84
+
85
+
86
+ def test_get_fixed
87
+
88
+ # Read in mock JSON
89
+ file = File.read('mock-api/get-fixed-server.json')
90
+ data = JSON.parse(file)
91
+
92
+ # Create stub and perform call
93
+ Excon.stub({:method => :get,
94
+ :path => "/v1/servers/fixed_instance_sizes/#{data['id']}"},
95
+ {:body => JSON.generate(data), :status => 200})
96
+
97
+ response = @server.get_fixed(fixed_instance_id: data['id'])
98
+
99
+ # Assertions
100
+ assert_equal response['id'], data['id']
101
+
102
+ # Clear out stubs
103
+ Excon.stubs.clear
104
+
105
+ end
106
+
107
+
108
+ def test_get
109
+
110
+ # Read in mock JSON
111
+ file = File.read('mock-api/get-server.json')
112
+ data = JSON.parse(file)
113
+
114
+ # Create stub and perform call
115
+ Excon.stub({:method => :get,
116
+ :path => "/v1/servers/#{data['id']}"},
117
+ {:body => JSON.generate(data), :status => 200})
118
+
119
+ response = @server.get(server_id: data['id'])
120
+
121
+ # Assertions
122
+ assert_equal response['id'], data['id']
123
+
124
+ # Clear out stubs
125
+ Excon.stubs.clear
126
+
127
+ end
128
+
129
+
130
+ def test_modify
131
+
132
+ # Read in mock JSON
133
+ file = File.read('mock-api/modify-server.json')
134
+ data = JSON.parse(file)
135
+
136
+ # Create stub and perform call
137
+ Excon.stub({:method => :put, :path => "/v1/servers/#{data['id']}"},
138
+ {:body => JSON.generate(data), :status => 200})
139
+
140
+ response = @server.modify(server_id: data['id'], name: data['name'])
141
+
142
+ # Assertions
143
+ assert_equal response['name'], data['name']
144
+
145
+ # Clear out stubs
146
+ Excon.stubs.clear
147
+
148
+ end
149
+
150
+
151
+ def test_delete
152
+
153
+ # Read in mock JSON
154
+ file = File.read('mock-api/delete-server.json')
155
+ data = JSON.parse(file)
156
+
157
+ # Create stub and perform call
158
+ Excon.stub({:method => :delete, :path => "/v1/servers/#{data['id']}"},
159
+ {:body => JSON.generate(data), :status => 202})
160
+
161
+ response = @server.delete(server_id: data['id'])
162
+
163
+ # Assertions
164
+ assert_equal response['name'], data['name']
165
+ assert_equal response['status']['state'], 'REMOVING'
166
+
167
+ # Clear out stubs
168
+ Excon.stubs.clear
169
+
170
+ end
171
+
172
+
173
+ def test_hardware
174
+
175
+ # Read in mock JSON
176
+ file = File.read('mock-api/get-hardware.json')
177
+ data = JSON.parse(file)
178
+
179
+ # Create stub and perform call
180
+ Excon.stub({:method => :get,
181
+ :path => "/v1/servers/#{data['id']}/hardware"},
182
+ {:body => JSON.generate(data), :status => 200})
183
+
184
+ response = @server.hardware(server_id: data['id'])
185
+
186
+ # Assertions
187
+ assert_equal response['id'], data['id']
188
+ assert_equal response['vcore'], 1
189
+
190
+ # Clear out stubs
191
+ Excon.stubs.clear
192
+
193
+ end
194
+
195
+
196
+ def test_modify_hardware
197
+
198
+ # Read in mock JSON
199
+ file = File.read('mock-api/modify-server-hardware.json')
200
+ data = JSON.parse(file)
201
+
202
+ # Create stub and perform call
203
+ Excon.stub({:method => :put, :path => "/v1/servers/#{data['id']}/hardware"},
204
+ {:body => JSON.generate(data), :status => 202})
205
+
206
+ response = @server.modify_hardware(server_id: data['id'],
207
+ vcore: data['hardware']['vcore'])
208
+
209
+ # Assertions
210
+ assert_equal response['hardware']['vcore'], data['hardware']['vcore']
211
+
212
+ # Clear out stubs
213
+ Excon.stubs.clear
214
+
215
+ end
216
+
217
+
218
+ def test_hdds
219
+
220
+ # Read in mock JSON
221
+ file = File.read('mock-api/list-hdds.json')
222
+ data = JSON.parse(file)
223
+
224
+ # Create stub and perform call
225
+ Excon.stub({:method => :get,
226
+ :path => "/v1/servers/SERVER-ID/hardware/hdds"},
227
+ {:body => JSON.generate(data), :status => 200})
228
+
229
+ response = @server.hdds(server_id: 'SERVER-ID')
230
+
231
+ # Assertions
232
+ assert_equal response[0]['id'], data[0]['id']
233
+
234
+ # Clear out stubs
235
+ Excon.stubs.clear
236
+
237
+ end
238
+
239
+
240
+ def test_add_hdds
241
+
242
+ # Read in mock JSON
243
+ file = File.read('mock-api/add-hdd.json')
244
+ data = JSON.parse(file)
245
+
246
+ # Create stub and perform call
247
+ Excon.stub({:method => :post,
248
+ :path => "/v1/servers/#{data['id']}/hardware/hdds"},
249
+ {:body => JSON.generate(data), :status => 202})
250
+
251
+ hdd2 = {
252
+ 'size' => 20,
253
+ 'is_main' => false
254
+ }
255
+
256
+ hdds = [hdd2]
257
+
258
+ response = @server.add_hdds(server_id: data['id'], hdds: hdds)
259
+
260
+ # Assertions
261
+ assert_equal response['hardware']['hdds'][1]['size'], 20
262
+
263
+ # Clear out stubs
264
+ Excon.stubs.clear
265
+
266
+ end
267
+
268
+
269
+ def test_get_hdd
270
+
271
+ # Read in mock JSON
272
+ file = File.read('mock-api/get-hdd.json')
273
+ data = JSON.parse(file)
274
+
275
+ # Create stub and perform call
276
+ Excon.stub({:method => :get,
277
+ :path => "/v1/servers/SERVER-ID/hardware/hdds/#{data['id']}"},
278
+ {:body => JSON.generate(data), :status => 200})
279
+
280
+ response = @server.get_hdd(server_id: 'SERVER-ID', hdd_id: data['id'])
281
+
282
+ # Assertions
283
+ assert_equal response['id'], data['id']
284
+
285
+ # Clear out stubs
286
+ Excon.stubs.clear
287
+
288
+ end
289
+
290
+
291
+ def test_modify_hdd
292
+
293
+ # Read in mock JSON
294
+ file = File.read('mock-api/modify-server-hdd.json')
295
+ data = JSON.parse(file)
296
+
297
+ # Create stub and perform call
298
+ Excon.stub({:method => :put,
299
+ :path => "/v1/servers/#{data['id']}/hardware/hdds/#{data['hardware']['hdds'][1]['id']}"},
300
+ {:body => JSON.generate(data), :status => 202})
301
+
302
+ response = @server.modify_hdd(server_id: data['id'],
303
+ hdd_id: data['hardware']['hdds'][1]['id'], size: 20)
304
+
305
+ # Assertions
306
+ assert_equal response['hardware']['hdds'][1]['size'], 20
307
+
308
+ # Clear out stubs
309
+ Excon.stubs.clear
310
+
311
+ end
312
+
313
+
314
+ def test_delete_hdd
315
+
316
+ # Read in mock JSON
317
+ file = File.read('mock-api/remove-hdd.json')
318
+ data = JSON.parse(file)
319
+
320
+ # Create stub and perform call
321
+ Excon.stub({:method => :delete,
322
+ :path => "/v1/servers/#{data['id']}/hardware/hdds/#{data['hardware']['hdds'][1]['id']}"},
323
+ {:body => JSON.generate(data), :status => 202})
324
+
325
+ response = @server.delete_hdd(server_id: data['id'],
326
+ hdd_id: data['hardware']['hdds'][1]['id'])
327
+
328
+ # Assertions
329
+ assert_equal response['status']['state'], 'CONFIGURING'
330
+
331
+ # Clear out stubs
332
+ Excon.stubs.clear
333
+
334
+ end
335
+
336
+
337
+ def test_image
338
+
339
+ # Read in mock JSON
340
+ file = File.read('mock-api/get-server-image.json')
341
+ data = JSON.parse(file)
342
+
343
+ # Create stub and perform call
344
+ Excon.stub({:method => :get,
345
+ :path => "/v1/servers/SERVER-ID/image"},
346
+ {:body => JSON.generate(data), :status => 200})
347
+
348
+ response = @server.image(server_id: 'SERVER-ID')
349
+
350
+ # Assertions
351
+ assert_equal response['name'], 'centos7-64std'
352
+
353
+ # Clear out stubs
354
+ Excon.stubs.clear
355
+
356
+ end
357
+
358
+
359
+ def test_install_image
360
+
361
+ # Read in mock JSON
362
+ file = File.read('mock-api/reinstall-image.json')
363
+ data = JSON.parse(file)
364
+
365
+ # Create stub and perform call
366
+ Excon.stub({:method => :put,
367
+ :path => "/v1/servers/#{data['id']}/image"},
368
+ {:body => JSON.generate(data), :status => 202})
369
+
370
+ response = @server.install_image(server_id: data['id'],
371
+ image_id: data['image']['id'])
372
+
373
+ # Assertions
374
+ assert_equal response['image']['name'], 'centos7-64std'
375
+
376
+ # Clear out stubs
377
+ Excon.stubs.clear
378
+
379
+ end
380
+
381
+
382
+ def test_ips
383
+
384
+ # Read in mock JSON
385
+ file = File.read('mock-api/list-server-ips.json')
386
+ data = JSON.parse(file)
387
+
388
+ # Create stub and perform call
389
+ Excon.stub({:method => :get,
390
+ :path => "/v1/servers/SERVER-ID/ips"},
391
+ {:body => JSON.generate(data), :status => 200})
392
+
393
+ response = @server.ips(server_id: 'SERVER-ID')
394
+
395
+ # Assertions
396
+ assert_equal response[0]['ip'], '10.5.135.140'
397
+
398
+ # Clear out stubs
399
+ Excon.stubs.clear
400
+
401
+ end
402
+
403
+
404
+ def test_add_ip
405
+
406
+ # Read in mock JSON
407
+ file = File.read('mock-api/add-server-ip.json')
408
+ data = JSON.parse(file)
409
+
410
+ # Create stub and perform call
411
+ Excon.stub({:method => :post,
412
+ :path => "/v1/servers/#{data['id']}/ips"},
413
+ {:body => JSON.generate(data), :status => 201})
414
+
415
+ response = @server.add_ip(server_id: data['id'])
416
+
417
+ # Assertions
418
+ assert_equal response['ips'][1]['ip'], '10.4.141.161'
419
+
420
+ # Clear out stubs
421
+ Excon.stubs.clear
422
+
423
+ end
424
+
425
+
426
+ def test_ip
427
+
428
+ # Read in mock JSON
429
+ file = File.read('mock-api/get-server-ip.json')
430
+ data = JSON.parse(file)
431
+
432
+ # Create stub and perform call
433
+ Excon.stub({:method => :get,
434
+ :path => "/v1/servers/SERVER-ID/ips/#{data['id']}"},
435
+ {:body => JSON.generate(data), :status => 200})
436
+
437
+ response = @server.ip(server_id: 'SERVER-ID', ip_id: data['id'])
438
+
439
+ # Assertions
440
+ assert_equal response['id'], data['id']
441
+
442
+ # Clear out stubs
443
+ Excon.stubs.clear
444
+
445
+ end
446
+
447
+
448
+ def test_release_ip
449
+
450
+ # Read in mock JSON
451
+ file = File.read('mock-api/remove-server-ip.json')
452
+ data = JSON.parse(file)
453
+
454
+ # Create stub and perform call
455
+ Excon.stub({:method => :delete,
456
+ :path => "/v1/servers/#{data['id']}/ips/#{data['ips'][0]['id']}"},
457
+ {:body => JSON.generate(data), :status => 202})
458
+
459
+ response = @server.release_ip(server_id: data['id'],
460
+ ip_id: data['ips'][0]['id'])
461
+
462
+ # Assertions
463
+ assert_equal response['ips'][0]['id'], data['ips'][0]['id']
464
+
465
+ # Clear out stubs
466
+ Excon.stubs.clear
467
+
468
+ end
469
+
470
+
471
+ def test_add_firewall
472
+
473
+ # Read in mock JSON
474
+ file = File.read('mock-api/add-firewall.json')
475
+ data = JSON.parse(file)
476
+
477
+ # Create stub and perform call
478
+ Excon.stub({:method => :put,
479
+ :path => "/v1/servers/#{data['id']}/ips/#{data['ips'][0]['id']}/firewall_policy"},
480
+ {:body => JSON.generate(data), :status => 202})
481
+
482
+ response = @server.add_firewall(server_id: data['id'],
483
+ ip_id: data['ips'][0]['id'],
484
+ firewall_id: data['ips'][0]['firewall_policy']['id'])
485
+
486
+ # Assertions
487
+ assert_equal response['ips'][0]['firewall_policy']['id'],
488
+ data['ips'][0]['firewall_policy']['id']
489
+
490
+ # Clear out stubs
491
+ Excon.stubs.clear
492
+
493
+ end
494
+
495
+
496
+ def test_firewall
497
+
498
+ # Read in mock JSON
499
+ file = File.read('mock-api/get-server-ip-fp.json')
500
+ data = JSON.parse(file)
501
+
502
+ # Create stub and perform call
503
+ Excon.stub({:method => :get,
504
+ :path => "/v1/servers/SERVER-ID/ips/IP-ID/firewall_policy"},
505
+ {:body => JSON.generate(data), :status => 200})
506
+
507
+ response = @server.firewall(server_id: 'SERVER-ID',
508
+ ip_id: 'IP-ID')
509
+
510
+ # Assertions
511
+ assert_equal response['id'], '3C4F21EDFEEDD6ABB728EA5CE684E1AF'
512
+
513
+ # Clear out stubs
514
+ Excon.stubs.clear
515
+
516
+ end
517
+
518
+
519
+ def test_remove_firewall
520
+
521
+ # Read in mock JSON
522
+ file = File.read('mock-api/remove-ip-fp.json')
523
+ data = JSON.parse(file)
524
+
525
+ # Create stub and perform call
526
+ Excon.stub({:method => :delete,
527
+ :path => "/v1/servers/#{data['id']}/ips/IP-ID/firewall_policy"},
528
+ {:body => JSON.generate(data), :status => 202})
529
+
530
+ response = @server.remove_firewall(server_id: data['id'],
531
+ ip_id: 'IP-ID')
532
+
533
+ # Assertions
534
+ assert_equal response['state'], 'CONFIGURING'
535
+
536
+ # Clear out stubs
537
+ Excon.stubs.clear
538
+
539
+ end
540
+
541
+
542
+ def test_load_balancers
543
+
544
+ # Read in mock JSON
545
+ file = File.read('mock-api/list-server-lbs.json')
546
+ data = JSON.parse(file)
547
+
548
+ # Create stub and perform call
549
+ Excon.stub({:method => :get,
550
+ :path => "/v1/servers/SERVER-ID/ips/IP-ID/load_balancers"},
551
+ {:body => JSON.generate(data), :status => 200})
552
+
553
+ response = @server.load_balancers(server_id: 'SERVER-ID',
554
+ ip_id: 'IP-ID')
555
+
556
+ # Assertions
557
+ assert_equal response[0]['id'], '37E2FDEB2945990CEE4B7927FB1ED425'
558
+
559
+ # Clear out stubs
560
+ Excon.stubs.clear
561
+
562
+ end
563
+
564
+
565
+ def test_add_load_balancer
566
+
567
+ # Read in mock JSON
568
+ file = File.read('mock-api/add-lb.json')
569
+ data = JSON.parse(file)
570
+
571
+ # Create stub and perform call
572
+ Excon.stub({:method => :post,
573
+ :path => "/v1/servers/#{data['id']}/ips/#{data['ips'][0]['id']}/load_balancers"},
574
+ {:body => JSON.generate(data), :status => 202})
575
+
576
+ response = @server.add_load_balancer(server_id: data['id'],
577
+ ip_id: data['ips'][0]['id'],
578
+ load_balancer_id: data['ips'][0]['load_balancers'][0]['id'])
579
+
580
+ # Assertions
581
+ assert_equal response['ips'][0]['load_balancers'][0]['id'],
582
+ data['ips'][0]['load_balancers'][0]['id']
583
+
584
+ # Clear out stubs
585
+ Excon.stubs.clear
586
+
587
+ end
588
+
589
+
590
+ def test_remove_load_balancer
591
+
592
+ # Read in mock JSON
593
+ file = File.read('mock-api/remove-lb.json')
594
+ data = JSON.parse(file)
595
+
596
+ # Create stub and perform call
597
+ Excon.stub({:method => :delete,
598
+ :path => "/v1/servers/#{data['id']}/ips/#{data['ips'][0]['id']}/load_balancers/LOAD-BALANCER-ID"},
599
+ {:body => JSON.generate(data), :status => 202})
600
+
601
+ response = @server.remove_load_balancer(server_id: data['id'],
602
+ ip_id: data['ips'][0]['id'], load_balancer_id: 'LOAD-BALANCER-ID')
603
+
604
+ # Assertions
605
+ assert_equal response['ips'][0]['load_balancers'], []
606
+
607
+ # Clear out stubs
608
+ Excon.stubs.clear
609
+
610
+ end
611
+
612
+
613
+ def test_status
614
+
615
+ # Read in mock JSON
616
+ file = File.read('mock-api/get-server-status.json')
617
+ data = JSON.parse(file)
618
+
619
+ # Create stub and perform call
620
+ Excon.stub({:method => :get,
621
+ :path => "/v1/servers/SERVER-ID/status"},
622
+ {:body => JSON.generate(data), :status => 200})
623
+
624
+ response = @server.status(server_id: 'SERVER-ID')
625
+
626
+ # Assertions
627
+ assert_equal response['state'], 'POWERED_ON'
628
+
629
+ # Clear out stubs
630
+ Excon.stubs.clear
631
+
632
+ end
633
+
634
+
635
+ def test_change_status
636
+
637
+ # Read in mock JSON
638
+ file = File.read('mock-api/change-server-status.json')
639
+ data = JSON.parse(file)
640
+
641
+ # Create stub and perform call
642
+ Excon.stub({:method => :put,
643
+ :path => "/v1/servers/#{data['id']}/status/action"},
644
+ {:body => JSON.generate(data), :status => 202})
645
+
646
+ response = @server.change_status(server_id: data['id'],
647
+ action: 'POWER_OFF',
648
+ method: 'SOFTWARE')
649
+
650
+ # Assertions
651
+ assert_equal response['status']['state'], 'POWERING_OFF'
652
+
653
+ # Clear out stubs
654
+ Excon.stubs.clear
655
+
656
+ end
657
+
658
+
659
+ def test_dvd
660
+
661
+ # Read in mock JSON
662
+ file = File.read('mock-api/get-server-dvd.json')
663
+ data = JSON.parse(file)
664
+
665
+ # Create stub and perform call
666
+ Excon.stub({:method => :get,
667
+ :path => "/v1/servers/SERVER-ID/dvd"},
668
+ {:body => JSON.generate(data), :status => 200})
669
+
670
+ response = @server.dvd(server_id: 'SERVER-ID')
671
+
672
+ # Assertions
673
+ assert_equal response['name'], 'Windows 2012 - 64 bits'
674
+
675
+ # Clear out stubs
676
+ Excon.stubs.clear
677
+
678
+ end
679
+
680
+
681
+ def test_load_dvd
682
+
683
+ # Read in mock JSON
684
+ file = File.read('mock-api/load-dvd.json')
685
+ data = JSON.parse(file)
686
+
687
+ # Create stub and perform call
688
+ Excon.stub({:method => :put,
689
+ :path => "/v1/servers/#{data['id']}/dvd"},
690
+ {:body => JSON.generate(data), :status => 202})
691
+
692
+ response = @server.load_dvd(server_id: data['id'], dvd_id: 'DVD-ID')
693
+
694
+ # Assertions
695
+ assert_equal response['dvd'], nil
696
+
697
+ # Clear out stubs
698
+ Excon.stubs.clear
699
+
700
+ end
701
+
702
+
703
+ def test_eject_dvd
704
+
705
+ # Read in mock JSON
706
+ file = File.read('mock-api/eject-dvd.json')
707
+ data = JSON.parse(file)
708
+
709
+ # Create stub and perform call
710
+ Excon.stub({:method => :delete,
711
+ :path => "/v1/servers/#{data['id']}/dvd"},
712
+ {:body => JSON.generate(data), :status => 202})
713
+
714
+ response = @server.eject_dvd(server_id: data['id'])
715
+
716
+ # Assertions
717
+ assert_equal response['status']['state'], 'CONFIGURING'
718
+
719
+ # Clear out stubs
720
+ Excon.stubs.clear
721
+
722
+ end
723
+
724
+
725
+ def test_private_networks
726
+
727
+ # Read in mock JSON
728
+ file = File.read('mock-api/list-server-pns.json')
729
+ data = JSON.parse(file)
730
+
731
+ # Create stub and perform call
732
+ Excon.stub({:method => :get,
733
+ :path => "/v1/servers/SERVER-ID/private_networks"},
734
+ {:body => JSON.generate(data), :status => 200})
735
+
736
+ response = @server.private_networks(server_id: 'SERVER-ID')
737
+
738
+ # Assertions
739
+ assert_equal response[0]['name'], 'New private network 1'
740
+
741
+ # Clear out stubs
742
+ Excon.stubs.clear
743
+
744
+ end
745
+
746
+
747
+ def test_private_network
748
+
749
+ # Read in mock JSON
750
+ file = File.read('mock-api/get-server-pn.json')
751
+ data = JSON.parse(file)
752
+
753
+ # Create stub and perform call
754
+ Excon.stub({:method => :get,
755
+ :path => "/v1/servers/#{data['servers'][0]['id']}/private_networks/#{data['id']}"},
756
+ {:body => JSON.generate(data), :status => 200})
757
+
758
+ response = @server.private_network(server_id: data['servers'][0]['id'],
759
+ private_network_id: data['id'])
760
+
761
+ # Assertions
762
+ assert_equal response['name'], 'New private network 1'
763
+
764
+ # Clear out stubs
765
+ Excon.stubs.clear
766
+
767
+ end
768
+
769
+
770
+ def test_add_private_network
771
+
772
+ # Read in mock JSON
773
+ file = File.read('mock-api/add-pn.json')
774
+ data = JSON.parse(file)
775
+
776
+ # Create stub and perform call
777
+ Excon.stub({:method => :post,
778
+ :path => "/v1/servers/#{data['id']}/private_networks"},
779
+ {:body => JSON.generate(data), :status => 202})
780
+
781
+ response = @server.add_private_network(server_id: data['id'],
782
+ private_network_id: 'PRIVATE-NETWORK-ID')
783
+
784
+ # Assertions
785
+ assert_equal response['private_networks'], nil
786
+
787
+ # Clear out stubs
788
+ Excon.stubs.clear
789
+
790
+ end
791
+
792
+
793
+ def test_remove_private_network
794
+
795
+ # Read in mock JSON
796
+ file = File.read('mock-api/remove-pn.json')
797
+ data = JSON.parse(file)
798
+
799
+ # Create stub and perform call
800
+ Excon.stub({:method => :delete,
801
+ :path => "/v1/servers/#{data['id']}/private_networks/PRIVATE-NETWORK-ID"},
802
+ {:body => JSON.generate(data), :status => 202})
803
+
804
+ response = @server.remove_private_network(server_id: data['id'],
805
+ private_network_id: 'PRIVATE-NETWORK-ID')
806
+
807
+ # Assertions
808
+ assert_equal response['private_networks'][0]['name'], 'New private network 1'
809
+
810
+ # Clear out stubs
811
+ Excon.stubs.clear
812
+
813
+ end
814
+
815
+
816
+ def test_create_snapshot
817
+
818
+ # Read in mock JSON
819
+ file = File.read('mock-api/create-snapshot.json')
820
+ data = JSON.parse(file)
821
+
822
+ # Create stub and perform call
823
+ Excon.stub({:method => :post,
824
+ :path => "/v1/servers/#{data['id']}/snapshots"},
825
+ {:body => JSON.generate(data), :status => 202})
826
+
827
+ response = @server.create_snapshot(server_id: data['id'])
828
+
829
+ # Assertions
830
+ assert_equal response['snapshot']['id'], data['snapshot']['id']
831
+
832
+ # Clear out stubs
833
+ Excon.stubs.clear
834
+
835
+ end
836
+
837
+
838
+ def test_snapshot
839
+
840
+ # Read in mock JSON
841
+ file = File.read('mock-api/list-snapshots.json')
842
+ data = JSON.parse(file)
843
+
844
+ # Create stub and perform call
845
+ Excon.stub({:method => :get,
846
+ :path => "/v1/servers/SERVER-ID/snapshots"},
847
+ {:body => JSON.generate(data), :status => 200})
848
+
849
+ response = @server.snapshot(server_id: 'SERVER-ID')
850
+
851
+ # Assertions
852
+ assert_equal response[0]['id'], 'B77E19E062D5818532EFF11C747BD104'
853
+
854
+ # Clear out stubs
855
+ Excon.stubs.clear
856
+
857
+ end
858
+
859
+
860
+ def test_restore_snapshot
861
+
862
+ # Read in mock JSON
863
+ file = File.read('mock-api/restore-snapshot.json')
864
+ data = JSON.parse(file)
865
+
866
+ # Create stub and perform call
867
+ Excon.stub({:method => :put,
868
+ :path => "/v1/servers/#{data['id']}/snapshots/#{data['snapshot']['id']}"},
869
+ {:body => JSON.generate(data), :status => 202})
870
+
871
+ response = @server.restore_snapshot(server_id: data['id'],
872
+ snapshot_id: data['snapshot']['id'])
873
+
874
+ # Assertions
875
+ assert_equal response['status']['state'], 'CONFIGURING'
876
+
877
+ # Clear out stubs
878
+ Excon.stubs.clear
879
+
880
+ end
881
+
882
+
883
+ def test_delete_snapshot
884
+
885
+ # Read in mock JSON
886
+ file = File.read('mock-api/delete-snapshot.json')
887
+ data = JSON.parse(file)
888
+
889
+ # Create stub and perform call
890
+ Excon.stub({:method => :delete,
891
+ :path => "/v1/servers/#{data['id']}/snapshots/#{data['snapshot']['id']}"},
892
+ {:body => JSON.generate(data), :status => 202})
893
+
894
+ response = @server.delete_snapshot(server_id: data['id'],
895
+ snapshot_id: data['snapshot']['id'])
896
+
897
+ # Assertions
898
+ assert_equal response['status']['state'], 'CONFIGURING'
899
+
900
+ # Clear out stubs
901
+ Excon.stubs.clear
902
+
903
+ end
904
+
905
+
906
+ def test_clone
907
+
908
+ # Read in mock JSON
909
+ file = File.read('mock-api/clone-server.json')
910
+ data = JSON.parse(file)
911
+
912
+ # Create stub and perform call
913
+ Excon.stub({:method => :post,
914
+ :path => "/v1/servers/SERVER-ID/clone"},
915
+ {:body => JSON.generate(data), :status => 202})
916
+
917
+ response = @server.clone(server_id: 'SERVER-ID',
918
+ name: data['name'])
919
+
920
+ # Assertions
921
+ assert_equal response['name'], data['name']
922
+
923
+ # Clear out stubs
924
+ Excon.stubs.clear
925
+
926
+ end
927
+
928
+
929
+ end