forked from tinova/one-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oneconf
executable file
·71 lines (51 loc) · 1.57 KB
/
oneconf
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env ruby
# This script prepares oned.conf and sched.conf
require "fileutils"
# Taken from: http://jimeh.me/blog/2010/02/22/built-in-sudo-for-ruby-command-line-tools/
def sudome
if ENV["USER"] != "root"
exec("sudo #{ENV['_']} #{ARGV.join(' ')}")
end
end
class String
def uncomment(string)
self.gsub!(string) do |m|
m.split("\n").map{|e| e.gsub(/^([\t\s]*)#+/,'\1')}.join("\n")
end
end
end
if ONE_LOCATION = ENV['ONE_LOCATION']
oned_conf = ONE_LOCATION + '/etc/oned.conf'
sched_conf = ONE_LOCATION + '/etc/sched.conf'
else
sudome()
oned_conf = '/etc/one/oned.conf'
sched_conf = '/etc/one/sched.conf'
end
now = Time.now.strftime('%Y%m%d%H%M%S').to_s
FileUtils.cp(oned_conf, oned_conf + '.' + now)
FileUtils.cp(sched_conf, sched_conf + '.' + now)
# oned.conf
conf = File.read(oned_conf)
single_vals = {
:manager_timer => 5,
:host_monitoring_interval => 10,
:vm_polling_interval => 10
}
single_vals.each do |k,v|
k = k.to_s.upcase
v = v.to_s
if conf.match(/^#{k}/)
conf.gsub!(/^#{k}.*$/,"#{k} = #{v}")
else
conf << "\n#{k} = #{v}"
end
end
conf.uncomment('#IM_MAD = [ name="dummy", executable="one_im_dummy"]')
conf.uncomment('#VM_MAD = [ name="dummy", executable="one_vmm_dummy", type="xml" ]')
conf.gsub!('fs,vmware,vmfs,iscsi,lvm,ceph', 'dummy,fs,vmware,vmfs,iscsi,lvm,ceph')
File.open(oned_conf,'w'){|f| f.write(conf)}
# sched.conf
conf = File.read(sched_conf)
conf.gsub!('SCHED_INTERVAL = 30','SCHED_INTERVAL = 5')
File.open(sched_conf,'w'){|f| f.write(conf)}