Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
71029ef5
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
71029ef5
编写于
9月 21, 2018
作者:
S
Simon Kobyda
提交者:
Michal Privoznik
9月 24, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
virsh: Implement vshTable API to net-list and net-dhcp-leases
Signed-off-by:
N
Simon Kobyda
<
skobyda@redhat.com
>
上级
0396cf53
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
38 addition
and
21 deletion
+38
-21
tools/virsh-network.c
tools/virsh-network.c
+38
-21
未找到文件。
tools/virsh-network.c
浏览文件 @
71029ef5
...
...
@@ -33,6 +33,7 @@
#include "virstring.h"
#include "virtime.h"
#include "conf/network_conf.h"
#include "vsh-table.h"
#define VIRSH_COMMON_OPT_NETWORK(_helpstr, cflags) \
{.name = "network", \
...
...
@@ -677,6 +678,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
bool
optUUID
=
vshCommandOptBool
(
cmd
,
"uuid"
);
char
uuid
[
VIR_UUID_STRING_BUFLEN
];
unsigned
int
flags
=
VIR_CONNECT_LIST_NETWORKS_ACTIVE
;
vshTablePtr
table
=
NULL
;
if
(
vshCommandOptBool
(
cmd
,
"inactive"
))
flags
=
VIR_CONNECT_LIST_NETWORKS_INACTIVE
;
...
...
@@ -705,10 +707,10 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
return
false
;
if
(
optTable
)
{
vshPrintExtra
(
ctl
,
" %-20s %-10s %-13s %s
\n
"
,
_
(
"Name"
),
_
(
"State
"
),
_
(
"Autostart"
),
_
(
"Persistent"
)
);
vshPrintExtra
(
ctl
,
"----------------------------------------------------------
\n
"
)
;
table
=
vshTableNew
(
_
(
"Name"
),
_
(
"State"
),
_
(
"Autostart
"
),
_
(
"Persistent"
),
NULL
);
if
(
!
table
)
goto
cleanup
;
}
for
(
i
=
0
;
i
<
list
->
nnets
;
i
++
)
{
...
...
@@ -722,11 +724,15 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
else
autostartStr
=
is_autostart
?
_
(
"yes"
)
:
_
(
"no"
);
vshPrint
(
ctl
,
" %-20s %-10s %-13s %s
\n
"
,
virNetworkGetName
(
network
),
virNetworkIsActive
(
network
)
?
_
(
"active"
)
:
_
(
"inactive"
),
autostartStr
,
virNetworkIsPersistent
(
network
)
?
_
(
"yes"
)
:
_
(
"no"
));
if
(
vshTableRowAppend
(
table
,
virNetworkGetName
(
network
),
virNetworkIsActive
(
network
)
?
_
(
"active"
)
:
_
(
"inactive"
),
autostartStr
,
virNetworkIsPersistent
(
network
)
?
_
(
"yes"
)
:
_
(
"no"
),
NULL
)
<
0
)
goto
cleanup
;
}
else
if
(
optUUID
)
{
if
(
virNetworkGetUUIDString
(
network
,
uuid
)
<
0
)
{
vshError
(
ctl
,
"%s"
,
_
(
"Failed to get network's UUID"
));
...
...
@@ -738,8 +744,12 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
}
}
if
(
optTable
)
vshTablePrintToStdout
(
table
,
ctl
);
ret
=
true
;
cleanup:
vshTableFree
(
table
);
virshNetworkListFree
(
list
);
return
ret
;
}
...
...
@@ -1351,6 +1361,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
size_t
i
;
unsigned
int
flags
=
0
;
virNetworkPtr
network
=
NULL
;
vshTablePtr
table
=
NULL
;
if
(
vshCommandOptStringReq
(
ctl
,
cmd
,
"mac"
,
&
mac
)
<
0
)
return
false
;
...
...
@@ -1366,15 +1377,15 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
/* Sort the list according to MAC Address/IAID */
qsort
(
leases
,
nleases
,
sizeof
(
*
leases
),
virshNetworkDHCPLeaseSorter
);
vshPrintExtra
(
ctl
,
" %-20s %-18s %-9s %-25s %-15s %s
\n
%s%s
\n
"
,
_
(
"Expiry Time"
),
_
(
"MAC address"
),
_
(
"Protocol
"
),
_
(
"IP address"
),
_
(
"Hostname"
),
_
(
"Client ID or DUID"
),
"----------------------------------------------------------"
,
"---------------------------------------------------------"
)
;
table
=
vshTableNew
(
_
(
"Expiry Time"
),
_
(
"MAC address"
),
_
(
"Protocol"
)
,
_
(
"IP address"
),
_
(
"Hostname"
),
_
(
"Client ID or DUID
"
),
NULL
);
if
(
!
table
)
goto
cleanup
;
for
(
i
=
0
;
i
<
nleases
;
i
++
)
{
const
char
*
typestr
=
NULL
;
char
*
cidr_format
=
NULL
;
VIR_AUTOFREE
(
char
*
)
cidr_format
=
NULL
;
virNetworkDHCPLeasePtr
lease
=
leases
[
i
];
time_t
expirytime_tmp
=
lease
->
expirytime
;
struct
tm
ts
;
...
...
@@ -1390,17 +1401,23 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
ignore_value
(
virAsprintf
(
&
cidr_format
,
"%s/%d"
,
lease
->
ipaddr
,
lease
->
prefix
));
vshPrint
(
ctl
,
" %-20s %-18s %-9s %-25s %-15s %s
\n
"
,
expirytime
,
EMPTYSTR
(
lease
->
mac
),
EMPTYSTR
(
typestr
),
cidr_format
,
EMPTYSTR
(
lease
->
hostname
),
EMPTYSTR
(
lease
->
clientid
));
VIR_FREE
(
cidr_format
);
if
(
vshTableRowAppend
(
table
,
expirytime
,
EMPTYSTR
(
lease
->
mac
),
EMPTYSTR
(
typestr
),
EMPTYSTR
(
cidr_format
),
EMPTYSTR
(
lease
->
hostname
),
EMPTYSTR
(
lease
->
clientid
),
NULL
)
<
0
)
goto
cleanup
;
}
vshTablePrintToStdout
(
table
,
ctl
);
ret
=
true
;
cleanup:
vshTableFree
(
table
);
if
(
leases
)
{
for
(
i
=
0
;
i
<
nleases
;
i
++
)
virNetworkDHCPLeaseFree
(
leases
[
i
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录