From patchwork Wed Oct 16 01:52:52 2019
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: aginwala aginwala
X-Patchwork-Id: 1177493
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Authentication-Results: ozlabs.org;
spf=pass (mailfrom) smtp.mailfrom=openvswitch.org
(client-ip=140.211.169.12; helo=mail.linuxfoundation.org;
envelope-from=ovs-dev-bounces@openvswitch.org;
receiver=)
Authentication-Results: ozlabs.org;
dmarc=fail (p=none dis=none) header.from=gmail.com
Authentication-Results: ozlabs.org;
dkim=fail reason="signature verification failed" (2048-bit key;
unprotected) header.d=gmail.com header.i=@gmail.com
header.b="EATVqI2I"; dkim-atps=neutral
Received: from mail.linuxfoundation.org (mail.linuxfoundation.org
[140.211.169.12])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256
bits)) (No client certificate requested)
by ozlabs.org (Postfix) with ESMTPS id 46tFgp6qlzz9sP7
for ;
Wed, 16 Oct 2019 12:53:26 +1100 (AEDT)
Received: from mail.linux-foundation.org (localhost [127.0.0.1])
by mail.linuxfoundation.org (Postfix) with ESMTP id E0810C9A;
Wed, 16 Oct 2019 01:52:57 +0000 (UTC)
X-Original-To: dev@openvswitch.org
Delivered-To: ovs-dev@mail.linuxfoundation.org
Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org
[172.17.192.35])
by mail.linuxfoundation.org (Postfix) with ESMTPS id 9A5D6C7C
for ; Wed, 16 Oct 2019 01:52:56 +0000 (UTC)
X-Greylist: whitelisted by SQLgrey-1.7.6
Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com
[209.85.210.195])
by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 73D227D2
for ; Wed, 16 Oct 2019 01:52:55 +0000 (UTC)
Received: by mail-pf1-f195.google.com with SMTP id q10so13661195pfl.0
for ; Tue, 15 Oct 2019 18:52:55 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=from:to:cc:subject:date:message-id:mime-version
:content-transfer-encoding;
bh=BxNu0WPmhaNv4J1M6E5a2XL7G8NvWijJ/tj6uUcjnUA=;
b=EATVqI2Is56BMzFkpbZr5GCT4XZRO82MRVR115GoMVHyfeiBf59FTxaXpMGeKZPjYd
YlI6KJKQNV65dzMjEr8rT3OzTspRfG6jpxUb1/8FRaihuadAgj8DevxU3fjU/BPQB0ay
d9/2W1NAQaz4BN0nFUzzn/rKfuBekaWo2ymkMu4wtxGb0OdHV9EK9sOzToF+EGVlKtcH
l46W6oW92A4CV9mHY9MPfkq5LZa7ZG+HylAX7vB3W9qYy+99TkDpDpC55xos0/h+ffoi
FsMlUkGsO5/VBYLygMWdEp58dBYLHj+OZef8/KhQFMfNnDRTaTJoRwWJFcWEOetH/fkS
p8jA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
:content-transfer-encoding;
bh=BxNu0WPmhaNv4J1M6E5a2XL7G8NvWijJ/tj6uUcjnUA=;
b=hOZUTabJUf4B56YGg2fui1GBYVVVyiqGiNVsWbx7iPz/EaDMO6Rmt/Sy8igRCSIw69
q06zVOqMljWk4E7A2vm+rH2QDaimVgtdmaskuQl8epQCwNVlhBfsJxc+Zgfb6vSQaGuc
1wkwVmLCqWCKTV7rp0hdZ6btN4C7xCKbhtn1LkiQZTwPwsAZ+NBnBk4uaA7b2cm/OkHj
1oJZWHbHCMMXMBOhNVI9oZnRCNAUB82Ib5lXd22LsZAkqLk1NswxFHe9v72sFk+EmTXw
vOkvClIOnppPsN5BNIlP3zbZKuzWFG0o/y0OeuPJEzD9WxN5dtc3bqfDdldbhRSIx3n7
F+TA==
X-Gm-Message-State: APjAAAXloEbYHjhLCv6pPtOaVHl3u1Bf2jHXByF0J4q9q8+dXitJCKkp
pPu1uA9L3Ussgu+02JcCBhVM7aGW
X-Google-Smtp-Source:
APXvYqwtMSinaXBCMPzoUVjvhMyOqQn5Wt/MYAX9a0TEXanzJ5SdFLiXaBfM3NN2BB2ZZzDZA4USRg==
X-Received: by 2002:a17:90a:8592:: with SMTP id
m18mr1835958pjn.118.1571190774746;
Tue, 15 Oct 2019 18:52:54 -0700 (PDT)
Received: from LM-SJC-11015761.corp.ebay.com ([216.113.160.77])
by smtp.gmail.com with ESMTPSA id
13sm162218pgm.76.2019.10.15.18.52.54
(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
Tue, 15 Oct 2019 18:52:54 -0700 (PDT)
From: amginwal@gmail.com
To: dev@openvswitch.org
Date: Tue, 15 Oct 2019 18:52:52 -0700
Message-Id: <20191016015252.10441-1-amginwal@gmail.com>
X-Mailer: git-send-email 2.20.1 (Apple Git-117)
MIME-Version: 1.0
X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM,
RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
smtp1.linux-foundation.org
Cc: Aliasgar Ginwala
Subject: [ovs-dev] [PATCH v2 ovn] ovn-nb/sbctl.c: Use env variables for
passing options.
X-BeenThere: ovs-dev@openvswitch.org
X-Mailman-Version: 2.1.12
Precedence: list
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Sender: ovs-dev-bounces@openvswitch.org
Errors-To: ovs-dev-bounces@openvswitch.org
From: Aliasgar Ginwala
Add new env variables OVN_NBCTL_OPTIONS and OVN_SBCTL_OPTIONS for
ovn-nbctl and ovn-sbctl respectively where user can set
supported ovn-nb/sbctl options using environment variable.
e.g. OVN_SBCTL_OPTIONS="--db=unix:sb1.ovsdb --no-leader-only"
Signed-off-by: Aliasgar Ginwala
---
v1 -> v2
-------
* Addressed Ben's comment - Write ovs_cmdl_env_parse_all for parsing
env options in lib/command-line.c and update docs about new env var
usage.
utilities/ovn-nbctl.8.xml | 25 +++++++++++++++++++++++++
utilities/ovn-nbctl.c | 19 +++++++++++++++++--
utilities/ovn-sbctl.8.in | 8 ++++++++
utilities/ovn-sbctl.c | 19 +++++++++++++++++--
4 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml
index fd75c0e44..b207dac46 100644
--- a/utilities/ovn-nbctl.8.xml
+++ b/utilities/ovn-nbctl.8.xml
@@ -1178,6 +1178,31 @@
wait at all. Use the sync
command to override this
behavior.
+
+
+ User can set one or more OVN_NBCTL_OPTIONS options in
+ environment variable. Under the Bourne shell this might be
+ done like this:
+
+
+
+ OVN_NBCTL_OPTIONS="--db=unix:nb1.ovsdb --no-leader-only"
+
+
+
+ When OVN_NBCTL_OPTIONS is set, ovn-nbctl
+ automatically and transparently uses the environment variable to
+ execute its commands. However user can still over-ride environment
+ options by passing different in cli.
+
+
+
+ When the environment variable is no longer needed, unset it, e.g.:
+
+
+
+ unset OVN_NBCTL_OPTIONS
+
--db
database
diff --git a/utilities/ovn-nbctl.c b/utilities/ovn-nbctl.c
index a89a9cb4d..684f0f40b 100644
--- a/utilities/ovn-nbctl.c
+++ b/utilities/ovn-nbctl.c
@@ -124,18 +124,33 @@ static char * OVS_WARN_UNUSED_RESULT main_loop(const char *args,
static void server_loop(struct ovsdb_idl *idl, int argc, char *argv[]);
int
-main(int argc, char *argv[])
+main(int argc, char *argv_[])
{
struct ovsdb_idl *idl;
struct shash local_options;
- set_program_name(argv[0]);
+ set_program_name(argv_[0]);
fatal_ignore_sigpipe();
vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
vlog_set_levels_from_string_assert("reconnect:warn");
nbctl_cmd_init();
+ /* Check if options are set via env var. */
+ char *ctl_options = getenv("OVN_NBCTL_OPTIONS");
+ char **argv;
+ int *argcp;
+ argcp = xmalloc(sizeof(int));
+ *argcp = argc;
+ argv = ovs_cmdl_env_parse_all(argcp, argv_,
+ ctl_options);
+ if (!argv) {
+ /* This situation should never occur, but... */
+ ctl_fatal("Unable to read argv");
+ }
+ argc = *argcp;
+ free(argcp);
+
/* ovn-nbctl has three operation modes:
*
* - Direct: Executes commands by contacting ovsdb-server directly.
diff --git a/utilities/ovn-sbctl.8.in b/utilities/ovn-sbctl.8.in
index 2aaa457e8..b3c21d625 100644
--- a/utilities/ovn-sbctl.8.in
+++ b/utilities/ovn-sbctl.8.in
@@ -93,6 +93,14 @@ to approximately \fIsecs\fR seconds. If the timeout expires,
would normally happen only if the database cannot be contacted, or if
the system is overloaded.)
.
+.IP "\fBOVN_SBCTL_OPTIONS\fR"
+.User can set one or more options using \fBOVN_SBCTL_OPTIONS\fR environment
+.variable. Under the Bourne shell this might be done like this:
+.export \fBOVN_SBCTL_OPTIONS\fR"="--db=unix:sb1.ovsdb --no-leader-only".
+.However user can still over-ride environment options by passing different
+.options in cli. When the environment variable is no longer needed, unset it,
+.e.g.: unset \fBOVN_SBCTL_OPTIONS\fR"
+.
.so lib/vlog.man
.so lib/common.man
.
diff --git a/utilities/ovn-sbctl.c b/utilities/ovn-sbctl.c
index 9a9b6f0ec..7c991a5fc 100644
--- a/utilities/ovn-sbctl.c
+++ b/utilities/ovn-sbctl.c
@@ -93,7 +93,7 @@ static bool do_sbctl(const char *args, struct ctl_command *, size_t n,
struct ovsdb_idl *);
int
-main(int argc, char *argv[])
+main(int argc, char *argv_[])
{
struct ovsdb_idl *idl;
struct ctl_command *commands;
@@ -101,13 +101,28 @@ main(int argc, char *argv[])
unsigned int seqno;
size_t n_commands;
- set_program_name(argv[0]);
+ set_program_name(argv_[0]);
fatal_ignore_sigpipe();
vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
vlog_set_levels_from_string_assert("reconnect:warn");
sbctl_cmd_init();
+ /* Check if options are set via env var. */
+ char *ctl_options = getenv("OVN_SBCTL_OPTIONS");
+ char **argv;
+ int *argcp;
+ argcp = xmalloc(sizeof(int));
+ *argcp = argc;
+ argv = ovs_cmdl_env_parse_all(argcp, argv_,
+ ctl_options);
+ if (!argv) {
+ /* This situation should never occur, but... */
+ ctl_fatal("Unable to read argv");
+ }
+ argc = *argcp;
+ free(argcp);
+
/* Parse command line. */
char *args = process_escape_args(argv);
shash_init(&local_options);