noc 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/noc +5 -2
- data/lib/noc/version.rb +1 -1
- data/templates/Vagrantfile.erb +109 -0
- data/templates/knife.rb.erb +12 -0
- metadata +3 -1
data/bin/noc
CHANGED
@@ -46,6 +46,9 @@ command :init do |c|
|
|
46
46
|
when args[0] == "solo"
|
47
47
|
puts "Init solo"
|
48
48
|
|
49
|
+
when args[0] == "repo"
|
50
|
+
system("git clone git://github.com/opscode/chef-repo.git #{args[1]}") unless args[1].nil?
|
51
|
+
|
49
52
|
when args[0] == "users"
|
50
53
|
users_dir = File.join(DATABAGS,"users")
|
51
54
|
Dir.mkdir(users_dir) unless File.exists?(users_dir)
|
@@ -71,6 +74,7 @@ command :init do |c|
|
|
71
74
|
%w[clusters users secrets].each do |b|
|
72
75
|
system("knife data bag create #{b}")
|
73
76
|
end
|
77
|
+
|
74
78
|
when args[0] == "vagrant"
|
75
79
|
# create vagrantfile
|
76
80
|
if File.exists?(VAGRANTFILE) then
|
@@ -168,7 +172,6 @@ command :upload do |c|
|
|
168
172
|
end
|
169
173
|
system("knife data bag from file clusters #{$cluster[:id]}.json")
|
170
174
|
|
171
|
-
|
172
175
|
when args[0] == "users"
|
173
176
|
Dir.glob("data_bags/users/*.json").each do |f|
|
174
177
|
system("knife data bag from file users #{File.basename(f)}")
|
@@ -209,7 +212,7 @@ pre do |global,command,options,args|
|
|
209
212
|
STDERR.puts e.message
|
210
213
|
# STDERR.puts "ERROR: No infrastructure .yml file provided."
|
211
214
|
exit(-1)
|
212
|
-
end
|
215
|
+
end unless command.names == "init" and args[0] == "repo"
|
213
216
|
|
214
217
|
true
|
215
218
|
end
|
data/lib/noc/version.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
#
|
4
|
+
|
5
|
+
# header
|
6
|
+
clusterfile = "<%= clusterfile %>"
|
7
|
+
begin
|
8
|
+
$cluster = YAML.load_file clusterfile
|
9
|
+
rescue Exception => e
|
10
|
+
STDERR.puts e.message
|
11
|
+
STDERR.puts "ERROR: Clusterfile not found: #{clusterfile}"
|
12
|
+
exit(-1)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# vagrant
|
17
|
+
Vagrant::Config.run do |config|
|
18
|
+
|
19
|
+
vm_defaults = proc do |cfg|
|
20
|
+
$cluster[:defaults][:vm].each do |k,v|
|
21
|
+
eval("cfg.vm.#{k} = \"#{v}\"")
|
22
|
+
end
|
23
|
+
|
24
|
+
$cluster[:defaults][:modifyvm].each do |k,v|
|
25
|
+
cfg.vm.customize ["modifyvm", :id, "--#{k}", "#{v}"]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# cluster
|
30
|
+
$cluster[:nodes].each do |node,opts|
|
31
|
+
puts "Load cluster node: #{node}"
|
32
|
+
config.vm.define node.to_s do |cfg|
|
33
|
+
vm_defaults[cfg]
|
34
|
+
# cpu and memory
|
35
|
+
if not opts[:cpus].nil? then
|
36
|
+
cfg.vm.customize ["modifyvm", :id, "--cpus", opts[:cpus]]
|
37
|
+
end
|
38
|
+
if not opts[:memory].nil? then
|
39
|
+
cfg.vm.customize ["modifyvm", :id, "--memory", opts[:memory]]
|
40
|
+
end
|
41
|
+
|
42
|
+
cfg.vm.host_name = node.to_s
|
43
|
+
|
44
|
+
# networking
|
45
|
+
if not opts[:hostonly].nil? then
|
46
|
+
cfg.vm.network :hostonly, opts[:hostonly]
|
47
|
+
end
|
48
|
+
if not opts[:bridged].nil? then
|
49
|
+
cfg.vm.network :bridged, opts[:bridged]
|
50
|
+
end
|
51
|
+
|
52
|
+
# forwarding
|
53
|
+
if not opts[:forward].nil? then
|
54
|
+
opts[:forward].each { |p| cfg.vm.forward_port p[0], p[1]}
|
55
|
+
end
|
56
|
+
|
57
|
+
if opts[:chef_client] then
|
58
|
+
orgname = $cluster[:knife][:node_name]
|
59
|
+
|
60
|
+
cfg.vm.provision :chef_client do |chef|
|
61
|
+
if $cluster[:knife][:server_url].nil? then
|
62
|
+
chef.chef_server_url = "https://api.opscode.com/organizations/#{orgname}"
|
63
|
+
else
|
64
|
+
chef.chef_server_url = $cluster[:knife][:server_url]
|
65
|
+
end
|
66
|
+
|
67
|
+
if $cluster[:knife][:client_name].nil? then
|
68
|
+
chef.validation_client_name = "#{orgname}-validator"
|
69
|
+
chef.validation_key_path = ".chef/#{orgname}-validator.pem"
|
70
|
+
else
|
71
|
+
chef.validation_client_name = $cluster[:knife][:client_name]
|
72
|
+
chef.validation_key_path = ".chef/#{$cluster[:knife][:client_name]}.pem"
|
73
|
+
end
|
74
|
+
|
75
|
+
chef.encrypted_data_bag_secret_key_path = ".chef/data_bag.key"
|
76
|
+
chef.node_name = node.to_s
|
77
|
+
|
78
|
+
if not $cluster[:knife][:log_level].nil? then
|
79
|
+
chef.log_level = $cluster[:knife][:log_level]
|
80
|
+
end
|
81
|
+
chef.environment = opts[:chef_client]
|
82
|
+
|
83
|
+
if not opts[:roles].nil? then
|
84
|
+
chef.run_list = opts[:roles]
|
85
|
+
end
|
86
|
+
end # :chef_client
|
87
|
+
else
|
88
|
+
cfg.vm.provision :chef_solo do |chef|
|
89
|
+
chef.cookbooks_path = opts[:cookbooks_path].nil? ? "cookbooks" : opts[:cookbooks_path]
|
90
|
+
|
91
|
+
chef.log_level = :debug
|
92
|
+
|
93
|
+
if not opts[:roles].nil? then
|
94
|
+
chef.run_list = opts[:roles]
|
95
|
+
end
|
96
|
+
|
97
|
+
# access from chef node[:]
|
98
|
+
chef.json = {
|
99
|
+
:cluster => $cluster,
|
100
|
+
:host => opts,
|
101
|
+
"chef_server" => opts[:chef_server]
|
102
|
+
}
|
103
|
+
end
|
104
|
+
end # :chef_solo
|
105
|
+
|
106
|
+
end # cfg
|
107
|
+
end # nodes
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
current_dir = File.dirname(__FILE__)
|
2
|
+
log_level :info
|
3
|
+
log_location STDOUT
|
4
|
+
node_name "<%= if not defined? node_name then 'localhost' else node_name end %>"
|
5
|
+
client_key "#{current_dir}/<%= if not defined? node_name then 'localhost' else node_name end %>.pem"
|
6
|
+
validation_client_name "<%= if not defined? client_name then 'localhost' else client_name end %>"
|
7
|
+
validation_key "#{current_dir}/<%= if not defined? client_name then 'localhost' else client_name end %>.pem"
|
8
|
+
chef_server_url "<%= if not defined? server_url then 'http://localhost:4000' else server_url end %>"
|
9
|
+
cache_type 'BasicFile'
|
10
|
+
cache_options( :path => "#{ENV['HOME']}/.chef/checksums" )
|
11
|
+
cookbook_path ["#{current_dir}/../cookbooks"]
|
12
|
+
encrypted_data_bag_secret "#{current_dir}/data_bag.key"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -119,6 +119,8 @@ files:
|
|
119
119
|
- bin/noc
|
120
120
|
- lib/noc/version.rb
|
121
121
|
- lib/noc.rb
|
122
|
+
- templates/Vagrantfile.erb
|
123
|
+
- templates/knife.rb.erb
|
122
124
|
- README.rdoc
|
123
125
|
- noc.rdoc
|
124
126
|
homepage: http://your.website.com
|