|
| 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 SearchingManager |
| 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') |
| 25 | +@click.option('--types', |
| 26 | + is_flag=True, default=False, |
| 27 | + help="Show only planned events") |
| 28 | +@click.option('--advanced', is_flag=True, help="Show only planned events") |
| 29 | +@environment.pass_env |
| 30 | +def cli(env, query, types, advanced): |
| 31 | + searching = SearchingManager(env.client) |
| 32 | + name = object_types.get(query) |
| 33 | + if types: |
| 34 | + object_type = searching.get_object_types() |
| 35 | + |
| 36 | + table = formatting.Table(["Name", "Type", 'Resource']) |
| 37 | + |
| 38 | + for type_object in object_type: |
| 39 | + for property in type_object['properties']: |
| 40 | + if name == type_object['name']: |
| 41 | + table.add_row([property['name'], property['type'], type_object['name']]) |
| 42 | + |
| 43 | + env.fout(table) |
| 44 | + if advanced: |
| 45 | + search_string = '_objectType:' + name |
| 46 | + result = searching.advanced(search_string) |
| 47 | + |
| 48 | + env.fout(formatting.iter_to_table(result)) |
0 commit comments