Skip to content

Commit

Permalink
Merge pull request #184 from mael-morel/issue#110
Browse files Browse the repository at this point in the history
Issue#110 : specify endpoint interface configuration
  • Loading branch information
ggiamarchi committed Dec 21, 2014
2 parents eafb86a + ac84102 commit 22d80de
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ This provider exposes quite a few provider-specific configuration options:
* `openstack_network_url` - The network service URL to hit. This is good for custom endpoints. If not provided, vagrant will try to get it from catalog endpoint.
* `openstack_volume_url` - The block storage URL to hit. This is good for custom endpoints. If not provided, vagrant will try to get it from catalog endpoint.
* `openstack_image_url` - The image URL to hit. This is good for custom endpoints. If not provided, vagrant will try to get it from catalog endpoint.
* `endpoint_type` - The endpoint type to use : publicURL, adminURL, internalURL. If not provided, vagrant will use publicURL by default.

### VM Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def read(env, catalog)
config = env[:machine].provider_config
client = env[:openstack_client]
endpoints = client.session.endpoints
endpoint_type = config.endpoint_type
@logger.info(I18n.t('vagrant_openstack.client.looking_for_available_endpoints'))
@logger.info("Selecting endpoints matching region '#{config.region}'") unless config.region.nil?

Expand All @@ -18,12 +19,12 @@ def read(env, catalog)
if config.region.nil?
if se.size > 1
env[:ui].warn I18n.t('vagrant_openstack.client.multiple_endpoint', size: se.size, type: service['type'])
env[:ui].warn " => #{service['endpoints'][0]['publicURL']}"
env[:ui].warn " => #{service['endpoints'][0][endpoint_type]}"
end
url = se[0]['publicURL'].strip
url = se[0][endpoint_type].strip
else
se.each do |endpoint|
url = endpoint['publicURL'].strip if endpoint['region'].eql? config.region
url = endpoint[endpoint_type].strip if endpoint['region'].eql? config.region
end
end
endpoints[service['type'].to_sym] = url unless url.nil? || url.empty?
Expand Down
8 changes: 8 additions & 0 deletions source/lib/vagrant-openstack-provider/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ class Config < Vagrant.plugin('2', :config)
# @return [Boolean]
attr_accessor :ssh_disabled

# Specify the endpoint_type to use : publicURL, adminURL, or internalURL (default is publicURL)
#
# @return [String]
attr_accessor :endpoint_type

def initialize
@password = UNSET_VALUE
@openstack_compute_url = UNSET_VALUE
Expand All @@ -168,6 +173,7 @@ def initialize
@openstack_orchestration_url = UNSET_VALUE
@openstack_image_url = UNSET_VALUE
@openstack_auth_url = UNSET_VALUE
@endpoint_type = UNSET_VALUE
@region = UNSET_VALUE
@flavor = UNSET_VALUE
@image = UNSET_VALUE
Expand Down Expand Up @@ -238,6 +244,7 @@ def finalize!
@openstack_volume_url = nil if @openstack_volume_url == UNSET_VALUE
@openstack_image_url = nil if @openstack_image_url == UNSET_VALUE
@openstack_auth_url = nil if @openstack_auth_url == UNSET_VALUE
@endpoint_type = 'publicURL' if @endpoint_type == UNSET_VALUE
@region = nil if @region == UNSET_VALUE
@flavor = nil if @flavor == UNSET_VALUE
@image = nil if @image == UNSET_VALUE
Expand Down Expand Up @@ -279,6 +286,7 @@ def validate(machine)

errors << I18n.t('vagrant_openstack.config.password_required') unless @password
errors << I18n.t('vagrant_openstack.config.username_required') unless @username
errors << I18n.t('vagrant_openstack.config.invalid_endpoint_type') unless %w(publicURL adminURL internalURL).include?(@endpoint_type)

validate_ssh_username(machine, errors)
validate_stack_config(errors)
Expand Down
2 changes: 2 additions & 0 deletions source/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ en:
name: 'mystack',
template: '/path/to/heat_template.yml',
}]
invalid_endpoint_type: |-
endpoint_type must be publicURL, adminURL or internalURL (if not provided, default is publicURL)
metadata_must_be_hash: |-
Metadata must be a hash.
keypair_name_required: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
config.stub(:username) { 'username' }
config.stub(:password) { 'password' }
config.stub(:region) { nil }
config.stub(:endpoint_type) { 'publicURL' }
end
end

Expand All @@ -44,6 +45,25 @@
end
end

let(:neutron_admin_url) do
double.tap do |neutron|
neutron.stub(:get_api_version_list).with(anything) do
[
{
'status' => 'CURRENT',
'id' => 'v2.0',
'links' => [
{
'href' => 'http://neutron/v2.0/admin',
'rel' => 'self'
}
]
}
]
end
end
end

let(:neutron_france) do
double.tap do |neutron|
neutron.stub(:get_api_version_list).with(anything) do
Expand Down Expand Up @@ -82,6 +102,25 @@
end
end

let(:glance_admin_url) do
double.tap do |glance|
glance.stub(:get_api_version_list).with(anything) do
[
{
'status' => 'CURRENT',
'id' => 'v2.1',
'links' => [
{
'href' => 'http://glance/v2.0/admin',
'rel' => 'self'
}
]
}
]
end
end
end

let(:glance_v1) do
double.tap do |glance|
glance.stub(:get_api_version_list).with(anything) do
Expand Down Expand Up @@ -317,8 +356,191 @@
end
end

describe 'endpoint_type' do
context 'with adminURL specified' do
it 'read service catalog and stores endpoints URL in session' do
catalog = [
{
'endpoints' => [
{
'publicURL' => 'http://nova/v2/projectId',
'adminURL' => 'http://nova/v2/projectId/admin',
'id' => '1'
}
],
'type' => 'compute',
'name' => 'nova'
},
{
'endpoints' => [
{
'publicURL' => 'http://neutron',
'adminURL' => 'http://neutron/admin',
'id' => '2'
}
],
'type' => 'network',
'name' => 'neutron'
},
{
'endpoints' => [
{
'publicURL' => 'http://cinder/v2/projectId',
'adminURL' => 'http://cinder/v2/projectId/admin',
'id' => '2'
}
],
'type' => 'volume',
'name' => 'cinder'
},
{
'endpoints' => [
{
'publicURL' => 'http://glance',
'adminURL' => 'http://glance/admin',
'id' => '2'
}
],
'type' => 'image',
'name' => 'glance'
}
]

double.tap do |keystone|
keystone.stub(:authenticate).with(anything) { catalog }
env[:openstack_client].stub(:keystone) { keystone }
end
env[:openstack_client].stub(:neutron) { neutron_admin_url }
env[:openstack_client].stub(:glance) { glance_admin_url }
config.stub(:endpoint_type) { 'adminURL' }

@action.call(env)

expect(env[:openstack_client].session.endpoints)
.to eq(compute: 'http://nova/v2/projectId/admin',
network: 'http://neutron/v2.0/admin',
volume: 'http://cinder/v2/projectId/admin',
image: 'http://glance/v2.0/admin')
end
end
end

describe 'endpoint_type' do
context 'with internalURL specified' do
it 'read service catalog and stores endpoints URL in session' do
catalog = [
{
'endpoints' => [
{
'publicURL' => 'http://nova/v2/projectId',
'adminURL' => 'http://nova/v2/projectId/admin',
'internalURL' => 'http://nova/v2/projectId/internal',
'id' => '1'
}
],
'type' => 'compute',
'name' => 'nova'
},
{
'endpoints' => [
{
'publicURL' => 'http://cinder/v2/projectId',
'adminURL' => 'http://cinder/v2/projectId/admin',
'internalURL' => 'http://cinder/v2/projectId/internal',
'id' => '2'
}
],
'type' => 'volume',
'name' => 'cinder'
}
]

double.tap do |keystone|
keystone.stub(:authenticate).with(anything) { catalog }
env[:openstack_client].stub(:keystone) { keystone }
end
config.stub(:endpoint_type) { 'internalURL' }

@action.call(env)

expect(env[:openstack_client].session.endpoints)
.to eq(compute: 'http://nova/v2/projectId/internal',
volume: 'http://cinder/v2/projectId/internal')
end
end
end

describe 'endpoint_type' do
context 'with publicURL specified' do
it 'read service catalog and stores endpoints URL in session' do
catalog = [
{
'endpoints' => [
{
'publicURL' => 'http://nova/v2/projectId',
'adminURL' => 'http://nova/v2/projectId/admin',
'id' => '1'
}
],
'type' => 'compute',
'name' => 'nova'
},
{
'endpoints' => [
{
'publicURL' => 'http://neutron',
'adminURL' => 'http://neutron/admin',
'id' => '2'
}
],
'type' => 'network',
'name' => 'neutron'
},
{
'endpoints' => [
{
'publicURL' => 'http://cinder/v2/projectId',
'adminURL' => 'http://cinder/v2/projectId/admin',
'id' => '2'
}
],
'type' => 'volume',
'name' => 'cinder'
},
{
'endpoints' => [
{
'publicURL' => 'http://glance',
'adminURL' => 'http://glance/admin',
'id' => '2'
}
],
'type' => 'image',
'name' => 'glance'
}
]

double.tap do |keystone|
keystone.stub(:authenticate).with(anything) { catalog }
env[:openstack_client].stub(:keystone) { keystone }
end
env[:openstack_client].stub(:neutron) { neutron }
env[:openstack_client].stub(:glance) { glance }
config.stub(:endpoint_type) { 'publicURL' }

@action.call(env)

expect(env[:openstack_client].session.endpoints)
.to eq(compute: 'http://nova/v2/projectId',
network: 'http://neutron/v2.0',
volume: 'http://cinder/v2/projectId',
image: 'http://glance/v2.0')
end
end
end

context 'with glance v1 only' do
it 'read service catalog and stores endpoints URL in session', :focus do
it 'read service catalog and stores endpoints URL in session' do
catalog = [
{
'endpoints' => [
Expand Down

0 comments on commit 22d80de

Please sign in to comment.