fog-proxmox 0.10.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +79 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +1 -1
  5. data/README.md +10 -2
  6. data/docs/compute.md +23 -7
  7. data/docs/identity.md +31 -6
  8. data/examples/compute.rb +11 -11
  9. data/examples/identity.rb +28 -15
  10. data/fog-proxmox.gemspec +2 -2
  11. data/lib/fog/proxmox.rb +16 -76
  12. data/lib/fog/proxmox/auth/token.rb +88 -0
  13. data/lib/fog/proxmox/auth/token/access_ticket.rb +85 -0
  14. data/lib/fog/proxmox/auth/token/user_token.rb +94 -0
  15. data/lib/fog/{compute/proxmox.rb → proxmox/compute.rb} +31 -16
  16. data/lib/fog/{compute/proxmox → proxmox/compute}/models/disk.rb +15 -2
  17. data/lib/fog/{compute/proxmox → proxmox/compute}/models/disks.rb +5 -1
  18. data/lib/fog/{compute/proxmox → proxmox/compute}/models/interface.rb +4 -0
  19. data/lib/fog/{compute/proxmox → proxmox/compute}/models/interfaces.rb +1 -1
  20. data/lib/fog/{compute/proxmox → proxmox/compute}/models/node.rb +0 -0
  21. data/lib/fog/{compute/proxmox → proxmox/compute}/models/nodes.rb +1 -1
  22. data/lib/fog/{compute/proxmox → proxmox/compute}/models/server.rb +2 -3
  23. data/lib/fog/{compute/proxmox → proxmox/compute}/models/server_config.rb +9 -1
  24. data/lib/fog/{compute/proxmox → proxmox/compute}/models/servers.rb +1 -1
  25. data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshot.rb +4 -5
  26. data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshots.rb +1 -1
  27. data/lib/fog/{compute/proxmox → proxmox/compute}/models/storage.rb +2 -3
  28. data/lib/fog/{compute/proxmox → proxmox/compute}/models/storages.rb +1 -1
  29. data/lib/fog/{compute/proxmox → proxmox/compute}/models/task.rb +2 -3
  30. data/lib/fog/{compute/proxmox → proxmox/compute}/models/tasks.rb +1 -1
  31. data/lib/fog/{compute/proxmox → proxmox/compute}/models/volume.rb +9 -3
  32. data/lib/fog/{compute/proxmox → proxmox/compute}/models/volumes.rb +1 -1
  33. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/action_server.rb +1 -0
  34. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/clone_server.rb +1 -0
  35. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_backup.rb +1 -0
  36. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_server.rb +1 -0
  37. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_snapshot.rb +3 -1
  38. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_spice.rb +1 -0
  39. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_term.rb +1 -0
  40. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_vnc.rb +1 -0
  41. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_server.rb +1 -0
  42. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_snapshot.rb +3 -1
  43. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_volume.rb +1 -1
  44. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_node_statistics.rb +2 -2
  45. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_config.rb +18 -0
  46. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_status.rb +21 -0
  47. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_snapshot_config.rb +1 -1
  48. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_task.rb +1 -1
  49. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_vnc.rb +1 -0
  50. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_volume.rb +1 -1
  51. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_nodes.rb +8 -1
  52. data/lib/fog/proxmox/compute/requests/list_servers.rb +113 -0
  53. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_snapshots.rb +24 -1
  54. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_storages.rb +3 -1
  55. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_tasks.rb +3 -1
  56. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_volumes.rb +3 -1
  57. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/log_task.rb +3 -1
  58. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/migrate_server.rb +1 -1
  59. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_disk.rb +1 -1
  60. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_volume.rb +1 -1
  61. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/next_vmid.rb +1 -0
  62. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_container.rb +1 -1
  63. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_server.rb +1 -1
  64. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/rollback_snapshot.rb +3 -1
  65. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/status_task.rb +1 -1
  66. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/stop_task.rb +1 -1
  67. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/template_server.rb +1 -0
  68. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_server.rb +1 -0
  69. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_snapshot.rb +1 -1
  70. data/lib/fog/proxmox/core.rb +67 -58
  71. data/lib/fog/proxmox/hash.rb +2 -2
  72. data/lib/fog/proxmox/helpers/cpu_helper.rb +48 -9
  73. data/lib/fog/proxmox/helpers/disk_helper.rb +55 -19
  74. data/lib/fog/proxmox/helpers/nic_helper.rb +28 -20
  75. data/lib/fog/{identity/proxmox.rb → proxmox/identity.rb} +31 -17
  76. data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain.rb +0 -0
  77. data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain_type.rb +0 -0
  78. data/lib/fog/{identity/proxmox → proxmox/identity}/models/domains.rb +1 -1
  79. data/lib/fog/{identity/proxmox → proxmox/identity}/models/group.rb +4 -2
  80. data/lib/fog/{identity/proxmox → proxmox/identity}/models/groups.rb +1 -1
  81. data/lib/fog/{identity/proxmox → proxmox/identity}/models/permission.rb +0 -0
  82. data/lib/fog/{identity/proxmox → proxmox/identity}/models/permissions.rb +1 -1
  83. data/lib/fog/{identity/proxmox → proxmox/identity}/models/pool.rb +18 -0
  84. data/lib/fog/{identity/proxmox → proxmox/identity}/models/pools.rb +4 -2
  85. data/lib/fog/{identity/proxmox → proxmox/identity}/models/principal.rb +0 -0
  86. data/lib/fog/{identity/proxmox → proxmox/identity}/models/role.rb +0 -0
  87. data/lib/fog/{identity/proxmox → proxmox/identity}/models/roles.rb +1 -1
  88. data/lib/fog/proxmox/identity/models/token.rb +71 -0
  89. data/lib/fog/proxmox/identity/models/token_info.rb +41 -0
  90. data/lib/fog/proxmox/identity/models/tokens.rb +58 -0
  91. data/lib/fog/{identity/proxmox → proxmox/identity}/models/user.rb +25 -2
  92. data/lib/fog/{identity/proxmox → proxmox/identity}/models/users.rb +1 -1
  93. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/change_password.rb +0 -0
  94. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/check_permissions.rb +0 -0
  95. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_domain.rb +0 -0
  96. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_group.rb +0 -0
  97. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_pool.rb +0 -0
  98. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_role.rb +0 -0
  99. data/lib/fog/proxmox/identity/requests/create_token.rb +40 -0
  100. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_user.rb +0 -0
  101. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_domain.rb +0 -0
  102. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_group.rb +0 -0
  103. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_pool.rb +0 -0
  104. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_role.rb +0 -0
  105. data/lib/fog/proxmox/identity/requests/delete_token.rb +40 -0
  106. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_user.rb +0 -0
  107. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_domain.rb +0 -0
  108. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_group.rb +0 -0
  109. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_pool.rb +0 -0
  110. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_role.rb +0 -0
  111. data/lib/fog/proxmox/identity/requests/get_token_info.rb +41 -0
  112. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_user.rb +0 -0
  113. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_domains.rb +0 -0
  114. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_groups.rb +0 -0
  115. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_permissions.rb +0 -0
  116. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_pools.rb +0 -0
  117. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_roles.rb +0 -0
  118. data/lib/fog/proxmox/identity/requests/list_tokens.rb +41 -0
  119. data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +44 -0
  120. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_users.rb +0 -0
  121. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/read_version.rb +0 -0
  122. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_domain.rb +0 -0
  123. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_group.rb +0 -0
  124. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_permissions.rb +0 -0
  125. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_pool.rb +0 -0
  126. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_role.rb +0 -0
  127. data/lib/fog/proxmox/identity/requests/update_token.rb +41 -0
  128. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_user.rb +0 -0
  129. data/lib/fog/{network/proxmox.rb → proxmox/network.rb} +21 -14
  130. data/lib/fog/{network/proxmox → proxmox/network}/models/network.rb +0 -0
  131. data/lib/fog/{network/proxmox → proxmox/network}/models/networks.rb +1 -1
  132. data/lib/fog/{network/proxmox → proxmox/network}/models/node.rb +1 -1
  133. data/lib/fog/{network/proxmox → proxmox/network}/models/nodes.rb +1 -1
  134. data/lib/fog/{network/proxmox → proxmox/network}/requests/create_network.rb +0 -0
  135. data/lib/fog/{network/proxmox → proxmox/network}/requests/delete_network.rb +0 -0
  136. data/lib/fog/{network/proxmox → proxmox/network}/requests/get_network.rb +0 -0
  137. data/lib/fog/{network/proxmox → proxmox/network}/requests/get_node.rb +0 -0
  138. data/lib/fog/{network/proxmox → proxmox/network}/requests/list_networks.rb +0 -0
  139. data/lib/fog/{network/proxmox → proxmox/network}/requests/list_nodes.rb +0 -0
  140. data/lib/fog/{network/proxmox → proxmox/network}/requests/power_node.rb +0 -0
  141. data/lib/fog/{network/proxmox → proxmox/network}/requests/update_network.rb +0 -0
  142. data/lib/fog/{storage/proxmox.rb → proxmox/storage.rb} +1 -1
  143. data/lib/fog/proxmox/version.rb +1 -1
  144. data/spec/compute_spec.rb +4 -4
  145. data/spec/fixtures/proxmox/compute/common_auth.yml +40 -0
  146. data/spec/fixtures/proxmox/compute/containers.yml +1752 -7568
  147. data/spec/fixtures/proxmox/compute/nodes.yml +24 -30
  148. data/spec/fixtures/proxmox/compute/servers.yml +5015 -10683
  149. data/spec/fixtures/proxmox/compute/snapshots.yml +479 -1719
  150. data/spec/fixtures/proxmox/compute/storages.yml +32 -40
  151. data/spec/fixtures/proxmox/compute/tasks.yml +118 -338
  152. data/spec/fixtures/proxmox/identity/auth.yml +9 -11
  153. data/spec/fixtures/proxmox/identity/auth_access_ticket.yml +77 -0
  154. data/spec/fixtures/proxmox/identity/auth_user_token.yml +77 -0
  155. data/spec/fixtures/proxmox/identity/common_auth.yml +40 -0
  156. data/spec/fixtures/proxmox/identity/domains.yml +146 -178
  157. data/spec/fixtures/proxmox/identity/groups.yml +72 -90
  158. data/spec/fixtures/proxmox/identity/permissions.yml +301 -193
  159. data/spec/fixtures/proxmox/identity/pools.yml +422 -159
  160. data/spec/fixtures/proxmox/identity/read_version.yml +7 -9
  161. data/spec/fixtures/proxmox/identity/roles.yml +74 -92
  162. data/spec/fixtures/proxmox/identity/tokens.yml +494 -0
  163. data/spec/fixtures/proxmox/identity/users.yml +149 -187
  164. data/spec/fixtures/proxmox/network/common_auth.yml +40 -0
  165. data/spec/fixtures/proxmox/network/networks.yml +99 -96
  166. data/spec/helpers/cpu_helper_spec.rb +28 -21
  167. data/spec/helpers/disk_helper_spec.rb +231 -175
  168. data/spec/helpers/nic_helper_spec.rb +113 -114
  169. data/spec/identity_spec.rb +116 -28
  170. data/spec/network_spec.rb +3 -3
  171. data/spec/proxmox_vcr.rb +24 -22
  172. data/spec/spec_helper.rb +4 -3
  173. metadata +160 -145
  174. data/.gitlab-ci.yml +0 -50
  175. data/.travis.yml +0 -20
  176. data/lib/fog/compute/proxmox/requests/list_servers.rb +0 -42
  177. data/spec/fixtures/proxmox/compute/identity_ticket.yml +0 -40
  178. data/spec/fixtures/proxmox/identity/identity_ticket.yml +0 -40
  179. data/spec/fixtures/proxmox/identity/renew.yml +0 -40
  180. data/spec/fixtures/proxmox/network/identity_ticket.yml +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b70163a7fccb9ed54779d18ca8dc37d6ea04fec9ab2c94c91d13282feb589c6
4
- data.tar.gz: 65b66339365af13f176e4cd4410f58bd9fa46c10c45082852b36bb5beaa4332b
3
+ metadata.gz: 2e153a5fb10f314d09cc54eec5e8b2a6733120fe5c82ab6a809f203d2211fbfa
4
+ data.tar.gz: 7f2aa37e3830abb05c6717dc3f9e1705bfb8aebfa6cf52b2726a81a430ce1ac9
5
5
  SHA512:
6
- metadata.gz: 6e85b1ec840dd0bb45da7eec64fb4b0a0727cf99fadc08a6a2f8a1b6a389a280b6ea36420bb611f645be77f19c351b00651f08d32e9448f904f1e4b1e0a91ee4
7
- data.tar.gz: 7e4fcd61713c55989078272a458b98fddb6399eacf36e5dc0d2678925799a48179097cec35bcc0f2332569b432d1c275fd5b25c50ba5d2fe4f3697c6c8f7ec69
6
+ metadata.gz: 615ea980593082a11de74ad48d342df7ea3d5af4a39c9ae467280990ec6fcbc54c6589fe40e824b0ce7429f041707eb6953f71eb6bc3bcd23146ba37d3d98737
7
+ data.tar.gz: 73174f09ca4246a44b357d2f6c9b86daf01808623766877f04b59f210dcb581f056b32954aa9d2e919384d7a371bb0edbc720d3196867b9631cf8375d8f76e79
@@ -0,0 +1,79 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+ release:
9
+ types: [created]
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6
20
+ - name: Install dependencies
21
+ run: bundle install
22
+ - name: Run tests
23
+ run: bundle exec rake test spec audit
24
+ - name: Upload results for coverage
25
+ uses: actions/upload-artifact@v1
26
+ with:
27
+ name: coverage
28
+ path: coverage/
29
+
30
+ coverage:
31
+ needs: [ test ]
32
+ name: coverage
33
+ runs-on: ubuntu-latest
34
+ steps:
35
+ - uses: actions/checkout@v2
36
+ - name: Download tests result from test
37
+ uses: actions/download-artifact@v1
38
+ with:
39
+ name: coverage
40
+ - name: Install Code Climate test-reporter
41
+ run: |
42
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
43
+ chmod +x ./cc-test-reporter
44
+ - name: Format code coverage
45
+ env:
46
+ GIT_BRANCH: ${{ github.ref }}
47
+ GIT_COMMIT_SHA: ${{ github.sha }}
48
+ run: |
49
+ export GIT_COMMITTED_AT="$(date +%s)"
50
+ ./cc-test-reporter format-coverage -d -t simplecov -o coverage/codeclimate.json coverage/.resultset.json
51
+ - name: Publish code coverage
52
+ env:
53
+ GIT_BRANCH: ${{ github.ref }}
54
+ GIT_COMMIT_SHA: ${{ github.sha }}
55
+ run: |
56
+ export GIT_COMMITTED_AT="$(date +%s)"
57
+ ./cc-test-reporter upload-coverage -d -r ${{secrets.CC_TEST_REPORTER_ID}}
58
+
59
+ publish:
60
+ needs: [ test ]
61
+ name: publish
62
+ runs-on: ubuntu-latest
63
+ if: contains(github.ref, '/tags/v')
64
+ steps:
65
+ - uses: actions/checkout@v2
66
+ - name: Set up Ruby 2.6
67
+ uses: actions/setup-ruby@v1
68
+ with:
69
+ version: 2.6.x
70
+ - name: Publish to RubyGems
71
+ env:
72
+ GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
73
+ run: |
74
+ mkdir -p $HOME/.gem
75
+ touch $HOME/.gem/credentials
76
+ chmod 0600 $HOME/.gem/credentials
77
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
78
+ gem build *.gemspec
79
+ gem push *.gem
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ spec/debug/
5
5
  coverage/
6
6
  TAGS
7
7
  Gemfile.lock
8
+ *.gem
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.4
3
3
  Include:
4
4
  - '**/Rakefile'
5
5
  Exclude:
data/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  # Fog::Proxmox
4
4
 
5
- [![Build Status](https://travis-ci.org/fog/fog-proxmox.svg?branch=master)](https://travis-ci.org/fog/fog-proxmox)
5
+ ![CI](https://github.com/fog/fog-proxmox/workflows/CI/badge.svg)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/33e619f2167cc9864b61/maintainability)](https://codeclimate.com/github/fog/fog-proxmox/maintainability)
7
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/33e619f2167cc9864b61/test_coverage)](https://codeclimate.com/github/fog/fog-proxmox/test_coverage)
8
+ [![Gem Version](https://badge.fury.io/rb/fog-proxmox.svg)](https://badge.fury.io/rb/fog-proxmox)
8
9
 
9
10
  This is a [FOG](http://fog.io/) (>= 2.1) module gem to support [Proxmox VE](https://www.proxmox.com/en/proxmox-ve)
10
11
 
@@ -21,6 +22,7 @@ It is inspired by the great [fog-openstack](https://github.com/fog/fog-openstack
21
22
  |>=0.8|>=5.4|>=1.45|>=2.3|
22
23
  |>=0.9|>=6.0|>=2.1|>=2.3|
23
24
  |>=0.10|>=6.0|>=2.1|>=2.5|
25
+ |>=0.14|>=6.2|>=2.1|>=2.5|
24
26
 
25
27
  ## Installation
26
28
 
@@ -57,7 +59,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
57
59
  To record your VCR cassettes:
58
60
 
59
61
  ```shell
60
- PVE_URL=https://192.168.56.101:8006/api2/json DISABLE_PROXY=true SSL_VERIFY_PEER=false bundle exec rake spec
62
+ PROXMOX_URL=https://192.168.56.101:8006/api2/json DISABLE_PROXY=true SSL_VERIFY_PEER=false bundle exec rake spec
61
63
  ```
62
64
 
63
65
  To replay your recorded tests:
@@ -66,6 +68,12 @@ To replay your recorded tests:
66
68
  USE_VCR=true bundle exec rake spec
67
69
  ```
68
70
 
71
+ Code formatting:
72
+
73
+ ```shell
74
+ bundle exec bin/rake rubocop
75
+ ```
76
+
69
77
  ## Contributing
70
78
 
71
79
  You can reach the [contributors](.github/CONTRIBUTORS.md).
data/docs/compute.md CHANGED
@@ -18,16 +18,32 @@ require 'fog/proxmox'
18
18
 
19
19
  ## Create compute service
20
20
 
21
+ with access ticket:
22
+
23
+ ```ruby
24
+ identity = Fog::Proxmox::Identity.new(
25
+ proxmox_url: 'https://localhost:8006/api2/json',
26
+ proxmox_auth_method: 'access_ticket',
27
+ proxmox_username: 'your_user@your_realm',
28
+ proxmox_password: 'his_password',
29
+ connection_options: { ... }
30
+ )
31
+ ```
32
+
33
+ with API user token:
34
+
21
35
  ```ruby
22
- compute = Fog::Proxmox::Compute.new(
23
- pve_username: PVE_USERNAME, # your user name
24
- pve_password: PVE_PASSWORD, # your password
25
- pve_url: PVE_URL, # your server url
26
- connection_options: {} # connection options
27
- )
36
+ identity = Fog::Proxmox::Identity.new(
37
+ proxmox_url: 'https://localhost:8006/api2/json',
38
+ proxmox_auth_method: 'user_token',
39
+ proxmox_userid: 'your_user',
40
+ proxmox_tokenid: 'his_tokenid',
41
+ proxmox_token: 'his_token',
42
+ connection_options: { ... }
43
+ )
28
44
  ```
29
45
 
30
- [connection_options](connection_parameters.md) are also available.
46
+ [connection_options](connection_parameters.md) are also available and optional.
31
47
 
32
48
  ## Fog Abstractions
33
49
 
data/docs/identity.md CHANGED
@@ -18,16 +18,32 @@ require 'fog/proxmox'
18
18
 
19
19
  ## Create identity service
20
20
 
21
+ with access ticket:
22
+
23
+ ```ruby
24
+ identity = Fog::Proxmox::Identity.new(
25
+ proxmox_url: 'https://localhost:8006/api2/json',
26
+ proxmox_auth_method: 'access_ticket',
27
+ proxmox_username: 'your_user@your_realm',
28
+ proxmox_password: 'his_password',
29
+ connection_options: { ... }
30
+ )
31
+ ```
32
+
33
+ with API user token:
34
+
21
35
  ```ruby
22
36
  identity = Fog::Proxmox::Identity.new(
23
- pve_username: PVE_USERNAME, # your user name
24
- pve_password: PVE_PASSWORD, # your password
25
- pve_url: PVE_URL, # your server url
26
- connection_options: {} # connection options
27
- )
37
+ proxmox_url: 'https://localhost:8006/api2/json',
38
+ proxmox_auth_method: 'user_token',
39
+ proxmox_userid: 'your_user@your_realm',
40
+ proxmox_tokenid: 'his_tokenid',
41
+ proxmox_token: 'his_token',
42
+ connection_options: { ... }
43
+ )
28
44
  ```
29
45
 
30
- [connection_options](connection_parameters.md) are also available.
46
+ [connection_options](connection_parameters.md) are also available and optional.
31
47
 
32
48
  ## Fog Abstractions
33
49
 
@@ -312,6 +328,15 @@ identity.permissions.remove({
312
328
  users: 'bobsinclar@pve'
313
329
  })
314
330
  ```
331
+
332
+ User permissions:
333
+
334
+
335
+ ```ruby
336
+ bob = identity.users.get 'bobsinclar@pve'
337
+ bob.permissions
338
+ ```
339
+
315
340
  #### Pools management
316
341
 
317
342
  Proxmox supports pools management of VMs or storages. It eases managing permissions on these.
data/examples/compute.rb CHANGED
@@ -19,22 +19,22 @@
19
19
 
20
20
  # There are basically two modes of operation for these specs.
21
21
  #
22
- # 1. ENV[PVE_URL] exists: talk to an actual Proxmox server and record HTTP
22
+ # 1. ENV[PROXMOX_URL] exists: talk to an actual Proxmox server and record HTTP
23
23
  # traffic in VCRs at "spec/debug" (credentials are read from the conventional
24
- # environment variables: PVE_URL, PVE_USERNAME, PVE_PASSWORD)
24
+ # environment variables: PROXMOX_URL, PROXMOX_USERNAME, PROXMOX_PASSWORD)
25
25
  # 2. otherwise (Travis, etc): use VCRs at "spec/fixtures/proxmox/#{service}"
26
26
 
27
27
  require 'fog/proxmox'
28
28
 
29
- pve_url = 'https://172.26.49.146:8006/api2/json'
30
- pve_username = 'root@pam'
31
- pve_password = 'proxmox01'
29
+ proxmox_url = 'https://172.26.49.146:8006/api2/json'
30
+ proxmox_username = 'root@pam'
31
+ proxmox_password = 'proxmox01'
32
32
 
33
33
  # Create service compute
34
34
  compute = Fog::Proxmox::Compute.new(
35
- pve_url: pve_url,
36
- pve_username: pve_username,
37
- pve_password: pve_password
35
+ proxmox_url: proxmox_url,
36
+ proxmox_username: proxmox_username,
37
+ proxmox_password: proxmox_password
38
38
  )
39
39
 
40
40
  # Create pools
@@ -62,7 +62,7 @@ pool1.destroy
62
62
  # Create servers
63
63
 
64
64
  # Get node owner
65
- node_name = 'pve'
65
+ node_name = 'proxmox'
66
66
  node = compute.nodes.get node_name
67
67
 
68
68
  # Get next free vmid
@@ -170,7 +170,7 @@ server.config.disks
170
170
  server.destroy
171
171
 
172
172
  # Create containers
173
- node_name = 'pve'
173
+ node_name = 'proxmox'
174
174
  node = compute.nodes.get node_name
175
175
  ostemplate = 'local:vztmpl/alpine-3.7-default_20171211_amd64.tar.xz'
176
176
  container_hash = {
@@ -267,7 +267,7 @@ container.destroy
267
267
 
268
268
  # List 1 task
269
269
  filters = { limit: 1 }
270
- node = compute.nodes.get 'pve'
270
+ node = compute.nodes.get 'proxmox'
271
271
  tasks = node.tasks.all(filters)
272
272
  # Get task
273
273
  upid = tasks[0].upid
data/examples/identity.rb CHANGED
@@ -20,30 +20,40 @@
20
20
 
21
21
  # There are basically two modes of operation for these specs.
22
22
  #
23
- # 1. ENV[PVE_URL] exists: talk to an actual Proxmox server and record HTTP
23
+ # 1. ENV[PROXMOX_URL] exists: talk to an actual Proxmox server and record HTTP
24
24
  # traffic in VCRs at "spec/debug" (credentials are read from the conventional
25
- # environment variables: PVE_URL, PVE_USERNAME, PVE_PASSWORD)
25
+ # environment variables: PROXMOX_URL, PROXMOX_USERNAME, PROXMOX_PASSWORD)
26
26
  # 2. otherwise (Travis, etc): use VCRs at "spec/fixtures/proxmox/#{service}"
27
27
 
28
28
  require 'fog/proxmox'
29
29
 
30
- pve_url = 'https://172.26.49.146:8006/api2/json'
31
- pve_username = 'root@pam'
32
- pve_password = 'proxmox01'
30
+ proxmox_url = 'https://172.26.49.146:8006/api2/json'
31
+ proxmox_username = 'root@pam'
32
+ proxmox_password = 'proxmox01'
33
33
 
34
- # Create service identity
34
+ # Create service identity with access ticket
35
35
  identity = Fog::Proxmox::Identity.new(
36
- pve_url: pve_url,
37
- pve_username: pve_username,
38
- pve_password: pve_password
36
+ proxmox_url: proxmox_url,
37
+ proxmox_auth_method: 'access_ticket',
38
+ proxmox_username: proxmox_username,
39
+ proxmox_password: proxmox_password
39
40
  )
40
41
 
42
+ # or with a user token
43
+ identity = Fog::Proxmox::Identity.new(
44
+ proxmox_url: proxmox_url,
45
+ proxmox_auth_method: 'user_token',
46
+ proxmox_userid: proxmox_username,
47
+ proxmox_tokenid: 'root1',
48
+ proxmox_token: 'ed6402b4-641d-46b1-b20a-33ba9ba12f54'
49
+ )
50
+
41
51
  # Get proxmox version
42
52
  identity.read_version
43
53
 
44
54
  # Create a new user
45
55
  bob_hash = {
46
- userid: 'bobsinclar@pve',
56
+ userid: 'bobsinclar@proxmox',
47
57
  password: 'bobsinclar1',
48
58
  firstname: 'Bob',
49
59
  lastname: 'Sinclar',
@@ -53,7 +63,7 @@ bob_hash = {
53
63
  identity.users.create(bob_hash)
54
64
 
55
65
  # Get a user by id
56
- bob = identity.users.get 'bobsinclar@pve'
66
+ bob = identity.users.get 'bobsinclar@proxmox'
57
67
 
58
68
  # List all users
59
69
  identity.users.all
@@ -69,6 +79,9 @@ bob.comment = 'novelist'
69
79
  bob.groups = %w[group1]
70
80
  bob.update
71
81
 
82
+ # List user permissions
83
+ bob.permissions
84
+
72
85
  # Delete user
73
86
  bob.destroy
74
87
 
@@ -117,8 +130,8 @@ end
117
130
  role1.destroy
118
131
 
119
132
  # Create a new domain (authentication server)
120
- # Three types: PAM, PVE, LDAP and ActiveDirectory
121
- # PAM and PVE already exist by default
133
+ # Three types: PAM, PROXMOX, LDAP and ActiveDirectory
134
+ # PAM and PROXMOX already exist by default
122
135
  # LDAP sample:
123
136
  ldap_hash = {
124
137
  realm: 'LDAP',
@@ -165,14 +178,14 @@ ldap.destroy
165
178
  permission_hash = {
166
179
  type: 'user'
167
180
  path: '/access',
168
- roleid: 'PVEUserAdmin',
181
+ roleid: 'PROXMOXUserAdmin',
169
182
  ugid: bob_hash[:userid]
170
183
  }
171
184
  # Add a group permission
172
185
  # permission_hash = {
173
186
  # type: 'group'
174
187
  # path: '/access',
175
- # roleid: 'PVEUserAdmin',
188
+ # roleid: 'PROXMOXUserAdmin',
176
189
  # ugid: 'group1'
177
190
  # }
178
191
  permission = identity.permissions.create(permission_hash)
data/fog-proxmox.gemspec CHANGED
@@ -40,6 +40,7 @@ Gem::Specification.new do |spec|
40
40
  spec.rubygems_version = '~> 2.6'
41
41
 
42
42
  spec.add_development_dependency 'bundler', '~> 2.1'
43
+ spec.add_development_dependency 'bundler-audit', '~> 0.6'
43
44
  spec.add_development_dependency 'debase', '~> 0.2.2'
44
45
  spec.add_development_dependency 'debride', '~> 1.8'
45
46
  spec.add_development_dependency 'fasterer', '~> 0.3'
@@ -52,10 +53,9 @@ Gem::Specification.new do |spec|
52
53
  spec.add_development_dependency 'rspec', '~> 3.7'
53
54
  spec.add_development_dependency 'rubocop', '~> 0.55'
54
55
  spec.add_development_dependency 'ruby-debug-ide', '~> 0.6'
55
- spec.add_development_dependency 'simplecov'
56
+ spec.add_development_dependency 'simplecov', '0.17'
56
57
  spec.add_development_dependency 'vcr', '~> 4.0'
57
58
  spec.add_development_dependency 'webmock', '~> 3.5'
58
- spec.add_development_dependency 'bundler-audit', '~> 0.6'
59
59
 
60
60
  spec.add_dependency 'fog-core', '~> 2.1'
61
61
  spec.add_dependency 'fog-json', '~> 1.2'
data/lib/fog/proxmox.rb CHANGED
@@ -18,98 +18,38 @@
18
18
 
19
19
  # frozen_string_literal: true
20
20
 
21
- require 'fog/proxmox/version'
22
- require 'fog/proxmox/core'
23
- require 'fog/proxmox/json'
24
21
  require 'fog/core'
25
22
  require 'fog/json'
26
23
 
27
24
  module Fog
28
25
  # Proxmox module
29
26
  module Proxmox
27
+
28
+ require 'fog/proxmox/auth/token'
29
+
30
+ autoload :Core, 'fog/proxmox/core'
31
+ autoload :Errors, 'fog/proxmox/errors'
32
+ autoload :Identity, 'fog/proxmox/identity'
33
+ autoload :Compute, 'fog/proxmox/compute'
34
+ autoload :Storage, 'fog/proxmox/storage'
35
+ autoload :Network, 'fog/proxmox/network'
36
+
30
37
  extend Fog::Provider
31
- autoload :Identity, File.expand_path('identity/proxmox', __dir__)
32
- autoload :Compute, File.expand_path('compute/proxmox', __dir__)
33
- autoload :Storage, File.expand_path('storage/proxmox', __dir__)
34
- autoload :Network, File.expand_path('network/proxmox', __dir__)
38
+
35
39
  service(:identity, 'Identity')
36
40
  service(:compute, 'Compute')
37
41
  service(:storage, 'Storage')
38
42
  service(:network, 'Network')
39
43
 
40
- @credentials = {}
44
+ @token_cache = {}
41
45
 
42
46
  class << self
43
- attr_reader :credentials
44
- attr_reader :version
45
- end
46
-
47
- def self.clear_credentials
48
- @credentials = {}
49
- end
50
-
51
- def self.authenticate(options, connection_options = {})
52
- get_credentials(options, connection_options)
53
- self
54
- end
55
-
56
- def self.authenticated?
57
- !@credentials.empty?
58
- end
59
-
60
- def self.credentials_has_expired?
61
- authenticated? && @credentials[:deadline] < Time.now
62
- end
63
-
64
- def self.extract_password(options)
65
- ticket = options[:pve_ticket]
66
- ticket ? ticket : options[:pve_password].to_s
67
- end
68
-
69
- def self.get_credentials(options, connection_options = {})
70
- pve_ticket_lifetime = options[:pve_ticket_lifetime]
71
- # Default lifetime ticket is 2 hours
72
- ticket_lifetime = pve_ticket_lifetime ? pve_ticket_lifetime : 2 * 60 * 60
73
- username = options[:pve_username].to_s
74
- password = extract_password(options)
75
- url = options[:pve_url]
76
- uri = URI.parse(url)
77
- @api_path = uri.path
78
- connection_options = connection_options.merge(path_prefix: @api_path)
79
- password = @credentials[:ticket] if credentials_has_expired?
80
- request_credentials(uri, connection_options, username, password, ticket_lifetime)
81
- end
82
-
83
- def self.request_credentials(uri, connection_options, username, password, ticket_lifetime)
84
- request = {
85
- expects: [200, 204],
86
- headers: { 'Accept' => 'application/json' },
87
- body: URI.encode_www_form(username: username, password: password),
88
- method: 'POST',
89
- path: 'access/ticket'
90
- }
91
- connection = Fog::Core::Connection.new(
92
- uri.to_s,
93
- false,
94
- connection_options
95
- )
96
- response = connection.request(request)
97
- data = Json.get_data(response)
98
- ticket = data['ticket']
99
- username = data['username']
100
- csrftoken = data['CSRFPreventionToken']
101
- epoch = Time.now.to_i + ticket_lifetime
102
- deadline = Time.at(epoch)
103
- save_credentials(username, ticket, csrftoken, deadline)
47
+ attr_accessor :token_cache
104
48
  end
105
49
 
106
- def self.save_credentials(username, ticket, csrftoken, deadline)
107
- @credentials = {
108
- username: username,
109
- ticket: ticket,
110
- csrftoken: csrftoken,
111
- deadline: deadline
112
- }
50
+ def self.clear_token_cache
51
+ Fog::Proxmox.token_cache = {}
113
52
  end
53
+
114
54
  end
115
55
  end