Skip to content

Commit bcab03a

Browse files
authored
Merge pull request #2 from allmightyspiff/caberos-Issue1815-2
2 parents fb6f704 + eb6a784 commit bcab03a

File tree

4 files changed

+64
-51
lines changed

4 files changed

+64
-51
lines changed

SoftLayer/CLI/find.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@
386386
('vlan:cancel', 'SoftLayer.CLI.vlan.cancel:cli'),
387387

388388
('summary', 'SoftLayer.CLI.summary:cli'),
389-
('find', 'SoftLayer.CLI.find:cli'),
389+
('search', 'SoftLayer.CLI.search:cli'),
390390

391391
('report', 'SoftLayer.CLI.report'),
392392
('report:bandwidth', 'SoftLayer.CLI.report.bandwidth:cli'),

SoftLayer/CLI/search.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""Search for SoftLayer Resources by simple phrase."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
5+
import click
6+
7+
import SoftLayer
8+
from SoftLayer.CLI import environment
9+
from SoftLayer.CLI import formatting
10+
from SoftLayer.managers.search import SearchManager
11+
12+
object_types = {'ticket': 'SoftLayer_Ticket',
13+
'firewall': 'SoftLayer_Network_Vlan_Firewall',
14+
'vlan': 'SoftLayer_Network_Vlan',
15+
'subnet': 'SoftLayer_Network_Subnet_IpAddress',
16+
'delivery': 'SoftLayer_Network_Application_Delivery_Controller',
17+
'dedicated': 'SoftLayer_Virtual_DedicatedHost',
18+
'log': 'SoftLayer_Event_Log',
19+
'hardware': 'SoftLayer_Hardware',
20+
'virtual': 'SoftLayer_Virtual_Guest'}
21+
22+
23+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
24+
@click.argument('query', nargs=-1)
25+
@click.option('--types', is_flag=True, default=False, is_eager=True, help="Display searchable types.")
26+
@click.option('--advanced', is_flag=True, help="Calls the AdvancedSearh API.")
27+
@environment.pass_env
28+
def cli(env, query, types, advanced):
29+
"""Perform a query against the SoftLayer search database.
30+
31+
Read More: https://sldn.softlayer.com/reference/services/SoftLayer_Search/search/
32+
Examples:
33+
slcli search test.com
34+
slcli search _objectType:SoftLayer_Virtual_Guest test.com
35+
slcli -vvv search _objectType:SoftLayer_Hardware hostname:testibm --advanced
36+
"""
37+
search = SearchManager(env.client)
38+
# query is in array, so we need to convert it to a normal string for the API
39+
query = " ".join(query)
40+
if types:
41+
search_types = search.get_object_types()
42+
43+
table = formatting.Table(["Name", "Properties"])
44+
table.align = "r"
45+
46+
for type_object in search_types:
47+
prop_table = formatting.Table(["Property", "Sortable"])
48+
prop_table.align = "l"
49+
for prop in type_object.get('properties'):
50+
prop_table.add_row([prop.get('name'), prop.get('sortableFlag')])
51+
table.add_row([type_object.get('name'), prop_table])
52+
53+
env.fout(table)
54+
return
55+
if advanced:
56+
result = search.advanced(query)
57+
58+
env.fout(formatting.iter_to_table(result))
59+
else:
60+
result = search.search(query)
61+
env.fout(formatting.iter_to_table(result))

SoftLayer/managers/search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
22
SoftLayer.search
33
~~~~~~~~~~~~~~~~~~
4-
Searching Manager
4+
Search Manager
55
66
:license: MIT, see LICENSE for more details.
77
"""
88

99

10-
class SearchingManager(object):
10+
class SearchManager(object):
1111
"""Manager to help searcha via the SoftLayer API.
1212
1313
:param SoftLayer.API.BaseClient client: the client instance

0 commit comments

Comments
 (0)