Package ZenModel :: Module WinService
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.WinService

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 as published by 
  8  # the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 11  # 
 12  ########################################################################### 
 13   
 14  from Globals import InitializeClass 
 15  from AccessControl import ClassSecurityInfo, Permissions 
 16  from Products.ZenModel.ZenossSecurity import * 
 17   
 18  from Products.ZenRelations.RelSchema import * 
 19  from Products.ZenUtils.Utils import prepId 
 20  from Products.ZenWidgets import messaging 
 21   
 22  from Service import Service 
 23   
24 -def manage_addWinService(context, id, description, userCreated=None, 25 REQUEST=None):
26 """make a device""" 27 s = WinService(id) 28 context._setObject(id, s) 29 s = context._getOb(id) 30 s.description = description 31 args = {'name':id, 'description':description} 32 s.setServiceClass(args) 33 if userCreated: s.setUserCreateFlag() 34 if REQUEST is not None: 35 REQUEST['RESPONSE'].redirect(context.absolute_url() 36 +'/manage_main') 37 return s
38 39
40 -class WinService(Service):
41 """Windows Service Class 42 """ 43 portal_type = meta_type = 'WinService' 44 45 acceptPause = False 46 acceptStop = False 47 pathName = "" 48 serviceType = "" 49 startMode = "" 50 startName = "" 51 collectors = ('zenwin',) 52 53 _properties = Service._properties + ( 54 {'id': 'acceptPause', 'type':'boolean', 'mode':'w'}, 55 {'id': 'acceptStop', 'type':'boolean', 'mode':'w'}, 56 {'id': 'pathName', 'type':'string', 'mode':'w'}, 57 {'id': 'serviceType', 'type':'string', 'mode':'w'}, 58 {'id': 'startMode', 'type':'string', 'mode':'w'}, 59 {'id': 'startName', 'type':'string', 'mode':'w'}, 60 ) 61 62 _relations = Service._relations + ( 63 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "winservices")), 64 ) 65 66 factory_type_information = ( 67 { 68 'immediate_view' : 'winServiceDetail', 69 'actions' : 70 ( 71 { 'id' : 'status' 72 , 'name' : 'Status' 73 , 'action' : 'winServiceDetail' 74 , 'permissions' : ( 75 Permissions.view, ) 76 }, 77 { 'id' : 'events' 78 , 'name' : 'Events' 79 , 'action' : 'viewEvents' 80 , 'permissions' : (ZEN_VIEW, ) 81 }, 82 { 'id' : 'manage' 83 , 'name' : 'Administration' 84 , 'action' : 'winServiceManage' 85 , 'permissions' : ("Manage DMD",) 86 }, 87 { 'id' : 'viewHistory' 88 , 'name' : 'Modifications' 89 , 'action' : 'viewHistory' 90 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 91 }, 92 ) 93 }, 94 ) 95 96 security = ClassSecurityInfo() 97 98
99 - def getInstDescription(self):
100 """Return some text that describes this component. Default is name. 101 """ 102 return "'%s' StartMode:%s StartName:%s" % (self.caption(), 103 self.startMode, self.startName)
104 105
106 - def getServiceClass(self):
107 """Return a dict like one set by zenwinmodeler for services. 108 """ 109 desc = self.description 110 if not desc: 111 svccl = self.serviceclass() 112 if svccl: desc = svccl.description 113 return {'name': self.name(), 'description': desc }
114 115
116 - def setServiceClass(self, kwargs):
117 """Set the service class where name=ServiceName and description=Caption. 118 """ 119 name = kwargs['name'] 120 description = kwargs['description'] 121 path = "/WinService/" 122 srvs = self.dmd.getDmdRoot("Services") 123 srvclass = srvs.createServiceClass(name=name, description=description, 124 path=path) 125 self.serviceclass.addRelation(srvclass)
126 127
128 - def caption(self):
129 """Return the windows caption for this service. 130 """ 131 svccl = self.serviceclass() 132 if svccl: return svccl.description 133 return ""
134 primarySortKey = caption 135 136 security.declareProtected('Manage DMD', 'manage_editService')
137 - def manage_editService(self, id=None, description=None, 138 acceptPause=None, acceptStop=None, 139 pathName=None, serviceType=None, 140 startMode=None, startName=None, 141 monitor=False, severity=5, 142 REQUEST=None):
143 """Edit a Service from a web page. 144 """ 145 renamed = False 146 if id is not None: 147 self.description = description 148 self.acceptPause = acceptPause 149 self.acceptStop = acceptStop 150 self.pathName = pathName 151 self.serviceType = serviceType 152 self.startMode = startMode 153 self.startName = startName 154 if self.id != id: 155 id = prepId(id) 156 self.setServiceClass(dict(name=id, description=description)) 157 renamed = self.rename(id) 158 tmpl = super(WinService, self).manage_editService(monitor, severity, 159 REQUEST=REQUEST) 160 if REQUEST and renamed: 161 messaging.IMessageSender(self).sendToBrowser( 162 'Service Renamed', 163 "Object renamed to: %s" % self.id 164 ) 165 return self.callZenScreen(REQUEST, renamed) 166 return tmpl
167 168 InitializeClass(WinService) 169