Package virtualization :: Module notification
[hide private]
[frames] | no frames]

Source Code for Module virtualization.notification

 1  # 
 2  # Copyright (c) 2008--2013 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  # This module defines notification-related functions and constants, for use 
18  # with the client-side virtualization code. 
19  # 
20   
21  import sys 
22   
23  import time 
24   
25  from up2date_client import up2dateAuth 
26  from up2date_client import up2dateErrors 
27  from up2date_client import rhnserver 
28  from up2date_client import up2dateLog 
29  from virtualization.errors import NotRegistered 
30   
31  log = up2dateLog.initLog() 
32   
33  ############################################################################### 
34  # Constants 
35  ############################################################################### 
36   
37 -class EventType:
38 EXISTS = 'exists' 39 REMOVED = 'removed' 40 CRAWL_BEGAN = 'crawl_began' 41 CRAWL_ENDED = 'crawl_ended'
42
43 -class TargetType:
44 SYSTEM = 'system' 45 DOMAIN = 'domain' 46 LOG_MSG = 'log_message'
47 48 ############################################################################### 49 # Plan Class 50 ############################################################################### 51
52 -class Plan:
53
54 - def __init__(self):
55 self.__items = []
56
57 - def add(self, event, target = None, properties = {}):
58 """ 59 Creates a new plan item and adds it to the list. 60 """ 61 self.__items.append(self.__make_item(event, target, properties))
62
63 - def execute(self):
64 """ 65 Sends all items in the plan to the satellite. 66 """ 67 systemid = up2dateAuth.getSystemId() 68 69 if systemid is None: 70 raise NotRegistered("System ID not found.") 71 72 server = rhnserver.RhnServer() 73 74 try: 75 server.registration.virt_notify(systemid, self.__items) 76 except up2dateErrors.CommunicationError: 77 e = sys.exc_info()[1] 78 log.trace_me() 79 log.log_me(e)
80 81
82 - def __make_item(self, event, target, properties):
83 """ 84 Creates a new plan item. 85 """ 86 87 # Get the current time. 88 current_time = int(time.time()) 89 return ( current_time, event, target, properties )
90