diff --git a/app/models/concerns/fog_extensions/azure/servers.rb b/app/models/concerns/fog_extensions/azure/servers.rb index c2961d5..4973a36 100644 --- a/app/models/concerns/fog_extensions/azure/servers.rb +++ b/app/models/concerns/fog_extensions/azure/servers.rb @@ -2,30 +2,28 @@ module FogExtensions module Azure module Servers extend ActiveSupport::Concern + module Overrides + # Azure servers.all doesn't take any argument, against the fog + # standard, so we override the method. + # https://github.com/fog/fog-azure/pull/25 + def all(_options = {}) + super(options) + end - included do - alias_method_chain :all, :patched_arguments - alias_method_chain :get, :cloud_service_patch + # Azure servers.get takes 2 arguments, the cloud service name and + # the vm_name. This is against the fog standard, however it's not + # possible to uniquely find a VM with just one argument. Instead, + # we try our best (see models/foreman_azure/azure.rb#find_vm_by_uuid + # for a similar method) to find it. + def get(identity, cloud_service_name = nil) + cloud_service_name ||= identity + cloud_service_vm = super(identity, cloud_service_name) + return cloud_service_vm if cloud_service_vm.present? + find { |vm| vm.vm_name == identity } + end end - # Azure servers.all doesn't take any argument, against the fog - # standard, so we override the method. - # https://github.com/fog/fog-azure/pull/25 - def all_with_patched_arguments(_options = {}) - all_without_patched_arguments - end - - # Azure servers.get takes 2 arguments, the cloud service name and - # the vm_name. This is against the fog standard, however it's not - # possible to uniquely find a VM with just one argument. Instead, - # we try our best (see models/foreman_azure/azure.rb#find_vm_by_uuid - # for a similar method) to find it. - def get_with_cloud_service_patch(identity, cloud_service_name = nil) - cloud_service_name ||= identity - cloud_service_vm = get_without_cloud_service_patch(identity, cloud_service_name) - return cloud_service_vm if cloud_service_vm.present? - find { |vm| vm.vm_name == identity } - end + prepend Overrides end end end diff --git a/app/models/foreman_azure/concerns/ssh_provision_extensions.rb b/app/models/foreman_azure/concerns/ssh_provision_extensions.rb index a786799..e75d2f9 100644 --- a/app/models/foreman_azure/concerns/ssh_provision_extensions.rb +++ b/app/models/foreman_azure/concerns/ssh_provision_extensions.rb @@ -2,25 +2,26 @@ module ForemanAzure module Concerns module SSHProvisionExtensions extend ActiveSupport::Concern - - included do - alias_method_chain :setSSHWaitForResponse, :use_ssh_keys + module Overrides + def setSSHWaitForResponse + if compute_resource.type == "ForemanAzure::Azure" + self.client = Foreman::Provision::SSH.new( + provision_ip, + image.username, + { :template => template_file.path, + :uuid => uuid, + :keys => [compute_resource.certificate_path] }) + else + super + end + rescue => e + failure _("Failed to login via SSH to %{name}: %{e}") % + { :name => name, :e => e }, e + end end - def setSSHWaitForResponse_with_use_ssh_keys - if compute_resource.type == "ForemanAzure::Azure" - self.client = Foreman::Provision::SSH.new( - provision_ip, - image.username, - { :template => template_file.path, - :uuid => uuid, - :keys => [compute_resource.certificate_path] }) - else - setSSHWaitForResponse_without_use_ssh_keys - end - rescue => e - failure _("Failed to login via SSH to %{name}: %{e}") % - { :name => name, :e => e }, e + included do + prepend Overrides end end end