]> Frank Brehm's Git Trees - pixelpark/create-vmware-tpl.git/commitdiff
Defining command line parameters
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 13 Apr 2018 12:34:22 +0000 (14:34 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 13 Apr 2018 12:34:22 +0000 (14:34 +0200)
lib/cr_vmware_tpl/app.py
lib/cr_vmware_tpl/handler.py

index 6bc5f28386c483344a481f96df99bf5e3b896556..157d1f3202d2be5cf083cd181cddc5f9a4762b55 100644 (file)
@@ -34,7 +34,7 @@ from .config import CrTplConfiguration
 
 from .handler import ExpectedHandlerError, CrTplHandler
 
-__version__ = '0.3.4'
+__version__ = '0.4.1'
 LOG = logging.getLogger(__name__)
 
 
@@ -406,6 +406,8 @@ class CrTplApplication(PpBaseObject):
             self.config.password = getpass.getpass(prompt=prompt)
 
         self.handler.config = self.config
+        if self.args.rotate:
+            self.handler.rotate_only = True
         self.handler.initialized = True
         self.initialized = True
 
@@ -612,7 +614,7 @@ class CrTplApplication(PpBaseObject):
         vmware_group.add_argument(
             '-F', '--folder', dest='folder',
             help="Folder in vSphere, where to create the template (Default: {!r}).".format(
-                CrTplConfiguration.default_template_vm)
+                CrTplConfiguration.default_folder)
         )
 
         vmware_group.add_argument(
@@ -629,6 +631,21 @@ class CrTplApplication(PpBaseObject):
                 "(Default: {!r}).").format(CrTplConfiguration.default_template_name)
         )
 
+        vmware_group.add_argument(
+            '-N', '--number', '--number-templates', dest='number',
+            type=int, metavar='INT',
+            help=(
+                "Maximum number of templates to stay in templates folder ("
+                "1 <= x < 100, Default: {}).".format(
+                    CrTplConfiguration.default_max_nr_templates_stay))
+        )
+
+        vmware_group.add_argument(
+            '-R', '--rotate', '--rotate-only', dest="rotate", action='store_true',
+            help="Execute rortation of existing templates only, don't create a new one."
+        )
+
+
     # -------------------------------------------------------------------------
     def _perform_arg_parser(self):
         """
@@ -678,6 +695,19 @@ class CrTplApplication(PpBaseObject):
         if self.args.template:
             self.config.template_name = self.args.template
 
+        if self.args.number is not None:
+            v = self.args.number
+            if v < 1:
+                LOG.error((
+                    "Wrong number {} of templates to stay in templates folder, "
+                    "must be greater than zero.").format(v))
+            elif v >= 100:
+                LOG.error((
+                    "Wrong number {} of templates to stay in templates folder, "
+                    "must be less than 100.").format(v))
+            else:
+                self.config.max_nr_templates_stay = v
+
     # -------------------------------------------------------------------------
     def _init_env(self):
         """
index 4777a700d64db535ffb1751587b667a120aa6363..9fff9ef84d251b1f8876a26174397f0a779e3480 100644 (file)
@@ -171,7 +171,7 @@ class CrTplHandler(PpBaseObject):
         self.ssh_user = 'root'
         self.ssh_timeout = 30
         self.max_wait_for_shutdown = 600
-        self.rotate_only = True
+        self.rotate_only = False
 
         if initialized:
             self.initialized = True
@@ -211,7 +211,9 @@ class CrTplHandler(PpBaseObject):
             self.ensure_vm_folder()
             self.check_for_temp_tpl_vm()
             self.select_data_store()
-            if not self.rotate_only:
+            if self.rotate_only:
+                LOG.warn("Only executing of template rotating.")
+            else:
                 self.check_network()
                 self.create_vm()
                 self.tpl_vm = self.get_temp_tpl_vm()