ok
Direktori : /opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/feature_suites/ |
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/feature_suites/suites.py |
# -*- coding: utf-8 -*- # Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2022 All Rights Reserved # # Licensed under CLOUD LINUX LICENSE AGREEMENT # http://cloudlinux.com/docs/LICENSE.TXT # suites.py - definitions of AccelerateWP feature suites from enum import Enum from typing import Set, List, Dict, Any import os from clcommon.lib.cledition import is_cl_solo_edition from clwpos.optimization_features import ( Feature, OBJECT_CACHE_FEATURE, SITE_OPTIMIZATION_FEATURE, CDN_FEATURE, CRITICAL_CSS_FEATURE, IMAGE_OPTIMIZATION_FEATURE ) from dataclasses import dataclass, field PREMIUM_ENABLE_FLAG = '/var/lve/enable-wpos.flag' # TODO: [unification] investigate could we keep same default value for Shared Pro and Solo IS_FREE_SUITE_ALLOWED_BY_DEFAULT = bool(is_cl_solo_edition()) # TODO: discuss this with Dennis # TODO: [unification] investigate could we keep same default value for Shared Pro and Solo IS_PREMIUM_SUITE_ALLOWED_BY_DEFAULT = is_cl_solo_edition() and os.path.isfile(PREMIUM_ENABLE_FLAG) # TODO: [unification] investigate could we keep same default value for Shared Pro and Solo IS_CDN_SUITE_ALLOWED_BY_DEFAULT = is_cl_solo_edition() class TrafficLimit(Enum): LIMIT_50_GB = "50 GB" LIMIT_100_GB = "100 GB" LIMIT_250_GB = "250 GB" LIMIT_500_GB = "500 GB" LIMIT_1_TB = "1 TB" LIMIT_2_5_TB = "2.5 TB" LIMIT_5_TB = "5 TB" LIMIT_10_TB = "10 TB" @dataclass class Attribute: """Base model of attribute supported by suite""" name: str type: type default: Any = None @dataclass class Suite: """Base Suite implementation""" name: str features: Set # for some cases we need to handle only primary feature (e.g for CDN suite = cdn feature) primary: Set is_allowed_by_default: bool allowed_attrubites: List[Attribute] = field(default_factory=list) @property def feature_set(self) -> Set[Feature]: """""" return self.features @property def primary_features(self) -> Set[Feature]: """""" return self.primary AWPSuite = Suite( name='accelerate_wp', features={ SITE_OPTIMIZATION_FEATURE }, primary={ SITE_OPTIMIZATION_FEATURE }, is_allowed_by_default=IS_FREE_SUITE_ALLOWED_BY_DEFAULT ) PremiumSuite = Suite( name='accelerate_wp_premium', features={ OBJECT_CACHE_FEATURE, CRITICAL_CSS_FEATURE, IMAGE_OPTIMIZATION_FEATURE }, primary={ OBJECT_CACHE_FEATURE, CRITICAL_CSS_FEATURE, IMAGE_OPTIMIZATION_FEATURE }, is_allowed_by_default=IS_PREMIUM_SUITE_ALLOWED_BY_DEFAULT ) # Free CDN suite (1GB) CDNSuite = Suite( name='accelerate_wp_cdn', features={ SITE_OPTIMIZATION_FEATURE, CDN_FEATURE }, primary={ CDN_FEATURE }, is_allowed_by_default=IS_CDN_SUITE_ALLOWED_BY_DEFAULT ) # Premium CDN suite (50GB) CDNSuitePro = Suite( name='accelerate_wp_cdn_pro', features={ SITE_OPTIMIZATION_FEATURE, CDN_FEATURE }, primary={ CDN_FEATURE }, is_allowed_by_default=IS_PREMIUM_SUITE_ALLOWED_BY_DEFAULT, allowed_attrubites=[ Attribute(name='traffic_limit', type=TrafficLimit, default=TrafficLimit.LIMIT_50_GB) ] ) ALL_SUITES: Dict[str, Suite] = { AWPSuite.name: AWPSuite, PremiumSuite.name: PremiumSuite, CDNSuite.name: CDNSuite, CDNSuitePro.name: CDNSuitePro } SUPPORTED_SUITES = { AWPSuite.name: AWPSuite, PremiumSuite.name: PremiumSuite, CDNSuite.name: CDNSuite, CDNSuitePro.name: CDNSuitePro } # for backward compatibility with old configs OLD_NEW_SUITE_NAME_PAIRS = { 'object_cache': 'accelerate_wp_premium', 'site_optimization': 'accelerate_wp' }