This repository has been archived by the owner on Mar 21, 2024. It is now read-only.
forked from yamanawabi/isilon-migrationscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfsexports.py
executable file
·117 lines (98 loc) · 3.35 KB
/
nfsexports.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
# python script to generate commands to create nfs mounts
# on a new cluster from a source cluster
# where isi nfs exports list --format=json > nfsexports.json
# is used as the input
# current features tracked are:
# clients, root clients, export description, read-only clients, read-write-clients
import json
with open('depot_nfs_exports.json') as nfsexports:
nfs_export_data = json.load(nfsexports)
for i in nfs_export_data:
# comma separated client list
clients = ""
if (len(i['clients']) == 0):
# no clients listed
pass
else:
for client in i['clients']:
clients += client + ","
# remove trailing comma
if(clients):
clients = " --clients " + clients[0:len(clients)-1]
else:
clients = ""
# comma separated root client list
rootclients = ""
if (len(i['root_clients']) == 0):
# no clients
pass
else:
for rootclient in i['root_clients']:
rootclients += rootclient + ","
# remove trailing comma
if(rootclients):
rootclients = " --root-clients " + rootclients[0:len(rootclients)-1]
else:
rootclients = ""
# comma separated read-write client list
rwclients = ""
if (len(i['read_write_clients']) == 0):
# no read-write clients
pass
else:
for rwclient in i['read_write_clients']:
rwclients += rwclient + ","
# remove trailing comma
if(rwclients):
rwclients = " --read-write-clients " + rwclients[0:len(rwclients)-1]
else:
rwclients = ""
# comma separated read-only client list
roclients = ""
if (len(i['read_only_clients']) == 0):
# no read-only clients
pass
else:
for roclient in i['read_only_clients']:
roclients += roclient + ","
# remove trailing comma
if(roclients):
roclients = " --read-only-clients " + roclients[0:len(roclients)-1]
else:
roclients = ""
# read only mount
readonly = ""
if (i['read_only'] == False):
pass
else:
readonly = "--read-only yes"
# export description
description = ""
if str(i['description']) == "":
# no description data
pass
else:
description = " --description \""+ str(i['description']) + "\""
alldirs = ""
if (i['all_dirs'] == True):
alldirs = " --all-dirs true"
else:
alldirs = " --all-dirs false"
maproot = ""
if (i['map_root']['enabled'] == True):
maprootusergroup = i['map_root']['user']+":"+i['map_root']['primary_group']+","+i['map_root']['secondary_groups']
maproot = " --map-root-enabled true --map-root="+maprootusergroup
else:
maproot = " --map-root-enabled false"
mapnonroot = ""
if (i['map_non_root']['enabled'] == True):
mapnonrootusergroup = i['map_root']['user']+":"+i['map_root']['primary_group']+","+i['map_root']['secondary_groups']
mapnonroot = " --map-non-root-enabled true --map-non-root="+mapnonrootusergroup
else:
mapnonroot = " --map-non-root-enabled false"
# put together the command per nfs export
command = "isi nfs exports create "
path = str(i['paths'][0])
print(command + path + clients + rootclients + roclients + rwclients +
description + readonly + alldirs + maproot + mapnonroot + "\n")