Vagrantfile

libvirt-vagrant Vagrant example

6

Votes

# -*- mode: ruby -*-
# vi: set ft=ruby :

# NETWORKS: 10.0.10/24 - 10.0.20/24
# PXE:          10.0.10/24
# Management:   10.0.11/24
# Public:       10.0.12/24
# Storage:      10.0.13/24
# Fuel Admin:   10.0.14/24

def default(ip,forward_mode = 'nat', dhcp_enabled = false)
  [ip,forward_mode,dhcp_enabled]
end

$network_map  = { 
  pxe:        default('10.0.20','none'),
  mgmt:       default('10.0.21','none'),
  public:     default('10.0.22'),
  storage:    default('10.0.23','none'),
  admin:      default('10.0.24','nat',true)
}

Vagrant.configure("2") do |config|
  config.hostmanager.enabled = false

  config.vm.synced_folder ".", "/vagrant", type: 'rsync'

  # config.vm.box = "ubuntu/trusty64"
  config.ssh.username = 'root'

  # Update puppet
  config.vm.provision "shell", inline: <<-SHELL
    if [ ! -f /usr/sbin/puppet ]; then 
      cd /tmp
      wget http://apt.puppetlabs.com/puppetlabs-release-pc1-trusty.deb
      dpkg -i /tmp/puppetlabs-release-pc1-trusty.deb
      apt-get update
      apt-get install -y puppet-agent
      ln -fs /opt/puppetlabs/bin/puppet /usr/sbin/puppet
    fi
  SHELL

  config.vm.provider :libvirt do |libvirt|
    libvirt.driver          = 'kvm'

    libvirt.host            = "desktop.mirantis"
    libvirt.username        = 'paulche'
    libvirt.id_ssh_key_file = 'mirantis.insecure'

    libvirt.connect_via_ssh = true
    libvirt.nested          = true
    libvirt.memory          = 4096
    libvirt.cpus            = 2

    libvirt.graphics_ip     = '172.18.xx.xx'
  end

  config.vm.define :fuel do |vm|
    vm.vm.provider :libvirt do |domain|
      domain.storage :file, :size => '100G', :type => 'qcow2'
      domain.storage :file, :device => :cdrom, :path => '/home/paulche/iso/MirantisOpenStack-7.0-RC4.iso'
      domain.boot 'hd'
      domain.boot 'cdrom'
    end

    network(vm,:pxe)
    network(vm,:admin)
  end

  # Controller node
  #
  0.upto(2).each do |num|
    config.vm.define "controller#{num}".to_sym do |vm|
      vm.vm.provider :libvirt do |domain|
        domain.storage :file, :size => '100G', :type => 'qcow2'
        domain.boot 'hd'
        domain.boot 'network'
      end

      network(vm,:pxe)
      network(vm,:mgmt)
      network(vm,:storage)
      network(vm,:public)
    end
  end

  config.vm.define :storage do |vm|
    vm.vm.provider :libvirt do |domain|
      domain.storage :file, :size => '50G', :type => 'qcow2'
      domain.boot 'hd'
      domain.boot 'network'

      domain.memory = 1024
      domain.cpus = 1
    end

    network(vm,:pxe)
    network(vm,:mgmt)
    network(vm,:storage)
  end

  #compute
  0.upto(1).each do |num|
    config.vm.define "compute#{num}".to_sym do |vm|
      vm.vm.provider :libvirt do |domain|
        domain.storage :file, :size => '30G', :type => 'qcow2'
        domain.boot 'hd'
        domain.boot 'network'

        domain.memory = 2048
        domain.cpus = 4
      end

      network(vm,:pxe)
      network(vm,:mgmt)
      network(vm,:storage)
    end
  end

end


def network(vm,name)
  config = $network_map[name]

  raise "Unknown network name! You have to define network in advance!" unless config

  ip              = "#{config[0]}.2"
  forward_mode    = config[1]
  dhcp_enabled    = config[2]

  vm.vm.network :private_network,           
    ip: ip,
    libvirt__network_name: "fuel7-#{name}",
    libvirt__forward_mode: forward_mode,
    libvirt__dhcp_enabled: dhcp_enabled

end

def default(ip,forward_mode = 'nat', dhcp_enabled = false)
  [ip,forward_mode,dhcp_enabled]
end

Vote Here

You must earn at least 1 vote on your snippets to be allowed to vote

Terms Of Use

Privacy Policy

Featured snippets are MIT license

Gears & Masters

Advertise

DevOpsnipp.com © 2020

medium.png