-
Notifications
You must be signed in to change notification settings - Fork 31
/
deletepublishdest.py
executable file
·64 lines (56 loc) · 2.28 KB
/
deletepublishdest.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# deletepublishdest.py
# April 2020
#
# Delete a Viya publishing destination
#
# Change History
#
# Copyright © 2020, 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.
#
# Delete a publishing destination, after first validating that it exists
debug=False
folder_exists=False
# Import Python modules
import argparse
import sys
from sharedfunctions import callrestapi
parser = argparse.ArgumentParser(description="Delete a publishing destination")
parser.add_argument("-n","--name", help="Enter the name of the publishing destination to be deleted.",required=True)
parser.add_argument("-d","--debug", action='store_true', help="Debug")
args = parser.parse_args()
publish_name=args.name
debug=args.debug
# Does a publishing destination of the specified name actually exist?
# This call exits with a reasonably clear error message if the publishing destination does not exist,
# so I decided that no other error handling is required for the case where the folder does not exist.
reqval="/modelPublish/destinations/"+publish_name
reqtype="get"
test_exists_result_json=callrestapi(reqval,reqtype)
#print(test_exists_result_json)
#print('test_exists_result_json is a '+type(test_exists_result_json).__name__+' object') #test_exists_result_json is a dict object
if test_exists_result_json['name'] == publish_name:
folder_exists=True
if debug:
print('Publishing destination '+publish_name+' found.')
# Build the rest call
# Aiming for something equivalent to ./callrestapi.py -e /modelPublish/destinations/newcasdest2 -m delete
reqval="/modelPublish/destinations/"+publish_name
reqtype="delete"
# Delete the publishing destination
callrestapi(reqval,reqtype)
print('Publishing destination '+publish_name+' deleted.')