ggiamarchi / vagrant-openstack-provider

Use Vagrant to manage OpenStack Cloud instances.
MIT License
247 stars 101 forks source link

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

Open JonTheNiceGuy opened 6 years ago

JonTheNiceGuy commented 6 years ago

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: mordred@inaugust.com
      password: XXXXXXXXX
      project_name: mordred@inaugust.com
    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 commented 6 years ago

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:

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 commented 6 years ago

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

ssbarnea commented 5 years ago

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.