From c355c15a12e5206a6292fbbaf0c0a909db4dbbaf Mon Sep 17 00:00:00 2001 From: Gerry Nelson Date: Tue, 18 Dec 2018 12:43:45 -0500 Subject: [PATCH] add listcaslibs.py as an example of developing a tool --- listcaslibs.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 listcaslibs.py diff --git a/listcaslibs.py b/listcaslibs.py new file mode 100644 index 0000000..7df8d11 --- /dev/null +++ b/listcaslibs.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# listcaslibs.py December 2017 +# +# listcaslibs an example of how easy it is to build a new tool. This tool is not really needed as you can do this easily with the CLI +# it is here for demo purposes. It lists the caslibs and there details accepting the cas server as a parameter +# +# +# Change History +# +# 27JAN2017 Comments added +# +# +# Copyright © 2018, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +# express or implied. See the License for the specific language governing permissions and limitations under the License. +# + +import argparse +from sharedfunctions import callrestapi,printresult + +# setup command-line arguements. In this block which is common to all the tools you setup what parameters +# are passed to the tool +# the --output parameter is a common one which supports the three styles of output json, simple or csv + +parser = argparse.ArgumentParser() +parser.add_argument("-s","--server", help="The CAS SERVER.",required='True',default="cas-shared-default") +parser.add_argument("-o","--output", help="Output Style", choices=['csv','json','simple'],default='json') +args = parser.parse_args() +casserver=args.server +output_style=args.output + +# set the request type +reqtype='get' + +# set the endpoint to call +reqval='/casManagement/servers/'+casserver+'/caslibs' + +#make the rest call using the callrestapi function. You can have one or many calls +caslib_result_json=callrestapi(reqval,reqtype) + +# example of overriding the columns for csv output +cols=['name','type','path','scope','attributes','description'] + +# print result accepts +# the json returned +# the output style +# optionally the columns for csv outtput, if you don't pass in columns you get defaults + +# You can just print results r post process the results as you need to + +printresult(caslib_result_json,output_style,cols) +