-
Notifications
You must be signed in to change notification settings - Fork 31
/
importconfiguration.py
executable file
·75 lines (57 loc) · 2.57 KB
/
importconfiguration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# importconfiguration.py
# April 2021
#
# Pass in a directory and this tool will import all the json files in the directory. It depends on the admin CLI
# The json files should be standard viya configuration definitions
#
#
# Change History
#
# Copyright © 2019, 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 Python modules
import argparse, sys, subprocess, os, json
from sharedfunctions import callrestapi, getapplicationproperties,getclicommand
# get cli location from properties, check that cli is there if not ERROR and stop
clicommand=getclicommand()
# get input parameters
parser = argparse.ArgumentParser(description="Import JSON files that update Viya configuration. All json files in directory will be imported.")
parser.add_argument("-d","--directory", help="Directory that contains JSON configuration definition files to import",required='True')
parser.add_argument("-q","--quiet", help="Suppress the are you sure prompt.", action='store_true')
args= parser.parse_args()
basedir=args.directory
quietmode=args.quiet
# get python version
version=int(str(sys.version_info[0]))
# if the quiet mode flag is not passed then prompt to continue
if not quietmode:
if version > 2:
areyousure=input("WARNING: Are you sure? (Y)")
else:
areyousure=raw_input("WARNING: Are you sure? (Y)")
else:
areyousure="Y"
if areyousure.upper() =='Y':
# check that directory exists
if os.path.isdir(basedir):
# loop files in the directory
for filename in os.listdir( basedir ):
# only process json files
if filename.lower().endswith('.json'):
command=clicommand+' configuration configurations update --file '+os.path.join(basedir,filename)
print(command)
subprocess.call(command, shell=True)
print("NOTE: Configuration import attempted from json file "+filename+" in directory "+basedir )
else: print("ERROR: Directory does not exist")
else:
print("NOTE: Operation cancelled")