Class: PreparePlan
- Inherits:
-
Object
- Object
- PreparePlan
- Defined in:
- lib/commands/prepare-plan.rb
Instance Method Summary collapse
-
#do(blueprint, segment, step, task, test, privateKey, serverBase, serverNumber) ⇒ Object
Read the blueprint instructions and prepare plan for a particular segment.
- #doPatch(paramsString, test, privateKey, serverBase, serverNumber) ⇒ Object
-
#initialize ⇒ PreparePlan
constructor
A new instance of PreparePlan.
- #log(msg) ⇒ Object
Constructor Details
#initialize ⇒ PreparePlan
Returns a new instance of PreparePlan.
10 11 12 13 |
# File 'lib/commands/prepare-plan.rb', line 10 def initialize () @log = Logger.new(Canzea::config[:logging_root] + '/plans.log') @basePath = "#{Pathname.new(Canzea::config[:catalog_location]).realpath}" end |
Instance Method Details
#do(blueprint, segment, step, task, test, privateKey, serverBase, serverNumber) ⇒ Object
Read the blueprint instructions and prepare plan for a particular segment
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/commands/prepare-plan.rb', line 31 def do (blueprint, segment, step, task, test, privateKey, serverBase, serverNumber) planStep = PlanStep.new log "Processing configure.json for #{segment} in #{blueprint} from #{@basePath}" instructions = YAML.load_file("#{@basePath}/blueprints/#{blueprint}/instruction.yml") segment = instructions['instructions']['segments'][segment] log segment['abbreviation'] first = true index = 1 segment['image'].each { |item| if item.start_with?("step:") parts = item.split(':') if (index < Integer(step)) log "[#{index.to_s.rjust(2, "0")}] #{item} SKIPPING" msg = { "message" => { "task" => "skip", "context" => { "step" => index } } } puts msg.to_json else log "[#{index.to_s.rjust(2, "0")}] #{item}" publicIp = File.read("#{Canzea::config[:pwd]}/vps-#{serverBase}-#{serverNumber}.json") publicIp.strip! if (test == false) if (task == nil) RemoteRun.new.do publicIp, privateKey, parts[1], parts[2], index.to_s.rjust(2, "0") else RemoteRun.new.doTask publicIp, privateKey, parts[1], parts[2], task, index.to_s.rjust(2, "0") end # Keep track of what we have done; parsing the response and looking at the JSON else RemoteRun.new.test publicIp, privateKey, parts[1], parts[2], index.to_s.rjust(2, "0") end if first == true # task is only relevant for the first invocation task = nil first = false end end index = index + 1 end } end |
#doPatch(paramsString, test, privateKey, serverBase, serverNumber) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/commands/prepare-plan.rb', line 15 def doPatch (paramsString, test, privateKey, serverBase, serverNumber) publicIp = File.read("#{Canzea::config[:pwd]}/vps-#{serverBase}-#{serverNumber}.json") publicIp.strip! params = JSON.parse(paramsString) patches = Base64.decode64(params["patches"]) params['patches'] = JSON.parse(patches) params['patches'].each do | patch | RemoteRun.new.doCommand publicIp, privateKey, patch["command"] end end |
#log(msg) ⇒ Object
78 79 80 81 |
# File 'lib/commands/prepare-plan.rb', line 78 def log (msg) puts "-- #{msg}" @log.info(msg) end |