noc 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/noc +80 -16
- data/lib/noc/version.rb +1 -1
- metadata +1 -1
data/bin/noc
CHANGED
@@ -12,8 +12,9 @@ end
|
|
12
12
|
|
13
13
|
CHEF=".chef"
|
14
14
|
KNIFE="knife.rb"
|
15
|
-
CHEF_KNIFE=File.join(CHEF, KNIFE
|
15
|
+
CHEF_KNIFE=File.join(CHEF, KNIFE)
|
16
16
|
VAGRANTFILE="Vagrantfile"
|
17
|
+
DATABAGS="data_bags"
|
17
18
|
|
18
19
|
|
19
20
|
include GLI::App
|
@@ -44,7 +45,47 @@ command :init do |c|
|
|
44
45
|
case
|
45
46
|
when args[0] == "solo"
|
46
47
|
puts "Init solo"
|
47
|
-
|
48
|
+
|
49
|
+
when args[0] == "users"
|
50
|
+
users_dir = File.join(DATABAGS,"users")
|
51
|
+
Dir.mkdir(users_dir) unless File.exists?(users_dir)
|
52
|
+
|
53
|
+
$cluster[:users].each do |user|
|
54
|
+
json = File.join( users_dir, user, ".json")
|
55
|
+
if File.exists?(json) then
|
56
|
+
raise "File exists #{json}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# gen key
|
60
|
+
key = File.join( users_dir, user, ".key" )
|
61
|
+
if File.exists?(key) then
|
62
|
+
raise "File exists #{key}"
|
63
|
+
end
|
64
|
+
|
65
|
+
system( "ssh-keygen -b 2048 -f #{key}" )
|
66
|
+
pub = IO.read("#{key}.pub")
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
when args[0] == "bags"
|
71
|
+
%w[clusters users secrets].each do |b|
|
72
|
+
system("knife data bag create #{b}")
|
73
|
+
end
|
74
|
+
when args[0] == "vagrant"
|
75
|
+
# create vagrantfile
|
76
|
+
if File.exists?(VAGRANTFILE) then
|
77
|
+
raise "File exists #{VAGRANTFILE}"
|
78
|
+
end
|
79
|
+
template = File.join(File.dirname(__FILE__), '..', 'templates', VAGRANTFILE + ".erb" )
|
80
|
+
if not File.exists?(template) then
|
81
|
+
raise "Template not found: #{template}"
|
82
|
+
end
|
83
|
+
File.open( VAGRANTFILE, 'w' ) do |f|
|
84
|
+
f.write( Erubis::Eruby.new(File.new(template).read).result({:clusterfile => global_options[:clusterfile],
|
85
|
+
:cluster => $cluster}))
|
86
|
+
end
|
87
|
+
|
88
|
+
when args[0].nil?
|
48
89
|
if File.exists?(CHEF_KNIFE) then
|
49
90
|
raise "File exists #{CHEF_KNIFE}"
|
50
91
|
end
|
@@ -65,22 +106,24 @@ command :init do |c|
|
|
65
106
|
puts "#{CHEF_KNIFE}"
|
66
107
|
end
|
67
108
|
|
68
|
-
# create vagrantfile
|
69
|
-
if File.exists?(VAGRANTFILE) then
|
70
|
-
raise "File exists #{VAGRANTFILE}"
|
71
|
-
end
|
72
|
-
template = File.join(File.dirname(__FILE__), '..', 'templates', VAGRANTFILE + ".erb" )
|
73
|
-
if not File.exists?(template) then
|
74
|
-
raise "Template not found: #{template}"
|
75
|
-
end
|
76
|
-
File.open( VAGRANTFILE, 'w' ) do |f|
|
77
|
-
f.write( Erubis::Eruby.new(File.new(template).read).result({:clusterfile => global_options[:clusterfile],
|
78
|
-
:cluster => $cluster}))
|
79
|
-
end
|
80
109
|
puts "init command ran"
|
81
110
|
end
|
82
111
|
end
|
83
112
|
|
113
|
+
desc 'Download stuff'
|
114
|
+
arg_name 'COMMAND [options]'
|
115
|
+
command :download do |c|
|
116
|
+
c.action do |global_options,options,args|
|
117
|
+
case
|
118
|
+
when args[0] == 'books'
|
119
|
+
$cluster[:cookbooks].each do |b|
|
120
|
+
system("knife cookbook site install #{b}")
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
|
84
127
|
desc 'Upload cookbook, role, databag'
|
85
128
|
arg_name 'COMMAND [options]'
|
86
129
|
command :upload do |c|
|
@@ -123,14 +166,35 @@ command :upload do |c|
|
|
123
166
|
File.open( data_bag, 'w' ) do |f|
|
124
167
|
f.write( $cluster.to_json )
|
125
168
|
end
|
126
|
-
system("knife data bag create clusters")
|
127
169
|
system("knife data bag from file clusters #{$cluster[:id]}.json")
|
128
|
-
end
|
129
170
|
|
171
|
+
|
172
|
+
when args[0] == "users"
|
173
|
+
Dir.glob("data_bags/users/*.json").each do |f|
|
174
|
+
system("knife data bag from file users #{File.basename(f)}")
|
175
|
+
end
|
176
|
+
when args[0] == "user"
|
177
|
+
system("knife data bag from file users #{args[1]}.json")
|
178
|
+
|
179
|
+
end # upload
|
130
180
|
puts "upload command ran"
|
131
181
|
end
|
132
182
|
end
|
133
183
|
|
184
|
+
|
185
|
+
desc 'Delete client from chef server'
|
186
|
+
arg_name 'COMMAND [options]'
|
187
|
+
command :delete do |c|
|
188
|
+
c.action do |global_options,options,args|
|
189
|
+
case
|
190
|
+
when args[0] == 'client'
|
191
|
+
system("knife client delete #{args[1]}")
|
192
|
+
system("knife node delete #{args[1]}")
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
|
134
198
|
pre do |global,command,options,args|
|
135
199
|
# Pre logic here
|
136
200
|
# Return true to proceed; false to abourt and not call the
|
data/lib/noc/version.rb
CHANGED