| # Licensed to the Apache Software Foundation (ASF) under one or more |
| # contributor license agreements. See the NOTICE file distributed with |
| # this work for additional information regarding copyright ownership. |
| # The ASF licenses this file to You under the Apache License, Version 2.0 |
| # (the "License"); you may not use this file except in compliance with |
| # the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| require 'yaml' |
| |
| # Because of linked_clone. 1.9+ recommended for Ubuntu Xenial |
| Vagrant.require_version ">= 1.8" |
| |
| module CustomProviders |
| @@providers = [] |
| def register(&fn) |
| @@providers << fn |
| end |
| def configure(config, machine_config) |
| @@providers.each do |provider| |
| provider.call(config, machine_config) |
| end |
| end |
| |
| module_function :register |
| module_function :configure |
| end |
| |
| |
| Dir[Dir.home() + '/.jclouds/vagrant/providers/*.rb'].each do |file| |
| require File.dirname(file) + "/" + File.basename(file, '.rb') |
| end |
| |
| Vagrant.configure(2) do |config| |
| Dir.glob('machines/*.yaml') do |machine_file| |
| machine_config = YAML.load_file(machine_file) |
| name = File.basename(machine_file, ".yaml") |
| config.vm.define name do |config| |
| config.vm.box = machine_config["box"] |
| config.vm.box_check_update = false |
| config.vm.network "private_network", type: "dhcp" |
| config.vm.synced_folder '.', '/vagrant', disabled: true |
| config.ssh.username = machine_config["username"] if machine_config.key?("username") |
| config.ssh.password = machine_config["password"] if machine_config.key?("password") |
| config.ssh.private_key_path = machine_config["private_key_path"] if machine_config.key?("private_key_path") |
| |
| isWindows = (machine_config["osFamily"] == "windows"); |
| if isWindows |
| # That's a Powershell script. |
| # Go through a temporary file, otherwise getting the following error: |
| |
| # out-lineoutput : The OS handle's position is not what FileStream expected. Do n |
| # ot use a handle simultaneously in one FileStream and in Win32 code or another F |
| # ileStream. This may cause data loss. |
| # + CategoryInfo : NotSpecified: (:) [out-lineoutput], IOException |
| # + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Comma |
| # nds.OutLineOutputCommand |
| |
| config.vm.provision "shell", inline: <<-EOF |
| $tmp = [System.IO.Path]::GetTempFileName() |
| echo "================= Networks start =================" > $tmp |
| ipconfig | find "IPv4 Address" >> $tmp 2>&1 |
| echo "================= Networks end ===================" >> $tmp |
| echo "================= Hostname start ==========================" >> $tmp |
| hostname >> $tmp 2>&1 |
| echo "================= Hostname end ============================" >> $tmp |
| type $tmp |
| EOF |
| else |
| config.vm.provision "shell", inline: <<-EOF |
| echo "================= Networks start =================" |
| ip address show | grep 'scope global' 2>&1 |
| echo "================= Networks end ===================" |
| echo "================= Hostname start ==========================" |
| hostname 2>&1 |
| echo "================= Hostname end ============================" |
| EOF |
| end |
| |
| config.vm.provider "virtualbox" do |v| |
| v.gui = false |
| v.memory = machine_config["memory"] if machine_config.key?("memory") |
| v.cpus = machine_config["cpus"] if machine_config.key?("cpus") |
| v.linked_clone = true |
| # Windows needs additional drivers for virtio and the default one is dreadfully slow on linux |
| if !isWindows |
| v.customize ["modifyvm", :id, "--nictype1", "virtio"] |
| v.customize ["modifyvm", :id, "--nictype2", "virtio"] |
| end |
| end |
| config.vm.provider "libvirt" do |v| |
| v.memory = machine_config["memory"] if machine_config.key?("memory") |
| v.cpus = machine_config["cpus"] if machine_config.key?("cpus") |
| end |
| |
| CustomProviders.configure(config, machine_config) |
| end |
| end |
| end |