Few housekeeping changes
- Whitespace cleanup - Removed the 'hardcoded' username and password. Will not throw an error if it is not defined or blank in /etc/pve/storage.cfg for each ZFS via ISCSI definition. - Used a Ternary (Elvis - ?:) Operator for the scheme variable.
This commit is contained in:
		
							parent
							
								
									32d243b872
								
							
						
					
					
						commit
						42edb8614e
					
				|  | @ -26,10 +26,8 @@ sub get_base { | ||||||
| sub run_lun_command { | sub run_lun_command { | ||||||
|     my ($scfg, $timeout, $method, @params) = @_; |     my ($scfg, $timeout, $method, @params) = @_; | ||||||
| 
 | 
 | ||||||
|     # TODO : Move configuration of the storage |     if(!defined($scfg->{'freenas_user'}) || !defined($scfg->{'freenas_password'})) { | ||||||
|     if(!defined($scfg->{'freenas_user'})) { |         die "Undefined freenas_user and/or freenas_password."; | ||||||
|         $scfg->{'freenas_user'} = 'root'; |  | ||||||
|         $scfg->{'freenas_password'} = '*** password ***'; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     syslog("info","FreeNAS::lun_command : $method(@params)"); |     syslog("info","FreeNAS::lun_command : $method(@params)"); | ||||||
|  | @ -106,7 +104,7 @@ sub run_list_lu { | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     if(!defined($result)) { |     if(!defined($result)) { | ||||||
|       syslog("info","FreeNAS::list_lu($object):$result_value_type : lun not found"); |         syslog("info","FreeNAS::list_lu($object):$result_value_type : lun not found"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return $result; |     return $result; | ||||||
|  | @ -128,8 +126,8 @@ sub run_list_extent { | ||||||
|             last; |             last; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     if(!defined($result)) { |     if (!defined($result)) { | ||||||
|       syslog("info","FreeNAS::list_extent($object): naa not found"); |         syslog("info","FreeNAS::list_extent($object): naa not found"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return $result; |     return $result; | ||||||
|  | @ -231,19 +229,17 @@ sub run_delete_lu { | ||||||
| sub freenas_api_call { | sub freenas_api_call { | ||||||
|     my ($scfg, $method, $path, $data) = @_; |     my ($scfg, $method, $path, $data) = @_; | ||||||
|     my $client = undef; |     my $client = undef; | ||||||
|     my $scheme = 'http'; |     my $scheme = $scfg->{freenas_use_ssl} ? "https" : "http"; | ||||||
| 
 | 
 | ||||||
|     $client = REST::Client->new(); |     $client = REST::Client->new(); | ||||||
|     if ($scfg->{freenas_use_ssl}) { |     $client->setHost($scheme . '://' . $scfg->{portal}); | ||||||
|         $scheme = 'https'; |  | ||||||
|     } |  | ||||||
|     $client->setHost($scheme . '://'.  $scfg->{portal}); |  | ||||||
|     $client->addHeader('Content-Type'  , 'application/json'); |     $client->addHeader('Content-Type'  , 'application/json'); | ||||||
|     $client->addHeader('Authorization' , 'Basic ' . encode_base64(  $scfg->{freenas_user} . ':' .  $scfg->{freenas_password})); |     $client->addHeader('Authorization' , 'Basic ' . encode_base64($scfg->{freenas_user} . ':' . $scfg->{freenas_password})); | ||||||
|     # don't verify SSL certs |     # If using SSL, don't verify SSL certs | ||||||
|     $client->getUseragent()->ssl_opts(verify_hostname => 0); |     if ($scfg->{freenas_use_ssl}) { | ||||||
|     $client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE ); |         $client->getUseragent()->ssl_opts(verify_hostname => 0); | ||||||
| 
 |         $client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE); | ||||||
|  |     } | ||||||
|     if ($method eq 'GET') { |     if ($method eq 'GET') { | ||||||
|         $client->GET($path); |         $client->GET($path); | ||||||
|     } |     } | ||||||
|  | @ -295,12 +291,12 @@ sub freenas_iscsi_get_extent { | ||||||
| 
 | 
 | ||||||
|     my $code = $client->responseCode(); |     my $code = $client->responseCode(); | ||||||
|     if ($code == 200) { |     if ($code == 200) { | ||||||
|       my $result = decode_json($client->responseContent()); |         my $result = decode_json($client->responseContent()); | ||||||
|       syslog("info","FreeNAS::API::get_extent : sucessfull"); |         syslog("info","FreeNAS::API::get_extent : sucessfull"); | ||||||
|       return $result; |         return $result; | ||||||
|     } else { |     } else { | ||||||
|       freenas_api_log_error($client, "get_extent"); |         freenas_api_log_error($client, "get_extent"); | ||||||
|       return undef; |         return undef; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -518,8 +514,8 @@ sub freenas_get_first_available_lunid { | ||||||
| 
 | 
 | ||||||
|     # find the first hole, if not, give the +1 of the last lun |     # find the first hole, if not, give the +1 of the last lun | ||||||
|     foreach my $lun (@sorted_luns) { |     foreach my $lun (@sorted_luns) { | ||||||
|   	    last if $lun != $lun_id; |         last if $lun != $lun_id; | ||||||
|   	    $lun_id = $lun_id + 1; |         $lun_id = $lun_id + 1; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     syslog("info", "FreeNAS::API::freenas_get_first_available_lunid : return $lun_id"); |     syslog("info", "FreeNAS::API::freenas_get_first_available_lunid : return $lun_id"); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue