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

Source Code for Module ZenModel.zendmd

  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  import os 
 15  import atexit 
 16  import socket 
 17  try: 
 18      import readline 
 19      import rlcompleter 
 20  except ImportError: 
 21      readline = rlcompleter = None 
 22  from pprint import pprint 
 23   
 24  import Globals 
 25  import transaction 
 26  from AccessControl.SecurityManagement import newSecurityManager 
 27  from AccessControl.SecurityManagement import noSecurityManager 
 28   
 29  #from Products.ZenUtils.ZCmdBase import ZCmdBase 
 30  from Products.ZenUtils.ZenScriptBase import ZenScriptBase 
 31  from Products.ZenUtils.Utils import zenPath 
 32   
 33  if readline: 
 34      zenHome = zenPath() 
 35      historyPath = zenPath('.pyhistory') 
36 - def save_history(historyPath=historyPath):
37 import readline 38 readline.write_history_file(historyPath)
39 40 if os.path.exists(historyPath): 41 readline.read_history_file(historyPath) 42
43 -class zendmd(ZenScriptBase):
44 pass
45 46 if __name__ == '__main__': 47 zendmd = zendmd(connect=True) 48 dmd = zendmd.dmd 49 app = dmd.getPhysicalRoot() 50 zport = app.zport 51 find = dmd.Devices.findDevice 52 devices = dmd.Devices 53 sync = dmd._p_jar.sync 54 commit = transaction.commit 55 abort = transaction.abort 56 me = find(socket.getfqdn()) 57
58 - def zhelp():
59 cmds = filter(lambda x: not x.startswith("_"), globals()) 60 cmds.sort() 61 for cmd in cmds[2:]: print cmd
62 63
64 - def reindex():
65 sync() 66 dmd.Devices.reIndex() 67 dmd.Events.reIndex() 68 dmd.Manufacturers.reIndex() 69 dmd.Networks.reIndex() 70 commit()
71
72 - def login(name):
73 '''Logs in.''' 74 uf = zport.acl_users 75 user = uf.getUserById(name) 76 if not hasattr(user, 'aq_base'): 77 user = user.__of__(uf) 78 newSecurityManager(None, user)
79
80 - def logout():
81 '''Logs out.''' 82 noSecurityManager()
83
84 - def grepdir(obj, regex="", exact=""):
85 if regex: 86 import re 87 pattern = re.compile(regex) 88 for key in dir(obj): 89 if pattern.search(key): 90 print key 91 if exact: 92 for key in dir(obj): 93 if key == exact: 94 print key
95 96 print "Welcome to zenoss dmd command shell!" 97 print "use zhelp() to list commands" 98 99 if readline: 100 atexit.register(save_history) 101 del os, atexit, readline, rlcompleter, save_history, historyPath 102