Skip to content
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
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Changelog

All notable changes to this project will be documented in this file.

## Development

- Added new function `powercli::hosts_status` to retrieve the current connection status
for ESXi hosts in vCenter.

Contributed by Nick Maludy (@nmaludy)

## v0.1.2 (2020-11-13)

- Simplified dvs_add_hosts resource. It will no longer take into consideration defaults and other complexities. These complexities are to be handed within the puppet profile which calls this resource.

Contributed by Greg Perry (@gperry2011)

## Development

- Converted from Travis to GitHub Actions

Contributed by Nick Maludy (@nmaludy)
Expand Down
41 changes: 41 additions & 0 deletions lib/puppet/functions/powercli/hosts_status.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'rbvmomi'

# Returns a hash of hosts along with their connection status
# Note: this uses PowerCLI under the hood, so it should be run as a deferred function
Puppet::Functions.create_function(:'powercli::hosts_status') do
# @param hosts Explicit list of hosts to retrieve status for.
# If not specified all hosts that exist in the vCenter will be returned
# @return Hash where the key is the ESXi hostname, the value is the connection status for
# that host, either 'online' or 'offline'.
# Hosts that have a connection status of 'Disconnected' or 'NotResponding' will be
# marked as 'offline', otherwise they will be returned as 'online'.
dispatch :hosts_status do
required_param 'Powercli::Connection', :connection
optional_param 'Array[String]', :hosts
return_type "Hash[String, Enum['online', 'offline']]"
end

def hosts_status(connection, hosts = nil)
credentials = {
host: connection['server'],
user: connection['username'],
password: connection['password'],
insecure: true
}
vim = RbVmomi::VIM.connect(credentials)

# recursive find/grep to find all ESX hosts
# Type list: https://code.vmware.com/apis/196/vsphere
query = {
container: vim.rootFolder,
type: ['HostSystem'],
recursive: true
}
host_list = vim.serviceContent.viewManager.CreateContainerView(query).view
results = {}
host_list.map do |host|
results[host.name] = host.runtime.connectionState
end
results
end
end
1 change: 0 additions & 1 deletion lib/puppet/provider/powercli_esx_ntp/powercli.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'powercli'))
require 'ruby-pwsh'

Puppet::Type.type(:powercli_esx_ntp).provide(:api, parent: Puppet::Provider::PowerCLI) do
commands powershell: 'powershell.exe'
Expand Down
1 change: 0 additions & 1 deletion lib/puppet/provider/powercli_esx_syslog/powercli.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'powercli'))
require 'ruby-pwsh'
require 'uri'

Puppet::Type.type(:powercli_esx_syslog).provide(:api, parent: Puppet::Provider::PowerCLI) do
Expand Down
1 change: 0 additions & 1 deletion lib/puppet/provider/powercli_esx_vs_portgroup/powercli.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'powercli'))
require 'ruby-pwsh'

Puppet::Type.type(:powercli_esx_vs_portgroup).provide(:api, parent: Puppet::Provider::PowerCLI) do
commands powershell: 'powershell.exe'
Expand Down
1 change: 1 addition & 0 deletions lib/puppet_x/encore/powercli/helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'puppet_x'
require 'ruby-pwsh'
require 'singleton'

module PuppetX::PowerCLI
Expand Down
1 change: 0 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
Optional[Powercli::Connection] $vcenter_connection = undef,
Optional[Hash] $config = $powercli::params::config,
) inherits powercli::params {

pspackageprovider { 'Nuget':
ensure => 'present',
}
Expand Down