From 246cd098981e96a77b80973a5a1f4b21445bc49d Mon Sep 17 00:00:00 2001 From: Simon Fuhrer Date: Sat, 27 Jun 2020 07:32:57 +0200 Subject: [PATCH] add methods to be compatible with available_networks and available_storage_domains controller --- .../concerns/fog_extensions/xenserver/network.rb | 11 +++++++++++ .../fog_extensions/xenserver/storage_repository.rb | 12 ++++++++++++ app/models/foreman_xen/xenserver.rb | 8 ++++++++ lib/foreman_xen/engine.rb | 3 +++ 4 files changed, 34 insertions(+) create mode 100644 app/models/concerns/fog_extensions/xenserver/network.rb diff --git a/app/models/concerns/fog_extensions/xenserver/network.rb b/app/models/concerns/fog_extensions/xenserver/network.rb new file mode 100644 index 0000000..eee12c9 --- /dev/null +++ b/app/models/concerns/fog_extensions/xenserver/network.rb @@ -0,0 +1,11 @@ +module FogExtensions + module Xenserver + module Network + extend ActiveSupport::Concern + + def id + uuid + end + end + end +end diff --git a/app/models/concerns/fog_extensions/xenserver/storage_repository.rb b/app/models/concerns/fog_extensions/xenserver/storage_repository.rb index a29c010..71b6b0d 100644 --- a/app/models/concerns/fog_extensions/xenserver/storage_repository.rb +++ b/app/models/concerns/fog_extensions/xenserver/storage_repository.rb @@ -8,6 +8,10 @@ module StorageRepository prepend FogExtensions::Xenserver::StorageRepository end + def id + uuid + end + def initialize(new_attributes = {}) super(new_attributes) attributes[:display_name] = init_display_name @@ -29,6 +33,14 @@ def physical_utilisation_gb physical_utilisation.to_i / 1024 / 1024 / 1024 end + def capacity + physical_size_gb + end + + def freespace + free_space + end + def init_display_name srname = name unless shared diff --git a/app/models/foreman_xen/xenserver.rb b/app/models/foreman_xen/xenserver.rb index df4236c..f30a720 100644 --- a/app/models/foreman_xen/xenserver.rb +++ b/app/models/foreman_xen/xenserver.rb @@ -110,6 +110,14 @@ def available_images custom_templates! end + def available_storage_domains(*) + storage_pools + end + + def available_networks(*) + networks + end + def available_hypervisors hypervisors.select(&:enabled) end diff --git a/lib/foreman_xen/engine.rb b/lib/foreman_xen/engine.rb index ec68bcc..6ab31ad 100644 --- a/lib/foreman_xen/engine.rb +++ b/lib/foreman_xen/engine.rb @@ -45,10 +45,12 @@ class Engine < ::Rails::Engine require 'fog/xenserver/compute/models/server' require 'fog/xenserver/compute/models/host' require 'fog/xenserver/compute/models/vdi' + require 'fog/xenserver/compute/models/network' require 'fog/xenserver/compute/models/storage_repository' require File.expand_path('../../app/models/concerns/fog_extensions/xenserver/server', __dir__) require File.expand_path('../../app/models/concerns/fog_extensions/xenserver/host', __dir__) require File.expand_path('../../app/models/concerns/fog_extensions/xenserver/vdi', __dir__) + require File.expand_path('../../app/models/concerns/fog_extensions/xenserver/network', __dir__) require File.expand_path('../../app/models/concerns/fog_extensions/xenserver/storage_repository', __dir__) require File.expand_path('../../app/models/concerns/foreman_xen/host_helper_extensions', __dir__) require File.expand_path('../../app/models/concerns/foreman_xen/host_extensions', __dir__) @@ -56,6 +58,7 @@ class Engine < ::Rails::Engine Fog::XenServer::Compute::Models::Server.include ::FogExtensions::Xenserver::Server Fog::XenServer::Compute::Models::Host.include ::FogExtensions::Xenserver::Host Fog::XenServer::Compute::Models::Vdi.include ::FogExtensions::Xenserver::Vdi + Fog::XenServer::Compute::Models::Network.include ::FogExtensions::Xenserver::Network Fog::XenServer::Compute::Models::StorageRepository.include ::FogExtensions::Xenserver::StorageRepository ::HostsHelper.include ForemanXen::HostHelperExtensions ::Host::Managed.prepend ForemanXen::HostExtensions