fog-proxmox-configlmm 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +8 -0
  3. data/LICENSE +674 -0
  4. data/README.md +110 -0
  5. data/docs/compute.md +874 -0
  6. data/docs/connection_parameters.md +45 -0
  7. data/docs/getting_started.md +53 -0
  8. data/docs/identity.md +382 -0
  9. data/examples/compute.rb +276 -0
  10. data/examples/identity.rb +203 -0
  11. data/lib/fog/proxmox/attributes.rb +34 -0
  12. data/lib/fog/proxmox/auth/token/access_ticket.rb +96 -0
  13. data/lib/fog/proxmox/auth/token/user_token.rb +107 -0
  14. data/lib/fog/proxmox/auth/token.rb +94 -0
  15. data/lib/fog/proxmox/compute/models/disk.rb +94 -0
  16. data/lib/fog/proxmox/compute/models/disks.rb +55 -0
  17. data/lib/fog/proxmox/compute/models/interface.rb +56 -0
  18. data/lib/fog/proxmox/compute/models/interfaces.rb +44 -0
  19. data/lib/fog/proxmox/compute/models/node.rb +93 -0
  20. data/lib/fog/proxmox/compute/models/nodes.rb +39 -0
  21. data/lib/fog/proxmox/compute/models/server.rb +271 -0
  22. data/lib/fog/proxmox/compute/models/server_config.rb +161 -0
  23. data/lib/fog/proxmox/compute/models/servers.rb +80 -0
  24. data/lib/fog/proxmox/compute/models/snapshot.rb +83 -0
  25. data/lib/fog/proxmox/compute/models/snapshots.rb +47 -0
  26. data/lib/fog/proxmox/compute/models/storage.rb +65 -0
  27. data/lib/fog/proxmox/compute/models/storages.rb +51 -0
  28. data/lib/fog/proxmox/compute/models/task.rb +79 -0
  29. data/lib/fog/proxmox/compute/models/tasks.rb +65 -0
  30. data/lib/fog/proxmox/compute/models/volume.rb +68 -0
  31. data/lib/fog/proxmox/compute/models/volumes.rb +58 -0
  32. data/lib/fog/proxmox/compute/requests/action_server.rb +45 -0
  33. data/lib/fog/proxmox/compute/requests/clone_server.rb +44 -0
  34. data/lib/fog/proxmox/compute/requests/create_backup.rb +42 -0
  35. data/lib/fog/proxmox/compute/requests/create_server.rb +43 -0
  36. data/lib/fog/proxmox/compute/requests/create_snapshot.rb +46 -0
  37. data/lib/fog/proxmox/compute/requests/create_spice.rb +44 -0
  38. data/lib/fog/proxmox/compute/requests/create_term.rb +45 -0
  39. data/lib/fog/proxmox/compute/requests/create_vnc.rb +44 -0
  40. data/lib/fog/proxmox/compute/requests/delete_server.rb +45 -0
  41. data/lib/fog/proxmox/compute/requests/delete_snapshot.rb +47 -0
  42. data/lib/fog/proxmox/compute/requests/delete_volume.rb +40 -0
  43. data/lib/fog/proxmox/compute/requests/get_node_statistics.rb +44 -0
  44. data/lib/fog/proxmox/compute/requests/get_server_config.rb +60 -0
  45. data/lib/fog/proxmox/compute/requests/get_server_status.rb +63 -0
  46. data/lib/fog/proxmox/compute/requests/get_snapshot_config.rb +44 -0
  47. data/lib/fog/proxmox/compute/requests/get_task.rb +41 -0
  48. data/lib/fog/proxmox/compute/requests/get_vnc.rb +45 -0
  49. data/lib/fog/proxmox/compute/requests/get_volume.rb +42 -0
  50. data/lib/fog/proxmox/compute/requests/list_nodes.rb +48 -0
  51. data/lib/fog/proxmox/compute/requests/list_servers.rb +113 -0
  52. data/lib/fog/proxmox/compute/requests/list_snapshots.rb +66 -0
  53. data/lib/fog/proxmox/compute/requests/list_storages.rb +46 -0
  54. data/lib/fog/proxmox/compute/requests/list_tasks.rb +44 -0
  55. data/lib/fog/proxmox/compute/requests/list_volumes.rb +44 -0
  56. data/lib/fog/proxmox/compute/requests/log_task.rb +44 -0
  57. data/lib/fog/proxmox/compute/requests/migrate_server.rb +44 -0
  58. data/lib/fog/proxmox/compute/requests/move_disk.rb +43 -0
  59. data/lib/fog/proxmox/compute/requests/move_volume.rb +43 -0
  60. data/lib/fog/proxmox/compute/requests/next_vmid.rb +42 -0
  61. data/lib/fog/proxmox/compute/requests/resize_container.rb +43 -0
  62. data/lib/fog/proxmox/compute/requests/resize_server.rb +43 -0
  63. data/lib/fog/proxmox/compute/requests/rollback_snapshot.rb +48 -0
  64. data/lib/fog/proxmox/compute/requests/status_task.rb +41 -0
  65. data/lib/fog/proxmox/compute/requests/stop_task.rb +41 -0
  66. data/lib/fog/proxmox/compute/requests/template_server.rb +44 -0
  67. data/lib/fog/proxmox/compute/requests/update_server.rb +44 -0
  68. data/lib/fog/proxmox/compute/requests/update_snapshot.rb +45 -0
  69. data/lib/fog/proxmox/compute.rb +141 -0
  70. data/lib/fog/proxmox/core.rb +147 -0
  71. data/lib/fog/proxmox/errors.rb +65 -0
  72. data/lib/fog/proxmox/hash.rb +37 -0
  73. data/lib/fog/proxmox/helpers/controller_helper.rb +63 -0
  74. data/lib/fog/proxmox/helpers/cpu_helper.rb +88 -0
  75. data/lib/fog/proxmox/helpers/disk_helper.rb +185 -0
  76. data/lib/fog/proxmox/helpers/ip_helper.rb +101 -0
  77. data/lib/fog/proxmox/helpers/nic_helper.rb +132 -0
  78. data/lib/fog/proxmox/identity/models/domain.rb +69 -0
  79. data/lib/fog/proxmox/identity/models/domain_type.rb +47 -0
  80. data/lib/fog/proxmox/identity/models/domains.rb +44 -0
  81. data/lib/fog/proxmox/identity/models/group.rb +51 -0
  82. data/lib/fog/proxmox/identity/models/groups.rb +44 -0
  83. data/lib/fog/proxmox/identity/models/permission.rb +66 -0
  84. data/lib/fog/proxmox/identity/models/permissions.rb +46 -0
  85. data/lib/fog/proxmox/identity/models/pool.rb +89 -0
  86. data/lib/fog/proxmox/identity/models/pools.rb +46 -0
  87. data/lib/fog/proxmox/identity/models/principal.rb +42 -0
  88. data/lib/fog/proxmox/identity/models/role.rb +48 -0
  89. data/lib/fog/proxmox/identity/models/roles.rb +44 -0
  90. data/lib/fog/proxmox/identity/models/token.rb +72 -0
  91. data/lib/fog/proxmox/identity/models/token_info.rb +41 -0
  92. data/lib/fog/proxmox/identity/models/tokens.rb +54 -0
  93. data/lib/fog/proxmox/identity/models/user.rb +82 -0
  94. data/lib/fog/proxmox/identity/models/users.rb +44 -0
  95. data/lib/fog/proxmox/identity/requests/change_password.rb +41 -0
  96. data/lib/fog/proxmox/identity/requests/check_permissions.rb +41 -0
  97. data/lib/fog/proxmox/identity/requests/create_domain.rb +40 -0
  98. data/lib/fog/proxmox/identity/requests/create_group.rb +40 -0
  99. data/lib/fog/proxmox/identity/requests/create_pool.rb +40 -0
  100. data/lib/fog/proxmox/identity/requests/create_role.rb +40 -0
  101. data/lib/fog/proxmox/identity/requests/create_token.rb +40 -0
  102. data/lib/fog/proxmox/identity/requests/create_user.rb +40 -0
  103. data/lib/fog/proxmox/identity/requests/delete_domain.rb +40 -0
  104. data/lib/fog/proxmox/identity/requests/delete_group.rb +40 -0
  105. data/lib/fog/proxmox/identity/requests/delete_pool.rb +39 -0
  106. data/lib/fog/proxmox/identity/requests/delete_role.rb +40 -0
  107. data/lib/fog/proxmox/identity/requests/delete_token.rb +40 -0
  108. data/lib/fog/proxmox/identity/requests/delete_user.rb +39 -0
  109. data/lib/fog/proxmox/identity/requests/get_domain.rb +41 -0
  110. data/lib/fog/proxmox/identity/requests/get_group.rb +41 -0
  111. data/lib/fog/proxmox/identity/requests/get_pool.rb +41 -0
  112. data/lib/fog/proxmox/identity/requests/get_role.rb +41 -0
  113. data/lib/fog/proxmox/identity/requests/get_token_info.rb +41 -0
  114. data/lib/fog/proxmox/identity/requests/get_user.rb +41 -0
  115. data/lib/fog/proxmox/identity/requests/list_domains.rb +41 -0
  116. data/lib/fog/proxmox/identity/requests/list_groups.rb +41 -0
  117. data/lib/fog/proxmox/identity/requests/list_permissions.rb +41 -0
  118. data/lib/fog/proxmox/identity/requests/list_pools.rb +41 -0
  119. data/lib/fog/proxmox/identity/requests/list_roles.rb +40 -0
  120. data/lib/fog/proxmox/identity/requests/list_tokens.rb +41 -0
  121. data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +44 -0
  122. data/lib/fog/proxmox/identity/requests/list_users.rb +42 -0
  123. data/lib/fog/proxmox/identity/requests/read_version.rb +39 -0
  124. data/lib/fog/proxmox/identity/requests/update_domain.rb +41 -0
  125. data/lib/fog/proxmox/identity/requests/update_group.rb +40 -0
  126. data/lib/fog/proxmox/identity/requests/update_permissions.rb +41 -0
  127. data/lib/fog/proxmox/identity/requests/update_pool.rb +41 -0
  128. data/lib/fog/proxmox/identity/requests/update_role.rb +41 -0
  129. data/lib/fog/proxmox/identity/requests/update_token.rb +41 -0
  130. data/lib/fog/proxmox/identity/requests/update_user.rb +41 -0
  131. data/lib/fog/proxmox/identity.rb +144 -0
  132. data/lib/fog/proxmox/json.rb +32 -0
  133. data/lib/fog/proxmox/network/models/network.rb +76 -0
  134. data/lib/fog/proxmox/network/models/networks.rb +48 -0
  135. data/lib/fog/proxmox/network/models/node.rb +75 -0
  136. data/lib/fog/proxmox/network/models/nodes.rb +39 -0
  137. data/lib/fog/proxmox/network/requests/create_network.rb +41 -0
  138. data/lib/fog/proxmox/network/requests/delete_network.rb +42 -0
  139. data/lib/fog/proxmox/network/requests/get_network.rb +43 -0
  140. data/lib/fog/proxmox/network/requests/get_node.rb +41 -0
  141. data/lib/fog/proxmox/network/requests/list_networks.rb +43 -0
  142. data/lib/fog/proxmox/network/requests/list_nodes.rb +42 -0
  143. data/lib/fog/proxmox/network/requests/power_node.rb +43 -0
  144. data/lib/fog/proxmox/network/requests/update_network.rb +42 -0
  145. data/lib/fog/proxmox/network.rb +90 -0
  146. data/lib/fog/proxmox/storage/requests/create.rb +23 -0
  147. data/lib/fog/proxmox/storage/requests/download_appliance.rb +24 -0
  148. data/lib/fog/proxmox/storage/requests/list.rb +22 -0
  149. data/lib/fog/proxmox/storage/requests/list_appliances.rb +23 -0
  150. data/lib/fog/proxmox/storage/requests/upload.rb +44 -0
  151. data/lib/fog/proxmox/storage.rb +82 -0
  152. data/lib/fog/proxmox/string.rb +32 -0
  153. data/lib/fog/proxmox/variables.rb +40 -0
  154. data/lib/fog/proxmox/version.rb +24 -0
  155. data/lib/fog/proxmox.rb +53 -0
  156. data/spec/compute_spec.rb +447 -0
  157. data/spec/fixtures/proxmox/compute/common_auth.yml +40 -0
  158. data/spec/fixtures/proxmox/compute/containers.yml +6921 -0
  159. data/spec/fixtures/proxmox/compute/nodes.yml +115 -0
  160. data/spec/fixtures/proxmox/compute/servers.yml +19011 -0
  161. data/spec/fixtures/proxmox/compute/snapshots.yml +1376 -0
  162. data/spec/fixtures/proxmox/compute/storages.yml +151 -0
  163. data/spec/fixtures/proxmox/compute/tasks.yml +465 -0
  164. data/spec/fixtures/proxmox/identity/auth.yml +42 -0
  165. data/spec/fixtures/proxmox/identity/auth_access_ticket.yml +77 -0
  166. data/spec/fixtures/proxmox/identity/auth_user_token.yml +77 -0
  167. data/spec/fixtures/proxmox/identity/common_auth.yml +40 -0
  168. data/spec/fixtures/proxmox/identity/domains.yml +665 -0
  169. data/spec/fixtures/proxmox/identity/groups.yml +345 -0
  170. data/spec/fixtures/proxmox/identity/permissions.yml +911 -0
  171. data/spec/fixtures/proxmox/identity/pools.yml +946 -0
  172. data/spec/fixtures/proxmox/identity/read_version.yml +40 -0
  173. data/spec/fixtures/proxmox/identity/roles.yml +345 -0
  174. data/spec/fixtures/proxmox/identity/tokens.yml +494 -0
  175. data/spec/fixtures/proxmox/identity/users.yml +725 -0
  176. data/spec/fixtures/proxmox/network/common_auth.yml +40 -0
  177. data/spec/fixtures/proxmox/network/networks.yml +375 -0
  178. data/spec/fixtures/proxmox/pve.home +34 -0
  179. data/spec/hash_spec.rb +43 -0
  180. data/spec/helpers/controller_helper_spec.rb +157 -0
  181. data/spec/helpers/cpu_helper_spec.rb +82 -0
  182. data/spec/helpers/disk_helper_spec.rb +304 -0
  183. data/spec/helpers/ip_helper_spec.rb +177 -0
  184. data/spec/helpers/nic_helper_spec.rb +144 -0
  185. data/spec/identity_spec.rb +416 -0
  186. data/spec/network_spec.rb +67 -0
  187. data/spec/proxmox_vcr.rb +97 -0
  188. data/spec/spec_helper.rb +41 -0
  189. metadata +566 -0
data/docs/compute.md ADDED
@@ -0,0 +1,874 @@
1
+ # Compute
2
+
3
+ This document shows you the compute service available with fog-proxmox.
4
+
5
+ Proxmox supports both virtual machines (QEMU/KVM) and containers (LXC) management.
6
+
7
+ You can see more details in [Proxmox VM management wiki page](https://pve.proxmox.com/wiki/Qemu/KVM_Virtual_Machines) and [Proxmox containers management wiki page](https://pve.proxmox.com/wiki/Linux_Container).
8
+
9
+ ## Starting irb console
10
+
11
+ ```ruby
12
+ irb
13
+ ```
14
+
15
+ ```ruby
16
+ require 'fog/proxmox'
17
+ ```
18
+
19
+ ## Create compute service
20
+
21
+ with access ticket:
22
+
23
+ ```ruby
24
+ identity = Fog::Proxmox::Identity.new(
25
+ proxmox_url: 'https://localhost:8006/api2/json',
26
+ proxmox_auth_method: 'access_ticket',
27
+ proxmox_username: 'your_user@your_realm',
28
+ proxmox_password: 'his_password',
29
+ connection_options: { ... }
30
+ )
31
+ ```
32
+
33
+ with API user token:
34
+
35
+ ```ruby
36
+ identity = Fog::Proxmox::Identity.new(
37
+ proxmox_url: 'https://localhost:8006/api2/json',
38
+ proxmox_auth_method: 'user_token',
39
+ proxmox_userid: 'your_user',
40
+ proxmox_tokenid: 'his_tokenid',
41
+ proxmox_token: 'his_token',
42
+ connection_options: { ... }
43
+ )
44
+ ```
45
+
46
+ [connection_options](connection_parameters.md) are also available and optional.
47
+
48
+ ## Fog Abstractions
49
+
50
+ Fog provides both a **model** and **request** abstraction. The request abstraction provides the most efficient interface and the model abstraction wraps the request abstraction to provide a convenient `ActiveModel` like interface.
51
+
52
+ ### Request Layer
53
+
54
+ The request abstraction maps directly to the [Proxmox VE API](https://pve.proxmox.com/wiki/Proxmox_VE_API). It provides an interface to the Proxmox Compute service.
55
+
56
+ To see a list of requests supported by the service:
57
+
58
+ ```ruby
59
+ compute.requests
60
+ ```
61
+
62
+ To learn more about Compute request methods refer to source files.
63
+
64
+ To learn more about Excon refer to [Excon GitHub repo](https://github.com/geemus/excon).
65
+
66
+ ### Model Layer
67
+
68
+ Fog models behave in a manner similar to `ActiveModel`. Models will generally respond to `create`, `save`, `persisted?`, `destroy`, `reload` and `attributes` methods. Additionally, fog will automatically create attribute accessors.
69
+
70
+ Here is a summary of common model methods:
71
+
72
+ <table>
73
+ <tr>
74
+ <th>Method</th>
75
+ <th>Description</th>
76
+ </tr>
77
+ <tr>
78
+ <td>create</td>
79
+ <td>
80
+ Accepts hash of attributes and creates object.<br>
81
+ Note: creation is a non-blocking call and you will be required to wait for a valid state before using resulting object.
82
+ </td>
83
+ </tr>
84
+ <tr>
85
+ <td>save</td>
86
+ <td>Saves object.<br>
87
+ Note: not all objects support updating object.</td>
88
+ </tr>
89
+ <tr>
90
+ <td>persisted?</td>
91
+ <td>Returns true if the object has been persisted.</td>
92
+ </tr>
93
+ <tr>
94
+ <td>destroy</td>
95
+ <td>
96
+ Destroys object.<br>
97
+ Note: this is a non-blocking call and object deletion might not be instantaneous.
98
+ </td>
99
+ <tr>
100
+ <td>reload</td>
101
+ <td>Updates object with latest state from service.</td>
102
+ <tr>
103
+ <td>ready?</td>
104
+ <td>Returns true if object is in a ready state and able to perform actions. This method will raise an exception if object is in an error state.</td>
105
+ </tr>
106
+ <tr>
107
+ <td>attributes</td>
108
+ <td>Returns a hash containing the list of model attributes and values.</td>
109
+ </tr>
110
+ <td>identity</td>
111
+ <td>
112
+ Returns the identity of the object.<br>
113
+ Note: This might not always be equal to object.id.
114
+ </td>
115
+ </tr>
116
+ <tr>
117
+ <td>wait_for</td>
118
+ <td>This method periodically reloads model and then yields to specified block until block returns true or a timeout occurs.</td>
119
+ </tr>
120
+ </table>
121
+
122
+ The remainder of this document details the model abstraction.
123
+
124
+ #### Nodes management
125
+
126
+ Proxmox supports cluster management. Each hyperviser in the cluster is called a node.
127
+ Proxmox installs a default node in the cluster called `pve`.
128
+
129
+ List all nodes:
130
+
131
+ ```ruby
132
+ service.nodes.all
133
+ ```
134
+
135
+ This returns a collection of `Fog::Proxmox::Compute::Node` models:
136
+
137
+ Get a node:
138
+
139
+ ```ruby
140
+ node = service.nodes.find_by_id 'pve'
141
+ ```
142
+
143
+ Get statistics (default is data):
144
+
145
+ ```ruby
146
+ node.statistics
147
+ ```
148
+
149
+ Get statistics (image png):
150
+
151
+ ```ruby
152
+ node.statistics('rrd', { timeframe: 'hour', ds: 'cpu,memused', cf: 'AVERAGE' })
153
+ ```
154
+
155
+ #### Servers management
156
+
157
+ Proxmox supports servers management. Servers are also called virtual machines (VM).
158
+
159
+ VM are QEMU/KVM managed. They are attached to a node.
160
+
161
+ More details in [Proxmox VM management wiki page](https://pve.proxmox.com/wiki/Qemu/KVM_Virtual_Machines)
162
+
163
+ You need to specify a node before managing VM. Fog-proxmox enables it by managing VM from a node.
164
+
165
+ List all servers:
166
+
167
+ ```ruby
168
+ node.servers.all
169
+ ```
170
+
171
+ This returns a collection of `Fog::Proxmox::Identity::Server` models.
172
+
173
+ Before creating a server you can get the next available server id (integer >= 100) in the cluster:
174
+
175
+ ```ruby
176
+ nextid = node.servers.next_id
177
+ ```
178
+
179
+ You can also verify that an id is free or valid:
180
+
181
+ ```ruby
182
+ node.servers.id_valid? nextid
183
+ ```
184
+
185
+ Now that you have a valid id, you can create a server in this node:
186
+
187
+ ```ruby
188
+ node.servers.create({ vmid: nextid })
189
+ ```
190
+
191
+ Get this server:
192
+
193
+ ```ruby
194
+ server = node.servers.get nextid
195
+ ```
196
+
197
+ Add options: boot at startup, OS type (linux 4.x), french keyboard, no hardware KVM:
198
+
199
+ ```ruby
200
+ server.update({ onboot: 1, keyboard: 'fr', ostype: 'l26', kvm: 0 })
201
+ ```
202
+
203
+ Add a cdrom volume:
204
+
205
+ ```ruby
206
+ server.update({ ide2: 'none,media=cdrom' })
207
+ ```
208
+
209
+ Add a network interface controller (nic):
210
+
211
+ ```ruby
212
+ server.update({ net0: 'virtio,bridge=vmbr0' })
213
+ ```
214
+
215
+ Get mac adresses generated by Proxmox:
216
+
217
+ ```ruby
218
+ server.config.mac_adresses
219
+ ```
220
+
221
+ This returns an array of strings.
222
+
223
+ Get all server configuration:
224
+
225
+ ```ruby
226
+ server.config
227
+ ```
228
+
229
+ This returns a `Fog::Proxmox::Compute::ServerConfig` model:
230
+
231
+ ```ruby
232
+ <Fog::Proxmox::Compute::ServerConfig
233
+ smbios1: "uuid=ba2da6bd-0c92-4cfe-8f70-d22cc5b5bba2",
234
+ numa: 0,
235
+ digest: "348fdc21536f23a29dfb9b3120faa124aaeec742",
236
+ ostype: "l26",
237
+ cores: 1,
238
+ virtio0: "local-lvm:vm-100-disk-1,size=1G",
239
+ bootdisk: "virtio0",
240
+ scsihw: "virtio-scsi-pci",
241
+ sockets: 1,
242
+ net0: "virtio=8E:BF:3E:E7:17:0D,bridge=vmbr0",
243
+ memory: 512,
244
+ name: "test",
245
+ ide2: "cdrom,media=cdrom",
246
+ server: <Fog::Proxmox::Compute::Server vmid: 100, ...>
247
+ >
248
+ ```
249
+
250
+ Get nics config:
251
+
252
+ ```ruby
253
+ nics = server.config.interfaces
254
+ ```
255
+
256
+ This returns a hash:
257
+
258
+ ```ruby
259
+ nics = {net0: 'virtio=8E:BF:3E:E7:17:0D,bridge=vmbr0'}
260
+ ```
261
+
262
+ Get IDE,SATA,SCSI or VirtIO controllers config:
263
+
264
+ ```ruby
265
+ disks = server.config.disks
266
+ ```
267
+
268
+ This returns a hash:
269
+
270
+ ```ruby
271
+ disks = {ide2: 'cdrom,media=cdrom', virtio0: "local-lvm:vm-100-disk-1,size=1G", sata0: "local-lvm:vm-100-disk-2,size=1G"}
272
+ ```
273
+
274
+ ##### Console
275
+
276
+ VNC, SPICE and terminal consoles are availables.
277
+
278
+ Server needs to be running and a VGA display configured.
279
+
280
+ Default VGA set to `std` implies vnc console:
281
+
282
+ ```ruby
283
+ vnc_console = server.start_console(websocket: 1)
284
+ server.connect_vnc(vnc_console)
285
+ ```
286
+
287
+ returns a vnc session hash,
288
+
289
+ and set to `qxl` implies spice console:
290
+
291
+ ```ruby
292
+ spice_console = server.start_console(proxy: 'localhost')
293
+ ```
294
+
295
+ returns a spice session hash,
296
+
297
+
298
+ and set to `serial0` implies terminal console:
299
+
300
+ ```ruby
301
+ term_console = server.start_console
302
+ ```
303
+
304
+ returns a term session hash.
305
+
306
+ ##### Volumes server management
307
+
308
+ Before attaching a hdd volume, you can first fetch available storages that could have images in this node:
309
+
310
+ ```ruby
311
+ storages = node.storages.list_by_content_type 'images'
312
+ storage = storages[0] # local-lvm
313
+ ```
314
+
315
+ Four types of storage controllers emulated by Qemu are available:
316
+
317
+ * **IDE**: ide[n], n in [0..3]
318
+ * **SATA**: sata[n], n in [0..5]
319
+ * **SCSI**: scsi[n], n in [0..13]
320
+ * **VirtIO Block**: virtio[n], n in [0..15]
321
+
322
+ The hdd id is the type controller appended with an integer (n).
323
+
324
+ More details on complete configuration options can be find in [Proxmox VE API](https://pve.proxmox.com/wiki/Proxmox_VE_API).
325
+
326
+ Then attach a hdd from this storage:
327
+
328
+ ```ruby
329
+ disk = { id: 'virtio0', storage: storage.storage, size: '1' } # virtualIO block with 1Gb
330
+ options = { backup: 0, replicate: 0 } # nor backup, neither replication
331
+ server.attach(disk, options)
332
+ ```
333
+
334
+ Resize a disk:
335
+
336
+ ```ruby
337
+ server.extend('virtio0','+1G')
338
+ ```
339
+
340
+ Move a disk
341
+
342
+ ```ruby
343
+ server.move('virtio0','local')
344
+ ```
345
+
346
+ Detach a disk
347
+
348
+ ```ruby
349
+ server.detach 'virtio0'
350
+ ```
351
+
352
+ Actions on your server:
353
+
354
+ ```ruby
355
+ server.action('start') # start your server
356
+ server.wait_for { server.ready? } # wait until it is running
357
+ server.ready? # you can check if it is ready (i.e. running)
358
+ ```
359
+
360
+ ```ruby
361
+ server.action('suspend') # pause your server
362
+ server.wait_for { server.qmpstatus == 'paused' } # wait until it is paused
363
+ ```
364
+
365
+ ```ruby
366
+ server.action('resume') # resume your server
367
+ server.wait_for { server.ready? } # wait until it is running
368
+ ```
369
+
370
+ ```ruby
371
+ server.action('stop') # stop your server
372
+ server.wait_for { server.status == 'stopped' } # wait until it is stopped
373
+ ```
374
+
375
+ Fetch server disk_images:
376
+
377
+ ```ruby
378
+ disk_images = server.disk_images
379
+ ```
380
+
381
+ This returns an array of `Fog::Proxmox::Compute::Volume` instances.
382
+
383
+ Delete server:
384
+
385
+ ```ruby
386
+ server.destroy
387
+ ```
388
+
389
+ ##### Backup and restore server
390
+
391
+ You can backup all node's guests or just one guest.
392
+
393
+ You need first to get a node or a server to manage its backups:
394
+
395
+ ```ruby
396
+ node = compute.nodes.get 'pve'
397
+ server = node.servers.get vmid
398
+ ```
399
+
400
+ Then you can backup one server:
401
+
402
+ ```ruby
403
+ options = { compress: 'lzo'}
404
+ server.backup options
405
+ ```
406
+
407
+ or backup all servers on a node:
408
+
409
+ ```ruby
410
+ node.backup options
411
+ ```
412
+
413
+ You can restore a server from a backup.
414
+ Backups are volumes which content type is `backup` and owned by a server.
415
+
416
+ You first fetch the backup volumes of this server:
417
+
418
+ ```ruby
419
+ volumes = server.backups
420
+ ```
421
+
422
+ This returns an array of `Fog::Proxmox::Compute::Volume` instances.
423
+
424
+ Then you choose one:
425
+
426
+ ```ruby
427
+ backup = volumes[0] # local:backup/vzdump-qemu-100-2018_05_15-15_18_31.vma.lzo
428
+ ```
429
+
430
+ This returns a `Fog::Proxmox::Compute::Volume` instance:
431
+
432
+ ```ruby
433
+ <Fog::Proxmox::Compute::Volume
434
+ volid="local:backup/vzdump-qemu-100-2018_05_15-15_18_31.vma.lzo",
435
+ content="backup",
436
+ size=376,
437
+ format="vma.lzo",
438
+ node=nil,
439
+ storage=nil,
440
+ vmid="100"
441
+ >
442
+ ```
443
+
444
+ Then you can restore it:
445
+
446
+ ```ruby
447
+ options = { compress: 'lzo'}
448
+ server.restore backup
449
+ ```
450
+
451
+ You can delete it:
452
+
453
+ ```ruby
454
+ backup.delete
455
+ ```
456
+
457
+ More details on complete backup `options` configuration hash can be find in [Backup and restore wiki page](https://pve.proxmox.com/wiki/Backup_and_Restore).
458
+
459
+ ##### Snapshots server management
460
+
461
+ You need first to get a server to manage its snapshots:
462
+
463
+ ```ruby
464
+ server = node.servers.get vmid
465
+ ```
466
+
467
+ Then you can create a snapshot on it:
468
+
469
+ ```ruby
470
+ snapname = 'snapshot1' # you define its id
471
+ server.snapshots.create snapname
472
+ ```
473
+
474
+ Get a snapshot:
475
+
476
+ ```ruby
477
+ snapshot = server.snapshots.get snapname
478
+ ```
479
+
480
+ Add description:
481
+
482
+ ```ruby
483
+ snapshot.description = 'Snapshot 1'
484
+ snapshot.update
485
+ ```
486
+
487
+ Rollback server to this snapshot:
488
+
489
+ ```ruby
490
+ snapshot.rollback
491
+ ```
492
+
493
+ Delete snapshot:
494
+
495
+ ```ruby
496
+ snapshot.destroy
497
+ ```
498
+
499
+ ##### Clones server management
500
+
501
+ Proxmox supports cloning servers. It creates a new VM as a copy of the server.
502
+
503
+ You need first to get a server to manage its clones and a valid new VM id:
504
+
505
+ ```ruby
506
+ server = node.servers.get vmid
507
+ newid = node.servers.next_id
508
+ ```
509
+
510
+ Then you can clone it:
511
+
512
+ ```ruby
513
+ server.clone(newid)
514
+ ```
515
+
516
+ It creates a new server which id is newid. So you can manage it as a server.
517
+
518
+ Destroy the clone:
519
+
520
+ ```ruby
521
+ clone = node.servers.get newid
522
+ clone.destroy
523
+ ```
524
+
525
+ #### Containers management
526
+
527
+ Proxmox supports Linux containers management.
528
+
529
+ Containers are LXC managed. They are attached to a node.
530
+
531
+ More details in [Proxmox Linux Containers management wiki page](https://pve.proxmox.com/wiki/Linux_Container)
532
+
533
+ You need to specify a node before managing Containers. Fog-proxmox enables it by managing Containers from a node.
534
+
535
+ List all containers:
536
+
537
+ ```ruby
538
+ node.containers.all
539
+ ```
540
+
541
+ This returns a collection of `Fog::Proxmox::Identity::Container` models which are inherited from `Fog::Proxmox::Identity::Server` because they have many common features.
542
+
543
+ Before creating a container you can get the next available container id (integer >= 100) in the cluster:
544
+
545
+ ```ruby
546
+ nextid = node.containers.next_id
547
+ ```
548
+
549
+ You can also verify that an id is free or valid:
550
+
551
+ ```ruby
552
+ node.containers.id_valid? nextid
553
+ ```
554
+
555
+ Now that you have a valid id, you can create a container in this node.
556
+ Before creating the container, you need to have an available template uploaded into the cluster.
557
+ You can define the rootfs volume (1G), a root password and a SSH public key.
558
+
559
+ ```ruby
560
+ ostemplate = 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz'
561
+ container_hash = { vmid: vmid, storage: 'local-lvm',
562
+ ostemplate: ostemplate, password: 'proxmox01',
563
+ rootfs: 'local-lvm:1' }
564
+ node.containers.create container_hash
565
+ ```
566
+
567
+ Get this container:
568
+
569
+ ```ruby
570
+ container = node.containers.get nextid
571
+ ```
572
+
573
+ Add options: boot at startup, OS type (alpine):
574
+
575
+ ```ruby
576
+ container.update({ onboot: 1, ostype: 'alpine' })
577
+ ```
578
+
579
+ Add a network interface controller (nic):
580
+
581
+ ```ruby
582
+ container.update({ net0: 'bridge=vmbr0,name=eth0,ip=dhcp,ip6=dhcp' })
583
+ ```
584
+
585
+ Fetch all nics:
586
+
587
+ ```ruby
588
+ nics = container.config.nics
589
+ ```
590
+
591
+ This returns a hash:
592
+
593
+ ```ruby
594
+ nics = { net0: 'bridge=vmbr0,name=eth0,ip=dhcp,ip6=dhcp' }
595
+ ```
596
+
597
+ Get mac adresses generated by Proxmox:
598
+
599
+ ```ruby
600
+ container.config.mac_adresses
601
+ ```
602
+
603
+ This returns an array of strings.
604
+
605
+ Get container configuration:
606
+
607
+ ```ruby
608
+ container.config
609
+ ```
610
+
611
+ This returns a `Fog::Proxmox::Compute::ContainerConfig` model:
612
+
613
+ ```ruby
614
+ <Fog::Proxmox::Compute::ContainerConfig
615
+ memory: 512,
616
+ net0: "name=eth0,bridge=vmbr0,hwaddr=BE:3C:A9:3F:4E:39,ip=dhcp,ip6=dhcp,type=veth",
617
+ swap: 512,
618
+ cores: 1,
619
+ rootfs: "local-lvm:vm-100-disk-1,size=1G",
620
+ hostname: "CT100",
621
+ digest: "e5131befed2f6ff8e11d598c4d8bb6016d5c0901",
622
+ ostype: "alpine",
623
+ arch: "amd64"
624
+ container: <Fog::Proxmox::Compute::Container vmid: 100, ...>
625
+ >
626
+ ```
627
+
628
+ ##### Volumes container management
629
+
630
+ Before attaching a volume, you can first fetch available storages that could have images in this node:
631
+
632
+ ```ruby
633
+ storages = node.storages.list_by_content_type 'images'
634
+ storage = storages[0] # local-lvm
635
+ ```
636
+
637
+ A default and minimum volume is called `rootfs`.
638
+ Additional volumes could be attached to a container and are called mount points:
639
+
640
+ * **Mount points**: mp[n], n in [0..9]
641
+
642
+ The mount points id is `mp` appended with an integer (n).
643
+
644
+ More details on complete configuration options can be find in [Proxmox VE Linux Container](https://pve.proxmox.com/wiki/Linux_Container).
645
+
646
+ Then attach a volume from this storage:
647
+
648
+ ```ruby
649
+ mp0 = { id: 'mp0', storage: storage.storage, size: '1' }
650
+ options = { mp: '/opt/app', backup: 0, replicate: 0, quota: 1 }
651
+ container.attach(mp0, options)
652
+ ```
653
+
654
+ Extend a volume:
655
+
656
+ ```ruby
657
+ container.extend('rootfs', '+5M') # add 5Mb to rootfs volume
658
+ ```
659
+
660
+ Move a volume:
661
+
662
+ ```ruby
663
+ container.move('rootfs', 'local-lvm', delete: 1) # move rootfs and delete original
664
+ ```
665
+
666
+ Detach a volume
667
+
668
+ ```ruby
669
+ container.detach('mp0') # detach
670
+ container.detach('unused0') # remove
671
+ ```
672
+
673
+ Actions on your container:
674
+
675
+ ```ruby
676
+ container.action('start') # start your container
677
+ container.wait_for { container.ready? } # wait until it is running
678
+ container.ready? # you can check if it is ready (i.e. running)
679
+ ```
680
+
681
+ ```ruby
682
+ container.action('stop') # stop your container
683
+ container.wait_for { container.status == 'stopped' } # wait until it is stopped
684
+ ```
685
+
686
+ Resume, suspend actions are not implemented.
687
+
688
+ Fetch container mount points:
689
+
690
+ ```ruby
691
+ mount_points = container.config.mount_points
692
+ ```
693
+
694
+ This returns a hash:
695
+
696
+ ```ruby
697
+ mount_points = { mp0: "local-lvm:vm-100-disk-2,mp=/opt/app,size=1G" }
698
+ ```
699
+
700
+ Delete container:
701
+
702
+ ```ruby
703
+ container.destroy
704
+ ```
705
+
706
+ ##### Backup and restore container
707
+
708
+ You can backup all node's guests or just one guest.
709
+
710
+ You need first to get a node or a container to manage its backups:
711
+
712
+ ```ruby
713
+ node = compute.nodes.get 'pve'
714
+ container = node.containers.get vmid
715
+ ```
716
+
717
+ Then you can backup one container:
718
+
719
+ ```ruby
720
+ options = { compress: 'lzo'}
721
+ container.backup options
722
+ ```
723
+
724
+ or backup all containers and servers on a node:
725
+
726
+ ```ruby
727
+ node.backup options
728
+ ```
729
+
730
+ You can restore a container from a backup.
731
+ Backups are volumes which content type is `backup` and owned by a container.
732
+
733
+ You first fetch the backup volumes of this container:
734
+
735
+ ```ruby
736
+ volumes = container.backups
737
+ ```
738
+
739
+ This returns an array of `Fog::Proxmox::Compute::Volume` instances.
740
+
741
+ Then you choose one:
742
+
743
+ ```ruby
744
+ backup = volumes[0] # local:backup/vzdump-qemu-100-2018_05_15-15_18_31.vma.lzo
745
+ ```
746
+
747
+ This returns a `Fog::Proxmox::Compute::Volume` instance:
748
+
749
+ ```ruby
750
+ <Fog::Proxmox::Compute::Volume
751
+ volid="local:backup/vzdump-qemu-100-2018_05_15-15_18_31.vma.lzo",
752
+ content="backup",
753
+ size=376,
754
+ format="vma.lzo",
755
+ node=nil,
756
+ storage=nil,
757
+ vmid="100"
758
+ >
759
+ ```
760
+
761
+ Then you can restore it:
762
+
763
+ ```ruby
764
+ options = { compress: 'lzo'}
765
+ container.restore backup
766
+ ```
767
+
768
+ You can delete it:
769
+
770
+ ```ruby
771
+ backup.delete
772
+ ```
773
+
774
+ More details on complete backup `options` configuration hash can be find in [Backup and restore wiki page](https://pve.proxmox.com/wiki/Backup_and_Restore).
775
+
776
+ ##### Snapshots container management
777
+
778
+ You need first to get a container to manage its snapshots:
779
+
780
+ ```ruby
781
+ container = node.containers.get vmid
782
+ ```
783
+
784
+ Then you can create a snapshot on it:
785
+
786
+ ```ruby
787
+ snapname = 'snapshot1' # you define its id
788
+ container.snapshots.create snapname
789
+ ```
790
+
791
+ Get a snapshot:
792
+
793
+ ```ruby
794
+ snapshot = container.snapshots.get snapname
795
+ ```
796
+
797
+ Add description:
798
+
799
+ ```ruby
800
+ snapshot.description = 'Snapshot 1'
801
+ snapshot.update
802
+ ```
803
+
804
+ Rollback container to this snapshot:
805
+
806
+ ```ruby
807
+ snapshot.rollback
808
+ ```
809
+
810
+ Delete snapshot:
811
+
812
+ ```ruby
813
+ snapshot.destroy
814
+ ```
815
+
816
+ ##### Clones container management
817
+
818
+ Proxmox supports cloning containers. It creates a new container as a copy of the original container.
819
+
820
+ You need first to get a container to manage its clones and a valid new container id:
821
+
822
+ ```ruby
823
+ container = node.containers.get vmid
824
+ newid = node.containers.next_id
825
+ ```
826
+
827
+ Then you can clone it:
828
+
829
+ ```ruby
830
+ container.clone(newid)
831
+ ```
832
+
833
+ It creates a new container which id is newid. So you can manage it as a container.
834
+
835
+ Destroy the clone:
836
+
837
+ ```ruby
838
+ clone = node.containers.get newid
839
+ clone.destroy
840
+ ```
841
+
842
+ #### Tasks management
843
+
844
+ Proxmox supports tasks management. A task enables to follow all asynchronous actions made in a node: VM creation, start, etc. Indeed, some of these tasks could be long to execute.
845
+
846
+ You need first to get a node to manage its tasks:
847
+
848
+ ```ruby
849
+ node = compute.nodes.find_by_id 'pve'
850
+ ```
851
+
852
+ Search tasks (limit results to 1):
853
+
854
+ ```ruby
855
+ tasks = node.tasks.search { limit: 1 }
856
+ ```
857
+
858
+ Get a task by its id. This id can be retrieved as a result of an action:
859
+
860
+ ```ruby
861
+ taskid = snapshot.destroy
862
+ task = node.tasks.find_by_id taskid
863
+ task.wait_for { succeeded? }
864
+ ```
865
+
866
+ Stop a task:
867
+
868
+ ```ruby
869
+ task.stop
870
+ ```
871
+
872
+ ### Examples
873
+
874
+ More examples can be seen at [examples/compute.rb](examples/compute.rb) or [spec/compute_spec.rb](spec/compute_spec.rb).