sos 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64b648104b60bf1378fdc920e03d4a0a8e09a300
4
+ data.tar.gz: 288228ed48ff2d5360413ebe84b405471844d6a4
5
+ SHA512:
6
+ metadata.gz: 3af67b2e6ade113668399680dbf08723ffd5f78c4cafd9035b4abca9744139051c2f9f5d68d2fee8b400fef40946c66a282556149cf012142d3c045b02bc40c5
7
+ data.tar.gz: 8eda5473276ec4f183f1c439a227d9f39c1dee0acb44e5a941a08c035b600b42d9cccf619521ceb2e2366ce2fe64869759ae684cad89b83759bd39502815307b
data/bin/sos ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'sos'
3
+
4
+ command = Syntax.new(ARGV)
5
+ command.run
data/lib/sos.rb ADDED
@@ -0,0 +1,101 @@
1
+ =begin header
2
+ * Name: os
3
+ * Description: OpenStack services and logs tool for Red Hat OSes familly
4
+ * URL: https://github.com/gildub/os
5
+ * Date: 29 Nov 2013
6
+ * Author: Gilles Dubreuil <gilles@redhat.com>
7
+ * License: Copyright 2011, 2013 Gilles Dubreuil
8
+ =end
9
+
10
+ =begin rdoc
11
+ =end
12
+
13
+ require 'os/service'
14
+ require 'os/openstack'
15
+
16
+ SYNTAX =
17
+ %s{Usage:
18
+ os [-fr] clean [<SERVICE>] ... [<SERVICE>]
19
+ os [-fr] list
20
+ os [-fr] logs [<SERVICE>] ... [<SERVICE>]
21
+ os [-fr] restart [<SERVICE>] ... [<SERVICE>]
22
+ os [-fr] start [<SERVICE>] ... [<SERVICE>]
23
+ os [-fr] satus [<SERVICE>] ... [<SERVICE>]
24
+ os [-fr] stop [<SERVICE>] ... [<SERVICE>]
25
+ os help
26
+
27
+ Options:
28
+ -r, --runlevel <RUNLEVEL> Change run-level, default is 3
29
+ -h, --help This help
30
+
31
+ Commands:
32
+ clean
33
+ list List available OpenStack services
34
+ logs Runs "tail -f"
35
+ restart Runs "service restart"
36
+ start Runs "service start"
37
+ status Runs "service status"
38
+ stop Runs "service stop"
39
+
40
+ <SERVICE> Openstack service
41
+ }
42
+
43
+ class Syntax
44
+ def initialize(line)
45
+ @command = ""
46
+ @options = {
47
+ :runlevel => 3,
48
+ :filter => '/neutron|openstack/',
49
+ :all => false }
50
+ @arguments = []
51
+
52
+ until line.empty?
53
+ case line[0]
54
+ when '-a', '--all'
55
+ @options[:all] = true
56
+ when '-f', '--filter'
57
+ line.shift
58
+ @options[:filter] = line[0]
59
+ when '-r', '--run_level'
60
+ line.shift
61
+ @options[:runlevel] = line[0].to_i
62
+ when /status/i, /start/i, /stop/i, /restart/i, /logs/i, /list/i, 'test'
63
+ @command << line[0]
64
+ line.shift
65
+ @arguments = line
66
+ break
67
+ else
68
+ self.usage
69
+ end
70
+ line.shift
71
+ end
72
+ end
73
+
74
+ def run
75
+ @services = Services.new(@options[:filter], @options[:runlevel], OpenStack::LOGS)
76
+
77
+ case @command
78
+ when /status/i, /start/i, /stop/i, /restart/i
79
+ @services.enabled.each do |service|
80
+ system("service #{service.name} #{@command}")
81
+ end
82
+ when /logs/i
83
+ logs = ''
84
+ @services.enabled.each do |service|
85
+ logs << service.logs.join(' ') + ' '
86
+ end
87
+ exec("tail -f #{logs}") if logs
88
+ when /list/i
89
+ @services.enabled.each do |service|
90
+ puts service.name
91
+ end
92
+ when 'test'
93
+ p self
94
+ end
95
+ end
96
+
97
+ def usage
98
+ puts SYNTAX
99
+ exit
100
+ end
101
+ end
@@ -0,0 +1,28 @@
1
+ module OpenStack
2
+ VarLog = '/var/log/'
3
+
4
+ LOGS = {
5
+ 'neutron-server' => ["#{VarLog}/neutron/server.log"],
6
+ 'neutron-dhcp-agent' => ["#{VarLog}/neutron/dhcp-agent.log"],
7
+ 'neutron-l3-agent' => ["#{VarLog}/neutron/l3-agent.log"],
8
+ 'openstack-ceilometer-api' => ["#{VarLog}/ceilometer/api.log"],
9
+ 'openstack-ceilometer-central' => ["#{VarLog}/ceilometer/central.log"],
10
+ 'openstack-ceilometer-collector' => ["#{VarLog}/ceilometer/collector.log"],
11
+ 'openstack-cinder-api' => ["#{VarLog}/cinder/api.log"],
12
+ 'openstack-cinder-scheduler' => ["#{VarLog}/cinder/api.log"],
13
+ 'openstack-cinder-volume' => ["#{VarLog}/cinder/api.log"],
14
+ 'openstack-glance-api' => ["#{VarLog}/glance/api.log"],
15
+ 'openstack-glance-registry' => ["#{VarLog}/glance/registry.log"],
16
+ 'openstack-heat-api' => ["#{VarLog}/heat/heat-api.log"],
17
+ 'openstack-heat-engine' => ["#{VarLog}/heat/heat-engine.log"],
18
+ 'openstack-heat-manage' => ["#{VarLog}/heat/heat-manage.log"],
19
+ 'openstack-keystone' => ["#{VarLog}/keystone/keystone.log"],
20
+ 'openstack-nova-api' => ["#{VarLog}/nova/api.log"],
21
+ 'openstack-nova-cert' => ["#{VarLog}/nova/cert.log"],
22
+ 'openstack-nova-conductor' => ["#{VarLog}/nova/conductor.log"],
23
+ 'openstack-nova-console' => ["#{VarLog}/nova/console.log"],
24
+ 'openstack-nova-consoleauth' => ["#{VarLog}/nova/consoleauth.log"],
25
+ 'openstack-nova-novncproxy' => [""],
26
+ 'openstack-nova-scheduler' => ["#{VarLog}/nova/scheduler.log"],
27
+ }
28
+ end
@@ -0,0 +1,61 @@
1
+ class Service
2
+ attr_reader :name, :state, :logs
3
+
4
+ def initialize(name, state, logs)
5
+ @name = name
6
+ if state =~ /on/i
7
+ @state = true
8
+ else
9
+ @state = false
10
+ end
11
+ @logs = logs
12
+ end
13
+
14
+ def has?(filter)
15
+ true if @name =~ /#{filter}/
16
+ end
17
+
18
+ def to_s
19
+ @name + ':' + @state
20
+ end
21
+ end
22
+
23
+ class Services
24
+ def initialize(filter, run_level, logs)
25
+ @services = []
26
+
27
+ list = %x{chkconfig --list | awk '#{filter} {print $1":"$#{run_level+2}}'}
28
+ list.each { |line|
29
+ line_tab = line.chop.split(':')
30
+ name = line_tab[0]
31
+ state = line_tab[2]
32
+ @services << Service.new(name, state, logs[name])
33
+ }
34
+ end
35
+
36
+ def get_by_name(filters)
37
+ list = []
38
+ filters.each { |filter|
39
+ @services.each { |service|
40
+ list << service.name if @service.has?(filter)
41
+ }
42
+ }
43
+ list
44
+ end
45
+
46
+ def get_by_name_all
47
+ list = []
48
+ @services.each { |service|
49
+ list << service.name
50
+ }
51
+ list
52
+ end
53
+
54
+ def enabled
55
+ list = []
56
+ @services.each { |service|
57
+ list << service if service.state
58
+ }
59
+ list
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Gilles Dubreuil
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Easy manipulation of OpenStack services and view corresponding log files
14
+ for a specific host. Allows grouping part or all services at once.
15
+ email:
16
+ - gilles@redhat.com
17
+ executables:
18
+ - sos
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/sos.rb
23
+ - lib/sos/services.rb
24
+ - lib/sos/openstack.rb
25
+ - bin/sos
26
+ homepage: https://github.com/gildub/sos
27
+ licenses:
28
+ - GNU GPLv3
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.0.14
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Service for OpenStack is a services and logs tool for Red Hat OS
50
+ test_files: []