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 generate_toolbox_deployment(
service: str, cluster: str, user: str
) -> EksDeploymentConfig:
"""Creates virtual EKS deployment for toolbox containers starting from adhoc configuration
:param str service: toolbox name
:param str cluster: target deployment cluster
:param str user: user requesting... | Creates virtual EKS deployment for toolbox containers starting from adhoc configuration
:param str service: toolbox name
:param str cluster: target deployment cluster
:param str user: user requesting the toolbox
:return: deployment configuration
| generate_toolbox_deployment | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def find_job_pod(
kube_client: KubeClient,
namespace: str,
job_name: str,
job_label: str = REMOTE_RUN_JOB_LABEL,
retries: int = 3,
) -> Optional[V1Pod]:
"""Locate pod for remote-run job
:param KubeClient kube_client: Kubernetes client
:param str namespace: the pod namespace
:param s... | Locate pod for remote-run job
:param KubeClient kube_client: Kubernetes client
:param str namespace: the pod namespace
:param str job_name: remote-run job name
:param int retries: maximum number of attemps
:return: pod object if found
| find_job_pod | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def create_temp_exec_token(
kube_client: KubeClient,
namespace: str,
service_account: str,
) -> str:
"""Create a short lived token for service account
:param KubeClient kube_client: Kubernetes client
:param str namespace: service account namespace
:param str service_account: service account... | Create a short lived token for service account
:param KubeClient kube_client: Kubernetes client
:param str namespace: service account namespace
:param str service_account: service account name
:return: token value
| create_temp_exec_token | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def get_remote_run_service_accounts(
kube_client: KubeClient, namespace: str, user: str = ""
) -> Sequence[V1ServiceAccount]:
"""List all temporary service account related to remote-run
:param KubeClient kube_client: Kubernetes client
:param str namespace: pod namespace
:param str user: optionally ... | List all temporary service account related to remote-run
:param KubeClient kube_client: Kubernetes client
:param str namespace: pod namespace
:param str user: optionally filter by owning user
:return: list of service accounts
| get_remote_run_service_accounts | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def create_remote_run_service_account(
kube_client: KubeClient,
namespace: str,
pod_name: str,
user: str,
) -> str:
"""Create service account to exec into remote-run pod
:param KubeClient kube_client: Kubernetes client
:param str namespace: pod namespace
:param str pod_name: pod name
... | Create service account to exec into remote-run pod
:param KubeClient kube_client: Kubernetes client
:param str namespace: pod namespace
:param str pod_name: pod name
:param str user: user requiring credentials
| create_remote_run_service_account | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def create_pod_scoped_role(
kube_client: KubeClient,
namespace: str,
pod_name: str,
user: str,
) -> str:
"""Create role with execution access to specific pod
:param KubeClient kube_client: Kubernetes client
:param str namespace: pod namespace
:param str pod_name: pod name
:param str... | Create role with execution access to specific pod
:param KubeClient kube_client: Kubernetes client
:param str namespace: pod namespace
:param str pod_name: pod name
:param str user: user requiring the role
:return: name of the role
| create_pod_scoped_role | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def bind_role_to_service_account(
kube_client: KubeClient,
namespace: str,
service_account: str,
role: str,
user: str,
) -> None:
"""Bind service account to role
:param KubeClient kube_client: Kubernetes client
:param str namespace: service account namespace
:param str service_accou... | Bind service account to role
:param KubeClient kube_client: Kubernetes client
:param str namespace: service account namespace
:param str service_account: service account name
:param str role: role name
:param str user: user requiring the role
| bind_role_to_service_account | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def get_remote_run_roles(kube_client: KubeClient, namespace: str) -> List[V1Role]:
"""List all temporary roles related to remote-run
:param KubeClient kube_client: Kubernetes client
:param str namespace: role namespace
:return: list of roles
"""
return kube_client.rbac.list_namespaced_role(
... | List all temporary roles related to remote-run
:param KubeClient kube_client: Kubernetes client
:param str namespace: role namespace
:return: list of roles
| get_remote_run_roles | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def get_remote_run_role_bindings(
kube_client: KubeClient, namespace: str
) -> List[V1RoleBinding]:
"""List all temporary role bindings related to remote-run
:param KubeClient kube_client: Kubernetes client
:param str namespace: role namespace
:return: list of roles
"""
return kube_client.r... | List all temporary role bindings related to remote-run
:param KubeClient kube_client: Kubernetes client
:param str namespace: role namespace
:return: list of roles
| get_remote_run_role_bindings | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def get_remote_run_jobs(kube_client: KubeClient, namespace: str) -> List[V1Job]:
"""List all remote-run jobs
:param KubeClient kube_client: Kubernetes client
:param str namespace: job namespace
"""
return kube_client.batches.list_namespaced_job(
namespace,
label_selector=f"{paasta_p... | List all remote-run jobs
:param KubeClient kube_client: Kubernetes client
:param str namespace: job namespace
| get_remote_run_jobs | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def __init__(
self,
item: Union[V1Deployment, V1StatefulSet],
logging=logging.getLogger(__name__),
) -> None:
"""
This Application wrapper is an interface for creating/deleting k8s deployments and statefulsets
soa_config is KubernetesDeploymentConfig. It is not loaded... |
This Application wrapper is an interface for creating/deleting k8s deployments and statefulsets
soa_config is KubernetesDeploymentConfig. It is not loaded in init because it is not always required.
:param item: Kubernetes Object(V1Deployment/V1StatefulSet) that has already been filled up.
... | __init__ | python | Yelp/paasta | paasta_tools/kubernetes/application/controller_wrappers.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/application/controller_wrappers.py | Apache-2.0 |
def ensure_service_account(self, kube_client: KubeClient) -> None:
"""
Ensure that the service account for this application exists
:param kube_client:
"""
if self.soa_config.get_iam_role():
ensure_service_account(
iam_role=self.soa_config.get_iam_role(... |
Ensure that the service account for this application exists
:param kube_client:
| ensure_service_account | python | Yelp/paasta | paasta_tools/kubernetes/application/controller_wrappers.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/application/controller_wrappers.py | Apache-2.0 |
def deep_delete(
self, kube_client: KubeClient, propagation_policy="Foreground"
) -> None:
"""
Remove all controllers, pods, and pod disruption budgets related to this application
:param kube_client:
"""
delete_options = V1DeleteOptions(propagation_policy=propagation_... |
Remove all controllers, pods, and pod disruption budgets related to this application
:param kube_client:
| deep_delete | python | Yelp/paasta | paasta_tools/kubernetes/application/controller_wrappers.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/application/controller_wrappers.py | Apache-2.0 |
def sync_horizontal_pod_autoscaler(self, kube_client: KubeClient) -> None:
"""
In order for autoscaling to work, there needs to be at least two configurations
min_instnace, max_instance, and there cannot be instance.
"""
desired_hpa_spec = self.soa_config.get_autoscaling_metric_s... |
In order for autoscaling to work, there needs to be at least two configurations
min_instnace, max_instance, and there cannot be instance.
| sync_horizontal_pod_autoscaler | python | Yelp/paasta | paasta_tools/kubernetes/application/controller_wrappers.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/application/controller_wrappers.py | Apache-2.0 |
def deep_delete(self, kube_client: KubeClient) -> None:
"""
Remove all controllers, pods, and pod disruption budgets related to this application
:param kube_client:
"""
delete_options = V1DeleteOptions(propagation_policy="Foreground")
try:
kube_client.deployme... |
Remove all controllers, pods, and pod disruption budgets related to this application
:param kube_client:
| deep_delete | python | Yelp/paasta | paasta_tools/kubernetes/application/controller_wrappers.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/application/controller_wrappers.py | Apache-2.0 |
def deep_delete(self, kube_client: KubeClient) -> None:
"""Remove resources related to the job"""
delete_options = V1DeleteOptions(propagation_policy="Foreground")
try:
kube_client.batches.delete_namespaced_job(
self.item.metadata.name,
self.item.metad... | Remove resources related to the job | deep_delete | python | Yelp/paasta | paasta_tools/kubernetes/application/controller_wrappers.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/application/controller_wrappers.py | Apache-2.0 |
def list_all_applications(
kube_client: KubeClient, application_types: Sequence[Any]
) -> Dict[Tuple[str, str], List[Application]]:
"""
List all applications in the cluster of the types from application_types.
Only applications with complete set of labels are included (See is_valid_application()).
:... |
List all applications in the cluster of the types from application_types.
Only applications with complete set of labels are included (See is_valid_application()).
:param kube_client:
:param application_types: types of applications
:return: A mapping from (service, instance) to application
| list_all_applications | python | Yelp/paasta | paasta_tools/kubernetes/application/tools.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/application/tools.py | Apache-2.0 |
def set_temporary_environment_variables(
environ: Mapping[str, str]
) -> Generator[None, None, None]:
"""
*Note the return value means "yields None, takes None, and when finished, returns None"*
Modifies the os.environ variable then yields this temporary state. Resets it when finished.
:param envi... |
*Note the return value means "yields None, takes None, and when finished, returns None"*
Modifies the os.environ variable then yields this temporary state. Resets it when finished.
:param environ: Environment variables to set
| set_temporary_environment_variables | python | Yelp/paasta | paasta_tools/kubernetes/bin/paasta_secrets_sync.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/bin/paasta_secrets_sync.py | Apache-2.0 |
def get_services_to_k8s_namespaces_to_allowlist(
service_list: List[str], cluster: str, soa_dir: str, kube_client: KubeClient
) -> Dict[
str, # service
Dict[
str, # namespace
Optional[Set[str]], # allowlist of secret names, None means allow all.
],
]:
"""
Generate a mapping of... |
Generate a mapping of service -> namespace -> allowlist of secrets, e.g.
{
"yelp-main": {
"paasta": {"secret1", "secret2"},
"paastasvc-yelp-main": {"secret1", "secret3"},
"paasta-flinks": None,
},
"_shared": {
"paasta": {"sharedsecret1"},... | get_services_to_k8s_namespaces_to_allowlist | python | Yelp/paasta | paasta_tools/kubernetes/bin/paasta_secrets_sync.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/bin/paasta_secrets_sync.py | Apache-2.0 |
def sync_datastore_credentials(
kube_client: KubeClient,
cluster: str,
service: str,
secret_provider_name: str,
vault_cluster_config: Dict[str, str],
soa_dir: str,
vault_token_file: str,
overwrite_namespace: Optional[str] = None,
) -> bool:
"""
Map all the passwords requested for... |
Map all the passwords requested for this service-instance to a single Kubernetes Secret store.
Volume mounts will then map the associated secrets to their associated mount paths.
| sync_datastore_credentials | python | Yelp/paasta | paasta_tools/kubernetes/bin/paasta_secrets_sync.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/bin/paasta_secrets_sync.py | Apache-2.0 |
def sync_crypto_secrets(
kube_client: KubeClient,
cluster: str,
service: str,
secret_provider_name: str,
vault_cluster_config: Dict[str, str],
soa_dir: str,
vault_token_file: str,
) -> bool:
"""
For each key-name in `crypto_key`,
1. Fetch all versions of the key-name from Vault s... |
For each key-name in `crypto_key`,
1. Fetch all versions of the key-name from Vault superregion mapped from cluster, e.g. `kubestage` maps to `devc` Vault server.
2. Create K8s secret from JSON blob containing all key versions.
3. Create signatures as K8s configmap based on JSON blob hash.
So each... | sync_crypto_secrets | python | Yelp/paasta | paasta_tools/kubernetes/bin/paasta_secrets_sync.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/bin/paasta_secrets_sync.py | Apache-2.0 |
def create_or_update_k8s_secret(
service: str,
secret_name: str,
signature_name: str,
get_secret_data: Callable[[], Dict[str, str]],
secret_signature: str,
kube_client: KubeClient,
namespace: str,
) -> None:
"""
:param get_secret_data: is a function to postpone fetching data in order... |
:param get_secret_data: is a function to postpone fetching data in order to reduce service load, e.g. Vault API
| create_or_update_k8s_secret | python | Yelp/paasta | paasta_tools/kubernetes/bin/paasta_secrets_sync.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/bin/paasta_secrets_sync.py | Apache-2.0 |
def resolve(self, cfg):
"""Resolve the URL to the mesos master.
The value of cfg should be one of:
- host:port
- zk://host1:port1,host2:port2/path
- zk://username:password@host1:port1/path
- file:///path/to/file (where file contains one of the above)
... | Resolve the URL to the mesos master.
The value of cfg should be one of:
- host:port
- zk://host1:port1,host2:port2/path
- zk://username:password@host1:port1/path
- file:///path/to/file (where file contains one of the above)
| resolve | python | Yelp/paasta | paasta_tools/mesos/master.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos/master.py | Apache-2.0 |
def stream(fn, elements, workers):
"""Yield the results of fn as jobs complete."""
jobs = []
with execute(workers) as executor:
for elem in elements:
jobs.append(executor.submit(fn, elem))
for job in concurrent.futures.as_completed(jobs):
try:
yield ... | Yield the results of fn as jobs complete. | stream | python | Yelp/paasta | paasta_tools/mesos/parallel.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/mesos/parallel.py | Apache-2.0 |
def get_num_masters() -> int:
"""Gets the number of masters from mesos state"""
zookeeper_host_path = get_zookeeper_host_path()
return get_number_of_mesos_masters(
zookeeper_host_path.host, zookeeper_host_path.path
) | Gets the number of masters from mesos state | get_num_masters | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_mesos_cpu_status(
metrics: MesosMetrics, mesos_state: MesosState
) -> Tuple[int, int, int]:
"""Takes in the mesos metrics and analyzes them, returning the status.
:param metrics: mesos metrics dictionary.
:param mesos_state: mesos state dictionary.
:returns: Tuple of total, used, and availa... | Takes in the mesos metrics and analyzes them, returning the status.
:param metrics: mesos metrics dictionary.
:param mesos_state: mesos state dictionary.
:returns: Tuple of total, used, and available CPUs.
| get_mesos_cpu_status | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_kube_cpu_status(
nodes: Sequence[V1Node],
) -> Tuple[float, float, float]:
"""Takes in the list of Kubernetes nodes and analyzes them, returning the status.
:param nodes: list of Kubernetes nodes.
:returns: Tuple of total, used, and available CPUs.
"""
total = 0.0
available = 0.0
... | Takes in the list of Kubernetes nodes and analyzes them, returning the status.
:param nodes: list of Kubernetes nodes.
:returns: Tuple of total, used, and available CPUs.
| get_kube_cpu_status | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_mesos_memory_status(
metrics: MesosMetrics, mesos_state: MesosState
) -> Tuple[int, int, int]:
"""Takes in the mesos metrics and analyzes them, returning the status.
:param metrics: mesos metrics dictionary.
:param mesos_state: mesos state dictionary.
:returns: Tuple of total, used, and ava... | Takes in the mesos metrics and analyzes them, returning the status.
:param metrics: mesos metrics dictionary.
:param mesos_state: mesos state dictionary.
:returns: Tuple of total, used, and available memory in Mi.
| get_mesos_memory_status | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_kube_memory_status(
nodes: Sequence[V1Node],
) -> Tuple[float, float, float]:
"""Takes in the list of Kubernetes nodes and analyzes them, returning the status.
:param nodes: list of Kubernetes nodes.
:returns: Tuple of total, used, and available memory in Mi.
"""
total = 0.0
availab... | Takes in the list of Kubernetes nodes and analyzes them, returning the status.
:param nodes: list of Kubernetes nodes.
:returns: Tuple of total, used, and available memory in Mi.
| get_kube_memory_status | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_mesos_disk_status(
metrics: MesosMetrics, mesos_state: MesosState
) -> Tuple[int, int, int]:
"""Takes in the mesos metrics and analyzes them, returning the status.
:param metrics: mesos metrics dictionary.
:param mesos_state: mesos state dictionary.
:returns: Tuple of total, used, and avail... | Takes in the mesos metrics and analyzes them, returning the status.
:param metrics: mesos metrics dictionary.
:param mesos_state: mesos state dictionary.
:returns: Tuple of total, used, and available disk space in Mi.
| get_mesos_disk_status | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_kube_disk_status(
nodes: Sequence[V1Node],
) -> Tuple[float, float, float]:
"""Takes in the list of Kubernetes nodes and analyzes them, returning the status.
:param nodes: list of Kubernetes nodes.
:returns: Tuple of total, used, and available disk space in Mi.
"""
total = 0.0
avai... | Takes in the list of Kubernetes nodes and analyzes them, returning the status.
:param nodes: list of Kubernetes nodes.
:returns: Tuple of total, used, and available disk space in Mi.
| get_kube_disk_status | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_mesos_gpu_status(
metrics: MesosMetrics, mesos_state: MesosState
) -> Tuple[int, int, int]:
"""Takes in the mesos metrics and analyzes them, returning gpus status.
:param metrics: mesos metrics dictionary.
:param mesos_state: mesos state dictionary.
:returns: Tuple of total, used, and avail... | Takes in the mesos metrics and analyzes them, returning gpus status.
:param metrics: mesos metrics dictionary.
:param mesos_state: mesos state dictionary.
:returns: Tuple of total, used, and available GPUs.
| get_mesos_gpu_status | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_kube_gpu_status(
nodes: Sequence[V1Node],
) -> Tuple[float, float, float]:
"""Takes in the list of Kubernetes nodes and analyzes them, returning the status.
:param nodes: list of Kubernetes nodes.
:returns: Tuple of total, used, and available GPUs.
"""
total = 0.0
available = 0.0
... | Takes in the list of Kubernetes nodes and analyzes them, returning the status.
:param nodes: list of Kubernetes nodes.
:returns: Tuple of total, used, and available GPUs.
| get_kube_gpu_status | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def healthcheck_result_for_resource_utilization(
resource_utilization: ResourceUtilization, threshold: int
) -> HealthCheckResult:
"""Given a resource data dict, assert that cpu
data is ok.
:param resource_utilization: the resource_utilization tuple to check
:returns: a HealthCheckResult
"""
... | Given a resource data dict, assert that cpu
data is ok.
:param resource_utilization: the resource_utilization tuple to check
:returns: a HealthCheckResult
| healthcheck_result_for_resource_utilization | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def key_func_for_attribute(
attribute: str,
) -> Callable[[_SlaveT], str]:
"""Return a closure that given a slave, will return the value of a specific
attribute.
:param attribute: the attribute to inspect in the slave
:returns: a closure, which takes a slave and returns the value of an attribute
... | Return a closure that given a slave, will return the value of a specific
attribute.
:param attribute: the attribute to inspect in the slave
:returns: a closure, which takes a slave and returns the value of an attribute
| key_func_for_attribute | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def key_func_for_attribute_multi(
attributes: Sequence[str],
) -> _GenericNodeGroupingFunctionT:
"""Return a closure that given a slave, will return the value of a list of
attributes, compiled into a hashable tuple
:param attributes: the attributes to inspect in the slave
:returns: a closure, which... | Return a closure that given a slave, will return the value of a list of
attributes, compiled into a hashable tuple
:param attributes: the attributes to inspect in the slave
:returns: a closure, which takes a slave and returns the value of those attributes
| key_func_for_attribute_multi | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def key_func_for_attribute_multi_kube(
attributes: Sequence[str],
) -> Callable[[V1Node], _KeyFuncRetT]:
"""Return a closure that given a node, will return the value of a list of
attributes, compiled into a hashable tuple
:param attributes: the attributes to inspect in the slave
:returns: a closure... | Return a closure that given a node, will return the value of a list of
attributes, compiled into a hashable tuple
:param attributes: the attributes to inspect in the slave
:returns: a closure, which takes a node and returns the value of those attributes
| key_func_for_attribute_multi_kube | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def group_slaves_by_key_func(
key_func: _GenericNodeGroupingFunctionT,
slaves: Sequence[_GenericNodeT],
sort_func: _GenericNodeSortFunctionT = None,
) -> Mapping[_KeyFuncRetT, Sequence[_GenericNodeT]]:
"""Given a function for grouping slaves, return a
dict where keys are the unique values returned b... | Given a function for grouping slaves, return a
dict where keys are the unique values returned by
the key_func and the values are all those slaves which
have that specific value.
:param key_func: a function which consumes a slave and returns a value
:param slaves: a list of slaves
:returns: a di... | group_slaves_by_key_func | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def calculate_resource_utilization_for_slaves(
slaves: Sequence[_SlaveT], tasks: Sequence[MesosTask]
) -> ResourceUtilizationDict:
"""Given a list of slaves and a list of tasks, calculate the total available
resource available in that list of slaves, and the resources consumed by tasks
running on those ... | Given a list of slaves and a list of tasks, calculate the total available
resource available in that list of slaves, and the resources consumed by tasks
running on those slaves.
:param slaves: a list of slaves to calculate resource usage for
:param tasks: the list of tasks running in the mesos cluster
... | calculate_resource_utilization_for_slaves | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def calculate_resource_utilization_for_kube_nodes(
nodes: Sequence[V1Node],
pods_by_node: Mapping[str, Sequence[V1Pod]],
) -> ResourceUtilizationDict:
"""Given a list of Kubernetes nodes, calculate the total available
resource available and the resources consumed in that list of nodes.
:param nodes... | Given a list of Kubernetes nodes, calculate the total available
resource available and the resources consumed in that list of nodes.
:param nodes: a list of Kubernetes nodes to calculate resource usage for
:returns: a dict, containing keys for "free" and "total" resources. Each of these keys
is a Resou... | calculate_resource_utilization_for_kube_nodes | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def filter_tasks_for_slaves(
slaves: Sequence[_SlaveT], tasks: Sequence[MesosTask]
) -> Sequence[MesosTask]:
"""Given a list of slaves and a list of tasks, return a filtered
list of tasks, where those returned belong to slaves in the list of
slaves
:param slaves: the list of slaves which the tasks ... | Given a list of slaves and a list of tasks, return a filtered
list of tasks, where those returned belong to slaves in the list of
slaves
:param slaves: the list of slaves which the tasks provided should be
running on.
:param tasks: the tasks to filter :returns: a list of tasks,
identical to tha... | filter_tasks_for_slaves | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def filter_slaves(
slaves: Sequence[_GenericNodeT], filters: Sequence[_GenericNodeFilterFunctionT]
) -> Sequence[_GenericNodeT]:
"""Filter slaves by attributes
:param slaves: list of slaves to filter
:param filters: list of functions that take a slave and return whether the
slave should be included... | Filter slaves by attributes
:param slaves: list of slaves to filter
:param filters: list of functions that take a slave and return whether the
slave should be included
:returns: list of slaves that return true for all the filters
| filter_slaves | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_resource_utilization_by_grouping(
grouping_func: _GenericNodeGroupingFunctionT,
mesos_state: MesosState,
filters: Sequence[_GenericNodeFilterFunctionT] = [],
sort_func: _GenericNodeSortFunctionT = None,
) -> Mapping[_KeyFuncRetT, ResourceUtilizationDict]:
"""Given a function used to group sl... | Given a function used to group slaves and mesos state, calculate
resource utilization for each value of a given attribute.
:grouping_func: a function that given a slave, will return the value of an
attribute to group by.
:param mesos_state: the mesos state
:param filters: filters to apply to the sl... | get_resource_utilization_by_grouping | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_resource_utilization_by_grouping_kube(
grouping_func: _GenericNodeGroupingFunctionT,
kube_client: KubeClient,
*,
namespace: str,
filters: Sequence[_GenericNodeFilterFunctionT] = [],
sort_func: _GenericNodeSortFunctionT = None,
) -> Mapping[_KeyFuncRetT, ResourceUtilizationDict]:
"""G... | Given a function used to group nodes, calculate resource utilization
for each value of a given attribute.
:grouping_func: a function that given a node, will return the value of an
attribute to group by.
:param kube_client: the Kubernetes client
:param filters: filters to apply to the nodes in the c... | get_resource_utilization_by_grouping_kube | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def resource_utillizations_from_resource_info(
total: ResourceInfo, free: ResourceInfo
) -> Sequence[ResourceUtilization]:
"""
Given two ResourceInfo tuples, one for total and one for free,
create a ResourceUtilization tuple for each metric in the ResourceInfo.
:param total:
:param free:
:re... |
Given two ResourceInfo tuples, one for total and one for free,
create a ResourceUtilization tuple for each metric in the ResourceInfo.
:param total:
:param free:
:returns: ResourceInfo for a metric
| resource_utillizations_from_resource_info | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def has_registered_slaves(
mesos_state: MesosState,
) -> bool:
"""Return a boolean indicating if there are any slaves registered
to the master according to the mesos state.
:param mesos_state: the mesos state from the master
:returns: a boolean, indicating if there are > 0 slaves
"""
return ... | Return a boolean indicating if there are any slaves registered
to the master according to the mesos state.
:param mesos_state: the mesos state from the master
:returns: a boolean, indicating if there are > 0 slaves
| has_registered_slaves | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_kube_resource_utilization_health(
kube_client: KubeClient,
) -> Sequence[HealthCheckResult]:
"""Perform healthchecks against Kubernetes.
:param kube_client: the KUbernetes client
:returns: a list of HealthCheckResult tuples
"""
nodes = get_all_nodes_cached(kube_client)
return [
... | Perform healthchecks against Kubernetes.
:param kube_client: the KUbernetes client
:returns: a list of HealthCheckResult tuples
| get_kube_resource_utilization_health | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_kube_status(
kube_client: KubeClient, namespace: str
) -> Sequence[HealthCheckResult]:
"""Gather information about Kubernetes.
:param kube_client: the KUbernetes client
:return: string containing the status
"""
return run_healthchecks_with_param(
[kube_client, namespace], [assert... | Gather information about Kubernetes.
:param kube_client: the KUbernetes client
:return: string containing the status
| get_kube_status | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def critical_events_in_outputs(healthcheck_outputs):
"""Given a list of HealthCheckResults return those which are unhealthy."""
return [
healthcheck
for healthcheck in healthcheck_outputs
if healthcheck.healthy is False
] | Given a list of HealthCheckResults return those which are unhealthy. | critical_events_in_outputs | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def generate_summary_for_check(name, ok):
"""Given a check name and a boolean indicating if the service is OK, return
a formatted message.
"""
status = PaastaColors.green("OK") if ok is True else PaastaColors.red("CRITICAL")
summary = f"{name} Status: {status}"
return summary | Given a check name and a boolean indicating if the service is OK, return
a formatted message.
| generate_summary_for_check | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def healthcheck_result_resource_utilization_pair_for_resource_utilization(
utilization, threshold
):
"""Given a ResourceUtilization, produce a tuple of (HealthCheckResult, ResourceUtilization),
where that HealthCheckResult describes the 'health' of a given utilization.
:param utilization: a ResourceUtil... | Given a ResourceUtilization, produce a tuple of (HealthCheckResult, ResourceUtilization),
where that HealthCheckResult describes the 'health' of a given utilization.
:param utilization: a ResourceUtilization tuple
:param threshold: a threshold which decides the health of the given ResourceUtilization
:r... | healthcheck_result_resource_utilization_pair_for_resource_utilization | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def format_table_column_for_healthcheck_resource_utilization_pair(
healthcheck_utilization_pair,
):
"""Given a tuple of (HealthCheckResult, ResourceUtilization), return a
string representation of the ResourceUtilization such that it is formatted
according to the value of HealthCheckResult.healthy.
... | Given a tuple of (HealthCheckResult, ResourceUtilization), return a
string representation of the ResourceUtilization such that it is formatted
according to the value of HealthCheckResult.healthy.
:param healthcheck_utilization_pair: a tuple of (HealthCheckResult, ResourceUtilization)
:returns: a string... | format_table_column_for_healthcheck_resource_utilization_pair | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def format_row_for_resource_utilization_healthchecks(healthcheck_utilization_pairs):
"""Given a list of (HealthCheckResult, ResourceUtilization) tuples, return a list with each of those
tuples represented by a formatted string.
:param healthcheck_utilization_pairs: a list of (HealthCheckResult, ResourceUti... | Given a list of (HealthCheckResult, ResourceUtilization) tuples, return a list with each of those
tuples represented by a formatted string.
:param healthcheck_utilization_pairs: a list of (HealthCheckResult, ResourceUtilization) tuples.
:returns: a list containing a string representation of each (HealthChe... | format_row_for_resource_utilization_healthchecks | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def get_table_rows_for_resource_info_dict(
attribute_values, healthcheck_utilization_pairs
):
"""A wrapper method to join together
:param attribute: The attribute value and formatted columns to be shown in
a single row. :param attribute_value: The value of the attribute
associated with the row. Th... | A wrapper method to join together
:param attribute: The attribute value and formatted columns to be shown in
a single row. :param attribute_value: The value of the attribute
associated with the row. This becomes index 0 in the array returned.
:param healthcheck_utilization_pairs: a list of 2-tuples, w... | get_table_rows_for_resource_info_dict | python | Yelp/paasta | paasta_tools/metrics/metastatus_lib.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/metrics/metastatus_lib.py | Apache-2.0 |
def pool(self):
"""Create thread pool on first request
avoids instantiating unused threadpool for blocking clients.
"""
if self._pool is None:
atexit.register(self.close)
self._pool = ThreadPool(self.pool_threads)
return self._pool | Create thread pool on first request
avoids instantiating unused threadpool for blocking clients.
| pool | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def sanitize_for_serialization(cls, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
If obj is list, sanitize each e... | Builds a JSON POST object.
If obj is None, return None.
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
If obj is list, sanitize each element in the list.
If obj is dict, return th... | sanitize_for_serialization | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def deserialize(self, response, response_type, _check_type):
"""Deserializes response into an object.
:param response: RESTResponse object to be deserialized.
:param response_type: For the response, a tuple containing:
valid classes
a list containing valid classes (for l... | Deserializes response into an object.
:param response: RESTResponse object to be deserialized.
:param response_type: For the response, a tuple containing:
valid classes
a list containing valid classes (for list schemas)
a dict containing a tuple of valid classes as t... | deserialize | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def call_api(
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
query_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
header_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
... | Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter.
:param resource_path: Path to method endpoint.
:param method: Method to call.
:param path_params: Path parameters in the url.
:param query_params: Quer... | call_api | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def request(self, method, url, query_params=None, headers=None,
post_params=None, body=None, _preload_content=True,
_request_timeout=None):
"""Makes the HTTP request using RESTClient."""
if method == "GET":
return self.rest_client.GET(url,
... | Makes the HTTP request using RESTClient. | request | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def parameters_to_tuples(self, params, collection_formats):
"""Get parameters as list of tuples, formatting collections.
:param params: Parameters as dict or list of two-tuples
:param dict collection_formats: Parameter collection formats
:return: Parameters as list of tuples, collection... | Get parameters as list of tuples, formatting collections.
:param params: Parameters as dict or list of two-tuples
:param dict collection_formats: Parameter collection formats
:return: Parameters as list of tuples, collections formatted
| parameters_to_tuples | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def files_parameters(self, files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None):
"""Builds form parameters.
:param files: None or a dict with key=param_name and
value is a list of open file objects
:return: List of tuples of form parameters with file data
... | Builds form parameters.
:param files: None or a dict with key=param_name and
value is a list of open file objects
:return: List of tuples of form parameters with file data
| files_parameters | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def select_header_accept(self, accepts):
"""Returns `Accept` based on an array of accepts provided.
:param accepts: List of headers.
:return: Accept (e.g. application/json).
"""
if not accepts:
return
accepts = [x.lower() for x in accepts]
if 'appli... | Returns `Accept` based on an array of accepts provided.
:param accepts: List of headers.
:return: Accept (e.g. application/json).
| select_header_accept | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def select_header_content_type(self, content_types):
"""Returns `Content-Type` based on an array of content_types provided.
:param content_types: List of content-types.
:return: Content-Type (e.g. application/json).
"""
if not content_types:
return 'application/json'... | Returns `Content-Type` based on an array of content_types provided.
:param content_types: List of content-types.
:return: Content-Type (e.g. application/json).
| select_header_content_type | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def update_params_for_auth(self, headers, querys, auth_settings,
resource_path, method, body):
"""Updates header and query params based on authentication setting.
:param headers: Header parameters dict to be updated.
:param querys: Query parameters tuple list to b... | Updates header and query params based on authentication setting.
:param headers: Header parameters dict to be updated.
:param querys: Query parameters tuple list to be updated.
:param auth_settings: Authentication setting identifiers list.
:param resource_path: A string representation o... | update_params_for_auth | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def __init__(self, settings=None, params_map=None, root_map=None,
headers_map=None, api_client=None, callable=None):
"""Creates an endpoint
Args:
settings (dict): see below key value pairs
'response_type' (tuple/None): response type
'auth' (l... | Creates an endpoint
Args:
settings (dict): see below key value pairs
'response_type' (tuple/None): response type
'auth' (list): a list of auth type keys
'endpoint_path' (str): the endpoint path
'operation_id' (str): endpoint string ide... | __init__ | python | Yelp/paasta | paasta_tools/paastaapi/api_client.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/api_client.py | Apache-2.0 |
def get_default_copy(cls):
"""Return new instance of configuration.
This method returns newly created, based on default constructor,
object of Configuration class or returns a copy of default
configuration passed by the set_default method.
:return: The configuration object.
... | Return new instance of configuration.
This method returns newly created, based on default constructor,
object of Configuration class or returns a copy of default
configuration passed by the set_default method.
:return: The configuration object.
| get_default_copy | python | Yelp/paasta | paasta_tools/paastaapi/configuration.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/configuration.py | Apache-2.0 |
def logger_file(self, value):
"""The logger file.
If the logger_file is None, then add stream handler and remove file
handler. Otherwise, add file handler and remove stream handler.
:param value: The logger_file path.
:type: str
"""
self.__logger_file = value
... | The logger file.
If the logger_file is None, then add stream handler and remove file
handler. Otherwise, add file handler and remove stream handler.
:param value: The logger_file path.
:type: str
| logger_file | python | Yelp/paasta | paasta_tools/paastaapi/configuration.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/configuration.py | Apache-2.0 |
def debug(self, value):
"""Debug status
:param value: The debug status, True or False.
:type: bool
"""
self.__debug = value
if self.__debug:
# if debug status is True, turn on debug logging
for _, logger in self.logger.items():
log... | Debug status
:param value: The debug status, True or False.
:type: bool
| debug | python | Yelp/paasta | paasta_tools/paastaapi/configuration.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/configuration.py | Apache-2.0 |
def logger_format(self, value):
"""The logger format.
The logger_formatter will be updated when sets logger_format.
:param value: The format string.
:type: str
"""
self.__logger_format = value
self.logger_formatter = logging.Formatter(self.__logger_format) | The logger format.
The logger_formatter will be updated when sets logger_format.
:param value: The format string.
:type: str
| logger_format | python | Yelp/paasta | paasta_tools/paastaapi/configuration.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/configuration.py | Apache-2.0 |
def get_api_key_with_prefix(self, identifier, alias=None):
"""Gets API key (with prefix if set).
:param identifier: The identifier of apiKey.
:param alias: The alternative identifier of apiKey.
:return: The token for api key authentication.
"""
if self.refresh_api_key_ho... | Gets API key (with prefix if set).
:param identifier: The identifier of apiKey.
:param alias: The alternative identifier of apiKey.
:return: The token for api key authentication.
| get_api_key_with_prefix | python | Yelp/paasta | paasta_tools/paastaapi/configuration.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/configuration.py | Apache-2.0 |
def get_basic_auth_token(self):
"""Gets HTTP basic authentication header (string).
:return: The token for basic HTTP authentication.
"""
username = ""
if self.username is not None:
username = self.username
password = ""
if self.password is not None:
... | Gets HTTP basic authentication header (string).
:return: The token for basic HTTP authentication.
| get_basic_auth_token | python | Yelp/paasta | paasta_tools/paastaapi/configuration.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/configuration.py | Apache-2.0 |
def to_debug_report(self):
"""Gets the essential information for debugging.
:return: The report for debugging.
"""
return "Python SDK Debug Report:\n"\
"OS: {env}\n"\
"Python Version: {pyversion}\n"\
"Version of the API: 1.2.0\n"\
... | Gets the essential information for debugging.
:return: The report for debugging.
| to_debug_report | python | Yelp/paasta | paasta_tools/paastaapi/configuration.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/configuration.py | Apache-2.0 |
def get_host_settings(self):
"""Gets an array of host settings
:return: An array of host settings
"""
return [
{
'url': "{scheme}://{host}/{basePath}",
'description': "No description provided",
'variables': {
... | Gets an array of host settings
:return: An array of host settings
| get_host_settings | python | Yelp/paasta | paasta_tools/paastaapi/configuration.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/configuration.py | Apache-2.0 |
def get_host_from_settings(self, index, variables=None, servers=None):
"""Gets host URL based on the index and variables
:param index: array index of the host settings
:param variables: hash of variable and the corresponding value
:param servers: an array of host settings or None
... | Gets host URL based on the index and variables
:param index: array index of the host settings
:param variables: hash of variable and the corresponding value
:param servers: an array of host settings or None
:return: URL based on host settings
| get_host_from_settings | python | Yelp/paasta | paasta_tools/paastaapi/configuration.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/configuration.py | Apache-2.0 |
def __init__(self, msg, path_to_item=None):
"""
Args:
msg (str): the exception message
Keyword Args:
path_to_item (list) the path to the exception in the
received_data dict. None if unset
"""
self.path_to_item = path_to_item
full_... |
Args:
msg (str): the exception message
Keyword Args:
path_to_item (list) the path to the exception in the
received_data dict. None if unset
| __init__ | python | Yelp/paasta | paasta_tools/paastaapi/exceptions.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/exceptions.py | Apache-2.0 |
def __init__(self, msg, path_to_item=None):
"""
Raised when an attribute reference or assignment fails.
Args:
msg (str): the exception message
Keyword Args:
path_to_item (None/list) the path to the exception in the
received_data dict
"""
... |
Raised when an attribute reference or assignment fails.
Args:
msg (str): the exception message
Keyword Args:
path_to_item (None/list) the path to the exception in the
received_data dict
| __init__ | python | Yelp/paasta | paasta_tools/paastaapi/exceptions.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/exceptions.py | Apache-2.0 |
def __init__(self, msg, path_to_item=None):
"""
Args:
msg (str): the exception message
Keyword Args:
path_to_item (None/list) the path to the exception in the
received_data dict
"""
self.path_to_item = path_to_item
full_msg = msg
... |
Args:
msg (str): the exception message
Keyword Args:
path_to_item (None/list) the path to the exception in the
received_data dict
| __init__ | python | Yelp/paasta | paasta_tools/paastaapi/exceptions.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/exceptions.py | Apache-2.0 |
def allows_single_value_input(cls):
"""
This function returns True if the input composed schema model or any
descendant model allows a value only input
This is true for cases where oneOf contains items like:
oneOf:
- float
- NumberWithValidation
- StringEnum
- ArrayModel
... |
This function returns True if the input composed schema model or any
descendant model allows a value only input
This is true for cases where oneOf contains items like:
oneOf:
- float
- NumberWithValidation
- StringEnum
- ArrayModel
- null
TODO: lru_cache this
| allows_single_value_input | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def composed_model_input_classes(cls):
"""
This function returns a list of the possible models that can be accepted as
inputs.
TODO: lru_cache this
"""
if issubclass(cls, ModelSimple) or cls in PRIMITIVE_TYPES:
return [cls]
elif issubclass(cls, ModelNormal):
if cls.discrimina... |
This function returns a list of the possible models that can be accepted as
inputs.
TODO: lru_cache this
| composed_model_input_classes | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __setitem__(self, name, value):
"""set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
if name in self.required_properties:
self.__dict__[name] = value
return
self.set_attribute(name, value) | set the value of an attribute using square-bracket notation: `instance[attr] = val` | __setitem__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def get(self, name, default=None):
"""returns the value of an attribute or some default value if the attribute was not set"""
if name in self.required_properties:
return self.__dict__[name]
return self.__dict__['_data_store'].get(name, default) | returns the value of an attribute or some default value if the attribute was not set | get | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __getitem__(self, name):
"""get the value of an attribute using square-bracket notation: `instance[attr]`"""
if name in self:
return self.get(name)
raise ApiAttributeError(
"{0} has no attribute '{1}'".format(
type(self).__name__, name),
[... | get the value of an attribute using square-bracket notation: `instance[attr]` | __getitem__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __contains__(self, name):
"""used by `in` operator to check if an attrbute value was set in an instance: `'attr' in instance`"""
if name in self.required_properties:
return name in self.__dict__
return name in self.__dict__['_data_store'] | used by `in` operator to check if an attrbute value was set in an instance: `'attr' in instance` | __contains__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, self.__class__):
return False
this_val = self._data_store['value']
that_val = other._data_store['value']
types = set()
types.add(this_val.__class__)
types.a... | Returns true if both objects are equal | __eq__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __setitem__(self, name, value):
"""set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
if name in self.required_properties:
self.__dict__[name] = value
return
self.set_attribute(name, value) | set the value of an attribute using square-bracket notation: `instance[attr] = val` | __setitem__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def get(self, name, default=None):
"""returns the value of an attribute or some default value if the attribute was not set"""
if name in self.required_properties:
return self.__dict__[name]
return self.__dict__['_data_store'].get(name, default) | returns the value of an attribute or some default value if the attribute was not set | get | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __getitem__(self, name):
"""get the value of an attribute using square-bracket notation: `instance[attr]`"""
if name in self:
return self.get(name)
raise ApiAttributeError(
"{0} has no attribute '{1}'".format(
type(self).__name__, name),
[... | get the value of an attribute using square-bracket notation: `instance[attr]` | __getitem__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __contains__(self, name):
"""used by `in` operator to check if an attrbute value was set in an instance: `'attr' in instance`"""
if name in self.required_properties:
return name in self.__dict__
return name in self.__dict__['_data_store'] | used by `in` operator to check if an attrbute value was set in an instance: `'attr' in instance` | __contains__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, self.__class__):
return False
if not set(self._data_store.keys()) == set(other._data_store.keys()):
return False
for _var_name, this_val in self._data_store.items():
... | Returns true if both objects are equal | __eq__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __setitem__(self, name, value):
"""set the value of an attribute using square-bracket notation: `instance[attr] = val`"""
if name in self.required_properties:
self.__dict__[name] = value
return
# set the attribute on the correct instance
model_instances = sel... | set the value of an attribute using square-bracket notation: `instance[attr] = val` | __setitem__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def get(self, name, default=None):
"""returns the value of an attribute or some default value if the attribute was not set"""
if name in self.required_properties:
return self.__dict__[name]
# get the attribute from the correct instance
model_instances = self._var_name_to_mod... | returns the value of an attribute or some default value if the attribute was not set | get | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __getitem__(self, name):
"""get the value of an attribute using square-bracket notation: `instance[attr]`"""
value = self.get(name, self.__unset_attribute_value__)
if value is self.__unset_attribute_value__:
raise ApiAttributeError(
"{0} has no attribute '{1}'".fo... | get the value of an attribute using square-bracket notation: `instance[attr]` | __getitem__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __contains__(self, name):
"""used by `in` operator to check if an attrbute value was set in an instance: `'attr' in instance`"""
if name in self.required_properties:
return name in self.__dict__
model_instances = self._var_name_to_model_instances.get(
name, self._ad... | used by `in` operator to check if an attrbute value was set in an instance: `'attr' in instance` | __contains__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, self.__class__):
return False
if not set(self._data_store.keys()) == set(other._data_store.keys()):
return False
for _var_name, this_val in self._data_store.items():
... | Returns true if both objects are equal | __eq__ | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def get_simple_class(input_value):
"""Returns an input_value's simple class that we will use for type checking
Python2:
float and int will return int, where int is the python3 int backport
str and unicode will return str, where str is the python3 str backport
Note: float and int ARE both instances o... | Returns an input_value's simple class that we will use for type checking
Python2:
float and int will return int, where int is the python3 int backport
str and unicode will return str, where str is the python3 str backport
Note: float and int ARE both instances of int backport
Note: str_py2 and unico... | get_simple_class | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def check_allowed_values(allowed_values, input_variable_path, input_values):
"""Raises an exception if the input_values are not allowed
Args:
allowed_values (dict): the allowed_values dict
input_variable_path (tuple): the path to the input variable
input_values (list/str/int/float/date/... | Raises an exception if the input_values are not allowed
Args:
allowed_values (dict): the allowed_values dict
input_variable_path (tuple): the path to the input variable
input_values (list/str/int/float/date/datetime): the values that we
are checking to see if they are in allowed... | check_allowed_values | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def is_json_validation_enabled(schema_keyword, configuration=None):
"""Returns true if JSON schema validation is enabled for the specified
validation keyword. This can be used to skip JSON schema structural validation
as requested in the configuration.
Args:
schema_keyword (string): the name of... | Returns true if JSON schema validation is enabled for the specified
validation keyword. This can be used to skip JSON schema structural validation
as requested in the configuration.
Args:
schema_keyword (string): the name of a JSON schema validation keyword.
configuration (Configuration): t... | is_json_validation_enabled | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def check_validations(
validations, input_variable_path, input_values,
configuration=None):
"""Raises an exception if the input_values are invalid
Args:
validations (dict): the validation dictionary.
input_variable_path (tuple): the path to the input variable.
input_valu... | Raises an exception if the input_values are invalid
Args:
validations (dict): the validation dictionary.
input_variable_path (tuple): the path to the input variable.
input_values (list/str/int/float/date/datetime): the values that we
are checking.
configuration (Configur... | check_validations | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def order_response_types(required_types):
"""Returns the required types sorted in coercion order
Args:
required_types (list/tuple): collection of classes or instance of
list or dict with class information inside it.
Returns:
(list): coercion order sorted collection of classes o... | Returns the required types sorted in coercion order
Args:
required_types (list/tuple): collection of classes or instance of
list or dict with class information inside it.
Returns:
(list): coercion order sorted collection of classes or instance
of list or dict with class... | order_response_types | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
def get_discriminated_classes(cls):
"""
Returns all the classes that a discriminator converts to
TODO: lru_cache this
"""
possible_classes = []
key = list(cls.discriminator.keys())[0]
if is_type_nullable(cls):
possible_classes.append(cls)
for discr_cls in cls.discriminator[key].v... |
Returns all the classes that a discriminator converts to
TODO: lru_cache this
| get_discriminated_classes | python | Yelp/paasta | paasta_tools/paastaapi/model_utils.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/paastaapi/model_utils.py | Apache-2.0 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.