Restripe BTRFS: add or remove devices from the particular mounted filesystem.
166054
def _restripe(mountpoint, direction, *devices, **kwargs):
    '''
    
    '''
    fs_log = []

    if salt.utils.fsutils._is_device(mountpoint):
        raise CommandExecutionError(
            "Mountpount expected, while device \"{0}\" specified".format(mountpoint))

    mounted = False
    for device, mntpoints in six.iteritems(salt.utils.fsutils._get_mounts("btrfs")):
        for mntdata in mntpoints:
            if mntdata['mount_point'] == mountpoint:
                mounted = True
                break

    if not mounted:
        raise CommandExecutionError(
            "No BTRFS device mounted on \"{0}\" mountpoint".format(mountpoint))

    if not devices:
        raise CommandExecutionError("No devices specified.")

    available_devices = __salt__['btrfs.devices']()
    for device in devices:
        if device not in six.iterkeys(available_devices):
            raise CommandExecutionError("Device \"{0}\" is not recognized".format(device))

    cmd = ['btrfs device {0}'.format(direction)]
    for device in devices:
        cmd.append(device)

    if direction == 'add':
        if kwargs.get("nodiscard"):
            cmd.append("-K")
        if kwargs.get("force"):
            cmd.append("-f")

    cmd.append(mountpoint)

    out = __salt__['cmd.run_all'](' '.join(cmd))
    salt.utils.fsutils._verify_run(out)
    if out['stdout']:
        fs_log.append(out['stdout'])

    if direction == 'add':
        out = None
        data_conversion = kwargs.get("dc")
        meta_conversion = kwargs.get("mc")
        if data_conversion and meta_conversion:
            out = __salt__['cmd.run_all'](
                "btrfs balance start -dconvert={0} -mconvert={1} {2}".format(
                    data_conversion, meta_conversion, mountpoint))
        else:
            out = __salt__['cmd.run_all']("btrfs filesystem balance {0}".format(mountpoint))
        salt.utils.fsutils._verify_run(out)
        if out['stdout']:
            fs_log.append(out['stdout'])

    # Summarize the result
    ret = {}
    if fs_log:
        ret.update({'log': '\n'.join(fs_log)})
    ret.update(__salt__['btrfs.info'](mountpoint))

    return ret
517299
private void pullDeviceFiles(IDevice device) throws Exception {
    for (String dir : DEVICE_DIRS) {
      pullDirectory(device, dir);
    }
  }
1213190
function (req, res, next) {
                    req.mounted = true
                    req.url     = req.url.replace(remove, '')

                    // clear cached req.path
                    delete req._path
                    delete req._pathLength

                    next()
                }
504686
def _mount(device):
    '''
    
    '''
    dest = tempfile.mkdtemp()
    res = __states__['mount.mounted'](dest, device=device, fstype='btrfs',
                                      opts='subvol=/', persist=False)
    if not res['result']:
        log.error('Cannot mount device %s in %s', device, dest)
        _umount(dest)
        return None
    return dest
168119
def add_device_override(self, addr, cat, subcat, firmware=None):
        """"""
        self.plm.devices.add_override(addr, 'cat', cat)
        self.plm.devices.add_override(addr, 'subcat', subcat)
        if firmware:
            self.plm.devices.add_override(addr, 'firmware', firmware)
1142311
def _fillVolumesAndPaths(self, paths):
        
        with self.btrfs as mount:
            for bv in mount.subvolumes:
                if not bv.readOnly:
                    continue

                vol = self._btrfsVol2StoreVol(bv)
                if vol is None:
                    continue

                path = bv.fullPath

                if path is None:
                    logger.info("Skipping deleted volume %s", bv.uuid)
                    continue

                relPath = None

                for path in bv.linuxPaths:
                    path = self._relativePath(path)

                    if path is None:
                        continue  # path is outside store scope

                    paths[vol].append(path)

                    infoPath = self._fullPath(path + Store.theInfoExtension)
                    if os.path.exists(infoPath):
                        logger.debug("Reading %s", infoPath)
                        with open(infoPath) as info:
                            Store.Volume.readInfo(info)

                    if not path.startswith("/"):
                        relPath = path

                if vol not in paths:
                    continue

                logger.debug("%s", vol.display(sink=self, detail='phrase'))

                if vol.uuid in self.butterVolumes:
                    logger.warn(
                        "Duplicate effective uuid %s in '%s' and '%s'",
                        vol.uuid, path, self.butterVolumes[vol.uuid].fullPath
                    )

                self.butterVolumes[vol.uuid] = bv

                if relPath is not None:
                    # vol is inside Store directory
                    self.extraVolumes[vol] = relPath
292554
def pvremove(devices, override=True):
    '''
    
    '''
    if isinstance(devices, six.string_types):
        devices = devices.split(',')

    cmd = ['pvremove', '-y']
    for device in devices:
        if pvdisplay(device):
            cmd.append(device)
        elif not override:
            raise CommandExecutionError('{0} is not a physical volume'.format(device))

    if not cmd[2:]:
        # Nothing to do
        return True

    out = __salt__['cmd.run_all'](cmd, python_shell=False)
    if out.get('retcode'):
        raise CommandExecutionError(out.get('stderr'))

    # Verify pvcremove was successful
    for device in devices:
        if pvdisplay(device, quiet=True):
            raise CommandExecutionError('Device "{0}" was not affected.'.format(device))

    return True
704801
def on_remove_vrf_conf(self, evt):
        
        vrf_conf = evt.value
        # Detach VrfConf change listener.
        vrf_conf.remove_listener(VrfConf.VRF_CHG_EVT, self.on_chg_vrf_conf)

        self._table_manager.remove_vrf_by_vrf_conf(vrf_conf)

        # Update local RT NLRIs
        self._rt_manager.update_local_rt_nlris()

        self._signal_bus.vrf_removed(vrf_conf.route_dist)

        # Remove AttributeMaps under the removed vrf
        rd = vrf_conf.route_dist
        rf = vrf_conf.route_family
        peers = self._peer_manager.iterpeers
        for peer in peers:
            key = ':'.join([rd, rf])
            peer.attribute_maps.pop(key, None)
566380
def devices():
    '''
    
    '''
    out = __salt__['cmd.run_all']("blkid -o export")
    salt.utils.fsutils._verify_run(out)

    return salt.utils.fsutils._blkid_output(out['stdout'], fs_type='btrfs')
1343397
def _treat_devices_removed(self):
        """"""
        for device in self._removed_ports.copy():
            eventlet.spawn_n(self._process_removed_port, device)
1074288
def chmod(hdfs_path, mode, user=None):
    
    host, port, path_ = path.split(hdfs_path, user)
    fs = hdfs(host, port, user)
    retval = fs.chmod(path_, mode)
    fs.close()
    return retval
907281
def router_removed_from_hosting_device(self, context, router):
        """"""
        self._notification(context, 'router_removed_from_hosting_device',
                           [router], operation=None, shuffle_agents=False)
1275013
def device_removed(self, device):
        """"""
        if not self._mounter.is_handleable(device):
            return
        device_file = device.device_presentation
        if (device.is_drive or device.is_toplevel) and device_file:
            self._show_notification(
                'device_removed',
                _('Device removed'),
                _('device disappeared on {0.device_presentation}', device),
                device.icon_name)
550921
def _add_device(self, scs_id, ha_id, name):
        
        if scs_id in self._devices:
            return

        self._devices[scs_id] = {
            'name': name,
            'ha_id': ha_id
        }
812591
def mount(self,
              fstype=None,
              options=None,
              auth_no_user_interaction=None):
        """"""
        return self._M.Filesystem.Mount(
            '(a{sv})',
            filter_opt({
                'fstype': ('s', fstype),
                'options': ('s', ','.join(options or [])),
                'auth.no_user_interaction': ('b', auth_no_user_interaction),
            })
        )
1297258
def rmrf(items, verbose=True):
    ""
    if isinstance(items, str):
        items = [items]

    for item in items:
        if verbose:
            print("Removing {}".format(item))
        shutil.rmtree(item, ignore_errors=True)
        # rmtree doesn't remove bare files
        try:
            os.remove(item)
        except FileNotFoundError:
            pass
194148
def remove_router_from_hosting_device(self, client, hosting_device_id,
                                          router_id):
        """"""
        res_path = hostingdevice.HostingDevice.resource_path
        return client.delete((res_path + DEVICE_L3_ROUTERS + "/%s") % (
            hosting_device_id, router_id))