noc 0.0.6 → 1.0.0

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.
@@ -1,6 +1,9 @@
1
1
  = noc
2
2
 
3
- Describe your project here
3
+ Vagrant helper
4
+
5
+ Upload stuff to chef server:
6
+ upload cluster | user(s) | book(s) | role(s) | bag(s) | env(s)
4
7
 
5
8
  :include:noc.rdoc
6
9
 
data/bin/noc CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gli'
3
- begin # XXX: Remove this begin/rescue before distributing your app
3
+ #begin # XXX: Remove this begin/rescue before distributing your app
4
4
  require 'noc'
5
- rescue LoadError
6
- STDERR.puts "In development, you need to use `bundle exec bin/todo` to run your app"
7
- STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
8
- STDERR.puts "Feel free to remove this message from bin/todo now"
9
- exit 64
10
- end
5
+ #rescue LoadError
6
+ # STDERR.puts "In development, you need to use `bundle exec bin/todo` to run your app"
7
+ # STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path"
8
+ # STDERR.puts "Feel free to remove this message from bin/todo now"
9
+ # exit 64
10
+ #end
11
11
 
12
12
 
13
13
  CHEF=".chef"
@@ -35,74 +35,50 @@ flag [:c,:clusterfile]
35
35
  desc 'Scaffold the cluster'
36
36
  arg_name 'options'
37
37
  command :init do |c|
38
- # c.desc 'Describe a switch to init'
39
- # c.switch :s
40
38
 
41
- # c.desc 'Describe a flag to init'
42
- # c.default_value 'default'
43
- # c.flag :f
44
39
  c.action do |global_options,options,args|
45
- case
46
- when args[0] == "solo"
47
- puts "Init solo"
48
-
49
- when args[0] == "repo"
50
- system("git clone git://github.com/opscode/chef-repo.git #{args[1]}") unless args[1].nil?
40
+ case args[0]
51
41
 
52
- when args[0] == "users"
42
+ when "users"
53
43
  users_dir = File.join(DATABAGS,"users")
54
44
  Dir.mkdir(users_dir) unless File.exists?(users_dir)
55
45
 
56
46
  $cluster[:users].each do |user|
57
47
  json = File.join( users_dir, user, ".json")
58
- if File.exists?(json) then
59
- raise "File exists #{json}"
60
- end
48
+ raise "File exists #{json}" if File.exists?(json)
61
49
 
62
- # gen key
63
50
  key = File.join( users_dir, user, ".key" )
64
- if File.exists?(key) then
65
- raise "File exists #{key}"
66
- end
51
+ raise "File exists #{key}" if File.exists?(key)
67
52
 
68
53
  system( "ssh-keygen -b 2048 -f #{key}" )
69
54
  pub = IO.read("#{key}.pub")
70
-
71
55
  end
72
56
 
73
- when args[0] == "bags"
57
+ when "bags"
74
58
  %w[clusters users secrets].each do |b|
75
59
  system("knife data bag create #{b}")
76
60
  end
77
61
 
78
- when args[0] == "vagrant"
62
+ when "vagrant"
79
63
  # create vagrantfile
80
- if File.exists?(VAGRANTFILE) then
81
- raise "File exists #{VAGRANTFILE}"
82
- end
64
+ raise "File exists #{VAGRANTFILE}" if File.exists?(VAGRANTFILE)
83
65
  template = File.join(File.dirname(__FILE__), '..', 'templates', VAGRANTFILE + ".erb" )
84
- if not File.exists?(template) then
85
- raise "Template not found: #{template}"
86
- end
66
+ raise "Template not found: #{template}" if not File.exists?(template)
67
+
87
68
  File.open( VAGRANTFILE, 'w' ) do |f|
88
69
  f.write( Erubis::Eruby.new(File.new(template).read).result({:clusterfile => global_options[:clusterfile],
89
70
  :cluster => $cluster}))
90
71
  end
91
72
 
92
- when args[0].nil?
93
- if File.exists?(CHEF_KNIFE) then
94
- raise "File exists #{CHEF_KNIFE}"
95
- end
96
- if $cluster[:knife].nil? then
97
- raise "No knife section in cluster"
98
- end
73
+ when nil
74
+ raise "File exists #{CHEF_KNIFE}" if File.exists?(CHEF_KNIFE)
75
+ raise "No knife section in cluster" if $cluster[:knife].nil?
76
+
99
77
  # create chef directory
100
78
  Dir.mkdir(CHEF) unless File.exists?(CHEF)
101
79
  # knife.rb template
102
80
  template = File.join(File.dirname(__FILE__), '..', 'templates', KNIFE + ".erb" )
103
- if not File.exists?(template) then
104
- raise "Template not found: #{template}"
105
- end
81
+ raise "Template not found: #{template}" if not File.exists?(template)
106
82
  # create knife.rb
107
83
  File.open( CHEF_KNIFE, 'w' ) do |f|
108
84
  f.write( Erubis::Eruby.new(File.new(template).read).result($cluster[:knife]) )
@@ -118,8 +94,8 @@ desc 'Download stuff'
118
94
  arg_name 'COMMAND [options]'
119
95
  command :download do |c|
120
96
  c.action do |global_options,options,args|
121
- case
122
- when args[0] == 'books'
97
+ case args[0]
98
+ when 'books'
123
99
  $cluster[:cookbooks].each do |b|
124
100
  system("knife cookbook site install #{b}")
125
101
  end
@@ -128,68 +104,59 @@ command :download do |c|
128
104
  end
129
105
 
130
106
 
131
- desc 'Upload cookbook, role, databag'
107
+ desc 'Upload: cluster user(s) book(s) role(s) bag(s) env(s)'
132
108
  arg_name 'COMMAND [options]'
133
109
  command :upload do |c|
134
110
  c.desc 'force'
135
111
  c.switch :f
136
112
 
137
113
  c.action do |global_options,options,args|
138
- case
139
- when args[0] == 'books'
114
+ case args[0]
115
+ when 'books'
140
116
  system("knife cookbook upload --all")
141
- when args[0] == "book"
117
+ when 'book'
142
118
  args.shift
143
119
  args.each do |a|
144
120
  system("knife cookbook upload #{a}")
145
121
  end
146
122
 
147
- when args[0] == "roles"
123
+ when 'roles'
148
124
  Dir.glob("roles/*.rb").each do |f|
149
125
  system("knife role from file #{f}")
150
126
  end
151
- when args[0] == "role"
127
+ when 'role'
152
128
  system("knife role from file roles/#{args[1]}.rb")
153
129
 
154
- when args[0] == "envs"
130
+ when 'envs'
155
131
  Dir.glob("environments/*.rb").each do |f|
156
132
  system("knife environment from file #{f}")
157
133
  end
158
- when args[0] == "env"
134
+ when 'env'
159
135
  system("knife environment from file environments/#{args[1]}.rb")
160
136
 
161
- when args[0] == "cluster"
137
+ when 'cluster'
162
138
  data_bag = File.join( "data_bags", "clusters", "#{$cluster[:id]}.json" )
163
139
  if File.exists?( data_bag ) then
164
- if not options[:f] then
165
- raise "Cluster found: #{data_bag}"
166
- end
140
+ raise "Cluster found: #{data_bag}" if not options[:f]
167
141
  end
168
142
  data_bag_dir = File.join( "data_bags", "clusters" )
169
143
  Dir.mkdir(data_bag_dir) unless File.exists?(data_bag_dir)
170
144
  File.open( data_bag, 'w' ) do |f|
171
145
  f.write( $cluster.to_json )
172
146
  end
147
+ system("knife data bag create clusters")
173
148
  system("knife data bag from file clusters #{$cluster[:id]}.json")
174
149
 
175
- when args[0] == "users"
150
+ when 'users'
151
+ system("knife data bag create users")
176
152
  Dir.glob("data_bags/users/*.json").each do |f|
177
153
  system("knife data bag from file users #{File.basename(f)}")
178
154
  end
179
- when args[0] == "user"
155
+ when 'user'
180
156
  system("knife data bag from file users #{args[1]}.json")
181
157
 
182
- when args[0] == "bags"
183
- if args[1].nil? then
184
- raise "Set bag"
185
- end
186
- system("knife data bag create #{args[1]}")
187
- Dir.glob("data_bags/#{args[1]}/*.json").each do |f|
188
- system("knife data bag from file #{args[1]} #{File.basename(f)}")
189
- end
158
+ end
190
159
 
191
- end # upload
192
- puts "upload command ran"
193
160
  end
194
161
  end
195
162
 
@@ -198,8 +165,8 @@ desc 'Delete client from chef server'
198
165
  arg_name 'COMMAND [options]'
199
166
  command :delete do |c|
200
167
  c.action do |global_options,options,args|
201
- case
202
- when args[0] == 'client'
168
+ case args[0]
169
+ when 'client'
203
170
  system("knife client delete #{args[1]}")
204
171
  system("knife node delete #{args[1]}")
205
172
  end
@@ -221,7 +188,7 @@ pre do |global,command,options,args|
221
188
  STDERR.puts e.message
222
189
  # STDERR.puts "ERROR: No infrastructure .yml file provided."
223
190
  exit(-1)
224
- end unless command.names == "init" and args[0] == "repo"
191
+ end
225
192
 
226
193
  true
227
194
  end
@@ -1,3 +1,3 @@
1
1
  module Noc
2
- VERSION = '0.0.6'
2
+ VERSION = '1.0.0'
3
3
  end
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.6
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-31 00:00:00.000000000 Z
12
+ date: 2012-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -76,21 +76,21 @@ dependencies:
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: JSON
79
+ name: chef
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ! '>='
83
+ - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: '0'
85
+ version: 0.10.8
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ! '>='
91
+ - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: '0'
93
+ version: 0.10.8
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: gli
96
96
  requirement: !ruby/object:Gem::Requirement
@@ -119,8 +119,6 @@ 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
124
122
  - README.rdoc
125
123
  - noc.rdoc
126
124
  homepage: http://your.website.com
@@ -1,109 +0,0 @@
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
@@ -1,12 +0,0 @@
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"