#!/usr/bin/perl -w

=head1 NAME

    mk-glusterfs-client-files - создание файлов для маунтинга директорий, расшаренных по glusterfs

=head1 USAGE

    mk-glusterfs-client-files debian/yandex-direct-logs-mount `hosts all` direct-app-logs -d mount_dir=/mnt/qqq

=head1 DESCRIPTION
    

=cut

use strict;
use warnings;

use SvnRelease::MkFiles;

my $mkfiles = SvnRelease::MkFiles->new(
    files => [],
    templates_fh => \*DATA,
    );

my ($hosts, $volume_name, @dummy) = $mkfiles->parse_options("hosts volume_name");
if (@dummy) {
    $mkfiles->usage("Incorrect number of parameters");
} elsif ($hosts !~ /^(([a-z0-9\-]+\.)+[a-z]+,)*([a-z0-9\-]+\.)+[a-z]+$/i) {
    $mkfiles->usage("Incorrect hosts");
} elsif ($volume_name !~ /^[a-z0-9\-]+$/i) {
    $mkfiles->usage("Incorrect volume_name");
}

$mkfiles->{vars}->{volume_name} = $volume_name;

for my $host (split ',', $hosts) {
    $mkfiles->{vars}->{host} = $host;
    $mkfiles->mkfiles([
        {tmpl => 'glusterfs_client_config', file => "/etc/glusterfs/client.d/[% host %]-[% volume_name %].vol", },
        ]);
}

__DATA__
<< glusterfs_client_config
#! mount-dir: [% mount_dir || '/mnt' %]/[% host %]/[% volume_name %]
volume [% volume_name %]
  type protocol/client
  option transport-type tcp/client
  option remote-host [% host %]
  option remote-port 24016              
  option transport-timeout 30
  option remote-subvolume [% volume_name %]
end-volume

