From 94d897f7d1d15071513de1fe1819e0faa22f01b1 Mon Sep 17 00:00:00 2001 From: Kevin Scott Adams Date: Sun, 19 Aug 2018 15:28:39 -0400 Subject: [PATCH] Added API Host - This change allows the API traffic to be on a different interface then the iSCSI Provider interface. This allows the selection of the FreeNAS WebGUI address for HTTP/HTTPS to be on a specific interface instead of "ALL" (0.0.0.0) interfaces. If the API Host is not defined then the API traffic will default to the iSCSI Provider interface. --- perl5/PVE/Storage/LunCmd/FreeNAS.pm | 8 ++-- perl5/PVE/Storage/ZFSPlugin.pm.patch | 13 ++++-- pve-docs/api-viewer/apidoc.js.patch | 26 ++++++++--- pve-manager/js/pvemanagerlib.js.patch | 66 +++++++++++++++++---------- 4 files changed, 77 insertions(+), 36 deletions(-) diff --git a/perl5/PVE/Storage/LunCmd/FreeNAS.pm b/perl5/PVE/Storage/LunCmd/FreeNAS.pm index befefde..e68bf9c 100644 --- a/perl5/PVE/Storage/LunCmd/FreeNAS.pm +++ b/perl5/PVE/Storage/LunCmd/FreeNAS.pm @@ -230,10 +230,11 @@ sub freenas_api_call { my ($scfg, $method, $path, $data) = @_; my $client = undef; my $scheme = $scfg->{freenas_use_ssl} ? "https" : "http"; + my $apihost = defined($scfg->{freenas_apiv4_host}) ? $scfg->{freenas_apiv4_host} : $scfg->{portal}; my $apiping = '/api/v1.0/system/version/'; $client = REST::Client->new(); - $client->setHost($scheme . '://' . $scfg->{portal}); + $client->setHost($scheme . '://' . $apihost); $client->addHeader('Content-Type' , 'application/json'); $client->addHeader('Authorization' , 'Basic ' . encode_base64($scfg->{freenas_user} . ':' . $scfg->{freenas_password})); # If using SSL, don't verify SSL certs @@ -241,12 +242,13 @@ sub freenas_api_call { $client->getUseragent()->ssl_opts(verify_hostname => 0); $client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE); } - # Check if the API is working via the selected scheme + # Check if the APIs are accessable via the selected host and scheme my $code = $client->request('GET', $apiping)->responseCode(); if ($code != 200) { freenas_api_log_error($client, "freenas_api_call"); - die "Unable to connect to the FreeNAS API service at '" . $scfg->{portal} . "' using '" . $scheme . "' protocol"; + die "Unable to connect to the FreeNAS API service at '" . $apihost . "' using the '" . $scheme . "' protocol"; } + syslog("info","FreeNAS::api_call : setup : sucessfull"); if ($method eq 'GET') { $client->GET($path); } diff --git a/perl5/PVE/Storage/ZFSPlugin.pm.patch b/perl5/PVE/Storage/ZFSPlugin.pm.patch index d8e218e..32fd05d 100644 --- a/perl5/PVE/Storage/ZFSPlugin.pm.patch +++ b/perl5/PVE/Storage/ZFSPlugin.pm.patch @@ -1,5 +1,5 @@ ---- /usr/share/perl5/PVE/Storage/ZFSPlugin.pm.orig 2018-06-04 11:59:59.851426278 +0800 -+++ /usr/share/perl5/PVE/Storage/ZFSPlugin.pm 2018-06-04 12:04:56.781049166 +0800 +--- ZFSPlugin.pm.orig 2018-05-16 04:06:14.000000000 -0400 ++++ ZFSPlugin.pm 2018-08-19 09:34:25.169349056 -0400 @@ -10,6 +10,7 @@ use base qw(PVE::Storage::ZFSPoolPlugin); @@ -35,7 +35,7 @@ } elsif ($scfg->{iscsiprovider} eq 'istgt') { $msg = PVE::Storage::LunCmd::Istgt::run_lun_command($scfg, $timeout, $method, @params); } elsif ($scfg->{iscsiprovider} eq 'iet') { -@@ -173,6 +178,18 @@ +@@ -173,6 +178,22 @@ description => "iscsi provider", type => 'string', }, @@ -50,17 +50,22 @@ + freenas_use_ssl => { + description => "FreeNAS API access via SSL", + type => 'boolean', ++ }, ++ freenas_apiv4_host => { ++ description => "FreeNAS API Host", ++ type => 'string', + }, # this will disable write caching on comstar and istgt. # it is not implemented for iet. iet blockio always operates with # writethrough caching when not in readonly mode -@@ -204,6 +221,9 @@ +@@ -204,6 +225,10 @@ sparse => { optional => 1 }, comstar_hg => { optional => 1 }, comstar_tg => { optional => 1 }, + freenas_user => { optional => 1 }, + freenas_password => { optional => 1 }, + freenas_use_ssl => { optional => 1 }, ++ freenas_apiv4_host => { optional => 1 }, content => { optional => 1 }, bwlimit => { optional => 1 }, }; diff --git a/pve-docs/api-viewer/apidoc.js.patch b/pve-docs/api-viewer/apidoc.js.patch index 22b7c6c..af861f2 100644 --- a/pve-docs/api-viewer/apidoc.js.patch +++ b/pve-docs/api-viewer/apidoc.js.patch @@ -1,6 +1,6 @@ ---- apidoc.js 2018-07-10 06:05:33.000000000 -0400 -+++ apidoc.js.new 2018-07-30 22:21:11.479045222 -0400 -@@ -27584,6 +27584,24 @@ +--- apidoc.js.orig 2018-08-19 10:18:11.715767285 -0400 ++++ apidoc.js.new 2018-08-19 10:17:09.364282178 -0400 +@@ -27584,6 +27584,31 @@ "type" : "string", "typetext" : "" }, @@ -21,14 +21,22 @@ + "optional" : 1, + "type" : "boolean", + "typetext" : "" ++ }, ++ "freenas_apiv4_host" : { ++ "description" : "FreeNAS API Host via IPv4", ++ "format" : "address", ++ "optional" : 1, ++ "type" : "string", ++ "typetext" : "" + }, "content" : { "description" : "Allowed content types.\n\nNOTE: the value 'rootdir' is used for Containers, and value 'images' for VMs.\n", "format" : "pve-storage-content-list", -@@ -27949,6 +27967,24 @@ +@@ -27948,6 +27973,31 @@ + "optional" : 1, "type" : "string", "typetext" : "" - }, ++ }, + "freenas_user" : { + "description" : "FreeNAS user for API access", + "optional" : 1, @@ -47,6 +55,12 @@ + "type" : "boolean", + "typetext" : "" + }, ++ "freenas_apiv4_host" : { ++ "description" : "FreeNAS API Host via IPv4", ++ "format" : "address", ++ "optional" : 1, ++ "type" : "string", ++ "typetext" : "" + }, "content" : { "description" : "Allowed content types.\n\nNOTE: the value 'rootdir' is used for Containers, and value 'images' for VMs.\n", - "format" : "pve-storage-content-list", diff --git a/pve-manager/js/pvemanagerlib.js.patch b/pve-manager/js/pvemanagerlib.js.patch index 73e076d..5bd8066 100644 --- a/pve-manager/js/pvemanagerlib.js.patch +++ b/pve-manager/js/pvemanagerlib.js.patch @@ -1,5 +1,5 @@ ---- pvemanagerlib.js 2018-07-10 08:46:32.000000000 -0400 -+++ pvemanagerlib.js.new 2018-07-30 22:19:23.207915760 -0400 +--- pvemanagerlib.js.orig 2018-07-30 23:13:28.045035059 -0400 ++++ pvemanagerlib.js.new 2018-08-19 10:42:58.494724196 -0400 @@ -5379,6 +5379,7 @@ alias: ['widget.pveiScsiProviderSelector'], comboItems: [ @@ -8,10 +8,19 @@ [ 'istgt', 'istgt'], [ 'iet', 'IET'] ] -@@ -27361,6 +27362,30 @@ +@@ -27361,7 +27362,23 @@ value: '', fieldLabel: gettext('Target group'), allowBlank: true +- } ++ }, ++ { ++ xtype: 'proxmoxcheckbox', ++ name: 'freenas_use_ssl', ++ checked: false, ++ uncheckedValue: 0, ++ hidden: me.iscsiprovider !== "freenas", ++ fieldLabel: gettext('FreeNAS API use SSL') + }, + { + xtype: me.isCreate ? 'textfield' : 'displayfield', @@ -21,25 +30,10 @@ + fieldLabel: gettext('FreeNAS User'), + allowBlank: true + }, -+ { -+ xtype: me.isCreate ? 'textfield' : 'displayfield', -+ name: 'freenas_password', -+ value: '', -+ hidden: me.iscsiprovider !== "freenas", -+ fieldLabel: gettext('FreeNAS Password'), -+ allowBlank: true -+ }, -+ { -+ xtype: 'proxmoxcheckbox', -+ name: 'freenas_use_ssl', -+ checked: false, -+ uncheckedValue: 0, -+ hidden: me.iscsiprovider !== "freenas", -+ fieldLabel: gettext('FreeNAS API use SSL') - } ]; -@@ -27370,7 +27395,23 @@ + me.column2 = [ +@@ -27370,7 +27387,26 @@ name: 'iscsiprovider', value: 'comstar', fieldLabel: gettext('iSCSI Provider'), @@ -48,19 +42,45 @@ + listeners: { + change: function(f, value) { + if (value === "freenas") { ++ me.down('field[name=freenas_use_ssl]').setHidden(false); ++ me.down('field[name=freenas_apiv4_host]').setHidden(false); + me.down('field[name=freenas_user]').setHidden(false); + me.down('field[name=freenas_password]').setHidden(false); -+ me.down('field[name=freenas_use_ssl]').setHidden(false); + } else { ++ me.down('field[name=freenas_use_ssl]').setHidden(true); ++ me.down('field[name=freenas_use_ssl]').setValue(false); ++ me.down('field[name=freenas_apiv4_host]').setHidden(true); ++ me.down('field[name=freenas_apiv4_host]').setValue(false); + me.down('field[name=freenas_user]').setHidden(true); + me.down('field[name=freenas_user]').setValue(''); + me.down('field[name=freenas_password]').setHidden(true); + me.down('field[name=freenas_password]').setValue(''); -+ me.down('field[name=freenas_use_ssl]').setHidden(true); -+ me.down('field[name=freenas_use_ssl]').setValue(false); + } + } + } }, { xtype: 'proxmoxcheckbox', +@@ -27392,6 +27428,22 @@ + value: '', + fieldLabel: gettext('Host group'), + allowBlank: true ++ }, ++ { ++ xtype: me.isCreate ? 'textfield' : 'displayfield', ++ name: 'freenas_apiv4_host', ++ value: '', ++ hidden: me.iscsiprovider !== "freenas", ++ fieldLabel: gettext('API IPv4 Host'), ++ allowBlank: true ++ }, ++ { ++ xtype: me.isCreate ? 'textfield' : 'displayfield', ++ name: 'freenas_password', ++ value: '', ++ hidden: me.iscsiprovider !== "freenas", ++ fieldLabel: gettext('FreeNAS Password'), ++ allowBlank: true + } + ]; +