Blob Blame History Raw
From 3947c435cb32f8f8347b8f51f8dde967ac0d47c6 Mon Sep 17 00:00:00 2001
From: Andy Grover <agrover@redhat.com>
Date: Wed, 17 Dec 2014 16:13:27 -0800
Subject: [PATCH 2/2] Add a global pref for adding default portal

Expand info messages to mention this pref as well

Fixes #46

Signed-off-by: Andy Grover <agrover@redhat.com>
---
 scripts/targetcli      |  1 +
 targetcli/ui_node.py   |  3 +++
 targetcli/ui_target.py | 13 +++++++++----
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/scripts/targetcli b/scripts/targetcli
index b95e842..5404fcd 100755
--- a/scripts/targetcli
+++ b/scripts/targetcli
@@ -49,6 +49,7 @@ class TargetCLI(ConfigShell):
                      'auto_add_mapped_luns': True,
                      'auto_cd_after_create': False,
                      'auto_save_on_exit': True,
+                     'auto_add_default_portal': True,
                     }
 
 def usage():
diff --git a/targetcli/ui_node.py b/targetcli/ui_node.py
index 53c095f..5abfd7f 100644
--- a/targetcli/ui_node.py
+++ b/targetcli/ui_node.py
@@ -43,6 +43,9 @@ class UINode(ConfigNode):
         self.define_config_group_param(
             'global', 'auto_save_on_exit', 'bool',
             'If true, saves configuration on exit.')
+        self.define_config_group_param(
+            'global', 'auto_add_default_portal', 'bool',
+            'If true, adds a portal listening on all IPs to new targets.')
 
     def assert_root(self):
         '''
diff --git a/targetcli/ui_target.py b/targetcli/ui_target.py
index a28925c..7fcaab0 100644
--- a/targetcli/ui_target.py
+++ b/targetcli/ui_target.py
@@ -335,10 +335,15 @@ class UIMultiTPGTarget(UIRTSLibNode):
 
         self.shell.log.info("Created TPG %s." % tpg.tag)
 
-        if tpg.has_feature("nps"):
-            NetworkPortal(tpg, "0.0.0.0")
-            self.shell.log.info("Created default portal listening on all IPs"
-                                " (0.0.0.0), port 3260.")
+        if tpg.has_feature("nps") and self.shell.prefs['auto_add_default_portal']:
+            try:
+                NetworkPortal(tpg, "0.0.0.0")
+                self.shell.log.info("Global pref auto_add_default_portal=true")
+                self.shell.log.info("Created default portal listening on all IPs"
+                                    " (0.0.0.0), port 3260.")
+            except RTSLibError:
+                self.shell.log.info("Default portal not created, TPGs within a " +
+                                    "target cannot share ip:port.")
 
         ui_tpg = UITPG(tpg, self)
         return self.new_node(ui_tpg)
-- 
1.9.3