def main(): """ Main function """ global smt parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: create_software_project.py ''')) parser.add_argument('-p', '--project', help='name of the project to be created. Required') parser.add_argument("-e", "--environment", help="Comma delimited list without spaces of the environments to be created. Required") parser.add_argument("-b", '--basechannel', help="The base channel on which the project should be based.") parser.add_argument("-a", '--addchannel', help="Comma delimited list without spaces of the channels to be added. Can be used together with --basechannel") parser.add_argument("-d", '--deletechannel', help="Comma delimited list without spaces of the channels to be removed from the project.") parser.add_argument("-m", '--description', help="Description of the project to be created.") parser.add_argument('--version', action='version', version='%(prog)s 2.0.0, July 8, 2020') args = parser.parse_args() if not args.project: smt = smtools.SMTools("create_software_project") smt.log_error("The option --project is mandatory. Exiting script") smt.exit_program(1) else: smt = smtools.SMTools("create_software_project") # login to suse manager smt.log_info("Start") smt.suman_login() manage_project(args) smt.close_program()
def main(): """ Main function """ global smt parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: do_package_update.py ''')) parser.add_argument( '-s', '--server', help='name of the server to patched (without domain). Required') parser.add_argument('--version', action='version', version='%(prog)s 1.0.1, April 11, 2019') args = parser.parse_args() if not args.server: perr = "The option --server <server_to_run_script_on> is required" smt = smtools.SMTools("nonamed", "do_package_update") smt.set_hostname("nonamed") smt.fatal_error(perr) else: smt = smtools.SMTools(args.server.lower(), "do_package_update") smt.suman_login() smt.set_hostname(args.server.lower()) smt.log_info("######################################################") smt.log_info("Start") smt.log_info("######################################################") do_package_update(smt.get_server_id()) smt.close_program()
def main(): """ Main Function """ global smt smt = smtools.SMTools("create_repos") parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: create_repos.py ''')) parser.add_argument("-r", "--repos", help="file containing the reposotiries to be created") parser.add_argument("-s", '--sync', action="store_true", default=0, help="Synchronizechannel after creation. Default off") parser.add_argument('--version', action='version', version='%(prog)s 2.0.0, June 30, 2020') args = parser.parse_args() if not args.repos: smt = smtools.SMTools("create_repos") smt.log_error("The option --repos is mandatory. Exiting script") smt.exit_program(1) else: if not os.path.exists(args.repos): smt = smtools.SMTools("create_repos") smt.log_error("The given file {} doesn't exist.".format(args.repos)) smt.exit_program(1) else: with open(args.repos) as repo_cfg: repo_config = smtools.load_yaml(repo_cfg) smt.suman_login() do_repo_config(repo_config, args.sync) smt.close_program()
def main(): """ Main function """ global smt parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: system_update.py ''')) parser.add_argument( '-s', '--server', help='name of the server to receive config update. Required') parser.add_argument( "-n", "--noreboot", action="store_true", default=0, help="Do not reboot server after patching or supportpack upgrade.") parser.add_argument( "-f", "--forcereboot", action="store_true", default=0, help="Force a reboot server after patching or supportpack upgrade.") parser.add_argument("-c", '--applyconfig', action="store_true", default=0, help="Apply configuration after and before patching") parser.add_argument( "-u", "--updatescript", action="store_true", default=0, help="Excute the server specific _start and _end scripts") parser.add_argument('--version', action='version', version='%(prog)s 2.0.0, June 29, 2020') args = parser.parse_args() if not args.server: smt = smtools.SMTools("system_update") smt.log_error("The option --server is mandatory. Exiting script") smt.exit_program(1) else: smt = smtools.SMTools("system_update", args.server, True) # login to suse manager smt.log_info("Start") smt.log_debug("The following arguments are set: ") smt.log_debug(args) smt.suman_login() smt.set_hostname(args.server) update_server(args) smt.close_program()
def main(): """ Main section """ global smt smt = smtools.SMTools("sync_environment") parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: sync_environment.py ''')) parser.add_argument( "-e", "--environment", help="the project to be updated. Mandatory with --project") parser.add_argument("-b", "--backup", action="store_true", default=0, help="creates a backup of the stage first.") parser.add_argument('--version', action='version', version='%(prog)s 1.1.0, May 2, 2020') args = parser.parse_args() smt.suman_login() if args.environment: update_environment(args) else: smt.fatal_error( "Option --environment is not given. Aborting operation") smt.close_program()
def main(): """ Main Function """ global smt smt = smtools.SMTools("test", "test") smt.suman_login() smt.log_info("Start") configchannels = smt.client.configchannel.listGlobals(smt.session) #smt.log_info(configchannels) configfiles = smt.client.configchannel.listFiles(smt.session, "default") #print(configfiles) for x in configfiles: #fileinfo = smt.client.configchannel.getFileRevisions(smt.session, "default") fileinfo = smt.client.configchannel.getFileRevisions(smt.session, "default", x.get('path')) #print(fileinfo) for x in configfiles: fileinfo = smt.client.configchannel.lookupFileInfo(smt.session, "default", [x.get('path')]) print(fileinfo) for y in fileinfo: print(y) print(y.get('contents')) if "/init.sls" != y.get('path'): print(fileinfo) print(y.get('contents')) oo = y.get('contents') inhoud = oo + "\nEn deze lijn is toegevoegd" temp = smt.client.configchannel.createOrUpdatePath(smt.session, "default", y.get('path'), False, {'revision': 11, 'contents': inhoud, 'owner': 'root', 'group': 'root', 'permissions': '644', 'macro-start-delimiter': '{|', 'macro-end-delimiter': '|}', 'binary': False}) print(temp) smt.close_program()
def main(): """ Main function """ global smt parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: system_update.py ''')) parser.add_argument('-s', '--server', help='name of the server to be re-registered.') parser.add_argument('-p', '--proxy', help='name of the proxy server the system should be registered against. Required') parser.add_argument('-f', '--file', help='file with list of servers to be re-registered. There should be 1 server per line') parser.add_argument('--version', action='version', version='%(prog)s 0.0.2, April 2, 2020') args = parser.parse_args() smt = smtools.SMTools("system_update") if not args.proxy: smt.log_error("The option --proxy is mandatory. Exiting script") smt.exit_program(1) else: smt.log_info("Start") smt.suman_login() smt.set_hostname(args.proxy) dummy = smt.get_server_id() # login to suse manager rereg_server(args) smt.close_program()
def main(): """ Main Function """ global smt smt = smtools.SMTools("sync_channel") parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: sync_channel.py ''')) parser.add_argument("-c", "--channel", help="name of the cloned parent channel to be updates") parser.add_argument('--version', action='version', version='%(prog)s 1.0.1, February 10, 2019') args = parser.parse_args() if not args.channel: smt.fatal_error( "No parent channel to be cloned given. Aborting operation") else: channel = args.channel smt.suman_login() smt.log_info( "Updating the following channel with latest patches and packages") smt.log_info( "===============================================================") # noinspection PyUnboundLocalVariable smt.log_info("Updating: %s" % channel) try: clone_label = smt.client.channel.software.getDetails( smt.session, channel).get('clone_original') except xmlrpc.client.Fault: message = ('Unable to get channel information for {}.'.format(channel)) message += ' Does the channels exist or is it a cloned channel?' smt.fatal_error(message) smt.log_info(' Errata .....') total = None try: # noinspection PyUnboundLocalVariable total = smt.client.channel.software.mergeErrata( smt.session, clone_label, channel) except xmlrpc.client.Fault: smt.fatal_error('Unable to get errata for channel {}'.format(channel)) smt.log_info(' Merging {} patches'.format(len(total))) time.sleep(120) smt.log_info(' Packages .....') try: total = smt.client.channel.software.mergePackages( smt.session, clone_label, channel) except xmlrpc.client.Fault: smt.minor_error( 'Unable to get packages for channel {}.'.format(channel)) smt.log_info(' Merging {} packages'.format(len(total))) smt.log_info("FINISHED") smt.close_program()
def main(): """ Main Function """ global smt parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: register_system.py ''')) parser.add_argument( '-s', '--server', help='name of the server to receive config update. Required') parser.add_argument('-a', '--activationkey', help='activationkey to use for registration') parser.add_argument('--version', action='version', version='%(prog)s 1.0.0, April 1, 2020') args = parser.parse_args() if not args.server: smt = smtools.SMTools("register_system") smt.log_error("The option --server is mandatory. Exiting script") smt.exit_program(1) elif not args.activationkey: smt = smtools.SMTools("register_system") smt.log_error( "The option --activationkey is mandatory. Exiting script") smt.exit_program(1) else: smt = smtools.SMTools("register_system", args.server) smt.suman_login() smt.set_hostname_only(args.server) # login to suse manager smt.log_info("Start") perform_bootstrap(args.server, args.activationkey) smt.close_program()
def main(): """ Main function """ global smt parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: do_swat.py ''')) parser.add_argument( '-g', '--group', help='name of the server to receive config update. Required') parser.add_argument("-c", '--applyconfig', action="store_true", default=0, help="Apply configuration after and before patching") parser.add_argument( "-u", "--updatescript", action="store_true", default=0, help="Excute the server specific _start and _end scripts") parser.add_argument( "-n", "--noreboot", action="store_true", default=0, help="Do not reboot server after patching or supportpack upgrade.") parser.add_argument( "-f", "--forcereboot", action="store_true", default=0, help="Force a reboot server after patching or supportpack upgrade.") parser.add_argument('--version', action='version', version='%(prog)s 1.0.1, January 16, 2020') args = parser.parse_args() smt = smtools.SMTools("group_system_update") if not args.group: smt.log_error("The option --group is mandatory. Exiting script") smt.exit_program(1) # login to suse manager smt.log_info("Start") smt.suman_login() group_update_server(args) smt.close_program()
def main(): """ Main Function """ global smt smt = smtools.SMTools("sync_channel") parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: sync_channel.py ''')) parser.add_argument("-c", "--channel", help="name of the cloned parent channel to be updates") parser.add_argument('--version', action='version', version='%(prog)s 1.1.0, May 2, 2019') args = parser.parse_args() if not args.channel: smt.fatal_error( "No parent channel to be cloned given. Aborting operation") else: channel = args.channel smt.suman_login() smt.log_info( "Updating the following channel with latest patches and packages") smt.log_info( "===============================================================") # noinspection PyUnboundLocalVariable smt.log_info("Updating: %s" % channel) clone_label = smt.channel_software_getdetails(channel).get( 'clone_original') if not clone_label: smt.log_error( 'Unable to get parent data for channel {}. Has this channel been cloned. Skipping' .format(channel)) return smt.log_info(' Errata .....') smt.log_info(' Merging {} patches'.format( len(smt.channel_software_mergeerrata(clone_label, channel)))) time.sleep(60) smt.log_info(' Packages .....') smt.log_info(' Merging {} packages'.format( len(smt.channel_software_mergepackages(clone_label, channel)))) smt.log_info("FINISHED") smt.close_program()
def main(): """ Main section """ global smt smt = smtools.SMTools("sync_stage") parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: sync_channel.py ''')) parser.add_argument("-c", "--channel", help="name of the cloned parent channel to be updates") parser.add_argument("-b", "--backup", action="store_true", default=0, \ help="creates a backup of the stage first.") parser.add_argument( "-p", "--project", help= "name of the project to be updated. --environment is also mandatory") parser.add_argument( "-e", "--environment", help="the project to be updated. Mandatory with --project") parser.add_argument("-m", "--message", help="Message to be displayed when build is updated") parser.add_argument('--version', action='version', version='%(prog)s 1.0.3, March 23, 2020') args = parser.parse_args() smt.suman_login() if args.channel: update_stage(args) elif args.project and args.environment: update_project(args) else: smt.fatal_error( "Option --channel or options --project and --environment are not given. Aborting operation" ) smt.close_program()
def main(): """ Main function. """ global smt smt = smtools.SMTools("cve_report") parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description="CVE report tool") parser.add_argument( "-c", "--cve", help="list of CVEs to be checked, comma delimeted, no spaces", required=True) parser.add_argument("-r", "--reverse", action="store_true", default=0, help="list systems that have the CVE installed") parser.add_argument( "-f", "--filename", help= "filename the data should be writen in. If no path is given it will be stored in directory where the script has been started.", required=True, type=logfile_present) parser.add_argument('--version', action='version', version='%(prog)s 0.0.1, October 20, 2017') args = parser.parse_args() if args.filename: cve_data = get_cve_data(args) if not args.reverse: create_file_cve(cve_data, args.filename) else: create_file_cve_reverse(cve_data, args.filename) smt.log_info("Result can be found in file: {}".format(args.filename)) smt.suman_logout() smt.close_program() else: parser.print_help()
def main(): """ Main Function """ global smt smt = smtools.SMTools("channel_cloner") parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description=('''\ Usage: make-activation-key.py ''')) parser.add_argument("-r", "--release", help="VCT release. Mandatory", required=True) parser.add_argument("-s", "--source", help="OS Version. Mandatory", required=True) parser.add_argument( "-t", "--todate", help= "Patches until (and including) this date will be added. Format YYYY-MM-DD.", required=True, type=valid_date) parser.add_argument("-o", "--overwrite", action="store_true", default=False, help="If channel already exists, override") parser.add_argument('--version', action='version', version='%(prog)s 0.0.1, January 16, 2019') args = parser.parse_args() if not args.release: smt.fatal_error( "ERROR: Option --release is mandatory. Aborting operation") else: release = args.release bcsuse = None if not args.source: smt.fatal_error("Option --source is mandatory. Aborting operation") else: try: bcsuse = smtools.CONFIGSM['channel_cloner'][ args.source]['base_channel'] except xmlrpc.client.Fault: smt.fatal_error( 'The given Source {} does not exist. Aborting operation'. format(args.source)) smt.suman_login() smt.log_info( "Cloning channels with patches and packages from the given data") smt.log_info( "==============================================================") # check if source base channel exists try: smt.client.channel.software.getDetails(smt.session, bcsuse) except xmlrpc.client.Fault: smt.fatal_error( "The base channel {} set in configuration file is not present. Aborting operation" .format(bcsuse)) # check if release is already present and when overwrite has been set delete otherwise exit. bcvct = args.release + "-" + bcsuse try: smt.client.channel.software.getDetails(smt.session, bcvct) except xmlrpc.client.Fault: # Channel doesn't exist and can be cloned smt.log_info("Cloning channel {} to {}".format(bcsuse, bcvct)) else: # channels exist. If overwrite is set delete stage else abort if args.overwrite: smt.log_info( "Channel {} exists. Channel will be deleted first".format( bcvct)) all_child_channels = None try: all_child_channels = smt.client.channel.software.listChildren( smt.session, bcvct) except xmlrpc.client.Fault: smt.fatal_error( "unable to get a list of child channels for {}".format( bcvct)) for child_channel in all_child_channels: try: smt.client.channel.software.delete( smt.session, child_channel.get('label')) except xmlrpc.client.Fault: smt.log_error("unable to delete channel {}".format( child_channel.get('label'))) try: smt.client.channel.software.delete(smt.session, bcvct) except xmlrpc.client.Fault: smt.fatal_error( "unable to delete channel {}. Aborting".format(bcvct)) time.sleep(30) else: smt.fatal_error( "Channel {} exists. To delete channel first set -o option. Aborting operation." .format(bcvct)) smt.log_info("Start cloning") # clone base channel clone_channel(bcsuse, bcvct, "", False) # clone SUSE channels for channel in smtools.CONFIGSM['channel_cloner'][args.source]['channels']: if "update" in channel: clone_channel( channel.split(",")[0], channel.split(",")[1].replace("RELEASE", release), bcvct, True) try: smt.client.channel.software.mergeErrata( smt.session, channel.split(",")[0], channel.split(",")[1].replace("RELEASE", release), "2000-01-01", args.todate.strftime("%Y-%m-%d")) except xmlrpc.client.Fault: smt.log_error("adding errata to {} failed.".format( channel.split(",")[1].replace("RELEASE", release))) else: smt.log_info("merging errate for channel {}".format( channel.split(",")[1].replace("RELEASE", release))) time.sleep(120) else: clone_channel( channel.split(",")[0], channel.split(",")[1].replace("RELEASE", release), bcvct, False) for channel in smtools.CONFIGSM['channel_cloner'][args.source]['channels']: if "update" in channel: add_packages(channel.split(",")[1].replace("RELEASE", release)) # Set description to channel try: smt.client.channel.software.setDetails( smt.session, bcvct, {'description': ("Release Date: {}".format(args.todate))}) except xmlrpc.client.Fault: smt.log_error("Error setting description for {}".format(bcvct)) smt.log_info("Finished") smt.close_program()
def main(): """ Main function """ try: global smt parser = argparse.ArgumentParser(description="Update the give system.") parser.add_argument( '-s', '--server', help='name of the server to receive config update. Required') parser.add_argument( "-n", "--noreboot", action="store_true", default=0, help="Do not reboot server after patching or supportpack upgrade.") parser.add_argument( "-f", "--forcereboot", action="store_true", default=0, help="Force a reboot server after patching or supportpack upgrade." ) parser.add_argument( "-c", '--applyconfig', action="store_true", default=0, help="Apply configuration after and before patching") parser.add_argument( "-u", "--updatescript", action="store_true", default=0, help="Execute the server specific _start and _end scripts") parser.add_argument( "-p", "--post_script", help= "Execute given script on the SUSE Manger Server when system_update has finished" ) parser.add_argument('--version', action='version', version='%(prog)s 2.0.0, June 29, 2020') args = parser.parse_args() if not args.server: smt = smtools.SMTools("system_update") smt.log_error("The option --server is mandatory. Exiting script") smt.exit_program(1) else: smt = smtools.SMTools("system_update", args.server, True) # login to suse manager smt.log_info("Start") smt.log_debug("The following arguments are set: ") smt.log_debug(args) smt.suman_login() smt.set_hostname(args.server) update_server(args) smt.close_program() except Exception as err: smt.log_debug("general error:") smt.log_debug(err) raise