Esempio n. 1
0
class Server(Entity):
    implements(IDroneModelServer)
    connectFailure = None
    appinstances = property( lambda self: (i for i in AppInstance.objects if \
            i.server is self) )
    apps = property(lambda self:
                    (a for a in App.objects if self in a.shouldRunOn))
    scabs = property(lambda self:
                     (s for s in Scab.objects if s.server is self))
    unreachable = property(lambda self: self.connectFailure is not None)
    #FIXME this doesn't seem right we should remove it
    installedApps = property(lambda self: set(av.app for av in self.installed))
    debug = False
    serializable = True
    listed = False
    logs = {}

    def __init__(self, hostname):
        self.hostname = hostname
        self.installed = {}
        self.droned = DroneD(self)
        self.manager = ServerManager(self)

    def __getstate__(self):
        installed = {}
        for appversion, configs in self.installed.items():
            av = (appversion.app.name, appversion.version)
            installed[av] = []
            for configpkg in configs:
                cp = (configpkg.name, configpkg.version)
                installed[av].append(cp)

        return {
            'hostname': self.hostname,
            'connectFailure': self.connectFailure,
            'debug': self.debug,
            'installed': installed,
        }

    @staticmethod
    def construct(state):
        server = Server(state['hostname'])
        if state['connectFailure'] != server.connectFailure:
            server.connectFailure = state['connectFailure']
        if state['debug'] != server.debug:
            server.debug = state['debug']
        if 'installed' in state:
            for av, configs in state['installed'].items():
                app, version = App(av[0]), av[1]
                av = AppVersion(app, version)
                server.installed[av] = set(
                    ConfigPackage(*cp) for cp in configs)
        return server

    @staticmethod
    def byName(name):
        if Server.exists(name):
            return Server(name)
        for server in Server.objects:
            if server.hostname.startswith(name):
                return server

    def startPolling(self):
        self.droned.startPolling()

    def stopPolling(self):
        self.droned.stopPolling()
Esempio n. 2
0
class Server(Entity):
    implements(IDroneModelServer)
    connectFailure = None
    appinstances = property( lambda self: (i for i in AppInstance.objects if \
            i.server is self) )
    apps = property( lambda self: (a for a in App.objects if self in a.shouldRunOn) )
    scabs = property( lambda self: (s for s in Scab.objects if s.server is self) )
    unreachable = property( lambda self: self.connectFailure is not None )
#FIXME this doesn't seem right we should remove it
    installedApps = property( lambda self: set(av.app for av in self.installed) )
    debug = False
    serializable = True
    listed = False
    logs = {}

    def __init__(self, hostname):
        self.hostname = hostname
        self.installed = {}
        self.droned = DroneD(self)
        self.manager = ServerManager(self)

    def __getstate__(self):
        installed = {}
        for appversion,configs in self.installed.items():
            av = (appversion.app.name, appversion.version)
            installed[av] = []
            for configpkg in configs:
                cp = (configpkg.name, configpkg.version)
                installed[av].append(cp)

        return {
            'hostname' : self.hostname,
            'connectFailure' : self.connectFailure,
            'debug' : self.debug,
            'installed' : installed,
        }

    @staticmethod
    def construct(state):
        server = Server( state['hostname'] )
        if state['connectFailure'] != server.connectFailure:
            server.connectFailure = state['connectFailure']
        if state['debug'] != server.debug:
            server.debug = state['debug']
        if 'installed' in state:
            for av,configs in state['installed'].items():
                app, version = App(av[0]), av[1]
                av = AppVersion(app,version)
                server.installed[av] = set( ConfigPackage(*cp) for cp in configs )
        return server

    @staticmethod
    def byName(name):
      if Server.exists(name):
          return Server(name)
      for server in Server.objects:
          if server.hostname.startswith(name):
              return server

    def startPolling(self):
        self.droned.startPolling()

    def stopPolling(self): 
        self.droned.stopPolling()