How to use the heat.common.exception function in heat

To help you get started, we’ve selected a few heat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / heat / heat / engine / output.py View on Github external
def required_resource_names(self):
        if self._deps is None:
            try:
                required_resources = function.dependencies(self._value)
                self._deps = set(map(lambda rp: rp.name, required_resources))
            except (exception.InvalidTemplateAttribute,
                    exception.InvalidTemplateReference):
                # This output ain't gonna work anyway
                self._deps = set()
        return self._deps
github openstack / heat / heat / engine / clients / os / swift.py View on Github external
"""
        client = self.client()
        files = {}

        if files_to_skip is None:
            files_to_skip = []

        try:
            headers, objects = client.get_container(files_container)
            bytes_used = int(headers.get('x-container-bytes-used', 0))
            if bytes_used > cfg.CONF.max_json_body_size:
                msg = _("Total size of files to download (%(size)s bytes) "
                        "exceeds maximum allowed (%(limit)s bytes).") % {
                            'size': bytes_used,
                            'limit': cfg.CONF.max_json_body_size}
                raise exception.DownloadLimitExceeded(message=msg)
            for obj in objects:
                file_name = obj['name']
                if file_name not in files_to_skip:
                    contents = client.get_object(files_container, file_name)[1]
                files[file_name] = contents
        except exceptions.ClientException as cex:
            raise exception.NotFound(_('Could not fetch files from '
                                       'container %(container)s, '
                                       'reason: %(reason)s.') %
                                     {'container': files_container,
                                      'reason': str(cex)})
        return files
github openstack / heat / heat / engine / resources / openstack / heat / scaling_policy.py View on Github external
def _validate_min_adjustment_step(self):
        adjustment_type = self.properties.get(self.ADJUSTMENT_TYPE)
        adjustment_step = self.properties.get(self.MIN_ADJUSTMENT_STEP)
        if (adjustment_type != sc_util.PERCENT_CHANGE_IN_CAPACITY
                and adjustment_step is not None):
            raise exception.ResourcePropertyValueDependency(
                prop1=self.MIN_ADJUSTMENT_STEP,
                prop2=self.ADJUSTMENT_TYPE,
                value=sc_util.PERCENT_CHANGE_IN_CAPACITY)
github openstack / heat / heat / engine / resources / openstack / nova / server_network_mixin.py View on Github external
def _validate_belonging_subnet_to_net(self, network):
        if network.get(self.NETWORK_PORT) is None:
            net = self._get_network_id(network)
            # check if there are subnet and network both specified that
            # subnet belongs to specified network
            subnet = network.get(self.NETWORK_SUBNET)
            if (subnet is not None and net is not None):
                subnet_net = self.client_plugin(
                    'neutron').network_id_from_subnet_id(subnet)
                if subnet_net != net:
                    msg = _('Specified subnet %(subnet)s does not belongs to '
                            'network %(network)s.') % {
                        'subnet': subnet,
                        'network': net}
                    raise exception.StackValidationFailed(message=msg)
github openstack / heat / heat / engine / resources / stack_resource.py View on Github external
def _resolve_attribute(self, name):
        try:
            return self.get_output(name)
        except exception.NotFound:
            raise exception.InvalidTemplateAttribute(resource=self.name,
                                                     key=name)
github openstack / heat / heat / common / environment_util.py View on Github external
new_strategies = {}

    if not old:
        return new, new_strategies

    for key, value in new.items():
        # if key not in param_schemata ignore it
        if key in param_schemata and value is not None:
            param_merge_strategy = get_param_merge_strategy(
                strategies_in_file, key)
            if key not in available_strategies:
                new_strategies[key] = param_merge_strategy

            elif param_merge_strategy != available_strategies[key]:
                raise exception.ConflictingMergeStrategyForParam(
                    strategy=param_merge_strategy,
                    param=key, env_file=env_file)

            if param_merge_strategy == DEEP_MERGE:
                param_merge(key, value,
                            param_schemata[key],
                            deep_merge=True)
            elif param_merge_strategy == MERGE:
                param_merge(key, value, param_schemata[key])
            else:
                old[key] = value

    return old, new_strategies
github openstack / heat / heat / engine / constraints.py View on Github external
if not int(param) == param:
                raise exception.InvalidSchemaError(
                    message=_('step/offset must be integer'))

        step, offset = int(step), int(offset)

        if step == 0:
            raise exception.InvalidSchemaError(message=_('step cannot be 0.'))

        if abs(offset) >= abs(step):
            raise exception.InvalidSchemaError(
                message=_('offset must be smaller (by absolute value) '
                          'than step.'))

        if step * offset < 0:
            raise exception.InvalidSchemaError(
                message=_('step and offset must be both positive or both '
                          'negative.'))
github openstack / heat / heat / engine / conditions.py View on Github external
return condition_name

        if not (isinstance(condition_name, str) and
                condition_name in self._conditions):
            raise ValueError(_('Invalid condition "%s"') % condition_name)

        if condition_name not in self._resolved:
            self._resolved[condition_name] = _in_progress
            self._resolved[condition_name] = self._resolve(condition_name)

        result = self._resolved[condition_name]

        if result is _in_progress:
            message = _('Circular definition for condition '
                        '"%s"') % condition_name
            raise exception.StackValidationFailed(
                error='Condition validation error',
                message=message)

        return result
github openstack / heat / heat / engine / resources / instance.py View on Github external
else:
            try:
                image_list = self.nova().images.list()
            except clients.novaclient.exceptions.ClientException as ex:
                raise exception.ServerError(message=str(ex))
            image_names = dict(
                (o.id, o.name)
                for o in image_list if o.name == image_identifier)
            if len(image_names) == 0:
                logger.info("Image %s was not found in glance" %
                            image_identifier)
                raise exception.ImageNotFound(image_name=image_identifier)
            elif len(image_names) > 1:
                logger.info("Mulitple images %s were found in glance with name"
                            % image_identifier)
                raise exception.NoUniqueImageFound(image_name=image_identifier)
            image_id = image_names.popitem()[0]
        return image_id