mirror of https://github.com/apache/cloudstack.git
1. implement event processing for vm start/stop/destroy, nic create/delete events
2. add dnsrecordurl in nic_details table 3. add dnsrecordurl in vm response
This commit is contained in:
parent
1c1eef3cc7
commit
caf85330bb
|
|
@ -1353,6 +1353,7 @@ public class ApiConstants {
|
|||
public static final String DISABLED = "disabled";
|
||||
public static final String CONTENT_TYPE = "Content-Type";
|
||||
public static final String NATIVE_ZONE = "Native";
|
||||
public static final String NIC_DNS_RECORD = "nicdnsrecord";
|
||||
|
||||
|
||||
public static final String PARAMETER_DESCRIPTION_ACTIVATION_RULE = "Quota tariff's activation rule. It can receive a JS script that results in either " +
|
||||
|
|
|
|||
|
|
@ -45,13 +45,12 @@ import com.cloud.user.Account;
|
|||
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
||||
public class DisassociateDnsZoneFromNetworkCmd extends BaseCmd {
|
||||
|
||||
@Parameter(name = ApiConstants.DNS_ZONE_ID, type = CommandType.UUID, entityType = DnsZoneResponse.class,
|
||||
required = true, description = "The ID of the DNS zone")
|
||||
@Parameter(name = ApiConstants.DNS_ZONE_ID, type = CommandType.UUID, entityType = DnsZoneResponse.class, description = "The ID of the DNS zone")
|
||||
private Long dnsZoneId;
|
||||
|
||||
@ACL(accessType = SecurityChecker.AccessType.OperateEntry)
|
||||
@Parameter(name = ApiConstants.NETWORK_ID, type = CommandType.UUID, entityType = NetworkResponse.class,
|
||||
required = true, description = "The ID of the network")
|
||||
required = true, description = "The ID of the Network")
|
||||
private Long networkId;
|
||||
|
||||
@Override
|
||||
|
|
@ -78,7 +77,7 @@ public class DisassociateDnsZoneFromNetworkCmd extends BaseCmd {
|
|||
return dnsZoneId;
|
||||
}
|
||||
|
||||
public void setDnsZoneId(Long dnsZoneId) {
|
||||
this.dnsZoneId = dnsZoneId;
|
||||
public Long getNetworkId() {
|
||||
return networkId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,6 +146,10 @@ public class NicResponse extends BaseResponse {
|
|||
@Param(description = "Public IP address associated with this NIC via Static NAT rule")
|
||||
private String publicIp;
|
||||
|
||||
@SerializedName("dnsrecordurl")
|
||||
@Param(description = "Public IP address associated with this NIC via Static NAT rule")
|
||||
private String dnsRecordUrl;
|
||||
|
||||
public void setVmId(String vmId) {
|
||||
this.vmId = vmId;
|
||||
}
|
||||
|
|
@ -416,4 +420,8 @@ public class NicResponse extends BaseResponse {
|
|||
public void setPublicIp(String publicIp) {
|
||||
this.publicIp = publicIp;
|
||||
}
|
||||
|
||||
public void setDnsRecordUrl(String dnsRecordUrl) {
|
||||
this.dnsRecordUrl = dnsRecordUrl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,5 +40,5 @@ public interface DnsProvider extends Adapter {
|
|||
String addRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException;
|
||||
List<DnsRecord> listRecords(DnsServer server, DnsZone zone) throws DnsProviderException;
|
||||
String updateRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException;
|
||||
void deleteRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException;
|
||||
String deleteRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,5 +77,5 @@ public interface DnsProviderManager extends Manager, PluggableService {
|
|||
|
||||
void checkDnsServerPermissions(Account caller, DnsServer server);
|
||||
|
||||
boolean processDnsRecordForInstance(VirtualMachine instance, Network network, Nic nic, boolean isAdd);
|
||||
String processDnsRecordForInstance(VirtualMachine instance, Network network, Nic nic, boolean isAdd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ SELECT
|
|||
`nics`.`mac_address` AS `mac_address`,
|
||||
`nics`.`broadcast_uri` AS `broadcast_uri`,
|
||||
`nics`.`isolation_uri` AS `isolation_uri`,
|
||||
`nic_details`.`value` AS `dns_record_url`,
|
||||
`vpc`.`id` AS `vpc_id`,
|
||||
`vpc`.`uuid` AS `vpc_uuid`,
|
||||
`networks`.`uuid` AS `network_uuid`,
|
||||
|
|
@ -185,7 +186,7 @@ SELECT
|
|||
`lease_expiry_action`.`value` AS `lease_expiry_action`,
|
||||
`lease_action_execution`.`value` AS `lease_action_execution`
|
||||
FROM
|
||||
(((((((((((((((((((((((((((((((((((((`user_vm`
|
||||
((((((((((((((((((((((((((((((((((((((`user_vm`
|
||||
JOIN `vm_instance` ON (((`vm_instance`.`id` = `user_vm`.`id`)
|
||||
AND ISNULL(`vm_instance`.`removed`))))
|
||||
JOIN `account` ON ((`vm_instance`.`account_id` = `account`.`id`)))
|
||||
|
|
@ -212,6 +213,7 @@ FROM
|
|||
LEFT JOIN `user_data` ON ((`user_data`.`id` = `user_vm`.`user_data_id`)))
|
||||
LEFT JOIN `nics` ON (((`vm_instance`.`id` = `nics`.`instance_id`)
|
||||
AND ISNULL(`nics`.`removed`))))
|
||||
LEFT JOIN `nic_details` ON ((`nic_details`.`nic_id` = `nics`.`id`) AND (`nic_details`.`name` = 'nicdnsrecord')))
|
||||
LEFT JOIN `networks` ON ((`nics`.`network_id` = `networks`.`id`)))
|
||||
LEFT JOIN `vpc` ON (((`networks`.`vpc_id` = `vpc`.`id`)
|
||||
AND ISNULL(`vpc`.`removed`))))
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ public class PowerDnsClient implements AutoCloseable {
|
|||
HttpPatch request = new HttpPatch(buildUrl(baseUrl, port, "/servers/" + externalServerId + "/zones/" + encodedZone));
|
||||
request.setEntity(new org.apache.http.entity.StringEntity(root.toString(), StandardCharsets.UTF_8));
|
||||
execute(request, apiKey, 204);
|
||||
return normalizedRecord;
|
||||
return normalizedRecord.endsWith(".") ? normalizedRecord.substring(0, normalizedRecord.length() - 1) : normalizedRecord;
|
||||
}
|
||||
|
||||
public Iterable<JsonNode> listRecords(String baseUrl, Integer port, String apiKey, String externalServerId, String zoneName) throws DnsProviderException {
|
||||
|
|
|
|||
|
|
@ -105,9 +105,9 @@ public class PowerDnsProvider extends AdapterBase implements DnsProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deleteRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException {
|
||||
public String deleteRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException {
|
||||
validateRequiredServerAndZoneFields(server, zone);
|
||||
applyRecord(server.getUrl(),
|
||||
return applyRecord(server.getUrl(),
|
||||
server.getPort(),
|
||||
server.getApiKey(),
|
||||
server.getExternalServerId(),
|
||||
|
|
|
|||
|
|
@ -17,14 +17,13 @@
|
|||
package com.cloud.api.query.dao;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
|
@ -34,8 +33,6 @@ import java.util.stream.Collectors;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.gpu.dao.VgpuProfileDao;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupResponse;
|
||||
import org.apache.cloudstack.annotation.AnnotationService;
|
||||
import org.apache.cloudstack.annotation.dao.AnnotationDao;
|
||||
|
|
@ -61,11 +58,13 @@ import com.cloud.api.ApiDBUtils;
|
|||
import com.cloud.api.ApiResponseHelper;
|
||||
import com.cloud.api.query.vo.UserVmJoinVO;
|
||||
import com.cloud.gpu.GPU;
|
||||
import com.cloud.gpu.dao.VgpuProfileDao;
|
||||
import com.cloud.host.ControlState;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.vpc.VpcVO;
|
||||
import com.cloud.network.vpc.dao.VpcDao;
|
||||
import com.cloud.service.ServiceOfferingDetailsVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
import com.cloud.storage.GuestOS;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
|
|
@ -92,9 +91,9 @@ import com.cloud.vm.VMInstanceDetailVO;
|
|||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import com.cloud.vm.VmStats;
|
||||
import com.cloud.vm.dao.NicDetailsDao;
|
||||
import com.cloud.vm.dao.NicExtraDhcpOptionDao;
|
||||
import com.cloud.vm.dao.NicSecondaryIpVO;
|
||||
|
||||
import com.cloud.vm.dao.VMInstanceDetailsDao;
|
||||
|
||||
@Component
|
||||
|
|
@ -128,6 +127,8 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
|
|||
private VgpuProfileDao vgpuProfileDao;
|
||||
@Inject
|
||||
VMTemplateDao vmTemplateDao;
|
||||
@Inject
|
||||
NicDetailsDao nicDetailsDao;
|
||||
|
||||
private final SearchBuilder<UserVmJoinVO> VmDetailSearch;
|
||||
private final SearchBuilder<UserVmJoinVO> activeVmByIsoSearch;
|
||||
|
|
@ -358,6 +359,7 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
|
|||
nicResponse.setIp6Address(userVm.getIp6Address());
|
||||
nicResponse.setIp6Gateway(userVm.getIp6Gateway());
|
||||
nicResponse.setIp6Cidr(userVm.getIp6Cidr());
|
||||
nicResponse.setDnsRecordUrl(userVm.getDnsRecordUrl());
|
||||
if (userVm.getBroadcastUri() != null) {
|
||||
nicResponse.setBroadcastUri(userVm.getBroadcastUri().toString());
|
||||
}
|
||||
|
|
@ -611,6 +613,9 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
|
|||
nicResponse.setIp6Gateway(uvo.getIp6Gateway());
|
||||
/*13: IPv6Cidr*/
|
||||
nicResponse.setIp6Cidr(uvo.getIp6Cidr());
|
||||
/* dnsRecordUrl */
|
||||
nicResponse.setDnsRecordUrl(uvo.getDnsRecordUrl());
|
||||
|
||||
/*14: deviceId*/
|
||||
// where do we find nicResponse.setDeviceId(
|
||||
// this is probably not String.valueOf(uvo.getNicId())); as this is a db-id
|
||||
|
|
|
|||
|
|
@ -32,21 +32,22 @@ import javax.persistence.Temporal;
|
|||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import org.apache.cloudstack.util.HypervisorTypeConverter;
|
||||
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.network.Network.GuestType;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.storage.Storage;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.util.StoragePoolTypeConverter;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import org.apache.cloudstack.util.HypervisorTypeConverter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user_vm_view")
|
||||
|
|
@ -398,6 +399,9 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
|
|||
@Column(name = "public_ip_address")
|
||||
private String publicIpAddress;
|
||||
|
||||
@Column(name = "dns_record_url")
|
||||
private String dnsRecordUrl;
|
||||
|
||||
@Column(name = "user_data", updatable = true, nullable = true, length = 2048)
|
||||
private String userData;
|
||||
|
||||
|
|
@ -1089,4 +1093,8 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
|
|||
public String getLeaseActionExecution() {
|
||||
return leaseActionExecution;
|
||||
}
|
||||
|
||||
public String getDnsRecordUrl() {
|
||||
return dnsRecordUrl;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -441,20 +441,15 @@ public class DnsProviderManagerImpl extends ManagerBase implements DnsProviderMa
|
|||
if (zone == null) {
|
||||
throw new InvalidParameterValueException("DNS zone not found.");
|
||||
}
|
||||
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
accountMgr.checkAccess(caller, null, true, zone);
|
||||
|
||||
DnsServerVO server = dnsServerDao.findById(zone.getDnsServerId());
|
||||
|
||||
try {
|
||||
// Reconstruct the record DTO just for deletion criteria
|
||||
DnsRecord record = new DnsRecord();
|
||||
record.setName(cmd.getName());
|
||||
record.setType(cmd.getType());
|
||||
DnsProvider provider = getProviderByType(server.getProviderType());
|
||||
provider.deleteRecord(server, zone, record);
|
||||
return true;
|
||||
return provider.deleteRecord(server, zone, record) != null;
|
||||
} catch (Exception ex) {
|
||||
logger.error("Failed to delete DNS record via provider", ex);
|
||||
throw new CloudRuntimeException(String.format("Failed to delete DNS record: %s", cmd.getName()));
|
||||
|
|
@ -610,30 +605,30 @@ public class DnsProviderManagerImpl extends ManagerBase implements DnsProviderMa
|
|||
@Override
|
||||
public DnsZoneNetworkMapResponse associateZoneToNetwork(AssociateDnsZoneToNetworkCmd cmd) {
|
||||
Account caller = CallContext.current().getCallingAccount();
|
||||
DnsZoneVO zone = dnsZoneDao.findById(cmd.getDnsZoneId());
|
||||
if (zone == null) {
|
||||
DnsZoneVO dnsZone = dnsZoneDao.findById(cmd.getDnsZoneId());
|
||||
if (dnsZone == null) {
|
||||
throw new InvalidParameterValueException("DNS zone not found.");
|
||||
}
|
||||
accountMgr.checkAccess(caller, null, true, zone);
|
||||
accountMgr.checkAccess(caller, null, true, dnsZone);
|
||||
|
||||
NetworkVO network = networkDao.findById(cmd.getNetworkId());
|
||||
if (network == null) {
|
||||
throw new InvalidParameterValueException("Network not found.");
|
||||
}
|
||||
|
||||
if (!NetworkVO.GuestType.Shared.equals(network.getGuestType())) {
|
||||
throw new CloudRuntimeException(String.format("Operation is not permitted for network type: %s", network.getGuestType()));
|
||||
}
|
||||
accountMgr.checkAccess(caller, null, true, network);
|
||||
DnsZoneNetworkMapVO existing = dnsZoneNetworkMapDao.findByZoneAndNetwork(zone.getId(), network.getId());
|
||||
|
||||
DnsZoneNetworkMapVO existing = dnsZoneNetworkMapDao.findByNetworkId(network.getId());
|
||||
if (existing != null) {
|
||||
throw new InvalidParameterValueException("This DNS zone is already associated with this Network.");
|
||||
throw new InvalidParameterValueException("Network has existing DNS zone associated to it.");
|
||||
}
|
||||
DnsZoneNetworkMapVO mapping = new DnsZoneNetworkMapVO(zone.getId(), network.getId(), cmd.getSubDomain());
|
||||
DnsZoneNetworkMapVO mapping = new DnsZoneNetworkMapVO(dnsZone.getId(), network.getId(), cmd.getSubDomain());
|
||||
dnsZoneNetworkMapDao.persist(mapping);
|
||||
DnsZoneNetworkMapResponse response = new DnsZoneNetworkMapResponse();
|
||||
response.setId(mapping.getUuid());
|
||||
response.setDnsZoneId(zone.getUuid());
|
||||
response.setDnsZoneId(dnsZone.getUuid());
|
||||
response.setNetworkId(network.getUuid());
|
||||
response.setSubDomain(mapping.getSubDomain());
|
||||
return response;
|
||||
|
|
@ -641,10 +636,9 @@ public class DnsProviderManagerImpl extends ManagerBase implements DnsProviderMa
|
|||
|
||||
@Override
|
||||
public boolean disassociateZoneFromNetwork(DisassociateDnsZoneFromNetworkCmd cmd) {
|
||||
// fix this method
|
||||
DnsZoneNetworkMapVO mapping = dnsZoneNetworkMapDao.findById(cmd.getDnsZoneId());
|
||||
DnsZoneNetworkMapVO mapping = dnsZoneNetworkMapDao.findByNetworkId(cmd.getNetworkId());
|
||||
if (mapping == null) {
|
||||
throw new InvalidParameterValueException("The specified DNS zone to network mapping does not exist.");
|
||||
throw new InvalidParameterValueException("No DNS zone is associated to specified network.");
|
||||
}
|
||||
DnsZoneVO zone = dnsZoneDao.findById(mapping.getDnsZoneId());
|
||||
if (zone == null) {
|
||||
|
|
@ -673,67 +667,58 @@ public class DnsProviderManagerImpl extends ManagerBase implements DnsProviderMa
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean processDnsRecordForInstance(VirtualMachine instance, Network network, Nic nic, boolean isAdd) {
|
||||
public String processDnsRecordForInstance(VirtualMachine instance, Network network, Nic nic, boolean isAdd) {
|
||||
long networkId = network.getId();
|
||||
List<DnsZoneNetworkMapVO> mappings = dnsZoneNetworkMapDao.listByNetworkId(networkId);
|
||||
if (mappings == null || mappings.isEmpty()) {
|
||||
logger.warn("No DNS zones are mapped to this network. Please associate a zone first.");
|
||||
return false;
|
||||
DnsZoneNetworkMapVO dnsZoneNetworkMap = dnsZoneNetworkMapDao.findByNetworkId(networkId);
|
||||
if (dnsZoneNetworkMap == null) {
|
||||
logger.warn("No DNS zone is mapped to this network. Please associate a zone first.");
|
||||
return null;
|
||||
}
|
||||
DnsZoneVO dnsZone = dnsZoneDao.findById(dnsZoneNetworkMap.getDnsZoneId());
|
||||
if (dnsZone == null || dnsZone.getState() != DnsZone.State.Active) {
|
||||
return null;
|
||||
}
|
||||
DnsServerVO server = dnsServerDao.findById(dnsZone.getDnsServerId());
|
||||
// Construct FQDN Prefix (e.g., "instance-id" or "instance-id.subdomain")
|
||||
String recordName = String.valueOf(instance.getInstanceName());
|
||||
if (StringUtils.isNotBlank(dnsZoneNetworkMap.getSubDomain())) {
|
||||
recordName = recordName + "." + dnsZoneNetworkMap.getSubDomain();
|
||||
}
|
||||
boolean atLeastOneSuccess = false;
|
||||
for (DnsZoneNetworkMapVO map : mappings) {
|
||||
DnsZoneVO zone = dnsZoneDao.findById(map.getDnsZoneId());
|
||||
if (zone == null || zone.getState() != DnsZone.State.Active) {
|
||||
continue;
|
||||
}
|
||||
DnsServerVO server = dnsServerDao.findById(zone.getDnsServerId());
|
||||
// Construct FQDN Prefix (e.g., "instance-id" or "instance-id.subdomain")
|
||||
String recordName = String.valueOf(instance.getInstanceName());
|
||||
if (StringUtils.isNotBlank(map.getSubDomain())) {
|
||||
recordName = recordName + "." + map.getSubDomain();
|
||||
}
|
||||
|
||||
try {
|
||||
DnsProvider provider = getProviderByType(server.getProviderType());
|
||||
// Handle IPv4 (A Record)
|
||||
if (nic.getIPv4Address() != null) {
|
||||
DnsRecord recordA = new DnsRecord(recordName, DnsRecord.RecordType.A, Collections.singletonList(nic.getIPv4Address()), 3600);
|
||||
if (isAdd) {
|
||||
provider.addRecord(server, zone, recordA);
|
||||
} else {
|
||||
provider.deleteRecord(server, zone, recordA);
|
||||
}
|
||||
atLeastOneSuccess = true;
|
||||
try {
|
||||
DnsProvider provider = getProviderByType(server.getProviderType());
|
||||
// Handle IPv4 (A Record)
|
||||
String ipv4DnsRecord = null;
|
||||
if (nic.getIPv4Address() != null) {
|
||||
DnsRecord recordA = new DnsRecord(recordName, DnsRecord.RecordType.A, Collections.singletonList(nic.getIPv4Address()), 3600);
|
||||
if (isAdd) {
|
||||
ipv4DnsRecord = provider.addRecord(server, dnsZone, recordA);
|
||||
} else {
|
||||
ipv4DnsRecord = provider.deleteRecord(server, dnsZone, recordA);
|
||||
}
|
||||
|
||||
// Handle IPv6 (AAAA Record) if it exists
|
||||
if (nic.getIPv6Address() != null) {
|
||||
DnsRecord recordAAAA = new DnsRecord(recordName, DnsRecord.RecordType.AAAA, Collections.singletonList(nic.getIPv6Address()), 3600);
|
||||
if (isAdd) {
|
||||
provider.addRecord(server, zone, recordAAAA);
|
||||
} else {
|
||||
provider.deleteRecord(server, zone, recordAAAA);
|
||||
}
|
||||
atLeastOneSuccess = true;
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error(
|
||||
"Failed to {} DNS record for Instance {} in zone {}",
|
||||
isAdd ? "register" : "remove",
|
||||
instance.getHostName(),
|
||||
zone.getName(),
|
||||
ex
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!atLeastOneSuccess) {
|
||||
logger.error("Failed to process DNS records. Ensure the Instance has a valid IP address.");
|
||||
return false;
|
||||
// Handle IPv6 (AAAA Record) if it exists
|
||||
String ipv6DnsRecord = null;
|
||||
if (nic.getIPv6Address() != null) {
|
||||
DnsRecord recordAAAA = new DnsRecord(recordName, DnsRecord.RecordType.AAAA, Collections.singletonList(nic.getIPv6Address()), 3600);
|
||||
if (isAdd) {
|
||||
ipv6DnsRecord = provider.addRecord(server, dnsZone, recordAAAA);
|
||||
} else {
|
||||
ipv6DnsRecord = provider.deleteRecord(server, dnsZone, recordAAAA);
|
||||
}
|
||||
}
|
||||
return ipv4DnsRecord != null ? ipv4DnsRecord : ipv6DnsRecord;
|
||||
} catch (Exception ex) {
|
||||
logger.error(
|
||||
"Failed to {} DNS record for Instance {} in zone {}",
|
||||
isAdd ? "register" : "remove",
|
||||
instance.getHostName(),
|
||||
dnsZone.getName(),
|
||||
ex
|
||||
);
|
||||
}
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import com.cloud.vm.Nic;
|
|||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.NicDetailsDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
|
@ -60,6 +61,8 @@ public class DnsVmLifecycleListener extends ManagerBase implements EventSubscrib
|
|||
NicDao nicDao;
|
||||
@Inject
|
||||
DnsProviderManager providerManager;
|
||||
@Inject
|
||||
NicDetailsDao nicDetailsDao;
|
||||
|
||||
@Override
|
||||
public boolean configure(final String name, final Map<String, Object> params) {
|
||||
|
|
@ -69,6 +72,7 @@ public class DnsVmLifecycleListener extends ManagerBase implements EventSubscrib
|
|||
}
|
||||
try {
|
||||
eventBus.subscribe(new EventTopic(null, EventTypes.EVENT_VM_CREATE, null, null, null), this);
|
||||
eventBus.subscribe(new EventTopic(null, EventTypes.EVENT_VM_START, null, null, null), this);
|
||||
eventBus.subscribe(new EventTopic(null, EventTypes.EVENT_VM_STOP, null, null, null), this);
|
||||
eventBus.subscribe(new EventTopic(null, EventTypes.EVENT_VM_DESTROY, null, null, null), this);
|
||||
eventBus.subscribe(new EventTopic(null, EventTypes.EVENT_NIC_CREATE, null, null, null), this);
|
||||
|
|
@ -81,7 +85,6 @@ public class DnsVmLifecycleListener extends ManagerBase implements EventSubscrib
|
|||
|
||||
@Override
|
||||
public void onEvent(Event event) {
|
||||
logger.debug("Received EventBus event: {}", event);
|
||||
JsonNode descJson = parseEventDescription(event);
|
||||
if (!isEventCompleted(descJson)) {
|
||||
return;
|
||||
|
|
@ -89,7 +92,6 @@ public class DnsVmLifecycleListener extends ManagerBase implements EventSubscrib
|
|||
|
||||
String eventType = event.getEventType();
|
||||
String resourceUuid = event.getResourceUUID();
|
||||
logger.debug("Processing Event: {}", event);
|
||||
try {
|
||||
switch (eventType) {
|
||||
case EventTypes.EVENT_VM_CREATE:
|
||||
|
|
@ -112,15 +114,13 @@ public class DnsVmLifecycleListener extends ManagerBase implements EventSubscrib
|
|||
} catch (Exception ex) {
|
||||
logger.error("Failed to process DNS lifecycle event: type={}, resourceUuid={}",
|
||||
eventType, event.getResourceUUID(), ex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void handleNicEvent(JsonNode eventDesc, boolean isAddDnsRecord) {
|
||||
JsonNode nicUuid = eventDesc.get("Nic");
|
||||
JsonNode vmUuid = eventDesc.get("VirtualMachine");
|
||||
JsonNode networkUuid = eventDesc.get("Network");
|
||||
if (nicUuid == null || nicUuid.isNull() || vmUuid == null || vmUuid.isNull() || networkUuid == null || networkUuid.isNull()) {
|
||||
if (nicUuid == null || nicUuid.isNull() || vmUuid == null || vmUuid.isNull()) {
|
||||
logger.warn("Event has missing data to work on: {}", eventDesc);
|
||||
return;
|
||||
}
|
||||
|
|
@ -129,22 +129,17 @@ public class DnsVmLifecycleListener extends ManagerBase implements EventSubscrib
|
|||
logger.error("Unable to find Instance with ID: {}", vmUuid);
|
||||
return;
|
||||
}
|
||||
|
||||
Network network = networkDao.findByUuid(networkUuid.asText());
|
||||
Nic nic = nicDao.findByUuidIncludingRemoved(nicUuid.asText());
|
||||
if (nic == null) {
|
||||
logger.error("NIC is not found for the ID: {}", nicUuid);
|
||||
return;
|
||||
}
|
||||
Network network = networkDao.findById(nic.getNetworkId());
|
||||
if (network == null || !Network.GuestType.Shared.equals(network.getGuestType())) {
|
||||
logger.warn("Network is not eligible for DNS record registration");
|
||||
return;
|
||||
}
|
||||
Nic nic = nicDao.findByUuid(nicUuid.asText());
|
||||
if (nic == null) {
|
||||
logger.error("NIC is not found for the ID: {}", nicUuid);
|
||||
}
|
||||
|
||||
boolean dnsRecordAdded = providerManager.processDnsRecordForInstance(vmInstanceVO, network, nic, isAddDnsRecord);
|
||||
if (!dnsRecordAdded) {
|
||||
logger.error("Failure {} DNS record for Instance: {} for Network with ID: {}",
|
||||
isAddDnsRecord ? "adding" : "removing", vmUuid, networkUuid);
|
||||
}
|
||||
processEventForDnsRecord(vmInstanceVO, network, nic, isAddDnsRecord);
|
||||
}
|
||||
|
||||
private void handleVmEvent(String vmUuid, boolean isAddDnsRecord) {
|
||||
|
|
@ -156,13 +151,24 @@ public class DnsVmLifecycleListener extends ManagerBase implements EventSubscrib
|
|||
List<NicVO> vmNics = nicDao.listByVmId(vmInstanceVO.getId());
|
||||
for (NicVO nic : vmNics) {
|
||||
Network network = networkDao.findById(nic.getNetworkId());
|
||||
if (Network.GuestType.Shared.equals(network.getGuestType())) {
|
||||
boolean dnsRecordAdded = providerManager.processDnsRecordForInstance(vmInstanceVO, network, nic, isAddDnsRecord);
|
||||
if (!dnsRecordAdded) {
|
||||
logger.error("Failure {} DNS record for Instance: {} for Network with ID: {}",
|
||||
isAddDnsRecord ? "adding" : "removing", vmUuid, network.getUuid());
|
||||
}
|
||||
if (network == null || !Network.GuestType.Shared.equals(network.getGuestType())) {
|
||||
continue;
|
||||
}
|
||||
processEventForDnsRecord(vmInstanceVO, network, nic, isAddDnsRecord);
|
||||
}
|
||||
}
|
||||
|
||||
void processEventForDnsRecord(VMInstanceVO vmInstanceVO, Network network, Nic nic, boolean isAddDnsRecord) {
|
||||
String dnsRecordUrl = providerManager.processDnsRecordForInstance(vmInstanceVO, network, nic, isAddDnsRecord);
|
||||
if (dnsRecordUrl != null) {
|
||||
if (isAddDnsRecord) {
|
||||
nicDetailsDao.addDetail(nic.getId(), ApiConstants.NIC_DNS_RECORD, dnsRecordUrl, true);
|
||||
} else {
|
||||
nicDetailsDao.removeDetail(nic.getId(), ApiConstants.NIC_DNS_RECORD);
|
||||
}
|
||||
} else {
|
||||
logger.error("Failure {} DNS record for Instance: {} for Network with ID: {}",
|
||||
isAddDnsRecord ? "adding" : "removing", vmInstanceVO.getUuid(), network.getUuid());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -188,6 +194,8 @@ public class DnsVmLifecycleListener extends ManagerBase implements EventSubscrib
|
|||
if (statusNode == null || statusNode.isNull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
logger.debug("Processing Event: {}", descJson);
|
||||
return ApiConstants.COMPLETED.equalsIgnoreCase(statusNode.asText());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,11 @@
|
|||
|
||||
package org.apache.cloudstack.dns.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.dns.vo.DnsZoneNetworkMapVO;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface DnsZoneNetworkMapDao extends GenericDao<DnsZoneNetworkMapVO, Long> {
|
||||
DnsZoneNetworkMapVO findByZoneAndNetwork(long dnsZoneId, long networkId);
|
||||
List<DnsZoneNetworkMapVO> listByNetworkId(long networkId);
|
||||
DnsZoneNetworkMapVO findByNetworkId(long networkId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
package org.apache.cloudstack.dns.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.dns.vo.DnsZoneNetworkMapVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -54,9 +52,9 @@ public class DnsZoneNetworkMapDaoImpl extends GenericDaoBase<DnsZoneNetworkMapVO
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<DnsZoneNetworkMapVO> listByNetworkId(long networkId) {
|
||||
public DnsZoneNetworkMapVO findByNetworkId(long networkId) {
|
||||
SearchCriteria<DnsZoneNetworkMapVO> sc = NetworkSearch.create();
|
||||
sc.setParameters(ApiConstants.NETWORK_ID, networkId);
|
||||
return listBy(sc);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@
|
|||
<a-descriptions-item :label="$t('label.isolationuri')" v-if="record.isolationuri">
|
||||
{{ record.isolationuri }}
|
||||
</a-descriptions-item>
|
||||
|
||||
<a-descriptions-item :label="$t('label.dns_url')" v-if="record.dns_url">
|
||||
{{ record.dns_url }}
|
||||
</a-descriptions-item>
|
||||
</template>
|
||||
</a-descriptions>
|
||||
</template>
|
||||
|
|
|
|||
Loading…
Reference in New Issue