Package backend :: Package server :: Package action :: Module kickstart
[hide private]
[frames] | no frames]

Source Code for Module backend.server.action.kickstart

  1  # 
  2  # Copyright (c) 2008--2016 Red Hat, Inc. 
  3  # 
  4  # This software is licensed to you under the GNU General Public License, 
  5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
  6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
  8  # along with this software; if not, see 
  9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
 10  # 
 11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
 12  # granted to use or replicate Red Hat trademarks that are incorporated 
 13  # in this software or its documentation. 
 14  # 
 15  # 
 16   
 17  from spacewalk.common.rhnLog import log_debug 
 18  from spacewalk.server import rhnSQL 
 19  from spacewalk.server.rhnLib import InvalidAction, ShadowAction 
 20  from spacewalk.server.rhnServer import server_kickstart, server_packages 
 21   
 22  # the "exposed" functions 
 23  __rhnexport__ = ['initiate', 'schedule_sync'] 
 24   
 25  _query_initiate = rhnSQL.Statement(""" 
 26      select ak.append_string, ak.static_device, ak.kickstart_host, ak.cobbler_system_name 
 27        from rhnActionKickstart ak, rhnKickstartableTree kst 
 28       where ak.action_id = :action_id 
 29  """) 
 30   
 31  _query_file_list_initiate = rhnSQL.Statement(""" 
 32      select distinct rcfn.path 
 33        from rhnActionKickstartFileList akfl, 
 34             rhnFileListMembers rflm, 
 35             rhnConfigFileName rcfn, 
 36             rhnActionKickstart ak 
 37       where rcfn.id = rflm.config_file_name_id 
 38         and akfl.file_list_id = rflm.file_list_id 
 39         and akfl.action_ks_id = ak.id 
 40         and ak.action_id = :action_id 
 41  """) 
 42   
 43   
44 -def initiate(server_id, action_id, dry_run=0):
45 log_debug(3) 46 h = rhnSQL.prepare(_query_initiate) 47 h.execute(action_id=action_id) 48 row = h.fetchone_dict() 49 if not row: 50 raise InvalidAction("Kickstart action without an associated kickstart") 51 boot_image, append_string = ('spacewalk-koan', row['append_string']) 52 static_device = row['static_device'] or "" 53 kickstart_host = row['kickstart_host'] 54 system_record = row['cobbler_system_name'] 55 if system_record is None: 56 system_record = '' 57 if not boot_image: 58 raise InvalidAction("Boot image missing") 59 if not kickstart_host: 60 raise InvalidAction("Kickstart_host missing") 61 62 h = rhnSQL.prepare(_query_file_list_initiate) 63 h.execute(action_id=action_id) 64 files = [x['path'] for x in h.fetchall_dict() or []] 65 66 return (kickstart_host, boot_image, append_string, static_device, system_record, files)
67 68
69 -def schedule_sync(server_id, action_id, dry_run=0):
70 log_debug(3, server_id, action_id) 71 if dry_run: 72 raise ShadowAction("dry run requested - skipping") 73 74 kickstart_session_id = server_kickstart.get_kickstart_session_id(server_id, 75 action_id) 76 77 if kickstart_session_id is None: 78 raise InvalidAction("Could not find kickstart session ID") 79 80 row = server_kickstart.get_kickstart_session_info(kickstart_session_id, server_id) 81 deploy_configs = (row['deploy_configs'] == 'Y') 82 83 ks_package_profile = server_kickstart.get_kisckstart_session_package_profile(kickstart_session_id) 84 # if the session doesn't have a pkg profile, try from the ks profile itself 85 if not ks_package_profile: 86 ks_package_profile = server_kickstart.get_kickstart_profile_package_profile(kickstart_session_id) 87 88 if not ks_package_profile: 89 log_debug(4, "No kickstart package profile") 90 # No profile to bring this system to 91 if deploy_configs: 92 # We have to deploy configs, so pass in a server profile 93 server_profile = server_kickstart.get_server_package_profile(server_id) 94 else: 95 # No configs to be deployed 96 server_profile = None 97 98 server_kickstart.schedule_config_deploy(server_id, 99 action_id, kickstart_session_id, server_profile=server_profile) 100 raise ShadowAction("Package sync not scheduled, missing kickstart " 101 "package profile; proceeding with configfiles.deploy") 102 103 server_profile = server_kickstart.get_server_package_profile(server_id) 104 105 installs, removes = server_packages.package_delta(server_profile, 106 ks_package_profile) 107 108 if not (installs or removes): 109 log_debug(4, "No packages to be installed/removed") 110 if not deploy_configs: 111 server_profile = None 112 113 server_kickstart.schedule_config_deploy(server_id, 114 action_id, kickstart_session_id, server_profile=None) 115 raise ShadowAction("Package sync not scheduled, nothing to do") 116 117 log_debug(4, "Scheduling kickstart delta") 118 server_kickstart.schedule_kickstart_delta(server_id, 119 kickstart_session_id, installs, removes) 120 121 raise ShadowAction("Package sync scheduled")
122