Trees | Indices | Help |
---|
|
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 common functionality for flumotion-admin-command 20 """ 21 22 import sys 23 24 # we need to have the unjelliers registered 25 # FIXME: why is this not in flumotion.admin.admin ? 26 from flumotion.common import componentui, common, errors 27 from flumotion.admin import admin 28 29 # FIXME: move 30 from flumotion.monitor.nagios import util 31 32 __version__ = "$Rev: 6562 $" 33 34 # explain the complicated arguments system for the invoke methods 35 ARGUMENTS_DESCRIPTION = """ 36 Arguments to the method are passed using an argument list string, and the 37 arguments (matching the argument list string). 38 39 Example: "method ss one two" would invoke remote_method("one", "two") 40 """ 41 42 # code copied over from old flumotion-command 43 44 47 48 # FIXME: don't print darn it 49 5052 53 def _readFile(filename): 54 try: 55 f = open(filename) 56 contents = f.read() 57 f.close() 58 return contents 59 except OSError: 60 raise ParseException("Failed to read file %s" % (filename, ))61 62 def _doParseTypedArgs(spec, args): 63 accum = [] 64 while spec: 65 argtype = spec.pop(0) 66 parsers = {'i': int, 's': str, 'b': common.strToBool, 67 'F': _readFile, 'N': (lambda _: None)} 68 if argtype == ')': 69 return tuple(accum) 70 elif argtype == '(': 71 accum.append(_doParseTypedArgs(spec, args)) 72 elif argtype == '}': 73 return dict(accum) 74 elif argtype == '{': 75 accum.append(_doParseTypedArgs(spec, args)) 76 elif argtype == ']': 77 return accum 78 elif argtype == '[': 79 accum.append(_doParseTypedArgs(spec, args)) 80 elif argtype not in parsers: 81 raise ParseException('Unknown argument type: %r' 82 % argtype) 83 else: 84 parser = parsers[argtype] 85 try: 86 arg = args.pop(0) 87 except IndexError: 88 raise ParseException('Missing argument of type %r' 89 % parser) 90 try: 91 accum.append(parser(arg)) 92 except Exception, e: 93 raise ParseException('Failed to parse %s as %r: %s' 94 % (arg, parser, e)) 95 96 spec = list(spec) + [')'] 97 args = list(args) 98 99 try: 100 res = _doParseTypedArgs(spec, args) 101 except ParseException, e: 102 print e.args[0] 103 return None 104 105 if args: 106 print 'Left over arguments:', args 107 return None 108 else: 109 return res 110 111 # helper subclass for leaf commands 112 113115182 183117 # call our callback after connecting 118 self.getRootCommand().loginDeferred.addCallback(self._callback, args)119 123125 """ 126 Subclasses should implement this as an alternative to the normal do 127 method. It will be called after a connection to the manager is made. 128 129 Don't forget to return a deferred you create to properly chain 130 execution. 131 """ 132 raise NotImplementedError( 133 "subclass %r should implement doCallback" % self.__class__)134136 """ 137 Connect to a manager. 138 139 @type connection: L{flumotion.common.connection.PBConnectionInfo} 140 141 @rtype: L{defer.Deferred} firing L{flumotion.admin.admin.AdminModel} 142 """ 143 from flumotion.twisted import pb as fpb 144 if not connection.authenticator: 145 connection.authenticator = fpb.Authenticator( 146 username=connection.username, 147 password=connection.password, 148 address=connection.host) 149 # platform-3/trunk compatibility stuff to guard against 150 # gratuitous changes 151 try: 152 # platform-3 153 adminMedium = admin.AdminModel(connection.authenticator) 154 self.debug("code is platform-3") 155 except TypeError: 156 # trunk 157 adminMedium = admin.AdminModel() 158 self.debug("code is trunk") 159 160 if hasattr(adminMedium, 'connectToHost'): 161 # platform-3 162 d = adminMedium.connectToHost(connection.host, 163 connection.port, not connection.use_ssl) 164 else: 165 d = adminMedium.connectToManager(connection) 166 167 d.addCallback(self._connectToManagerCb, adminMedium) 168 d.addErrback(self._connectToManagerEb) 169 170 return d171 175177 if failure.check(errors.ConnectionFailedError): 178 self.stderr.write("Unable to connect to manager.\n") 179 if failure.check(errors.ConnectionRefusedError): 180 self.stderr.write("Manager refused connection.\n") 181 return failure185 """ 186 Raised when the code wants the program to exit with a return value and 187 a message. 188 """ 189194 195197 raise Exited(1, "ERROR: " + msg)198 199 203
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Tue Aug 13 06:17:23 2013 | http://epydoc.sourceforge.net |