vagrant-guests-photon 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/vagrant-guests-photon/cap/configure_networks.rb +54 -15
- data/lib/vagrant-guests-photon/version.rb +1 -1
- data/spec/cap/configure_networks_spec.rb +164 -16
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 78a2f47f2f4da91108b4e1a202da0f3006f6f08b
         | 
| 4 | 
            +
              data.tar.gz: 0085fd4d34bdda428f9129adc791b2af45dee6a6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d628f32f1edb4319b9246090a1e1c7590b6188a1faab21bf83e9327779846424dfdabfcbea4c2e743ae6b0e91bbe56b0c8e69469e6c4d6ec5aa942d2b617e82f
         | 
| 7 | 
            +
              data.tar.gz: 721336c56c357163a9ca5b7a05af9d31def65f32057561f2ec5ca127e1fe780c3fbebea760d7adcb89193f68658d99a21ecfc2926ff1ea39ca2570b1b4db2dd5
         | 
    
        data/README.md
    CHANGED
    
    | @@ -14,11 +14,11 @@ To build and install the plugin directly from this repo: | |
| 14 14 |  | 
| 15 15 | 
             
            ```
         | 
| 16 16 | 
             
            $ rake build
         | 
| 17 | 
            -
            $ vagrant plugin install pkg/vagrant-guests-photon-1.0. | 
| 17 | 
            +
            $ vagrant plugin install pkg/vagrant-guests-photon-1.0.1.gem
         | 
| 18 18 | 
             
            ```
         | 
| 19 19 |  | 
| 20 20 | 
             
            You can run RSpec with:
         | 
| 21 21 |  | 
| 22 22 | 
             
            ```
         | 
| 23 23 | 
             
            $ rake
         | 
| 24 | 
            -
            ```
         | 
| 24 | 
            +
            ```
         | 
| @@ -2,41 +2,80 @@ | |
| 2 2 | 
             
            # Copyright (c) 2015 VMware, Inc. All Rights Reserved.
         | 
| 3 3 |  | 
| 4 4 | 
             
            require 'tempfile'
         | 
| 5 | 
            -
            require ' | 
| 5 | 
            +
            require 'ipaddr'
         | 
| 6 | 
            +
            require 'log4r'
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            # Borrowed from http://stackoverflow.com/questions/1825928/netmask-to-cidr-in-ruby
         | 
| 9 | 
            +
            IPAddr.class_eval do
         | 
| 10 | 
            +
              def to_cidr
         | 
| 11 | 
            +
                self.to_i.to_s(2).count("1")
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            STATIC_NETWORK = <<EOF
         | 
| 16 | 
            +
            [Match]
         | 
| 17 | 
            +
            Name=%s
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            [Network]
         | 
| 20 | 
            +
            Address=%s
         | 
| 21 | 
            +
            EOF
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            DHCP_NETWORK = <<EOF
         | 
| 24 | 
            +
            [Match]
         | 
| 25 | 
            +
            Name=%s
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            [Network]
         | 
| 28 | 
            +
            DHCP=yes
         | 
| 29 | 
            +
            EOF
         | 
| 6 30 |  | 
| 7 31 | 
             
            module VagrantPlugins
         | 
| 8 32 | 
             
              module GuestPhoton
         | 
| 9 33 | 
             
                module Cap
         | 
| 10 34 | 
             
                  class ConfigureNetworks
         | 
| 11 | 
            -
                     | 
| 35 | 
            +
                    @@logger = Log4r::Logger.new("vagrant::guest::photon::configure_networks")
         | 
| 12 36 |  | 
| 13 37 | 
             
                    def self.configure_networks(machine, networks)
         | 
| 14 38 | 
             
                      machine.communicate.tap do |comm|
         | 
| 39 | 
            +
                        comm.sudo("rm -f /etc/systemd/network/50-vagrant-*.network")
         | 
| 40 | 
            +
             | 
| 15 41 | 
             
                        # Read network interface names
         | 
| 16 42 | 
             
                        interfaces = []
         | 
| 17 | 
            -
                        comm.sudo("ifconfig | grep 'eth' | cut -f1 -d' '") do |_, result|
         | 
| 43 | 
            +
                        comm.sudo("ifconfig -a | grep '^eth' | cut -f1 -d' '") do |_, result|
         | 
| 18 44 | 
             
                          interfaces = result.split("\n")
         | 
| 19 45 | 
             
                        end
         | 
| 20 46 |  | 
| 21 47 | 
             
                        # Configure interfaces
         | 
| 22 48 | 
             
                        networks.each do |network|
         | 
| 23 | 
            -
                           | 
| 24 | 
            -
             | 
| 49 | 
            +
                          interface = network[:interface].to_i
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                          iface = interfaces[interface]
         | 
| 52 | 
            +
                          if iface.nil?
         | 
| 53 | 
            +
                            @@logger.warn("Could not find match rule for network #{network.inspect}")
         | 
| 54 | 
            +
                            next
         | 
| 55 | 
            +
                          end
         | 
| 25 56 |  | 
| 26 | 
            -
             | 
| 27 | 
            -
                        primary_machine = machine.env.machine(*primary_machine_config, true)
         | 
| 57 | 
            +
                          unit_name = "50-vagrant-%s.network" % [iface]
         | 
| 28 58 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
                             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
                            end
         | 
| 59 | 
            +
                          if network[:type] == :static
         | 
| 60 | 
            +
                            cidr = IPAddr.new(network[:netmask]).to_cidr
         | 
| 61 | 
            +
                            address = "%s/%s" % [network[:ip], cidr]
         | 
| 62 | 
            +
                            unit_file = STATIC_NETWORK % [iface, address]
         | 
| 63 | 
            +
                          elsif network[:type] == :dhcp
         | 
| 64 | 
            +
                            unit_file = DHCP_NETWORK % [iface]
         | 
| 36 65 | 
             
                          end
         | 
| 37 66 |  | 
| 38 | 
            -
                           | 
| 67 | 
            +
                          temp = Tempfile.new("vagrant")
         | 
| 68 | 
            +
                          temp.binmode
         | 
| 69 | 
            +
                          temp.write(unit_file)
         | 
| 70 | 
            +
                          temp.close
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                          comm.upload(temp.path, "/tmp/#{unit_name}")
         | 
| 73 | 
            +
                          comm.sudo("mv /tmp/#{unit_name} /etc/systemd/network/")
         | 
| 74 | 
            +
                          comm.sudo("chown root:root /etc/systemd/network/#{unit_name}")
         | 
| 75 | 
            +
                          comm.sudo("chmod +r /etc/systemd/network/#{unit_name}")
         | 
| 39 76 | 
             
                        end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                        comm.sudo("systemctl restart systemd-networkd.service")
         | 
| 40 79 | 
             
                      end
         | 
| 41 80 | 
             
                    end
         | 
| 42 81 | 
             
                  end
         | 
| @@ -7,23 +7,171 @@ require 'spec_helper' | |
| 7 7 | 
             
            describe VagrantPlugins::GuestPhoton::Cap::ConfigureNetworks do
         | 
| 8 8 | 
             
              include_context 'machine'
         | 
| 9 9 |  | 
| 10 | 
            -
               | 
| 10 | 
            +
              context 'configure 4 kinds of networks' do
         | 
| 11 11 | 
             
                networks = [
         | 
| 12 | 
            -
                   | 
| 13 | 
            -
                  { | 
| 14 | 
            -
             | 
| 12 | 
            +
                  # config.vm.network :private_network, ip: "192.168.33.10"
         | 
| 13 | 
            +
                  {
         | 
| 14 | 
            +
                    :type => :static,
         | 
| 15 | 
            +
                    :adapter_ip => '192.168.10.1',
         | 
| 16 | 
            +
                    :ip => '192.168.10.10',
         | 
| 17 | 
            +
                    :netmask => '255.255.255.0',
         | 
| 18 | 
            +
                    :auto_config => true,
         | 
| 19 | 
            +
                    :interface => 1
         | 
| 20 | 
            +
                  },
         | 
| 21 | 
            +
                  # config.vm.network :private_network, type: "dhcp"
         | 
| 22 | 
            +
                  {
         | 
| 23 | 
            +
                    :type => :dhcp,
         | 
| 24 | 
            +
                    :adapter_ip => "172.28.128.1",
         | 
| 25 | 
            +
                    :ip => "172.28.128.1",
         | 
| 26 | 
            +
                    :netmask => "255.255.255.0",
         | 
| 27 | 
            +
                    :auto_config => true,
         | 
| 28 | 
            +
                    :interface => 2
         | 
| 29 | 
            +
                  },
         | 
| 30 | 
            +
                  # config.vm.network :public_network, bridge: "en0: Wi-Fi (AirPort)"
         | 
| 31 | 
            +
                  {
         | 
| 32 | 
            +
                    :type => :dhcp,
         | 
| 33 | 
            +
                    :use_dhcp_assigned_default_route => false,
         | 
| 34 | 
            +
                    :auto_config => true,
         | 
| 35 | 
            +
                    :interface => 3
         | 
| 36 | 
            +
                  },
         | 
| 37 | 
            +
                  # config.vm.network :public_network, bridge: "en0: Wi-Fi (AirPort)", ip: "192.168.1.201"
         | 
| 38 | 
            +
                  {
         | 
| 39 | 
            +
                    :type=>:static,
         | 
| 40 | 
            +
                    :bridge => "en0: Wi-Fi (AirPort)",
         | 
| 41 | 
            +
                    :ip => "192.168.1.201",
         | 
| 42 | 
            +
                    :netmask => "255.255.255.0",
         | 
| 43 | 
            +
                    :use_dhcp_assigned_default_route => false,
         | 
| 44 | 
            +
                    :auto_config => true,
         | 
| 45 | 
            +
                    :interface => 4
         | 
| 46 | 
            +
                  }
         | 
| 15 47 | 
             
                ]
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                 | 
| 18 | 
            -
             | 
| 19 | 
            -
                 | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
                 | 
| 23 | 
            -
             | 
| 24 | 
            -
                 | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 48 | 
            +
             | 
| 49 | 
            +
                interfaces = "eth0\neth1\neth2\neth3\neth4\n"
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                before do
         | 
| 52 | 
            +
                  communicate.stub(:sudo).with("ifconfig -a | grep '^eth' | cut -f1 -d' '")
         | 
| 53 | 
            +
                    .and_yield(nil, interfaces)
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                it 'should configure networks' do
         | 
| 57 | 
            +
                  communicate.should_receive(:sudo).with("rm -f /etc/systemd/network/50-vagrant-*.network")
         | 
| 58 | 
            +
                  communicate.should_receive(:sudo).with("ifconfig -a | grep '^eth' | cut -f1 -d' '")
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  # eth1
         | 
| 61 | 
            +
                  communicate.should_receive(:upload) do |src, dst|
         | 
| 62 | 
            +
                    contents = (File.readlines src).join("")
         | 
| 63 | 
            +
                    contents.should eq "[Match]\nName=eth1\n\n[Network]\nAddress=192.168.10.10/24\n"
         | 
| 64 | 
            +
                    dst.should eq "/tmp/50-vagrant-eth1.network"
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 67 | 
            +
                    .with("mv /tmp/50-vagrant-eth1.network /etc/systemd/network/")
         | 
| 68 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 69 | 
            +
                    .with("chown root:root /etc/systemd/network/50-vagrant-eth1.network")
         | 
| 70 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 71 | 
            +
                    .with("chmod +r /etc/systemd/network/50-vagrant-eth1.network")
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  # eth2
         | 
| 74 | 
            +
                  communicate.should_receive(:upload) do |src, dst|
         | 
| 75 | 
            +
                    contents = (File.readlines src).join("")
         | 
| 76 | 
            +
                    contents.should eq "[Match]\nName=eth2\n\n[Network]\nDHCP=yes\n"
         | 
| 77 | 
            +
                    dst.should eq "/tmp/50-vagrant-eth2.network"
         | 
| 78 | 
            +
                  end
         | 
| 79 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 80 | 
            +
                    .with("mv /tmp/50-vagrant-eth2.network /etc/systemd/network/")
         | 
| 81 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 82 | 
            +
                    .with("chown root:root /etc/systemd/network/50-vagrant-eth2.network")
         | 
| 83 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 84 | 
            +
                    .with("chmod +r /etc/systemd/network/50-vagrant-eth2.network")
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  # eth3
         | 
| 87 | 
            +
                  communicate.should_receive(:upload) do |src, dst|
         | 
| 88 | 
            +
                    contents = (File.readlines src).join("")
         | 
| 89 | 
            +
                    contents.should eq "[Match]\nName=eth3\n\n[Network]\nDHCP=yes\n"
         | 
| 90 | 
            +
                    dst.should eq "/tmp/50-vagrant-eth3.network"
         | 
| 91 | 
            +
                  end
         | 
| 92 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 93 | 
            +
                    .with("mv /tmp/50-vagrant-eth3.network /etc/systemd/network/")
         | 
| 94 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 95 | 
            +
                    .with("chown root:root /etc/systemd/network/50-vagrant-eth3.network")
         | 
| 96 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 97 | 
            +
                    .with("chmod +r /etc/systemd/network/50-vagrant-eth3.network")
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                  # eth4
         | 
| 100 | 
            +
                  communicate.should_receive(:upload) do |src, dst|
         | 
| 101 | 
            +
                    contents = (File.readlines src).join("")
         | 
| 102 | 
            +
                    contents.should eq "[Match]\nName=eth4\n\n[Network]\nAddress=192.168.1.201/24\n"
         | 
| 103 | 
            +
                    dst.should eq "/tmp/50-vagrant-eth4.network"
         | 
| 104 | 
            +
                  end
         | 
| 105 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 106 | 
            +
                    .with("mv /tmp/50-vagrant-eth4.network /etc/systemd/network/")
         | 
| 107 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 108 | 
            +
                    .with("chown root:root /etc/systemd/network/50-vagrant-eth4.network")
         | 
| 109 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 110 | 
            +
                    .with("chmod +r /etc/systemd/network/50-vagrant-eth4.network")
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                  communicate.should_receive(:sudo).with("systemctl restart systemd-networkd.service")
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                  described_class.configure_networks(machine, networks)
         | 
| 115 | 
            +
                end
         | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
             | 
| 118 | 
            +
              context 'configure 2 kinds of networks without eth2' do
         | 
| 119 | 
            +
                networks = [
         | 
| 120 | 
            +
                  # config.vm.network :private_network, ip: "192.168.33.10"
         | 
| 121 | 
            +
                  {
         | 
| 122 | 
            +
                    :type => :static,
         | 
| 123 | 
            +
                    :adapter_ip => '192.168.10.1',
         | 
| 124 | 
            +
                    :ip => '192.168.10.10',
         | 
| 125 | 
            +
                    :netmask => '255.255.255.0',
         | 
| 126 | 
            +
                    :auto_config => true,
         | 
| 127 | 
            +
                    :interface => 1
         | 
| 128 | 
            +
                  },
         | 
| 129 | 
            +
                  # config.vm.network :private_network, type: "dhcp"
         | 
| 130 | 
            +
                  {
         | 
| 131 | 
            +
                    :type => :dhcp,
         | 
| 132 | 
            +
                    :adapter_ip => "172.28.128.1",
         | 
| 133 | 
            +
                    :ip => "172.28.128.1",
         | 
| 134 | 
            +
                    :netmask => "255.255.255.0",
         | 
| 135 | 
            +
                    :auto_config => true,
         | 
| 136 | 
            +
                    :interface => 2
         | 
| 137 | 
            +
                  }
         | 
| 138 | 
            +
                ]
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                interfaces = "eth0\neth1\n"
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                before do
         | 
| 143 | 
            +
                  communicate.stub(:sudo).with("ifconfig -a | grep '^eth' | cut -f1 -d' '")
         | 
| 144 | 
            +
                    .and_yield(nil, interfaces)
         | 
| 145 | 
            +
                  @@logger = Log4r::Logger.new("vagrant::guest::photon::configure_networks") 
         | 
| 146 | 
            +
                end
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                it 'should configure networks without eth2' do
         | 
| 149 | 
            +
                  communicate.should_receive(:sudo).with("rm -f /etc/systemd/network/50-vagrant-*.network")
         | 
| 150 | 
            +
                  communicate.should_receive(:sudo).with("ifconfig -a | grep '^eth' | cut -f1 -d' '")
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                  # eth1
         | 
| 153 | 
            +
                  communicate.should_receive(:upload) do |src, dst|
         | 
| 154 | 
            +
                    contents = (File.readlines src).join("")
         | 
| 155 | 
            +
                    contents.should eq "[Match]\nName=eth1\n\n[Network]\nAddress=192.168.10.10/24\n"
         | 
| 156 | 
            +
                    dst.should eq "/tmp/50-vagrant-eth1.network"
         | 
| 157 | 
            +
                  end
         | 
| 158 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 159 | 
            +
                    .with("mv /tmp/50-vagrant-eth1.network /etc/systemd/network/")
         | 
| 160 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 161 | 
            +
                    .with("chown root:root /etc/systemd/network/50-vagrant-eth1.network")
         | 
| 162 | 
            +
                  communicate.should_receive(:sudo)
         | 
| 163 | 
            +
                    .with("chmod +r /etc/systemd/network/50-vagrant-eth1.network")
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                  # eth2
         | 
| 166 | 
            +
                  @@logger.should_receive(:warn).with(
         | 
| 167 | 
            +
                    "Could not find match rule for network " +
         | 
| 168 | 
            +
                    "{:type=>:dhcp, :adapter_ip=>\"172.28.128.1\", :ip=>\"172.28.128.1\", " +
         | 
| 169 | 
            +
                    ":netmask=>\"255.255.255.0\", :auto_config=>true, :interface=>2}"
         | 
| 170 | 
            +
                  )
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                  communicate.should_receive(:sudo).with("systemctl restart systemd-networkd.service")
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                  described_class.configure_networks(machine, networks)
         | 
| 175 | 
            +
                end
         | 
| 28 176 | 
             
              end
         | 
| 29 177 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: vagrant-guests-photon
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0. | 
| 4 | 
            +
              version: 1.0.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Fabio Rapposelli
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-05-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         |