File: hpilo_es_dump

package info (click to toggle)
python-hpilo 4.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 984 kB
  • sloc: python: 2,528; ruby: 467; makefile: 116
file content (42 lines) | stat: -rwxr-xr-x 1,217 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python
#
# (c) 2011-2016 Dennis Kaarsemaker <dennis@kaarsemaker.net>
# see COPYING for license details

try:
    import ConfigParser
except ImportError:
    import configparser as ConfigParser
import optparse
import elasticsearch
from pprint import pprint
import os

def main():
    usage = """%prog [options]"""
    p = optparse.OptionParser(usage=usage)
    p.add_option("-c", "--config", dest="config", default="~/.ilo.conf",
                 help="File containing authentication and config details", metavar="FILE")

    opts, args = p.parse_args()

    if args:
        p.print_help()
        p.exit(1)

    es = None
    if os.path.exists(os.path.expanduser(opts.config)):
        config = ConfigParser.ConfigParser()
        config.read(os.path.expanduser(opts.config))
        if config.has_option('elasticsearch', 'host'):
            es = elasticsearch.Elasticsearch(config.get('elasticsearch', 'host'))
    if not es:
        es = elasticsearch.Elasticsearch()

    request = {'query': {'match_all': {}}, 'size': 20000}
    ilos = es.search(index='hpilo', doc_type='hpilo', body=request)
    for ilo in ilos['hits']['hits']:
        pprint(ilo['_source'])

if __name__ == '__main__':
    main()