| 1 | package RackMan::Format::LDAP; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use NetAddr::IP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use RackMan::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 2 | ▶ | use constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | CONFIG_SECTION => "format:ldap", | |||||||||
| 11 | DEFAULT_PATH => "/etc/ldap/hosts", | ||||||||||
| 12 | 2 | }; | |||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | # | ||||||||||
| 16 | # write() | ||||||||||
| 17 | # ----- | ||||||||||
| 18 | 0 | ▶ | sub write { | ||||||||
|
Subroutine
write: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 19 | 0 | my ($class, $args) = @_; | |||||||||
| 20 | |||||||||||
| 21 | 0 | my $rackdev = $args->{rackdev}; | |||||||||
| 22 | 0 | my $rackman = $args->{rackman}; | |||||||||
| 23 | 0 | my $config = RackMan::File->new; | |||||||||
| 24 | 0 | my $name = $rackdev->object_name; | |||||||||
| 25 | |||||||||||
| 26 | # generate the config | ||||||||||
| 27 | 0 | $config->add_content(make_ldif($rackdev)); | |||||||||
| 28 | |||||||||||
| 29 | # write the configuration on disk | ||||||||||
| 30 | 0 | $config->name("$name.ldif"); | |||||||||
| 31 | 0 | $config->path($rackman->config->val(CONFIG_SECTION, "path", DEFAULT_PATH)); | |||||||||
| 32 | 0 | ▶ | print " + writing ", $config->fullpath, $/ if $args->{verbose}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | my $scm = $rackman->get_scm({ path => $config->path }); | |||||||||
| 34 | 0 | $scm->update; | |||||||||
| 35 | 0 | $config->write; | |||||||||
| 36 | 0 | $scm->add($config->name); | |||||||||
| 37 | 0 | $scm->commit($config->name, "generated by $class / $::PROGRAM v$::VERSION"); | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | |||||||||||
| 41 | # | ||||||||||
| 42 | # make_ldif() | ||||||||||
| 43 | # --------- | ||||||||||
| 44 | 0 | ▶ | sub make_ldif { | ||||||||
|
Subroutine
make_ldif: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 45 | 0 | my ($rackdev) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 0 | my $name = $rackdev->object_name; | |||||||||
| 48 | |||||||||||
| 49 | # find the first MAC address of the device, excluding the iLO | ||||||||||
| 50 | 0 | my @mac_addrs = $rackdev->regular_mac_addrs; | |||||||||
| 51 | 0 | ▶ | RackMan->error("RackObject '$name' lacks a MAC address") unless @mac_addrs; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | # find the first IP address of the device, excluding the iLO | ||||||||||
| 54 | 0 | my @ip_addrs = $rackdev->regular_ipv4addrs; | |||||||||
| 55 | 0 | ▶ | RackMan->error("RackObject '$name' lacks an IPv4 address") unless @ip_addrs; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | |||||||||||
| 57 | # find the defaut IPv4 gateway | ||||||||||
| 58 | 0 | my $gateway = $rackdev->default_ipv4_gateway; | |||||||||
| 59 | |||||||||||
| 60 | # determine the network mask | ||||||||||
| 61 | 0 | my $addr = NetAddr::IP->new($ip_addrs[0]{addr}, $gateway->{masklen}); | |||||||||
| 62 | 0 | my $netmask = $addr->mask; | |||||||||
| 63 | |||||||||||
| 64 | # fetch the base DN | ||||||||||
| 65 | 0 | my $base_dn = $rackdev->rackman->config->val(CONFIG_SECTION, "base_dn", ""); | |||||||||
| 66 | 0 | ▶ | $base_dn = ",$base_dn" if $base_dn; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | |||||||||||
| 68 | # construct the LDIF | ||||||||||
| 69 | my $ldif = join "", | ||||||||||
| 70 | "dn: cn=$name$base_dn\n", | ||||||||||
| 71 | "cn: $name\n", | ||||||||||
| 72 | "macAddress: $mac_addrs[0]{l2address_text}\n", | ||||||||||
| 73 | "ipHostNumber: $ip_addrs[0]{addr}\n", | ||||||||||
| 74 | "ipNetmaskNumber: $netmask\n", | ||||||||||
| 75 | "description: " . lc($rackdev->object_type) . " " | ||||||||||
| 76 | 0 | . $rackdev->attributes->{"HW type"} . "\n", | |||||||||
| 77 | "objectClass: top\n", | ||||||||||
| 78 | "objectClass: goServer\n"; | ||||||||||
| 79 | |||||||||||
| 80 | 0 | return $ldif | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | |||||||||||
| 84 | 2 | __PACKAGE__ | |||||||||
| 85 | |||||||||||
| 86 | __END__ | ||||||||||