Author: arkurth
Date: Tue Dec 9 23:56:55 2014
New Revision: 1644246
URL: http://svn.apache.org/r1644246
Log:
VCL-702
Renamed mixed-case hash keys in DataStructure.pm's $SUBROUTINE_MAPPINGS hash:
server_request_fixedIP > server_request_fixed_ip
server_request_DNSservers > server_request_dns_servers
server_request_fixedMAC > server_request_fixed_mac
user_usePublicKeys > user_use_public_keys
user_sshPublicKeys > user_ssh_public_keys
log_remoteIP > log_remote_ip
sublog_IPaddress > sublog_ip_address
Updated locations where these are used.
Cleaned up lots of poor indentation.
Other
Added "no warnings 'redefine';" to Semaphore.pm. If you tried to run it
directly warnings would appear to to a require loop with Module.pm.
Modified:
vcl/trunk/managementnode/lib/VCL/DataStructure.pm
vcl/trunk/managementnode/lib/VCL/Module.pm
vcl/trunk/managementnode/lib/VCL/Module/OS.pm
vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/Ubuntu.pm
vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/UnixLab.pm
vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_6.pm
vcl/trunk/managementnode/lib/VCL/Module/Predictive/Level_0.pm
vcl/trunk/managementnode/lib/VCL/Module/Predictive/Level_1.pm
vcl/trunk/managementnode/lib/VCL/Module/Predictive/Level_2.pm
vcl/trunk/managementnode/lib/VCL/Module/Provisioning/Lab.pm
vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/VMware.pm
vcl/trunk/managementnode/lib/VCL/Module/Provisioning/VMware/vSphere_SDK.pm
vcl/trunk/managementnode/lib/VCL/Module/Provisioning/esxthin.pm
vcl/trunk/managementnode/lib/VCL/Module/Provisioning/one.pm
vcl/trunk/managementnode/lib/VCL/Module/Semaphore.pm
vcl/trunk/managementnode/lib/VCL/blockrequest.pm
vcl/trunk/managementnode/lib/VCL/healthcheck.pm
vcl/trunk/managementnode/lib/VCL/image.pm
vcl/trunk/managementnode/lib/VCL/inuse.pm
vcl/trunk/managementnode/lib/VCL/new.pm
vcl/trunk/managementnode/lib/VCL/utils.pm
Modified: vcl/trunk/managementnode/lib/VCL/DataStructure.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/DataStructure.pm?rev=1644246&r1=1644245&r2=1644246&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/DataStructure.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/DataStructure.pm Tue Dec 9 23:56:55 2014
@@ -163,14 +163,14 @@ $SUBROUTINE_MAPPINGS{log_wasavailable} =
$SUBROUTINE_MAPPINGS{log_ending} = '$self->request_data->{log}{ending}';
$SUBROUTINE_MAPPINGS{log_requestid} = '$self->request_data->{log}{requestid}';
$SUBROUTINE_MAPPINGS{log_computerid} =
'$self->request_data->{log}{computerid}';
-$SUBROUTINE_MAPPINGS{log_remoteIP} = '$self->request_data->{log}{remoteIP}';
+$SUBROUTINE_MAPPINGS{log_remote_ip} = '$self->request_data->{log}{remoteIP}';
$SUBROUTINE_MAPPINGS{log_imageid} = '$self->request_data->{log}{imageid}';
$SUBROUTINE_MAPPINGS{log_size} = '$self->request_data->{log}{size}';
$SUBROUTINE_MAPPINGS{sublog_imageid} = '$self->request_data->{log}{imageid}';
$SUBROUTINE_MAPPINGS{sublog_imagerevisionid} =
'$self->request_data->{log}{imagerevisionid}';
$SUBROUTINE_MAPPINGS{sublog_computerid} =
'$self->request_data->{log}{computerid}';
-$SUBROUTINE_MAPPINGS{sublog_IPaddress} =
'$self->request_data->{log}{IPaddress}';
+$SUBROUTINE_MAPPINGS{sublog_ip_address} =
'$self->request_data->{log}{IPaddress}';
$SUBROUTINE_MAPPINGS{sublog_managementnodeid} =
'$self->request_data->{log}{managementnodeid}';
$SUBROUTINE_MAPPINGS{sublog_predictivemoduleid} =
'$self->request_data->{log}{predictivemoduleid}';
@@ -417,11 +417,11 @@ $SUBROUTINE_MAPPINGS{image_platform_name
$SUBROUTINE_MAPPINGS{imagetype_name} =
'$self->request_data->{reservation}{RESERVATION_ID}{image}{imagetype}{name}';
$SUBROUTINE_MAPPINGS{server_request_id} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{id}';
-$SUBROUTINE_MAPPINGS{server_request_fixedIP} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{fixedIP}';
+$SUBROUTINE_MAPPINGS{server_request_fixed_ip} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{fixedIP}';
$SUBROUTINE_MAPPINGS{server_request_router} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{router}';
$SUBROUTINE_MAPPINGS{server_request_netmask} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{netmask}';
-$SUBROUTINE_MAPPINGS{server_request_DNSservers} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{DNSservers}';
-$SUBROUTINE_MAPPINGS{server_request_fixedMAC} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{fixedMAC}';
+$SUBROUTINE_MAPPINGS{server_request_dns_servers} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{DNSservers}';
+$SUBROUTINE_MAPPINGS{server_request_fixed_mac} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{fixedMAC}';
$SUBROUTINE_MAPPINGS{server_request_admingroupid} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{admingroupid}';
$SUBROUTINE_MAPPINGS{server_request_logingroupid} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{logingroupid}';
$SUBROUTINE_MAPPINGS{server_request_monitored} =
'$self->request_data->{reservation}{RESERVATION_ID}{serverrequest}{monitored}';
@@ -469,8 +469,8 @@ $SUBROUTINE_MAPPINGS{user_affiliation_he
$SUBROUTINE_MAPPINGS{user_affiliation_name} =
'$self->request_data->{user}{affiliation}{name}';
$SUBROUTINE_MAPPINGS{user_affiliation_sitewwwaddress} =
'$self->request_data->{user}{affiliation}{sitewwwaddress}';
$SUBROUTINE_MAPPINGS{user_imtype_name} =
'$self->request_data->{user}{IMtype}{name}';
-$SUBROUTINE_MAPPINGS{user_usePublicKeys} =
'$self->request_data->{user}{usepublickeys}';
-$SUBROUTINE_MAPPINGS{user_sshPublicKeys} =
'$self->request_data->{user}{sshpublickeys}';
+$SUBROUTINE_MAPPINGS{user_use_public_keys} =
'$self->request_data->{user}{usepublickeys}';
+$SUBROUTINE_MAPPINGS{user_ssh_public_keys} =
'$self->request_data->{user}{sshpublickeys}';
$SUBROUTINE_MAPPINGS{management_node_id} = '$ENV{management_node_info}{id}';
$SUBROUTINE_MAPPINGS{management_node_ipaddress} =
'$ENV{management_node_info}{IPaddress}';
Modified: vcl/trunk/managementnode/lib/VCL/Module.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module.pm?rev=1644246&r1=1644245&r2=1644246&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module.pm Tue Dec 9 23:56:55 2014
@@ -539,7 +539,7 @@ sub create_vmhost_os_object {
computer_identifier =>
$vmhost_computer_id,
image_identifier =>
$vmhost_profile_image_id
}
-
);
+
);
};
if ($EVAL_ERROR) {
Modified: vcl/trunk/managementnode/lib/VCL/Module/OS.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS.pm?rev=1644246&r1=1644245&r2=1644246&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS.pm Tue Dec 9 23:56:55 2014
@@ -501,9 +501,10 @@ sub wait_for_reboot {
my $ssh_actual_seconds = ($ssh_elapsed_seconds -
$ping_elapsed_seconds);
notify($ERRORS{'OK'}, 0, "$computer_node_name responded to SSH:
- unresponsive: $no_ping_elapsed_seconds seconds
- respond to ping: $ping_elapsed_seconds seconds
($ping_actual_seconds seconds after unresponsive)
- respond to SSH $ssh_elapsed_seconds seconds
($ssh_actual_seconds seconds after ping)");
+ unresponsive: $no_ping_elapsed_seconds seconds
+ respond to ping: $ping_elapsed_seconds seconds
($ping_actual_seconds seconds after unresponsive)
+ respond to SSH $ssh_elapsed_seconds seconds
($ssh_actual_seconds seconds after ping)"
+ );
return 1;
}
@@ -907,60 +908,60 @@ sub server_request_set_fixed_ip {
my $computer_public_ip_address =
$self->data->get_computer_public_ip_address();
my $public_ip_configuration =
$self->data->get_management_node_public_ip_configuration() || return;
my $server_request_id = $self->data->get_server_request_id();
- my $server_request_fixedIP =
$self->data->get_server_request_fixedIP();
-
- if ($server_request_id) {
- if ($server_request_fixedIP) {
- #Update the info related to fixedIP
- if (!$self->update_fixed_ip_info()) {
- notify($ERRORS{'WARNING'}, 0, "Unable to update information
related fixedIP for server_request $server_request_id");
- }
+ my $server_request_fixed_ip =
$self->data->get_server_request_fixed_ip();
+ if ($server_request_id) {
+ if ($server_request_fixed_ip) {
+ #Update the info related to fixedIP
+ if (!$self->update_fixed_ip_info()) {
+ notify($ERRORS{'WARNING'}, 0, "Unable to update
information related fixedIP for server_request $server_request_id");
+ }
+
#Confirm requested IP is not being used
if (!$self->confirm_fixed_ip_is_available()) {
#failed, insert into loadlog, fail reservation
- insertloadlog($reservation_id, $computer_id,
"failed","$server_request_fixedIP is NOT available");
+ insertloadlog($reservation_id, $computer_id,
"failed","$server_request_fixed_ip is NOT available");
return 0;
}
-
+
#if set for static IPs, save the old address to restore
if ($public_ip_configuration =~ /static/i) {
notify($ERRORS{'DEBUG'}, 0, "saving original IP
for restore on post reseration");
my $original_IPvalue = "originalIPaddr_" .
$server_request_id;
set_variable($original_IPvalue,
$computer_public_ip_address);
}
-
- # Try to set the static public IP address using the OS module
- if ($self->can("set_static_public_address")) {
- if ($self->set_static_public_address()) {
- notify($ERRORS{'DEBUG'}, 0, "set static public IP address on
$computer_node_name using OS module's set_static_public_address() method");
-
$self->data->set_computer_public_ip_address($server_request_fixedIP);
-
- # Delete cached network configuration information so it is
retrieved next time it is needed
- delete $self->{network_configuration};
-
- if (update_computer_public_ip_address($computer_id,
$server_request_fixedIP)) {
- notify($ERRORS{'OK'}, 0, "updated public IP address in
computer table for $computer_node_name, $server_request_fixedIP");
- }
-
- #Update Hostname to match Public assigned name
- if ($self->can("update_public_hostname")) {
- if ($self->update_public_hostname()) {
- notify($ERRORS{'OK'}, 0, "Updated hostname based on
fixedIP $server_request_fixedIP");
- }
- }
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "failed to set static public IP
address on $computer_node_name");
- insertloadlog($reservation_id, $computer_id,
"failed"," Not able to assigne IPaddress $server_request_fixedIP");
- return 0;
- }
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "unable to set static public IP
address on $computer_node_name, " . ref($self) . " module does not implement a
set_static_public_address subroutine");
- }
- }
- }
+
+ # Try to set the static public IP address using the OS
module
+ if ($self->can("set_static_public_address")) {
+ if ($self->set_static_public_address()) {
+ notify($ERRORS{'DEBUG'}, 0, "set static
public IP address on $computer_node_name using OS module's
set_static_public_address() method");
+
$self->data->set_computer_public_ip_address($server_request_fixed_ip);
+
+ # Delete cached network configuration
information so it is retrieved next time it is needed
+ delete $self->{network_configuration};
+
+ if
(update_computer_public_ip_address($computer_id, $server_request_fixed_ip)) {
+ notify($ERRORS{'OK'}, 0,
"updated public IP address in computer table for $computer_node_name,
$server_request_fixed_ip");
+ }
+
+ #Update Hostname to match Public
assigned name
+ if
($self->can("update_public_hostname")) {
+ if
($self->update_public_hostname()) {
+ notify($ERRORS{'OK'},
0, "Updated hostname based on fixedIP $server_request_fixed_ip");
+ }
+ }
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "failed
to set static public IP address on $computer_node_name");
+ insertloadlog($reservation_id,
$computer_id, "failed"," Not able to assigne IPaddress
$server_request_fixed_ip");
+ return 0;
+ }
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "unable to set static
public IP address on $computer_node_name, " . ref($self) . " module does not
implement a set_static_public_address subroutine");
+ }
+ }
+ }
return 1;
@@ -991,20 +992,20 @@ sub confirm_fixed_ip_is_available {
my $reservation_id = $self->data->get_reservation_id() || return;
my $computer_id = $self->data->get_computer_id() || return;
my $computer_node_name = $self->data->get_computer_node_name() ||
return;
- my $server_request_id = $self->data->get_server_request_id();
- my $server_request_fixedIP =
$self->data->get_server_request_fixedIP();
+ my $server_request_id = $self->data->get_server_request_id();
+ my $server_request_fixed_ip =
$self->data->get_server_request_fixed_ip();
#check VCL computer table
- if (is_ip_assigned_query($server_request_fixedIP)) {
- notify($ERRORS{'WARNING'}, 0, "$server_request_fixedIP is
already assigned");
- insertloadlog($reservation_id, $computer_id,
"failed","$server_request_fixedIP is already assigned");
+ if (is_ip_assigned_query($server_request_fixed_ip)) {
+ notify($ERRORS{'WARNING'}, 0, "$server_request_fixed_ip is
already assigned");
+ insertloadlog($reservation_id, $computer_id,
"failed","$server_request_fixed_ip is already assigned");
return 0;
}
#Is IP pingable
- if (_pingnode($server_request_fixedIP)) {
- notify($ERRORS{'WARNING'}, 0, "$server_request_fixedIP is
answering ping test");
- insertloadlog($reservation_id, $computer_id,
"failed","$server_request_fixedIP is answering ping test, but is not assigned
in VCL database");
+ if (_pingnode($server_request_fixed_ip)) {
+ notify($ERRORS{'WARNING'}, 0, "$server_request_fixed_ip is
answering ping test");
+ insertloadlog($reservation_id, $computer_id,
"failed","$server_request_fixed_ip is answering ping test, but is not assigned
in VCL database");
return 0;
}
@@ -2532,11 +2533,11 @@ sub manage_server_access {
my $server_request_admingroupid =
$self->data->get_server_request_admingroupid();
my $server_request_logingroupid =
$self->data->get_server_request_logingroupid();
my $user_login_id_owner = $self->data->get_user_login_id();
- my $user_sshPublicKeys =
$self->data->get_user_sshPublicKeys(0);
- my $user_id_owner = $self->data->get_user_id();
- my $image_os_type =
$self->data->get_image_os_type();
+ my $user_ssh_public_keys =
$self->data->get_user_ssh_public_keys(0);
+ my $user_id_owner = $self->data->get_user_id();
+ my $image_os_type =
$self->data->get_image_os_type();
my $request_laststate_name =
$self->data->get_request_laststate_name();
- my $reservation_users =
$self->data->get_reservation_users();
+ my $reservation_users =
$self->data->get_reservation_users();
# Build list of users.
# If in admin group set admin flag
@@ -2567,13 +2568,13 @@ sub manage_server_access {
if (!exists($res_accounts{$userid}) || $request_laststate_name
eq "reinstall" ) {
if($request_laststate_name ne "reinstall" ){
-
+
$user_hash{$userid}{"passwd"} = 0;
# Generate password if linux and standalone
affiliation
unless ($image_os_type =~ /linux/ &&
!$standalone) {
$user_hash{$userid}{"passwd"} = getpw();
}
-
+
if
(update_reservation_accounts($reservation_id,$userid,$user_hash{$userid}{passwd},"add"))
{
notify($ERRORS{'OK'}, 0, "Inserted
$reservation_id,$userid into reservationsaccounts table");
}
@@ -2589,7 +2590,7 @@ sub manage_server_access {
unless ($image_os_type =~ /linux/ &&
!$standalone) {
$user_hash{$userid}{"passwd"} =
getpw();
}
-
+
if
(update_reservation_accounts($reservation_id,$userid,0,"delete")) {
}
if
(update_reservation_accounts($reservation_id,$userid,$user_hash{$userid}{passwd},"add"))
{
@@ -2599,7 +2600,14 @@ sub manage_server_access {
}
# Create user on the OS
- if
($self->create_user($user_hash{$userid}{unityid},$user_hash{$userid}{passwd},$user_hash{$userid}{uid},$user_hash{$userid}{ROOTACCESS},$standalone,$user_hash{$userid}{user_info}{user_sshPublicKeys}))
{
+ if ($self->create_user(
+ $user_hash{$userid}{unityid},
+ $user_hash{$userid}{passwd},
+ $user_hash{$userid}{uid},
+ $user_hash{$userid}{ROOTACCESS},
+ $standalone,
+
$user_hash{$userid}{user_info}{sshpublickeys}
+ )) {
notify($ERRORS{'OK'}, 0, "Successfully created
user $user_hash{$userid}{unityid} on $computer_node_name");
}
else {
@@ -2620,16 +2628,16 @@ sub manage_server_access {
next;
}
if (!exists($user_hash{$res_userid})) {
- notify($ERRORS{'OK'}, 0, "username=
$res_accounts{$res_userid}{username} is not listed in reservationsaccounts,
attempting to delete");
- #Delete from reservationaccounts
- if
(update_reservation_accounts($reservation_id,$res_accounts{$res_userid}{userid},0,"delete"))
{
- notify($ERRORS{'OK'}, 0,
"Deleted $reservation_id,$res_accounts{$res_userid}{userid} from
reservationsaccounts table");
- }
- #Delete from OS
- if
($self->delete_user($res_accounts{$res_userid}{username},0,0)) {
- notify($ERRORS{'OK'}, 0,
"Successfully removed user= $res_accounts{$res_userid}{username}");
- }
- next;
+ notify($ERRORS{'OK'}, 0, "username=
$res_accounts{$res_userid}{username} is not listed in reservationsaccounts,
attempting to delete");
+ #Delete from reservationaccounts
+ if
(update_reservation_accounts($reservation_id,$res_accounts{$res_userid}{userid},0,"delete"))
{
+ notify($ERRORS{'OK'}, 0, "Deleted
$reservation_id,$res_accounts{$res_userid}{userid} from reservationsaccounts
table");
+ }
+ #Delete from OS
+ if
($self->delete_user($res_accounts{$res_userid}{username},0,0)) {
+ notify($ERRORS{'OK'}, 0, "Successfully removed
user= $res_accounts{$res_userid}{username}");
+ }
+ next;
}
}
@@ -3327,26 +3335,25 @@ sub update_fixed_ip_info {
my $server_variable_data;
if (is_variable_set($variable_name)) {
- #fetch variable
- $server_variable_data = get_variable($variable_name);
-
- notify($ERRORS{'DEBUG'}, 0, "data is set for $variable_name"
. format_data($server_variable_data));
-
- my $router = $server_variable_data->{router};
- my $netmask = $server_variable_data->{netmask};
- my @dns = @{$server_variable_data->{dns}};
+ #fetch variable
+ $server_variable_data = get_variable($variable_name);
+
+ notify($ERRORS{'DEBUG'}, 0, "data is set for $variable_name" .
format_data($server_variable_data));
+
+ my $router = $server_variable_data->{router};
+ my $netmask = $server_variable_data->{netmask};
+ my @dns = @{$server_variable_data->{dns}};
+
+ notify($ERRORS{'OK'}, 0, "updated data server request router
info") if
($self->data->set_server_request_router($server_variable_data->{router}));
+ notify($ERRORS{'OK'}, 0, "updated data server request netmask
info") if
($self->data->set_server_request_netmask($server_variable_data->{netmask}));
+ notify($ERRORS{'OK'}, 0, "updated data server request dns
info") if
($self->data->set_server_request_dns_servers(@{$server_variable_data->{dns}}));
+ notify($ERRORS{'DEBUG'}, 0, "router= $router, netmask=
$netmask, dns= @dns");
- notify($ERRORS{'OK'}, 0, "updated data server request
router info") if
($self->data->set_server_request_router($server_variable_data->{router}));
- notify($ERRORS{'OK'}, 0, "updated data server request
netmask info") if
($self->data->set_server_request_netmask($server_variable_data->{netmask}));
- notify($ERRORS{'OK'}, 0, "updated data server request
dns info") if
($self->data->set_server_request_DNSservers(@{$server_variable_data->{dns}}));
- notify($ERRORS{'DEBUG'}, 0, "router= $router, netmask=
$netmask, dns= @dns");
-
}
- else{
- notify($ERRORS{'DEBUG'}, 0, "data is not set for $variable_name");
- return 0;
- }
-
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "data is not set for
$variable_name");
+ return 0;
+ }
}
#/////////////////////////////////////////////////////////////////////////////
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=1644246&r1=1644245&r2=1644246&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Tue Dec 9 23:56:55 2014
@@ -812,16 +812,16 @@ sub set_static_public_address {
return 0;
}
- my $computer_name = $self->data->get_computer_short_name();
- my $server_request_id = $self->data->get_server_request_id();
- my $server_request_fixedIP = $self->data->get_server_request_fixedIP();
+ my $computer_name = $self->data->get_computer_short_name();
+ my $server_request_id = $self->data->get_server_request_id();
+ my $server_request_fixed_ip =
$self->data->get_server_request_fixed_ip();
# Make sure public IP configuration is static or this is a server
request
my $ip_configuration =
$self->data->get_management_node_public_ip_configuration();
if ($ip_configuration !~ /static/i) {
- if (!$server_request_fixedIP) {
- notify($ERRORS{'WARNING'}, 0, "static public address
can only be set if IP configuration is static or is a server request, current
value: $ip_configuration \nserver_request_fixedIP=$server_request_fixedIP");
+ if (!$server_request_fixed_ip) {
+ notify($ERRORS{'WARNING'}, 0, "static public address
can only be set if IP configuration is static or is a server request, current
value: $ip_configuration \nserver_request_fixed_ip=$server_request_fixed_ip");
return;
}
}
@@ -838,11 +838,11 @@ sub set_static_public_address {
my $default_gateway =
$self->data->get_management_node_public_default_gateway() || '<undefined>';
my @dns_servers =
$self->data->get_management_node_public_dns_servers();
- if ($server_request_fixedIP) {
- $computer_public_ip_address = $server_request_fixedIP;
+ if ($server_request_fixed_ip) {
+ $computer_public_ip_address = $server_request_fixed_ip;
$subnet_mask =
$self->data->get_server_request_netmask();
$default_gateway =
$self->data->get_server_request_router();
- @dns_servers =
$self->data->get_server_request_DNSservers();
+ @dns_servers =
$self->data->get_server_request_dns_servers();
}
# Assemble a string containing the static IP configuration
@@ -2077,9 +2077,9 @@ sub get_file_size {
if ($calling_sub !~ /get_file_size/) {
notify($ERRORS{'DEBUG'}, 0, "size of " . join(", ",
@file_paths) . " on $computer_node_name:\n" .
- "file count: $file_count\n" .
- "reserved: " .
get_file_size_info_string($total_bytes_reserved) . "\n" .
- "used: " .
get_file_size_info_string($total_bytes_used));
+ "file count: $file_count\n" .
+ "reserved: " . get_file_size_info_string($total_bytes_reserved)
. "\n" .
+ "used: " . get_file_size_info_string($total_bytes_used));
}
if (wantarray) {
@@ -2621,7 +2621,7 @@ sub create_user {
$uid = $self->data->get_user_uid() unless defined $uid;
$root_access = $self->data->get_imagemeta_rootaccess() unless
defined $root_access;
$user_standalone = $self->data->get_user_standalone() unless
defined $user_standalone;
- $user_ssh_public_keys = $self->data->get_user_sshPublicKeys(0)
unless defined $user_ssh_public_keys;
+ $user_ssh_public_keys =
$self->data->get_user_ssh_public_keys(0) unless defined $user_ssh_public_keys;
}
$root_access = 1 unless defined $root_access;
@@ -3374,10 +3374,11 @@ sub get_cpu_core_count {
my $hyperthreading_enabled = ($siblings > $cpu_cores) ? 'yes' : 'no';
notify($ERRORS{'DEBUG'}, 0, "retrieved $computer_node_name CPU core
count: $cpu_core_count
- cpuinfo 'processor' line count: $processor_count
- cpuinfo 'cpu cores': $cpu_cores
- cpuinfo 'siblings': $siblings
- hyperthreading enabled: $hyperthreading_enabled");
+ cpuinfo 'processor' line count: $processor_count
+ cpuinfo 'cpu cores': $cpu_cores
+ cpuinfo 'siblings': $siblings
+ hyperthreading enabled: $hyperthreading_enabled"
+ );
return $cpu_core_count;
}
@@ -4957,7 +4958,7 @@ sub notify_user_console {
my $username = shift;
if (!$username) {
- $username = $self->data->get_user_login_id();
+ $username = $self->data->get_user_login_id();
}
my $computer_node_name = $self->data->get_computer_node_name();
Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/Ubuntu.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/Ubuntu.pm?rev=1644246&r1=1644245&r2=1644246&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/Ubuntu.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/Ubuntu.pm Tue Dec 9
23:56:55 2014
@@ -69,67 +69,64 @@ use VCL::utils;
sub clean_iptables {
my $self = shift;
- if (ref($self) !~ /ubuntu/i) {
- notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it
must be called as a class method");
- return;
- }
-
+ if (ref($self) !~ /ubuntu/i) {
+ notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
+ return;
+ }
+
# Check to see if this distro has iptables
- if (!$self->service_exists("iptables")) {
- notify($ERRORS{'WARNING'}, 0, "iptables service does not exist on this
OS");
- return 1;
- }
-
-
- my $computer_node_name = $self->data->get_computer_node_name();
- my $reservation_id = $self->data->get_reservation_id();
- my $management_node_keys = $self->data->get_management_node_keys();
-
-
- # Retrieve the iptables file to work on locally
- my $tmpfile = "/tmp/" . $reservation_id . "_iptables";
- my $source_file_path = "/etc/iptables.rules";
- if (run_scp_command("$computer_node_name:\"$source_file_path\"", $tmpfile,
$management_node_keys)) {
- my @lines;
- if (open(IPTAB_TMPFILE, $tmpfile)) {
- @lines = <IPTAB_TMPFILE>;
- close(IPTAB_TMPFILE);
- }
- foreach my $line (@lines) {
- if ($line =~ s/-A INPUT -s .*\n//) {
- }
- }
-
- #Rewrite array to tmpfile
- if (open(IPTAB_TMPFILE, ">$tmpfile")) {
- print IPTAB_TMPFILE @lines;
- close (IPTAB_TMPFILE);
- }
-
- # Copy iptables file back to node
- if (run_scp_command($tmpfile,
"$computer_node_name:\"$source_file_path\"", $management_node_keys)) {
- notify($ERRORS{'DEBUG'}, 0, "copied $tmpfile to $computer_node_name
$source_file_path");
- }
- }
-
- #restart iptables
- my $command = "iptables -P INPUT ACCEPT;iptables -P OUTPUT ACCEPT; iptables
-P FORWARD ACCEPT; iptables -F; iptables-restore < /etc/iptables.rules";
- my ($status_iptables,$output_iptables) = $self->execute($command);
- if (defined $status_iptables && $status_iptables == 0) {
- notify($ERRORS{'DEBUG'}, 0, "executed command $command on
$computer_node_name");
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "output from iptables:" . join("\n",
@$output_iptables));
- }
-
- if ($self->wait_for_ssh(0)) {
- return 1;
- }
- else {
- notify($ERRORS{'CRITICAL'}, 0, "not able to login via ssh after
cleaning_iptables");
- return 0;
- }
-
+ if (!$self->service_exists("iptables")) {
+ notify($ERRORS{'WARNING'}, 0, "iptables service does not exist
on this OS");
+ return 1;
+ }
+
+ my $computer_node_name = $self->data->get_computer_node_name();
+ my $reservation_id = $self->data->get_reservation_id();
+ my $management_node_keys = $self->data->get_management_node_keys();
+
+ # Retrieve the iptables file to work on locally
+ my $tmpfile = "/tmp/" . $reservation_id . "_iptables";
+ my $source_file_path = "/etc/iptables.rules";
+ if (run_scp_command("$computer_node_name:\"$source_file_path\"",
$tmpfile, $management_node_keys)) {
+ my @lines;
+ if (open(IPTAB_TMPFILE, $tmpfile)) {
+ @lines = <IPTAB_TMPFILE>;
+ close(IPTAB_TMPFILE);
+ }
+ foreach my $line (@lines) {
+ if ($line =~ s/-A INPUT -s .*\n//) {
+ }
+ }
+
+ #Rewrite array to tmpfile
+ if (open(IPTAB_TMPFILE, ">$tmpfile")) {
+ print IPTAB_TMPFILE @lines;
+ close (IPTAB_TMPFILE);
+ }
+
+ # Copy iptables file back to node
+ if (run_scp_command($tmpfile,
"$computer_node_name:\"$source_file_path\"", $management_node_keys)) {
+ notify($ERRORS{'DEBUG'}, 0, "copied $tmpfile to
$computer_node_name $source_file_path");
+ }
+ }
+
+ #restart iptables
+ my $command = "iptables -P INPUT ACCEPT;iptables -P OUTPUT ACCEPT;
iptables -P FORWARD ACCEPT; iptables -F; iptables-restore <
/etc/iptables.rules";
+ my ($status_iptables,$output_iptables) = $self->execute($command);
+ if (defined $status_iptables && $status_iptables == 0) {
+ notify($ERRORS{'DEBUG'}, 0, "executed command $command on
$computer_node_name");
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "output from iptables:" .
join("\n", @$output_iptables));
+ }
+
+ if ($self->wait_for_ssh(0)) {
+ return 1;
+ }
+ else {
+ notify($ERRORS{'CRITICAL'}, 0, "not able to login via ssh after
cleaning_iptables");
+ return 0;
+ }
}
#/////////////////////////////////////////////////////////////////////////////
@@ -144,49 +141,49 @@ sub clean_iptables {
sub clean_known_files {
my $self = shift;
- if (ref($self) !~ /ubuntu/i) {
- notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it
must be called as a class method");
- return 0;
- }
+ if (ref($self) !~ /ubuntu/i) {
+ notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
+ return 0;
+ }
my $computer_node_name = $self->data->get_computer_node_name();
-
+
# Clear SSH idenity keys from /root/.ssh
- if (!$self->clear_private_keys()) {
- notify($ERRORS{'WARNING'}, 0, "unable to clear known identity keys");
- }
+ if (!$self->clear_private_keys()) {
+ notify($ERRORS{'WARNING'}, 0, "unable to clear known identity keys");
+ }
# Try to clear /tmp
- if ($self->execute("/bin/cp /dev/null /var/log/wtmp")) {
- notify($ERRORS{'DEBUG'}, 0, "cleared /var/log/wtmp on
$computer_node_name");
- }
-
+ if ($self->execute("/bin/cp /dev/null /var/log/wtmp")) {
+ notify($ERRORS{'DEBUG'}, 0, "cleared /var/log/wtmp on
$computer_node_name");
+ }
+
#Fetch exclude_list
- my @exclude_list = $self->get_exclude_list();
+ my @exclude_list = $self->get_exclude_list();
if (@exclude_list ) {
- notify($ERRORS{'DEBUG'}, 0, "skipping files listed in exclude_list\n" .
join("\n", @exclude_list));
- }
-
- #Remove files
- if (!(grep( /70-persistent-net.rules/ , @exclude_list ) ) ) {
- if (!$self->delete_file("/etc/udev/rules.d/70-persistent-net.rules")) {
- notify($ERRORS{'WARNING'}, 0, "unable to remove
/etc/udev/rules.d/70-persistent-net.rules");
- }
- }
-
- if (!(grep( /\/var\/log\/auth/ , @exclude_list ) ) ) {
- if (!$self->execute("cp /dev/null /var/log/auth.log")) {
- notify($ERRORS{'WARNING'}, 0, "unable to overwrite
/var/log/auth.log");
- }
- }
-
- if (!(grep( /\/var\/log\/lastlog/ , @exclude_list ) ) ) {
- if (!$self->execute("cp /dev/null /var/log/lastlog")) {
- notify($ERRORS{'WARNING'}, 0, "unable to overwrite /var/log/lastlog");
- }
- }
-
+ notify($ERRORS{'DEBUG'}, 0, "skipping files listed in
exclude_list\n" . join("\n", @exclude_list));
+ }
+
+ #Remove files
+ if (!(grep( /70-persistent-net.rules/ , @exclude_list ) ) ) {
+ if
(!$self->delete_file("/etc/udev/rules.d/70-persistent-net.rules")) {
+ notify($ERRORS{'WARNING'}, 0, "unable to remove
/etc/udev/rules.d/70-persistent-net.rules");
+ }
+ }
+
+ if (!(grep( /\/var\/log\/auth/ , @exclude_list ) ) ) {
+ if (!$self->execute("cp /dev/null /var/log/auth.log")) {
+ notify($ERRORS{'WARNING'}, 0, "unable to overwrite
/var/log/auth.log");
+ }
+ }
+
+ if (!(grep( /\/var\/log\/lastlog/ , @exclude_list ) ) ) {
+ if (!$self->execute("cp /dev/null /var/log/lastlog")) {
+ notify($ERRORS{'WARNING'}, 0, "unable to overwrite
/var/log/lastlog");
+ }
+ }
+
return 1;
}
@@ -204,10 +201,10 @@ sub clean_known_files {
sub enable_dhcp {
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");
- return;
- }
+ if (ref($self) !~ /VCL::Module/i) {
+ notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
+ return;
+ }
my $computer_node_name = $self->data->get_computer_node_name();
@@ -307,82 +304,82 @@ sub changepasswd {
=cut
sub get_network_configuration {
- 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");
- return;
- }
-
- # Check if the network configuration has already been retrieved and saved
in this object
- return $self->{network_configuration} if ($self->{network_configuration});
-
- # Run ipconfig
- my $ifconfig_command = "/sbin/ifconfig -a";
- my ($ifconfig_exit_status, $ifconfig_output) =
$self->execute($ifconfig_command);
- if (!defined($ifconfig_output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to retrieve network
configuration: $ifconfig_command");
- return;
- }
-
- # Loop through the ifconfig output lines
- my $network_configuration;
- my $interface_name;
- for my $ifconfig_line (@$ifconfig_output) {
- # Extract the interface name from the Link line:
- # eth2 Link encap:Ethernet HWaddr 00:0C:29:78:77:AB
- if ($ifconfig_line =~ /^([^\s]+).*Link/) {
- $interface_name = $1;
- $network_configuration->{$interface_name}{name} = $interface_name;
- }
-
- # Skip to the next line if the interface name has not been determined yet
- next if !$interface_name;
-
- # Parse the HWaddr line:
- # eth2 Link encap:Ethernet HWaddr 00:0C:29:78:77:AB
- if ($ifconfig_line =~ /HWaddr\s+([\w:]+)/) {
- $network_configuration->{$interface_name}{physical_address} = lc($1);
- }
+ 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");
+ return;
+ }
+
+ # Check if the network configuration has already been retrieved and
saved in this object
+ return $self->{network_configuration} if
($self->{network_configuration});
+
+ # Run ipconfig
+ my $ifconfig_command = "/sbin/ifconfig -a";
+ my ($ifconfig_exit_status, $ifconfig_output) =
$self->execute($ifconfig_command);
+ if (!defined($ifconfig_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to
retrieve network configuration: $ifconfig_command");
+ return;
+ }
+
+ # Loop through the ifconfig output lines
+ my $network_configuration;
+ my $interface_name;
+ for my $ifconfig_line (@$ifconfig_output) {
+ # Extract the interface name from the Link line:
+ # eth2 Link encap:Ethernet HWaddr 00:0C:29:78:77:AB
+ if ($ifconfig_line =~ /^([^\s]+).*Link/) {
+ $interface_name = $1;
+ $network_configuration->{$interface_name}{name} =
$interface_name;
+ }
+
+ # Skip to the next line if the interface name has not been
determined yet
+ next if !$interface_name;
+
+ # Parse the HWaddr line:
+ # eth2 Link encap:Ethernet HWaddr 00:0C:29:78:77:AB
+ if ($ifconfig_line =~ /HWaddr\s+([\w:]+)/) {
+
$network_configuration->{$interface_name}{physical_address} = lc($1);
+ }
# Parse the IP address line:
- # inet addr:10.10.4.35 Bcast:10.10.15.255 Mask:255.255.240.0
- if ($ifconfig_line =~ /inet
addr:([\d\.]+)\s+Bcast:([\d\.]+)\s+Mask:([\d\.]+)/) {
- $network_configuration->{$interface_name}{ip_address}{$1} = $3;
- $network_configuration->{$interface_name}{broadcast_address} = $2;
- }
- }
-
- # Run route
- my $route_command = "/sbin/route -n";
- my ($route_exit_status, $route_output) = $self->execute($route_command);
- if (!defined($route_output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to retrieve routing
configuration: $route_command");
- return;
- }
-
+ # inet addr:10.10.4.35 Bcast:10.10.15.255 Mask:255.255.240.0
+ if ($ifconfig_line =~ /inet
addr:([\d\.]+)\s+Bcast:([\d\.]+)\s+Mask:([\d\.]+)/) {
+
$network_configuration->{$interface_name}{ip_address}{$1} = $3;
+
$network_configuration->{$interface_name}{broadcast_address} = $2;
+ }
+ }
+
+ # Run route
+ my $route_command = "/sbin/route -n";
+ my ($route_exit_status, $route_output) = $self->execute($route_command);
+ if (!defined($route_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to
retrieve routing configuration: $route_command");
+ return;
+ }
+
# Loop through the route output lines
- for my $route_line (@$route_output) {
- my ($default_gateway, $interface_name) = $route_line =~
/^0\.0\.0\.0\s+([\d\.]+).*\s([^\s]+)$/g;
-
- if (!defined($interface_name) || !defined($default_gateway)) {
- notify($ERRORS{'DEBUG'}, 0, "route output line does not contain a
default gateway: '$route_line'");
- }
- elsif (!defined($network_configuration->{$interface_name})) {
- notify($ERRORS{'WARNING'}, 0, "found default gateway for
'$interface_name' interface but the network configuration for '$interface_name'
was not previously retrieved, route output:\n" . join("\n", @$route_output) .
"\nnetwork configuation:\n" . format_data($network_configuration));
- }
- elsif
(defined($network_configuration->{$interface_name}{default_gateway})) {
- notify($ERRORS{'WARNING'}, 0, "multiple default gateway are
configured for '$interface_name' interface, route output:\n" . join("\n",
@$route_output));
- }
- else {
- $network_configuration->{$interface_name}{default_gateway} =
$default_gateway;
- notify($ERRORS{'DEBUG'}, 0, "found default route configured for
'$interface_name' interface: $default_gateway");
- }
- }
-
- $self->{network_configuration} = $network_configuration;
+ for my $route_line (@$route_output) {
+ my ($default_gateway, $interface_name) = $route_line =~
/^0\.0\.0\.0\s+([\d\.]+).*\s([^\s]+)$/g;
+
+ if (!defined($interface_name) || !defined($default_gateway)) {
+ notify($ERRORS{'DEBUG'}, 0, "route output line does not
contain a default gateway: '$route_line'");
+ }
+ elsif (!defined($network_configuration->{$interface_name})) {
+ notify($ERRORS{'WARNING'}, 0, "found default gateway
for '$interface_name' interface but the network configuration for
'$interface_name' was not previously retrieved, route output:\n" . join("\n",
@$route_output) . "\nnetwork configuation:\n" .
format_data($network_configuration));
+ }
+ elsif
(defined($network_configuration->{$interface_name}{default_gateway})) {
+ notify($ERRORS{'WARNING'}, 0, "multiple default gateway
are configured for '$interface_name' interface, route output:\n" . join("\n",
@$route_output));
+ }
+ else {
+
$network_configuration->{$interface_name}{default_gateway} = $default_gateway;
+ notify($ERRORS{'DEBUG'}, 0, "found default route
configured for '$interface_name' interface: $default_gateway");
+ }
+ }
+
+ $self->{network_configuration} = $network_configuration;
#can produce large output, if you need to monitor the configuration
setting uncomment the below output statement
- #notify($ERRORS{'DEBUG'}, 0, "retrieved network configuration:\n" .
format_data($self->{network_configuration}));
- return $self->{network_configuration};
+ #notify($ERRORS{'DEBUG'}, 0, "retrieved network configuration:\n" .
format_data($self->{network_configuration}));
+ return $self->{network_configuration};
}
@@ -397,11 +394,11 @@ sub get_network_configuration {
=cut
sub enable_firewall_port {
- 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");
- return;
- }
+ 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");
+ return;
+ }
return 1;
}
@@ -417,11 +414,11 @@ sub enable_firewall_port {
=cut
sub disable_firewall_port {
- 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");
- return;
- }
+ 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");
+ return;
+ }
return 1;
}
@@ -453,101 +450,96 @@ sub disable_firewall_port {
sub get_firewall_configuration {
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 $computer_node_name = $self->data->get_computer_node_name();
- my $firewall_configuration = {};
-
- # Check to see if this distro has iptables
- if (!$self->service_exists("ufw")) {
- notify($ERRORS{'WARNING'}, 0, "iptables service does not exist on this
OS");
- return {};
- }
-
- my $port_command = "ufw status numbered";
- my ($iptables_exit_status, $output_iptables) =
$self->execute($port_command);
- if (!defined($output_iptables)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to show open
firewall ports on $computer_node_name");
- return;
- }
-
+ 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 $computer_node_name = $self->data->get_computer_node_name();
+ my $firewall_configuration = {};
+
+ # Check to see if this distro has iptables
+ if (!$self->service_exists("ufw")) {
+ notify($ERRORS{'WARNING'}, 0, "iptables service does not exist
on this OS");
+ return {};
+ }
+
+ my $port_command = "ufw status numbered";
+ my ($iptables_exit_status, $output_iptables) =
$self->execute($port_command);
+ if (!defined($output_iptables)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to show
open firewall ports on $computer_node_name");
+ return;
+ }
+
my $status;
my $chain = "INPUT";
- my $previous_protocol;
- my $previous_port;
-
- for my $line (@$output_iptables) {
- if ($line =~ /^Status: (inactive|active)/ig) {
- $status = $1;
- notify($ERRORS{'DEBUG'}, 0, "output Chain = $chain");
+ my $previous_protocol;
+ my $previous_port;
+
+ for my $line (@$output_iptables) {
+ if ($line =~ /^Status: (inactive|active)/ig) {
+ $status = $1;
+ notify($ERRORS{'DEBUG'}, 0, "output Chain = $chain");
if ($status =~ /inactive/i) {
return;
}
- }
- elsif ($line =~
/^(\d+)\s+([A-Z]*)\s+([a-z]*)\s+(--)\s+(\S+)\s+(\S+)\s+(.*)/ig ) {
-
- my $num = $1;
- my $target = $2;
- my $protocol = $3;
- my $scope = $5;
- my $destination =$6;
- my $port_string = $7 if (defined($7));
- my $port = '';
- my $name;
-
-
- if (defined($port_string) && ($port_string =~
/([\s(a-zA-Z)]*)(dpt:)(\d+)/ig )) {
- $port = $3;
- notify($ERRORS{'DEBUG'}, 0, "output rule: $num, $target,
$protocol, $scope, $destination, $port ");
- }
-
- if (!$port) {
- $port = "any";
- }
-
- my $services_cmd = "cat /etc/services";
- my ($services_status, $service_output) =
$self->execute($services_cmd);
- if (!defined($service_output)) {
- notify($ERRORS{'DEBUG'}, 0, "failed to get /etc/services");
- }
- else {
- for my $sline (@$service_output) {
- if ( $sline =~ /(^[_-a-zA-Z1-9]+)\s+($port\/$protocol)\s+(.*)
/ig ) {
- $name = $1;
- }
- }
-
- }
-
- $name = $port if (!$name);
-
- $firewall_configuration->{$chain}->{$num}{$protocol}{$port}{name}=
$name;
- $firewall_configuration->{$chain}->{$num}{$protocol}{$port}{number}=
$num;
- $firewall_configuration->{$chain}->{$num}{$protocol}{$port}{scope}=
$scope;
- $firewall_configuration->{$chain}->{$num}{$protocol}{$port}{target}=
$target;
-
$firewall_configuration->{$chain}->{$num}{$protocol}{$port}{destination}=
$destination;
-
-
- if (!defined($previous_protocol) ||
- !defined($previous_port) ||
- !defined($firewall_configuration->{$previous_protocol}) ||
-
!defined($firewall_configuration->{$previous_protocol}{$previous_port})
- ) {
- next;
- }
- elsif ($scope !~ /0.0.0.0\/0/) {
-
$firewall_configuration->{$previous_protocol}{$previous_port}{scope} = $scope;
- }
- }
- }
-
- notify($ERRORS{'DEBUG'}, 0, "retrieved firewall configuration from
$computer_node_name:\n" . format_data($firewall_configuration));
- return $firewall_configuration;
+ }
+ elsif ($line =~
/^(\d+)\s+([A-Z]*)\s+([a-z]*)\s+(--)\s+(\S+)\s+(\S+)\s+(.*)/ig ) {
+
+ my $num = $1;
+ my $target = $2;
+ my $protocol = $3;
+ my $scope = $5;
+ my $destination =$6;
+ my $port_string = $7 if (defined($7));
+ my $port = '';
+ my $name;
+
+ if (defined($port_string) && ($port_string =~
/([\s(a-zA-Z)]*)(dpt:)(\d+)/ig )) {
+ $port = $3;
+ notify($ERRORS{'DEBUG'}, 0, "output rule: $num,
$target, $protocol, $scope, $destination, $port ");
+ }
+
+ if (!$port) {
+ $port = "any";
+ }
+
+ my $services_cmd = "cat /etc/services";
+ my ($services_status, $service_output) =
$self->execute($services_cmd);
+ if (!defined($service_output)) {
+ notify($ERRORS{'DEBUG'}, 0, "failed to get
/etc/services");
+ }
+ else {
+ for my $sline (@$service_output) {
+ if ( $sline =~
/(^[_-a-zA-Z1-9]+)\s+($port\/$protocol)\s+(.*) /ig ) {
+ $name = $1;
+ }
+ }
+ }
+
+ $name = $port if (!$name);
+
+
$firewall_configuration->{$chain}->{$num}{$protocol}{$port}{name}= $name;
+
$firewall_configuration->{$chain}->{$num}{$protocol}{$port}{number}= $num;
+
$firewall_configuration->{$chain}->{$num}{$protocol}{$port}{scope}= $scope;
+
$firewall_configuration->{$chain}->{$num}{$protocol}{$port}{target}= $target;
+
$firewall_configuration->{$chain}->{$num}{$protocol}{$port}{destination}=
$destination;
+
+ if (!defined($previous_protocol) ||
+ !defined($previous_port) ||
+
!defined($firewall_configuration->{$previous_protocol}) ||
+
!defined($firewall_configuration->{$previous_protocol}{$previous_port})
+ ) {
+ next;
+ }
+ elsif ($scope !~ /0.0.0.0\/0/) {
+
$firewall_configuration->{$previous_protocol}{$previous_port}{scope} = $scope;
+ }
+ }
+ }
-
+ notify($ERRORS{'DEBUG'}, 0, "retrieved firewall configuration from
$computer_node_name:\n" . format_data($firewall_configuration));
+ return $firewall_configuration;
}
#/////////////////////////////////////////////////////////////////////////////
@@ -561,64 +553,64 @@ sub get_firewall_configuration {
=cut
sub set_static_public_address {
- my $self = shift;
- if (ref($self) !~ /ubuntu/i) {
- notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it
must be called as a class method");
- return 0;
- }
-
- my $computer_name = $self->data->get_computer_short_name();
+ my $self = shift;
+ if (ref($self) !~ /ubuntu/i) {
+ notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
+ return 0;
+ }
+
+ my $computer_name = $self->data->get_computer_short_name();
my $request_id = $self->data->get_request_id();
my $server_request_id = $self->data->get_server_request_id();
- my $management_node_keys = $self->data->get_management_node_keys();
-
- my $server_request_fixedIP =
$self->data->get_server_request_fixedIP();
-
+ my $management_node_keys = $self->data->get_management_node_keys();
+
+ my $server_request_fixed_ip =
$self->data->get_server_request_fixed_ip();
+
+
+ # Make sure public IP configuration is static or this is a server
request
+ my $ip_configuration =
$self->data->get_management_node_public_ip_configuration();
+
+ if ($ip_configuration !~ /static/i) {
+ if ( !$server_request_fixed_ip ) {
+ notify($ERRORS{'WARNING'}, 0, "static public address
can only be set if IP configuration is static or is a server request, current
value: $ip_configuration \nserver_request_fixed_ip=$server_request_fixed_ip");
+ return;
+ }
+ }
+
+ # Get the IP configuration
+ my $interface_name = $self->get_public_interface_name() ||
'<undefined>';
+ my $computer_public_ip_address =
$self->data->get_computer_public_ip_address() || '<undefined>';
+ my $subnet_mask = $self->data->get_management_node_public_subnet_mask()
|| '<undefined>';
+ my $default_gateway =
$self->data->get_management_node_public_default_gateway() || '<undefined>';
+ my @dns_servers = $self->data->get_management_node_public_dns_servers();
+
+ if ($server_request_fixed_ip) {
+ $computer_public_ip_address = $server_request_fixed_ip;
+ $subnet_mask = $self->data->get_server_request_netmask();
+ $default_gateway = $self->data->get_server_request_router();
+ @dns_servers = $self->data->get_server_request_dns_servers();
+ }
- # Make sure public IP configuration is static or this is a server
request
- my $ip_configuration =
$self->data->get_management_node_public_ip_configuration();
-
- if ($ip_configuration !~ /static/i) {
- if ( !$server_request_fixedIP ) {
- notify($ERRORS{'WARNING'}, 0, "static public address can only be set
if IP configuration is static or is a server request, current value:
$ip_configuration \nserver_request_fixedIP=$server_request_fixedIP");
- return;
- }
- }
-
- # Get the IP configuration
- my $interface_name = $self->get_public_interface_name() || '<undefined>';
- my $computer_public_ip_address =
$self->data->get_computer_public_ip_address() || '<undefined>';
- my $subnet_mask = $self->data->get_management_node_public_subnet_mask() ||
'<undefined>';
- my $default_gateway =
$self->data->get_management_node_public_default_gateway() || '<undefined>';
- my @dns_servers = $self->data->get_management_node_public_dns_servers();
-
- if ($server_request_fixedIP) {
- $computer_public_ip_address = $server_request_fixedIP;
- $subnet_mask = $self->data->get_server_request_netmask();
- $default_gateway = $self->data->get_server_request_router();
- @dns_servers = $self->data->get_server_request_DNSservers();
- }
-
- # Make sure required info was retrieved
- if ("$interface_name $computer_public_ip_address $subnet_mask
$default_gateway" =~ /undefined/) {
- notify($ERRORS{'WARNING'}, 0, "failed to retrieve required network
configuration for $computer_name");
- return;
- }
- else {
- notify($ERRORS{'OK'}, 0, "attempting to set static public IP address on
$computer_name");
- }
+ # Make sure required info was retrieved
+ if ("$interface_name $computer_public_ip_address $subnet_mask
$default_gateway" =~ /undefined/) {
+ notify($ERRORS{'WARNING'}, 0, "failed to retrieve required
network configuration for $computer_name");
+ return;
+ }
+ else {
+ notify($ERRORS{'OK'}, 0, "attempting to set static public IP
address on $computer_name");
+ }
#Try to ping address to make sure it's available
- #FIXME -- need to add other tests for checking ip_address is or is not
available.
- if (_pingnode($computer_public_ip_address)) {
- notify($ERRORS{'WARNING'}, 0, "ip_address $computer_public_ip_address is
pingable, can not assign to $computer_name ");
- return;
- }
-
- # Assemble the ifcfg file path
- my $network_interfaces_file = "/etc/network/interfaces";
+ #FIXME -- need to add other tests for checking ip_address is or is not
available.
+ if (_pingnode($computer_public_ip_address)) {
+ notify($ERRORS{'WARNING'}, 0, "ip_address
$computer_public_ip_address is pingable, can not assign to $computer_name ");
+ return;
+ }
+
+ # Assemble the ifcfg file path
+ my $network_interfaces_file = "/etc/network/interfaces";
my $network_interfaces_file_default = "/etc/network/interfaces";
- notify($ERRORS{'DEBUG'}, 0, "interface file path:
$network_interfaces_file");
+ notify($ERRORS{'DEBUG'}, 0, "interface file path:
$network_interfaces_file");
if ($self->execute("cp network_interfaces_file
/etc/network/interfaces_orig")) {
notify($ERRORS{'OK'}, 0, "Created backup of
$network_interfaces_file");
@@ -626,34 +618,33 @@ sub set_static_public_address {
#Get interfaces file
my $tmpfile = "/tmp/$request_id.interfaces";
- if (run_scp_command("$computer_name:$network_interfaces_file", $tmpfile,
$management_node_keys)) {
- notify($ERRORS{'DEBUG'}, 0, "copied sshd init script from $computer_name
for local processing");
- }
- else{
- notify($ERRORS{'WARNING'}, 0, "failed to copied ssh init script from
$computer_name for local processing");
- return 0;
- }
-
+ if (run_scp_command("$computer_name:$network_interfaces_file",
$tmpfile, $management_node_keys)) {
+ notify($ERRORS{'DEBUG'}, 0, "copied sshd init script from
$computer_name for local processing");
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "failed to copied ssh init script
from $computer_name for local processing");
+ return 0;
+ }
+
my @interfaces = read_file_to_array($tmpfile);
#Build new interfaces file
my @new_interfaces_file;
-
+
foreach my $l (@interfaces) {
push(@new_interfaces_file, $l) if($l =~ /^(#.*)/ );
push(@new_interfaces_file, $l) if($l =~ /^auto lo/);
push(@new_interfaces_file, $l) if($l =~ /^\n$/);
-
+
if ($l =~ /^iface/) {
push(@new_interfaces_file, $l) if($l !~
/$interface_name/ );
}
-
+
if ($l =~ /^iface $interface_name/) {
push(@new_interfaces_file, "iface $interface_name inet
static\n");
push(@new_interfaces_file, "address
$computer_public_ip_address\n");
push(@new_interfaces_file, "netmask $subnet_mask\n");
push(@new_interfaces_file, "gateway
$default_gateway\n");
}
-
}
notify($ERRORS{'OK'}, 0, "output:\n" .
format_data(@new_interfaces_file));
@@ -661,122 +652,121 @@ sub set_static_public_address {
unlink($tmpfile);
#Write array to file
if (open(FILE, ">$tmpfile")) {
- print FILE @new_interfaces_file;
- close FILE;
- }
-
- #copy temp file to node
- if (run_scp_command($tmpfile, "$computer_name:/etc/network/interfaces",
$management_node_keys)) {
- notify($ERRORS{'DEBUG'}, 0, "copied $tmpfile to
$computer_name:/etc/network/interfaces");
- }
- else{
- notify($ERRORS{'WARNING'}, 0, "failed to copied $tmpfile to
$computer_name:/etc/network/interfaces");
- return 0;
- }
- unlink($tmpfile);
-
-
- # Restart the interface
- if (!$self->restart_network_interface($interface_name)) {
- notify($ERRORS{'WARNING'}, 0, "failed to restart public interface
$interface_name on $computer_name");
- return;
- }
-
- # Delete existing default route
- my $route_del_command = "/sbin/route del default";
- my ($route_del_exit_status, $route_del_output) =
$self->execute($route_del_command);
- if (!defined($route_del_output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to delete the
existing default route on $computer_name: '$route_del_command'");
- return;
- }
- elsif (grep(/No such process/i, @$route_del_output)) {
- notify($ERRORS{'DEBUG'}, 0, "existing default route is not set");
- }
- elsif ($route_del_exit_status) {
- notify($ERRORS{'WARNING'}, 0, "failed to delete existing default route
on $computer_name, exit status: $route_del_exit_status, command:
'$route_del_command', output:\n" . join("\n", @$route_del_output));
- return;
- }
- else {
- notify($ERRORS{'DEBUG'}, 0, "deleted existing default route on
$computer_name, output:\n" . join("\n", @$route_del_output));
- }
-
- # Set default route
- my $route_add_command = "/sbin/route add default gw $default_gateway metric
0 $interface_name 2>&1 && /sbin/route -n";
- my ($route_add_exit_status, $route_add_output) =
$self->execute($route_add_command);
- if (!defined($route_add_output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to add default
route to $default_gateway on public interface $interface_name on
$computer_name: '$route_add_command'");
- return;
- }
- elsif ($route_add_exit_status) {
- notify($ERRORS{'WARNING'}, 0, "failed to add default route to
$default_gateway on public interface $interface_name on $computer_name, exit
status: $route_add_exit_status, command: '$route_add_command', output:\n" .
join("\n", @$route_add_output));
- return;
- }
- else {
- notify($ERRORS{'DEBUG'}, 0, "added default route to $default_gateway on
public interface $interface_name on $computer_name, output:\n" .
format_data($route_add_output));
- }
-
- my $ext_sshd_config_file_path = '/etc/ssh/external_sshd_config';
+ print FILE @new_interfaces_file;
+ close FILE;
+ }
+
+ #copy temp file to node
+ if (run_scp_command($tmpfile, "$computer_name:/etc/network/interfaces",
$management_node_keys)) {
+ notify($ERRORS{'DEBUG'}, 0, "copied $tmpfile to
$computer_name:/etc/network/interfaces");
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "failed to copied $tmpfile to
$computer_name:/etc/network/interfaces");
+ return 0;
+ }
+ unlink($tmpfile);
+
+
+ # Restart the interface
+ if (!$self->restart_network_interface($interface_name)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to restart public
interface $interface_name on $computer_name");
+ return;
+ }
+
+ # Delete existing default route
+ my $route_del_command = "/sbin/route del default";
+ my ($route_del_exit_status, $route_del_output) =
$self->execute($route_del_command);
+ if (!defined($route_del_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to delete
the existing default route on $computer_name: '$route_del_command'");
+ return;
+ }
+ elsif (grep(/No such process/i, @$route_del_output)) {
+ notify($ERRORS{'DEBUG'}, 0, "existing default route is not
set");
+ }
+ elsif ($route_del_exit_status) {
+ notify($ERRORS{'WARNING'}, 0, "failed to delete existing
default route on $computer_name, exit status: $route_del_exit_status, command:
'$route_del_command', output:\n" . join("\n", @$route_del_output));
+ return;
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "deleted existing default route on
$computer_name, output:\n" . join("\n", @$route_del_output));
+ }
+
+ # Set default route
+ my $route_add_command = "/sbin/route add default gw $default_gateway
metric 0 $interface_name 2>&1 && /sbin/route -n";
+ my ($route_add_exit_status, $route_add_output) =
$self->execute($route_add_command);
+ if (!defined($route_add_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to add
default route to $default_gateway on public interface $interface_name on
$computer_name: '$route_add_command'");
+ return;
+ }
+ elsif ($route_add_exit_status) {
+ notify($ERRORS{'WARNING'}, 0, "failed to add default route to
$default_gateway on public interface $interface_name on $computer_name, exit
status: $route_add_exit_status, command: '$route_add_command', output:\n" .
join("\n", @$route_add_output));
+ return;
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "added default route to
$default_gateway on public interface $interface_name on $computer_name,
output:\n" . format_data($route_add_output));
+ }
+
+ my $ext_sshd_config_file_path = '/etc/ssh/external_sshd_config';
# Remove existing ListenAddress lines from external_sshd_config
$self->remove_lines_from_file($ext_sshd_config_file_path,
'ListenAddress') || return;
# Add ListenAddress line to the end of the file
$self->append_text_file($ext_sshd_config_file_path, "ListenAddress
$computer_public_ip_address\n") || return;
-
- # Update resolv.conf if DNS server address is configured for the management
node
- my $resolv_conf_path = "/etc/resolv.conf";
- if (@dns_servers) {
- # Get the resolve.conf contents
- my $cat_resolve_command = "cat $resolv_conf_path";
- my ($cat_resolve_exit_status, $cat_resolve_output) =
$self->execute($cat_resolve_command);
- if (!defined($cat_resolve_output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to retrieve
existing $resolv_conf_path contents from $computer_name");
- return;
- }
- elsif ($cat_resolve_exit_status || grep(/^(bash:|cat:)/,
@$cat_resolve_output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to retrieve existing
$resolv_conf_path contents from $computer_name, exit status:
$cat_resolve_exit_status, command: '$cat_resolve_command', output:\n" .
join("\n", @$cat_resolve_output));
- return;
- }
- else {
- notify($ERRORS{'DEBUG'}, 0, "retrieved existing $resolv_conf_path
contents from $computer_name:\n" . join("\n", @$cat_resolve_output));
- }
-
- # Remove lines containing nameserver
- my @resolv_conf_lines = grep(!/nameserver/i, @$cat_resolve_output);
-
- # Add a nameserver line for each configured DNS server
- for my $dns_server_address (@dns_servers) {
- push @resolv_conf_lines, "nameserver $dns_server_address";
- }
-
- # Remove newlines for consistency
- map { chomp $_ } @resolv_conf_lines;
-
- # Assemble the lines into an array
- my $resolv_conf_contents = join("\n", @resolv_conf_lines);
-
- # Echo the updated contents to resolv.conf
- my $echo_resolve_command = "echo \"$resolv_conf_contents\" >
$resolv_conf_path 2>&1 && cat $resolv_conf_path";
- my ($echo_resolve_exit_status, $echo_resolve_output) =
$self->execute($echo_resolve_command);
- if (!defined($echo_resolve_output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to update
$resolv_conf_path on $computer_name:\n$echo_resolve_command");
- return;
- }
- elsif ($echo_resolve_exit_status) {
- notify($ERRORS{'WARNING'}, 0, "failed to update $resolv_conf_path on
$computer_name, exit status:
$echo_resolve_exit_status\ncommand:\n$echo_resolve_command\noutput:\n" .
join("\n", @$echo_resolve_output));
- return;
- }
- else {
- notify($ERRORS{'DEBUG'}, 0, "updated $resolv_conf_path on
$computer_name:\n" . join("\n", @$echo_resolve_output));
- }
- }
- else {
- notify($ERRORS{'DEBUG'}, 0, "$resolv_conf_path not updated on
$computer_name because DNS server address is not configured for the management
node");
- }
-
- notify($ERRORS{'OK'}, 0, "successfully set static public IP address on
$computer_name");
- return 1;
-
+
+ # Update resolv.conf if DNS server address is configured for the
management node
+ my $resolv_conf_path = "/etc/resolv.conf";
+ if (@dns_servers) {
+ # Get the resolve.conf contents
+ my $cat_resolve_command = "cat $resolv_conf_path";
+ my ($cat_resolve_exit_status, $cat_resolve_output) =
$self->execute($cat_resolve_command);
+ if (!defined($cat_resolve_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to
retrieve existing $resolv_conf_path contents from $computer_name");
+ return;
+ }
+ elsif ($cat_resolve_exit_status || grep(/^(bash:|cat:)/,
@$cat_resolve_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to retrieve
existing $resolv_conf_path contents from $computer_name, exit status:
$cat_resolve_exit_status, command: '$cat_resolve_command', output:\n" .
join("\n", @$cat_resolve_output));
+ return;
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "retrieved existing
$resolv_conf_path contents from $computer_name:\n" . join("\n",
@$cat_resolve_output));
+ }
+
+ # Remove lines containing nameserver
+ my @resolv_conf_lines = grep(!/nameserver/i,
@$cat_resolve_output);
+
+ # Add a nameserver line for each configured DNS server
+ for my $dns_server_address (@dns_servers) {
+ push @resolv_conf_lines, "nameserver
$dns_server_address";
+ }
+
+ # Remove newlines for consistency
+ map { chomp $_ } @resolv_conf_lines;
+
+ # Assemble the lines into an array
+ my $resolv_conf_contents = join("\n", @resolv_conf_lines);
+
+ # Echo the updated contents to resolv.conf
+ my $echo_resolve_command = "echo \"$resolv_conf_contents\" >
$resolv_conf_path 2>&1 && cat $resolv_conf_path";
+ my ($echo_resolve_exit_status, $echo_resolve_output) =
$self->execute($echo_resolve_command);
+ if (!defined($echo_resolve_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to
update $resolv_conf_path on $computer_name:\n$echo_resolve_command");
+ return;
+ }
+ elsif ($echo_resolve_exit_status) {
+ notify($ERRORS{'WARNING'}, 0, "failed to update
$resolv_conf_path on $computer_name, exit status:
$echo_resolve_exit_status\ncommand:\n$echo_resolve_command\noutput:\n" .
join("\n", @$echo_resolve_output));
+ return;
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "updated $resolv_conf_path
on $computer_name:\n" . join("\n", @$echo_resolve_output));
+ }
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "$resolv_conf_path not updated on
$computer_name because DNS server address is not configured for the management
node");
+ }
+
+ notify($ERRORS{'OK'}, 0, "successfully set static public IP address on
$computer_name");
+ return 1;
}
#/////////////////////////////////////////////////////////////////////////////
@@ -790,37 +780,37 @@ sub set_static_public_address {
=cut
sub restart_network_interface {
- 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 0;
- }
-
- my $interface_name = shift;
- if (!$interface_name) {
- notify($ERRORS{'WARNING'}, 0, "unable to restart network interface,
interface name argument was not supplied");
- return;
- }
-
- my $computer_name = $self->data->get_computer_short_name();
-
- # Restart the interface
- notify($ERRORS{'DEBUG'}, 0, "attempting to restart network interface
$interface_name on $computer_name");
- my $interface_restart_command = "/sbin/ifdown $interface_name ; /sbin/ifup
$interface_name";
- my ($interface_restart_exit_status, $interface_restart_output) =
$self->execute($interface_restart_command);
- if (!defined($interface_restart_output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to run command to restart
interface $interface_name on $computer_name: '$interface_restart_command'");
- return;
- }
- elsif ($interface_restart_exit_status) {
- notify($ERRORS{'WARNING'}, 0, "failed to restart network interface
$interface_name on $computer_name, exit status: $interface_restart_exit_status,
command: '$interface_restart_command', output:\n" . join("\n",
@$interface_restart_output));
- return;
- }
- else {
- notify($ERRORS{'DEBUG'}, 0, "restarted network interface $interface_name
on $computer_name");
- }
-
- return 1;
+ 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 0;
+ }
+
+ my $interface_name = shift;
+ if (!$interface_name) {
+ notify($ERRORS{'WARNING'}, 0, "unable to restart network
interface, interface name argument was not supplied");
+ return;
+ }
+
+ my $computer_name = $self->data->get_computer_short_name();
+
+ # Restart the interface
+ notify($ERRORS{'DEBUG'}, 0, "attempting to restart network interface
$interface_name on $computer_name");
+ my $interface_restart_command = "/sbin/ifdown $interface_name ;
/sbin/ifup $interface_name";
+ my ($interface_restart_exit_status, $interface_restart_output) =
$self->execute($interface_restart_command);
+ if (!defined($interface_restart_output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to run command to restart
interface $interface_name on $computer_name: '$interface_restart_command'");
+ return;
+ }
+ elsif ($interface_restart_exit_status) {
+ notify($ERRORS{'WARNING'}, 0, "failed to restart network
interface $interface_name on $computer_name, exit status:
$interface_restart_exit_status, command: '$interface_restart_command',
output:\n" . join("\n", @$interface_restart_output));
+ return;
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "restarted network interface
$interface_name on $computer_name");
+ }
+
+ return 1;
}
#/////////////////////////////////////////////////////////////////////////////
@@ -836,40 +826,37 @@ sub restart_network_interface {
=cut
sub update_hostname_file {
- 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 0;
- }
-
- my $public_hostname = shift;
- if (!$public_hostname) {
- notify($ERRORS{'WARNING'}, 0, "public_hostname was not passed
correctly");
- return 0;
- }
-
- my $computer_node_name = $self->data->get_computer_node_name();
- my $network_file_path = '/etc/hostname';
-
- my $command = "echo \"$public_hostname\" > $network_file_path";
- my ($exit_status, $output) = $self->execute($command);
- if (!defined($output)) {
- notify($ERRORS{'WARNING'}, 0, "failed to SSH command to set hostname on
$computer_node_name to $public_hostname, command: '$command'");
- return;
- }
- elsif ($exit_status == 0) {
- notify($ERRORS{'OK'}, 0, "set public hostname on $computer_node_name to
$public_hostname");
- return 1;
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "failed to set public hostname on
$computer_node_name to $public_hostname, exit status: $exit_status, output:\n"
. join("\n", @ $output));
- return 0;
- }
-
+ 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 0;
+ }
+
+ my $public_hostname = shift;
+ if (!$public_hostname) {
+ notify($ERRORS{'WARNING'}, 0, "public_hostname was not passed
correctly");
+ return 0;
+ }
+
+ my $computer_node_name = $self->data->get_computer_node_name();
+ my $network_file_path = '/etc/hostname';
+
+ my $command = "echo \"$public_hostname\" > $network_file_path";
+ my ($exit_status, $output) = $self->execute($command);
+ if (!defined($output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to SSH command to set
hostname on $computer_node_name to $public_hostname, command: '$command'");
+ return;
+ }
+ elsif ($exit_status == 0) {
+ notify($ERRORS{'OK'}, 0, "set public hostname on
$computer_node_name to $public_hostname");
+ return 1;
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "failed to set public hostname on
$computer_node_name to $public_hostname, exit status: $exit_status, output:\n"
. join("\n", @ $output));
+ return 0;
+ }
}
-
-
#/////////////////////////////////////////////////////////////////////////////
=head2 activate_interfaces
Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/UnixLab.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/UnixLab.pm?rev=1644246&r1=1644245&r2=1644246&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/UnixLab.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/UnixLab.pm Tue Dec 9
23:56:55 2014
@@ -116,14 +116,14 @@ sub revoke_access {
if (run_scp_command($clientdata, $target, $identity, "24")) {
notify($ERRORS{'OK'}, 0, "Success copied $clientdata to
$target");
unlink($clientdata);
-
+
# send flag to activate changes
my @sshcmd =
run_ssh_command($computer_public_ip_address, $identity, "echo 1 >
/home/vclstaff/flag", "vclstaff", "24");
notify($ERRORS{'OK'}, 0, "setting flag to 1 on
$computer_public_ip_address");
-
+
my $nmapchecks = 0;
# return nmap check
-
+
NMAPPORT:
if (!(nmap_port($computer_public_ip_address, 22))) {
return 1;
@@ -152,7 +152,6 @@ sub revoke_access {
}
return 1;
-
} ## end sub revoke_access
#/////////////////////////////////////////////////////////////////////////////
@@ -171,7 +170,7 @@ sub reserve {
notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
return 0;
}
-
+
return 1;
}
@@ -191,7 +190,7 @@ sub grant_access {
notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
return 0;
}
-
+
my $user = $self->data->get_user_login_id();
my $computer_node_name = $self->data->get_computer_node_name();
my $computer_public_ip_address =
$self->data->get_computer_public_ip_address;
@@ -211,19 +210,19 @@ sub grant_access {
print CLIENTDATA "$user\n";
print CLIENTDATA "$remoteIP\n";
close CLIENTDATA;
-
+
# scp to hostname
my $target =
"vclstaff\@$computer_public_ip_address:/home/vclstaff/clientdata";
if (run_scp_command($clientdata, $target, $identity, "24")) {
notify($ERRORS{'OK'}, 0, "Success copied $clientdata to
$target");
unlink($clientdata);
-
+
# send flag to activate changes
my @sshcmd =
run_ssh_command($computer_public_ip_address, $identity, "echo 1 >
/home/vclstaff/flag", "vclstaff", "24");
notify($ERRORS{'OK'}, 0, "setting flag to 1 on
$computer_public_ip_address");
-
+
my $nmapchecks = 0;
-
+
NMAPPORT:
if (nmap_port($computer_public_ip_address, 22)) {
notify($ERRORS{'OK'}, 0, "sshd opened");
@@ -253,10 +252,8 @@ sub grant_access {
}
return 1;
-
} ## end sub grant_access
-
#/////////////////////////////////////////////////////////////////////////////
=head2 post_reserve
@@ -287,9 +284,9 @@ sub sanitize {
notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
return;
}
-
+
my $computer_node_name = $self->data->get_computer_node_name();
-
+
# Delete all user associated with the reservation
if ($self->revoke_access()) {
notify($ERRORS{'OK'}, 0, "access has been disabled for
$computer_node_name");
@@ -298,7 +295,7 @@ sub sanitize {
notify($ERRORS{'WARNING'}, 0, "failed to delete users from
$computer_node_name");
return 0;
}
-
+
notify($ERRORS{'OK'}, 0, "$computer_node_name has been sanitized");
return 1;
} ## end sub sanitize
@@ -345,77 +342,75 @@ sub get_current_image_name {
=cut
sub check_connection_on_port {
- 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");
- return;
- }
-
- my $management_node_keys =
$self->data->get_management_node_keys();
- my $computer_node_name =
$self->data->get_computer_node_name();
- my $remote_ip =
$self->data->get_reservation_remote_ip();
- my $computer_public_ip_address =
$self->data->get_computer_public_ip_address();
- my $request_state_name =
$self->data->get_request_state_name();
-
- my $port = shift;
- if (!$port) {
- notify($ERRORS{'WARNING'}, 0, "port variable was not passed as
an argument");
- return "failed";
- }
-
- my $ret_val = "no";
- my $command = "netstat -an";
- my ($status, $output) = run_ssh_command($computer_node_name,
$management_node_keys, $command, 'vclstaff', 24, 1);
- notify($ERRORS{'DEBUG'}, 0, "checking connections on node
$computer_node_name on port $port");
- foreach my $line (@{$output}) {
- if ($line =~ /Connection refused|Permission denied/) {
- chomp($line);
- notify($ERRORS{'WARNING'}, 0, "$line");
- if ($request_state_name =~ /reserved/) {
- $ret_val = "failed";
- }
- else {
- $ret_val = "timeout";
- }
- return $ret_val;
- } ## end if ($line =~ /Connection refused|Permission denied/)
- if ($line =~
/tcp\s+([0-9]*)\s+([0-9]*)\s($computer_public_ip_address:$port)\s+([.0-9]*):([0-9]*)(.*)(ESTABLISHED)/)
{
- if ($4 eq $remote_ip) {
- $ret_val = "connected";
- return $ret_val;
- }
- else {
- #this isn't the remoteIP
- $ret_val = "conn_wrong_ip";
- return $ret_val;
- }
- } # Linux
- if ($line =~
/tcp\s+([0-9]*)\s+([0-9]*)\s::ffff:($computer_public_ip_address:$port)\s+::ffff:([.0-9]*):([0-9]*)(.*)(ESTABLISHED)
/) {
- if ($4 eq $remote_ip) {
- $ret_val = "connected";
- return $ret_val;
- }
- else {
- #this isn't the remoteIP
- $ret_val = "conn_wrong_ip";
- return $ret_val;
- }
- } ##
+ 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");
+ return;
+ }
+
+ my $management_node_keys =
$self->data->get_management_node_keys();
+ my $computer_node_name = $self->data->get_computer_node_name();
+ my $remote_ip =
$self->data->get_reservation_remote_ip();
+ my $computer_public_ip_address =
$self->data->get_computer_public_ip_address();
+ my $request_state_name = $self->data->get_request_state_name();
+
+ my $port = shift;
+ if (!$port) {
+ notify($ERRORS{'WARNING'}, 0, "port variable was not passed as
an argument");
+ return "failed";
+ }
+
+ my $ret_val = "no";
+ my $command = "netstat -an";
+ my ($status, $output) = run_ssh_command($computer_node_name,
$management_node_keys, $command, 'vclstaff', 24, 1);
+ notify($ERRORS{'DEBUG'}, 0, "checking connections on node
$computer_node_name on port $port");
+ foreach my $line (@{$output}) {
+ if ($line =~ /Connection refused|Permission denied/) {
+ chomp($line);
+ notify($ERRORS{'WARNING'}, 0, "$line");
+ if ($request_state_name =~ /reserved/) {
+ $ret_val = "failed";
+ }
+ else {
+ $ret_val = "timeout";
+ }
+ return $ret_val;
+ } ## end if ($line =~ /Connection refused|Permission denied/)
+ if ($line =~
/tcp\s+([0-9]*)\s+([0-9]*)\s($computer_public_ip_address:$port)\s+([.0-9]*):([0-9]*)(.*)(ESTABLISHED)/)
{
+ if ($4 eq $remote_ip) {
+ $ret_val = "connected";
+ return $ret_val;
+ }
+ else {
+ #this isn't the remoteIP
+ $ret_val = "conn_wrong_ip";
+ return $ret_val;
+ }
+ } # Linux
+ if ($line =~
/tcp\s+([0-9]*)\s+([0-9]*)\s::ffff:($computer_public_ip_address:$port)\s+::ffff:([.0-9]*):([0-9]*)(.*)(ESTABLISHED)
/) {
+ if ($4 eq $remote_ip) {
+ $ret_val = "connected";
+ return $ret_val;
+ }
+ else {
+ #this isn't the remoteIP
+ $ret_val = "conn_wrong_ip";
+ return $ret_val;
+ }
+ } ##
if ($line =~
/\s*($computer_public_ip_address\.$port)\s+([.0-9]*)\.([0-9]*)(.*)(ESTABLISHED)/)
{
- if ($4 eq $remote_ip) {
- $ret_val = "connected";
- return $ret_val;
- }
- else {
- #this isn't the remoteIP
- $ret_val = "conn_wrong_ip";
- return $ret_val;
- }
- } ##
-
-
- }
- return $ret_val;
+ if ($4 eq $remote_ip) {
+ $ret_val = "connected";
+ return $ret_val;
+ }
+ else {
+ #this isn't the remoteIP
+ $ret_val = "conn_wrong_ip";
+ return $ret_val;
+ }
+ } ##
+ }
+ return $ret_val;
}
#/////////////////////////////////////////////////////////////////////////////
@@ -424,31 +419,31 @@ sub check_connection_on_port {
Parameters : $computer_name (optional), $max_attempts (optional)
Returns : If computer responds to SSH: 1
If computer never responds to SSH: 0
- Description : Checks if the computer is
responding to SSH. Ports 22 and 24 are
+ Description : Checks if the computer is responding to SSH.
Ports 22 and 24 are
first checked to see if either is open. If neither is open, 0 is
returned. If either of the ports is open a test SSH command
which
simply echo's a string is attempted. The default is to only
attempt to run this command once. This can be changed by
supplying the $max_attempts argument. If the $max_attempts is
- supplied but set to 0, only the port
checks are done.
+ supplied but set to 0, only the port checks are done.
=cut
sub is_ssh_responding {
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");
- return;
+ notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
+ return;
}
my $computer_node_name;
my $max_attempts = 1;
-
+
my $argument_1 = shift;
my $argument_2 = shift;
-
+
if ($argument_1) {
- # Check if the argument is an integer
+ # Check if the argument is an integer
if ($argument_1 =~ /^\d+$/) {
$max_attempts = $argument_1;
}
@@ -503,13 +498,12 @@ sub is_ssh_responding {
=head2 firewall_compare_update
Parameters : $computer_name (optional), $max_attempts (optional)
- Returns : returns true.
- Since the vclstaff user doesn't have
root on the lab machines, there is not much this routine can do.
+ Returns : returns true.
+ Since the vclstaff user doesn't have root on the lab machines,
there is not much this routine can do.
=cut
sub firewall_compare_update {
-
return 1;
}
@@ -530,30 +524,30 @@ sub notify_user_console {
notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
return;
}
-
+
my $message = shift;
if (!$message) {
notify($ERRORS{'WARNING'}, 0, "message argument was not
supplied");
return;
}
-
+
my $username = shift;
if (!$username) {
- $username = $self->data->get_user_login_id();
+ $username = $self->data->get_user_login_id();
}
-
+
my $computer_node_name = $self->data->get_computer_node_name();
-
+
my $cmd = "echo \"$message\" \| write $username";
my ($exit_status, $output) = $self->execute({
- node => $computer_node_name,
- command => $cmd,
- display_output => 0,
- timeout => 30,
- max_attempts => 2,
- port => 24,
- user => "vclstaff",
- });
+ node => $computer_node_name,
+ command => $cmd,
+ display_output => 0,
+ timeout => 30,
+ max_attempts => 2,
+ port => 24,
+ user => "vclstaff",
+ });
if (!defined($output)) {
notify($ERRORS{'WARNING'}, 0, "failed to execute command to
determine if the '$cmd' shell command exists on $computer_node_name");
return;
@@ -564,7 +558,6 @@ sub notify_user_console {
}
}
-
#/////////////////////////////////////////////////////////////////////////////
=head2 get_current_image_info
@@ -586,24 +579,24 @@ sub get_current_image_info {
notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
return;
}
-
+
my $input = shift;
-
+
if (!defined $input) {
$input = "imagerevision_id";
}
-
+
my $computer_node_name = $self->data->get_computer_node_name();
my $imagerevision_id = $self->data->get_imagerevision_id();
-
+
#The Lab machine image does have a currentimage.txt file.
#Predefine matching variables so it doesn't fail.
-
+
my %current_image_txt_contents;
$current_image_txt_contents{"imagerevision_id"} = $imagerevision_id;
my $time = localtime;
$current_image_txt_contents{"vcld_post_load"} = "vcld_post_load=success
($time)";
-
+
# Make sure an empty hash wasn't returned
if (defined $current_image_txt_contents{imagerevision_id}) {
notify($ERRORS{'DEBUG'}, 0, "user selected content of image
currently loaded on $computer_node_name:
$current_image_txt_contents{current_image_name}");