Creating a Python Script from Scratch

By on 04/22/2015.

Over the the next several weeks I will be posting a new series of articles focused around the Python programming language. The simple goal of the series will be to enable you to take advantage of Python to make your life easier in some form or another.

I am by no stretch of the imagination a ‘developer’ but I am a firm believer in automating anything that you have to do more than twice. This is where Python shines. It’s simple syntax and active community allows anyone to easily and quickly create any manor of scripts and utilities for their tool chest. There are also a plethora of SDKs, APIs, and DevOps tools written in Python that can be taken advantage of once the basics of Python are understood.

In my experience the easiest way to learn a new programming language is by actually coding something relevant. For the purpose of this series we will be taking a request from the VMware vExpert community.

When I initially saw the tweet from Chris I thought to myself ‘it should be easy enough to accomplish that in Python’ and sure enough within an hour I had a basic prototype up and running. Since then I have been slowly adding features and in its current state the script will report blocked ports and the services that are being affected.

If you are already familiar with Python but would like more practice take a look at the vphere-port-scan repo hosted on the newly created DatacenterDudes organization on GitHub. See what code you can improve on or review the ‘Features in Development’ section of the README and see what progress you can make on adding features.

For those of you just getting started in Python (or programming in general) I will be walking through the code step by step and overviewing the process I took to get the script to its current form in subsequent articles. By working through the step-by-step process we will have the opportunity to review:

  • external libraries
  • variables
  • functions
  • lists
  • dictionaries
  • conditional statements
  • loops
  • gathering user input
  • and more

If you do not already have an account on GitHub take a few minutes to get one created and be sure to watch the vsphere-port-scan repo to stay up to date on the latest changes.

Stay tuned for our first walkthrough of the code!

Drew Russell
As a member of the World Wide Technology (WWT) Professional Services Data Center team, Drew Russell has the opportunity to see first hand what is currently being discussed and deployed in the environments of some of the largest organizations in the country. When not traveling, you can often find Drew in WWTs Advanced Technology Center (ATC) vetting the latest product offerings from the OEMs.

2 Comments