Пример #1
0
def records_new(zone_id):
    from route53.models import ChangeBatch, Change, db
    conn = get_connection()
    zone = conn.get_hosted_zone(zone_id)['GetHostedZoneResponse']['HostedZone']
    form = RecordForm()
    error = None
    if form.validate_on_submit():
        change_batch = ChangeBatch(change_id='',
                                   status='created',
                                   comment=form.comment.data)
        db.session.add(change_batch)
        change = Change(action="CREATE",
                        name=form.name.data,
                        type=form.type.data,
                        ttl=form.ttl.data,
                        values=form.values,
                        change_batch_id=change_batch.id)
        db.session.add(change)
        rendered_xml = render_change_batch({'changes': [change],
                                            'comment': change_batch.comment})
        try:
            resp = conn.change_rrsets(zone_id, rendered_xml)
            change_batch.process_response(resp)
            db.session.commit()
            return redirect(url_for('zones.zones_records', zone_id=zone_id))
        except DNSServerError as error:
            error = error
            db.session.rollback()
    return render_template('records/new.html',
                           form=form,
                           zone=zone,
                           zone_id=zone_id,
                           error=error)
Пример #2
0
def records_new(zone_id):
    from route53.models import ChangeBatch, Change, db
    conn = get_connection()
    zone = conn.get_hosted_zone(zone_id)['GetHostedZoneResponse']['HostedZone']
    form = RecordForm()
    error = None
    if form.validate_on_submit():
        change_batch = ChangeBatch(change_id='',
                                   status='created',
                                   comment=form.comment.data)
        db.session.add(change_batch)
        change = Change(action="CREATE",
                        name=form.name.data,
                        type=form.type.data,
                        ttl=form.ttl.data,
                        values=form.values,
                        change_batch_id=change_batch.id)
        db.session.add(change)
        rendered_xml = render_change_batch({
            'changes': [change],
            'comment': change_batch.comment
        })
        try:
            resp = conn.change_rrsets(zone_id, rendered_xml)
            change_batch.process_response(resp)
            db.session.commit()
            return redirect(url_for('zones.zones_records', zone_id=zone_id))
        except DNSServerError as error:
            error = error
            db.session.rollback()
    return render_template('records/new.html',
                           form=form,
                           zone=zone,
                           zone_id=zone_id,
                           error=error)
Пример #3
0
def records_update(zone_id):
    from route53.models import ChangeBatch, Change, db
    conn = get_connection()
    zone = conn.get_hosted_zone(zone_id)['GetHostedZoneResponse']['HostedZone']
    val_dict = get_record_fields()

    if request.method == "GET":
        values = request.args.getlist('value')
        if not values:
            abort(404)
        initial_data = dict(val_dict)
        initial_data['value'] = ';'.join(values)
        form = RecordForm(**initial_data)

    error = None
    if request.method == "POST":
        form = RecordForm()
        change_batch = ChangeBatch(change_id='',
                                   status='created',
                                   comment=form.comment.data)
        db.session.add(change_batch)
        values = request.form.getlist('data_value')
        delete_change = Change(action="DELETE",
                               change_batch_id=change_batch.id,
                               values=values,
                               **val_dict)
        create_change = Change(action="CREATE",
                               change_batch_id=change_batch.id,
                               values=form.values,
                               type=form.type.data,
                               ttl=form.ttl.data,
                               name=form.name.data)
        db.session.add(delete_change)
        db.session.add(create_change)
        rendered_xml = render_change_batch({
            'changes': [delete_change, create_change],
            'comment':
            change_batch.comment
        })
        try:
            resp = conn.change_rrsets(zone_id, rendered_xml)
            change_batch.process_response(resp)
            db.session.commit()
            return redirect(url_for('zones.zones_records', zone_id=zone_id))
        except DNSServerError as error:
            error = error
    return render_template('records/update.html',
                           val_dict=val_dict,
                           values=values,
                           form=form,
                           zone=zone,
                           zone_id=zone_id,
                           error=error)
Пример #4
0
def new(zone_id):
    conn = get_connection()
    zone = get_zone(zone_id, conn)
    form = RecordForm()
    error = None

    if form.validate_on_submit():
        changes = ResourceRecordSets(conn, zone_id, form.comment.data)
        change = changes.add_change("CREATE", form.name.data, form.type.data,
            form.ttl.data)
        for value in form.values:
            change.add_value(value)
        changes.commit()

        flash('Created new %s record %s' % (form.type.data, form.name.data))
        return redirect(url_for('zones.detail', zone_id=zone_id))

    return render_template('records/new.html', form=form, zone=zone,
        zone_id=zone_id, error=error)