def post(self, request, command): if (command == 'bootstrap'): self._refresh_pool_state() for p in Pool.objects.all(): import_shares(p, request) for share in Share.objects.all(): try: if (share.pqgroup == settings.MODEL_DEFS['pqgroup']): share.pqgroup = qgroup_create(share.pool) share.save() if (not is_share_mounted(share.name)): mnt_pt = ('%s%s' % (settings.MNT_PT, share.name)) mount_share(share, mnt_pt) except Exception, e: e_msg = ('Exception while mounting a share(%s) during ' 'bootstrap: %s' % (share.name, e.__str__())) logger.error(e_msg) logger.exception(e) try: import_snapshots(share) except Exception, e: e_msg = ('Exception while importing Snapshots of ' 'Share(%s): %s' % (share.name, e.__str__())) logger.error(e_msg) logger.exception(e)
def _btrfs_disk_import(self, dname, request): try: disk = self._validate_disk(dname, request) p_info = get_pool_info(dname) # get some options from saved config? po = Pool(name=p_info['label'], raid="unknown") # need to save it so disk objects get updated properly in the for # loop below. po.save() for d in p_info['disks']: do = Disk.objects.get(name=d) do.pool = po do.parted = False do.save() mount_root(po) po.raid = pool_raid('%s%s' % (settings.MNT_PT, po.name))['data'] po.size = pool_usage('%s%s' % (settings.MNT_PT, po.name))[0] po.save() enable_quota(po) import_shares(po, request) for share in Share.objects.filter(pool=po): import_snapshots(share) return Response(DiskInfoSerializer(disk).data) except Exception, e: e_msg = ( 'Failed to import any pool on this device(%s). Error: %s' % (dname, e.__str__())) handle_exception(Exception(e_msg), request)
def _btrfs_disk_import(self, dname, request): try: disk = self._validate_disk(dname, request) p_info = get_pool_info(dname) # get some options from saved config? po = Pool(name=p_info['label'], raid="unknown") # need to save it so disk objects get updated properly in the for # loop below. po.save() for d in p_info['disks']: do = Disk.objects.get(name=d) do.pool = po do.parted = False do.save() mount_root(po) po.raid = pool_raid('%s%s' % (settings.MNT_PT, po.name))['data'] po.size = pool_usage('%s%s' % (settings.MNT_PT, po.name))[0] po.save() enable_quota(po) import_shares(po, request) for share in Share.objects.filter(pool=po): import_snapshots(share) return Response(DiskInfoSerializer(disk).data) except Exception, e: e_msg = ('Failed to import any pool on this device(%s). Error: %s' % (dname, e.__str__())) handle_exception(Exception(e_msg), request)
def _btrfs_disk_import(self, dname, request): try: disk = self._validate_disk(dname, request) disk_name = self._role_filter_disk_name(disk, request) p_info = get_pool_info(disk_name) # get some options from saved config? po = Pool(name=p_info['label'], raid="unknown") # need to save it so disk objects get updated properly in the for # loop below. po.save() for device in p_info['disks']: disk_name, isPartition = \ self._reverse_role_filter_name(device, request) do = Disk.objects.get(name=disk_name) do.pool = po # update this disk's parted property do.parted = isPartition if isPartition: # ensure a redirect role to reach this partition; ie: # "redirect": "virtio-serial-3-part2" if do.role is not None: # db default is null / None. # Get our previous roles into a dictionary roles = json.loads(do.role) # update or add our "redirect" role with our part name roles['redirect'] = '%s' % device # convert back to json and store in disk object do.role = json.dumps(roles) else: # role=None so just add a json formatted redirect role do.role = '{"redirect": "%s"}' % device.name do.save() mount_root(po) po.raid = pool_raid('%s%s' % (settings.MNT_PT, po.name))['data'] po.size = po.usage_bound() po.save() enable_quota(po) import_shares(po, request) for share in Share.objects.filter(pool=po): import_snapshots(share) return Response(DiskInfoSerializer(disk).data) except Exception as e: e_msg = ( 'Failed to import any pool on this device(%s). Error: %s' % (dname, e.__str__())) handle_exception(Exception(e_msg), request)
def post(self, request, command, rtcepoch=None): if command == "bootstrap": self._update_disk_state() self._refresh_pool_state() for p in Pool.objects.all(): if p.disk_set.attached().count() == 0: continue if not p.is_mounted: # Prior _refresh_pool_state() should have ensure a mount. logger.error("Skipping import/update of prior known " "shares for pool ({}) as it is not mounted. " "(see previous errors)" ".".format(p.name)) continue # Import / update db shares counterpart for managed pool. import_shares(p, request) for share in Share.objects.all(): if share.pool.disk_set.attached().count() == 0: continue if not share.pool.is_mounted: logger.error("Skipping mount of share ({}) as pool () is " "not mounted (see previous errors)" ".".format(share.name, share.pool.name)) continue try: if not share.is_mounted: # System mounted shares i.e. home will already be mounted. mnt_pt = "{}{}".format(settings.MNT_PT, share.name) mount_share(share, mnt_pt) except Exception as e: e_msg = ("Exception while mounting a share ({}) during " "bootstrap: ({}).").format( share.name, e.__str__()) logger.error(e_msg) logger.exception(e) try: import_snapshots(share) except Exception as e: e_msg = ("Exception while importing snapshots of share " "({}): ({}).").format(share.name, e.__str__()) logger.error(e_msg) logger.exception(e) for snap in Snapshot.objects.all(): if snap.uvisible: try: mount_snap(snap.share, snap.real_name, snap.qgroup) except Exception as e: e_msg = ("Failed to make the snapshot ({}) visible. " "Exception: ({}).").format( snap.real_name, e.__str__()) logger.error(e_msg) mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT) for sftpo in SFTP.objects.all(): # The following may be buggy when used with system mounted (fstab) /home # but we currently don't allow /home to be exported. try: sftp_mount( sftpo.share, settings.MNT_PT, settings.SFTP_MNT_ROOT, mnt_map, sftpo.editable, ) sftp_snap_toggle(sftpo.share) except Exception as e: e_msg = ("Exception while exporting a SFTP share during " "bootstrap: ({}).").format(e.__str__()) logger.error(e_msg) try: adv_entries = [ a.export_str for a in AdvancedNFSExport.objects.all() ] exports_d = self.create_adv_nfs_export_input( adv_entries, request) exports = self.create_nfs_export_input(NFSExport.objects.all()) exports.update(exports_d) self.refresh_wrapper(exports, request, logger) except Exception as e: e_msg = ("Exception while bootstrapping NFS: " "({}).").format(e.__str__()) logger.error(e_msg) # bootstrap services try: systemctl("firewalld", "stop") systemctl("firewalld", "disable") systemctl("nginx", "stop") systemctl("nginx", "disable") systemctl("atd", "enable") systemctl("atd", "start") except Exception as e: e_msg = ("Exception while setting service statuses during " "bootstrap: ({}).").format(e.__str__()) logger.error(e_msg) handle_exception(Exception(e_msg), request) logger.debug("Bootstrap operations completed") return Response() if command == "utcnow": return Response(datetime.utcnow().replace(tzinfo=utc)) if command == "uptime": return Response(uptime()) if command == "kernel": try: return Response(kernel_info(settings.SUPPORTED_KERNEL_VERSION)) except Exception as e: handle_exception(e, request) if command == "update-check": try: subo = None try: subo = UpdateSubscription.objects.get(name="Stable", status="active") except UpdateSubscription.DoesNotExist: try: subo = UpdateSubscription.objects.get(name="Testing", status="active") except UpdateSubscription.DoesNotExist: pass return Response(rockstor_pkg_update_check(subscription=subo)) except Exception as e: e_msg = ("Unable to check update due to a system error: " "({}).").format(e.__str__()) handle_exception(Exception(e_msg), request) if command == "update": try: # Once again, like on system shutdown/reboot, we filter # incoming requests with request.auth: every update from # WebUI misses request.auth, while yum update requests from # data_collector APIWrapper have it, so we can avoid # an additional command for yum updates if request.auth is None: update_run() else: update_run(update_all_other=True) return Response("Done") except Exception as e: e_msg = ("Update failed due to this exception: " "({}).").format(e.__str__()) handle_exception(Exception(e_msg), request) if command == "current-version": try: return Response(current_version()) except Exception as e: e_msg = ("Unable to check current version due to this " "exception: ({}).").format(e.__str__()) handle_exception(Exception(e_msg), request) # default has shutdown and reboot with delay set to now # having normal sytem power off with now = 1 min # reboot and shutdown requests from WebUI don't have request.auth # while same requests over rest api (ex. scheduled tasks) have # an auth token, so if we detect a token we delay with 3 mins # to grant connected WebUI user to close it or cancel shutdown/reboot delay = "now" if request.auth is not None: delay = 3 if command == "shutdown": msg = "The system will now be shutdown." try: # if shutdown request coming from a scheduled task # with rtc wake up time on we set it before # system shutdown starting if rtcepoch is not None: set_system_rtc_wake(rtcepoch) request.session.flush() system_shutdown(delay) except Exception as e: msg = ("Failed to shutdown the system due to a low level " "error: ({}).").format(e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if command == "reboot": msg = "The system will now reboot." try: request.session.flush() system_reboot(delay) except Exception as e: msg = ("Failed to reboot the system due to a low level " "error: ({}).").format(e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if command == "suspend": msg = "The system will now be suspended to RAM." try: request.session.flush() set_system_rtc_wake(rtcepoch) system_suspend() except Exception as e: msg = ("Failed to suspend the system due to a low level " "error: ({}).").format(e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if command == "current-user": return Response(request.user.username) if command == "auto-update-status": status = True try: status = auto_update_status() except: status = False finally: return Response({"enabled": status}) if command == "enable-auto-update": try: auto_update(enable=True) return Response({"enabled": True}) except Exception as e: msg = ("Failed to enable auto update due to this exception: " "({}).").format(e.__str__()) handle_exception(Exception(msg), request) if command == "disable-auto-update": try: auto_update(enable=False) return Response({"enabled": False}) except Exception as e: msg = ("Failed to disable auto update due to this exception: " "({}).").format(e.__str__()) handle_exception(Exception(msg), request) if command == "refresh-disk-state": self._update_disk_state() return Response() if command == "refresh-pool-state": self._refresh_pool_state() return Response() if command == "refresh-share-state": for p in Pool.objects.all(): import_shares(p, request) return Response() if command == "refresh-snapshot-state": for share in Share.objects.all(): import_snapshots(share) return Response()
def post(self, request, command, rtcepoch=None): if (command == 'bootstrap'): self._update_disk_state() self._refresh_pool_state() for p in Pool.objects.all(): if p.disk_set.attached().count() == 0: continue if not p.is_mounted: # Prior _refresh_pool_state() should have ensure a mount. logger.error('Skipping import/update of prior known ' 'shares for pool ({}) as it is not mounted. ' '(see previous errors)' '.'.format(p.name)) continue # Import / update db shares counterpart for managed pool. import_shares(p, request) for share in Share.objects.all(): if share.pool.disk_set.attached().count() == 0: continue if not share.pool.is_mounted: logger.error('Skipping mount of share ({}) as pool () is ' 'not mounted (see previous errors)' '.'.format(share.name, share.pool.name)) continue try: if not share.is_mounted: mnt_pt = ('%s%s' % (settings.MNT_PT, share.name)) mount_share(share, mnt_pt) except Exception as e: e_msg = ('Exception while mounting a share ({}) during ' 'bootstrap: ({}).').format(share.name, e.__str__()) logger.error(e_msg) logger.exception(e) try: import_snapshots(share) except Exception as e: e_msg = ('Exception while importing snapshots of share ' '({}): ({}).').format(share.name, e.__str__()) logger.error(e_msg) logger.exception(e) for snap in Snapshot.objects.all(): if (snap.uvisible): try: mount_snap(snap.share, snap.real_name, snap.qgroup) except Exception as e: e_msg = ('Failed to make the snapshot ({}) visible. ' 'Exception: ({}).').format(snap.real_name, e.__str__()) logger.error(e_msg) mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT) for sftpo in SFTP.objects.all(): try: sftp_mount(sftpo.share, settings.MNT_PT, settings.SFTP_MNT_ROOT, mnt_map, sftpo.editable) sftp_snap_toggle(sftpo.share) except Exception as e: e_msg = ('Exception while exporting a SFTP share during ' 'bootstrap: ({}).').format(e.__str__()) logger.error(e_msg) try: adv_entries = [a.export_str for a in AdvancedNFSExport.objects.all()] exports_d = self.create_adv_nfs_export_input(adv_entries, request) exports = self.create_nfs_export_input(NFSExport.objects.all()) exports.update(exports_d) self.refresh_wrapper(exports, request, logger) except Exception as e: e_msg = ('Exception while bootstrapping NFS: ' '({}).').format(e.__str__()) logger.error(e_msg) # bootstrap services try: systemctl('firewalld', 'stop') systemctl('firewalld', 'disable') systemctl('nginx', 'stop') systemctl('nginx', 'disable') systemctl('atd', 'enable') systemctl('atd', 'start') except Exception as e: e_msg = ('Exception while setting service statuses during ' 'bootstrap: ({}).').format(e.__str__()) logger.error(e_msg) handle_exception(Exception(e_msg), request) logger.debug('Bootstrap operations completed') return Response() if (command == 'utcnow'): return Response(datetime.utcnow().replace(tzinfo=utc)) if (command == 'uptime'): return Response(uptime()) if (command == 'kernel'): try: return Response(kernel_info(settings.SUPPORTED_KERNEL_VERSION)) except Exception as e: handle_exception(e, request) if (command == 'update-check'): try: subo = None try: subo = UpdateSubscription.objects.get(name='Stable', status='active') except UpdateSubscription.DoesNotExist: try: subo = UpdateSubscription.objects.get(name='Testing', status='active') except UpdateSubscription.DoesNotExist: pass return Response(update_check(subscription=subo)) except Exception as e: e_msg = ('Unable to check update due to a system error: ' '({}).').format(e.__str__()) handle_exception(Exception(e_msg), request) if (command == 'update'): try: # Once again, like on system shutdown/reboot, we filter # incoming requests with request.auth: every update from # WebUI misses request.auth, while yum update requests from # data_collector APIWrapper have it, so we can avoid # an additional command for yum updates if request.auth is None: update_run() else: update_run(yum_update=True) return Response('Done') except Exception as e: e_msg = ('Update failed due to this exception: ' '({}).').format(e.__str__()) handle_exception(Exception(e_msg), request) if (command == 'current-version'): try: return Response(current_version()) except Exception as e: e_msg = ('Unable to check current version due to this ' 'exception: ({}).').format(e.__str__()) handle_exception(Exception(e_msg), request) # default has shutdown and reboot with delay set to now # having normal sytem power off with now = 1 min # reboot and shutdown requests from WebUI don't have request.auth # while same requests over rest api (ex. scheduled tasks) have # an auth token, so if we detect a token we delay with 3 mins # to grant connected WebUI user to close it or cancel shutdown/reboot delay = 'now' if request.auth is not None: delay = 3 if (command == 'shutdown'): msg = 'The system will now be shutdown.' try: # if shutdown request coming from a scheduled task # with rtc wake up time on we set it before # system shutdown starting if rtcepoch is not None: set_system_rtc_wake(rtcepoch) request.session.flush() system_shutdown(delay) except Exception as e: msg = ('Failed to shutdown the system due to a low level ' 'error: ({}).').format(e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if (command == 'reboot'): msg = 'The system will now reboot.' try: request.session.flush() system_reboot(delay) except Exception as e: msg = ('Failed to reboot the system due to a low level ' 'error: ({}).').format(e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if (command == 'suspend'): msg = 'The system will now be suspended to RAM.' try: request.session.flush() set_system_rtc_wake(rtcepoch) system_suspend() except Exception as e: msg = ('Failed to suspend the system due to a low level ' 'error: ({}).').format(e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if (command == 'current-user'): return Response(request.user.username) if (command == 'auto-update-status'): status = True try: status = auto_update_status() except: status = False finally: return Response({'enabled': status, }) if (command == 'enable-auto-update'): try: auto_update(enable=True) return Response({'enabled': True, }) except Exception as e: msg = ('Failed to enable auto update due to this exception: ' '({}).').format(e.__str__()) handle_exception(Exception(msg), request) if (command == 'disable-auto-update'): try: auto_update(enable=False) return Response({'enabled': False, }) except Exception as e: msg = ('Failed to disable auto update due to this exception: ' '({}).').format(e.__str__()) handle_exception(Exception(msg), request) if (command == 'refresh-disk-state'): self._update_disk_state() return Response() if (command == 'refresh-pool-state'): self._refresh_pool_state() return Response() if (command == 'refresh-share-state'): for p in Pool.objects.all(): import_shares(p, request) return Response() if (command == 'refresh-snapshot-state'): for share in Share.objects.all(): import_snapshots(share) return Response()
try: auto_update(enable=True) return Response({'enabled': True, }) except Exception, e: msg = ('Failed to enable auto update due to this exception: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) if (command == 'disable-auto-update'): try: auto_update(enable=False) return Response({'enabled': False, }) except Exception, e: msg = ('Failed to disable auto update due to this exception: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) if (command == 'refresh-pool-state'): self._refresh_pool_state() return Response() if (command == 'refresh-share-state'): for p in Pool.objects.all(): import_shares(p, request) return Response() if (command == 'refresh-snapshot-state'): for share in Share.objects.all(): import_snapshots(share) return Response()
def post(self, request, command, rtcepoch=None): if (command == 'bootstrap'): self._update_disk_state() self._refresh_pool_state() for p in Pool.objects.all(): if p.disk_set.attached().count() == 0: continue import_shares(p, request) for share in Share.objects.all(): if share.pool.disk_set.attached().count() == 0: continue try: if (share.pqgroup == settings.MODEL_DEFS['pqgroup']): share.pqgroup = qgroup_create(share.pool) share.save() if not share.is_mounted: mnt_pt = ('%s%s' % (settings.MNT_PT, share.name)) mount_share(share, mnt_pt) except Exception as e: e_msg = ('Exception while mounting a share(%s) during ' 'bootstrap: %s' % (share.name, e.__str__())) logger.error(e_msg) logger.exception(e) try: import_snapshots(share) except Exception as e: e_msg = ('Exception while importing Snapshots of ' 'Share(%s): %s' % (share.name, e.__str__())) logger.error(e_msg) logger.exception(e) for snap in Snapshot.objects.all(): if (snap.uvisible): try: mount_snap(snap.share, snap.real_name) except Exception as e: e_msg = ('Failed to make the Snapshot(%s) visible. ' 'Exception: %s' % (snap.real_name, e.__str__())) logger.error(e_msg) mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT) for sftpo in SFTP.objects.all(): try: sftp_mount(sftpo.share, settings.MNT_PT, settings.SFTP_MNT_ROOT, mnt_map, sftpo.editable) sftp_snap_toggle(sftpo.share) except Exception as e: e_msg = ('Exception while exportin a sftp share during ' 'bootstrap: %s' % e.__str__()) logger.error(e_msg) try: adv_entries = [a.export_str for a in AdvancedNFSExport.objects.all()] exports_d = self.create_adv_nfs_export_input(adv_entries, request) exports = self.create_nfs_export_input(NFSExport.objects.all()) exports.update(exports_d) self.refresh_wrapper(exports, request, logger) except Exception as e: e_msg = ('Exception while bootstrapping NFS: %s' % e.__str__()) logger.error(e_msg) # bootstrap services try: systemctl('firewalld', 'stop') systemctl('firewalld', 'disable') systemctl('nginx', 'stop') systemctl('nginx', 'disable') systemctl('atd', 'enable') systemctl('atd', 'start') except Exception as e: e_msg = ('Exception while setting service statuses during ' 'bootstrap: %s' % e.__str__()) logger.error(e_msg) handle_exception(Exception(e_msg), request) logger.debug('Bootstrap operations completed') return Response() if (command == 'utcnow'): return Response(datetime.utcnow().replace(tzinfo=utc)) if (command == 'uptime'): return Response(uptime()) if (command == 'kernel'): try: return Response(kernel_info(settings.SUPPORTED_KERNEL_VERSION)) except Exception as e: handle_exception(e, request) if (command == 'update-check'): try: subo = None try: subo = UpdateSubscription.objects.get(name='Stable', status='active') except UpdateSubscription.DoesNotExist: try: subo = UpdateSubscription.objects.get(name='Testing', status='active') except UpdateSubscription.DoesNotExist: pass return Response(update_check(subscription=subo)) except Exception as e: e_msg = ('Unable to check update due to a system error: %s' % e.__str__()) handle_exception(Exception(e_msg), request) if (command == 'update'): try: # Once again, like on system shutdown/reboot, we filter # incoming requests with request.auth: every update from # WebUI misses request.auth, while yum update requests from # data_collector APIWrapper have it, so we can avoid # an additional command for yum updates if request.auth is None: update_run() else: update_run(yum_update=True) return Response('Done') except Exception as e: e_msg = ('Update failed due to this exception: %s' % e.__str__()) handle_exception(Exception(e_msg), request) if (command == 'current-version'): try: return Response(current_version()) except Exception as e: e_msg = ('Unable to check current version due to this ' 'exception: ' % e.__str__()) handle_exception(Exception(e_msg), request) # default has shutdown and reboot with delay set to now # having normal sytem power off with now = 1 min # reboot and shutdown requests from WebUI don't have request.auth # while same requests over rest api (ex. scheduled tasks) have # an auth token, so if we detect a token we delay with 3 mins # to grant connected WebUI user to close it or cancel shutdown/reboot delay = 'now' if request.auth is not None: delay = 3 if (command == 'shutdown'): msg = ('The system will now be shutdown') try: # if shutdown request coming from a scheduled task # with rtc wake up time on we set it before # system shutdown starting if rtcepoch is not None: set_system_rtc_wake(rtcepoch) request.session.flush() system_shutdown(delay) except Exception as e: msg = ('Failed to shutdown the system due to a low level ' 'error: %s' % e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if (command == 'reboot'): msg = ('The system will now reboot') try: request.session.flush() system_reboot(delay) except Exception as e: msg = ('Failed to reboot the system due to a low level error: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if (command == 'suspend'): msg = ('The system will now be suspended to RAM') try: request.session.flush() set_system_rtc_wake(rtcepoch) system_suspend() except Exception as e: msg = ('Failed to suspend the system due to a low level ' 'error: %s' % e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if (command == 'current-user'): return Response(request.user.username) if (command == 'auto-update-status'): status = True try: status = auto_update_status() except: status = False finally: return Response({'enabled': status, }) if (command == 'enable-auto-update'): try: auto_update(enable=True) return Response({'enabled': True, }) except Exception as e: msg = ('Failed to enable auto update due to this exception: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) if (command == 'disable-auto-update'): try: auto_update(enable=False) return Response({'enabled': False, }) except Exception as e: msg = ('Failed to disable auto update due to this exception: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) if (command == 'refresh-disk-state'): self._update_disk_state() return Response() if (command == 'refresh-pool-state'): self._refresh_pool_state() return Response() if (command == 'refresh-share-state'): for p in Pool.objects.all(): import_shares(p, request) return Response() if (command == 'refresh-snapshot-state'): for share in Share.objects.all(): import_snapshots(share) return Response()
def post(self, request, command): if (command == 'bootstrap'): self._refresh_pool_state() for p in Pool.objects.all(): import_shares(p, request) for share in Share.objects.all(): try: if (share.pqgroup == settings.MODEL_DEFS['pqgroup']): share.pqgroup = qgroup_create(share.pool) share.save() if (not is_share_mounted(share.name)): mnt_pt = ('%s%s' % (settings.MNT_PT, share.name)) mount_share(share, mnt_pt) except Exception as e: e_msg = ('Exception while mounting a share(%s) during ' 'bootstrap: %s' % (share.name, e.__str__())) logger.error(e_msg) logger.exception(e) try: import_snapshots(share) except Exception as e: e_msg = ('Exception while importing Snapshots of ' 'Share(%s): %s' % (share.name, e.__str__())) logger.error(e_msg) logger.exception(e) for snap in Snapshot.objects.all(): if (snap.uvisible): try: mount_snap(snap.share, snap.real_name) except Exception as e: e_msg = ('Failed to make the Snapshot(%s) visible. ' 'Exception: %s' % (snap.real_name, e.__str__())) logger.error(e_msg) mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT) for sftpo in SFTP.objects.all(): try: sftp_mount(sftpo.share, settings.MNT_PT, settings.SFTP_MNT_ROOT, mnt_map, sftpo.editable) sftp_snap_toggle(sftpo.share) except Exception as e: e_msg = ('Exception while exportin a sftp share during ' 'bootstrap: %s' % e.__str__()) logger.error(e_msg) try: adv_entries = [ a.export_str for a in AdvancedNFSExport.objects.all() ] exports_d = self.create_adv_nfs_export_input( adv_entries, request) exports = self.create_nfs_export_input(NFSExport.objects.all()) exports.update(exports_d) self.refresh_wrapper(exports, request, logger) except Exception as e: e_msg = ('Exception while bootstrapping NFS: %s' % e.__str__()) logger.error(e_msg) # bootstrap services try: systemctl('firewalld', 'stop') systemctl('firewalld', 'disable') systemctl('nginx', 'stop') systemctl('nginx', 'disable') systemctl('atd', 'enable') systemctl('atd', 'start') except Exception as e: e_msg = ('Exception while setting service statuses during ' 'bootstrap: %s' % e.__str__()) logger.error(e_msg) handle_exception(Exception(e_msg), request) logger.debug('Bootstrap operations completed') return Response() if (command == 'utcnow'): return Response(datetime.utcnow().replace(tzinfo=utc)) if (command == 'uptime'): return Response(uptime()) if (command == 'kernel'): try: return Response(kernel_info(settings.SUPPORTED_KERNEL_VERSION)) except Exception as e: handle_exception(e, request) if (command == 'update-check'): try: subo = None try: subo = UpdateSubscription.objects.get(name='Stable', status='active') except UpdateSubscription.DoesNotExist: try: subo = UpdateSubscription.objects.get(name='Testing', status='active') except UpdateSubscription.DoesNotExist: pass return Response(update_check(subscription=subo)) except Exception as e: e_msg = ('Unable to check update due to a system error: %s' % e.__str__()) handle_exception(Exception(e_msg), request) if (command == 'update'): try: update_run() return Response('Done') except Exception as e: e_msg = ('Update failed due to this exception: %s' % e.__str__()) handle_exception(Exception(e_msg), request) if (command == 'current-version'): try: return Response(current_version()) except Exception as e: e_msg = ('Unable to check current version due to this ' 'exception: ' % e.__str__()) handle_exception(Exception(e_msg), request) if (command == 'shutdown'): msg = ('The system will now be shutdown') try: request.session.flush() system_shutdown() except Exception as e: msg = ('Failed to shutdown the system due to a low level ' 'error: %s' % e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if (command == 'reboot'): msg = ('The system will now reboot') try: request.session.flush() system_reboot() except Exception as e: msg = ('Failed to reboot the system due to a low level error: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) finally: return Response(msg) if (command == 'current-user'): return Response(request.user.username) if (command == 'auto-update-status'): status = True try: status = auto_update_status() except: status = False finally: return Response({ 'enabled': status, }) if (command == 'enable-auto-update'): try: auto_update(enable=True) return Response({ 'enabled': True, }) except Exception as e: msg = ('Failed to enable auto update due to this exception: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) if (command == 'disable-auto-update'): try: auto_update(enable=False) return Response({ 'enabled': False, }) except Exception as e: msg = ('Failed to disable auto update due to this exception: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) if (command == 'refresh-pool-state'): self._refresh_pool_state() return Response() if (command == 'refresh-share-state'): for p in Pool.objects.all(): import_shares(p, request) return Response() if (command == 'refresh-snapshot-state'): for share in Share.objects.all(): import_snapshots(share) return Response()
try: auto_update(enable=False) return Response({'enabled': False, }) except Exception, e: msg = ('Failed to disable auto update due to this exception: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) if (command == 'refresh-pool-state'): for p in Pool.objects.all(): fd = p.disk_set.first() if (fd is None): p.delete() mount_root(p) pool_info = get_pool_info(fd.name) p.name = pool_info['label'] p.raid = pool_raid('%s%s' % (settings.MNT_PT, p.name))['data'] p.size = pool_usage('%s%s' % (settings.MNT_PT, p.name))[0] p.save() return Response() if (command == 'refresh-share-state'): for p in Pool.objects.all(): import_shares(p) return Response() if (command == 'refresh-snapshot-state'): for share in Share.objects.all(): import_snapshots(share) return Response()
return Response({ 'enabled': False, }) except Exception, e: msg = ('Failed to disable auto update due to this exception: ' '%s' % e.__str__()) handle_exception(Exception(msg), request) if (command == 'refresh-pool-state'): for p in Pool.objects.all(): fd = p.disk_set.first() if (fd is None): p.delete() mount_root(p) pool_info = get_pool_info(fd.name) p.name = pool_info['label'] p.raid = pool_raid('%s%s' % (settings.MNT_PT, p.name))['data'] p.size = pool_usage('%s%s' % (settings.MNT_PT, p.name))[0] p.save() return Response() if (command == 'refresh-share-state'): for p in Pool.objects.all(): import_shares(p, request) return Response() if (command == 'refresh-snapshot-state'): for share in Share.objects.all(): import_snapshots(share) return Response()