<s> """<STR_LIT>""" <EOL> import copy <EOL> from mininext . mount import MountProperties <EOL> from mininext . util import ParamContainer <EOL> class Service ( ParamContainer ) : <EOL> "<STR_LIT>" <EOL> def __init__ ( self , name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> ParamContainer . __init__ ( self , name = name , ** kwargs ) <EOL> def nodeIsSubscribed ( self , node ) : <EOL> """<STR_LIT>""" <EOL> return self . hasNodeParams ( node ) <EOL> def errIfNodeNotSubscribed ( self , node ) : <EOL> "<STR_LIT>" <EOL> if self . nodeIsSubscribed ( node ) is False : <EOL> raise Exception ( "<STR_LIT>" <EOL> % ( self . name , node ) ) <EOL> def setupNode ( self , node , nodeServiceParams , includeDefaults = True ) : <EOL> "<STR_LIT>" <EOL> if self . nodeIsSubscribed ( node ) : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( self . name , node ) ) <EOL> self . verifyNodeMeetsServiceRequirements ( node ) <EOL> self . storeNodeParams ( node , nodeServiceParams , includeDefaults ) <EOL> self . setupNodeMounts ( node ) <EOL> self . setupNodeForService ( node ) <EOL> def verifyNodeMeetsServiceRequirements ( self , node ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def setupNodeForService ( self , node ) : <EOL> "<STR_LIT>" <EOL> pass <EOL> def setupNodeMounts ( self , node ) : <EOL> "<STR_LIT>" <EOL> nodeServiceMounts = self . getMountsForNode ( node ) <EOL> for mountPoint in nodeServiceMounts : <EOL> if mountPoint . source is not None and mountPoint . source . path is not None and mountPoint . target is not None : <EOL> node . setupMountPoint ( mountPoint ) <EOL> def autoStart ( self , node ) : <EOL> "<STR_LIT>" <EOL> if self . getNodeParam ( node , '<STR_LIT>' , defaultValue = None ) is True : <EOL> return self . start ( node ) <EOL> return None <EOL> def autoStop ( self , node ) : <EOL> "<STR_LIT>" <EOL> if self . getNodeParam ( node , '<STR_LIT>' , defaultValue = None ) is True : <EOL> return self . stop ( node ) <EOL> return None <EOL> def start ( self , node ) : <EOL> "<STR_LIT>" <EOL> self . errIfNodeNotSubscribed ( node ) <EOL> startCmd = self . getNodeParam ( node , '<STR_LIT>' , defaultValue = None ) <EOL> if startCmd is None : <EOL> raise Exception ( "<STR_LIT>" <EOL> % ( self . name ) ) <EOL> _ , err , ret = node . pexec ( startCmd ) <EOL> if ret != <NUM_LIT:0> and self . getNodeParam ( <EOL> node , <EOL> '<STR_LIT>' ) is True : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( self . name , err ) ) <EOL> return { '<STR_LIT>' : err , '<STR_LIT>' : ret } <EOL> def stop ( self , node ) : <EOL> "<STR_LIT>" <EOL> self . errIfNodeNotSubscribed ( node ) <EOL> stopCmd = self . getNodeParam ( node , '<STR_LIT>' , defaultValue = None ) <EOL> if stopCmd is None : <EOL> raise Exception ( "<STR_LIT>" <EOL> % ( self . name ) ) <EOL> _ , err , ret = node . pexec ( stopCmd ) <EOL> return { '<STR_LIT>' : err , '<STR_LIT>' : ret } <EOL> def getDefaultGlobalParams ( self ) : <EOL> "<STR_LIT>" <EOL> return None <EOL> def getDefaultGlobalMounts ( self ) : <EOL> "<STR_LIT>" <EOL> mounts = [ ] <EOL> mountConfigPairs = { } <EOL> return mounts , mountConfigPairs <EOL> def getMountsForNode ( self , node ) : <EOL> "<STR_LIT>" <EOL> self . errIfNodeNotSubscribed ( node ) <EOL> if self . hasNodeParam ( node , '<STR_LIT>' ) is True : <EOL> return self . getNodeParam ( node , '<STR_LIT>' ) <EOL> nodeMounts = [ ] <EOL> _ , mountConfigPairs = self . getDefaultGlobalMounts ( ) <EOL> for mountName , mountProperties in mountConfigPairs . iteritems ( ) : <EOL> mountProperties = copy . deepcopy ( mountProperties ) <EOL> nodeMountOptions = self . getNodeParam ( node , mountName , <EOL> defaultValue = None ) <EOL> if nodeMountOptions is None : <EOL> continue <EOL> if isinstance ( nodeMountOptions , basestring ) : <EOL> mountProperties . source . path = nodeMountOptions <EOL> elif isinstance ( nodeMountOptions , MountProperties ) : <EOL> mountProperties = nodeMountOptions <EOL> else : <EOL> raise Exception ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> nodeMounts . append ( mountProperties ) <EOL> return nodeMounts <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . name ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __hash__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return hash ( self . name ) </s>
