Projet

Général

Profil

Révision d8c30923

IDd8c309232526dfe3f5381819161248b82cd3e721
Parent 37d81d7a
Enfant 4387edfa

Ajouté par Lars Kruse il y a environ 5 ans

Plugin nova_services: migrate to Python3, format documentation

Voir les différences:

plugins/nova/nova_services
1
#!/usr/bin/env python
2
#
3
# Plugin to report service status
4
#
5
# Needs following minimal configuration in plugin-conf.d/nova:
6
#   [nova_*]
7
#   user nova
8
#
9
# Magic markers
10
#%# capabilities=autoconf
11
#%# family=auto
1
#!/usr/bin/env python3
2
"""
3
=head1 NAME
4

  
5
nova_services - report nova service status
6

  
7

  
8
=head1 CONFIGURATION
9

  
10
Needs following minimal configuration in plugin-conf.d/nova:
11

  
12
 [nova_*]
13
 user nova
14

  
15

  
16
=head1 AUTHORS
17

  
18
Copyright 2012 Mehdi Abaakouk <sileht@sileht.net>
19

  
20

  
21
=head1 MAGIC MARKERS
22

  
23
 #%# capabilities=autoconf
24
 #%# family=auto
25

  
26
=cut
27
"""
12 28

  
13 29
import sys
14 30

  
15 31
try:
16
    from nova import context
17
    from nova import db
18
    from nova import flags
19
    from nova import utils
32
    from nova import context, db, flags, utils
20 33
except ImportError:
21 34
    successful_import = False
22 35
else:
23 36
    successful_import = True
24 37

  
25
services = ['nova-compute', 'nova-volume', 'nova-scheduler', 'nova-vncproxy', 'nova-network', 'nova-cert', 'nova-console', 'nova-consoleauth']
38

  
39
services = [
40
    'nova-compute',
41
    'nova-volume',
42
    'nova-scheduler',
43
    'nova-vncproxy',
44
    'nova-network',
45
    'nova-cert',
46
    'nova-console',
47
    'nova-consoleauth',
48
]
26 49

  
27 50

  
28 51
def print_config():
29
    global services
30
    print 'graph_title Nova Services'
31
    print 'graph_vlabel qty'
32
    print 'graph_args --base 1000 --lower-limit 0'
33
    print 'graph_category cloud'
34
    print 'graph_scale no'
35
    print 'graph_info Nova services - alive and active'
52
    print('graph_title Nova Services')
53
    print('graph_vlabel qty')
54
    print('graph_args --base 1000 --lower-limit 0')
55
    print('graph_category cloud')
56
    print('graph_scale no')
57
    print('graph_info Nova services - alive and active')
36 58
    for service in services:
37
        print '%s_alive.label %s alive' % (service, service)
38
        print '%s_alive.draw LINE2' % service
39
        print '%s_alive.info seen in last 30 seconds' % service
40
        print '%s_active.label %s active' % (service, service)
41
        print '%s_active.draw LINE2' % service
42
        print '%s_active.info alive and enabled' % service
59
        print('%s_alive.label %s alive' % (service, service))
60
        print('%s_alive.draw LINE2' % service)
61
        print('%s_alive.info seen in last 30 seconds' % service)
62
        print('%s_active.label %s active' % (service, service))
63
        print('%s_active.draw LINE2' % service)
64
        print('%s_active.info alive and enabled' % service)
43 65

  
44 66

  
45 67
def get_status():
......
49 71
    for k in services:
50 72
        alive[k] = 0
51 73
        active[k] = 0
52

  
53 74
    ctxt = context.get_admin_context()
54 75
    now = utils.utcnow()
55 76
    services = db.service_get_all(ctxt)
......
59 80
            alive[svc['binary']] += 1
60 81
            if not svc['disabled']:
61 82
                active[svc['binary']] += 1
62

  
63 83
    return {'alive': alive, 'active': active}
64 84

  
65 85

  
66 86
def print_values():
67 87
    status = get_status()
68
    for (state, value) in status['alive'].iteritems():
69
        print "%s_alive.value %s" % (state, value)
70
    for (state, value) in status['active'].iteritems():
71
        print "%s_active.value %s" % (state, value)
88
    for (state, value) in status['alive'].items():
89
        print("%s_alive.value %s" % (state, value))
90
    for (state, value) in status['active'].items():
91
        print("%s_active.value %s" % (state, value))
72 92

  
73 93

  
74 94
if __name__ == '__main__':
......
77 97
            print_config()
78 98
        elif sys.argv[1] == "autoconf":
79 99
            if not successful_import:
80
                print 'no (failed import nova module]'
100
                print('no (failed import nova module]')
81 101
            else:
82
                print 'yes'
102
                print('yes')
83 103
    elif successful_import:
84 104
        utils.default_flagfile()
85 105
        flags.FLAGS(sys.argv)
t/test-exception-wrapper.expected-failures
272 272
plugins/nginx/nginx_working_set
273 273
plugins/nova/nova_instance_launched
274 274
plugins/nova/nova_instance_timing
275
plugins/nova/nova_services
276 275
plugins/ntp/ntpdate_
277 276
plugins/ntp/ntp_kernel_pll_prec
278 277
plugins/ntp/ntp_pool_score_

Formats disponibles : Unified diff