aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaarten Vanraes <alien@mageia.org>2016-02-10 20:52:27 +0100
committerMaarten Vanraes <alien@mageia.org>2016-05-14 09:25:23 +0200
commit6282d3572f41bd7e5df0602dc381f247ee8ac295 (patch)
tree5a6f24b5746d9d51e472b6caccf1fb5c565013e3
parentc0863b56d22a684521cc03ebb18bfee6b0d3aa89 (diff)
downloadmanatools-6282d3572f41bd7e5df0602dc381f247ee8ac295.tar
manatools-6282d3572f41bd7e5df0602dc381f247ee8ac295.tar.gz
manatools-6282d3572f41bd7e5df0602dc381f247ee8ac295.tar.bz2
manatools-6282d3572f41bd7e5df0602dc381f247ee8ac295.tar.xz
manatools-6282d3572f41bd7e5df0602dc381f247ee8ac295.zip
add a disk_backend class with a plugin structure
-rw-r--r--lib/ManaTools/Shared/disk_backend.pm595
-rw-r--r--lib/ManaTools/Shared/disk_backend/IO.pm120
-rw-r--r--lib/ManaTools/Shared/disk_backend/IOs.pm189
-rw-r--r--lib/ManaTools/Shared/disk_backend/Part.pm254
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin.pm243
-rw-r--r--lib/ManaTools/Shared/disk_backend/Plugin/README3
6 files changed, 1404 insertions, 0 deletions
diff --git a/lib/ManaTools/Shared/disk_backend.pm b/lib/ManaTools/Shared/disk_backend.pm
new file mode 100644
index 00000000..7159c667
--- /dev/null
+++ b/lib/ManaTools/Shared/disk_backend.pm
@@ -0,0 +1,595 @@
+# vim: set et ts=4 sw=4:
+package ManaTools::Shared::disk_backend;
+
+#============================================================= -*-perl-*-
+
+=head1 NAME
+
+ ManaTools::Shared::disk_backend - disks backend class
+
+=head1 SYNOPSIS
+
+ use ManaTools::Shared::disk_backend;
+
+ my $db_man = ManaTools::Shared::disk_backend->new();
+ $db_man->load();
+ $db_man->probe();
+ $db_man->findin($io);
+ $db_man->findout($io);
+ $db_man->findnoin();
+ $db_man->findnoout();
+ my @parts = $db_man->findpart($type);
+ my @ios = $db_man->findioprop($prop, $value);
+ ...
+ $db_man->save();
+ $db_man->mkio('Foo', {id => 'foo-id', other => 'value'});
+ $db_man->mkpart('Foo', {other => 'value'});
+
+
+=head1 DESCRIPTION
+
+ This plugin is a backend to manadisk
+
+=head1 SUPPORT
+
+ You can find documentation for this plugin with the perldoc command:
+
+ perldoc ManaTools::Shared::disk_backend
+
+
+=head1 AUTHOR
+
+ Maarten Vanraes <alien@rmail.be>
+
+=head1 COPYRIGHT and LICENSE
+
+Copyright (c) 2015 Maarten Vanraes <alien@rmail.be>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2, as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+=head1 METHODS
+
+=cut
+
+use Moose;
+
+use File::Basename;
+use Module::Path qw(module_path);
+
+
+has 'plugins' => (
+ is => 'ro',
+ isa => 'ArrayRef[ManaTools::Shared::disk_backend::Plugin]',
+ default => sub {
+ my $self = shift;
+ my $plugins = [];
+ my @more = ();
+ for my $pluginfile (glob((module_path($self->blessed()) =~ s/\.pm$//r ) ."/Plugin/*.pm")) {
+ my $pluginclass = "ManaTools::Shared::disk_backend::Plugin::". basename($pluginfile, '.pm');
+ require $pluginfile;
+ my $plugin = $pluginclass->new(parent => $self);
+ if ($self->_check_dependencies($plugins, @{$plugin->dependencies()})) {
+ push @{$plugins}, $plugin;
+ }
+ else {
+ push @more, $plugin;
+ }
+ }
+ # reorder the other plugins correctly according to dependencies
+ my $progress = 1;
+ while ($progress && scalar(@more) > 0) {
+ $progress = 0;
+ my $i = 0;
+ while ($i < scalar(@more)) {
+ if ($self->_check_dependencies($plugins, @{$more[$i]->dependencies()})) {
+ # move plugin from @more to $plugins
+ push @{$plugins}, $more[$i];
+ $progress = 1;
+ splice @more, $i, 1;
+ }
+ else {
+ $i = $i + 1;
+ }
+ }
+ }
+ return $plugins;
+ }
+);
+
+has 'ios' => (
+ is => 'rw',
+ isa =>'HashRef[ManaTools::Shared::disk_backend::IO]',
+ default => sub {
+ return {};
+ }
+);
+
+has 'parts' => (
+ is => 'rw',
+ isa =>'ArrayRef[ManaTools::Shared::disk_backend::Part]',
+ default => sub {
+ return [];
+ }
+);
+
+
+#=============================================================
+
+=head2 _check_dependencies
+
+=head3 OUTPUT
+
+ 1 if true, 0 otherwise
+
+=head3 DESCRIPTION
+
+ this method checks to see if plugins are already loaded
+
+=cut
+
+#=============================================================
+sub _check_dependencies {
+ my $self = shift;
+ my $plugins = shift;
+ while (my $plugin = shift) {
+ if (! grep { blessed($_) eq 'ManaTools::Shared::disk_backend::Plugin::'. $plugin } @{$plugins}) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+#=============================================================
+
+=head2 mkio
+
+=head3 OUTPUT
+
+ ManaTools::Shared::disk_backend::IO subclass
+
+=head3 DESCRIPTION
+
+ this method creates an IO and adds it to the list if it does not already exists, and returns the IO
+
+=cut
+
+#=============================================================
+sub mkio {
+ my $self = shift;
+ my $class = 'ManaTools::Shared::disk_backend::IO::'. shift;
+ my $parameters = shift;
+ defined($parameters->{'id'}) or die('id is a required parameter when creating IO');
+ my $id = $parameters->{'id'};
+ if (!defined($self->ios->{$id})) {
+ $self->ios->{$id} = $class->new(%$parameters);
+ $self->ios->{$id}->db($self);
+ $self->probeio($self->ios->{$id});
+ }
+ return $self->ios->{$id};
+}
+
+#=============================================================
+
+=head2 rmio
+
+=head3 INPUT
+
+ $io: ManaTools::Shared::disk_backend::IO subclass
+
+=head3 DESCRIPTION
+
+ this method removes a IO and returns the IO
+
+=cut
+
+#=============================================================
+sub rmio {
+ my $self = shift;
+ my $io = shift;
+ my $parts = $self->parts();
+ my $ios = $self->ios();
+ delete $ios->{$io->id()};
+ # walk parts and remove io from ins or outs
+ for my $part (@{$parts}) {
+ $part->rmio($io);
+ }
+ return $io;
+}
+
+#=============================================================
+
+=head2 mkpart
+
+=head3 OUTPUT
+
+ ManaTools::Shared::disk_backend::Part subclass
+
+=head3 DESCRIPTION
+
+ this method creates a Part and returns the Part
+
+=cut
+
+#=============================================================
+sub mkpart {
+ my $self = shift;
+ my $class = 'ManaTools::Shared::disk_backend::Part::'. shift;
+ my $parameters = shift;
+ my $part = $class->new(%$parameters);
+ $part->db($self);
+ push @{$self->parts}, $part;
+ return $part;
+}
+
+#=============================================================
+
+=head2 rmpart
+
+=head3 INPUT
+
+ $part: ManaTools::Shared::disk_backend::Part subclass
+
+=head3 DESCRIPTION
+
+ this method removes a Part and returns the Part
+
+=cut
+
+#=============================================================
+sub rmpart {
+ my $self = shift;
+ my $part = shift;
+ my $parts = $self->parts();
+ my $i = scalar(@{$parts});
+ while ($i >= 0) {
+ $i = $i - 1;
+ if ($parts->[$i] eq $part) {
+ splice @{$parts}, $i;
+ return $part;
+ }
+ }
+ return $part;
+}
+
+#=============================================================
+
+=head2 load
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this method loads the config files for all plugins
+
+=cut
+
+#=============================================================
+sub load {
+ my $self = shift;
+
+ for my $plugin (@{$self->plugins}) {
+ $plugin->load();
+ }
+ 1;
+}
+
+#=============================================================
+
+=head2 save
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this method saves the config files for all plugins
+
+=cut
+
+#=============================================================
+sub save {
+ my $self = shift;
+
+ for my $plugin (@{$self->plugins}) {
+ $plugin->save();
+ }
+ 1;
+}
+
+#=============================================================
+
+=head2 probe
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this method will call probe for all plugins and merge results of the probe
+
+=cut
+
+#=============================================================
+sub probe {
+ my $self = shift;
+
+ for my $plugin (@{$self->plugins}) {
+ $plugin->probe();
+ }
+ 1;
+}
+
+#=============================================================
+
+=head2 probeio
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this method will call probeio for all plugins and merge results of the probe
+
+=cut
+
+#=============================================================
+sub probeio {
+ my $self = shift;
+ my $io = shift;
+
+ for my $plugin (@{$self->plugins}) {
+ $plugin->probeio($io);
+ }
+ 1;
+}
+
+#=============================================================
+
+=head2 findin
+
+=head3 OUTPUT
+
+ array of Part
+
+=head3 DESCRIPTION
+
+ this method will return all Part that match on an in IO
+
+=cut
+
+#=============================================================
+sub findin {
+ my $self = shift;
+ my $io = shift;
+
+ return grep {grep {$io eq $_} $_->get_ins()} @{$self->parts};
+}
+
+#=============================================================
+
+=head2 findout
+
+=head3 OUTPUT
+
+ array of Part
+
+=head3 DESCRIPTION
+
+ this method will return all Part that match on an out IO
+
+=cut
+
+#=============================================================
+sub findout {
+ my $self = shift;
+ my $io = shift;
+
+ return grep {grep {$io eq $_} $_->get_outs()} @{$self->parts};
+}
+
+#=============================================================
+
+=head2 findnoin
+
+=head3 OUTPUT
+
+ array of Part
+
+=head3 DESCRIPTION
+
+ this method will return all Part that have no ins
+
+=cut
+
+#=============================================================
+sub findnoin {
+ my $self = shift;
+ my $io = shift;
+
+ return grep {$_->in_length() == 0} @{$self->parts};
+}
+
+#=============================================================
+
+=head2 findoutnoin
+
+=head3 OUTPUT
+
+ array of Part
+
+=head3 DESCRIPTION
+
+ this method will return all Part that have outs, but no ins
+
+=cut
+
+#=============================================================
+sub findoutnoin {
+ my $self = shift;
+ my $io = shift;
+
+ return grep {$_->in_length() == 0 && $_->out_length() > 0} @{$self->parts};
+}
+
+#=============================================================
+
+=head2 findnoout
+
+=head3 OUTPUT
+
+ array of Part
+
+=head3 DESCRIPTION
+
+ this method will return all Part that have no outs
+
+=cut
+
+#=============================================================
+sub findnoout {
+ my $self = shift;
+ my $io = shift;
+
+ return grep {$_->out_length() == 0} @{$self->parts};
+}
+
+#=============================================================
+
+=head2 findinnoout
+
+=head3 OUTPUT
+
+ array of Part
+
+=head3 DESCRIPTION
+
+ this method will return all Part that have ins, but no outs
+
+=cut
+
+#=============================================================
+sub findinnoout {
+ my $self = shift;
+ my $io = shift;
+
+ return grep {$_->out_length() == 0 && $_->in_length() > 0} @{$self->parts};
+}
+
+#=============================================================
+
+=head2 findpart
+
+=head3 OUTPUT
+
+ array of Part
+
+=head3 DESCRIPTION
+
+ this method will return all Part that match on a type
+
+=cut
+
+#=============================================================
+sub findpart {
+ my $self = shift;
+ my $type = shift;
+
+ return grep {$_->type() eq $type} @{$self->parts};
+}
+
+#=============================================================
+
+=head2 walkplugins
+
+=head3 INPUT
+
+ $code: CodeRef
+ ...
+
+=head3 OUTPUT
+
+ a Plugin or undef
+
+=head3 DESCRIPTION
+
+ this method will return the first matching Plugin
+
+=cut
+
+#=============================================================
+sub walkplugin {
+ my $self = shift;
+ my $code = shift;
+ my @parameters = @_;
+ my $plugins = $self->plugins;
+ for my $plugin (@{$plugins}) {
+ my $res = $code->($plugin, @parameters);
+ return $res if ($res);
+ }
+ return undef;
+}
+
+#=============================================================
+
+=head2 findioprop
+
+=head3 OUTPUT
+
+ array of IO
+
+=head3 DESCRIPTION
+
+ this method will return all IO that matches on a prop value
+
+=cut
+
+#=============================================================
+sub findioprop {
+ my $self = shift;
+ my $prop = shift;
+ my $value = shift;
+
+ return grep {$_->has_prop($prop) && $_->prop($prop) eq $value} values %{$self->ios};
+}
+
+#=============================================================
+
+=head2 findpartprop
+
+=head3 OUTPUT
+
+ array of Part
+
+=head3 DESCRIPTION
+
+ this method will return all Part that matches on a prop value and optionally a type
+
+=cut
+
+#=============================================================
+sub findpartprop {
+ my $self = shift;
+ my $type = shift;
+ my $prop = shift;
+ my $value = shift;
+
+ return grep {( !defined($type) || $type eq $_->type() ) && $_->has_prop($prop) && $_->prop($prop) eq $value} @{$self->parts};
+}
+
+1;
diff --git a/lib/ManaTools/Shared/disk_backend/IO.pm b/lib/ManaTools/Shared/disk_backend/IO.pm
new file mode 100644
index 00000000..a143e54b
--- /dev/null
+++ b/lib/ManaTools/Shared/disk_backend/IO.pm
@@ -0,0 +1,120 @@
+# vim: set et ts=4 sw=4:
+package ManaTools::Shared::disk_backend::IO;
+
+#============================================================= -*-perl-*-
+
+=head1 NAME
+
+ ManaTools::Shared::disk_backend::IO - IO class
+
+=head1 SYNOPSIS
+
+ use ManaTools::Shared::disk_backend::IO;
+
+ my $db_man = ManaTools::Shared::disk_backend::IO->new($id);
+ $db_man->label();
+ $db_man->id();
+
+
+=head1 DESCRIPTION
+
+ This is an abstract class for IO in the backend to manadisk
+
+=head1 SUPPORT
+
+ You can find documentation for this class with the perldoc command:
+
+ perldoc ManaTools::Shared::disk_backend::IO
+
+
+=head1 AUTHOR
+
+ Maarten Vanraes <alien@rmail.be>
+
+=head1 COPYRIGHT and LICENSE
+
+Copyright (c) 2015 Maarten Vanraes <alien@rmail.be>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2, as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+=head1 METHODS
+
+=cut
+
+use Moose;
+
+with 'ManaTools::Shared::PropertiesRole';
+
+## Class data
+has 'type' => (
+ is => 'ro',
+ isa => 'Str',
+ init_arg => undef,
+ lazy => 1,
+ default => 'IO'
+);
+
+## Object vars
+has 'db' => (
+ is => 'rw',
+ isa => 'ManaTools::Shared::disk_backend',
+ init_arg => undef,
+ lazy => 1,
+ default => undef,
+);
+
+has 'id' => (
+ is => 'ro',
+ isa => 'Str',
+ required => 1
+);
+
+#=============================================================
+
+=head2 label
+
+=head3 OUTPUT
+
+ label of the IO
+
+=head3 DESCRIPTION
+
+ this method returns the label for this IO
+
+=cut
+
+#=============================================================
+sub label {
+ my $self = shift;
+
+ return $self->type .' '. $self->id;
+}
+
+#=============================================================
+
+=head2 unhook
+
+=head3 DESCRIPTION
+
+ this method returns removes the IO from the parent and Parts
+
+=cut
+
+#=============================================================
+sub unhook {
+ my $self = shift;
+ $self->db->rmio($self);
+}
+
+1;
diff --git a/lib/ManaTools/Shared/disk_backend/IOs.pm b/lib/ManaTools/Shared/disk_backend/IOs.pm
new file mode 100644
index 00000000..5a6dfd30
--- /dev/null
+++ b/lib/ManaTools/Shared/disk_backend/IOs.pm
@@ -0,0 +1,189 @@
+# vim: set et ts=4 sw=4:
+package ManaTools::Shared::disk_backend::IOs;
+
+#============================================================= -*-perl-*-
+
+=head1 NAME
+
+ ManaTools::Shared::disk_backend::IOs - list of IOs
+
+=head1 SYNOPSIS
+
+ use ManaTools::Shared::disk_backend::IOs;
+
+ my $db_man = ManaTools::Shared::disk_backend::IOs->new(parent => $self, restriction => $restriction);
+ $db_man->append($io);
+ $db_man->remove($io);
+ $db_man->list();
+ $db_man->length();
+
+
+=head1 DESCRIPTION
+
+ This plugin is an collection of IOs in the backend to manadisk
+
+=head1 SUPPORT
+
+ You can find documentation for this plugin with the perldoc command:
+
+ perldoc ManaTools::Shared::disk_backend::IOs
+
+
+=head1 AUTHOR
+
+ Maarten Vanraes <alien@rmail.be>
+
+=head1 COPYRIGHT and LICENSE
+
+Copyright (c) 2015 Maarten Vanraes <alien@rmail.be>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2, as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+=head1 METHODS
+
+=cut
+
+use Moose;
+
+has 'parent' => (
+ is => 'ro',
+ isa => 'ManaTools::Shared::disk_backend::Part',
+ required => 1
+);
+has 'restriction' => (
+ traits => ['Code'],
+ is => 'ro',
+ isa => 'CodeRef',
+ required => 1,
+ handles => {
+ check => 'execute'
+ }
+);
+has 'ios' => (
+ is => 'ro',
+ isa => 'HashRef[ManaTools::Shared::disk_backend::IO]',
+ default => sub {return {};}
+);
+
+#=============================================================
+
+=head2 length
+
+=head3 OUTPUT
+
+ Int
+
+=head3 DESCRIPTION
+
+ this method returns the number of IOs
+
+=cut
+
+#=============================================================
+sub length {
+ my $self = shift;
+
+ return scalar(keys %{$self->ios});
+}
+
+#=============================================================
+
+=head2 list
+
+=head3 OUTPUT
+
+ array of the IOs
+
+=head3 DESCRIPTION
+
+ this method returns a list of IOs
+
+=cut
+
+#=============================================================
+sub list {
+ my $self = shift;
+
+ return values %{$self->ios};
+}
+
+#=============================================================
+
+=head2 append
+
+=head3 INPUT
+
+ $io: IO to add
+
+=head3 OUTPUT
+
+ 1 if success, 0 otherwise
+
+=head3 DESCRIPTION
+
+ this method appends an IO
+
+=cut
+
+#=============================================================
+sub append {
+ my $self = shift;
+ my $io = shift;
+
+ # check IO with restriction
+ if (defined $self->restriction) {
+ if (!$self->check($self->parent(), $io)) {
+ return 0;
+ }
+ }
+
+ $self->ios->{$io->id} = $io;
+}
+
+#=============================================================
+
+=head2 remove
+
+=head3 INPUT
+
+ $io: IO to remove
+
+=head3 OUTPUT
+
+ 1 if success, 0 otherwise
+
+=head3 DESCRIPTION
+
+ this method removes an IO
+
+=cut
+
+#=============================================================
+sub remove {
+ my $self = shift;
+ my $io = shift;
+
+ # check IO with restriction
+ if (defined $self->restriction) {
+ if (!$self->check($self->parent(), $io, 1)) {
+ return 0;
+ }
+ }
+
+ # remove the io
+ delete $self->ios->{$io->id};
+}
+
+1;
+
diff --git a/lib/ManaTools/Shared/disk_backend/Part.pm b/lib/ManaTools/Shared/disk_backend/Part.pm
new file mode 100644
index 00000000..b4ebbfa4
--- /dev/null
+++ b/lib/ManaTools/Shared/disk_backend/Part.pm
@@ -0,0 +1,254 @@
+# vim: set et ts=4 sw=4:
+package ManaTools::Shared::disk_backend::Part;
+
+#============================================================= -*-perl-*-
+
+=head1 NAME
+
+ ManaTools::Shared::disk_backend::Part - Part class
+
+=head1 SYNOPSIS
+ package ManaTools::Shared::disk_backend::Part::MBR;
+
+ extend 'ManaTools::Shared::disk_backend::Part';
+
+ has '+type', required => 0, default => 'MBR';
+ has '+in_restriction', default => sub { my ($self, $io)=@_; return ($self->in_length() < 1 && $io->type == 'disk');};
+ has '+out_restriction', default => sub { my ($self, $io)=@_; return ($self->out_length() < 4 && $io->type == 'partition');};
+
+ override('label', sub {
+ my $self = shift;
+ my $label = super;
+ if ($self->in_length < 1) {
+ return $label;
+ }
+ my @ins = $self->in_list();
+ return $label .= "(". $ins[0]->id() .")";
+ });
+
+ 1;
+
+ ...
+
+ my $mbr = ManaTools::Shared::disk_backend::Part::MBR->new();
+ $mbr->label(); // MBR(/dev/sda)
+ $mbr->get_ins();
+ $mbr->get_outs();
+ $mbr->out_add($io);
+ my $size = $mbr->prop('size');
+ $mbr->prop('size', '20G');
+ $mbr->action('format');
+
+
+=head1 DESCRIPTION
+
+ This is an abstract class for Part in the backend to manadisk
+
+=head1 SUPPORT
+
+ You can find documentation for this plugin with the perldoc command:
+
+ perldoc ManaTools::Shared::disk_backend::Part
+
+
+=head1 AUTHOR
+
+ Maarten Vanraes <alien@rmail.be>
+
+=head1 COPYRIGHT and LICENSE
+
+Copyright (c) 2015 Maarten Vanraes <alien@rmail.be>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2, as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+=head1 METHODS
+
+=cut
+
+use Moose;
+
+with 'ManaTools::Shared::ActionsRole', 'ManaTools::Shared::PropertiesRole';
+
+use ManaTools::Shared::disk_backend::IOs;
+
+## Class DATA
+has 'type' => (
+ is => 'ro',
+ init_arg => undef,
+ lazy => 1,
+ isa => 'Str',
+ default => 'Part'
+);
+has 'in_restriction' => (
+ is => 'ro',
+ init_arg => undef,
+ lazy => 1,
+ isa => 'Maybe[CodeRef]',
+ default => sub {
+ sub { return 1; }
+ }
+);
+has 'out_restriction' => (
+ is => 'ro',
+ init_arg => undef,
+ lazy => 1,
+ isa => 'Maybe[CodeRef]',
+ default => sub {
+ sub { return 1; }
+ }
+);
+
+## Object Variables
+has 'db' => (
+ is => 'rw',
+ isa => 'ManaTools::Shared::disk_backend',
+ init_arg => undef,
+ lazy => 1,
+ default => undef,
+);
+
+has 'ins' => (
+ is => 'ro',
+ isa => 'ManaTools::Shared::disk_backend::IOs',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ return ManaTools::Shared::disk_backend::IOs->new(parent => $self, restriction => $self->in_restriction);
+ },
+ handles => {
+ in_length => 'length',
+ in_list => 'list',
+ in_add => 'append'
+ }
+);
+has 'outs' => (
+ is => 'ro',
+ isa => 'ManaTools::Shared::disk_backend::IOs',
+ lazy => 1,
+ default => sub {
+ my $self = shift;
+ return ManaTools::Shared::disk_backend::IOs->new(parent => $self, restriction => $self->out_restriction);
+ },
+ handles => {
+ out_length => 'length',
+ out_list => 'list',
+ out_add => 'append'
+ }
+);
+
+#=============================================================
+
+=head2 label
+
+=head3 OUTPUT
+
+ label of the IO
+
+=head3 DESCRIPTION
+
+ this method returns the label for this IO
+
+=cut
+
+#=============================================================
+sub label {
+ my $self = shift;
+
+ return $self->type;
+}
+
+#=============================================================
+
+=head2 get_ins
+
+=head3 OUTPUT
+
+ array of the in IOs
+
+=head3 DESCRIPTION
+
+ this method returns the in IOs
+
+=cut
+
+#=============================================================
+sub get_ins {
+ my $self = shift;
+
+ return $self->ins->list();
+}
+
+#=============================================================
+
+=head2 get_outs
+
+=head3 OUTPUT
+
+ array of the out IOs
+
+=head3 DESCRIPTION
+
+ this method returns the out IOs
+
+=cut
+
+#=============================================================
+sub get_outs {
+ my $self = shift;
+
+ return $self->outs->list();
+}
+
+#=============================================================
+
+=head2 rmio
+
+=head3 INPUT
+
+ $io: ManaTools::Shared::disk_backend::IO
+
+=head3 DESCRIPTION
+
+ this method returns removes the IO from the Part
+
+=cut
+
+#=============================================================
+sub rmio {
+ my $self = shift;
+ my $io = shift;
+ my $ins = $self->ins();
+ my $outs = $self->outs();
+ # remove io from ins and outs
+ $ins->remove($io);
+ $outs->remove($io);
+}
+
+#=============================================================
+
+=head2 unhook
+
+=head3 DESCRIPTION
+
+ this method returns removes the Part from the parent
+
+=cut
+
+#=============================================================
+sub unhook {
+ my $self = shift;
+ $self->db->rmpart($self);
+}
+
+1;
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin.pm b/lib/ManaTools/Shared/disk_backend/Plugin.pm
new file mode 100644
index 00000000..e38553a5
--- /dev/null
+++ b/lib/ManaTools/Shared/disk_backend/Plugin.pm
@@ -0,0 +1,243 @@
+# vim: set et ts=4 sw=4:
+package ManaTools::Shared::disk_backend::Plugin;
+
+#============================================================= -*-perl-*-
+
+=head1 NAME
+
+ ManaTools::Shared::disk_backend::Plugin - disks object
+
+=head1 SYNOPSIS
+
+ package ManaTools::Shared::disk_backend::Plugin::Foo;
+ use Moose;
+
+ extend 'ManaTools::Shared::disk_backend::Plugin';
+
+ override('load', sub {
+ ...
+ });
+
+ override('save', sub {
+ ...
+ });
+
+ override('probe', sub {
+ ...
+ });
+
+ override('probeio', sub {
+ ...
+ });
+
+ 1;
+
+ package ManaTools::Shared::disk_backend::IO::Bar;
+ use Moose;
+
+ extend 'ManaTools::Shared::disk_backend::IO';
+
+ has '+type', default => 'bar';
+
+ ...
+
+ 1;
+
+ package ManaTools::Shared::disk_backend::Part::Baz;
+ use Moose;
+
+ extend 'ManaTools::Shared::disk_backend::Part';
+
+ has '+type', default => 'baz';
+ has '+in_restriction', default => sub { ... };
+ has '+out_restriction', default => sub { ... };
+
+ ...
+
+ 1;
+
+=head1 DESCRIPTION
+
+ This plugin is a abstract plugin for the backend to manadisk
+
+=head1 SUPPORT
+
+ You can find documentation for this plugin with the perldoc command:
+
+ perldoc ManaTools::Shared::disk_backend::Plugin
+
+
+=head1 AUTHOR
+
+ Maarten Vanraes <alien@rmail.be>
+
+=head1 COPYRIGHT and LICENSE
+
+Copyright (c) 2015 Maarten Vanraes <alien@rmail.be>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License version 2, as
+published by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+=head1 METHODS
+
+=cut
+
+use Moose;
+
+## class DATA
+has 'dependencies' => (
+ is => 'ro',
+ init_arg => undef,
+ isa => 'ArrayRef[Str]',
+ lazy => 1,
+ default => sub {
+ return [];
+ }
+);
+
+has 'parent' => (
+ is => 'ro',
+ isa => 'ManaTools::Shared::disk_backend',
+ required => 1
+);
+
+#=============================================================
+
+=head2 load
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this is a default method for loading Part's, the idea is to override it if needed
+
+=cut
+
+#=============================================================
+sub load {
+ my $self = shift;
+
+ 1;
+}
+
+#=============================================================
+
+=head2 save
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this is a default method for saving Part's, the idea is to override it if needed
+
+=cut
+
+#=============================================================
+sub save {
+ my $self = shift;
+
+ 1;
+}
+
+#=============================================================
+
+=head2 probe
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this is a default method for probing IO's and/or Part's, the idea is to override it if needed
+
+=cut
+
+#=============================================================
+sub probe {
+ my $self = shift;
+
+ 1;
+}
+
+#=============================================================
+
+=head2 loadio
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this is a default method for loading a Part from a specific IO, the idea is to override it if needed
+
+=cut
+
+#=============================================================
+sub loadio {
+ my $self = shift;
+ my $io = shift;
+
+ 1;
+}
+
+#=============================================================
+
+=head2 savepart
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this is a default method for saving a specific Part, the idea is to override it if needed
+
+=cut
+
+#=============================================================
+sub savepart {
+ my $self = shift;
+ my $part = shift;
+
+ 1;
+}
+
+#=============================================================
+
+=head2 probeio
+
+=head3 OUTPUT
+
+ 0 if failed, 1 if success
+
+=head3 DESCRIPTION
+
+ this is a default method for probing specific a specific IO, the idea is to override it if needed
+
+=cut
+
+#=============================================================
+sub probeio {
+ my $self = shift;
+ my $io = shift;
+
+ 1;
+}
+
+1;
diff --git a/lib/ManaTools/Shared/disk_backend/Plugin/README b/lib/ManaTools/Shared/disk_backend/Plugin/README
new file mode 100644
index 00000000..3ca9e07a
--- /dev/null
+++ b/lib/ManaTools/Shared/disk_backend/Plugin/README
@@ -0,0 +1,3 @@
+This directory is for placing disk backend plugins subclassed from ManaTools::Shared::disk_backend::Plugin
+
+they should have IO subclasses or Part subclasses or both with some functions to handle Plugin load/probe/save/...