Repository: softlayer/softlayer-python
Pull request #2109 (2023-10-09 16:10:06)

fixed vs list with tag search, allowing multiple tags as well
Fixed #2108 


Patch:
diff --git a/SoftLayer/CLI/virt/list.py b/SoftLayer/CLI/virt/list.py
index 4becb400..b16d5602 100644
--- a/SoftLayer/CLI/virt/list.py
+++ b/SoftLayer/CLI/virt/list.py
@@ -19,18 +19,11 @@
     column_helper.Column('backend_ip', ('primaryBackendIpAddress',)),
     column_helper.Column('datacenter', ('datacenter', 'name')),
     column_helper.Column('action', lambda guest: formatting.active_txn(guest),
-                         mask='''
-                         activeTransaction[
-                            id,transactionStatus[name,friendlyName]
-                         ]'''),
+                         mask='activeTransaction[id,transactionStatus[name,friendlyName]]'),
     column_helper.Column('power_state', ('powerState', 'name')),
-    column_helper.Column(
-        'created_by',
-        ('billingItem', 'orderItem', 'order', 'userRecord', 'username')),
-    column_helper.Column(
-        'tags',
-        lambda server: formatting.tags(server.get('tagReferences')),
-        mask="tagReferences.tag.name"),
+    column_helper.Column('created_by', ('billingItem', 'orderItem', 'order', 'userRecord', 'username')),
+    column_helper.Column('tags', lambda server: formatting.tags(server.get('tagReferences')),
+                         mask="tagReferences.tag.name"),
     column_helper.Column(
         'createDate',
         lambda guest: utils.clean_time(guest.get('createDate'),
@@ -59,7 +52,7 @@
 @click.option('--network', '-n', help='Network port speed in Mbps')
 @click.option('--hourly', is_flag=True, help='Show only hourly instances')
 @click.option('--monthly', is_flag=True, help='Show only monthly instances')
-@click.option('--tag', '-t', help='list of tags')
+@click.option('--tag', '-t', help='list of tags', multiple=True)
 @click.option('--transient', help='Filter by transient instances', type=click.BOOL)
 @click.option('--search', is_flag=False, flag_value="", default=None,
               help="Use the more flexible Search API to list instances. See `slcli search --types` for list " +
diff --git a/SoftLayer/managers/search.py b/SoftLayer/managers/search.py
index 69e96eaf..fad826db 100644
--- a/SoftLayer/managers/search.py
+++ b/SoftLayer/managers/search.py
@@ -47,8 +47,8 @@ def search_instances(self, search_string, mask=None, **kwargs):
         if kwargs.get('datacenter'):
             search_string = f"{search_string} datacenter.longName: *{kwargs.get('datacenter')}*"
         if kwargs.get('tags'):
-            tags = " ".join(kwargs.get("tags", []))
-            search_string = f"{search_string} internalTagReferences.tag.name: {tags}"
+            tags = " ".join(f"tagReferences.tag.name: \"{t}\"" for t in kwargs.get("tags", []))
+            search_string = f"{search_string} {tags}"
         result = self.search_manager.advancedSearch(search_string, mask=mask)
         guests = []
         for resource in result:
diff --git a/SoftLayer/managers/vs.py b/SoftLayer/managers/vs.py
index 9da87e40..df2e99f1 100644
--- a/SoftLayer/managers/vs.py
+++ b/SoftLayer/managers/vs.py
@@ -134,7 +134,7 @@ def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
         if tags:
             _filter['virtualGuests']['tagReferences']['tag']['name'] = {
                 'operation': 'in',
-                'options': [{'name': 'data', 'value': tags}],
+                'options': [{'name': 'data', 'value': list(tags)}],
             }
 
         if cpus:


Test patch:
diff --git a/tests/managers/search_tests.py b/tests/managers/search_tests.py
index 54dfe67b..2c6eb89a 100644
--- a/tests/managers/search_tests.py
+++ b/tests/managers/search_tests.py
@@ -43,4 +43,4 @@ def test_search_instances_basic(self):
                                 args=(f"{expected} datacenter.longName: *dal13*",))
         self.search.search_instances(search_string, tags=["thisTag"])
         self.assert_called_with('SoftLayer_Search', 'advancedSearch',
-                                args=(f"{expected} internalTagReferences.tag.name: thisTag",))
+                                args=(f"{expected} tagReferences.tag.name: \"thisTag\"",))