Package flumotion :: Package component :: Package plugs :: Module manhole
[hide private]

Source Code for Module flumotion.component.plugs.manhole

  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  import os 
 20  from twisted.internet import defer 
 21   
 22  from flumotion.component.plugs import base 
 23  from flumotion.common.manhole import openSSHManhole 
 24  from flumotion.common.manhole import openAnonymousTelnetManhole 
 25   
 26  __version__ = "$Rev$" 
 27   
 28   
29 -class ManholeMixin(object):
30 """ 31 """ 32
33 - def __init__(self, args):
34 35 self.useSSH = False 36 self.authorizedKeysFile = None 37 self.port = None 38 self.requestedPortNum = None 39 self.namespace = {}
40
41 - def start(self, namespace):
42 self.namespace.update(namespace) 43 props = self.args['properties'] 44 if 'ssh-authorized-keys-file' in props: 45 self.useSSH = True 46 self.authorizedKeysFile = os.path.expanduser( 47 props['ssh-authorized-keys-file']) 48 49 self.requestedPortNum = props.get('port', -1) 50 51 self._insinuate() 52 53 if props.get('initially-open', False): 54 self.openManhole()
55
56 - def stop(self, obj):
57 self.closeManhole()
58
59 - def _insinuate(self):
60 # "And I wish you didn't have the devil's curly hair!" 61 from flumotion.manager.admin import AdminAvatar 62 AdminAvatar.perspective_openManhole = self.openManhole 63 AdminAvatar.perspective_closeManhole = self.closeManhole
64
65 - def openManhole(self):
66 if not self.port: 67 if self.useSSH: 68 self.port = openSSHManhole(self.authorizedKeysFile, 69 self.namespace, 70 self.requestedPortNum) 71 else: 72 self.port = openAnonymousTelnetManhole(self.namespace, 73 self.requestedPortNum) 74 75 return self.port.getHost().port
76
77 - def closeManhole(self):
78 if self.port: 79 ret = self.port.loseConnection() 80 else: 81 ret = defer.succeed(None) 82 self.port = None 83 return ret
84 85
86 -class ManagerManholePlug(base.ManagerPlug, ManholeMixin):
87
88 - def __init__(self, args):
91
92 - def start(self, vishnu):
93 namespace = {'vishnu': vishnu} 94 ManholeMixin.start(self, namespace)
95 96
97 -class ComponentManholePlug(base.ComponentPlug, ManholeMixin):
98
99 - def __init__(self, args):
102
103 - def start(self, component):
104 namespace = {'component': component} 105 ManholeMixin.start(self, namespace)
106