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:
Kevin Scott Adams 2018-07-31 21:33:21 -04:00
parent 32d243b872
commit 42edb8614e
1 changed files with 20 additions and 24 deletions

View File

@ -26,10 +26,8 @@ sub get_base {
sub run_lun_command {
my ($scfg, $timeout, $method, @params) = @_;
# TODO : Move configuration of the storage
if(!defined($scfg->{'freenas_user'})) {
$scfg->{'freenas_user'} = 'root';
$scfg->{'freenas_password'} = '*** password ***';
if(!defined($scfg->{'freenas_user'}) || !defined($scfg->{'freenas_password'})) {
die "Undefined freenas_user and/or freenas_password.";
}
syslog("info","FreeNAS::lun_command : $method(@params)");
@ -128,7 +126,7 @@ sub run_list_extent {
last;
}
}
if(!defined($result)) {
if (!defined($result)) {
syslog("info","FreeNAS::list_extent($object): naa not found");
}
@ -231,19 +229,17 @@ sub run_delete_lu {
sub freenas_api_call {
my ($scfg, $method, $path, $data) = @_;
my $client = undef;
my $scheme = 'http';
my $scheme = $scfg->{freenas_use_ssl} ? "https" : "http";
$client = REST::Client->new();
if ($scfg->{freenas_use_ssl}) {
$scheme = 'https';
}
$client->setHost($scheme . '://'. $scfg->{portal});
$client->setHost($scheme . '://' . $scfg->{portal});
$client->addHeader('Content-Type' , 'application/json');
$client->addHeader('Authorization' , 'Basic ' . encode_base64( $scfg->{freenas_user} . ':' . $scfg->{freenas_password}));
# don't verify SSL certs
$client->addHeader('Authorization' , 'Basic ' . encode_base64($scfg->{freenas_user} . ':' . $scfg->{freenas_password}));
# If using SSL, don't verify SSL certs
if ($scfg->{freenas_use_ssl}) {
$client->getUseragent()->ssl_opts(verify_hostname => 0);
$client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE );
$client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE);
}
if ($method eq 'GET') {
$client->GET($path);
}