mirror of
https://github.com/openvswitch/ovs
synced 2025-09-02 23:35:27 +00:00
ovn-nbctl: Don't die in lb_by_name_or_uuid()
Let the caller handle the error. Signed-off-by: Jakub Sitnicki <jkbs@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
committed by
Ben Pfaff
parent
3ec52ecee5
commit
31cd8e4ee0
@@ -569,8 +569,9 @@ ls_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct nbrec_load_balancer *
|
static char * OVS_WARN_UNUSED_RESULT
|
||||||
lb_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist)
|
lb_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist,
|
||||||
|
const struct nbrec_load_balancer **lb_p)
|
||||||
{
|
{
|
||||||
const struct nbrec_load_balancer *lb = NULL;
|
const struct nbrec_load_balancer *lb = NULL;
|
||||||
|
|
||||||
@@ -588,19 +589,22 @@ lb_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (lb) {
|
if (lb) {
|
||||||
ctl_fatal("Multiple load balancers named '%s'. "
|
return xasprintf("Multiple load balancers named '%s'. "
|
||||||
"Use a UUID.", id);
|
"Use a UUID.", id);
|
||||||
}
|
}
|
||||||
lb = iter;
|
lb = iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lb && must_exist) {
|
if (!lb && must_exist) {
|
||||||
ctl_fatal("%s: load balancer %s not found", id,
|
return xasprintf("%s: load balancer %s not found", id,
|
||||||
is_uuid ? "UUID" : "name");
|
is_uuid ? "UUID" : "name");
|
||||||
}
|
}
|
||||||
|
|
||||||
return lb;
|
if (lb_p) {
|
||||||
|
*lb_p = lb;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct nbrec_port_group *
|
static const struct nbrec_port_group *
|
||||||
@@ -2069,7 +2073,10 @@ nbctl_lb_add(struct ctl_context *ctx)
|
|||||||
|
|
||||||
const struct nbrec_load_balancer *lb = NULL;
|
const struct nbrec_load_balancer *lb = NULL;
|
||||||
if (!add_duplicate) {
|
if (!add_duplicate) {
|
||||||
lb = lb_by_name_or_uuid(ctx, lb_name, false);
|
char *error = lb_by_name_or_uuid(ctx, lb_name, false, &lb);
|
||||||
|
if (error) {
|
||||||
|
ctl_fatal("%s", error);
|
||||||
|
}
|
||||||
if (lb) {
|
if (lb) {
|
||||||
if (smap_get(&lb->vips, lb_vip_normalized)) {
|
if (smap_get(&lb->vips, lb_vip_normalized)) {
|
||||||
if (!may_exist) {
|
if (!may_exist) {
|
||||||
@@ -2118,7 +2125,10 @@ nbctl_lb_del(struct ctl_context *ctx)
|
|||||||
const struct nbrec_load_balancer *lb = NULL;
|
const struct nbrec_load_balancer *lb = NULL;
|
||||||
bool must_exist = !shash_find(&ctx->options, "--if-exists");
|
bool must_exist = !shash_find(&ctx->options, "--if-exists");
|
||||||
|
|
||||||
lb = lb_by_name_or_uuid(ctx, id, false);
|
char *error = lb_by_name_or_uuid(ctx, id, false, &lb);
|
||||||
|
if (error) {
|
||||||
|
ctl_fatal("%s", error);
|
||||||
|
}
|
||||||
if (!lb) {
|
if (!lb) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2255,7 +2265,10 @@ nbctl_lr_lb_add(struct ctl_context *ctx)
|
|||||||
const struct nbrec_load_balancer *new_lb;
|
const struct nbrec_load_balancer *new_lb;
|
||||||
|
|
||||||
lr = lr_by_name_or_uuid(ctx, ctx->argv[1], true);
|
lr = lr_by_name_or_uuid(ctx, ctx->argv[1], true);
|
||||||
new_lb = lb_by_name_or_uuid(ctx, ctx->argv[2], true);
|
char *error = lb_by_name_or_uuid(ctx, ctx->argv[2], true, &new_lb);
|
||||||
|
if (error) {
|
||||||
|
ctl_fatal("%s", error);
|
||||||
|
}
|
||||||
|
|
||||||
bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
|
bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
|
||||||
for (int i = 0; i < lr->n_load_balancer; i++) {
|
for (int i = 0; i < lr->n_load_balancer; i++) {
|
||||||
@@ -2300,7 +2313,10 @@ nbctl_lr_lb_del(struct ctl_context *ctx)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
del_lb = lb_by_name_or_uuid(ctx, ctx->argv[2], true);
|
char *error = lb_by_name_or_uuid(ctx, ctx->argv[2], true, &del_lb);
|
||||||
|
if (error) {
|
||||||
|
ctl_fatal("%s", error);
|
||||||
|
}
|
||||||
for (size_t i = 0; i < lr->n_load_balancer; i++) {
|
for (size_t i = 0; i < lr->n_load_balancer; i++) {
|
||||||
const struct nbrec_load_balancer *lb
|
const struct nbrec_load_balancer *lb
|
||||||
= lr->load_balancer[i];
|
= lr->load_balancer[i];
|
||||||
@@ -2361,7 +2377,10 @@ nbctl_ls_lb_add(struct ctl_context *ctx)
|
|||||||
if (error) {
|
if (error) {
|
||||||
ctl_fatal("%s", error);
|
ctl_fatal("%s", error);
|
||||||
}
|
}
|
||||||
new_lb = lb_by_name_or_uuid(ctx, ctx->argv[2], true);
|
error = lb_by_name_or_uuid(ctx, ctx->argv[2], true, &new_lb);
|
||||||
|
if (error) {
|
||||||
|
ctl_fatal("%s", error);
|
||||||
|
}
|
||||||
|
|
||||||
bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
|
bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
|
||||||
for (int i = 0; i < ls->n_load_balancer; i++) {
|
for (int i = 0; i < ls->n_load_balancer; i++) {
|
||||||
@@ -2409,7 +2428,10 @@ nbctl_ls_lb_del(struct ctl_context *ctx)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
del_lb = lb_by_name_or_uuid(ctx, ctx->argv[2], true);
|
error = lb_by_name_or_uuid(ctx, ctx->argv[2], true, &del_lb);
|
||||||
|
if (error) {
|
||||||
|
ctl_fatal("%s", error);
|
||||||
|
}
|
||||||
for (size_t i = 0; i < ls->n_load_balancer; i++) {
|
for (size_t i = 0; i < ls->n_load_balancer; i++) {
|
||||||
const struct nbrec_load_balancer *lb
|
const struct nbrec_load_balancer *lb
|
||||||
= ls->load_balancer[i];
|
= ls->load_balancer[i];
|
||||||
|
Reference in New Issue
Block a user