From 62ef8d4d8d228d5bc022a325eab33f2bfd0dc2a6 Mon Sep 17 00:00:00 2001
From: Apollon Oikonomopoulos <apollon@noc.grnet.gr>
Date: Mon, 21 Jun 2010 12:57:39 +0300
Subject: [PATCH] Add tagging option to gnt-instance create

Add TAG_ADD_OPT option to cli.py and use it in gnt-instance. Modify
cli.GenericInstanceCreate() accordingly.

Signed-off-by: Apollon Oikonomopoulos <apollon@noc.grnet.gr>
---
 lib/cli.py                 | 11 +++++++++++
 lib/client/gnt_instance.py |  1 +
 2 files changed, 12 insertions(+)

diff --git a/lib/cli.py b/lib/cli.py
index 9d304055b..f288cb1ce 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -159,6 +159,7 @@ __all__ = [
   "SUBMIT_OPT",
   "STATIC_OPT",
   "SYNC_OPT",
+  "TAG_ADD_OPT",
   "TAG_SRC_OPT",
   "TIMEOUT_OPT",
   "UIDPOOL_OPT",
@@ -657,6 +658,10 @@ IGNORE_OFFLINE_OPT = cli_option("--ignore-offline", dest="ignore_offline",
                                   help=("Ignore offline nodes and do as much"
                                         " as possible"))
 
+TAG_ADD_OPT = cli_option("--tags", dest="tags",
+                         default=None, help="Comma-separated list of instance"
+                                            " tags")
+
 TAG_SRC_OPT = cli_option("--from", dest="tags_source",
                          default=None, help="File with tag names")
 
@@ -2117,6 +2122,11 @@ def GenericInstanceCreate(mode, opts, args):
                                    " disk %d" % didx)
       disks[didx] = ddict
 
+  if opts.tags is not None:
+    tags = opts.tags.split(',')
+  else:
+    tags = []
+
   utils.ForceDictType(opts.beparams, constants.BES_PARAMETER_TYPES)
   utils.ForceDictType(hvparams, constants.HVS_PARAMETER_TYPES)
 
@@ -2160,6 +2170,7 @@ def GenericInstanceCreate(mode, opts, args):
                                 force_variant=force_variant,
                                 src_node=src_node,
                                 src_path=src_path,
+                                tags=tags,
                                 no_install=no_install,
                                 identify_defaults=identify_defaults)
 
diff --git a/lib/client/gnt_instance.py b/lib/client/gnt_instance.py
index f132ee4de..1e529acd7 100644
--- a/lib/client/gnt_instance.py
+++ b/lib/client/gnt_instance.py
@@ -1387,6 +1387,7 @@ add_opts = [
   OS_OPT,
   FORCE_VARIANT_OPT,
   NO_INSTALL_OPT,
+  TAG_ADD_OPT,
   ]
 
 commands = {
-- 
GitLab