Search in sources :

Example 1 with DnsZone

use of org.platformlayer.service.dns.model.DnsZone in project platformlayer by platformlayer.

the class DnsHelpers method buildDnsFile.

public ZoneFile buildDnsFile(DnsRecord dnsRecord) throws OpsException {
    List<DnsZone> matches = Lists.newArrayList();
    for (DnsZone dnsZone : platformLayer.listItems(DnsZone.class)) {
        if (isInZone(dnsRecord, dnsZone)) {
            matches.add(dnsZone);
        }
    }
    if (matches.size() == 0) {
        throw new OpsException("Cannot find zone for record: " + dnsRecord.dnsName);
    }
    if (matches.size() != 1) {
        throw new OpsException("Picking between multiple matching zones not yet implemented");
    }
    DnsZone dnsZone = matches.get(0);
    return buildDnsFile(dnsZone);
}
Also used : OpsException(org.platformlayer.ops.OpsException) DnsZone(org.platformlayer.service.dns.model.DnsZone)

Example 2 with DnsZone

use of org.platformlayer.service.dns.model.DnsZone in project platformlayer by platformlayer.

the class DnsServerBootstrap method handler.

@Handler
public void handler(OpsTarget target) throws OpsException {
    for (DnsZone record : platformLayer.listItems(DnsZone.class)) {
        ZoneFile dnsFile = dns.buildDnsFile(record);
        dns.upload(target, dnsFile);
    }
}
Also used : DnsZone(org.platformlayer.service.dns.model.DnsZone) Handler(org.platformlayer.ops.Handler)

Example 3 with DnsZone

use of org.platformlayer.service.dns.model.DnsZone in project platformlayer by platformlayer.

the class DnsService method beforeCreateItem.

@Override
public void beforeCreateItem(ItemBase item) throws OpsException {
    if (item instanceof DnsServer) {
        DnsServer model = (DnsServer) item;
        model.dnsName = normalize(model.dnsName);
        if (Strings.isNullOrEmpty(model.dnsName)) {
            throw new IllegalArgumentException("dnsName must be specified");
        }
    }
    if (item instanceof DnsRecord) {
        DnsRecord model = (DnsRecord) item;
        model.dnsName = normalize(model.dnsName);
        if (Strings.isNullOrEmpty(model.dnsName)) {
            throw new IllegalArgumentException("dnsName must be specified");
        }
        if (Strings.isNullOrEmpty(model.recordType)) {
            model.recordType = "A";
        }
        if (model.recordType.equals("A")) {
        // OK
        } else {
            throw new IllegalArgumentException("Record type not supported: " + model.recordType);
        }
    }
    if (item instanceof DnsZone) {
        DnsZone model = (DnsZone) item;
        model.dnsName = normalize(model.dnsName);
        if (Strings.isNullOrEmpty(model.dnsName)) {
            model.dnsName = normalize(model.getId());
        }
    }
    super.beforeCreateItem(item);
}
Also used : DnsRecord(org.platformlayer.dns.model.DnsRecord) DnsServer(org.platformlayer.service.dns.model.DnsServer) DnsZone(org.platformlayer.service.dns.model.DnsZone)

Aggregations

DnsZone (org.platformlayer.service.dns.model.DnsZone)3 DnsRecord (org.platformlayer.dns.model.DnsRecord)1 Handler (org.platformlayer.ops.Handler)1 OpsException (org.platformlayer.ops.OpsException)1 DnsServer (org.platformlayer.service.dns.model.DnsServer)1