cancel
Showing results for 
Search instead for 
Did you mean: 
cancel

Pondering Automation: Back to Basics Part 3

218
Views
0
Helpful
0
Comments
Cisco Employee

Howdy out there in Automation land!! Hope everyone is having a great summer. We draw into the last true month of summer and we are going to take you further on your Action Orchestrator journey. Since we are on our last "Back to the Basics", I think we will go with this movie poster...

 

last_starfighter.jpg

 

Going a little old(er) school for you guys this time! In this blog we are going to do my most recent "advanced" workflow authoring lab. This will teach you looping, conditionals, and how to work with tables in AO. Also to go along with that, I would like to introduce the new *LOGO* for the blog and get your feedback! :)

ponderingautomation_logo.png

 

Let me know what you folks think! Lots of pondering in that Thinker fella. Also in the video blog I will chat a bit on using git integration with your workflows. I know we already did that but a quick refresher. I will also talk, briefly, about how to get your "easier to use" API keys from CloudCenter Suite so you can use them with AO calls *outside* of AO. I know you can do them in AO via the API page, but this is from outside or if you want to call AO from itself..... *Twilight Zone Music*.

 

To get our API key we need to do the following...

  1. Login to our CloudCenter Suite
  2. Select Suite Admin
  3. Click your login name at the top right
  4. Select Generate API Key
  5. The User ID it gives you is your username. The API Key is your Password
  6. You can now use those in a Basic Authentication style header. So base 64 encode username:password and you are good to go! (Or just use anything like postman/etc that does it for you)

Now... onto the lab!! (got you there I bet... Video is coming..)

 

Setup Steps

  1. Create a new workflow called Advanced Workflow Lab
  2. Add it to your category or any
  3. Create some variables! A string for output called id_list. A local integer called LVC. A couple of local strings for storage. An input integer called number_of_users. A local integer called TRUE, set it to 1. The local strings can just be local_storage or whatever you like to call them

Writing an ADVANCED WORKFLOW!

  1. You will need to re-use the JSONPath holder HTTP endpoint we made in the Back to the Basics Part 2 blog. Don't have it? Go back to that blog and watch and add it!!!
  2. Now... back to this lab... Make a call to JSONPath Holder again accessing the /posts endpoint. It should be a GET. *You* get to fill in all the other stuff... watch the VOD here or do this first and attempt it yourself. This will help you and should not be hard if you watched the previous blog.
  3. Now add  new data type to your your workflow, click ADD VARIABLE under Variables, under Data Type click ADD NEW.
  4. Table Type will be selected as it is the only advanced data type currently supported. Give your table a DISPLAY NAME. This table is just for show, we won't use it, and you will see in the VOD I skipped it... however I want you to do it so you get the feel of creating a table!
  5. Go to your COLUMNS and add fields via ADD 1 MORE FIELD at the bottom. The FIELD NAME is the column name, the FIELD TITLE is what is on the UI. You can select the type for the column in FIELD TYPE and add optional parameters.
  6. Add a few fields and make some required and some not via the REQUIRED slider. Click SAVE to save your table.
  7. Now back to your workflow....Drag and drop a Read Table from JSON activity below your web call.
  8. Under Read Table, set the JSON PATH to $..table[*] and check the PERSIST TABLE checkbox. If you do not check this, the data from the table will not be available to you later in the workflow.
  9. In COLUMNS TO READ click ADD to start adding columns. They should be all type String and their names should be userId, id, title, and body. Their names must match the JSON.
  10. Under SOURCE JSON, we need to "wrap" the web request json in some tags to make it readable, so we will put the output of the web activity into the SOURCE JSON field, but then wrap it as below
   {
        "table": <reference to web call output>
    }

read_table_from_json.jpg

What about a LOOP and the Results?

  1. Drag and a drop FOR EACH Loop from the Logic area in the toolbox under your Read Table from JSON activity

  2. Click the insert variable reference icon to load in the SOURCE ARRAY. Select the output of the Read Table from JSON Activity. You can *only* feed tables into this field.

  3. Drag and drop a CONDITION BLOCK inside the FOR EACH loop

  4. Set the DISPLAY NAME of the conditional to If ID LIST is empty

  5. Set the left CONDITION BRANCH to THEN and right one to ELSE (Remember we are doing that best practice of documentation! --- and all the developers gasp!)

  6. On the left CONDITION BRANCH set the CONDITION to one of your local variables(the storage one) being empty or blank. We can do that by setting it to Equals then a blank field.

  7. On the right CONDITION BRANCH set the CONDITION to your local TRUE variable Equals to 1. This is another way to do an ELSE statement.

  8. In the left or empty branch, drag and drop a SET VARIABLE activity.

  9. Set your local string variable to the current loop iterations id value. You do this via Activities->For Each Loop->Source Array->Items->id. Then click SAVE.

  10. On the right branch, drag and drop another SET VARIABLE activity, or duplicate the other one.

  11. Set your local string variable to itself, then a comma, and then the current loop iteration id value. This will build you a comma-delimited list of ids. This is how we do string concatenation in AO and will be *HUGE* for you going forward.

  12. How about looking at the table where ID=2, how do we do that?

  13. Drag and drop the Select from Table activity below your loop

  14. Under Select, set the INPUT TABLE to the output of your Read Table From JSONPath

  15. Then set the WHERE CLAUSE to id='2'. Persist this table as well and return all columns.

  16. Lastly, set an output variable. Set your output id_list to your local storage.

  17. Validate, Run your workflow and see the results!

  18. Check out individual iterations of the loop. Check out what is at ID=2 and check out your resultant id list!

 

conditional.JPG

 

Pretty cool huh? A quick and simple lab to teach you some of the advanced things or standard flow control in AO! Now time for you to build on it more!!! Feel free to try the above or watch the video and do it at the same time...

 

Now.... ONTO THE VIDEO!!!! :)

 

Link: Play recording

Pass: sQJSapc2 

 

Standard End-O-Blog Disclaimer:

 

Thanks as always to all my wonderful readers and those who continue to stick with and use CPO and now those learning AO! I have always wanted to find good questions, scenarios, stories, etc... if you have a question, please ask, if you want to see more, please ask... if you have topic ideas that you want me to blog on, Please ask! I am happy to cater to the readers and make this the best blog you will find :)

 

AUTOMATION BLOG DISCLAIMER: As always, this is a blog and my (Shaun Roberts) thoughts on CPO, AO, CCS, orchestration, and automation, my thoughts on best practices, and my experiences with the products and customers. The above views are in no way representative of Cisco or any of it's partners, etc. None of these views, etc are supported and this is not a place to find standard product support. If you need standard product support please do so via the current call in numbers on Cisco.com or email tac@cisco.com

 

Thanks and Happy Automating!!!

 

--Shaun Roberts

shaurobe@cisco.com

CreatePlease to create content
Content for Community-Ad
July's Community Spotlight Awards
This widget could not be displayed.