CLI Scripting by Miranda Steele, Guest Blogger

I’d like to introduce my first guest blogger, Miranda Steele. Miranda works on our REST API and FlashArray programmability team. She is extremely knowledgeable about our API, CLI and more. I couldn’t be happier having her contribute to my blog.

—————–

Hopefully everyone is aware of our REST API that can be used to script against FlashArray and FlashBlade arrays. And some writers on this blog are big fans of using PowerShell to interact with your Pure products. But what if you’re a simple lover of BASH? This blog post aims to explain some of the CLI scripting utilities that we have built into the Purity CLI. For the most part, all of these utilities exist on the latest Purity//FA and Purity//FB releases.

This post assumes that you are already familiar with the Purity CLI. If you aren’t, check out the CLI section of the user guide to learn more (FlashArray User GuideFlashBlade User Guide).

Getting into the FlashArray

Before we talk about CLI scripting, let’s talk about getting into the array. It’s always possible to enter your password in manually as you’re ssh-ing into the array (or to use a common utility like sshpass to enter your password in for you). But it’s worth mentioning that Purity//FA also has support for configuring a public key. For example if I…

miranda@flasharray001> pureadmin setattr --publickey
Enter key: ssh-rsa AAAAAAAAxAAAAAAxAAAAAAAAAAAxx miranda@pstg.com
Name      Public Key
miranda   ****

Now I can ssh in from the outside without being prompted for a password:

miranda@server$ ssh flasharray001 "purearray list"
Name           ID                                    Version  OS
flasharray001  4d90f65c-11a9-49a3-a54b-09c32e70fe56  5.0.1    Purity//FA

Simple Format Options

Alright, now that we’re able to ssh to our system easily using our public key, the next thing to mention are the CLI format options. These options transform the format of the CLI output in different useful ways.

Format options, for the most part, are common to all CLI commands:

format options: 
  --cli                 display as CLI commands
  --csv                 display as comma-separated values
  --notitle             hide column titles
  --nvp                 display as name-value pairs
  --raw                 display unformatted column titles and data

Let’s say my FlashArray has two volumes, vol1 and vol2. This is what the default “purevol list” output looks like:

miranda@server$ ssh flasharray001 "purevol list"
Name  Size  Source  Created                  Serial
vol1  1G    -       2018-01-17 15:52:02 PST  4D90F65C11A949A300011012
vol2  200M  -       2018-01-17 15:52:08 PST  4D90F65C11A949A300011013

Here’s that same “purevol list” output, with each of the format options.

  • “–csv” displays the output as comma-separated values. Note that it also transforms the values into a more machine-readable format. For example, the “Size” column changes from the human-readable string “1G” to the raw bytes value “1073741824”:
    miranda@server$ ssh flasharray001 "purevol list --csv"
    Name,Size,Source,Created,Serial
    vol1,1073741824,,2018-01-17 15:52:02,4D90F65C11A949A300011012
    vol2,209715200,,2018-01-17 15:52:08,4D90F65C11A949A300011013
  • “–notitle” simply gets rid of the first row of column titles:
    miranda@server$ ssh flasharray001 "purevol list --notitle"
    vol1  1G    -  2018-01-17 15:52:02 PST  4D90F65C11A949A300011012
    vol2  200M  -  2018-01-17 15:52:08 PST  4D90F65C11A949A300011013
  • “–nvp” stands for “name-value pairs”. This means that it returns output where each line takes the format “Key=Value”. One of the biggest advantages of “–nvp” is that your script will continue to work even if a subsequent upgrade adds a new column or changes the order of the columns:
    miranda@server$ ssh flasharray001 "purevol list --nvp"
    Name=vol1
    Size=1073741824
    Source=
    Created=2018-01-17 15:52:02
    Serial=4D90F65C11A949A300011012
    Name=vol2
    Size=209715200
    Source=
    Created=2018-01-17 15:52:08
    Serial=4D90F65C11A949A300011013
  • “–raw” shows the “raw” version of the column titles which can then be passed into the filter and sort options.  Additionally, like “–csv”, it transforms the values into a more machine-readable version.
    miranda@server$ ssh flasharray001 "purevol list --raw"
    name  size        source  created                  serial
    vol1  1073741824  -       2018-01-17 15:52:02 PST  4D90F65C11A949A300011012
    vol2  209715200   -       2018-01-17 15:52:08 PST  4D90F65C11A949A300011013

    Here’s a more interesting example of how the “–raw” flag can show different fields from the default list output:

    miranda@server$ sshpass -p pureuser ssh pureuser@flashblade001 "purefs list"
    Name               Size  Used   Created                  Protocols
    test_rest_fs_2     -     0.00   2018-01-26 13:45:00 PST  nfs
    test_rest_fs_snap  -     0.00   2018-01-26 13:45:11 PST  -
     
    miranda@server$ sshpass -p pureuser ssh pureuser@flashblade001 "purefs list"
    name               provisioned  space.virtual  created     nfs.enabled  smb.enabled  http.enabled
    test_rest_fs_2     0            0              1517003100  True         False        False
    test_rest_fs_snap  0            0              1517003111  False        False        False
     
    miranda@server$ sshpass -p pureuser ssh pureuser@flashblade001 "purefs list --filter \"nfs.enabled='true'\""
    Name            Size  Used   Created                  Protocols
    test_rest_fs_2  -     0.00   2018-01-26 13:45:00 PST  nfs

Note that some of these options can be used together:

miranda@server$ ssh flasharray001 "purevol list --csv --notitle"
vol1,1073741824,,2018-01-17 15:52:02,4D90F65C11A949A300011012
vol2,209715200,,2018-01-17 15:52:08,4D90F65C11A949A300011013

Simple Format Option Examples

Using what you just learned, you can create some pretty interesting commands. For example, you could compile a list of your FlashBlade flashblade001’s blade names and serial numbers, that could be exported into a spreadsheet:

miranda@server$ sshpass -p pureuser ssh pureuser@flashblade001 "purehw list --type fb --spec --csv" | cut -d ',' -f1,7
Name,Serial
CH1.FB1,PBLUC16140E44
CH1.FB2,PBLUC16140E73
CH1.FB3,PBLUC16140DB9
CH1.FB4,PBLUC16140E66
CH1.FB5,PBLUC16140DF0
CH1.FB6,PBLUC16140E48
CH1.FB7,PBLUC16140DDC
CH1.FB8,PBLUC16140E3A
CH1.FB9,PBLUC16140E15
CH1.FB10,PBLUC160509CA
CH1.FB11,PBLUC16090AB6
CH1.FB12,PBLUC16090B1E
CH1.FB13,PBLUC16090A69
CH1.FB14,PBLUC16090ACD
CH1.FB15,PBLUC160509DB

Or, figure out all IP addresses used by your different Pure arrays:

miranda@server$ for i in flasharray001 flashblade001; do sshpass -p pureuser_pw ssh pureuser@$i "purenetwork list --notitle" | cut -d ',' -f4; done
10.8.102.96
10.8.102.220
10.8.102.21
10.8.102.22
10.8.102.230
10.8.102.231
10.8.102.232
10.8.102.233
10.8.102.234
10.8.102.235

Or finally, discover who destroyed your precious volume “vol1”:

miranda@server$ ssh flasharray001 "puremessage list --audit" | grep -E "ID|vol1"
ID   Time                     User         Command      Subcommand      Name       Arguments
63   2018-01-17 15:52:02 PST  miranda      purevol      create          -          --size 1G vol1
116  2018-01-17 16:48:15 PST  joe_sixpack  purevol      destroy         -          vol1
117  2018-01-17 16:48:20 PST  joe_sixpack  purevol      eradicate       -          vol1

The –cli Option

You might have noticed that I skipped the “–cli” option above. I left the “best for last,” because this option is pretty different from the other format options.

The idea behind “–cli” is that it will output the list of CLI commands that you would need to run to reproduce the current configuration. Another way of thinking about it is that it “teaches” you how to use the CLI by showing you what the CLI commands would look like to get to your current state.

So for the same “purevol list” output that we had above, “purevol list –cli” would show:

miranda@server$ ssh flasharray001 "purevol list --cli"
purevol create --size 1G vol1
purevol create --size 200M vol2

So if I ran these two CLI commands on a blank array, I would end up with two volumes called vol1 and vol2, with the same respective sizes as my other array.

I find this command to be the most useful when editing something like the networking configuration. Let’s say I knew I wanted to mess around with flashblade001’s data vips on vlan 1006:

# Store old configuration into a file called "old_config.sh"
miranda@server$ sshpass -p pureuser_pw ssh pureuser@flashblade001 "purenetwork list --cli --vlan 1006" | tee old_config.sh
purenetwork create vip dv01 --address 10.8.102.96 --servicelist data
purenetwork create vip dv02 --address 10.8.102.97 --servicelist data
purenetwork create vip dv03 --address 10.8.102.98 --servicelist data
 
# Delete these data vips, create some other ones, mess around
 
# Finally, I want to put everything back
miranda@server$ sshpass -p pureuser_pw ssh pureuser@flashblade001 < old_config.sh
Welcome to Iridium
(flashblade001-ch1-fm1  3.13.0-86-generic  #131-Ubuntu SMP Thu May 12 23:33:13 UTC 2016)
Name  Enabled  Subnet  Address      VLAN  Mask           Gateway     MTU   Services
dv01  True     net123  10.8.102.96  1006  255.255.254.0  10.8.102.1  1500  data
Name  Enabled  Subnet  Address      VLAN  Mask           Gateway     MTU   Services
dv02  True     net123  10.8.102.97  1006  255.255.254.0  10.8.102.1  1500  data
Name  Enabled  Subnet  Address      VLAN  Mask           Gateway     MTU   Services
dv03  True     net123  10.8.102.98  1006  255.255.254.0  10.8.102.1  1500  data

The CLI command “pureconfig list” outputs all of the “pure* list –cli” commands for every CLI command in your system. This produces a script that can then be run on another array to get it to the exact same configuration:

miranda@flasharray001> pureconfig list
purevol create --size 1G vol1
purevol create --size 200M vol2
purealert disable flasharray-alerts@purestorage.com
pureadmin global setattr --min-password-length 1
pureadmin setattr --publickey pureuser
purearray rename flasharray001
purearray disable console-lock
purearray setattr --idle-timeout 30
purearray enable phonehome
purearray setattr --proxy http://test.com:1234
...
purecert setattr --self-signed --key-size '2048' --organization 'Pure Storage, Inc.' --organizational-unit 'Pure Storage, Inc.' --days 3650
puresw global disable --auto-download

This is really useful if you want to “clone” one array so that it looks just like another one. You can also pass in specific options to just get “object” configuration, meaning you can have the same volumes and host configuration, without messing with system settings:

miranda@flasharray001> pureconfig list --object
purevol create --size 1G vol1
purevol create --size 2T vol2
purehost create host1
purehost setattr --personality "" host1
purehost setattr --preferred-array "" host1
purehost create host2
purehost setattr --personality "" host2
purehost setattr --preferred-array "" host2
purehost create host3
purehost setattr --personality "" host3
purehost setattr --preferred-array "" host3
purehgroup create --hostlist host1,host2,host3 hg1
purehgroup connect --lun 253 --vol vol2 hg1
purehgroup connect --lun 254 --vol vol1 hg1
purepgroup create --hgrouplist hg1 protection-group1
purepgroup schedule --replicate-frequency 4h --snap-frequency 1h protection-group1
purepgroup retain --per-day 4 --all-for 1d --days 7 --target-per-day 4 --target-all-for 1d --target-days 7 protection-group1

Conclusion

Even though the REST API is our first choice for scripting against your Pure arrays, the CLI has some really useful developer-friendly options. Let me know in the comments what your favorites are… Next time I want to talk more about our scale CLI options “–sort”, “–filter” and “–page”.

 

3 comments
  1. How do I connect multiple volumes to a host group ?
    The following command doesnt work
    purehgroup connect –vol PRDREP_DATA1, PRDREP_DATA2, PRDREP_DATA3 dr-repl7-rac

    Does it work for one LUN/VOL only?

    • Hi Devinder —

      Current CLI and REST 1.x does not support this capability. The way to handle this is via a loop using our Python or PowerShell SDKs.In the future REST 2.x will support batching.

      Thanks//barkz

Add Comment

Required fields are marked *. Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.