fog-proxmox 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +34 -49
- data/.github/workflows/release.yml +38 -0
- data/.rubocop.yml +11 -10
- data/.rubocop_todo.yml +255 -0
- data/CHANGELOG.md +8 -0
- data/README.md +28 -4
- data/Rakefile +8 -35
- data/bin/console +2 -4
- data/bin/setup +2 -4
- data/fog-proxmox.gemspec +7 -5
- data/lib/fog/proxmox/attributes.rb +3 -2
- data/lib/fog/proxmox/auth/token/access_ticket.rb +68 -57
- data/lib/fog/proxmox/auth/token/user_token.rb +79 -66
- data/lib/fog/proxmox/auth/token.rb +66 -60
- data/lib/fog/proxmox/compute/models/disk.rb +6 -1
- data/lib/fog/proxmox/compute/models/disks.rb +1 -1
- data/lib/fog/proxmox/compute/models/interface.rb +1 -1
- data/lib/fog/proxmox/compute/models/interfaces.rb +1 -1
- data/lib/fog/proxmox/compute/models/node.rb +3 -5
- data/lib/fog/proxmox/compute/models/nodes.rb +1 -1
- data/lib/fog/proxmox/compute/models/server.rb +27 -16
- data/lib/fog/proxmox/compute/models/server_config.rb +9 -4
- data/lib/fog/proxmox/compute/models/servers.rb +5 -5
- data/lib/fog/proxmox/compute/models/snapshots.rb +1 -1
- data/lib/fog/proxmox/compute/models/storage.rb +3 -2
- data/lib/fog/proxmox/compute/models/storages.rb +2 -2
- data/lib/fog/proxmox/compute/models/tasks.rb +1 -0
- data/lib/fog/proxmox/compute/models/volume.rb +2 -1
- data/lib/fog/proxmox/compute/models/volumes.rb +2 -2
- data/lib/fog/proxmox/compute/requests/get_server_config.rb +14 -14
- data/lib/fog/proxmox/compute/requests/get_server_status.rb +17 -17
- data/lib/fog/proxmox/compute/requests/log_task.rb +1 -1
- data/lib/fog/proxmox/core.rb +27 -24
- data/lib/fog/proxmox/errors.rb +2 -1
- data/lib/fog/proxmox/hash.rb +0 -2
- data/lib/fog/proxmox/helpers/controller_helper.rb +3 -4
- data/lib/fog/proxmox/helpers/cpu_helper.rb +13 -6
- data/lib/fog/proxmox/helpers/disk_helper.rb +17 -11
- data/lib/fog/proxmox/helpers/ip_helper.rb +21 -20
- data/lib/fog/proxmox/helpers/nic_helper.rb +13 -11
- data/lib/fog/proxmox/identity/models/domain.rb +7 -3
- data/lib/fog/proxmox/identity/models/domain_type.rb +0 -1
- data/lib/fog/proxmox/identity/models/domains.rb +1 -2
- data/lib/fog/proxmox/identity/models/group.rb +4 -2
- data/lib/fog/proxmox/identity/models/groups.rb +1 -1
- data/lib/fog/proxmox/identity/models/permission.rb +5 -4
- data/lib/fog/proxmox/identity/models/permissions.rb +3 -1
- data/lib/fog/proxmox/identity/models/pool.rb +4 -4
- data/lib/fog/proxmox/identity/models/pools.rb +4 -4
- data/lib/fog/proxmox/identity/models/role.rb +1 -1
- data/lib/fog/proxmox/identity/models/roles.rb +1 -1
- data/lib/fog/proxmox/identity/models/token.rb +4 -3
- data/lib/fog/proxmox/identity/models/token_info.rb +2 -2
- data/lib/fog/proxmox/identity/models/tokens.rb +9 -13
- data/lib/fog/proxmox/identity/models/user.rb +1 -2
- data/lib/fog/proxmox/identity/models/users.rb +1 -1
- data/lib/fog/proxmox/identity/requests/get_user.rb +1 -0
- data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +1 -1
- data/lib/fog/proxmox/network/models/networks.rb +1 -1
- data/lib/fog/proxmox/network/models/node.rb +1 -0
- data/lib/fog/proxmox/network/models/nodes.rb +1 -1
- data/lib/fog/proxmox/string.rb +4 -3
- data/lib/fog/proxmox/version.rb +1 -1
- data/lib/fog/proxmox.rb +1 -3
- data/spec/hash_spec.rb +2 -1
- data/spec/helpers/controller_helper_spec.rb +135 -123
- data/spec/helpers/cpu_helper_spec.rb +58 -53
- data/spec/helpers/disk_helper_spec.rb +104 -54
- data/spec/helpers/ip_helper_spec.rb +155 -138
- data/spec/helpers/nic_helper_spec.rb +28 -19
- data/spec/identity_spec.rb +86 -74
- data/spec/proxmox_vcr.rb +2 -2
- data/tasks/audit.rake +25 -0
- data/tasks/lint.rake +22 -0
- data/tasks/test.rake +65 -0
- metadata +62 -47
- data/.codeclimate.yml +0 -14
@@ -22,64 +22,75 @@ require 'fog/proxmox/variables'
|
|
22
22
|
require 'fog/proxmox/json'
|
23
23
|
|
24
24
|
module Fog
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|
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
|
+
|
51
|
+
if params[:proxmox_username].nil? || params[:proxmox_username].empty?
|
52
|
+
raise URIError,
|
53
|
+
'proxmox_username is required'
|
54
|
+
end
|
55
|
+
if params[:proxmox_password].nil? || params[:proxmox_password].empty?
|
56
|
+
raise URIError,
|
57
|
+
'proxmox_password is required'
|
58
|
+
end
|
59
|
+
|
60
|
+
URI.encode_www_form(username: params[:proxmox_username], password: params[:proxmox_password])
|
61
|
+
end
|
62
|
+
|
63
|
+
def headers(method = 'GET', _params = {}, additional_headers = {})
|
64
|
+
headers_hash = {}
|
65
|
+
@data ||= {}
|
66
|
+
unless @data.empty?
|
67
|
+
headers_hash.store('Cookie', "PVEAuthCookie=#{@data['ticket']}")
|
68
|
+
if %w[PUT POST DELETE].include? method
|
69
|
+
headers_hash.store('CSRFPreventionToken', @data['CSRFPreventionToken'])
|
70
|
+
end
|
82
71
|
end
|
72
|
+
headers_hash.merge! additional_headers
|
73
|
+
headers_hash
|
74
|
+
end
|
75
|
+
|
76
|
+
def build_credentials(_proxmox_options, data)
|
77
|
+
@token = data['ticket']
|
78
|
+
@expires = Time.now.utc.to_i + EXPIRATION_DELAY
|
79
|
+
@userid = data['username']
|
80
|
+
@csrf_token = data['CSRFPreventionToken']
|
81
|
+
end
|
82
|
+
|
83
|
+
def missing_credentials(options)
|
84
|
+
missing_credentials = []
|
85
|
+
missing_credentials << :proxmox_username unless options[:proxmox_username]
|
86
|
+
missing_credentials << :proxmox_password unless options[:proxmox_password]
|
87
|
+
return if missing_credentials.empty?
|
88
|
+
|
89
|
+
raise ArgumentError,
|
90
|
+
"Missing required arguments: #{missing_credentials.join(', ')}"
|
91
|
+
end
|
83
92
|
end
|
93
|
+
end
|
84
94
|
end
|
95
|
+
end
|
85
96
|
end
|
@@ -22,73 +22,86 @@ require 'fog/proxmox/variables'
|
|
22
22
|
require 'fog/proxmox/json'
|
23
23
|
|
24
24
|
module Fog
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
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
|
+
|
45
|
+
if params[:proxmox_userid].nil? || params[:proxmox_userid].empty?
|
46
|
+
raise URIError,
|
47
|
+
'proxmox_userid is required'
|
91
48
|
end
|
49
|
+
if params[:proxmox_tokenid].nil? || params[:proxmox_tokenid].empty?
|
50
|
+
raise URIError,
|
51
|
+
'proxmox_tokenid is required'
|
52
|
+
end
|
53
|
+
|
54
|
+
"/access/users/#{URI.encode_www_form_component(params[:proxmox_userid])}/token/#{params[:proxmox_tokenid]}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def auth_body(_params = {})
|
58
|
+
''
|
59
|
+
end
|
60
|
+
|
61
|
+
def no_token?(params)
|
62
|
+
(params.respond_to?(:proxmox_token) || params[:proxmox_token].nil? || params[:proxmox_token].empty?) && (@token.nil? || @token.empty?)
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_credentials(params)
|
66
|
+
token = @token
|
67
|
+
token = params[:proxmox_token] if token.empty?
|
68
|
+
token_id = @token_id
|
69
|
+
token_id = params[:proxmox_tokenid] if token_id.empty?
|
70
|
+
userid = @userid
|
71
|
+
userid = params[:proxmox_userid] if userid.empty?
|
72
|
+
{ userid: userid, token_id: token_id, token: token }
|
73
|
+
end
|
74
|
+
|
75
|
+
def headers(_method = 'GET', params = {}, additional_headers = {})
|
76
|
+
raise URIError, 'User token is required' if no_token?(params)
|
77
|
+
|
78
|
+
credentials = set_credentials(params)
|
79
|
+
headers_hash = {}
|
80
|
+
headers_hash.store('Authorization',
|
81
|
+
"PVEAPIToken=#{credentials[:userid]}!#{credentials[:token_id]}=#{credentials[:token]}")
|
82
|
+
headers_hash.merge! additional_headers
|
83
|
+
headers_hash
|
84
|
+
end
|
85
|
+
|
86
|
+
def build_credentials(proxmox_options, data)
|
87
|
+
@expires = data['expire']
|
88
|
+
@token = proxmox_options[:proxmox_token]
|
89
|
+
@token_id = proxmox_options[:proxmox_tokenid]
|
90
|
+
@userid = proxmox_options[:proxmox_userid]
|
91
|
+
end
|
92
|
+
|
93
|
+
def missing_credentials(options)
|
94
|
+
missing_credentials = []
|
95
|
+
missing_credentials << :proxmox_userid unless options[:proxmox_userid]
|
96
|
+
missing_credentials << :proxmox_tokenid unless options[:proxmox_tokenid]
|
97
|
+
missing_credentials << :proxmox_token unless options[:proxmox_token]
|
98
|
+
return if missing_credentials.empty?
|
99
|
+
|
100
|
+
raise ArgumentError,
|
101
|
+
"Missing required arguments: #{missing_credentials.join(', ')}"
|
102
|
+
end
|
92
103
|
end
|
104
|
+
end
|
93
105
|
end
|
106
|
+
end
|
94
107
|
end
|
@@ -23,66 +23,72 @@ require 'fog/proxmox/variables'
|
|
23
23
|
require 'fog/proxmox/json'
|
24
24
|
|
25
25
|
module Fog
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
26
|
+
module Proxmox
|
27
|
+
# Core module
|
28
|
+
module Auth
|
29
|
+
module Token
|
30
|
+
autoload :AccessTicket, 'fog/proxmox/auth/token/access_ticket'
|
31
|
+
autoload :UserToken, 'fog/proxmox/auth/token/user_token'
|
32
|
+
|
33
|
+
attr_reader :userid, :token, :expires, :data
|
34
|
+
|
35
|
+
class ExpiryError < RuntimeError; end
|
36
|
+
class URLError < RuntimeError; end
|
37
|
+
|
38
|
+
def initialize(proxmox_options, options = {})
|
39
|
+
if proxmox_options[:proxmox_url].nil? || proxmox_options[:proxmox_url].empty?
|
40
|
+
raise URLError,
|
41
|
+
'No proxmox_url provided'
|
42
|
+
end
|
43
|
+
|
44
|
+
@token ||= ''
|
45
|
+
@token_id ||= ''
|
46
|
+
@userid ||= ''
|
47
|
+
@data = authenticate(proxmox_options, options)
|
48
|
+
build_credentials(proxmox_options, data)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.build(proxmox_options, options)
|
52
|
+
unless proxmox_options.key? :proxmox_auth_method
|
53
|
+
raise ArgumentError,
|
54
|
+
'Missing required proxmox_auth_method in options.'
|
55
|
+
end
|
56
|
+
|
57
|
+
auth_method = proxmox_options[:proxmox_auth_method]
|
58
|
+
if auth_method == Fog::Proxmox::Auth::Token::AccessTicket::NAME
|
59
|
+
Fog::Proxmox::Auth::Token::AccessTicket.new(proxmox_options, options)
|
60
|
+
elsif auth_method == Fog::Proxmox::Auth::Token::UserToken::NAME
|
61
|
+
Fog::Proxmox::Auth::Token::UserToken.new(proxmox_options, options)
|
62
|
+
else
|
63
|
+
raise ArgumentError,
|
64
|
+
"Unkown authentication method: #{auth_method}. Only #{Fog::Proxmox::Auth::Token::AccessTicket::NAME} or #{Fog::Proxmox::Auth::Token::UserToken::NAME} are accepted."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def authenticate(proxmox_options, connection_options = {})
|
69
|
+
uri = URI.parse(proxmox_options[:proxmox_url])
|
70
|
+
request = {
|
71
|
+
expects: [200, 201],
|
72
|
+
headers: headers(auth_method, proxmox_options, { Accept: 'application/json' }),
|
73
|
+
body: auth_body(proxmox_options),
|
74
|
+
method: auth_method,
|
75
|
+
path: uri.path + auth_path(proxmox_options)
|
76
|
+
}
|
77
|
+
connection = Fog::Core::Connection.new(
|
78
|
+
uri.to_s,
|
79
|
+
false,
|
80
|
+
connection_options
|
81
|
+
)
|
82
|
+
response = connection.request(request)
|
83
|
+
Json.get_data(response)
|
84
|
+
end
|
85
|
+
|
86
|
+
def expired?
|
87
|
+
raise ExpiryError, 'Missing token expiration data' if @expires.nil? || @expires.empty?
|
88
|
+
|
89
|
+
Time.at(@expires) < Time.now.utc
|
86
90
|
end
|
91
|
+
end
|
87
92
|
end
|
93
|
+
end
|
88
94
|
end
|
@@ -23,7 +23,8 @@ require 'fog/proxmox/helpers/controller_helper'
|
|
23
23
|
module Fog
|
24
24
|
module Proxmox
|
25
25
|
class Compute
|
26
|
-
# class Disk model
|
26
|
+
# class Disk model: https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/{qemu|lxc}/{vmid}/config
|
27
|
+
# size is in Gb
|
27
28
|
class Disk < Fog::Model
|
28
29
|
identity :id
|
29
30
|
attribute :volid
|
@@ -83,6 +84,10 @@ module Fog
|
|
83
84
|
def to_s
|
84
85
|
Fog::Proxmox::Hash.flatten(flatten)
|
85
86
|
end
|
87
|
+
|
88
|
+
def has_volume?
|
89
|
+
!volid.empty?
|
90
|
+
end
|
86
91
|
end
|
87
92
|
end
|
88
93
|
end
|
@@ -61,14 +61,13 @@ module Fog
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def backup(options = {})
|
64
|
-
|
65
|
-
task_upid
|
64
|
+
service.backup({ node: node }, options)
|
66
65
|
end
|
67
66
|
|
68
|
-
def statistics(output = 'rrddata', options = { timeframe: 'hour', cf: 'AVERAGE'})
|
67
|
+
def statistics(output = 'rrddata', options = { timeframe: 'hour', cf: 'AVERAGE' })
|
69
68
|
path_params = { node: node, output: output }
|
70
69
|
query_params = options
|
71
|
-
service.get_node_statistics(path_params,query_params)
|
70
|
+
service.get_node_statistics(path_params, query_params)
|
72
71
|
end
|
73
72
|
|
74
73
|
private
|
@@ -88,7 +87,6 @@ module Fog
|
|
88
87
|
def initialize_storages
|
89
88
|
attributes[:storages] = Fog::Proxmox::Compute::Storages.new(service: service, node_id: node)
|
90
89
|
end
|
91
|
-
|
92
90
|
end
|
93
91
|
end
|
94
92
|
end
|
@@ -78,14 +78,11 @@ module Fog
|
|
78
78
|
|
79
79
|
def persisted?
|
80
80
|
service.next_vmid(vmid: vmid)
|
81
|
-
|
82
|
-
persisted
|
81
|
+
false
|
83
82
|
rescue Excon::Error::InternalServerError
|
84
|
-
|
85
|
-
persisted
|
83
|
+
false
|
86
84
|
rescue Excon::Error::BadRequest
|
87
|
-
|
88
|
-
persisted
|
85
|
+
true
|
89
86
|
end
|
90
87
|
|
91
88
|
# request with async task
|
@@ -122,6 +119,7 @@ module Fog
|
|
122
119
|
action_known = %w[start stop resume suspend shutdown reset].include? action
|
123
120
|
message = "Action #{action} not implemented"
|
124
121
|
raise Fog::Errors::Error, message unless action_known
|
122
|
+
|
125
123
|
request(:action_server, options, action: action, vmid: vmid)
|
126
124
|
reload
|
127
125
|
end
|
@@ -136,11 +134,11 @@ module Fog
|
|
136
134
|
end
|
137
135
|
|
138
136
|
def restore(backup, options = {})
|
139
|
-
if container?
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
137
|
+
attr_hash = if container?
|
138
|
+
options.merge(ostemplate: backup.volid, force: 1, restore: 1)
|
139
|
+
else
|
140
|
+
options.merge(archive: backup.volid, force: 1)
|
141
|
+
end
|
144
142
|
save(attr_hash)
|
145
143
|
end
|
146
144
|
|
@@ -186,14 +184,24 @@ module Fog
|
|
186
184
|
end
|
187
185
|
|
188
186
|
def start_console(options = {})
|
189
|
-
|
187
|
+
unless ready?
|
188
|
+
raise ::Fog::Proxmox::Errors::ServiceError,
|
189
|
+
'Unable to start console because server not running.'
|
190
|
+
end
|
191
|
+
|
190
192
|
if container?
|
191
193
|
type_console = options[:console]
|
192
194
|
options.delete_if { |option| [:console].include? option }
|
193
|
-
|
195
|
+
unless type_console
|
196
|
+
raise ::Fog::Proxmox::Errors::ServiceError,
|
197
|
+
'Unable to start console because console container config is not set or unknown.'
|
198
|
+
end
|
194
199
|
else
|
195
200
|
type_console = config.type_console
|
196
|
-
|
201
|
+
unless type_console
|
202
|
+
raise ::Fog::Proxmox::Errors::ServiceError,
|
203
|
+
'Unable to start console because VGA display server config is not set or unknown.'
|
204
|
+
end
|
197
205
|
end
|
198
206
|
requires :vmid, :node_id, :type
|
199
207
|
path_params = { node: node_id, type: type, vmid: vmid }
|
@@ -238,11 +246,14 @@ module Fog
|
|
238
246
|
private
|
239
247
|
|
240
248
|
def initialize_snapshots
|
241
|
-
attributes[:snapshots] =
|
249
|
+
attributes[:snapshots] =
|
250
|
+
Fog::Proxmox::Compute::Snapshots.new(service: service, server_id: vmid, server_type: type, node_id: node_id)
|
242
251
|
end
|
243
252
|
|
244
253
|
def initialize_tasks
|
245
|
-
attributes[:tasks] = Fog::Proxmox::Compute::Tasks.new(service: service, node_id: node_id).select
|
254
|
+
attributes[:tasks] = Fog::Proxmox::Compute::Tasks.new(service: service, node_id: node_id).select do |task|
|
255
|
+
task.id == vmid
|
256
|
+
end
|
246
257
|
end
|
247
258
|
|
248
259
|
def node
|
@@ -24,7 +24,8 @@ require 'fog/proxmox/helpers/controller_helper'
|
|
24
24
|
module Fog
|
25
25
|
module Proxmox
|
26
26
|
class Compute
|
27
|
-
# ServerConfig model
|
27
|
+
# ServerConfig model: https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/{qemu|lxc}/{vmid}/config
|
28
|
+
# memory, balloon, shares and swap are in Mb
|
28
29
|
class ServerConfig < Fog::Model
|
29
30
|
identity :vmid
|
30
31
|
attribute :description
|
@@ -99,7 +100,7 @@ module Fog
|
|
99
100
|
end
|
100
101
|
|
101
102
|
def flatten
|
102
|
-
flat_hash = attributes.reject { |attribute| [
|
103
|
+
flat_hash = attributes.reject { |attribute| %i[node_id type vmid disks interfaces].include? attribute }
|
103
104
|
flat_hash.merge(interfaces_flatten)
|
104
105
|
flat_hash.merge(disks_flatten)
|
105
106
|
flat_hash
|
@@ -128,7 +129,9 @@ module Fog
|
|
128
129
|
model: Fog::Proxmox::NicHelper.extract_nic_id(value),
|
129
130
|
macaddr: Fog::Proxmox::NicHelper.extract_mac_address(value)
|
130
131
|
}
|
131
|
-
names = Fog::Proxmox::Compute::Interface.attributes.reject
|
132
|
+
names = Fog::Proxmox::Compute::Interface.attributes.reject do |attribute|
|
133
|
+
%i[id macaddr model].include? attribute
|
134
|
+
end
|
132
135
|
names.each { |name| nic_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
|
133
136
|
attributes[:interfaces] << Fog::Proxmox::Compute::Interface.new(nic_hash)
|
134
137
|
end
|
@@ -145,7 +148,9 @@ module Fog
|
|
145
148
|
volid: volid,
|
146
149
|
storage: storage
|
147
150
|
}
|
148
|
-
names = Fog::Proxmox::Compute::Disk.attributes.reject
|
151
|
+
names = Fog::Proxmox::Compute::Disk.attributes.reject do |attribute|
|
152
|
+
%i[id size storage volid].include? attribute
|
153
|
+
end
|
149
154
|
names.each { |name| disk_hash.store(name.to_sym, Fog::Proxmox::ControllerHelper.extract(name, value)) }
|
150
155
|
attributes[:disks] << Fog::Proxmox::Compute::Disk.new(disk_hash)
|
151
156
|
end
|