fog-proxmox 0.13.0

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