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