mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh: lookup interface by name or mac other than one by one
Use virMacAddrParse() to distinguish interface name from interface mac address.
This commit is contained in:
parent
a6a04ea47a
commit
36c0a791e6
@ -35,6 +35,7 @@
|
|||||||
#include "virbuffer.h"
|
#include "virbuffer.h"
|
||||||
#include "viralloc.h"
|
#include "viralloc.h"
|
||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
|
#include "virmacaddr.h"
|
||||||
#include "virutil.h"
|
#include "virutil.h"
|
||||||
#include "virxml.h"
|
#include "virxml.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
@ -46,6 +47,8 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
|
|||||||
{
|
{
|
||||||
virInterfacePtr iface = NULL;
|
virInterfacePtr iface = NULL;
|
||||||
const char *n = NULL;
|
const char *n = NULL;
|
||||||
|
bool is_mac = false;
|
||||||
|
virMacAddr dummy;
|
||||||
virCheckFlags(VSH_BYNAME | VSH_BYMAC, NULL);
|
virCheckFlags(VSH_BYNAME | VSH_BYMAC, NULL);
|
||||||
|
|
||||||
if (!optname)
|
if (!optname)
|
||||||
@ -62,14 +65,17 @@ vshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
|
|||||||
if (name)
|
if (name)
|
||||||
*name = n;
|
*name = n;
|
||||||
|
|
||||||
|
if (virMacAddrParse(n, &dummy) == 0)
|
||||||
|
is_mac = true;
|
||||||
|
|
||||||
/* try it by NAME */
|
/* try it by NAME */
|
||||||
if (flags & VSH_BYNAME) {
|
if (!is_mac && (flags & VSH_BYNAME)) {
|
||||||
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface NAME\n",
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface NAME\n",
|
||||||
cmd->def->name, optname);
|
cmd->def->name, optname);
|
||||||
iface = virInterfaceLookupByName(ctl->conn, n);
|
iface = virInterfaceLookupByName(ctl->conn, n);
|
||||||
}
|
|
||||||
/* try it by MAC */
|
/* try it by MAC */
|
||||||
if (!iface && (flags & VSH_BYMAC)) {
|
} else if (is_mac && (flags & VSH_BYMAC)) {
|
||||||
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface MAC\n",
|
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface MAC\n",
|
||||||
cmd->def->name, optname);
|
cmd->def->name, optname);
|
||||||
iface = virInterfaceLookupByMACString(ctl->conn, n);
|
iface = virInterfaceLookupByMACString(ctl->conn, n);
|
||||||
|
Loading…
Reference in New Issue
Block a user