Skip to content

Commit

Permalink
Merge pull request #258 from andinod/master
Browse files Browse the repository at this point in the history
Connection through project_id to Openstack
  • Loading branch information
ramonskie authored Nov 7, 2022
2 parents 940ef2d + 919d61a commit 34eae27
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
4 changes: 3 additions & 1 deletion jobs/openstack_cpi/spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ properties:
openstack.tenant:
description: OpenStack tenant name (required for Keystone API V2)
openstack.project:
description: OpenStack project name (required for Keystone API V3)
description: OpenStack project name (required for Keystone API V3. Also can be used the project_id property )
openstack.project_id:
description: OpenStack project id (required for Keystone API V3. Also can be used the project property)
openstack.domain:
description: OpenStack domain (required for Keystone API V3)
openstack.region:
Expand Down
1 change: 1 addition & 0 deletions jobs/openstack_cpi/templates/cpi.json.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
if_p('openstack.user_domain_name') { |value| openstack_params['user_domain_name'] = value }
if_p('openstack.project_domain_name') { |value| openstack_params['project_domain_name'] = value }
if_p('openstack.project') { |value| openstack_params['project'] = value }
if_p('openstack.project_id') { |value| openstack_params['project_id'] = value }
if_p('openstack.tenant') { |value| openstack_params['tenant'] = value }
if_p('openstack.human_readable_vm_names') { |value| openstack_params['human_readable_vm_names'] = value }

Expand Down
7 changes: 6 additions & 1 deletion src/bosh_openstack_cpi/lib/cloud/openstack/cloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ def validate_options
auth_url = @options['openstack']['auth_url']
user_domain_name = @options['openstack']['user_domain_name']
project_domain_name = @options['openstack']['project_domain_name']
project_id = @options['openstack']['project_id']
schema = Membrane::SchemaParser.parse do
openstack_options_schema = {
'openstack' => {
Expand Down Expand Up @@ -778,7 +779,11 @@ def validate_options
optional('agent') => Hash,
}
if Bosh::OpenStackCloud::Openstack.is_v3(auth_url)
openstack_options_schema['openstack']['project'] = String
if project_id
openstack_options_schema['openstack']['project_id'] = String
else
openstack_options_schema['openstack']['project'] = String
end
if user_domain_name || project_domain_name
openstack_options_schema['openstack']['user_domain_name'] = String
openstack_options_schema['openstack']['project_domain_name'] = String
Expand Down
15 changes: 14 additions & 1 deletion src/bosh_openstack_cpi/lib/cloud/openstack/openstack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,19 @@ def with_openstack(retryable: false, ignore_not_found: false)
end

def project_name
is_v3 ? params[:openstack_project_name] : params[:openstack_tenant]
if is_v3
# Check if our connection is done through the openstack_project_name
if params.key?(:openstack_project_name)
params[:openstack_project_name]
else
# Then it means that we are using the openstack_project_id
connection = compute
connection.current_tenant['name']
end
else
# Return the tenant name
params[:openstack_tenant]
end
end

def use_nova_networking?
Expand Down Expand Up @@ -257,6 +269,7 @@ def openstack_params(options)
openstack_api_key: options['api_key'],
openstack_tenant: options['tenant'],
openstack_project_name: options['project'],
openstack_project_id: options['project_id'],
openstack_domain_name: options['domain'],
openstack_user_domain_name: options['user_domain_name'],
openstack_project_domain_name: options['project_domain_name'],
Expand Down
13 changes: 12 additions & 1 deletion src/bosh_openstack_cpi/spec/unit/cloud_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
options['openstack']['auth_url'] = 'http://127.0.0.1:5000/v3'
end

it 'raises an error when no project is specified' do
it 'raises an error when no project or project_id is specified' do
options['openstack']['domain'] = 'fake_domain'
expect { subject }
.to raise_error(ArgumentError,
Expand All @@ -166,6 +166,17 @@
end
end

context 'when project_id and domain are specified' do
before do
options['openstack']['project_id'] = 'fake_project_id'
options['openstack']['domain'] = 'fake_domain'
end

it 'does not raise an error' do
expect { subject }.to_not raise_error
end
end

context 'when project and user_domain_name and project_domain_name are specified' do
before do
options['openstack']['project'] = 'fake_project'
Expand Down

0 comments on commit 34eae27

Please sign in to comment.