示例#1
0
    def initialize(self, endpoint):
        """ Initialize based on endpoint
        Args:
            endpoint (message): endpoint message
        """
        if endpoint is None:
            raise ERROR_GRPC_CONFIGURATION
        endpoint_str_temp = endpoint.endpoint
        endpoint_str = endpoint_str_temp.replace('"', '')
        e = parse_endpoint(endpoint_str)
        protocol = e['scheme']
        if protocol == 'grpc':
            self.client = pygrpc.client(endpoint="%s:%s" %
                                        (e['hostname'], e['port']),
                                        version='plugin')
        elif protocol == 'http':
            # TODO:
            pass

        if self.client is None:
            _LOGGER.error(
                f'[initialize] Cannot access gRPC server. '
                f'(host: {e.get("hostname")}, port: {e.get("port")}, version: plugin)'
            )
            raise ERROR_GRPC_CONFIGURATION
    def _init_client(self):
        for version, uri in self.config['endpoint'].items():
            e = parse_endpoint(uri)

            self.client = pygrpc.client(
                endpoint=f'{e.get("hostname")}:{e.get("port")}',
                version=version)
示例#3
0
 def initialize(self, endpoint):
     static_endpoint = self.config.get('endpoint')
     if static_endpoint:
         endpoint = static_endpoint.get('v1')
     e = parse_endpoint(endpoint)
     self.client = pygrpc.client(
         endpoint=f'{e.get("hostname")}:{e.get("port")}', version='plugin')
 def _init_client(self):
     for k, v in self.config['endpoint'].items():
         # parse endpoint
         e = parse_endpoint(v)
         self.protocol = e['scheme']
         if self.protocol == 'grpc':
             # create grpc client
             self.client = pygrpc.client(endpoint="%s:%s" % (e['hostname'], e['port']), version=k)
         elif self.protocol == 'http':
             # TODO:
             pass
示例#5
0
    def test_parse_endpoint(self):
        url = 'file:///home/hojinshim/test.yaml'
        url_parsed = utils.parse_endpoint(url)
        print(url_parsed)
        self.assertEqual('file', url_parsed.get('scheme'))

        url = 'http://pyengine.net/hojinshim/test.yaml'
        url_parsed = utils.parse_endpoint(url)
        print(url_parsed)
        self.assertEqual('http', url_parsed.get('scheme'))

        url = 'https://pyengine.net/hojinshim/test.yaml'
        url_parsed = utils.parse_endpoint(url)
        print(url_parsed)
        self.assertEqual('https', url_parsed.get('scheme'))

        url = 'grpc://pyengine.net/hojinshim/test.yaml'
        url_parsed = utils.parse_endpoint(url)
        print(url_parsed)
        self.assertEqual('grpc', url_parsed.get('scheme'))
示例#6
0
    def __init__(self, transaction, config):
        super().__init__(transaction, config)

        if 'endpoint' not in self.config:
            raise ERROR_WRONG_CONFIGURATION(key='endpoint')

        if len(self.config['endpoint']) > 1:
            raise ERROR_WRONG_CONFIGURATION(key='too many endpoint')

        for (k, v) in self.config['endpoint'].items():
            e = parse_endpoint(v)
            self.client = pygrpc.client(endpoint=f'{e.get("hostname")}:{e.get("port")}', version=k)
示例#7
0
def set_remote_conf_from_file(config_yml):
    file_conf = utils.load_yaml_from_file(config_yml)
    url_conf: list = file_conf.get('REMOTE_URL', [])

    for url in url_conf:
        endpoint_info = utils.parse_endpoint(url)
        if endpoint_info['scheme'] == 'file':
            yaml_file = f'{endpoint_info["path"]}'
            conf_to_merge = utils.load_yaml_from_file(yaml_file)
            set_global(**conf_to_merge)
        elif endpoint_info['scheme'] in ['http', 'https']:
            conf_to_merge = utils.load_yaml_from_url(url)
            set_global(**conf_to_merge)
示例#8
0
    def _init_client(self, service, resource):
        if service not in self.client:
            if service not in self.config:
                raise ERROR_INVALID_RESOURCE_TYPE(
                    resource_type=f'{service}.{resource}')

            e = parse_endpoint(self.config[service])
            if e.get('path') is None:
                raise ERROR_CONNECTOR_CONFIGURATION(
                    backend=self.__class__.__name__)

            self.client[service] = pygrpc.client(
                endpoint=f'{e.get("hostname")}:{e.get("port")}')
示例#9
0
def import_remote_conf(uri):
    endpoint = utils.parse_endpoint(uri)
    scheme = endpoint.get('scheme')
    if scheme == 'file':
        remote_conf = utils.load_yaml_from_file(endpoint['path'])

    elif scheme in ['http', 'https']:
        remote_conf = utils.load_yaml_from_url(uri)

    elif scheme == 'consul':
        remote_conf = load_consul_config(endpoint)

    if isinstance(remote_conf, dict):
        set_global(**remote_conf)
示例#10
0
    def _init_client(self):
        self.client = {}
        for service, endpoint in self.config.items():
            e = parse_endpoint(endpoint)
            # _LOGGER.debug(f'[_init_client] Load endpoint : {endpoint}')
            if e.get('path') is None:
                raise ERROR_CONNECTOR_CONFIGURATION(
                    backend=self.__class__.__name__)

            version = e.get('path').replace('/', '')

            self.client[service] = pygrpc.client(
                endpoint=f'{e.get("hostname")}:{e.get("port")}',
                version=version)
示例#11
0
    def initialize(self, endpoint):
        _LOGGER.info(f'[initialize] endpoint: {endpoint}')

        endpoint = endpoint.replace('"', '')
        e = parse_endpoint(endpoint)
        protocol = e['scheme']
        if protocol == 'grpc':
            self.client = pygrpc.client(endpoint="%s:%s" %
                                        (e['hostname'], e['port']),
                                        version='plugin')
        elif protocol == 'http':
            # TODO:
            pass

        if self.client is None:
            raise ERROR_GRPC_CONFIGURATION
示例#12
0
def _get_client(service, api_version):
    endpoint = get_endpoint(service)

    if endpoint is None:
        raise Exception(f'Endpoint is not set. (service={service})')

    try:
        e = parse_endpoint(endpoint)
        client = pygrpc.client(endpoint=f'{e.get("hostname")}:{e.get("port")}',
                               version=api_version,
                               max_message_length=1024 * 1024 * 256)
        client.service = service
        client.api_version = api_version
        return client
    except Exception:
        raise ValueError(f'Endpoint is invalid. (endpoint={endpoint})')
示例#13
0
def _get_resources_from_client(endpoints, api_version='v1'):
    resources = {}
    for service, endpoint in endpoints.items():
        try:
            e = parse_endpoint(endpoint)
            client = pygrpc.client(
                endpoint=f'{e.get("hostname")}:{e.get("port")}',
                version=api_version)

            resources[service] = {}
            for api_resource, verb in client.api_resources.items():
                resources[service][api_resource] = {'alias': [], 'verb': verb}

        except Exception:
            raise ValueError(f'Endpoint is invalid. (endpoint={endpoint})')

    return resources
示例#14
0
    def __init__(self, transaction, config):
        super().__init__(transaction, config)
        _LOGGER.debug("config: %s" % self.config)
        if 'endpoint' not in self.config:
            raise ERROR_WRONG_CONFIGURATION(key='endpoint')

        if len(self.config['endpoint']) > 1:
            raise ERROR_WRONG_CONFIGURATION(key='too many endpoint')

        for (k, v) in self.config['endpoint'].items():
            # parse endpoint
            e = parse_endpoint(v)
            self.protocol = e['scheme']
            if self.protocol == 'grpc':
                # create grpc client
                self.client = pygrpc.client(endpoint="%s:%s" %
                                            (e['hostname'], e['port']),
                                            version=k)
            elif self.protocol == 'http':
                # TODO:
                pass
示例#15
0
 def initialize(self, endpoint):
     e = parse_endpoint(endpoint)
     self.client = pygrpc.client(
         endpoint=f'{e.get("hostname")}:{e.get("port")}', version='plugin')
示例#16
0
    def initialize(self, endpoint):
        _LOGGER.info(f'[initialize] endpoint: {endpoint}')

        e = parse_endpoint(endpoint)
        self.client = pygrpc.client(endpoint=f'{e.get("hostname")}:{e.get("port")}', version='plugin')