PK!%1main.py""" Zelt: Orchestrate Locust deployments in Kubernetes. Usage: zelt from-har ... -m [-w ] [--storage ] [--s3-bucket --s3-key ] [-p ]... [--clean] [--logging ] zelt from-har ... --local [-p ]... [--logging ] zelt from-har --config [--local] [--clean] [--logging ] zelt from-locustfile -m [-w ] [--storage ] [--s3-bucket --s3-key ] [--clean] [--logging ] zelt from-locustfile --local [--logging ] zelt from-locustfile --config [--local] [--clean] [--logging ] zelt rescale -m [--logging ] zelt rescale --config [--logging ] zelt delete -m [--storage ] [--s3-bucket --s3-key ] [--logging ] zelt delete --config [--logging ] zelt --help zelt --version Options: -h, --help Show this screen. -v, --version Show version. -p, --transformer-plugins= Module name of Transformer plugin (repeatable). -m, --manifests= Path to manifest files. -w, --worker-pods= Number of worker pods to deploy [default: 1]. -s, --storage= Remote locustfile storage method (S3 or ConfigMap) [default: ConfigMap]. --s3-bucket= Name of S3 bucket for remote locustfile storage. --s3-key= Name of S3 key for remote locustfile storage. -c, --clean Delete and redeploy remote resources. -l, --local Run Locust locally. --logging= Set logging level (INFO, DEBUG, or ERROR) [default: INFO]. --config= Optional configuration file specifying options. """ import logging import os import pkg_resources import sys import yaml from docopt import docopt from pathlib import Path from typing import NamedTuple, Sequence import zelt from zelt.zelt import StorageMethod class Config(NamedTuple): from_har: bool from_locustfile: bool rescale: bool delete: bool har_files: Sequence[os.PathLike] locustfile: os.PathLike transformer_plugins: Sequence[str] manifests: os.PathLike worker_pods: int required_pods: int storage: str s3_bucket: str s3_key: str clean: bool local: bool logging: str def cli(): """ Entrypoint for Zelt. """ # Disable deprecation warning coming from Kubernetes client's YAML loading. # See https://github.com/yaml/pyyaml/wiki/PyYAML-yaml.load(input)-Deprecation yaml.warnings({"YAMLLoadWarning": False}) config = _load_config(docopt(__doc__, version=_version())) logging.basicConfig(level=config.logging) if config.from_har: config = config._replace( locustfile=zelt.invoke_transformer( paths=config.har_files, plugin_names=config.transformer_plugins ) ) _deploy(config) if config.from_locustfile: _deploy(config) if config.rescale: _rescale(config) if config.delete: _delete(config) def _version() -> str: return pkg_resources.get_distribution("zelt").version def _deploy(config: Config) -> None: """ Deploys Locust. """ try: zelt.deploy( config.locustfile, int(config.worker_pods), config.manifests, config.clean, StorageMethod.from_storage_arg(config.storage), config.local, config.s3_bucket, config.s3_key, ) except Exception as e: logging.fatal("Error: %s", e) exit(1) def _rescale(config: Config) -> None: """ Rescales a worker deployment. """ try: zelt.rescale(config.manifests, int(config.required_pods)) except Exception as e: logging.fatal("Error: %s", e) exit(1) def _delete(config: Config) -> None: """ Deletes a deployment. """ try: zelt.delete( config.manifests, StorageMethod.from_storage_arg(config.storage), config.s3_bucket, config.s3_key, ) except Exception as e: logging.fatal("Error: %s", e) exit(1) def _load_config(config: dict) -> Config: """ Loads config from command-line or file. """ config = _normalise_config(config) if config["config"]: config = {**config, **yaml.safe_load(Path(config["config"]).read_text())} return Config( from_har=config["from-har"], from_locustfile=config["from-locustfile"], rescale=config["rescale"], delete=config["delete"], har_files=config.get("har-files", []), locustfile=config["locustfile"], transformer_plugins=config.get("transformer-plugins", []), manifests=config["manifests"], worker_pods=config["worker-pods"], required_pods=config["required-pods"], storage=config["storage"], s3_bucket=config["s3-bucket"], s3_key=config["s3-key"], clean=config["clean"], local=config["local"], logging=config["logging"], ) def _normalise_config(config: dict) -> dict: """ Removes special characters from config keys. """ normalised_config = {} for k in config: normalised_config[ k.replace("--", "").replace("<", "").replace(">", "") ] = config[k] return normalised_config PK!Ha#!%zelt-1.2.1.dist-info/entry_points.txtN+I/N.,()J)M̳JPK!d*++zelt-1.2.1.dist-info/LICENSEMIT License Copyright (c) 2019 Zalando SE Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTUzelt-1.2.1.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HZ:izelt-1.2.1.dist-info/METADATAX[s6~{Eʉtq<-&d$'cA$$& .ZQT&d·s/`3$I~ LD#ZjakqţO~tsc\ h]츪z}h#~V ͋/5,Ax~(>y;~~c*`XZg;ӧvXkăUUxg@*JEv=ʪMe-"S,A~B Q"J^"-%ױռ4s H"f ǝT^'/ (y*횐@"bFRF"׽H3aR-+q|Ɠu%HG^gjUFax.gLѡ,3Y P;0ųa?GQOI=,sY f̔NQ 2RLTZQsv{,3%1;V(AIKTeJd+NZWvKsIy.&лVf+1EBAM>3T>݆A 5G§&ԁ1uS$ubZ=&P%{ɖKx䫛˓Oףﲠ~&edyi+3&6/\ܵ1&5:c's D$MMQWSJ>"i\Vv:=WEPPƜt+ Ser#F~NG*E۟//O6 =  jJW 4;# &(2e\Z61QA6G;{@ 1s0HJ. < dPM0`#J4 ԕ[I4R;jOǶҤ߃?569^n2*-2?g  `dT'=m<% %.7Bo:  ^Pn€pLF#3P./Ӏ*Co Iҹ~Bai v~'L;Iּ;= iƀWxޏԐ;k#}ZT=2eO0ZuA*@1JI 4j!MOoO&dxkRdl:gk !ԺTkB=Cѯ]uVbl|F9 h>9߮5 cwOv,|%FD⟦nY1L3P_r%9r-9o0h3\4+7̎%^h ұhZ**OVBI\wLL&+^B鼕nQԼ&HՏO><;}$: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