/usr/share/perl5/LxctlHelpers/config.pm is in lxctl 0.3.1+debian-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | package LxctlHelpers::config;
use strict;
use warnings;
use YAML::Tiny qw(DumpFile LoadFile);
use Lxc::object;
# @main_config_paths should be hardcoded, at least for now.
my @main_config_paths = ("/etc/lxctl", "/etc", ".");
sub print_warn #(message)
{
use Term::ANSIColor;
my ($self, $message) = @_;
print STDERR color 'bold yellow';
print STDERR "Warning:";
print STDERR color 'reset';
print STDERR " $message";
return 1;
}
sub load_main
{
my ($self) = @_;
foreach my $path (@main_config_paths) {
if ( -f "$path/lxctl.yaml" ) {
my $yaml = YAML::Tiny->new;
$yaml = YAML::Tiny->read("$path/lxctl.yaml");
# For compatibility reasons. Remove somewhere in 0.3+
eval {
$self->{'lxc'}->set_roots_path($yaml->[0]->{'paths'}->{'ROOTS_PATH'});
$self->print_warn("$path/lxctl.yaml: ROOTS_PATH is deprecated. Please rename to ROOT_MOUNT_PATH\n");
} or do {
$self->{'lxc'}->set_root_mount_path($yaml->[0]->{'paths'}->{'ROOT_MOUNT_PATH'});
};
eval {
$self->{'lxc'}->set_config_path($yaml->[0]->{'paths'}->{'CONFIG_PATH'});
$self->print_warn("$path/lxctl.yaml: CONFIG_PATH is deprecated. Please rename to YAML_CONFIG_PATH\n");
} or do {
$self->{'lxc'}->set_yaml_config_path($yaml->[0]->{'paths'}->{'YAML_CONFIG_PATH'});
};
$self->{'lxc'}->set_lxc_conf_dir($yaml->[0]->{'paths'}->{'LXC_CONF_DIR'});
$self->{'lxc'}->set_lxc_log_path($yaml->[0]->{'paths'}->{'LXC_LOG_PATH'});
$self->{'lxc'}->set_lxc_log_level($yaml->[0]->{'paths'}->{'LXC_LOG_LEVEL'});
$self->{'lxc'}->set_template_path($yaml->[0]->{'paths'}->{'TEMPLATE_PATH'});
$self->{'lxc'}->set_vg($yaml->[0]->{'lvm'}->{'VG'});
my $skip_check = $yaml->[0]->{'check'}->{'skip_kernel_config_check'};
if (defined($skip_check)) {
$self->{'lxc'}->set_conf_check($skip_check);
}
last;
}
}
return;
}
sub get_option_from_main #($section, $option_name)
{
my ($self, $section, $option_name) = @_;
my $result = '';
foreach my $path (@main_config_paths) {
if ( -f "$path/lxctl.yaml" ) {
my $yaml = YAML::Tiny->new;
$yaml = YAML::Tiny->read("$path/lxctl.yaml");
eval {
$result = $yaml->[0]->{"$section"}->{"$option_name"};
};
last;
}
}
return $result;
}
sub get_option_from_yaml #($filepath, $section, $option_name)
{
my ($self, $filepath, $section, $option_name) = @_;
my $result = undef;
return $result if (! -f "$filepath");
my $yaml = YAML::Tiny->new;
$yaml = YAML::Tiny->read("$filepath");
eval {
if ($section ne '') {
$result = $yaml->[0]->{"$section"}->{"$option_name"};
} else {
$result = $yaml->[0]->{"$option_name"};
}
1;
};
return $result;
}
# hash_ref, filename
# ex: $config->save_hash(\%options, "abrakadabra.yaml");
sub save_hash
{
my $self = shift;
my $hash = shift;
my $filename = shift;
my %rhash = %$hash;
DumpFile($filename, \%rhash);
return;
}
# only arg: filename
# ex:
# my $tmp = $config->load_file("abrakadabra.yaml");
# my %opts = %$tmp;
sub load_file
{
my $self = shift;
my $filename = shift;
my $hash = LoadFile($filename);
my %h = %$hash;
$h{'api_ver'} = 0 if (!defined($h{'api_ver'}));
$hash = \%h;
return $hash
}
#Current config API version
sub get_api_ver
{
my $self = shift;
return 1;
}
# Loads hash from file, then modifys it whti hash from 1-st arg
# After that writes back to file.
sub change_hash
{
my $self = shift;
my $hash = shift;
my $filename = shift;
if ( ! -f $filename ) {
return;
}
my $tmp = $self->load_file($filename);
my %tmp_hash = %$tmp;
my %rhash = %$hash;
foreach my $key (sort keys %rhash) {
$tmp_hash{$key} = $rhash{$key};
}
$self->save_hash(\%tmp_hash, $filename);
return;
}
sub new
{
my $class = shift;
my $self = {};
bless $self, $class;
$self->{'lxc'} = new Lxc::object;
return $self;
}
1;
__END__
=head1 AUTHOR
Anatoly Burtsev, E<lt>anatolyburtsev@yandex.ruE<gt>
Pavel Potapenkov, E<lt>ppotapenkov@gmail.comE<gt>
Vladimir Smirnov, E<lt>civil.over@gmail.comE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2011 by Anatoly Burtsev, Pavel Potapenkov, Vladimir Smirnov
This library is free software; you can redistribute it and/or modify
it under the same terms of GPL v2 or later, or, at your opinion
under terms of artistic license.
=cut
|