forked from cloudfoundry/vcap-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pool_tool
executable file
·89 lines (76 loc) · 2.05 KB
/
pool_tool
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env ruby
$:.unshift(File.join(File.dirname(__FILE__), '../lib/vcap/user_pools'))
ENV["BUNDLE_GEMFILE"] ||= File.join(File.dirname(__FILE__), '../Gemfile')
require 'bundler'
Bundler.setup
require 'optparse'
require 'user_pool_util'
module PoolTool
USAGE = 'usage: pool_tool [OPTIONS], try -h for more options'
class << self
def require_root
if Process.uid != 0
puts "This operation requires root privileges."
exit 1
end
end
def install_pool(name, size)
require_root
if not VCAP::UserPoolUtil.pool_exists?(name)
VCAP::UserPoolUtil.install_pool(name, size.to_i)
else
puts "Pool with name #{name} already exists, can't install."
exit 1
end
end
def remove_pool(name)
require_root
if VCAP::UserPoolUtil.pool_exists?(name)
VCAP::UserPoolUtil.remove_pool(name)
else
puts "No pool with name #{name}, can't do remove."
exit 1
end
end
def list_pools
list = VCAP::UserPoolUtil.pool_list
if list.size > 0
puts list
else
puts "No user pools found."
end
end
def parse_options
options = OptionParser.new do |opts|
opts.banner = USAGE
opts.on("-c", "--create NAME,SIZE", "Create pool NAME with SIZE users.") do |opt|
name, size = opt.split(',')
if size == nil
puts "Invalid input to create, see ./pool_tool -h."
exit 1
end
install_pool(name, size)
end
opts.on("-d", "--delete NAME", "Delete pool NAME.") do |opt|
remove_pool(opt)
end
opts.on("-l", "--list", "List current pools.") do
list_pools
end
opts.on("-h", "--help", "Help") do
puts opts
exit
end
end
options.parse!(ARGV)
end
end
logger = Logger.new(STDOUT)
logger.level = Logger::INFO
VCAP::UserPoolUtil.init(logger)
if ARGV.length == 0
puts USAGE
exit
end
parse_options
end