Skip to content

Instantly share code, notes, and snippets.

View lamw's full-sized avatar

William Lam lamw

View GitHub Profile
#!/usr/bin/perl -w
use strict;
use warnings;
use VMware::VIRuntime;
use VMware::VILib;
Opts::parse();
Opts::validate();
Util::connect();
@lamw
lamw / start_ntp_sample.py
Created February 18, 2014 05:28
vSphere SDK for Python to start NTP Service on an ESXi host
#!/usr/bin/python
# William Lam
# www.virtuallyghetto.com
"""
vSphere Python SDK program demonstrating starting up ESXi Service
"""
from optparse import OptionParser, make_option
from pyVim.connect import SmartConnect, Disconnect
@lamw
lamw / gist:9725974
Last active July 24, 2018 07:26
one-liner to automate installation of VMware Tools on NIX system (mount/cp/extract/install)
mkdir -p /mnt/vmw-tools && mount /dev/cdrom /mnt/vmw-tools && VMW_TOOLS=$(ls /mnt/vmw-tools/ | grep .gz) && cp -f /mnt/vmw-tools/${VMW_TOOLS} /tmp/ && umount /mnt/vmw-tools && rmdir /mnt/vmw-tools && tar -zxvf /tmp/${VMW_TOOLS} -C /tmp/ && cd /tmp/vmware-tools-distrib/ && ./vmware-install.pl -d default && rm -rf vmware-tools-distrib/ && rm -f /tmp/${VMW_TOOLS} && cd ~
@lamw
lamw / gist:9928202
Created April 2, 2014 05:00
Parsing JSON in PowerShell using ConvertFrom-Json
$json = @"
{"A": {"property1": "value1", "property2": "value2"}, "B": {"property1": "value3", "property2": "value4"}}
"@
$parsed = $json | ConvertFrom-Json
foreach ($line in $parsed | Get-Member) {
echo $parsed.$($line.Name).property1
echo $parsed.$($line.Name).property2
}
@lamw
lamw / gist:11322180
Last active August 29, 2015 14:00
Enhancement to RVC cluster.add_host to extract SSL Thumbprint of ESXi host w/o having to run commmand twice
opts :add_host2 do
summary "Add a host to a cluster"
arg :cluster, nil, :lookup => VIM::ClusterComputeResource
arg :hostnames, nil, :multi => true
opt :username, "Username", :short => 'u', :default => 'root'
opt :password, "Password", :short => 'p', :default => ''
opt :force, "Force, e.g when host is already managed by other VC"
end
def add_host2 cluster, hostnames, opts
@lamw
lamw / gist:4a7182994200f74e890a
Last active August 29, 2015 14:21
Having some fun with VSAN HCL JSON
#!/usr/bin/env python
# William Lam
# www.virtuallyghetto.com
import json
import urllib2
# download json
response = urllib2.urlopen('http://partnerweb.vmware.com/service/vsan/all.json')
@lamw
lamw / gist:d5b8b725f466ee37feb8
Created May 17, 2015 16:34
Lists of all VSAN Storage Controller sorted from smallest to largest Queue Depth
#!/usr/bin/env python
# William Lam
# www.virtuallyghetto.com
# Lists of all VSAN Storage Controller sorted from smallest to largest Queue Depth
import json
import urllib2
# download json
response = urllib2.urlopen('http://partnerweb.vmware.com/service/vsan/all.json')
@lamw
lamw / gist:3271a29d49b2fb3633ba
Created June 5, 2015 16:49
PowerCLI snippet to get/set VSAN.ClomRepairDelay ESXi Advanced Property
Connect-VIServer -Server 192.168.1.60 -User administrator@vghetto.local -Password VMware1!
$cluster = "MacMini-Cluster"
$vmhosts = Get-Cluster $cluster | Get-VMHost
foreach ($vmhost in $vmhosts) {
# Retrieve VSAN.ClomRepairDelay
Get-AdvancedSetting -Entity $vmhost -Name VSAN.ClomRepairDelay | Select Name, Value
@lamw
lamw / gist:bae9687faa14c7d7ee18
Created June 17, 2015 05:46
Automate silent install of VMware Tools including enabling Automatic Kernel Module Update
#!/bin/bash
# Create temp workign directory
mkdir -p /mnt/vmw-tools
# Mount VMware Tools ISO
mount /dev/cdrom /mnt/vmw-tools
# Retrieve the VMware Tools package name from the directory
VMW_TOOLS=$(ls /mnt/vmw-tools/ | grep .gz)
@lamw
lamw / gist:487c9ecb2dc7d043eec8
Last active October 30, 2022 06:21
Automate silent installation of VMware Tools for Mac OS X
#!/bin/bash
# 1 = VMware Tools ISO is mounted from vSphere
# 2 = Download VMware Tools (assumes you can connect to internet)
INSTALL_METHOD=2
# Thanks to Rich Trouton for tip on Tools being available online
VMWARE_TOOLS_DOWNLOAD_URL=http://softwareupdate.vmware.com/cds/vmw-desktop/fusion/7.1.2/2779224/packages/com.vmware.fusion.tools.darwin.zip.tar
# DO NOT MODIFY BEYOND HERE #