Skip to content

Commit

Permalink
add nsxv cli tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ogrand committed Jul 19, 2019
1 parent b65d130 commit 97f1aef
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ENV BBR_VERSION="1.5.0" \
BUNDLER_VERSION="1.17.3" \
CF_CLI_VERSION="6.45.0" \
CF_UAAC_VERSION="4.1.0" \
CREDHUB_VERSION="2.2.1" \
CREDHUB_VERSION="2.5.2" \
DB_DUMPER_VERSION="1.4.2" \
FLY_VERSION="5.3.0" \
HELM_VERSION="2.14.0" \
Expand Down
85 changes: 85 additions & 0 deletions bosh-cli/init-pynsxv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash
#===========================================================================
# Init pynsxv cli configuration
#===========================================================================

#--- Colors and styles
export RED='\033[1;31m'
export YELLOW='\033[1;33m'
export STD='\033[0m'
export REVERSE='\033[7m'

#--- Display information
display() {
case "$1" in
"INFO") printf "\n%b%s...%b\n" "${REVERSE}${YELLOW}" "$2" "${STD}" ;;
"ERROR") printf "\n%bERROR: %s.%b\n\n" "${REVERSE}${RED}" "$2" "${STD}" ; exit 1 ;;
esac
}

#--- Get a parameter in credhub
getCredhubValue() {
value=$(credhub g -n $2 | grep 'value:' | awk '{print $2}')
if [ "${value}" = "" ] ; then
printf "\n\n%bERROR : \"$2\" credhub value unknown.%b\n\n" "${RED}" "${STD}" ; flagError=1
else
eval "$1=${value}"
fi
}

#--- Catch a parameter
catchValue() {
flag=0
while [ ${flag} = 0 ] ; do
printf "\n%b%s :%b " "${REVERSE}${GREEN}" "$2" "${STD}" ; read value
if [ "${value}" != "" ] ; then
flag=1
fi
done
eval "$1=${value}"
}

#--- Check prerequisistes
if [ "${iaas_type}" != "vsphere" ] ; then
display "ERROR" "pynsxv is only available for vsphere context"
fi

#--- Log to credhub
log-credhub.sh

#--- Delete unused mc aliases
display "INFO" "Configure pynsxv cli..."

getCredhubValue "VCENTER_IP" "/secrets/vsphere_vcenter_ip"
getCredhubValue "VCENTER_USER" "/secrets/vsphere_vcenter_user"
getCredhubValue "VCENTER_PASSWORD" "/secrets/vsphere_vcenter_password"
getCredhubValue "VCENTER_DATACENTER" "/secrets/vsphere_vcenter_dc"
getCredhubValue "VCENTER_DATASTORE" "/secrets/vsphere_vcenter_ds"
getCredhubValue "VCENTER_CLUSTER" "/secrets/vsphere_vcenter_cluster"

catchValue "NSX_MANAGER_IP" "NSX manager ip"
catchValue "NSX_PASSWORD" "NSX admin password"
catchValue "TRANSPORT_ZONE" "NSX transport zone"

#--- Create configuration file for nsxv cli
cat > $HOME/.nsx.ini <<EOF
# Uncomment the above section and add the path to the raml spec you want to use instead of the bundled version
# [nsxraml]
# nsxraml_file = ${NSX_RAML_FILE}
[nsxv]
nsx_manager = ${NSX_MANAGER_IP}
nsx_username = admin
nsx_password = ${NSX_PASSWORD}
[vcenter]
vcenter = ${VCENTER_IP}
vcenter_user = ${VCENTER_USER}
vcenter_passwd = ${VCENTER_PASSWORD}
[defaults]
transport_zone = ${TRANSPORT_ZONE}
datacenter_name = ${VCENTER_DATACENTER}
edge_datastore = ${VCENTER_DATASTORE}
edge_cluster = ${VCENTER_CLUSTER}
EOF
2 changes: 2 additions & 0 deletions bosh-cli/profile
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ alias diff='colordiff'
alias f='function __f() { printf "\n";find . ! -regex ".*[/]\.git[/]?.*" -type f -print0 | xargs -0 grep -I -i --color "$1";unset -f __f;printf "\n"; }; __f'
alias fly='fly -t concourse'
alias init-mc='. init-mc.sh'
alias init-pynsxv='. init-pynsxv.sh'
alias os='openstack'
alias proxy='. proxy.sh'
alias prune-workers='fly prune-worker -a'
alias pynsxv='pynsxv -i $HOME/.nsx.ini'
alias show-cert='function __scrt() { openssl x509 -noout -in $1 -subject -issuer -dates; }; __scrt'
alias show-csr='function __scsr() { openssl req -noout -text -in $1; }; __scsr'
alias switch='. switch.sh'
Expand Down
1 change: 1 addition & 0 deletions bosh-cli/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ printf "%bCLI TOOLS%b\n" "${GREEN}${BOLD}${REVERSE}" "${STD}"
display "credhub-get" "Get credhub propertie value"
display "go3fr" "S3 cli"
display "init-mc" "Init mc config for minio access"
display "init-pynsxv" "Init pynsxv config for nsx-v access"
display "log-cf" "Log with cf cli"
display "log-credhub" "Log with credhub cli"
display "log-fly" "Log with concourse cli"
Expand Down

0 comments on commit 97f1aef

Please sign in to comment.