Fix the dependency issue (#231)

This commit is contained in:
Robbie Zhang
2018-06-21 12:09:42 -07:00
committed by GitHub
parent 027b76651d
commit 6ec1098bb8
16629 changed files with 74837 additions and 4975021 deletions

View File

@@ -1 +0,0 @@
.wireshark-*

View File

@@ -1,43 +0,0 @@
#!/bin/bash
# Copyright (c) 2014 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.
set -e
# This script shows for every request in a debug trace how long it took
# and the name of the request body.
function body-name {
(
xmllint --shell $1 <<EOS
setns soapenv=http://schemas.xmlsoap.org/soap/envelope/
xpath name(//soapenv:Body/*)
EOS
) | head -1 | sed 's/.*Object is a string : \(.*\)$/\1/'
}
if [ -n "$1" ]; then
cd $1
fi
for req in $(find . -name '*.req.xml'); do
base=$(basename $req .req.xml)
session=$(echo $base | awk -F'-' "{printf \"%d\", \$1}")
number=$(echo $base | awk -F'-' "{printf \"%d\", \$2}")
client_log=$(dirname $req)/${session}-client.log
took=$(awk "/ ${number} took / { print \$4 }" ${client_log})
printf "%s %8s: %s\n" ${base} ${took} $(body-name $req)
done

View File

@@ -1,18 +0,0 @@
#!/bin/bash -e
# pipe the most recent debug run to xmlformat
cd ${GOVC_DEBUG_PATH-"$HOME/.govmomi/debug"}
cd $(ls -t | head -1)
header() {
printf "<!-- %s %s/%s\n%s\n-->\n" "$1" "$PWD" "$2" "$(tr -d '\r' < "$3")"
}
for file in *.req.xml; do
base=$(basename "$file" .req.xml)
header Request "$file" "${base}.req.headers"
xmlformat < "$file"
file="${base}.res.xml"
header Response "$file" "${base}.res.headers"
xmlformat < "$file"
done

View File

@@ -1,62 +0,0 @@
# Copyright (c) 2015 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.
# Provide a simple shell extension to save and load govc
# environments to disk. No more running `export GOVC_ABC=xyz`
# in different shells over and over again. Loading the right
# govc environment variables is now only one short and
# autocompleted command away!
#
# Usage:
# * Source this file from your `~/.bashrc` or running shell.
# * Execute `govc-env` to print GOVC_* variables.
# * Execute `govc-env --save <name>` to save GOVC_* variables.
# * Execute `govc-env <name>` to load GOVC_* variables.
#
_govc_env_dir=$HOME/.govmomi/env
mkdir -p "${_govc_env_dir}"
_govc-env-complete() {
local w="${COMP_WORDS[COMP_CWORD]}"
local c="$(find ${_govc_env_dir} -mindepth 1 -maxdepth 1 -type f | sort | xargs -r -L1 basename | xargs echo)"
# Only allow completion if preceding argument if the function itself
if [ "$3" == "govc-env" ]; then
COMPREPLY=( $(compgen -W "${c}" -- "${w}") )
fi
}
govc-env() {
# Print current environment
if [ -z "$1" ]; then
for VAR in $(env | grep ^GOVC_ | cut -d= -f1); do
echo "export ${VAR}='${!VAR}'"
done
return
fi
# Save current environment
if [ "$1" == "--save" ]; then
govc-env > ${_govc_env_dir}/$2
return
fi
# Load specified environment
source ${_govc_env_dir}/$1
}
complete -F _govc-env-complete govc-env

View File

@@ -1,43 +0,0 @@
#!/bin/bash
# govc Bash completion script
# place in etc/bash_completion.d/ or source on command line with "."
_govc_complete()
{
local cur prev subcmd
prev=${COMP_WORDS[COMP_CWORD-1]}
cur=${COMP_WORDS[COMP_CWORD]}
subcmd=${COMP_WORDS[1]}
COMPREPLY=()
if [[ ${prev} == "govc" ]] ; then # show subcommands, no options
COMPREPLY=( $(compgen -W "$(govc -h | grep -v Usage | tr -s '\n' ' ')" -- ${cur}) )
return 0
elif [[ ${cur} == "-"* ]] ; then
: # drop out and show options
elif [[ ${subcmd} == "ls" ]] ; then # not completing an option, try for appropriate values
if [[ ${prev} == "-t" ]] ; then
COMPREPLY=( $(compgen -W "$(govc ls -l "/**" | awk '{print $2}' | \
sort -u | tr -d '()' | tr '\n' ' ' )" -- ${cur}) )
else
COMPREPLY=( $(compgen -W "$(govc ls "${cur:-/*}*" | tr -s '\n' ' ' )" -- ${cur}) )
fi
elif [[ ${subcmd} == "vm."* || ${prev} == "-vm" ]] ; then
COMPREPLY=( $(compgen -W "$(govc ls -t VirtualMachine -l "${cur}*" | \
awk '{print $1}' | tr -s '\n' ' ' )" -- ${cur}) )
fi
# did not hit any specifcs so show all options from help
if [[ -z ${COMPREPLY} ]]; then
COMPREPLY=( $(compgen -W "-h $(govc ${subcmd} -h | awk '{print $1}' | \
grep "^-" | sed -e 's/=.*//g' | tr -s '\n' ' ' )" -- ${cur}) )
fi
return 0
}
complete -F _govc_complete govc

View File

@@ -1,15 +0,0 @@
/*
Copyright (c) ${YEARS} 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.
*/

View File

@@ -1,13 +0,0 @@
# Copyright (c) ${YEARS} 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.

View File

@@ -1,117 +0,0 @@
# vCenter cluster testbed automation
## Overview
This directory contains scripts to automate VCSA/ESXi install and cluster configuration for developing and testing.
## Dependencies
### govc
Install the latest release via https://github.com/vmware/govmomi/releases
### jq
Used here to derive static VCSA networking from its parent ESXi host.
But, you should already be using and loving jq for other tasks: http://stedolan.github.io/jq/
## Scripts
### create-esxi-vm.sh
This script creates a VM running stateless ESXi, booted via cdrom/iso.
It will create 2 disks by default:
* vSAN cache disk (Virtual SSD)
* vSAN store disk
The two vSAN disks will be unformatted, leaving them to be autoclaimed
by a vSAN enabled cluster.
Note that for a cluster to use vSAN, it will need at least 3 of these
ESXi VMs.
To create an ESXi VM for standalone use, use the `-s` flag and optionally increase the default disk size with the `-d`
flag:
```
./create-esxi-vm.sh -s -d 56 $GOVC_URL my-esxi-vm
```
The script can also be used directly against Workstation. Without a username in the url, govc will use local ticket
authentication. No password is used in this case, but the script will still use this value to set the password for
`root` in the ESX vm. You may also want to decrease the default disk `-d` and memory `-m` sizes. Example:
```
GOVC_NETWORK=NAT ./create-esxi-vm.sh -d 16 -m 4 -s :password-for-esx60@localhost $USER-esxbox
```
For use against Fusion, use `.` as the hostname:
```
./create-esxi-vm.sh -d 16 -m 4 -s root:password-for-esx60@. $USER-esxbox
```
### create-vcsa-vm.sh
This script creates a VM with VCSA (Virtual Center Server Appliance) installed.
### create-cluster.sh
The first argument to the script is the IP address of VCSA.
There must be at least three arguments that follow, IP addresses of ESXi hosts, to form the cluster.
The script then creates the following managed objects:
* Datacenter (dc1)
* ClusterComputeResource (cluster1)
* DistributedVirtualSwitch (DSwitch)
* DistributedVirtualPortgroup (PublicNetwork)
* DistributedVirtualPortgroup (InternalNetwork)
All of the given host systems are:
* Added to the ClusterComputeResource (cluster1)
* Added to the DistributedVirtualSwitch (DSwitch)
* Enabled for vSAN traffic (vmk0)
* Firewall configured to enable the remoteSerialPort rule
Cluster configuration includes:
* DRS enabled
* vSAN autoclaim of host system disks (results in shared Datastore "vsanDatastore")
## Example
This example will install VCSA, 3 ESXi VMs and create a cluster.
```
export GOVC_URL="root:password@some-esx-host"
./create-vcsa-vm.sh -n "${USER}-vcsa" $GOVC_URL
printf "${USER}-esxi-%03d\n" {1..3} | xargs -P3 -n1 ./create-esxi-vm.sh $GOVC_URL
govc vm.ip -k "${USER}-vcsa" "${USER}-esxi-*" | xargs ./create-cluster.sh
```
## Licenses
Optional, if you want to assign licenses to VCSA or ESXi hosts.
Where "ESX_LICENSE" should be that of "vSphere 6 per CPU, Enterprise Plus".
And "VCSA_LICENSE" should be that of "vCenter Server 6, Standard".
```
ESX_LICENSE=... VCSA_LICENSE=... ./assign-licenses.sh
```

View File

@@ -1,31 +0,0 @@
#!/bin/bash -e
# Copyright 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.
#
export GOVC_INSECURE=true
govc license.add "$VCSA_LICENSE" "$ESX_LICENSE" >/dev/null
govc license.assign "$VCSA_LICENSE" >/dev/null
govc ls -t HostSystem /dc1/host/cluster1 | xargs -I% -n1 govc license.assign -host % "$ESX_LICENSE" >/dev/null
echo "Assigned licenses..."
govc license.assigned.ls
echo ""
echo "License usage..."
govc license.ls

View File

@@ -1,132 +0,0 @@
#!/bin/bash -e
# Copyright 2017-2018 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.
#
# Configure a vCenter cluster with vSAN datastore, DVS and DVPGs
export GOVC_INSECURE=1
export GOVC_USERNAME=${GOVC_USERNAME:-"Administrator@vsphere.local"}
if [ -z "$GOVC_PASSWORD" ] ; then
# extract password from $GOVC_URL
GOVC_PASSWORD=$(govc env GOVC_PASSWORD)
fi
usage() {
echo "Usage: $0 [-d DATACENTER] [-c CLUSTER] VCSA_IP ESX_IP..." 1>&2
exit 1
}
# Defaults
dc_name="dc1"
cluster_name="cluster1"
vsan_vnic="vmk0"
while getopts c:d: flag
do
case $flag in
c)
cluster_name=$OPTARG
;;
d)
dc_name=$OPTARG
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ $# -lt 2 ] ; then
usage
fi
vc_ip=$1
shift
unset GOVC_DATACENTER
export GOVC_URL="${GOVC_USERNAME}:${GOVC_PASSWORD}@${vc_ip}"
cluster_path="/$dc_name/host/$cluster_name"
dvs_path="/$dc_name/network/DSwitch"
public_network="/$dc_name/network/PublicNetwork"
internal_network="/$dc_name/network/InternalNetwork"
if [ -z "$(govc ls "/$dc_name")" ] ; then
echo "Creating datacenter ${dc_name}..."
govc datacenter.create "$dc_name"
fi
export GOVC_DATACENTER="$dc_name"
if [ -z "$(govc ls "$cluster_path")" ] ; then
echo "Creating cluster ${cluster_path}..."
govc cluster.create "$cluster_name"
fi
if [ -z "$(govc ls "$dvs_path")" ] ; then
echo "Creating dvs ${dvs_path}..."
govc dvs.create -product-version 5.5.0 -folder "$(dirname "$dvs_path")" "$(basename "$dvs_path")"
fi
if [ -z "$(govc ls "$public_network")" ] ; then
govc dvs.portgroup.add -dvs "$dvs_path" -type earlyBinding -nports 16 "$(basename "$public_network")"
fi
if [ -z "$(govc ls "$internal_network")" ] ; then
govc dvs.portgroup.add -dvs "$dvs_path" -type ephemeral "$(basename "$internal_network")"
fi
hosts=()
vsan_hosts=()
for host_ip in "$@" ; do
host_path="$cluster_path/$host_ip"
hosts+=($host_path)
if [ -z "$(govc ls "$host_path")" ] ; then
echo "Adding host ($host_ip) to cluster $cluster_name"
govc cluster.add -cluster "$cluster_path" -noverify -force \
-hostname "$host_ip" -username root -password "$GOVC_PASSWORD"
fi
unclaimed=$(govc host.storage.info -host "$host_path" -unclaimed | tail -n+2 | wc -l)
if [ "$unclaimed" -eq 2 ] ; then
echo "Enabling vSAN traffic on ${vsan_vnic} for ${host_path}..."
govc host.vnic.service -host "$host_path" -enable vsan "$vsan_vnic"
vsan_hosts+=($host_path)
else
echo "Skipping vSAN configuration for ${host_path}: $unclaimed unclaimed disks"
fi
done
govc dvs.add -dvs "$dvs_path" -pnic vmnic1 "${hosts[@]}"
echo "Enabling DRS for ${cluster_path}..."
govc cluster.change -drs-enabled "$cluster_path"
if [ ${#vsan_hosts[@]} -ge 3 ] ; then
echo "Enabling vSAN for ${cluster_path}..."
govc cluster.change -vsan-enabled -vsan-autoclaim "$cluster_path"
fi
echo "Enabling HA for ${cluster_path}..."
govc cluster.change -ha-enabled "$cluster_path"
echo "Granting Admin permissions for user root..."
govc permissions.set -principal root -role Admin
echo "Done."

View File

@@ -1,283 +0,0 @@
#!/bin/bash -e
# Copyright 2017-2018 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.
#
# Create a VM and boot stateless ESXi via cdrom/iso
set -o pipefail
usage() {
cat <<'EOF'
Usage: $0 [-d DISK_GB] [-m MEM_GB] [-i ESX_ISO] [-s] ESX_URL VM_NAME
GOVC_* environment variables also apply, see https://github.com/vmware/govmomi/tree/master/govc#usage
If GOVC_USERNAME is set, it is used to create an account on the ESX vm. Default is to use the existing root account.
If GOVC_PASSWORD is set, the account password will be set to this value. Default is to use the given ESX_URL password.
EOF
}
disk=48
mem=16
# 6.5U1 (EP5) - https://docs.vmware.com/en/VMware-vSphere/6.5/rn/vsphere-esxi-651-release-notes.html
iso=VMware-VMvisor-6.5.0-7526137.x86_64.iso
while getopts d:hi:m:s flag
do
case $flag in
d)
disk=$OPTARG
;;
h)
usage
exit
;;
i)
iso=$OPTARG
;;
m)
mem=$OPTARG
;;
s)
standalone=true
;;
*)
usage 1>&2
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ $# -ne 2 ] ; then
usage
exit 1
fi
if [[ "$iso" == *"-Installer-"* ]] ; then
echo "Invalid iso name (need stateless, not installer): $iso" 1>&2
exit 1
fi
export GOVC_INSECURE=1
export GOVC_URL=$1
network=${GOVC_NETWORK:-"VM Network"}
username=$GOVC_USERNAME
password=$GOVC_PASSWORD
unset GOVC_USERNAME GOVC_PASSWORD
guest=${GUEST:-"vmkernel6Guest"}
if [ -z "$password" ] ; then
# extract password from $GOVC_URL
password=$(govc env GOVC_PASSWORD)
fi
shift
name=$1
shift
echo -n "Checking govc version..."
govc version -require 0.15.0
if [ "$(govc env -x GOVC_URL_HOST)" = "." ] ; then
if [ "$(uname -s)" = "Darwin" ]; then
PATH="/Applications/VMware Fusion.app/Contents/Library:$PATH"
fi
dir="${name}.vmwarevm"
vmx="$dir/${name}.vmx"
if [ -d "$dir" ] ; then
if vmrun list | grep -q "$vmx" ; then
vmrun stop "$vmx" hard
fi
rm -rf "$dir"
fi
mkdir "$dir"
vmware-vdiskmanager -c -s "${disk}GB" -a lsilogic -t 1 "$dir/${name}.vmdk" 2>/dev/null
cat > "$vmx" <<EOF
config.version = "8"
virtualHW.version = "11"
numvcpus = "2"
memsize = "$((mem*1024))"
displayName = "$name"
guestOS = "vmkernel6"
vhv.enable = "TRUE"
scsi0.present = "TRUE"
scsi0.virtualDev = "lsilogic"
scsi0:0.present = "TRUE"
scsi0:0.fileName = "${name}.vmdk"
ide1:0.present = "TRUE"
ide1:0.fileName = "$(realpath "$iso")"
ide1:0.deviceType = "cdrom-image"
ethernet0.present = "TRUE"
ethernet0.connectionType = "nat"
ethernet0.virtualDev = "e1000"
ethernet0.wakeOnPcktRcv = "FALSE"
ethernet0.linkStatePropagation.enable = "TRUE"
vmci0.present = "TRUE"
hpet0.present = "TRUE"
tools.syncTime = "TRUE"
pciBridge0.present = "TRUE"
pciBridge4.present = "TRUE"
pciBridge4.virtualDev = "pcieRootPort"
pciBridge4.functions = "8"
pciBridge5.present = "TRUE"
pciBridge5.virtualDev = "pcieRootPort"
pciBridge5.functions = "8"
pciBridge6.present = "TRUE"
pciBridge6.virtualDev = "pcieRootPort"
pciBridge6.functions = "8"
pciBridge7.present = "TRUE"
pciBridge7.virtualDev = "pcieRootPort"
pciBridge7.functions = "8"
EOF
vmrun start "$vmx" nogui
vm_ip=$(vmrun getGuestIPAddress "$vmx" -wait)
else
export GOVC_DATASTORE=${GOVC_DATASTORE:-$(basename "$(govc ls datastore)")}
if [ "$(govc about -json | jq -r .About.ProductLineId)" == "embeddedEsx" ] ; then
policy=$(govc host.portgroup.info -json | jq -r ".Portgroup[] | select(.Spec.Name == \"$network\") | .Spec.Policy.Security")
if [ -n "$policy" ] && [ "$(jq -r <<<"$policy" .AllowPromiscuous)" != "true" ] ; then
echo "Enabling promiscuous mode for $network on $(govc env -x GOVC_URL_HOST)..."
govc host.portgroup.change -allow-promiscuous "$network"
fi
fi
boot=$(basename "$iso")
if ! govc datastore.ls "$boot" > /dev/null 2>&1 ; then
govc datastore.upload "$iso" "$boot"
fi
echo "Creating vm ${name}..."
govc vm.create -on=false -net "$network" -m $((mem*1024)) -c 2 -g "$guest" -net.adapter=vmxnet3 -disk.controller pvscsi "$name"
echo "Adding a second nic for ${name}..."
govc vm.network.add -net "$network" -net.adapter=vmxnet3 -vm "$name"
echo "Enabling nested hv for ${name}..."
govc vm.change -vm "$name" -nested-hv-enabled
echo "Enabling Mac Learning dvFilter for ${name}..."
seq 0 1 | xargs -I% govc vm.change -vm "$name" \
-e ethernet%.filter4.name=dvfilter-maclearn \
-e ethernet%.filter4.onFailure=failOpen
echo "Adding cdrom device to ${name}..."
id=$(govc device.cdrom.add -vm "$name")
echo "Inserting $boot into $name cdrom device..."
govc device.cdrom.insert -vm "$name" -device "$id" "$boot"
if [ -n "$standalone" ] ; then
echo "Creating $name disk for use by ESXi..."
govc vm.disk.create -vm "$name" -name "$name"/disk1 -size "${disk}G"
fi
echo "Powering on $name VM..."
govc vm.power -on "$name"
echo "Waiting for $name ESXi IP..."
vm_ip=$(govc vm.ip "$name")
! govc events -n 100 "vm/$name" | grep -E 'warning|error'
fi
esx_url="root:@${vm_ip}"
echo "Waiting for $name hostd (via GOVC_URL=$esx_url)..."
while true; do
if govc about -u "$esx_url" 2>/dev/null; then
break
fi
printf "."
sleep 1
done
if [ -z "$standalone" ] ; then
# Create disk for vSAN after boot so they are unclaimed
echo "Creating $name disks for use by vSAN..."
govc vm.disk.create -vm "$name" -name "$name"/vsan-cache -size "$((disk/2))G"
govc vm.disk.create -vm "$name" -name "$name"/vsan-store -size "${disk}G"
fi
# Set target to the ESXi VM
GOVC_URL="$esx_url"
if [ -z "$standalone" ] ; then
echo "Rescanning ${name} HBA for new devices..."
disk=($(govc host.storage.info -rescan | grep /vmfs/devices/disks | awk '{print $1}' | sort))
echo "Marking ${name} disk ${disk[0]} as SSD..."
govc host.storage.mark -ssd "${disk[0]}"
echo "Marking ${name} disk ${disk[1]} as HDD..."
govc host.storage.mark -ssd=false "${disk[1]}"
fi
echo "Enabling MOB for ${name}..."
govc host.option.set Config.HostAgent.plugins.solo.enableMob true
echo "Configuring NTP for ${name}..."
govc host.date.change -server 0.pool.ntp.org
for id in TSM TSM-SSH ntpd ; do
printf "Enabling service %s for ${name}...\n" $id
govc host.service enable $id
govc host.service start $id
done
if [ -z "$username" ] ; then
username=root
action="update"
else
action="create"
fi
echo "Disabling VSAN device monitoring for ${name}..."
govc host.esxcli system settings advanced set -o /LSOM/VSANDeviceMonitoring -i 0
# A setting of 1 means that vSwp files are created thin, with 0% Object Space Reservation
govc host.esxcli system settings advanced set -o /VSAN/SwapThickProvisionDisabled -i 1
govc host.esxcli system settings advanced set -o /VSAN/FakeSCSIReservations -i 1
echo "ESX host account $action for user $username on ${name}..."
govc host.account.$action -id $username -password "$password"
echo "Granting Admin permissions for user $username on ${name}..."
govc permissions.set -principal $username -role Admin
echo "Enabling guest ARP inspection to get vm IPs without vmtools on ${name}..."
govc host.esxcli system settings advanced set -o /Net/GuestIPHack -i 1
echo "Opening firewall for serial port traffic for ${name}..."
govc host.esxcli network firewall ruleset set -r remoteSerialPort -e true
echo "Setting hostname for ${name}..."
govc host.esxcli system hostname set -H "$name"
if which sshpass >/dev/null && [ -e ~/.ssh/id_rsa.pub ] ; then
echo "Adding ssh authorized key to ${name}..."
sshpass -p "$password" scp \
-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=error \
~/.ssh/id_rsa.pub "root@$vm_ip:/etc/ssh/keys-root/authorized_keys"
fi
echo "Done: GOVC_URL=${username}:${password}@${vm_ip}"

View File

@@ -1,144 +0,0 @@
#!/bin/bash -e
# Copyright 2017-2018 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.
#
# Create a VCSA VM
usage() {
echo "Usage: $0 [-n VM_NAME] [-i VCSA_OVA] [-a IP] ESX_URL" 1>&2
exit 1
}
export GOVC_INSECURE=1
name=vcsa
# 6.5 U1e (EP5) - https://docs.vmware.com/en/VMware-vSphere/6.5/rn/vsphere-vcenter-server-65u1e-release-notes.html
ova=VMware-vCenter-Server-Appliance-6.5.0.14000-7515524_OVF10.ova
while getopts a:i:n: flag
do
case $flag in
a)
ip=$OPTARG
;;
i)
ova=$OPTARG
;;
n)
name=$OPTARG
;;
*)
usage
;;
esac
done
if [ -d "$ova" ] ; then
ova=$(ls "$ova"/*.ovf)
fi
shift $((OPTIND-1))
if [ $# -ne 1 ] ; then
usage
fi
export GOVC_URL=$1
network=${GOVC_NETWORK:-$(basename "$(govc ls network)")}
product=$(govc about -json | jq -r .About.ProductLineId)
# Use the same password as GOVC_URL
password=$(govc env GOVC_PASSWORD)
if [ -z "$password" ] ; then
echo "password not set"
exit 1
fi
opts=(
cis.vmdir.password=$password
cis.appliance.root.passwd=$password
cis.appliance.root.shell=/bin/bash
cis.deployment.node.type=embedded
cis.vmdir.domain-name=vsphere.local
cis.vmdir.site-name=VCSA
cis.appliance.net.addr.family=ipv4
cis.appliance.ssh.enabled=True
cis.ceip_enabled=False
cis.deployment.autoconfig=True
)
if [ -z "$ip" ] ; then
mode=dhcp
ntp=0.pool.ntp.org
else
mode=static
# Derive net config from the ESX server
config=$(govc host.info -k -json | jq -r .HostSystems[].Config)
gateway=$(jq -r .Network.IpRouteConfig.DefaultGateway <<<"$config")
dns=$(jq -r .Network.DnsConfig.Address[0] <<<"$config")
ntp=$(jq -r .DateTimeInfo.NtpConfig.Server[0] <<<"$config")
route=$(jq -r ".Network.RouteTableInfo.IpRoute[] | select(.DeviceName == \"vmk0\") | select(.Gateway == \"0.0.0.0\")" <<<"$config")
prefix=$(jq -r .PrefixLength <<<"$route")
opts+=(cis.appliance.net.addr=$ip
cis.appliance.net.prefix=$prefix
cis.appliance.net.dns.servers=$dns
cis.appliance.net.gateway=$gateway)
fi
opts+=(
cis.appliance.ntp.servers="$ntp"
cis.appliance.net.mode=$mode
)
if [ "$product" = "ws" ] ; then
# workstation does not suport NFC
dir=$(govc datastore.info -json | jq -r .Datastores[0].Info.Url)
ovftool --name="$name" --acceptAllEulas "$ova" "$dir"
vmx="$name/${name}.vmx"
printf "guestinfo.%s\n" "${opts[@]}" >> "$dir/$vmx"
govc vm.register "$vmx"
govc vm.network.change -vm "$name" -net NAT ethernet-0
else
props=$(printf -- "guestinfo.%s\n" "${opts[@]}" | \
jq --slurp -R 'split("\n") | map(select(. != "")) | map(split("=")) | map({"Key": .[0], "Value": .[1]})')
cat <<EOF | govc import.${ova##*.} -options - "$ova"
{
"Name": "$name",
"Deployment": "tiny",
"DiskProvisioning": "thin",
"IPProtocol": "IPv4",
"Annotation": "VMware vCenter Server Appliance",
"PowerOn": false,
"WaitForIP": false,
"InjectOvfEnv": true,
"NetworkMapping": [
{
"Name": "Network 1",
"Network": "${network}"
}
],
"PropertyMapping": $props
}
EOF
fi
govc vm.power -on "$name"
govc vm.ip "$name"

View File

@@ -1,63 +0,0 @@
#!/bin/bash -e
#
# Capture ESXi traffic and decrypt SOAP traffic on port 443 via wireshark
# Device to capture
dev="${1-vmk0}"
# Device to get the ip for wireshark ssl_keys config
if [ "$dev" = "lo0" ] ; then
ip_dev="vmk0"
else
ip_dev="$dev"
fi
ip=$(govc host.info -k -json | \
jq -r ".HostSystems[].Config.Network.Vnic[] | select(.Device == \"${ip_dev}\") | .Spec.Ip.IpAddress")
scp=(scp)
ssh=(ssh)
# Check if vagrant ssh-config applies to $ip
if [ -d ".vagrant" ] ; then
vssh_opts=($(vagrant ssh-config | awk NF | awk -v ORS=' ' '{print "-o " $1 "=" $2}'))
if grep "HostName=${ip}" >/dev/null <<<"${vssh_opts[*]}" ; then
ssh_opts=("${vssh_opts[@]}")
fi
fi
# Otherwise, use default ssh opts + sshpass if available
if [ ${#ssh_opts[@]} -eq 0 ] ; then
user="$(govc env GOVC_USERNAME)"
ssh_opts=(-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=FATAL -o User=$user)
if [ -x "$(which sshpass)" ] ; then
password="$(govc env GOVC_PASSWORD)"
scp=(sshpass -p $password scp)
ssh=(sshpass -p $password ssh)
fi
fi
if [ "$dev" != "lo0" ] ; then
# If you change this filter, be sure to exclude the ssh port (not tcp port 22)
filter="host $ip and \(port 80 or port 443\)"
dst="$HOME/.wireshark/rui-${ip}.key"
if [ ! -f "$dst" ] ; then
# Copy key from ESX
"${scp[@]}" "${ssh_opts[@]}" "${ip}:/etc/vmware/ssl/rui.key" "$dst"
fi
if ! grep "$ip" ~/.wireshark/ssl_keys 2>/dev/null ; then
# Add key to wireshark ssl_keys config
echo "adding rui.key for $ip"
cat <<EOF >> ~/.wireshark/ssl_keys
"$ip","443","http","$dst",""
EOF
fi
fi
echo "Capturing $dev on $ip..."
"${ssh[@]}" "${ssh_opts[@]}" "$ip" tcpdump-uw -i "$dev" -s0 -v -w - "$filter" | wireshark -k -i -

View File

@@ -1,64 +0,0 @@
#!/bin/bash -e
#
# Capture SOAP traffic between web client and vpxd on 127.0.0.1:8085.
#
# Caveats: tested with VCSA 6.0, unlikely to work for other versions.
#
set -e
cache_deb() {
wget $1
ar x *.deb data.tar.gz
tar zxf data.tar.gz
rm -f data.tar.gz
rm -f *.deb
}
dirname="$(dirname $0)"
basename="$(basename $0)"
bindir="${dirname}/.${basename}"
mkdir -p "${bindir}"
# Cache binaries required to run tcpdump on vcsa
if [ ! -f "${bindir}/.done" ]; then
pushd ${bindir}
cache_deb https://launchpadlibrarian.net/200649143/libssl0.9.8_0.9.8k-7ubuntu8.27_amd64.deb
cache_deb https://launchpadlibrarian.net/37430984/libpcap0.8_1.0.0-6_amd64.deb
cache_deb https://launchpadlibrarian.net/41774869/tcpdump_4.0.0-6ubuntu3_amd64.deb
touch .done
popd
fi
scp=(scp)
ssh=(ssh)
# Extract host from GOVC_URL
host="$(govc env -x GOVC_HOST)"
username=root
password="$(govc env GOVC_PASSWORD)"
if [ -x "$(which sshpass)" ] ; then
scp=(sshpass -p "$password" scp)
ssh=(sshpass -p "$password" ssh)
fi
ssh_opts=(-o UserKnownHostsFile=/dev/null
-o StrictHostKeyChecking=no
-o LogLevel=FATAL
-o User=${username}
-o ControlMaster=no)
dev="lo"
filter="port 8085"
tcpdump="env LD_LIBRARY_PATH=/tmp /tmp/tcpdump"
echo "Capturing $dev on $host..."
"${scp[@]}" "${ssh_opts[@]}" \
"${bindir}/lib/libcrypto.so.0.9.8" \
"${bindir}/usr/lib/libpcap.so.0.8" \
"${bindir}/usr/sbin/tcpdump" \
"${host}:/tmp"
"${ssh[@]}" "${ssh_opts[@]}" "$host" ${tcpdump} -i "$dev" -s0 -v -w - "$filter" | wireshark -k -i - 2>/dev/null