Exemplo n.º 1
0
def update_alias(zone_id):
    conn = get_connection()
    zone = get_zone(zone_id, conn)
    error = None
    form = RecordAliasForm(request.values, csrf_enabled=False)

    if form.validate_on_submit():

        changes = ResourceRecordSets(conn, zone_id, form.comment.data)

        change = changes.add_change("DELETE", form.name.data, form.type.data,
            form.ttl.data)
        change.set_alias(form.alias_hosted_zone_id.data,
            form.alias_dns_name.data)

        change = changes.add_change("CREATE", form.name.data, form.type.data,
            form.ttl.data)
        change.set_alias(form.alias_hosted_zone_id.data,
            form.alias_dns_name.data)

        changes.commit()
        flash('Updated alias %s for %s' % (form.type.data, form.name.data))
        return redirect(url_for('zones.detail', zone_id=zone_id))

    elbs = get_connection('elb').get_all_load_balancers()

    return render_template('records/update_alias.html', form=form, zone=zone,
        zone_id=zone_id, error=error, elbs=elbs)
Exemplo n.º 2
0
def import_zone(zone_id):
    from route53.models import ChangeBatch, Change, db

    Zone = get_zone_class()
    zone = Zone.find(zone_id)
    Record = get_record_class()

    # filter out NS records
    records = filter(lambda x: x.record_type != "NS", Record.find(zone_id=zone_id))

    records = sorted(records, key=lambda x: x.record_type)

    # order records by record_type and name into recordsets

    conn = get_connection()
    response = conn.create_hosted_zone(zone.origin)
    info = response["CreateHostedZoneResponse"]
    new_zone_id = info["HostedZone"]["Id"]

    errors = []

    for k, g in groupby(records, key=lambda x: (x.record_type, x.name)):
        change_batch = ChangeBatch(change_id="", status="created", comment="")

        db.session.add(change_batch)
        record_type, name = k
        rcds = list(g)
        record_name = zone.origin in name and name or name + "." + zone.origin

        if record_type not in ("MX", "SRV"):
            values = map(lambda x: x.data, rcds)
        else:
            values = map(lambda x: "%s %s" % (x.aux, x.data), rcds)
        change = Change(
            action="CREATE",
            name=record_name,
            type=record_type,
            ttl=rcds[0].ttl,
            values=values,
            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((record_type, name, error))
            db.session.rollback()

    if errors:
        return render_template("slicehost/import_zone.html", errors=errors, zone=zone)

    return redirect(url_for("main.index"))
Exemplo n.º 3
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)
Exemplo n.º 4
0
def import_zone(zone_id):
    from route53.models import ChangeBatch, Change, db

    Zone = get_zone_class()
    zone = Zone.find(zone_id)
    Record = get_record_class()

    # filter out NS records
    records = filter(lambda x: x.record_type != 'NS',
                     Record.find(zone_id=zone_id))

    records = sorted(records, key=lambda x: x.record_type)

    # order records by record_type and name into recordsets

    conn = get_connection()
    response = conn.create_hosted_zone(zone.origin)
    info = response['CreateHostedZoneResponse']
    new_zone_id = info['HostedZone']['Id']

    errors = []

    for k, g in groupby(records, key=lambda x: (x.record_type, x.name)):
        change_batch = ChangeBatch(change_id='', status='created', comment='')

        db.session.add(change_batch)
        record_type, name = k
        rcds = list(g)
        record_name = zone.origin in name and name or name + "." + zone.origin

        if record_type not in ('MX', 'SRV'):
            values = map(lambda x: x.data, rcds)
        else:
            values = map(lambda x: "%s %s" % (x.aux, x.data), rcds)
        change = Change(action="CREATE",
                        name=record_name,
                        type=record_type,
                        ttl=rcds[0].ttl,
                        values={'values': values},
                        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((record_type, name, error))
            db.session.rollback()

    if errors:
        return render_template('slicehost/import_zone.html',
                               errors=errors,
                               zone=zone)

    return redirect(url_for('main.index'))
Exemplo n.º 5
0
def update(zone_id):
    conn = get_connection()
    zone = get_zone(zone_id, conn)
    form = EditRecordForm(request.values)
    error = None

    if request.method == "GET" and not form.values:
        return redirect(url_for('.update_alias', zone_id=zone_id, **request.values.to_dict()))

    if request.method == "POST":
        changes = ResourceRecordSets(conn, zone_id, form.comment.data)
        del_change = changes.add_change("DELETE", form.previous_name.data,
            form.previous_type.data, form.previous_ttl.data)

        [del_change.add_value(v) for v in form.previous_values]

        change = changes.add_change("CREATE", form.name.data, form.type.data,
            form.ttl.data)

        [change.add_value(v) for v in form.values]

        changes.commit()
        flash('Updated %s record for %s' % (form.type.data, form.name.data))
        return redirect(url_for('zones.detail', zone_id=zone_id))

    return render_template('records/update.html', form=form, zone=zone,
        zone_id=zone_id, error=error)
Exemplo n.º 6
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)
Exemplo n.º 7
0
def zones_detail(zone_id):
    conn = get_connection()
    resp = conn.get_hosted_zone(zone_id)
    zone = resp['GetHostedZoneResponse']['HostedZone']
    nameservers = resp['GetHostedZoneResponse']['DelegationSet']['NameServers']

    return render_template('zones/detail.html',
            zone_id=zone_id,
            zone=zone,
            nameservers=nameservers)
Exemplo n.º 8
0
def zones_records(zone_id):
    conn = get_connection()
    resp = conn.get_hosted_zone(zone_id)
    zone = resp['GetHostedZoneResponse']['HostedZone']

    record_resp = conn.get_all_rrsets(zone_id)

    return render_template('zones/records.html',
            zone_id=zone_id,
            zone=zone,
            recordsets=record_resp)
Exemplo n.º 9
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)
Exemplo n.º 10
0
def records_delete(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')
        alias_hosted_zone_id = request.args.get('alias_hosted_zone_id', None)
        alias_dns_name = request.args.get('alias_dns_name', None)
        if not values and not alias_hosted_zone_id and not alias_dns_name:
            abort(404)

    error = None
    if request.method == "POST":
        change_batch = ChangeBatch(change_id='', status='created', comment='')
        db.session.add(change_batch)
        values = request.form.getlist('data_value')
        alias_hosted_zone_id = request.form.get('data_alias_hosted_zone_id',
                                                None)
        alias_dns_name = request.form.get('data_alias_dns_name', None)
        change = Change(action="DELETE",
                        change_batch_id=change_batch.id,
                        values={
                            'values': values,
                            'alias_hosted_zone_id': alias_hosted_zone_id,
                            'alias_dns_name': alias_dns_name,
                        },
                        **val_dict)
        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
    return render_template('records/delete.html',
                           val_dict=val_dict,
                           values=values,
                           alias_hosted_zone_id=alias_hosted_zone_id,
                           alias_dns_name=alias_dns_name,
                           zone=zone,
                           zone_id=zone_id,
                           error=error)
Exemplo n.º 11
0
def zones_records(zone_id):
    conn = get_connection()
    resp = conn.get_hosted_zone(zone_id)
    zone = resp['GetHostedZoneResponse']['HostedZone']

    record_resp = sorted(conn.get_all_rrsets(zone_id), key=lambda x: x.type)

    groups = groupby(record_resp, key=lambda x: x.type)

    groups = [(k, list(v)) for k, v in groups]

    return render_template('zones/records.html',
                           zone_id=zone_id,
                           zone=zone,
                           groups=groups)
Exemplo n.º 12
0
def zones_records(zone_id):
    conn = get_connection()
    resp = conn.get_hosted_zone(zone_id)
    zone = resp['GetHostedZoneResponse']['HostedZone']

    record_resp = sorted(conn.get_all_rrsets(zone_id), key=lambda x: x.type)

    groups = groupby(record_resp, key=lambda x: x.type)

    groups = [(k, list(v)) for k, v in groups]

    return render_template('zones/records.html',
            zone_id=zone_id,
            zone=zone,
            groups=groups)
Exemplo n.º 13
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)
Exemplo n.º 14
0
def records_delete(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')
        alias_hosted_zone_id = request.args.get('alias_hosted_zone_id', None)
        alias_dns_name = request.args.get('alias_dns_name', None)
        if not values and not alias_hosted_zone_id and not alias_dns_name:
            abort(404)

    error = None
    if request.method == "POST":
        change_batch = ChangeBatch(change_id='', status='created', comment='')
        db.session.add(change_batch)
        values = request.form.getlist('data_value')
        alias_hosted_zone_id = request.form.get('data_alias_hosted_zone_id', None)
        alias_dns_name = request.form.get('data_alias_dns_name', None)
        change = Change(action="DELETE",
                        change_batch_id=change_batch.id,
                        values={
                            'values': values,
                            'alias_hosted_zone_id': alias_hosted_zone_id,
                            'alias_dns_name': alias_dns_name,
                        },
                        **val_dict)
        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
    return render_template('records/delete.html',
                           val_dict=val_dict,
                           values=values,
                           alias_hosted_zone_id=alias_hosted_zone_id,
                           alias_dns_name=alias_dns_name,
                           zone=zone,
                           zone_id=zone_id,
                           error=error)
Exemplo n.º 15
0
def zones_new():
    conn = get_connection()

    form = ZoneForm()
    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'])
        zone_id = info['HostedZone']['Id']

        flash(u"A zone with id %s has been created. "
              u"Use following nameservers %s" % (zone_id, nameservers))

        return redirect(url_for('zones_list'))
    return render_template('zones/new.html', form=form)
Exemplo n.º 16
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)
Exemplo n.º 17
0
def zones_delete(zone_id):
    conn = get_connection()
    zone = conn.get_hosted_zone(zone_id)['GetHostedZoneResponse']['HostedZone']

    error = None

    if request.method == 'POST' and 'delete' in request.form:
        try:
            conn.delete_hosted_zone(zone_id)

            flash(u"A zone with id %s has been deleted" % zone_id)

            return redirect(url_for('zones_list'))
        except DNSServerError as error:
            error = error
    return render_template('zones/delete.html',
                           zone_id=zone_id,
                           zone=zone,
                           error=error)
Exemplo n.º 18
0
def delete(zone_id):
    conn = get_connection()
    zone = conn.get_hosted_zone(zone_id)['GetHostedZoneResponse']['HostedZone']

    error = None

    if request.method == 'POST' and 'delete' in request.form:
        try:
            conn.delete_hosted_zone(zone_id)

            flash(u"A zone with id %s has been deleted" % zone_id)

            return redirect(url_for('zones_list'))
        except DNSServerError as error:
            error = error
    return render_template('zones/delete.html',
                           zone_id=zone_id,
                           zone=zone,
                           error=error)
Exemplo n.º 19
0
def detail(zone_id):
    conn = get_connection()
    resp = conn.get_hosted_zone(zone_id)
    zone = resp['GetHostedZoneResponse']['HostedZone']
    nameservers = resp['GetHostedZoneResponse']['DelegationSet']['NameServers']

    resp = conn.get_hosted_zone(zone_id)
    zone = resp['GetHostedZoneResponse']['HostedZone']

    record_resp = sorted(conn.get_all_rrsets(zone_id), key=lambda x: x.type)

    groups = groupby(record_resp, key=lambda x: x.type)

    groups = [(k, list(v)) for k, v in groups]

    return render_template('zones/detail.html',
            zone_id=zone_id,
            zone=zone,
            nameservers=nameservers,
            groups=groups)
Exemplo n.º 20
0
def new():
    conn = get_connection()

    form = ZoneForm()
    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'])
        zone_id = info['HostedZone']['Id']

        flash(u"A zone with id %s has been created. "
              u"Use following nameservers %s"
               % (zone_id, nameservers))

        return redirect(url_for('zones_list'))
    return render_template('zones/new.html', form=form)
Exemplo n.º 21
0
def delete_alias(zone_id):
    conn = get_connection()
    zone = get_zone(zone_id, conn)
    form = DeleteRecordAliasForm(request.values)

    if request.method == "GET":
        if form.values:
            abort(404)

    error = None
    if request.method == "POST":
        changes = ResourceRecordSets(conn, zone_id, '')
        change = changes.add_change("DELETE", form.name.data, form.type.data)
        change.set_alias(form.alias_hosted_zone_id.data,
            form.alias_dns_name.data)

        changes.commit()
        flash('Deleted alias %s' % form.name.data)
        return redirect(url_for('zones.detail', zone_id=zone_id))

    return render_template('records/delete_alias.html', zone=zone,
        zone_id=zone_id, error=error, form=form)
Exemplo n.º 22
0
def delete(zone_id):
    conn = get_connection()
    zone = get_zone(zone_id, conn)
    form = RecordForm(request.values)

    if request.method == "GET":
        if not form.values:
            abort(404)

    error = None
    if request.method == "POST":
        changes = ResourceRecordSets(conn, zone_id, form.comment.data)
        change = changes.add_change("DELETE", form.name.data, form.type.data, form.ttl.data)
        change.set_alias(None, None)
        [change.add_value(v) for v in form.values]
        changes.commit()

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

    return render_template('records/delete.html', zone=zone, zone_id=zone_id,
        error=error, form=form)
Exemplo n.º 23
0
def get_zone(zone_id, conn=None):
    if not conn:
        conn = get_connection()
    return conn.get_hosted_zone(zone_id)['GetHostedZoneResponse']['HostedZone']
Exemplo n.º 24
0
def import_zone(zone_id):
    from route53.models import ChangeBatch, Change, db

    Zone = get_zone_class()
    zone = Zone.find(zone_id)
    Record = get_record_class()

    # filter out NS records
    records = filter(lambda x: x.record_type != 'NS', Record.find(zone_id=zone_id))

    records = sorted(records, key=lambda x: x.record_type)

    # order records by record_type and name into recordsets

    conn = get_connection()
    response = conn.create_hosted_zone(zone.origin)
    info = response['CreateHostedZoneResponse']
    new_zone_id = info['HostedZone']['Id']

    errors = []

    for k, g in groupby(records, key=lambda x: (x.record_type, x.name)):
        change_batch = ChangeBatch(change_id='',
                                   status='created',
                                   comment='')

        db.session.add(change_batch)
        record_type, name = k
        rcds = list(g)
        record_name = zone.origin in name and name or name + "." + zone.origin

        if record_type not in ('MX', 'SRV'):
            values = map(lambda x: x.data, rcds)
        else:
            values = map(lambda x: "%s %s" % (x.aux, x.data), rcds)
        change = Change(action="CREATE",
                        name=record_name,
                        type=record_type,
                        ttl=rcds[0].ttl,
                        values={'values':values},
                        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((record_type, name, error))
            db.session.rollback()

    if errors:
        return render_template('slicehost/import_zone.html',
                errors=errors,
                zone=zone)

    return redirect(url_for('main.index'))
Exemplo n.º 25
0
def zones_list():
    conn = get_connection()
    response = conn.get_all_hosted_zones()
    zones = response['ListHostedZonesResponse']['HostedZones']
    return render_template('zones/list.html', zones=zones)
Exemplo n.º 26
0
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)
Exemplo n.º 27
0
def 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)
Exemplo n.º 28
0
def index():
    conn = get_connection()
    response = conn.get_all_hosted_zones()
    zones = response['ListHostedZonesResponse']['HostedZones']
    return render_template('zones/list.html', zones=zones)