Better server share mounting
* Added ability to mount read-only or read-write * Allows the same main.py file to be used for all build scripts.
This commit is contained in:
parent
fbf956c651
commit
e0db7560e6
4 changed files with 35 additions and 9 deletions
|
|
@ -239,7 +239,7 @@ def mount_all_volumes():
|
||||||
line.append(info)
|
line.append(info)
|
||||||
return report
|
return report
|
||||||
|
|
||||||
def mount_backup_shares():
|
def mount_backup_shares(read_write=False):
|
||||||
"""Mount the backup shares unless labeled as already mounted."""
|
"""Mount the backup shares unless labeled as already mounted."""
|
||||||
if psutil.LINUX:
|
if psutil.LINUX:
|
||||||
mounted_data = get_mounted_data()
|
mounted_data = get_mounted_data()
|
||||||
|
|
@ -258,12 +258,22 @@ def mount_backup_shares():
|
||||||
print_warning(mounted_str)
|
print_warning(mounted_str)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mount_network_share(server)
|
mount_network_share(server, read_write)
|
||||||
|
|
||||||
def mount_network_share(server):
|
def mount_network_share(server, read_write=False):
|
||||||
"""Mount a network share defined by server."""
|
"""Mount a network share defined by server."""
|
||||||
|
if read_write:
|
||||||
|
username = server['RW-User']
|
||||||
|
password = server['RW-Pass']
|
||||||
|
else:
|
||||||
|
username = server['User']
|
||||||
|
password = server['Pass']
|
||||||
if psutil.WINDOWS:
|
if psutil.WINDOWS:
|
||||||
cmd = r'net use \\{IP}\{Share} /user:{User} {Pass}'.format(**server)
|
cmd = r'net use \\{ip}\{share} /user:{username} {password}'.format(
|
||||||
|
ip = server['IP'],
|
||||||
|
share = server['Share'],
|
||||||
|
username = username,
|
||||||
|
password = password)
|
||||||
cmd = cmd.split(' ')
|
cmd = cmd.split(' ')
|
||||||
warning = r'Failed to mount \\{Name}\{Share}, {IP} unreachable.'.format(
|
warning = r'Failed to mount \\{Name}\{Share}, {IP} unreachable.'.format(
|
||||||
**server)
|
**server)
|
||||||
|
|
@ -278,7 +288,10 @@ def mount_network_share(server):
|
||||||
'sudo', 'mount',
|
'sudo', 'mount',
|
||||||
'//{IP}/{Share}'.format(**server),
|
'//{IP}/{Share}'.format(**server),
|
||||||
'/Backups/{Name}'.format(**server),
|
'/Backups/{Name}'.format(**server),
|
||||||
'-o', 'username={User},password={Pass}'.format(**server)]
|
'-o', '{}username={},password={}'.format(
|
||||||
|
'' if read_write else 'ro,',
|
||||||
|
username,
|
||||||
|
password)]
|
||||||
warning = 'Failed to mount /Backups/{Name}, {IP} unreachable.'.format(
|
warning = 'Failed to mount /Backups/{Name}, {IP} unreachable.'.format(
|
||||||
**server)
|
**server)
|
||||||
error = 'Failed to mount /Backups/{Name}'.format(**server)
|
error = 'Failed to mount /Backups/{Name}'.format(**server)
|
||||||
|
|
@ -514,7 +527,7 @@ def select_source(ticket_number):
|
||||||
local_sources = []
|
local_sources = []
|
||||||
remote_sources = []
|
remote_sources = []
|
||||||
sources = []
|
sources = []
|
||||||
mount_backup_shares()
|
mount_backup_shares(read_write=False)
|
||||||
|
|
||||||
# Check for ticket folders on servers
|
# Check for ticket folders on servers
|
||||||
for server in BACKUP_SERVERS:
|
for server in BACKUP_SERVERS:
|
||||||
|
|
|
||||||
|
|
@ -154,9 +154,12 @@ def format_mbr(disk):
|
||||||
run_diskpart(script)
|
run_diskpart(script)
|
||||||
|
|
||||||
def mount_windows_share():
|
def mount_windows_share():
|
||||||
"""Mount the Windows images share unless labeled as already mounted."""
|
"""Mount the Windows images share unless labeled as already mounted."""
|
||||||
if not WINDOWS_SERVER['Mounted']:
|
if not WINDOWS_SERVER['Mounted']:
|
||||||
mount_network_share(WINDOWS_SERVER)
|
# Mounting read-write in case a backup was done in the same session
|
||||||
|
# and the server was left mounted read-write. This avoids throwing an
|
||||||
|
# error by trying to mount the same server with multiple credentials.
|
||||||
|
mount_network_share(WINDOWS_SERVER, read_write=True)
|
||||||
|
|
||||||
def select_windows_version():
|
def select_windows_version():
|
||||||
actions = [
|
actions = [
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ def menu_backup():
|
||||||
ticket_number = get_ticket_number()
|
ticket_number = get_ticket_number()
|
||||||
|
|
||||||
# Mount backup shares
|
# Mount backup shares
|
||||||
mount_backup_shares()
|
mount_backup_shares(read_write=True)
|
||||||
|
|
||||||
# Select destination
|
# Select destination
|
||||||
destination = select_backup_destination(auto_select=False)
|
destination = select_backup_destination(auto_select=False)
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ BACKUP_SERVERS = [
|
||||||
'Share': 'Backups',
|
'Share': 'Backups',
|
||||||
'User': 'restore',
|
'User': 'restore',
|
||||||
'Pass': 'Abracadabra',
|
'Pass': 'Abracadabra',
|
||||||
|
'RW-User': 'backup',
|
||||||
|
'RW-Pass': 'Abracadabra',
|
||||||
},
|
},
|
||||||
{ 'IP': '10.0.0.11',
|
{ 'IP': '10.0.0.11',
|
||||||
'Name': 'ServerTwo',
|
'Name': 'ServerTwo',
|
||||||
|
|
@ -42,6 +44,8 @@ BACKUP_SERVERS = [
|
||||||
'Share': 'Backups',
|
'Share': 'Backups',
|
||||||
'User': 'restore',
|
'User': 'restore',
|
||||||
'Pass': 'Abracadabra',
|
'Pass': 'Abracadabra',
|
||||||
|
'RW-User': 'backup',
|
||||||
|
'RW-Pass': 'Abracadabra',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
CRASH_SERVER = {
|
CRASH_SERVER = {
|
||||||
|
|
@ -57,6 +61,8 @@ OFFICE_SERVER = {
|
||||||
'Share': 'Office',
|
'Share': 'Office',
|
||||||
'User': 'restore',
|
'User': 'restore',
|
||||||
'Pass': 'Abracadabra',
|
'Pass': 'Abracadabra',
|
||||||
|
'RW-User': 'backup',
|
||||||
|
'RW-Pass': 'Abracadabra',
|
||||||
}
|
}
|
||||||
QUICKBOOKS_SERVER = {
|
QUICKBOOKS_SERVER = {
|
||||||
'IP': QUICKBOOKS_SERVER_IP,
|
'IP': QUICKBOOKS_SERVER_IP,
|
||||||
|
|
@ -65,6 +71,8 @@ QUICKBOOKS_SERVER = {
|
||||||
'Share': 'QuickBooks',
|
'Share': 'QuickBooks',
|
||||||
'User': 'restore',
|
'User': 'restore',
|
||||||
'Pass': 'Abracadabra',
|
'Pass': 'Abracadabra',
|
||||||
|
'RW-User': 'backup',
|
||||||
|
'RW-Pass': 'Abracadabra',
|
||||||
}
|
}
|
||||||
WINDOWS_SERVER = {
|
WINDOWS_SERVER = {
|
||||||
'IP': '10.0.0.10',
|
'IP': '10.0.0.10',
|
||||||
|
|
@ -73,6 +81,8 @@ WINDOWS_SERVER = {
|
||||||
'Share': 'Windows',
|
'Share': 'Windows',
|
||||||
'User': 'restore',
|
'User': 'restore',
|
||||||
'Pass': 'Abracadabra',
|
'Pass': 'Abracadabra',
|
||||||
|
'RW-User': 'backup',
|
||||||
|
'RW-Pass': 'Abracadabra',
|
||||||
}
|
}
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue