fog-proxmox 0.14.0 → 0.15.1
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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +28 -4
- 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 +33 -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/snapshot.rb +1 -1
- 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/task.rb +1 -1
- 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 +28 -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 +18 -12
- data/lib/fog/proxmox/helpers/ip_helper.rb +21 -20
- data/lib/fog/proxmox/helpers/nic_helper.rb +23 -14
- 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/compute_spec.rb +3 -2
- data/spec/fixtures/proxmox/compute/snapshots.yml +350 -1055
- 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 +29 -20
- data/spec/identity_spec.rb +86 -74
- data/spec/proxmox_vcr.rb +3 -3
- metadata +89 -90
- data/.bundle/config +0 -4
- data/.codeclimate.yml +0 -14
- data/.github/CODE_OF_CONDUCT.md +0 -74
- data/.github/CONTRIBUTING.md +0 -20
- data/.github/CONTRIBUTORS.md +0 -9
- data/.github/FUNDING.yml +0 -12
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
- data/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
- data/.github/ISSUE_TEMPLATE.md +0 -43
- data/.github/SUPPORT.md +0 -9
- data/.github/fogproxmox.png +0 -0
- data/.github/workflows/ci.yml +0 -79
- data/.gitignore +0 -8
- data/.rubocop.yml +0 -13
- data/.ruby-gemset +0 -1
- data/.solargraph.yml +0 -10
- data/.vscode/launch.json +0 -96
- data/.vscode/settings.json +0 -45
- data/.vscode/tasks.json +0 -27
- data/Gemfile +0 -23
- data/Rakefile +0 -58
- data/bin/console +0 -29
- data/bin/setup +0 -29
- data/fog-proxmox.gemspec +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8570832df51a02eaf643d8ff711aded5ed8f664168eb2c1e0e8b3dec1f4b309
|
4
|
+
data.tar.gz: c162e5cddd1f8c809310d95b82bce305e2a48c19dad469c432ffd77f8f733723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa4247e9c6f778ad157ba72561f04da0876a6e2d5acd185c93dc84c5ecba5168f1fb3ae3d6a87ddb803d26271963e101f51b8aef5955877ee2f3434cb8de60a
|
7
|
+
data.tar.gz: 8dee3cdb18fe8c1e6ec5103adfb311d6d5d946b44cf3b73acba3b66808321306ea0542c7d40111f53d2b681a1d39b87b2fd43949d5fd15468fd496b66e704184
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [0.15.1](https://github.com/fog/fog-proxmox/compare/v0.15.0...v0.15.1) (2025-02-25)
|
4
|
+
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
|
8
|
+
* Fixes EOF OpenSSL error in Proxmox connection ([#102](https://github.com/fog/fog-proxmox/issues/102)) ([ac8b0e1](https://github.com/fog/fog-proxmox/commit/ac8b0e11a39da6b19703b4f4507edf19486899ba))
|
9
|
+
|
10
|
+
## [0.15.0](https://github.com/fog/fog-proxmox/compare/v0.14.0...v0.15.0) (2022-12-01)
|
11
|
+
|
12
|
+
|
13
|
+
### Features
|
14
|
+
|
15
|
+
* :sparkles: memory unit is Mb and disk size is Gb ([c5410b5](https://github.com/fog/fog-proxmox/commit/c5410b5c79ed59a89bb4f0f2188613cbcc6a8f11))
|
data/README.md
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# Fog::Proxmox
|
4
4
|
|
5
5
|

|
6
|
-
[](https://codeclimate.com/github/fog/fog-proxmox/maintainability)
|
7
|
+
[](https://codeclimate.com/github/fog/fog-proxmox/test_coverage)
|
8
8
|
[](https://badge.fury.io/rb/fog-proxmox)
|
9
9
|
|
10
10
|
This is a [FOG](http://fog.io/) (>= 2.1) module gem to support [Proxmox VE](https://www.proxmox.com/en/proxmox-ve)
|
@@ -62,16 +62,40 @@ To record your VCR cassettes:
|
|
62
62
|
PROXMOX_URL=https://192.168.56.101:8006/api2/json DISABLE_PROXY=true SSL_VERIFY_PEER=false bundle exec rake spec
|
63
63
|
```
|
64
64
|
|
65
|
-
To replay your recorded tests:
|
65
|
+
To replay all your recorded tests:
|
66
66
|
|
67
67
|
```shell
|
68
68
|
USE_VCR=true bundle exec rake spec
|
69
69
|
```
|
70
70
|
|
71
|
+
To replay one group (compute, identity or network) of your recorded tests:
|
72
|
+
|
73
|
+
```shell
|
74
|
+
USE_VCR=true bundle exec rake spec:compute
|
75
|
+
```
|
76
|
+
|
71
77
|
Code formatting:
|
72
78
|
|
73
79
|
```shell
|
74
|
-
bundle exec
|
80
|
+
bundle exec rake rubocop
|
81
|
+
```
|
82
|
+
|
83
|
+
Auto correcting (safe):
|
84
|
+
|
85
|
+
```shell
|
86
|
+
bundle exec rake rubocop:autocorrect
|
87
|
+
```
|
88
|
+
|
89
|
+
Exclude cops in todo file:
|
90
|
+
|
91
|
+
```shell
|
92
|
+
bundle exec rubocop --auto-gen-config
|
93
|
+
```
|
94
|
+
|
95
|
+
See all available rake tasks:
|
96
|
+
|
97
|
+
```shell
|
98
|
+
bundle exec rake --tasks
|
75
99
|
```
|
76
100
|
|
77
101
|
## Contributing
|
@@ -24,9 +24,10 @@ module Fog
|
|
24
24
|
def self.set_attr(attr_name, attributes, new_attributes)
|
25
25
|
attributes[attr_name.to_sym] = new_attributes[attr_name] unless new_attributes[attr_name].nil?
|
26
26
|
end
|
27
|
+
|
27
28
|
def self.set_attr_and_sym(attr_name, attributes, new_attributes)
|
28
|
-
|
29
|
-
|
29
|
+
set_attr(attr_name, attributes, new_attributes)
|
30
|
+
set_attr(attr_name.to_sym, attributes, new_attributes)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -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
|