fog-proxmox-configlmm 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +8 -0
  3. data/LICENSE +674 -0
  4. data/README.md +110 -0
  5. data/docs/compute.md +874 -0
  6. data/docs/connection_parameters.md +45 -0
  7. data/docs/getting_started.md +53 -0
  8. data/docs/identity.md +382 -0
  9. data/examples/compute.rb +276 -0
  10. data/examples/identity.rb +203 -0
  11. data/lib/fog/proxmox/attributes.rb +34 -0
  12. data/lib/fog/proxmox/auth/token/access_ticket.rb +96 -0
  13. data/lib/fog/proxmox/auth/token/user_token.rb +107 -0
  14. data/lib/fog/proxmox/auth/token.rb +94 -0
  15. data/lib/fog/proxmox/compute/models/disk.rb +94 -0
  16. data/lib/fog/proxmox/compute/models/disks.rb +55 -0
  17. data/lib/fog/proxmox/compute/models/interface.rb +56 -0
  18. data/lib/fog/proxmox/compute/models/interfaces.rb +44 -0
  19. data/lib/fog/proxmox/compute/models/node.rb +93 -0
  20. data/lib/fog/proxmox/compute/models/nodes.rb +39 -0
  21. data/lib/fog/proxmox/compute/models/server.rb +271 -0
  22. data/lib/fog/proxmox/compute/models/server_config.rb +161 -0
  23. data/lib/fog/proxmox/compute/models/servers.rb +80 -0
  24. data/lib/fog/proxmox/compute/models/snapshot.rb +83 -0
  25. data/lib/fog/proxmox/compute/models/snapshots.rb +47 -0
  26. data/lib/fog/proxmox/compute/models/storage.rb +65 -0
  27. data/lib/fog/proxmox/compute/models/storages.rb +51 -0
  28. data/lib/fog/proxmox/compute/models/task.rb +79 -0
  29. data/lib/fog/proxmox/compute/models/tasks.rb +65 -0
  30. data/lib/fog/proxmox/compute/models/volume.rb +68 -0
  31. data/lib/fog/proxmox/compute/models/volumes.rb +58 -0
  32. data/lib/fog/proxmox/compute/requests/action_server.rb +45 -0
  33. data/lib/fog/proxmox/compute/requests/clone_server.rb +44 -0
  34. data/lib/fog/proxmox/compute/requests/create_backup.rb +42 -0
  35. data/lib/fog/proxmox/compute/requests/create_server.rb +43 -0
  36. data/lib/fog/proxmox/compute/requests/create_snapshot.rb +46 -0
  37. data/lib/fog/proxmox/compute/requests/create_spice.rb +44 -0
  38. data/lib/fog/proxmox/compute/requests/create_term.rb +45 -0
  39. data/lib/fog/proxmox/compute/requests/create_vnc.rb +44 -0
  40. data/lib/fog/proxmox/compute/requests/delete_server.rb +45 -0
  41. data/lib/fog/proxmox/compute/requests/delete_snapshot.rb +47 -0
  42. data/lib/fog/proxmox/compute/requests/delete_volume.rb +40 -0
  43. data/lib/fog/proxmox/compute/requests/get_node_statistics.rb +44 -0
  44. data/lib/fog/proxmox/compute/requests/get_server_config.rb +60 -0
  45. data/lib/fog/proxmox/compute/requests/get_server_status.rb +63 -0
  46. data/lib/fog/proxmox/compute/requests/get_snapshot_config.rb +44 -0
  47. data/lib/fog/proxmox/compute/requests/get_task.rb +41 -0
  48. data/lib/fog/proxmox/compute/requests/get_vnc.rb +45 -0
  49. data/lib/fog/proxmox/compute/requests/get_volume.rb +42 -0
  50. data/lib/fog/proxmox/compute/requests/list_nodes.rb +48 -0
  51. data/lib/fog/proxmox/compute/requests/list_servers.rb +113 -0
  52. data/lib/fog/proxmox/compute/requests/list_snapshots.rb +66 -0
  53. data/lib/fog/proxmox/compute/requests/list_storages.rb +46 -0
  54. data/lib/fog/proxmox/compute/requests/list_tasks.rb +44 -0
  55. data/lib/fog/proxmox/compute/requests/list_volumes.rb +44 -0
  56. data/lib/fog/proxmox/compute/requests/log_task.rb +44 -0
  57. data/lib/fog/proxmox/compute/requests/migrate_server.rb +44 -0
  58. data/lib/fog/proxmox/compute/requests/move_disk.rb +43 -0
  59. data/lib/fog/proxmox/compute/requests/move_volume.rb +43 -0
  60. data/lib/fog/proxmox/compute/requests/next_vmid.rb +42 -0
  61. data/lib/fog/proxmox/compute/requests/resize_container.rb +43 -0
  62. data/lib/fog/proxmox/compute/requests/resize_server.rb +43 -0
  63. data/lib/fog/proxmox/compute/requests/rollback_snapshot.rb +48 -0
  64. data/lib/fog/proxmox/compute/requests/status_task.rb +41 -0
  65. data/lib/fog/proxmox/compute/requests/stop_task.rb +41 -0
  66. data/lib/fog/proxmox/compute/requests/template_server.rb +44 -0
  67. data/lib/fog/proxmox/compute/requests/update_server.rb +44 -0
  68. data/lib/fog/proxmox/compute/requests/update_snapshot.rb +45 -0
  69. data/lib/fog/proxmox/compute.rb +141 -0
  70. data/lib/fog/proxmox/core.rb +147 -0
  71. data/lib/fog/proxmox/errors.rb +65 -0
  72. data/lib/fog/proxmox/hash.rb +37 -0
  73. data/lib/fog/proxmox/helpers/controller_helper.rb +63 -0
  74. data/lib/fog/proxmox/helpers/cpu_helper.rb +88 -0
  75. data/lib/fog/proxmox/helpers/disk_helper.rb +185 -0
  76. data/lib/fog/proxmox/helpers/ip_helper.rb +101 -0
  77. data/lib/fog/proxmox/helpers/nic_helper.rb +132 -0
  78. data/lib/fog/proxmox/identity/models/domain.rb +69 -0
  79. data/lib/fog/proxmox/identity/models/domain_type.rb +47 -0
  80. data/lib/fog/proxmox/identity/models/domains.rb +44 -0
  81. data/lib/fog/proxmox/identity/models/group.rb +51 -0
  82. data/lib/fog/proxmox/identity/models/groups.rb +44 -0
  83. data/lib/fog/proxmox/identity/models/permission.rb +66 -0
  84. data/lib/fog/proxmox/identity/models/permissions.rb +46 -0
  85. data/lib/fog/proxmox/identity/models/pool.rb +89 -0
  86. data/lib/fog/proxmox/identity/models/pools.rb +46 -0
  87. data/lib/fog/proxmox/identity/models/principal.rb +42 -0
  88. data/lib/fog/proxmox/identity/models/role.rb +48 -0
  89. data/lib/fog/proxmox/identity/models/roles.rb +44 -0
  90. data/lib/fog/proxmox/identity/models/token.rb +72 -0
  91. data/lib/fog/proxmox/identity/models/token_info.rb +41 -0
  92. data/lib/fog/proxmox/identity/models/tokens.rb +54 -0
  93. data/lib/fog/proxmox/identity/models/user.rb +82 -0
  94. data/lib/fog/proxmox/identity/models/users.rb +44 -0
  95. data/lib/fog/proxmox/identity/requests/change_password.rb +41 -0
  96. data/lib/fog/proxmox/identity/requests/check_permissions.rb +41 -0
  97. data/lib/fog/proxmox/identity/requests/create_domain.rb +40 -0
  98. data/lib/fog/proxmox/identity/requests/create_group.rb +40 -0
  99. data/lib/fog/proxmox/identity/requests/create_pool.rb +40 -0
  100. data/lib/fog/proxmox/identity/requests/create_role.rb +40 -0
  101. data/lib/fog/proxmox/identity/requests/create_token.rb +40 -0
  102. data/lib/fog/proxmox/identity/requests/create_user.rb +40 -0
  103. data/lib/fog/proxmox/identity/requests/delete_domain.rb +40 -0
  104. data/lib/fog/proxmox/identity/requests/delete_group.rb +40 -0
  105. data/lib/fog/proxmox/identity/requests/delete_pool.rb +39 -0
  106. data/lib/fog/proxmox/identity/requests/delete_role.rb +40 -0
  107. data/lib/fog/proxmox/identity/requests/delete_token.rb +40 -0
  108. data/lib/fog/proxmox/identity/requests/delete_user.rb +39 -0
  109. data/lib/fog/proxmox/identity/requests/get_domain.rb +41 -0
  110. data/lib/fog/proxmox/identity/requests/get_group.rb +41 -0
  111. data/lib/fog/proxmox/identity/requests/get_pool.rb +41 -0
  112. data/lib/fog/proxmox/identity/requests/get_role.rb +41 -0
  113. data/lib/fog/proxmox/identity/requests/get_token_info.rb +41 -0
  114. data/lib/fog/proxmox/identity/requests/get_user.rb +41 -0
  115. data/lib/fog/proxmox/identity/requests/list_domains.rb +41 -0
  116. data/lib/fog/proxmox/identity/requests/list_groups.rb +41 -0
  117. data/lib/fog/proxmox/identity/requests/list_permissions.rb +41 -0
  118. data/lib/fog/proxmox/identity/requests/list_pools.rb +41 -0
  119. data/lib/fog/proxmox/identity/requests/list_roles.rb +40 -0
  120. data/lib/fog/proxmox/identity/requests/list_tokens.rb +41 -0
  121. data/lib/fog/proxmox/identity/requests/list_user_permissions.rb +44 -0
  122. data/lib/fog/proxmox/identity/requests/list_users.rb +42 -0
  123. data/lib/fog/proxmox/identity/requests/read_version.rb +39 -0
  124. data/lib/fog/proxmox/identity/requests/update_domain.rb +41 -0
  125. data/lib/fog/proxmox/identity/requests/update_group.rb +40 -0
  126. data/lib/fog/proxmox/identity/requests/update_permissions.rb +41 -0
  127. data/lib/fog/proxmox/identity/requests/update_pool.rb +41 -0
  128. data/lib/fog/proxmox/identity/requests/update_role.rb +41 -0
  129. data/lib/fog/proxmox/identity/requests/update_token.rb +41 -0
  130. data/lib/fog/proxmox/identity/requests/update_user.rb +41 -0
  131. data/lib/fog/proxmox/identity.rb +144 -0
  132. data/lib/fog/proxmox/json.rb +32 -0
  133. data/lib/fog/proxmox/network/models/network.rb +76 -0
  134. data/lib/fog/proxmox/network/models/networks.rb +48 -0
  135. data/lib/fog/proxmox/network/models/node.rb +75 -0
  136. data/lib/fog/proxmox/network/models/nodes.rb +39 -0
  137. data/lib/fog/proxmox/network/requests/create_network.rb +41 -0
  138. data/lib/fog/proxmox/network/requests/delete_network.rb +42 -0
  139. data/lib/fog/proxmox/network/requests/get_network.rb +43 -0
  140. data/lib/fog/proxmox/network/requests/get_node.rb +41 -0
  141. data/lib/fog/proxmox/network/requests/list_networks.rb +43 -0
  142. data/lib/fog/proxmox/network/requests/list_nodes.rb +42 -0
  143. data/lib/fog/proxmox/network/requests/power_node.rb +43 -0
  144. data/lib/fog/proxmox/network/requests/update_network.rb +42 -0
  145. data/lib/fog/proxmox/network.rb +90 -0
  146. data/lib/fog/proxmox/storage/requests/create.rb +23 -0
  147. data/lib/fog/proxmox/storage/requests/download_appliance.rb +24 -0
  148. data/lib/fog/proxmox/storage/requests/list.rb +22 -0
  149. data/lib/fog/proxmox/storage/requests/list_appliances.rb +23 -0
  150. data/lib/fog/proxmox/storage/requests/upload.rb +44 -0
  151. data/lib/fog/proxmox/storage.rb +82 -0
  152. data/lib/fog/proxmox/string.rb +32 -0
  153. data/lib/fog/proxmox/variables.rb +40 -0
  154. data/lib/fog/proxmox/version.rb +24 -0
  155. data/lib/fog/proxmox.rb +53 -0
  156. data/spec/compute_spec.rb +447 -0
  157. data/spec/fixtures/proxmox/compute/common_auth.yml +40 -0
  158. data/spec/fixtures/proxmox/compute/containers.yml +6921 -0
  159. data/spec/fixtures/proxmox/compute/nodes.yml +115 -0
  160. data/spec/fixtures/proxmox/compute/servers.yml +19011 -0
  161. data/spec/fixtures/proxmox/compute/snapshots.yml +1376 -0
  162. data/spec/fixtures/proxmox/compute/storages.yml +151 -0
  163. data/spec/fixtures/proxmox/compute/tasks.yml +465 -0
  164. data/spec/fixtures/proxmox/identity/auth.yml +42 -0
  165. data/spec/fixtures/proxmox/identity/auth_access_ticket.yml +77 -0
  166. data/spec/fixtures/proxmox/identity/auth_user_token.yml +77 -0
  167. data/spec/fixtures/proxmox/identity/common_auth.yml +40 -0
  168. data/spec/fixtures/proxmox/identity/domains.yml +665 -0
  169. data/spec/fixtures/proxmox/identity/groups.yml +345 -0
  170. data/spec/fixtures/proxmox/identity/permissions.yml +911 -0
  171. data/spec/fixtures/proxmox/identity/pools.yml +946 -0
  172. data/spec/fixtures/proxmox/identity/read_version.yml +40 -0
  173. data/spec/fixtures/proxmox/identity/roles.yml +345 -0
  174. data/spec/fixtures/proxmox/identity/tokens.yml +494 -0
  175. data/spec/fixtures/proxmox/identity/users.yml +725 -0
  176. data/spec/fixtures/proxmox/network/common_auth.yml +40 -0
  177. data/spec/fixtures/proxmox/network/networks.yml +375 -0
  178. data/spec/fixtures/proxmox/pve.home +34 -0
  179. data/spec/hash_spec.rb +43 -0
  180. data/spec/helpers/controller_helper_spec.rb +157 -0
  181. data/spec/helpers/cpu_helper_spec.rb +82 -0
  182. data/spec/helpers/disk_helper_spec.rb +304 -0
  183. data/spec/helpers/ip_helper_spec.rb +177 -0
  184. data/spec/helpers/nic_helper_spec.rb +144 -0
  185. data/spec/identity_spec.rb +416 -0
  186. data/spec/network_spec.rb +67 -0
  187. data/spec/proxmox_vcr.rb +97 -0
  188. data/spec/spec_helper.rb +41 -0
  189. metadata +566 -0
@@ -0,0 +1,51 @@
1
+ # Copyright 2018 Tristan Robert
2
+
3
+ # This file is part of Fog::Proxmox.
4
+
5
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # Fog::Proxmox is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ module Fog
21
+ module Proxmox
22
+ class Identity
23
+ # class Group model authentication
24
+ class Group < Fog::Model
25
+ identity :groupid
26
+ attribute :comment
27
+ attribute :users
28
+ attribute :members
29
+
30
+ def save(options = {})
31
+ service.create_group((attributes.reject { |attribute| %i[users members].include? attribute }).merge(options))
32
+ reload
33
+ end
34
+
35
+ def destroy
36
+ requires :groupid
37
+ service.delete_group(groupid)
38
+ true
39
+ end
40
+
41
+ def update
42
+ requires :groupid
43
+ service.update_group(identity, attributes.reject do |attribute|
44
+ %i[groupid users members].include? attribute
45
+ end)
46
+ reload
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,44 @@
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/proxmox/identity/models/group'
21
+
22
+ module Fog
23
+ module Proxmox
24
+ class Identity
25
+ # class Groups authentication
26
+ class Groups < Fog::Collection
27
+ model Fog::Proxmox::Identity::Group
28
+
29
+ def all
30
+ load service.list_groups
31
+ end
32
+
33
+ def get(id)
34
+ all.find { |group| group.identity == id }
35
+ end
36
+
37
+ def destroy(id)
38
+ group = get(id)
39
+ group.destroy
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,66 @@
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
+ module Fog
21
+ module Proxmox
22
+ class Identity
23
+ # class Permission
24
+ class Permission < Fog::Model
25
+ identity :type
26
+ identity :roleid
27
+ identity :path
28
+ identity :ugid
29
+ attribute :propagate
30
+
31
+ def save
32
+ service.update_permissions(to_update)
33
+ end
34
+
35
+ def destroy
36
+ service.update_permissions(to_update.merge(delete: 1))
37
+ end
38
+
39
+ private
40
+
41
+ def initialize_roles(new_attributes = {})
42
+ roles = new_attributes.delete(:roleid)
43
+ new_attributes.store(:roles, roles)
44
+ end
45
+
46
+ def initialize_ugid(new_attributes = {})
47
+ ugs = new_attributes.delete(:ugid)
48
+ case type
49
+ when 'user'
50
+ new_attributes.store(:users, ugs)
51
+ when 'group'
52
+ new_attributes.store(:groups, ugs)
53
+ end
54
+ new_attributes.delete(:type)
55
+ end
56
+
57
+ def to_update
58
+ new_attributes = attributes.clone
59
+ initialize_roles(new_attributes)
60
+ initialize_ugid(new_attributes)
61
+ new_attributes
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,46 @@
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/proxmox/identity/models/permission'
21
+
22
+ module Fog
23
+ module Proxmox
24
+ class Identity
25
+ # class Permissions authentication
26
+ class Permissions < Fog::Collection
27
+ model Fog::Proxmox::Identity::Permission
28
+
29
+ def all
30
+ load service.list_permissions
31
+ end
32
+
33
+ def get(type, path, roleid, ugid)
34
+ all.find do |permission|
35
+ permission.type == type && permission.path == path && permission.roleid == roleid && permission.ugid == ugid
36
+ end
37
+ end
38
+
39
+ def destroy(permission_hash)
40
+ permission = new(permission_hash)
41
+ permission.destroy
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,89 @@
1
+ # Copyright 2018 Tristan Robert
2
+
3
+ # This file is part of Fog::Proxmox.
4
+
5
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # Fog::Proxmox is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ module Fog
21
+ module Proxmox
22
+ class Identity
23
+ # class Pool model of VMs
24
+ class Pool < Fog::Model
25
+ identity :poolid
26
+ attribute :comment
27
+ attribute :members
28
+
29
+ def save(options = {})
30
+ service.create_pool(attributes.merge(options))
31
+ reload
32
+ end
33
+
34
+ def destroy
35
+ requires :poolid
36
+ service.delete_pool(poolid)
37
+ true
38
+ end
39
+
40
+ def add_server(server)
41
+ update_with_member('vms', server, false)
42
+ end
43
+
44
+ def add_storage(storage)
45
+ update_with_member('storage', storage, false)
46
+ end
47
+
48
+ def remove_storage(storage)
49
+ update_with_member('storage', storage, true)
50
+ end
51
+
52
+ def remove_server(server)
53
+ update_with_member('vms', server, true)
54
+ end
55
+
56
+ def update_with_member(member_name, member_id, delete = false)
57
+ requires :poolid
58
+ otpions = attributes.reject { |attribute| %i[poolid members].include? attribute }
59
+ otpions.store(member_name, member_id) if member_name
60
+ otpions.store('delete', 1) if delete
61
+ service.update_pool(poolid, otpions)
62
+ reload
63
+ end
64
+
65
+ def update
66
+ update_with_member(nil, nil, false)
67
+ end
68
+
69
+ def has_server?(vmid)
70
+ has?('vmid', vmid)
71
+ end
72
+
73
+ def has_storage?(storage)
74
+ has?('storage', storage)
75
+ end
76
+
77
+ private
78
+
79
+ def has?(key, vmid)
80
+ result = false
81
+ attributes[:members].each do |member|
82
+ result = member[key].to_s.eql?(vmid.to_s) if member.has_key?(key) && member[key] && vmid
83
+ end
84
+ result
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,46 @@
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/proxmox/identity/models/pool'
21
+
22
+ module Fog
23
+ module Proxmox
24
+ class Identity
25
+ # class Pools Collection of pools of VMs
26
+ class Pools < Fog::Collection
27
+ model Fog::Proxmox::Identity::Pool
28
+
29
+ def all
30
+ pools_with_members = []
31
+ service.list_pools.each { |pool| pools_with_members.push(pool.merge(service.get_pool(pool['poolid']))) }
32
+ load pools_with_members
33
+ end
34
+
35
+ def get(id)
36
+ all.find { |pool| pool.identity == id }
37
+ end
38
+
39
+ def destroy(id)
40
+ pool = get(id)
41
+ pool.destroy
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,42 @@
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
+ # Copyright 2018 Tristan Robert
12
+
13
+ # This file is part of Fog::Proxmox.
14
+
15
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
16
+ # it under the terms of the GNU General Public License as published by
17
+ # the Free Software Foundation, either version 3 of the License, or
18
+ # (at your option) any later version.
19
+
20
+ # Fog::Proxmox is distributed in the hope that it will be useful,
21
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ # GNU General Public License for more details.
24
+
25
+ # You should have received a copy of the GNU General Public License
26
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
27
+
28
+ module Fog
29
+ module Proxmox
30
+ class Identity
31
+ # class Principal current user authenticated
32
+ class Principal < Fog::Model
33
+ identity :username
34
+ attribute :password
35
+ attribute :privs
36
+ attribute :path
37
+ attribute :otp
38
+ attribute :realm
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,48 @@
1
+ # Copyright 2018 Tristan Robert
2
+
3
+ # This file is part of Fog::Proxmox.
4
+
5
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # Fog::Proxmox is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ module Fog
21
+ module Proxmox
22
+ class Identity
23
+ # class Role model authentication
24
+ class Role < Fog::Model
25
+ identity :roleid
26
+ attribute :privs
27
+ attribute :special
28
+
29
+ def save(options = {})
30
+ service.create_role(attributes.merge(options))
31
+ reload
32
+ end
33
+
34
+ def destroy
35
+ requires :roleid
36
+ service.delete_role(roleid)
37
+ true
38
+ end
39
+
40
+ def update
41
+ requires :roleid
42
+ service.update_role(roleid, attributes.reject { |attribute| %i[roleid special].include? attribute })
43
+ reload
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,44 @@
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/proxmox/identity/models/role'
21
+
22
+ module Fog
23
+ module Proxmox
24
+ class Identity
25
+ # class Roles model collection authentication
26
+ class Roles < Fog::Collection
27
+ model Fog::Proxmox::Identity::Role
28
+
29
+ def all
30
+ load service.list_roles
31
+ end
32
+
33
+ def get(id)
34
+ all.find { |role| role.identity == id }
35
+ end
36
+
37
+ def destroy(id)
38
+ role = get(id)
39
+ role.destroy
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,72 @@
1
+ # Copyright 2018 Tristan Robert
2
+
3
+ # This file is part of Fog::Proxmox.
4
+
5
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # Fog::Proxmox is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ require 'fog/proxmox/identity/models/token_info'
21
+
22
+ module Fog
23
+ module Proxmox
24
+ class Identity
25
+ # class Token model
26
+ class Token < Fog::Model
27
+ identity :tokenid
28
+ identity :userid
29
+ attribute :privsep
30
+ attribute :comment
31
+ attribute :expire
32
+ attribute :info
33
+
34
+ def initialize(new_attributes = {})
35
+ prepare_service_value(new_attributes)
36
+ Fog::Proxmox::Attributes.set_attr_and_sym('tokenid', attributes, new_attributes)
37
+ Fog::Proxmox::Attributes.set_attr_and_sym('userid', attributes, new_attributes)
38
+ requires :userid, :tokenid
39
+ initialize_info
40
+ super(new_attributes)
41
+ end
42
+
43
+ def save(options = {})
44
+ requires :tokenid, :userid
45
+ token_hash = (attributes.reject { |attribute| %i[userid tokenid info].include? attribute }).merge(options)
46
+ service.create_token(userid, tokenid, token_hash)
47
+ reload
48
+ end
49
+
50
+ def destroy
51
+ requires :tokenid, :userid
52
+ service.delete_token(userid, tokenid)
53
+ true
54
+ end
55
+
56
+ def update
57
+ requires :tokenid, :userid
58
+ service.update_token(userid, tokenid, attributes.reject do |attribute|
59
+ %i[userid tokenid info].include? attribute
60
+ end)
61
+ reload
62
+ end
63
+
64
+ private
65
+
66
+ def initialize_info
67
+ attributes[:info] = Fog::Proxmox::Identity::TokenInfo.new(service: service, tokenid: tokenid, userid: userid)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright 2018 Tristan Robert
2
+
3
+ # This file is part of Fog::Proxmox.
4
+
5
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+
10
+ # Fog::Proxmox is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ # frozen_string_literal: true
19
+
20
+ module Fog
21
+ module Proxmox
22
+ class Identity
23
+ # class TokenInfo model
24
+ class TokenInfo < Fog::Model
25
+ identity :tokenid
26
+ identity :userid
27
+ attribute :fulltokenid
28
+ attribute :info
29
+ attribute :value
30
+
31
+ def initialize(new_attributes = {})
32
+ prepare_service_value(new_attributes)
33
+ Fog::Proxmox::Attributes.set_attr_and_sym('tokenid', attributes, new_attributes)
34
+ Fog::Proxmox::Attributes.set_attr_and_sym('userid', attributes, new_attributes)
35
+ requires :userid, :tokenid
36
+ super(new_attributes)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,54 @@
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/proxmox/identity/models/user'
21
+
22
+ module Fog
23
+ module Proxmox
24
+ class Identity
25
+ # class Tokens model collection
26
+ class Tokens < Fog::Collection
27
+ model Fog::Proxmox::Identity::Token
28
+ attribute :userid
29
+
30
+ def new(new_attributes = {})
31
+ super({ userid: userid }.merge(new_attributes))
32
+ end
33
+
34
+ def get(tokenid)
35
+ all.find { |token| token.tokenid == tokenid && token.userid == userid }
36
+ end
37
+
38
+ def all(_options = {})
39
+ load service.list_tokens(userid)
40
+ rescue Excon::Error::InternalServerError => e
41
+ raise e unless e.response.status_line.include? 'no such user'
42
+
43
+ []
44
+ end
45
+
46
+ def create(new_attributes = {})
47
+ object = new(new_attributes.select { |key, _value| %i[userid tokenid].include? key.to_sym })
48
+ object.save(new_attributes.reject { |key, _value| %i[userid tokenid].include? key.to_sym })
49
+ object
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end