A reminder that there is a "Grant license to ASF for inclusion in ASF works" radio button when attaching files to Jira.
This is the clearest indication of a contributors intent. Please validate this when accepting patches… --kevan On May 23, 2012, at 10:10 AM, fapee...@apache.org wrote: > Author: fapeeler > Date: Wed May 23 14:10:39 2012 > New Revision: 1341871 > > URL: http://svn.apache.org/viewvc?rev=1341871&view=rev > Log: > VCL-579 > > Based on contribtion from Dmitri Chebotarov, Thanks Dmitri > > I added some addtional routines as placeholders for future code that might > need to be addressed. > > > > Modified: > incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm > > Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm > URL: > http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm?rev=1341871&r1=1341870&r2=1341871&view=diff > ============================================================================== > --- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm > (original) > +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm Wed > May 23 14:10:39 2012 > @@ -100,6 +100,289 @@ sub post_load { > > #///////////////////////////////////////////////////////////////////////////// > > +=head2 reserve > + > + Parameters : > + Returns : > + Description : > + > +=cut > + > +sub reserve { > + 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 0; > + } > + notify($ERRORS{'DEBUG'}, 0, "Enterered reserve() in the ESXi OS module"); > + > + return 1; > +} > + > +#///////////////////////////////////////////////////////////////////////////// > + > +=head2 grant_access > + > + Parameters : > + Returns : > + Description : this sub called when user clicks Connect button on web GUI > + > +=cut > + > +sub grant_access { > + 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 0; > + } > + > + my $esxi_storage_mount_command; > + my @commands; > + > + my $computer_short_name = $self->data->get_computer_short_name(); > + my $computer_node_name = $self->data->get_computer_node_name(); > + notify($ERRORS{'OK'}, 0, "$computer_short_name: processing with > ESXi.pm::grant_access()"); > + > + my $username = $self->data->get_user_login_id(); > + my $reservation_password = $self->data->get_reservation_password(); > + my $management_node_keys = $self->data->get_management_node_keys(); > + > + my $vcld_config = &local_read_vcld_config("/etc/vcl/vcld.conf"); > + my $esxi_storage_name_prefix = $vcld_config->{"ESXI_STORAGE_NAME_PREFIX"}; > + my $esxi_storage_address = $vcld_config->{"ESXI_STORAGE_ADDRESS"}; > + my $esxi_storage_volume = $vcld_config->{"ESXI_STORAGE_VOLUME"}; > + > + $esxi_storage_mount_command = "esxcfg-nas -a > $esxi_storage_name_prefix-$username -o $esxi_storage_address -s > $esxi_storage_volume/$username"; > + > + push(@commands, "chmod +w /etc/pam.d/system-auth"); > + push(@commands, "echo s/min=8,8,8,7,6/min=8,8,8,7,6 enforce=none/g > > /tmp/sed"); > + push(@commands, "sed -f /tmp/sed -i /etc/pam.d/system-auth"); > + push(@commands, "rm -f /tmp/sed"); > + push(@commands, "chmod -w /etc/pam.d/system-auth"); > + push(@commands, "useradd -M $username"); > + push(@commands, "groupadd root $username"); > + push(@commands, "echo $reservation_password \| passwd $username > --stdin"); > + push(@commands, "vim-cmd vimsvc/auth/entity_permission_add > vim.Folder:ha-folder-root root true Admin true"); > + push(@commands, $esxi_storage_mount_command) if > ($esxi_storage_mount_command); > + push(@commands, "sleep 3"); > + push(@commands, "echo /uuid.action/c > /tmp/sed"); > + push(@commands, "echo \\\$ a uuid.action = \\\"keep\\\" >> /tmp/sed"); > + push(@commands, "find /vmfs/volumes/$esxi_storage_name_prefix-$username/ > -name *.vmx -exec sed -f /tmp/sed -i {} \\;"); > + push(@commands, "rm -rf /tmp/sed"); > + push(@commands, "find > /vmfs/volumes/$esxi_storage_name_prefix-$username/ -name *.vmx -exec vim-cmd > solo/registervm {} \\;"); > + > + foreach my $command (@commands) { > + my ($exit_status, $output) = run_ssh_command($computer_node_name, > $management_node_keys, $command, "root"); > + if (!defined($output)) { > + notify($ERRORS{'WARNING'}, 0, "failed to run SSH command: > $command"); > + return; > + } > + } > + return 1; > + > +} > + > +#///////////////////////////////////////////////////////////////////////////// > + > +=head2 sanitize > + > + Parameters : > + Returns : > + Description : does ESXi need to reload? Check if user ever clicked connect > button, if never then don't reload > + > +=cut > + > +sub sanitize { > + 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_short_name = $self->data->get_computer_short_name(); > + my $computer_state_name = $self->data->get_computer_state_name(); > + > + if ($computer_state_name =~ /^(inuse)$/) { > + notify($ERRORS{'OK'}, 0, "$computer_short_name : need to reload."); > + return 0; > + } else { > + notify($ERRORS{'OK'}, 0, "$computer_short_name : user never connected. > No need to reload."); > + return 1; > + } > +} > +#///////////////////////////////////////////////////////////////////////////// > +=head2 local_read_vcld_config > + > + Parameters : full path to vcld.conf > + Returns : vcld_config array with all vcld.conf values > + Description : this is local sub to read vcld.conf file > + > +=cut > + > +sub local_read_vcld_config { > + my ($value,$config_file,$vcld_config); > + ($config_file) = @_; > + open (CONFIG,$config_file) or die "cannot open vcld.conf file"; > + while (<CONFIG>) { > + chomp; > + s/#.*//; > + s/^\s+//; > + s/\s+$//; > + next unless length; > + my ($var,$value) = split(/\s*=\s*/,$_, 2); > + $vcld_config->{$var} = $value; > + } > + return $vcld_config; > +} > + > +#///////////////////////////////////////////////////////////////////////////// > + > +=head2 get_public_ip_address > + > + Parameters : > + Returns : public IP address (IP address on interface vmk1) > + Description : retrive Public IP address from ESXi server. This should be > vmk1 interface > + > +=cut > + > +sub get_public_ip_address { > + 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 $public_ip_address; > + > + my $command = "esxcfg-vmknic -l"; > + my ($exit_status, $output) = $self->execute($command); > + if (!defined($output)) { > + notify($ERRORS{'WARNING'}, 0, "failed to run command to retrieve > network configuration: $command"); > + return; > + } > + for my $line (@$output) { > + if ($line =~ /vmk1/) { > + my @vmk1 = split(/ +/,$line); > + for my $vmk1_line (@vmk1) { > + if ($vmk1_line =~ /(\d+)(\.\d+){3}/) { > + $public_ip_address = $vmk1_line; > + last; > + } > + } > + } > + } > + > + return $public_ip_address; > +} > + > + > +#///////////////////////////////////////////////////////////////////////////// > + > +=head2 enable_firewall_port > + > + Parameters : $protocol, $port, $scope (optional) > + Returns : 1 if succeeded, 0 otherwise > + Description : Enables a firewall port on the computer. The protocol and port > + arguments are required. An optional scope argument may > supplied. > + > +# called by OS::process_connect_methods() > + > +=cut > + > +sub enable_firewall_port { > + > + #TODO > + my $self = shift; > + if (ref($self) !~ /osx/i) { > + notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, > it must be called as a class method"); > + return; > + } > + > + return 1; > +} > + > +#///////////////////////////////////////////////////////////////////////////// > + > +=head2 get_cpu_core_count > + > + Parameters : none > + Returns : integer > + Description : Retrieves the number of CPU cores the computer has by querying > + the NUMBER_OF_PROCESSORS environment variable. > + > +# called by Provisioning::VMware:VMware.pm > +# Windows.pm only returns value from database > +# return $self->get_environment_variable_value('NUMBER_OF_PROCESSORS'); > + > +=cut > + > +sub get_cpu_core_count { > + #TODO > + my $self = shift; > + if (ref($self) !~ /osx/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(); > + return 1; > +} > + > +#///////////////////////////////////////////////////////////////////////////// > + > +=head2 check_connection_on_port > + > + Parameters : $port > + Returns : (connected|conn_wrong_ip|timeout|failed) > + Description : uses netstat to see if any thing is connected to the provided > port > + > +# called by OS.pm:is_user_connected() > + > +=cut > + > +sub check_connection_on_port { > + #TODO > + my $self = shift; > + if (ref($self) !~ /osx/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 $remote_ip = > $self->data->get_reservation_remote_ip(); > + my $computer_ip_address = $self->data->get_computer_ip_address(); > + > + my $port = shift; > + if (!$port) { > + notify($ERRORS{'WARNING'}, 0, "port variable was not passed as an > argument"); > + return "failed"; > + } > + return 1; > +} > + > +#///////////////////////////////////////////////////////////////////////////// > + > +=head2 user_exists > + > + Parameters : > + Returns : > + Description : > + > +=cut > + > +sub user_exists { > + #TODO > + my $self = shift; > + if (ref($self) !~ /osx/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(); > + return 1; > +} > +#///////////////////////////////////////////////////////////////////////////// > + > 1; > __END__ > > >