#!/usr/bin/perl
use Astaro::ConfdPlRPC;   
use Data::Dumper;
use Storable qw( nstore ); 

if ( !defined($ARGV[0]) ) {
	print "fail: missing first parameter that is a directory in which RED objects are exported!\n";
} else {
	my $dir = $ARGV[0];
	my $sys = new Astaro::ConfdPlRPC(); 
	$sys->connect();

	print "writing objects ...\n";

	foreach my $obj (@{ $sys->get_objects(qw(itfhw red_server)) }) {
#		print Dumper( $obj );
		my $red_id = $obj->{data}->{'red_id'};
		print "\t$red_id\n";
		nstore $obj, "$dir/$red_id";
	}

	$sys->disconnect();
}
