Last active
August 29, 2015 14:06
-
-
Save b4ldr/d2d56e2cf6cb7b17e184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node /^[a-z]{3}\d{,2}\.example\.org$/ inherits default { | |
@@nexpose_host { | |
$::fqdn: | |
ensure => present, | |
siteid => 1, | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nexpose' | |
include Nexpose | |
Puppet::Type.type(:nexpose_host).provide(:nexpose) do | |
defaultfor :kernel => 'Linux' | |
mk_resource_methods | |
def initialize(value={}) | |
super(value) | |
@property_flush = {} | |
end | |
def self.prefetch(resources) | |
instances.each do |prov| | |
if resource = resources[prov.name] | |
resource.provider = prov | |
end | |
end | |
end | |
def self.instances | |
nsc = Connection.new('127.0.0.1', 'nxadmin', 'nxpassword', 443) | |
nsc.login | |
nsc.devices.collect do |device| | |
result = { :ensure => :present } | |
result[:name] = device.address | |
result[:siteid] = device.id | |
new(result) | |
end | |
nsc.logout | |
end | |
def siteid=(value) | |
@property_flush[:siteid] = value | |
end | |
def flush | |
nsc = Connection.new('127.0.0.1', 'nxadmin', 'nxpassword', 443) | |
nsc.login | |
@siteid = @property_flush.key?(:siteid)? @property_flush[:siteid] : @resource[:siteid] | |
if @property_flush[:ensure] == :absent | |
site = Site.load(nsc, @siteid) | |
site.add_host(@resource[:name]) | |
site.save | |
else | |
Puppet.debug('not implmented') | |
end | |
nsc.logout | |
end | |
def create | |
@property_flush[:ensure] = :present | |
end | |
def destroy | |
@property_flush[:ensure] = :absent | |
end | |
def exists? | |
@property_hash[:ensure] == :present | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Type.newtype(:nexpose_host) do | |
@doc = 'This type provides the capability to manage hosts in nexpose' | |
ensurable | |
def munge_boolean(value) | |
case value | |
when true, "true", :true | |
:true | |
when false, "false", :false | |
:false | |
else | |
fail("munge_boolean only takes booleans") | |
end | |
end | |
newparam(:host, :namevar => true) do | |
desc 'the FQFN' | |
newvalues(/[\w\-\.]+/) | |
end | |
newproperty(:operational, :boolean => true ) do | |
desc "whether to monitor the host" | |
newvalue(:true) | |
newvalue(:false) | |
munge do |value| | |
@resource.munge_boolean(value) | |
end | |
end | |
newproperty(:siteid ) do | |
desc "siteid to use" | |
newvalues(/\d+/) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node /^[a-z]{2,3}\d{,2}\.nexpose\.example\.org$/ inherits default { | |
Nexpose_host <<||>> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment