This post is part of the Automating your Pure Storage Infrastructure series.
    Using Python to Provision your Pure Storage Infrastructure

Using Python to Provision your Pure Storage Infrastructure

Share on:

In the continuation of my Automating your Pure Storage Infrastructure blog series, next I will be covering how to use Python to provision your Pure Storage Infrastructure.

This post has been updated on 8/25/20 to include information about the recently released Pure Storage Python Module. Learn more over at JHOP’s blog.

Information on the Pure Storage Python Package

The official site has information on the package and the quickstart is a great place on how to learn to use the Pure Storage package.

Installing and Setting up the Python Package

  1. Install Python3
  2. Install Pure Storage Python package by running pip3 install purestorage
  3. Install Pure Storage VMware Python SDK by running python3 -m pip install purepyvmware

Using Python to Provision your Pure Storage Infrastructure

Below is a sample python script using the Pure Storage FlashArray Python Module* that will create a volume, two hosts with an ISCSI iqn and then add the hosts and volume to a hostgroup.

 1import purestorage
 2from purestorage import FlashArray
 3
 4# Never do this in prod. SSL warning are there for a reason.
 5import urllib3
 6urllib3.disable_warnings()
 7
 8#Variables
 9fa_url = "myarray.fqdn"
10fa_username = "pureuser"
11fa_password = "pureuser"
12
13#Start Session
14array = FlashArray(fa_url, fa_username, fa_password)
15
16#Create Volume
17array.create_volume("david-python-vol01", "10G")
18
19#Create Hosts
20array.create_host("david-python-host1", iqnlist=["iqn.1998-01.com.vmware:david-python-host1"])
21array.create_host("david-python-host2", iqnlist=["iqn.1998-01.com.vmware:david-python-host2"])
22
23#Create Host Group and Add Host1 and Host2
24array.create_hgroup("david-python-hostgroup", hostlist=["david-python-host1", "david-python-host2"])
25
26#Connect Volume to Host Group
27array.connect_hgroup("david-python-hostgroup", "david-python-vol01")
28
29#End Session
30array.invalidate_cookie()

Below is an example of using the Pure Storage VMware Python Module to provision a Datastore to your Cluster.

 1#imports
 2from purepyvmware import base_connector
 3from purepyvmware import datastores
 4
 5#Variables
 6fa_url = "myarray.fqdn"
 7fa_username = "pureuser"
 8vc_url = "vc.lab.local"
 9vc_username = "[email protected]"
10vc_cluster = "cluster01"
11
12#Start Session
13connector = base_connector.BaseConnector(fa_url, fa_username, vc_url, vc_username, verify_ssl=False)
14flasharray = connector.fa_instance
15
16#Create Datastore
17vmfs_mgr = datastores.VmfsDatastores(vsphere_content, flasharray)
18vmfs_ds = vmfs_mgr.create_vmfs_datastore(vc_cluster, 'python_vc01-ds01', 500)

GitHub Repo with Samples

The above examples can be found here

Closing

Python is a great tool when it comes to getting your environment, as I stated before it is great that the Pure Storage array integrates with so many scripting languages and Python is just another one of those.

Any questions or comments? Leave them below.

comments powered by Disqus