This repository was archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathadd_exclusion_to_fileset.py
More file actions
84 lines (82 loc) · 3.34 KB
/
add_exclusion_to_fileset.py
File metadata and controls
84 lines (82 loc) · 3.34 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<<<<<<< HEAD
#
# Title: add_exclusion_to_fileset.py
#
# Description: This script will take all fileset templates of a given type on a Rubrik system, and update the exclusion
# list to include an array of additional file types.
#
# Author: Stew Parkin (Assured DP), Tim Hynes (Rubrik)
#
import requests
import json
requests.packages.urllib3.disable_warnings()
## Variables to modify here
username = "admin"
password = "Rubrik123!"
rubrik_ip = "rubrik.demo.com"
excludes = ["*.mp3"]
fileset_type = "SMB"
## Should not need to modify anything beyond this point
clusterUrl = "https://"+rubrik_ip+"/api/v1"
fileseturl = clusterUrl + "/fileset_template?share_type=" + fileset_type
# Get our session token
tokenurl = clusterUrl + "/session"
session = requests.post(tokenurl, verify=False, auth=(username, password))
session = session.json()
token = 'Bearer ' + session['token']
# Get all fileset templates
filesets = requests.get(fileseturl, headers= { 'Accept': 'application/json', 'Authorization': token },verify=False, stream=True)
filesets = filesets.json()
# For each fileset template we will add the new file exclusion types, and patch it using the REST API
for fileset in filesets['data']:
filesetId = fileset['id']
for exclude in fileset['excludes']:
excludes.append(str(exclude))
data = {"id":filesetId,"excludes":excludes}
print (data)
editUrl = clusterUrl+"/fileset_template/"+filesetId
addExclude = requests.patch(editUrl, data=json.dumps(data), headers= { 'Accept': 'application/json', 'Authorization': token },verify=False, stream=True)
print addExclude
print (addExclude.text)
=======
#
# Title: add_exclusion_to_fileset.py
#
# Description: This script will take all fileset templates of a given type on a Rubrik system, and update the exclusion
# list to include an array of additional file types.
#
# Author: Stew Parkin (Assured DP), Tim Hynes (Rubrik)
#
import requests
import json
requests.packages.urllib3.disable_warnings()
## Variables to modify here
username = "admin"
password = "Rubrik123!"
rubrik_ip = "rubrik.demo.com"
exclude_list = ["*.mp3"]
fileset_type = "SMB"
## Should not need to modify anything beyond this point
clusterUrl = "https://"+rubrik_ip+"/api/v1"
fileseturl = clusterUrl + "/fileset_template?share_type=" + fileset_type
# Get our session token
tokenurl = clusterUrl + "/session"
session = requests.post(tokenurl, verify=False, auth=(username, password))
session = session.json()
token = 'Bearer ' + session['token']
# Get all fileset templates
filesets = requests.get(fileseturl, headers= { 'Accept': 'application/json', 'Authorization': token },verify=False, stream=True)
filesets = filesets.json()
# For each fileset template we will add the new file exclusion types, and patch it using the REST API
for fileset in filesets['data']:
excludes = exclude_list
filesetId = fileset['id']
for exclude in fileset['excludes']:
excludes.append(str(exclude))
data = {"id":filesetId,"excludes":excludes}
print (data)
editUrl = clusterUrl+"/fileset_template/"+filesetId
addExclude = requests.patch(editUrl, data=json.dumps(data), headers= { 'Accept': 'application/json', 'Authorization': token },verify=False, stream=True)
print addExclude
print (addExclude.text)
>>>>>>> 3cbba5eef094335fbc9ade1dcc30b3a7944beb7e