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 prepare_new_container(soa_dir, synapse_service_dir, service, instance, mac): """Update iptables to include rules for a new (not yet running) MAC address""" ensure_shared_chains() # probably already set, but just to be safe service_group = ServiceGroup(service, instance) service_group.update_rules(s...
Update iptables to include rules for a new (not yet running) MAC address
prepare_new_container
python
Yelp/paasta
paasta_tools/firewall.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/firewall.py
Apache-2.0
def firewall_flock(flock_path=DEFAULT_FIREWALL_FLOCK_PATH): """Grab an exclusive flock to avoid concurrent iptables updates""" with io.FileIO(flock_path, "w") as f: with timed_flock(f, seconds=DEFAULT_FIREWALL_FLOCK_TIMEOUT_SECS): yield
Grab an exclusive flock to avoid concurrent iptables updates
firewall_flock
python
Yelp/paasta
paasta_tools/firewall.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/firewall.py
Apache-2.0
def load_flinkeks_instance_config( service: str, instance: str, cluster: str, load_deployments: bool = True, soa_dir: str = DEFAULT_SOA_DIR, ) -> FlinkEksDeploymentConfig: """Read a service instance's configuration for Flink on EKS. If a branch isn't specified for a config, the 'branch' key...
Read a service instance's configuration for Flink on EKS. If a branch isn't specified for a config, the 'branch' key defaults to paasta-${cluster}.${instance}. :param service: The service name :param instance: The instance of the service to retrieve :param cluster: The cluster to read the configur...
load_flinkeks_instance_config
python
Yelp/paasta
paasta_tools/flinkeks_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/flinkeks_tools.py
Apache-2.0
def get_pool(self) -> Optional[str]: """ Parses flink_pool from a specific Flink Deployment instance's configuration data, using key 'spot'. Args: flink_deployment_config_data: The FlinkDeploymentConfig for a specific Flink yelpsoa instance Returns: The flink po...
Parses flink_pool from a specific Flink Deployment instance's configuration data, using key 'spot'. Args: flink_deployment_config_data: The FlinkDeploymentConfig for a specific Flink yelpsoa instance Returns: The flink pool string.
get_pool
python
Yelp/paasta
paasta_tools/flink_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py
Apache-2.0
def load_flink_instance_config( service: str, instance: str, cluster: str, load_deployments: bool = True, soa_dir: str = DEFAULT_SOA_DIR, ) -> FlinkDeploymentConfig: """Read a service instance's configuration for Flink. If a branch isn't specified for a config, the 'branch' key defaults to ...
Read a service instance's configuration for Flink. If a branch isn't specified for a config, the 'branch' key defaults to paasta-${cluster}.${instance}. :param service: The service name :param instance: The instance of the service to retrieve :param cluster: The cluster to read the configuration f...
load_flink_instance_config
python
Yelp/paasta
paasta_tools/flink_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py
Apache-2.0
def _filter_for_endpoint(json_response: Any, endpoint: str) -> Mapping[str, Any]: """ Filter json response to include only a subset of fields. """ if endpoint == "config": return { key: value for (key, value) in json_response.items() if key in CONFIG_KEYS } if endpoint ==...
Filter json response to include only a subset of fields.
_filter_for_endpoint
python
Yelp/paasta
paasta_tools/flink_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py
Apache-2.0
def get_flink_jobs_from_paasta_api_client( service: str, instance: str, client: PaastaOApiClient ) -> FlinkJobs: """Get flink jobs for (service, instance) pair by connecting to the paasta api endpoint. Appends exception to output list if any. :param service: The service name :param instance: The i...
Get flink jobs for (service, instance) pair by connecting to the paasta api endpoint. Appends exception to output list if any. :param service: The service name :param instance: The instance of the service to retrieve :param client: The paasta api client :returns: Flink jobs in the flink cluster
get_flink_jobs_from_paasta_api_client
python
Yelp/paasta
paasta_tools/flink_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py
Apache-2.0
async def get_flink_job_details_from_paasta_api_client( service: str, instance: str, job_id: str, client: PaastaOApiClient ) -> FlinkJobDetails: """Get flink job details for (service, instance) pair by connecting to the paasta api endpoint. Appends exception to output list if any. :param service: The ...
Get flink job details for (service, instance) pair by connecting to the paasta api endpoint. Appends exception to output list if any. :param service: The service name :param instance: The instance of the service to retrieve :param client: The paasta api client :returns: Flink jobs in the flink clu...
get_flink_job_details_from_paasta_api_client
python
Yelp/paasta
paasta_tools/flink_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py
Apache-2.0
def get_flink_config_from_paasta_api_client( service: str, instance: str, client: PaastaOApiClient ) -> FlinkConfig: """Get flink config for (service, instance) pair by connecting to the paasta api endpoint. Appends exception to output list if any. :param service: The service name :param instance:...
Get flink config for (service, instance) pair by connecting to the paasta api endpoint. Appends exception to output list if any. :param service: The service name :param instance: The instance of the service to retrieve :param client: The paasta api client :returns: Flink cluster configurations
get_flink_config_from_paasta_api_client
python
Yelp/paasta
paasta_tools/flink_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py
Apache-2.0
def get_flink_overview_from_paasta_api_client( service: str, instance: str, client: PaastaOApiClient ) -> FlinkClusterOverview: """Get flink cluster overview for (service, instance) pair by connecting to the paasta api endpoint. Appends exception to output list if any. :param service: The service name...
Get flink cluster overview for (service, instance) pair by connecting to the paasta api endpoint. Appends exception to output list if any. :param service: The service name :param instance: The instance of the service to retrieve :param client: The paasta api client :returns: Flink cluster overview
get_flink_overview_from_paasta_api_client
python
Yelp/paasta
paasta_tools/flink_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/flink_tools.py
Apache-2.0
def get_deploy_group_mappings( soa_dir: str, service: str ) -> Tuple[Dict[str, V1_Mapping], V2_Mappings]: """Gets mappings from service:deploy_group to services-service:paasta-hash-image_version, where hash is the current SHA at the HEAD of branch_name and image_version can be used to provide additional...
Gets mappings from service:deploy_group to services-service:paasta-hash-image_version, where hash is the current SHA at the HEAD of branch_name and image_version can be used to provide additional version information for the Docker image. This is done for all services in soa_dir. :param soa_dir: The SOA...
get_deploy_group_mappings
python
Yelp/paasta
paasta_tools/generate_deployments_for_service.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/generate_deployments_for_service.py
Apache-2.0
async def get_spool(spool_url: str) -> SpoolInfo: """Query hacheck for the state of a task, and parse the result into a dictionary.""" if spool_url is None: return None # TODO: aiohttp says not to create a session per request. Fix this. async with aiohttp.ClientSession(timeout=HACHECK_TIMEOUT) ...
Query hacheck for the state of a task, and parse the result into a dictionary.
get_spool
python
Yelp/paasta
paasta_tools/hacheck.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/hacheck.py
Apache-2.0
def ensure_chain(chain, rules): """Idempotently ensure a chain exists and has an exact set of rules. This function creates or updates an existing chain to match the rules passed in. This function will not reorder existing rules, but any new rules are always inserted at the front of the chain. ...
Idempotently ensure a chain exists and has an exact set of rules. This function creates or updates an existing chain to match the rules passed in. This function will not reorder existing rules, but any new rules are always inserted at the front of the chain.
ensure_chain
python
Yelp/paasta
paasta_tools/iptables.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/iptables.py
Apache-2.0
def reorder_chain(chain_name): """Ensure that any REJECT rules are last, and any LOG rules are second-to-last""" table = iptc.Table(iptc.Table.FILTER) with iptables_txn(table): rules = list_chain(chain_name) chain = iptc.Chain(table, chain_name) # sort the rules by rule_key, which ...
Ensure that any REJECT rules are last, and any LOG rules are second-to-last
reorder_chain
python
Yelp/paasta
paasta_tools/iptables.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/iptables.py
Apache-2.0
def list_chain(chain_name): """List rules in a chain. Returns a list of iptables rules, or raises ChainDoesNotExist. """ table = iptc.Table(iptc.Table.FILTER) chain = iptc.Chain(table, chain_name) # TODO: is there any way to do this without listing all chains? (probably slow) # If the chain...
List rules in a chain. Returns a list of iptables rules, or raises ChainDoesNotExist.
list_chain
python
Yelp/paasta
paasta_tools/iptables.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/iptables.py
Apache-2.0
def load_kafkacluster_instance_config( service: str, instance: str, cluster: str, load_deployments: bool = True, soa_dir: str = DEFAULT_SOA_DIR, ) -> KafkaClusterDeploymentConfig: """Read a service instance's configuration for KafkaCluster. If a branch isn't specified for a config, the 'bra...
Read a service instance's configuration for KafkaCluster. If a branch isn't specified for a config, the 'branch' key defaults to paasta-${cluster}.${instance}. :param service: The service name :param instance: The instance of the service to retrieve :param cluster: The cluster to read the configur...
load_kafkacluster_instance_config
python
Yelp/paasta
paasta_tools/kafkacluster_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kafkacluster_tools.py
Apache-2.0
def load_kubernetes_service_config_no_cache( service: str, instance: str, cluster: str, load_deployments: bool = True, soa_dir: str = DEFAULT_SOA_DIR, ) -> "KubernetesDeploymentConfig": """Read a service instance's configuration for kubernetes. If a branch isn't specified for a config, the ...
Read a service instance's configuration for kubernetes. If a branch isn't specified for a config, the 'branch' key defaults to paasta-${cluster}.${instance}. :param name: The service name :param instance: The instance of the service to retrieve :param cluster: The cluster to read the configuration...
load_kubernetes_service_config_no_cache
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def load_kubernetes_service_config( service: str, instance: str, cluster: str, load_deployments: bool = True, soa_dir: str = DEFAULT_SOA_DIR, ) -> "KubernetesDeploymentConfig": """Read a service instance's configuration for kubernetes. If a branch isn't specified for a config, the 'branch' ...
Read a service instance's configuration for kubernetes. If a branch isn't specified for a config, the 'branch' key defaults to paasta-${cluster}.${instance}. :param name: The service name :param instance: The instance of the service to retrieve :param cluster: The cluster to read the configuration...
load_kubernetes_service_config
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def __new__( cls, component: Optional[str] = None, config_file: Optional[str] = None, context: Optional[str] = None, ) -> "KubeClient": """By @lru_cache'ing this function, repeated instantiations of KubeClient with the same arguments will return the exact same object....
By @lru_cache'ing this function, repeated instantiations of KubeClient with the same arguments will return the exact same object. This makes it possible to effectively cache function calls that take a KubeClient as an argument.
__new__
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def allowlist_denylist_to_requirements( allowlist: DeployWhitelist, denylist: DeployBlacklist ) -> List[Tuple[str, str, List[str]]]: """Converts deploy_whitelist and deploy_blacklist to a list of requirements, which can be converted to node affinities. """ requirements = [] # convert whitelist i...
Converts deploy_whitelist and deploy_blacklist to a list of requirements, which can be converted to node affinities.
allowlist_denylist_to_requirements
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def raw_selectors_to_requirements( raw_selectors: Mapping[str, NodeSelectorConfig] ) -> List[Tuple[str, str, List[str]]]: """Converts certain node_selectors into requirements, which can be converted to node affinities. """ requirements: List[Tuple[str, str, List[str]]] = [] for label, configs i...
Converts certain node_selectors into requirements, which can be converted to node affinities.
raw_selectors_to_requirements
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_bounce_method(self) -> str: """Get the bounce method specified in the service's kubernetes configuration.""" # map existing bounce methods to k8s equivalents. # but if there's an EBS volume we must downthenup to free up the volume. # in the future we may support stateful sets to ...
Get the bounce method specified in the service's kubernetes configuration.
get_bounce_method
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_autoscaling_scaling_policy( self, max_replicas: int, autoscaling_params: AutoscalingParamsDict, ) -> Dict: """Returns the k8s HPA scaling policy in raw JSON. Requires k8s v1.18 to work. """ # The HPA scaling algorithm is as follows. Every sync period (...
Returns the k8s HPA scaling policy in raw JSON. Requires k8s v1.18 to work.
get_autoscaling_scaling_policy
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_sanitised_volume_name(self, volume_name: str, length_limit: int = 0) -> str: """I know but we really aren't allowed many characters...""" volume_name = volume_name.rstrip("/") sanitised = volume_name.replace("/", "slash-").replace(".", "dot-") sanitised_name = sanitise_kubernetes...
I know but we really aren't allowed many characters...
get_sanitised_volume_name
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_readiness_check_script( self, system_paasta_config: SystemPaastaConfig ) -> List[str]: """Script to check if a service is up in smartstack / envoy""" enable_envoy_check = self.get_enable_envoy_readiness_check(system_paasta_config) enable_nerve_check = self.get_enable_nerve_re...
Script to check if a service is up in smartstack / envoy
get_readiness_check_script
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_env_vars_that_use_secrets(self) -> Tuple[Dict[str, str], Dict[str, str]]: """Returns two dictionaries of environment variable name->value; the first is vars that use non-shared secrets, and the second is vars that use shared secrets. The values of the dictionaries are the secret refs as...
Returns two dictionaries of environment variable name->value; the first is vars that use non-shared secrets, and the second is vars that use shared secrets. The values of the dictionaries are the secret refs as formatted in yelpsoa-configs, e.g. "SECRET(foo)" or "SHARED_SECRET(bar)". These can ...
get_env_vars_that_use_secrets
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_hacheck_prestop_sleep_seconds(self) -> int: """The number of seconds to sleep between hadown and terminating the hacheck container. We want hacheck to be up for slightly longer than the main container is, so we default to pre_stop_drain_seconds + 1. It doesn't super matter if hacheck go...
The number of seconds to sleep between hadown and terminating the hacheck container. We want hacheck to be up for slightly longer than the main container is, so we default to pre_stop_drain_seconds + 1. It doesn't super matter if hacheck goes down before the main container -- if it's down, healthchecks...
get_hacheck_prestop_sleep_seconds
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_datastore_credentials_secrets_volume(self) -> V1Volume: """ All credentials are stored in 1 Kubernetes Secret, which are mapped on an item->path structure to /datastore/<datastore>/<credential>/<password file>. """ datastore_credentials = self.get_datastore_credentials() ...
All credentials are stored in 1 Kubernetes Secret, which are mapped on an item->path structure to /datastore/<datastore>/<credential>/<password file>.
get_datastore_credentials_secrets_volume
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_boto_secret_signature_name(self) -> str: """ Keep the following signature naming convention so that bounces do not happen because boto_keys configmap signatures already exist, see PAASTA-17910 Note: Since hashing is done only on a portion of secret, it may explode if service or instance...
Keep the following signature naming convention so that bounces do not happen because boto_keys configmap signatures already exist, see PAASTA-17910 Note: Since hashing is done only on a portion of secret, it may explode if service or instance names are too long
get_boto_secret_signature_name
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_datastore_credentials_signature_name(self) -> str: """ All datastore credentials are stored in a single Kubernetes secret, so they share a name """ return _get_secret_signature_name( self.get_namespace(), "datastore-credentials", self.get_servi...
All datastore credentials are stored in a single Kubernetes secret, so they share a name
get_datastore_credentials_signature_name
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def set_autoscaled_instances( self, instance_count: int, kube_client: KubeClient ) -> None: """Set the number of instances in the same way that the autoscaler does.""" set_instances_for_kubernetes_service( kube_client=kube_client, service_config=self, instance_count=instance_coun...
Set the number of instances in the same way that the autoscaler does.
set_autoscaled_instances
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_desired_instances(self) -> int: """For now if we have an EBS instance it means we can only have 1 instance since we can't attach to multiple instances. In the future we might support statefulsets which are clever enough to manage EBS for you""" instances = super().get_desired_ins...
For now if we have an EBS instance it means we can only have 1 instance since we can't attach to multiple instances. In the future we might support statefulsets which are clever enough to manage EBS for you
get_desired_instances
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_enable_nerve_readiness_check( self, system_paasta_config: SystemPaastaConfig ) -> bool: """Enables a k8s readiness check on the Pod to ensure that all registrations are UP on the local synapse haproxy""" return self.config_dict.get("bounce_health_params", {}).get( ...
Enables a k8s readiness check on the Pod to ensure that all registrations are UP on the local synapse haproxy
get_enable_nerve_readiness_check
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_enable_envoy_readiness_check( self, system_paasta_config: SystemPaastaConfig ) -> bool: """Enables a k8s readiness check on the Pod to ensure that all registrations are UP on the local Envoy""" return self.config_dict.get("bounce_health_params", {}).get( "check_en...
Enables a k8s readiness check on the Pod to ensure that all registrations are UP on the local Envoy
get_enable_envoy_readiness_check
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_namespace(self) -> str: """Get namespace from config, default to 'paasta'""" return self.config_dict.get( "namespace", f"paastasvc-{self.get_sanitised_service_name()}" )
Get namespace from config, default to 'paasta'
get_namespace
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def format_kubernetes_job( self, job_label: str, deadline_seconds: int = 3600, keep_routable_ip: bool = False, include_sidecars: bool = False, ) -> V1Job: """Create the config for launching the deployment as a Job :param str job_label: value to set for the "j...
Create the config for launching the deployment as a Job :param str job_label: value to set for the "job type" label :param int deadline_seconds: maximum allowed duration for the job :param bool keep_routable_ip: maintain routable IP annotation in pod template :param bool include_sidecar...
format_kubernetes_job
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def format_kubernetes_app(self) -> Union[V1Deployment, V1StatefulSet]: """Create the configuration that will be passed to the Kubernetes REST API.""" try: system_paasta_config = load_system_paasta_config() docker_url = self.get_docker_url() git_sha = get_git_sha_from...
Create the configuration that will be passed to the Kubernetes REST API.
format_kubernetes_app
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def has_routable_ip( self, service_namespace_config: ServiceNamespaceConfig, system_paasta_config: SystemPaastaConfig, ) -> str: """Return whether the routable_ip label should be true or false. Services with a `prometheus_port` defined or that use certain sidecars must have ...
Return whether the routable_ip label should be true or false. Services with a `prometheus_port` defined or that use certain sidecars must have a routable IP address to allow Prometheus shards to scrape metrics.
has_routable_ip
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_node_selector(self) -> Mapping[str, str]: """Converts simple node restrictions into node selectors. Unlike node affinities, selectors will show up in `kubectl describe`. """ raw_selectors: Mapping[str, Any] = self.config_dict.get("node_selectors", {}) node_selectors = { ...
Converts simple node restrictions into node selectors. Unlike node affinities, selectors will show up in `kubectl describe`.
get_node_selector
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_node_affinity( self, pool_node_affinities: Dict[str, Dict[str, List[str]]] = None ) -> Optional[V1NodeAffinity]: """Converts deploy_whitelist and deploy_blacklist in node affinities. note: At the time of writing, `kubectl describe` does not show affinities, only selectors. T...
Converts deploy_whitelist and deploy_blacklist in node affinities. note: At the time of writing, `kubectl describe` does not show affinities, only selectors. To see affinities, use `kubectl get pod -o json` instead.
get_node_affinity
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_pod_anti_affinity(self) -> Optional[V1PodAntiAffinity]: """ Converts the given anti-affinity on service and instance to pod affinities with the "paasta.yelp.com" prefixed label selector :return: """ required_terms = self.get_pod_required_anti_affinity_terms() ...
Converts the given anti-affinity on service and instance to pod affinities with the "paasta.yelp.com" prefixed label selector :return:
get_pod_anti_affinity
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def _kube_affinity_condition_to_label_selector( self, condition: KubeAffinityCondition ) -> Optional[V1LabelSelector]: """Converts the given condition to label selectors with paasta prefix""" labels = {} if "service" in condition: labels[PAASTA_ATTRIBUTE_PREFIX + "service...
Converts the given condition to label selectors with paasta prefix
_kube_affinity_condition_to_label_selector
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def sanitize_for_config_hash( self, config: Union[V1Deployment, V1StatefulSet] ) -> Mapping[str, Any]: """Removes some data from config to make it suitable for calculation of config hash. :param config: complete_config hash to sanitise :returns: sanitised copy of complete_co...
Removes some data from config to make it suitable for calculation of config hash. :param config: complete_config hash to sanitise :returns: sanitised copy of complete_config hash
sanitize_for_config_hash
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_termination_grace_period( self, service_namespace_config: ServiceNamespaceConfig ) -> Optional[int]: """Return the number of seconds that kubernetes should wait for pre-stop hooks to finish (or for the main process to exit after signaling) before forcefully terminating the pod. ...
Return the number of seconds that kubernetes should wait for pre-stop hooks to finish (or for the main process to exit after signaling) before forcefully terminating the pod. For smartstack services, defaults to a value long enough to allow the default pre-stop hook to finish. For non-smartstac...
get_termination_grace_period
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_all_kubernetes_services_running_here() -> List[Tuple[str, str, int]]: """Returns all k8s paasta services, even if not in smartstack. Returns a service, instance, port tuple to match the return value of other similar functions""" services = [] try: pods = get_k8s_pods() except request...
Returns all k8s paasta services, even if not in smartstack. Returns a service, instance, port tuple to match the return value of other similar functions
get_all_kubernetes_services_running_here
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def list_all_paasta_deployments(kube_client: KubeClient) -> Sequence[KubeDeployment]: """Gets deployments in all namespaces by passing the service label selector""" label_selectors = "paasta.yelp.com/service" return list_deployments_in_all_namespaces( kube_client=kube_client, label_selector=label_se...
Gets deployments in all namespaces by passing the service label selector
list_all_paasta_deployments
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def filter_nodes_by_blacklist( nodes: Sequence[V1Node], blacklist: DeployBlacklist, whitelist: DeployWhitelist ) -> Sequence[V1Node]: """Takes an input list of nodes and filters them based on the given blacklist. The blacklist is in the form of: [["location_type", "location]] Where the list in...
Takes an input list of nodes and filters them based on the given blacklist. The blacklist is in the form of: [["location_type", "location]] Where the list inside is something like ["region", "uswest1-prod"] :returns: The list of nodes after the filter
filter_nodes_by_blacklist
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def update_secret( kube_client: KubeClient, service_name: str, secret_name: str, secret_data: Dict[str, str], namespace: str, ) -> None: """ Expect secret_name to exist, e.g. kubectl get secret :param service_name: Expect unsanitised service name :param secret_data: Expect a mapping ...
Expect secret_name to exist, e.g. kubectl get secret :param service_name: Expect unsanitised service name :param secret_data: Expect a mapping of string-to-string where values are base64-encoded :param namespace: Unsanitized namespace of a service that will use the secret :raises ApiException:
update_secret
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_secret_signature( kube_client: KubeClient, signature_name: str, namespace: str, ) -> Optional[str]: """ :param signature_name: Expect the signature to exist in kubernetes configmap :return: Kubernetes configmap as a signature :raises ApiException: """ try: signature =...
:param signature_name: Expect the signature to exist in kubernetes configmap :return: Kubernetes configmap as a signature :raises ApiException:
get_secret_signature
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def update_secret_signature( kube_client: KubeClient, service_name: str, signature_name: str, secret_signature: str, namespace: str, ) -> None: """ :param service_name: Expect unsanitised service_name :param signature_name: Expect signature_name to exist in kubernetes configmap :para...
:param service_name: Expect unsanitised service_name :param signature_name: Expect signature_name to exist in kubernetes configmap :param secret_signature: Signature to replace with :raises ApiException:
update_secret_signature
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def create_secret_signature( kube_client: KubeClient, service_name: str, signature_name: str, secret_signature: str, namespace: str, ) -> None: """ :param service_name: Expect unsanitised service_name :param signature_name: Expected properly formatted signature, see _get_secret_signature...
:param service_name: Expect unsanitised service_name :param signature_name: Expected properly formatted signature, see _get_secret_signature_name() :param secret_signature: Signature value :param namespace: Unsanitized namespace of a service that will use the signature
create_secret_signature
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def sanitise_kubernetes_name( service: str, ) -> str: """ Sanitizes kubernetes name so that hyphen (-) can be used a delimeter """ name = service.replace("_", "--") if name.startswith("--"): name = name.replace("--", "underscore-", 1) return name.lower()
Sanitizes kubernetes name so that hyphen (-) can be used a delimeter
sanitise_kubernetes_name
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def create_pod_topology_spread_constraints( service: str, instance: str, topology_spread_constraints: List[TopologySpreadConstraintDict], ) -> List[V1TopologySpreadConstraint]: """ Applies cluster-level topology spread constraints to every Pod template. This allows us to configure default topolo...
Applies cluster-level topology spread constraints to every Pod template. This allows us to configure default topology spread constraints on EKS where we cannot configure the scheduler.
create_pod_topology_spread_constraints
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_pod_hostname(kube_client: KubeClient, pod: V1Pod) -> str: """Gets the hostname of a pod's node from labels""" if not pod.spec.node_name: # can be none, if pod not yet scheduled return "NotScheduled" try: node = kube_client.core.read_node(name=pod.spec.node_name) except ApiExcept...
Gets the hostname of a pod's node from labels
get_pod_hostname
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def _get_secret_signature_name( namespace: str, secret_identifier: str, service_name: str, key_name: str ) -> str: """ :param namespace: Unsanitised namespace of a service that will use the signature :param secret_identifier: Identifies the type of secret :param service_name: Unsanitised service_nam...
:param namespace: Unsanitised namespace of a service that will use the signature :param secret_identifier: Identifies the type of secret :param service_name: Unsanitised service_name :param key_name: Name of the actual secret, typically specified in a configuration file :return: Sanitised signature...
_get_secret_signature_name
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_paasta_secret_name(namespace: str, service_name: str, key_name: str) -> str: """ Use whenever creating or references a PaaSTA secret :param namespace: Unsanitised namespace of a service that will use the signature :param service_name: Unsanitised service_name :param key_name: Name of the ac...
Use whenever creating or references a PaaSTA secret :param namespace: Unsanitised namespace of a service that will use the signature :param service_name: Unsanitised service_name :param key_name: Name of the actual secret, typically specified in a configuration file :return: Sanitised PaaSTA secre...
get_paasta_secret_name
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_paasta_secret_signature_name( namespace: str, service_name: str, key_name: str ) -> str: """ Get PaaSTA signature name stored as kubernetes configmap :param namespace: Unsanitised namespace of a service that will use the signature :param service_name: Unsanitised service_name :param key...
Get PaaSTA signature name stored as kubernetes configmap :param namespace: Unsanitised namespace of a service that will use the signature :param service_name: Unsanitised service_name :param key_name: Name of the actual secret, typically specified in a configuration file :return: Sanitised PaaSTA ...
get_paasta_secret_signature_name
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_secret( kube_client: KubeClient, secret_name: str, key_name: str, *, namespace: str, decode: bool = True, ) -> Union[str, bytes]: """ :param secret_name: Expect properly formatted kubernetes secret name and that it exists :param key_name: Expect key_name to be a key in a data...
:param secret_name: Expect properly formatted kubernetes secret name and that it exists :param key_name: Expect key_name to be a key in a data section :raises ApiException: :raises KeyError: if key_name does not exists in kubernetes secret's data section
get_secret
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def patch_namespaced_configmap( name: str, body: Dict[str, str], *, namespace: str, kube_client: KubeClient, ) -> V1ConfigMap: """ Patches a configmap with the given body. The body should be a dictionary of key-value pairs. """ try: return kube_client.core.patch_namespaced_co...
Patches a configmap with the given body. The body should be a dictionary of key-value pairs.
patch_namespaced_configmap
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_or_create_namespaced_configmap( configmap: str, *, namespace: str, kube_client: KubeClient, ) -> Tuple[V1ConfigMap, bool]: """ Returns a 2-tuple of (the configmap, a bool representing whether it was just created) """ try: return ( kube_client.core.read_namespa...
Returns a 2-tuple of (the configmap, a bool representing whether it was just created)
get_or_create_namespaced_configmap
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_authenticating_services(soa_dir: str = DEFAULT_SOA_DIR) -> Set[str]: """Load list of services participating in authenticated traffic""" authenticating_services_conf_path = os.path.join(soa_dir, "authenticating.yaml") config = service_configuration_lib.read_yaml_file(authenticating_services_conf_path...
Load list of services participating in authenticated traffic
get_authenticating_services
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def add_volumes_for_authenticating_services( service_name: str, config_volumes: List[ProjectedSAVolume], soa_dir: str = DEFAULT_SOA_DIR, ) -> List[ProjectedSAVolume]: """Add projected service account volume to the list of volumes if service participates in authenticated traffic. In case of changes, ...
Add projected service account volume to the list of volumes if service participates in authenticated traffic. In case of changes, a new list is returned, no updates in-place. :param str service_name: name of the service :param List[ProjectedSAVolume] config_volumes: existing projected volumes from serv...
add_volumes_for_authenticating_services
python
Yelp/paasta
paasta_tools/kubernetes_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes_tools.py
Apache-2.0
def get_healthcheck_mode(self) -> str: """Get the healthcheck mode for the service. In most cases, this will match the mode of the service, but we do provide the opportunity for users to specify both. Default to the mode if no healthcheck_mode is specified. """ healthcheck_mode =...
Get the healthcheck mode for the service. In most cases, this will match the mode of the service, but we do provide the opportunity for users to specify both. Default to the mode if no healthcheck_mode is specified.
get_healthcheck_mode
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_mode(self) -> str: """Get the mode that the service runs in and check that we support it. If the mode is not specified, we check whether the service uses smartstack in order to determine the appropriate default value. If proxy_port is specified in the config, the service uses sma...
Get the mode that the service runs in and check that we support it. If the mode is not specified, we check whether the service uses smartstack in order to determine the appropriate default value. If proxy_port is specified in the config, the service uses smartstack, and we can thus safely assume...
get_mode
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_longest_timeout_ms(self) -> int: """Calculate the longest amount of time a connection to this service might stay open.""" return max( [self.get_timeout_server_ms()] + list(self.get("endpoint_timeouts", {}).values()) )
Calculate the longest amount of time a connection to this service might stay open.
get_longest_timeout_ms
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_drain_method(self, service_namespace_config: ServiceNamespaceConfig) -> str: """Get the drain method specified in the service's configuration. :param service_config: The service instance's configuration dictionary :returns: The drain method specified in the config, or 'noop' if not spec...
Get the drain method specified in the service's configuration. :param service_config: The service instance's configuration dictionary :returns: The drain method specified in the config, or 'noop' if not specified
get_drain_method
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_drain_method_params( self, service_namespace_config: ServiceNamespaceConfig ) -> Dict: """Get the drain method parameters specified in the service's configuration. :param service_config: The service instance's configuration dictionary :returns: The drain_method_params dictio...
Get the drain method parameters specified in the service's configuration. :param service_config: The service instance's configuration dictionary :returns: The drain_method_params dictionary specified in the config, or {} if not specified
get_drain_method_params
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_instances(self, with_limit: bool = True) -> int: """Gets the number of instances for a service, ignoring whether the user has requested the service to be started or stopped""" if self.is_autoscaling_enabled(): autoscaled_instances = self.get_autoscaled_instances() ...
Gets the number of instances for a service, ignoring whether the user has requested the service to be started or stopped
get_instances
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_desired_instances(self) -> int: """Get the number of instances specified in zookeeper or the service's configuration. If the number of instances in zookeeper is less than min_instances, returns min_instances. If the number of instances in zookeeper is greater than max_instances, returns ...
Get the number of instances specified in zookeeper or the service's configuration. If the number of instances in zookeeper is less than min_instances, returns min_instances. If the number of instances in zookeeper is greater than max_instances, returns max_instances. Defaults to 0 if not specif...
get_desired_instances
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_healthcheck_for_instance( service: str, instance: str, service_manifest: LongRunningServiceConfig, random_port: int, soa_dir: str = DEFAULT_SOA_DIR, ) -> Tuple[Optional[str], Optional[str]]: """ Returns healthcheck for a given service instance in the form of a tuple (mode, healthchec...
Returns healthcheck for a given service instance in the form of a tuple (mode, healthcheck_command) or (None, None) if no healthcheck
get_healthcheck_for_instance
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def load_service_namespace_config( service: str, namespace: str, soa_dir: str = DEFAULT_SOA_DIR ) -> ServiceNamespaceConfig: """Attempt to read the configuration for a service's namespace in a more strict fashion. Retrieves the following keys: - proxy_port: the proxy port defined for the given namespa...
Attempt to read the configuration for a service's namespace in a more strict fashion. Retrieves the following keys: - proxy_port: the proxy port defined for the given namespace - healthcheck_mode: the mode for the healthcheck (http or tcp) - healthcheck_port: An alternate port to use for health checki...
load_service_namespace_config
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_proxy_port_for_instance( service_config: LongRunningServiceConfig, ) -> Optional[int]: """Get the proxy_port defined in the first namespace configuration for a service instance. This means that the namespace first has to be loaded from the service instance's configuration, and then the prox...
Get the proxy_port defined in the first namespace configuration for a service instance. This means that the namespace first has to be loaded from the service instance's configuration, and then the proxy_port has to loaded from the smartstack configuration for that namespace. :param service_config:...
get_proxy_port_for_instance
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def host_passes_blacklist( host_attributes: Mapping[str, str], blacklist: DeployBlacklist ) -> bool: """ :param host: A single host attributes dict :param blacklist: A list of lists like [["location_type", "location"], ["foo", "bar"]] :returns: boolean, True if the host gets passed the blacklist ...
:param host: A single host attributes dict :param blacklist: A list of lists like [["location_type", "location"], ["foo", "bar"]] :returns: boolean, True if the host gets passed the blacklist
host_passes_blacklist
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def host_passes_whitelist( host_attributes: Mapping[str, str], whitelist: DeployWhitelist ) -> bool: """ :param host: A single host attributes dict. :param whitelist: A 2 item list like ["location_type", ["location1", 'location2']] :returns: boolean, True if the host gets past the whitelist """ ...
:param host: A single host attributes dict. :param whitelist: A 2 item list like ["location_type", ["location1", 'location2']] :returns: boolean, True if the host gets past the whitelist
host_passes_whitelist
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_all_namespaces( soa_dir: str = DEFAULT_SOA_DIR, ) -> Sequence[Tuple[str, ServiceNamespaceConfig]]: """Get all the smartstack namespaces across all services. This is mostly so synapse can get everything it needs in one call. :param soa_dir: The SOA config directory to read from :returns: A l...
Get all the smartstack namespaces across all services. This is mostly so synapse can get everything it needs in one call. :param soa_dir: The SOA config directory to read from :returns: A list of tuples of the form (service.namespace, namespace_config)
get_all_namespaces
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_all_namespaces_for_service( service: str, soa_dir: str = DEFAULT_SOA_DIR, full_name: bool = True ) -> Sequence[Tuple[str, ServiceNamespaceConfig]]: """Get all the smartstack namespaces listed for a given service name. :param service: The service name :param soa_dir: The SOA config directory to ...
Get all the smartstack namespaces listed for a given service name. :param service: The service name :param soa_dir: The SOA config directory to read from :param full_name: A boolean indicating if the service name should be prepended to the namespace in the returned tuples as described...
get_all_namespaces_for_service
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def get_expected_instance_count_for_namespace( service: str, namespace: str, instance_type_class: Type[LongRunningServiceConfig], cluster: str = None, soa_dir: str = DEFAULT_SOA_DIR, ) -> int: """Get the number of expected instances for a namespace, based on the number of instances set to ru...
Get the number of expected instances for a namespace, based on the number of instances set to run on that namespace as specified in service configuration files. :param service: The service's name :param namespace: The namespace for that service to check instance_type_class: The type of the instance, op...
get_expected_instance_count_for_namespace
python
Yelp/paasta
paasta_tools/long_running_service_tools.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/long_running_service_tools.py
Apache-2.0
def reserve_unique_mac_address(lock_directory): """Pick and reserve a unique mac address for a container returns (mac_address, lockfile) where the mac address is a string in the form of 00:00:00:00:00:00 and lockfile is a file object that holds an exclusive lock """ for x in range(100): ...
Pick and reserve a unique mac address for a container returns (mac_address, lockfile) where the mac address is a string in the form of 00:00:00:00:00:00 and lockfile is a file object that holds an exclusive lock
reserve_unique_mac_address
python
Yelp/paasta
paasta_tools/mac_address.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mac_address.py
Apache-2.0
def obtain_lock(lock_filepath): """Open and obtain a flock on the parameter. Returns a file if successful, None if not""" lock_file = open(lock_filepath, "w") try: fcntl.flock(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB) return lock_file except IOError as err: if err.errno != errno....
Open and obtain a flock on the parameter. Returns a file if successful, None if not
obtain_lock
python
Yelp/paasta
paasta_tools/mac_address.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mac_address.py
Apache-2.0
def base_api(mesos_config_path: Optional[str] = None): """Helper function for making all API requests :returns: a function that can be called to make a request """ leader = get_mesos_leader(mesos_config_path) def execute_request(method, endpoint, timeout=(3, 2), **kwargs): url = "http://%s...
Helper function for making all API requests :returns: a function that can be called to make a request
base_api
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def master_api(mesos_config_path: Optional[str] = None): """Helper function for making API requests to the /master API endpoints :returns: a function that can be called to make a request to /master """ def execute_master_api_request(method, endpoint, **kwargs): base_api_client = base_api(mesos...
Helper function for making API requests to the /master API endpoints :returns: a function that can be called to make a request to /master
master_api
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def reserve_api(): """Helper function for making API requests to the /reserve API endpoints :returns: a function that can be called to make a request to /reserve """ def execute_reserve_api_request(method, endpoint, **kwargs): master_api_client = master_api() return master_api_client(m...
Helper function for making API requests to the /reserve API endpoints :returns: a function that can be called to make a request to /reserve
reserve_api
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def unreserve_api(): """Helper function for making API requests to the /unreserve API endpoints :returns: a function that can be called to make a request to /unreserve """ def execute_unreserve_api_request(method, endpoint, **kwargs): master_api_client = master_api() return master_api_...
Helper function for making API requests to the /unreserve API endpoints :returns: a function that can be called to make a request to /unreserve
unreserve_api
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def maintenance_api(): """Helper function for making API requests to the /master/maintenance API endpoints :returns: a function that can be called to make a request to /master/maintenance """ def execute_schedule_api_request(method, endpoint, **kwargs): master_api_client = master_api() ...
Helper function for making API requests to the /master/maintenance API endpoints :returns: a function that can be called to make a request to /master/maintenance
maintenance_api
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def get_schedule_client(): """Helper function for making API requests to the /master/maintenance/schedule API endpoints :returns: a function that can be called to make a request to /master/maintenance/schedule """ def execute_schedule_api_request(method, endpoint, **kwargs): maintenance_api_cl...
Helper function for making API requests to the /master/maintenance/schedule API endpoints :returns: a function that can be called to make a request to /master/maintenance/schedule
get_schedule_client
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def get_maintenance_schedule(): """Makes a GET_MAINTENANCE_SCHEDULE request to the operator api :returns: a GET_MAINTENANCE_SCHEDULE response """ client_fn = operator_api() return client_fn(data={"type": "GET_MAINTENANCE_SCHEDULE"})
Makes a GET_MAINTENANCE_SCHEDULE request to the operator api :returns: a GET_MAINTENANCE_SCHEDULE response
get_maintenance_schedule
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def get_maintenance_status(mesos_config_path: Optional[str] = None): """Makes a GET_MAINTENANCE_STATUS request to the operator api :returns: a GET_MAINTENANCE_STATUS response """ client_fn = operator_api(mesos_config_path=mesos_config_path) return client_fn(data={"type": "GET_MAINTENANCE_STATUS"})
Makes a GET_MAINTENANCE_STATUS request to the operator api :returns: a GET_MAINTENANCE_STATUS response
get_maintenance_status
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def schedule(): """Get the Mesos maintenance schedule. This contains hostname/ip mappings and their maintenance window. :returns: GET_MAINTENANCE_SCHEDULE response text """ try: schedule = get_maintenance_schedule() except HTTPError: raise HTTPError("Error getting maintenance schedul...
Get the Mesos maintenance schedule. This contains hostname/ip mappings and their maintenance window. :returns: GET_MAINTENANCE_SCHEDULE response text
schedule
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def get_hosts_with_state( state, system_paasta_config: Optional[SystemPaastaConfig] = None ) -> List[str]: """Helper function to check the maintenance status and return all hosts listed as being in a current state :param state: State we are interested in ('down_machines' or 'draining_machines') :re...
Helper function to check the maintenance status and return all hosts listed as being in a current state :param state: State we are interested in ('down_machines' or 'draining_machines') :returns: A list of hostnames in the specified state or an empty list if no machines
get_hosts_with_state
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def get_draining_hosts(system_paasta_config: Optional[SystemPaastaConfig] = None): """Returns a list of hostnames that are marked as draining :returns: a list of strings representing hostnames """ return get_hosts_with_state( state="draining_machines", system_paasta_config=system_paasta_config ...
Returns a list of hostnames that are marked as draining :returns: a list of strings representing hostnames
get_draining_hosts
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def get_hosts_forgotten_draining(grace=0): """Find hosts that are still marked as draining (rather than down) after the start of their maintenance window. :param grace: integer number of nanoseconds to allow a host to be left in the draining state after the start of its maintenance window before we cons...
Find hosts that are still marked as draining (rather than down) after the start of their maintenance window. :param grace: integer number of nanoseconds to allow a host to be left in the draining state after the start of its maintenance window before we consider it forgotten. :returns: a list of hostnam...
get_hosts_forgotten_draining
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def get_hosts_forgotten_down(grace=0): """Find hosts that are still marked as down (rather than up) after the end of their maintenance window. :param grace: integer number of nanoseconds to allow a host to be left in the down state after the end of its maintenance window before we consider it forgotten....
Find hosts that are still marked as down (rather than up) after the end of their maintenance window. :param grace: integer number of nanoseconds to allow a host to be left in the down state after the end of its maintenance window before we consider it forgotten. :returns: a list of hostnames of hosts fo...
get_hosts_forgotten_down
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def parse_timedelta(value): """Return the delta in nanoseconds. :param value: a string containing a time format supported by :mod:`pytimeparse` :returns: an integer (or float) representing the specified delta in nanoseconds """ error_msg = "'%s' is not a valid time expression" % value try: ...
Return the delta in nanoseconds. :param value: a string containing a time format supported by :mod:`pytimeparse` :returns: an integer (or float) representing the specified delta in nanoseconds
parse_timedelta
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def parse_datetime(value): """Return the datetime in nanoseconds. :param value: a string containing a datetime supported by :mod:`dateutil.parser` :returns: an integer (or float) representing the specified datetime in nanoseconds """ error_msg = "'%s' is not a valid datetime expression" % value ...
Return the datetime in nanoseconds. :param value: a string containing a datetime supported by :mod:`dateutil.parser` :returns: an integer (or float) representing the specified datetime in nanoseconds
parse_datetime
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def build_maintenance_payload(hostnames, maint_type): """Creates the JSON payload necessary to bring the specified hostnames up/down for maintenance. :param hostnames: a list of hostnames :returns: a dictionary representing the list of machines to bring up/down for maintenance """ return { "...
Creates the JSON payload necessary to bring the specified hostnames up/down for maintenance. :param hostnames: a list of hostnames :returns: a dictionary representing the list of machines to bring up/down for maintenance
build_maintenance_payload
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def hostnames_to_components(hostnames, resolve=False): """Converts a list of 'host[|ip]' entries into namedtuples containing 'host' and 'ip' attributes, optionally performing a DNS lookup to resolve the hostname into an IP address :param hostnames: a list of hostnames where each hostname can be of the form ...
Converts a list of 'host[|ip]' entries into namedtuples containing 'host' and 'ip' attributes, optionally performing a DNS lookup to resolve the hostname into an IP address :param hostnames: a list of hostnames where each hostname can be of the form 'host[|ip]' :param resolve: boolean representing whether t...
hostnames_to_components
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def get_machine_ids(hostnames): """Helper function to convert a list of hostnames into a JSON list of hostname/ip pairs. :param hostnames: a list of hostnames :returns: a dictionary representing the list of machines to bring up/down for maintenance """ machine_ids = [] components = hostnames_to_...
Helper function to convert a list of hostnames into a JSON list of hostname/ip pairs. :param hostnames: a list of hostnames :returns: a dictionary representing the list of machines to bring up/down for maintenance
get_machine_ids
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def build_reservation_payload(resources): """Creates the JSON payload needed to dynamically (un)reserve resources in mesos. :param resources: list of Resource named tuples specifying the name and amount of the resource to (un)reserve :returns: a dictionary that can be sent to Mesos to (un)reserve resources ...
Creates the JSON payload needed to dynamically (un)reserve resources in mesos. :param resources: list of Resource named tuples specifying the name and amount of the resource to (un)reserve :returns: a dictionary that can be sent to Mesos to (un)reserve resources
build_reservation_payload
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def build_maintenance_schedule_payload( hostnames, start=None, duration=None, drain=True ): """Creates the JSON payload needed to (un)schedule maintenance on the specified hostnames. :param hostnames: a list of hostnames :param start: the time to start the maintenance, represented as number of nanosecon...
Creates the JSON payload needed to (un)schedule maintenance on the specified hostnames. :param hostnames: a list of hostnames :param start: the time to start the maintenance, represented as number of nanoseconds since the epoch :param duration: length of the maintenance window, represented as number of nano...
build_maintenance_schedule_payload
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0
def load_credentials(mesos_secrets="/nail/etc/mesos-slave-secret"): """Loads the mesos-slave credentials from the specified file. These credentials will be used for all maintenance API requests. :param mesos_secrets: optional argument specifying the path to the file containing the mesos-slave credentials ...
Loads the mesos-slave credentials from the specified file. These credentials will be used for all maintenance API requests. :param mesos_secrets: optional argument specifying the path to the file containing the mesos-slave credentials :returns: a tuple of the form (username, password)
load_credentials
python
Yelp/paasta
paasta_tools/mesos_maintenance.py
https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos_maintenance.py
Apache-2.0