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 Acquisition import aq_base 
 17   
 18  from Products.ZenRelations.RelSchema import * 
 19  from Products.ZenUtils.Utils import prepId 
 20   
 21  from Service import Service 
 22   
23 -def manage_addWinService(context, id, description, userCreated=None, REQUEST=None):
24 """make a device""" 25 s = WinService(id) 26 context._setObject(id, s) 27 s = context._getOb(id) 28 #setattr(s, 'name', id) 29 setattr(s, 'description', description) 30 args = {'name':id, 'description':description} 31 s.setServiceClass(args) 32 if userCreated: s.setUserCreateFlag() 33 if REQUEST is not None: 34 REQUEST['RESPONSE'].redirect(context.absolute_url() 35 +'/manage_main') 36 return s
37
38 -class WinService(Service):
39 """Windows Service Class 40 """ 41 portal_type = meta_type = 'WinService' 42 43 acceptPause = False 44 acceptStop = False 45 pathName = "" 46 serviceType = "" 47 startMode = "" 48 startName = "" 49 collectors = ('zenwin',) 50 51 _properties = Service._properties + ( 52 {'id': 'acceptPause', 'type':'boolean', 'mode':'w'}, 53 {'id': 'acceptStop', 'type':'boolean', 'mode':'w'}, 54 {'id': 'pathName', 'type':'string', 'mode':'w'}, 55 {'id': 'serviceType', 'type':'string', 'mode':'w'}, 56 {'id': 'startMode', 'type':'string', 'mode':'w'}, 57 {'id': 'startName', 'type':'string', 'mode':'w'}, 58 ) 59 60 _relations = Service._relations + ( 61 ("os", ToOne(ToManyCont, "Products.ZenModel.OperatingSystem", "winservices")), 62 ) 63 64 factory_type_information = ( 65 { 66 'immediate_view' : 'winServiceDetail', 67 'actions' : 68 ( 69 { 'id' : 'status' 70 , 'name' : 'Status' 71 , 'action' : 'winServiceDetail' 72 , 'permissions' : ( 73 Permissions.view, ) 74 }, 75 { 'id' : 'manage' 76 , 'name' : 'Administration' 77 , 'action' : 'winServiceManage' 78 , 'permissions' : ("Manage DMD",) 79 }, 80 { 'id' : 'viewHistory' 81 , 'name' : 'Modifications' 82 , 'action' : 'viewHistory' 83 , 'permissions' : ( 84 Permissions.view, ) 85 }, 86 ) 87 }, 88 ) 89 90 security = ClassSecurityInfo() 91 92
93 - def getInstDescription(self):
94 """Return some text that describes this component. Default is name. 95 """ 96 return "'%s' StartMode:%s StartName:%s" % (self.caption(), 97 self.startMode, self.startName)
98 99
100 - def getServiceClass(self):
101 """Return a dict like one set by zenwinmodeler for services. 102 """ 103 return {'name': self.name, 'description': self.description }
104 105
106 - def setServiceClass(self, kwargs):
107 """Set the service class based on a dict describing the service. 108 Dict keys are be name and description. where name=ServiceName 109 and description=Caption. 110 """ 111 name = kwargs['name'] 112 description = kwargs['description'] 113 path = "/WinService/" 114 srvs = self.dmd.getDmdRoot("Services") 115 srvclass = srvs.createServiceClass(name=name, description=description, 116 path=path) 117 self.serviceclass.addRelation(srvclass)
118 119
120 - def caption(self):
121 """Return the windows caption for this service. 122 """ 123 svccl = self.serviceclass() 124 if svccl: return svccl.description 125 return ""
126 primarySortKey = caption 127 128 security.declareProtected('Manage DMD', 'manage_editService')
129 - def manage_editService(self, id=None, description=None, 130 acceptPause=None, acceptStop=None, 131 pathName=None, serviceType=None, 132 startMode=None, startName=None, 133 monitor=False, severity=5, 134 REQUEST=None):
135 """Edit a Service from a web page. 136 """ 137 renamed = False 138 if id is not None: 139 self.description = description 140 self.acceptPause = acceptPause 141 self.acceptStop = acceptStop 142 self.pathName = pathName 143 self.serviceType = serviceType 144 self.startMode = startMode 145 self.startName = startName 146 if self.id != id: 147 id = prepId(id) 148 self.setServiceClass({'name':id, 'description':description}) 149 renamed = self.rename(id) 150 tmpl = super(WinService, self).manage_editService(monitor, severity, 151 REQUEST=REQUEST) 152 if REQUEST and renamed: 153 REQUEST['message'] = "Object renamed to: %s" % self.id 154 return self.callZenScreen(REQUEST, renamed) 155 return tmpl
156 157 InitializeClass(WinService) 158