/[pxelator]/lib/PXElator/upstream.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /lib/PXElator/upstream.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (show annotations)
Wed Aug 19 22:48:54 2009 UTC (14 years, 8 months ago) by dpavlin
File size: 1677 byte(s)
first semi-complicated setup to show off some of sysadmin DSL in PXElator

implement nfs root boot with writable snapshot directories for each
client which are rolled out on demand using aufs on server side.

So, client can implement additional layer of aufs if needed
(for /tmp and things like that) and offload more important files
(configuration changes) back to server via NFS.

1 package upstream;
2
3 use warnings;
4 use strict;
5 use autodie;
6
7 use Data::Dump qw/dump/;
8 use LWP::Simple qw/mirror RC_NOT_MODIFIED/;
9 use Storable;
10 use server;
11
12 sub mirror_file {
13 my ( $url, $file ) = @_;
14 warn "mirror_file $url -> $file\n";
15 mirror( $url, $file )
16 == RC_NOT_MODIFIED
17 && warn(" not modified\n")
18 || warn(" done ", -s $file, " bytes\n")
19 ;
20 }
21
22 my $once_path = '/tmp/pxelator.once';
23 our $just_once = retrieve $once_path if -e $once_path;
24 sub first_time {
25 my $what = shift;
26 return if $just_once->{$what}++;
27 store $just_once, $once_path;
28 return 1;
29 }
30
31 sub iso {
32 my $url = shift;
33
34 return if ! first_time($url);
35
36 my $name = (caller(1))[3];
37 $name =~ s{config::}{} || die "caller isn't package config !";
38
39 warn "$name $url";
40
41 my $dir = "$server::base_dir/iso";
42 mkdir $dir unless -e $dir;
43
44 my $file = $1 if $url =~ m{/([^/]+\.iso$)}i;
45 die "can't find iso file in $url" unless $file;
46
47 my $iso = "$dir/$file";
48
49 mirror_file( $url, $iso );
50
51 $file =~ s{\.iso$}{}i;
52 my $mnt = "$server::base_dir/tftp/$name";
53 mkdir $mnt unless -d $mnt;
54 $mnt .= '/iso';
55 mkdir $mnt unless -d $mnt;
56
57 system("mount -t iso9660 | grep $name/iso || sudo mount $iso $mnt -o loop -t iso9660 -v") == 0;
58 }
59
60 sub files {
61 my $url = shift;
62 my @files = @_;
63
64 if ( ! @files ) {
65 push @files, $1 if $url =~ s{/([^/]+)$}{};
66 }
67
68 my $name = (caller(1))[3];
69 $name =~ s{config::}{} || die "caller isn't package config !";
70
71 my $path = "$server::base_dir/tftp/$name";
72 mkdir $path unless -d $path;
73
74 warn "# files $url ",dump( @files ), " -> $path\n";
75
76 foreach my $file ( @files ) {
77 mirror_file( "$url/$file", "$path/$file" )
78 if ! -e "$path/$file" || first_time( "$url/$file" );
79 }
80 }
81
82 1;

  ViewVC Help
Powered by ViewVC 1.1.26