@zones.route('/clone/<zone_id>', methods=['GET', 'POST'])
def zones_clone(zone_id):
    conn = get_connection()

    zone_response = conn.get_hosted_zone(zone_id)
    original_zone = zone_response['GetHostedZoneResponse']['HostedZone']

    form = ZoneForm()
    errors = []

    if form.validate_on_submit():
        response = conn.create_hosted_zone(
                form.name.data,
                comment=form.comment.data)

        info = response['CreateHostedZoneResponse']

        nameservers = ', '.join(info['DelegationSet']['NameServers'])

        new_zone_id = info['HostedZone']['Id']

        original_records = conn.get_all_rrsets(zone_id)

        from route53.models import ChangeBatch, Change, db

        for recordset in original_records:
            if not recordset.type in ["SOA", "NS"]:

                change_batch = ChangeBatch(change_id='',
                                           status='created',
                                           comment='')
                db.session.add(change_batch)
                change = Change(action="CREATE",
                                name=recordset.name.replace(original_zone['Name'],
                                                            form.name.data),
                                type=recordset.type,
                                ttl=recordset.ttl,
                                values = recordset.resource_records,
                                change_batch_id=change_batch.id)

                db.session.add(change)
                changes = [change]

                rendered_xml = render_change_batch({'changes': changes, 'comment': ''})

                try:
                    from route53 import shortid
                    resp = conn.change_rrsets(shortid(new_zone_id), rendered_xml)
                    change_batch.process_response(resp)
                    db.session.commit()
                except DNSServerError as error:
                    errors.append((recordset.type, recordset.name, error))
                    db.session.rollback()

        if not errors:
            flash(u"A zone with id %s has been created. "
                  u"Use following nameservers %s"
                   % (new_zone_id, nameservers))
            return redirect(url_for('zones_list'))

    return render_template('zones/clone.html',
        form=form, errors=errors, original_zone=original_zone)
dataset/ETHPy150Open zen4ever/route53manager/route53/views/zones.py/zones_clone/original