C+libvirt获取KVM存储池信息
来源:互联网 发布:键盘按键替换软件 编辑:程序博客网 时间:2024/06/06 11:04
分享一段代码,可以获取指定虚拟化宿主机器上的存储池信息,如:存储池名称、存储池容量、存储池状态、存储池可用、总计以及已使用容量,代码如下:
#include <stdio.h>#include <stdlib.h>#include <libvirt/libvirt.h>int main(int argc, char *argv[]){virConnectPtr conn;conn = virConnectOpen("qemu:///system");if (conn == NULL) {fprintf(stderr, "Failed to open connection to qemu:///system\n");}virStoragePoolPtr *pPoolList;int i;int nAllPoolNum = virConnectNumOfStoragePools(conn);int nDefinePoolNum = virConnectNumOfDefinedStoragePools(conn);char **PoolName = (char **)malloc(sizeof(char*) * (nAllPoolNum));virConnectListStoragePools(conn,PoolName,nAllPoolNum);for(i = 0; i < nAllPoolNum; i++){printf("PoolName:[%s]\n",PoolName[i]);virStoragePoolPtr pPool = malloc(sizeof(virStoragePoolPtr));pPool = virStoragePoolLookupByName(conn,PoolName[i]);virStoragePoolInfoPtr pinfor= malloc(sizeof(virStoragePoolInfoPtr));virStoragePoolGetInfo(pPool,pinfor);printf("[%d][%ld][%ld][%ld]\n",pinfor->state,pinfor->capacity,pinfor->allocation,pinfor->available);}}
执行后的效果如下:
[root@kvm poolstatus]# ./t PoolName:[default][2][52844687360][26866851840][25977835520]PoolName:[poolB][2][485150105600][107614916608][377535188992]
- C+libvirt获取KVM存储池信息
- libvirt KVM
- Kvm Qemu Libvirt
- KVM Qemu libvirt
- KVM 介绍:libvirt 介绍
- Kvm Qemu Libvirt
- KVM 介绍:libvirt 介绍
- kvm qemu libvirt区别
- kvm+libvirt虚拟机快照
- KVM+Qemu+Libvirt实战
- java使用ssh调用shell命令获取KVM数据(KVM需要通过libvirt管理)
- qemu,kqemu,kvm,qemu-kvm,libvirt关系
- 利用libvirt管理KVM虚拟机
- 使用libvirt管理KVM虚拟机
- 使用libvirt创建kvm虚拟机
- 使用libvirt管理kvm虚拟机
- 使用libvirt管理kvm虚拟机
- 使用libvirt管理kvm虚拟机
- 习题 ct6_1: 循环移位☆
- get table names and table columns from db
- 石头剪子布的游戏
- Commando War UVa 11729(贪心)
- Oracle 自定义函数详解(转)
- C+libvirt获取KVM存储池信息
- 题目1491:求1和2的个数
- how to execute sql script in c#
- 将图像中的某种颜色设为透明
- Oracle的system被锁的解决办法
- C/C++程序员求职面试指导
- linux 用户组的权限分配
- C++第2周项目6——点结构体与枚举
- IOS截屏的几种方法