Module kickstart_guest
[hide private]
[frames] | no frames]

Source Code for Module kickstart_guest

 1  # 
 2  # Copyright (c) 2008--2014 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  import sys 
17   
18  rhnpath="/usr/share/rhn" 
19  if rhnpath not in sys.path: 
20      sys.path.append(rhnpath) 
21   
22  from spacewalkkoan import spacewalkkoan 
23   
24  from virtualization.batching_log_notifier import BatchNotifyHandler 
25  from virtualization.constants             import PropertyType 
26  from virtualization.notification          import Plan,                \ 
27                                                   EventType,           \ 
28                                                   TargetType 
29   
30  __rhnexport__ = [ 
31      'initiate' 
32  ] 
33   
34  ############################################################################### 
35  # Public Interface 
36  ############################################################################### 
37   
38 -def initiate(kickstart_host, cobbler_system_name, virt_type, ks_session_id, name, mem_kb, vcpus, disk_gb, virt_bridge, disk_path, extra_append, cache_only=None):
39 if cache_only: 40 return (0, "no-ops for caching", {}) 41 error_code = 0 42 status_message = 'Guest kickstart initiated successfully.' 43 error_messages = {} 44 45 log_notify_handler = KickstartLogNotifyHandler(ks_session_id) 46 47 return spacewalkkoan.initiate_guest(kickstart_host, cobbler_system_name, 48 virt_type, name, mem_kb, vcpus, disk_gb, virt_bridge, disk_path, extra_append, log_notify_handler)
49 50 ############################################################################### 51 # LogNotifyHandler Class 52 ############################################################################### 53
54 -class KickstartLogNotifyHandler(BatchNotifyHandler):
55
56 - def __init__(self, ks_session_id):
57 self.__ks_session_id = ks_session_id 58 self.__plan = None
59
60 - def batch_began(self):
61 self.__plan = Plan()
62
63 - def log_message_discovered(self, log_message):
64 self.__plan.add( 65 EventType.EXISTS, 66 TargetType.LOG_MSG, 67 { PropertyType.ID : self.__ks_session_id, 68 PropertyType.MESSAGE : log_message })
69
70 - def batch_ended(self):
71 self.__plan.execute()
72