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…

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

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:

Let’s say my FlashArray has two volumes, vol1 and vol2. This is what the default “purevol list” output looks like:
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”:
  • “–notitle” simply gets rid of the first row of column titles:
  • “–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:
  • “–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.

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

Note that some of these options can be used together:

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:

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

Or finally, discover who destroyed your precious volume “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:

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:

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:

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:

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”.

 

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 class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">