How To use RHEVM Command Line?

   本文简单的描述下如何链接rhev shell以及简单的使用。关于更详细的用法请参考官方文档。shell

一、如何链接到rhevm?api

   要想链接到rhevm,必须拥有一个有效的证书。此证书通常安装完rhevm后会自动产生。下面是如何获取到证书。网络

[root@rhevm ~]# wget -O rhevm.cer http://rhevm.xzxj.edu.cn/ca.crt
--2014-05-02 09:29:34--  http://rhevm.xzxj.edu.cn/ca.crt
Resolving rhevm.xzxj.edu.cn... 172.16.255.100
Connecting to rhevm.xzxj.edu.cn|172.16.255.100|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1355 (1.3K) [application/x-x509-ca-cert]
Saving to: “rhevm.cer”
100%[=========================================================================================>] 1,355       --.-K/s   in 0s    
2014-05-02 09:29:34 (313 MB/s) - “rhevm.cer” saved [1355/1355]

   接着使用rhevm-shell命令链接。app

[root@rhevm ~]# rhevm-shell -c -l "https://rhevm.xzxj.edu.cn/api" -u "admin@internal" -A rhevm.cer
Password:
 ==========================================
 >>> connected to RHEVM manager 3.3.0.0 <<<
 ==========================================
                                                                                                                                                                                              
 ++++++++++++++++++++++++++++++++++++++++++
                                                                                                                                                                                       
           Welcome to RHEVM shell
                                                                                                                                                                                       
 ++++++++++++++++++++++++++++++++++++++++++
                                                                                                                                                                                              
                                                                                                                                                                                          
[RHEVM shell (connected)]#

二、查看数据中心less

[RHEVM shell (connected)]# list datacenters
id         : c47b976d-3205-491f-9fc3-43c0204b2ca8
name       : DATA01
description: ISCSI_SHARE

三、查看集群dom

[RHEVM shell (connected)]# list clusters
id         : 99408929-82cf-4dc7-a532-9d998063fa95
name       : Default
description: The default server cluster
id         : 374ab972-3470-416f-9f47-49a076e643c8
name       : MyCluster
description: Just For Home

四、查看网络socket

[RHEVM shell (connected)]# list networks --show-all
id            : 8cc17c17-7e04-4ddf-9004-257529c9ca50
name          : rhevm
description   : Management Network
data_center-id: c47b976d-3205-491f-9fc3-43c0204b2ca8
mtu           : 0
stp           : False
usages-usage  : vm

五、查看虚拟机ide

[RHEVM shell (connected)]# list vms
id         : e1a8a858-c2b5-435c-86cf-e90c0d54de8a
name       : TestOS01
id         : 652aff2a-12d5-489c-87db-240b2f413e21
name       : TestOS02
id         : f26bbce5-8c7f-4221-9b39-4a14f48ebc25
name       : win2k3

     查看单个虚拟机信息spa

[RHEVM shell (connected)]# show vm TestOS01
id                                     : e1a8a858-c2b5-435c-86cf-e90c0d54de8a
name                                   : TestOS01
cluster-id                             : 374ab972-3470-416f-9f47-49a076e643c8
cpu-topology-cores                     : 1
cpu-topology-sockets                   : 2
cpu_shares                             : 0
creation_time                          : 2014-05-01 18:17:19.215000+08:00
custom_properties-custom_property-name : viodiskcache
custom_properties-custom_property-value: writethrough
delete_protected                       : False
display-address                        : 172.16.255.154
display-allow_override                 : True
display-monitors                       : 1
display-port                           : 5902
display-secure_port                    : 5903
display-single_qxl_pci                 : True
display-smartcard_enabled              : False
display-type                           : spice
guest_info-ips-ip-address              : 172.16.255.151
high_availability-enabled              : True
high_availability-priority             : 50
host-id                                : 6958d0be-7eef-4191-81f1-be43c839df68
memory                                 : 1073741824
memory_policy-guaranteed               : 715128832
origin                                 : ovirt
os-boot-dev                            : hd
os-type                                : rhel_6x64
placement_policy-affinity              : migratable
start_time                             : 2014-05-03 16:08:10.147000+08:00
stateless                              : False
status-state                           : up
template-id                            : 00000000-0000-0000-0000-000000000000
type                                   : server
usb-enabled                            : True
usb-type                               : native

六、建立虚拟机3d

[RHEVM shell (connected)]# add vm --name TestOS03 --cluster-name MyCluster --template-name rhel65 --memory 536870912
id                        : 5c8ecb9c-4eea-4e9c-9ecb-c6a4ec5c0248
name                      : TestOS03
cluster-id                : 374ab972-3470-416f-9f47-49a076e643c8
console-enabled           : True
cpu-topology-cores        : 1
cpu-topology-sockets      : 2
cpu_shares                : 0
creation_status-state     : pending
creation_time             : 2014-05-03 17:02:00.810000+08:00
delete_protected          : False
display-allow_override    : True
display-monitors          : 1
display-single_qxl_pci    : True
display-smartcard_enabled : False
display-type              : spice
high_availability-enabled : True
high_availability-priority: 50
memory                    : 536870912           //定义的内存大小为512MB
memory_policy-ballooning  : True
memory_policy-guaranteed  : 536870912
origin                    : ovirt
os-boot-dev               : hd
os-type                   : rhel_6x64
placement_policy-affinity : migratable
stateless                 : False
status-state              : p_w_picpath_locked
template-id               : 4fc2c10d-d3d9-44fb-b4ae-e838ef38e2a3
type                      : server
usb-enabled               : False
virtio_scsi-enabled       : True
//将TestOS03的内存更新至1GB
[RHEVM shell (connected)]# update vm TestOS03 --memory 1073741824
id                        : 5c8ecb9c-4eea-4e9c-9ecb-c6a4ec5c0248
name                      : TestOS03
cluster-id                : 374ab972-3470-416f-9f47-49a076e643c8
console-enabled           : False
cpu-topology-cores        : 1
cpu-topology-sockets      : 2
cpu_shares                : 0
creation_time             : 2014-05-03 17:02:00.810000+08:00
delete_protected          : False
display-allow_override    : True
display-monitors          : 1
display-single_qxl_pci    : True
display-smartcard_enabled : False
display-type              : spice
high_availability-enabled : True
high_availability-priority: 50
memory                    : 1073741824
memory_policy-ballooning  : True
memory_policy-guaranteed  : 536870912
origin                    : ovirt
os-boot-dev               : hd
os-type                   : rhel_6x64
placement_policy-affinity : migratable
stateless                 : False
status-state              : down
template-id               : 4fc2c10d-d3d9-44fb-b4ae-e838ef38e2a3
type                      : server
usb-enabled               : False
virtio_scsi-enabled       : True

七、向虚拟机添加硬盘

[RHEVM shell (connected)]# add disk --vm-identifier TestOS03 --name ShareDisk01 --format cow --interface virtio --size 5368709120
id                               : 2e7549f2-9236-457f-9bdb-b90d60464365
name                             : ShareDisk01
active                           : True
actual_size                      : 0
alias                            : ShareDisk01
bootable                         : False
creation_status-state            : pending
format                           : cow
p_w_picpath_id                         : 3160c9ac-69c6-4697-9d19-95f19f497437
interface                        : virtio
propagate_errors                 : False
provisioned_size                 : 5368709120
shareable                        : False
size                             : 5368709120  //磁盘大小为5G
sparse                           : True
status-state                     : locked
storage_domains-storage_domain-id: e2947295-2e94-4aaa-a643-d0bfd45d9fd6
vm-id                            : 5c8ecb9c-4eea-4e9c-9ecb-c6a4ec5c0248
wipe_after_delete                : False

八、删除虚拟机

//删除磁盘
[RHEVM shell (connected)]# remove disk ShareDisk01 --vm-identifier TestOS03
status-state: complete
//删除虚拟机
[RHEVM shell (connected)]# remove vm TestOS03
status-state: complete