sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
def precheck_ami_id(context): """ Is the AMI in service the same as the AMI marked current in the version records? This tool won't update records unless the world state is coherent. Args: context: a populated EFVersionContext object Returns: True if ok to proceed Raises: RuntimeError if not ok t...
Is the AMI in service the same as the AMI marked current in the version records? This tool won't update records unless the world state is coherent. Args: context: a populated EFVersionContext object Returns: True if ok to proceed Raises: RuntimeError if not ok to proceed
entailment
def precheck_dist_hash(context): """ Is the dist in service the same as the dist marked current in the version records? This tool won't update records unless the world state is coherent. Args: context: a populated EFVersionContext object Returns: True if ok to proceed Raises: RuntimeError if not...
Is the dist in service the same as the dist marked current in the version records? This tool won't update records unless the world state is coherent. Args: context: a populated EFVersionContext object Returns: True if ok to proceed Raises: RuntimeError if not ok to proceed
entailment
def precheck(context): """ calls a function named "precheck_<key>" where <key> is context_key with '-' changed to '_' (e.g. "precheck_ami_id") Checking function should return True if OK, or raise RuntimeError w/ message if not Args: context: a populated EFVersionContext object Returns: True if the p...
calls a function named "precheck_<key>" where <key> is context_key with '-' changed to '_' (e.g. "precheck_ami_id") Checking function should return True if OK, or raise RuntimeError w/ message if not Args: context: a populated EFVersionContext object Returns: True if the precheck passed, or if there was...
entailment
def get_versions(context, return_stable=False): """ Get all versions of a key Args: context: a populated EFVersionContext object return_stable: (default:False) If True, stop fetching if 'stable' version is found; return only that version Returns: json list of object data sorted in reverse by last_mo...
Get all versions of a key Args: context: a populated EFVersionContext object return_stable: (default:False) If True, stop fetching if 'stable' version is found; return only that version Returns: json list of object data sorted in reverse by last_modified (newest version is first). Each item is a dict: ...
entailment
def get_version_by_value(context, value): """ Get the latest version that matches the provided ami-id Args: context: a populated EFVersionContext object value: the value of the version to look for """ versions = get_versions(context) for version in versions: if version.value == value: retu...
Get the latest version that matches the provided ami-id Args: context: a populated EFVersionContext object value: the value of the version to look for
entailment
def cmd_rollback(context): """ Roll back by finding the most recent "stable" tagged version, and putting it again, so that it's the new "current" version. Args: context: a populated EFVersionContext object """ last_stable = get_versions(context, return_stable=True) if len(last_stable) != 1: fail("...
Roll back by finding the most recent "stable" tagged version, and putting it again, so that it's the new "current" version. Args: context: a populated EFVersionContext object
entailment
def cmd_rollback_to(context): """ Roll back by finding a specific version in the history of the service and putting it as the new current version. Args: context: a populated EFVersionContext object """ version = get_version_by_value(context, context.rollback_to) context.value = version.value context...
Roll back by finding a specific version in the history of the service and putting it as the new current version. Args: context: a populated EFVersionContext object
entailment
def cmd_set(context): """ Set the new "current" value for a key. If the existing current version and the new version have identical /value/ and /status, then nothing is written, to avoid stacking up redundant entreis in the version table. Args: context: a populated EFVersionContext object """ # If ke...
Set the new "current" value for a key. If the existing current version and the new version have identical /value/ and /status, then nothing is written, to avoid stacking up redundant entreis in the version table. Args: context: a populated EFVersionContext object
entailment
def to_json(self): """ called by VersionEncoder.default() when doing json.dumps() on the object the json materializes in reverse order from the order used here """ return { "build_number": self._build_number, "commit_hash": self._commit_hash, "last_modified": self._last_modif...
called by VersionEncoder.default() when doing json.dumps() on the object the json materializes in reverse order from the order used here
entailment
def learn(self, steps=1, **kwargs): """ Train the model using the environment and the agent. Note that the model might be shared between multiple agents (which most probably are of the same type) at the same time. :param steps: The number of steps to train for. """ ...
Train the model using the environment and the agent. Note that the model might be shared between multiple agents (which most probably are of the same type) at the same time. :param steps: The number of steps to train for.
entailment
def get_value(self, symbol): """ Hierarchically searches for 'symbol' in the parameters blob if there is one (would have been retrieved by 'load()'). Order is: default, <env_short>, <env> Args: symbol: the key to resolve Returns: Hierarchically resolved value for 'symbol' in the environm...
Hierarchically searches for 'symbol' in the parameters blob if there is one (would have been retrieved by 'load()'). Order is: default, <env_short>, <env> Args: symbol: the key to resolve Returns: Hierarchically resolved value for 'symbol' in the environment set by the constructor, or None...
entailment
def overlay_classification_on_image(classification, rgb_image, scale=1): """ Overlay a classification either 1 channel or 3 channels on an input image. :param classification: The classification tensor of shape [bach_size, v, u, 1] or [batch_size, v, u, 3]. The value range of the c...
Overlay a classification either 1 channel or 3 channels on an input image. :param classification: The classification tensor of shape [bach_size, v, u, 1] or [batch_size, v, u, 3]. The value range of the classification tensor is supposed to be 0 to 1. :param rgb_image: The input image ...
entailment
def inflate_to_one_hot(tensor, classes): """ Converts a tensor with index form to a one hot tensor. :param tensor: A tensor of shape [batch, h, w, 1] :param classes: The number of classes that exist. (length of one hot encoding) :return: A tensor of shape [batch, h, w, classes]. """ one_hot ...
Converts a tensor with index form to a one hot tensor. :param tensor: A tensor of shape [batch, h, w, 1] :param classes: The number of classes that exist. (length of one hot encoding) :return: A tensor of shape [batch, h, w, classes].
entailment
def accountaliasofenv(self, lookup, default=None): """ Args: lookup: ENV_SHORT name of an env, such as: 'prod' or 'proto' default: the optional value to return if lookup failed; returns None if not set Returns: The account alias of the account that hosts the env named in lookupor default/N...
Args: lookup: ENV_SHORT name of an env, such as: 'prod' or 'proto' default: the optional value to return if lookup failed; returns None if not set Returns: The account alias of the account that hosts the env named in lookupor default/None if no match found
entailment
def customdata(self, lookup, default=None): """ Args: lookup: the custom data file default: the optional value to return if lookup failed; returns None if not set Returns: The custom data returned from the file 'lookup' or default/None if no match found """ try: if lookup in ...
Args: lookup: the custom data file default: the optional value to return if lookup failed; returns None if not set Returns: The custom data returned from the file 'lookup' or default/None if no match found
entailment
def fail(message, exception_data=None): """ Print a failure message and exit nonzero """ print(message, file=sys.stderr) if exception_data: print(repr(exception_data)) sys.exit(1)
Print a failure message and exit nonzero
entailment
def http_get_metadata(metadata_path, timeout=__HTTP_DEFAULT_TIMEOUT_SEC): """ Fetch AWS metadata from http://169.254.169.254/latest/meta-data/<metadata_path> ARGS: metadata_path - the optional path and required key to the EC2 metadata (e.g. "instance-id") RETURN: response content on success RAISE: ...
Fetch AWS metadata from http://169.254.169.254/latest/meta-data/<metadata_path> ARGS: metadata_path - the optional path and required key to the EC2 metadata (e.g. "instance-id") RETURN: response content on success RAISE: URLError if there was a problem reading metadata
entailment
def is_in_virtualbox(): """ Is the current environment a virtualbox instance? Returns a boolean Raises IOError if the necessary tooling isn't available """ if not isfile(__VIRT_WHAT) or not access(__VIRT_WHAT, X_OK): raise IOError("virt-what not available") try: return subprocess.check_output(["su...
Is the current environment a virtualbox instance? Returns a boolean Raises IOError if the necessary tooling isn't available
entailment
def whereami(): """ Determine if this is an ec2 instance or "running locally" Returns: "ec2" - this is an ec2 instance "virtualbox-kvm" - kernel VM (virtualbox with vagrant) "local" - running locally and not in a known VM "unknown" - I have no idea where I am """ # If the metadata endpoint res...
Determine if this is an ec2 instance or "running locally" Returns: "ec2" - this is an ec2 instance "virtualbox-kvm" - kernel VM (virtualbox with vagrant) "local" - running locally and not in a known VM "unknown" - I have no idea where I am
entailment
def http_get_instance_env(): """ Returns: just the env this ec2 instance is in. Doesn't require API access like get_instance_aws_context does Example return value: "staging" """ try: info = json.loads(http_get_metadata('iam/info')) except Exception as error: raise IOError("Error looking up metadata:...
Returns: just the env this ec2 instance is in. Doesn't require API access like get_instance_aws_context does Example return value: "staging"
entailment
def get_instance_aws_context(ec2_client): """ Returns: a dictionary of aws context dictionary will contain these entries: region, instance_id, account, role, env, env_short, service Raises: IOError if couldn't read metadata or lookup attempt failed """ result = {} try: result["region"] = http_ge...
Returns: a dictionary of aws context dictionary will contain these entries: region, instance_id, account, role, env, env_short, service Raises: IOError if couldn't read metadata or lookup attempt failed
entailment
def pull_repo(): """ Pulls latest version of EF_REPO_BRANCH from EF_REPO (as set in ef_config.py) if client is in EF_REPO and on the branch EF_REPO_BRANCH Raises: RuntimeError with message if not in the correct repo on the correct branch """ try: current_repo = subprocess.check_output(["git", "remot...
Pulls latest version of EF_REPO_BRANCH from EF_REPO (as set in ef_config.py) if client is in EF_REPO and on the branch EF_REPO_BRANCH Raises: RuntimeError with message if not in the correct repo on the correct branch
entailment
def create_aws_clients(region, profile, *clients): """ Create boto3 clients for one or more AWS services. These are the services used within the libs: cloudformation, cloudfront, ec2, iam, lambda, route53, waf Args: region: the region in which to create clients that are region-specific (all but IAM) p...
Create boto3 clients for one or more AWS services. These are the services used within the libs: cloudformation, cloudfront, ec2, iam, lambda, route53, waf Args: region: the region in which to create clients that are region-specific (all but IAM) profile: Name of profile (in .aws/credentials). Pass the val...
entailment
def get_account_alias(env): """ Given an env, return <account_alias> if env is valid Args: env: an environment, such as "prod", "staging", "proto<N>", "mgmt.<account_alias>" Returns: the alias of the AWS account that holds the env Raises: ValueError if env is misformatted or doesn't name a known e...
Given an env, return <account_alias> if env is valid Args: env: an environment, such as "prod", "staging", "proto<N>", "mgmt.<account_alias>" Returns: the alias of the AWS account that holds the env Raises: ValueError if env is misformatted or doesn't name a known environment
entailment
def get_env_short(env): """ Given an env, return <env_short> if env is valid Args: env: an environment, such as "prod", "staging", "proto<N>", "mgmt.<account_alias>" Returns: the shortname of the env, such as "prod", "staging", "proto", "mgmt" Raises: ValueError if env is misformatted or doesn't n...
Given an env, return <env_short> if env is valid Args: env: an environment, such as "prod", "staging", "proto<N>", "mgmt.<account_alias>" Returns: the shortname of the env, such as "prod", "staging", "proto", "mgmt" Raises: ValueError if env is misformatted or doesn't name a known environment
entailment
def env_valid(env): """ Given an env, determine if it's valid Args: env: the env to check Returns: True if the env is valid Raises: ValueError with message if the env is not valid """ if env not in EFConfig.ENV_LIST: raise ValueError("unknown env: {}; env must be one of: ".format(env) + ",...
Given an env, determine if it's valid Args: env: the env to check Returns: True if the env is valid Raises: ValueError with message if the env is not valid
entailment
def global_env_valid(env): """ Given an env, determine if it's a valid "global" or "mgmt" env as listed in EFConfig Args: env: the env to check Returns: True if the env is a valid global env in EFConfig Raises: ValueError with message if the env is not valid """ if env not in EFConfig.ACCOUNT_...
Given an env, determine if it's a valid "global" or "mgmt" env as listed in EFConfig Args: env: the env to check Returns: True if the env is a valid global env in EFConfig Raises: ValueError with message if the env is not valid
entailment
def kms_encrypt(kms_client, service, env, secret): """ Encrypt string for use by a given service/environment Args: kms_client (boto3 kms client object): Instantiated kms client object. Usually created through create_aws_clients. service (string): name of the service that the secret is being encrypted for....
Encrypt string for use by a given service/environment Args: kms_client (boto3 kms client object): Instantiated kms client object. Usually created through create_aws_clients. service (string): name of the service that the secret is being encrypted for. env (string): environment that the secret is being enc...
entailment
def kms_decrypt(kms_client, secret): """ Decrypt kms-encrypted string Args: kms_client (boto3 kms client object): Instantiated kms client object. Usually created through create_aws_clients. secret (string): base64 encoded value to be decrypted Returns: a populated EFPWContext object Raises: Sy...
Decrypt kms-encrypted string Args: kms_client (boto3 kms client object): Instantiated kms client object. Usually created through create_aws_clients. secret (string): base64 encoded value to be decrypted Returns: a populated EFPWContext object Raises: SystemExit(1): If there is an error with the bo...
entailment
def kms_key_arn(kms_client, alias): """ Obtain the full key arn based on the key alias provided Args: kms_client (boto3 kms client object): Instantiated kms client object. Usually created through create_aws_clients. alias (string): alias of key, example alias/proto0-evs-drm. Returns: string of the ...
Obtain the full key arn based on the key alias provided Args: kms_client (boto3 kms client object): Instantiated kms client object. Usually created through create_aws_clients. alias (string): alias of key, example alias/proto0-evs-drm. Returns: string of the full key arn
entailment
def get_template_parameters_file(template_full_path): """ Checks for existance of parameters file against supported suffixes and returns parameters file path if found Args: template_full_path: full filepath for template file Returns: filename of parameters file if it exists """ for s...
Checks for existance of parameters file against supported suffixes and returns parameters file path if found Args: template_full_path: full filepath for template file Returns: filename of parameters file if it exists
entailment
def get_template_parameters_s3(template_key, s3_resource): """ Checks for existance of parameters object in S3 against supported suffixes and returns parameters file key if found Args: template_key: S3 key for template file. omit bucket. s3_resource: a boto3 s3 resource Returns: filename of paramete...
Checks for existance of parameters object in S3 against supported suffixes and returns parameters file key if found Args: template_key: S3 key for template file. omit bucket. s3_resource: a boto3 s3 resource Returns: filename of parameters file if it exists
entailment
def get_autoscaling_group_properties(asg_client, env, service): """ Gets the autoscaling group properties based on the service name that is provided. This function will attempt the find the autoscaling group base on the following logic: 1. If the service name provided matches the autoscaling group name 2....
Gets the autoscaling group properties based on the service name that is provided. This function will attempt the find the autoscaling group base on the following logic: 1. If the service name provided matches the autoscaling group name 2. If the service name provided matches the Name tag of the autoscaling gr...
entailment
def get_default_config(gpu_memory_usage=0.75, allow_growth=False): """ A helper to create sessions easily. :param gpu_memory_usage: How much of the gpu should be used for your project. :param allow_growth: If you want to have a fixed gpus size or if it should grow and use just as much as it needs. :...
A helper to create sessions easily. :param gpu_memory_usage: How much of the gpu should be used for your project. :param allow_growth: If you want to have a fixed gpus size or if it should grow and use just as much as it needs. :return: A configuration you can pass to your session when creating it.
entailment
def export_graph(checkpoint_path, output_nodes): """ Export a graph stored in a checkpoint as a *.pb file. :param checkpoint_path: The checkpoint path which should be frozen. :param output_nodes: The output nodes you care about as a list of strings (their names). :return: """ if not tf.gfile...
Export a graph stored in a checkpoint as a *.pb file. :param checkpoint_path: The checkpoint path which should be frozen. :param output_nodes: The output nodes you care about as a list of strings (their names). :return:
entailment
def load_graph(frozen_graph_filename, namespace_prefix="", placeholders=None): """ Loads a frozen graph from a *.pb file. :param frozen_graph_filename: The file which graph to load. :param namespace_prefix: A namespace for your graph to live in. This is useful when having multiple models. :param pla...
Loads a frozen graph from a *.pb file. :param frozen_graph_filename: The file which graph to load. :param namespace_prefix: A namespace for your graph to live in. This is useful when having multiple models. :param placeholders: A dict containing the new placeholders that replace the old inputs. :return:...
entailment
def _elbv2_load_balancer(self, lookup): """ Args: lookup: the friendly name of the V2 elb to look up Returns: A dict with the load balancer description Raises: botocore.exceptions.ClientError: no such load-balancer """ client = EFAwsResolver.__CLIENTS['elbv2'] elbs = client...
Args: lookup: the friendly name of the V2 elb to look up Returns: A dict with the load balancer description Raises: botocore.exceptions.ClientError: no such load-balancer
entailment
def acm_certificate_arn(self, lookup, default=None): """ Args: lookup: region/domain on the certificate to be looked up default: the optional value to return if lookup failed; returns None if not set Returns: ARN of a certificate with status "Issued" for the region/domain, if found, or def...
Args: lookup: region/domain on the certificate to be looked up default: the optional value to return if lookup failed; returns None if not set Returns: ARN of a certificate with status "Issued" for the region/domain, if found, or default/None if no match If more than one "Issued" certificate...
entailment
def ec2_elasticip_elasticip_id(self, lookup, default=None): """ Args: lookup: the CloudFormation resource name of the Elastic IP ID to look up default: the optional value to return if lookup failed; returns None if not set Returns: The ID of the first Elastic IP found with a description ma...
Args: lookup: the CloudFormation resource name of the Elastic IP ID to look up default: the optional value to return if lookup failed; returns None if not set Returns: The ID of the first Elastic IP found with a description matching 'lookup' or default/None if no match found
entailment
def ec2_elasticip_elasticip_ipaddress(self, lookup, default=None): """ Args: lookup: the CloudFormation resource name of the Elastic IP address to look up default: the optional value to return if lookup failed; returns None if not set Returns: The IP address of the first Elastic IP found w...
Args: lookup: the CloudFormation resource name of the Elastic IP address to look up default: the optional value to return if lookup failed; returns None if not set Returns: The IP address of the first Elastic IP found with a description matching 'lookup' or default/None if no match
entailment
def ec2_eni_eni_id(self, lookup, default=None): """ Args: lookup: the description of the Elastic Network Interface (ENI) to look up default: the optional value to return if lookup failed; returns None if not set Returns: The ID of the first ENI found with a description matching 'lookup' or...
Args: lookup: the description of the Elastic Network Interface (ENI) to look up default: the optional value to return if lookup failed; returns None if not set Returns: The ID of the first ENI found with a description matching 'lookup' or default/None if no match found
entailment
def ec2_network_network_acl_id(self, lookup, default=None): """ Args: lookup: the friendly name of the network ACL we are looking up default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the network ACL, or None if no match found """ net...
Args: lookup: the friendly name of the network ACL we are looking up default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the network ACL, or None if no match found
entailment
def ec2_security_group_security_group_id(self, lookup, default=None): """ Args: lookup: the friendly name of a security group to look up default: the optional value to return if lookup failed; returns None if not set Returns: Security group ID if target found or default/None if no match ...
Args: lookup: the friendly name of a security group to look up default: the optional value to return if lookup failed; returns None if not set Returns: Security group ID if target found or default/None if no match
entailment
def ec2_subnet_subnet_id(self, lookup, default=None): """ Return: the ID of a single subnet or default/None if no match Args: lookup: the friendly name of the subnet to look up (subnet-<env>-a or subnet-<env>-b) default: the optional value to return if lookup failed; returns None if not se...
Return: the ID of a single subnet or default/None if no match Args: lookup: the friendly name of the subnet to look up (subnet-<env>-a or subnet-<env>-b) default: the optional value to return if lookup failed; returns None if not set
entailment
def ec2_vpc_availabilityzones(self, lookup, default=None): """ Args: lookup: the friendly name of a VPC to look up default: the optional value to return if lookup failed; returns None if not set Returns: A comma-separated list of availability zones in use in the named VPC or default/None i...
Args: lookup: the friendly name of a VPC to look up default: the optional value to return if lookup failed; returns None if not set Returns: A comma-separated list of availability zones in use in the named VPC or default/None if no match
entailment
def ec2_vpc_subnets(self, lookup, default=None): """ Args: lookup - the friendly name of the VPC whose subnets we want Returns: A comma-separated list of all subnets in use in the named VPC or default/None if no match found """ vpc_id = self.ec2_vpc_vpc_id(lookup) if vpc_id is None: ...
Args: lookup - the friendly name of the VPC whose subnets we want Returns: A comma-separated list of all subnets in use in the named VPC or default/None if no match found
entailment
def ec2_vpc_cidrblock(self, lookup, default=None): """ Args: lookup - the friendly name of the VPC whose CIDR block we want Returns: The CIDR block of the named VPC, or default/None if no match found """ vpcs = EFAwsResolver.__CLIENTS["ec2"].describe_vpcs(Filters=[{ 'Name': 'tag:Na...
Args: lookup - the friendly name of the VPC whose CIDR block we want Returns: The CIDR block of the named VPC, or default/None if no match found
entailment
def elbv2_load_balancer_hosted_zone(self, lookup, default=None): """ Args: lookup: the friendly name of the V2 elb to look up default: value to return in case of no match Returns: The hosted zone ID of the ELB found with a name matching 'lookup'. """ try: elb = self._elbv2_lo...
Args: lookup: the friendly name of the V2 elb to look up default: value to return in case of no match Returns: The hosted zone ID of the ELB found with a name matching 'lookup'.
entailment
def elbv2_load_balancer_dns_name(self, lookup, default=None): """ Args: lookup: the friendly name of the V2 elb to look up default: value to return in case of no match Returns: The hosted zone ID of the ELB found with a name matching 'lookup'. """ try: elb = self._elbv2_load_...
Args: lookup: the friendly name of the V2 elb to look up default: value to return in case of no match Returns: The hosted zone ID of the ELB found with a name matching 'lookup'.
entailment
def elbv2_load_balancer_arn_suffix(self, lookup, default=None): """ Args: lookup: the friendly name of the v2 elb to look up default: value to return in case of no match Returns: The shorthand fragment of the ALB's ARN, of the form `app/*/*` """ try: elb = self._elbv2_load_ba...
Args: lookup: the friendly name of the v2 elb to look up default: value to return in case of no match Returns: The shorthand fragment of the ALB's ARN, of the form `app/*/*`
entailment
def elbv2_target_group_arn_suffix(self, lookup, default=None): """ Args: lookup: the friendly name of the v2 elb target group default: value to return in case of no match Returns: The shorthand fragment of the target group's ARN, of the form `targetgroup/*/*` """ try: c...
Args: lookup: the friendly name of the v2 elb target group default: value to return in case of no match Returns: The shorthand fragment of the target group's ARN, of the form `targetgroup/*/*`
entailment
def waf_rule_id(self, lookup, default=None): """ Args: lookup: the friendly name of a WAF rule default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the WAF rule whose name matches 'lookup' or default/None if no match found """ # list_ru...
Args: lookup: the friendly name of a WAF rule default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the WAF rule whose name matches 'lookup' or default/None if no match found
entailment
def waf_web_acl_id(self, lookup, default=None): """ Args: lookup: the friendly name of a Web ACL default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the WAF Web ACL whose name matches rule_name or default/None if no match found """ # l...
Args: lookup: the friendly name of a Web ACL default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the WAF Web ACL whose name matches rule_name or default/None if no match found
entailment
def route53_public_hosted_zone_id(self, lookup, default=None): """ Args: lookup: The zone name to look up. Must end with "." default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the public hosted zone for the 'lookup' domain, or default/None if...
Args: lookup: The zone name to look up. Must end with "." default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the public hosted zone for the 'lookup' domain, or default/None if no match found
entailment
def ec2_route_table_main_route_table_id(self, lookup, default=None): """ Args: lookup: the friendly name of the VPC whose main route table we are looking up default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the main route table of the named ...
Args: lookup: the friendly name of the VPC whose main route table we are looking up default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the main route table of the named VPC, or default if no match/multiple matches found
entailment
def ec2_route_table_tagged_route_table_id(self, lookup, default=None): """ Args: lookup: the tagged route table name, should be unique default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the route table, or default if no match/multiple matches...
Args: lookup: the tagged route table name, should be unique default: the optional value to return if lookup failed; returns None if not set Returns: the ID of the route table, or default if no match/multiple matches found
entailment
def cloudfront_domain_name(self, lookup, default=None): """ Args: lookup: any CNAME on the Cloudfront distribution default: the optional value to return if lookup failed; returns None if not set Returns: The domain name (FQDN) of the Cloudfront distrinbution, or default/None if no match ...
Args: lookup: any CNAME on the Cloudfront distribution default: the optional value to return if lookup failed; returns None if not set Returns: The domain name (FQDN) of the Cloudfront distrinbution, or default/None if no match
entailment
def cloudfront_origin_access_identity_oai_canonical_user_id(self, lookup, default=None): """ Args: lookup: the FQDN of the Origin Access Identity (from its comments) default: the optional value to return if lookup failed; returns None if not set Returns: the S3 Canonical User ID of the OAI...
Args: lookup: the FQDN of the Origin Access Identity (from its comments) default: the optional value to return if lookup failed; returns None if not set Returns: the S3 Canonical User ID of the OAI associated with the named FQDN in 'lookup', or default/None if no match
entailment
def cognito_identity_identity_pool_arn(self, lookup, default=None): """ Args: lookup: Cognito Federated Identity name, proto0-cms-identity-pool default: the optional value to return if lookup failed; returns None if not set Returns: the constructed ARN for the cognito identity pool,...
Args: lookup: Cognito Federated Identity name, proto0-cms-identity-pool default: the optional value to return if lookup failed; returns None if not set Returns: the constructed ARN for the cognito identity pool, else default/None
entailment
def cognito_identity_identity_pool_id(self, lookup, default=None): """ Args: lookup: Cognito Federated Identity name, proto0-cms-identity-pool default: the optional value to return if lookup failed; returns None if not set Returns: the Cognito Identity Pool ID corresponding to the g...
Args: lookup: Cognito Federated Identity name, proto0-cms-identity-pool default: the optional value to return if lookup failed; returns None if not set Returns: the Cognito Identity Pool ID corresponding to the given lookup, else default/None
entailment
def cognito_idp_user_pool_arn(self, lookup, default=None): """ Args: lookup: Cognito User Pool name, proto0-cms-user-pool default: the optional value to return if lookup failed; returns None if not set Returns: the User Pool ARN corresponding to the given lookup, else default/None ...
Args: lookup: Cognito User Pool name, proto0-cms-user-pool default: the optional value to return if lookup failed; returns None if not set Returns: the User Pool ARN corresponding to the given lookup, else default/None
entailment
def kms_decrypt_value(self, lookup): """ Args: lookup: the encrypted value to be decrypted by KMS; base64 encoded Returns: The decrypted lookup value """ decrypted_lookup = ef_utils.kms_decrypt(EFAwsResolver.__CLIENTS["kms"], lookup) return decrypted_lookup
Args: lookup: the encrypted value to be decrypted by KMS; base64 encoded Returns: The decrypted lookup value
entailment
def kms_key_arn(self, lookup): """ Args: lookup: The key alias, EX: alias/proto0-evs-drm Returns: The full key arn """ key_arn = ef_utils.kms_key_arn(EFAwsResolver.__CLIENTS["kms"], lookup) return key_arn
Args: lookup: The key alias, EX: alias/proto0-evs-drm Returns: The full key arn
entailment
def handle_args_and_set_context(args): """ Args: args: the command line args, probably passed from main() as sys.argv[1:] Returns: a populated EFContext object Raises: IOError: if service registry file can't be found or can't be opened RuntimeError: if repo or branch isn't as spec'd in ef_config...
Args: args: the command line args, probably passed from main() as sys.argv[1:] Returns: a populated EFContext object Raises: IOError: if service registry file can't be found or can't be opened RuntimeError: if repo or branch isn't as spec'd in ef_config.EF_REPO and ef_config.EF_REPO_BRANCH Calle...
entailment
def conditionally_create_security_groups(env, service_name, service_type): """ Create security groups as needed; name and number created depend on service_type Args: env: the environment the SG will be created in service_name: name of the service in service registry service_type: service registry serv...
Create security groups as needed; name and number created depend on service_type Args: env: the environment the SG will be created in service_name: name of the service in service registry service_type: service registry service type: 'aws_ec2', 'aws_lambda', 'aws_security_group', or 'http_service'
entailment
def conditionally_create_role(role_name, sr_entry): """ Create role_name if a role by that name does not already exist; attach a custom list of Principals to its AssumeRolePolicy Args: role_name: the name for the role to create sr_entry: service registry entry Example of a (complex) AssumeRole policy...
Create role_name if a role by that name does not already exist; attach a custom list of Principals to its AssumeRolePolicy Args: role_name: the name for the role to create sr_entry: service registry entry Example of a (complex) AssumeRole policy document comprised of two IAM entities and a service: { ...
entailment
def conditionally_create_profile(role_name, service_type): """ Check that there is a 1:1 correspondence with an InstanceProfile having the same name as the role, and that the role is contained in it. Create InstanceProfile and attach to role if needed. """ # make instance profile if this service_type gets an ...
Check that there is a 1:1 correspondence with an InstanceProfile having the same name as the role, and that the role is contained in it. Create InstanceProfile and attach to role if needed.
entailment
def conditionally_attach_managed_policies(role_name, sr_entry): """ If 'aws_managed_policies' key lists the names of AWS managed policies to bind to the role, attach them to the role Args: role_name: name of the role to attach the policies to sr_entry: service registry entry """ service_type = sr_en...
If 'aws_managed_policies' key lists the names of AWS managed policies to bind to the role, attach them to the role Args: role_name: name of the role to attach the policies to sr_entry: service registry entry
entailment
def conditionally_inline_policies(role_name, sr_entry): """ If 'policies' key lists the filename prefixes of policies to bind to the role, load them from the expected path and inline them onto the role Args: role_name: name of the role to attach the policies to sr_entry: service registry entry """ s...
If 'policies' key lists the filename prefixes of policies to bind to the role, load them from the expected path and inline them onto the role Args: role_name: name of the role to attach the policies to sr_entry: service registry entry
entailment
def conditionally_create_kms_key(role_name, service_type): """ Create KMS Master Key for encryption/decryption of sensitive values in cf templates and latebind configs Args: role_name: name of the role that kms key is being created for; it will be given decrypt privileges. service_type: service regist...
Create KMS Master Key for encryption/decryption of sensitive values in cf templates and latebind configs Args: role_name: name of the role that kms key is being created for; it will be given decrypt privileges. service_type: service registry service type: 'aws_ec2', 'aws_fixture', 'aws_lambda', or 'http_s...
entailment
def sum_abs_distance(labels, preds): """ Compute the sum of abs distances. :param labels: A float tensor of shape [batch_size, ..., X] representing the labels. :param preds: A float tensor of shape [batch_size, ..., X] representing the predictions. :return: A float tensor of shape [batch_size, ...]...
Compute the sum of abs distances. :param labels: A float tensor of shape [batch_size, ..., X] representing the labels. :param preds: A float tensor of shape [batch_size, ..., X] representing the predictions. :return: A float tensor of shape [batch_size, ...] representing the summed absolute distance.
entailment
def l1_distance(labels, preds): """ Compute the l1_distance. :param labels: A float tensor of shape [batch_size, ..., X] representing the labels. :param preds: A float tensor of shape [batch_size, ..., X] representing the predictions. :return: A float tensor of shape [batch_size, ...] representing ...
Compute the l1_distance. :param labels: A float tensor of shape [batch_size, ..., X] representing the labels. :param preds: A float tensor of shape [batch_size, ..., X] representing the predictions. :return: A float tensor of shape [batch_size, ...] representing the l1 distance.
entailment
def smooth_l1_distance(labels, preds, delta=1.0): """ Compute the smooth l1_distance. :param labels: A float tensor of shape [batch_size, ..., X] representing the labels. :param preds: A float tensor of shape [batch_size, ..., X] representing the predictions. :param delta: `float`, the point where ...
Compute the smooth l1_distance. :param labels: A float tensor of shape [batch_size, ..., X] representing the labels. :param preds: A float tensor of shape [batch_size, ..., X] representing the predictions. :param delta: `float`, the point where the huber loss function changes from a quadratic to linear. ...
entailment
def l2_distance(labels, preds): """ Compute the l2_distance. :param labels: A float tensor of shape [batch_size, ..., X] representing the labels. :param preds: A float tensor of shape [batch_size, ..., X] representing the predictions. :return: A float tensor of shape [batch_size, ...] representing ...
Compute the l2_distance. :param labels: A float tensor of shape [batch_size, ..., X] representing the labels. :param preds: A float tensor of shape [batch_size, ..., X] representing the predictions. :return: A float tensor of shape [batch_size, ...] representing the l2 distance.
entailment
def cross_entropy(labels, logits): """ Calculate the cross_entropy. :param labels: A float tensor of shape [batch_size, ..., num_classes] representing the label class probabilities. :param logits: A float tensor of shape [batch_size, ..., num_classes] representing the logits. :return: A tensor repr...
Calculate the cross_entropy. :param labels: A float tensor of shape [batch_size, ..., num_classes] representing the label class probabilities. :param logits: A float tensor of shape [batch_size, ..., num_classes] representing the logits. :return: A tensor representing the cross entropy.
entailment
def handle_args_and_set_context(args): """ Args: args: the command line args, probably passed from main() as sys.argv[1:] Returns: a populated EFCFContext object (extends EFContext) Raises: IOError: if service registry file can't be found or can't be opened RuntimeError: if repo or branch isn't ...
Args: args: the command line args, probably passed from main() as sys.argv[1:] Returns: a populated EFCFContext object (extends EFContext) Raises: IOError: if service registry file can't be found or can't be opened RuntimeError: if repo or branch isn't as spec'd in ef_config.EF_REPO and ef_config.EF...
entailment
def merge_files(service, skip_on_user_group_error=False): """ Given a prefix, find all templates below; merge with parameters; write to "dest" Args: service: "<service>", "all", or "ssh" skip_on_user_group_error: True or False For S3, full path becomes: s3://ellation-cx-global-configs/<service>/tem...
Given a prefix, find all templates below; merge with parameters; write to "dest" Args: service: "<service>", "all", or "ssh" skip_on_user_group_error: True or False For S3, full path becomes: s3://ellation-cx-global-configs/<service>/templates/<filename> s3://ellation-cx-global-configs/<service>/pa...
entailment
def get_metadata_or_fail(metadata_key): """ Call get_metadata; halt with fail() if it raises an exception """ try: return http_get_metadata(metadata_key) except IOError as error: fail("Exception in http_get_metadata {} {}".format(metadata_key, repr(error)))
Call get_metadata; halt with fail() if it raises an exception
entailment
def load(self, template, parameters=None): """ 'template' Loads template text from a 'string' or 'file' type Template text contains {{TOKEN}} symbols to be replaced 'parameters' parameters contains environment-specific sections as discussed in the class documentation. the 'parameters' arg c...
'template' Loads template text from a 'string' or 'file' type Template text contains {{TOKEN}} symbols to be replaced 'parameters' parameters contains environment-specific sections as discussed in the class documentation. the 'parameters' arg can be None, a 'string', 'file', or 'dictionary' Wh...
entailment
def search_parameters(self, symbol): """ Hierarchically searches for 'symbol' in the parameters blob if there is one (would have been retrieved by 'load()'). Order is: default, <env_short>, <env> Returns Hierarchically resolved value for 'symbol', or None if a match is not found or there are no pa...
Hierarchically searches for 'symbol' in the parameters blob if there is one (would have been retrieved by 'load()'). Order is: default, <env_short>, <env> Returns Hierarchically resolved value for 'symbol', or None if a match is not found or there are no parameters
entailment
def render(self): """ Find {{}} tokens; resolve then replace them as described elsewhere Resolution is multi-pass: tokens may be nested to form parts of other tokens. Token search steps when resolving symbols - 1. lookups of AWS resource identifiers, such as a security group ID - 2. secure ...
Find {{}} tokens; resolve then replace them as described elsewhere Resolution is multi-pass: tokens may be nested to form parts of other tokens. Token search steps when resolving symbols - 1. lookups of AWS resource identifiers, such as a security group ID - 2. secure credentials - 3. version...
entailment
def count_braces(self): """ returns a count of "{{" and "}}" in the template, as (N_left_braces, N_right_braces) Useful to check after resolve() has run, to infer that template has an error since no {{ or }} should be present in the template after resolve() """ n_left = len(re.findall("{{", self...
returns a count of "{{" and "}}" in the template, as (N_left_braces, N_right_braces) Useful to check after resolve() has run, to infer that template has an error since no {{ or }} should be present in the template after resolve()
entailment
def resolved_ok(self): """ Shortcut to testing unresolved_symbols and count_braces separately. Returns false if there are unresolved symbols or {{ or }} braces remaining, true otherwise """ left_braces, right_braces = self.count_braces() return len(self.unresolved_symbols()) == left_braces == ri...
Shortcut to testing unresolved_symbols and count_braces separately. Returns false if there are unresolved symbols or {{ or }} braces remaining, true otherwise
entailment
def handle_args_and_set_context(args): """ Args: args: the command line args, probably passed from main() as sys.argv[1:] Returns: a populated Context object based on CLI args """ parser = argparse.ArgumentParser() parser.add_argument("env", help="environment") parser.add_argument("path_to_templat...
Args: args: the command line args, probably passed from main() as sys.argv[1:] Returns: a populated Context object based on CLI args
entailment
def merge_files(context): """ Given a context containing path to template, env, and service: merge config into template and output the result to stdout Args: context: a populated context object """ resolver = EFTemplateResolver( profile=context.profile, region=context.region, env=conte...
Given a context containing path to template, env, and service: merge config into template and output the result to stdout Args: context: a populated context object
entailment
def handle_args(args): """ Handle command line arguments Raises: Exception if the config path wasn't explicitly state and dead reckoning based on script location fails """ parser = argparse.ArgumentParser() parser.add_argument("configpath", default=None, nargs="?", help="/path/to/c...
Handle command line arguments Raises: Exception if the config path wasn't explicitly state and dead reckoning based on script location fails
entailment
def load_json(json_filespec): """ Loads JSON from a config file Args: json_filespec: path/to/file.json Returns: a dict made from the JSON read, if successful Raises: IOError if the file could not be opened ValueError if the JSON could not be read successfully RuntimeError if something else...
Loads JSON from a config file Args: json_filespec: path/to/file.json Returns: a dict made from the JSON read, if successful Raises: IOError if the file could not be opened ValueError if the JSON could not be read successfully RuntimeError if something else went wrong
entailment
def lookup(self, token): """ Return key version if found, None otherwise Lookup should look like this: pattern: <key>,<env>/<service> example: ami-id,staging/core """ # get search key and env/service from token try: key, envservice = token.split(",") except Valu...
Return key version if found, None otherwise Lookup should look like this: pattern: <key>,<env>/<service> example: ami-id,staging/core
entailment
def alert_policy_exists(self, policy_name): """Check to see if an alert policy exists in NewRelic. Return True if so, False if not""" if next((policy for policy in self.all_alerts if policy['name'] == policy_name), False): return True
Check to see if an alert policy exists in NewRelic. Return True if so, False if not
entailment
def create_alert_policy(self, policy_name): """Creates an alert policy in NewRelic""" policy_data = { 'policy': { 'incident_preference': 'PER_POLICY', 'name': policy_name } } create_policy = requests.post( 'https://api.newrelic.com/v2/alerts_policies.json', headers=self.auth_header, data=j...
Creates an alert policy in NewRelic
entailment
def element_href(name): """ Get specified element href by element name :param name: name of element :return: string href location of object, else None """ if name: element = fetch_meta_by_name(name) if element.href: return element.href
Get specified element href by element name :param name: name of element :return: string href location of object, else None
entailment
def element_as_json(name): """ Get specified element json data by name :param name: name of element :return: json data representing element, else None """ if name: element = fetch_json_by_name(name) if element.json: return element.json
Get specified element json data by name :param name: name of element :return: json data representing element, else None
entailment
def element_as_json_with_filter(name, _filter): """ Get specified element json data by name with filter. Filter can be any valid element type. :param name: name of element :param _filter: element filter, host, network, tcp_service, network_elements, services, services_and_applic...
Get specified element json data by name with filter. Filter can be any valid element type. :param name: name of element :param _filter: element filter, host, network, tcp_service, network_elements, services, services_and_applications, etc :return: json data representing element, els...
entailment
def element_info_as_json(name): """ Get specified element META data based on search query This is the base level search that returns basic object info with the following attributes: * href: link to element * name: name of element * type: type of element :param str name: name of element...
Get specified element META data based on search query This is the base level search that returns basic object info with the following attributes: * href: link to element * name: name of element * type: type of element :param str name: name of element :return: list dict with meta (href, nam...
entailment
def element_info_as_json_with_filter(name, _filter): """ Top level json meta data (href, name, type) for element :param str name: name of element :param str _filter: filter of entry point :return: list dict with metadata, otherwise None """ if name and _filter: element = fetch_meta_...
Top level json meta data (href, name, type) for element :param str name: name of element :param str _filter: filter of entry point :return: list dict with metadata, otherwise None
entailment
def element_href_use_wildcard(name): """ Get element href using a wildcard rather than matching only on the name field. This will likely return multiple results. :param name: name of element :return: list of matched elements """ if name: element = fetch_meta_by_name(name, exact_match=Fa...
Get element href using a wildcard rather than matching only on the name field. This will likely return multiple results. :param name: name of element :return: list of matched elements
entailment
def element_href_use_filter(name, _filter): """ Get element href using filter Filter should be a valid entry point value, ie host, router, network, single_fw, etc :param name: name of element :param _filter: filter type, unknown filter will result in no matches :return: element href (if found)...
Get element href using filter Filter should be a valid entry point value, ie host, router, network, single_fw, etc :param name: name of element :param _filter: filter type, unknown filter will result in no matches :return: element href (if found), else None
entailment
def element_by_href_as_json(href, params=None): """ Get specified element by href :param href: link to object :param params: optional search query parameters :return: json data representing element, else None """ if href: element = fetch_json_by_href(href, params=params) if elem...
Get specified element by href :param href: link to object :param params: optional search query parameters :return: json data representing element, else None
entailment
def element_name_by_href(href): """ The element href is known, possibly from a reference in an elements json. You want to retrieve the name of this element. :param str href: href of element :return: str name of element, or None """ if href: element = fetch_json_by_href(href) ...
The element href is known, possibly from a reference in an elements json. You want to retrieve the name of this element. :param str href: href of element :return: str name of element, or None
entailment
def element_name_and_type_by_href(href): """ Retrieve the element name and type of element based on the href. You may have a href that is within another element reference and want more information on that reference. :param str href: href of element :return: tuple (name, type) """ if hre...
Retrieve the element name and type of element based on the href. You may have a href that is within another element reference and want more information on that reference. :param str href: href of element :return: tuple (name, type)
entailment