Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please consider supporting os-client-config style clouds.yml files #350

Open
JonTheNiceGuy opened this issue Feb 21, 2018 · 3 comments
Open
Labels

Comments

@JonTheNiceGuy
Copy link

Hi!

I'm about to start using this provider, but I was wondering whether it would be possible for you to consider using the os-client-config style files. These files are typically (on Linux at least) stored in ./clouds.y(a)ml, $HOME/.config/openstack/clouds.y(a)ml and /etc/openstack/clouds.y(a)ml. OS X and Windows have their own paths.

The format of these files is documented in https://docs.openstack.org/os-client-config/latest/user/configuration.html

The python library to load these files is here: https://github.com/openstack/os-client-config

Here's an example file (from the docs url above):

clouds:
  mtvexx:
    profile: vexxhost
    auth:
      username: [email protected]
      password: XXXXXXXXX
      project_name: [email protected]
    region_name: ca-ymq-1
    dns_api_version: 1

  mordred:
    region_name: RegionOne
    auth:
      username: 'mordred'
      password: XXXXXXX
      project_name: 'shade'
      auth_url: 'https://montytaylor-sjc.openstack.blueboxgrid.com:5001/v2.0'

  infra:
    profile: rackspace
    auth:
      username: openstackci
      password: XXXXXXXX
      project_id: 610275
    regions:
    - DFW
    - ORD
    - IAD
@ggiamarchi
Copy link
Owner

Hi @JonTheNiceGuy,

I agree it would be a good thing to support os-client-config format. For some reason there's a lot of work to do to support it in good conditions:

  • Everything in Vagrant is written in Ruby. We should port openstack/os-client-config in Ruby
  • Currently authentication in Vagrant OpenStack Provider have some missing parts. Authentication must be done using project name, it does not work with project ID. Keystone v3 support is not complete.

I can't personally take time currently to work on that but pull requests are welcome.

Also, you could currently read your os-client-config file with the following approach. A little bit tricky but it should work.


1 /

I consider os-client-config python package is globaly install on your system

Create a python script generate-clouds-config.py that print on Stdout the full configuration in JSON frormat from your os-client-config yaml configuration.

#!/usr/bin/env python

import json
import os_client_config

cloud_config = os_client_config.OpenStackConfig().get_all_clouds()
config = {}
for cloud in cloud_config:
    if cloud.name not in config:
        config[cloud.name] = {}
    config[cloud.name][cloud.region] = cloud.config

print(json.dumps(config, indent=4))

2 /

In your Vagrantfile call this script, capture its output and parse it as a ruby object

cloud_config = JSON.parse(`./generate-clouds-config.py`)

then you can use this object to get configuration data. For instance, to get the authentication URL

cloud_config[cloud][region]['auth']['auth_url']

Finally, here comes the full Vagrantfile.

Vagrant.configure('2') do |config|

  cloud  = 'infra'
  region = 'ORD'

  cloud_config = JSON.parse(`./generate-clouds-config.py`)
  auth = cloud_config[cloud][region]['auth']

  config.vm.provider :openstack do |os|
    os.openstack_auth_url               = auth['auth_url']
    os.tenant_name                      = auth['project_name']
    os.username                         = auth['username']
    os.password                         = auth['password']
    os.region                           = region
    os.server_name                      = ...
    os.floating_ip_pool                 = ...
    os.floating_ip_pool_always_allocate = ...
    os.flavor                           = ...
    os.image                            = ...
    os.networks                        << ...
  end
  config.ssh.username = ...
end

You should be able to switch from one cloud to another one changing only cloud and region variables.

N.B.

I didn't run a end to end test, so it's possible you need to adapt some small things but I think the overall approach is good.

@JonTheNiceGuy
Copy link
Author

This is awesome, thanks. I'll investigate it with my system and clouds.yml over the weekend...

@ssbarnea
Copy link

ssbarnea commented Jul 2, 2019

Any chance of ever seeing this happening? If clouds.yml could be supported the only thing needed for the user to specify wouldbe the tenant name, in fact not even that as the default one is the first one listed in the file.

Current behavior forces users to put credentials into the Vagrantfile which means we cannot include it in the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants