From 874cebbf2d1f3902164944a4ef94dd524a4723b5 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Thu, 8 Oct 2015 09:19:42 -0600 Subject: [PATCH 1/5] Add structure for OVN project Add structure and starting files for OVN project --- ovn/README.md | 25 +++++++++++++++++++++++++ ovn/Vagrantfile | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 ovn/README.md create mode 100644 ovn/Vagrantfile diff --git a/ovn/README.md b/ovn/README.md new file mode 100644 index 0000000..7afe86d --- /dev/null +++ b/ovn/README.md @@ -0,0 +1,25 @@ +# Generic Debian 8.0 ("Jessie") VM + +These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) to quickly and easily spin up a generic Debian 8.0 ("Jessie") 64-bit VM. The configuration was tested using Vagrant 1.7.2, VMware Fusion 6.0.5, and the Vagrant VMware plugin. + +**NOTE:** There's really nothing special here; I created these files because I often had a need to quickly and easily spin up a generic Debian VM for some purpose (building a package or testing a command). I'm including them here just for the sake of completeness. + +## Contents + +* **README.md**: This file you're currently reading. + +* **servers.yml**: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. + +* **Vagrantfile**: This file is used by Vagrant to spin up the virtual machines. This file is fairly extensively commented to help explain what's happening. You should be able to use this file unchanged; all the VM configuration options are stored outside this file. + +## Instructions + +These instructions assume you've already installed VMware Fusion, Vagrant, and the Vagrant VMware plugin. Please refer to the documentation for those products for more information on installation or configuration. + +1. Use `vagrant box add` to add a 64-bit Debian 8.0 ("Jessie") base box to be used by this `Vagrantfile`. You'll need to specify a box that provides support for the `vmware_desktop` provider (it should work with either VMware Workstation or VMware Fusion). + +2. Edit the `servers.yml` file to ensure the box you downloaded in step 1 is specified on the "box:" line of this file. + +3. Run `vagrant up`, and when the VM is up use `vagrant ssh` to access the generic Debian VM. + +Enjoy! diff --git a/ovn/Vagrantfile b/ovn/Vagrantfile new file mode 100644 index 0000000..cdf94b9 --- /dev/null +++ b/ovn/Vagrantfile @@ -0,0 +1,40 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# Specify Vagrant version, Vagrant API version, and Vagrant clone location +Vagrant.require_version ">= 1.6.0" +VAGRANTFILE_API_VERSION = "2" +ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant' + +# Require 'yaml' module +require 'yaml' + +# Read YAML file with VM details (box, CPU, and RAM) +servers = YAML.load_file('servers.yml') + +# Create and configure the VMs +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + + # Always use Vagrant's default insecure key + config.ssh.insert_key = false + + # Iterate through entries in YAML file to create VMs + servers.each do |servers| + config.vm.define servers["name"] do |srv| + + # Don't check for box updates + srv.vm.box_check_update = false + srv.vm.hostname = servers["name"] + srv.vm.box = servers["box"] + + # Disable default synced folder + srv.vm.synced_folder ".", "/vagrant", disabled: true + + # Configure VMs with RAM and CPUs per settings in servers.yml + srv.vm.provider :vmware_fusion do |vmw| + vmw.vmx["memsize"] = servers["ram"] + vmw.vmx["numvcpus"] = servers["vcpu"] + end # srv.vm.provider + end # config.vm.define + end # servers.each +end # Vagrant.configure From 76a76cd5b096568905090aaac7c3c5fe62345cb0 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Thu, 8 Oct 2015 17:33:06 -0600 Subject: [PATCH 2/5] Develop OVN environment Expand Vagrantfile to include coverage for other providers. Add logic to Vagrantfile for disabling folder sync. Add YAML data file to specify VMs to be created. General syntax clean-up. --- ovn/Vagrantfile | 46 +++++++++++++++++++++++++++++++++------------- ovn/servers.yml | 16 ++++++++++++++++ 2 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 ovn/servers.yml diff --git a/ovn/Vagrantfile b/ovn/Vagrantfile index cdf94b9..7b2a9e7 100644 --- a/ovn/Vagrantfile +++ b/ovn/Vagrantfile @@ -1,10 +1,14 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -# Specify Vagrant version, Vagrant API version, and Vagrant clone location -Vagrant.require_version ">= 1.6.0" -VAGRANTFILE_API_VERSION = "2" +# Specify Vagrant version, Vagrant API version, Vagrant clone location, +# and default Vagrant provider +Vagrant.require_version '>= 1.6.0' +VAGRANTFILE_API_VERSION = '2' +ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_fusion' ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant' +#ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox' +#ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_appcatalyst' # Require 'yaml' module require 'yaml' @@ -19,22 +23,38 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.ssh.insert_key = false # Iterate through entries in YAML file to create VMs - servers.each do |servers| - config.vm.define servers["name"] do |srv| + servers.each do |server| + config.vm.define server['name'] do |srv| # Don't check for box updates srv.vm.box_check_update = false - srv.vm.hostname = servers["name"] - srv.vm.box = servers["box"] + srv.vm.hostname = server['name'] + srv.vm.box = server['box'] - # Disable default synced folder - srv.vm.synced_folder ".", "/vagrant", disabled: true + # Configure default synced folder (disable by default) + if server['sync_disabled'] != nil + srv.vm.synced_folder '.', '/vagrant', disabled: server['sync_disabled'] + else + srv.vm.synced_folder '.', '/vagrant', disabled: true + end #if servers['sync_disabled'] - # Configure VMs with RAM and CPUs per settings in servers.yml + # Configure CPU & RAM per settings in servers.yml (Fusion) srv.vm.provider :vmware_fusion do |vmw| - vmw.vmx["memsize"] = servers["ram"] - vmw.vmx["numvcpus"] = servers["vcpu"] - end # srv.vm.provider + vmw.vmx['memsize'] = server['ram'] + vmw.vmx['numvcpus'] = server['vcpu'] + end # srv.vm.provider vmware_fusion + + # Configure CPU & RAM per settings in servers.yml (AppCatalyst) + srv.vm.provider :vmware_appcatalyst do |vmw| + vmw.vmx['memsize'] = server['ram'] + vmw.vmx['numvcpus'] = server['vcpu'] + end # srv.vm.provider vmware_appcatalyst + + # Configure CPU & RAM per settings in servers.yml (VirtualBox) + srv.vm.provider :virtualbox do |vb| + vb.memory = server['ram'] + vb.cpus = server['vcpu'] + end # srv.vm.provider virtualbox end # config.vm.define end # servers.each end # Vagrant.configure diff --git a/ovn/servers.yml b/ovn/servers.yml new file mode 100644 index 0000000..1cc67de --- /dev/null +++ b/ovn/servers.yml @@ -0,0 +1,16 @@ +--- +- name: "ovn-01" + box: "slowe/ubuntu-trusty-x64" + ram: "512" + vcpu: "1" + ip_addr: "192.168.100.101" +- name: "ovn-02" + box: "slowe/ubuntu-trusty-x64" + ram: "512" + vcpu: "1" + ip_addr: "192.168.100.102" +- name: "ovn-03" + box: "slowe/ubuntu-trusty-x64" + ram: "512" + vcpu: "1" + ip_addr: "192.168.100.103" From 217e3f5af615bd6b03807517eaa5ea01e57ad250 Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Thu, 1 Dec 2016 19:47:56 -0700 Subject: [PATCH 3/5] Commit working files for OVN environment Rename `servers.yml` to `machines.yml` to adhere to naming standards. Edit files to assume the use of Ubuntu 16.04. Modify `Vagrantfile` to use latest approach in reading data from YAML config file. Signed-off-by: Scott S. Lowe --- ovn/Vagrantfile | 71 +++++++++++++++++++++++++++--------------------- ovn/machines.yml | 28 +++++++++++++++++++ ovn/servers.yml | 16 ----------- 3 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 ovn/machines.yml delete mode 100644 ovn/servers.yml diff --git a/ovn/Vagrantfile b/ovn/Vagrantfile index 7b2a9e7..ed0d192 100644 --- a/ovn/Vagrantfile +++ b/ovn/Vagrantfile @@ -1,20 +1,16 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -# Specify Vagrant version, Vagrant API version, Vagrant clone location, -# and default Vagrant provider +# Specify minimum Vagrant version and Vagrant API version Vagrant.require_version '>= 1.6.0' VAGRANTFILE_API_VERSION = '2' -ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_fusion' -ENV['VAGRANT_VMWARE_CLONE_DIRECTORY'] = '~/.vagrant' -#ENV['VAGRANT_DEFAULT_PROVIDER'] = 'virtualbox' -#ENV['VAGRANT_DEFAULT_PROVIDER'] = 'vmware_appcatalyst' # Require 'yaml' module require 'yaml' -# Read YAML file with VM details (box, CPU, and RAM) -servers = YAML.load_file('servers.yml') +# Read YAML file with VM details (box, CPU, RAM, IP addresses) +# Edit machines.yml to change VM configuration details +machines = YAML.load_file(File.join(File.dirname(__FILE__), 'machines.yml')) # Create and configure the VMs Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| @@ -23,38 +19,51 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.ssh.insert_key = false # Iterate through entries in YAML file to create VMs - servers.each do |server| - config.vm.define server['name'] do |srv| + machines.each do |machine| + + # Configure the VMs per details in machines.yml + config.vm.define machine['name'] do |srv| # Don't check for box updates srv.vm.box_check_update = false - srv.vm.hostname = server['name'] - srv.vm.box = server['box'] + + # Specify the hostname of the VM + srv.vm.hostname = machine['name'] + + # Specify the Vagrant box to use (use VMware box by default) + srv.vm.box = machine['box']['vmw'] # Configure default synced folder (disable by default) - if server['sync_disabled'] != nil - srv.vm.synced_folder '.', '/vagrant', disabled: server['sync_disabled'] + if machine['sync_disabled'] != nil + srv.vm.synced_folder '.', '/vagrant', disabled: machine['sync_disabled'] else srv.vm.synced_folder '.', '/vagrant', disabled: true - end #if servers['sync_disabled'] + end #if machine['sync_disabled'] - # Configure CPU & RAM per settings in servers.yml (Fusion) - srv.vm.provider :vmware_fusion do |vmw| - vmw.vmx['memsize'] = server['ram'] - vmw.vmx['numvcpus'] = server['vcpu'] - end # srv.vm.provider vmware_fusion + # Iterate through networks as per settings in machines.yml + machine['nics'].each do |net| + if net['ip_addr'] == 'dhcp' + srv.vm.network net['type'], type: net['ip_addr'] + else + srv.vm.network net['type'], ip: net['ip_addr'] + end # if net['ip_addr'] + end # machine['nics'].each - # Configure CPU & RAM per settings in servers.yml (AppCatalyst) - srv.vm.provider :vmware_appcatalyst do |vmw| - vmw.vmx['memsize'] = server['ram'] - vmw.vmx['numvcpus'] = server['vcpu'] - end # srv.vm.provider vmware_appcatalyst + # Configure CPU & RAM per settings in machines.yml (Fusion) + srv.vm.provider 'vmware_fusion' do |vmw| + vmw.vmx['memsize'] = machine['ram'] + vmw.vmx['numvcpus'] = machine['vcpu'] + if machine['nested'] == true + vmw.vmx['vhv.enable'] = 'TRUE' + end #if machine['nested'] + end # srv.vm.provider 'vmware_fusion' - # Configure CPU & RAM per settings in servers.yml (VirtualBox) - srv.vm.provider :virtualbox do |vb| - vb.memory = server['ram'] - vb.cpus = server['vcpu'] - end # srv.vm.provider virtualbox + # Configure CPU & RAM per settings in machines.yml (VirtualBox) + srv.vm.provider 'virtualbox' do |vb, override| + vb.memory = machine['ram'] + vb.cpus = machine['vcpu'] + override.vm.box = machine['box']['vb'] + end # srv.vm.provider 'virtualbox' end # config.vm.define - end # servers.each + end # machines.each end # Vagrant.configure diff --git a/ovn/machines.yml b/ovn/machines.yml new file mode 100644 index 0000000..1e02bf1 --- /dev/null +++ b/ovn/machines.yml @@ -0,0 +1,28 @@ +--- +- name: "ovn-01" + box: + vmw: "bento/ubuntu-16.04" + vb: "bento/ubuntu-16.04" + ram: "512" + vcpu: "1" + nics: + - type: "private_network" + ip_addr: "192.168.100.101" +- name: "ovn-02" + box: + vmw: "bento/ubuntu-16.04" + vb: "bento/ubuntu-16.04" + ram: "512" + vcpu: "1" + nics: + - type: "private_network" + ip_addr: "192.168.100.102" +- name: "ovn-03" + box: + vmw: "bento/ubuntu-16.04" + vb: "bento/ubuntu-16.04" + ram: "512" + vcpu: "1" + nics: + - type: "private_network" + ip_addr: "192.168.100.103" diff --git a/ovn/servers.yml b/ovn/servers.yml deleted file mode 100644 index 1cc67de..0000000 --- a/ovn/servers.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- name: "ovn-01" - box: "slowe/ubuntu-trusty-x64" - ram: "512" - vcpu: "1" - ip_addr: "192.168.100.101" -- name: "ovn-02" - box: "slowe/ubuntu-trusty-x64" - ram: "512" - vcpu: "1" - ip_addr: "192.168.100.102" -- name: "ovn-03" - box: "slowe/ubuntu-trusty-x64" - ram: "512" - vcpu: "1" - ip_addr: "192.168.100.103" From fb99b1682f210caa4557ec19e2e1d359092fd401 Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Thu, 1 Dec 2016 20:02:03 -0700 Subject: [PATCH 4/5] Commit initial Ansible files Add `ansible.cfg` and `provision.yml` as initial versions of Ansible configuration/provisioning tools to turn up the OVN environment (will be called by Vagrant) Signed-off-by: Scott S. Lowe --- ovn/ansible.cfg | 5 +++++ ovn/provision.yml | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 ovn/ansible.cfg create mode 100644 ovn/provision.yml diff --git a/ovn/ansible.cfg b/ovn/ansible.cfg new file mode 100644 index 0000000..b3a4567 --- /dev/null +++ b/ovn/ansible.cfg @@ -0,0 +1,5 @@ +[defaults] +inventory = ./.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory +private_key_file = ~/.vagrant.d/insecure_private_key +remote_user = vagrant +host_key_checking = False \ No newline at end of file diff --git a/ovn/provision.yml b/ovn/provision.yml new file mode 100644 index 0000000..521d3bd --- /dev/null +++ b/ovn/provision.yml @@ -0,0 +1,22 @@ +--- +- hosts: "all" + become: "yes" + remote_user: "vagrant" + + tasks: + - name: "Add Ubuntu Cloud Archive repository" + apt_repository: + repo: "{{ item }}" + state: "present" + with_items: + - "deb http://cloud.archive.ubuntu.com/ubuntu newton main" + + - name: "Install OVS/OVN 2.6.0" + apt: + state: "present" + update_cache: "yes" + name: "{{ item }}" + with_items: + - "openvswitch-switch" + - "openvswitch-common" + - "ovn-controller" From 21df937172e917359ca43e9c9f4bd8697d4fa56b Mon Sep 17 00:00:00 2001 From: "Scott S. Lowe" Date: Fri, 2 Dec 2016 17:52:38 -0700 Subject: [PATCH 5/5] Add final changes for working OVN learning environment Add README.md with instructions on how to use the environment. Add final changes to the Vagrantfile and Ansible provisioning script. Add Jinja2 template for final setup script. Signed-off-by: Scott S. Lowe --- ovn/README.md | 28 +++++++++++++++++++--------- ovn/Vagrantfile | 5 +++++ ovn/provision.yml | 31 +++++++++++++++++++++++++++---- ovn/setup.sh.j2 | 14 ++++++++++++++ 4 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 ovn/setup.sh.j2 diff --git a/ovn/README.md b/ovn/README.md index 7afe86d..7085313 100644 --- a/ovn/README.md +++ b/ovn/README.md @@ -1,25 +1,35 @@ -# Generic Debian 8.0 ("Jessie") VM +# Open Virtual Network (OVN) -These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) to quickly and easily spin up a generic Debian 8.0 ("Jessie") 64-bit VM. The configuration was tested using Vagrant 1.7.2, VMware Fusion 6.0.5, and the Vagrant VMware plugin. - -**NOTE:** There's really nothing special here; I created these files because I often had a need to quickly and easily spin up a generic Debian VM for some purpose (building a package or testing a command). I'm including them here just for the sake of completeness. +These files were created to allow users to use Vagrant ([http://www.vagrantup.com](http://www.vagrantup.com)) to quickly and easily spin up an environment to test Open Virtual Network (OVN), a part of the Open vSwitch project. ## Contents +* **ansible.cfg**: This is an Ansible configuration file that instructs Ansible to use the "vagrant" remote user, and to use Vagrant's built-in Ansible inventory. + +* **machines.yml**: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. + +* **provision.yml**: This Ansible playbook installs the OVS/OVN components on each Vagrant machine. It's called automatically by Vagrant. + * **README.md**: This file you're currently reading. -* **servers.yml**: This YAML file contains a list of VM definitions and associated configuration data. It is referenced by `Vagrantfile` when Vagrant instantiates the VMs. +* **setup.sh.j2**: This Jinja2 template is used by Ansible to build a customized OVS/OVN configuration script for each Vagrant machine. The shell script created by this template is placed by Ansible in `/home/vagrant/setup.sh`. * **Vagrantfile**: This file is used by Vagrant to spin up the virtual machines. This file is fairly extensively commented to help explain what's happening. You should be able to use this file unchanged; all the VM configuration options are stored outside this file. ## Instructions -These instructions assume you've already installed VMware Fusion, Vagrant, and the Vagrant VMware plugin. Please refer to the documentation for those products for more information on installation or configuration. +These instructions assume you've already installed Vagrant, your back-end virtualization provider (such as VMware Fusion or VirtualBox), and any necessary plugins (such as the Vagrant VMware plugin). Please refer to the documentation for those products for more information on installation or configuration. -1. Use `vagrant box add` to add a 64-bit Debian 8.0 ("Jessie") base box to be used by this `Vagrantfile`. You'll need to specify a box that provides support for the `vmware_desktop` provider (it should work with either VMware Workstation or VMware Fusion). +1. Use `vagrant box add` to add an Ubuntu 16.04 box to your system. The "bento/ubuntu-16.04" box is very good for both VirtualBox and VMware Fusion/Workstation. (Note that the "ubuntu/xenial64" box for VirtualBox is currently broken under Vagrant.) -2. Edit the `servers.yml` file to ensure the box you downloaded in step 1 is specified on the "box:" line of this file. +2. Edit the `machines.yml` file to ensure the box you downloaded in step 1 is specified on the "box:" sections of this file. Specify the name of a VMware-formatted box on the "vmw:" line; place the name of a VirtualBox-formatted box on the "vb:" line. -3. Run `vagrant up`, and when the VM is up use `vagrant ssh` to access the generic Debian VM. +3. Run `vagrant up` to have Vagrant instantiate the three machines configured by default in this environment, and provision them using Ansible. (Note you'll need Ansible installed locally on the system where you're running `vagrant up`.) + +4. Use `vagrant ssh ovn-01` to log into the first system. Run `sudo ./setup.sh` to perform final configuration steps for OVS/OVN. + +5. Repeat step #4 with `ovn-02` and `ovn-03`. + +You now have a three-node system running OVN. The OVN central components are running on "ovn-01". Enjoy! diff --git a/ovn/Vagrantfile b/ovn/Vagrantfile index ed0d192..3f9888a 100644 --- a/ovn/Vagrantfile +++ b/ovn/Vagrantfile @@ -66,4 +66,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end # srv.vm.provider 'virtualbox' end # config.vm.define end # machines.each + + # Configure the machines with Ansible + config.vm.provision 'ansible' do |ansible| + ansible.playbook = 'provision.yml' + end # config.vm.provision end # Vagrant.configure diff --git a/ovn/provision.yml b/ovn/provision.yml index 521d3bd..7fc476e 100644 --- a/ovn/provision.yml +++ b/ovn/provision.yml @@ -4,19 +4,42 @@ remote_user: "vagrant" tasks: + - name: "Install Ubuntu Cloud Keyring package" + apt: + state: "present" + update_cache: "yes" + name: "ubuntu-cloud-keyring" + - name: "Add Ubuntu Cloud Archive repository" apt_repository: repo: "{{ item }}" state: "present" + update_cache: "yes" with_items: - - "deb http://cloud.archive.ubuntu.com/ubuntu newton main" + - "deb http://ubuntu-cloud.archive.canonical.com/ubuntu xenial-updates/newton main" - name: "Install OVS/OVN 2.6.0" apt: state: "present" - update_cache: "yes" + update_cache: "no" name: "{{ item }}" with_items: - - "openvswitch-switch" + - "ovn-common" + - "ovn-host" - "openvswitch-common" - - "ovn-controller" + - "openvswitch-switch" + + - name: "Install central OVN components" + apt: + state: "present" + update_cache: "no" + name: "ovn-central" + when: ansible_hostname == "ovn-01" + + - name: "Install configuration script" + template: + src: "setup.sh.j2" + dest: "/home/vagrant/setup.sh" + owner: "vagrant" + group: "vagrant" + mode: "0755" diff --git a/ovn/setup.sh.j2 b/ovn/setup.sh.j2 new file mode 100644 index 0000000..6ad54ce --- /dev/null +++ b/ovn/setup.sh.j2 @@ -0,0 +1,14 @@ +#!/bin/bash + +# Stop the ovn-controller daemon +sudo /usr/share/openvswitch/scripts/ovn-ctl stop_controller + +# Configure OVS +sudo ovs-vsctl set Open_vSwitch . \ + external_ids:ovn-remote="tcp:192.168.100.101:6642" \ + external_ids:ovn-nb="tcp:192.168.100.101:6641" \ + external_ids:ovn-encap-ip={{ ansible_enp0s8.ipv4.address }} \ + external_ids:ovn-encap-type="geneve" + +# Start the ovn-controller daemon +sudo /usr/share/openvswitch/scripts/ovn-ctl start_controller