def __init__(self, host='localhost', port=2379, ca_cert=None, cert_key=None, cert_cert=None, timeout=None): self._url = '{host}:{port}'.format(host=host, port=port) cert_params = [c is not None for c in (cert_cert, cert_key, ca_cert)] if all(cert_params): # all the cert parameters are set credentials = self._get_secure_creds(ca_cert, cert_key, cert_cert) self.uses_secure_channel = True self.channel = grpc.secure_channel(self._url, credentials) elif any(cert_params): # some of the cert parameters are set raise ValueError('the parameters cert_cert, cert_key and ca_cert ' 'must all be set to use a secure channel') else: self.uses_secure_channel = False self.channel = grpc.insecure_channel(self._url) self.timeout = timeout self.kvstub = etcdrpc.KVStub(self.channel) self.watcher = watch.Watcher(etcdrpc.WatchStub(self.channel), timeout=self.timeout) self.clusterstub = etcdrpc.ClusterStub(self.channel) self.leasestub = etcdrpc.LeaseStub(self.channel) self.maintenancestub = etcdrpc.MaintenanceStub(self.channel) self.transactions = Transactions()
def __init__(self, host='localhost', port=2379): self.channel = grpc.insecure_channel('{host}:{port}'.format(host=host, port=port)) self.kvstub = etcdrpc.KVStub(self.channel) self.watchstub = etcdrpc.WatchStub(self.channel) self.clusterstub = etcdrpc.ClusterStub(self.channel) self.leasestub = etcdrpc.LeaseStub(self.channel) self.transactions = Transactions()
def _init_channel(self): self.kvstub = etcdrpc.KVStub(self.retrieve_endpoint) self.watcher = watch.Watcher(etcdrpc.WatchStub(self.retrieve_endpoint), timeout=self.timeout, call_credentials=self.call_credentials, metadata=self.metadata) self.clusterstub = etcdrpc.ClusterStub(self.retrieve_endpoint) self.leasestub = etcdrpc.LeaseStub(self.retrieve_endpoint) self.maintenancestub = etcdrpc.MaintenanceStub(self.retrieve_endpoint) self.transactions = Transactions()
def __init__(self, host='localhost', port=2379, ca_cert=None, cert_key=None, cert_cert=None, timeout=None, user=None, password=None, grpc_options=None, multi_host = [], host_version = ''): if multi_host and host_version: if host_version in ('ipv6', 'v6'): host_version = 'ipv6' else: host_version = 'ipv4' hosts = [] for host_info in multi_host: hosts.append('{host}:{port}'.format(host=host_info['host'], port=host_info['port'])) hosts = ",".join(hosts) self._url = '{version}:{hosts}'.format(version=host_version, hosts=hosts) else: self._url = '{host}:{port}'.format(host=host, port=port) self.metadata = None cert_params = [c is not None for c in (cert_cert, cert_key)] if ca_cert is not None: if all(cert_params): credentials = self._get_secure_creds( ca_cert, cert_key, cert_cert ) self.uses_secure_channel = True self.channel = grpc.secure_channel(self._url, credentials, options=grpc_options) elif any(cert_params): # some of the cert parameters are set raise ValueError( 'to use a secure channel ca_cert is required by itself, ' 'or cert_cert and cert_key must both be specified.') else: credentials = self._get_secure_creds(ca_cert, None, None) self.uses_secure_channel = True self.channel = grpc.secure_channel(self._url, credentials, options=grpc_options) else: self.uses_secure_channel = False self.channel = grpc.insecure_channel(self._url, options=grpc_options) self.timeout = timeout self.call_credentials = None cred_params = [c is not None for c in (user, password)] if all(cred_params): self.auth_stub = etcdrpc.AuthStub(self.channel) auth_request = etcdrpc.AuthenticateRequest( name=user, password=password ) resp = self.auth_stub.Authenticate(auth_request, self.timeout) self.metadata = (('token', resp.token),) self.call_credentials = grpc.metadata_call_credentials( EtcdTokenCallCredentials(resp.token)) elif any(cred_params): raise Exception( 'if using authentication credentials both user and password ' 'must be specified.' ) self.kvstub = etcdrpc.KVStub(self.channel) self.watcher = watch.Watcher( etcdrpc.WatchStub(self.channel), timeout=self.timeout, call_credentials=self.call_credentials, metadata=self.metadata ) self.clusterstub = etcdrpc.ClusterStub(self.channel) self.leasestub = etcdrpc.LeaseStub(self.channel) self.maintenancestub = etcdrpc.MaintenanceStub(self.channel) self.transactions = Transactions()
def __init__(self, host='localhost', port=2379, ca_cert=None, cert_key=None, cert_cert=None, timeout=None, user=None, password=None): self._url = '{host}:{port}'.format(host=host, port=port) cert_params = [c is not None for c in (cert_cert, cert_key)] if ca_cert is not None: if all(cert_params): credentials = self._get_secure_creds(ca_cert, cert_key, cert_cert) self.uses_secure_channel = True self.channel = grpc.secure_channel(self._url, credentials) elif any(cert_params): # some of the cert parameters are set raise ValueError( 'to use a secure channel ca_cert is required by itself, ' 'or cert_cert and cert_key must both be specified.') else: credentials = self._get_secure_creds(ca_cert, None, None) self.uses_secure_channel = True self.channel = grpc.secure_channel(self._url, credentials) else: self.uses_secure_channel = False self.channel = grpc.insecure_channel(self._url) self.timeout = timeout self.call_credentials = None cred_params = [c is not None for c in (user, password)] if all(cred_params): self.auth_stub = etcdrpc.AuthStub(self.channel) auth_request = etcdrpc.AuthenticateRequest(name=user, password=password) resp = self.auth_stub.Authenticate(auth_request, self.timeout) self.call_credentials = grpc.metadata_call_credentials( EtcdTokenCallCredentials(resp.token)) elif any(cred_params): raise Exception( 'if using authentication credentials both user and password ' 'must be specified.') self.kvstub = etcdrpc.KVStub(self.channel) self.watcher = watch.Watcher( etcdrpc.WatchStub(self.channel), timeout=self.timeout, call_credentials=self.call_credentials, ) self.clusterstub = etcdrpc.ClusterStub(self.channel) self.leasestub = etcdrpc.LeaseStub(self.channel) self.maintenancestub = etcdrpc.MaintenanceStub(self.channel) self.transactions = Transactions()