Skip to content

Commit

Permalink
allow esx resources to work without vcenter
Browse files Browse the repository at this point in the history
Many esx resources searched for the esx host to configure under a
specific datacenter. This prevents the esx host itself from being used
as the transport because the host does not exist in a datacenter.

This patch falls back to searching for the host by ip or dns name
alone if no path is specified for the host.
  • Loading branch information
gavin-scott committed May 20, 2014
1 parent 5037c41 commit de585f8
Show file tree
Hide file tree
Showing 24 changed files with 61 additions and 246 deletions.
5 changes: 0 additions & 5 deletions lib/puppet/provider/esx_advanced_options/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,5 @@ def cast_option(key, value)
end
end

def host
@host ||= vim.searchIndex.FindByDnsName(:dnsName => resource[:host], :vmSearch => false) ||
fail("host #{resource[:host]} not found")
end

end

21 changes: 0 additions & 21 deletions lib/puppet/provider/esx_datastore/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,6 @@ def exists?

private

def host
if resource[:path]
@host ||= vim.searchIndex.FindByDnsName(:datacenter => walk_dc, :dnsName => resource[:host], :vmSearch => false)
else
@host ||= vim.searchIndex.FindByDnsName(:dnsName => resource[:host], :vmSearch => false)
end

if @host
return @host
else
fail "An invalid host name or IP address is entered. Enter the correct host name and IP address."
end
end

def scsi_lun(uuid)
adapters = host.configManager.storageSystem.storageDeviceInfo.scsiTopology.adapter
result = adapters.collect{|a| a.target.collect{|t| t.lun}}.flatten.find{|lun| lun.key =~ /#{uuid}/}
Expand Down Expand Up @@ -184,11 +170,4 @@ def scsi_target_iqn(uuid)
iscsi_name unless iscsi_name.nil?
end

# To support the multiple datacenter in same vCenter.
def walk_dc(path=resource[:path])
datacenter = walk(path, RbVmomi::VIM::Datacenter)
raise Puppet::Error.new( "Unable to find datacenter path: #{path}") unless datacenter
datacenter
end

end
4 changes: 0 additions & 4 deletions lib/puppet/provider/esx_dnsconfig/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,4 @@ def hostDnsConfig
@host_dns ||= {}.merge(host.config.network.dnsConfig.props)
end

def host
@host ||= vim.searchIndex.FindByDnsName(:dnsName => resource[:host], :vmSearch => false)
end

end
12 changes: 0 additions & 12 deletions lib/puppet/provider/esx_fc_multiple_path_config/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,5 @@ def exists?
def destroy
end

private

def host
@host ||= vim.searchIndex.FindByDnsName(:datacenter => walk_dc, :dnsName => resource[:host], :vmSearch => false)
end

#traverse dc
def walk_dc(path=resource[:path])
datacenter = walk(path, RbVmomi::VIM::Datacenter)
raise Puppet::Error.new( "No datacenter in path: #{path}") unless datacenter
datacenter
end
end

17 changes: 0 additions & 17 deletions lib/puppet/provider/esx_fcoe/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,4 @@ def hba
return nil
end

#find host given the host IP or name
def host
@host ||= vim.searchIndex.FindByDnsName(:datacenter => walk_dc, :dnsName => resource[:host], :vmSearch => false)
if @host
return @host
else
fail "An invalid host name or IP address is entered. Enter the correct host name and IP address."
end
end

#traverse datacenter
def walk_dc(path=resource[:path])
datacenter = walk(path, RbVmomi::VIM::Datacenter)
raise Puppet::Error.new( "No datacenter in path: #{path}") unless datacenter
datacenter
end

end
3 changes: 1 addition & 2 deletions lib/puppet/provider/esx_iscsi/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def exists?
private

def esxhost
@esxhost ||= vim.searchIndex.FindByDnsName(:dnsName => @resource[:esx_host],
:vmSearch => false)
host(@resource[:esx_host])
end

end
3 changes: 1 addition & 2 deletions lib/puppet/provider/esx_iscsi_hba_name/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def iscsi_name=(value)

private
def esxhost
@esxhost ||= vim.searchIndex.FindByDnsName(:dnsName => @resource[:esx_host],
:vmSearch => false)
host(@resource[:esx_host])
end

def hba
Expand Down
12 changes: 0 additions & 12 deletions lib/puppet/provider/esx_iscsi_multiple_path_config/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,4 @@ def exists?
return false
end

private

def host
@host ||= vim.searchIndex.FindByDnsName(:datacenter => walk_dc, :dnsName => resource[:host], :vmSearch => false)
end

#traverse dc
def walk_dc(path=resource[:path])
datacenter = walk(path, RbVmomi::VIM::Datacenter)
raise Puppet::Error.new("No datacenter in path: #{path}") unless datacenter
datacenter
end
end
3 changes: 1 addition & 2 deletions lib/puppet/provider/esx_iscsi_targets/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def config_should
end

def esxhost
@esxhost ||= vim.searchIndex.FindByDnsName(:dnsName => @resource[:esx_host],
:vmSearch => false)
host(@resource[:esx_host])
end

def hba
Expand Down
9 changes: 0 additions & 9 deletions lib/puppet/provider/esx_maintmode/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,4 @@ def exists?
end
end

private

def host
begin
@host ||= vim.searchIndex.FindByDnsName(:dnsName => resource[:host], :vmSearch => false)
rescue Exception => e
fail "Could not find Host system.Either Host is not exist or disconnected: #{e.message}"
end
end
end
14 changes: 3 additions & 11 deletions lib/puppet/provider/esx_mem/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ def get_iscsi_chapsecret
# Turn TSM-SSH on if it is off
def toggle_ssh
if !ssh_state
host.configManager.serviceSystem.StartService(:id=>'TSM-SSH')
host(resource[:name]).configManager.serviceSystem.StartService(:id=>'TSM-SSH')
end
end

# Let's turn TSM-SSH off it we had to turn it on
def reset_ssh
if !ssh_state
host.configManager.serviceSystem.StopService(:id=>'TSM-SSH')
host(resource[:name]).configManager.serviceSystem.StopService(:id=>'TSM-SSH')
end
end

Expand All @@ -278,16 +278,8 @@ def ssh_state

def ssh_svc
@ssh_svc ||=
host.config.service.service.find{|x| x.key == "TSM-SSH"} ||
host(resource[:name]).config.service.service.find{|x| x.key == "TSM-SSH"} ||
fail("service TSM-SSH not found")
end


def host
if resource[:name] =~ Resolv::IPv4::Regex
@host ||= vim.searchIndex.FindByIp(:ip => resource[:name], :vmSearch => false)
else
@host ||= vim.searchIndex.FindByDnsName(:dnsName => resource[:name],:vmSearch => false)
end
end
end
5 changes: 0 additions & 5 deletions lib/puppet/provider/esx_ntpconfig/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,5 @@ def server=(value)
host.configManager.dateTimeSystem.UpdateDateTimeConfig(:config => dtconfig)
end

private

def host
@host ||= vim.searchIndex.FindByDnsName(:dnsName => resource[:host], :vmSearch => false)
end
end

Loading

0 comments on commit de585f8

Please sign in to comment.