sos 0.2.6 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sos.rb +18 -12
  3. data/lib/sos/services.rb +34 -19
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98fecbea1e93ebdba1bc7b10cffcaa1cf3ed39a7
4
- data.tar.gz: 30df4a9e22f27f3ba7968f91bce07f98eeaf0057
3
+ metadata.gz: 349b29c2085bb1ccd9feac783a9ecfec2d97f536
4
+ data.tar.gz: 0bfe909da1aced6c8aaaabe44dd0c6b25174c06f
5
5
  SHA512:
6
- metadata.gz: 88ec0f2f820c4ffb0316bee320a63b14e25e6042aa458b047fd8a248d882ffbda0fe8b7d6229c3301eed0577158d1aafe804765a0bec9884536e73b7044c7546
7
- data.tar.gz: ec3cae53b52b4a74b49ad8936f4c6c5638326c9b88622cc90ead8713248294ad7d5205935db4297777bc7f2638a4bb536d7f4017bb0739411657a4d6b561bbeb
6
+ metadata.gz: 5fc7f026f206af038dbd723bf9bf1bd877beed488374f552d2e4228f6fafe82aedc4507f4e512e7653284011cc66305d008bb8c00a52062cfe5663df30ad369a
7
+ data.tar.gz: 5503c0556fa1a0dc22a3a2e489212211c30161295a6b3f91d8a9770f26ff26e9d59a6cf002fc811fca8d5d67e9726346fae5e8786196b6eea11fd4a36cf90ab7
data/lib/sos.rb CHANGED
@@ -21,18 +21,22 @@ SYNTAX =
21
21
  sos help
22
22
 
23
23
  Options:
24
- -r, --runlevel <RUNLEVEL> Change run-level. Default is level 3.
25
- -h, --help This help
24
+ -r, --runlevel <RUNLEVEL>
25
+ Change run-level. Default is level 3.
26
+ -s, --selector <NAME>, ... ,<NAME>
27
+ Assign selector. Default is "openstack,neutron".
28
+ -h, --help
29
+ This help
26
30
 
27
31
  Commands:
28
32
  list List available OpenStack services
29
33
  logs Runs "tail -f"
30
- restart Runs "service restart"
31
- start Runs "service start"
32
- status Runs "service status"
33
- stop Runs "service stop"
34
+ restart Runs "service restart" on enabled services
35
+ start Runs "service start" on enabled services
36
+ status Runs "service status" on enabled services
37
+ stop Runs "service stop" on enabled services
34
38
 
35
- <SERVICE> Openstack service
39
+ <SERVICE> Service name
36
40
  }
37
41
 
38
42
  class Syntax
@@ -40,7 +44,7 @@ class Syntax
40
44
  @command = nil
41
45
  @options = {
42
46
  :runlevel => 3,
43
- :selector => '/neutron|openstack/',
47
+ :selector => 'openstack,neutron',
44
48
  :all => false }
45
49
  @arguments = []
46
50
 
@@ -50,7 +54,7 @@ class Syntax
50
54
  @options[:all] = true
51
55
  when '-s', '--selector'
52
56
  line.shift
53
- @options[:selector] = line[0]
57
+ @options[:selector] = line[0].gsub(/\s*/,'')
54
58
  when '-r', '--run_level'
55
59
  line.shift
56
60
  @options[:runlevel] = line[0].to_i
@@ -68,7 +72,9 @@ class Syntax
68
72
  end
69
73
 
70
74
  def run
71
- services = Services.new(@options[:selector], @options[:runlevel], @arguments, OpenStack::LOGS)
75
+
76
+ services_list = Services.build_list(@options[:selector], @options[:runlevel], @arguments)
77
+ services = Services.new(services_list, OpenStack::LOGS)
72
78
 
73
79
  case @command
74
80
  when /status/i, /start/i, /stop/i, /restart/i
@@ -82,8 +88,8 @@ class Syntax
82
88
  }
83
89
  exec("tail -f #{logs}") if logs
84
90
  when /list/i
85
- services.enabled.each { |service|
86
- puts service.name
91
+ services.by_name.each { |service|
92
+ puts service
87
93
  }
88
94
  when 'test'
89
95
  p self
@@ -2,9 +2,9 @@ class Service
2
2
  attr_reader :name, :state, :logs
3
3
 
4
4
  def initialize(name, state, logs)
5
- @name = name
6
- @state = state =~ /on/i ? true : false
7
- @logs = logs
5
+ @name = name
6
+ @state = state =~ /on|enabled/i ? true : false
7
+ @logs = logs
8
8
  end
9
9
 
10
10
  def has?(filter)
@@ -12,40 +12,55 @@ class Service
12
12
  end
13
13
 
14
14
  def to_s
15
- @name + ':' + @state
15
+ state = @state ? 'enabled' : 'disabled'
16
+ @name + ':' + state
16
17
  end
17
18
  end
18
19
 
19
20
  class Services
20
- def initialize(selector, run_level, filters, loglist)
21
- @services = []
21
+ def self.build_list(selectors, run_level, filters)
22
+ # Returns each service on a line with
23
+ # name:state
24
+
25
+ selector = selectors.split(',').join('|')
22
26
 
23
- list = %x{chkconfig --list | awk '#{selector} {print $1":"$#{run_level+2}}'}
27
+ list=''
28
+ redhat = %x{cat /etc/redhat-release}
29
+ case redhat
30
+ when /Red Hat Enterprise Linux/
31
+ if redhat =~ /release 6/
32
+ list = %x{ chkconfig --list | awk '/#{selector}/ {print $1":"$#{run_level+2}}'}
33
+ list.gsub!(/:\d:/,':')
34
+ end
35
+ when /Fedora/
36
+ list = %x{ systemctl list-unit-files | awk '/#{selector}/ {print}'}
37
+ list.gsub!(/\.service[\s]*/,':')
38
+ end
24
39
 
25
40
  if filters != []
26
41
  filtered = ''
27
- list.each { |line|
42
+ list.each_line { |line|
28
43
  filters.each { |filter| filtered << line if line =~ /#{filter}/ }
29
44
  }
30
45
  list = filtered
31
46
  end
47
+ list
48
+ end
32
49
 
33
- list.each { |line|
34
- line_tab = line.chop.split(':')
35
- name = line_tab[0]
36
- state = line_tab[2]
37
- log = loglist[name] ? loglist[name] : ''
50
+ def initialize(service_list, services_logs)
51
+ @services = []
52
+ service_list.each_line { |line|
53
+ name, state = line.chop.split(':')
54
+ log = services_logs[name] ? services_logs[name] : ''
38
55
  @services << Service.new(name, state, log)
39
56
  }
57
+ @services
40
58
  end
41
59
 
42
- def get_by_name(filters)
43
- return @services
60
+ def by_name
44
61
  list = []
45
- filters.each { |filter|
46
- @services.each { |service|
47
- list << service if @service.has?(filter)
48
- }
62
+ @services.each { |service|
63
+ list << service
49
64
  }
50
65
  list
51
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilles Dubreuil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-04 00:00:00.000000000 Z
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Easy manipulation of OpenStack services and view corresponding log files
14
14
  for a specific host. Allows grouping part or all services at once.