Class: Yast::DrbdClass
- Inherits:
-
Module
- Object
- Module
- Yast::DrbdClass
- Defined in:
- ../../src/modules/Drbd.rb
Instance Method Summary (collapse)
- - (Object) del_empty_item(old_map)
- - (Object) main
- - (Object) prepare_conf_file
- - (Object) Read
- - (Object) recursive_write_map(cur_path, the_map)
- - (Object) restore_yast_save_files
- - (Object) validate_configure
- - (Object) Write
Instance Method Details
- (Object) del_empty_item(old_map)
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File '../../src/modules/Drbd.rb', line 365 def del_empty_item(old_map) old_map = deep_copy(old_map) new_map = deep_copy(old_map) Builtins.foreach( Convert.convert(old_map, :from => "map", :to => "map <string, any>") ) do |key, val| if Ops.is_map?(val) Ops.set(new_map, key, del_empty_item(Convert.to_map(val))) #if (is(val, string)) else if Builtins.size(Convert.to_string(val)) == 0 Ops.set(new_map, key, nil) end #new_map = remove(new_map, key); end end deep_copy(new_map) end |
- (Object) main
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 |
# File '../../src/modules/Drbd.rb', line 35 def main textdomain "drbd" Yast.import "Popup" Yast.import "Progress" Yast.import "Report" Yast.import "Summary" Yast.import "Service" Yast.import "Mode" Yast.import "PackageSystem" @proposal_valid = false @modified = false @global_config = {} @resource_config = {} @drbd_dir = "/etc" @start_daemon = false @config_name = { "disk_s" => ["on-io-error", "size"], "syncer" => ["rate", "al-extents"], "net" => [ "timeout", "connect-int", "ping-int", "max-buffers", "unplug-watermark", "max-epoch-size", "sndbuf-size", "ko-count" ], "startup" => ["wfc-timeout", "degr-wfc-timeout"] } @global_error = "" end |
- (Object) prepare_conf_file
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File '../../src/modules/Drbd.rb', line 72 def prepare_conf_file merge_script = Ops.add( Ops.add("\n\t\tpushd ", @drbd_dir), " > /dev/null 2>&1\n" + "\t\tcat drbd.conf | while read line; do\n" + "\t\t\ts=`echo $line | awk '{print $1}'`;\n" + "\t\t\tif [[ x$s =~ xinclude ]]; then\n" + "\t\t\t\tcat `echo $line | sed 's/include//' | sed 's/;//g' | sed 's/\"//g'`;\n" + "\t\t\telse\n" + "\t\t\t\techo $line;\n" + "\t\t\tfi\n" + "\t\tdone > drbd.conf.YaST2prepare \n" + "\t\tpopd > /dev/null 2>&1\n" + "\t" ) if SCR.Execute( path(".target.bash"), Ops.add( Ops.add("/usr/bin/grep '^[ \t]*include' ", @drbd_dir), "/drbd.conf" ) ) == 0 out = Convert.to_map( SCR.Execute(path(".target.bash_output"), merge_script) ) if Ops.get_integer(out, "exit", 0) != 0 || Builtins.size(Ops.get_string(out, "stderr", "")) != 0 @global_error = Ops.add( _("Failed to merge separated DRBD conf files\n"), Ops.get_string(out, "stderr", "") ) Builtins.y2error( "Failed to merge separated DRBD conf files:\n%1", out ) return false end else r = SCR.Execute( path(".target.bash"), Ops.add( Ops.add( Ops.add(Ops.add("/bin/cp ", @drbd_dir), "/drbd.conf "), @drbd_dir ), "/drbd.conf.YaST2prepare" ) ) if r != 0 Builtins.y2error("Failed to write drbd.conf.YaST2prepare") @global_error = _("Failed to write drbd.conf.YaST2prepare") return false end end true end |
- (Object) Read
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File '../../src/modules/Drbd.rb', line 131 def Read # DRBD read dialog caption caption = _("Initializing DRBD Configuration") # We do not set help text here, because it was set outside Progress.New( caption, " ", 4, [ _("Read global settings"), _("Read resources"), _("Read daemon status") ], [ _("Reading global settings..."), _("Reading resources..."), _("Reading daemon status..."), _("Finished") ], "" ) Progress.NextStage # check installed packages # find out which krbd-kmp-<arch> to be installed out = Convert.to_map( SCR.Execute( path(".target.bash_output"), "echo -n `uname -r|grep -Eo \"default|smp|bigsmp|desktop|pae|xen|xenpae|debug|ppc64|iseries64\"`" ) ) krbd_kmp_arch = Ops.get_string(out, "stdout", "default") if !Mode.test && !PackageSystem.CheckAndInstallPackagesInteractive( ["drbd", Ops.add("drbd-kmp-", krbd_kmp_arch)] ) return false end if Ops.greater_than( SCR.Read(path(".target.size"), Ops.add(@drbd_dir, "/drbd.conf")), 0 ) Builtins.y2milestone("DRBD conf file is %1/drbd.conf", @drbd_dir) return false if prepare_conf_file == false # //merge include file # if (SCR::Execute(.target.bash, "/usr/bin/grep '^[ \t]*include' " + drbd_dir + "/drbd.conf") == 0) # { # if (Popup::YesNo(_("Warning: YaST2 DRBD module will rename all included files ") + # _(" for DRBD into a supported schema. Do you want to continue?"))) # { # string merge_script = " # pushd " + drbd_dir + " > /dev/null 2>&1 # cat drbd.conf | while read line; do # s=`echo $line | awk '{print $1}'`; # if [[ x$s =~ xinclude ]]; then # cat `echo $line | sed 's/include//' | sed 's/;//g' | sed 's/\"//g'`; # else # echo $line; # fi # done > drbd.conf.YaST2prepare # popd > /dev/null 2>&1 # "; # map out = (map) SCR::Execute(.target.bash_output, merge_script); # if (out["exit"]:0 != 0 || size(out["stderr"]:"") != 0) # { # y2error("Failed to merge separated configuration files:\n exit code = %1\n stderr = %2", out["exit"]:0, out["stderr"]:""); # Popup::Error(_("Failed to merge separated configuration files.")); # return false; # } # } # else # { # return false; # } # } # else # { # map out = (map)SCR::Execute(.target.bash, "/bin/cp " + drbd_dir + "/drbd.conf " + drbd_dir + "/drbd.conf.YaST2prepare"); # if (out["exit"]:0 != 0) { # y2error("Failed to prepare drbd.conf for reading"); # return false; # } # } # # map out = (map)SCR::Execute(.target.bash_output, "/bin/mkdir -p " + drbd_dir + "/drbd.d"); # if (out["exit"]:0 != 0) { # y2error("Failed to prepare the directory for DRBD"); # return false; # } #read global configs Builtins.foreach( ["disable-ip-verification", "minor-count", "dialog-refresh"] ) do |key| val = Convert.to_string( SCR.Read(Builtins.topath(Builtins.sformat(".drbd.global.%1", key))) ) Ops.set(@global_config, key, val) end if Ops.get(@global_config, "minor-count") == nil Ops.set(@global_config, "minor-count", "5") end if Ops.get(@global_config, "dialog-refresh") == nil Ops.set(@global_config, "dialog-refresh", "1") end #read resources configs res_names = SCR.Dir(Builtins.topath(".drbd.resources")) Builtins.foreach(res_names) do |resname| config = {} res_configs = SCR.Dir( Builtins.topath(Builtins.sformat(".drbd.resources.%1", resname)) ) Builtins.foreach(["protocol"]) do |resconf| if Builtins.contains(res_configs, resconf) val = Convert.to_string( SCR.Read( Builtins.topath( Builtins.sformat(".drbd.resources.%1.%2", resname, resconf) ) ) ) Ops.set(config, resconf, val) end end Builtins.foreach(@config_name) do |r, l| if Builtins.contains(res_configs, r) cf = {} Builtins.foreach(l) do |k| v = Convert.to_string( SCR.Read( Builtins.topath( Builtins.sformat( ".drbd.resources.%1.%2.%3", resname, r, k ) ) ) ) if v != nil Ops.set(cf, k, v) Builtins.y2debug("%1 %2 %3 is %4", resname, r, k, v) end end Ops.set(config, r, cf) if Ops.greater_than(Builtins.size(cf), 0) end end if Builtins.contains(res_configs, "on") nodes = SCR.Dir( Builtins.topath( Builtins.sformat(".drbd.resources.%1.on", resname) ) ) nodescf = {} Builtins.foreach(nodes) do |n| nodecf = {} Builtins.foreach(["device", "disk", "meta-disk", "address"]) do |k| v = Convert.to_string( SCR.Read( Builtins.topath( Builtins.sformat( ".drbd.resources.%1.on.%2.%3", resname, n, k ) ) ) ) if v != nil Ops.set(nodecf, k, v) Builtins.y2debug("%1 on %2 %3 is %4", resname, n, k, v) end end if Ops.greater_than(Builtins.size(nodecf), 0) Ops.set(nodescf, n, nodecf) end end if Ops.greater_than(Builtins.size(nodescf), 0) Ops.set(config, "on", nodescf) end end if Ops.greater_than(Builtins.size(config), 0) Ops.set(@resource_config, resname, config) end end else SCR.Execute(path(".target.bash"), "rm /etc/drbd.conf.YaST2prepare") Builtins.y2milestone("DRBD conf file %1/drbd.conf not found", @drbd_dir) end Builtins.y2milestone("read resource_config=%1", @resource_config) Progress.NextStage @start_daemon = Service.Enabled("drbd") Progress.NextStage Progress.Finish @modified = false true end |
- (Object) recursive_write_map(cur_path, the_map)
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File '../../src/modules/Drbd.rb', line 342 def recursive_write_map(cur_path, the_map) the_map = deep_copy(the_map) Builtins.foreach(the_map) do |key, val| if Ops.is_map?(val) && val != nil SCR.Write(Builtins.add(cur_path, key), nil) recursive_write_map( Builtins.add(cur_path, key), Convert.convert(val, :from => "any", :to => "map <string, any>") ) else Builtins.y2debug( "write conf file: %1=%2", Builtins.add(cur_path, key), val ) SCR.Write(Builtins.add(cur_path, key), val) end end nil end |
- (Object) restore_yast_save_files
384 385 386 387 388 389 390 391 392 393 394 395 |
# File '../../src/modules/Drbd.rb', line 384 def restore_yast_save_files SCR.Execute( path(".target.bash"), "/bin/mv /etc/drbd.conf.YaST2save /etc/drbd.conf" ) SCR.Execute( path(".target.bash"), "/usr/bin/rename .YaST2save '' /etc/drbd.d/*.YaST2save" ) nil end |
- (Object) validate_configure
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File '../../src/modules/Drbd.rb', line 397 def validate_configure out = {} if Ops.less_than(SCR.Read(path(".target.size"), "/etc/drbd.conf"), 0) return true end out = Convert.to_map( SCR.Execute( path(".target.bash_output"), "/bin/cp /etc/drbd.conf /etc/drbd.conf.bak" ) ) if Ops.get_integer(out, "exit", 0) != 0 @global_error = _("Failed to backup drbd.conf") Builtins.y2error("Failed to backup drbd.conf\n %1", out) return false end out = Convert.to_map( SCR.Execute(path(".target.bash_output"), "/bin/echo>/etc/drbd.conf") ) if Ops.get_integer(out, "exit", 0) != 0 @global_error = _("Failed to clean drbd.conf for drbdadm test") Builtins.y2error("Failed to clean drbd.conf for drbdadm test\n%1", out) return false end Builtins.y2milestone("drbdadm res=%1", @resource_config) r = Builtins.foreach( Convert.convert( @resource_config, :from => "map", :to => "map <string, any>" ) ) do |key, val| out = Convert.to_map( SCR.Execute( path(".target.bash_output"), Ops.add( Ops.add("/usr/sbin/drbdadm -t /etc/drbd.d/", key), ".res sh-nop" ) ) ) if Ops.get_integer(out, "exit", 0) != 0 @global_error = Builtins.sformat( _("Invalid configuration of resource %1\n%2"), key, Ops.get_string(out, "stderr", "") ) Builtins.y2error("Invalid configuration of resource %1\n%2", key, out) next false end end return false if r == false if Ops.greater_or_equal( SCR.Read(path(".target.size"), "/etc/drbd.conf.bak"), 0 ) && SCR.Execute( path(".target.bash"), "/bin/mv /etc/drbd.conf.bak /etc/drbd.conf" ) != 0 @global_error = _("Failed to bring drbd.conf back") Builtins.y2error("Failed to bring drbd.conf back") return false end true end |
- (Object) Write
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File '../../src/modules/Drbd.rb', line 472 def Write # DRBD write dialog caption caption = _("Writing DRBD Configuration") # Comment code below due to change the "booting" status # won't change modified flag #return true if !@modified # We do not set help text here, because it was set outside Progress.New( caption, " ", 4, [ _("Write global settings"), _("Write resources"), _("Set daemon status") ], [ _("Writing global settings..."), _("Writing resources..."), _("Setting daemon status..."), _("Finished") ], "" ) if SCR.Execute( path(".target.bash"), Ops.add(Ops.add("/bin/mkdir -p ", @drbd_dir), "/drbd.d") ) != 0 @global_error = _("Failed to make directory /etc/drbd.d") Builtins.y2error("Failed to make directory /etc/drbd.d") return false end #global config here Progress.NextStage Builtins.y2debug( "to write global config: global_config=%1", @global_config ) Builtins.foreach( ["disable-ip-verification", "minor-count", "dialog-refresh"] ) do |key| if Ops.get(@global_config, key) != nil SCR.Write( Builtins.topath(Builtins.sformat(".drbd.global.%1", key)), Ops.get(@global_config, key) ) end end #resource config here Progress.NextStage @resource_config = del_empty_item(@resource_config) recursive_write_map( path(".drbd.resources"), Convert.convert( @resource_config, :from => "map", :to => "map <string, any>" ) ) Builtins.y2debug( "to write resource config: resource_config=%1", @resource_config ) SCR.Write(Builtins.topath(".drbd"), "") if validate_configure == false restore_yast_save_files return false end Progress.NextStage if @start_daemon Service.Enable("drbd") if Service.Status("drbd") == 0 Service.Restart("drbd") else Service.Start("drbd") end else Service.Disable("drbd") Service.Stop("drbd") end Progress.NextStage Progress.Finish true end |