Start work on multi-instance OpenStack files

Add new Vagrantfile with multi-instance support. Modify external
data file (instances.yml) accordingly.
This commit is contained in:
Scott Lowe 2015-10-07 23:05:37 -06:00
parent 17947667d2
commit 028bc1bd4b
4 changed files with 119 additions and 0 deletions

View file

@ -0,0 +1,40 @@
# Using Vagrant with OpenStack (Multiple Instances)
These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) with OpenStack ([http://www.openstack.org](http://www.openstack.org)), where the VMs managed by Vagrant are instances in an OpenStack cloud. This configuration supports Vagrant operations against multiple instances, and was tested using Vagrant 1.7.4, version 0.7.0 of [the vagrant-openstack-provider plugin](https://github.com/ggiamarchi/vagrant-openstack-provider), and the "Juno" release of OpenStack.
## Contents
* **credentials.yml**: This YAML file contains the username, password, and tenant name for authenticating against OpenStack. You **must** edit this file to specify the correct information for your OpenStack installation.
* **instances.yml**: This YAML file contains the instance-specific information for the instance that will be created in OpenStack. You **must** edit this file to specify the correct instance name (as shown in the OpenStack Dashboard), flavor, image, floating IP pool, network name, SSH keypair name, and SSH username. _Failure to edit this file may result in errors trying to run Vagrant._
* **README.md**: The file you're currently reading.
* **Vagrantfile**: This file is used by Vagrant to spin up the OpenStack instance.
## Instructions
Please note that you'll need a working OpenStack installation in order to use these files.
1. Edit `credentials.yml` to supply a valid username, password, and tenant name for your particular OpenStack installation.
2. Edit `instances.yml`. The fields in this YAML file is fairly straightforward, but here's a quick breakdown:
* A display name for the instance ("name")
* The name of an OpenStack flavor ("flavor"), which you can obtain using `nova flavor-list`
* The name of an OpenStack image ("image"), obtainable via the `glance image-list` command
* The name of a floating IP pool ("ip_pool")
* The name of the tenant network to which the new instance should be attached ("networks")
* The SSH keypair that OpenStack should inject into the instance ("keypair")
* The username Vagrant can use to log into the instance ("ssh_user"); this will vary from image to image
3. Edit `Vagrantfile` and look for comments stating "Edit the following line with your correct information". There are **three** changes you must make in the `Vagrantfile`:
* You must specify the correct URL for authenticating with OpenStack
* You must provide the correct path for the private key that matches the keypair specified in `instances.yml`
* You must supply the list of security groups that OpenStack should apply to the new instance
4. Ensure that the system running Vagrant has connectivity to the authentication URL for OpenStack.
5. Run `vagrant up` to have Vagrant authenticate to OpenStack and create the desired instance for you. Once the instance is created, you can use `vagrant ssh` to connect to the instance, and `vagrant destroy` will terminate (destroy) the OpenStack instance for you.
Enjoy!
## Planned Enhancements
* Changing the `Vagrantfile` to allow for multi-instance configurations
* Removing all user-specific parameters from the `Vagrantfile` so that no edits are required

60
vagrant-openstack-multi/Vagrantfile vendored Normal file
View file

@ -0,0 +1,60 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Require the OpenStack provider plugin and YAML module
require 'vagrant-openstack-provider'
require 'yaml'
# Read YAML file with OpenStack credentials
creds = YAML.load_file('credentials.yml')
instances = YAML.load_file('instances.yml')
# Specify Vagrant version and Vagrant API version
Vagrant.require_version '>= 1.6.0'
VAGRANTFILE_API_VERSION = '2'
ENV['VAGRANT_DEFAULT_PROVIDER'] = 'openstack'
# Specify OpenStack authentication URL
# Edit the following line with your correct information
ENV['OS_AUTH_URL'] = 'http://cloud.lowehome.net:5000/v2.0'
# Create and configure the OpenStack instance(s)
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# No Vagrant box needed with OpenStack
# config.vm.box = "dummy"
# Specify path to SSH private key
config.ssh.private_key_path = '~/.ssh/homelab.pem'
# Configure the base information for the OpenStack provider
config.vm.provider 'openstack' do |os|
os.openstack_auth_url = ENV['OS_AUTH_URL']
os.username = creds['username']
os.password = creds['password']
os.tenant_name = creds['tenant']
os.server_name = 'default'
os.flavor = 'm1.small'
os.image = 'default'
os.floating_ip_pool = 'default'
os.networks = 'default'
os.keypair_name = 'default'
os.security_groups = ['default']
os.sync_method = 'none'
end # config.vm.provider 'openstack'
# Loop through YAML file and set per-instance information
instances.each do |instance|
config.vm.define instance['name'] do |srv|
srv.vm.provider 'openstack' do |os, override|
os.server_name = instance['name']
os.flavor = instance['flavor']
os.image = instance['image']
os.floating_ip_pool = instance['ip_pool']
os.networks = instance['networks']
os.keypair_name = instance['keypair']
override.ssh.username = instance['ssh_user']
end # srv.vm.provider
end # config.vm.define
end # instances.each
end # Vagrant.configure

View file

@ -0,0 +1,4 @@
---
username: "slowe"
password: "Me3twet8ein"
tenant: "lab"

View file

@ -0,0 +1,15 @@
---
- name: "test-01"
flavor: "m1.small"
image: "Ubuntu 14.04.3 LTS x64"
ip_pool: "ext-net-1"
networks: "test-01"
keypair: "homelab"
ssh_user: "ubuntu"
- name: "test-02"
flavor: "m1.small"
image: "Ubuntu 12.04.5 LTS x64"
ip_pool: "ext-net-1"
networks: "test-01"
keypair: "homelab"
ssh_user: "ubuntu"