fog-proxmox 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/config +4 -0
  3. data/.codeclimate.yml +14 -0
  4. data/.github/CODE_OF_CONDUCT.md +74 -0
  5. data/.github/CONTRIBUTING.md +20 -0
  6. data/.github/CONTRIBUTORS.md +9 -0
  7. data/.github/FUNDING.yml +12 -0
  8. data/.github/ISSUE_TEMPLATE.md +43 -0
  9. data/.github/ISSUE_TEMPLATE/bug_report.md +35 -0
  10. data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  11. data/.github/SUPPORT.md +9 -0
  12. data/.github/fogproxmox.png +0 -0
  13. data/.github/workflows/ci.yml +79 -0
  14. data/.gitignore +8 -0
  15. data/.rubocop.yml +13 -0
  16. data/.ruby-gemset +1 -0
  17. data/.solargraph.yml +10 -0
  18. data/.vscode/launch.json +96 -0
  19. data/.vscode/settings.json +45 -0
  20. data/.vscode/tasks.json +27 -0
  21. data/Gemfile +23 -0
  22. data/LICENSE +674 -0
  23. data/README.md +79 -0
  24. data/Rakefile +58 -0
  25. data/docs/compute.md +858 -0
  26. data/docs/connection_parameters.md +45 -0
  27. data/docs/getting_started.md +53 -0
  28. data/docs/identity.md +357 -0
  29. data/examples/compute.rb +276 -0
  30. data/examples/identity.rb +190 -0
  31. data/fog-proxmox.gemspec +63 -0
  32. data/lib/fog/compute/proxmox.rb +126 -0
  33. data/lib/fog/compute/proxmox/models/disk.rb +76 -0
  34. data/lib/fog/compute/proxmox/models/disks.rb +51 -0
  35. data/lib/fog/compute/proxmox/models/interface.rb +52 -0
  36. data/lib/fog/compute/proxmox/models/interfaces.rb +44 -0
  37. data/lib/fog/compute/proxmox/models/node.rb +95 -0
  38. data/lib/fog/compute/proxmox/models/nodes.rb +39 -0
  39. data/lib/fog/compute/proxmox/models/server.rb +254 -0
  40. data/lib/fog/compute/proxmox/models/server_config.rb +148 -0
  41. data/lib/fog/compute/proxmox/models/servers.rb +80 -0
  42. data/lib/fog/compute/proxmox/models/snapshot.rb +83 -0
  43. data/lib/fog/compute/proxmox/models/snapshots.rb +47 -0
  44. data/lib/fog/compute/proxmox/models/storage.rb +64 -0
  45. data/lib/fog/compute/proxmox/models/storages.rb +51 -0
  46. data/lib/fog/compute/proxmox/models/task.rb +79 -0
  47. data/lib/fog/compute/proxmox/models/tasks.rb +64 -0
  48. data/lib/fog/compute/proxmox/models/volume.rb +61 -0
  49. data/lib/fog/compute/proxmox/models/volumes.rb +58 -0
  50. data/lib/fog/compute/proxmox/requests/action_server.rb +45 -0
  51. data/lib/fog/compute/proxmox/requests/clone_server.rb +44 -0
  52. data/lib/fog/compute/proxmox/requests/create_backup.rb +42 -0
  53. data/lib/fog/compute/proxmox/requests/create_server.rb +43 -0
  54. data/lib/fog/compute/proxmox/requests/create_snapshot.rb +46 -0
  55. data/lib/fog/compute/proxmox/requests/create_spice.rb +44 -0
  56. data/lib/fog/compute/proxmox/requests/create_term.rb +44 -0
  57. data/lib/fog/compute/proxmox/requests/create_vnc.rb +44 -0
  58. data/lib/fog/compute/proxmox/requests/delete_server.rb +45 -0
  59. data/lib/fog/compute/proxmox/requests/delete_snapshot.rb +47 -0
  60. data/lib/fog/compute/proxmox/requests/delete_volume.rb +40 -0
  61. data/lib/fog/compute/proxmox/requests/get_node_statistics.rb +44 -0
  62. data/lib/fog/compute/proxmox/requests/get_server_config.rb +60 -0
  63. data/lib/fog/compute/proxmox/requests/get_server_status.rb +63 -0
  64. data/lib/fog/compute/proxmox/requests/get_snapshot_config.rb +44 -0
  65. data/lib/fog/compute/proxmox/requests/get_task.rb +41 -0
  66. data/lib/fog/compute/proxmox/requests/get_vnc.rb +44 -0
  67. data/lib/fog/compute/proxmox/requests/get_volume.rb +42 -0
  68. data/lib/fog/compute/proxmox/requests/list_nodes.rb +48 -0
  69. data/lib/fog/compute/proxmox/requests/list_servers.rb +113 -0
  70. data/lib/fog/compute/proxmox/requests/list_snapshots.rb +66 -0
  71. data/lib/fog/compute/proxmox/requests/list_storages.rb +46 -0
  72. data/lib/fog/compute/proxmox/requests/list_tasks.rb +44 -0
  73. data/lib/fog/compute/proxmox/requests/list_volumes.rb +44 -0
  74. data/lib/fog/compute/proxmox/requests/log_task.rb +44 -0
  75. data/lib/fog/compute/proxmox/requests/migrate_server.rb +44 -0
  76. data/lib/fog/compute/proxmox/requests/move_disk.rb +43 -0
  77. data/lib/fog/compute/proxmox/requests/move_volume.rb +43 -0
  78. data/lib/fog/compute/proxmox/requests/next_vmid.rb +42 -0
  79. data/lib/fog/compute/proxmox/requests/resize_container.rb +43 -0
  80. data/lib/fog/compute/proxmox/requests/resize_server.rb +43 -0
  81. data/lib/fog/compute/proxmox/requests/rollback_snapshot.rb +48 -0
  82. data/lib/fog/compute/proxmox/requests/status_task.rb +41 -0
  83. data/lib/fog/compute/proxmox/requests/stop_task.rb +41 -0
  84. data/lib/fog/compute/proxmox/requests/template_server.rb +44 -0
  85. data/lib/fog/compute/proxmox/requests/update_server.rb +44 -0
  86. data/lib/fog/compute/proxmox/requests/update_snapshot.rb +45 -0
  87. data/lib/fog/identity/proxmox.rb +130 -0
  88. data/lib/fog/identity/proxmox/models/domain.rb +65 -0
  89. data/lib/fog/identity/proxmox/models/domain_type.rb +48 -0
  90. data/lib/fog/identity/proxmox/models/domains.rb +45 -0
  91. data/lib/fog/identity/proxmox/models/group.rb +47 -0
  92. data/lib/fog/identity/proxmox/models/groups.rb +44 -0
  93. data/lib/fog/identity/proxmox/models/permission.rb +65 -0
  94. data/lib/fog/identity/proxmox/models/permissions.rb +44 -0
  95. data/lib/fog/identity/proxmox/models/pool.rb +89 -0
  96. data/lib/fog/identity/proxmox/models/pools.rb +46 -0
  97. data/lib/fog/identity/proxmox/models/principal.rb +42 -0
  98. data/lib/fog/identity/proxmox/models/role.rb +48 -0
  99. data/lib/fog/identity/proxmox/models/roles.rb +44 -0
  100. data/lib/fog/identity/proxmox/models/user.rb +60 -0
  101. data/lib/fog/identity/proxmox/models/users.rb +44 -0
  102. data/lib/fog/identity/proxmox/requests/change_password.rb +41 -0
  103. data/lib/fog/identity/proxmox/requests/check_permissions.rb +41 -0
  104. data/lib/fog/identity/proxmox/requests/create_domain.rb +40 -0
  105. data/lib/fog/identity/proxmox/requests/create_group.rb +40 -0
  106. data/lib/fog/identity/proxmox/requests/create_pool.rb +40 -0
  107. data/lib/fog/identity/proxmox/requests/create_role.rb +40 -0
  108. data/lib/fog/identity/proxmox/requests/create_user.rb +40 -0
  109. data/lib/fog/identity/proxmox/requests/delete_domain.rb +40 -0
  110. data/lib/fog/identity/proxmox/requests/delete_group.rb +40 -0
  111. data/lib/fog/identity/proxmox/requests/delete_pool.rb +39 -0
  112. data/lib/fog/identity/proxmox/requests/delete_role.rb +40 -0
  113. data/lib/fog/identity/proxmox/requests/delete_user.rb +39 -0
  114. data/lib/fog/identity/proxmox/requests/get_domain.rb +41 -0
  115. data/lib/fog/identity/proxmox/requests/get_group.rb +41 -0
  116. data/lib/fog/identity/proxmox/requests/get_pool.rb +41 -0
  117. data/lib/fog/identity/proxmox/requests/get_role.rb +41 -0
  118. data/lib/fog/identity/proxmox/requests/get_user.rb +40 -0
  119. data/lib/fog/identity/proxmox/requests/list_domains.rb +41 -0
  120. data/lib/fog/identity/proxmox/requests/list_groups.rb +41 -0
  121. data/lib/fog/identity/proxmox/requests/list_permissions.rb +41 -0
  122. data/lib/fog/identity/proxmox/requests/list_pools.rb +41 -0
  123. data/lib/fog/identity/proxmox/requests/list_roles.rb +40 -0
  124. data/lib/fog/identity/proxmox/requests/list_users.rb +42 -0
  125. data/lib/fog/identity/proxmox/requests/read_version.rb +39 -0
  126. data/lib/fog/identity/proxmox/requests/update_domain.rb +41 -0
  127. data/lib/fog/identity/proxmox/requests/update_group.rb +40 -0
  128. data/lib/fog/identity/proxmox/requests/update_permissions.rb +41 -0
  129. data/lib/fog/identity/proxmox/requests/update_pool.rb +41 -0
  130. data/lib/fog/identity/proxmox/requests/update_role.rb +41 -0
  131. data/lib/fog/identity/proxmox/requests/update_user.rb +41 -0
  132. data/lib/fog/network/proxmox.rb +83 -0
  133. data/lib/fog/network/proxmox/models/network.rb +76 -0
  134. data/lib/fog/network/proxmox/models/networks.rb +48 -0
  135. data/lib/fog/network/proxmox/models/node.rb +74 -0
  136. data/lib/fog/network/proxmox/models/nodes.rb +39 -0
  137. data/lib/fog/network/proxmox/requests/create_network.rb +41 -0
  138. data/lib/fog/network/proxmox/requests/delete_network.rb +42 -0
  139. data/lib/fog/network/proxmox/requests/get_network.rb +43 -0
  140. data/lib/fog/network/proxmox/requests/get_node.rb +41 -0
  141. data/lib/fog/network/proxmox/requests/list_networks.rb +43 -0
  142. data/lib/fog/network/proxmox/requests/list_nodes.rb +42 -0
  143. data/lib/fog/network/proxmox/requests/power_node.rb +43 -0
  144. data/lib/fog/network/proxmox/requests/update_network.rb +42 -0
  145. data/lib/fog/proxmox.rb +115 -0
  146. data/lib/fog/proxmox/attributes.rb +33 -0
  147. data/lib/fog/proxmox/core.rb +135 -0
  148. data/lib/fog/proxmox/errors.rb +64 -0
  149. data/lib/fog/proxmox/hash.rb +39 -0
  150. data/lib/fog/proxmox/helpers/controller_helper.rb +64 -0
  151. data/lib/fog/proxmox/helpers/cpu_helper.rb +42 -0
  152. data/lib/fog/proxmox/helpers/disk_helper.rb +159 -0
  153. data/lib/fog/proxmox/helpers/ip_helper.rb +100 -0
  154. data/lib/fog/proxmox/helpers/nic_helper.rb +115 -0
  155. data/lib/fog/proxmox/json.rb +32 -0
  156. data/lib/fog/proxmox/string.rb +31 -0
  157. data/lib/fog/proxmox/variables.rb +40 -0
  158. data/lib/fog/proxmox/version.rb +24 -0
  159. data/lib/fog/storage/proxmox.rb +29 -0
  160. data/spec/compute_spec.rb +446 -0
  161. data/spec/fixtures/proxmox/compute/containers.yml +12737 -0
  162. data/spec/fixtures/proxmox/compute/identity_ticket.yml +40 -0
  163. data/spec/fixtures/proxmox/compute/nodes.yml +121 -0
  164. data/spec/fixtures/proxmox/compute/servers.yml +24679 -0
  165. data/spec/fixtures/proxmox/compute/snapshots.yml +3321 -0
  166. data/spec/fixtures/proxmox/compute/storages.yml +159 -0
  167. data/spec/fixtures/proxmox/compute/tasks.yml +685 -0
  168. data/spec/fixtures/proxmox/identity/auth.yml +44 -0
  169. data/spec/fixtures/proxmox/identity/domains.yml +701 -0
  170. data/spec/fixtures/proxmox/identity/groups.yml +363 -0
  171. data/spec/fixtures/proxmox/identity/identity_ticket.yml +40 -0
  172. data/spec/fixtures/proxmox/identity/permissions.yml +803 -0
  173. data/spec/fixtures/proxmox/identity/pools.yml +1191 -0
  174. data/spec/fixtures/proxmox/identity/read_version.yml +42 -0
  175. data/spec/fixtures/proxmox/identity/renew.yml +40 -0
  176. data/spec/fixtures/proxmox/identity/roles.yml +363 -0
  177. data/spec/fixtures/proxmox/identity/users.yml +763 -0
  178. data/spec/fixtures/proxmox/network/identity_ticket.yml +40 -0
  179. data/spec/fixtures/proxmox/network/networks.yml +372 -0
  180. data/spec/fixtures/proxmox/pve.home +34 -0
  181. data/spec/hash_spec.rb +42 -0
  182. data/spec/helpers/controller_helper_spec.rb +145 -0
  183. data/spec/helpers/cpu_helper_spec.rb +70 -0
  184. data/spec/helpers/disk_helper_spec.rb +210 -0
  185. data/spec/helpers/ip_helper_spec.rb +160 -0
  186. data/spec/helpers/nic_helper_spec.rb +136 -0
  187. data/spec/identity_spec.rb +322 -0
  188. data/spec/network_spec.rb +67 -0
  189. data/spec/proxmox_vcr.rb +95 -0
  190. data/spec/spec_helper.rb +40 -0
  191. metadata +547 -0
@@ -0,0 +1,130 @@
1
+ # frozen_string_literal: true
2
+ # Copyright 2018 Tristan Robert
3
+
4
+ # This file is part of Fog::Proxmox.
5
+
6
+ # Fog::Proxmox is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+
11
+ # Fog::Proxmox is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Fog::Proxmox. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+ # frozen_string_literal: true
20
+
21
+ require 'fog/core'
22
+ require 'fog/proxmox/string'
23
+
24
+ module Fog
25
+ module Proxmox
26
+ # Identity and authentication proxmox class
27
+ class Identity < Fog::Service
28
+ requires :pve_url
29
+ recognizes :pve_ticket, :pve_path, :pve_ticket_expires, :pve_csrftoken, :persistent, :current_user, :pve_username, :pve_password, :pve_deadline
30
+
31
+ model_path 'fog/identity/proxmox/models'
32
+ model :principal
33
+ model :user
34
+ collection :users
35
+ model :group
36
+ collection :groups
37
+ model :pool
38
+ collection :pools
39
+ model :role
40
+ collection :roles
41
+ model :domain
42
+ model :domain_type
43
+ collection :domains
44
+ model :permission
45
+ collection :permissions
46
+
47
+ request_path 'fog/identity/proxmox/requests'
48
+
49
+ # Manage permissions
50
+ request :check_permissions
51
+ request :list_permissions
52
+ request :update_permissions
53
+ request :read_version
54
+
55
+ # Manage users
56
+ request :list_users
57
+ request :get_user
58
+ request :create_user
59
+ request :update_user
60
+ request :delete_user
61
+ request :change_password
62
+
63
+ # CRUD groups
64
+ request :list_groups
65
+ request :get_group
66
+ request :create_group
67
+ request :update_group
68
+ request :delete_group
69
+
70
+ # CRUD roles
71
+ request :list_roles
72
+ request :get_role
73
+ request :create_role
74
+ request :update_role
75
+ request :delete_role
76
+
77
+ # CRUD domains
78
+ request :list_domains
79
+ request :get_domain
80
+ request :create_domain
81
+ request :update_domain
82
+ request :delete_domain
83
+
84
+ # CRUD pools
85
+ request :list_pools
86
+ request :get_pool
87
+ request :create_pool
88
+ request :update_pool
89
+ request :delete_pool
90
+
91
+ # Mock class
92
+ class Mock
93
+ attr_reader :config
94
+
95
+ def initialize(options = {})
96
+ @pve_uri = URI.parse(options[:pve_url])
97
+ @pve_path = @pve_uri.path
98
+ @config = options
99
+ end
100
+ end
101
+
102
+ # Real class
103
+ class Real
104
+ include Fog::Proxmox::Core
105
+ def initialize(options = {})
106
+ initialize_identity(options)
107
+ @connection_options = options[:connection_options] || {}
108
+ @path_prefix = URI.parse(options[:pve_url]).path
109
+ authenticate
110
+ @persistent = options[:persistent] || false
111
+ url = "#{@scheme}://#{@host}:#{@port}"
112
+ if ENV.has_key?('SSL_VERIFY_PEER')
113
+ Excon.defaults[:ssl_verify_peer] = Fog::Proxmox::String.to_boolean(ENV['SSL_VERIFY_PEER'])
114
+ end
115
+ @connection = Fog::Core::Connection.new(url, @persistent, @connection_options.merge(path_prefix: @path_prefix))
116
+ end
117
+
118
+ def config
119
+ self
120
+ end
121
+
122
+ def configure(source)
123
+ source.instance_variables.each do |v|
124
+ instance_variable_set(v, source.instance_variable_get(v))
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,65 @@
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
+ module Fog
19
+ module Proxmox
20
+ class Identity
21
+ # class Domain model authentication
22
+ class Domain < Fog::Model
23
+ identity :realm
24
+ attribute :comment
25
+ attribute :tfa
26
+ attribute :type
27
+
28
+ def initialize(new_attributes = {})
29
+ initialize_type(new_attributes)
30
+ super(new_attributes)
31
+ end
32
+
33
+ def save(new_attributes = {})
34
+ service.create_domain(type.attributes.merge(new_attributes).merge(attributes.reject { |attribute| [:type].include? attribute }))
35
+ reload
36
+ end
37
+
38
+ def destroy
39
+ requires :realm
40
+ service.delete_domain(realm)
41
+ true
42
+ end
43
+
44
+ def update
45
+ requires :realm
46
+ service.update_domain(realm, type.attributes.merge(attributes).reject { |attribute| [:type, :realm].include? attribute })
47
+ reload
48
+ end
49
+
50
+ private
51
+
52
+ def initialize_type(new_attributes = {})
53
+ if new_attributes.has_key? :realm
54
+ realm = new_attributes.delete(:realm)
55
+ elsif new_attributes.has_key? 'realm'
56
+ realm = new_attributes.delete('realm')
57
+ end
58
+ attributes[:type] = Fog::Proxmox::Identity::DomainType.new(new_attributes)
59
+ new_attributes.delete_if { |new_attribute| attributes[:type].attributes.has_key? new_attribute.to_sym }
60
+ new_attributes.store(:realm, realm)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ 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
+ module Fog
19
+ module Proxmox
20
+ class Identity
21
+ # class Domain type model authentication
22
+ class DomainType < Fog::Model
23
+ identity :type
24
+ attribute :id
25
+ attribute :key
26
+ attribute :url
27
+ attribute :base_dn
28
+ attribute :bind_dn
29
+ attribute :capath
30
+ attribute :cert
31
+ attribute :certkey
32
+ attribute :comment
33
+ attribute :default
34
+ attribute :domain
35
+ attribute :port
36
+ attribute :secure
37
+ attribute :server1
38
+ attribute :server2
39
+ attribute :tfa
40
+ attribute :user_attr
41
+ attribute :verify
42
+ attribute :step
43
+ attribute :digits
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,45 @@
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/identity/proxmox/models/domain'
21
+
22
+ module Fog
23
+ module Proxmox
24
+ class Identity
25
+ # class Domains collection authentication
26
+ class Domains < Fog::Collection
27
+ model Fog::Proxmox::Identity::Domain
28
+
29
+ def all
30
+ load service.list_domains
31
+ end
32
+
33
+ def get(id)
34
+ all.find { |domain| domain.identity === id }
35
+ end
36
+
37
+ def destroy(id)
38
+ domain = get(id)
39
+ domain.destroy
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,47 @@
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
+
28
+ def save(options = {})
29
+ service.create_group(attributes.merge(options))
30
+ reload
31
+ end
32
+
33
+ def destroy
34
+ requires :groupid
35
+ service.delete_group(groupid)
36
+ true
37
+ end
38
+
39
+ def update
40
+ requires :groupid
41
+ service.update_group(identity, attributes.reject { |attribute| [:groupid].include? attribute })
42
+ reload
43
+ end
44
+ end
45
+ end
46
+ end
47
+ 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/identity/proxmox/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,65 @@
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
+ if type === 'user'
49
+ new_attributes.store(:users, ugs)
50
+ elsif type === 'group'
51
+ new_attributes.store(:groups, ugs)
52
+ end
53
+ new_attributes.delete(:type)
54
+ end
55
+
56
+ def to_update
57
+ new_attributes = attributes.clone
58
+ initialize_roles(new_attributes)
59
+ initialize_ugid(new_attributes)
60
+ new_attributes
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end