vcl-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arku...@apache.org
Subject svn commit: r1646885 - in /vcl/trunk/managementnode/lib/VCL: ./ Module/OS/ Module/OS/Linux/ Module/OS/Linux/firewall/ Module/OS/Linux/init/
Date Fri, 19 Dec 2014 21:45:40 GMT
Author: arkurth
Date: Fri Dec 19 21:45:40 2014
New Revision: 1646885

URL: http://svn.apache.org/r1646885
Log:
VCL-174
Fixed recusion problem with Linux init and firewall modules. They can't call $self->sub
directly to access the OS. Instead, $self->os->sub must be called.

Added firewall.pm which iptables.pm inherits from.

Fixed recursion issue in utils.pm::get_computer_nathost_info if the computer and NAT host
are the same computer.

Added:
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall.pm   (with props)
Modified:
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init.pm
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/SysV.pm
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/Upstart.pm
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/systemd.pm
    vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm?rev=1646885&r1=1646884&r2=1646885&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Fri Dec 19 21:45:40 2014
@@ -164,7 +164,12 @@ sub get_init_modules {
 		# initialize will check the computer to determine if it contains the corresponding Linux
init daemon installed
 		# If not installed, the constructor will return false
 		my $init;
-		eval { $init = ($init_perl_package)->new({data_structure => $self->data, os =>
$self, mn_os => $self->mn_os, base_package => ref($self)}) };
+		eval { $init = ($init_perl_package)->new({
+					data_structure => $self->data,
+					os => $self,
+					mn_os => $self->mn_os,
+					init_modules => $self->{init_modules},
+		}) };
 		if ($init) {
 			my @required_commands = eval "@" . $init_perl_package . "::REQUIRED_COMMANDS";
 			if ($EVAL_ERROR) {
@@ -269,7 +274,11 @@ sub firewall {
 		# Attempt to create the object
 		my $firewall_object;
 		eval {
-			$firewall_object = ($firewall_perl_package)->new({data_structure => $self->data,
base_package => ref($self), os => $self->os})
+			$firewall_object = ($firewall_perl_package)->new({
+				data_structure => $self->data,
+				os => $self,
+				mn_os => $self->mn_os,
+			})
 		};
 		
 		if ($EVAL_ERROR) {
@@ -3158,11 +3167,11 @@ sub enable_service {
 	}
 	
 	my $init_module = ($self->get_init_modules())[$init_module_index];
-	if (!$init_module->can('_enable_service')) {
-		notify($ERRORS{'WARNING'}, 0, "unable to enable '$service_name' service on $computer_node_name,
" . ref($init_module) . " module does not implement an '_enable_service' subroutine");
+	if (!$init_module->can('enable_service')) {
+		notify($ERRORS{'WARNING'}, 0, "unable to enable '$service_name' service on $computer_node_name,
" . ref($init_module) . " module does not implement an 'enable_service' subroutine");
 		return;
 	}
-	return $init_module->_enable_service($service_name);
+	return $init_module->enable_service($service_name);
 }
 
 #/////////////////////////////////////////////////////////////////////////////
@@ -3197,11 +3206,11 @@ sub disable_service {
 	}
 	
 	my $init_module = ($self->get_init_modules())[$init_module_index];
-	if (!$init_module->can('_disable_service')) {
-		notify($ERRORS{'WARNING'}, 0, "unable to disable '$service_name' service on $computer_node_name,
" . ref($init_module) . " module does not implement an '_disable_service' subroutine");
+	if (!$init_module->can('disable_service')) {
+		notify($ERRORS{'WARNING'}, 0, "unable to disable '$service_name' service on $computer_node_name,
" . ref($init_module) . " module does not implement an 'disable_service' subroutine");
 		return;
 	}
-	return $init_module->_disable_service($service_name);
+	return $init_module->disable_service($service_name);
 }
 
 #/////////////////////////////////////////////////////////////////////////////

Added: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall.pm?rev=1646885&view=auto
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall.pm (added)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall.pm Fri Dec 19 21:45:40 2014
@@ -0,0 +1,69 @@
+#!/usr/bin/perl -w
+###############################################################################
+# $Id$
+###############################################################################
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###############################################################################
+
+=head1 NAME
+
+VCL::Module::OS::Linux::firewall
+
+=head1 DESCRIPTION
+
+ This module is the parent class for the Linux firewall modules.
+
+=cut
+
+##############################################################################
+package VCL::Module::OS::Linux::firewall;
+
+# Specify the lib path using FindBin
+use FindBin;
+use lib "$FindBin::Bin/../../../..";
+
+# Configure inheritance
+# Do not inherit from OS.pm or Linux.pm - force the use of $self->os
+use base qw(VCL::Module);
+
+# Specify the version of this module
+our $VERSION = '2.3';
+
+# Specify the version of Perl to use
+use 5.008000;
+
+use strict;
+use warnings;
+use diagnostics;
+
+use VCL::utils;
+
+##############################################################################
+
+=head1 OBJECT METHODS
+
+=cut
+
+#/////////////////////////////////////////////////////////////////////////////
+
+1;
+__END__
+
+=head1 SEE ALSO
+
+L<http://cwiki.apache.org/VCL/>
+
+=cut

Propchange: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall.pm
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm?rev=1646885&r1=1646884&r2=1646885&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/firewall/iptables.pm Fri Dec 19 21:45:40
2014
@@ -36,7 +36,7 @@ use FindBin;
 use lib "$FindBin::Bin/../../../../..";
 
 # Configure inheritance
-use base qw(VCL::Module::OS::Linux);
+use base qw(VCL::Module::OS::Linux::firewall);
 
 # Specify the version of this module
 our $VERSION = '2.3';
@@ -77,19 +77,11 @@ sub initialize {
 	
 	my $arguments = shift || {};
 	
-	# Check if base_package argument was specified
-	# This is necessary for ManagementNode OS objects to work
-	# Otherwise the base Linux.pm subroutines would be used instead of ManagementNode.pm
-	if (defined($arguments->{base_package})) {
-		notify($ERRORS{'DEBUG'}, 0, "overriding object package: " . $ISA[0] . " --> $arguments->{base_package}");
-		@ISA = ($arguments->{base_package});
-	}
-	
 	my $computer_name = $self->data->get_computer_hostname();
 	
 	notify($ERRORS{'DEBUG'}, 0, "initializing " . ref($self) . " object to control $computer_name");
 	
-	if (!$self->command_exists('iptables')) {
+	if (!$self->os->command_exists('iptables')) {
 		notify($ERRORS{'DEBUG'}, 0, ref($self) . " object not initialized to control $computer_name,
iptables command does not exist");
 		return 0;
 	}
@@ -175,7 +167,7 @@ sub insert_rule {
 		}
 	}
 	
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command $computer_name: $command");
 		return;
@@ -277,7 +269,7 @@ sub delete_rule {
 		$command .= " -D $chain_name -t $table_name $specification";
 	}
 	
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command $computer_name: $command");
 		return;
@@ -323,7 +315,7 @@ sub create_chain {
 	my $computer_name = $self->data->get_computer_hostname();
 	
 	my $command = "/sbin/iptables --new-chain $chain_name --table $table_name";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command $computer_name: $command");
 		return;
@@ -392,7 +384,7 @@ sub delete_chain {
 	}
 	
 	my $command = "/sbin/iptables --delete-chain $chain_name --table $table_name";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command $computer_name: $command");
 		return;
@@ -495,7 +487,7 @@ sub flush_chain {
 	}
 	$command .= " --table $table_name";
 	
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command $computer_name: $command");
 		return;
@@ -543,7 +535,7 @@ sub get_table_info {
 	}
 	$command .= " --table $table_name";
 	
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command $computer_name: $command");
 		return;
@@ -611,7 +603,7 @@ sub configure_nat {
 	}
 	
 	# Enable IP port forwarding
-	if (!$self->enable_ip_forwarding()) {
+	if (!$self->os->enable_ip_forwarding()) {
 		notify($ERRORS{'WARNING'}, 0, "unable to configure NAT host $computer_name, failed to enable
IP forwarding");
 		return;
 	}
@@ -644,7 +636,7 @@ sub configure_nat {
 	my $public_subnet_mask;
 	my $internal_subnet_mask;
 	
-	my $network_configuration = $self->get_network_configuration();
+	my $network_configuration = $self->os->get_network_configuration();
 	for my $interface_name (keys %$network_configuration) {
 		my @ip_addresses = keys %{$network_configuration->{$interface_name}{ip_address}};
 		
@@ -887,8 +879,8 @@ sub add_nat_port_forward {
 	
 	$protocol = lc($protocol);
 	
-	my $public_interface_name = $self->get_public_interface_name();
-	my $public_ip_address = $self->get_public_ip_address();
+	my $public_interface_name = $self->os->get_public_interface_name();
+	my $public_ip_address = $self->os->get_public_ip_address();
 	
 	if ($self->insert_rule({
 		'table' => 'nat',

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init.pm?rev=1646885&r1=1646884&r2=1646885&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init.pm Fri Dec 19 21:45:40 2014
@@ -36,13 +36,12 @@ use FindBin;
 use lib "$FindBin::Bin/../../../..";
 
 # Configure inheritance
-use base qw(VCL::Module::OS::Linux);
+# Do not inherit from OS.pm or Linux.pm - force the use of $self->os
+use base qw(VCL::Module);
 
 # Specify the version of this module
 our $VERSION = '2.3';
 
-our @ISA;
-
 # Specify the version of Perl to use
 use 5.008000;
 
@@ -60,36 +59,6 @@ use VCL::utils;
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 initialize
-
- Parameters  : 
- Returns     : boolean
- Description : 
-
-=cut
-
-sub initialize {
-	my $self = shift;
-	if (ref($self) !~ /linux/i) {
-		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
-		return;
-	}
-	
-	my $arguments = shift || {};
-	
-	# Check if base_package argument was specified
-	# This is necessary for ManagementNode OS objects to work
-	# Otherwise the base Linux.pm subroutines would be used instead of ManagementNode.pm
-	if (defined($arguments->{base_package})) {
-		notify($ERRORS{'DEBUG'}, 0, "overriding object package: " . $ISA[0] . " --> $arguments->{base_package}");
-		@ISA = ($arguments->{base_package});
-	}
-	
-	return 1;
-}
-
-#/////////////////////////////////////////////////////////////////////////////
-
 1;
 __END__
 

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/SysV.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/SysV.pm?rev=1646885&r1=1646884&r2=1646885&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/SysV.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/SysV.pm Fri Dec 19 21:45:40 2014
@@ -112,7 +112,7 @@ sub get_service_names {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "chkconfig --list";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to list SysV services on $computer_node_name");
 		return;
@@ -132,7 +132,7 @@ sub get_service_names {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 _enable_service
+=head2 enable_service
 
  Parameters  : $service_name
  Returns     : boolean
@@ -141,7 +141,7 @@ sub get_service_names {
 
 =cut
 
-sub _enable_service {
+sub enable_service {
 	my $self = shift;
 	if (ref($self) !~ /VCL::Module/i) {
 		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
@@ -158,7 +158,7 @@ sub _enable_service {
 	
 	# Enable the service
 	my $command = "chkconfig $service_name on";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to enable '$service_name' service
on $computer_node_name: $command");
 		return;
@@ -181,7 +181,7 @@ sub _enable_service {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 _disable_service
+=head2 disable_service
 
  Parameters  : $service_name
  Returns     : boolean
@@ -190,7 +190,7 @@ sub _enable_service {
 
 =cut
 
-sub _disable_service {
+sub disable_service {
 	my $self = shift;
 	if (ref($self) !~ /VCL::Module/i) {
 		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
@@ -207,7 +207,7 @@ sub _disable_service {
 	
 	# Disable the service
 	my $command = "chkconfig $service_name off";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to disable '$service_name' service
on $computer_node_name: $command");
 		return;
@@ -255,7 +255,7 @@ sub service_enabled {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "chkconfig --list $service_name";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to determine if '$service_name'
service is enabled on $computer_node_name: $command");
 		return;
@@ -309,7 +309,7 @@ sub service_running {
 	
 	# Enable the service
 	my $command = "service $service_name status";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to determine if '$service_name'
service is running on $computer_node_name: $command");
 		return;
@@ -364,7 +364,7 @@ sub add_service {
 	
 	# Add the service
 	my $command = "chkconfig --add $service_name";
-	my ($exit_status, $output) = $self->execute($command);
+	my ($exit_status, $output) = $self->os->execute($command);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to add '$service_name' service
on $computer_node_name");
 		return;
@@ -408,7 +408,7 @@ sub delete_service {
 	
 	# Delete the service
 	my $command = "chkconfig --del $service_name";
-	my ($exit_status, $output) = $self->execute($command);
+	my ($exit_status, $output) = $self->os->execute($command);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to delete '$service_name' service
on $computer_node_name");
 		return;
@@ -424,7 +424,7 @@ sub delete_service {
 	
 	# Delete the service configuration file
 	my $service_file_path = "/etc/rc.d/init.d/$service_name";
-	if (!$self->delete_file($service_file_path)) {
+	if (!$self->os->delete_file($service_file_path)) {
 		return;
 	}
 	
@@ -458,7 +458,7 @@ sub start_service {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "service $service_name start";
-	my ($exit_status, $output) = $self->execute($command);
+	my ($exit_status, $output) = $self->os->execute($command);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to start '$service_name' service
on $computer_node_name");
 		return;
@@ -503,7 +503,7 @@ sub stop_service {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "service $service_name status ; service $service_name stop";
-	my ($exit_status, $output) = $self->execute($command);
+	my ($exit_status, $output) = $self->os->execute($command);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to stop '$service_name' service
on $computer_node_name");
 		return;
@@ -553,7 +553,7 @@ sub restart_service {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "service $service_name restart";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to restart '$service_name' service
on $computer_node_name");
 		return;
@@ -600,7 +600,7 @@ sub add_ext_sshd_service {
 	my $ext_sshd_config_file_path       = '/etc/ssh/external_sshd_config';
 	
 	# Get the contents of the sshd service startup file already on the computer
-	my @sshd_service_file_lines = $self->get_file_contents($sshd_service_file_path);
+	my @sshd_service_file_lines = $self->os->get_file_contents($sshd_service_file_path);
 	if (!@sshd_service_file_lines) {
 		notify($ERRORS{'WARNING'}, 0, "failed to retrieve contents of $sshd_service_file_path from
$computer_node_name");
 		return;
@@ -641,11 +641,11 @@ sub add_ext_sshd_service {
 	# Check if any changes were made to the original sshd file
 	if ($sshd_service_file_contents_updated ne $sshd_service_file_contents_original) {
 		# Save a copy of the original sshd file if the backup doesn't already exist
-		if (!$self->file_exists($sshd_service_file_path_original)) {
-			$self->copy_file($sshd_service_file_path, $sshd_service_file_path_original);
+		if (!$self->os->file_exists($sshd_service_file_path_original)) {
+			$self->os->copy_file($sshd_service_file_path, $sshd_service_file_path_original);
 		}
 		
-		if (!$self->create_text_file($sshd_service_file_path, $sshd_service_file_contents_updated))
{
+		if (!$self->os->create_text_file($sshd_service_file_path, $sshd_service_file_contents_updated))
{
 			notify($ERRORS{'WARNING'}, 0, "failed to update sshd service file on $computer_node_name:
$sshd_service_file_path");
 		}
 	}
@@ -653,12 +653,12 @@ sub add_ext_sshd_service {
 		notify($ERRORS{'DEBUG'}, 0, "sshd service file on $computer_node_name does not need to
be updated");
 	}
 	
-	if (!$self->create_text_file($ext_sshd_service_file_path, $ext_sshd_service_file_contents))
{
+	if (!$self->os->create_text_file($ext_sshd_service_file_path, $ext_sshd_service_file_contents))
{
 		notify($ERRORS{'WARNING'}, 0, "failed to create ext_sshd service file on $computer_node_name:
$ext_sshd_service_file_path");
 		return;
 	}
 	
-	if (!$self->set_file_permissions($ext_sshd_service_file_path, '755')) {
+	if (!$self->os->set_file_permissions($ext_sshd_service_file_path, '755')) {
 		notify($ERRORS{'WARNING'}, 0, "failed to set permissions on ext_sshd service file to 755
on $computer_node_name: $ext_sshd_service_file_path");
 		return;
 	}
@@ -666,7 +666,7 @@ sub add_ext_sshd_service {
 	# Add the service
 	return unless $self->add_service('ext_sshd');
 	
-	return $self->_enable_service('ext_sshd');
+	return $self->enable_service('ext_sshd');
 }
 
 #/////////////////////////////////////////////////////////////////////////////

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/Upstart.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/Upstart.pm?rev=1646885&r1=1646884&r2=1646885&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/Upstart.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/Upstart.pm Fri Dec 19 21:45:40 2014
@@ -123,7 +123,7 @@ sub get_service_names {
 	my $service_info = {};
 	
 	my $command = "initctl list";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to list Upstart services on $computer_node_name");
 		return;
@@ -186,7 +186,7 @@ sub delete_service {
 		
 		# Delete the service configuration file
 		my $service_file_path = "/etc/init/$service_name.conf";
-		$self->delete_file($service_file_path) || return;
+		$self->os->delete_file($service_file_path) || return;
 		
 		notify($ERRORS{'DEBUG'}, 0, "deleted '$service_name' service on $computer_node_name");
 	}
@@ -221,7 +221,7 @@ sub start_service {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "initctl start $service_name";
-	my ($exit_status, $output) = $self->execute($command);
+	my ($exit_status, $output) = $self->os->execute($command);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to start '$service_name' service
on $computer_node_name");
 		return;
@@ -282,7 +282,7 @@ sub stop_service {
 	
 	for my $service_name (@service_names) {
 		my $command = "initctl stop $service_name";
-		my ($exit_status, $output) = $self->execute($command);
+		my ($exit_status, $output) = $self->os->execute($command);
 		if (!defined($output)) {
 			notify($ERRORS{'WARNING'}, 0, "failed to execute command to stop '$service_name' service
on $computer_node_name");
 			return;
@@ -337,7 +337,7 @@ sub restart_service {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "initctl restart $service_name";
-	my ($exit_status, $output) = $self->execute($command);
+	my ($exit_status, $output) = $self->os->execute($command);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to restart '$service_name' service
on $computer_node_name");
 		return;
@@ -388,7 +388,7 @@ sub add_ext_sshd_service {
 	my $ext_sshd_config_file_path = '/etc/ssh/external_sshd_config';
 	
 	# Get the contents of the sshd service startup file already on the computer
-	my @sshd_service_file_contents = $self->get_file_contents($sshd_service_file_path);
+	my @sshd_service_file_contents = $self->os->get_file_contents($sshd_service_file_path);
 	if (!@sshd_service_file_contents) {
 		notify($ERRORS{'WARNING'}, 0, "failed to retrieve contents of $sshd_service_file_path from
$computer_node_name");
 		return;
@@ -408,12 +408,12 @@ sub add_ext_sshd_service {
 	# Replace /var/run/sshd --> /var/run/ext_sshd
 	$ext_sshd_service_file_contents =~ s|(/var/run/)sshd|$1ext_sshd|g;
 	
-	if (!$self->create_text_file($ext_sshd_service_file_path, $ext_sshd_service_file_contents))
{
+	if (!$self->os->create_text_file($ext_sshd_service_file_path, $ext_sshd_service_file_contents))
{
 		notify($ERRORS{'WARNING'}, 0, "failed to create ext_sshd service file on $computer_node_name:
$ext_sshd_service_file_path");
 		return;
 	}
 	
-	if (!$self->set_file_permissions($ext_sshd_service_file_path, '644')) {
+	if (!$self->os->set_file_permissions($ext_sshd_service_file_path, '644')) {
 		notify($ERRORS{'WARNING'}, 0, "failed to set permissions on ext_sshd service file to 644
on $computer_node_name: $ext_sshd_service_file_path");
 		return;
 	}
@@ -449,7 +449,7 @@ sub service_running {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "initctl status $service_name";
-	my ($exit_status, $output) = $self->execute($command);
+	my ($exit_status, $output) = $self->os->execute($command);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to determine if '$service_name'
service is enabled on $computer_node_name");
 		return;
@@ -504,8 +504,8 @@ sub service_enabled {
 	
 	# Check if an override file exists and contains 'manual'
 	my $service_override_file_path = "/etc/init/$service_name.override";
-	if ($self->file_exists($service_override_file_path)) {
-		my @override_file_contents = $self->get_file_contents($service_override_file_path);
+	if ($self->os->file_exists($service_override_file_path)) {
+		my @override_file_contents = $self->os->get_file_contents($service_override_file_path);
 		if (!@override_file_contents) {
 			notify($ERRORS{'WARNING'}, 0, "failed to retrieve contents of $service_override_file_path
from $computer_node_name");
 		}
@@ -518,7 +518,7 @@ sub service_enabled {
 	}
 	
 	my $command = "initctl show-config $service_name";
-	my ($exit_status, $output) = $self->execute($command);
+	my ($exit_status, $output) = $self->os->execute($command);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to determine if '$service_name'
service is enabled on $computer_node_name");
 		return;
@@ -551,7 +551,7 @@ sub service_enabled {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 _enable_service
+=head2 enable_service
 
  Parameters  : $service_name
  Returns     : boolean
@@ -559,7 +559,7 @@ sub service_enabled {
 
 =cut
 
-sub _enable_service {
+sub enable_service {
 	my $self = shift;
 	if (ref($self) !~ /linux/i) {
 		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
@@ -577,10 +577,10 @@ sub _enable_service {
 	
 	my $service_override_file_path = "/etc/init/$service_name.override";
 	
-	if (!$self->file_exists($service_override_file_path)) {
+	if (!$self->os->file_exists($service_override_file_path)) {
 		return 1;
 	}
-	if ($self->delete_file($service_override_file_path)) {
+	if ($self->os->delete_file($service_override_file_path)) {
 		return 1;
 	}
 	else {
@@ -591,7 +591,7 @@ sub _enable_service {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 _disable_service
+=head2 disable_service
 
  Parameters  : $service_name
  Returns     : boolean
@@ -599,7 +599,7 @@ sub _enable_service {
 
 =cut
 
-sub _disable_service {
+sub disable_service {
 	my $self = shift;
 	if (ref($self) !~ /linux/i) {
 		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
@@ -617,7 +617,7 @@ sub _disable_service {
 	
 	my $service_override_file_path = "/etc/init/$service_name.override";
 	
-	if ($self->create_text_file($service_override_file_path, "manual\n")) {
+	if ($self->os->create_text_file($service_override_file_path, "manual\n")) {
 		return 1;
 	}
 	else {

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/systemd.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/systemd.pm?rev=1646885&r1=1646884&r2=1646885&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/systemd.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/init/systemd.pm Fri Dec 19 21:45:40 2014
@@ -106,10 +106,10 @@ sub get_service_names {
 		return;
 	}
 	
-	my $computer_node_name   = $self->data->get_computer_node_name();
+	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "systemctl --no-pager list-unit-files";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to retrieve systemd service names
on $computer_node_name");
 		return;
@@ -130,6 +130,42 @@ sub get_service_names {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 service_exists
+
+ Parameters  : $service_name
+ Returns     : boolean
+ Description : Determines if a service controlled by systemd exists on the
+               computer.
+
+=cut
+
+sub service_exists {
+	my $self = shift;
+	if (ref($self) !~ /linux/i) {
+		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
+		return;
+	}
+	my ($service_name) = @_;
+	if (!defined($service_name)) {
+		notify($ERRORS{'WARNING'}, 0, "service name argument was not supplied");
+		return;
+	}
+	
+	my $computer_node_name = $self->data->get_computer_node_name();
+	
+	my @service_names = $self->get_service_names();
+	if (grep { $_ eq $service_name } @service_names) {
+		notify($ERRORS{'DEBUG'}, 0, "$service_name service exists on $computer_node_name");
+		return 1;
+	}
+	else {
+		notify($ERRORS{'DEBUG'}, 0, "$service_name service does not exist on $computer_node_name");
+		return 0;
+	}
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 service_running
 
  Parameters  : $service_name
@@ -155,7 +191,7 @@ sub service_running {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "systemctl is-active $service_name.service";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to determine if $service_name
service is running on $computer_node_name");
 		return;
@@ -203,7 +239,7 @@ sub service_enabled {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "systemctl is-enabled $service_name.service";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to determine if $service_name
service is running on $computer_node_name");
 		return;
@@ -226,7 +262,7 @@ sub service_enabled {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 _enable_service
+=head2 enable_service
 
  Parameters  : $service_name
  Returns     : boolean
@@ -235,7 +271,7 @@ sub service_enabled {
 
 =cut
 
-sub _enable_service {
+sub enable_service {
 	my $self = shift;
 	if (ref($self) !~ /VCL::Module/i) {
 		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
@@ -252,7 +288,7 @@ sub _enable_service {
 	
 	# Enable the service
 	my $command = "systemctl --no-reload enable $service_name.service";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to enable '$service_name' service
on $computer_node_name: $command");
 		return;
@@ -275,7 +311,7 @@ sub _enable_service {
 
 #/////////////////////////////////////////////////////////////////////////////
 
-=head2 _disable_service
+=head2 disable_service
 
  Parameters  : $service_name
  Returns     : boolean
@@ -284,7 +320,7 @@ sub _enable_service {
 
 =cut
 
-sub _disable_service {
+sub disable_service {
 	my $self = shift;
 	if (ref($self) !~ /VCL::Module/i) {
 		notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called
as a class method");
@@ -300,7 +336,7 @@ sub _disable_service {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "systemctl --no-reload disable $service_name.service";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to disable '$service_name' service
on $computer_node_name: $command");
 		return;
@@ -350,12 +386,12 @@ sub delete_service {
 	# Disable the service before deleting it
 	if ($self->service_exists($service_name)) {
 		$self->stop_service($service_name) || return;
-		$self->_disable_service($service_name) || return;
+		$self->disable_service($service_name) || return;
 	}
 	
 	# Delete the service configuration file
 	my $service_file_path = "/lib/systemd/system/$service_name.service";
-	if (!$self->delete_file($service_file_path)) {
+	if (!$self->os->delete_file($service_file_path)) {
 		return;
 	}
 	
@@ -392,7 +428,7 @@ sub start_service {
 	
 	# start the service
 	my $command = "systemctl start $service_name.service";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to start '$service_name' service
on $computer_node_name: $command");
 		return;
@@ -442,7 +478,7 @@ sub stop_service {
 	
 	# stop the service
 	my $command = "systemctl stop $service_name.service";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to stop '$service_name' service
on $computer_node_name: $command");
 		return;
@@ -492,7 +528,7 @@ sub restart_service {
 	
 	# Restart the service
 	my $command = "systemctl restart $service_name.service";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to restart '$service_name' service
on $computer_node_name: $command");
 		return;
@@ -538,7 +574,7 @@ sub add_ext_sshd_service {
 	my $ext_sshd_service_file_path = '/lib/systemd/system/ext_sshd.service';
 	
 	# Get the contents of the sshd service configuration file already on the computer
-	my @sshd_service_file_contents = $self->get_file_contents($sshd_service_file_path);
+	my @sshd_service_file_contents = $self->os->get_file_contents($sshd_service_file_path);
 	if (!@sshd_service_file_contents) {
 		notify($ERRORS{'WARNING'}, 0, "failed to retrieve contents of $sshd_service_file_path from
$computer_node_name");
 		return;
@@ -562,19 +598,19 @@ sub add_ext_sshd_service {
 	
 	$ext_sshd_service_file_contents .= "\n";
 	
-	if (!$self->create_text_file($ext_sshd_service_file_path, $ext_sshd_service_file_contents))
{
+	if (!$self->os->create_text_file($ext_sshd_service_file_path, $ext_sshd_service_file_contents))
{
 		notify($ERRORS{'WARNING'}, 0, "failed to create ext_sshd service file on $computer_node_name:
$ext_sshd_service_file_path");
 		return;
 	}
 	
-	if (!$self->set_file_permissions($ext_sshd_service_file_path, '644')) {
+	if (!$self->os->set_file_permissions($ext_sshd_service_file_path, '644')) {
 		notify($ERRORS{'WARNING'}, 0, "failed to set permissions of ext_sshd service file to 644
on $computer_node_name: $ext_sshd_service_file_path");
 		return;
 	}
 	
 	$self->_daemon_reload();
 	
-	return $self->_enable_service('ext_sshd');
+	return $self->enable_service('ext_sshd');
 }
 
 #/////////////////////////////////////////////////////////////////////////////
@@ -599,7 +635,7 @@ sub _daemon_reload {
 	my $computer_node_name = $self->data->get_computer_node_name();
 	
 	my $command = "systemctl --system daemon-reload";
-	my ($exit_status, $output) = $self->execute($command, 0);
+	my ($exit_status, $output) = $self->os->execute($command, 0);
 	if (!defined($output)) {
 		notify($ERRORS{'WARNING'}, 0, "failed to execute command to reload systemd manager configuration
on $computer_node_name: $command");
 		return;

Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1646885&r1=1646884&r2=1646885&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Fri Dec 19 21:45:40 2014
@@ -484,7 +484,7 @@ INIT {
 	elsif (!defined($EXECUTE_NEW)) {
 		$EXECUTE_NEW = 0;
 	}
-	$ENV{execute_new} = $EXECUTE_NEW;
+	$ENV{execute_new} = $EXECUTE_NEW if $EXECUTE_NEW;
 	
 	# Set boolean variables to 0 or 1, they may be set to 'no' or 'yes' in the conf file
 	for ($MYSQL_SSL, $JABBER, $VERBOSE, $DAEMON_MODE, $SETUP_MODE) {
@@ -6839,7 +6839,7 @@ sub get_computer_info {
 		notify($ERRORS{'WARNING'}, 0, "computer identifier argument was not supplied");
 		return;
 	}
-
+	
 	if (!$no_cache && defined($ENV{computer_info}{$computer_identifier})) {
 		return $ENV{computer_info}{$computer_identifier};
 	}
@@ -7090,6 +7090,8 @@ sub get_computer_nathost_info {
 	
 	# Construct the select statement
 	my $select_statement = "SELECT DISTINCT\n";
+	$select_statement .= "computer.id AS 'computer-id',\n";
+	$select_statement .= "computer.hostname AS 'computer-hostname',\n";
 	
 	# Get the column names for each table and add them to the select statement
 	for my $table (@tables) {
@@ -7168,6 +7170,7 @@ EOF
 	
 	$nathost_info->{HOSTNAME} = '<unknown>';
 	
+	my $computer_id = $nathost_info->{computer}{id};
 	my $resource_id = $nathost_info->{resource}{id};
 	my $resource_type = $nathost_info->{resource}{resourcetype}{name};
 	my $resource_subid = $nathost_info->{resource}{subid};
@@ -7176,8 +7179,14 @@ EOF
 		$nathost_info->{HOSTNAME} = $management_node_info->{hostname};
 	}
 	elsif ($resource_type eq 'computer') {
-		my $computer_info = get_computer_info($resource_subid) || {};
-		$nathost_info->{HOSTNAME} = $computer_info->{hostname};
+		# Check if NAT host is the same computer as it is assigned to to avoid recursion
+		if ($computer_id eq $resource_subid) {
+			$nathost_info->{HOSTNAME} = $nathost_info->{computer}{hostname};
+		}
+		else {
+			my $computer_info = get_computer_info($resource_subid) || {};
+			$nathost_info->{HOSTNAME} = $computer_info->{hostname};
+		}
 	}
 	else {
 		notify($ERRORS{'WARNING'}, 0, "NAT host resource type is not supported: $resource_type,
resource ID: $resource_id");



Mime
View raw message