Skip to content

Commit 7b70bad

Browse files
author
caberos
committed
update with Christopher method and fix the team code review comments
1 parent 0d4789f commit 7b70bad

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

SoftLayer/CLI/call_api.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,12 @@ def _validate_parameters(ctx, param, value): # pylint: disable=unused-argument
112112
@click.option('--mask', help="String-based object mask")
113113
@click.option('--limit', type=click.INT, help="Result limit")
114114
@click.option('--offset', type=click.INT, help="Result offset")
115-
@click.option('--orderBy', type=click.STRING, help="an object filter that adds an order by clause"
116-
"E.G --orderBy subnets.id default DESC"
117-
" --orderBy subnets.id=ASC")
115+
@click.option('--orderBy', type=click.STRING,
116+
help="To set the sort direction, ASC or DESC can be provided."
117+
"This should be of the form: '--orderBy nested.property' default DESC or "
118+
"'--orderBy nested.property=ASC', e.g. "
119+
" --orderBy subnets.id default DESC"
120+
" --orderBy subnets.id=ASC")
118121
@click.option('--output-python / --no-output-python',
119122
help="Show python example code instead of executing the call")
120123
@click.option('--json-filter', callback=_validate_filter,
@@ -144,17 +147,19 @@ def cli(env, service, method, parameters, _id, _filters, mask, limit, offset, or
144147
--json-filter '{"virtualGuests":{"hostname":{"operation":"^= test"}}}' --limit=10
145148
slcli -v call-api SoftLayer_User_Customer addBulkPortalPermission --id=1234567 \\
146149
'[{"keyName": "NETWORK_MESSAGE_DELIVERY_MANAGE"}]'
150+
slcli call-api Account getVirtualGuests \\
151+
--orderBy virttualguests.id=ASC
147152
"""
148153

149154
if _filters and json_filter:
150155
raise exceptions.CLIAbort("--filter and --json-filter cannot be used together.")
151156

152157
object_filter = _build_filters(_filters)
153158
if orderby:
154-
_filters = utils.build_filter_orderby(orderby)
155-
object_filter.update(_filters)
159+
orderby = utils.build_filter_orderby(orderby)
160+
object_filter = utils.dict_merge(object_filter, orderby)
156161
if json_filter:
157-
object_filter.update(json_filter)
162+
object_filter = utils.dict_merge(json_filter, object_filter)
158163

159164
args = [service, method] + list(parameters)
160165
kwargs = {

SoftLayer/utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,19 @@ def event_log_filter_less_than_date(date, utc):
221221
def build_filter_orderby(orderby):
222222
"""Builds filters using the filter options passed into the CLI.
223223
224-
Only support fot create filter option orderBy, default value is DESC.
224+
It only supports the orderBy option, the default value is DESC.
225225
"""
226226
_filters = {}
227-
aux = list(reversed(str(orderby).split('.')))
228-
for split in aux:
227+
reverse_filter = list(reversed(orderby.split('.')))
228+
for keyword in reverse_filter:
229229
_aux_filter = {}
230-
if str(split).__contains__('='):
231-
_aux_filter[str(split).split('=')[0]] = query_filter_orderby(str(split).split('=')[1])
230+
if '=' in keyword:
231+
_aux_filter[str(keyword).split('=')[0]] = query_filter_orderby(str(keyword).split('=')[1])
232232
_filters = _aux_filter
233-
elif split == list(aux)[0]:
234-
_aux_filter[split] = query_filter_orderby('DESC')
233+
elif keyword == list(reverse_filter)[0]:
234+
_aux_filter[keyword] = query_filter_orderby('DESC')
235235
else:
236-
_aux_filter[split] = _filters
236+
_aux_filter[keyword] = _filters
237237
_filters = _aux_filter
238238
return _filters
239239

tests/CLI/modules/call_api_tests.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ def test_json_filter(self):
301301

302302
def test_call_api_orderBy(self):
303303
result = self.run_command(['call-api', 'Account', 'getVirtualGuests',
304-
'--orderBy', 'virtualGuests.id=DESC'])
304+
'--orderBy', 'virtualGuests.id=DESC',
305+
'--mask=virtualGuests.typeId,maxCpu',
306+
'-f', 'virtualGuests.typeId=1'])
305307
self.assert_no_fail(result)
306308
self.assert_called_with('SoftLayer_Account',
307309
'getVirtualGuests',
@@ -311,4 +313,6 @@ def test_call_api_orderBy(self):
311313
'operation': 'orderBy',
312314
'options': [{
313315
'name': 'sort',
314-
'value': ['DESC']}]}}})
316+
'value': ['DESC']}]},
317+
'typeId': {'operation': 1}}
318+
})

0 commit comments

Comments
 (0)