Esempio n. 1
0
        p = urlparse('http://' + self.addr)
        channel = grpc.insecure_channel('%s:%s' % (p.hostname, p.port))
        if self.auth_static_client_creds is not None:
            channel = grpc_with_metadata.GRPCWithMetadataChannel(
                channel, self.get_auth_static_client_creds)
        self.stub = vtctlservice_pb2.VtctlStub(channel)

    def close(self):
        self.stub = None

    def is_closed(self):
        return self.stub is None

    def get_auth_static_client_creds(self):
        return static_auth_client.StaticAuthClientCreds(
            self.auth_static_client_creds).metadata()

    def execute_vtctl_command(self, args, action_timeout=30.0):
        req = vtctldata_pb2.ExecuteVtctlCommandRequest(
            args=args, action_timeout=long(action_timeout * 1e9))
        it = self.stub.ExecuteVtctlCommand(req, action_timeout)
        for response in it:
            t = datetime.datetime.utcfromtimestamp(response.event.time.seconds)
            yield vtctl_client.Event(t, response.event.level,
                                     response.event.file, response.event.line,
                                     response.event.value)


vtctl_client.register_conn_class('grpc', GRPCVtctlClient)
Esempio n. 2
0
            action_timeout: total timeout for the action (float, in seconds).
            lock_timeout: timeout for locking topology (float, in seconds).
            info_to_debug: if set, changes the info messages to debug.

        Returns:
            The console output of the action.
        """
        req = vtctl_pb2.ExecuteVtctlCommandArgs(
            args=args,
            action_timeout=long(action_timeout * 1000000000),
            lock_timeout=long(lock_timeout * 1000000000))
        console_result = ''
        with self.stub as stub:
            for e in stub.ExecuteVtctlCommand(req, action_timeout):
                if e.level == 0:
                    if info_to_debug:
                        logging.debug('%s', e.value)
                    else:
                        logging.info('%s', e.value)
                elif e.level == 1:
                    logging.warning('%s', e.value)
                elif e.level == 2:
                    logging.error('%s', e.value)
                elif e.level == 3:
                    console_result += e.value

        return console_result


vtctl_client.register_conn_class("grpc", GRPCVtctlClient)
Esempio n. 3
0
  def __str__(self):
    return '<GRPCVtctlClient %s>' % self.addr

  def dial(self):
    if self.stub:
      self.stub.close()

    p = urlparse('http://' + self.addr)
    channel = implementations.insecure_channel(p.hostname, p.port)
    self.stub = vtctlservice_pb2.beta_create_Vtctl_stub(channel)

  def close(self):
    self.stub = None

  def is_closed(self):
    return self.stub is None

  def execute_vtctl_command(self, args, action_timeout=30.0):
    req = vtctldata_pb2.ExecuteVtctlCommandRequest(
        args=args,
        action_timeout=long(action_timeout * 1e9))
    it = self.stub.ExecuteVtctlCommand(req, action_timeout)
    for response in it:
      t = datetime.datetime.utcfromtimestamp(response.event.time.seconds)
      yield vtctl_client.Event(t, response.event.level, response.event.file,
                               response.event.line, response.event.value)


vtctl_client.register_conn_class('grpc', GRPCVtctlClient)
Esempio n. 4
0
            args: Command line to run.
            action_timeout: total timeout for the action (float, in seconds).
            lock_timeout: timeout for locking topology (float, in seconds).
            info_to_debug: if set, changes the info messages to debug.

        Returns:
            The console output of the action.
        """
        req = vtctl_pb2.ExecuteVtctlCommandRequest(
            args=args,
            action_timeout=long(action_timeout * 1000000000),
            lock_timeout=long(lock_timeout * 1000000000))
        console_result = ''
        with self.stub as stub:
            for response in stub.ExecuteVtctlCommand(req, action_timeout):
                if response.event.level == 0:
                    if info_to_debug:
                        logging.debug('%s', response.event.value)
                    else:
                        logging.info('%s', response.event.value)
                elif response.event.level == 1:
                    logging.warning('%s', response.event.value)
                elif response.event.level == 2:
                    logging.error('%s', response.event.value)
                elif response.event.level == 3:
                    console_result += response.event.value

        return console_result

vtctl_client.register_conn_class("grpc", GRPCVtctlClient)