From 4a89279eea351956ed0e1fc02077169bc76c167c Mon Sep 17 00:00:00 2001 From: Scott Seago Date: Tue, 24 Jul 2018 08:52:49 -0400 Subject: [PATCH] add sshkey support to OpenStack Cloud Add sshkey support to OpenStack Cloud needed for v2v. --- .../controllers/ems_common/ems_common_form_controller.js | 7 ++++--- .../controllers/ems_keypair/ems_keypair_controller.js | 5 +++-- app/controllers/mixins/ems_common_angular.rb | 9 ++++++++- .../layouts/angular/_multi_auth_credentials.html.haml | 6 +++--- .../ems_keypair/ems_keypair_controller_spec.js | 4 ++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js b/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js index 0a53f0655098..fa6eabf239a4 100644 --- a/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js +++ b/app/assets/javascripts/controllers/ems_common/ems_common_form_controller.js @@ -315,8 +315,8 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.emsCommonModel.emstype === "kubevirt" && $scope.emsCommonModel.default_hostname || $scope.emsCommonModel.emstype == "vmwarews" && $scope.emsCommonModel.default_hostname || $scope.emsCommonModel.emstype == "vmware_cloud" && $scope.emsCommonModel.default_hostname) && - ($scope.emsCommonModel.default_userid != '' && $scope.angularForm.default_userid.$valid && - $scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid)) { + ($scope.emsCommonModel.default_userid != '' && $scope.angularForm.default_userid !== undefined && $scope.angularForm.default_userid.$valid && + $scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password !== undefined && $scope.angularForm.default_password.$valid)) { return true; } else if(($scope.currentTab == "amqp") && ($scope.emsCommonModel.amqp_hostname) && @@ -337,7 +337,8 @@ ManageIQ.angular.app.controller('emsCommonFormController', ['$http', '$scope', ' $scope.emsCommonModel.default_password != '' && $scope.angularForm.default_password.$valid) && ($scope.newRecord && $scope.angularForm.provider_region.$valid || ! $scope.newRecord)) { return true; - } else if(($scope.currentTab == "ssh_keypair" && $scope.emsCommonModel.emstype == "openstack_infra") && + } else if(($scope.currentTab == "ssh_keypair" && + ($scope.emsCommonModel.emstype == "openstack" || $scope.emsCommonModel.emstype == "openstack_infra")) && ($scope.emsCommonModel.ssh_keypair_userid != '' && $scope.angularForm.ssh_keypair_userid.$valid && $scope.emsCommonModel.ssh_keypair_password != '' && $scope.angularForm.ssh_keypair_password.$valid)) { return true; diff --git a/app/assets/javascripts/controllers/ems_keypair/ems_keypair_controller.js b/app/assets/javascripts/controllers/ems_keypair/ems_keypair_controller.js index 004bf7e1ad11..034e7b294601 100644 --- a/app/assets/javascripts/controllers/ems_keypair/ems_keypair_controller.js +++ b/app/assets/javascripts/controllers/ems_keypair/ems_keypair_controller.js @@ -63,9 +63,10 @@ }; EmsKeypairController.prototype.showValidate = function(tab) { - var openstackAndNew = (this.model.emstype === 'openstack_infra') && this.newRecord; + var openstackInfraAndNew = (this.model.emstype === 'openstack_infra') && this.newRecord; + var openstackCloud = this.model.emstype === 'openstack'; var rhevm = this.model.emstype === 'rhevm'; - return ! ((openstackAndNew || rhevm) && tab === 'ssh_keypair'); + return ! ((openstackInfraAndNew || openstackCloud || rhevm) && tab === 'ssh_keypair'); }; EmsKeypairController.$inject = ["$scope"]; diff --git a/app/controllers/mixins/ems_common_angular.rb b/app/controllers/mixins/ems_common_angular.rb index 688cecaccefd..af0c6e4f3b86 100644 --- a/app/controllers/mixins/ems_common_angular.rb +++ b/app/controllers/mixins/ems_common_angular.rb @@ -375,6 +375,7 @@ def ems_form_fields :openstack_infra_providers_exist => retrieve_openstack_infra_providers.length > 0, :default_userid => @ems.authentication_userid.to_s, :amqp_userid => amqp_userid, + :ssh_keypair_userid => ssh_keypair_userid, :smartstate_docker_userid => smartstate_docker_userid, :service_account => service_account.to_s, :azure_tenant_id => azure_tenant_id.to_s, @@ -388,6 +389,7 @@ def ems_form_fields :ems_controller => controller_name, :default_auth_status => default_auth_status, :amqp_auth_status => amqp_auth_status, + :ssh_keypair_auth_status => ssh_keypair_auth_status.nil? ? true : ssh_keypair_auth_status, :service_account_auth_status => service_account_auth_status, :amqp_fallback_hostname1 => amqp_fallback_hostname1 ? amqp_fallback_hostname1 : "", :amqp_fallback_hostname2 => amqp_fallback_hostname2 ? amqp_fallback_hostname2 : "", @@ -564,7 +566,7 @@ def set_ems_record_vars(ems, mode = nil) end end - if ems.kind_of?(ManageIQ::Providers::Openstack::InfraManager) || ems.kind_of?(ManageIQ::Providers::Redhat::InfraManager) + if ems.kind_of?(ManageIQ::Providers::Openstack::CloudManager) || ems.kind_of?(ManageIQ::Providers::Openstack::InfraManager) || ems.kind_of?(ManageIQ::Providers::Redhat::InfraManager) ssh_keypair_endpoint = {:role => :ssh_keypair} end @@ -760,6 +762,11 @@ def build_credentials(ems, mode) ssh_keypair_password = params[:ssh_keypair_password] ? params[:ssh_keypair_password].gsub(/\r\n/, "\n") : ems.authentication_key(:ssh_keypair) creds[:ssh_keypair] = {:userid => params[:ssh_keypair_userid], :auth_key => ssh_keypair_password, :save => (mode != :validate)} end + if ems.kind_of?(ManageIQ::Providers::Openstack::CloudManager) && + ems.supports_authentication?(:ssh_keypair) && params[:ssh_keypair_userid] + ssh_keypair_password = params[:ssh_keypair_password] ? params[:ssh_keypair_password].gsub(/\r\n/, "\n") : ems.authentication_key(:ssh_keypair) + creds[:ssh_keypair] = {:userid => params[:ssh_keypair_userid], :auth_key => ssh_keypair_password, :save => (mode != :validate)} + end if ems.kind_of?(ManageIQ::Providers::Redhat::InfraManager) && ems.supports_authentication?(:ssh_keypair) && params[:ssh_keypair_userid] ssh_keypair_password = params[:ssh_keypair_password] ? params[:ssh_keypair_password].gsub(/\r\n/, "\n") : ems.authentication_key(:ssh_keypair) diff --git a/app/views/layouts/angular/_multi_auth_credentials.html.haml b/app/views/layouts/angular/_multi_auth_credentials.html.haml index e1463d642809..064e9b6a4dc0 100644 --- a/app/views/layouts/angular/_multi_auth_credentials.html.haml +++ b/app/views/layouts/angular/_multi_auth_credentials.html.haml @@ -301,7 +301,7 @@ = _("Disable event monitoring.") = miq_tab_content('ssh_keypair', 'default') do .form-group - .col-md-12.col-md-12{"ng-if" => "#{ng_model}" == "emsCommonModel" && ("#{ng_model}.emstype == 'openstack_infra' || #{ng_model}.emstype == 'rhevm'") } + .col-md-12.col-md-12{"ng-if" => "#{ng_model}" == "emsCommonModel" && ("#{ng_model}.emstype == 'openstack' || #{ng_model}.emstype == 'openstack_infra' || #{ng_model}.emstype == 'rhevm'") } = render :partial => "layouts/angular-bootstrap/auth_keypair_angular_bootstrap", :locals => {:ng_show => true, :ng_model => "#{ng_model}", @@ -531,7 +531,7 @@ miq_tabs_show_hide("#ssh_keypair_tab", false); miq_tabs_init('#auth_tabs'); $('#auth_tabs').show(); -%div{"ng-if" => "#{ng_model}.emstype == 'openstack' || #{ng_model}.emstype == 'vmware_cloud'"} +%div{"ng-if" => "#{ng_model}.emstype == 'vmware_cloud'"} :javascript miq_tabs_show_hide("#amqp_tab", true); miq_tabs_show_hide("#metrics_tab", false); @@ -540,7 +540,7 @@ miq_tabs_show_hide("#smartstate_docker_tab", false); miq_tabs_init('#auth_tabs'); $('#auth_tabs').show(); -%div{"ng-if" => "#{ng_model}.emstype == 'openstack_infra'"} +%div{"ng-if" => "#{ng_model}.emstype == 'openstack' || #{ng_model}.emstype == 'openstack_infra'"} :javascript miq_tabs_show_hide("#amqp_tab", true); miq_tabs_show_hide("#metrics_tab", false); diff --git a/spec/javascripts/controllers/ems_keypair/ems_keypair_controller_spec.js b/spec/javascripts/controllers/ems_keypair/ems_keypair_controller_spec.js index bb6b63a2732e..399f0d10944c 100644 --- a/spec/javascripts/controllers/ems_keypair/ems_keypair_controller_spec.js +++ b/spec/javascripts/controllers/ems_keypair/ems_keypair_controller_spec.js @@ -72,6 +72,10 @@ describe('emsKeypairController', function() { describe('#showValidate', function() { var combinations = [ + { emstype: 'openstack', newRecord: true, tab: 'ssh_keypair', value: false }, + { emstype: 'openstack', newRecord: true, tab: 'other_tab', value: true }, + { emstype: 'openstack', newRecord: false, tab: 'tab', value: true }, + { emstype: 'openstack_infra', newRecord: true, tab: 'ssh_keypair', value: false }, { emstype: 'openstack_infra', newRecord: true, tab: 'other_tab', value: true }, { emstype: 'openstack_infra', newRecord: false, tab: 'tab', value: true },