Skip to content
This repository has been archived by the owner on Aug 21, 2020. It is now read-only.

Proposed port of dell-asm#77 - Allow VDS to be created according to host versions #196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/puppet/provider/vc_dvswitch/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dvswitch.nil? seems unnecessarily redundant since this is the create method and @DVSwitch is set by the method triggered by the exists? method.

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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/puppet/type/vc_dvswitch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
2 changes: 2 additions & 0 deletions manifests/dvswitch.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Manage vcenter vmware distributed virtual switch
define vcenter::dvswitch (
$ensure,
$vds_version = undef,
$networkResourceManagementEnabled = undef,
$spec = {},
# transport is a metaparameter
Expand All @@ -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']),
Expand Down