fog-proxmox 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/fog-proxmox.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copyright 2018 Tristan Robert
|
3
|
+
|
4
|
+
# This file is part of Fog::Proxmox.
|
5
|
+
|
6
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
|
11
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
18
|
+
|
19
|
+
# frozen_string_literal: true
|
20
|
+
|
21
|
+
lib = File.expand_path('lib', __dir__)
|
22
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
23
|
+
require 'fog/proxmox/version'
|
24
|
+
|
25
|
+
Gem::Specification.new do |spec|
|
26
|
+
spec.name = 'fog-proxmox'
|
27
|
+
spec.version = Fog::Proxmox::VERSION
|
28
|
+
spec.authors = ['Tristan Robert']
|
29
|
+
spec.email = ['tristan.robert.44@gmail.com']
|
30
|
+
|
31
|
+
spec.summary = "Module for the 'Fog' gem to support Proxmox VE"
|
32
|
+
spec.description = 'This library can be used as a module for `fog`.'
|
33
|
+
spec.homepage = 'http://github.com/fog/fog-proxmox'
|
34
|
+
spec.license = 'GPL-3.0'
|
35
|
+
|
36
|
+
spec.files = `git ls-files -z`.split("\x0")
|
37
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
38
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
39
|
+
spec.require_paths = ['lib']
|
40
|
+
spec.required_ruby_version = '>= 2.3'
|
41
|
+
spec.rubygems_version = '~> 2.6'
|
42
|
+
|
43
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
44
|
+
spec.add_development_dependency 'debase', '~> 0.2.2'
|
45
|
+
spec.add_development_dependency 'debride', '~> 1.8'
|
46
|
+
spec.add_development_dependency 'fasterer', '~> 0.3'
|
47
|
+
spec.add_development_dependency 'fastri', '~> 0.3'
|
48
|
+
spec.add_development_dependency 'minitest', '~> 5.11'
|
49
|
+
spec.add_development_dependency 'pry', '~> 0.11'
|
50
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
51
|
+
spec.add_development_dependency 'rcodetools', '~> 0.3'
|
52
|
+
spec.add_development_dependency 'reek', '~> 4.7'
|
53
|
+
spec.add_development_dependency 'rspec', '~> 3.7'
|
54
|
+
spec.add_development_dependency 'rubocop', '~> 0.55'
|
55
|
+
spec.add_development_dependency 'ruby-debug-ide', '~> 0.6'
|
56
|
+
spec.add_development_dependency 'simplecov'
|
57
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
58
|
+
spec.add_development_dependency 'webmock', '~> 3.4'
|
59
|
+
|
60
|
+
spec.add_dependency 'fog-core', '~> 1.45'
|
61
|
+
spec.add_dependency 'fog-json', '~> 1.0'
|
62
|
+
spec.add_dependency 'ipaddress', '~> 0.8'
|
63
|
+
end
|
data/fogproxmox.png
ADDED
Binary file
|
@@ -0,0 +1,131 @@
|
|
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 'fog/proxmox/core'
|
21
|
+
|
22
|
+
module Fog
|
23
|
+
module Compute
|
24
|
+
# Proxmox compute service
|
25
|
+
class Proxmox < Fog::Service
|
26
|
+
requires :pve_url
|
27
|
+
recognizes :pve_ticket, :pve_path, :pve_ticket_expires,
|
28
|
+
:pve_csrftoken, :persistent, :current_user, :pve_username,
|
29
|
+
:pve_password, :pve_deadline
|
30
|
+
|
31
|
+
# Models
|
32
|
+
model_path 'fog/compute/proxmox/models'
|
33
|
+
model :node
|
34
|
+
collection :nodes
|
35
|
+
model :server
|
36
|
+
collection :servers
|
37
|
+
model :interface
|
38
|
+
collection :interfaces
|
39
|
+
model :disk
|
40
|
+
collection :disks
|
41
|
+
model :server_config
|
42
|
+
model :volume
|
43
|
+
collection :volumes
|
44
|
+
model :storage
|
45
|
+
collection :storages
|
46
|
+
model :task
|
47
|
+
collection :tasks
|
48
|
+
model :snapshot
|
49
|
+
collection :snapshots
|
50
|
+
model :container
|
51
|
+
collection :containers
|
52
|
+
model :container_config
|
53
|
+
|
54
|
+
# Requests
|
55
|
+
request_path 'fog/compute/proxmox/requests'
|
56
|
+
|
57
|
+
# Manage nodes cluster
|
58
|
+
request :list_nodes
|
59
|
+
request :get_node
|
60
|
+
# Manage servers
|
61
|
+
request :next_vmid
|
62
|
+
request :check_vmid
|
63
|
+
request :list_servers
|
64
|
+
request :create_server
|
65
|
+
request :get_server_status
|
66
|
+
request :get_server_config
|
67
|
+
request :update_server
|
68
|
+
request :delete_server
|
69
|
+
request :action_server
|
70
|
+
request :template_server
|
71
|
+
request :clone_server
|
72
|
+
request :migrate_server
|
73
|
+
request :move_disk
|
74
|
+
request :move_volume
|
75
|
+
request :resize_server
|
76
|
+
request :resize_container
|
77
|
+
# Manage volumes
|
78
|
+
request :list_volumes
|
79
|
+
request :get_volume
|
80
|
+
request :delete_volume
|
81
|
+
# Manage backups
|
82
|
+
request :create_backup
|
83
|
+
# Manage storages
|
84
|
+
request :list_storages
|
85
|
+
request :get_storage
|
86
|
+
# Tasks
|
87
|
+
request :list_tasks
|
88
|
+
request :get_task
|
89
|
+
request :stop_task
|
90
|
+
request :status_task
|
91
|
+
request :log_task
|
92
|
+
# CRUD snapshots
|
93
|
+
request :list_snapshots
|
94
|
+
request :get_snapshot
|
95
|
+
request :create_snapshot
|
96
|
+
request :update_snapshot
|
97
|
+
request :delete_snapshot
|
98
|
+
request :rollback_snapshot
|
99
|
+
# Consoles
|
100
|
+
request :create_term
|
101
|
+
request :create_spice
|
102
|
+
request :create_vnc
|
103
|
+
request :get_vnc
|
104
|
+
|
105
|
+
# Mock class
|
106
|
+
class Mock
|
107
|
+
attr_reader :config
|
108
|
+
|
109
|
+
def initialize(options = {})
|
110
|
+
@pve_uri = URI.parse(options[:pve_url])
|
111
|
+
@pve_path = @pve_uri.path
|
112
|
+
@config = options
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Real class
|
117
|
+
class Real
|
118
|
+
include Fog::Proxmox::Core
|
119
|
+
def initialize(options = {})
|
120
|
+
initialize_identity(options)
|
121
|
+
@connection_options = options[:connection_options] || {}
|
122
|
+
@path_prefix = URI.parse(options[:pve_url]).path
|
123
|
+
authenticate
|
124
|
+
@persistent = options[:persistent] || false
|
125
|
+
url = "#{@scheme}://#{@host}:#{@port}"
|
126
|
+
@connection = Fog::Core::Connection.new(url, @persistent, @connection_options.merge(path_prefix: @path_prefix))
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,97 @@
|
|
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 'fog/compute/proxmox/models/server'
|
21
|
+
require 'fog/compute/proxmox/models/container_config'
|
22
|
+
|
23
|
+
module Fog
|
24
|
+
module Compute
|
25
|
+
class Proxmox
|
26
|
+
# Container model
|
27
|
+
class Container < Fog::Compute::Proxmox::Server
|
28
|
+
identity :vmid
|
29
|
+
attribute :lock
|
30
|
+
attribute :maxswap
|
31
|
+
attribute :swap
|
32
|
+
attribute :config
|
33
|
+
|
34
|
+
def initialize(attributes = {})
|
35
|
+
prepare_service_value(attributes)
|
36
|
+
set_config(attributes)
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
def type(attributes = {})
|
41
|
+
@type ||= 'lxc' unless attributes[:type] || attributes['type']
|
42
|
+
@type
|
43
|
+
end
|
44
|
+
|
45
|
+
def restore(backup, options = {})
|
46
|
+
requires :node, :vmid
|
47
|
+
path_params = { node: node, type: type }
|
48
|
+
body_params = options.merge(vmid: vmid, ostemplate: backup.volid, force: 1, restore: 1)
|
49
|
+
task_upid = service.create_server(path_params, body_params)
|
50
|
+
tasks.wait_for(task_upid)
|
51
|
+
end
|
52
|
+
|
53
|
+
def move(volume, storage, options = {})
|
54
|
+
requires :vmid, :node
|
55
|
+
path_params = { node: node, vmid: vmid }
|
56
|
+
body_params = options.merge(volume: volume, storage: storage)
|
57
|
+
task_upid = service.move_volume(path_params, body_params)
|
58
|
+
tasks.wait_for(task_upid)
|
59
|
+
end
|
60
|
+
|
61
|
+
def update(config = {})
|
62
|
+
requires :node, :vmid
|
63
|
+
path_params = { node: node, type: type, vmid: vmid }
|
64
|
+
body_params = config
|
65
|
+
service.update_server(path_params, body_params)
|
66
|
+
end
|
67
|
+
|
68
|
+
def set_config(attributes = {})
|
69
|
+
@config = Fog::Compute::Proxmox::ContainerConfig.new({ service: service }.merge(attributes))
|
70
|
+
end
|
71
|
+
|
72
|
+
def config
|
73
|
+
path_params = { node: node, type: type, vmid: vmid }
|
74
|
+
set_config(service.get_server_config(path_params)) if uptime
|
75
|
+
@config
|
76
|
+
end
|
77
|
+
|
78
|
+
def detach(mpid)
|
79
|
+
update(delete: mpid)
|
80
|
+
end
|
81
|
+
|
82
|
+
def extend(disk, size, options = {})
|
83
|
+
requires :vmid, :node
|
84
|
+
path_params = { node: node, vmid: vmid }
|
85
|
+
body_params = options.merge(disk: disk, size: size)
|
86
|
+
task_upid = service.resize_container(path_params, body_params)
|
87
|
+
tasks.wait_for(task_upid)
|
88
|
+
end
|
89
|
+
|
90
|
+
def action(action, options = {})
|
91
|
+
raise Fog::Errors::Error, "Action #{action} not implemented" unless %w[start stop shutdown].include? action
|
92
|
+
super
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,90 @@
|
|
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 'fog/proxmox/variables'
|
21
|
+
require 'fog/proxmox/helpers/nic_helper'
|
22
|
+
|
23
|
+
module Fog
|
24
|
+
module Compute
|
25
|
+
class Proxmox
|
26
|
+
# ContainerConfig model
|
27
|
+
class ContainerConfig < Fog::Proxmox::Model
|
28
|
+
identity :digest
|
29
|
+
attribute :ostype
|
30
|
+
attribute :arch
|
31
|
+
attribute :memory
|
32
|
+
attribute :swap
|
33
|
+
attribute :hostname
|
34
|
+
attribute :onboot
|
35
|
+
attribute :rootfs
|
36
|
+
attribute :interfaces
|
37
|
+
attribute :mount_points
|
38
|
+
|
39
|
+
def initialize(attributes = {})
|
40
|
+
prepare_service_value(attributes)
|
41
|
+
compute_nets(attributes)
|
42
|
+
compute_mps(attributes)
|
43
|
+
super(attributes)
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_reader :interfaces
|
47
|
+
|
48
|
+
attr_reader :mount_points
|
49
|
+
|
50
|
+
def mac_addresses
|
51
|
+
Fog::Proxmox::NicHelper.to_mac_adresses_array(interfaces)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def compute_nets(attributes)
|
57
|
+
nets = Fog::Proxmox::ControllerHelper.to_hash(attributes, Fog::Compute::Proxmox::Interface::NAME)
|
58
|
+
@interfaces ||= Fog::Compute::Proxmox::Interfaces.new
|
59
|
+
nets.each do |key, value|
|
60
|
+
nic_hash = {
|
61
|
+
id: key.to_s,
|
62
|
+
name: Fog::Proxmox::NicHelper.extract_name(value),
|
63
|
+
mac: Fog::Proxmox::NicHelper.extract_mac_address(value)
|
64
|
+
}
|
65
|
+
names = Fog::Compute::Proxmox::Interface.attributes.reject { |key, _value| %i[id mac name].include? key }
|
66
|
+
names.each { |name| nic_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
|
67
|
+
@interfaces << Fog::Compute::Proxmox::Interface.new(nic_hash)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def compute_mps(attributes)
|
72
|
+
mps = Fog::Proxmox::ControllerHelper.to_hash(attributes, 'mp')
|
73
|
+
@mount_points ||= Fog::Compute::Proxmox::Disks.new
|
74
|
+
mps.each do |key, value|
|
75
|
+
storage, volid, size = Fog::Proxmox::DiskHelper.extract_storage_volid_size(value)
|
76
|
+
disk_hash = {
|
77
|
+
id: key.to_s,
|
78
|
+
storage: storage,
|
79
|
+
volid: volid,
|
80
|
+
size: size
|
81
|
+
}
|
82
|
+
names = Fog::Compute::Proxmox::Disk.attributes.reject { |key, _value| %i[id size storage].include? key }
|
83
|
+
names.each { |name| disk_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
|
84
|
+
@mount_points << Fog::Compute::Proxmox::Disk.new(disk_hash)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,40 @@
|
|
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 'fog/compute/proxmox/models/server'
|
21
|
+
|
22
|
+
module Fog
|
23
|
+
module Compute
|
24
|
+
class Proxmox
|
25
|
+
# Containers Collection
|
26
|
+
class Containers < Fog::Compute::Proxmox::Servers
|
27
|
+
model Fog::Compute::Proxmox::Container
|
28
|
+
|
29
|
+
def new(attributes = {})
|
30
|
+
super({ node: node, type: type }.merge(attributes))
|
31
|
+
end
|
32
|
+
|
33
|
+
def type(attributes = {})
|
34
|
+
@type ||= 'lxc' unless attributes[:type] || attributes['type']
|
35
|
+
@type
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Copyright 2018 Tristan Robert
|
3
|
+
|
4
|
+
# This file is part of Fog::Proxmox.
|
5
|
+
|
6
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation, either version 3 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
# Copyright 2018 Tristan Robert
|
11
|
+
|
12
|
+
# This file is part of Fog::Proxmox.
|
13
|
+
|
14
|
+
# Fog::Proxmox is free software: you can redistribute it and/or modify
|
15
|
+
# it under the terms of the GNU General Public License as published by
|
16
|
+
# the Free Software Foundation, either version 3 of the License, or
|
17
|
+
# (at your option) any later version.
|
18
|
+
|
19
|
+
# Fog::Proxmox is distributed in the hope that it will be useful,
|
20
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22
|
+
# GNU General Public License for more details.
|
23
|
+
|
24
|
+
# You should have received a copy of the GNU General Public License
|
25
|
+
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
26
|
+
|
27
|
+
# frozen_string_literal: true
|
28
|
+
|
29
|
+
require 'fog/proxmox/models/model'
|
30
|
+
require 'fog/proxmox/helpers/disk_helper'
|
31
|
+
|
32
|
+
module Fog
|
33
|
+
module Compute
|
34
|
+
class Proxmox
|
35
|
+
# class Disk model
|
36
|
+
class Disk < Fog::Proxmox::Model
|
37
|
+
identity :id
|
38
|
+
attribute :volid
|
39
|
+
attribute :size
|
40
|
+
attribute :storage
|
41
|
+
attribute :cache
|
42
|
+
attribute :replicate
|
43
|
+
attribute :media
|
44
|
+
attribute :format
|
45
|
+
attribute :model
|
46
|
+
attribute :shared
|
47
|
+
attribute :snapshot
|
48
|
+
attribute :backup
|
49
|
+
attribute :aio
|
50
|
+
|
51
|
+
CONTROLLERS = %w[ide sata scsi virtio].freeze
|
52
|
+
|
53
|
+
def controller
|
54
|
+
Fog::Proxmox::DiskHelper.extract_controller(id)
|
55
|
+
end
|
56
|
+
|
57
|
+
def device
|
58
|
+
Fog::Proxmox::DiskHelper.extract_device(id)
|
59
|
+
end
|
60
|
+
|
61
|
+
def cdrom?
|
62
|
+
id == 'ide2' && media == 'cdrom'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|