def mounts_host_type_index(host_type): """ The host type index (hosts/hostgroups) - Allows you to get, put, or post host_type info ex. GET /mounts/hosts - returns all hosts """ if request.method == 'GET': try: return ok(Mounts(app=app).nfs_info[f"nfs_mounts::{host_type}"]) except BaseException: return error('invalid type. must be hostgroups or hosts') elif request.method == 'POST' or request.method == 'PUT': data = {} try: data = loads(request.data) except BaseException: return error('invalid json body. Please check syntax') if 'options' not in data.keys(): data[ 'options'] = 'rw,bg,suid,soft,rsize=16384,wsize=16384,vers=3,tcp' if 'owner' not in data.keys(): data['owner'] = 'root' if 'group' not in data.keys(): data['group'] = 'root' if 'local_path' not in data.keys(): return error('missing local_path for mount point') if 'share_path' not in data.keys(): return error('missing share_path for NAS share') if 'name' not in data.keys(): return error('missing name for host or hostgroup') if host_type == 'hosts': try: return ok( Mounts(app=app).add_nas_share( host=data['name'], local_path=data['local_path'], share_path=data['share_path'], owner=data['owner'], group=data['group'], options=data['options'])) except ExistsException as exc: return error(exc) except Exception as exc: return error(code=500, message=exc) elif host_type == 'hostgroups': try: return ok( Mounts(app=app).add_nas_share( hostgroup=data['name'], local_path=data['local_path'], share_path=data['share_path'], owner=data['owner'], group=data['group'], options=data['options'])) except ExistsException as exc: return error(exc) except Exception as exc: return error(code=500, message=exc) else: return error('invalid type. must be hostgroups or hosts')
def mounts_index(): """ A readness test will ensure you have the most up to date pull returns all mounts TODO: Place an index to avoid large returns """ return ok(Mounts(app=app).nfs_info)
def __init__(self, logger): """ """ self.logger = logger self.mounts = Mounts(self.logger) self.frozen_items = set() self.unfrozen_items = set()
def __init__(self, patching, logger, hutil): """ """ self.patching = patching self.logger = logger self.hutil = hutil try: self.mounts = Mounts(patching=self.patching, logger=self.logger) except Exception as e: errMsg = 'Failed to retrieve mount points, Exception %s, stack trace: %s' % ( str(e), traceback.format_exc()) self.logger.log(errMsg, True, 'Warning') self.logger.log(str(e), True) self.mounts = None self.frozen_items = set() self.unfrozen_items = set() self.freeze_handler = FreezeHandler(self.logger, self.hutil) self.mount_open_failed = False resource_disk = ResourceDiskUtil(patching=patching, logger=logger) self.resource_disk_mount_point = resource_disk.get_resource_disk_mount_point( ) self.skip_freeze = True self.isAquireLockSucceeded = True self.getLockRetry = 0 self.maxGetLockRetry = 5
def init_create(cls, source_path, deck_path): if exists(deck_path) and \ (not isdir(deck_path) or len(os.listdir(deck_path)) != 0): raise Error("`%s' exists and is not an empty directory" % deck_path) storage = DeckStorage(deck_path) makedirs(deck_path) storage.create(source_path) if os.geteuid() == 0: mounts = Mounts(source_path) if len(mounts): id = deckcache.new_id() deckcache.blob(id, "w").write(str(mounts)) storage.mounts_id = id elif storage.mounts_id: # make an identical copy of the blob newid = deckcache.new_id() print >> deckcache.blob(newid, "w"), deckcache.blob( storage.mounts_id).read() storage.mounts_id = newid deck = cls(deck_path) deck.mount() deck.add_level() return deck
def host_mount_index(host_type, name, uuid): """ The individual mount index - Allows get, delete, or patch (update a mount) ex. GET /mounts/hosts/hostname.example.com/<uuid> - returns a particular mount for that host """ if request.method == 'GET': try: return ok([ x for x in Mounts( app=app).nfs_info[f"nfs_mounts::{host_type}"][name] if x['uuid'] == uuid ]) except KeyError: return not_found() except Exception as exc: return error(exc) elif request.method == 'DELETE': try: Mounts(app=app).delete_host_mount(host_type=host_type, name=name, uuid_num=uuid) return ok(f'successfully deleted mount {uuid} for {name}') except KeyError: return not_found() except Exception as exc: return error(exc) else: data = {} try: data = loads(request.data) except BaseException: return error('invalid json body. Please check syntax') try: if host_type == 'hostgroups': return ok( Mounts(app=app).update_nas_share(uuid_num=uuid, replacement_dict=data, hostgroup=name)) elif host_type == 'hosts': return ok( Mounts(app=app).update_nas_share(uuid_num=uuid, replacement_dict=data, host=name)) except KeyError: return not_found() except Exception as exc: return error(exc)
def __init__(self, patching, logger): """ """ self.patching = patching self.logger = logger self.mounts = Mounts(patching=self.patching, logger=self.logger) self.frozen_items = set() self.unfrozen_items = set()
def __init__(self, patching, logger, hutil): """ """ self.patching = patching self.logger = logger self.hutil = hutil self.safeFreezeFolderPath = "safefreeze/bin/safefreeze" self.isArm64Machine = False try: platformMachine = platform.machine() architectureFromUname = os.uname()[-1] self.logger.log("platformMachine : " + str(platformMachine) + " architectureFromUname : " + str(architectureFromUname)) if ((platformMachine != None and (platformMachine.startswith("aarch64") or platformMachine.startswith("arm64"))) or (architectureFromUname != None and (architectureFromUname.startswith("aarch64") or architectureFromUname.startswith("arm64")))): self.isArm64Machine = True except Exception as e: errorMsg = "Unable to fetch machine processor architecture, error: %s, stack trace: %s" % ( str(e), traceback.format_exc()) self.logger.log(errorMsg, 'Error') if (self.isArm64Machine == True): self.logger.log("isArm64Machine : " + str(self.isArm64Machine) + " Using ARM64 safefreeze binary") self.safeFreezeFolderPath = "safefreezeArm64/bin/safefreeze" else: self.logger.log("isArm64Machine : " + str(self.isArm64Machine) + " Using x64 safefreeze binary") self.safeFreezeFolderPath = "safefreeze/bin/safefreeze" try: self.mounts = Mounts(patching=self.patching, logger=self.logger) except Exception as e: errMsg = 'Failed to retrieve mount points, Exception %s, stack trace: %s' % ( str(e), traceback.format_exc()) self.logger.log(errMsg, True, 'Warning') self.logger.log(str(e), True) self.mounts = None self.frozen_items = set() self.unfrozen_items = set() self.freeze_handler = FreezeHandler(self.logger, self.hutil) self.mount_open_failed = False resource_disk = ResourceDiskUtil(patching=patching, logger=logger) self.resource_disk_mount_point = resource_disk.get_resource_disk_mount_point( ) self.skip_freeze = True self.isAquireLockSucceeded = True self.getLockRetry = 0 self.maxGetLockRetry = 5 self.safeFreezelockFile = None
def mount(self): if self.is_mounted(): raise Error("`%s' already mounted" % self.path) levels = self.storage.get_levels() levels.reverse() aufs.mount(levels, self.path) if os.geteuid() == 0 and self.storage.mounts_id: Mounts(fstab=deckcache.blob(self.storage.mounts_id)).mount( self.path)
def host_index(host_type, name): """ The host index - Allows you to get all mounts or delete all mounts from being managed ex. GET /mounts/hosts/hostname.example.com - returns all mounts for that host """ if request.method == 'GET': try: return ok( Mounts(app=app).nfs_info[f"nfs_mounts::{host_type}"][name]) except KeyError: return not_found() except Exception as exc: return error(exc) else: try: Mounts(app=app).delete_host_name(host_type=host_type, name=name) return ok(f'successfully deleted {name}') except KeyError: return not_found() except Exception as exc: return error(exc)
def refresh_fstab(self): if not self.is_mounted(): raise Error("can't refresh fstab - `%s' not mounted" % self.path) if os.geteuid() != 0: raise Error( "no fstab to refresh - auto-mounting disabled for non-root users" ) fstab = str(Mounts(self.path)) if not self.storage.mounts_id: self.storage.mounts_id = deckcache.new_id() print >> deckcache.blob(self.storage.mounts_id, "w"), fstab
def __init__(self, patching, logger): """ """ self.patching = patching self.logger = logger try: self.mounts = Mounts(patching=self.patching, logger=self.logger) except Exception as e: errMsg = "Failed to retrieve mount points" self.logger.log(errMsg, True, 'Warning') self.mounts = None self.frozen_items = set() self.unfrozen_items = set() self.freeze_handler = FreezeHandler(self.logger)
def __init__(self, patching, logger): """ """ self.patching = patching self.logger = logger try: self.mounts = Mounts(patching = self.patching, logger = self.logger) except Exception as e: errMsg='Failed to retrieve mount points, Exception %s, stack trace: %s' % (str(e), traceback.format_exc()) self.logger.log(errMsg,True,'Warning') self.logger.log(str(e), True) self.mounts = None self.frozen_items = set() self.unfrozen_items = set() self.freeze_handler = FreezeHandler(self.logger)
def umount(self): if not self.is_mounted(): raise Error("`%s' not mounted" % self.path) if os.geteuid() == 0: self.refresh_fstab() mounts = Mounts(fstab=deckcache.blob(self.storage.mounts_id)) mounts.umount(self.path) try: aufs.umount(self.path) except: mounts.mount(self.path) raise aufs.umount(self.path)
def __init__(self, logger): """ """ self.logger = logger self.mounts = Mounts(self.logger)