当前位置: 首页>>代码示例>>Python>>正文


Python errors.AnsibleFilterError方法代码示例

本文整理汇总了Python中ansible.errors.AnsibleFilterError方法的典型用法代码示例。如果您正苦于以下问题:Python errors.AnsibleFilterError方法的具体用法?Python errors.AnsibleFilterError怎么用?Python errors.AnsibleFilterError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ansible.errors的用法示例。


在下文中一共展示了errors.AnsibleFilterError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_account_id

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def get_account_id(region, profile=None):
    """ Retrieve the AWS account id.
    Args:
        region (str): The AWS region.

    Basic Usage:
        >>> region = 'us-west-2'
        >>> account_id = get_account_id(region)
        12345667899

    Returns:
        String
    """
    client = aws_client(region, 'iam', profile)
    try:
        account_id = client.list_users()['Users'][0]['Arn'].split(':')[4]
        return account_id
    except Exception as e:
        if isinstance(e, botocore.exceptions.ClientError):
            raise e
        else:
            raise errors.AnsibleFilterError(
                "Failed to retrieve account id"
            ) 
开发者ID:PacktPublishing,项目名称:-Deploying-Jenkins-to-the-Cloud-with-DevOps-Tools,代码行数:26,代码来源:aws.py

示例2: get_instance_by_tags

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def get_instance_by_tags(region, tags, return_key="PublicIpAddress",
                         state=None, profile=None):

    instances = get_instances_by_tags(region, tags, return_key, state, profile)
    if len(instances) > 1:
        raise errors.AnsibleFilterError(
            "More than 1 {0} instance was found with the following tags {1} in region {2}"
            .format(instances, tags, region)
        )
    elif len(instances) == 1:
        return instances[0]
    else:
        raise errors.AnsibleFilterError(
            "No instances was found with the following tags {0} in region {1}"
            .format(tags, region)
        ) 
开发者ID:PacktPublishing,项目名称:-Deploying-Jenkins-to-the-Cloud-with-DevOps-Tools,代码行数:18,代码来源:aws.py

示例3: get_acm_arn

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def get_acm_arn(domain_name, region, profile=None):
    """Retrieve the attributes of a certificate if it exists or all certs.
    Args:
        domain_name (str): The domain name of the certificate.
        region (str): The AWS region.

    Basic Usage:
        >>> arn = get_acm_arn('test', 'us-west-2')
        "arn:aws:acm:us-west-2:123456789:certificate/25b4ad8a-1e24-4001-bcd0-e82fb3554cd7",
    """
    arn = None
    client = aws_client(region, 'acm', profile)
    try:
        acm_certs = client.list_certificates()['CertificateSummaryList']
        for cert in acm_certs:
            if domain_name == cert['DomainName']:
                arn = cert['CertificateArn']
                return arn
        if not arn:
            raise errors.AnsibleFilterError(
                'Certificate {0} does not exist'.format(domain_name)
            )
    except Exception as e:
        raise e 
开发者ID:PacktPublishing,项目名称:-Deploying-Jenkins-to-the-Cloud-with-DevOps-Tools,代码行数:26,代码来源:aws.py

示例4: get_redshift_endpoint

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def get_redshift_endpoint(region, name, profile=None):
    """Retrieve the endpoint name of the redshift cluster.
    Args:
        region (str): The AWS region.
        name (str): The name of the redshift cluster.

    Basic Usage:
        >>> import boto3
        >>> redshift = boto3.client('redshift', 'us-west-2')
        >>> endpoint = get_redshift_endpoint(region, 'test')
        dns_name
    """
    client = aws_client(region, 'redshift', profile)
    try:
        return client.describe_clusters(ClusterIdentifier=name)['Clusters'][0]['Endpoint']['Address']
    except Exception as e:
        if isinstance(e, botocore.exceptions.ClientError):
            raise e
        else:
            raise errors.AnsibleFilterError(
                'Could not retreive ip for {0}: {1}'.format(name, str(e))
            ) 
开发者ID:PacktPublishing,项目名称:-Deploying-Jenkins-to-the-Cloud-with-DevOps-Tools,代码行数:24,代码来源:aws.py

示例5: get_attr

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def get_attr(data, attribute=None):
        """ This looks up dictionary attributes of the form a.b.c and returns
            the value.

            If the key isn't present, None is returned.
            Ex: data = {'a': {'b': {'c': 5}}}
                attribute = "a.b.c"
                returns 5
        """
        if not attribute:
            raise errors.AnsibleFilterError("|failed expects attribute to be set")

        ptr = data
        for attr in attribute.split('.'):
            if attr in ptr:
                ptr = ptr[attr]
            else:
                ptr = None
                break

        return ptr 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:23,代码来源:oo_filters.py

示例6: oo_select_keys

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def oo_select_keys(data, keys):
        """ This returns a list, which contains the value portions for the keys
            Ex: data = { 'a':1, 'b':2, 'c':3 }
                keys = ['a', 'c']
                returns [1, 3]
        """

        if not isinstance(data, Mapping):
            raise errors.AnsibleFilterError("|failed expects to filter on a dict or object")

        if not isinstance(keys, list):
            raise errors.AnsibleFilterError("|failed expects first param is a list")

        # Gather up the values for the list of keys passed in
        retval = [data[key] for key in keys if key in data]

        return retval 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:19,代码来源:oo_filters.py

示例7: oo_ami_selector

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def oo_ami_selector(data, image_name):
        """ This takes a list of amis and an image name and attempts to return
            the latest ami.
        """
        if not isinstance(data, list):
            raise errors.AnsibleFilterError("|failed expects first param is a list")

        if not data:
            return None
        else:
            if image_name is None or not image_name.endswith('_*'):
                ami = sorted(data, key=itemgetter('name'), reverse=True)[0]
                return ami['ami_id']
            else:
                ami_info = [(ami, ami['name'].split('_')[-1]) for ami in data]
                ami = sorted(ami_info, key=itemgetter(1), reverse=True)[0][0]
                return ami['ami_id'] 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:19,代码来源:oo_filters.py

示例8: oo_filter_list

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def oo_filter_list(data, filter_attr=None):
        """ This returns a list, which contains all items where filter_attr
            evaluates to true
            Ex: data = [ { a: 1, b: True },
                         { a: 3, b: False },
                         { a: 5, b: True } ]
                filter_attr = 'b'
                returns [ { a: 1, b: True },
                          { a: 5, b: True } ]
        """
        if not isinstance(data, list):
            raise errors.AnsibleFilterError("|failed expects to filter on a list")

        if not isinstance(filter_attr, basestring):
            raise errors.AnsibleFilterError("|failed expects filter_attr is a str or unicode")

        # Gather up the values for the list of keys passed in
        return [x for x in data if filter_attr in x and x[filter_attr]] 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:20,代码来源:oo_filters.py

示例9: oo_openshift_env

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def oo_openshift_env(hostvars):
        ''' Return facts which begin with "openshift_" and translate
            legacy facts to their openshift_env counterparts.

            Ex: hostvars = {'openshift_fact': 42,
                            'theyre_taking_the_hobbits_to': 'isengard'}
                returns  = {'openshift_fact': 42}
        '''
        if not issubclass(type(hostvars), dict):
            raise errors.AnsibleFilterError("|failed expects hostvars is a dict")

        facts = {}
        regex = re.compile('^openshift_.*')
        for key in hostvars:
            if regex.match(key):
                facts[key] = hostvars[key]

        migrations = {'openshift_router_selector': 'openshift_hosted_router_selector',
                      'openshift_registry_selector': 'openshift_hosted_registry_selector'}
        for old_fact, new_fact in migrations.iteritems():
            if old_fact in facts and new_fact not in facts:
                facts[new_fact] = facts[old_fact]
        return facts 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:25,代码来源:oo_filters.py

示例10: oo_31_rpm_rename_conversion

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def oo_31_rpm_rename_conversion(rpms, openshift_version=None):
        """ Filters a list of 3.0 rpms and return the corresponding 3.1 rpms
            names with proper version (if provided)

            If 3.1 rpms are passed in they will only be augmented with the
            correct version.  This is important for hosts that are running both
            Masters and Nodes.
        """
        if not isinstance(rpms, list):
            raise errors.AnsibleFilterError("failed expects to filter on a list")
        if openshift_version is not None and not isinstance(openshift_version, basestring):
            raise errors.AnsibleFilterError("failed expects openshift_version to be a string")

        rpms_31 = []
        for rpm in rpms:
            if not 'atomic' in rpm:
                rpm = rpm.replace("openshift", "atomic-openshift")
            if openshift_version:
                rpm = rpm + openshift_version
            rpms_31.append(rpm)

        return rpms_31 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:24,代码来源:oo_filters.py

示例11: oo_pods_match_component

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def oo_pods_match_component(pods, deployment_type, component):
        """ Filters a list of Pods and returns the ones matching the deployment_type and component
        """
        if not isinstance(pods, list):
            raise errors.AnsibleFilterError("failed expects to filter on a list")
        if not isinstance(deployment_type, basestring):
            raise errors.AnsibleFilterError("failed expects deployment_type to be a string")
        if not isinstance(component, basestring):
            raise errors.AnsibleFilterError("failed expects component to be a string")

        image_prefix = 'openshift/origin-'
        if deployment_type in ['enterprise', 'online', 'openshift-enterprise']:
            image_prefix = 'openshift3/ose-'
        elif deployment_type == 'atomic-enterprise':
            image_prefix = 'aep3_beta/aep-'

        matching_pods = []
        image_regex = image_prefix + component + r'.*'
        for pod in pods:
            for container in pod['spec']['containers']:
                if re.search(image_regex, container['image']):
                    matching_pods.append(pod)
                    break # stop here, don't add a pod more than once

        return matching_pods 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:27,代码来源:oo_filters.py

示例12: oo_image_tag_to_rpm_version

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def oo_image_tag_to_rpm_version(version, include_dash=False):
        """ Convert an image tag string to an RPM version if necessary
            Empty strings and strings that are already in rpm version format
            are ignored. Also remove non semantic version components.

            Ex. v3.2.0.10 -> -3.2.0.10
                v1.2.0-rc1 -> -1.2.0
        """
        if not isinstance(version, basestring):
            raise errors.AnsibleFilterError("|failed expects a string or unicode")
        if version.startswith("v"):
            version = version[1:]
            # Strip release from requested version, we no longer support this.
            version = version.split('-')[0]

        if include_dash and version and not version.startswith("-"):
            version = "-" + version

        return version 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:21,代码来源:oo_filters.py

示例13: validate

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def validate(self):
        ''' validate this idp instance '''
        IdentityProviderBase.validate(self)
        if not isinstance(self.provider['attributes'], dict):
            raise errors.AnsibleFilterError("|failed attributes for provider "
                                            "{0} must be a dictionary".format(self.__class__.__name__))

        attrs = ['id', 'email', 'name', 'preferredUsername']
        for attr in attrs:
            if attr in self.provider['attributes'] and not isinstance(self.provider['attributes'][attr], list):
                raise errors.AnsibleFilterError("|failed {0} attribute for "
                                                "provider {1} must be a list".format(attr, self.__class__.__name__))

        unknown_attrs = set(self.provider['attributes'].keys()) - set(attrs)
        if len(unknown_attrs) > 0:
            raise errors.AnsibleFilterError("|failed provider {0} has unknown "
                                            "attributes: {1}".format(self.__class__.__name__, ', '.join(unknown_attrs))) 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:19,代码来源:openshift_master.py

示例14: translate_idps

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def translate_idps(idps, api_version, openshift_version, deployment_type):
        ''' Translates a list of dictionaries into a valid identityProviders config '''
        idp_list = []

        if not isinstance(idps, list):
            raise errors.AnsibleFilterError("|failed expects to filter on a list of identity providers")
        for idp in idps:
            if not isinstance(idp, dict):
                raise errors.AnsibleFilterError("|failed identity providers must be a list of dictionaries")

            cur_module = sys.modules[__name__]
            idp_class = getattr(cur_module, idp['kind'], None)
            idp_inst = idp_class(api_version, idp) if idp_class is not None else IdentityProviderBase(api_version, idp)
            idp_inst.set_provider_items()
            idp_list.append(idp_inst)


        IdentityProviderBase.validate_idp_list(idp_list, openshift_version, deployment_type)
        return yaml.safe_dump([idp.to_dict() for idp in idp_list], default_flow_style=False) 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:21,代码来源:openshift_master.py

示例15: validate_pcs_cluster

# 需要导入模块: from ansible import errors [as 别名]
# 或者: from ansible.errors import AnsibleFilterError [as 别名]
def validate_pcs_cluster(data, masters=None):
        ''' Validates output from "pcs status", ensuring that each master
            provided is online.
            Ex: data = ('...',
                        'PCSD Status:',
                        'master1.example.com: Online',
                        'master2.example.com: Online',
                        'master3.example.com: Online',
                        '...')
                masters = ['master1.example.com',
                           'master2.example.com',
                           'master3.example.com']
               returns True
        '''
        if not issubclass(type(data), basestring):
            raise errors.AnsibleFilterError("|failed expects data is a string or unicode")
        if not issubclass(type(masters), list):
            raise errors.AnsibleFilterError("|failed expects masters is a list")
        valid = True
        for master in masters:
            if "{0}: Online".format(master) not in data:
                valid = False
        return valid 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:25,代码来源:openshift_master.py


注:本文中的ansible.errors.AnsibleFilterError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。