文章目录
一、golang常用库之-VMware vSphere SDK API入门
1. 什么是VMware vSphere
VMware vSphere 是 VMware 的虚拟化平台,可将数据中心转换为包括 CPU、存储和网络资源的聚合计算基础架构。vSphere 将这些基础架构作为一个统一的运行环境进行管理,并为您提供工具来管理加入该环境的数据中心。
vSphere 的两个核心组件是 ESXi和vCenter Server。ESXi是用于创建并运行虚拟机和虚拟设备的虚拟化平台。vCenter Server是一项服务,用于管理网络中连接的多个主机,并将主机资源池化。
2. vSphere API
官方有2个语言版本的sdk,如下一个是python、一个是go。
-
pyVmomi 是适用于VMware vSphere API的Python SDK,可让您管理ESX,ESXi和vCenter。
-
govmomi: 是 VMware vSphere API 的 GO 库,用于与VMware vSphere API(ESXi和/或vCenter)进行交互。
govmomi 和 pyvmomi 都是基于 VMware 的 api 实现的。
3. 关于govmomi
3.1 兼容性
该库是为ESXi和vCenter 6.5、6.7和7.0构建的,并针对它们进行了测试。
它可能与5.1、5.5和6.0版本一起使用,但均未正式支持。
3.2 文档
该库公开的API紧密遵循《 VMware vSphere API参考文档》中描述的API。(https://code.vmware.com/apis/196/vsphere)
govmomi软件包中的代码是对从vSphere API描述生成的代码的包装。 它主要提供使用vSphere API的便利功能。
3.3 使用govmomi 的项目
- Docker Machine
- Docker InfraKit
- Docker LinuxKit
- Kubernetes
- Kubernetes Cloud Provider
- Kubernetes Cluster API
- Kubernetes kops
- Terraform
- Packer
- VMware VIC Engine
- Travis CI
- collectd-vsphere
- Gru
- Libretto
- Telegraf
- Open Storage
- Juju
- vSphere 7.0
- OPS
- VMware Event Broker Appliance
3.4 govc 使用举例
govmomi 不仅提供了这个第三方库,同时基于这个库还写了 govc,vcsim 和 toolbox 这三个命令行工具,你完全可以使用它们在命令行管理你的 vsphere。
govc 基本上实现了 govmomi 的所有功能。
下载安装:
$ go install github.com/vmware/govmomi/govc
govc -h 列出所有功能
F:\open_code\govmomi>govc -h
Usage of govc:
about
about.cert
cluster.add
cluster.change
cluster.create
cluster.group.change
cluster.group.create
cluster.group.ls
cluster.group.remove
...
3.5 api 使用demo举例
登录demo
package main
import (
"context"
"fmt"
"github.com/vmware/govmomi"
"net/url"
)
const (
ip = ""
user = ""
password = ""
)
func main() {
u := &url.URL{
Scheme: "https",
Host: ip,
Path: "/sdk",
}
ctx := context.Background()
u.User = url.UserPassword(user, password)
//url 的最终格式如:https://user:password@IP/sdk
client, err := govmomi.NewClient(ctx, u, true)
if err != nil {
panic(err)
}
fmt.Println(client)
}
govmoni官方源码也提供了example示例:
二、参考
VMware vSphere 官方文档 (https://docs.vmware.com/cn/VMware-vSphere/index.html)
github ( https://github.com/vmware )
govmoni 官方文档( http://godoc.org/github.com/vmware/govmomi )
vsphere golang sdk govmomi 使用指南 ( https://juejin.cn/post/6844903902152753165 )
ttp://godoc.org/github.com/vmware/govmomi )
vsphere golang sdk govmomi 使用指南 ( https://juejin.cn/post/6844903902152753165 )