fog-proxmox 0.13.0 → 0.14.0
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/README.md +8 -1
- data/docs/compute.md +23 -7
- data/docs/identity.md +31 -6
- data/examples/compute.rb +11 -11
- data/examples/identity.rb +28 -15
- data/fog-proxmox.gemspec +1 -1
- data/lib/fog/proxmox.rb +16 -76
- data/lib/fog/proxmox/auth/token.rb +88 -0
- data/lib/fog/proxmox/auth/token/access_ticket.rb +85 -0
- data/lib/fog/proxmox/auth/token/user_token.rb +94 -0
- data/lib/fog/{compute/proxmox.rb → proxmox/compute.rb} +31 -16
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/disk.rb +15 -2
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/disks.rb +5 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/interface.rb +4 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/interfaces.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/node.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/nodes.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/server.rb +2 -2
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/server_config.rb +8 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/servers.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/snapshots.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/storage.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/storages.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/tasks.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/volume.rb +6 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/models/volumes.rb +1 -1
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/action_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/clone_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_backup.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_spice.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_term.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/create_vnc.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/delete_volume.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_node_statistics.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_config.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_server_status.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_snapshot_config.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_vnc.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/get_volume.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_nodes.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_servers.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_snapshots.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_storages.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_tasks.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/list_volumes.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/log_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/migrate_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_disk.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/move_volume.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/next_vmid.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_container.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/resize_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/rollback_snapshot.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/status_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/stop_task.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/template_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_server.rb +0 -0
- data/lib/fog/{compute/proxmox → proxmox/compute}/requests/update_snapshot.rb +0 -0
- data/lib/fog/proxmox/core.rb +66 -57
- data/lib/fog/proxmox/hash.rb +2 -2
- data/lib/fog/proxmox/helpers/cpu_helper.rb +48 -9
- data/lib/fog/proxmox/helpers/disk_helper.rb +42 -22
- data/lib/fog/proxmox/helpers/nic_helper.rb +28 -20
- data/lib/fog/{identity/proxmox.rb → proxmox/identity.rb} +31 -17
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/domain_type.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/domains.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/group.rb +4 -2
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/groups.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/permission.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/permissions.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/pools.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/principal.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/role.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/roles.rb +1 -1
- data/lib/fog/proxmox/identity/models/token.rb +71 -0
- data/lib/fog/proxmox/identity/models/token_info.rb +41 -0
- data/lib/fog/proxmox/identity/models/tokens.rb +58 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/user.rb +25 -2
- data/lib/fog/{identity/proxmox → proxmox/identity}/models/users.rb +1 -1
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/change_password.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/check_permissions.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/create_token.rb +40 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/create_user.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/delete_token.rb +40 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/delete_user.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/get_token_info.rb +41 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/get_user.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_domains.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_groups.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_permissions.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_pools.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_roles.rb +0 -0
- data/lib/fog/proxmox/identity/requests/list_tokens.rb +41 -0
- data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +44 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/list_users.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/read_version.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_domain.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_group.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_permissions.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_pool.rb +0 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_role.rb +0 -0
- data/lib/fog/proxmox/identity/requests/update_token.rb +41 -0
- data/lib/fog/{identity/proxmox → proxmox/identity}/requests/update_user.rb +0 -0
- data/lib/fog/{network/proxmox.rb → proxmox/network.rb} +21 -14
- data/lib/fog/{network/proxmox → proxmox/network}/models/network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/models/networks.rb +1 -1
- data/lib/fog/{network/proxmox → proxmox/network}/models/node.rb +1 -1
- data/lib/fog/{network/proxmox → proxmox/network}/models/nodes.rb +1 -1
- data/lib/fog/{network/proxmox → proxmox/network}/requests/create_network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/delete_network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/get_network.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/get_node.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/list_networks.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/list_nodes.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/power_node.rb +0 -0
- data/lib/fog/{network/proxmox → proxmox/network}/requests/update_network.rb +0 -0
- data/lib/fog/{storage/proxmox.rb → proxmox/storage.rb} +1 -1
- data/lib/fog/proxmox/version.rb +1 -1
- data/spec/compute_spec.rb +4 -4
- data/spec/fixtures/proxmox/compute/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/compute/containers.yml +1752 -7568
- data/spec/fixtures/proxmox/compute/nodes.yml +24 -30
- data/spec/fixtures/proxmox/compute/servers.yml +5015 -10683
- data/spec/fixtures/proxmox/compute/snapshots.yml +479 -1719
- data/spec/fixtures/proxmox/compute/storages.yml +32 -40
- data/spec/fixtures/proxmox/compute/tasks.yml +118 -338
- data/spec/fixtures/proxmox/identity/auth.yml +10 -12
- data/spec/fixtures/proxmox/identity/auth_access_ticket.yml +77 -0
- data/spec/fixtures/proxmox/identity/auth_user_token.yml +77 -0
- data/spec/fixtures/proxmox/identity/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/identity/domains.yml +145 -181
- data/spec/fixtures/proxmox/identity/groups.yml +72 -90
- data/spec/fixtures/proxmox/identity/permissions.yml +297 -189
- data/spec/fixtures/proxmox/identity/pools.yml +176 -421
- data/spec/fixtures/proxmox/identity/read_version.yml +7 -9
- data/spec/fixtures/proxmox/identity/roles.yml +69 -87
- data/spec/fixtures/proxmox/identity/tokens.yml +494 -0
- data/spec/fixtures/proxmox/identity/users.yml +149 -187
- data/spec/fixtures/proxmox/network/common_auth.yml +40 -0
- data/spec/fixtures/proxmox/network/networks.yml +99 -96
- data/spec/helpers/cpu_helper_spec.rb +27 -20
- data/spec/helpers/disk_helper_spec.rb +231 -187
- data/spec/helpers/nic_helper_spec.rb +113 -114
- data/spec/identity_spec.rb +110 -28
- data/spec/network_spec.rb +3 -3
- data/spec/proxmox_vcr.rb +24 -22
- data/spec/spec_helper.rb +4 -3
- metadata +155 -139
- data/spec/fixtures/proxmox/compute/identity_ticket.yml +0 -40
- data/spec/fixtures/proxmox/identity/identity_ticket.yml +0 -40
- data/spec/fixtures/proxmox/identity/renew.yml +0 -40
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e153a5fb10f314d09cc54eec5e8b2a6733120fe5c82ab6a809f203d2211fbfa
|
4
|
+
data.tar.gz: 7f2aa37e3830abb05c6717dc3f9e1705bfb8aebfa6cf52b2726a81a430ce1ac9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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[
|
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:
|
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
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
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 = '
|
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 = '
|
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 '
|
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[
|
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:
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
37
|
-
|
38
|
-
|
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@
|
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@
|
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,
|
121
|
-
# PAM and
|
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: '
|
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: '
|
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
|
-
|
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
|
-
@
|
44
|
+
@token_cache = {}
|
41
45
|
|
42
46
|
class << self
|
43
|
-
|
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.
|
107
|
-
|
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
|