summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2014-03-11 13:21:50 +0100
committerJiří Klimeš <jklimes@redhat.com>2014-03-11 13:58:11 +0100
commit42f4f05b399155b4c4b1270d1861060240c5f3bf (patch)
treedcfd23bad7ec21a64fbd3b033adb67f35d11eceb
parente2acf1fa521b2a6f357d2b8cd266dbbfa19c829f (diff)
downloadNetworkManager-jk/rh1057494-nmcli-master-id.tar.gz
cli: accept prefix "ifname/", "uuid/" or "id/" for 'master' argumentjk/rh1057494-nmcli-master-id
nmcli con add type team-slave ifname em2 master team-master0 nmcli con add type team-slave ifname em2 master id/team-master0 It helps to disambiguate values for cases where they may overlap, e.g. "team0" -> "ifname/team0" or "id/team0"
-rw-r--r--cli/src/connections.c62
-rw-r--r--man/nmcli.1.in9
2 files changed, 56 insertions, 15 deletions
diff --git a/cli/src/connections.c b/cli/src/connections.c
index 472b71ae22..734de3c2fe 100644
--- a/cli/src/connections.c
+++ b/cli/src/connections.c
@@ -2743,6 +2743,28 @@ unique_master_iface_ifname (GSList *list,
return new_name;
}
+static const char *
+_strip_master_prefix (const char *master, const char *(**func)(NMConnection *))
+{
+ if (!master)
+ return NULL;
+
+ if (g_str_has_prefix (master, "ifname/")) {
+ master = master + strlen ("ifname/");
+ if (func)
+ *func = nm_connection_get_virtual_iface_name;
+ } else if (g_str_has_prefix (master, "uuid/")) {
+ master = master + strlen ("uuid/");
+ if (func)
+ *func = nm_connection_get_uuid;
+ } else if (g_str_has_prefix (master, "id/")) {
+ master = master + strlen ("id/");
+ if (func)
+ *func = nm_connection_get_id;
+ }
+ return master;
+}
+
/* verify_master_for_slave:
* @connections: list af all connections
* @master: UUID, ifname or ID of the master connection
@@ -2765,7 +2787,12 @@ verify_master_for_slave (GSList *connections,
GSList *iterator = connections;
const char *found_by_id = NULL;
const char *out_master = NULL;
+ const char *(*func) (NMConnection *) = NULL;
+
+ if (!master)
+ return NULL;
+ master = _strip_master_prefix (master, &func);
while (iterator) {
connection = NM_CONNECTION (iterator->data);
s_con = nm_connection_get_setting_connection (connection);
@@ -2775,16 +2802,27 @@ verify_master_for_slave (GSList *connections,
iterator = g_slist_next (iterator);
continue;
}
- id = nm_connection_get_id (connection);
- uuid = nm_connection_get_uuid (connection);
- ifname = nm_connection_get_virtual_iface_name (connection);
- if ( g_strcmp0 (master, uuid) == 0
- || g_strcmp0 (master, ifname) == 0) {
- out_master = master;
- break;
+ if (func) {
+ /* There was a prefix; only compare to that type. */
+ if (g_strcmp0 (master, func (connection)) == 0) {
+ if (func == nm_connection_get_id)
+ out_master = nm_connection_get_uuid (connection);
+ else
+ out_master = master;
+ break;
+ }
+ } else {
+ id = nm_connection_get_id (connection);
+ uuid = nm_connection_get_uuid (connection);
+ ifname = nm_connection_get_virtual_iface_name (connection);
+ if ( g_strcmp0 (master, uuid) == 0
+ || g_strcmp0 (master, ifname) == 0) {
+ out_master = master;
+ break;
+ }
+ if (!found_by_id && g_strcmp0 (master, id) == 0)
+ found_by_id = uuid;
}
- if (!found_by_id && g_strcmp0 (master, id) == 0)
- found_by_id = uuid;
iterator = g_slist_next (iterator);
}
@@ -4419,7 +4457,7 @@ cleanup_bond:
/* Change properties in 'connection' setting */
g_object_set (s_con,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
- NM_SETTING_CONNECTION_MASTER, checked_master ? checked_master : master,
+ NM_SETTING_CONNECTION_MASTER, checked_master ? checked_master : _strip_master_prefix (master, NULL),
NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BOND_SETTING_NAME,
NULL);
@@ -4533,7 +4571,7 @@ cleanup_team:
/* Change properties in 'connection' setting */
g_object_set (s_con,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
- NM_SETTING_CONNECTION_MASTER, checked_master ? checked_master : master,
+ NM_SETTING_CONNECTION_MASTER, checked_master ? checked_master : _strip_master_prefix (master, NULL),
NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_TEAM_SETTING_NAME,
NULL);
@@ -4738,7 +4776,7 @@ cleanup_bridge:
/* Change properties in 'connection' setting */
g_object_set (s_con,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
- NM_SETTING_CONNECTION_MASTER, checked_master ? checked_master : master,
+ NM_SETTING_CONNECTION_MASTER, checked_master ? checked_master : _strip_master_prefix (master, NULL),
NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_BRIDGE_SETTING_NAME,
NULL);
diff --git a/man/nmcli.1.in b/man/nmcli.1.in
index bc3b942cf1..6eb6f1fac0 100644
--- a/man/nmcli.1.in
+++ b/man/nmcli.1.in
@@ -522,7 +522,8 @@ Note: use quotes around \fB*\fP to suppress shell expansion.
.TP
.B bond-slave:
.IP "\fImaster <master (ifname, or connection UUID or name)>\fP" 42
-\(en name of bond master interface
+\(en master bond interface name, or connection UUID or ID of bond master connection profile.
+The value can be prefixed with \fBifname/\fP, \fBuuid/\fP or \fBid/\fP to disambiguate it.
.RE
.RS
.TP
@@ -534,7 +535,8 @@ Note: use quotes around \fB*\fP to suppress shell expansion.
.TP
.B team-slave:
.IP "\fImaster <master (ifname, or connection UUID or name)>\fP" 42
-\(en name of team master interface
+\(en master team interface name, or connection UUID or ID of team master connection profile.
+The value can be prefixed with \fBifname/\fP, \fBuuid/\fP or \fBid/\fP to disambiguate it.
.IP "\fI[config <file>|<raw JSON data>]\fP" 42
\(en JSON configuration for team
.RE
@@ -558,7 +560,8 @@ Note: use quotes around \fB*\fP to suppress shell expansion.
.TP
.B bridge-slave:
.IP "\fImaster <master (ifname, or connection UUID or name)>\fP" 42
-\(en name of bridge master interface
+\(en master bridge interface name, or connection UUID or ID of bridge master connection profile.
+The value can be prefixed with \fBifname/\fP, \fBuuid/\fP or \fBid/\fP to disambiguate it.
.IP "\fI[priority <0-63>]\fP" 42
\(en STP priority of this slave (default: 32)
.IP "\fI[path-cost <1-65535>]\fP" 42