lib/Illumos/SMF.pm

filter: Statementstmt 8.0% 22 / 274 Branchbran 2.3% 3 / 128 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 11.5% 3 / 26 Podpod 95.4% 21 / 22 totaltotal 9.6% 49 / 510 CC 88 SCAR 41.0
CC
88
Cov
6%
listFMRI
132.0
getFMRIProperties
132.0
setProperty
110.0
CRAP 60.4
↑ Summary
1 package Illumos::SMF;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # version
7 1 our $VERSION = '0.1.7';
8  
9 # commands
10 1 my $SVCS = '/usr/bin/svcs';
11 1 my $SVCCFG = '/usr/sbin/svccfg';
12 1 my $SVCADM = '/usr/sbin/svcadm';
13 1 my $ZLOGIN = '/usr/sbin/zlogin';
14  
15 # constructor
16 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.1
Pod undocumented
17 2 my $class = shift;
18 2 my $self = { @_ };
19  
20 # add Illumos::Zone instance if zone support is required
21 2 ▶ $self->{zonesupport} && do {
Branch: 1 branch
BranchTrueFalseTotal
$self->{"zonesupport"} and do { eval { do { require Illumos::Zones } }; if ($@) { die "ERROR: Unable to load package Illumos::Zones."; } ; $self->{"zone"} = "Illumos::Zones"->new("debug", $self->{"debug"}) } 1 1 2
22 1 eval {
23 1 require Illumos::Zones;
24 };
25 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
26 0 die "ERROR: Unable to load package Illumos::Zones.";
27 }
28  
29 1 $self->{zone} = Illumos::Zones->new(debug => $self->{debug});
30 };
31
32 2 return bless $self, $class
33 }
34 # private methods
35 0 ▶my $svcAdm = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
36 0 my $self = shift;
37 0 my $cmd = shift;
38 0 my $fmri = shift;
39  
40 0 my @cmd = ($SVCADM, $cmd, $fmri);
41  
42 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
43 0 ▶ system(@cmd) and die "ERROR: cannot $cmd '$fmri'\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot $cmd '${fmri}'\n" 0 0 0
44 1 };
45  
46 0 ▶my $zoneCmd = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
47 0 my $self = shift;
48 0 my $zoneName = shift;
49  
50 print STDERR "WARNING: zonename specified but 'zonesupport' not enabled for Illumos::SMF\n"
51 0 ▶ . "use 'Illumos::SMF(zonesupport => 1)' to enable zone support\n" if $zoneName && !$self->{zone};
Branch: 1 branch
BranchTrueFalseTotal
if $zoneName and not $self->{"zone"} 0 0 0
Condition0%0/3
$zoneName and not $self->{"zone"}
!ll&&!rl&&r
000
MC/DC0%0/2
$zoneName and not $self->{"zone"}
$zoneName not $self->{"zone"}
Truth table0%0/3
A and not(B)
A= $zoneNameB= not $self->{"zone"}
ABresult
0X0
100
111
52  
53 0 ▶ return { cmd => [], shellquote => q{"} } if !$zoneName || !$self->{zone};
Branch: 1 branch
BranchTrueFalseTotal
unless $zoneName and $self->{"zone"} 0 0 0
Condition0%0/3
$zoneName and $self->{"zone"}
!ll&&!rl&&r
000
MC/DC0%0/2
$zoneName and $self->{"zone"}
$zoneName $self->{"zone"}
Truth table0%0/3
A and B
A= $zoneNameB= $self->{"zone"}
ABresult
0X0
100
111
54  
55 0 ▶ my $zone = $self->{zone}->listZone($zoneName, { requireSMF => 1 })
Branch: 1 branch
BranchTrueFalseTotal
my $zone = $self->{"zone"}->listZone($zoneName, {"requireSMF", 1}) or die "ERROR: zone '${zoneName}' does not exist or not support SMF (is the zone root dataset mounted?).\n" 0 0 0
56 or die "ERROR: zone '$zoneName' does not exist or not support SMF (is the zone root dataset mounted?).\n";
57  
58 0 ▶ if ($zone->{state} eq 'running') {
Branch: 1 branch
BranchTrueFalseTotal
if ($zone->{'state'} eq 'running') { } 0 0 0
59 0 return { cmd => [ $ZLOGIN, $zoneName ], shellquote => q{'"'} };
60 }
61 else {
62 0 return { cmd => [], zpath => $zone->{zonepath}, shellquote => q{"} };
63 }
64  
65 # just in case, should never reach here...
66 0 return { cmd => [], shellquote => q{"} };
67 1 };
68  
69 # public methods
70 0 ▶sub refreshFMRI {
Subroutine refreshFMRI: not called CC=5 SCAR=34.0
Pod documented
71 0 my $self = shift;
72 0 my $fmri = shift;
73 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
74
75 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
76 0 my @cmd = @{$zcmd->{cmd}};
77 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
78 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
79  
80 0 push @cmd, ($SVCCFG, '-s', $fmri, 'refresh');
81  
82 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
83 0 ▶ system(@cmd) and die "ERROR: cannot refresh FMRI '$fmri'\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot refresh FMRI '${fmri}'\n" 0 0 0
84
85 0 return 1;
86 }
87  
88 0 ▶sub listFMRI {
Subroutine listFMRI: not called CC=11 SCAR=48.8
Pod documented
89 0 my $self = shift;
90 0 my $fmri = shift;
91 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
92 0 my @fmris;
93
94 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
95 0 my @cmd = @{$zcmd->{cmd}};
96 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
97 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
98
99 0 ▶ $fmri ||= '*';
Condition0%0/2
$fmri ||= "*"
l!l
00
MC/DC0%0/1
$fmri ||= "*"
$fmri
Truth table0%0/2
A
A= $fmri
Aresult
11
00
100
101 # remove leading 'svc:/'
102 0 $fmri =~ s/^svc:\///;
103  
104 0 my @cmd1 = (@cmd, $SVCCFG, 'list', $fmri);
105  
106 0 ▶ print STDERR '# ' . join(' ', @cmd1) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
107 0 ▶ open my $fmris, '-|', @cmd1
Branch: 1 branch
BranchTrueFalseTotal
open my $fmris, "-|", @cmd1 or die "ERROR: cannot get list of FMRI\n" 0 0 0
108 or die "ERROR: cannot get list of FMRI\n";
109  
110 0 ▶ while (my $elem = <$fmris>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $elem = readline $fmris)) 0 0 0
111 0 chomp $elem;
112 0 ▶ push @fmris, "svc:/$elem" if !$opts->{instancesonly};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts->{"instancesonly"} 0 0 0
113
114 0 my @cmd2 = (@cmd, $SVCCFG, '-s', $elem, 'list');
115  
116 0 ▶ open my $instances, '-|', @cmd2
Branch: 1 branch
BranchTrueFalseTotal
open my $instances, "-|", @cmd2 or die "ERROR: cannot get instances of '${elem}'\n" 0 0 0
117 or die "ERROR: cannot get instances of '$elem'\n";
118  
119 0 ▶ while (<$instances>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $instances)) 0 0 0
120 0 chomp;
121 0 ▶ next if /:properties/;
Branch: 1 branch
BranchTrueFalseTotal
if /:properties/ 0 0 0
122 0 push @fmris, "svc:/$elem:$_";
123 }
124 0 close $instances;
125 }
126  
127 0 return [ @fmris ];
128 }
129  
130 0 ▶sub fmriExists {
Subroutine fmriExists: not called CC=1 SCAR=6.9
Pod documented
131 0 my $self = shift;
132 0 my $fmri = shift;
133 0 my $opts = shift;
134  
135 # remove instance name
136 0 my ($baseFmri) = $fmri =~ /^((?:svc:)?[^:]+)/;
137  
138 0 return grep { $fmri eq $_ } @{$self->listFMRI($baseFmri, $opts)};
139 }
140  
141 0 ▶sub fmriState {
Subroutine fmriState: not called CC=4 SCAR=30.0
Pod documented
142 0 my $self = shift;
143 0 my $fmri = shift;
144 0 my $opts = shift;
145  
146 0 ▶ my @cmd = ($SVCS, $opts->{zonename} ? ('-z', $opts->{zonename}) : (), qw(-H -o state), $fmri);
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'zonename'} ? : 0 0 0
147  
148 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
149 0 ▶ open my $fmris, '-|', @cmd
Branch: 1 branch
BranchTrueFalseTotal
open my $fmris, "-|", @cmd or die "ERROR: cannot get list of FMRI\n" 0 0 0
150 or die "ERROR: cannot get list of FMRI\n";
151  
152 0 chomp(my $state = <$fmris>);
153 0 return $state;
154 }
155  
156 0 ▶sub fmriOnline {
Subroutine fmriOnline: not called CC=1 SCAR=6.9
Pod documented
157 0 my $self = shift;
158
159 0 return $self->fmriState(shift, shift) eq 'online';
160 }
161  
162 0 ▶sub enable {
Subroutine enable: not called CC=1 SCAR=6.9
Pod documented
163 0 my $self = shift;
164 0 my $fmri = shift;
165  
166 0 $self->$svcAdm('enable', $fmri);
167 }
168  
169 0 ▶sub disable {
Subroutine disable: not called CC=1 SCAR=6.9
Pod documented
170 0 my $self = shift;
171 0 my $fmri = shift;
172  
173 0 $self->$svcAdm('disable', $fmri);
174 }
175  
176 0 ▶sub restart {
Subroutine restart: not called CC=1 SCAR=6.9
Pod documented
177 0 my $self = shift;
178 0 my $fmri = shift;
179  
180 0 $self->$svcAdm('restart', $fmri);
181 }
182  
183 0 ▶sub addFMRI {
Subroutine addFMRI: not called CC=5 SCAR=34.0
Pod documented
184 0 my $self = shift;
185 0 my $fmri = shift;
186 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
187  
188 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
189 0 my @cmd = @{$zcmd->{cmd}};
190 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
191 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
192  
193 # remove leading 'svc:/'
194 0 $fmri =~ s/^svc:\///;
195  
196 0 push @cmd, ($SVCCFG, 'add', $fmri);
197  
198 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
199 0 ▶ system(@cmd) and die "ERROR: cannot add '$fmri'\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot add '${fmri}'\n" 0 0 0
200 }
201  
202 0 ▶sub deleteFMRI {
Subroutine deleteFMRI: not called CC=5 SCAR=34.0
Pod documented
203 0 my $self = shift;
204 0 my $fmri = shift;
205 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
206  
207 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
208 0 my @cmd = @{$zcmd->{cmd}};
209 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
210 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
211  
212 0 push @cmd, ($SVCCFG, 'delete', $fmri);
213 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
214 0 ▶ system(@cmd) and die "ERROR: cannot delete $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot delete $fmri\n" 0 0 0
215 }
216  
217 0 ▶sub addInstance {
Subroutine addInstance: not called CC=6 SCAR=37.4
Pod documented
218 0 my $self = shift;
219 0 my $fmri = shift;
220 0 my $instance = shift;
221 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
222  
223 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
224 0 my @cmd = @{$zcmd->{cmd}};
225 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
226 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
227  
228 0 push @cmd, ($SVCCFG, '-s', $fmri, 'add', $instance);
229 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
230 0 ▶ system(@cmd) and die "ERROR: cannot add instance '$instance' to $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot add instance '${instance}' to $fmri\n" 0 0 0
231  
232 0 $self->addPropertyGroup("$fmri:$instance", 'general', 'framework', $opts);
233 0 $self->setProperty("$fmri:$instance", 'general/complete', $instance, undef, $opts);
234 $self->setProperty("$fmri:$instance", 'general/enabled',
235 0 ▶ $opts->{enabled} ? 'true' : 'false', undef, $opts);
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'enabled'} ? : 0 0 0
236 }
237  
238 0 ▶sub getPropertyGroups {
Subroutine getPropertyGroups: not called CC=6 SCAR=37.4
Pod documented
239 0 my $self = shift;
240 0 my $fmri = shift;
241 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
242  
243 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
244 0 my @cmd = @{$zcmd->{cmd}};
245 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
246 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
247  
248 0 my $pg = [];
249 0 push @cmd, ($SVCCFG, '-s', $fmri, 'listpg');
250  
251 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
252 0 ▶ open my $props, '-|', @cmd
Branch: 1 branch
BranchTrueFalseTotal
open my $props, "-|", @cmd or die "ERROR: cannot get property group of FMRI '${fmri}'\n" 0 0 0
253 or die "ERROR: cannot get property group of FMRI '$fmri'\n";
254  
255 0 ▶ while (my $prop = <$props>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $prop = readline $props)) 0 0 0
256 0 chomp $prop;
257 0 my ($name, $type) = split /\s+/, $prop, 2;
258 0 push @$pg, $name;
259 }
260
261 0 return $pg;
262 }
263  
264 0 ▶sub propertyExists {
Subroutine propertyExists: not called CC=1 SCAR=6.9
Pod documented
265 0 my $self = shift;
266 0 my $fmri = shift;
267 0 my $property = shift;
268 0 my $opts = shift;
269
270 # extract property group
271 0 my ($pg) = $property =~ /^([^\/]+)/;
272  
273 0 return grep { $property eq $_ } keys %{$self->getProperties($fmri, $pg, $opts)};
274 }
275  
276 0 ▶sub propertyGroupExists {
Subroutine propertyGroupExists: not called CC=1 SCAR=6.9
Pod documented
277 0 my $self = shift;
278 0 my $fmri = shift;
279 0 my $pg = shift;
280 0 my $opts = shift;
281  
282 0 return grep { $pg eq $_ } @{$self->getPropertyGroups($fmri, $opts)};
283 }
284  
285 0 ▶sub addPropertyGroup {
Subroutine addPropertyGroup: not called CC=7 SCAR=40.3
Pod documented
286 0 my $self = shift;
287 0 my $fmri = shift;
288 0 my $pg = shift;
289 0 my $type = shift;
290 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
291
292 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
293 0 my @cmd = @{$zcmd->{cmd}};
294 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
295 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
296
297 # set type to application if not specified
298 0 ▶ $type //= 'application';
Condition0%0/2
$type //= "application"
l!l
00
MC/DC0%0/1
$type //= "application"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
299  
300 0 ▶ return if $self->propertyGroupExists($fmri, $pg, $opts);
Branch: 1 branch
BranchTrueFalseTotal
if $self->propertyGroupExists($fmri, $pg, $opts) 0 0 0
301  
302 0 push @cmd, ($SVCCFG, '-s', $fmri, 'addpg', $pg, $type);
303 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
304 0 ▶ system(@cmd) and die "ERROR: cannot add property group to $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot add property group to $fmri\n" 0 0 0
305 }
306  
307 0 ▶sub deletePropertyGroup {
Subroutine deletePropertyGroup: not called CC=5 SCAR=34.0
Pod documented
308 0 my $self = shift;
309 0 my $fmri = shift;
310 0 my $pg = shift;
311 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
312
313 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
314 0 my @cmd = @{$zcmd->{cmd}};
315 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
316 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
317
318 0 push @cmd, ($SVCCFG, '-s', $fmri, 'delpg', $pg);
319 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
320 0 ▶ system(@cmd) and die "ERROR: cannot delete property group from $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot delete property group from $fmri\n" 0 0 0
321 }
322  
323 0 ▶sub setProperty {
Subroutine setProperty: not called CC=10 SCAR=47.0
Pod documented
324 0 my $self = shift;
325 0 my $fmri = shift;
326 0 my $property = shift;
327 0 my $value = shift;
328 0 my $type = shift;
329 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
330
331 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
332 0 my @cmd = @{$zcmd->{cmd}};
333 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
334 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
335  
336 # guess property type if not provided
337 0 ▶ $type || do {
Branch: 1 branch
BranchTrueFalseTotal
$type or do { $type = "astring"; foreach $_ ($value) { /^\d+$/ and do { $type = "count"; last }; /^(?:true|false)$/i and do { $type = "boolean"; last }; } } 0 0 0
338 0 $type = 'astring';
339  
340 0 for ($value){
341 0 ▶ /^\d+$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^\d+$/ and do { $type = "count"; last } 0 0 0
342 0 $type = 'count';
343 0 last;
344 };
345  
346 0 ▶ /^(?:true|false)$/i && do {
Branch: 1 branch
BranchTrueFalseTotal
/^(?:true|false)$/i and do { $type = "boolean"; last } 0 0 0
347 0 $type = 'boolean';
348 0 last;
349 };
350 }
351 };
352  
353 push @cmd, $self->propertyExists($fmri, $property, $opts) ?
354 ($SVCCFG, '-s', $fmri, 'setprop', $property, '=',
355 $zcmd->{shellquote} . $value . $zcmd->{shellquote})
356 : ($SVCCFG, '-s', $fmri, 'addpropvalue', $property, "$type:",
357 0 ▶ $zcmd->{shellquote} . $value . $zcmd->{shellquote});
Branch: 1 branch
BranchTrueFalseTotal
$self->propertyExists($fmri, $property, $opts) ? : 0 0 0
358 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
359 0 ▶ system(@cmd) and die "ERROR: cannot set property $property of $fmri\n";
Branch: 1 branch
BranchTrueFalseTotal
system @cmd and die "ERROR: cannot set property $property of $fmri\n" 0 0 0
360 }
361  
362 0 ▶sub setProperties {
Subroutine setProperties: not called CC=2 SCAR=17.9
Pod documented
363 0 my $self = shift;
364 0 my $fmri = shift;
365 0 my $properties = shift;
366 0 my $opts = shift;
367  
368 0 for my $key (keys %$properties){
369 0 $self->setProperty($fmri, $key, $properties->{$key}, undef, $opts)
370 }
371 }
372  
373 0 ▶sub getProperties {
Subroutine getProperties: not called CC=7 SCAR=40.3
Pod documented
374 0 my $self = shift;
375 0 my $fmri = shift;
376 0 my $pg = shift;
377 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
378
379 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
380 0 my @cmd = @{$zcmd->{cmd}};
381 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
382 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
383  
384 0 my $properties = {};
385  
386 0 push @cmd, ($SVCCFG, '-s', $fmri, 'listprop', $pg);
387  
388 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
389 0 ▶ open my $props, '-|', @cmd
Branch: 1 branch
BranchTrueFalseTotal
open my $props, "-|", @cmd or die "ERROR: cannot get properties of FMRI '${fmri}'\n" 0 0 0
390 or die "ERROR: cannot get properties of FMRI '$fmri'\n";
391  
392 0 ▶ while (<$props>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $props)) 0 0 0
393 0 chomp;
394 0 my ($name, $type, $value) = split /\s+/, $_, 3;
395 0 ▶ next if $name eq $pg;
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $pg 0 0 0
396 #remove quotes
397 0 $value =~ s/^"|"$//g;
398 0 $properties->{$name} = $value;
399  
400 }
401
402 0 return $properties;
403 }
404  
405 0 ▶sub setFMRIProperties {
Subroutine setFMRIProperties: not called CC=7 SCAR=40.3
Pod documented
406 0 my $self = shift;
407 0 my $fmri = shift;
408 0 my $properties = shift;
409 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
410
411 0 ▶ $self->addFMRI($fmri, $opts) if !$self->fmriExists($fmri, $opts);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->fmriExists($fmri, $opts) 0 0 0
412 # extract property groups
413 0 ▶ my @pg = map { $properties->{$_}->{members} ? $_ : () } keys %$properties;
Branch: 1 branch
BranchTrueFalseTotal
$properties->{$_}{'members'} ? : 0 0 0
414  
415 0 for my $pg (@pg) {
416 0 $self->addPropertyGroup($fmri, $pg, $properties->{$pg}->{type}, $opts);
417 0 for my $prop (keys %{$properties->{$pg}->{members}}) {
418 $self->setProperty($fmri, "$pg/$prop",
419 $properties->{$pg}->{members}->{$prop}->{value},
420 $properties->{$pg}->{members}->{$prop}->{type},
421 0 $opts);
422 }
423 0 delete $properties->{$pg};
424 }
425  
426 0 for my $prop (keys %$properties) {
427 $self->setProperty($fmri, $prop,
428 $properties->{$prop}->{value},
429 $properties->{$prop}->{type},
430 0 $opts);
431 }
432 }
433  
434 0 ▶sub getFMRIProperties {
Subroutine getFMRIProperties: not called CC=11 SCAR=48.8
Pod documented
435 0 my $self = shift;
436 0 my $fmri = shift;
437 0 ▶ my $opts = $_[0] // {};
Condition0%0/2
$_[0] // {}
l!l
00
MC/DC0%0/1
$_[0] // {}
$_[0]
Truth table0%0/2
A
A= $_[0]
Aresult
11
00
438
439 0 my $zcmd = $self->$zoneCmd($opts->{zonename});
440 0 my @cmd = @{$zcmd->{cmd}};
441 local $ENV{SVCCFG_REPOSITORY} = $zcmd->{zpath}
442 0 ▶ . '/root/etc/svc/repository.db' if $zcmd->{zpath};
Branch: 1 branch
BranchTrueFalseTotal
if $zcmd->{"zpath"} 0 0 0
443  
444 0 my $properties = {};
445  
446 0 push @cmd, ($SVCCFG, '-s', $fmri, 'listprop');
447  
448 0 ▶ print STDERR '# ' . join(' ', @cmd) . "\n" if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
449 0 ▶ open my $props, '-|', @cmd
Branch: 1 branch
BranchTrueFalseTotal
open my $props, "-|", @cmd or die "ERROR: cannot get properties of FMRI\n" 0 0 0
450 or die "ERROR: cannot get properties of FMRI\n";
451  
452 0 ▶ while (<$props>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $props)) 0 0 0
453 0 chomp;
454 0 my ($pg, $prop, $type, $value) = /^(?:([-\w]+)\/)?([-\w]+)\s+([-\w]+)(?:\s+(.+))?$/;
455 0 ▶ next if !$prop || !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $prop and $type 0 0 0
Condition0%0/3
$prop and $type
!ll&&!rl&&r
000
MC/DC0%0/2
$prop and $type
$prop $type
Truth table0%0/3
A and B
A= $propB= $type
ABresult
0X0
100
111
456 # remove quotes from $value
457 0 ▶ $value =~ s/^"|"$//g if $value;
Branch: 1 branch
BranchTrueFalseTotal
if $value 0 0 0
458 0 ▶ if ($pg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pg) { } 0 0 0
459 0 $properties->{$pg}->{members}->{$prop}->{type} = $type;
460 0 $properties->{$pg}->{members}->{$prop}->{value} = $value;
461 }
462 else {
463 0 $properties->{$prop}->{type} = $type;
464 0 ▶ $properties->{$prop}->{value} = $value // '';
Condition0%0/2
$value // ""
l!l
00
MC/DC0%0/1
$value // ""
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
465 }
466 }
467  
468 0 return $properties;
469 }
470  
471 1 1;
472  
473 __END__
↑ Summary