summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2010-12-02 19:21:24 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2010-12-02 19:21:24 -0800
commit983fdb9f5ec3319b1b7695cc5dffe585f708e501 (patch)
tree83045d4af933c30efc28a076f015d63ee64ed2a3
parent11b0a437451fcd39c6ab9a45ccd5bd35eb5f3cac (diff)
downloadvyatta-cfg-983fdb9f5ec3319b1b7695cc5dffe585f708e501.tar.gz
vyatta-cfg-983fdb9f5ec3319b1b7695cc5dffe585f708e501.zip
change "load" to use new backend loadFile implementation.
* export loadFile through perl API. * "load" operation is now handled by the backend library.
-rwxr-xr-xlib/Vyatta/Config.pm7
-rw-r--r--perl_dmod/Cstore/Cstore.xs8
-rwxr-xr-xscripts/vyatta-load-config.pl53
3 files changed, 38 insertions, 30 deletions
diff --git a/lib/Vyatta/Config.pm b/lib/Vyatta/Config.pm
index ed3095b..914230a 100755
--- a/lib/Vyatta/Config.pm
+++ b/lib/Vyatta/Config.pm
@@ -186,6 +186,13 @@ sub sessionChanged {
return $self->{_cstore}->sessionChanged();
}
+## loadFile()
+# "load" the specified file
+sub loadFile {
+ my ($self, $file) = @_;
+ return $self->{_cstore}->loadFile($file);
+}
+
######
# observers of the "effective" config.
# they can be used
diff --git a/perl_dmod/Cstore/Cstore.xs b/perl_dmod/Cstore/Cstore.xs
index 383f204..255eac0 100644
--- a/perl_dmod/Cstore/Cstore.xs
+++ b/perl_dmod/Cstore/Cstore.xs
@@ -325,3 +325,11 @@ OUTPUT:
RETVAL
+bool
+Cstore::loadFile(char *filename)
+CODE:
+ RETVAL = THIS->loadFile(filename);
+OUTPUT:
+ RETVAL
+
+
diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl
index fe119cf..92b556f 100755
--- a/scripts/vyatta-load-config.pl
+++ b/scripts/vyatta-load-config.pl
@@ -171,52 +171,45 @@ syslog( "warning", "Load config [$orig_load_file] by $login" );
# do config migration
system("$sbindir/vyatta_config_migrate.pl $load_file");
+# note: "load" is now handled in the backend so only "merge" is actually
+# handled in this script. "merge" hasn't been moved into the backend since
+# the command itself needs to be revisited after mendocino time frame.
print "Loading configuration from '$load_file'...\n";
-my %cfg_hier = Vyatta::ConfigLoad::loadConfigHierarchy($load_file,$merge);
-if ( scalar( keys %cfg_hier ) == 0 ) {
+my $cobj = new Vyatta::Config;
+if (!defined($merge)) {
+ # "load" => use backend through API
+ $cobj->loadFile($load_file);
+} else {
+ # "merge" => handled here
+ my %cfg_hier = Vyatta::ConfigLoad::loadConfigHierarchy($load_file,$merge);
+ if ( scalar( keys %cfg_hier ) == 0 ) {
print "The specified file does not contain any configuration.\n";
print
"Do you want to remove everything in the running configuration? [no] ";
my $resp = <STDIN>;
if ( !( $resp =~ /^yes$/i ) ) {
- print "Configuration not loaded\n";
- exit 1;
- }
-}
-
-my %cfg_diff = Vyatta::ConfigLoad::getConfigDiff(\%cfg_hier);
-my @set_list = @{ $cfg_diff{'set'} };
-
-if (!defined($merge)) {
- my @delete_list = @{ $cfg_diff{'delete'} };
-
- foreach (@delete_list) {
- my ( $cmd_ref, $rank ) = @{$_};
- my @cmd = ( "$sbindir/my_delete", @{$cmd_ref} );
- my $cmd_str = join ' ', @cmd;
- system("$cmd_str");
- if ( $? >> 8 ) {
- $cmd_str =~ s/^$sbindir\/my_//;
- print "\"$cmd_str\" failed\n";
- }
+ print "Configuration not loaded\n";
+ exit 1;
}
-}
+ }
-foreach (@set_list) {
+ my %cfg_diff = Vyatta::ConfigLoad::getConfigDiff(\%cfg_hier);
+ my @set_list = @{ $cfg_diff{'set'} };
+ foreach (@set_list) {
my ( $cmd_ref, $rank ) = @{$_};
my @cmd = ( "$sbindir/my_set", @{$cmd_ref} );
my $cmd_str = join ' ', @cmd;
system("$cmd_str");
if ( $? >> 8 ) {
- $cmd_str =~ s/^$sbindir\/my_//;
- print "\"$cmd_str\" failed\n";
+ $cmd_str =~ s/^$sbindir\/my_//;
+ print "\"$cmd_str\" failed\n";
}
+ }
}
-my $rc = system("cli-shell-api sessionChanged");
-if (defined $rc and $rc > 0) {
- print "No configuration changes to commit\n";
- exit 0;
+if (!($cobj->sessionChanged())) {
+ print "No configuration changes to commit\n";
+ exit 0;
}
print ("\n" . (defined($merge) ? 'Merge' : 'Load')