canzea 0.1.149 → 0.1.151

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06ea91c2d819d2853665868ab8fe3d9b53474657
4
- data.tar.gz: e9e24e68a9127f3a874f00a2db0c0f7ab1cee9a9
3
+ metadata.gz: 254a64dc073ab378b19653debbe60b4183d92c89
4
+ data.tar.gz: e520f2ac45c7569aa865f861b16a0514f5107967
5
5
  SHA512:
6
- metadata.gz: 8e8a6fabc22a777c58e7cd047bb834ff59a923a13101d192401f477ee2bd9a3872f6debd88522f40f1ec5bf0ed73f59562a99d4e87b38a2067a736ca219727d8
7
- data.tar.gz: f90ffb0576175d6e58d303209c7239f176c86dc77c03831e38f26c840b2f634c57d2dbdd1752a61ccb38c8d420fd2b4556328cbd5e901c9bb3c9c5937e95cb82
6
+ metadata.gz: 95b298648522f79b86f3bc28c167db8333d4eaf4b054138c760c1545e877f09dcf7ef0afd83d86b98c3c7e5aab9325c55a83eb8d24c64e97eb942d706f0e6625
7
+ data.tar.gz: 9f232b09ddb3fa11d060e01d2ec9ccf5adf78c1d8f06df6e8d9c78d352f77e5c1c46f40e63a053d1858af8e296521beb20637dcb1010e48cfce463457bb7e309
@@ -1,3 +1,3 @@
1
1
  module Canzea
2
- VERSION = "0.1.149"
2
+ VERSION = "0.1.151"
3
3
  end
data/lib/canzea.rb CHANGED
@@ -6,6 +6,7 @@ require "canzea/config"
6
6
  require "canzea/version"
7
7
  require "canzea/environment"
8
8
  require "helper-run-class"
9
+ require "trace-component"
9
10
  require "plan-step-class"
10
11
  require "ssh-base-cmd-class"
11
12
  require "template-runner"
@@ -45,6 +46,7 @@ module Canzea
45
46
  # flag nil, :run, 'Run a step'
46
47
  # flag nil, :helper, 'Execute a helper'
47
48
  flag nil, :remote, 'Remote execution'
49
+ flag nil, :remote_configure, 'Remote configuration'
48
50
  flag nil, :remote_wire, 'Remote execution of a helper'
49
51
  flag nil, :get, 'Get a file from the remote server'
50
52
  flag nil, :put, 'Put a file onto the remote server'
@@ -137,6 +139,35 @@ module Canzea
137
139
  RegisterMetadata.new.do(opts[:role], opts[:solution], test)
138
140
  end
139
141
 
142
+ if (util == "analyze-command")
143
+ step = Integer(opts.fetch(:step, '0'))
144
+
145
+ list = []
146
+ args = JSON.parse(opts.fetch(:args, "{'phases'=>['install']}"))
147
+ phases = args['phases']
148
+
149
+ publicIp = File.read("#{Canzea::config[:pwd]}/vps-#{opts[:serverBase]}-#{opts[:serverNumber]}.json")
150
+ publicIp.strip!
151
+
152
+ phases.each { | phase |
153
+ basePath = "#{Pathname.new(Canzea::config[:catalog_location]).realpath}"
154
+ cmd = "#{basePath}/roles/#{opts[:role]}/#{opts[:solution]}/#{phase}.sh"
155
+ if File.exists? cmd
156
+ list += Worker.new.find (cmd)
157
+ end
158
+ }
159
+
160
+ list.each_with_index { | cmd, index |
161
+ if index >= step
162
+ puts "[#{index}] #{cmd}"
163
+
164
+ RemoteRun.new.doCommand publicIp, opts[:privateKey], cmd
165
+ else
166
+ puts "[#{index}] SKIP #{cmd}"
167
+ end
168
+ }
169
+ end
170
+
140
171
  if (util == "gen-user")
141
172
  GenUser.new.do(args[0])
142
173
  end
@@ -241,6 +272,12 @@ module Canzea
241
272
  RemoteRun.new.do publicIp, opts[:privateKey], opts[:role], opts[:solution]
242
273
  end
243
274
 
275
+ if opts[:remote_configure]
276
+ publicIp = File.read("#{Canzea::config[:pwd]}/vps-#{opts[:serverBase]}-#{opts[:serverNumber]}.json")
277
+ publicIp.strip!
278
+ RemoteRun.new.doConfigure publicIp, opts[:privateKey], opts[:role], opts[:solution]
279
+ end
280
+
244
281
  if opts[:remote_wire]
245
282
  publicIp = File.read("#{Canzea::config[:pwd]}/vps-#{opts[:serverBase]}-#{opts[:serverNumber]}.json")
246
283
  publicIp.strip!
@@ -26,7 +26,7 @@ class PushConfig
26
26
  def cp(filePath, destPath)
27
27
  if File.directory?(filePath)
28
28
  Dir.foreach(filePath) { |x|
29
- if x == '.' or x == '..' or x.starts_with('.')
29
+ if x == '.' or x == '..' or x.start_with?('.')
30
30
  else
31
31
  if File.directory?("#{filePath}/#{x}")
32
32
  cp "#{filePath}/#{x}", "#{destPath}/#{x}"
@@ -40,20 +40,69 @@ class PushConfig
40
40
  end
41
41
  end
42
42
 
43
+ def backupAndRemove(filePath)
44
+ backup(filePath)
45
+ rm(filePath)
46
+ end
47
+
48
+ def backup(filePath)
49
+ path = "ecosystems/#{ENV['ECOSYSTEM']}/#{@relPath}#{filePath}"
50
+
51
+ folder = "sc"
52
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
53
+ folder = "_working"
54
+ end
55
+
56
+ if File.exists? folder
57
+ g = Git.init(folder)
58
+ else
59
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
60
+ g = Git.clone(ENV['ECOSYSTEM_CONFIG_GIT'], folder, :path => '.')
61
+ else
62
+ g = Git.init(folder)
63
+ end
64
+ end
65
+
66
+ puts "Exists? #{folder}/#{path}"
67
+ if File.exists? "#{folder}/#{path}"
68
+ numb = 1
69
+ bkup = "#{folder}/#{path}.archived"
70
+ while File.exists? "#{bkup}#{numb}"
71
+ numb = numb + 1
72
+ end
73
+ puts "Backed up to #{bkup}#{numb}"
74
+ File.write "#{bkup}#{numb}", File.read("#{folder}/#{path}");
75
+
76
+ g.add("#{path}.archived#{numb}")
77
+ end
78
+ end
79
+
43
80
  def write(filePath, contents)
44
81
 
45
82
  path = "ecosystems/#{ENV['ECOSYSTEM']}/#{@relPath}#{filePath}"
46
83
 
47
84
  begin
48
- folder = "_working"
85
+ folder = "sc"
86
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
87
+ folder = "_working"
88
+ end
89
+
49
90
 
50
91
  if File.exists? folder
51
92
  g = Git.init(folder)
52
93
  else
53
- g = Git.clone(ENV['ECOSYSTEM_CONFIG_GIT'], folder, :path => '.')
94
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
95
+ g = Git.clone(ENV['ECOSYSTEM_CONFIG_GIT'], folder, :path => '.')
96
+ else
97
+ g = Git.init(folder)
98
+ end
54
99
  end
55
100
  FileUtils.mkdir_p File.dirname("#{folder}/#{path}")
56
101
 
102
+ pth = File.expand_path "#{folder}/#{path}"
103
+
104
+ @log.info "Writing to: #{pth}"
105
+
57
106
  open("#{folder}/#{path}", 'w') { |f|
58
107
  f.puts contents
59
108
  }
@@ -73,17 +122,30 @@ class PushConfig
73
122
  path = "ecosystems/#{ENV['ECOSYSTEM']}/#{@relPath}#{filePath}"
74
123
 
75
124
  begin
76
- folder = "_working"
125
+ folder = "sc"
126
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
127
+ folder = "_working"
128
+ end
77
129
 
78
130
  if File.exists? folder
79
131
  g = Git.init(folder)
80
132
  else
81
133
  g = Git.clone(ENV['ECOSYSTEM_CONFIG_GIT'], folder, :path => '.')
82
134
  end
83
- FileUtils.rmdir_p File.dirname("#{folder}/#{path}")
84
135
 
85
- g.add("#{path}")
136
+ if File.directory? "#{folder}/#{path}"
137
+ puts "DELETE DIRECTORY: #{folder}/#{path}"
138
+ FileUtils.rmdir_p File.dirname("#{folder}/#{path}")
86
139
 
140
+ g.add("#{path}")
141
+
142
+ else
143
+ if File.exists? "#{folder}/#{path}"
144
+ puts "DELETE FILE: #{folder}/#{path}"
145
+ FileUtils.rm_f "#{folder}/#{path}"
146
+ g.remove("#{path}")
147
+ end
148
+ end
87
149
  rescue => exception
88
150
  @log.error("PushConfig Failed")
89
151
  @log.error(exception.to_s)
@@ -94,7 +156,12 @@ class PushConfig
94
156
  end
95
157
 
96
158
  def commit(comment)
97
- folder = "_working"
159
+ folder = "sc"
160
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
161
+ folder = "_working"
162
+ else
163
+ return
164
+ end
98
165
 
99
166
  begin
100
167
  count = 0
@@ -120,15 +187,21 @@ class PushConfig
120
187
  log "#{count} changes committed."
121
188
  g.commit(comment)
122
189
 
123
- g.push
190
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
191
+ g.push
192
+ end
124
193
  end
125
194
 
126
- FileUtils.rm_rf(folder)
195
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
196
+ FileUtils.rm_rf(folder)
197
+ end
127
198
  rescue => exception
128
- FileUtils.rm_rf(folder)
199
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
200
+ FileUtils.rm_rf(folder)
201
+ end
129
202
  @log.error("PushConfig Failed")
130
- @log.error(exception.to_s)
131
203
  @log.error(exception.backtrace)
204
+ @log.error(exception.to_s)
132
205
  abort()
133
206
  end
134
207
  end
@@ -138,7 +211,10 @@ class PushConfig
138
211
 
139
212
  # "git@#{ENV["GOGS_ADDRESS"]}:root/ecosystem.git"
140
213
 
141
- folder = "_working"
214
+ folder = "sc"
215
+ if ENV.has_key? 'ECOSYSTEM_CONFIG_GIT'
216
+ folder = "_working"
217
+ end
142
218
 
143
219
  FileUtils.rm_rf(folder)
144
220
 
@@ -20,6 +20,11 @@ class RemoteRun
20
20
  remote.exec publicIp, privateKey, "canzea --lifecycle=install --role=#{role} --solution=#{solution}", ref
21
21
  end
22
22
 
23
+ def doConfigure(publicIp, privateKey, role, solution, ref="")
24
+ remote = RemoteCall.new
25
+ remote.exec publicIp, privateKey, "canzea --lifecycle=configure --role=#{role} --solution=#{solution}", ref
26
+ end
27
+
23
28
  def doCommand(publicIp, privateKey, command, ref="")
24
29
  remote = RemoteCall.new
25
30
  remote.exec publicIp, privateKey, command, ref
@@ -6,19 +6,21 @@ class UpdateConfig
6
6
 
7
7
  steps = {}
8
8
 
9
- # write to configure the registration of the service
10
- if (File.exists?("#{gitRoot}/configure.json"))
11
- steps = JSON.parse(File.read("#{gitRoot}/configure.json"))
12
- else
13
- steps["steps"] = []
14
- end
9
+ if File.directory? "#{gitRoot}"
10
+ # write to configure the registration of the service
11
+ if (File.exists?("#{gitRoot}/configure.json"))
12
+ steps = JSON.parse(File.read("#{gitRoot}/configure.json"))
13
+ else
14
+ steps["steps"] = []
15
+ end
15
16
 
16
- conf = {
17
- :role => role,
18
- :solution => solution
19
- }
20
- steps["steps"].push(conf)
17
+ conf = {
18
+ :role => role,
19
+ :solution => solution
20
+ }
21
+ steps["steps"].push(conf)
21
22
 
22
- File.open("#{gitRoot}/configure.json", 'w') { |file| file.puts(JSON.generate(steps)) }
23
+ File.open("#{gitRoot}/configure.json", 'w') { |file| file.puts(JSON.generate(steps)) }
24
+ end
23
25
  end
24
26
  end
@@ -33,6 +33,34 @@ class Worker
33
33
  @test = t
34
34
  end
35
35
 
36
+ def find(command, list = [])
37
+ audit = Audit.new false
38
+
39
+ @log.info(" FIND: " + command)
40
+
41
+ File.foreach(command) { |l|
42
+ if ( l.start_with?('## ') )
43
+ @log.info "#{lines + 1} Label: " + l
44
+ elsif ( l.start_with?('#') )
45
+ elsif ( /\S/ !~ l )
46
+ elsif ( l.chomp.end_with?(".sh") && !l.chomp.end_with?(".atomic.sh") && !l.include?("cp ") && !l.include?("chmod") )
47
+ @log.info(" [#{ref}] RECURSE: " + l)
48
+
49
+ workingDir = "#{Pathname.new(Canzea::config[:catalog_location]).realpath}"
50
+
51
+ Dir.chdir(workingDir) {
52
+
53
+ newCommand = "#{Pathname.new(l.chomp).realpath}"
54
+
55
+ lines = find newCommand, list
56
+ }
57
+ else
58
+ list.push l
59
+ end
60
+ }
61
+ return list
62
+ end
63
+
36
64
  def run(command, start, lines, statusIndicator = false, ref = "" )
37
65
  audit = Audit.new false
38
66
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canzea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.149
4
+ version: 0.1.151
5
5
  platform: ruby
6
6
  authors:
7
7
  - Canzea Technologies
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-28 00:00:00.000000000 Z
11
+ date: 2017-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler