1and1 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,1208 @@
1
+ module OneAndOne
2
+
3
+
4
+ class Server
5
+
6
+
7
+ attr_accessor :id
8
+ attr_accessor :first_ip
9
+ attr_accessor :first_password
10
+ attr_accessor :specs
11
+
12
+
13
+ def initialize(test: false)
14
+ @id = nil
15
+ @first_ip = nil
16
+ @first_password = nil
17
+ @specs = nil
18
+
19
+ # Check if hitting mock api or live api
20
+ if test
21
+ @connection = Excon.new($base_url, :mock => true)
22
+ else
23
+ @connection = Excon.new($base_url)
24
+ end
25
+
26
+ end
27
+
28
+
29
+ def list(page: nil, per_page: nil, sort: nil, q: nil, fields: nil)
30
+
31
+ # Build hash for query parameters
32
+ keyword_args = {
33
+ :page => page,
34
+ :per_page => per_page,
35
+ :sort => sort,
36
+ :q => q,
37
+ :fields => fields
38
+ }
39
+
40
+ # Clean out null query parameters
41
+ params = OneAndOne.clean_hash(keyword_args)
42
+
43
+ # Build URL
44
+ path = OneAndOne.build_url('/servers')
45
+
46
+ # Perform request
47
+ response = @connection.request(:method => :get,
48
+ :path => path,
49
+ :headers => $header,
50
+ :query => params)
51
+
52
+ # Check response status
53
+ OneAndOne.check_response(response.body, response.status)
54
+
55
+ #JSON-ify the response string
56
+ JSON.parse(response.body)
57
+
58
+ end
59
+
60
+
61
+ def create(name: nil, description: nil, rsa_key: nil, fixed_instance_id: nil,
62
+ vcore: nil, cores_per_processor: nil, ram: nil, appliance_id: nil,
63
+ datacenter_id: nil, hdds: nil, password: nil, power_on: nil,
64
+ firewall_id: nil, ip_id: nil, load_balancer_id: nil,
65
+ monitoring_policy_id: nil)
66
+
67
+ # Build hardware hash
68
+ hardware_params = {
69
+ 'fixed_instance_size_id' => fixed_instance_id,
70
+ 'vcore' => vcore,
71
+ 'cores_per_processor' => cores_per_processor,
72
+ 'ram' => ram,
73
+ 'hdds' => hdds
74
+ }
75
+
76
+ # Clean out null keys in hardware hash
77
+ hardware = OneAndOne.clean_hash(hardware_params)
78
+
79
+ # Build POST body
80
+ new_server = {
81
+ 'name' => name,
82
+ 'description' => description,
83
+ 'hardware' => hardware,
84
+ 'appliance_id' => appliance_id,
85
+ 'datacenter_id' => datacenter_id,
86
+ 'rsa_key' => rsa_key,
87
+ 'password' => password,
88
+ 'power_on' => power_on,
89
+ 'firewall_policy_id' => firewall_id,
90
+ 'ip_id' => ip_id,
91
+ 'load_balancer_id' => load_balancer_id,
92
+ 'monitoring_policy_id' => monitoring_policy_id
93
+ }
94
+
95
+ # Clean out null keys in POST body
96
+ body = OneAndOne.clean_hash(new_server)
97
+
98
+ # Stringify the POST body
99
+ string_body = body.to_json
100
+
101
+ # Build URL
102
+ path = OneAndOne.build_url('/servers')
103
+
104
+ # Perform request
105
+ response = @connection.request(:method => :post,
106
+ :path => path,
107
+ :headers => $header,
108
+ :body => string_body)
109
+
110
+ # Check response status
111
+ OneAndOne.check_response(response.body, response.status)
112
+
113
+ #JSON-ify the response string
114
+ json = JSON.parse(response.body)
115
+
116
+ # Save new server ID to Server instance
117
+ @specs = json
118
+ @id = json['id']
119
+ @first_password = json['first_password']
120
+
121
+ # If all good, return JSON
122
+ json
123
+
124
+ end
125
+
126
+
127
+ def list_fixed
128
+
129
+ # Build URL
130
+ path = OneAndOne.build_url('/servers/fixed_instance_sizes')
131
+
132
+ # Perform request
133
+ response = @connection.request(:method => :get,
134
+ :path => path,
135
+ :headers => $header)
136
+
137
+ # Check response status
138
+ OneAndOne.check_response(response.body, response.status)
139
+
140
+ #JSON-ify the response string
141
+ JSON.parse(response.body)
142
+
143
+ end
144
+
145
+
146
+ def get_fixed(fixed_instance_id: nil)
147
+
148
+ # Build URL
149
+ path = OneAndOne.build_url("/servers/fixed_instance_sizes/#{fixed_instance_id}")
150
+
151
+ # Perform request
152
+ response = @connection.request(:method => :get,
153
+ :path => path,
154
+ :headers => $header)
155
+
156
+ # Check response status
157
+ OneAndOne.check_response(response.body, response.status)
158
+
159
+ #JSON-ify the response string
160
+ JSON.parse(response.body)
161
+
162
+ end
163
+
164
+
165
+ def get(server_id: @id)
166
+
167
+ # If user passed in server ID, reassign
168
+ @id = server_id
169
+
170
+ # Build URL
171
+ path = OneAndOne.build_url("/servers/#{@id}")
172
+
173
+ # Perform request
174
+ response = @connection.request(:method => :get,
175
+ :path => path,
176
+ :headers => $header)
177
+
178
+ # Check response status
179
+ OneAndOne.check_response(response.body, response.status)
180
+
181
+ #JSON-ify the response string
182
+ json = JSON.parse(response.body)
183
+
184
+ # Reload specs attribute
185
+ @specs = json
186
+
187
+ # If all good, return JSON
188
+ json
189
+
190
+ end
191
+
192
+
193
+ def modify(server_id: @id, name: nil, description: nil)
194
+
195
+ # If user passed in server ID, reassign
196
+ @id = server_id
197
+
198
+ # Build PUT body
199
+ server_specs = {
200
+ 'name' => name,
201
+ 'description' => description
202
+ }
203
+
204
+ # Clean out null keys in PUT body
205
+ body = OneAndOne.clean_hash(server_specs)
206
+
207
+ # Stringify the PUT body
208
+ string_body = body.to_json
209
+
210
+ # Build URL
211
+ path = OneAndOne.build_url("/servers/#{@id}")
212
+
213
+ # Perform Request
214
+ response = @connection.request(:method => :put,
215
+ :path => path,
216
+ :headers => $header,
217
+ :body => string_body)
218
+
219
+ # Check response status
220
+ OneAndOne.check_response(response.body, response.status)
221
+
222
+ #JSON-ify the response string
223
+ JSON.parse(response.body)
224
+
225
+ end
226
+
227
+
228
+ def delete(server_id: @id, keep_ips: nil)
229
+
230
+ # If user passed in server ID, reassign
231
+ @id = server_id
232
+
233
+ # Build hash for query parameters
234
+ keyword_args = {
235
+ 'keep_ips' => keep_ips
236
+ }
237
+
238
+ # Clean out null query parameters
239
+ params = OneAndOne.clean_hash(keyword_args)
240
+
241
+ # Build URL
242
+ path = OneAndOne.build_url("/servers/#{@id}")
243
+
244
+ # Perform request
245
+ response = @connection.request(:method => :delete,
246
+ :path => path,
247
+ :headers => $header,
248
+ :query => params)
249
+
250
+ # Check response status
251
+ OneAndOne.check_response(response.body, response.status)
252
+
253
+ #JSON-ify the response string
254
+ JSON.parse(response.body)
255
+
256
+ end
257
+
258
+
259
+ def hardware(server_id: @id)
260
+
261
+ # If user passed in server ID, reassign
262
+ @id = server_id
263
+
264
+ # Build URL
265
+ path = OneAndOne.build_url("/servers/#{@id}/hardware")
266
+
267
+ # Perform request
268
+ response = @connection.request(:method => :get,
269
+ :path => path,
270
+ :headers => $header)
271
+
272
+ # Check response status
273
+ OneAndOne.check_response(response.body, response.status)
274
+
275
+ #JSON-ify the response string
276
+ JSON.parse(response.body)
277
+
278
+ end
279
+
280
+
281
+ def modify_hardware(server_id: @id, fixed_instance_id: nil, vcore: nil,
282
+ cores_per_processor: nil, ram: nil)
283
+
284
+ # If user passed in server ID, reassign
285
+ @id = server_id
286
+
287
+ # Build PUT body
288
+ hardware_specs = {
289
+ 'fixed_instance_size_id' => fixed_instance_id,
290
+ 'vcore' => vcore,
291
+ 'cores_per_processor' => cores_per_processor,
292
+ 'ram' => ram
293
+ }
294
+
295
+ # Clean out null keys in PUT body
296
+ body = OneAndOne.clean_hash(hardware_specs)
297
+
298
+ # Stringify the PUT body
299
+ string_body = body.to_json
300
+
301
+ # Build URL
302
+ path = OneAndOne.build_url("/servers/#{@id}/hardware")
303
+
304
+ # Perform Request
305
+ response = @connection.request(:method => :put,
306
+ :path => path,
307
+ :headers => $header,
308
+ :body => string_body)
309
+
310
+ # Check response status
311
+ OneAndOne.check_response(response.body, response.status)
312
+
313
+ #JSON-ify the response string
314
+ JSON.parse(response.body)
315
+
316
+ end
317
+
318
+
319
+ def hdds(server_id: @id)
320
+
321
+ # If user passed in server ID, reassign
322
+ @id = server_id
323
+
324
+ # Build URL
325
+ path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds")
326
+
327
+ # Perform request
328
+ response = @connection.request(:method => :get,
329
+ :path => path,
330
+ :headers => $header)
331
+
332
+ # Check response status
333
+ OneAndOne.check_response(response.body, response.status)
334
+
335
+ #JSON-ify the response string
336
+ JSON.parse(response.body)
337
+
338
+ end
339
+
340
+
341
+ def add_hdds(server_id: @id, hdds: nil)
342
+
343
+ # If user passed in server ID, reassign
344
+ @id = server_id
345
+
346
+ # Build POST body
347
+ new_hdds = {
348
+ 'hdds' => hdds
349
+ }
350
+
351
+ # Stringify the POST body
352
+ string_body = new_hdds.to_json
353
+
354
+ # Build URL
355
+ path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds")
356
+
357
+ # Perform request
358
+ response = @connection.request(:method => :post,
359
+ :path => path,
360
+ :headers => $header,
361
+ :body => string_body)
362
+
363
+ # Check response status
364
+ OneAndOne.check_response(response.body, response.status)
365
+
366
+ #JSON-ify the response string
367
+ JSON.parse(response.body)
368
+
369
+ end
370
+
371
+
372
+ def get_hdd(server_id: @id, hdd_id: nil)
373
+
374
+ # If user passed in server ID, reassign
375
+ @id = server_id
376
+
377
+ # Build URL
378
+ path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds/#{hdd_id}")
379
+
380
+ # Perform request
381
+ response = @connection.request(:method => :get,
382
+ :path => path,
383
+ :headers => $header)
384
+
385
+ # Check response status
386
+ OneAndOne.check_response(response.body, response.status)
387
+
388
+ #JSON-ify the response string
389
+ JSON.parse(response.body)
390
+
391
+ end
392
+
393
+
394
+ def modify_hdd(server_id: @id, hdd_id: nil, size: nil)
395
+
396
+ # If user passed in server ID, reassign
397
+ @id = server_id
398
+
399
+ # Build PUT body
400
+ hdd_specs = {
401
+ 'size' => size
402
+ }
403
+
404
+ # Clean out null keys in PUT body
405
+ body = OneAndOne.clean_hash(hdd_specs)
406
+
407
+ # Stringify the PUT body
408
+ string_body = body.to_json
409
+
410
+ # Build URL
411
+ path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds/#{hdd_id}")
412
+
413
+ # Perform Request
414
+ response = @connection.request(:method => :put,
415
+ :path => path,
416
+ :headers => $header,
417
+ :body => string_body)
418
+
419
+ # Check response status
420
+ OneAndOne.check_response(response.body, response.status)
421
+
422
+ #JSON-ify the response string
423
+ JSON.parse(response.body)
424
+
425
+ end
426
+
427
+
428
+ def delete_hdd(server_id: @id, hdd_id: nil)
429
+
430
+ # If user passed in server ID, reassign
431
+ @id = server_id
432
+
433
+ # Build URL
434
+ path = OneAndOne.build_url("/servers/#{@id}/hardware/hdds/#{hdd_id}")
435
+
436
+ # Perform request
437
+ response = @connection.request(:method => :delete,
438
+ :path => path,
439
+ :headers => $header)
440
+
441
+ # Check response status
442
+ OneAndOne.check_response(response.body, response.status)
443
+
444
+ #JSON-ify the response string
445
+ JSON.parse(response.body)
446
+
447
+ end
448
+
449
+
450
+ def image(server_id: @id)
451
+
452
+ # If user passed in server ID, reassign
453
+ @id = server_id
454
+
455
+ # Build URL
456
+ path = OneAndOne.build_url("/servers/#{@id}/image")
457
+
458
+ # Perform request
459
+ response = @connection.request(:method => :get,
460
+ :path => path,
461
+ :headers => $header)
462
+
463
+ # Check response status
464
+ OneAndOne.check_response(response.body, response.status)
465
+
466
+ #JSON-ify the response string
467
+ JSON.parse(response.body)
468
+
469
+ end
470
+
471
+
472
+ def install_image(server_id: @id, image_id: nil, password: nil,
473
+ firewall_id: nil)
474
+
475
+ # If user passed in server ID, reassign
476
+ @id = server_id
477
+
478
+ # Build PUT body
479
+ image_specs = {
480
+ 'id' => image_id,
481
+ 'password' => password,
482
+ 'firewall_policy' => {
483
+ 'id' => firewall_id
484
+ }
485
+ }
486
+
487
+ # Clean out null keys in PUT body
488
+ body = OneAndOne.clean_hash(image_specs)
489
+
490
+ # Stringify the PUT body
491
+ string_body = body.to_json
492
+
493
+ # Build URL
494
+ path = OneAndOne.build_url("/servers/#{@id}/image")
495
+
496
+ # Perform Request
497
+ response = @connection.request(:method => :put,
498
+ :path => path,
499
+ :headers => $header,
500
+ :body => string_body)
501
+
502
+ # Check response status
503
+ OneAndOne.check_response(response.body, response.status)
504
+
505
+ #JSON-ify the response string
506
+ JSON.parse(response.body)
507
+
508
+ end
509
+
510
+
511
+ def ips(server_id: @id)
512
+
513
+ # If user passed in server ID, reassign
514
+ @id = server_id
515
+
516
+ # Build URL
517
+ path = OneAndOne.build_url("/servers/#{@id}/ips")
518
+
519
+ # Perform request
520
+ response = @connection.request(:method => :get,
521
+ :path => path,
522
+ :headers => $header)
523
+
524
+ # Check response status
525
+ OneAndOne.check_response(response.body, response.status)
526
+
527
+ #JSON-ify the response string
528
+ JSON.parse(response.body)
529
+
530
+ end
531
+
532
+
533
+ def add_ip(server_id: @id, ip_type: nil)
534
+
535
+ # If user passed in server ID, reassign
536
+ @id = server_id
537
+
538
+ # Build PUT body
539
+ ip_specs = {
540
+ 'type' => ip_type
541
+ }
542
+
543
+ # Clean out null keys in PUT body
544
+ body = OneAndOne.clean_hash(ip_specs)
545
+
546
+ # Stringify the PUT body
547
+ string_body = body.to_json
548
+
549
+ # Build URL
550
+ path = OneAndOne.build_url("/servers/#{@id}/ips")
551
+
552
+ # Perform Request
553
+ response = @connection.request(:method => :post,
554
+ :path => path,
555
+ :headers => $header,
556
+ :body => string_body)
557
+
558
+ # Check response status
559
+ OneAndOne.check_response(response.body, response.status)
560
+
561
+ #JSON-ify the response string
562
+ JSON.parse(response.body)
563
+
564
+ end
565
+
566
+
567
+ def ip(server_id: @id, ip_id: nil)
568
+
569
+ # If user passed in server ID, reassign
570
+ @id = server_id
571
+
572
+ # Build URL
573
+ path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}")
574
+
575
+ # Perform request
576
+ response = @connection.request(:method => :get,
577
+ :path => path,
578
+ :headers => $header)
579
+
580
+ # Check response status
581
+ OneAndOne.check_response(response.body, response.status)
582
+
583
+ #JSON-ify the response string
584
+ JSON.parse(response.body)
585
+
586
+ end
587
+
588
+ def release_ip(server_id: @id, ip_id: nil, keep_ip: nil)
589
+
590
+ # If user passed in server ID, reassign
591
+ @id = server_id
592
+
593
+ # Build PUT body
594
+ ip_specs = {
595
+ 'keep_ip' => keep_ip
596
+ }
597
+
598
+ # Clean out null keys in PUT body
599
+ body = OneAndOne.clean_hash(ip_specs)
600
+
601
+ # Stringify the PUT body
602
+ string_body = body.to_json
603
+
604
+ # Build URL
605
+ path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}")
606
+
607
+ # Perform request
608
+ response = @connection.request(:method => :delete,
609
+ :path => path,
610
+ :headers => $header,
611
+ :body => string_body)
612
+
613
+ # Check response status
614
+ OneAndOne.check_response(response.body, response.status)
615
+
616
+ #JSON-ify the response string
617
+ JSON.parse(response.body)
618
+
619
+ end
620
+
621
+
622
+ def add_firewall(server_id: @id, ip_id: nil, firewall_id: nil)
623
+
624
+ # If user passed in server ID, reassign
625
+ @id = server_id
626
+
627
+ # Build PUT body
628
+ firewall_specs = {
629
+ 'id' => firewall_id
630
+ }
631
+
632
+ # Clean out null keys in PUT body
633
+ body = OneAndOne.clean_hash(firewall_specs)
634
+
635
+ # Stringify the PUT body
636
+ string_body = body.to_json
637
+
638
+ # Build URL
639
+ path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/firewall_policy")
640
+
641
+ # Perform request
642
+ response = @connection.request(:method => :put,
643
+ :path => path,
644
+ :headers => $header,
645
+ :body => string_body)
646
+
647
+ # Check response status
648
+ OneAndOne.check_response(response.body, response.status)
649
+
650
+ #JSON-ify the response string
651
+ JSON.parse(response.body)
652
+
653
+ end
654
+
655
+
656
+ def firewall(server_id: @id, ip_id: nil)
657
+
658
+ # If user passed in server ID, reassign
659
+ @id = server_id
660
+
661
+ # Build URL
662
+ path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/firewall_policy")
663
+
664
+ # Perform request
665
+ response = @connection.request(:method => :get,
666
+ :path => path,
667
+ :headers => $header)
668
+
669
+ # Check response status
670
+ OneAndOne.check_response(response.body, response.status)
671
+
672
+ #JSON-ify the response string
673
+ JSON.parse(response.body)
674
+
675
+ end
676
+
677
+
678
+ def remove_firewall(server_id: @id, ip_id: nil)
679
+
680
+ # If user passed in server ID, reassign
681
+ @id = server_id
682
+
683
+ # Build URL
684
+ path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/firewall_policy")
685
+
686
+ # Perform request
687
+ response = @connection.request(:method => :delete,
688
+ :path => path,
689
+ :headers => $header)
690
+
691
+ # Check response status
692
+ OneAndOne.check_response(response.body, response.status)
693
+
694
+ #JSON-ify the response string
695
+ JSON.parse(response.body)
696
+
697
+ end
698
+
699
+
700
+ def load_balancers(server_id: @id, ip_id: nil)
701
+
702
+ # If user passed in server ID, reassign
703
+ @id = server_id
704
+
705
+ # Build URL
706
+ path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/load_balancers")
707
+
708
+ # Perform request
709
+ response = @connection.request(:method => :get,
710
+ :path => path,
711
+ :headers => $header)
712
+
713
+ # Check response status
714
+ OneAndOne.check_response(response.body, response.status)
715
+
716
+ #JSON-ify the response string
717
+ JSON.parse(response.body)
718
+
719
+ end
720
+
721
+
722
+ def add_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil)
723
+
724
+ # If user passed in server ID, reassign
725
+ @id = server_id
726
+
727
+ # Build PUT body
728
+ load_balancer_specs = {
729
+ 'load_balancer_id' => load_balancer_id
730
+ }
731
+
732
+ # Clean out null keys in PUT body
733
+ body = OneAndOne.clean_hash(load_balancer_specs)
734
+
735
+ # Stringify the PUT body
736
+ string_body = body.to_json
737
+
738
+ # Build URL
739
+ path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/load_balancers")
740
+
741
+ # Perform request
742
+ response = @connection.request(:method => :post,
743
+ :path => path,
744
+ :headers => $header,
745
+ :body => string_body)
746
+
747
+ # Check response status
748
+ OneAndOne.check_response(response.body, response.status)
749
+
750
+ #JSON-ify the response string
751
+ JSON.parse(response.body)
752
+
753
+ end
754
+
755
+
756
+ def remove_load_balancer(server_id: @id, ip_id: nil, load_balancer_id: nil)
757
+
758
+ # If user passed in server ID, reassign
759
+ @id = server_id
760
+
761
+ # Build URL
762
+ path = OneAndOne.build_url("/servers/#{@id}/ips/#{ip_id}/load_balancers/#{load_balancer_id}")
763
+
764
+ # Perform request
765
+ response = @connection.request(:method => :delete,
766
+ :path => path,
767
+ :headers => $header)
768
+
769
+ # Check response status
770
+ OneAndOne.check_response(response.body, response.status)
771
+
772
+ #JSON-ify the response string
773
+ JSON.parse(response.body)
774
+
775
+ end
776
+
777
+
778
+ def status(server_id: @id)
779
+
780
+ # If user passed in server ID, reassign
781
+ @id = server_id
782
+
783
+ # Build URL
784
+ path = OneAndOne.build_url("/servers/#{@id}/status")
785
+
786
+ # Perform request
787
+ response = @connection.request(:method => :get,
788
+ :path => path,
789
+ :headers => $header)
790
+
791
+ # Check response status
792
+ OneAndOne.check_response(response.body, response.status)
793
+
794
+ #JSON-ify the response string
795
+ JSON.parse(response.body)
796
+
797
+ end
798
+
799
+
800
+ def change_status(server_id: @id, action: nil, method: nil)
801
+
802
+ # If user passed in server ID, reassign
803
+ @id = server_id
804
+
805
+ # Build PUT body
806
+ status_specs = {
807
+ 'action' => action,
808
+ 'method' => method
809
+ }
810
+
811
+ # Clean out null keys in PUT body
812
+ body = OneAndOne.clean_hash(status_specs)
813
+
814
+ # Stringify the PUT body
815
+ string_body = body.to_json
816
+
817
+ # Build URL
818
+ path = OneAndOne.build_url("/servers/#{@id}/status/action")
819
+
820
+ # Perform request
821
+ response = @connection.request(:method => :put,
822
+ :path => path,
823
+ :headers => $header,
824
+ :body => string_body)
825
+
826
+ # Check response status
827
+ OneAndOne.check_response(response.body, response.status)
828
+
829
+ #JSON-ify the response string
830
+ JSON.parse(response.body)
831
+
832
+ end
833
+
834
+
835
+ def dvd(server_id: @id)
836
+
837
+ # If user passed in server ID, reassign
838
+ @id = server_id
839
+
840
+ # Build URL
841
+ path = OneAndOne.build_url("/servers/#{@id}/dvd")
842
+
843
+ # Perform request
844
+ response = @connection.request(:method => :get,
845
+ :path => path,
846
+ :headers => $header)
847
+
848
+ # Check response status
849
+ OneAndOne.check_response(response.body, response.status)
850
+
851
+ #JSON-ify the response string
852
+ JSON.parse(response.body)
853
+
854
+ end
855
+
856
+
857
+ def load_dvd(server_id: @id, dvd_id: nil)
858
+
859
+ # If user passed in server ID, reassign
860
+ @id = server_id
861
+
862
+ # Build PUT body
863
+ dvd_specs = {
864
+ 'id' => dvd_id
865
+ }
866
+
867
+ # Clean out null keys in PUT body
868
+ body = OneAndOne.clean_hash(dvd_specs)
869
+
870
+ # Stringify the PUT body
871
+ string_body = body.to_json
872
+
873
+ # Build URL
874
+ path = OneAndOne.build_url("/servers/#{@id}/dvd")
875
+
876
+ # Perform request
877
+ response = @connection.request(:method => :put,
878
+ :path => path,
879
+ :headers => $header,
880
+ :body => string_body)
881
+
882
+ # Check response status
883
+ OneAndOne.check_response(response.body, response.status)
884
+
885
+ #JSON-ify the response string
886
+ JSON.parse(response.body)
887
+
888
+ end
889
+
890
+
891
+ def eject_dvd(server_id: @id)
892
+
893
+ # If user passed in server ID, reassign
894
+ @id = server_id
895
+
896
+ # Build URL
897
+ path = OneAndOne.build_url("/servers/#{@id}/dvd")
898
+
899
+ # Perform request
900
+ response = @connection.request(:method => :delete,
901
+ :path => path,
902
+ :headers => $header)
903
+
904
+ # Check response status
905
+ OneAndOne.check_response(response.body, response.status)
906
+
907
+ #JSON-ify the response string
908
+ JSON.parse(response.body)
909
+
910
+ end
911
+
912
+
913
+ def private_networks(server_id: @id)
914
+
915
+ # If user passed in server ID, reassign
916
+ @id = server_id
917
+
918
+ # Build URL
919
+ path = OneAndOne.build_url("/servers/#{@id}/private_networks")
920
+
921
+ # Perform request
922
+ response = @connection.request(:method => :get,
923
+ :path => path,
924
+ :headers => $header)
925
+
926
+ # Check response status
927
+ OneAndOne.check_response(response.body, response.status)
928
+
929
+ #JSON-ify the response string
930
+ JSON.parse(response.body)
931
+
932
+ end
933
+
934
+
935
+ def private_network(server_id: @id, private_network_id: nil)
936
+
937
+ # If user passed in server ID, reassign
938
+ @id = server_id
939
+
940
+ # Build URL
941
+ path = OneAndOne.build_url("/servers/#{@id}/private_networks/#{private_network_id}")
942
+
943
+ # Perform request
944
+ response = @connection.request(:method => :get,
945
+ :path => path,
946
+ :headers => $header)
947
+
948
+ # Check response status
949
+ OneAndOne.check_response(response.body, response.status)
950
+
951
+ #JSON-ify the response string
952
+ JSON.parse(response.body)
953
+
954
+ end
955
+
956
+
957
+ def remove_private_network(server_id: @id, private_network_id: nil)
958
+
959
+ # If user passed in server ID, reassign
960
+ @id = server_id
961
+
962
+ # Build URL
963
+ path = OneAndOne.build_url("/servers/#{@id}/private_networks/#{private_network_id}")
964
+
965
+ # Perform request
966
+ response = @connection.request(:method => :delete,
967
+ :path => path,
968
+ :headers => $header)
969
+
970
+ # Check response status
971
+ OneAndOne.check_response(response.body, response.status)
972
+
973
+ #JSON-ify the response string
974
+ JSON.parse(response.body)
975
+
976
+ end
977
+
978
+
979
+ def add_private_network(server_id: @id, private_network_id: nil)
980
+
981
+ # If user passed in server ID, reassign
982
+ @id = server_id
983
+
984
+ # Build PUT body
985
+ private_network_specs = {
986
+ 'id' => private_network_id
987
+ }
988
+
989
+ # Clean out null keys in PUT body
990
+ body = OneAndOne.clean_hash(private_network_specs)
991
+
992
+ # Stringify the PUT body
993
+ string_body = body.to_json
994
+
995
+ # Build URL
996
+ path = OneAndOne.build_url("/servers/#{@id}/private_networks")
997
+
998
+ # Perform request
999
+ response = @connection.request(:method => :post,
1000
+ :path => path,
1001
+ :headers => $header,
1002
+ :body => string_body)
1003
+
1004
+ # Check response status
1005
+ OneAndOne.check_response(response.body, response.status)
1006
+
1007
+ #JSON-ify the response string
1008
+ JSON.parse(response.body)
1009
+
1010
+ end
1011
+
1012
+
1013
+ def create_snapshot(server_id: @id)
1014
+
1015
+ # If user passed in server ID, reassign
1016
+ @id = server_id
1017
+
1018
+ # Build URL
1019
+ path = OneAndOne.build_url("/servers/#{@id}/snapshots")
1020
+
1021
+ # Perform request
1022
+ response = @connection.request(:method => :post,
1023
+ :path => path,
1024
+ :headers => $header)
1025
+
1026
+ # Check response status
1027
+ OneAndOne.check_response(response.body, response.status)
1028
+
1029
+ #JSON-ify the response string
1030
+ JSON.parse(response.body)
1031
+
1032
+ end
1033
+
1034
+
1035
+ def snapshot(server_id: @id)
1036
+
1037
+ # If user passed in server ID, reassign
1038
+ @id = server_id
1039
+
1040
+ # Build URL
1041
+ path = OneAndOne.build_url("/servers/#{@id}/snapshots")
1042
+
1043
+ # Perform request
1044
+ response = @connection.request(:method => :get,
1045
+ :path => path,
1046
+ :headers => $header)
1047
+
1048
+ # Check response status
1049
+ OneAndOne.check_response(response.body, response.status)
1050
+
1051
+ #JSON-ify the response string
1052
+ JSON.parse(response.body)
1053
+
1054
+ end
1055
+
1056
+
1057
+ def restore_snapshot(server_id: @id, snapshot_id: nil)
1058
+
1059
+ # If user passed in server ID, reassign
1060
+ @id = server_id
1061
+
1062
+ # Build URL
1063
+ path = OneAndOne.build_url("/servers/#{@id}/snapshots/#{snapshot_id}")
1064
+
1065
+ # Perform request
1066
+ response = @connection.request(:method => :put,
1067
+ :path => path,
1068
+ :headers => $header)
1069
+
1070
+ # Check response status
1071
+ OneAndOne.check_response(response.body, response.status)
1072
+
1073
+ #JSON-ify the response string
1074
+ JSON.parse(response.body)
1075
+
1076
+ end
1077
+
1078
+
1079
+ def delete_snapshot(server_id: @id, snapshot_id: nil)
1080
+
1081
+ # If user passed in server ID, reassign
1082
+ @id = server_id
1083
+
1084
+ # Build URL
1085
+ path = OneAndOne.build_url("/servers/#{@id}/snapshots/#{snapshot_id}")
1086
+
1087
+ # Perform request
1088
+ response = @connection.request(:method => :delete,
1089
+ :path => path,
1090
+ :headers => $header)
1091
+
1092
+ # Check response status
1093
+ OneAndOne.check_response(response.body, response.status)
1094
+
1095
+ #JSON-ify the response string
1096
+ JSON.parse(response.body)
1097
+
1098
+ end
1099
+
1100
+
1101
+ def clone(server_id: @id, name: nil, datacenter_id: nil)
1102
+
1103
+ # If user passed in server ID, reassign
1104
+ @id = server_id
1105
+
1106
+ # Build PUT body
1107
+ clone_specs = {
1108
+ 'name' => name,
1109
+ 'datacenter_id' => datacenter_id
1110
+ }
1111
+
1112
+ # Clean out null keys in PUT body
1113
+ body = OneAndOne.clean_hash(clone_specs)
1114
+
1115
+ # Stringify the PUT body
1116
+ string_body = body.to_json
1117
+
1118
+ # Build URL
1119
+ path = OneAndOne.build_url("/servers/#{@id}/clone")
1120
+
1121
+ # Perform request
1122
+ response = @connection.request(:method => :post,
1123
+ :path => path,
1124
+ :headers => $header,
1125
+ :body => string_body)
1126
+
1127
+ # Check response status
1128
+ OneAndOne.check_response(response.body, response.status)
1129
+
1130
+ #JSON-ify the response string
1131
+ JSON.parse(response.body)
1132
+
1133
+ end
1134
+
1135
+
1136
+ def reload
1137
+
1138
+ # This reload fx is just a wrapper for the get fx
1139
+ get
1140
+
1141
+ end
1142
+
1143
+
1144
+ def check_state(response)
1145
+
1146
+ # Parse out server state and percent from response
1147
+ state = response['status']['state']
1148
+ percent = response['status']['percent']
1149
+
1150
+ # This is the ideal server state we are looking for
1151
+ ($good_states.include? state) && (percent == nil)
1152
+
1153
+ end
1154
+
1155
+
1156
+ def parser(response)
1157
+
1158
+ # Check for first IP
1159
+ ips = response['ips']
1160
+
1161
+ if ips.length == 1
1162
+ @first_ip = ips[0]
1163
+ end
1164
+
1165
+ end
1166
+
1167
+
1168
+ def wait_for(timeout: 25, interval: 15)
1169
+
1170
+ # Capture start time
1171
+ start = Time.now
1172
+
1173
+ # Poll server and check initial state
1174
+ initial_response = get
1175
+ server_state = check_state(initial_response)
1176
+
1177
+ # Keep polling the server's state until good
1178
+ until server_state
1179
+
1180
+ # Wait 15 seconds before polling again
1181
+ sleep interval
1182
+
1183
+ # Check server state and percent again
1184
+ current_response = get
1185
+ server_state = check_state(current_response)
1186
+
1187
+ # Calculate current duration and check for timeout
1188
+ duration = (Time.now - start) / 60
1189
+ if duration > timeout
1190
+ puts "The operation timed out after #{timeout} minutes.\n"
1191
+ return
1192
+ end
1193
+
1194
+ # Parse for first IP
1195
+ parser(current_response)
1196
+
1197
+ end
1198
+
1199
+ # Return Duration
1200
+ {:duration => duration}
1201
+
1202
+ end
1203
+
1204
+
1205
+ end
1206
+
1207
+
1208
+ end