Repository: softlayer/softlayer-python
Pull request #1278 (2020-06-05 15:58:54)

delete tags
https://github.com/softlayer/softlayer-python/issues/1272


Patch:
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index a71b6243..2ee59704 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -294,6 +294,7 @@
     ('tags:list', 'SoftLayer.CLI.tags.list:cli'),
     ('tags:set', 'SoftLayer.CLI.tags.set:cli'),
     ('tags:details', 'SoftLayer.CLI.tags.details:cli'),
+    ('tags:delete', 'SoftLayer.CLI.tags.delete:cli'),
 
     ('ticket', 'SoftLayer.CLI.ticket'),
     ('ticket:create', 'SoftLayer.CLI.ticket.create:cli'),
diff --git a/SoftLayer/CLI/tags/delete.py b/SoftLayer/CLI/tags/delete.py
new file mode 100644
index 00000000..5c6ccbc0
--- /dev/null
+++ b/SoftLayer/CLI/tags/delete.py
@@ -0,0 +1,30 @@
+"""List Tags."""
+# :license: MIT, see LICENSE for more details.
+
+import click
+
+from SoftLayer.exceptions import SoftLayerAPIError
+from SoftLayer.managers.tags import TagManager
+from SoftLayer.CLI import environment
+from SoftLayer.CLI import formatting
+from SoftLayer import utils
+
+# pylint: disable=unnecessary-lambda
+
+from pprint import pprint as pp
+
+
+@click.command()
+@click.option('-id', required=False, show_default=False, type=int, help='identifier')
+@click.option('--name', required=False, default=False, type=str, show_default=False, help='tag name')
+@environment.pass_env
+def cli(env, id, name):
+    """delete Tag."""
+
+    tag_manager = TagManager(env.client)
+
+    if not name and id is not None:
+        tag_name = tag_manager.get_tag(id)
+        tag_manager.delete_tag(tag_name['name'])
+    if name and id is None:
+        tag_manager.delete_tag(name)
diff --git a/SoftLayer/fixtures/SoftLayer_Tag.py b/SoftLayer/fixtures/SoftLayer_Tag.py
index 6839f739..ec4d1163 100644
--- a/SoftLayer/fixtures/SoftLayer_Tag.py
+++ b/SoftLayer/fixtures/SoftLayer_Tag.py
@@ -15,6 +15,8 @@
     }
 ]
 
+deleteTag = True
+
 setTags = True
 
 getObject = getAttachedTagsForCurrentUser[0]
diff --git a/SoftLayer/managers/tags.py b/SoftLayer/managers/tags.py
index e5b43a60..8752f525 100644
--- a/SoftLayer/managers/tags.py
+++ b/SoftLayer/managers/tags.py
@@ -116,6 +116,9 @@ def reference_lookup(self, resource_table_id, tag_type):
         # return {}
         return self.client.call(service, 'getObject', id=resource_table_id)
 
+    def delete_tag(self, name):
+        return self.client.call('SoftLayer_Tag', 'deleteTag', name)
+
     def set_tags(self, tags, key_name, resource_id):
         """Calls SoftLayer_Tag::setTags()
 


Test patch:
diff --git a/tests/CLI/modules/tag_tests.py b/tests/CLI/modules/tag_tests.py
index f7eac843..ac6930d0 100644
--- a/tests/CLI/modules/tag_tests.py
+++ b/tests/CLI/modules/tag_tests.py
@@ -7,6 +7,7 @@
 import mock
 
 from SoftLayer import testing
+from SoftLayer.managers.tags import TagManager
 
 
 class TagCLITests(testing.TestCase):
@@ -56,3 +57,11 @@ def test_details_by_id(self):
         result = self.run_command(['tags', 'details', tag_id])
         self.assert_no_fail(result)
         self.assert_called_with('SoftLayer_Tag', 'getObject', identifier=tag_id)
+
+    def test_deleteTags_by_name(self):
+        result = self.run_command(['tags', 'delete', '--name="test"'])
+        self.assert_no_fail(result)
+
+    def test_deleteTags_by_id(self):
+        result = self.run_command(['tags', 'delete', '-id=123456'])
+        self.assert_no_fail(result)