lambom 0.4.7 → 0.4.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18348d90022514710524de670d3a08e14a50c34d
4
- data.tar.gz: 1b06f188691179fd7fafa04aa636d451c7282e02
3
+ metadata.gz: 3d9ff2b563d32551701e588d0d320133b8d6ed33
4
+ data.tar.gz: db0627c24f2704f595bcfb04bd5606487e7750eb
5
5
  SHA512:
6
- metadata.gz: 058f35736be038c22002cb8f74f11d15db05accdf9380a6381ea7782b0d3c038962cb777fa298d76c25752c6faff655389ef644acaff87f9f24b11ea87be052a
7
- data.tar.gz: ea449373e8f86512ff94165d710fb999715da0a7b030c6d7ffc85a09c5eef1b55a82bec85411c8bc1153788ec51827b58ef9d4fead4a178b220f687d82ec29d0
6
+ metadata.gz: 934d87813db8c8f5057f7be31aad736e34427968ed3691aef7fb0c146266f5d4ea1fcade327312551f973550e4ffb9d3c0b1b2f536338dd95790ce79a80b88ee
7
+ data.tar.gz: 953c4955a06a55ad280793216ddfab86ad65514e02296e89aadc29c62a441962f6f13262fca69361885203f80b0a55e9448d25fc9b51f064e3c81c17cb7fffbe
data/lambom.gemspec CHANGED
@@ -6,7 +6,7 @@ require "lambom/version"
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'lambom'
8
8
  s.version = Lambom::VERSION
9
- s.date = '2014-01-21'
9
+ s.date = Date.today.to_s
10
10
  s.summary = "Tool to configure servers based on chef-solo and berkshelf"
11
11
  s.description = <<-EOF
12
12
  Riyic is a server configuration service based on chef (http://riyic.com).
data/lib/lambom/api.rb CHANGED
@@ -6,114 +6,114 @@ require 'openssl'
6
6
  require 'net/http'
7
7
 
8
8
  module Lambom
9
- class ApiClient
10
- DEFAULT_API_URL = "https://riyic.com/api/v1"
11
-
12
- def initialize(conf)
13
- @server_id = conf.server or raise "Required parameter \"server\" not found"
14
- @private_key_file = conf.private_key_file or raise "Required parameter \"private_key_file\" not found"
15
- @env = conf.environment
16
-
17
- @api_url = conf.api_url || DEFAULT_API_URL
18
- end
19
-
20
- def get_server_config
21
- get('servers',"#{@server_id}/generate_config");
22
-
23
- end
24
-
25
- def get_berksfile
26
- get("servers","#{@server_id}/berksfile")
27
- end
28
-
29
-
30
-
31
- def get(controller, action='',params={})
32
- uri = build_uri(controller,action)
33
- req = Net::HTTP::Get.new(uri.request_uri)
34
- req.body=generate_body_string(params)
35
- send(uri,req)
36
-
37
- end
38
-
39
- def post(controller, action='',params={})
40
- uri = build_uri(controller,action)
41
- req = Net::HTTP::Post.new(uri.request_uri)
42
- #req.set_form_data(params)
43
- req.body=generate_body_string(params)
44
- send(uri,req)
45
- end
46
-
47
- def send(uri,req)
48
-
49
- ## agregamos os headers da signature
50
- headers = generate_headers(@server_id, @private_key_file, req)
51
- puts headers.inspect if $debug
52
-
53
- headers.each do |header,value|
54
- req[header] = value
55
- end
56
-
57
- http = Net::HTTP.new(uri.host, uri.port)
58
- http.use_ssl = true if uri.scheme == 'https'
59
-
60
- response = http.request(req)
61
- puts response.body if $debug
62
-
63
- if response.is_a?(Net::HTTPSuccess)
64
- return response.body
65
- else
66
- puts "code:#{response.code}, message:#{response.message}" if $debug
67
- raise "api error: #{response.body}"
68
- end
69
-
70
- #puts resp.inspect if @debug
71
- #response = Oj.load(response.body)
72
-
73
- #if response["status"] == "OK"
74
- # return response
75
- #else
76
- # raise response.body
77
- #end
78
-
79
- end
80
-
81
-
82
- private
83
-
84
- def build_uri(controller, action='')
85
- URI("#{@api_url}/#{controller}/#{action}")
86
- end
87
-
88
- def generate_body_string(h={})
89
- r = ""
90
-
91
- h.each do |k,v|
92
- r << "&#{k}=#{v}"
93
- end
94
-
95
- r
96
- end
97
-
98
-
99
- def generate_headers(server_id, private_key_file, request)
100
-
101
- args = {
102
- :body => request.body.to_s,
103
- :user_id => server_id.to_s,
104
- :http_method => request.method.to_s,
105
- :timestamp => Time.now.iso8601,
106
- :path => request.path.to_s,
107
- :proto_version => 1.1
108
- }
109
-
110
- # cargamos a private key do ficheiro
111
- key = IO::read(private_key_file)
112
- private_key = OpenSSL::PKey::RSA.new(key)
113
-
114
- Mixlib::Authentication::SignedHeaderAuth.signing_object(args).sign(private_key)
115
- end
9
+ class ApiClient
10
+ DEFAULT_API_URL = "https://riyic.com/api/v1"
116
11
 
12
+ def initialize(conf)
13
+ @server_id = conf.server or raise "Required parameter \"server\" not found"
14
+ @private_key_file = conf.private_key_file or raise "Required parameter \"private_key_file\" not found"
15
+ @env = conf.environment
117
16
 
17
+ @api_url = conf.api_url || DEFAULT_API_URL
118
18
  end
19
+
20
+ def get_server_config
21
+ get('servers',"#{@server_id}/generate_config");
22
+
23
+ end
24
+
25
+ def get_berksfile
26
+ get("servers","#{@server_id}/berksfile")
27
+ end
28
+
29
+
30
+
31
+ def get(controller, action='',params={})
32
+ uri = build_uri(controller,action)
33
+ req = Net::HTTP::Get.new(uri.request_uri)
34
+ req.body=generate_body_string(params)
35
+ send(uri,req)
36
+
37
+ end
38
+
39
+ def post(controller, action='',params={})
40
+ uri = build_uri(controller,action)
41
+ req = Net::HTTP::Post.new(uri.request_uri)
42
+ #req.set_form_data(params)
43
+ req.body=generate_body_string(params)
44
+ send(uri,req)
45
+ end
46
+
47
+ def send(uri,req)
48
+
49
+ ## agregamos os headers da signature
50
+ headers = generate_headers(@server_id, @private_key_file, req)
51
+ puts headers.inspect if $debug
52
+
53
+ headers.each do |header,value|
54
+ req[header] = value
55
+ end
56
+
57
+ http = Net::HTTP.new(uri.host, uri.port)
58
+ http.use_ssl = true if uri.scheme == 'https'
59
+
60
+ response = http.request(req)
61
+ puts response.body if $debug
62
+
63
+ if response.is_a?(Net::HTTPSuccess)
64
+ return response.body
65
+ else
66
+ puts "code:#{response.code}, message:#{response.message}" if $debug
67
+ raise "api error: #{response.body}"
68
+ end
69
+
70
+ #puts resp.inspect if @debug
71
+ #response = Oj.load(response.body)
72
+
73
+ #if response["status"] == "OK"
74
+ # return response
75
+ #else
76
+ # raise response.body
77
+ #end
78
+
79
+ end
80
+
81
+
82
+ private
83
+
84
+ def build_uri(controller, action='')
85
+ URI("#{@api_url}/#{controller}/#{action}")
86
+ end
87
+
88
+ def generate_body_string(h={})
89
+ r = ""
90
+
91
+ h.each do |k,v|
92
+ r << "&#{k}=#{v}"
93
+ end
94
+
95
+ r
96
+ end
97
+
98
+
99
+ def generate_headers(server_id, private_key_file, request)
100
+
101
+ args = {
102
+ :body => request.body.to_s,
103
+ :user_id => server_id.to_s,
104
+ :http_method => request.method.to_s,
105
+ :timestamp => Time.now.iso8601,
106
+ :path => request.path.to_s,
107
+ :proto_version => 1.1
108
+ }
109
+
110
+ # cargamos a private key do ficheiro
111
+ key = IO::read(private_key_file)
112
+ private_key = OpenSSL::PKey::RSA.new(key)
113
+
114
+ Mixlib::Authentication::SignedHeaderAuth.signing_object(args).sign(private_key)
115
+ end
116
+
117
+
118
+ end
119
119
  end
@@ -1,190 +1,190 @@
1
1
  #require "berkshelf/cli"
2
2
  require 'chef/application/solo'
3
3
  module Lambom
4
- class Converger
5
- include ShellMixin
6
-
7
- DEFAULT_CHEF_PATH = '/var/chef'
8
-
9
- CACHE_PATH = "#{DEFAULT_CHEF_PATH}/cache"
10
-
11
- ENV_VARS_DELETE = %w{
12
- GEM_PATH
13
- RUBY_VERSION
14
- GEM_HOME
15
- MY_RUBY_HOME
16
- rvm_bin_path
17
- rvm_path
18
- rvm_gem_options
19
- rvm_prefix
20
- rvm_version
21
- }
22
-
23
- CHEF_CONF_FILE = "#{Lambom::Config::CONFIG_DIR}/solo.rb"
4
+ class Converger
5
+ include ShellMixin
6
+
7
+ DEFAULT_CHEF_PATH = '/var/chef'
8
+
9
+ CACHE_PATH = "#{DEFAULT_CHEF_PATH}/cache"
10
+
11
+ ENV_VARS_DELETE = %w{
12
+ GEM_PATH
13
+ RUBY_VERSION
14
+ GEM_HOME
15
+ MY_RUBY_HOME
16
+ rvm_bin_path
17
+ rvm_path
18
+ rvm_gem_options
19
+ rvm_prefix
20
+ rvm_version
21
+ }
22
+
23
+ CHEF_CONF_FILE = "#{Lambom::Config::CONFIG_DIR}/solo.rb"
24
24
 
25
- CHEF_CONF_DEV = <<EOF
25
+ CHEF_CONF_DEV = <<EOF
26
26
  cookbook_path ["/mnt/cookbooks/supermarket", "/mnt/others/cookbooks", "/mnt/riyic/cookbooks"]
27
27
  file_cache_path "#{CACHE_PATH}"
28
28
  EOF
29
29
 
30
- CHEF_CONF_OTHER = <<EOF
30
+ CHEF_CONF_OTHER = <<EOF
31
31
  cookbook_path ["#{DEFAULT_CHEF_PATH}/cookbooks", "#{DEFAULT_CHEF_PATH}/site-cookbooks"]
32
32
  file_cache_path "#{CACHE_PATH}"
33
33
  EOF
34
- CHEF_CONF = {
35
- :development => CHEF_CONF_DEV,
36
- :other => CHEF_CONF_OTHER,
37
- }
38
-
39
- def initialize(conf)
40
- @conf = conf
41
- @name = conf.server || String.random(8)
42
- @json_file = conf.json_file
43
- @berksfile = conf.berksfile
44
- end
45
-
46
-
47
- attr_reader :conf,:attributes_json
48
-
49
- def run
50
- preparar_entorno
51
-
52
- descargar_atributos unless conf.json_file
53
-
54
- descargar_cookbooks unless conf.cached || conf.environment == 'development'
55
-
56
- ejecutar_converger
57
- end
58
-
59
-
60
- private
61
-
62
- def descargar_atributos
63
-
64
- # descargar atributos do servidor
65
- json_attributes = Lambom::ApiClient.new(conf).get_server_config
66
-
67
- @json_file = "#{CACHE_PATH}/#{@name}.json"
68
-
69
- file = File.new(@json_file,"w")
70
- file.write(json_attributes)
71
- file.close
72
-
73
- end
74
-
75
- def descargar_cookbooks
76
-
77
- if conf.download_tarball
78
-
79
- # download cookbooks from a tarball
80
- temp = "/tmp/cookbooks.tar.gz"
81
- run_cmd('curl','-o',temp, '-L',conf.download_tarball)
82
- FileUtils.mkdir_p(DEFAULT_CHEF_PATH) unless File.directory?(DEFAULT_CHEF_PATH)
83
- run_cmd('tar','xzf',temp,'--no-same-owner','-C', DEFAULT_CHEF_PATH)
84
- File.unlink(temp)
85
-
86
- end
87
-
88
- # else
89
- # # use berkshelf to download cookbooks
90
- # # Download berksfile from riyic unless it was passed by command line
91
- # descargar_berksfile unless @berksfile
92
- # berks_install
93
- # end
94
- end
95
-
96
- # def descargar_berksfile
97
- # @berksfile = "#{CACHE_PATH}/#{@name}.berksfile"
98
- # berksfile_str = Lambom::ApiClient.new(conf).get_berksfile
99
-
100
- # file = File.new(@berksfile,"w")
101
- # file.write(berksfile_str)
102
- # file.close
103
- # end
104
-
105
-
106
- # def berks_install
107
- # cmd = %W{
108
- # berks install -b #{@berksfile} -p #{DEFAULT_CHEF_PATH}/cookbooks
109
- # }
110
-
111
- # run_cmd *cmd
112
-
113
- # end
114
-
115
-
116
- def ejecutar_converger
117
-
118
- #cmd = %W{
119
- # chef-solo
120
- # -c #{CHEF_CONF_FILE}
121
- # --log_level #{conf.loglevel}
122
- # -j #{@json_file}
123
- #}
124
- #
125
- #unless $debug
126
- # cmd += [
127
- # "--logfile",
128
- # "#{conf.logdir}/#{conf.logfile}"
129
- # ]
130
- #end
131
- #run_cmd *cmd
132
-
133
- cmd = %W{
134
- -c #{CHEF_CONF_FILE}
135
- --log_level #{conf.loglevel}
136
- -j #{@json_file}
137
- }
138
-
139
- unless $debug
140
- cmd += [
141
- "--logfile",
142
- "#{conf.logdir}/#{conf.logfile}"
143
- ]
144
- end
145
-
146
- # reseteamos argv
147
- ARGV.clear
148
- cmd.each do |arg|
149
- ARGV << arg
150
- end
151
-
152
- Chef::Application::Solo.new.run
153
- end
154
-
155
-
156
- def preparar_entorno
157
- # dont drop ruby vars from env
158
- #ENV_VARS_DELETE.each {|v| ENV.delete(v)}
159
- #ENV["PATH"] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
160
-
161
- #creamos directorio de logs
162
- FileUtils.mkdir_p(conf.logdir) unless File.directory?(conf.logdir)
163
- File.chmod(0750, conf.logdir)
164
-
165
- #creamos o directorio cache de chef
166
- FileUtils.mkdir_p(CACHE_PATH) unless File.directory?(CACHE_PATH)
167
- File.chmod(0750,CACHE_PATH)
168
-
169
- # establecemos o archivo de configuracion de chef segun o entorno
170
- switch_chef_conf(conf.environment.to_sym)
171
- end
172
-
173
-
174
- def switch_chef_conf(env)
175
- FileUtils.mkdir_p(Lambom::Config::CONFIG_DIR) unless File.directory?(Lambom::Config::CONFIG_DIR)
176
- File.chmod(0750,Lambom::Config::CONFIG_DIR)
177
-
178
- file = File.new(CHEF_CONF_FILE,"w")
179
-
180
- if CHEF_CONF.has_key?(env)
181
- file.write(CHEF_CONF[env])
182
- else
183
- file.write(CHEF_CONF[:other])
184
- end
185
-
186
-
187
- file.close
188
- end
34
+ CHEF_CONF = {
35
+ :development => CHEF_CONF_DEV,
36
+ :other => CHEF_CONF_OTHER,
37
+ }
38
+
39
+ def initialize(conf)
40
+ @conf = conf
41
+ @name = conf.server || String.random(8)
42
+ @json_file = conf.json_file
43
+ @berksfile = conf.berksfile
44
+ end
45
+
46
+
47
+ attr_reader :conf,:attributes_json
48
+
49
+ def run
50
+ preparar_entorno
51
+
52
+ descargar_atributos unless conf.json_file
53
+
54
+ descargar_cookbooks unless conf.cached || conf.environment == 'development'
55
+
56
+ ejecutar_converger
57
+ end
58
+
59
+
60
+ private
61
+
62
+ def descargar_atributos
63
+
64
+ # descargar atributos do servidor
65
+ json_attributes = Lambom::ApiClient.new(conf).get_server_config
66
+
67
+ @json_file = "#{CACHE_PATH}/#{@name}.json"
68
+
69
+ file = File.new(@json_file,"w")
70
+ file.write(json_attributes)
71
+ file.close
72
+
73
+ end
74
+
75
+ def descargar_cookbooks
76
+
77
+ if conf.download_tarball
78
+
79
+ # download cookbooks from a tarball
80
+ temp = "/tmp/cookbooks.tar.gz"
81
+ run_cmd('curl','-o',temp, '-L',conf.download_tarball)
82
+ FileUtils.mkdir_p(DEFAULT_CHEF_PATH) unless File.directory?(DEFAULT_CHEF_PATH)
83
+ run_cmd('tar','xzf',temp,'--no-same-owner','-C', DEFAULT_CHEF_PATH)
84
+ File.unlink(temp)
85
+
86
+ end
87
+
88
+ # else
89
+ # # use berkshelf to download cookbooks
90
+ # # Download berksfile from riyic unless it was passed by command line
91
+ # descargar_berksfile unless @berksfile
92
+ # berks_install
93
+ # end
94
+ end
95
+
96
+ # def descargar_berksfile
97
+ # @berksfile = "#{CACHE_PATH}/#{@name}.berksfile"
98
+ # berksfile_str = Lambom::ApiClient.new(conf).get_berksfile
99
+
100
+ # file = File.new(@berksfile,"w")
101
+ # file.write(berksfile_str)
102
+ # file.close
103
+ # end
104
+
105
+
106
+ # def berks_install
107
+ # cmd = %W{
108
+ # berks install -b #{@berksfile} -p #{DEFAULT_CHEF_PATH}/cookbooks
109
+ # }
110
+
111
+ # run_cmd *cmd
112
+
113
+ # end
114
+
115
+
116
+ def ejecutar_converger
117
+
118
+ #cmd = %W{
119
+ # chef-solo
120
+ # -c #{CHEF_CONF_FILE}
121
+ # --log_level #{conf.loglevel}
122
+ # -j #{@json_file}
123
+ #}
124
+ #
125
+ #unless $debug
126
+ # cmd += [
127
+ # "--logfile",
128
+ # "#{conf.logdir}/#{conf.logfile}"
129
+ # ]
130
+ #end
131
+ #run_cmd *cmd
132
+
133
+ cmd = %W{
134
+ -c #{CHEF_CONF_FILE}
135
+ --log_level #{conf.loglevel}
136
+ -j #{@json_file}
137
+ }
138
+
139
+ unless $debug
140
+ cmd += [
141
+ "--logfile",
142
+ "#{conf.logdir}/#{conf.logfile}"
143
+ ]
144
+ end
145
+
146
+ # reseteamos argv
147
+ ARGV.clear
148
+ cmd.each do |arg|
149
+ ARGV << arg
150
+ end
151
+
152
+ Chef::Application::Solo.new.run
153
+ end
154
+
155
+
156
+ def preparar_entorno
157
+ # dont drop ruby vars from env
158
+ #ENV_VARS_DELETE.each {|v| ENV.delete(v)}
159
+ #ENV["PATH"] = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
160
+
161
+ #creamos directorio de logs
162
+ FileUtils.mkdir_p(conf.logdir) unless File.directory?(conf.logdir)
163
+ File.chmod(0750, conf.logdir)
164
+
165
+ #creamos o directorio cache de chef
166
+ FileUtils.mkdir_p(CACHE_PATH) unless File.directory?(CACHE_PATH)
167
+ File.chmod(0750,CACHE_PATH)
168
+
169
+ # establecemos o archivo de configuracion de chef segun o entorno
170
+ switch_chef_conf(conf.environment.to_sym)
171
+ end
172
+
173
+
174
+ def switch_chef_conf(env)
175
+ FileUtils.mkdir_p(Lambom::Config::CONFIG_DIR) unless File.directory?(Lambom::Config::CONFIG_DIR)
176
+ File.chmod(0750,Lambom::Config::CONFIG_DIR)
177
+
178
+ file = File.new(CHEF_CONF_FILE,"w")
179
+
180
+ if CHEF_CONF.has_key?(env)
181
+ file.write(CHEF_CONF[env])
182
+ else
183
+ file.write(CHEF_CONF[:other])
184
+ end
185
+
186
+
187
+ file.close
189
188
  end
189
+ end
190
190
  end
@@ -2,33 +2,33 @@ require 'mixlib/shellout'
2
2
  require 'securerandom'
3
3
 
4
4
  module Lambom
5
- module ShellMixin
6
-
7
- DEFAULT_TIMEOUT = 12000
8
-
9
- def run_cmd(*cmd)
10
- # Seteamos a 200min o timeout por defecto
5
+ module ShellMixin
6
+
7
+ DEFAULT_TIMEOUT = 12000
8
+
9
+ def run_cmd(*cmd)
10
+ # Seteamos a 200min o timeout por defecto
11
11
 
12
- opts = {:timeout => DEFAULT_TIMEOUT}
12
+ opts = {:timeout => DEFAULT_TIMEOUT}
13
13
 
14
- if $debug
15
- puts "RUN_CMD: #{cmd}"
16
- opts[:live_stream] = STDOUT
17
- end
14
+ if $debug
15
+ puts "RUN_CMD: #{cmd}"
16
+ opts[:live_stream] = STDOUT
17
+ end
18
18
 
19
- com = Mixlib::ShellOut.new(cmd, opts)
19
+ com = Mixlib::ShellOut.new(cmd, opts)
20
20
 
21
- com.run_command
22
- com.error!
21
+ com.run_command
22
+ com.error!
23
23
 
24
- puts "output: #{com.stdout}" if $debug
25
- com.stdout
26
- end
24
+ puts "output: #{com.stdout}" if $debug
25
+ com.stdout
26
+ end
27
27
 
28
- class String
29
- def self.random(n)
30
- SecureRandom.hex(n)
31
- end
32
- end
28
+ class String
29
+ def self.random(n)
30
+ SecureRandom.hex(n)
31
+ end
33
32
  end
33
+ end
34
34
  end
@@ -1,3 +1,3 @@
1
1
  module Lambom
2
- VERSION = "0.4.7"
2
+ VERSION = '0.4.8'
3
3
  end
data/lib/lambom.rb CHANGED
@@ -13,25 +13,25 @@ require "lambom/converger"
13
13
 
14
14
 
15
15
  module Lambom
16
- $debug = false
17
-
18
- class << self
19
- def run(argv)
20
- puts "DEBUG ENABLED" if $debug
21
- puts "Recived args: #{argv.inspect}" if $debug
22
- raise 'Must be run as root' unless Process.uid == 0
23
-
24
- #cargar config
25
- conf = Lambom::Config.new.load(argv)
26
-
27
- # executar converxencia
28
- Lambom::Converger.new(conf).run
29
- end
16
+ $debug = false
17
+
18
+ class << self
19
+ def run(argv)
20
+ puts "DEBUG ENABLED" if $debug
21
+ puts "Recived args: #{argv.inspect}" if $debug
22
+ raise 'Must be run as root' unless Process.uid == 0
23
+
24
+ #cargar config
25
+ conf = Lambom::Config.new.load(argv)
26
+
27
+ # executar converxencia
28
+ Lambom::Converger.new(conf).run
29
+ end
30
30
 
31
31
 
32
- def enable_debug
33
- $debug = true
34
- end
32
+ def enable_debug
33
+ $debug = true
35
34
  end
35
+ end
36
36
 
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lambom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - J. Gomez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-21 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj