NAME
App::Netdisco::Util::Device
DESCRIPTION
A set of helper subroutines to support parts of the Netdisco application.
There are no default exports, however the :all
tag will export all subroutines.
EXPORT_OK
get_device( $ip )
Given an IP address, returns a DBIx::Class::Row object for the Device in the Netdisco database. The IP can be for any interface on the device.
If for any reason $ip
is already a DBIx::Class
Device object, then it is simply returned.
If the device or interface IP is not known to Netdisco a new Device object is created for the IP, and returned. This object is in-memory only and not yet stored to the database.
delete_device( $ip, $archive? )
Given an IP address, deletes the device from Netdisco, including all related data such as logs and nodes. If the $archive
parameter is true, then nodes will be maintained in an archive state.
Returns true if the transaction completes, else returns false.
renumber_device( $current_ip, $new_ip )
Will update all records in Netdisco referring to the device with $current_ip
to use $new_ip
instead, followed by renumbering the device iteself.
Returns true if the transaction completes, else returns false.
match_devicetype( $type, $setting_name )
Given a $type
(which may be any text value), returns true if any of the list of regular expressions in $setting_name
is matched, otherwise returns false.
check_device_no( $ip, $setting_name )
Given the IP address of a device, returns true if the configuration setting $setting_name
matches that device, else returns false. If the setting is undefined or empty, then check_no
also returns false.
print "rejected!" if check_no($ip, 'discover_no');
There are several options for what $setting_name
can contain:
Hostname, IP address, IP prefix
IP address range, using a hyphen and no whitespace
Regular Expression in YAML format which will match the device DNS name, e.g.:
- !!perl/regexp ^sep0.*$
"property:regex"
- matched against a device property, such asmodel
orvendor
To simply match all devices, use "any
" or IP Prefix "0.0.0.0/0
". Property regular expressions are anchored (that is, they must match the whole string). To match no devices we recommend an entry of "localhost
" in the setting.
check_device_only( $ip, $setting_name )
Given the IP address of a device, returns true if the configuration setting $setting_name
matches that device, else returns false. If the setting is undefined or empty, then check_only
also returns true.
print "rejected!" unless check_only($ip, 'discover_only');
There are several options for what $setting_name
can contain:
Hostname, IP address, IP prefix
IP address range, using a hyphen and no whitespace
Regular Expression in YAML format which will match the device DNS name, e.g.:
- !!perl/regexp ^sep0.*$
"property:regex"
- matched against a device property, such asmodel
orvendor
To simply match all devices, use "any
" or IP Prefix "0.0.0.0/0
". Property regular expressions are anchored (that is, they must match the whole string). To match no devices we recommend an entry of "localhost
" in the setting.
is_discoverable( $ip, $device_type? )
Given an IP address, returns true
if Netdisco on this host is permitted by the local configuration to discover the device.
The configuration items discover_no
and discover_only
are checked against the given IP.
If $device_type
is also given, then discover_no_type
will also be checked.
Returns false if the host is not permitted to discover the target device.
is_arpnipable( $ip )
Given an IP address, returns true
if Netdisco on this host is permitted by the local configuration to arpnip the device.
The configuration items arpnip_no
and arpnip_only
are checked against the given IP.
Returns false if the host is not permitted to arpnip the target device.
is_macsuckable( $ip )
Given an IP address, returns true
if Netdisco on this host is permitted by the local configuration to macsuck the device.
The configuration items macsuck_no
and macsuck_only
are checked against the given IP.
Returns false if the host is not permitted to macsuck the target device.