-
Notifications
You must be signed in to change notification settings - Fork 5
/
mount_isilon.py
executable file
·142 lines (122 loc) · 5.23 KB
/
mount_isilon.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
#
# Copyright (c) 2018 Dell Inc., or its subsidiaries. All Rights Reserved.
#
# Written by Claudio Fahey <claudio.fahey@dell.com>
#
"""
This script will SSH to multiple hosts and mount multiple Isilon interfaces on each host.
Isilon IP addresses are distributed in a round-robin fashion over hosts.
Installation of prerequisites:
sudo apt install python3-pip
pip3 install setuptools
pip3 install --requirement requirements.txt
"""
import configargparse
import subprocess
def main():
parser = configargparse.ArgParser(
description='SSH to multiple hosts and mount all Isilon interfaces on each host.',
config_file_parser_class=configargparse.YAMLConfigFileParser,
default_config_files=['mount_isilon.yaml'],
)
parser.add_argument('--export', default='/ifs')
parser.add_argument('--host', '-H', action='append', required=True,
help='List of hosts on which to run mount commands.')
parser.add_argument('--isilon_ip', '-i', action='append', required=True,
help='Isilon IP address to use as a mount target.')
parser.add_argument('--isilon_ip_count', '-c', type=int, default=1,
help='Total number of Isilon IP addresses. '
'If --isilon_ip specifies the first IP address only, consecutive IP addresses will be calculated.')
parser.add_argument('--mount_options', default='rsize=524288,wsize=524288,nolock,soft,timeo=50,retrans=12,proto=tcp')
parser.add_argument('--noop', action='store_true', default=False,
help='Print all commands but do not execute them.')
parser.add_argument('--nomount', dest='mount', action='store_false', default=True,
help='Unmount existing but do not mount.')
parser.add_argument('--skip_hosts', type=int, default=1,
help='Do not mount /mnt/isilon on the first skip_hosts hosts.')
parser.add_argument('--user', default='')
args = parser.parse_args()
print('# Initial Arguments: ' + str(args))
# Calculate consecutive Isilon IP addresses.
if len(args.isilon_ip) == 1 and len(args.isilon_ip) < args.isilon_ip_count:
first_isilon_ip = [int(octet) for octet in args.isilon_ip[0].split('.')]
args.isilon_ip = []
for i in range(args.isilon_ip_count):
isilon_ip = '.'.join([str(octet) for octet in first_isilon_ip[0:3] + [first_isilon_ip[3] + i]])
args.isilon_ip += [isilon_ip]
print('# Expanded Arguments: ' + str(args))
assert len(args.isilon_ip) == args.isilon_ip_count
ssh_user = '' if args.user == '' else args.user + '@'
# Mount /mnt/isilon on all except first host.
# This will use default mount parameters.
for host_index, host in enumerate(args.host):
if host_index < args.skip_hosts: continue
isilon_ip = args.isilon_ip[host_index % len(args.isilon_ip)]
cmd = [
'ssh',
'%s%s' % (ssh_user, host),
'sudo',
'umount',
'/mnt/isilon',
]
print(' '.join(cmd))
if not args.noop: subprocess.run(cmd, check=False)
if args.mount:
cmd = [
'ssh',
'%s%s' % (ssh_user, host),
'sudo',
'mkdir', '-p', '/mnt/isilon',
]
print(' '.join(cmd))
if not args.noop: subprocess.run(cmd, check=True)
cmd = [
'ssh',
'%s%s' % (ssh_user, host),
'sudo',
'mount',
'-t', 'nfs',
'%s:%s' % (isilon_ip, args.export),
'/mnt/isilon',
]
print(' '.join(cmd))
if not args.noop: subprocess.run(cmd, check=True)
# Mount /mnt/isilon1, /mnt/isilon2, ...
# This will use mount parameters optimized for high performance reads. nolock is used.
for host_index, host in enumerate(args.host):
for mount_index in range(len(args.isilon_ip)):
mount_number = mount_index + 1
isilon_ip = args.isilon_ip[(mount_index + host_index) % len(args.isilon_ip)]
cmd = [
'ssh',
'%s%s' % (ssh_user, host),
'sudo',
'umount',
'/mnt/isilon%d' % mount_number,
]
print(' '.join(cmd))
if not args.noop: subprocess.run(cmd, check=False)
if args.mount:
cmd = [
'ssh',
'%s%s' % (ssh_user, host),
'sudo',
'mkdir', '-p', '/mnt/isilon%d' % mount_number,
]
print(' '.join(cmd))
if not args.noop: subprocess.run(cmd, check=True)
cmd = [
'ssh',
'%s%s' % (ssh_user, host),
'sudo',
'mount',
'-t', 'nfs',
'-o', args.mount_options,
'%s:%s' % (isilon_ip, args.export),
'/mnt/isilon%d' % mount_number,
]
print(' '.join(cmd))
if not args.noop: subprocess.run(cmd, check=True)
if __name__ == '__main__':
main()