fog-proxmox 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/docs/compute.md +23 -7
- data/docs/identity.md +31 -6
- data/examples/compute.rb +11 -11
- data/examples/identity.rb +28 -15
- data/fog-proxmox.gemspec +1 -1
- data/lib/fog/proxmox.rb +16 -76
- data/lib/fog/proxmox/auth/token.rb +88 -0
- data/lib/fog/proxmox/auth/token/access_ticket.rb +85 -0
- data/lib/fog/proxmox/auth/token/user_token.rb +94 -0
- data/lib/fog/{compute/proxmox.rb → proxmox/compute.rb} +31 -16
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/disk.rb +15 -2
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/disks.rb +5 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/interface.rb +4 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/interfaces.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/node.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/nodes.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/server.rb +2 -2
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/server_config.rb +8 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/servers.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshots.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/storage.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/storages.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/tasks.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/volume.rb +6 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/volumes.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/action_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/clone_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_backup.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_spice.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_term.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_vnc.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_volume.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_node_statistics.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_config.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_status.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_snapshot_config.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_vnc.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_volume.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_nodes.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_servers.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_snapshots.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_storages.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_tasks.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_volumes.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/log_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/migrate_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_disk.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_volume.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/next_vmid.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_container.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/rollback_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/status_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/stop_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/template_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_snapshot.rb +0 -0
- data/lib/fog/proxmox/core.rb +66 -57
- data/lib/fog/proxmox/hash.rb +2 -2
- data/lib/fog/proxmox/helpers/cpu_helper.rb +48 -9
- data/lib/fog/proxmox/helpers/disk_helper.rb +42 -22
- data/lib/fog/proxmox/helpers/nic_helper.rb +28 -20
- data/lib/fog/{identity/proxmox.rb → proxmox/identity.rb} +31 -17
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain_type.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/domains.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/group.rb +4 -2
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/groups.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/permission.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/permissions.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/pools.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/principal.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/role.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/roles.rb +1 -1
- data/lib/fog/proxmox/identity/models/token.rb +71 -0
- data/lib/fog/proxmox/identity/models/token_info.rb +41 -0
- data/lib/fog/proxmox/identity/models/tokens.rb +58 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/user.rb +25 -2
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/users.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/change_password.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/check_permissions.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/create_token.rb +40 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_user.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/delete_token.rb +40 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_user.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/get_token_info.rb +41 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_user.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_domains.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_groups.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_permissions.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_pools.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_roles.rb +0 -0
- data/lib/fog/proxmox/identity/requests/list_tokens.rb +41 -0
- data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +44 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_users.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/read_version.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_permissions.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/update_token.rb +41 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_user.rb +0 -0
- data/lib/fog/{network/proxmox.rb → proxmox/network.rb} +21 -14
- data/lib/fog/{network/proxmox → proxmox/network}/models/network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/models/networks.rb +1 -1
- data/lib/fog/{network/proxmox → proxmox/network}/models/node.rb +1 -1
- data/lib/fog/{network/proxmox → proxmox/network}/models/nodes.rb +1 -1
- data/lib/fog/{network/proxmox → proxmox/network}/requests/create_network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/delete_network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/get_network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/get_node.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/list_networks.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/list_nodes.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/power_node.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/update_network.rb +0 -0
- data/lib/fog/{storage/proxmox.rb → proxmox/storage.rb} +1 -1
- data/lib/fog/proxmox/version.rb +1 -1
- data/spec/compute_spec.rb +4 -4
- data/spec/fixtures/proxmox/compute/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/compute/containers.yml +1752 -7568
- data/spec/fixtures/proxmox/compute/nodes.yml +24 -30
- data/spec/fixtures/proxmox/compute/servers.yml +5015 -10683
- data/spec/fixtures/proxmox/compute/snapshots.yml +479 -1719
- data/spec/fixtures/proxmox/compute/storages.yml +32 -40
- data/spec/fixtures/proxmox/compute/tasks.yml +118 -338
- data/spec/fixtures/proxmox/identity/auth.yml +10 -12
- data/spec/fixtures/proxmox/identity/auth_access_ticket.yml +77 -0
- data/spec/fixtures/proxmox/identity/auth_user_token.yml +77 -0
- data/spec/fixtures/proxmox/identity/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/identity/domains.yml +145 -181
- data/spec/fixtures/proxmox/identity/groups.yml +72 -90
- data/spec/fixtures/proxmox/identity/permissions.yml +297 -189
- data/spec/fixtures/proxmox/identity/pools.yml +176 -421
- data/spec/fixtures/proxmox/identity/read_version.yml +7 -9
- data/spec/fixtures/proxmox/identity/roles.yml +69 -87
- data/spec/fixtures/proxmox/identity/tokens.yml +494 -0
- data/spec/fixtures/proxmox/identity/users.yml +149 -187
- data/spec/fixtures/proxmox/network/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/network/networks.yml +99 -96
- data/spec/helpers/cpu_helper_spec.rb +27 -20
- data/spec/helpers/disk_helper_spec.rb +231 -187
- data/spec/helpers/nic_helper_spec.rb +113 -114
- data/spec/identity_spec.rb +110 -28
- data/spec/network_spec.rb +3 -3
- data/spec/proxmox_vcr.rb +24 -22
- data/spec/spec_helper.rb +4 -3
- metadata +155 -139
- data/spec/fixtures/proxmox/compute/identity_ticket.yml +0 -40
- data/spec/fixtures/proxmox/identity/identity_ticket.yml +0 -40
- data/spec/fixtures/proxmox/identity/renew.yml +0 -40
- data/spec/fixtures/proxmox/network/identity_ticket.yml +0 -40
@@ -0,0 +1,85 @@
|
|
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/json'
|
21
|
+
require 'fog/proxmox/variables'
|
22
|
+
require 'fog/proxmox/json'
|
23
|
+
|
24
|
+
module Fog
|
25
|
+
module Proxmox
|
26
|
+
# Core module
|
27
|
+
module Auth
|
28
|
+
module Token
|
29
|
+
class AccessTicket
|
30
|
+
include Fog::Proxmox::Auth::Token
|
31
|
+
|
32
|
+
NAME = 'access_ticket'
|
33
|
+
|
34
|
+
attr_reader :csrf_token
|
35
|
+
|
36
|
+
class URIError < RuntimeError; end
|
37
|
+
|
38
|
+
EXPIRATION_DELAY = 2 * 60 * 60
|
39
|
+
|
40
|
+
def auth_method
|
41
|
+
'POST'
|
42
|
+
end
|
43
|
+
|
44
|
+
def auth_path(params = {})
|
45
|
+
'/access/ticket'
|
46
|
+
end
|
47
|
+
|
48
|
+
def auth_body(params = {})
|
49
|
+
raise URIError, 'URI params is required' if params.nil? || params.empty?
|
50
|
+
raise URIError, 'proxmox_username is required' if params[:proxmox_username].nil? || params[:proxmox_username].empty?
|
51
|
+
raise URIError, 'proxmox_password is required' if params[:proxmox_password].nil? || params[:proxmox_password].empty?
|
52
|
+
URI.encode_www_form(username: params[:proxmox_username], password: params[:proxmox_password])
|
53
|
+
end
|
54
|
+
|
55
|
+
def headers(method = 'GET', params = {}, additional_headers = {})
|
56
|
+
headers_hash = {}
|
57
|
+
@data ||= {}
|
58
|
+
unless @data.empty?
|
59
|
+
headers_hash.store('Cookie', "PVEAuthCookie=#{@data['ticket']}")
|
60
|
+
if %w[PUT POST DELETE].include? method
|
61
|
+
headers_hash.store('CSRFPreventionToken', @data['CSRFPreventionToken'])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
headers_hash.merge! additional_headers
|
65
|
+
headers_hash
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_credentials(proxmox_options, data)
|
69
|
+
@token = data['ticket']
|
70
|
+
@expires = Time.now.utc.to_i + EXPIRATION_DELAY
|
71
|
+
@userid = data['username']
|
72
|
+
@csrf_token = data['CSRFPreventionToken']
|
73
|
+
end
|
74
|
+
|
75
|
+
def missing_credentials(options)
|
76
|
+
missing_credentials = []
|
77
|
+
missing_credentials << :proxmox_username unless options[:proxmox_username]
|
78
|
+
missing_credentials << :proxmox_password unless options[:proxmox_password]
|
79
|
+
raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,94 @@
|
|
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/json'
|
21
|
+
require 'fog/proxmox/variables'
|
22
|
+
require 'fog/proxmox/json'
|
23
|
+
|
24
|
+
module Fog
|
25
|
+
module Proxmox
|
26
|
+
# Core module
|
27
|
+
module Auth
|
28
|
+
module Token
|
29
|
+
class UserToken
|
30
|
+
include Fog::Proxmox::Auth::Token
|
31
|
+
|
32
|
+
NAME = 'user_token'
|
33
|
+
|
34
|
+
attr_reader :token_id
|
35
|
+
|
36
|
+
class URIError < RuntimeError; end
|
37
|
+
|
38
|
+
def auth_method
|
39
|
+
'GET'
|
40
|
+
end
|
41
|
+
|
42
|
+
def auth_path(params = {})
|
43
|
+
raise URIError, 'URI params are required' if params.nil? || params.empty?
|
44
|
+
raise URIError, 'proxmox_userid is required' if params[:proxmox_userid].nil? || params[:proxmox_userid].empty?
|
45
|
+
raise URIError, 'proxmox_tokenid is required' if params[:proxmox_tokenid].nil? || params[:proxmox_tokenid].empty?
|
46
|
+
"/access/users/#{URI.encode_www_form_component(params[:proxmox_userid])}/token/#{params[:proxmox_tokenid]}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def auth_body(params = {})
|
50
|
+
''
|
51
|
+
end
|
52
|
+
|
53
|
+
def no_token?(params)
|
54
|
+
(params.respond_to?(:proxmox_token) || params[:proxmox_token].nil? || params[:proxmox_token].empty?) && (@token.nil? || @token.empty?)
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_credentials(params)
|
58
|
+
token = @token
|
59
|
+
token = params[:proxmox_token] if token.empty?
|
60
|
+
token_id = @token_id
|
61
|
+
token_id = params[:proxmox_tokenid] if token_id.empty?
|
62
|
+
userid = @userid
|
63
|
+
userid = params[:proxmox_userid] if userid.empty?
|
64
|
+
{userid: userid, token_id: token_id, token: token }
|
65
|
+
end
|
66
|
+
|
67
|
+
def headers(method = 'GET', params = {}, additional_headers = {})
|
68
|
+
raise URIError, 'User token is required' if no_token?(params)
|
69
|
+
credentials = set_credentials(params)
|
70
|
+
headers_hash = {}
|
71
|
+
headers_hash.store('Authorization', "PVEAPIToken=#{credentials[:userid]}!#{credentials[:token_id]}=#{credentials[:token]}")
|
72
|
+
headers_hash.merge! additional_headers
|
73
|
+
headers_hash
|
74
|
+
end
|
75
|
+
|
76
|
+
def build_credentials(proxmox_options, data)
|
77
|
+
@expires = data['expire']
|
78
|
+
@token = proxmox_options[:proxmox_token]
|
79
|
+
@token_id = proxmox_options[:proxmox_tokenid]
|
80
|
+
@userid = proxmox_options[:proxmox_userid]
|
81
|
+
end
|
82
|
+
|
83
|
+
def missing_credentials(options)
|
84
|
+
missing_credentials = []
|
85
|
+
missing_credentials << :proxmox_userid unless options[:proxmox_userid]
|
86
|
+
missing_credentials << :proxmox_tokenid unless options[:proxmox_tokenid]
|
87
|
+
missing_credentials << :proxmox_token unless options[:proxmox_token]
|
88
|
+
raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -23,13 +23,11 @@ module Fog
|
|
23
23
|
module Proxmox
|
24
24
|
# Proxmox compute service
|
25
25
|
class Compute < Fog::Service
|
26
|
-
requires :
|
27
|
-
recognizes :
|
28
|
-
:pve_csrftoken, :persistent, :current_user, :pve_username,
|
29
|
-
:pve_password, :pve_deadline
|
26
|
+
requires :proxmox_url, :proxmox_auth_method
|
27
|
+
recognizes :proxmox_token, :proxmox_tokenid, :proxmox_userid, :persistent, :proxmox_username, :proxmox_password
|
30
28
|
|
31
29
|
# Models
|
32
|
-
model_path 'fog/compute/
|
30
|
+
model_path 'fog/proxmox/compute/models'
|
33
31
|
model :node
|
34
32
|
collection :nodes
|
35
33
|
model :server
|
@@ -49,7 +47,7 @@ module Fog
|
|
49
47
|
collection :snapshots
|
50
48
|
|
51
49
|
# Requests
|
52
|
-
request_path 'fog/compute/
|
50
|
+
request_path 'fog/proxmox/compute/requests'
|
53
51
|
|
54
52
|
# Manage nodes cluster
|
55
53
|
request :list_nodes
|
@@ -102,8 +100,14 @@ module Fog
|
|
102
100
|
attr_reader :config
|
103
101
|
|
104
102
|
def initialize(options = {})
|
105
|
-
@
|
106
|
-
@
|
103
|
+
@proxmox_uri = URI.parse(options[:proxmox_url])
|
104
|
+
@proxmox_auth_method = options[:proxmox_auth_method]
|
105
|
+
@proxmox_tokenid = options[:proxmox_tokenid]
|
106
|
+
@proxmox_userid = options[:proxmox_userid]
|
107
|
+
@proxmox_username = options[:proxmox_username]
|
108
|
+
@proxmox_password = options[:proxmox_password]
|
109
|
+
@proxmox_token = options[:proxmox_token]
|
110
|
+
@proxmox_path = @proxmox_uri.path
|
107
111
|
@config = options
|
108
112
|
end
|
109
113
|
end
|
@@ -111,14 +115,25 @@ module Fog
|
|
111
115
|
# Real class
|
112
116
|
class Real
|
113
117
|
include Fog::Proxmox::Core
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
118
|
+
|
119
|
+
def self.not_found_class
|
120
|
+
Fog::Proxmox::Compute::NotFound
|
121
|
+
end
|
122
|
+
|
123
|
+
def config
|
124
|
+
self
|
125
|
+
end
|
126
|
+
|
127
|
+
def config_service?
|
128
|
+
true
|
129
|
+
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
def configure(source)
|
134
|
+
source.instance_variables.each do |v|
|
135
|
+
instance_variable_set(v, source.instance_variable_get(v))
|
136
|
+
end
|
122
137
|
end
|
123
138
|
end
|
124
139
|
end
|
@@ -18,6 +18,7 @@
|
|
18
18
|
# frozen_string_literal: true
|
19
19
|
|
20
20
|
require 'fog/proxmox/helpers/disk_helper'
|
21
|
+
require 'fog/proxmox/helpers/controller_helper'
|
21
22
|
|
22
23
|
module Fog
|
23
24
|
module Proxmox
|
@@ -56,11 +57,23 @@ module Fog
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def mount_point?
|
59
|
-
|
60
|
+
Fog::Proxmox::DiskHelper.mount_point?(id)
|
60
61
|
end
|
61
62
|
|
62
63
|
def controller?
|
63
|
-
|
64
|
+
Fog::Proxmox::DiskHelper.server_disk?(id)
|
65
|
+
end
|
66
|
+
|
67
|
+
def cloud_init?
|
68
|
+
id != 'ide2' && media == 'cdrom'
|
69
|
+
end
|
70
|
+
|
71
|
+
def hard_disk?
|
72
|
+
controller? && !cdrom? && !cloud_init?
|
73
|
+
end
|
74
|
+
|
75
|
+
def template?
|
76
|
+
Fog::Proxmox::DiskHelper.template?(volid)
|
64
77
|
end
|
65
78
|
|
66
79
|
def flatten
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/compute/
|
20
|
+
require 'fog/proxmox/compute/models/disk'
|
21
21
|
|
22
22
|
module Fog
|
23
23
|
module Proxmox
|
@@ -45,6 +45,10 @@ module Fog
|
|
45
45
|
def rootfs
|
46
46
|
find(&:rootfs?)
|
47
47
|
end
|
48
|
+
|
49
|
+
def cloudinit
|
50
|
+
find(&:cloud_init?)
|
51
|
+
end
|
48
52
|
end
|
49
53
|
end
|
50
54
|
end
|
@@ -26,6 +26,7 @@ module Fog
|
|
26
26
|
class Interface < Fog::Model
|
27
27
|
identity :id
|
28
28
|
attribute :macaddr
|
29
|
+
attribute :hwaddr
|
29
30
|
attribute :model
|
30
31
|
attribute :name
|
31
32
|
attribute :ip
|
@@ -38,6 +39,9 @@ module Fog
|
|
38
39
|
attribute :rate
|
39
40
|
attribute :queues
|
40
41
|
attribute :tag
|
42
|
+
attribute :mtu
|
43
|
+
attribute :trunks
|
44
|
+
attribute :type
|
41
45
|
|
42
46
|
def flatten
|
43
47
|
Fog::Proxmox::NicHelper.flatten(attributes)
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/compute/
|
20
|
+
require 'fog/proxmox/compute/models/interface'
|
21
21
|
require 'fog/proxmox/helpers/controller_helper'
|
22
22
|
|
23
23
|
module Fog
|
File without changes
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/compute/
|
20
|
+
require 'fog/proxmox/compute/models/node'
|
21
21
|
|
22
22
|
module Fog
|
23
23
|
module Proxmox
|
@@ -228,7 +228,7 @@ module Fog
|
|
228
228
|
volumes
|
229
229
|
end
|
230
230
|
|
231
|
-
protected
|
231
|
+
protected
|
232
232
|
|
233
233
|
def initialize_config(new_attributes = {})
|
234
234
|
options = { service: service, vmid: vmid }
|
@@ -247,7 +247,7 @@ module Fog
|
|
247
247
|
|
248
248
|
def node
|
249
249
|
Fog::Proxmox::Compute::Node.new(service: service, node: node_id)
|
250
|
-
end
|
250
|
+
end
|
251
251
|
end
|
252
252
|
end
|
253
253
|
end
|
@@ -69,6 +69,14 @@ module Fog
|
|
69
69
|
attribute :unprivileged
|
70
70
|
attribute :interfaces
|
71
71
|
attribute :disks
|
72
|
+
attribute :ciuser
|
73
|
+
attribute :cipassword
|
74
|
+
attribute :cicustom
|
75
|
+
attribute :citype
|
76
|
+
attribute :ipconfigs
|
77
|
+
attribute :sshkeys
|
78
|
+
attribute :searchdomain
|
79
|
+
attribute :nameserver
|
72
80
|
|
73
81
|
def initialize(new_attributes = {})
|
74
82
|
prepare_service_value(new_attributes)
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/compute/
|
20
|
+
require 'fog/proxmox/compute/models/server'
|
21
21
|
|
22
22
|
module Fog
|
23
23
|
module Proxmox
|
File without changes
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/compute/
|
20
|
+
require 'fog/proxmox/compute/models/snapshot'
|
21
21
|
|
22
22
|
module Fog
|
23
23
|
module Proxmox
|
File without changes
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/compute/
|
20
|
+
require 'fog/proxmox/compute/models/storage'
|
21
21
|
|
22
22
|
module Fog
|
23
23
|
module Proxmox
|
File without changes
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require 'fog/compute/
|
20
|
+
require 'fog/proxmox/compute/models/task'
|
21
21
|
|
22
22
|
module Fog
|
23
23
|
module Proxmox
|
@@ -26,6 +26,8 @@
|
|
26
26
|
|
27
27
|
# frozen_string_literal: true
|
28
28
|
|
29
|
+
require 'fog/proxmox/helpers/disk_helper'
|
30
|
+
|
29
31
|
module Fog
|
30
32
|
module Proxmox
|
31
33
|
class Compute
|
@@ -55,6 +57,10 @@ module Fog
|
|
55
57
|
def restore(vmid, options = {})
|
56
58
|
service.create_server(node_id, options.merge(archive: volid, storage: storage_id, vmid: vmid))
|
57
59
|
end
|
60
|
+
|
61
|
+
def template?
|
62
|
+
Fog::Proxmox::DiskHelper.template?(volid)
|
63
|
+
end
|
58
64
|
end
|
59
65
|
end
|
60
66
|
end
|