# confd\_lib\_ha

`confd_lib_ha` - library for connecting to NSO HA subsystem

## Synopsis

```
#include <confd_lib.h>
#include <confd_ha.h>

int confd_ha_connect(
int sock, const struct sockaddr* srv, int srv_sz, const char *token);

int confd_ha_beprimary(
int sock, confd_value_t *mynodeid);

int confd_ha_besecondary(
int sock, confd_value_t *mynodeid, struct confd_ha_node *primary, int waitreply);

int confd_ha_berelay(
int sock);

int confd_ha_benone(
int sock);

int confd_ha_get_status(
int sock, struct confd_ha_status *stat);

int confd_ha_secondary_dead(
int sock, confd_value_t *nodeid);
```

## Library

ConfD Library, (`libconfd`, `-lconfd`)

## Description

The `libconfd` shared library is used to connect to the NSO High Availability (HA) subsystem. NSO can replicate the configuration data on several nodes in a cluster. The purpose of this API is to manage the HA functionality. The details on usage of the HA API are described in the chapter High Availability in the Admin Guide.

## Functions

```
int confd_ha_connect(
int sock, const struct sockaddr* srv, int srv_sz, const char *token);
```

Connect a HA socket which can be used to control a NSO HA node. The token is a secret string that must be shared by all participants in the cluster. There can only be one HA socket towards NSO, a new call to `confd_ha_connect()` makes NSO close the previous connection and reset the token to the new value. Returns CONFD\_OK or CONFD\_ERR.

If this call fails (i.e. does not return CONFD\_OK), the socket descriptor must be closed and a new socket created before the call is re-attempted.

```
int confd_ha_beprimary(
int sock, confd_value_t *mynodeid);
```

Instruct a HA node to be primary and also give the node a name. Returns CONFD\_OK or CONFD\_ERR.

*Errors:* CONFD\_ERR\_HA\_BIND if we cannot bind the TCP socket, CONFD\_ERR\_BADSTATE if NSO is still in start phase 0.

```
int confd_ha_besecondary(
int sock, confd_value_t *mynodeid, struct confd_ha_node *primary, int waitreply);
```

Instruct a NSO HA node to be secondary to a named primary. The `waitreply` is a boolean int. If 1, the function is synchronous and it will hang until the node has initialized its CDB database. This may mean that the CDB database is copied in its entirety from the primary. If 0, we do not wait for the reply, but it is possible to use a notifications socket and get notified asynchronously via a HA\_INFO\_BESECONDARY\_RESULT notification. In both cases, it is also possible to use a notifications socket and get notified asynchronously when CDB at the secondary is initialized.

If the call of this function fails with `confd_errno` CONFD\_ERR\_HA\_CLOSED, it means that the initial synchronization with the primary failed, either due to the socket being closed or due to a timeout while waiting for a response from the primary. The function will fail with error CONFD\_ERR\_BADSTATE if NSO is still in start phase 0.

*Errors:* CONFD\_ERR\_HA\_CONNECT, CONFD\_ERR\_HA\_BADNAME, CONFD\_ERR\_HA\_BADTOKEN, CONFD\_ERR\_HA\_BADFXS, CONFD\_ERR\_HA\_BADVSN, CONFD\_ERR\_HA\_CLOSED, CONFD\_ERR\_BADSTATE, CONFD\_ERR\_HA\_BADCONFIG

```
int confd_ha_berelay(
int sock);
```

Instruct an established HA secondary node to be a relay for other secondaries. This can be useful in certain deployment scenarios, but makes the management of the cluster more complex. Returns CONFD\_OK or CONFD\_ERR.

*Errors:* CONFD\_ERR\_HA\_BIND if we cannot bind the TCP socket, CONFD\_ERR\_BADSTATE if the node is not already a secondary.

```
int confd_ha_benone(
int sock);
```

Instruct a node to resume the initial state, i.e. neither primary nor secondary.

*Errors:* CONFD\_ERR\_BADSTATE if NSO is still in start phase 0.

```
int confd_ha_get_status(
int sock, struct confd_ha_status *stat);
```

Query a NSO HA node for its status. If successful, the function populates the confd\_ha\_status structure. This is the only HA related function which is possible to call while the NSO daemon is still in start phase 0.

```
int confd_ha_secondary_dead(
int sock, confd_value_t *nodeid);
```

This function must be used by the application to inform NSO HA subsystem that another node which is possibly connected to NSO is dead.

*Errors:* CONFD\_ERR\_BADSTATE if NSO is still in start phase 0.

## See Also

`confd.conf(5)` - ConfD daemon configuration file format

The NSO User Guide


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nso-docs.cisco.com/guides/nso-6.6/resources/man/confd_lib_ha.3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
