def teardown_module():
    client = servicedirectory_v1.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
Exemple #2
0
def delete_service(project_id, location_id, namespace_id, service_id):
    """Deletes a service in the given namespace."""

    client = servicedirectory_v1.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}.')
Exemple #3
0
def delete_namespace(project_id, location_id, namespace_id):
    """Deletes a namespace in the given location."""

    client = servicedirectory_v1.RegistrationServiceClient()

    namespace_name = client.namespace_path(project_id, location_id,
                                           namespace_id)

    client.delete_namespace(name=namespace_name)

    print(f'Deleted namespace {namespace_name}.')
Exemple #4
0
def delete_endpoint(project_id, location_id, namespace_id, service_id,
                    endpoint_id):
    """Deletes a endpoin in the given service."""

    client = servicedirectory_v1.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}.')
Exemple #5
0
def list_namespaces(project_id, location_id):
    """Lists all namespaces in the given location."""

    client = servicedirectory_v1.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
def teardown_module():
    client = servicedirectory_v1.RegistrationServiceClient()
    namespace_name = client.namespace_path(PROJECT_ID, LOCATION_ID,
                                           NAMESPACE_ID)
    all_namespaces = quickstart.list_namespaces(PROJECT_ID,
                                                LOCATION_ID).namespaces

    # Delete namespace only if it exists
    for namespace in all_namespaces:
        if namespace_name in namespace.name:
            try:
                client.delete_namespace(name=namespace_name)
            except exceptions.NotFound:
                print("Namespace already deleted")
            break
Exemple #7
0
def resolve_service(project_id, location_id, namespace_id, service_id):
    """Resolves a service in the given namespace."""

    client = servicedirectory_v1.LookupServiceClient()

    request = servicedirectory_v1.ResolveServiceRequest(
        name=servicedirectory_v1.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
Exemple #8
0
def create_service(project_id, location_id, namespace_id, service_id):
    """Creates a service in the given namespace."""

    client = servicedirectory_v1.RegistrationServiceClient()

    service = servicedirectory_v1.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
Exemple #9
0
def create_namespace(project_id, location_id, namespace_id):
    """Creates a namespace in the given location."""

    client = servicedirectory_v1.RegistrationServiceClient()

    namespace = servicedirectory_v1.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
Exemple #10
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_v1.RegistrationServiceClient()

    endpoint = servicedirectory_v1.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
Exemple #11
0
def client():
    return servicedirectory_v1.RegistrationServiceClient()