https://github.com/2spmohanty/gosphere
vCenter Automation GO way.
https://github.com/2spmohanty/gosphere
automation golang govmomi vcenter vmware vmware-vsphere vsphere vsphere-api vsphere-sdk
Last synced: 6 months ago
JSON representation
vCenter Automation GO way.
- Host: GitHub
- URL: https://github.com/2spmohanty/gosphere
- Owner: 2spmohanty
- License: apache-2.0
- Created: 2019-05-01T17:02:33.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-03-02T23:24:53.000Z (over 4 years ago)
- Last Synced: 2026-01-14T07:52:32.451Z (6 months ago)
- Topics: automation, golang, govmomi, vcenter, vmware, vmware-vsphere, vsphere, vsphere-api, vsphere-sdk
- Language: Go
- Homepage:
- Size: 36.3 MB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gosphere
The gosphere repository contains codes written in Go Language that can be used to perform automation task on VMWare vCenter. These codes are wrapper on govmomi and exposes easy Methods. Contributors are welcome.
```
func main() {
vc := flag.String("vc", "VC_IP", "Enter vCenter IP/ FQDN")
user := flag.String("user", "Administrator@vsphere.local", "vCenter User")
pass := flag.String("pass", "XXXXX", "Enter vCenter pass")
flag.Parse()
vcenter := operation.NewVCenter(*vc, *user, *pass)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
err := vcenter.Connect(ctx)
if err != nil {
fmt.Printf("Failed to connect to vCenter: %s\n", err)
return
}
fmt.Printf("Connected to vCenter: %s\n", *vc)
//Get Datacenter Operation Level object
dcops := operation.DatacenterOperation{Context: ctx, Vcenter: vcenter}
//Get Cluster Operation Level object
clops := operation.ClusterOperation{Context: ctx, Vcenter: vcenter}
datacenters, err := vcenter.GetAllDatacenter(ctx)
if err != nil {
fmt.Printf("Datacenters errors: %s", err)
return
}
for _, dc := range datacenters {
dcName := dc.Name()
fmt.Printf(" Datacenter %s\n", dcName)
standalonehosts := dcops.GetStandAloneHosts(dc)
if standalonehosts != nil {
fmt.Printf("Standalone Hosts on Datacenter %s\n", dcName)
for _, hostmor := range standalonehosts {
fmt.Println(hostmor.Name)
}
}
var cls []mo.ClusterComputeResource
cls, _ = dcops.GetAllCluster(dc)
if cls != nil {
for _, clsref := range cls {
fmt.Printf("Datcenter Clusters ***** %s ******\n", clsref.Name)
var hosts []mo.HostSystem
hosts, _ = clops.GetAllClusterHosts(clsref, "")
if hosts != nil {
fmt.Printf("Cluster Hosts")
for _, hostref := range hosts {
fmt.Printf("**** %s ****\n", hostref.Name)
}
}
}
}
}
}
```
# Philosophy
The code must be
```
- simple
- readable
- maintainable
- Do exactly one task.
```