示例#1
0
    def _get_all_instances(self, list_of_instance_ids=None):
        """Returns a list of instance objects for a list of instance IDs.

        :returns a list of instance objects.
        :raises NonRecoverableError: If Boto errors.
        """

        try:
            reservations = self.client.get_all_reservations(
                    list_of_instance_ids)
        except exception.EC2ResponseError as e:
            if 'InvalidInstanceID.NotFound' in e:
                instances = [instance for res in
                             self.client.get_all_reservations()
                             for instance in res.instances]
                utils.log_available_resources(instances)
            return None
        except exception.BotoServerError as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        instances = []

        for reservation in reservations:
            for instance in reservation.instances:
                instances.append(instance)

        return instances
示例#2
0
    def _get_all_instances(self, list_of_instance_ids=None):
        """Returns a list of instance objects for a list of instance IDs.

        :returns a list of instance objects.
        :raises NonRecoverableError: If Boto errors.
        """

        try:
            reservations = self.client.get_all_reservations(
                list_of_instance_ids)
        except exception.EC2ResponseError as e:
            if 'InvalidInstanceID.NotFound' in e:
                instances = [
                    instance for res in self.client.get_all_reservations()
                    for instance in res.instances
                ]
                utils.log_available_resources(instances)
            return None
        except exception.BotoServerError as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        instances = []

        for reservation in reservations:
            for instance in reservation.instances:
                instances.append(instance)

        return instances
    def get_target_resource(self):

        try:
            addresses = self.execute(self.client.get_all_addresses,
                                     dict(addresses=self.target_resource_id),
                                     raise_on_falsy=True)
        except exception.EC2ResponseError as e:
            if constants.ELASTICIP['NOT_FOUND_ERROR'] in e:
                addresses = self.client.get_all_addresses()
                utils.log_available_resources(addresses)
            return None
        except exception.BotoServerError as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        return addresses[0] if addresses else addresses
示例#4
0
    def get_target_resource(self):

        try:
            addresses = self.execute(self.client.get_all_addresses,
                                     dict(addresses=self.target_resource_id),
                                     raise_on_falsy=True)
        except exception.EC2ResponseError as e:
            if constants.ELASTICIP['NOT_FOUND_ERROR'] in e:
                addresses = self.client.get_all_addresses()
                utils.log_available_resources(addresses)
            return None
        except exception.BotoServerError as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        return addresses[0] if addresses else addresses
    def get_source_resource(self):

        try:
            instances = self.execute(self.client.get_all_instances,
                                     dict(instance_ids=self
                                          .source_resource_id),
                                     raise_on_falsy=True)
        except exception.EC2ResponseError as e:
            if constants.INSTANCE['NOT_FOUND_ERROR'] in e:
                instances = self.client.get_all_instances()
                utils.log_available_resources(instances)
            return None
        except exception.BotoServerError as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        return instances[0] if instances else instances
示例#6
0
    def get_source_resource(self):

        try:
            instances = self.execute(
                self.client.get_all_instances,
                dict(instance_ids=self.source_resource_id),
                raise_on_falsy=True)
        except exception.EC2ResponseError as e:
            if constants.INSTANCE['NOT_FOUND_ERROR'] in e:
                instances = self.client.get_all_instances()
                utils.log_available_resources(instances)
            return None
        except exception.BotoServerError as e:
            raise NonRecoverableError('{0}'.format(str(e)))

        return instances[0] if instances else instances