示例#1
0
 def __init__(self,
              title,
              Value=REQUIRED,
              Description=NOTHING,
              Export=NOTHING,
              DependsOn=NOTHING,
              **kwargs):
     processed_kwargs = preprocess_init_kwargs(title=title,
                                               Value=Value,
                                               Description=Description,
                                               Export=Export,
                                               **kwargs)
     super(Output, self).__init__(**processed_kwargs)
     if DependsOn is NOTHING:
         object.__setattr__(self,
                            mtdt.TemplateLevelField.OUTPUTS_DEPENDS_ON, [])
     else:
         depends_on = depends_on_helper(DependsOn)
         if not isinstance(depends_on, list):
             depends_on = [
                 depends_on,
             ]
         object.__setattr__(self,
                            mtdt.TemplateLevelField.OUTPUTS_DEPENDS_ON,
                            depends_on)
def x_depends_on_y(x, y):
    """
    Define that x depends on y.

    :type x: AWSObject
    :type y: AWSObject
    """
    if not isinstance(y, AWSObject):
        raise TypeError("y can't be a string in x_depends_on_y(x, y)!")

    y_logic_id = depends_on_helper(y)

    if DEPENDS_ON not in x.resource:
        x.resource[DEPENDS_ON] = [
            y_logic_id,
        ]
    elif x.resource[DEPENDS_ON] is None:
        x.resource[DEPENDS_ON] = [
            y_logic_id,
        ]
    elif isinstance(x.resource[DEPENDS_ON], list):
        if y_logic_id not in x.resource[DEPENDS_ON]:
            x.resource[DEPENDS_ON].append(y_logic_id)
    else:
        if y_logic_id != x.resource[DEPENDS_ON]:
            x.resource[DEPENDS_ON] = [x.resource[DEPENDS_ON], y_logic_id]
示例#3
0
 def test_depends_on_helper_with_string(self):
     resource_name = "Bucket1"
     self.assertEqual(depends_on_helper(resource_name), resource_name)
示例#4
0
 def test_depends_on_helper_with_resource(self):
     resource_name = "Bucket1"
     b1 = Bucket(resource_name)
     self.assertEqual(depends_on_helper(b1), resource_name)
示例#5
0
 def test_depends_on_helper_with_string(self):
     resource_name = "Bucket1"
     self.assertEqual(depends_on_helper(resource_name), resource_name)
示例#6
0
 def test_depends_on_helper_with_resource(self):
     resource_name = "Bucket1"
     b1 = Bucket(resource_name)
     self.assertEqual(depends_on_helper(b1), resource_name)
示例#7
0
    def __setattr__(self, name, value):
        if name in self.__dict__.keys() \
                or '_BaseAWSObject__initialized' not in self.__dict__:
            return dict.__setattr__(self, name, value)
        elif name in self.attributes:
            if name == "DependsOn":
                self.resource[name] = depends_on_helper(value)
            else:
                self.resource[name] = value
            return None
        elif name in self.propnames:
            # Check the type of the object and compare against what we were
            # expecting.
            expected_type = self.props[name][0]

            # If the value is a AWSHelperFn we can't do much validation
            # we'll have to leave that to Amazon.  Maybe there's another way
            # to deal with this that we'll come up with eventually
            if isinstance(value, AWSHelperFn):
                return self.properties.__setitem__(name, value)

            # If it's a function, call it...
            elif isinstance(expected_type, types.FunctionType):
                try:
                    value = expected_type(value)
                except Exception:
                    sys.stderr.write("%s: %s.%s function validator '%s' threw "
                                     "exception:\n" %
                                     (self.__class__, self.title, name,
                                      expected_type.__name__))
                    raise
                return self.properties.__setitem__(name, value)

            # If it's a list of types, check against those types...
            elif isinstance(expected_type, list):
                # If we're expecting a list, then make sure it is a list
                if not isinstance(value, list):
                    self._raise_type(name, value, expected_type)

                # Iterate over the list and make sure it matches our
                # type checks (as above accept AWSHelperFn because
                # we can't do the validation ourselves)
                for v in value:
                    if not isinstance(v, tuple(expected_type)) \
                            and not isinstance(v, AWSHelperFn):
                        self._raise_type(name, v, expected_type)
                # Validated so assign it
                return self.properties.__setitem__(name, value)

            # Final validity check, compare the type of value against
            # expected_type which should now be either a single type or
            # a tuple of types.
            elif isinstance(value, expected_type):
                return self.properties.__setitem__(name, value)
            else:
                self._raise_type(name, value, expected_type)

        type_name = getattr(self, 'resource_type', self.__class__.__name__)

        raise AttributeError("%s object does not support attribute %s" %
                             (type_name, name))