-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.pm
96 lines (63 loc) · 1.97 KB
/
Server.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#
# (c) 2015 FILIADATA GmbH
#
# vim: set ts=2 sw=2 tw=0:
# vim: set expandtab:
package PuppetDB::Server;
use common::sense;
use Rex -base;
use Rex::CMDB;
use base qw(Rex::Group::Entry::Server);
sub new {
my $that = shift;
my $proto = ref($that) || $that;
my $self = $proto->SUPER::new(@_);
bless( $self, $proto );
my $cmdb = get cmdb( undef, $self->{name} );
for my $key ( keys %{$cmdb} ) {
$self->{$key} = $cmdb->{$key};
}
return $self;
}
sub set_options {
my ($self, %options) = @_;
for my $o (keys %options) {
$self->{$o} = $options{$o};
}
}
sub fact {
my ( $self, $fact ) = @_;
if ( defined $fact && $self->{__puppet_fact__}->{$fact} ) {
return $self->{__puppet_fact__}->{$fact};
}
# no fact found, run facter
my $yaml = run "facter -y -p";
$self->{__puppet_fact__} = Load($yaml);
return $self->{__puppet_fact__}->{$fact};
}
sub get_user {
my $self = shift;
return $self->SUPER::get_user();
}
1;
__END__
=pod
=head1 NAME
PuppetDB::Server - Object to handle PuppetDB host entries.
This Object inherits from I<Rex::Group::Entry::Server> and extends this object by some methods that are helpfull when dealing with foreman and puppet hosts.
This is an internal object of the I<PuppetDB> module and normaly won't get called from the outside world.
=head1 METHODS
=over 4
=item fact($factname)
Read the facter information of the host and returns the requested value.
=head1 COPYRIGHT
Copyright 2015 FILIADATA GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.