Changeset 1082 for people/joerg.steffens/technical
- Timestamp:
- Aug 20, 2012, 10:45:22 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
people/joerg.steffens/technical/spacecmd/stage.py
r1019 r1082 25 25 from pprint import pprint 26 26 import sys 27 from StringIO import StringIO28 from tempfile import mkdtemp29 import difflib30 27 from spacecmd.utils import * 31 28 … … 53 50 "unknown": "?" 54 51 } 55 # when normalizing texts, exclude lines that start with following keywords,56 # because they result in differences57 # that are not relevant for our staging diffs58 _STAGE_TEXT_EXCLUDES=[59 # configchannel -> file details60 "Revision: ", "Created: ", "Modified: ",61 # kickstart62 "Org Default: ",63 # activation key64 "Universal Default: ",65 ]66 52 67 53 _DUMP_BASE_DIR="/tmp/spacecmd-stage-dump/" … … 172 158 -s SUB (e.g. application1)''' 173 159 174 def do_stage_create_skel(self, args , doreturn = False):160 def do_stage_create_skel(self, args): 175 161 options = [ 176 162 Option('-l', '--label', action='store'), … … 200 186 return 201 187 202 dist = options.label203 arch = options.arch204 188 if self.stage_create_skel( options.label, options.arch, options.sub, create=False ): 205 189 self.stage_create_skel( options.label, options.arch, options.sub, create=True ) … … 245 229 print " [exists]", 246 230 elif create: 247 self.do_distribution_create( "--name " + distribution + " --path " + distributionpath + " --base-channel " + base + " --install-type rhel_6")231 self.do_distribution_create( "--name " + distribution + " --path " + distributionpath + " --base-channel " + base + " --install-type " + disttype ) 248 232 print 249 233 … … 328 312 def get_next_stage_name( self, name ): 329 313 current_stage = self.get_stage_from_name( name ) 330 if not current_stage: return 314 if not current_stage: 315 return 331 316 next_stage = self.get_next_stage( current_stage ) 332 if not next_stage: return 317 if not next_stage: 318 return 333 319 next_stage_name = self.replace_stage_in_name( name, current_stage, next_stage ) 334 320 return next_stage_name 335 336 def get_normalized_text( self, text, stage, excludes=_STAGE_TEXT_EXCLUDES ):337 """Replace all occurances of stage by the word 'STAGE'"""338 normalized_text = []339 for line in text:340 if not line.startswith( tuple(excludes) ):341 normalized_text.append( self.replace_stage_in_name( line, stage, "STAGE" ) )342 return normalized_text343 321 344 322 def print_stage_status( self, name, name_next=None, status="unknown", indent="" ): … … 380 358 # 381 359 382 # softwarechannel helper383 384 def is_softwarechannel( self, name ):385 if not name: return386 return name in self.do_softwarechannel_list( name, True )387 388 def check_softwarechannel( self, name ):389 if not name:390 logging.error( "no softwarechannel label given" )391 return False392 if not self.is_softwarechannel( name ):393 logging.error( "invalid softwarechannel label " + name )394 return False395 return True396 397 360 def get_softwarechannel_childchannel( self, base_channel ): 398 361 result=[] … … 404 367 return result 405 368 406 369 370 407 371 # softwarechannel next 408 372 … … 421 385 return [] 422 386 423 def do_stage_softwarechannel_next(self, args , doreturn = False):387 def do_stage_softwarechannel_next(self, args): 424 388 (args, options) = parse_arguments(args) 425 389 … … 438 402 # check target name 439 403 if not self.is_softwarechannel(target_name): 440 if not doreturn: 441 logging.warning( "a next stage softwarechannel for "+source_name+" ("+target_name+") does not exist" ) 442 return 443 444 if doreturn: 445 return target_name 446 else: 447 print target_name 448 449 450 # softwarechannel diff 451 452 def help_stage_softwarechannel_diff(self): 453 print 'stage_softwarechannel_diff: diff softwarechannel files' 454 print '' 455 print 'usage: stage_softwarechannel_diff SOURCE_CHANNEL [TARGET_CHANNEL]' 456 457 def complete_stage_softwarechannel_diff(self, text, line, beg, end): 458 parts = shlex.split(line) 459 if line[-1] == ' ': parts.append('') 460 args = len(parts) 461 462 if args == 2: 463 return tab_completer(self.do_softwarechannel_list('', True), text) 464 if args == 3: 465 return tab_completer(self.do_softwarechannel_list('', True), text) 466 return [] 467 468 def do_stage_softwarechannel_diff(self, args, doreturn = False): 469 options = [] 470 471 (args, options) = parse_arguments(args, options) 472 473 if len(args) != 1 and len(args) != 2: 474 self.help_stage_softwarechannel_diff() 475 return 476 477 source_channel = args[0] 478 if not self.check_softwarechannel( source_channel ): return 479 480 if len(args) == 2: 481 target_channel = args[1] 482 else: 483 target_channel=self.do_stage_softwarechannel_next( source_channel, doreturn = True) 484 if not self.check_softwarechannel( target_channel ): return 485 486 487 source_data = self.dump_softwarechannel( source_channel, normalize=True ) 488 target_data = self.dump_softwarechannel( target_channel, normalize=True ) 489 490 result=[] 491 492 for line in difflib.unified_diff( source_data, target_data, source_channel, target_channel ): 493 if doreturn: 494 result.append(line) 495 else: 496 print line 497 return result 498 499 500 501 # softwarechannel sync 502 503 def help_stage_softwarechannel_sync(self): 504 print 'stage_softwarechannel_sync: sync the (most recent) packages' 505 print ' from a software channel to another' 506 print 'usage: stage_softwarechannel_sync SOURCE_CHANNEL [TARGET_CHANNEL]' 507 508 def complete_stage_softwarechannel_sync(self, text, line, beg, end): 509 parts = shlex.split(line) 510 if line[-1] == ' ': parts.append('') 511 args = len(parts) 512 513 514 if args == 2: 515 return tab_completer(self.do_softwarechannel_list('', True), text) 516 if args == 3: 517 return tab_completer(self.do_softwarechannel_list('', True), text) 518 return [] 519 520 def do_stage_softwarechannel_sync(self, args): 521 options = [] 522 523 (args, options) = parse_arguments(args, options) 524 525 if len(args) != 1 and len(args) != 2: 526 self.help_stage_softwarechannel_sync() 527 return 528 529 source_channel = args[0] 530 if len(args) == 2: 531 target_channel = args[1] 532 else: 533 target_channel=self.do_stage_softwarechannel_next( source_channel, doreturn = True) 534 535 logging.info( "syncing packages from softwarechannel "+source_channel+" to "+target_channel ) 536 537 # use API call instead of spacecmd function 538 # to get detailed infos about the packages 539 # and not just there names 540 source_packages = self.client.channel.software.listAllPackages(self.session, 541 source_channel) 542 target_packages = self.client.channel.software.listAllPackages(self.session, 543 target_channel) 544 545 546 # get the package IDs 547 source_package_ids = set() 548 for package in source_packages: 549 try: 550 source_package_ids.add(package['id']) 551 except KeyError: 552 logging.error( "failed to read key id" ) 553 continue 554 555 target_package_ids = set() 556 for package in target_packages: 557 try: 558 target_package_ids.add(package['id']) 559 except KeyError: 560 logging.error( "failed to read key id" ) 561 continue 562 563 print "packages common in both channels:" 564 for i in ( source_package_ids & target_package_ids ): 565 print self.get_package_name( i ) 566 print 567 568 source_only = source_package_ids.difference(target_package_ids) 569 if source_only: 570 print 'packages to add to channel "' + target_channel + '":' 571 for i in source_only: 572 print self.get_package_name( i ) 573 print 574 575 576 # check for packages only in target 577 target_only=target_package_ids.difference( source_package_ids ) 578 if target_only: 579 print 'packages to remove from channel "' + target_channel + '":' 580 for i in target_only: 581 print self.get_package_name( i ) 582 print 583 584 if source_only or target_only: 585 if not self.user_confirm('Perform these changes to channel ' + target_channel + ' [y/N]:'): return 586 587 self.client.channel.software.addPackages(self.session, 588 target_channel, 589 list(source_only) ) 590 self.client.channel.software.removePackages(self.session, 591 target_channel, 592 list(target_only) ) 404 logging.debug( "a next stage softwarechannel for "+source_name+" ("+target_name+") does not exist" ) 405 return 406 407 return target_name 408 409 593 410 594 411 #################### … … 597 414 # configchannel 598 415 # 599 600 # configchannel helper601 602 def is_configchannel( self, name ):603 if not name: return604 return name in self.do_configchannel_list( name, True )605 606 def check_configchannel( self, name ):607 if not name:608 logging.error( "no configchannel given" )609 return False610 if not self.is_configchannel( name ):611 logging.error( "invalid configchannel label " + name )612 return False613 return True614 615 416 616 417 # configchannel next … … 630 431 return [] 631 432 632 def do_stage_configchannel_next(self, args , doreturn = False):433 def do_stage_configchannel_next(self, args): 633 434 (args, options) = parse_arguments(args) 634 435 … … 647 448 # check target name 648 449 if not self.is_configchannel(target_name): 649 if not doreturn: 650 logging.warning( "a next stage configchannel for "+source_name+" ("+target_name+") does not exist" ) 651 return 652 653 if doreturn: 654 return target_name 655 else: 656 print target_name 657 658 659 # configchannel diff 660 661 def help_stage_configchannel_diff(self): 662 print 'stage_configchannel_diff: diff between config channels' 663 print ' ' 664 print 'usage: stage_configchannel_diff SOURCE_CHANNEL [TARGET_CHANNEL]' 665 666 def complete_stage_configchannel_diff(self, text, line, beg, end): 667 parts = shlex.split(line) 668 if line[-1] == ' ': parts.append('') 669 args = len(parts) 670 671 if args == 2: 672 return tab_completer(self.do_configchannel_list('', True), text) 673 if args == 3: 674 return tab_completer(self.do_configchannel_list('', True), text) 675 return [] 676 677 def do_stage_configchannel_diff(self, args, doreturn = False): 678 options = [] 679 680 (args, options) = parse_arguments(args, options) 681 682 if len(args) != 1 and len(args) != 2: 683 self.help_stage_configchannel_diff() 684 return 685 686 source_channel = args[0] 687 if not self.check_configchannel( source_channel ): return 688 689 if len(args) == 2: 690 target_channel = args[1] 691 else: 692 target_channel=self.do_stage_configchannel_next( source_channel, doreturn = True) 693 if not self.check_configchannel( target_channel ): return 694 695 source_data = self.dump_configchannel( source_channel, normalize=True ) 696 target_data = self.dump_configchannel( target_channel, normalize=True ) 697 698 result=[] 699 for line in difflib.unified_diff( source_data, target_data, source_channel, target_channel ): 700 if doreturn: 701 result.append(line) 702 else: 703 print line 704 return result 705 706 707 # configchannel sync 708 709 def help_stage_configchannel_sync(self): 710 print 'stage_configchannel_sync: sync config files' 711 print ' from a config channel to another' 712 print 'usage: stage_configchannel_sync SOURCE_CHANNEL [TARGET_CHANNEL]' 713 714 def complete_stage_configchannel_sync(self, text, line, beg, end): 715 parts = shlex.split(line) 716 if line[-1] == ' ': parts.append('') 717 args = len(parts) 718 719 720 if args == 2: 721 return tab_completer(self.do_configchannel_list('', True), text) 722 if args == 3: 723 return tab_completer(self.do_configchannel_list('', True), text) 724 return [] 725 726 def do_stage_configchannel_sync(self, args, doreturn = False): 727 options = [] 728 729 (args, options) = parse_arguments(args, options) 730 731 if len(args) != 1 and len(args) != 2: 732 self.help_stage_configchannel_sync() 733 return 734 735 source_channel = args[0] 736 if not self.check_configchannel( source_channel ): return 737 738 if len(args) == 2: 739 target_channel = args[1] 740 else: 741 target_channel=self.do_stage_configchannel_next( source_channel, doreturn = True) 742 if not self.check_configchannel( target_channel ): return 743 744 logging.info( "syncing files from configchannel "+source_channel+" to "+target_channel ) 745 746 source_files = set( self.do_configchannel_listfiles( source_channel, doreturn = True ) ) 747 target_files = set( self.do_configchannel_listfiles( target_channel, doreturn = True ) ) 748 749 both=source_files & target_files 750 if both: 751 print "files common in both channels:" 752 print "\n".join( both ) 753 print 754 755 source_only=source_files.difference( target_files ) 756 if source_only: 757 print "files only in source "+source_channel 758 print "\n".join( source_only ) 759 print 760 761 target_only=target_files.difference( source_files ) 762 if target_only: 763 print "files only in target "+target_channel 764 print "\n".join( target_only ) 765 print 766 767 if both: 768 print "files that are in both channels will be overwritten in the target channel" 769 if source_only: 770 print "files only in the source channel will be added to the target channel" 771 if target_only: 772 print "files only in the target channel will be deleted" 773 774 if not (both or source_only or target_only): 775 logging.info( "nothing to do" ) 776 return 777 778 if not self.user_confirm('perform synchronisation [y/N]:'): return 779 780 source_data_list = self.client.configchannel.lookupFileInfo(\ 781 self.session, source_channel, 782 list( both ) + list(source_only) ) 783 784 785 # TODO: check if this newly available function can be used instead: 786 # self.configchannel_sync_by_backup_import() 787 for source_data in source_data_list: 788 if source_data.get('type') == 'file' or source_data.get('type') == 'directory': 789 if source_data.get('contents') and not source_data.get('binary'): 790 contents = source_data.get('contents').encode('base64') 791 else: 792 contents = source_data.get('contents') 793 target_data = { 794 'contents': contents, 795 'contents_enc64': True, 796 'owner': source_data.get('owner'), 797 'group': source_data.get('group'), 798 #'permissions': str(source_data.get('permissions')), 799 'permissions': source_data.get('permissions_mode'), 800 'selinux_ctx': source_data.get('selinux_ctx'), 801 'macro-start-delimiter': source_data.get('macro-start-delimiter'), 802 'macro-end-delimiter': source_data.get('macro-end-delimiter'), 803 } 804 for k,v in target_data.items(): 805 if not v: 806 del target_data[k] 807 logging.debug( source_data.get('path') + ": " + str(target_data) ) 808 self.client.configchannel.createOrUpdatePath(self.session, 809 target_channel, 810 source_data.get('path'), 811 source_data.get('type') == 'directory', 812 target_data) 813 814 elif source_data.get('type') == 'symlink': 815 target_data = { 816 'target_path': source_data.get('target_path'), 817 'selinux_ctx': source_data.get('selinux_ctx'), 818 } 819 logging.debug( source_data.get('path') + ": " + str(target_data) ) 820 self.client.configchannel.createOrUpdateSymlink(self.session, 821 target_channel, 822 source_data.get('path'), 823 target_data ) 824 825 else: 826 logging.warning( "unknown file type " + source_data.type ) 827 828 829 # removing all files from target channel that did not exist on source channel 830 if target_only: 831 self.do_configchannel_removefiles( target_channel + " " + " ".join(target_only) ) 450 logging.debug( "a next stage configchannel for "+source_name+" ("+target_name+") does not exist" ) 451 return 452 return target_name 832 453 833 454 … … 837 458 # kickstart 838 459 # 839 840 # kickstart helper841 842 def is_kickstart( self, name ):843 if not name: return844 return name in self.do_kickstart_list( name, True )845 846 def check_kickstart( self, name ):847 if not name:848 logging.error( "no kickstart label given" )849 return False850 if not self.is_kickstart( name ):851 logging.error( "invalid kickstart label " + name )852 return False853 return True854 855 460 856 461 # kickstart next … … 870 475 return [] 871 476 872 def do_stage_kickstart_next(self, args , doreturn = False):477 def do_stage_kickstart_next(self, args): 873 478 (args, options) = parse_arguments(args) 874 479 … … 887 492 # check target name 888 493 if not self.is_kickstart(target_name): 889 if not doreturn: 890 logging.warning( "a next stage kickstart for "+source_name+" ("+target_name+") does not exist" ) 891 return 892 893 if doreturn: 894 return target_name 895 else: 896 print target_name 897 898 899 # kickstart diff 900 901 def help_stage_kickstart_diff(self): 902 print 'stage_kickstart_diff: diff kickstart files' 903 print '' 904 print 'usage: stage_kickstart_diff SOURCE_CHANNEL [TARGET_CHANNEL]' 905 906 def complete_stage_kickstart_diff(self, text, line, beg, end): 907 parts = shlex.split(line) 908 if line[-1] == ' ': parts.append('') 909 args = len(parts) 910 911 if args == 2: 912 return tab_completer(self.do_kickstart_list('', True), text) 913 if args == 3: 914 return tab_completer(self.do_kickstart_list('', True), text) 915 return [] 916 917 def do_stage_kickstart_diff(self, args, doreturn = False): 918 options = [] 919 920 (args, options) = parse_arguments(args, options) 921 922 if len(args) != 1 and len(args) != 2: 923 self.help_stage_kickstart_diff() 924 return 925 926 source_channel = args[0] 927 if not self.check_kickstart( source_channel ): return 928 929 if len(args) == 2: 930 target_channel = args[1] 931 else: 932 target_channel=self.do_stage_kickstart_next( source_channel, doreturn = True) 933 if not self.check_kickstart( target_channel ): return 934 935 936 source_data = self.dump_kickstart( source_channel, normalize=True ) 937 target_data = self.dump_kickstart( target_channel, normalize=True ) 938 939 result=[] 940 for line in difflib.unified_diff( source_data, target_data, source_channel, target_channel ): 941 if doreturn: 942 result.append(line) 943 else: 944 print line 945 return result 946 947 494 logging.debug( "a next stage kickstart for "+source_name+" ("+target_name+") does not exist" ) 495 return 496 return target_name 948 497 949 498 #################### … … 952 501 # activationkey 953 502 # 954 955 # activationkey helper956 957 def is_activationkey( self, name ):958 if not name: return959 return name in self.do_activationkey_list( name, True )960 961 def check_activationkey( self, name ):962 if not name:963 logging.error( "no activationkey label given" )964 return False965 if not self.is_activationkey( name ):966 logging.error( "invalid activationkey label " + name )967 return False968 return True969 970 503 971 504 # activationkey next … … 985 518 return [] 986 519 987 def do_stage_activationkey_next(self, args , doreturn = False):520 def do_stage_activationkey_next(self, args): 988 521 (args, options) = parse_arguments(args) 989 522 … … 1002 535 # check target name 1003 536 if not self.is_activationkey(target_name): 1004 if not doreturn: 1005 logging.warning( "a next stage activationkey for "+source_name+" ("+target_name+") does not exist" ) 1006 return 1007 1008 if doreturn: 1009 return target_name 1010 else: 1011 print target_name 1012 1013 1014 # activationkey diff 1015 1016 def help_stage_activationkey_diff(self): 1017 print 'stage_activationkeyt_diff: diff activationkeys' 1018 print '' 1019 print 'usage: stage_activationkey_diff SOURCE_ACTIVATIONKEY [TARGET_ACTIVATIONKEY]' 1020 1021 def complete_stage_activationkey_diff(self, text, line, beg, end): 1022 parts = shlex.split(line) 1023 if line[-1] == ' ': parts.append('') 1024 args = len(parts) 1025 1026 1027 if args == 2: 1028 return tab_completer(self.do_activationkey_list('', True), text) 1029 if args == 3: 1030 return tab_completer(self.do_activationkey_list('', True), text) 1031 return [] 1032 1033 def do_stage_activationkey_diff(self, args, doreturn = False): 1034 options = [] 1035 1036 (args, options) = parse_arguments(args, options) 1037 1038 if len(args) != 1 and len(args) != 2: 1039 self.help_stage_activationkey_diff() 1040 return 1041 1042 source_channel = args[0] 1043 if not self.check_activationkey( source_channel ): return 1044 1045 if len(args) == 2: 1046 target_channel = args[1] 1047 else: 1048 target_channel=self.do_stage_activationkey_next( source_channel, doreturn = True) 1049 if not self.check_activationkey( target_channel ): return 1050 1051 1052 source_data = self.dump_activationkey( source_channel, normalize=True ) 1053 target_data = self.dump_activationkey( target_channel, normalize=True ) 1054 1055 result=[] 1056 for line in difflib.unified_diff( source_data, target_data, source_channel, target_channel ): 1057 if doreturn: 1058 result.append(line) 1059 else: 1060 print line 1061 return result 1062 1063 537 logging.debug( "a next stage activationkey for "+source_name+" ("+target_name+") does not exist" ) 538 return 539 return target_name 1064 540 1065 541 … … 1081 557 if line[-1] == ' ': parts.append('') 1082 558 args = len(parts) 1083 1084 559 1085 560 if args == 2: … … 1115 590 def check_stage_softwarechannel_status( self, name, indent="" ): 1116 591 status="unknown" 1117 name_next = self.do_stage_softwarechannel_next( name , doreturn=True)592 name_next = self.do_stage_softwarechannel_next( name ) 1118 593 if name_next: 1119 if self.do_s tage_softwarechannel_diff( name + " " + name_next, doreturn=True):594 if self.do_softwarechannel_diff( name + " " + name_next ): 1120 595 status="modified" 1121 596 else: … … 1137 612 def check_stage_configchannels_status( self, name, indent="" ): 1138 613 status="unknown" 1139 name_next = self.do_stage_configchannel_next( name , doreturn=True)614 name_next = self.do_stage_configchannel_next( name ) 1140 615 if name_next: 1141 if self.do_ stage_configchannel_diff( name + " " + name_next, doreturn=True):616 if self.do_configchannel_diff( name + " " + name_next ): 1142 617 status="modified" 1143 618 else: … … 1160 635 def check_stage_kickstarts_status( self, name, indent="" ): 1161 636 status="unknown" 1162 name_next = self.do_stage_kickstart_next( name , doreturn=True)637 name_next = self.do_stage_kickstart_next( name ) 1163 638 if name_next: 1164 if self.do_ stage_kickstart_diff( name + " " + name_next, doreturn=True):639 if self.do_kickstart_diff( name + " " + name_next ): 1165 640 status="modified" 1166 641 else: … … 1183 658 def check_stage_activationkey_status( self, name, indent="" ): 1184 659 status="unknown" 1185 name_next = self.do_stage_activationkey_next( name , doreturn=True)660 name_next = self.do_stage_activationkey_next( name ) 1186 661 if name_next: 1187 if self.do_ stage_activationkey_diff( name + " " + name_next, doreturn=True):662 if self.do_activationkey_diff( name + " " + name_next ): 1188 663 status="modified" 1189 664 else: … … 1232 707 self.stage = stage 1233 708 1234 1235 709 if len(args) == 2: 1236 710 outputpath_base = datetime.now().strftime(os.path.expanduser(args[1])) … … 1248 722 self.dump_activationkeys( outputpath_base + "/activationkey/" ) 1249 723 1250 1251 1252 724 725 1253 726 def dump_softwarechannels(self, basedir): 1254 727 logging.info( "softwarechannel" ) … … 1265 738 for child_channel in self.get_softwarechannel_childchannel( base_channel ): 1266 739 logging.info( " " + child_channel ) 1267 packages = self.dump_softwarechannel( child_channel , onlyLastestPackages=False, normalize=True)740 packages = self.dump_softwarechannel( child_channel ) 1268 741 self.dump( base_channel_dir + '/' + self.get_common_name(child_channel), packages ) 1269 742 1270 def dump_softwarechannel(self, name, onlyLastestPackages=True, normalize=False): 1271 if onlyLastestPackages: 1272 content = self.do_softwarechannel_listallpackages( name, doreturn=True ) 1273 else: 1274 content = self.do_softwarechannel_listallpackages( name, doreturn=True ) 1275 return content 1276 1277 def dump_configchannel_filedetails(self, name, filename, normalize=False): 1278 # redirect stdout to string. 1279 # to be able to reuse the existing do_activationkey_details function 1280 old_stdout=sys.stdout 1281 output=StringIO() 1282 sys.stdout=output 1283 self.do_configchannel_filedetails( name +" "+ filename ) 1284 sys.stdout=old_stdout 1285 content=output.getvalue().split("\n") 1286 output.close() 1287 1288 if normalize: 1289 stage = self.get_stage_from_name( name ) 1290 content=self.get_normalized_text( content, stage ) 1291 return content 1292 1293 def dump_configchannel(self, name, normalize=False): 1294 # redirect stdout to string. 1295 # to be able to reuse the existing do_activationkey_details function 1296 old_stdout=sys.stdout 1297 output=StringIO() 1298 sys.stdout=output 1299 self.do_configchannel_details( name ) 1300 sys.stdout=old_stdout 1301 content=output.getvalue().split("\n") 1302 output.close() 1303 1304 for filename in self.do_configchannel_listfiles(name, True): 1305 content = content + self.dump_configchannel_filedetails(name, filename, normalize=True) 1306 1307 if normalize: 1308 stage = self.get_stage_from_name( name ) 1309 content=self.get_normalized_text( content, stage ) 1310 1311 return content 1312 1313 743 744 1314 745 def dump_configchannels(self, basedir): 1315 746 logging.info( "configchannel" ) … … 1319 750 if self.is_current_stage( name ): 1320 751 logging.info( " " + name ) 1321 dir = basedir + self.get_common_name(name) 1322 self.do_configchannel_backup( name+" "+dir ) 1323 1324 1325 def dump_kickstart_content(self, name, normalize=False): 1326 content = self.client.kickstart.profile.downloadRenderedKickstart(\ 1327 self.session, name ).split("\n") 1328 stage = self.get_stage_from_name( name ) 1329 if normalize: 1330 content=self.get_normalized_text( content, stage ) 1331 return content 1332 1333 def dump_kickstart_details(self, name, normalize=False): 1334 # redirect stdout to string. 1335 # to be able to reuse the existing do_activationkey_details function 1336 old_stdout=sys.stdout 1337 output=StringIO() 1338 sys.stdout=output 1339 self.do_kickstart_details( name ) 1340 sys.stdout=old_stdout 1341 content=output.getvalue().split("\n") 1342 output.close() 1343 1344 if normalize: 1345 stage = self.get_stage_from_name( name ) 1346 content=self.get_normalized_text( content, stage ) 1347 1348 return content 1349 1350 def dump_kickstart(self, name, normalize=False): 1351 return dump_kickstart_details(self, name, normalize=normalize) 1352 1353 1354 def dump_kickstarts(self, basedir, doreturn = False): 752 directory = basedir + self.get_common_name(name) 753 self.do_configchannel_backup( name+" "+directory ) 754 755 756 def dump_kickstarts(self, basedir): 1355 757 logging.info( "kickstart" ) 1356 758 kickstarts = self.client.kickstart.listKickstarts(self.session) … … 1361 763 logging.info( " " + name ) 1362 764 dir = basedir + self.get_common_name(name) 1363 content = self.dump_kickstart( name, normalize=True ) 1364 if doreturn: 1365 return content 1366 else: 1367 # dump kickstart details and ks file content. 1368 # use separate files 1369 self.dump( dir + '/' + self.get_common_name(name), content ) 1370 self.dump( dir + '/' + self.get_common_name(name) + ".content", dump_kickstart_content(self, name, normalize=True) ) 1371 1372 1373 def dump_activationkey(self, name, normalize=False): 1374 # redirect stdout to string. 1375 # to be able to reuse the existing do_activationkey_details function 1376 old_stdout=sys.stdout 1377 output=StringIO() 1378 sys.stdout=output 1379 self.do_activationkey_details( name ) 1380 sys.stdout=old_stdout 1381 content=output.getvalue().split("\n") 1382 output.close() 1383 1384 if normalize: 1385 stage = self.get_stage_from_name( name ) 1386 content=self.get_normalized_text( content, stage ) 1387 1388 return content 1389 765 content = self.dump_kickstart( name ) 766 # dump kickstart details and ks file content. 767 # use separate files 768 self.dump( dir + '/' + self.get_common_name(name), content ) 769 #self.dump( dir + '/' + self.get_common_name(name) + ".content", dump_kickstart_content(self, name) ) 1390 770 1391 771 … … 1398 778 logging.info( " " + name ) 1399 779 1400 content = self.dump_activationkey( name , normalize=True)780 content = self.dump_activationkey( name ) 1401 781 1402 782 dir = basedir + self.get_common_name(name) 1403 783 self.dump( dir + '/' + self.get_common_name(name), content ) 1404 784 785 1405 786 # vim:ts=4:expandtab:
Note:
See TracChangeset
for help on using the changeset viewer.