(self)
Setup the shared folders associated with the container.
Setup the shared folders associated with the container.
Setup the shared folders associated with the container .
def _setup_shares(self):
        """ Setup the shared folders associated with the container. """
        if 'shares' not in self.options:
            return

        logger.info('Setting up shares...')

        if not self._host.has_subuidgid_been_set():
            raise ContainerOperationFailed()

        container = self._container

        # First, let's make an inventory of shared sources that were already there.
        existing_shares = {
            k: d for k, d in container.devices.items() if k.startswith('lxdockshare')
        }

        # Let's get rid of previously set up lxdock shares.
        for k in existing_shares:
            del container.devices[k]

        for i, share in enumerate(self.options.get('shares', []), start=1):
            source = os.path.join(self.homedir, share['source'])
            shareconf = {'type': 'disk', 'source': source, 'path': share['dest'], }

            extra_properties = share.pop('share_properties', {})
            extra_properties.pop("type", None)
            extra_properties.pop("source", None)
            extra_properties.pop("path", None)
            shareconf.update(extra_properties)

            # Upstream issue: https://github.com/lxc/lxd/issues/4538
            if shareconf.get("optional", "false").lower() in {"true", "1", "on", "yes"}:
                if not os.path.exists(source):
                    continue

            container.devices['lxdockshare%s' % i] = shareconf

        guest_username = self.options.get("users", [{"name": "root"}])[0]["name"]
        host_uid, host_gid = self._host.uidgid()
        guest_uid, guest_gid = self._guest.uidgid(guest_username)
        raw_idmap = "uid {} {}\ngid {} {}".format(host_uid, guest_uid, host_gid, guest_gid)
        raw_idmap_updated = container.config.get("raw.idmap") != raw_idmap
        if raw_idmap_updated:
            container.config["raw.idmap"] = raw_idmap

        container.save(wait=True)

        if raw_idmap_updated:
            # the container must be restarted for this to take effect
            logger.info(
              "share uid map (raw.idmap) updated, container must be restarted to take effect"
            )
            container.restart(wait=True)
            self._setup_ip()
def _setup_shares ( self ) : if 'shares' not in self . options : return logger . info ( 'Setting up shares...' ) if not self . _host . has_subuidgid_been_set ( ) : raise ContainerOperationFailed ( ) container = self . _container # First, let's make an inventory of shared sources that were already there. existing_shares = { k : d for k , d in container . devices . items ( ) if k . startswith ( 'lxdockshare' ) } # Let's get rid of previously set up lxdock shares. for k in existing_shares : del container . devices [ k ] for i , share in enumerate ( self . options . get ( 'shares' , [ ] ) , start = 1 ) : source = os . path . join ( self . homedir , share [ 'source' ] ) shareconf = { 'type' : 'disk' , 'source' : source , 'path' : share [ 'dest' ] , } extra_properties = share . pop ( 'share_properties' , { } ) extra_properties . pop ( "type" , None ) extra_properties . pop ( "source" , None ) extra_properties . pop ( "path" , None ) shareconf . update ( extra_properties ) # Upstream issue: https://github.com/lxc/lxd/issues/4538 if shareconf . get ( "optional" , "false" ) . lower ( ) in { "true" , "1" , "on" , "yes" } : if not os . path . exists ( source ) : continue container . devices [ 'lxdockshare%s' % i ] = shareconf guest_username = self . options . get ( "users" , [ { "name" : "root" } ] ) [ 0 ] [ "name" ] host_uid , host_gid = self . _host . uidgid ( ) guest_uid , guest_gid = self . _guest . uidgid ( guest_username ) raw_idmap = "uid {} {}\ngid {} {}" . format ( host_uid , guest_uid , host_gid , guest_gid ) raw_idmap_updated = container . config . get ( "raw.idmap" ) != raw_idmap if raw_idmap_updated : container . config [ "raw.idmap" ] = raw_idmap container . save ( wait = True ) if raw_idmap_updated : # the container must be restarted for this to take effect logger . info ( "share uid map (raw.idmap) updated, container must be restarted to take effect" ) container . restart ( wait = True ) self . _setup_ip ( )