ni.measurementlink.discovery.v1.client

Public API for accessing the NI Discovery Service.

Classes

DiscoveryClient

Client for accessing the NI Discovery Service.

ComputeNodeDescriptor

Represents a compute node.

ServiceInfo

A named tuple providing information about a registered service.

ServiceLocation

Represents the location of a service.

Package Contents

class ni.measurementlink.discovery.v1.client.DiscoveryClient(stub=None, *, grpc_channel_pool=None)[source]

Client for accessing the NI Discovery Service.

Initialize the discovery client.

Parameters:
__slots__ = ['_initialization_lock', '_grpc_channel_pool', '_stub', '__weakref__']
register_service(service_info, service_location)[source]

Register the specified service with the discovery service.

Parameters:
  • service_info (ni.measurementlink.discovery.v1.client._types.ServiceInfo) – Information describing the service.

  • service_location (ni.measurementlink.discovery.v1.client._types.ServiceLocation) – The location of the service on the network.

Returns:

ID that can be used to unregister the service.

Return type:

str

unregister_service(registration_id)[source]

Unregisters the specified service from the discovery service.

This method should be called before the service exits.

Parameters:

registration_id (str) – The registration ID returned from register_service. This argument should be omitted after calling the deprecated register_measurement_service method.

Returns:

Boolean indicating whether the service was unregistered.

Return type:

bool

resolve_service(provided_interface, service_class='', deployment_target='', version='')[source]

Resolve the location of a service.

Given a description of a service, returns information that can be used to establish communication with that service. If necessary, the service will be started by the discovery service if it has not already been started.

Parameters:
  • provided_interface (str) – The gRPC full name of the service.

  • service_class (str) – The service “class” that should be matched. If the value is not specified and there is more than one matching service registered, an error is returned.

  • deployment_target (str) – The deployment target from which the service should be resolved. Callers should pass either the url string from a ComputeNodeSpecifier or a blank string for local execution.

  • version (str) – The version of the service to resolve. If not specified, the latest version will be resolved.

Returns:

The service location.

Return type:

ni.measurementlink.discovery.v1.client._types.ServiceLocation

resolve_service_with_information(provided_interface, service_class='', deployment_target='', version='')[source]

Resolve the location of a service along with its information.

Given a description of a service, returns information for the service in addition to the location of the service. If necessary, the service will be started by the discovery service if it has not already been started.

Parameters:
  • provided_interface (str) – The gRPC full name of the service.

  • service_class (str) – The service “class” that should be matched. If the value is not specified and there is more than one matching service registered, an error is returned.

  • deployment_target (str) – The deployment target from which the service should be resolved. Callers should pass either the url string from a ComputeNodeSpecifier or a blank string for local execution.

  • version (str) – The version of the service to resolve. If not specified, the latest version will be resolved.

Returns:

A tuple containing the service location and service information.

Return type:

tuple[ni.measurementlink.discovery.v1.client._types.ServiceLocation, ni.measurementlink.discovery.v1.client._types.ServiceInfo]

enumerate_services(provided_interface)[source]

Enumerates all the services for the provided interface.

Parameters:

provided_interface (str) – The gRPC full name of the services.

Returns:

The list of information describing the services.

Return type:

collections.abc.Sequence[ni.measurementlink.discovery.v1.client._types.ServiceInfo]

enumerate_compute_nodes()[source]

Enumerates all the compute nodes registered with the discovery service.

Returns:

The list of information describing the compute nodes.

Return type:

collections.abc.Sequence[ni.measurementlink.discovery.v1.client._types.ComputeNodeDescriptor]

class ni.measurementlink.discovery.v1.client.ComputeNodeDescriptor[source]

Bases: NamedTuple

Represents a compute node.

url: str

The resolvable name (URL) of the compute node.

is_local: bool

Indicates whether the compute node is local node.

class ni.measurementlink.discovery.v1.client.ServiceInfo[source]

Bases: NamedTuple

A named tuple providing information about a registered service.

This class is used with the NI Discovery Service when registering and enumerating services.

service_class: str

“The “class” of a service. The value of this field should be unique for all services. In effect, the .proto service declaration defines the interface, and this field defines a class or concrete type of the interface.

description_url: str

The URL of a web page that provides a description of the service.

provided_interfaces: list[str] = ['ni.measurementlink.measurement.v1.MeasurementService']

The service interfaces provided by the service. These are gRPC full names for the service.

annotations: dict[str, str]

Represents a set of annotations on the service.

Well-known annotations:

  • Description
    • Key: “ni/service.description”
      • Expected format: string

      • Example: “Measure inrush current with a shorted load and validate results against configured limits.”

  • Collection
    • Key: “ni/service.collection”
      • Expected format: “.” delimited namespace/hierarchy case-insensitive string

      • Example: “CurrentTests.Inrush”

  • Tags
    • Key: “ni/service.tags”
      • Expected format: serialized JSON string of an array of strings

      • Example: “[“powerup”, “current”]”

display_name: str = ''

The service display name for clients to display to users.

versions: list[str] = []

The list of versions associated with this service in the form major.minor.build[.revision] (e.g. 1.0.0).

class ni.measurementlink.discovery.v1.client.ServiceLocation[source]

Bases: NamedTuple

Represents the location of a service.

location: str
insecure_port: str
ssl_authenticated_port: str
property insecure_address: str

port.

Type:

Get the service’s insecure address in the format host

Return type:

str

property ssl_authenticated_address: str

port.

Type:

Get the service’s SSL-authenticated address in the format host

Return type:

str