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

Source Code for Module backend.server.action.configfiles

  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  # config file-related queuing functions 
 16  # 
 17   
 18  import time 
 19   
 20  from spacewalk.common.rhnLog import log_debug 
 21  from spacewalk.server import rhnSQL, rhnServer 
 22  from spacewalk.server.configFilesHandler import format_file_results 
 23  from spacewalk.server.config_common.templated_document import var_interp_prep 
 24   
 25  # the "exposed" functions 
 26  __rhnexport__ = ['upload', 'deploy', 'verify', 'diff', 'mtime_upload'] 
 27   
 28  _query_upload_files = rhnSQL.Statement(""" 
 29      select cfn.path 
 30        from rhnActionConfigFileName acfn, rhnConfigFileName cfn 
 31       where acfn.server_id = :server_id 
 32         and acfn.action_id = :action_id 
 33         and acfn.config_file_name_id = cfn.id 
 34  """) 
 35   
 36  _query_mtime_upload_info = rhnSQL.Statement(""" 
 37      select TO_CHAR(start_date, 'YYYY-MM-DD HH24:MI:SS') as start_date, 
 38             TO_CHAR(end_date, 'YYYY-MM-DD HH24:MI:SS') as end_date, 
 39             TO_CHAR(sysdate, 'YYYY-MM-DD HH24:MI:SS') as now, 
 40             import_contents 
 41        from rhnActionConfigDate 
 42       where action_id = :action_id 
 43  """) 
 44   
 45  _query_mtime_upload_paths = rhnSQL.Statement(""" 
 46      select file_name, 
 47             file_type 
 48        from rhnActionConfigDateFile 
 49       where action_id = :action_id 
 50  """) 
 51   
 52   
53 -def mtime_upload(server_id, action_id, dry_run=0):
54 log_debug(3) 55 56 data = {} 57 58 h = rhnSQL.prepare(_query_mtime_upload_info) 59 h.execute(action_id=action_id) 60 61 info = h.fetchone_dict() 62 info['start_date'] = time.mktime(time.strptime(info['start_date'], '%Y-%m-%d %H:%M:%S')) 63 info['now'] = time.mktime(time.strptime(info['now'], '%Y-%m-%d %H:%M:%S')) 64 65 if info['end_date']: 66 info['end_date'] = time.mktime(time.strptime(info['end_date'], '%Y-%m-%d %H:%M:%S')) 67 else: 68 info['end_date'] = '' 69 70 data['info'] = info 71 72 data['search'] = [] 73 data['ignore'] = [] 74 75 h = rhnSQL.prepare(_query_mtime_upload_paths) 76 h.execute(action_id=action_id) 77 78 while 1: 79 row = h.fetchone_dict() or [] 80 81 if not row: 82 break 83 84 if row['file_type'] == 'W': 85 data['search'].append(row['file_name']) 86 elif row['file_type'] == 'B': 87 data['ignore'].append(row['file_name']) 88 89 log_debug(4, 'data', data) 90 91 return action_id, data
92 93
94 -def upload(server_id, action_id, dry_run=0):
95 log_debug(3) 96 h = rhnSQL.prepare(_query_upload_files) 97 h.execute(action_id=action_id, server_id=server_id) 98 files = [x['path'] for x in h.fetchall_dict() or []] 99 100 return action_id, files
101 102
103 -def deploy(server_id, action_id, dry_run=0):
104 log_debug(3) 105 return _get_files(server_id, action_id)
106 107
108 -def verify(server_id, action_id, dry_run=0):
109 log_debug(3) 110 return _get_files(server_id, action_id)
111 112
113 -def diff(server_id, action_id, dry_run=0):
114 log_debug(3) 115 return _get_files(server_id, action_id)
116 117 _query_get_files = rhnSQL.Statement(""" 118 select cfn.path, 119 cc.label config_channel, 120 ccont.contents file_contents, 121 ccont.is_binary is_binary, 122 c.checksum_type, 123 c.checksum, 124 ccont.delim_start, 125 ccont.delim_end, 126 cr.revision, 127 ci.username, 128 ci.groupname, 129 ci.filemode, 130 cft.label, 131 ci.selinux_ctx, 132 case 133 when cft.label='symlink' then (select path from rhnConfigFileName where id = ci.SYMLINK_TARGET_FILENAME_ID) 134 else '' 135 end as symlink 136 from 137 rhnConfigFileState cfs, 138 rhnConfigChannel cc, 139 rhnConfigFileName cfn, 140 rhnConfigInfo ci, 141 rhnConfigFile cf, 142 rhnConfigRevision cr 143 left join rhnConfigContent ccont 144 on cr.config_content_id = ccont.id 145 left join rhnChecksumView c 146 on ccont.checksum_id = c.id, 147 rhnConfigFileType cft, 148 rhnActionConfigRevision acr 149 where acr.server_id = :server_id 150 and acr.action_id = :action_id 151 and acr.config_revision_id = cr.id 152 and cr.config_file_id = cf.id 153 and cr.config_info_id = ci.id 154 and cf.config_file_name_id = cfn.id 155 and cf.config_channel_id = cc.id 156 and cf.state_id = cfs.id 157 and cfs.label = 'alive' 158 and cr.config_file_type_id = cft.id 159 """) 160 161
162 -def _get_files(server_id, action_id):
163 h = rhnSQL.prepare(_query_get_files) 164 h.execute(action_id=action_id, server_id=server_id) 165 server = rhnServer.search(server_id) 166 server = var_interp_prep(server) 167 168 files = [] 169 while 1: 170 row = h.fetchone_dict() 171 if not row: 172 break 173 files.append(format_file_results(row, server=server)) 174 175 result = { 176 'files': files, 177 } 178 return result
179