Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
d47ddf5b
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d47ddf5b
编写于
5月 29, 2006
作者:
K
Karel Zak
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support mock & domuuid for virsh
上级
62450534
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
125 addition
and
55 deletion
+125
-55
ChangeLog
ChangeLog
+11
-0
include/libvirt.h
include/libvirt.h
+5
-0
include/libvirt/libvirt.h
include/libvirt/libvirt.h
+5
-0
src/virsh.c
src/virsh.c
+104
-55
未找到文件。
ChangeLog
浏览文件 @
d47ddf5b
Mon May 29 16:33:39 CEST 2006 Karel Zak <kzak@redhat.com>
* src/virsh.c: improved vshCommandOptDomain(), added <name> to the
connect command and minor changes to Daniel B.'s patch
Fri May 26 11:40:20 EDT 2006 Daniel P. Berrange <berrange@redhat.com>
* src/virsh.c: added 'domuuid' command to display printable UUID
string for a domain. Added '--connect' argument to allow the name
of the hypervisor connection passed to virConnect to be set.
Mon May 22 15:34:20 CEST 2006 Karel Zak <kzak@redhat.com>
* src/virsh.c: added UUID: to the dominfo command, vshPrint() refactoring,
...
...
include/libvirt.h
浏览文件 @
d47ddf5b
...
...
@@ -229,6 +229,9 @@ virDomainPtr virDomainLookupByID (virConnectPtr conn,
int
id
);
virDomainPtr
virDomainLookupByUUID
(
virConnectPtr
conn
,
const
unsigned
char
*
uuid
);
virDomainPtr
virDomainLookupByUUIDString
(
virConnectPtr
conn
,
const
char
*
uuid
);
int
virDomainShutdown
(
virDomainPtr
domain
);
int
virDomainReboot
(
virDomainPtr
domain
,
unsigned
int
flags
);
...
...
@@ -262,6 +265,8 @@ const char * virDomainGetName (virDomainPtr domain);
unsigned
int
virDomainGetID
(
virDomainPtr
domain
);
int
virDomainGetUUID
(
virDomainPtr
domain
,
unsigned
char
*
uuid
);
int
virDomainGetUUIDString
(
virDomainPtr
domain
,
char
*
buf
);
char
*
virDomainGetOSType
(
virDomainPtr
domain
);
unsigned
long
virDomainGetMaxMemory
(
virDomainPtr
domain
);
int
virDomainSetMaxMemory
(
virDomainPtr
domain
,
...
...
include/libvirt/libvirt.h
浏览文件 @
d47ddf5b
...
...
@@ -229,6 +229,9 @@ virDomainPtr virDomainLookupByID (virConnectPtr conn,
int
id
);
virDomainPtr
virDomainLookupByUUID
(
virConnectPtr
conn
,
const
unsigned
char
*
uuid
);
virDomainPtr
virDomainLookupByUUIDString
(
virConnectPtr
conn
,
const
char
*
uuid
);
int
virDomainShutdown
(
virDomainPtr
domain
);
int
virDomainReboot
(
virDomainPtr
domain
,
unsigned
int
flags
);
...
...
@@ -262,6 +265,8 @@ const char * virDomainGetName (virDomainPtr domain);
unsigned
int
virDomainGetID
(
virDomainPtr
domain
);
int
virDomainGetUUID
(
virDomainPtr
domain
,
unsigned
char
*
uuid
);
int
virDomainGetUUIDString
(
virDomainPtr
domain
,
char
*
buf
);
char
*
virDomainGetOSType
(
virDomainPtr
domain
);
unsigned
long
virDomainGetMaxMemory
(
virDomainPtr
domain
);
int
virDomainSetMaxMemory
(
virDomainPtr
domain
,
...
...
src/virsh.c
浏览文件 @
d47ddf5b
...
...
@@ -7,6 +7,8 @@
*
* Daniel Veillard <veillard@redhat.com>
* Karel Zak <kzak@redhat.com>
* Daniel P. Berrange <berrange@redhat.com>
*
*
* $Id$
*/
...
...
@@ -154,6 +156,7 @@ typedef struct __vshCmd {
* vshControl
*/
typedef
struct
__vshControl
{
char
*
name
;
/* connection name */
virConnectPtr
conn
;
/* connection to hypervisor */
vshCmd
*
cmd
;
/* the current command */
char
*
cmdstr
;
/* string with command */
...
...
@@ -184,11 +187,23 @@ static int vshCommandOptInt(vshCmd * cmd, const char *name, int *found);
static
char
*
vshCommandOptString
(
vshCmd
*
cmd
,
const
char
*
name
,
int
*
found
);
static
int
vshCommandOptBool
(
vshCmd
*
cmd
,
const
char
*
name
);
static
virDomainPtr
vshCommandOptDomain
(
vshControl
*
ctl
,
vshCmd
*
cmd
,
const
char
*
optname
,
char
**
name
);
#define VSH_DOMBYID (1 << 1)
#define VSH_DOMBYUUID (1 << 2)
#define VSH_DOMBYNAME (1 << 3)
static
virDomainPtr
vshCommandOptDomainBy
(
vshControl
*
ctl
,
vshCmd
*
cmd
,
const
char
*
optname
,
char
**
name
,
int
flag
);
/* default is lookup by Id, Name and UUID */
#define vshCommandOptDomain(_ctl, _cmd, _optname, _name) \
vshCommandOptDomainBy(_ctl, _cmd, _optname, _name,\
VSH_DOMBYID|VSH_DOMBYUUID|VSH_DOMBYNAME)
static
void
vshPrintExtra
(
vshControl
*
ctl
,
const
char
*
format
,
...);
static
void
vshDebug
(
vshControl
*
ctl
,
int
level
,
const
char
*
format
,
...);
/* XXX: add batch support */
#define vshPrint(_ctl, ...) fprintf(stdout, __VA_ARGS__)
static
const
char
*
vshDomainStateToString
(
int
state
);
...
...
@@ -246,7 +261,7 @@ cmdHelp(vshControl * ctl, vshCmd * cmd)
* "connect" command
*/
static
vshCmdInfo
info_connect
[]
=
{
{
"syntax"
,
"connect [--readonly]"
},
{
"syntax"
,
"connect [
name] [
--readonly]"
},
{
"help"
,
"(re)connect to hypervisor"
},
{
"desc"
,
"Connect to local hypervisor. This is build-in command after shell start up."
},
...
...
@@ -254,6 +269,7 @@ static vshCmdInfo info_connect[] = {
};
static
vshCmdOptDef
opts_connect
[]
=
{
{
"name"
,
VSH_OT_DATA
,
0
,
"optional argument currently unused (or used for tests only)"
},
{
"readonly"
,
VSH_OT_BOOL
,
0
,
"read-only connection"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -262,7 +278,7 @@ static int
cmdConnect
(
vshControl
*
ctl
,
vshCmd
*
cmd
)
{
int
ro
=
vshCommandOptBool
(
cmd
,
"readonly"
);
if
(
ctl
->
conn
)
{
if
(
virConnectClose
(
ctl
->
conn
)
!=
0
)
{
vshError
(
ctl
,
FALSE
,
...
...
@@ -271,10 +287,15 @@ cmdConnect(vshControl * ctl, vshCmd * cmd)
}
ctl
->
conn
=
NULL
;
}
if
(
ctl
->
name
)
free
(
ctl
->
name
);
ctl
->
name
=
vshCommandOptString
(
cmd
,
"name"
,
NULL
);
if
(
!
ro
)
ctl
->
conn
=
virConnectOpen
(
NULL
);
ctl
->
conn
=
virConnectOpen
(
ctl
->
name
);
else
ctl
->
conn
=
virConnectOpenReadOnly
(
NULL
);
ctl
->
conn
=
virConnectOpenReadOnly
(
ctl
->
name
);
if
(
!
ctl
->
conn
)
vshError
(
ctl
,
FALSE
,
"failed to connect to the hypervisor"
);
...
...
@@ -347,7 +368,7 @@ static vshCmdInfo info_domstate[] = {
};
static
vshCmdOptDef
opts_domstate
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
or
id"
},
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
, id or uu
id"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -385,7 +406,7 @@ static vshCmdInfo info_suspend[] = {
};
static
vshCmdOptDef
opts_suspend
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
or
id"
},
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
, id or uu
id"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -479,7 +500,7 @@ static vshCmdInfo info_save[] = {
};
static
vshCmdOptDef
opts_save
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
or
id"
},
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
, id or uu
id"
},
{
"file"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"where to save the data"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -561,7 +582,7 @@ static vshCmdInfo info_resume[] = {
};
static
vshCmdOptDef
opts_resume
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
or
id"
},
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
, id or uu
id"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -600,7 +621,7 @@ static vshCmdInfo info_shutdown[] = {
};
static
vshCmdOptDef
opts_shutdown
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
or
id"
},
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
, id or uu
id"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -639,7 +660,7 @@ static vshCmdInfo info_reboot[] = {
};
static
vshCmdOptDef
opts_reboot
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
or
id"
},
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
, id or uu
id"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -678,7 +699,7 @@ static vshCmdInfo info_destroy[] = {
};
static
vshCmdOptDef
opts_destroy
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
or
id"
},
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
, id or uu
id"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -717,7 +738,7 @@ static vshCmdInfo info_dominfo[] = {
};
static
vshCmdOptDef
opts_dominfo
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
or
id"
},
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
, id or uu
id"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -817,7 +838,7 @@ static vshCmdInfo info_dumpxml[] = {
};
static
vshCmdOptDef
opts_dumpxml
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
or
id"
},
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
, id, uu
id"
},
{
NULL
,
0
,
0
,
NULL
}
};
...
...
@@ -850,36 +871,29 @@ cmdDumpXML(vshControl * ctl, vshCmd * cmd)
* "domname" command
*/
static
vshCmdInfo
info_domname
[]
=
{
{
"syntax"
,
"domname <
id
>"
},
{
"help"
,
"convert a domain Id to domain name"
},
{
"syntax"
,
"domname <
domain
>"
},
{
"help"
,
"convert a domain Id
or UUID
to domain name"
},
{
NULL
,
NULL
}
};
static
vshCmdOptDef
opts_domname
[]
=
{
{
"
id"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain I
d"
},
{
"
domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain id or uui
d"
},
{
NULL
,
0
,
0
,
NULL
}
};
static
int
cmdDomname
(
vshControl
*
ctl
,
vshCmd
*
cmd
)
{
int
found
;
int
id
=
vshCommandOptInt
(
cmd
,
"id"
,
&
found
);
virDomainPtr
dom
;
if
(
!
vshConnectionUsability
(
ctl
,
ctl
->
conn
,
TRUE
))
return
FALSE
;
if
(
!
found
)
if
(
!
(
dom
=
vshCommandOptDomainBy
(
ctl
,
cmd
,
"domain"
,
NULL
,
VSH_DOMBYID
|
VSH_DOMBYUUID
)))
return
FALSE
;
dom
=
virDomainLookupByID
(
ctl
->
conn
,
id
);
if
(
dom
)
{
vshPrint
(
ctl
,
"%s
\n
"
,
virDomainGetName
(
dom
));
virDomainFree
(
dom
);
}
else
{
vshError
(
ctl
,
FALSE
,
"failed to get domain '%d'"
,
id
);
return
FALSE
;
}
vshPrint
(
ctl
,
"%s
\n
"
,
virDomainGetName
(
dom
));
virDomainFree
(
dom
);
return
TRUE
;
}
...
...
@@ -887,38 +901,67 @@ cmdDomname(vshControl * ctl, vshCmd * cmd)
* "domid" command
*/
static
vshCmdInfo
info_domid
[]
=
{
{
"syntax"
,
"domid <
name
>"
},
{
"help"
,
"convert a domain name to domain Id"
},
{
"syntax"
,
"domid <
domain
>"
},
{
"help"
,
"convert a domain name
or UUID
to domain Id"
},
{
NULL
,
NULL
}
};
static
vshCmdOptDef
opts_domid
[]
=
{
{
"
name"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name
"
},
{
"
domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain name or uuid
"
},
{
NULL
,
0
,
0
,
NULL
}
};
static
int
cmdDomid
(
vshControl
*
ctl
,
vshCmd
*
cmd
)
{
char
*
name
=
vshCommandOptString
(
cmd
,
"name"
,
NULL
);
virDomainPtr
dom
;
if
(
!
vshConnectionUsability
(
ctl
,
ctl
->
conn
,
TRUE
))
return
FALSE
;
if
(
!
name
)
if
(
!
(
dom
=
vshCommandOptDomainBy
(
ctl
,
cmd
,
"domain"
,
NULL
,
VSH_DOMBYNAME
|
VSH_DOMBYUUID
)))
return
FALSE
;
vshPrint
(
ctl
,
"%d
\n
"
,
virDomainGetID
(
dom
));
virDomainFree
(
dom
);
return
TRUE
;
}
dom
=
virDomainLookupByName
(
ctl
->
conn
,
name
);
if
(
dom
)
{
vshPrint
(
ctl
,
"%d
\n
"
,
virDomainGetID
(
dom
));
virDomainFree
(
dom
);
}
else
{
vshError
(
ctl
,
FALSE
,
"failed to get domain '%s'"
,
name
);
/*
* "domuuid" command
*/
static
vshCmdInfo
info_domuuid
[]
=
{
{
"syntax"
,
"domuuid <domain>"
},
{
"help"
,
"convert a domain name or id to domain UUID"
},
{
NULL
,
NULL
}
};
static
vshCmdOptDef
opts_domuuid
[]
=
{
{
"domain"
,
VSH_OT_DATA
,
VSH_OFLAG_REQ
,
"domain id or name"
},
{
NULL
,
0
,
0
,
NULL
}
};
static
int
cmdDomuuid
(
vshControl
*
ctl
,
vshCmd
*
cmd
)
{
virDomainPtr
dom
;
char
uuid
[
37
];
if
(
!
vshConnectionUsability
(
ctl
,
ctl
->
conn
,
TRUE
))
return
FALSE
;
}
if
(
!
(
dom
=
vshCommandOptDomainBy
(
ctl
,
cmd
,
"domain"
,
NULL
,
VSH_DOMBYNAME
|
VSH_DOMBYID
)))
return
FALSE
;
if
(
virDomainGetUUIDString
(
dom
,
uuid
)
!=
-
1
)
vshPrint
(
ctl
,
"%s
\n
"
,
uuid
);
else
vshError
(
ctl
,
FALSE
,
"failed to get domain UUID"
);
return
TRUE
;
}
/*
* "version" command
*/
...
...
@@ -1023,6 +1066,7 @@ static vshCmdDef commands[] = {
{
"create"
,
cmdCreate
,
opts_create
,
info_create
},
{
"destroy"
,
cmdDestroy
,
opts_destroy
,
info_destroy
},
{
"domid"
,
cmdDomid
,
opts_domid
,
info_domid
},
{
"domuuid"
,
cmdDomuuid
,
opts_domuuid
,
info_domuuid
},
{
"dominfo"
,
cmdDominfo
,
opts_dominfo
,
info_dominfo
},
{
"domname"
,
cmdDomname
,
opts_domname
,
info_domname
},
{
"domstate"
,
cmdDomstate
,
opts_domstate
,
info_domstate
},
...
...
@@ -1272,8 +1316,8 @@ vshCommandOptBool(vshCmd * cmd, const char *name)
static
virDomainPtr
vshCommandOptDomain
(
vshControl
*
ctl
,
vshCmd
*
cmd
,
const
char
*
optname
,
char
**
name
)
vshCommandOptDomain
By
(
vshControl
*
ctl
,
vshCmd
*
cmd
,
const
char
*
optname
,
char
**
name
,
int
flag
)
{
virDomainPtr
dom
=
NULL
;
char
*
n
,
*
end
=
NULL
;
...
...
@@ -1291,22 +1335,22 @@ vshCommandOptDomain(vshControl * ctl, vshCmd * cmd, const char *optname,
*
name
=
n
;
/* try it by ID */
id
=
(
int
)
strtol
(
n
,
&
end
,
10
);
if
(
id
>=
0
&&
end
&&
*
end
==
'\0'
)
{
vshDebug
(
ctl
,
5
,
"%s: <%s> seems like domain ID
\n
"
,
cmd
->
def
->
name
,
optname
);
dom
=
virDomainLookupByID
(
ctl
->
conn
,
id
);
if
(
flag
&
VSH_DOMBYID
)
{
id
=
(
int
)
strtol
(
n
,
&
end
,
10
);
if
(
id
>=
0
&&
end
&&
*
end
==
'\0'
)
{
vshDebug
(
ctl
,
5
,
"%s: <%s> seems like domain ID
\n
"
,
cmd
->
def
->
name
,
optname
);
dom
=
virDomainLookupByID
(
ctl
->
conn
,
id
);
}
}
/* try it by UUID */
if
(
dom
==
NULL
&&
strlen
(
n
)
==
36
)
{
if
(
dom
==
NULL
&&
(
flag
&
VSH_DOMBYUUID
)
&&
strlen
(
n
)
==
36
)
{
vshDebug
(
ctl
,
5
,
"%s: <%s> tring as domain UUID
\n
"
,
cmd
->
def
->
name
,
optname
);
dom
=
virDomainLookupByUUIDString
(
ctl
->
conn
,
(
const
unsigned
char
*
)
n
);
dom
=
virDomainLookupByUUIDString
(
ctl
->
conn
,
n
);
}
/* try it by NAME */
if
(
!
dom
)
{
if
(
dom
==
NULL
&&
(
flag
&
VSH_DOMBYNAME
)
)
{
vshDebug
(
ctl
,
5
,
"%s: <%s> tring as domain NAME
\n
"
,
cmd
->
def
->
name
,
optname
);
dom
=
virDomainLookupByName
(
ctl
->
conn
,
n
);
...
...
@@ -1715,9 +1759,9 @@ vshInit(vshControl * ctl)
/* basic connection to hypervisor */
if
(
ctl
->
uid
==
0
)
ctl
->
conn
=
virConnectOpen
(
NULL
);
ctl
->
conn
=
virConnectOpen
(
ctl
->
name
);
else
ctl
->
conn
=
virConnectOpenReadOnly
(
NULL
);
ctl
->
conn
=
virConnectOpenReadOnly
(
ctl
->
name
);
if
(
!
ctl
->
conn
)
vshError
(
ctl
,
TRUE
,
"failed to connect to the hypervisor"
);
...
...
@@ -1867,6 +1911,7 @@ vshUsage(vshControl * ctl, const char *cmdname)
if
(
!
cmdname
)
{
fprintf
(
stdout
,
"
\n
%s [options] [commands]
\n\n
"
" options:
\n
"
" -c | --connect <name> optional argument currently unused (or used for tests only)
\n
"
" -d | --debug <num> debug level [0-5]
\n
"
" -h | --help this help
\n
"
" -q | --quiet quiet mode
\n
"
...
...
@@ -1903,6 +1948,7 @@ vshParseArgv(vshControl * ctl, int argc, char **argv)
{
"quiet"
,
0
,
0
,
'q'
},
{
"timing"
,
0
,
0
,
't'
},
{
"version"
,
0
,
0
,
'v'
},
{
"connect"
,
1
,
0
,
'c'
},
{
0
,
0
,
0
,
0
}
};
...
...
@@ -1957,6 +2003,9 @@ vshParseArgv(vshControl * ctl, int argc, char **argv)
case
't'
:
ctl
->
timing
=
TRUE
;
break
;
case
'c'
:
ctl
->
name
=
vshStrdup
(
ctl
,
optarg
);
break
;
case
'v'
:
fprintf
(
stdout
,
"%s
\n
"
,
VERSION
);
exit
(
EXIT_SUCCESS
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录