Search in sources :

Example 6 with CreateOrUpdateRecordAndReverseCommand

use of com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand in project cloudstack by apache.

the class GloboDnsResourceTest method testCreateRecordAndReverseWillFailWhenRecordAlreadyExistsAndOverrideIsFalse.

@Test
@SuppressWarnings("unused")
public void testCreateRecordAndReverseWillFailWhenRecordAlreadyExistsAndOverrideIsFalse() throws Exception {
    String recordName = "recordname";
    String newIp = "40.30.20.10";
    String oldIp = "50.40.30.20";
    String domainName = "domain.name.com";
    Domain domain = generateFakeDomain(domainName, false);
    Record record = generateFakeRecord(domain, recordName, oldIp, false);
    Answer answer = _globoDnsResource.execute(new CreateOrUpdateRecordAndReverseCommand(recordName, newIp, domainName, TEMPLATE_ID, false));
    assertNotNull(answer);
    assertEquals(false, answer.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) Record(com.globo.globodns.client.model.Record) Domain(com.globo.globodns.client.model.Domain) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) Test(org.junit.Test)

Example 7 with CreateOrUpdateRecordAndReverseCommand

use of com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand in project cloudstack by apache.

the class GloboDnsElement method prepare.

@Override
@DB
public boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    if (!isTypeSupported(vm.getType())) {
        s_logger.info("GloboDNS only manages records for VMs of type User, ConsoleProxy and DomainRouter. VM " + vm + " is " + vm.getType());
        return false;
    }
    Long zoneId = network.getDataCenterId();
    final DataCenter zone = _dcDao.findById(zoneId);
    if (zone == null) {
        throw new CloudRuntimeException("Could not find zone associated to this network");
    }
    /* Create new A record in GloboDNS */
    // We allow only lower case names in DNS, so force lower case names for VMs
    String vmName = vm.getHostName();
    String vmHostname = hostNameOfVirtualMachine(vm);
    if (!vmName.equals(vmHostname) && vm.getType() == VirtualMachine.Type.User) {
        throw new InvalidParameterValueException("VM name should contain only lower case letters and digits: " + vmName + " - " + vm);
    }
    CreateOrUpdateRecordAndReverseCommand cmd = new CreateOrUpdateRecordAndReverseCommand(vmHostname, nic.getIPv4Address(), network.getNetworkDomain(), GloboDNSTemplateId.value(), GloboDNSOverride.value());
    callCommand(cmd, zoneId);
    return true;
}
Also used : DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateOrUpdateRecordAndReverseCommand(com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand) DB(com.cloud.utils.db.DB)

Aggregations

CreateOrUpdateRecordAndReverseCommand (com.globo.globodns.cloudstack.commands.CreateOrUpdateRecordAndReverseCommand)7 Answer (com.cloud.agent.api.Answer)6 Domain (com.globo.globodns.client.model.Domain)6 Record (com.globo.globodns.client.model.Record)6 Test (org.junit.Test)6 DataCenter (com.cloud.dc.DataCenter)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 DB (com.cloud.utils.db.DB)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 InOrder (org.mockito.InOrder)1