'Implements the BaseBomValidateDeployer interface.'

def do_undeploy(self):

    options = self.options
    logging.info('Terminating    "%s"', options.deploy_aws_name)
    if self.__instance_id:
        all_ids = [self.__instance_id]
    else:
        lookup_response = run_and_monitor('aws    ec2    describe-instances    --profile    {region}    --filters    "Name=tag:Name,Values={name},Name=instance-state-name,Values=running"'.format(region=options.deploy_aws_region, name=options.deploy_aws_name), echo=False)
        if (lookup_response.returncode != 0):
            raise ValueError('Could    not    lookup    instance    id:    {0}', lookup_response)
        exists = json.JSONDecoder().decode(lookup_response.stdout).get('Reservations')
        if (not exists):
            logging.warning('"%s"    is    not    running', options.deploy_aws_name)
            return
        all_ids = []
        for reservation in exists:
            all_ids.extend([instance['InstanceId'] for instance in reservation['Instances']])
    for instance_id in all_ids:
        logging.info('Terminating    "%s"    instanceId=%s', options.deploy_aws_name, instance_id)
        response = run_quick('aws    ec2    terminate-instances        --profile    {region}        --instance-ids    {id}'.format(region=options.deploy_aws_region, id=instance_id))
        if (response.returncode != 0):
            logging.warning('Failed    to    delete    "%s"    instanceId=%s', options.deploy_aws_name, instance_id)
