diff --git a/src/confd/src/infix-containers.c b/src/confd/src/infix-containers.c index 7355fe1f..c9bc43e9 100644 --- a/src/confd/src/infix-containers.c +++ b/src/confd/src/infix-containers.c @@ -240,6 +240,44 @@ err_abandon: return err; } +static int action(sr_session_ctx_t *session, uint32_t sub_id, const char *xpath, + const sr_val_t *input, const size_t input_cnt, + sr_event_t event, unsigned request_id, + sr_val_t **output, size_t *output_cnt, + void *priv) +{ + char buf[strlen(xpath) + 1]; + char *cmd, *name, *ptr; + char quote; + + /* /infix-containers:container/container[name='ntpd']/restart */ + strlcpy(buf, xpath, sizeof(buf)); + + name = strstr(buf, "[name="); + if (!name) + return SR_ERR_INTERNAL; + + ptr = &name[6]; + quote = ptr[0]; /* Quote char to look for: ' or " */ + name = &ptr[1]; + + ptr = strchr(name, quote); + if (!ptr) + return SR_ERR_INTERNAL; + *ptr++ = 0; + + cmd = strstr(ptr, "]/"); + if (!cmd) + return SR_ERR_INTERNAL; + cmd += 2; + + ERROR("CALLING 'container %s %s' (xpath %s)", cmd, name, xpath); + if (systemf("container %s %s", cmd, name)) + return SR_ERR_INTERNAL; + + return SR_ERR_OK; +} + void infix_containers_launch(void) { struct dirent *d; @@ -280,6 +318,10 @@ int infix_containers_init(struct confd *confd) goto fail; REGISTER_CHANGE(confd->session, MODULE, CFG_XPATH, 0, change, confd, &confd->sub); + REGISTER_RPC(confd->session, CFG_XPATH "/container/start", action, NULL, &confd->sub); + REGISTER_RPC(confd->session, CFG_XPATH "/container/stop", action, NULL, &confd->sub); + REGISTER_RPC(confd->session, CFG_XPATH "/container/restart", action, NULL, &confd->sub); + return SR_ERR_OK; fail: ERROR("init failed: %s", sr_strerror(rc)); diff --git a/src/confd/yang/infix-containers@2023-12-14.yang b/src/confd/yang/infix-containers@2023-12-14.yang index c7cc650d..cc595901 100644 --- a/src/confd/yang/infix-containers@2023-12-14.yang +++ b/src/confd/yang/infix-containers@2023-12-14.yang @@ -248,38 +248,15 @@ module infix-containers { type yang:date-and-time; } } - } - } - rpc container-pull { - description "Upgrade (fetch) a container image"; - - input { - leaf image { - description "Name of the container image to upgrade."; - type string; + action start { + description "Start a stopped container."; } - } - } - - rpc container-stop { - description "Stop a container"; - - input { - leaf name { - description "Name of the container to stop"; - type string; + action stop { + description "Stop a running container."; } - } - } - - rpc container-start { - description "Start a container"; - - input { - leaf name { - description "Name of the container to start"; - type string; + action restart { + description "Restart a running, or start, a stopped container."; } } }