class ProjectServer(Listener): def __init__(self, path): self.deploy_thread = None self.project = Project(path) self.subscribe('project', self.project.name, 'nodes', 'request') self.subscribe('project', self.project.name, 'node', 'update') self.subscribe('project', self.project.name, 'node', 'add') self.subscribe('project', self.project.name, 'node', 'remove') self.subscribe('project', self.project.name, 'node', 'connect') self.subscribe('project', self.project.name, 'node', 'disconnect') self.subscribe('project', self.project.name, 'deploy', 'run') self.subscribe('project', self.project.name, 'deploy', 'stop') def on_message(self, channel, data): if channel == ('project', self.project.name, 'nodes', 'request'): self.publish(('project', self.project.name, 'nodes', 'response'), self.project.to_dict()) elif channel == ('project', self.project.name, 'node', 'update'): self.project.update_node(data) elif channel == ('project', self.project.name, 'node', 'add'): self.project.add_node(data) elif channel == ('project', self.project.name, 'node', 'remove'): self.project.remove_node(data) elif channel == ('project', self.project.name, 'node', 'connect'): self.project.add_connection(data) elif channel == ('project', self.project.name, 'node', 'disconnect'): self.project.remove_connection(data) elif channel == ('project', self.project.name, 'deploy', 'run'): self.run(data) elif channel == ('project', self.project.name, 'deploy', 'stop'): self.stop() def run(self, json): self.stop() self.deploy_thread = DeployThread(json['ip'], json['user'], json['pass'], self.project) self.deploy_thread.start() def stop(self): if self.deploy_thread: self.deploy_thread.kill() self.deploy_thread = None
def run(self, json): self.stop() self.deploy_thread = DeployThread(json['ip'], json['user'], json['pass'], self.project) self.deploy_thread.start()