"""ZFS grain provider"""importlogging# Solve the Chicken and egg problem where grains need to run before any# of the modules are loaded and are generally available for any usage.importsalt.modules.cmdmodimportsalt.utils.dictupdateimportsalt.utils.platformimportsaltext.zfs.utils.zfs__virtualname__="zfs"__salt__={"cmd.run":salt.modules.cmdmod.run,}log=logging.getLogger(__name__)def__virtual__():# We always load this grain so we can properly export# at least the zfs_support grain# except for Windows... don't try to load this on Windows (#51703)ifsalt.utils.platform.is_windows():returnFalse,"ZFS: Not available on Windows"return__virtualname__def_zfs_pool_data():""" Provide grains about zpools """grains={}# collect zpool datazpool_list_cmd=saltext.zfs.utils.zfs.zpool_command("list",flags=["-H"],opts={"-o":"name,size"},)forzpoolin__salt__["cmd.run"](zpool_list_cmd,ignore_retcode=True).splitlines():if"zpool"notingrains:grains["zpool"]={}zpool=zpool.split()grains["zpool"][zpool[0]]=saltext.zfs.utils.zfs.to_size(zpool[1],False)returngrains
[docs]defzfs():""" Provide grains for zfs/zpool """grains={}grains["zfs_support"]=saltext.zfs.utils.zfs.is_supported()grains["zfs_feature_flags"]=saltext.zfs.utils.zfs.has_feature_flags()ifgrains["zfs_support"]:grains=salt.utils.dictupdate.update(grains,_zfs_pool_data(),merge_lists=True)returngrains