How to use the yay.errors.TypeError function in yay

To help you get started, we’ve selected a few yay 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 yaybu / yaybu / yaybu / static.py View on Github external
def _get_source_container(self):
        try:
            return self._get_source_container_from_string()
        except errors.TypeError:
            driver = get_driver_from_expression(
                self.params.source, get_driver, Provider, self.extra_drivers, self.root, ignore=("container", ))
            container = driver.get_container(
                self.params.source.container.as_string())
            return container
github yaybu / yaybu / yaybu / compute / layer / local.py View on Github external
def image(self):
        """ Image can look like one of these formats:

            image: http://server/path/image.img

            image:
              distro: ubuntu
              arch: amd64
              release: 12.04

        """
        p = self.original.params
        try:
            url = p.image.as_string()
            image = LiteralImage(url)
        except errors.TypeError:
            distro = p.image.distro.as_string(default=None)
            release = p.image.release.as_string(default=None)
            arch = p.image.arch.as_string(default=None)
            image = CanonicalImage(distro, release, arch)
        return image
github yaybu / yaybu / yaybu / heroku.py View on Github external
def apply(self):
        try:
            self.cloud = heroku.from_key(self.params.key.as_string())
        except errors.NoMatching:
            try:
                username = self.params.username.as_string()
                password = self.params.password.as_string()
            except errors.NoMatching:
                raise errors.TypeError(
                    "Must specify key or username and password", anchor=self.params.anchor)
            self.cloud = heroku.from_pass(username, password)

        if self.root.readonly:
            return

        changed = False

        app_id = self.params.application_id.as_string()
        if app_id not in self.cloud.apps:
            self.action("Creating new app named '%s'" % app_id)
            if not self.root.simulate:
                self.app = self.cloud.apps.add(app_id)
            else:
                self.app = None
            changed = True
github yaybu / yaybu / yaybu / heroku.py View on Github external
def __init__(self, params):
        super(Heroku, self).__init__(params)

        if not heroku:
            raise errors.TypeError(
                "Dependency 'heroku' is required and not available", anchor=self.anchor)
github yaybu / yaybu / yaybu / boto / elasticache.py View on Github external
def clean_allowed(self):
        from boto.ec2 import connect_to_region
        c = connect_to_region('eu-west-1')

        allowed = []

        try:
            groups = self.params.allowed.get_iterable()
        except errors.NoMatching:
            groups = []

        for group in groups:
            try:
                name = group.as_string()
            except errors.TypeError:
                name = group.get_key("name").as_string()

            try:
                groups = c.get_all_security_groups(groupnames=[name])
                g = groups[0]
            except EC2ResponseError:
                # FIXME: Don't raise if simulating
                raise TypeError("No such EC2 SecurityGroup '%s'" % name)

            allowed.append((g.name, g.owner_id))

        return allowed
github yaybu / yaybu / yaybu / util / libcloud.py View on Github external
def get_driver_from_expression(
    expression,
    get_driver,
    provider,
    extra_drivers,
    context,
        ignore=()):
    try:
        driver_id = expression.as_string()
        driver_id_expr = expression
        expression = None
    except errors.TypeError:
        driver_id = expression.id.as_string()
        driver_id_expr = expression.id

    if driver_id in extra_drivers:
        Driver = extra_drivers[driver_id]
    else:
        try:
            Driver = get_driver(getattr(provider, driver_id))
        except AttributeError:
            msg = ["'%s' is not a valid driver" % driver_id]
            all_drivers = list(
                v for v in vars(provider) if not v.startswith("_"))
            all_drivers.extend(extra_drivers.keys())
            all_drivers = sorted(set(all_drivers))
            possible = difflib.get_close_matches(driver_id, all_drivers)
            if possible:
github yaybu / yaybu / yaybu / compute / part.py View on Github external
def driver_id(self):
        """ Returns the name of the driver, which could be a plain string, or the id parameter of a driver dictionary. """
        try:
            driver_id = self.params.driver.as_string()
        except errors.TypeError:
            driver_id = self.params.driver.id.as_string()
        return driver_id
github yaybu / yaybu / yaybu / compute / layer / cloud.py View on Github external
def _get_size(self):
        try:
            self.original.params.size.as_dict()

        except errors.NoMatching as e:
            try:
                return self._get_size_from_id('default')
            except error.ValueError:
                pass

            # If the backend doesn't suport a 'default' size then raise the
            # original NoMatching exception
            raise e

        except errors.TypeError:
            return self._get_size_from_id(self.original.params.size.as_string())

        id = str(self.original.params.size.id)
        return NodeSize(
            id=id,
            name=self.original.params.size.name.as_string(default=id),
            ram=self.original.params.size.ram.as_int(default=0),
            disk=self.original.params.size.disk.as_int(default=0),
            bandwidth=self.original.params.bandwidth.as_int(default=0),
            price=self.original.params.size.price.as_int(default=0),
            driver=self.driver,
        )
github yaybu / yaybu / yaybu / boto / rds.py View on Github external
def clean_allowed(self):
        from boto.ec2 import connect_to_region
        c = connect_to_region('eu-west-1')

        allowed = []

        try:
            groups = self.params.allowed.get_iterable()
        except errors.NoMatching:
            groups = []

        for group in groups:
            try:
                name = group.as_string()
            except errors.TypeError:
                name = group.get_key("name").as_string()

            try:
                groups = c.get_all_security_groups(groupnames=[name])
                g = groups[0]
            except EC2ResponseError:
                # FIXME: Don't raise if simulating
                raise TypeError("No such EC2 SecurityGroup '%s'" % name)

            allowed.append((g.name, g.owner_id))

        return allowed