gosphere

package module
v0.0.0-...-b908e55 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2022 License: Apache-2.0 Imports: 0 Imported by: 0

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.

Documentation

Overview

Package gosphere contains API code and exposes easy methods to perform operation on vCenter. Author : Smruti P Mohanty

Copyright (c) 2017 VMware, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
Package examples contains code sample to easy automate vCEnter activity.
Package examples contains code sample to easy automate vCEnter activity.
createvcinventory
go build createinv createinv.go usage: ./createinv -vc vcip -user username -pass
go build createinv createinv.go usage: ./createinv -vc vcip -user username -pass
Package operation contains all vCenter objects related operation.
Package operation contains all vCenter objects related operation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL