It was been too long since I have written a new post and wish I had time to do this more often. I will say though that this post has me both very excited and very nervous.
As most people are aware Cody Hosterman has created an in-depth PowerShell module for integration between Pure Storage and VMware products. The challenge is that this product is for admins that have Windows installed within their environment and are familiar with PowerShell. Because his module has had such great success, with a lot of people referring to it often, we thought it would be a good idea to spread the joy to other Operating Systems! As a result, for the past several months, I have been working on a Python module that brings together both the Pure Storage and VMware APIs that allows for common workflows and automation to be performed within Unix / Linux platforms! I present to you the
purepyvmware Python module.
As I said previously this is both an exciting and nervous time for me because this is my first ever Open Source project. I am also relatively new to Python development and so this has really caused me to stretch my wings and grow a lot more! Luckily I have had some excellent mentors along the way to make sure things were done with the future in mind, ensuring it is all Object Oriented, and a solid framework.
So, without further ado….. let’s take a look at it shall we?!
All right, the first thing to cover are the requirements so you know what to expect.
– Python: 3.6 or higher
– purestorage SDK: 1.18.0 or higher
– pyvmomi: 6.7.3 or higher
Due to Python 2.x being largely deprecated and the world moving heavily towards Python 3.x it was decided that this would only be developed in Python 3. The primary reason for 3.6 and later is simply due to the use of f-strings for cleaner string formatting.
NOTE: If you follow the installation steps outlined below all of the Python requirements / dependencies will be installed along with the module. So there should be no action on your part unless you need to customize anything.
– vCenter / ESXi: 6.5 or higher
Since VMware officially stopped supporting vSphere 6.0 it was decided to develop the modules with vSphere 6.5 and later in mind. While most of the available modules will likely work in 6.0, it is not guaranteed. If some actions fail in 6.0, but work in 6.5 and later, there will be no fixes implemented to support that version. So please be aware of this should you decide to try with vSphere 6.0 and lower. I wanted to create something that would be beneficial for as many users as possible but felt it should also be targeted with the future in mind. Thus I felt that using VMware’s official announcement for End of General Support of 6.0 was an appropriate version for cut off.
Pure Storage Requirements:
– Purity 4.10 or later
While the restriction is Purity 4.10 or later you must keep in mind that this would only be for tasks that are NOT vVol related. If you attempt vVol operations on any version less than Purity 5.0 then expect some of the calls to fail. That said, If you are running vVols within your env you really should be running Purity 5.1.15 or later… with the recommendation being Purity 5.3.8.
There are two ways to install the
The first is by simply using
pip, as noted below:
python3 -m pip install purepyvmware
As I explained previously this is my first time providing Open Source code, so there has been a little bit of a learning curve. One of those is learning that when you upload Wheel files to PyPI they are Immutable. If you look at the purepyvmware module on PyPI you will notice that the ‘Description’ is not really readable (facepalm). I wasn’t aware of the formatting guidelines for PyPI so while it was parsing the README it turned out quite ugly. I tried to fix it and replace the file but I have to “up-version” to fix it, so when my first round of fixes are released this will be resolved. In the meantime GitHub has the prettier version for reference.
Which brings us to the next way you can install the module, via GitHub:
$ git clone https://github.com/PureStorage-OpenConnect/PureStorage-VMware-Python-SDK.git $ cd PureStorage-VMware-Python-SDK $ python3 -m pip install -r requirements.txt $ python setup.py install
Obviously the easiest way is via a pip install, but want to provide users with the flexibility to install however they feel is best for their environment.
What does it do?
The initial release is a very limited product. It will not remain this way for long as the goal is get this to be continually adding functionality for deeper integration. This means that the more people that use the module and provide feedback for desired integrations and improvements the better! This will help push development forward if it is found there is a real need / desire for this product!
As stated above, this is not a long list at this time. But will be expanding this in the future:
– Connecting to the Pure Storage and VMware Environments.
– Creating a VMFS-5, VMFS-6 or vVol datastore.
– Registering a Pure Storage FlashArray as a storage provider (vVol).
– Reporting all Pure Storage volumes connected to a vCenter Server.
Along with these integrations I also implemented the framework for logging so that debugging will be easier for end-users and, when problems arise, a log file can simply be provided for assistance in troubleshooting the issue. The logging is not yet implemented but that will be coming in version 1.0.1.
Connecting to the FlashArray and vCenter Server
Once the module has been successfully installed you can start to use it! I will provide several examples of how you can use the module to get things started.
Until the front-end work has been completed for this module you will need to use something like iPython to interact with it (unless you want to write your own front-end 🙂 ) :
The first step is to connect with the Pure Storage FlashArray and vCenter Environment that you wish to interact with:
In : from purepyvmware import base_connector
In : connector = base_connector.BaseConnector('10.21.186.x', 'pureuser', '10.21.186.x', 'kramerica\jhop', verify_ssl=False)
As you will note above I was prompted for both the
FlashArray Password and the
vSphere Password. That is because I didn’t want to type my password in plain-text for others to see so I omitted those optional parameters. Additionally, I set
verify_ssl to false because I do not have my certificates setup in my lab environment. If you want to use valid certificates within your env, instead of self-signed, then you can simply omit that option.
Additionally, if you don’t mind typing your password in plain-text you can specify the optional parameters as follows:
In : connector = base_connector.BaseConnector('10.21.186.x', 'pureuser', '10.21.186.x', 'kramerica\jhop', fa_passwd='password', vcenter_passwd='password', verify_ssl=False)
Lastly, if you want to use the API token from the FlashArray you also have that option as well.
In : connector = base_connector.BaseConnector('10.21.186.x', None, '10.21.186.x', 'kramerica\jhop', api_token='token', vcenter_passwd='password', verify_ssl=False)
NOTE: Notice that
fa_usr is required, so if you are using the token be sure to specify
None for the name. This will be fixed in the next version where it is only username/password or token only. This was noticed just after releasing this out into the wild.
Reporting Pure Storage Datastores
Once you have authenticated you can then start performing other tasks, such as gathering all Pure Storage Datastores from the vCenter Server:
In : from purepyvmware import datastores
In : flasharray = connector.fa_instance
In : vsphere_content = connector.vsphere_content
In : ds_mgr = datastores.Datastores(vsphere_content, flasharray)
In : pure_datastores = ds_mgr.get_all_pure_datastores()
Notice that I created a “datastore manager”
(ds_mgr) using the class
Datastores under my datastores module. Once that class has been instantiated I can then query the datastores connected to the vCenter Server.
Now that we have the datastores let’s take a look at them:
In : pure_datastores
Notice that the datastores are returned in a list as
vim.Datastore objects! If you recall previously it was stated that this module is being developed for Object Oriented programming. This means that the modules will do very little (if any) manipulation of the data it receives back from the vCenter / SMS and FlashArray environments. I don’t want to assume what data you want or need. Thus by returning the objects you, as the user, get to manipulate that data however you want.
So if you wanted to know their names, it is just as simple as:
In : for datastore in pure_datastores:
Creating a VMFS Datastore
Next thing to cover is creating a VMFS datastore.
In : vmfs_mgr = datastores.VmfsDatastores(vsphere_content, flasharray)
In : vmfs_ds = vmfs_mgr.create_vmfs_datastore('Mayberry', 'new_vmfs_ds', 500)
You’ll notice above that I created a “VMFS manager” (
vmfs_mgr) and it is associated with the sub-class
VmfsDatastores. Anything that is specific to VMFS only tasks will be located under this sub-class. I wanted to point this out because to list ALL of the datastores (as we did above) isn’t specific to just VMFS or vVols. So that is why it is under the generic
By breaking the code out into 3 main parts for datastores (
Datastores (parent class),
VmfsDatastores (sub-class), and
VvolDatastores (sub-class)) it is easy for you to know where to go to get the data you need.
The parameters that are passed in are the name of the ESXi cluster, the name of the datastore, and the size (
int) in GB that you want it to be. There is also an optional parameter (
vmfs_version) that you can specify if you don’t want the default version for whatever ESXi version you are on.
Again, if we look at the output for
vmfs_ds it is the actual
In : vmfs_ds Out: 'vim.Datastore:datastore-5021'
Creating a vVol Datastore
The last thing I will show here is how to create a vVol datastore. It is very similar to the VMFS datastore, with the difference being that we need to ensure we grab our Storage Monitoring Service (SMS) instance. This is the service that vCenter uses for vVol tasks which means no vVol tasks can be completed without it.
In : sms_instance = connector.sms_instance
In : vvol_mgr = datastores.VvolDatastores(sms_instance, vsphere_content, flasharray)
In : vvol_ds = vvol_mgr.create_vvol_datastore('Mayberry', 'my_vvol_ds')
You’ll notice that the SMS instance is instantiated in our
BaseConnector so it is available when / if it is needed. You simply just need to assign a variable to it. Once we have that we can instantiate our
VvolDatastores class and then call our
create_vvol_datastore() method. All that is required here is the ESXi cluster name and the name for the vVol datastore.
There is an optional parameter (
protocol_endpoint_name) but would recommend just leaving that at default unless absolutely required.
Feedback, Questions and Problems
Like any other product out there in the world there are going to be missing features, unexpected problems, and questions about how something works. I sincerely hope that people will take the time to provide this feedback so that this can be a solid product that helps make people’s lives easier so they can focus on other tasks they want or need to. I just ask that the feedback is respectful and professional. I am sure I am not yet to the caliber as many of you folks out there, so if you feel I have something to learn, I want to learn it! I just want to be sure we are all being respectful and kind to one another as we do it. 🙂
The BEST place to provide feedback is by opening issues or requests via the GitHub page (instructions are also in the description). Whenever issues are opened or commented on I will be notified and will work to address these things for you as quickly as possible.
Additionally, you can follow the instructions on GitHub and join the #python channel in our Code slack room and ask questions there! We are always happy to help wherever we can.