frapposelli / vagrant-vcenter

A Vagrant provider for VMware vCenter®
MIT License
106 stars 36 forks source link

Looking for the ability to assign unique IP, VCPU & memory with multiple vm deployments #6

Closed sdorsett closed 9 years ago

sdorsett commented 9 years ago

This very well might be a Vagrantfile configuration issue, but I only seem to be able to assign an IP address, VCPU count & memory in the config.vm.provider section like the following:

      [root@vagrant vcenter-test]# cat Vagrantfile
      # -*- mode: ruby -*-
      # vi: set ft=ruby :

      # Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
      VAGRANTFILE_API_VERSION = "2"

      precise64_vm_box_url = 'http://vagrant.gosddc.com/boxes/precise64-vcenter.box'

      nodes = [
        { :hostname => 'ubuntu-64-test',
          :box => 'precise64',
          :box_url => precise64_vm_box_url }
      ]

      Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

        config.vm.provider :vcenter do |vcenter|
          vcenter.hostname = 'vcenter.tyrell.corp'
          vcenter.username = 'root@localos'
          vcenter.password = '*********'
          vcenter.folder_name = 'vagrant-templates'
          vcenter.datacenter_name = 'Datacenter-01'
          vcenter.computer_name = 'Cluster-01'
          vcenter.datastore_name = 'vsanDatastore'
          vcenter.template_folder_name = 'vagrant-templates'
          vcenter.network_name = 'vlan2-mgmt'
          # If you want to use linked clones, set this to true
          vcenter.linked_clones = true
          vcenter.enable_vm_customization = true
          vcenter.prep_type = 'linux'
          vcenter.dns_server_list = ['8.8.4.4','8.8.8.8']
          vcenter.dns_suffix_list = ['tyrell.corp']
          vcenter.gateway = '192.168.1.1'
          vcenter.netmask = '255.255.255.0'
          vcenter.ipaddress = '192.168.1.51'
          vcenter.num_cpu = '4'
          vcenter.memory = '2048'
        end

        nodes.each do |node|
          config.vm.define node[:hostname] do |node_config|
            node_config.vm.box = node[:box]
            node_config.vm.hostname = node[:hostname]
            node_config.vm.box_url = node[:box_url]
            node_config.vm.network :forwarded_port,
                                   guest: 80,
                                   host: 8080,
                                   auto_correct: true
          end
        end
      end

Is there way to configure IP address, VCPU count & memory in the node section in order to be able to apply separate values for each of these for different nodes being deployed like with the vmware_fusion provider? The vbrownbag openstack Vagrantfile has an example like the following:

      nodes.each do |prefix, (count, ip_start)|
          count.times do |i|
            hostname = "%s" % [prefix, (i+1)]
              config.vm.define "#{hostname}" do |box|
                box.vm.hostname = "#{hostname}.book"
                box.vm.network :private_network, ip: "172.16.#{third_octet}.#{ip_start+i}", :netmask => "255.255.0.0"
                box.vm.network :private_network, ip: "10.10.#{third_octet}.#{ip_start+i}", :netmask => "255.255.0.0"
                box.vm.network :private_network, ip: "192.168.#{third_octet}.#{ip_start+i}", :netmask => "255.255.255.0"

                # Run the Shell Provisioning Script file
                box.vm.provision :shell, :path => "#{prefix}.sh"

                # If using VMware Fusion
                box.vm.provider :vmware_fusion do |v|
                # Default  
                  v.vmx["memsize"] = 1024
                  if prefix == "compute"
                    v.vmx["memsize"] = 3128
                    v.vmx["numvcpus"] = 2
                  elsif prefix == "controller"
                    v.vmx["memsize"] = 2048
                  elsif prefix == "client" or prefix == "proxy"
                    v.vmx["memsize"] = 512
                  end
                end
frapposelli commented 9 years ago

needs some heavy lifting, moved to v0.4.0

frapposelli commented 9 years ago

In the meantime, as a workaround, you can use this template to achieve the same result:

nodes = [
  { hostname: 'test1', box: 'gosddc/centos65-x64' },
  { hostname: 'test2', box: 'gosddc/centos65-x64' },
  { hostname: 'test3', box: 'gosddc/centos65-x64' }
]

Vagrant.configure('2') do |config|

  # Go through nodes and configure each of them.j
  nodes.each do |node|

    config.vm.provider :vcenter do |vcenter|
      vcenter.hostname = 'vpx.ad.lab.gosddc.com'
      vcenter.username = '<username>'
      vcenter.password = '<password>'
      vcenter.folder_name = 'Vagrant'
      vcenter.datacenter_name = 'Go SDDC'
      vcenter.computer_name = 'monster.ad.lab.gosddc.com'
      vcenter.datastore_name = 'nfs_fas2020_15k_01'
      vcenter.template_folder_name = 'Templates/Vagrant'
      vcenter.network_name = 'VM Network'
      vcenter.linked_clones = true
      case node[:hostname]
      when 'test1'
        vcenter.ipaddress = '10.250.26.61'
      when 'test2'
        vcenter.ipaddress = '10.250.26.62'
      when 'test3'
        vcenter.ipaddress = '10.250.26.63'
      end
      vcenter.netmask = '255.255.0.0'
      vcenter.gateway = '10.250.254.254'
      vcenter.enable_vm_customization = true
      vcenter.prep_type = 'linux'
      vcenter.dns_server_list = ['8.8.4.4', '8.8.8.8']
      vcenter.dns_suffix_list = ['ad.lab.gosddc.com']
    end

    config.vm.define node[:hostname] do |node_config|
      node_config.vm.box = node[:box]
      node_config.vm.hostname = node[:hostname]
      node_config.nfs.functional = false
    end
  end
end
frapposelli commented 9 years ago

Workaround doesn't work, bugs need to be squashed :)