From 55401d856cc8cb0491ec188334193054f99255e4 Mon Sep 17 00:00:00 2001 From: Sushil_R Date: Thu, 29 Oct 2015 18:52:29 +0530 Subject: [PATCH] ASM-5077 Allow VDS to be created according to host versions - Allow creating VDS with specific version - Enabled search of host based on the VDS version --- lib/puppet/provider/vc_dvswitch/default.rb | 14 +++++++++++++- lib/puppet/type/vc_dvswitch.rb | 4 ++++ manifests/dvswitch.pp | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/vc_dvswitch/default.rb b/lib/puppet/provider/vc_dvswitch/default.rb index d8465612..310288c2 100644 --- a/lib/puppet/provider/vc_dvswitch/default.rb +++ b/lib/puppet/provider/vc_dvswitch/default.rb @@ -18,6 +18,10 @@ def create create_spec = RbVmomi::VIM::DVSCreateSpec.new create_spec.configSpec = RbVmomi::VIM::DVSConfigSpec.new create_spec.configSpec.name = basename + if @dvswitch.nil? && resource[:vds_version] + create_spec.productInfo = RbVmomi::VIM::DistributedVirtualSwitchProductSpec.new + create_spec.productInfo.version = resource[:vds_version] + end # find the network folder and invoke the task dc = vim.serviceInstance.find_datacenter(parent) task_create_dvs = dc.networkFolder.CreateDVS_Task(:spec => create_spec) @@ -127,10 +131,13 @@ def mo_ref_by_name opts if type == VIM::HostSystem case scope when :datacenter + product_spec = RbVmomi::VIM::DistributedVirtualSwitchProductSpec.new + product_spec.version = host_version(name) list = vim.serviceInstance.content. dvSwitchManager.QueryCompatibleHostForNewDvs( :container => datacenter, - :recursive => true + :recursive => true, + :switchProductSpec => product_spec ) raise 'No ESX hosts compatible for DVS found' if list.size == 0 else @@ -224,4 +231,9 @@ def dvswitch @dvswitch end + def host_version(host) + @host ||= vim.searchIndex.FindByIp(:datacenter => datacenter , :ip => host, :vmSearch => false) or raise(Puppet::Error, "Unable to find the host '#{host}'") + @host.summary.config.product.version + end + end diff --git a/lib/puppet/type/vc_dvswitch.rb b/lib/puppet/type/vc_dvswitch.rb index fd00bdd4..7b50e5d8 100644 --- a/lib/puppet/type/vc_dvswitch.rb +++ b/lib/puppet/type/vc_dvswitch.rb @@ -40,6 +40,10 @@ def change_to_s(is, should) end end + newparam(:vds_version) do + desc "VDS Version that needs to be enforced for newly created VDS." + end + map = PuppetX::VMware::Mapper.new_map('VMwareDVSConfigSpecMap') map.leaf_list.each do |leaf| option = {} diff --git a/manifests/dvswitch.pp b/manifests/dvswitch.pp index 6ae286e0..cd05f117 100644 --- a/manifests/dvswitch.pp +++ b/manifests/dvswitch.pp @@ -2,6 +2,7 @@ # Manage vcenter vmware distributed virtual switch define vcenter::dvswitch ( $ensure, + $vds_version = undef, $networkResourceManagementEnabled = undef, $spec = {}, # transport is a metaparameter @@ -22,6 +23,7 @@ vc_dvswitch { $name: ensure => $ensure, transport => $transport, + vds_version => $vds_version, config_version => nested_value($spec, ['configVersion']), contact_info => nested_value($spec, ['contact', 'contact']), contact_name => nested_value($spec, ['contact', 'name']),