def conn(c=None, one=False, invoke=False): if globing.invoke or invoke: from invoke import Context c = Context(Config()) c.host = 'local' return c """ 确保传入的是connect,不是local的context """ if not hasattr(c, 'host'): c = hosts.one() if one else hosts.conn(0) print("connection [{}]".format(c.host)) return c
def connect(self, ctx: Context, remote_name: str) -> Connection: self._remote = self._api_client.remote.list( project_id=self._project.id, name=remote_name)[0] self._variables = self._remote.variables self._temporary_user = self._api_client.user.create_temporary( project_id=self._project.id, remote_id=self._remote.id) ctx.host = os.getenv('PROXY_HOST') ctx.port = int(os.getenv('PROXY_PORT')) ctx.user = self._temporary_user.username ctx.connect_kwargs.password = self._temporary_user.password ctx = Connection( host=ctx.host, user=ctx.user, port=ctx.port, connect_kwargs=ctx.connect_kwargs, ) ctx.config['run']['echo'] = True return ctx