コード例 #1
0
def teardown_module():
    client = servicedirectory_v1beta1.RegistrationServiceClient()
    namespace_name = client.namespace_path(PROJECT_ID, LOCATION_ID,
                                           NAMESPACE_ID)
    try:
        namespace = client.get_namespace(name=namespace_name)
        client.delete_namespace(name=namespace.name)
    except exceptions.NotFound:
        pass
コード例 #2
0
def delete_service(project_id, location_id, namespace_id, service_id):
    """Deletes a service in the given namespace."""

    client = servicedirectory_v1beta1.RegistrationServiceClient()

    service_name = client.service_path(project_id, location_id, namespace_id,
                                       service_id)

    client.delete_service(name=service_name)

    print(f'Deleted service {service_name}.')
コード例 #3
0
def delete_endpoint(project_id, location_id, namespace_id, service_id,
                    endpoint_id):
    """Deletes a endpoin in the given service."""

    client = servicedirectory_v1beta1.RegistrationServiceClient()

    endpoint_name = client.endpoint_path(project_id, location_id, namespace_id,
                                         service_id, endpoint_id)

    client.delete_endpoint(name=endpoint_name)

    print(f'Deleted endpoint {endpoint_name}.')
コード例 #4
0
def list_namespaces(project_id, location_id):
    """Lists all namespaces in the given location."""

    client = servicedirectory_v1beta1.RegistrationServiceClient()

    response = client.list_namespaces(
        parent=f'projects/{project_id}/locations/{location_id}')

    print(f'Listed namespaces in {location_id}.')
    for namespace in response:
        print(f'Namespace: {namespace.name}')

    return response
コード例 #5
0
def resolve_service(project_id, location_id, namespace_id, service_id):
    """Resolves a service in the given namespace."""

    client = servicedirectory_v1beta1.LookupServiceClient()

    request = servicedirectory_v1beta1.ResolveServiceRequest(
        name=servicedirectory_v1beta1.RegistrationServiceClient().service_path(
            project_id, location_id, namespace_id, service_id))

    response = client.resolve_service(request=request)

    print('Endpoints found:')
    for endpoint in response.service.endpoints:
        print(f'{endpoint.name} -- {endpoint.address}:{endpoint.port}')

    return response
コード例 #6
0
def create_service(project_id, location_id, namespace_id, service_id):
    """Creates a service in the given namespace."""

    client = servicedirectory_v1beta1.RegistrationServiceClient()

    service = servicedirectory_v1beta1.Service(name=client.service_path(
        project_id, location_id, namespace_id, service_id))

    response = client.create_service(
        parent=client.namespace_path(project_id, location_id, namespace_id),
        service=service,
        service_id=service_id,
    )

    print(f'Created service {response.name}.')

    return response
コード例 #7
0
def create_namespace(project_id, location_id, namespace_id):
    """Creates a namespace in the given location."""

    client = servicedirectory_v1beta1.RegistrationServiceClient()

    namespace = servicedirectory_v1beta1.Namespace(
        name=client.namespace_path(project_id, location_id, namespace_id))

    response = client.create_namespace(
        parent=f'projects/{project_id}/locations/{location_id}',
        namespace=namespace,
        namespace_id=namespace_id,
    )

    print(f'Created namespace {response.name}.')

    return response
コード例 #8
0
def create_endpoint(project_id, location_id, namespace_id, service_id,
                    endpoint_id, address, port):
    """Creates a endpoint in the given service."""

    client = servicedirectory_v1beta1.RegistrationServiceClient()

    endpoint = servicedirectory_v1beta1.Endpoint(name=client.endpoint_path(
        project_id, location_id, namespace_id, service_id, endpoint_id),
                                                 address=address,
                                                 port=port)

    response = client.create_endpoint(
        parent=client.service_path(project_id, location_id, namespace_id,
                                   service_id),
        endpoint=endpoint,
        endpoint_id=endpoint_id,
    )

    print(f'Created endpoint {response.name}.')

    return response
コード例 #9
0
def client():
    return servicedirectory_v1beta1.RegistrationServiceClient()