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