Skip to content

Commit 931e72d

Browse files
Merge pull request #2109 from allmightyspiff/issues2108
fixed vs list with tag search, allowing multiple tags as well
2 parents 5808786 + 9c8fae6 commit 931e72d

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

SoftLayer/CLI/virt/list.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,11 @@
1919
column_helper.Column('backend_ip', ('primaryBackendIpAddress',)),
2020
column_helper.Column('datacenter', ('datacenter', 'name')),
2121
column_helper.Column('action', lambda guest: formatting.active_txn(guest),
22-
mask='''
23-
activeTransaction[
24-
id,transactionStatus[name,friendlyName]
25-
]'''),
22+
mask='activeTransaction[id,transactionStatus[name,friendlyName]]'),
2623
column_helper.Column('power_state', ('powerState', 'name')),
27-
column_helper.Column(
28-
'created_by',
29-
('billingItem', 'orderItem', 'order', 'userRecord', 'username')),
30-
column_helper.Column(
31-
'tags',
32-
lambda server: formatting.tags(server.get('tagReferences')),
33-
mask="tagReferences.tag.name"),
24+
column_helper.Column('created_by', ('billingItem', 'orderItem', 'order', 'userRecord', 'username')),
25+
column_helper.Column('tags', lambda server: formatting.tags(server.get('tagReferences')),
26+
mask="tagReferences.tag.name"),
3427
column_helper.Column(
3528
'createDate',
3629
lambda guest: utils.clean_time(guest.get('createDate'),
@@ -59,7 +52,7 @@
5952
@click.option('--network', '-n', help='Network port speed in Mbps')
6053
@click.option('--hourly', is_flag=True, help='Show only hourly instances')
6154
@click.option('--monthly', is_flag=True, help='Show only monthly instances')
62-
@click.option('--tag', '-t', help='list of tags')
55+
@click.option('--tag', '-t', help='list of tags', multiple=True)
6356
@click.option('--transient', help='Filter by transient instances', type=click.BOOL)
6457
@click.option('--search', is_flag=False, flag_value="", default=None,
6558
help="Use the more flexible Search API to list instances. See `slcli search --types` for list " +

SoftLayer/managers/search.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def search_instances(self, search_string, mask=None, **kwargs):
4747
if kwargs.get('datacenter'):
4848
search_string = f"{search_string} datacenter.longName: *{kwargs.get('datacenter')}*"
4949
if kwargs.get('tags'):
50-
tags = " ".join(kwargs.get("tags", []))
51-
search_string = f"{search_string} internalTagReferences.tag.name: {tags}"
50+
tags = " ".join(f"tagReferences.tag.name: \"{t}\"" for t in kwargs.get("tags", []))
51+
search_string = f"{search_string} {tags}"
5252
result = self.search_manager.advancedSearch(search_string, mask=mask)
5353
guests = []
5454
for resource in result:

SoftLayer/managers/vs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def list_instances(self, hourly=True, monthly=True, tags=None, cpus=None,
134134
if tags:
135135
_filter['virtualGuests']['tagReferences']['tag']['name'] = {
136136
'operation': 'in',
137-
'options': [{'name': 'data', 'value': tags}],
137+
'options': [{'name': 'data', 'value': list(tags)}],
138138
}
139139

140140
if cpus:

tests/managers/search_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ def test_search_instances_basic(self):
4343
args=(f"{expected} datacenter.longName: *dal13*",))
4444
self.search.search_instances(search_string, tags=["thisTag"])
4545
self.assert_called_with('SoftLayer_Search', 'advancedSearch',
46-
args=(f"{expected} internalTagReferences.tag.name: thisTag",))
46+
args=(f"{expected} tagReferences.tag.name: \"thisTag\"",))

0 commit comments

Comments
 (0)