mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
virsh: let domif-{get,set}link take target name
Other virsh domifXXX commands can accept target name as a parameter to specify interface. From viewpoint of consistency, virsh domif-getlink command should accept target name as a parameter. This patch achieves this. Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
This commit is contained in:
parent
32b57a72de
commit
a3de9829d8
@ -1344,8 +1344,11 @@ cmdDomIfSetLink (vshControl *ctl, const vshCmd *cmd)
|
|||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
const char *iface;
|
const char *iface;
|
||||||
const char *state;
|
const char *state;
|
||||||
const char *mac;
|
const char *value;
|
||||||
const char *desc;
|
const char *desc;
|
||||||
|
unsigned char macaddr[VIR_MAC_BUFLEN];
|
||||||
|
const char *element;
|
||||||
|
const char *attr;
|
||||||
bool persistent;
|
bool persistent;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
@ -1405,26 +1408,34 @@ cmdDomIfSetLink (vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virParseMacAddr(iface, macaddr) == 0) {
|
||||||
|
element = "mac";
|
||||||
|
attr = "address";
|
||||||
|
} else {
|
||||||
|
element = "target";
|
||||||
|
attr = "dev";
|
||||||
|
}
|
||||||
|
|
||||||
/* find interface with matching mac addr */
|
/* find interface with matching mac addr */
|
||||||
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
||||||
cur = obj->nodesetval->nodeTab[i]->children;
|
cur = obj->nodesetval->nodeTab[i]->children;
|
||||||
|
|
||||||
while (cur) {
|
while (cur) {
|
||||||
if (cur->type == XML_ELEMENT_NODE &&
|
if (cur->type == XML_ELEMENT_NODE &&
|
||||||
xmlStrEqual(cur->name, BAD_CAST "mac")) {
|
xmlStrEqual(cur->name, BAD_CAST element)) {
|
||||||
mac = virXMLPropString(cur, "address");
|
value = virXMLPropString(cur, attr);
|
||||||
|
|
||||||
if (STRCASEEQ(mac, iface)) {
|
if (STRCASEEQ(value, iface)) {
|
||||||
VIR_FREE(mac);
|
VIR_FREE(value);
|
||||||
goto hit;
|
goto hit;
|
||||||
}
|
}
|
||||||
VIR_FREE(mac);
|
VIR_FREE(value);
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vshError(ctl, _("interface with address '%s' not found"), iface);
|
vshError(ctl, _("interface (%s: %s) not found"), element, iface);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
hit:
|
hit:
|
||||||
@ -1509,7 +1520,10 @@ cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *iface = NULL;
|
const char *iface = NULL;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
char *state = NULL;
|
char *state = NULL;
|
||||||
char *mac = NULL;
|
char *value = NULL;
|
||||||
|
unsigned char macaddr[VIR_MAC_BUFLEN];
|
||||||
|
const char *element;
|
||||||
|
const char *attr;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
int i;
|
int i;
|
||||||
char *desc;
|
char *desc;
|
||||||
@ -1552,27 +1566,35 @@ cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virParseMacAddr(iface, macaddr) == 0) {
|
||||||
|
element = "mac";
|
||||||
|
attr = "address";
|
||||||
|
} else {
|
||||||
|
element = "target";
|
||||||
|
attr = "dev";
|
||||||
|
}
|
||||||
|
|
||||||
/* find interface with matching mac addr */
|
/* find interface with matching mac addr */
|
||||||
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
|
||||||
cur = obj->nodesetval->nodeTab[i]->children;
|
cur = obj->nodesetval->nodeTab[i]->children;
|
||||||
|
|
||||||
while (cur) {
|
while (cur) {
|
||||||
if (cur->type == XML_ELEMENT_NODE &&
|
if (cur->type == XML_ELEMENT_NODE &&
|
||||||
xmlStrEqual(cur->name, BAD_CAST "mac")) {
|
xmlStrEqual(cur->name, BAD_CAST element)) {
|
||||||
|
|
||||||
mac = virXMLPropString(cur, "address");
|
value = virXMLPropString(cur, attr);
|
||||||
|
|
||||||
if (STRCASEEQ(mac, iface)){
|
if (STRCASEEQ(value, iface)) {
|
||||||
VIR_FREE(mac);
|
VIR_FREE(value);
|
||||||
goto hit;
|
goto hit;
|
||||||
}
|
}
|
||||||
VIR_FREE(mac);
|
VIR_FREE(value);
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vshError(ctl, _("Interface with address '%s' not found."), iface);
|
vshError(ctl, _("Interface (%s: %s) not found."), element, iface);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
hit:
|
hit:
|
||||||
|
@ -469,16 +469,18 @@ B<Explanation of fields> (fields appear in the folowing order):
|
|||||||
|
|
||||||
Get network interface stats for a running domain.
|
Get network interface stats for a running domain.
|
||||||
|
|
||||||
=item B<domif-setlink> I<domain> I<interface-MAC> I<state> I<--persistent>
|
=item B<domif-setlink> I<domain> I<interface-device> I<state> I<--persistent>
|
||||||
|
|
||||||
Modify link state of the domain's virtual interface. Possible values for
|
Modify link state of the domain's virtual interface. Possible values for
|
||||||
state are "up" and "down. If --persistent is specified, only the persistent
|
state are "up" and "down. If --persistent is specified, only the persistent
|
||||||
configuration of the domain is modified.
|
configuration of the domain is modified.
|
||||||
|
I<interface-device> can be the interface's target name or the MAC address.
|
||||||
|
|
||||||
=item B<domif-getlink> I<domain> I<interface-MAC> I<--persistent>
|
=item B<domif-getlink> I<domain> I<interface-device> I<--persistent>
|
||||||
|
|
||||||
Query link state of the domain's virtual interface. If --persistent
|
Query link state of the domain's virtual interface. If --persistent
|
||||||
is specified, query the persistent configuration.
|
is specified, query the persistent configuration.
|
||||||
|
I<interface-device> can be the interface's target name or the MAC address.
|
||||||
|
|
||||||
=item B<domiftune> I<domain> I<interface-device>
|
=item B<domiftune> I<domain> I<interface-device>
|
||||||
[[I<--config>] [I<--live>] | [I<--current>]]
|
[[I<--config>] [I<--live>] | [I<--current>]]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user