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.

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.

  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

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.

import purestorage
from purestorage import FlashArray

# Never do this in prod. SSL warning are there for a reason.
import urllib3
urllib3.disable_warnings()

#Variables
fa_url = "myarray.fqdn"
fa_username = "pureuser"
fa_password = "pureuser"

#Start Session
array = FlashArray(fa_url, fa_username, fa_password)

#Create Volume
array.create_volume("david-python-vol01", "10G")

#Create Hosts
array.create_host("david-python-host1", iqnlist=["iqn.1998-01.com.vmware:david-python-host1"])
array.create_host("david-python-host2", iqnlist=["iqn.1998-01.com.vmware:david-python-host2"])

#Create Host Group and Add Host1 and Host2
array.create_hgroup("david-python-hostgroup", hostlist=["david-python-host1", "david-python-host2"])

#Connect Volume to Host Group
array.connect_hgroup("david-python-hostgroup", "david-python-vol01")

#End Session
array.invalidate_cookie()
python

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

#imports
from purepyvmware import base_connector
from purepyvmware import datastores

#Variables
fa_url = "myarray.fqdn"
fa_username = "pureuser"
vc_url = "vc.lab.local"
vc_username = "[email protected]"
vc_cluster = "cluster01"

#Start Session
connector = base_connector.BaseConnector(fa_url, fa_username, vc_url, vc_username, verify_ssl=False)
flasharray = connector.fa_instance

#Create Datastore
vmfs_mgr = datastores.VmfsDatastores(vsphere_content, flasharray)
vmfs_ds = vmfs_mgr.create_vmfs_datastore(vc_cluster, 'python_vc01-ds01', 500)
python

The above examples can be found here

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.