Milestone4.1:PyvMomi - echadbourne/SYS-350 GitHub Wiki
Prerequisites
Start by installing PivMomi, vscode, and git:
sudo apt updatesudo apt install python3-pipsudo apt install git
Install as logged in user:
pip3 install wheelpip3 install pyvmomipip3 install pyvim
Visual Studio:
sudo snap install code --classic
Something you can use to help with getting certain things from vcenter with pyvimomi later is going to the vcenter address/mob and signing in
Set up git
SSH Connection
These instructions are taken from the Ubuntu Git Repo Connection wiki entry in my SYS-320 class repo. In that class we did this as a super user, in this one this is done as just the logged in user to ensure visual studio worked as intended
Generate SSH keys: ssh-keygen -t ed25519 -C "[email"
- It will ask for a passphrase, enter and remember this
Make note of where the keys are going, the path might be different than the root used below
Check is the SSH client is running with eval "$(ssh-agent) -s)"
Add your ssh private key to the aah-agent (if you used a different name insert that instead of "id_ed35529"
ssh-add /root/.ssh/id_ed25519> enter passphrase
Check that the path is correctly set for the logged in user
cat /root/.ssh/id_ed25519 and copy the output
Log into github > settings > SSH or GPG key > Add a new one, paste the output from above
Test the connection with ssh -T [email protected]
Git Stuff
Clone the repo with git clone [repo ssh link]
Set up email and username with:
git config --global user.email "[email]"git config --global user.name "[name]"
Add, commit, push as needed!
Coding
Because all the code is already in this repo, this will just be a reflection section
VConnect
For this section I needed to figure out how to use a json file, which I had never done before. I started with import json to be able to use the information contained in my json file, then opened it and loaded the information to python usable variables:
Because I was also using passw = getpass.getpass() to securely get the password as a variable, I then was able to just use this for the SmartConnect function:
SmartConnect(host=vhost, user=vadmin, pwd=passw, sslContent=s)
the
svariable specifies the SSL protocol, which was earlier defined ass = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
From there I was able to get all of the applicable information by using si.[thing], which was even used later in other parts of this lab. I actually had done enough foundational work in this document that I ended up importing it to the other as well to be able to use their variables.
References
For this section my only references are in class resources (the demonstration video) and help from the professor
VSession
This one involved getting information from both the management box and the vcenter box, I ended up using getpass and socket to grab information from the management box, and Natalie pointed me in the right direction of where to find the domain user, because I was not able to do that on my own. As I expected it was a simple thing, just content > sessionManager > currentSession > userName but I would not have known where to look for that.
The vcenter host name is just pulled from the json file like in vconnect.
References
https://www.geeksforgeeks.org/display-hostname-ip-address-python/
VDetail
This one definitely took the longest. My biggest struggle here was parsing all of the community samples we were given and making them make sense in my brain. It seemed like most of them were overcomplicating things in a way they did not need to be overcomplicated, and I think the biggest overall challenge was tracking where this info was even coming from in the first place. I took a look at a few different things, and asked a classmate questions to help me understand what was going on (yay Natalie!) and I think I have a good understanding of how everything works now. For me the learning curve was definitely understanding the examples and writing it my own way that made sense to me.
References
https://vthinkbeyondvm.com/pyvmomi-tutorial-how-to-get-all-the-core-vcenter-server-inventory-objects-and-play-around/ https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/getvnicinfo.py
VM-Utils
This gave me no problems. It pulls from all of the other files that each contain their own set of functions that do whatever they need to do, and puts it together in this pretty little package that the user can use to query for information. This was the one part of this project that made sense to me right out of the box.
pfSense VMtools
I was having some problems getting my pfsense firewall to get packages in the package manager, and when I went to update the package repo I was getting a ssl certificate problem when I ran
pkg-static -d updateTo fix this I rancertctl rehash, thenpkg-static -d updateagain, and it worked! I was successfully able to update the package repo on my pfsense, and I found the vm-tools package that I needed
Go to the Package Manager in the pfSense GUI > Available Packages > Search for "vm" and select "Open-VM-Tools"
And now vmtools is installed on pfSense!
References
https://forum.netgate.com/topic/185510/certificate-error-while-running-pkg-update-2024/2