fog-proxmox 0.13.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -1
  3. data/docs/compute.md +23 -7
  4. data/docs/identity.md +31 -6
  5. data/examples/compute.rb +11 -11
  6. data/examples/identity.rb +28 -15
  7. data/fog-proxmox.gemspec +1 -1
  8. data/lib/fog/proxmox.rb +16 -76
  9. data/lib/fog/proxmox/auth/token.rb +88 -0
  10. data/lib/fog/proxmox/auth/token/access_ticket.rb +85 -0
  11. data/lib/fog/proxmox/auth/token/user_token.rb +94 -0
  12. data/lib/fog/{compute/proxmox.rb → proxmox/compute.rb} +31 -16
  13. data/lib/fog/{compute/proxmox → proxmox/compute}/models/disk.rb +15 -2
  14. data/lib/fog/{compute/proxmox → proxmox/compute}/models/disks.rb +5 -1
  15. data/lib/fog/{compute/proxmox → proxmox/compute}/models/interface.rb +4 -0
  16. data/lib/fog/{compute/proxmox → proxmox/compute}/models/interfaces.rb +1 -1
  17. data/lib/fog/{compute/proxmox → proxmox/compute}/models/node.rb +0 -0
  18. data/lib/fog/{compute/proxmox → proxmox/compute}/models/nodes.rb +1 -1
  19. data/lib/fog/{compute/proxmox → proxmox/compute}/models/server.rb +2 -2
  20. data/lib/fog/{compute/proxmox → proxmox/compute}/models/server_config.rb +8 -0
  21. data/lib/fog/{compute/proxmox → proxmox/compute}/models/servers.rb +1 -1
  22. data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshot.rb +0 -0
  23. data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshots.rb +1 -1
  24. data/lib/fog/{compute/proxmox → proxmox/compute}/models/storage.rb +0 -0
  25. data/lib/fog/{compute/proxmox → proxmox/compute}/models/storages.rb +1 -1
  26. data/lib/fog/{compute/proxmox → proxmox/compute}/models/task.rb +0 -0
  27. data/lib/fog/{compute/proxmox → proxmox/compute}/models/tasks.rb +1 -1
  28. data/lib/fog/{compute/proxmox → proxmox/compute}/models/volume.rb +6 -0
  29. data/lib/fog/{compute/proxmox → proxmox/compute}/models/volumes.rb +1 -1
  30. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/action_server.rb +0 -0
  31. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/clone_server.rb +0 -0
  32. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_backup.rb +0 -0
  33. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_server.rb +0 -0
  34. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_snapshot.rb +0 -0
  35. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_spice.rb +0 -0
  36. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_term.rb +0 -0
  37. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_vnc.rb +0 -0
  38. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_server.rb +0 -0
  39. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_snapshot.rb +0 -0
  40. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_volume.rb +0 -0
  41. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_node_statistics.rb +0 -0
  42. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_config.rb +0 -0
  43. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_status.rb +0 -0
  44. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_snapshot_config.rb +0 -0
  45. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_task.rb +0 -0
  46. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_vnc.rb +0 -0
  47. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_volume.rb +0 -0
  48. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_nodes.rb +0 -0
  49. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_servers.rb +0 -0
  50. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_snapshots.rb +0 -0
  51. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_storages.rb +0 -0
  52. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_tasks.rb +0 -0
  53. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_volumes.rb +0 -0
  54. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/log_task.rb +0 -0
  55. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/migrate_server.rb +0 -0
  56. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_disk.rb +0 -0
  57. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_volume.rb +0 -0
  58. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/next_vmid.rb +0 -0
  59. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_container.rb +0 -0
  60. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_server.rb +0 -0
  61. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/rollback_snapshot.rb +0 -0
  62. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/status_task.rb +0 -0
  63. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/stop_task.rb +0 -0
  64. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/template_server.rb +0 -0
  65. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_server.rb +0 -0
  66. data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_snapshot.rb +0 -0
  67. data/lib/fog/proxmox/core.rb +66 -57
  68. data/lib/fog/proxmox/hash.rb +2 -2
  69. data/lib/fog/proxmox/helpers/cpu_helper.rb +48 -9
  70. data/lib/fog/proxmox/helpers/disk_helper.rb +42 -22
  71. data/lib/fog/proxmox/helpers/nic_helper.rb +28 -20
  72. data/lib/fog/{identity/proxmox.rb → proxmox/identity.rb} +31 -17
  73. data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain.rb +0 -0
  74. data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain_type.rb +0 -0
  75. data/lib/fog/{identity/proxmox → proxmox/identity}/models/domains.rb +1 -1
  76. data/lib/fog/{identity/proxmox → proxmox/identity}/models/group.rb +4 -2
  77. data/lib/fog/{identity/proxmox → proxmox/identity}/models/groups.rb +1 -1
  78. data/lib/fog/{identity/proxmox → proxmox/identity}/models/permission.rb +0 -0
  79. data/lib/fog/{identity/proxmox → proxmox/identity}/models/permissions.rb +1 -1
  80. data/lib/fog/{identity/proxmox → proxmox/identity}/models/pool.rb +0 -0
  81. data/lib/fog/{identity/proxmox → proxmox/identity}/models/pools.rb +1 -1
  82. data/lib/fog/{identity/proxmox → proxmox/identity}/models/principal.rb +0 -0
  83. data/lib/fog/{identity/proxmox → proxmox/identity}/models/role.rb +0 -0
  84. data/lib/fog/{identity/proxmox → proxmox/identity}/models/roles.rb +1 -1
  85. data/lib/fog/proxmox/identity/models/token.rb +71 -0
  86. data/lib/fog/proxmox/identity/models/token_info.rb +41 -0
  87. data/lib/fog/proxmox/identity/models/tokens.rb +58 -0
  88. data/lib/fog/{identity/proxmox → proxmox/identity}/models/user.rb +25 -2
  89. data/lib/fog/{identity/proxmox → proxmox/identity}/models/users.rb +1 -1
  90. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/change_password.rb +0 -0
  91. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/check_permissions.rb +0 -0
  92. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_domain.rb +0 -0
  93. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_group.rb +0 -0
  94. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_pool.rb +0 -0
  95. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_role.rb +0 -0
  96. data/lib/fog/proxmox/identity/requests/create_token.rb +40 -0
  97. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_user.rb +0 -0
  98. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_domain.rb +0 -0
  99. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_group.rb +0 -0
  100. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_pool.rb +0 -0
  101. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_role.rb +0 -0
  102. data/lib/fog/proxmox/identity/requests/delete_token.rb +40 -0
  103. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_user.rb +0 -0
  104. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_domain.rb +0 -0
  105. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_group.rb +0 -0
  106. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_pool.rb +0 -0
  107. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_role.rb +0 -0
  108. data/lib/fog/proxmox/identity/requests/get_token_info.rb +41 -0
  109. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_user.rb +0 -0
  110. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_domains.rb +0 -0
  111. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_groups.rb +0 -0
  112. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_permissions.rb +0 -0
  113. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_pools.rb +0 -0
  114. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_roles.rb +0 -0
  115. data/lib/fog/proxmox/identity/requests/list_tokens.rb +41 -0
  116. data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +44 -0
  117. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_users.rb +0 -0
  118. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/read_version.rb +0 -0
  119. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_domain.rb +0 -0
  120. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_group.rb +0 -0
  121. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_permissions.rb +0 -0
  122. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_pool.rb +0 -0
  123. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_role.rb +0 -0
  124. data/lib/fog/proxmox/identity/requests/update_token.rb +41 -0
  125. data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_user.rb +0 -0
  126. data/lib/fog/{network/proxmox.rb → proxmox/network.rb} +21 -14
  127. data/lib/fog/{network/proxmox → proxmox/network}/models/network.rb +0 -0
  128. data/lib/fog/{network/proxmox → proxmox/network}/models/networks.rb +1 -1
  129. data/lib/fog/{network/proxmox → proxmox/network}/models/node.rb +1 -1
  130. data/lib/fog/{network/proxmox → proxmox/network}/models/nodes.rb +1 -1
  131. data/lib/fog/{network/proxmox → proxmox/network}/requests/create_network.rb +0 -0
  132. data/lib/fog/{network/proxmox → proxmox/network}/requests/delete_network.rb +0 -0
  133. data/lib/fog/{network/proxmox → proxmox/network}/requests/get_network.rb +0 -0
  134. data/lib/fog/{network/proxmox → proxmox/network}/requests/get_node.rb +0 -0
  135. data/lib/fog/{network/proxmox → proxmox/network}/requests/list_networks.rb +0 -0
  136. data/lib/fog/{network/proxmox → proxmox/network}/requests/list_nodes.rb +0 -0
  137. data/lib/fog/{network/proxmox → proxmox/network}/requests/power_node.rb +0 -0
  138. data/lib/fog/{network/proxmox → proxmox/network}/requests/update_network.rb +0 -0
  139. data/lib/fog/{storage/proxmox.rb → proxmox/storage.rb} +1 -1
  140. data/lib/fog/proxmox/version.rb +1 -1
  141. data/spec/compute_spec.rb +4 -4
  142. data/spec/fixtures/proxmox/compute/common_auth.yml +40 -0
  143. data/spec/fixtures/proxmox/compute/containers.yml +1752 -7568
  144. data/spec/fixtures/proxmox/compute/nodes.yml +24 -30
  145. data/spec/fixtures/proxmox/compute/servers.yml +5015 -10683
  146. data/spec/fixtures/proxmox/compute/snapshots.yml +479 -1719
  147. data/spec/fixtures/proxmox/compute/storages.yml +32 -40
  148. data/spec/fixtures/proxmox/compute/tasks.yml +118 -338
  149. data/spec/fixtures/proxmox/identity/auth.yml +10 -12
  150. data/spec/fixtures/proxmox/identity/auth_access_ticket.yml +77 -0
  151. data/spec/fixtures/proxmox/identity/auth_user_token.yml +77 -0
  152. data/spec/fixtures/proxmox/identity/common_auth.yml +40 -0
  153. data/spec/fixtures/proxmox/identity/domains.yml +145 -181
  154. data/spec/fixtures/proxmox/identity/groups.yml +72 -90
  155. data/spec/fixtures/proxmox/identity/permissions.yml +297 -189
  156. data/spec/fixtures/proxmox/identity/pools.yml +176 -421
  157. data/spec/fixtures/proxmox/identity/read_version.yml +7 -9
  158. data/spec/fixtures/proxmox/identity/roles.yml +69 -87
  159. data/spec/fixtures/proxmox/identity/tokens.yml +494 -0
  160. data/spec/fixtures/proxmox/identity/users.yml +149 -187
  161. data/spec/fixtures/proxmox/network/common_auth.yml +40 -0
  162. data/spec/fixtures/proxmox/network/networks.yml +99 -96
  163. data/spec/helpers/cpu_helper_spec.rb +27 -20
  164. data/spec/helpers/disk_helper_spec.rb +231 -187
  165. data/spec/helpers/nic_helper_spec.rb +113 -114
  166. data/spec/identity_spec.rb +110 -28
  167. data/spec/network_spec.rb +3 -3
  168. data/spec/proxmox_vcr.rb +24 -22
  169. data/spec/spec_helper.rb +4 -3
  170. metadata +155 -139
  171. data/spec/fixtures/proxmox/compute/identity_ticket.yml +0 -40
  172. data/spec/fixtures/proxmox/identity/identity_ticket.yml +0 -40
  173. data/spec/fixtures/proxmox/identity/renew.yml +0 -40
  174. 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: 6c14d0c2b9706b9ccf13d70fb4b3f06496d74ab2469c93eed134e9ec1beffb37
4
- data.tar.gz: d7919eb9e2d9dff9a92f4377ef9bb0b101b5994b8e459b36443bb1881b6a3387
3
+ metadata.gz: 2e153a5fb10f314d09cc54eec5e8b2a6733120fe5c82ab6a809f203d2211fbfa
4
+ data.tar.gz: 7f2aa37e3830abb05c6717dc3f9e1705bfb8aebfa6cf52b2726a81a430ce1ac9
5
5
  SHA512:
6
- metadata.gz: d4fe53a4bd62f5a3664287d9b3a7683379537bddf315a907e8ee80ead4f2c00e76168e9da34c9fb4cdd2a1ad3b31aba4adc465622ca691d7f4db870a5c80755b
7
- data.tar.gz: 77cc6f9f1da87e845ddc442372fe827c58684aab525acf5f4c97fc2793e6f1ae4050cbbbfb3465f7e1e5b615b89c9ad521c1fdc56d143b37fa1a02086d347ef9
6
+ metadata.gz: 615ea980593082a11de74ad48d342df7ea3d5af4a39c9ae467280990ec6fcbc54c6589fe40e824b0ce7429f041707eb6953f71eb6bc3bcd23146ba37d3d98737
7
+ data.tar.gz: 73174f09ca4246a44b357d2f6c9b86daf01808623766877f04b59f210dcb581f056b32954aa9d2e919384d7a371bb0edbc720d3196867b9631cf8375d8f76e79
data/README.md CHANGED
@@ -22,6 +22,7 @@ It is inspired by the great [fog-openstack](https://github.com/fog/fog-openstack
22
22
  |>=0.8|>=5.4|>=1.45|>=2.3|
23
23
  |>=0.9|>=6.0|>=2.1|>=2.3|
24
24
  |>=0.10|>=6.0|>=2.1|>=2.5|
25
+ |>=0.14|>=6.2|>=2.1|>=2.5|
25
26
 
26
27
  ## Installation
27
28
 
@@ -58,7 +59,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
58
59
  To record your VCR cassettes:
59
60
 
60
61
  ```shell
61
- 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
62
63
  ```
63
64
 
64
65
  To replay your recorded tests:
@@ -67,6 +68,12 @@ To replay your recorded tests:
67
68
  USE_VCR=true bundle exec rake spec
68
69
  ```
69
70
 
71
+ Code formatting:
72
+
73
+ ```shell
74
+ bundle exec bin/rake rubocop
75
+ ```
76
+
70
77
  ## Contributing
71
78
 
72
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'
@@ -55,7 +56,6 @@ Gem::Specification.new do |spec|
55
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
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of Fog::Proxmox.
6
+
7
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+
12
+ # Fog::Proxmox is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'fog/json'
21
+ require 'fog/core'
22
+ require 'fog/proxmox/variables'
23
+ require 'fog/proxmox/json'
24
+
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
86
+ end
87
+ end
88
+ end