code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def get_container_type(self) -> Optional[str]: """Get Mesos containerizer type. Default to DOCKER if gpus are not used. :returns: Mesos containerizer type, DOCKER or MESOS""" if self.get_gpus() is not None: container_type = "MESOS" else: container_type =...
Get Mesos containerizer type. Default to DOCKER if gpus are not used. :returns: Mesos containerizer type, DOCKER or MESOS
get_container_type
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_env_dictionary( self, system_paasta_config: Optional["SystemPaastaConfig"] = None ) -> Dict[str, str]: """A dictionary of key/value pairs that represent environment variables to be injected to the container environment""" env = { "PAASTA_SERVICE": self.service, ...
A dictionary of key/value pairs that represent environment variables to be injected to the container environment
get_env_dictionary
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_env( self, system_paasta_config: Optional["SystemPaastaConfig"] = None ) -> Dict[str, str]: """Basic get_env that simply returns the basic env, other classes might need to override this getter for more implementation-specific env getting""" return self.get_env_diction...
Basic get_env that simply returns the basic env, other classes might need to override this getter for more implementation-specific env getting
get_env
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_args(self) -> Optional[List[str]]: """Get the docker args specified in the service's configuration. If not specified in the config and if cmd is not specified, defaults to an empty array. If not specified in the config but cmd is specified, defaults to null. If specified in the ...
Get the docker args specified in the service's configuration. If not specified in the config and if cmd is not specified, defaults to an empty array. If not specified in the config but cmd is specified, defaults to null. If specified in the config and if cmd is also specified, throws an excepti...
get_args
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_deploy_constraints( self, blacklist: DeployBlacklist, whitelist: DeployWhitelist, system_deploy_blacklist: DeployBlacklist, system_deploy_whitelist: DeployWhitelist, ) -> List[Constraint]: """Return the combination of deploy_blacklist and deploy_whitelist ...
Return the combination of deploy_blacklist and deploy_whitelist as a list of constraints.
get_deploy_constraints
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_docker_image(self) -> str: """Get the docker image name (with tag) for a given service branch from a generated deployments.json file.""" if self.branch_dict is not None: return self.branch_dict["docker_image"] else: return ""
Get the docker image name (with tag) for a given service branch from a generated deployments.json file.
get_docker_image
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_image_version(self) -> Optional[str]: """Get additional information identifying the Docker image from a generated deployments.json file.""" if self.branch_dict is not None and "image_version" in self.branch_dict: return self.branch_dict["image_version"] else: ...
Get additional information identifying the Docker image from a generated deployments.json file.
get_image_version
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_desired_state(self) -> str: """Get the desired state (either 'start' or 'stop') for a given service branch from a generated deployments.json file.""" if self.branch_dict is not None: return self.branch_dict["desired_state"] else: return "start"
Get the desired state (either 'start' or 'stop') for a given service branch from a generated deployments.json file.
get_desired_state
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_force_bounce(self) -> Optional[str]: """Get the force_bounce token for a given service branch from a generated deployments.json file. This is a token that, when changed, indicates that the instance should be recreated and bounced, even if no other parameters have changed. This ma...
Get the force_bounce token for a given service branch from a generated deployments.json file. This is a token that, when changed, indicates that the instance should be recreated and bounced, even if no other parameters have changed. This may be None or a string, generally a timestamp. ...
get_force_bounce
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_dependencies(self) -> Optional[Dict]: """Get the contents of the dependencies_dict pointed to by the dependency_reference or 'main' if no dependency_reference exists Defaults to None if not specified in the config. :returns: A list of dictionaries specified in the dependencies_...
Get the contents of the dependencies_dict pointed to by the dependency_reference or 'main' if no dependency_reference exists Defaults to None if not specified in the config. :returns: A list of dictionaries specified in the dependencies_dict, None if not specified
get_dependencies
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_outbound_firewall(self) -> Optional[str]: """Return 'block', 'monitor', or None as configured in security->outbound_firewall Defaults to None if not specified in the config :returns: A string specified in the config, None if not specified""" security = self.config_dict.get("sec...
Return 'block', 'monitor', or None as configured in security->outbound_firewall Defaults to None if not specified in the config :returns: A string specified in the config, None if not specified
get_outbound_firewall
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def color_text(color: str, text: str) -> str: """Return text that can be printed color. :param color: ANSI color code :param text: a string :return: a string with ANSI color encoding""" if os.getenv("NO_COLOR", "0") == "1": return text # any time text retur...
Return text that can be printed color. :param color: ANSI color code :param text: a string :return: a string with ANSI color encoding
color_text
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_git_url(service: str, soa_dir: str = DEFAULT_SOA_DIR) -> str: """Get the git url for a service. Assumes that the service's repo matches its name, and that it lives in services- i.e. if this is called with the string 'test', the returned url will be git@github.yelpcorp.com:services/test. :pa...
Get the git url for a service. Assumes that the service's repo matches its name, and that it lives in services- i.e. if this is called with the string 'test', the returned url will be git@github.yelpcorp.com:services/test. :param service: The service name to get a URL for :returns: A git url to the...
get_git_url
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def register_log_writer(name: str) -> Callable[[_LogWriterTypeT], _LogWriterTypeT]: """Returns a decorator that registers that log writer class at a given name so get_log_writer_class can find it.""" def outer(log_writer_class: _LogWriterTypeT) -> _LogWriterTypeT: _log_writer_classes[name] = log_wr...
Returns a decorator that registers that log writer class at a given name so get_log_writer_class can find it.
register_log_writer
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def configure_log() -> None: """We will log to the yocalhost binded scribe.""" log_writer_config = load_system_paasta_config().get_log_writer() global _log_writer LogWriterClass = get_log_writer_class(log_writer_config["driver"]) _log_writer = LogWriterClass(**log_writer_config.get("options", {}))
We will log to the yocalhost binded scribe.
configure_log
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def format_log_line( level: str, cluster: str, service: str, instance: str, component: str, line: str, timestamp: str = None, ) -> str: """Accepts a string 'line'. Returns an appropriately-formatted dictionary which can be serialized to JSON for logging and which contains 'line'...
Accepts a string 'line'. Returns an appropriately-formatted dictionary which can be serialized to JSON for logging and which contains 'line'.
format_log_line
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def format_audit_log_line( cluster: str, instance: str, user: str, host: str, action: str, action_details: dict = None, service: str = None, timestamp: str = None, ) -> str: """Accepts: * a string 'user' describing the user that initiated the action * a string 'host'...
Accepts: * a string 'user' describing the user that initiated the action * a string 'host' describing the server where the user initiated the action * a string 'action' describing an action performed by paasta_tools * a dict 'action_details' optional information about the action Re...
format_audit_log_line
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def log( self, service: str, line: str, component: str, level: str = DEFAULT_LOGLEVEL, cluster: str = ANY_CLUSTER, instance: str = ANY_INSTANCE, ) -> None: """This expects someone (currently the paasta cli main()) to...
This expects someone (currently the paasta cli main()) to have already configured the log object. We'll just write things to it.
log
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def timed_flock(fd: _AnyIO, seconds: int = 1) -> Iterator[None]: """Attempt to grab an exclusive flock with a timeout. Uses Timeout, so will raise a TimeoutError if `seconds` elapses before the flock can be obtained """ # We don't want to wrap the user code in the timeout, just the flock grab flock_...
Attempt to grab an exclusive flock with a timeout. Uses Timeout, so will raise a TimeoutError if `seconds` elapses before the flock can be obtained
timed_flock
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def _timeout(process: Popen) -> None: """Helper function for _run. It terminates the process. Doesn't raise OSError, if we try to terminate a non-existing process as there can be a very small window between poll() and kill() """ if process.poll() is None: try: # sending SIGKILL t...
Helper function for _run. It terminates the process. Doesn't raise OSError, if we try to terminate a non-existing process as there can be a very small window between poll() and kill()
_timeout
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_readable_files_in_glob(glob: str, path: str) -> List[str]: """ Returns a sorted list of files that are readable in an input glob by recursively searching a path """ globbed_files = [] for root, dirs, files in os.walk(path): for f in files: fn = os.path.join(root, f) ...
Returns a sorted list of files that are readable in an input glob by recursively searching a path
get_readable_files_in_glob
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def load_system_paasta_config( path: str = PATH_TO_SYSTEM_PAASTA_CONFIG_DIR, ) -> "SystemPaastaConfig": """ Reads Paasta configs in specified directory in lexicographical order and deep merges the dictionaries (last file wins). """ if not os.path.isdir(path): raise PaastaNotConfiguredErr...
Reads Paasta configs in specified directory in lexicographical order and deep merges the dictionaries (last file wins).
load_system_paasta_config
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def optionally_load_system_paasta_config( path: str = PATH_TO_SYSTEM_PAASTA_CONFIG_DIR, ) -> "SystemPaastaConfig": """ Tries to load the system paasta config, but will return an empty configuration if not available, without raising. """ try: return load_system_paasta_config(path=path) ...
Tries to load the system paasta config, but will return an empty configuration if not available, without raising.
optionally_load_system_paasta_config
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def parse_system_paasta_config( file_stats: FrozenSet[Tuple[str, os.stat_result]], path: str ) -> "SystemPaastaConfig": """Pass in a dictionary of filename -> os.stat_result, and this returns the merged parsed configs""" config: SystemPaastaConfigDict = {} for filename, _ in file_stats: with ope...
Pass in a dictionary of filename -> os.stat_result, and this returns the merged parsed configs
parse_system_paasta_config
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_default_spark_driver_pool_override(self) -> str: """ If defined, fetches the override for what pool to run a Spark driver in. Otherwise, returns the default Spark driver pool. :returns: The default_spark_driver_pool_override specified in the paasta configuration """ ...
If defined, fetches the override for what pool to run a Spark driver in. Otherwise, returns the default Spark driver pool. :returns: The default_spark_driver_pool_override specified in the paasta configuration
get_default_spark_driver_pool_override
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_zk_hosts(self) -> str: """Get the zk_hosts defined in this hosts's cluster config file. Strips off the zk:// prefix, if it exists, for use with Kazoo. :returns: The zk_hosts specified in the paasta configuration """ try: hosts = self.config_dict["zookeeper"] ...
Get the zk_hosts defined in this hosts's cluster config file. Strips off the zk:// prefix, if it exists, for use with Kazoo. :returns: The zk_hosts specified in the paasta configuration
get_zk_hosts
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_system_docker_registry(self) -> str: """Get the docker_registry defined in this host's cluster config file. :returns: The docker_registry specified in the paasta configuration """ try: return self.config_dict["docker_registry"] except KeyError: ra...
Get the docker_registry defined in this host's cluster config file. :returns: The docker_registry specified in the paasta configuration
get_system_docker_registry
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_hacheck_sidecar_volumes(self) -> List[DockerVolume]: """Get the hacheck sidecar volumes defined in this host's hacheck_sidecar_volumes config file. :returns: The list of volumes specified in the paasta configuration """ try: volumes = self.config_dict["hacheck_sideca...
Get the hacheck sidecar volumes defined in this host's hacheck_sidecar_volumes config file. :returns: The list of volumes specified in the paasta configuration
get_hacheck_sidecar_volumes
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_volumes(self) -> Sequence[DockerVolume]: """Get the volumes defined in this host's volumes config file. :returns: The list of volumes specified in the paasta configuration """ try: return self.config_dict["volumes"] except KeyError: raise PaastaNo...
Get the volumes defined in this host's volumes config file. :returns: The list of volumes specified in the paasta configuration
get_volumes
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_cluster(self) -> str: """Get the cluster defined in this host's cluster config file. :returns: The name of the cluster defined in the paasta configuration """ try: return self.config_dict["cluster"] except KeyError: raise PaastaNotConfiguredError(...
Get the cluster defined in this host's cluster config file. :returns: The name of the cluster defined in the paasta configuration
get_cluster
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_log_writer(self) -> LogWriterConfig: """Get the log_writer configuration out of global paasta config :returns: The log_writer dictionary. """ try: return self.config_dict["log_writer"] except KeyError: raise PaastaNotConfiguredError( ...
Get the log_writer configuration out of global paasta config :returns: The log_writer dictionary.
get_log_writer
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_log_reader(self) -> LogReaderConfig: """Get the log_reader configuration out of global paasta config :returns: the log_reader dictionary. """ try: return self.config_dict["log_reader"] except KeyError: raise PaastaNotConfiguredError( ...
Get the log_reader configuration out of global paasta config :returns: the log_reader dictionary.
get_log_reader
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_log_readers(self) -> List[LogReaderConfig]: """Get the log_readers configuration out of global paasta config :returns: the log_readers list of dicts. """ try: return self.config_dict["log_readers"] except KeyError: raise PaastaNotConfiguredError( ...
Get the log_readers configuration out of global paasta config :returns: the log_readers list of dicts.
get_log_readers
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_metrics_provider(self) -> Optional[str]: """Get the metrics_provider configuration out of global paasta config :returns: A string identifying the metrics_provider """ deployd_metrics_provider = self.config_dict.get("deployd_metrics_provider") if deployd_metrics_provider ...
Get the metrics_provider configuration out of global paasta config :returns: A string identifying the metrics_provider
get_metrics_provider
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_synapse_haproxy_url_format(self) -> str: """Get a format string for the URL to query for haproxy-synapse state. This format string gets two keyword arguments, host and port. Defaults to "http://{host:s}:{port:d}/;csv;norefresh". :returns: A format string for constructing the URL of hapr...
Get a format string for the URL to query for haproxy-synapse state. This format string gets two keyword arguments, host and port. Defaults to "http://{host:s}:{port:d}/;csv;norefresh". :returns: A format string for constructing the URL of haproxy-synapse's status page.
get_synapse_haproxy_url_format
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_envoy_admin_endpoint_format(self) -> str: """Get the format string for Envoy's admin interface.""" return self.config_dict.get( "envoy_admin_endpoint_format", "http://{host:s}:{port:d}/{endpoint:s}" )
Get the format string for Envoy's admin interface.
get_envoy_admin_endpoint_format
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_envoy_admin_port(self) -> int: """Get the port that Envoy's admin interface is listening on from /etc/services.""" return socket.getservbyname( self.config_dict.get("envoy_admin_domain_name", "envoy-admin") )
Get the port that Envoy's admin interface is listening on from /etc/services.
get_envoy_admin_port
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_git_config(self) -> Dict: """Gets git configuration. Includes repo names and their git servers. :returns: the git config dict """ return self.config_dict.get( "git_config", { "git_user": "git", "repos": { ...
Gets git configuration. Includes repo names and their git servers. :returns: the git config dict
get_git_config
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_gunicorn_exporter_sidecar_image_url(self) -> str: """Get the docker image URL for the gunicorn_exporter sidecar container""" return self.config_dict.get( "gunicorn_exporter_sidecar_image_url", "docker-paasta.yelpcorp.com:443/gunicorn_exporter-k8s-sidecar:v0.24.0-yelp0", ...
Get the docker image URL for the gunicorn_exporter sidecar container
get_gunicorn_exporter_sidecar_image_url
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_readiness_check_prefix_template(self) -> List[str]: """A prefix that will be added to the beginning of the readiness check command. Meant for e.g. `flock` and `timeout`.""" # We use flock+timeout here to work around issues discovered in PAASTA-17673: # In k8s 1.18, probe timeout ...
A prefix that will be added to the beginning of the readiness check command. Meant for e.g. `flock` and `timeout`.
get_readiness_check_prefix_template
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def _run( command: Union[str, List[str]], env: Mapping[str, str] = os.environ, timeout: float = None, log: bool = False, stream: bool = False, stdin: Any = None, stdin_interrupt: bool = False, popen_kwargs: Dict = {}, **kwargs: Any, ) -> Tuple[int, str]: """Given a command, run i...
Given a command, run it. Return a tuple of the return code and any output. :param timeout: If specified, the command will be terminated after timeout seconds. :param log: If True, the _log will be handled by _run. If set, it is mandatory to pass at least a :service: and a :component: parame...
_run
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_umask() -> int: """Get the current umask for this process. NOT THREAD SAFE.""" old_umask = os.umask(0o0022) os.umask(old_umask) return old_umask
Get the current umask for this process. NOT THREAD SAFE.
get_umask
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def compose_job_id( name: str, instance: str, git_hash: Optional[str] = None, config_hash: Optional[str] = None, spacer: str = SPACER, ) -> str: """Compose a job/app id by concatenating its name, instance, git hash, and config hash. :param name: The name of the service :param instance: ...
Compose a job/app id by concatenating its name, instance, git hash, and config hash. :param name: The name of the service :param instance: The instance of the service :param git_hash: The git_hash portion of the job_id. If git_hash is set, config_hash must also be set. :param confi...
compose_job_id
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def decompose_job_id(job_id: str, spacer: str = SPACER) -> Tuple[str, str, str, str]: """Break a composed job id into its constituent (service name, instance, git hash, config hash) by splitting with ``spacer``. :param job_id: The composed id of the job/app :returns: A tuple (service name, instance, gi...
Break a composed job id into its constituent (service name, instance, git hash, config hash) by splitting with ``spacer``. :param job_id: The composed id of the job/app :returns: A tuple (service name, instance, git hash, config hash) that comprise the job_id
decompose_job_id
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def build_docker_image_name(service: str) -> str: """docker-paasta.yelpcorp.com:443 is the URL for the Registry where PaaSTA will look for your images. :returns: a sanitized-for-Jenkins (s,/,-,g) version of the service's path in git. E.g. For github.yelpcorp.com:services/foo the docker image name i...
docker-paasta.yelpcorp.com:443 is the URL for the Registry where PaaSTA will look for your images. :returns: a sanitized-for-Jenkins (s,/,-,g) version of the service's path in git. E.g. For github.yelpcorp.com:services/foo the docker image name is docker_registry/services-foo.
build_docker_image_name
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def check_docker_image( service: str, commit: str, image_version: Optional[str] = None, ) -> bool: """Checks whether the given image for :service: with :tag: exists. :raises: ValueError if more than one docker image with :tag: found. :returns: True if there is exactly one matching image found. ...
Checks whether the given image for :service: with :tag: exists. :raises: ValueError if more than one docker image with :tag: found. :returns: True if there is exactly one matching image found.
check_docker_image
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_files_of_type_in_dir( file_type: str, service: str = None, soa_dir: str = DEFAULT_SOA_DIR, ) -> List[str]: """Recursively search path if type of file exists. :param file_type: a string of a type of a file (kubernetes, slo, etc.) :param service: a string of a service :param soa_dir: ...
Recursively search path if type of file exists. :param file_type: a string of a type of a file (kubernetes, slo, etc.) :param service: a string of a service :param soa_dir: a string of a path to a soa_configs directory :return: a list
get_files_of_type_in_dir
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def list_clusters( service: str = None, soa_dir: str = DEFAULT_SOA_DIR, instance_type: str = None ) -> List[str]: """Returns a sorted list of clusters a service is configured to deploy to, or all clusters if ``service`` is not specified. Includes every cluster that has a ``kubernetes-*.yaml`` or ``tron...
Returns a sorted list of clusters a service is configured to deploy to, or all clusters if ``service`` is not specified. Includes every cluster that has a ``kubernetes-*.yaml`` or ``tron-*.yaml`` file associated with it. :param service: The service name. If unspecified, clusters running any service will b...
list_clusters
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_service_instance_list_no_cache( service: str, cluster: Optional[str] = None, instance_type: str = None, soa_dir: str = DEFAULT_SOA_DIR, ) -> List[Tuple[str, str]]: """Enumerate the instances defined for a service as a list of tuples. :param service: The service name :param cluster: ...
Enumerate the instances defined for a service as a list of tuples. :param service: The service name :param cluster: The cluster to read the configuration for :param instance_type: The type of instances to examine: 'kubernetes', 'tron', or None (default) for both :param soa_dir: The SOA config directory...
get_service_instance_list_no_cache
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_service_instance_list( service: str, cluster: Optional[str] = None, instance_type: str = None, soa_dir: str = DEFAULT_SOA_DIR, ) -> List[Tuple[str, str]]: """Enumerate the instances defined for a service as a list of tuples. :param service: The service name :param cluster: The clust...
Enumerate the instances defined for a service as a list of tuples. :param service: The service name :param cluster: The cluster to read the configuration for :param instance_type: The type of instances to examine: 'kubernetes', 'tron', or None (default) for both :param soa_dir: The SOA config directory...
get_service_instance_list
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_services_for_cluster( cluster: str = None, instance_type: str = None, soa_dir: str = DEFAULT_SOA_DIR ) -> List[Tuple[str, str]]: """Retrieve all services and instances defined to run in a cluster. :param cluster: The cluster to read the configuration for :param instance_type: The type of instan...
Retrieve all services and instances defined to run in a cluster. :param cluster: The cluster to read the configuration for :param instance_type: The type of instances to examine: 'kubernetes', 'tron', or None (default) for both :param soa_dir: The SOA config directory to read from :returns: A list of t...
get_services_for_cluster
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_latest_deployment_tag( refs: Dict[str, str], deploy_group: str ) -> Tuple[str, str, Optional[str]]: """Gets the latest deployment tag and sha for the specified deploy_group :param refs: A dictionary mapping git refs to shas :param deploy_group: The deployment group to return a deploy tag for ...
Gets the latest deployment tag and sha for the specified deploy_group :param refs: A dictionary mapping git refs to shas :param deploy_group: The deployment group to return a deploy tag for :returns: A tuple of the form (ref, sha, image_version) where ref is the actual deployment tag (with t...
get_latest_deployment_tag
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_config_hash(config: Any, force_bounce: str = None) -> str: """Create an MD5 hash of the configuration dictionary to be sent to Kubernetes. Or anything really, so long as str(config) works. Returns the first 8 characters so things are not really long. :param config: The configuration to hash ...
Create an MD5 hash of the configuration dictionary to be sent to Kubernetes. Or anything really, so long as str(config) works. Returns the first 8 characters so things are not really long. :param config: The configuration to hash :param force_bounce: a timestamp (in the form of a string) that is append...
get_config_hash
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_git_sha_from_dockerurl(docker_url: str, long: bool = False) -> str: """We encode the sha of the code that built a docker image *in* the docker url. This function takes that url as input and outputs the sha. """ if ":paasta-" in docker_url: deployment_version = get_deployment_version_from...
We encode the sha of the code that built a docker image *in* the docker url. This function takes that url as input and outputs the sha.
get_git_sha_from_dockerurl
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_image_version_from_dockerurl(docker_url: str) -> Optional[str]: """We can optionally encode additional metadata about the docker image *in* the docker url. This function takes that url as input and outputs the sha. """ deployment_version = get_deployment_version_from_dockerurl(docker_url) re...
We can optionally encode additional metadata about the docker image *in* the docker url. This function takes that url as input and outputs the sha.
get_image_version_from_dockerurl
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def is_under_replicated( num_available: int, expected_count: int, crit_threshold: int ) -> Tuple[bool, float]: """Calculates if something is under replicated :param num_available: How many things are up :param expected_count: How many things you think should be up :param crit_threshold: Int from 0-...
Calculates if something is under replicated :param num_available: How many things are up :param expected_count: How many things you think should be up :param crit_threshold: Int from 0-100 :returns: Tuple of (bool, ratio)
is_under_replicated
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def deploy_blacklist_to_constraints( deploy_blacklist: DeployBlacklist, ) -> List[Constraint]: """Converts a blacklist of locations into tron appropriate constraints. :param blacklist: List of lists of locations to blacklist :returns: List of lists of constraints """ constraints: List[Constrain...
Converts a blacklist of locations into tron appropriate constraints. :param blacklist: List of lists of locations to blacklist :returns: List of lists of constraints
deploy_blacklist_to_constraints
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def deploy_whitelist_to_constraints( deploy_whitelist: DeployWhitelist, ) -> List[Constraint]: """Converts a whitelist of locations into tron appropriate constraints :param deploy_whitelist: List of lists of locations to whitelist :returns: List of lists of constraints """ if deploy_whitelist i...
Converts a whitelist of locations into tron appropriate constraints :param deploy_whitelist: List of lists of locations to whitelist :returns: List of lists of constraints
deploy_whitelist_to_constraints
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def format_table( rows: Iterable[Union[str, Sequence[str]]], min_spacing: int = 2 ) -> List[str]: """Formats a table for use on the command line. :param rows: List of rows, each of which can either be a tuple of strings containing the row's values, or a string to be inserted verbatim. Each...
Formats a table for use on the command line. :param rows: List of rows, each of which can either be a tuple of strings containing the row's values, or a string to be inserted verbatim. Each row (except literal strings) should be the same number of elements as all the others. :...
format_table
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def is_deploy_step(step: str) -> bool: """ Returns true if the given step deploys to an instancename Returns false if the step is a predefined step-type, e.g. itest or command-* """ return not ( (step in DEPLOY_PIPELINE_NON_DEPLOY_STEPS) or (step.startswith("command-")) )
Returns true if the given step deploys to an instancename Returns false if the step is a predefined step-type, e.g. itest or command-*
is_deploy_step
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def ldap_user_search( cn: str, search_base: str, search_ou: str, ldap_host: str, username: str, password: str, ) -> Set[str]: """Connects to LDAP and raises a subclass of LDAPOperationResult when it fails""" tls_config = ldap3.Tls( validate=ssl.CERT_REQUIRED, ca_certs_file="/etc/...
Connects to LDAP and raises a subclass of LDAPOperationResult when it fails
ldap_user_search
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def get_k8s_url_for_cluster(cluster: str) -> Optional[str]: """ Annoyingly, there's two layers of aliases: one to figure out what k8s server url to use (this one) and another to figure out what soaconfigs filename to use ;_; This exists so that we can map something like `--cluster pnw-devc` int...
Annoyingly, there's two layers of aliases: one to figure out what k8s server url to use (this one) and another to figure out what soaconfigs filename to use ;_; This exists so that we can map something like `--cluster pnw-devc` into spark-pnw-devc's k8s apiserver url without needing to update ...
get_k8s_url_for_cluster
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def maybe_load_previous_config( filename: str, config_loader: Callable[[TextIO], dict] ) -> Optional[dict]: """Try to load configuration file :param str filename: path to load from :param Callable[[TextIO], dict] config_loader: parser for the configuration :return: configuration data, None if loadi...
Try to load configuration file :param str filename: path to load from :param Callable[[TextIO], dict] config_loader: parser for the configuration :return: configuration data, None if loading fails
maybe_load_previous_config
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def write_json_configuration_file(filename: str, configuration: dict) -> None: """Atomically write configuration to JSON file :param str filename: path to write to :param dict configuration: configuration data """ with atomic_file_write(filename) as fp: json.dump( obj=configurat...
Atomically write configuration to JSON file :param str filename: path to write to :param dict configuration: configuration data
write_json_configuration_file
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def write_yaml_configuration_file( filename: str, configuration: dict, check_existing: bool = True ) -> None: """Atomically write configuration to YAML file :param str filename: path to write to :param dict configuration: configuration data :param bool check_existing: if existing file already match...
Atomically write configuration to YAML file :param str filename: path to write to :param dict configuration: configuration data :param bool check_existing: if existing file already matches config, do not overwrite
write_yaml_configuration_file
python
Yelp/paasta
paasta_tools/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/utils.py
Apache-2.0
def __call__(self, request: Request) -> Response: """ Extracts relevant metadata from request, and checks if it is authorized """ token = request.headers.get("Authorization", "").strip() token = token.split()[-1] if token else "" # removes "Bearer" prefix auth_outcome = ...
Extracts relevant metadata from request, and checks if it is authorized
__call__
python
Yelp/paasta
paasta_tools/api/tweens/auth.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/api/tweens/auth.py
Apache-2.0
def is_request_authorized( self, path: str, token: str, method: str, service: Optional[str], ) -> AuthorizationOutcome: """Check if API request is authorized :param str path: API path :param str token: authentication token :param str method: h...
Check if API request is authorized :param str path: API path :param str token: authentication token :param str method: http method :return: auth outcome
is_request_authorized
python
Yelp/paasta
paasta_tools/api/tweens/auth.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/api/tweens/auth.py
Apache-2.0
def cprofile_tween_factory(handler, registry): """Tween for profiling API requests and sending them to scribe. yelp_profiling does define a tween, but it is designed more for PaaSTA services. So, we need to define our own. """ def cprofile_tween(request): if yelp_profiling is None: ...
Tween for profiling API requests and sending them to scribe. yelp_profiling does define a tween, but it is designed more for PaaSTA services. So, we need to define our own.
cprofile_tween_factory
python
Yelp/paasta
paasta_tools/api/tweens/profiling.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/api/tweens/profiling.py
Apache-2.0
def set_autoscaling_override(request): """Set a temporary autoscaling override for a service/instance. This endpoint creates or updates a ConfigMap entry with override information including expiration time. The override will be applied by the autoscaler. Required parameters: - service: The service...
Set a temporary autoscaling override for a service/instance. This endpoint creates or updates a ConfigMap entry with override information including expiration time. The override will be applied by the autoscaler. Required parameters: - service: The service name - instance: The instance name - ...
set_autoscaling_override
python
Yelp/paasta
paasta_tools/api/views/autoscaler.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/api/views/autoscaler.py
Apache-2.0
def api_failure_response(exc, request): """Construct an HTTP response with an error status code. This happens when the API service has to stop on a 'hard' error. In contrast, the API service continues to produce results on a 'soft' error. It will place a 'message' field in the output. Multiple 'soft' er...
Construct an HTTP response with an error status code. This happens when the API service has to stop on a 'hard' error. In contrast, the API service continues to produce results on a 'soft' error. It will place a 'message' field in the output. Multiple 'soft' errors are concatenated in the same 'message'...
api_failure_response
python
Yelp/paasta
paasta_tools/api/views/exception.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/api/views/exception.py
Apache-2.0
def window_historical_load(historical_load, window_begin, window_end): """Filter historical_load down to just the datapoints lying between times window_begin and window_end, inclusive.""" filtered = [] for timestamp, value in historical_load: if timestamp >= window_begin and timestamp <= window_end:...
Filter historical_load down to just the datapoints lying between times window_begin and window_end, inclusive.
window_historical_load
python
Yelp/paasta
paasta_tools/autoscaling/forecasting.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/autoscaling/forecasting.py
Apache-2.0
def moving_average_forecast_policy( historical_load, moving_average_window_seconds=DEFAULT_UWSGI_AUTOSCALING_MOVING_AVERAGE_WINDOW, **kwargs, ): """Does a simple average of all historical load data points within the moving average window. Weights all data points within the window equally.""" wi...
Does a simple average of all historical load data points within the moving average window. Weights all data points within the window equally.
moving_average_forecast_policy
python
Yelp/paasta
paasta_tools/autoscaling/forecasting.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/autoscaling/forecasting.py
Apache-2.0
def linreg_forecast_policy( historical_load, linreg_window_seconds, linreg_extrapolation_seconds, linreg_default_slope=0, **kwargs, ): """Does a linear regression on the load data within the last linreg_window_seconds. For every time delta in linreg_extrapolation_seconds, forecasts the value...
Does a linear regression on the load data within the last linreg_window_seconds. For every time delta in linreg_extrapolation_seconds, forecasts the value at that time delta from now, and returns the maximum of these predicted values. (With linear extrapolation, it doesn't make sense to forecast at more than tw...
linreg_forecast_policy
python
Yelp/paasta
paasta_tools/autoscaling/forecasting.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/autoscaling/forecasting.py
Apache-2.0
def get_sso_auth_token(paasta_apis: bool = False) -> str: """Generate an authentication token for the calling user from the Single Sign On provider :param bool paasta_apis: authenticate for PaaSTA APIs """ system_config = load_system_paasta_config() client_id = ( system_config.get_api_auth_...
Generate an authentication token for the calling user from the Single Sign On provider :param bool paasta_apis: authenticate for PaaSTA APIs
get_sso_auth_token
python
Yelp/paasta
paasta_tools/cli/authentication.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/authentication.py
Apache-2.0
def load_method(module_name, method_name): """Return a function given a module and method name. :param module_name: a string :param method_name: a string :return: a function """ module = __import__(module_name, fromlist=[method_name]) method = getattr(module, method_name) return method
Return a function given a module and method name. :param module_name: a string :param method_name: a string :return: a function
load_method
python
Yelp/paasta
paasta_tools/cli/cli.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cli.py
Apache-2.0
def add_subparser(command, subparsers): """Given a command name, paasta_cmd, execute the add_subparser method implemented in paasta_cmd.py. Each paasta client command must implement a method called add_subparser. This allows the client to dynamically add subparsers to its subparser, which provides ...
Given a command name, paasta_cmd, execute the add_subparser method implemented in paasta_cmd.py. Each paasta client command must implement a method called add_subparser. This allows the client to dynamically add subparsers to its subparser, which provides the benefits of argcomplete/argparse but gets i...
add_subparser
python
Yelp/paasta
paasta_tools/cli/cli.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cli.py
Apache-2.0
def get_argparser(commands=None): """Create and return argument parser for a set of subcommands. :param commands: Union[None, List[str]] If `commands` argument is `None`, add full parsers for all subcommands, if `commands` is empty list - add thin parsers for all subcommands, otherwise - add full parse...
Create and return argument parser for a set of subcommands. :param commands: Union[None, List[str]] If `commands` argument is `None`, add full parsers for all subcommands, if `commands` is empty list - add thin parsers for all subcommands, otherwise - add full parsers for subcommands in the argument. ...
get_argparser
python
Yelp/paasta
paasta_tools/cli/cli.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cli.py
Apache-2.0
def parse_args(argv): """Initialize autocompletion and configure the argument parser. :return: an argparse.Namespace object mapping parameter names to the inputs from sys.argv """ parser = get_argparser(commands=[]) argcomplete.autocomplete(parser) args, _ = parser.parse_known_arg...
Initialize autocompletion and configure the argument parser. :return: an argparse.Namespace object mapping parameter names to the inputs from sys.argv
parse_args
python
Yelp/paasta
paasta_tools/cli/cli.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cli.py
Apache-2.0
def main(argv=None): """Perform a paasta call. Read args from sys.argv and pass parsed args onto appropriate command in paasta_cli/cmds directory. Ensure we kill any child pids before we quit """ logging.basicConfig() warnings.filterwarnings("ignore", category=DeprecationWarning) # if we a...
Perform a paasta call. Read args from sys.argv and pass parsed args onto appropriate command in paasta_cli/cmds directory. Ensure we kill any child pids before we quit
main
python
Yelp/paasta
paasta_tools/cli/cli.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cli.py
Apache-2.0
def make_copyfile_symlink_aware(): """The reasoning behind this monkeypatch is that cookiecutter doesn't respect symlinks at all, and at Yelp we use symlinks to reduce duplication in the soa configs. Maybe cookie-cutter will accept a symlink-aware PR? """ orig_copyfile = shutil.copyfile orig_cop...
The reasoning behind this monkeypatch is that cookiecutter doesn't respect symlinks at all, and at Yelp we use symlinks to reduce duplication in the soa configs. Maybe cookie-cutter will accept a symlink-aware PR?
make_copyfile_symlink_aware
python
Yelp/paasta
paasta_tools/cli/fsm_cmd.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/fsm_cmd.py
Apache-2.0
def is_file_in_dir(file_name, path): """Recursively search path for file_name. :param file_name: a string of a file name to find :param path: a string path :param file_ext: a string of a file extension :return: a boolean """ for root, dirnames, filenames in os.walk(path): for filena...
Recursively search path for file_name. :param file_name: a string of a file name to find :param path: a string path :param file_ext: a string of a file extension :return: a boolean
is_file_in_dir
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def validate_service_name(service, soa_dir=DEFAULT_SOA_DIR): """Determine whether directory named service exists in the provided soa_dir :param service: a string of the name of the service you wish to check exists :param soa_dir: directory to look for service names :return : boolean True :raises: No...
Determine whether directory named service exists in the provided soa_dir :param service: a string of the name of the service you wish to check exists :param soa_dir: directory to look for service names :return : boolean True :raises: NoSuchService exception
validate_service_name
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def list_paasta_services(soa_dir: str = DEFAULT_SOA_DIR): """Returns a sorted list of services that happen to have at least one service.instance, which indicates it is on PaaSTA """ the_list = [] for service in list_services(soa_dir): if list_all_instances_for_service(service, soa_dir=soa_di...
Returns a sorted list of services that happen to have at least one service.instance, which indicates it is on PaaSTA
list_paasta_services
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def list_service_instances(soa_dir: str = DEFAULT_SOA_DIR): """Returns a sorted list of service<SPACER>instance names""" the_list = [] for service in list_services(soa_dir): for instance in list_all_instances_for_service( service=service, soa_dir=soa_dir ): the_list.a...
Returns a sorted list of service<SPACER>instance names
list_service_instances
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def list_instances(**kwargs): """Returns a sorted list of all possible instance names for tab completion. We try to guess what service you might be operating on, otherwise we just provide *all* of them """ all_instances: Set[str] = set() service = guess_service_name() try: validate_s...
Returns a sorted list of all possible instance names for tab completion. We try to guess what service you might be operating on, otherwise we just provide *all* of them
list_instances
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def calculate_remote_masters( cluster: str, system_paasta_config: SystemPaastaConfig ) -> Tuple[List[str], str]: """Given a cluster, do a DNS lookup of that cluster (which happens to point, eventually, to the Mesos masters in that cluster). Return IPs of those Mesos masters. """ cluster_fqdn = ...
Given a cluster, do a DNS lookup of that cluster (which happens to point, eventually, to the Mesos masters in that cluster). Return IPs of those Mesos masters.
calculate_remote_masters
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def check_ssh_on_master(master, timeout=10): """Given a master, attempt to ssh to the master and run a simple command with sudo to verify that ssh and sudo work properly. Return a tuple of the success status (True or False) and any output from attempting the check. """ check_command = "ssh -A -n -o ...
Given a master, attempt to ssh to the master and run a simple command with sudo to verify that ssh and sudo work properly. Return a tuple of the success status (True or False) and any output from attempting the check.
check_ssh_on_master
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def run_on_master( cluster, system_paasta_config, cmd_parts, timeout=None, err_code=-1, graceful_exit=False, stdin=None, ): """Find connectable master for :cluster: and :system_paasta_config: args and invoke command from :cmd_parts:, wrapping it in ssh call. :returns (exit code,...
Find connectable master for :cluster: and :system_paasta_config: args and invoke command from :cmd_parts:, wrapping it in ssh call. :returns (exit code, output) :param cluster: cluster to find master in :param system_paasta_config: system configuration to lookup master data :param cmd_parts: passe...
run_on_master
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def figure_out_service_name(args, soa_dir=DEFAULT_SOA_DIR): """Figures out and validates the input service name""" service = args.service or guess_service_name() try: validate_service_name(service, soa_dir=soa_dir) except NoSuchService as service_not_found: print(service_not_found) ...
Figures out and validates the input service name
figure_out_service_name
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def get_jenkins_build_output_url(): """Returns the URL for Jenkins job's output. Returns None if it's not available. """ build_output = os.environ.get("BUILD_URL") if build_output: build_output = build_output + "console" return build_output
Returns the URL for Jenkins job's output. Returns None if it's not available.
get_jenkins_build_output_url
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def get_instance_config( service: str, instance: str, cluster: str, soa_dir: str = DEFAULT_SOA_DIR, load_deployments: bool = False, instance_type: Optional[str] = None, ) -> InstanceConfig: """Returns the InstanceConfig object for whatever type of instance it is. (kubernetes)""" if i...
Returns the InstanceConfig object for whatever type of instance it is. (kubernetes)
get_instance_config
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def extract_tags(paasta_tag: str) -> Mapping[str, str]: """Returns a dictionary containing information from a git tag""" regex = r"^refs/tags/(?:paasta-){1,2}(?P<deploy_group>[a-zA-Z0-9._-]+)(?:\+(?P<image_version>.*)){0,1}-(?P<tstamp>\d{8}T\d{6})-(?P<tag>.*?)$" regex_match = re.match(regex, paasta_tag) ...
Returns a dictionary containing information from a git tag
extract_tags
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def validate_given_deploy_groups( all_deploy_groups: Collection[str], args_deploy_groups: Collection[str] ) -> Tuple[Set[str], Set[str]]: """Given two lists of deploy groups, return the intersection and difference between them. :param all_deploy_groups: instances actually belonging to a service :param ...
Given two lists of deploy groups, return the intersection and difference between them. :param all_deploy_groups: instances actually belonging to a service :param args_deploy_groups: the desired instances :returns: a tuple with (common, difference) indicating deploy groups common in both lists and t...
validate_given_deploy_groups
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def pick_random_port(service_name): """Return a random port. Tries to return the same port for the same service each time, when possible. """ hash_key = f"{service_name},{getpass.getuser()}".encode("utf8") hash_number = int(hashlib.sha1(hash_key).hexdigest(), 16) preferred_port = 33000 + (h...
Return a random port. Tries to return the same port for the same service each time, when possible.
pick_random_port
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def trigger_deploys( service: str, system_config: Optional["SystemPaastaConfig"] = None, ) -> None: """Connects to the deploymentsd watcher on sysgit, which is an extremely simple service that listens for a service string and then generates a service deployment""" logline = f"Notifying soa-configs p...
Connects to the deploymentsd watcher on sysgit, which is an extremely simple service that listens for a service string and then generates a service deployment
trigger_deploys
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def verify_instances( args_instances: str, service: str, clusters: Sequence[str], soa_dir: str = DEFAULT_SOA_DIR, ) -> Sequence[str]: """Verify that a list of instances specified by user is correct for this service. :param args_instances: a list of instances. :param service: the service nam...
Verify that a list of instances specified by user is correct for this service. :param args_instances: a list of instances. :param service: the service name :param cluster: a list of clusters :returns: a list of instances specified in args_instances without any exclusions.
verify_instances
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def run_interactive_cli( cmd: str, shell: str = "/bin/bash", term: str = "xterm-256color" ): """Runs interactive command in a pseudo terminal, handling terminal size management :param str cmd: shell command :param str shell: shell utility to use as wrapper :param str term: terminal type """ ...
Runs interactive command in a pseudo terminal, handling terminal size management :param str cmd: shell command :param str shell: shell utility to use as wrapper :param str term: terminal type
run_interactive_cli
python
Yelp/paasta
paasta_tools/cli/utils.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/utils.py
Apache-2.0
def parse_duration_to_seconds(duration: str) -> Optional[int]: """Parse a duration string like '3h' or '30m' into seconds. Args: duration_str: A string representing a duration (e.g., "3h", "30m", "1d") Returns: The duration in seconds, or None if parsing failed """ if not duration:...
Parse a duration string like '3h' or '30m' into seconds. Args: duration_str: A string representing a duration (e.g., "3h", "30m", "1d") Returns: The duration in seconds, or None if parsing failed
parse_duration_to_seconds
python
Yelp/paasta
paasta_tools/cli/cmds/autoscale.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/autoscale.py
Apache-2.0
def deploy_check(service_path): """Check whether deploy.yaml exists in service directory. Prints success or error message. :param service_path: path to a directory containing deploy.yaml""" if is_file_in_dir("deploy.yaml", service_path): print(PaastaCheckMessages.DEPLOY_YAML_FOUND) else: ...
Check whether deploy.yaml exists in service directory. Prints success or error message. :param service_path: path to a directory containing deploy.yaml
deploy_check
python
Yelp/paasta
paasta_tools/cli/cmds/check.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py
Apache-2.0
def docker_check(): """Check whether Dockerfile exists in service directory, and is valid. Prints suitable message depending on outcome""" docker_file_path = is_file_in_dir("Dockerfile", os.getcwd()) if docker_file_path: print(PaastaCheckMessages.DOCKERFILE_FOUND) else: print(PaastaC...
Check whether Dockerfile exists in service directory, and is valid. Prints suitable message depending on outcome
docker_check
python
Yelp/paasta
paasta_tools/cli/cmds/check.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py
Apache-2.0