From 85be16db455932e482eb021220da732e3097077c Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 16 Jan 2013 22:21:56 +0100 Subject: initial commit --- .gitignore | 7 +++++++ Makefile.PL | 14 ++++++++++++++ README | 18 ++++++++++++++++++ lib/VServer.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/VServer.pm diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67b1788 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +Makefile +META.yml +inc/ +*.bak +*.old +blib/ +pm_to_blib diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..bf6c23a --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,14 @@ +#!/usr/bin/perl + +use inc::Module::Install; + +# Define metadata +name 'VServer'; +all_from 'lib/VServer.pm'; +abstract 'Little perl helpers for handling linux-vserver.'; +author 'Alexander Sulfrian '; +license 'perl'; +resources + homepage => 'http://git.spline.inf.fu-berlin.de/vserver-monitoring/'; + +WriteAll; diff --git a/README b/README new file mode 100644 index 0000000..c4d2c1a --- /dev/null +++ b/README @@ -0,0 +1,18 @@ +Some little perl helpers to deal with linux-vserver guests. + +INSTALLATION + +To install it: + + perl Makefile.PL + make + make install + + +LICENSE INFORMATION + +VServer is Copyright (C) 2013, Alexander Sulfrian. + +This module is free software; you can redistribute it and/or +modify it under the same terms as Perl 5.10.0. For more details, +see the full text of the licenses in the directory LICENSES. diff --git a/lib/VServer.pm b/lib/VServer.pm new file mode 100644 index 0000000..8c70bde --- /dev/null +++ b/lib/VServer.pm @@ -0,0 +1,40 @@ +#!/usr/bin/perl -T + +package VServer; +our $VERSION = '1.0'; + +use strict; +use warnings; + +sub get_context_id($) { + my $vserver = shift; + if ($vserver =~ /^([-a-z0-9._]*)$/) { + $vserver = $1; + }; + + my $dir = "/etc/vservers/$vserver"; + return unless -d $dir; + + open(my $context, '<', "$dir/context") || return undef; + + my $cid = undef; + while (<$context>) { + if ($_ =~ m/([0-9]*)/) { + $cid = $1; + last; + } + } + + close $context; + return $cid; +} + +sub get_proc_dir($) { + my $context = shift; + my $dir = "/proc/virtual/$context/"; + + return $dir if (-d $dir); + return undef; +} + +1; -- cgit v1.2.3-1-g7c22