(self, dev_path, mode="rwm")
return True
Add device to the configuration
Add device to the configuration
Add device to the configuration
def _add_device_spec(self, dev_path, mode="rwm"):
        """Add device to the configuration"""
        if not (os.path.exists(dev_path) and dev_path.startswith("/dev/")):
            Msg().err("Error: device not found", dev_path)
            return False
        dev_stat = os.stat(dev_path)
        if stat.S_ISBLK(dev_stat.st_mode):
            dev_type = 'b'
        elif stat.S_ISCHR(dev_stat.st_mode):
            dev_type = 'c'
        else:
            Msg().err("Error: not a device", dev_path)
            return False
        filemode = 0
        if 'r' in mode.lower():
            filemode += 0o444
        if 'w' in mode.lower():
            filemode += 0o222
        if not filemode:
            filemode = 0o666
        if "devices" not in self._container_specjson["linux"]:
            self._container_specjson["linux"]["devices"] = []
        device = {
            "path": dev_path,
            "type": dev_type,
            "major": os.major(dev_stat.st_dev),
            "minor": os.minor(dev_stat.st_dev),
            "fileMode": filemode,
            "uid": HostInfo.uid,
            "gid": HostInfo.gid,
        }
        self._container_specjson["linux"]["devices"].append(device)
        return True
def _add_device_spec ( self , dev_path , mode = "rwm" ) : if not ( os . path . exists ( dev_path ) and dev_path . startswith ( "/dev/" ) ) : Msg ( ) . err ( "Error: device not found" , dev_path ) return False dev_stat = os . stat ( dev_path ) if stat . S_ISBLK ( dev_stat . st_mode ) : dev_type = 'b' elif stat . S_ISCHR ( dev_stat . st_mode ) : dev_type = 'c' else : Msg ( ) . err ( "Error: not a device" , dev_path ) return False filemode = 0 if 'r' in mode . lower ( ) : filemode += 0o444 if 'w' in mode . lower ( ) : filemode += 0o222 if not filemode : filemode = 0o666 if "devices" not in self . _container_specjson [ "linux" ] : self . _container_specjson [ "linux" ] [ "devices" ] = [ ] device = { "path" : dev_path , "type" : dev_type , "major" : os . major ( dev_stat . st_dev ) , "minor" : os . minor ( dev_stat . st_dev ) , "fileMode" : filemode , "uid" : HostInfo . uid , "gid" : HostInfo . gid , } self . _container_specjson [ "linux" ] [ "devices" ] . append ( device ) return True