diff --git a/app/models/manageiq/providers/openstack/manager_mixin.rb b/app/models/manageiq/providers/openstack/manager_mixin.rb index 31108a9eb..2042faae4 100644 --- a/app/models/manageiq/providers/openstack/manager_mixin.rb +++ b/app/models/manageiq/providers/openstack/manager_mixin.rb @@ -11,14 +11,21 @@ module ManageIQ::Providers::Openstack::ManagerMixin # OpenStack interactions # module ClassMethods - def raw_connect(username, password, auth_url, service = "Compute") - require 'manageiq/providers/openstack/legacy/openstack_handle' - OpenstackHandle::Handle.raw_connect(username, MiqPassword.try_decrypt(password), auth_url, service) - end - - def auth_url(address, port = nil) - require 'manageiq/providers/openstack/legacy/openstack_handle' - OpenstackHandle::Handle.auth_url(address, port) + def raw_connect(password, params, service = "Compute") + ems = new + ems.name = params[:name].strip + ems.provider_region = params[:provider_region] + ems.api_version = params[:api_version].strip + ems.security_protocol = params[:default_security_protocol].strip + ems.keystone_v3_domain_id = params[:keystone_v3_domain_id] + + user, hostname, port = params[:default_userid], params[:default_hostname].strip, params[:default_api_port].strip + + endpoint = {:role => :default, :hostname => hostname, :port => port, :security_protocol => ems.security_protocol} + authentication = {:userid => user, :password => MiqPassword.try_decrypt(password), :save => false, :role => 'default', :authtype => 'default'} + ems.connection_configurations = [{:endpoint => endpoint, + :authentication => authentication}] + ems.connect(:service => service) end end diff --git a/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb b/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb index c6497729a..007cd884a 100644 --- a/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb +++ b/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb @@ -1,6 +1,6 @@ describe ManageIQ::Providers::Openstack::CloudManager do context "Class Methods" do - it("from mixin") { expect(described_class.methods).to include(:auth_url, :raw_connect) } + it("from mixin") { expect(described_class.methods).to include(:raw_connect) } end it ".ems_type" do @@ -59,25 +59,45 @@ end it "accepts and decrypts encrypted passwords" do + params = { + :name => 'dummy', + :provider_region => '', + :api_version => 'v2.0', + :default_security_protocol => 'non-ssl', + :default_userid => 'admin', + :default_hostname => 'address', + :default_api_port => '5000' + } expect(OpenstackHandle::Handle).to receive(:raw_connect).with( + "admin", "dummy", - "dummy", - "http://address:5000/v2.0/tokens", - "Compute" + "http://address:5000", + "Compute", + instance_of(Hash) ) - described_class.raw_connect("dummy", MiqPassword.encrypt("dummy"), "http://address:5000/v2.0/tokens", "Compute") + described_class.raw_connect(MiqPassword.encrypt("dummy"), params, "Compute") end it "works with unencrypted passwords" do + params = { + :name => 'dummy', + :provider_region => '', + :api_version => 'v2.0', + :default_security_protocol => 'non-ssl', + :default_userid => 'admin', + :default_hostname => 'address', + :default_api_port => '5000' + } expect(OpenstackHandle::Handle).to receive(:raw_connect).with( + "admin", "dummy", - "dummy", - "http://address:5000/v2.0/tokens", - "Compute" + "http://address:5000", + "Compute", + instance_of(Hash) ) - described_class.raw_connect("dummy", "dummy", "http://address:5000/v2.0/tokens", "Compute") + described_class.raw_connect("dummy", params, "Compute") end end