Package flumotion :: Package admin :: Package command :: Module manager
[hide private]

Source Code for Module flumotion.admin.command.manager

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  """ 
 23  manager commands 
 24  """ 
 25   
 26  import os 
 27   
 28  from twisted.spread import flavors 
 29  from twisted.python import failure 
 30   
 31  from flumotion.common import errors, log 
 32  from flumotion.monitor.nagios import util 
 33   
 34  from flumotion.admin.command import common 
 35   
 36  __version__ = "$Rev: 6562 $" 
 37   
 38   
39 -class Invoke(common.AdminCommand):
40 usage = "[method-name] [arguments]" 41 summary = "invoke a method on a manager" 42 description = """Invoke a method on a manager. 43 %s 44 For a list of methods that can be invoked, see the admin's avatar class 45 in flumotion.manager.admin and its perspective_* methods. 46 47 Note that not all of them can be invoked if you have no way of passing the 48 needed arguments (for example, componentStart needs a componentState) 49 50 Examples: getConfiguration, getVersions 51 """ % common.ARGUMENTS_DESCRIPTION 52
53 - def doCallback(self, args):
54 try: 55 methodName = args[0] 56 except IndexError: 57 common.errorRaise('Please specify a method name.') 58 59 if len(args) > 1: 60 args = common.parseTypedArgs(args[1], args[2:]) 61 if args is None: 62 common.errorRaise('Could not parse arguments.') 63 else: 64 args = [] 65 66 d = self.getRootCommand().medium.callRemote( 67 methodName, *args) 68 69 def cb(result): 70 import pprint 71 self.stdout.write("Invoking '%s' on manager returned:\n%s\n" % ( 72 methodName, pprint.pformat(result)))
73 74 def eb(failure): 75 # FIXME 76 if failure.check(errors.NoMethodError) \ 77 or failure.check(flavors.NoSuchMethod): 78 common.errorRaise("No method '%s' on manager." % methodName) 79 elif failure.check(errors.RemoteRunError): 80 common.errorRaise(log.getFailureMessage(failure)) 81 else: 82 common.errorRaise(log.getFailureMessage(failure))
83 84 d.addCallback(cb) 85 d.addErrback(eb) 86 87 return d 88 89
90 -class Load(common.AdminCommand):
91 usage = "[configuration-file]" 92 summary = "load a configuration onto the manager." 93
94 - def doCallback(self, args):
95 try: 96 filePath = args[0] 97 except IndexError: 98 common.errorRaise('Please specify a configuration file') 99 100 if not os.path.exists(filePath): 101 common.errorRaise("'%s' does not exist." % filePath) 102 103 d = self.getRootCommand().medium.callRemote('loadConfiguration', 104 open(filePath).read()) 105 106 def eb(failure): 107 common.errorRaise(log.getFailureMessage(failure))
108 109 d.addErrback(eb) 110 111 return d
112 113
114 -class Manager(util.LogCommand):
115 description = "Act on manager." 116 117 subCommandClasses = [Invoke, Load]
118