def prepare_disk(device_path): partition_path = "{dev}1".format(dev=device_path) mount_point = tempfile.mkdtemp(suffix=partition_path.rsplit("/", 1)[-1]) if not sys.platform.startswith("linux"): if settings.DEBUG: logger.debug("(virtually) formatting disk {}".format(device_path)) logger.debug("(virtual) mount point: {}".format(mount_point)) return mount_point else: raise NotImplemented("USB exports is Linux-only") logger.debug("unmounting {}".format(device_path)) unmount_device(device_path) us_environ = get_us_env() uid = os.getuid() gid = os.getgid() with sh.sudo: logger.debug("resetting partition table for {}".format(device_path)) sh.parted( "-s", "-a", "optimal", device_path, "--", "mklabel", "msdos", "mkpart", "primary", "fat32", "64s", "-1s", _env=us_environ, ) logger.debug("formatting {}".format(partition_path)) sh.mkfs("-t", "vfat", "-F", "32", "-n", "SLDSES", partition_path, _env=us_environ) logger.debug("mounting {} to {}".format(partition_path, mount_point)) sh.mount( "-o", "umask=0,dmask=000,fmask=111,uid={uid},gid={gid},utf8".format( uid=uid, gid=gid), partition_path, mount_point, ) return mount_point
def create_filesystem(path): try: # Create filesystem without user intervention, -F # NEED to be extra careful here!!!! mkfs("-t", "ext4", "-F", path) except Exception as ex: msg = (_('create file system failed exception is : %s'), six.text_type(ex)) LOG.error(msg) raise exception.HPEPluginFileSystemException(reason=msg) return True
def create_filesystem(self): filesystem = os.getenv('REMORA_DEFAULT_FILESYSTEM', 'ext4') logger.debug('Creating {} filesystem on {}'.format( filesystem, self.name)) try: mkfs('-t', filesystem, self.device_name) except ErrorReturnCode as err: logger.error('Failed to create {} filesystem on {}'.format( filesystem, self.name)) logger.debug(err) return False return True
def create_filesystem(path): try: # Create filesystem without user intervention, -F # NEED to be extra careful here!!!! # mkfs("-t", "ext4", "-F", path) # The containerized version of the plugin runs on Alpine # and there is no default mkfs. Therefore, we link # mkfs to mkfs.ext4 in our Dockerfile, so no need to # specify -t ext4. mkfs("-F", path) except Exception as ex: msg = (_('create file system failed exception is : %s'), six.text_type(ex)) LOG.error(msg) raise exception.HPEPluginFileSystemException(reason=msg) return True
def setupDisks(numDisks): print "Setup Disks" devLetters = list(string.ascii_lowercase) for x in range(1, int(numDisks) + 1): try: mkfs("/dev/xvd" + devLetters[x], "-text4", "-E lazy_itable_init=1") except Exception as e: pass if not os.path.exists("/mnt/data" + str(x)): os.makedirs("/mnt/data" + str(x)) try: mount("/dev/xvd" + devLetters[x], "/mnt/data" + str(x), "-text4") except Exception as e: pass try: Fstab.add("/dev/xvd" + devLetters[x], "/mnt/data" + str(x), filesystem="ext4") except Exception as e: pass
def format(device, fs_type, fs_options, sudo=False): mkfs_args = ['--type=%s' % fs_type] if fs_options: mkfs_args.extend(fs_options.split()) if sudo: mkfs = sh.sudo('-n', 'mkfs', *mkfs_args) else: mkfs = sh.mkfs(*mkfs_args) return mkfs
def CreateFileSystem(self, filepath): container = self.containers[filepath] self.logger.info('Creating filesystem on encrypted container [{0}]'.format(container.filepath)) sh.mkfs('-t','btrfs', container.mapped_device) self.logger.info('Created filesystem on encrypted container [{0}]'.format(container.filepath))