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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +28 -4
  4. data/lib/fog/proxmox/attributes.rb +3 -2
  5. data/lib/fog/proxmox/auth/token/access_ticket.rb +68 -57
  6. data/lib/fog/proxmox/auth/token/user_token.rb +79 -66
  7. data/lib/fog/proxmox/auth/token.rb +66 -60
  8. data/lib/fog/proxmox/compute/models/disk.rb +6 -1
  9. data/lib/fog/proxmox/compute/models/disks.rb +1 -1
  10. data/lib/fog/proxmox/compute/models/interface.rb +1 -1
  11. data/lib/fog/proxmox/compute/models/interfaces.rb +1 -1
  12. data/lib/fog/proxmox/compute/models/node.rb +3 -5
  13. data/lib/fog/proxmox/compute/models/nodes.rb +1 -1
  14. data/lib/fog/proxmox/compute/models/server.rb +33 -16
  15. data/lib/fog/proxmox/compute/models/server_config.rb +9 -4
  16. data/lib/fog/proxmox/compute/models/servers.rb +5 -5
  17. data/lib/fog/proxmox/compute/models/snapshot.rb +1 -1
  18. data/lib/fog/proxmox/compute/models/snapshots.rb +1 -1
  19. data/lib/fog/proxmox/compute/models/storage.rb +3 -2
  20. data/lib/fog/proxmox/compute/models/storages.rb +2 -2
  21. data/lib/fog/proxmox/compute/models/task.rb +1 -1
  22. data/lib/fog/proxmox/compute/models/tasks.rb +1 -0
  23. data/lib/fog/proxmox/compute/models/volume.rb +2 -1
  24. data/lib/fog/proxmox/compute/models/volumes.rb +2 -2
  25. data/lib/fog/proxmox/compute/requests/get_server_config.rb +14 -14
  26. data/lib/fog/proxmox/compute/requests/get_server_status.rb +17 -17
  27. data/lib/fog/proxmox/compute/requests/log_task.rb +1 -1
  28. data/lib/fog/proxmox/core.rb +28 -24
  29. data/lib/fog/proxmox/errors.rb +2 -1
  30. data/lib/fog/proxmox/hash.rb +0 -2
  31. data/lib/fog/proxmox/helpers/controller_helper.rb +3 -4
  32. data/lib/fog/proxmox/helpers/cpu_helper.rb +13 -6
  33. data/lib/fog/proxmox/helpers/disk_helper.rb +18 -12
  34. data/lib/fog/proxmox/helpers/ip_helper.rb +21 -20
  35. data/lib/fog/proxmox/helpers/nic_helper.rb +23 -14
  36. data/lib/fog/proxmox/identity/models/domain.rb +7 -3
  37. data/lib/fog/proxmox/identity/models/domain_type.rb +0 -1
  38. data/lib/fog/proxmox/identity/models/domains.rb +1 -2
  39. data/lib/fog/proxmox/identity/models/group.rb +4 -2
  40. data/lib/fog/proxmox/identity/models/groups.rb +1 -1
  41. data/lib/fog/proxmox/identity/models/permission.rb +5 -4
  42. data/lib/fog/proxmox/identity/models/permissions.rb +3 -1
  43. data/lib/fog/proxmox/identity/models/pool.rb +4 -4
  44. data/lib/fog/proxmox/identity/models/pools.rb +4 -4
  45. data/lib/fog/proxmox/identity/models/role.rb +1 -1
  46. data/lib/fog/proxmox/identity/models/roles.rb +1 -1
  47. data/lib/fog/proxmox/identity/models/token.rb +4 -3
  48. data/lib/fog/proxmox/identity/models/token_info.rb +2 -2
  49. data/lib/fog/proxmox/identity/models/tokens.rb +9 -13
  50. data/lib/fog/proxmox/identity/models/user.rb +1 -2
  51. data/lib/fog/proxmox/identity/models/users.rb +1 -1
  52. data/lib/fog/proxmox/identity/requests/get_user.rb +1 -0
  53. data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +1 -1
  54. data/lib/fog/proxmox/network/models/networks.rb +1 -1
  55. data/lib/fog/proxmox/network/models/node.rb +1 -0
  56. data/lib/fog/proxmox/network/models/nodes.rb +1 -1
  57. data/lib/fog/proxmox/string.rb +4 -3
  58. data/lib/fog/proxmox/version.rb +1 -1
  59. data/lib/fog/proxmox.rb +1 -3
  60. data/spec/compute_spec.rb +3 -2
  61. data/spec/fixtures/proxmox/compute/snapshots.yml +350 -1055
  62. data/spec/hash_spec.rb +2 -1
  63. data/spec/helpers/controller_helper_spec.rb +135 -123
  64. data/spec/helpers/cpu_helper_spec.rb +58 -53
  65. data/spec/helpers/disk_helper_spec.rb +104 -54
  66. data/spec/helpers/ip_helper_spec.rb +155 -138
  67. data/spec/helpers/nic_helper_spec.rb +29 -20
  68. data/spec/identity_spec.rb +86 -74
  69. data/spec/proxmox_vcr.rb +3 -3
  70. metadata +89 -90
  71. data/.bundle/config +0 -4
  72. data/.codeclimate.yml +0 -14
  73. data/.github/CODE_OF_CONDUCT.md +0 -74
  74. data/.github/CONTRIBUTING.md +0 -20
  75. data/.github/CONTRIBUTORS.md +0 -9
  76. data/.github/FUNDING.yml +0 -12
  77. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
  78. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -17
  79. data/.github/ISSUE_TEMPLATE.md +0 -43
  80. data/.github/SUPPORT.md +0 -9
  81. data/.github/fogproxmox.png +0 -0
  82. data/.github/workflows/ci.yml +0 -79
  83. data/.gitignore +0 -8
  84. data/.rubocop.yml +0 -13
  85. data/.ruby-gemset +0 -1
  86. data/.solargraph.yml +0 -10
  87. data/.vscode/launch.json +0 -96
  88. data/.vscode/settings.json +0 -45
  89. data/.vscode/tasks.json +0 -27
  90. data/Gemfile +0 -23
  91. data/Rakefile +0 -58
  92. data/bin/console +0 -29
  93. data/bin/setup +0 -29
  94. data/fog-proxmox.gemspec +0 -63
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e153a5fb10f314d09cc54eec5e8b2a6733120fe5c82ab6a809f203d2211fbfa
4
- data.tar.gz: 7f2aa37e3830abb05c6717dc3f9e1705bfb8aebfa6cf52b2726a81a430ce1ac9
3
+ metadata.gz: b8570832df51a02eaf643d8ff711aded5ed8f664168eb2c1e0e8b3dec1f4b309
4
+ data.tar.gz: c162e5cddd1f8c809310d95b82bce305e2a48c19dad469c432ffd77f8f733723
5
5
  SHA512:
6
- metadata.gz: 615ea980593082a11de74ad48d342df7ea3d5af4a39c9ae467280990ec6fcbc54c6589fe40e824b0ce7429f041707eb6953f71eb6bc3bcd23146ba37d3d98737
7
- data.tar.gz: 73174f09ca4246a44b357d2f6c9b86daf01808623766877f04b59f210dcb581f056b32954aa9d2e919384d7a371bb0edbc720d3196867b9631cf8375d8f76e79
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
  ![CI](https://github.com/fog/fog-proxmox/workflows/CI/badge.svg)
6
- [![Maintainability](https://api.codeclimate.com/v1/badges/33e619f2167cc9864b61/maintainability)](https://codeclimate.com/github/fog/fog-proxmox/maintainability)
7
- [![Test Coverage](https://api.codeclimate.com/v1/badges/33e619f2167cc9864b61/test_coverage)](https://codeclimate.com/github/fog/fog-proxmox/test_coverage)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/dfcdcc32f096abf1b2b4/maintainability)](https://codeclimate.com/github/fog/fog-proxmox/maintainability)
7
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/dfcdcc32f096abf1b2b4/test_coverage)](https://codeclimate.com/github/fog/fog-proxmox/test_coverage)
8
8
  [![Gem Version](https://badge.fury.io/rb/fog-proxmox.svg)](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 bin/rake rubocop
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
- self.set_attr(attr_name, attributes, new_attributes)
29
- self.set_attr(attr_name.to_sym, attributes, new_attributes)
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
- 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
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
- 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
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
- module Proxmox
27
- # Core module
28
- module Auth
29
- module Token
30
-
31
- autoload :AccessTicket, 'fog/proxmox/auth/token/access_ticket'
32
- autoload :UserToken, 'fog/proxmox/auth/token/user_token'
33
-
34
- attr_reader :userid, :token, :expires, :data
35
-
36
- class ExpiryError < RuntimeError; end
37
- class URLError < RuntimeError; end
38
-
39
- def initialize(proxmox_options, options = {})
40
- raise URLError, 'No proxmox_url provided' if proxmox_options[:proxmox_url].nil? || proxmox_options[:proxmox_url].empty?
41
- @token ||= ''
42
- @token_id ||= ''
43
- @userid ||= ''
44
- @data = authenticate(proxmox_options, options)
45
- build_credentials(proxmox_options, data)
46
- end
47
-
48
- def self.build(proxmox_options, options)
49
- raise ArgumentError, "Missing required proxmox_auth_method in options." unless proxmox_options.key? :proxmox_auth_method
50
- auth_method = proxmox_options[:proxmox_auth_method]
51
- if auth_method == Fog::Proxmox::Auth::Token::AccessTicket::NAME
52
- Fog::Proxmox::Auth::Token::AccessTicket.new(proxmox_options, options)
53
- elsif auth_method == Fog::Proxmox::Auth::Token::UserToken::NAME
54
- Fog::Proxmox::Auth::Token::UserToken.new(proxmox_options, options)
55
- else
56
- raise ArgumentError, "Unkown authentication method: #{auth_method}. Only #{Fog::Proxmox::Auth::Token::AccessTicket::NAME} or #{Fog::Proxmox::Auth::Token::UserToken::NAME} are accepted."
57
- end
58
- end
59
-
60
- def authenticate(proxmox_options, connection_options = {})
61
- uri = URI.parse(proxmox_options[:proxmox_url])
62
- request = {
63
- expects: [200, 201],
64
- headers: headers(auth_method, proxmox_options, { Accept: 'application/json' }),
65
- body: auth_body(proxmox_options),
66
- method: auth_method,
67
- path: uri.path + auth_path(proxmox_options)
68
- }
69
- connection = Fog::Core::Connection.new(
70
- uri.to_s,
71
- false,
72
- connection_options
73
- )
74
- response = connection.request(request)
75
- Json.get_data(response)
76
- end
77
-
78
- def expired?
79
- if @expires.nil? || @expires.empty?
80
- raise ExpiryError, 'Missing token expiration data'
81
- end
82
- Time.at(@expires) < Time.now.utc
83
- end
84
-
85
- end
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
@@ -31,7 +31,7 @@ module Fog
31
31
  end
32
32
 
33
33
  def get(id)
34
- all.find { |disk| disk.identity === id }
34
+ all.find { |disk| disk.identity == id }
35
35
  end
36
36
 
37
37
  def next_device(controller)
@@ -17,7 +17,7 @@
17
17
 
18
18
  # frozen_string_literal: true
19
19
 
20
- require "fog/proxmox/helpers/nic_helper"
20
+ require 'fog/proxmox/helpers/nic_helper'
21
21
 
22
22
  module Fog
23
23
  module Proxmox
@@ -32,7 +32,7 @@ module Fog
32
32
  end
33
33
 
34
34
  def get(id)
35
- all.find { |interface| interface.identity === id }
35
+ all.find { |interface| interface.identity == id }
36
36
  end
37
37
 
38
38
  def next_nicid
@@ -61,14 +61,13 @@ module Fog
61
61
  end
62
62
 
63
63
  def backup(options = {})
64
- task_upid = service.backup({ node: node }, options)
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
@@ -31,7 +31,7 @@ module Fog
31
31
  end
32
32
 
33
33
  def get(id)
34
- all.find { |node| node.identity === id }
34
+ all.find { |node| node.identity == id }
35
35
  end
36
36
  end
37
37
  end