foreman_fog_proxmox 0.12.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of foreman_fog_proxmox might be problematic. Click here for more details.

Files changed (113) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +619 -0
  3. data/README.md +290 -0
  4. data/Rakefile +49 -0
  5. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_compute_resource.js +33 -0
  6. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm.js +187 -0
  7. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_container.js +24 -0
  8. data/app/assets/javascripts/foreman_fog_proxmox/proxmox_vm_server.js +125 -0
  9. data/app/controllers/concerns/foreman_fog_proxmox/controller/parameters/compute_resource.rb +41 -0
  10. data/app/controllers/foreman_fog_proxmox/compute_resources_controller.rb +86 -0
  11. data/app/helpers/node_dashboard_helper.rb +35 -0
  12. data/app/helpers/proxmox_compute_selectors_helper.rb +184 -0
  13. data/app/helpers/proxmox_container_helper.rb +163 -0
  14. data/app/helpers/proxmox_form_helper.rb +70 -0
  15. data/app/helpers/proxmox_server_helper.rb +155 -0
  16. data/app/helpers/proxmox_vm_helper.rb +88 -0
  17. data/app/models/concerns/fog_extensions/proxmox/disk.rb +29 -0
  18. data/app/models/concerns/fog_extensions/proxmox/interface.rb +40 -0
  19. data/app/models/concerns/fog_extensions/proxmox/node.rb +41 -0
  20. data/app/models/concerns/fog_extensions/proxmox/server.rb +93 -0
  21. data/app/models/concerns/fog_extensions/proxmox/server_config.rb +71 -0
  22. data/app/models/concerns/fog_extensions/proxmox/volume.rb +29 -0
  23. data/app/models/concerns/host_ext/proxmox/interfaces.rb +52 -0
  24. data/app/models/concerns/orchestration/proxmox/compute.rb +42 -0
  25. data/app/models/foreman_fog_proxmox/options_select.rb +36 -0
  26. data/app/models/foreman_fog_proxmox/proxmox.rb +133 -0
  27. data/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +67 -0
  28. data/app/models/foreman_fog_proxmox/proxmox_connection.rb +67 -0
  29. data/app/models/foreman_fog_proxmox/proxmox_console.rb +41 -0
  30. data/app/models/foreman_fog_proxmox/proxmox_images.rb +61 -0
  31. data/app/models/foreman_fog_proxmox/proxmox_interfaces.rb +103 -0
  32. data/app/models/foreman_fog_proxmox/proxmox_operating_systems.rb +49 -0
  33. data/app/models/foreman_fog_proxmox/proxmox_pools.rb +56 -0
  34. data/app/models/foreman_fog_proxmox/proxmox_token_expiration.rb +30 -0
  35. data/app/models/foreman_fog_proxmox/proxmox_version.rb +36 -0
  36. data/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +116 -0
  37. data/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +178 -0
  38. data/app/models/foreman_fog_proxmox/proxmox_vm_queries.rb +75 -0
  39. data/app/models/foreman_fog_proxmox/proxmox_volumes.rb +94 -0
  40. data/app/models/foreman_fog_proxmox/vms.rb +37 -0
  41. data/app/overrides/compute_resources_vms/form/add_clone_to_new_vm_compute_detail.rb +25 -0
  42. data/app/overrides/compute_resources_vms/form/add_from_profile_to_compute_attributes_form.rb +34 -0
  43. data/app/overrides/compute_resources_vms/form/add_vm_type_node_to_new_form.rb +25 -0
  44. data/app/overrides/compute_resources_vms/form/add_vm_type_to_networks_form.rb +34 -0
  45. data/app/overrides/compute_resources_vms/form/add_vm_type_to_nic_provider_specific_form.rb +26 -0
  46. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_edit.rb +25 -0
  47. data/app/overrides/compute_resources_vms/form/add_vm_type_to_volumes_new_volume.rb +25 -0
  48. data/app/overrides/compute_resources_vms/form/remove_new_vm_from_removable_layout.rb +25 -0
  49. data/app/services/foreman_fog_proxmox/node_dashboard/data.rb +37 -0
  50. data/app/views/api/v2/compute_resources/proxmox.json.rabl +3 -0
  51. data/app/views/compute_resources/form/_proxmox.html.erb +29 -0
  52. data/app/views/compute_resources/show/_proxmox.html.erb +37 -0
  53. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_attributes_form.html.erb +23 -0
  54. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_compute_form.html.erb +23 -0
  55. data/app/views/compute_resources_vms/form/proxmox/_add_from_profile_to_hosts_compute_detail_form.html.erb +24 -0
  56. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_node_to_new_form.html.erb +24 -0
  57. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_form.html.erb +28 -0
  58. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_networks_new_childs_form.html.erb +32 -0
  59. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_nic_provider_specific_form.html.erb +30 -0
  60. data/app/views/compute_resources_vms/form/proxmox/_add_vm_type_to_volumes_edit.html.erb +71 -0
  61. data/app/views/compute_resources_vms/form/proxmox/_base.html.erb +39 -0
  62. data/app/views/compute_resources_vms/form/proxmox/_general.html.erb +39 -0
  63. data/app/views/compute_resources_vms/form/proxmox/_network.html.erb +19 -0
  64. data/app/views/compute_resources_vms/form/proxmox/_removable_layout.html.erb +27 -0
  65. data/app/views/compute_resources_vms/form/proxmox/container/_advanced.html.erb +31 -0
  66. data/app/views/compute_resources_vms/form/proxmox/container/_config.html.erb +41 -0
  67. data/app/views/compute_resources_vms/form/proxmox/container/_extended.html.erb +27 -0
  68. data/app/views/compute_resources_vms/form/proxmox/container/_network.html.erb +33 -0
  69. data/app/views/compute_resources_vms/form/proxmox/container/_volume_mp.html.erb +27 -0
  70. data/app/views/compute_resources_vms/form/proxmox/container/_volume_rootfs.html.erb +24 -0
  71. data/app/views/compute_resources_vms/form/proxmox/server/_advanced.html.erb +31 -0
  72. data/app/views/compute_resources_vms/form/proxmox/server/_config.html.erb +60 -0
  73. data/app/views/compute_resources_vms/form/proxmox/server/_network.html.erb +30 -0
  74. data/app/views/compute_resources_vms/form/proxmox/server/_volume.html.erb +28 -0
  75. data/app/views/compute_resources_vms/index/_proxmox.html.erb +49 -0
  76. data/app/views/compute_resources_vms/show/_proxmox.html.erb +42 -0
  77. data/app/views/dashboard/_foreman_fog_proxmox_widget.erb +21 -0
  78. data/app/views/images/form/_proxmox.html.erb +21 -0
  79. data/config/routes.rb +30 -0
  80. data/lib/foreman_fog_proxmox.rb +23 -0
  81. data/lib/foreman_fog_proxmox/engine.rb +105 -0
  82. data/lib/foreman_fog_proxmox/semver.rb +102 -0
  83. data/lib/foreman_fog_proxmox/value.rb +26 -0
  84. data/lib/foreman_fog_proxmox/version.rb +22 -0
  85. data/lib/tasks/foreman_fog_proxmox_tasks.rake +37 -0
  86. data/locale/Makefile +60 -0
  87. data/locale/en/foreman_fog_proxmox.po +401 -0
  88. data/locale/foreman_fog_proxmox.pot +627 -0
  89. data/locale/fr/foreman_fog_proxmox.po +401 -0
  90. data/locale/gemspec.rb +4 -0
  91. data/test/factories/foreman_fog_proxmox/proxmox_container_mock_factory.rb +137 -0
  92. data/test/factories/foreman_fog_proxmox/proxmox_node_mock_factory.rb +87 -0
  93. data/test/factories/foreman_fog_proxmox/proxmox_server_mock_factory.rb +134 -0
  94. data/test/factories/proxmox_factory.rb +79 -0
  95. data/test/functional/compute_resources_controller_test.rb +48 -0
  96. data/test/test_plugin_helper.rb +19 -0
  97. data/test/unit/foreman_fog_proxmox/helpers/proxmox_container_helper_test.rb +204 -0
  98. data/test/unit/foreman_fog_proxmox/helpers/proxmox_server_helper_test.rb +149 -0
  99. data/test/unit/foreman_fog_proxmox/helpers/proxmox_vm_helper_test.rb +216 -0
  100. data/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +124 -0
  101. data/test/unit/foreman_fog_proxmox/proxmox_images_test.rb +52 -0
  102. data/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +117 -0
  103. data/test/unit/foreman_fog_proxmox/proxmox_test.rb +58 -0
  104. data/test/unit/foreman_fog_proxmox/proxmox_version_test.rb +94 -0
  105. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_container_test.rb +280 -0
  106. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_create_test.rb +110 -0
  107. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_test.rb +222 -0
  108. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_server_update_volumes_test.rb +308 -0
  109. data/test/unit/foreman_fog_proxmox/proxmox_vm_commands_test.rb +43 -0
  110. data/test/unit/foreman_fog_proxmox/proxmox_vm_new_test.rb +71 -0
  111. data/test/unit/foreman_fog_proxmox/proxmox_vm_queries_test.rb +68 -0
  112. data/test/unit/foreman_fog_proxmox/semver_test.rb +111 -0
  113. metadata +249 -0
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module FogExtensions
21
+ module Proxmox
22
+ module Disk
23
+ extend ActiveSupport::Concern
24
+ def templated?
25
+ volid ? volid.match(/^([\w-]+)[:]base-(\d+)-disk-(\d+)/) : false
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'fog/proxmox/helpers/ip_helper'
21
+
22
+ module FogExtensions
23
+ module Proxmox
24
+ module Interface
25
+ extend ActiveSupport::Concern
26
+ attr_accessor :dhcpv4, :dhcpv6, :gwv4, :gwv6
27
+ def mac
28
+ macaddr
29
+ end
30
+
31
+ def cidrv4_prefix
32
+ Fog::Proxmox::IpHelper.prefix(ip) if ip
33
+ end
34
+
35
+ def cidrv6_prefix
36
+ Fog::Proxmox::IpHelper.prefix6(ip) if ip
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module FogExtensions
21
+ module Proxmox
22
+ module Node
23
+ extend ActiveSupport::Concern
24
+
25
+ def each(collection_filters = {})
26
+ if block_given?
27
+ Kernel.loop do
28
+ break unless collection_filters[:marker]
29
+
30
+ page = all(collection_filters)
31
+ # We need to explicitly use the base 'each' method here on the page,
32
+ # otherwise we get infinite recursion
33
+ base_each = Fog::Collection.instance_method(:each)
34
+ base_each.bind(page).call { |item| yield item }
35
+ end
36
+ end
37
+ self
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module FogExtensions
21
+ module Proxmox
22
+ module Server
23
+ extend ActiveSupport::Concern
24
+ attr_accessor :image_id, :templated, :ostemplate_storage, :ostemplate_file, :password, :start_after_create
25
+
26
+ def start
27
+ action('start')
28
+ end
29
+
30
+ def stop
31
+ action('stop')
32
+ end
33
+
34
+ def reboot
35
+ stop
36
+ start
37
+ end
38
+
39
+ def reset
40
+ reboot
41
+ end
42
+
43
+ def mac
44
+ config.mac_addresses.first
45
+ end
46
+
47
+ def memory
48
+ maxmem.to_i
49
+ end
50
+
51
+ def state
52
+ qmpstatus
53
+ end
54
+
55
+ delegate :description, to: :config
56
+
57
+ def vm_description
58
+ "Name=#{name}, vmid=#{vmid}"
59
+ end
60
+
61
+ def select_nic(fog_nics, nic)
62
+ fog_nics.find { |fog_nic| fog_nic.identity.to_s == nic.identifier }
63
+ end
64
+
65
+ delegate :interfaces, to: :config
66
+
67
+ def nics
68
+ config.interfaces.collect(&:to_s)
69
+ end
70
+
71
+ def volumes
72
+ config.disks.reject(&:cdrom?)
73
+ end
74
+
75
+ def disks
76
+ config.disks.collect(&:to_s)
77
+ end
78
+
79
+ delegate :vga, to: :config
80
+ delegate :pool, to: :config
81
+
82
+ def interfaces_attributes=(attrs); end
83
+
84
+ def volumes_attributes=(attrs); end
85
+
86
+ def config_attributes=(attrs); end
87
+
88
+ def templated?
89
+ volumes.any?(&:templated?)
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'fog/proxmox/helpers/cpu_helper'
21
+
22
+ module FogExtensions
23
+ module Proxmox
24
+ module ServerConfig
25
+ extend ActiveSupport::Concern
26
+ def cpu_type
27
+ Fog::Proxmox::CpuHelper.extract_type(cpu)
28
+ end
29
+
30
+ def spectre
31
+ Fog::Proxmox::CpuHelper.has_spectre?(cpu)
32
+ end
33
+
34
+ def pcid
35
+ Fog::Proxmox::CpuHelper.has_pcid?(cpu)
36
+ end
37
+
38
+ def cdrom
39
+ if disks.cdrom
40
+ ['none', 'cdrom'].include?(disks.cdrom.volid) ? disks.cdrom.volid : 'image'
41
+ else
42
+ 'none'
43
+ end
44
+ end
45
+
46
+ def cdrom_storage
47
+ disks.cdrom ? disks.cdrom.storage : ''
48
+ end
49
+
50
+ def cdrom_iso
51
+ disks.cdrom ? disks.cdrom.volid : ''
52
+ end
53
+
54
+ def cdrom_image
55
+ if disks.cdrom
56
+ ['none', 'cdrom'].include?(disks.cdrom.volid) ? disks.cdrom.volid : 'image'
57
+ else
58
+ 'none'
59
+ end
60
+ end
61
+
62
+ def rootfs_storage
63
+ disks.rootfs&.storage
64
+ end
65
+
66
+ def rootfs_file
67
+ disks.rootfs&.volid
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module FogExtensions
21
+ module Proxmox
22
+ module Volume
23
+ extend ActiveSupport::Concern
24
+ def templated?
25
+ volid ? volid.match(/^([\w-]+)[:]base-(\d+)-disk-(\d+)/) : false
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'fog/proxmox/helpers/ip_helper'
21
+
22
+ module HostExt
23
+ module Proxmox
24
+ module Interfaces
25
+ extend ActiveSupport::Concern
26
+ def update(attributes = {})
27
+ add_interfaces_to_compute_attributes(attributes) if provider == 'Proxmox' && !attributes.nil? && attributes.key?('compute_attributes')
28
+ super(attributes)
29
+ end
30
+
31
+ def add_interfaces_to_compute_attributes(attributes)
32
+ attributes['compute_attributes'].store('interfaces_attributes', {})
33
+ attributes['interfaces_attributes'].each do |index, interface_attributes|
34
+ add_interface_to_compute_attributes(index, interface_attributes, attributes['compute_attributes']['interfaces_attributes'])
35
+ end
36
+ end
37
+
38
+ def cidr_ip(interface_attributes)
39
+ Fog::Proxmox::IpHelper.to_cidr(interface_attributes['ip'], interface_attributes['compute_attributes']['cidr_suffix'])
40
+ end
41
+
42
+ def add_interface_to_compute_attributes(index, interface_attributes, compute_attributes)
43
+ compute_attributes[index] = {}
44
+ compute_attributes[index].store('id', interface_attributes['identifier'])
45
+ compute_attributes[index].store('_delete', interface_attributes['_destroy'])
46
+ compute_attributes[index].store('macaddr', interface_attributes['mac'])
47
+ compute_attributes[index].store('ip', cidr_ip(interface_attributes))
48
+ compute_attributes[index].merge!(interface_attributes['compute_attributes'].reject { |k, _v| k == 'id' })
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module Orchestration
21
+ module Proxmox
22
+ module Compute
23
+ extend ActiveSupport::Concern
24
+
25
+ def setComputeUpdate
26
+ logger.info "Update Proxmox Compute instance for #{name}"
27
+ final_compute_attributes = compute_attributes.merge(compute_resource.host_compute_attrs(self))
28
+ compute_resource.save_vm uuid, final_compute_attributes
29
+ rescue StandardError => e
30
+ failure format(_('Failed to update a compute %<compute_resource>s instance %<name>s: %<e>s'), :compute_resource => compute_resource, :name => name, :e => e), e
31
+ end
32
+
33
+ def delComputeUpdate
34
+ logger.info "Undo Update Proxmox Compute instance for #{name}"
35
+ final_compute_attributes = old.compute_attributes.merge(compute_resource.host_compute_attrs(old))
36
+ compute_resource.save_vm uuid, final_compute_attributes
37
+ rescue StandardError => e
38
+ failure format(_('Failed to undo update compute %<compute_resource>s instance %<name>s: %<e>s'), :compute_resource => compute_resource, :name => name, :e => e), e
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module ForemanFogProxmox
21
+ class OptionsSelect
22
+ attr_accessor :id
23
+ attr_accessor :name
24
+ attr_accessor :range
25
+
26
+ def to_s
27
+ id
28
+ end
29
+
30
+ def initialize(args = {})
31
+ @id = args[:id]
32
+ @name = args[:name]
33
+ @range = args[:range]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Tristan Robert
4
+
5
+ # This file is part of ForemanFogProxmox.
6
+
7
+ # ForemanFogProxmox 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
+ # ForemanFogProxmox 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 ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'fog/proxmox/helpers/nic_helper'
21
+ require 'fog/proxmox/helpers/disk_helper'
22
+ require 'foreman_fog_proxmox/value'
23
+
24
+ module ForemanFogProxmox
25
+ class Proxmox < ComputeResource
26
+ include ProxmoxVmHelper
27
+ include ProxmoxServerHelper
28
+ include ProxmoxContainerHelper
29
+ include ProxmoxConnection
30
+ include ProxmoxTokenExpiration
31
+ include ProxmoxVmNew
32
+ include ProxmoxVmCommands
33
+ include ProxmoxVmQueries
34
+ include ProxmoxComputeAttributes
35
+ include ProxmoxVolumes
36
+ include ProxmoxInterfaces
37
+ include ProxmoxImages
38
+ include ProxmoxOperatingSystems
39
+ include ProxmoxVersion
40
+ include ProxmoxConsole
41
+ validates :url, :format => { :with => URI::DEFAULT_PARSER.make_regexp }, :presence => true
42
+ validates :user, :format => { :with => /(\w+)[@]{1}(\w+)/ }, :presence => true
43
+ validates :password, :presence => true
44
+ before_create :test_connection
45
+
46
+ def provided_attributes
47
+ super.merge(
48
+ :mac => :mac
49
+ )
50
+ end
51
+
52
+ def self.provider_friendly_name
53
+ 'Proxmox'
54
+ end
55
+
56
+ def capabilities
57
+ [:build, :new_volume, :new_interface, :image]
58
+ end
59
+
60
+ def self.model_name
61
+ ComputeResource.model_name
62
+ end
63
+
64
+ def associated_host(vm)
65
+ associate_by('mac', vm.mac)
66
+ end
67
+
68
+ def ssl_certs
69
+ attrs[:ssl_certs]
70
+ end
71
+
72
+ def ssl_certs=(value)
73
+ attrs[:ssl_certs] = value
74
+ end
75
+
76
+ def certs_to_store
77
+ return if ssl_certs.blank?
78
+
79
+ store = OpenSSL::X509::Store.new
80
+ ssl_certs.split(/(?=-----BEGIN)/).each do |cert|
81
+ x509_cert = OpenSSL::X509::Certificate.new cert
82
+ store.add_cert x509_cert
83
+ end
84
+ store
85
+ rescue StandardError => e
86
+ logger.error(e)
87
+ raise ::Foreman::Exception, N_('Unable to store X509 certificates')
88
+ end
89
+
90
+ def ssl_verify_peer
91
+ attrs[:ssl_verify_peer].blank? ? false : Foreman::Cast.to_bool(attrs[:ssl_verify_peer])
92
+ end
93
+
94
+ def ssl_verify_peer=(value)
95
+ attrs[:ssl_verify_peer] = value
96
+ end
97
+
98
+ def renew
99
+ attrs[:renew].blank? ? false : Foreman::Cast.to_bool(attrs[:renew])
100
+ end
101
+
102
+ def renew=(value)
103
+ attrs[:renew] = value
104
+ end
105
+
106
+ private
107
+
108
+ def client
109
+ @client ||= ::Fog::Proxmox::Compute.new(fog_credentials)
110
+ rescue StandardError => e
111
+ logger.error(e)
112
+ raise ::Foreman::Exception, format(N_('Failed retrieving proxmox compute client caused by %<e>s'), e: e)
113
+ end
114
+
115
+ def identity_client
116
+ @identity_client ||= ::Fog::Proxmox::Identity.new(fog_credentials)
117
+ rescue StandardError => e
118
+ logger.error(e)
119
+ raise ::Foreman::Exception, format(N_('Failed retrieving proxmox identity client caused by %<e>s'), e: e)
120
+ end
121
+
122
+ def network_client
123
+ @network_client ||= ::Fog::Proxmox::Network.new(fog_credentials)
124
+ rescue StandardError => e
125
+ logger.error(e)
126
+ raise ::Foreman::Exception, format(N_('Failed retrieving proxmox network client caused by %<e>s'), e: e)
127
+ end
128
+
129
+ def host
130
+ URI.parse(url).host
131
+ end
132
+ end
133
+ end