File Coverage

blib/lib/Eixo/Zone/Starter.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Eixo::Zone::Starter;
2              
3             #
4             # Initialization Routine
5             #
6 1     1   916 use strict;
  1         2  
  1         28  
7 1     1   541 use Eixo::Zone::Resume;
  1         2  
  1         26  
8              
9 1     1   477 use Eixo::Zone::FS::Ctl;
  1         12  
  1         86  
10 1     1   477 use Eixo::Zone::Driver;
  0            
  0            
11              
12             use Eixo::Zone::Artifact::PSInit;
13             use Eixo::Zone::Artifact::FSVolumeTmp;
14             use Eixo::Zone::Artifact::FSVolumeProc;
15              
16              
17             use Eixo::Zone::Network::Starter;
18              
19             sub ctl_fs{
20             "Eixo::Zone::FS::Ctl"
21             }
22              
23             sub ctl_ps{
24             "Eixo::Zone::Driver";
25             }
26              
27             sub init{
28             my ($self, %args) = @_;
29              
30             my $r = Eixo::Zone::Resume->new();
31              
32             my $starter = $self->__initInit($r, %args);
33              
34             $self->__initVolumes($r, %args);
35              
36             $self->__initNetwork($r, %args);
37              
38             ($starter) ? $starter->() : $r->batch();
39              
40             }
41              
42             sub __initInit{
43             my ($self, $r, %args) = @_;
44              
45             return unless($args{init});
46              
47             my $ps_init = Eixo::Zone::Artifact::PSInit->new(
48              
49             sub {
50              
51             $r->batch;
52              
53             $args{init}->();
54              
55             },
56              
57             $r,
58              
59             $self->ctl_ps
60             );
61              
62             $r->addArtifact($ps_init);
63              
64             my %args_init = ();
65              
66             $args_init{MOUNTS} = 1 if($args{volumes});
67              
68             sub {
69             $ps_init->start(%args_init);
70              
71             $r->{pid} = $ps_init->{pid};
72              
73             $r;
74             }
75             }
76              
77             sub __initNetwork{
78             my ($self, $r, %args) = @_;
79              
80             return unless($args{network});
81              
82             Eixo::Zone::Network::Starter->init(
83              
84             $r,
85              
86             %args
87              
88             );
89             }
90              
91             sub __initVolumes{
92             my ($self, $r, %args) = @_;
93              
94             if($args{self_proc}){
95             $self->__initProc($r, %args);
96             }
97              
98             foreach my $path (keys %{$args{volumes}}){
99              
100             $self->__initVolume($r, $path, %{$args{volumes}->{$path}});
101             }
102              
103             }
104              
105             sub __initVolume{
106             my ($self, $r,$path, %data) = @_;
107              
108             return $self->__initVolumeTmp($r, $path, %data) if($data{type} eq 'tmpfs');
109              
110             return $self->__initVolumeProc($r, $path, %data) if($data{type} eq 'procfs');
111              
112             }
113              
114             sub __initVolumeTmp{
115             my ($self, $r, $path, %data) = @_;
116              
117             my $tmp_volume;
118              
119             $r->addArtifact(
120              
121             $tmp_volume = Eixo::Zone::Artifact::FSVolumeTmp->new(
122              
123             size=>$data{size},
124              
125             path=>$path,
126              
127             ctl=>$self->ctl_fs
128              
129             )
130              
131             );
132              
133             $r->addBatch(sub {
134              
135             $tmp_volume->mount;
136              
137             });
138             }
139              
140             sub __initVolumeProc{
141             my ($self, $r, $path, %data) = @_;
142              
143             my $proc_volume;
144              
145             $r->addArtifact(
146              
147             $proc_volume = Eixo::Zone::Artifact::FSVolumeProc->new(
148              
149             size=>$data{size},
150              
151             path=>$path,
152              
153             ctl=>$self->ctl_fs
154              
155             )
156              
157             );
158              
159             $r->addBatch(sub {
160              
161             $proc_volume->mount
162              
163             });
164             }
165              
166             1;