最近在做一个项目,主要是把Vmware Vsphere的数据通过RESTful API暴露给第三方,调用。

1.VMware vSphere

那么什么是Vmware Vsphere,或者说Vmware Vsphere是什么?

  • vSphere:VMware公司发布的一整套产品包,是VMware公司推出的一套服务器虚拟化解决方案,包含VMware ESXi hypervisor,VMware vCenter Server等产品
  • ESXi:服务器级别的虚拟机,它就是一个操作系统,一个平台
    • 创建和运行虚拟机和虚拟设备
  • vCenter Server:集中管理虚拟机的服务,vCenter Server有两种
    • vCenter Server可以安装在Windows Server上
    • 也可以是基于Linux的虚拟设备,vCenter Server是一个集中式管理应用程序,可以集中管理虚拟机和ESXi主机,vSphere可以通过访问vCenter Server对ESXi服务器进行管理,通过vCenter Server,可以克隆现有的虚拟机服务器。

vCenter可以作为虚拟机安装在ESXi服务器上,也可以安装在独立的物理服务器上,vCenter Server主要终于大型环境中,该环境中有许多ESXi主机和虚拟机,并且需要vSphere的高级企业功能(vMotion[虚拟机迁移]、VMware High Availability[HA高可用性]、VMware Update Manager[vmware更新管理器]、VMware Distributed Resource Scheduler(DRS)[分布式资源调度])。

  • vSphere Client:远程连接ESXi的客户端,一次只能管理一个ESXi的主机,而vCenter Server可以同时管理多个ESXi服务器,vSphere Client可以通过HTML5/Web进行登录,管理员登录Web浏览器来访问vSphere Client,以此来管理ESXi服务器(可以不安装vSphere Client的软件来访问ESXi服务器)

整体架构图

Overview diagram of VMware vSphere illustrating the relationship among ESXi hosts, vCenter Server, virtual machines, and vSphere Client.

首先VMware vSphere是一个虚拟化平台,将数据中心转换为包含CPU、存储和网络资源的计算基础设施。vSphere作为一个统一的操作环境来管理这些基础设施,并提供管理这个环境的数据中心的工具。

2.访问VMware vSphere

VMware vSphere官方提供了两个主要的SDK供开发者使用。并以此获取VMware vSphere的相关数据

  • vSphere Automation SDK
  • vSphere Management SDK

前者文档很清楚,且提供了.NET,Java,Python,REST,Ruby,Perl等不同语言平台的SDK,而且还都是开源的。由于本人是一个.NET从业者,有.NET的SDK,肯定优先使用.NET,但是有些数据vSphere Automation SDK无法找到相关数据。真的是脑壳大,连一整天找不到相关的数据,比如主机数量、CPU核数、内存分配等情况。无意间浏览到vSphere Automation Python SDK 的github仓库

This document describes the vSphere Automation Python SDK samples that use the vSphere Automation python client library. Additionally, some of the samples demonstrate the combined use of the vSphere Automation and vSphere APIs. To support this combined use, the vSphere Automation Python SDK samples require the vSphere Management SDK packages (pyVmomi) to be installed on the client. The samples have been developed to work with python 2.7.x and 3.3+

翻译:文章主要描述使用vSphere Automation python 客户端库的vSphere Automation Python SDK的示例,另外,一些示例演示了vSphere Automation 和vSphere APIs组合使用,为了支持这种组合使用,这些vSphere Automation Python SDK示例就需要Sphere Management SDK 包(pyVmomi),这些示例依赖python 版本2.7.x和3.3+

其他SDK的文档中均未发现这句话,也没有相关示例,运用出色的搜商,找到了.NET版本的vSphere Management SDK,当我满心欢喜的下载下来,以为胜利就在远方,发现文档中有一句话,这不满足我们可能需要跨平台的需求,因为还需要依赖windows

Requirements
.NET framework 4.5+, Visual Studio 2012+ and Windows Driver Kit (WDK)

3.VMware vSphere Python SDK

  • vSphere Automation Python SDK:https://github.com/vmware/vsphere-automation-sdk-python

  • vSphere Automation Api 文档:https://code.vmware.com/web/sdk/7.0/vsphere-automation-python

  • vSphere Management SDK 包pyvmomi:https://github.com/vmware/pyvmomi

  • pyvmomi 代码示例:https://github.com/vmware/pyvmomi-community-samples

  • pyvmomi 代码示例文档:http://vmware.github.io/pyvmomi-community-samples/

参考链接

https://blog.csdn.net/ryu2003/article/details/82255319

https://blog.csdn.net/waterxcfg304/article/details/49863693?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

https://blog.csdn.net/weixin_44837286/article/details/106221679?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

https://docs.vmware.com/en/VMware-vSphere/index.html