Skip to content

Commit caf8533

Browse files
committed
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
1 parent 1c1eef3 commit caf8533

File tree

15 files changed

+137
-121
lines changed

15 files changed

+137
-121
lines changed

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,7 @@ public class ApiConstants {
13531353
public static final String DISABLED = "disabled";
13541354
public static final String CONTENT_TYPE = "Content-Type";
13551355
public static final String NATIVE_ZONE = "Native";
1356+
public static final String NIC_DNS_RECORD = "nicdnsrecord";
13561357

13571358

13581359
public static final String PARAMETER_DESCRIPTION_ACTIVATION_RULE = "Quota tariff's activation rule. It can receive a JS script that results in either " +

api/src/main/java/org/apache/cloudstack/api/command/user/dns/DisassociateDnsZoneFromNetworkCmd.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@
4545
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
4646
public class DisassociateDnsZoneFromNetworkCmd extends BaseCmd {
4747

48-
@Parameter(name = ApiConstants.DNS_ZONE_ID, type = CommandType.UUID, entityType = DnsZoneResponse.class,
49-
required = true, description = "The ID of the DNS zone")
48+
@Parameter(name = ApiConstants.DNS_ZONE_ID, type = CommandType.UUID, entityType = DnsZoneResponse.class, description = "The ID of the DNS zone")
5049
private Long dnsZoneId;
5150

5251
@ACL(accessType = SecurityChecker.AccessType.OperateEntry)
5352
@Parameter(name = ApiConstants.NETWORK_ID, type = CommandType.UUID, entityType = NetworkResponse.class,
54-
required = true, description = "The ID of the network")
53+
required = true, description = "The ID of the Network")
5554
private Long networkId;
5655

5756
@Override
@@ -78,7 +77,7 @@ public Long getDnsZoneId() {
7877
return dnsZoneId;
7978
}
8079

81-
public void setDnsZoneId(Long dnsZoneId) {
82-
this.dnsZoneId = dnsZoneId;
80+
public Long getNetworkId() {
81+
return networkId;
8382
}
8483
}

api/src/main/java/org/apache/cloudstack/api/response/NicResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public class NicResponse extends BaseResponse {
146146
@Param(description = "Public IP address associated with this NIC via Static NAT rule")
147147
private String publicIp;
148148

149+
@SerializedName("dnsrecordurl")
150+
@Param(description = "Public IP address associated with this NIC via Static NAT rule")
151+
private String dnsRecordUrl;
152+
149153
public void setVmId(String vmId) {
150154
this.vmId = vmId;
151155
}
@@ -416,4 +420,8 @@ public void setPublicIpId(String publicIpId) {
416420
public void setPublicIp(String publicIp) {
417421
this.publicIp = publicIp;
418422
}
423+
424+
public void setDnsRecordUrl(String dnsRecordUrl) {
425+
this.dnsRecordUrl = dnsRecordUrl;
426+
}
419427
}

api/src/main/java/org/apache/cloudstack/dns/DnsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ public interface DnsProvider extends Adapter {
4040
String addRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException;
4141
List<DnsRecord> listRecords(DnsServer server, DnsZone zone) throws DnsProviderException;
4242
String updateRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException;
43-
void deleteRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException;
43+
String deleteRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException;
4444
}

api/src/main/java/org/apache/cloudstack/dns/DnsProviderManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,5 @@ public interface DnsProviderManager extends Manager, PluggableService {
7777

7878
void checkDnsServerPermissions(Account caller, DnsServer server);
7979

80-
boolean processDnsRecordForInstance(VirtualMachine instance, Network network, Nic nic, boolean isAdd);
80+
String processDnsRecordForInstance(VirtualMachine instance, Network network, Nic nic, boolean isAdd);
8181
}

engine/schema/src/main/resources/META-INF/db/views/cloud.user_vm_view.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ SELECT
141141
`nics`.`mac_address` AS `mac_address`,
142142
`nics`.`broadcast_uri` AS `broadcast_uri`,
143143
`nics`.`isolation_uri` AS `isolation_uri`,
144+
`nic_details`.`value` AS `dns_record_url`,
144145
`vpc`.`id` AS `vpc_id`,
145146
`vpc`.`uuid` AS `vpc_uuid`,
146147
`networks`.`uuid` AS `network_uuid`,
@@ -185,7 +186,7 @@ SELECT
185186
`lease_expiry_action`.`value` AS `lease_expiry_action`,
186187
`lease_action_execution`.`value` AS `lease_action_execution`
187188
FROM
188-
(((((((((((((((((((((((((((((((((((((`user_vm`
189+
((((((((((((((((((((((((((((((((((((((`user_vm`
189190
JOIN `vm_instance` ON (((`vm_instance`.`id` = `user_vm`.`id`)
190191
AND ISNULL(`vm_instance`.`removed`))))
191192
JOIN `account` ON ((`vm_instance`.`account_id` = `account`.`id`)))
@@ -212,6 +213,7 @@ FROM
212213
LEFT JOIN `user_data` ON ((`user_data`.`id` = `user_vm`.`user_data_id`)))
213214
LEFT JOIN `nics` ON (((`vm_instance`.`id` = `nics`.`instance_id`)
214215
AND ISNULL(`nics`.`removed`))))
216+
LEFT JOIN `nic_details` ON ((`nic_details`.`nic_id` = `nics`.`id`) AND (`nic_details`.`name` = 'nicdnsrecord')))
215217
LEFT JOIN `networks` ON ((`nics`.`network_id` = `networks`.`id`)))
216218
LEFT JOIN `vpc` ON (((`networks`.`vpc_id` = `vpc`.`id`)
217219
AND ISNULL(`vpc`.`removed`))))

plugins/dns/powerdns/src/main/java/org/apache/cloudstack/dns/powerdns/PowerDnsClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public String modifyRecord(String baseUrl, Integer port, String apiKey, String e
223223
HttpPatch request = new HttpPatch(buildUrl(baseUrl, port, "/servers/" + externalServerId + "/zones/" + encodedZone));
224224
request.setEntity(new org.apache.http.entity.StringEntity(root.toString(), StandardCharsets.UTF_8));
225225
execute(request, apiKey, 204);
226-
return normalizedRecord;
226+
return normalizedRecord.endsWith(".") ? normalizedRecord.substring(0, normalizedRecord.length() - 1) : normalizedRecord;
227227
}
228228

229229
public Iterable<JsonNode> listRecords(String baseUrl, Integer port, String apiKey, String externalServerId, String zoneName) throws DnsProviderException {

plugins/dns/powerdns/src/main/java/org/apache/cloudstack/dns/powerdns/PowerDnsProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ public String updateRecord(DnsServer server, DnsZone zone, DnsRecord record) thr
105105
}
106106

107107
@Override
108-
public void deleteRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException {
108+
public String deleteRecord(DnsServer server, DnsZone zone, DnsRecord record) throws DnsProviderException {
109109
validateRequiredServerAndZoneFields(server, zone);
110-
applyRecord(server.getUrl(),
110+
return applyRecord(server.getUrl(),
111111
server.getPort(),
112112
server.getApiKey(),
113113
server.getExternalServerId(),

server/src/main/java/com/cloud/api/query/dao/UserVmJoinDaoImpl.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
package com.cloud.api.query.dao;
1818

1919
import java.text.DecimalFormat;
20-
import java.util.ArrayList;
21-
import java.util.Collections;
2220
import java.time.LocalDate;
2321
import java.time.ZoneId;
2422
import java.time.temporal.ChronoUnit;
23+
import java.util.ArrayList;
2524
import java.util.Calendar;
25+
import java.util.Collections;
2626
import java.util.Date;
27-
2827
import java.util.HashMap;
2928
import java.util.Hashtable;
3029
import java.util.List;
@@ -34,8 +33,6 @@
3433

3534
import javax.inject.Inject;
3635

37-
import com.cloud.gpu.dao.VgpuProfileDao;
38-
import com.cloud.service.dao.ServiceOfferingDao;
3936
import org.apache.cloudstack.affinity.AffinityGroupResponse;
4037
import org.apache.cloudstack.annotation.AnnotationService;
4138
import org.apache.cloudstack.annotation.dao.AnnotationDao;
@@ -61,11 +58,13 @@
6158
import com.cloud.api.ApiResponseHelper;
6259
import com.cloud.api.query.vo.UserVmJoinVO;
6360
import com.cloud.gpu.GPU;
61+
import com.cloud.gpu.dao.VgpuProfileDao;
6462
import com.cloud.host.ControlState;
6563
import com.cloud.network.IpAddress;
6664
import com.cloud.network.vpc.VpcVO;
6765
import com.cloud.network.vpc.dao.VpcDao;
6866
import com.cloud.service.ServiceOfferingDetailsVO;
67+
import com.cloud.service.dao.ServiceOfferingDao;
6968
import com.cloud.storage.DiskOfferingVO;
7069
import com.cloud.storage.GuestOS;
7170
import com.cloud.storage.Storage.TemplateType;
@@ -92,9 +91,9 @@
9291
import com.cloud.vm.VirtualMachine;
9392
import com.cloud.vm.VirtualMachine.State;
9493
import com.cloud.vm.VmStats;
94+
import com.cloud.vm.dao.NicDetailsDao;
9595
import com.cloud.vm.dao.NicExtraDhcpOptionDao;
9696
import com.cloud.vm.dao.NicSecondaryIpVO;
97-
9897
import com.cloud.vm.dao.VMInstanceDetailsDao;
9998

10099
@Component
@@ -128,6 +127,8 @@ public class UserVmJoinDaoImpl extends GenericDaoBaseWithTagInformation<UserVmJo
128127
private VgpuProfileDao vgpuProfileDao;
129128
@Inject
130129
VMTemplateDao vmTemplateDao;
130+
@Inject
131+
NicDetailsDao nicDetailsDao;
131132

132133
private final SearchBuilder<UserVmJoinVO> VmDetailSearch;
133134
private final SearchBuilder<UserVmJoinVO> activeVmByIsoSearch;
@@ -358,6 +359,7 @@ public UserVmResponse newUserVmResponse(ResponseView view, String objectName, Us
358359
nicResponse.setIp6Address(userVm.getIp6Address());
359360
nicResponse.setIp6Gateway(userVm.getIp6Gateway());
360361
nicResponse.setIp6Cidr(userVm.getIp6Cidr());
362+
nicResponse.setDnsRecordUrl(userVm.getDnsRecordUrl());
361363
if (userVm.getBroadcastUri() != null) {
362364
nicResponse.setBroadcastUri(userVm.getBroadcastUri().toString());
363365
}
@@ -611,6 +613,9 @@ public UserVmResponse setUserVmResponse(ResponseView view, UserVmResponse userVm
611613
nicResponse.setIp6Gateway(uvo.getIp6Gateway());
612614
/*13: IPv6Cidr*/
613615
nicResponse.setIp6Cidr(uvo.getIp6Cidr());
616+
/* dnsRecordUrl */
617+
nicResponse.setDnsRecordUrl(uvo.getDnsRecordUrl());
618+
614619
/*14: deviceId*/
615620
// where do we find nicResponse.setDeviceId(
616621
// this is probably not String.valueOf(uvo.getNicId())); as this is a db-id

server/src/main/java/com/cloud/api/query/vo/UserVmJoinVO.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,22 @@
3232
import javax.persistence.TemporalType;
3333
import javax.persistence.Transient;
3434

35+
import org.apache.cloudstack.util.HypervisorTypeConverter;
36+
3537
import com.cloud.host.Status;
3638
import com.cloud.hypervisor.Hypervisor.HypervisorType;
3739
import com.cloud.network.Network.GuestType;
3840
import com.cloud.network.Networks.TrafficType;
3941
import com.cloud.resource.ResourceState;
4042
import com.cloud.storage.Storage;
41-
import com.cloud.storage.Storage.TemplateType;
4243
import com.cloud.storage.Storage.StoragePoolType;
44+
import com.cloud.storage.Storage.TemplateType;
4345
import com.cloud.storage.Volume;
4446
import com.cloud.user.Account;
4547
import com.cloud.util.StoragePoolTypeConverter;
4648
import com.cloud.utils.db.GenericDao;
4749
import com.cloud.vm.VirtualMachine;
4850
import com.cloud.vm.VirtualMachine.State;
49-
import org.apache.cloudstack.util.HypervisorTypeConverter;
5051

5152
@Entity
5253
@Table(name = "user_vm_view")
@@ -398,6 +399,9 @@ public class UserVmJoinVO extends BaseViewWithTagInformationVO implements Contro
398399
@Column(name = "public_ip_address")
399400
private String publicIpAddress;
400401

402+
@Column(name = "dns_record_url")
403+
private String dnsRecordUrl;
404+
401405
@Column(name = "user_data", updatable = true, nullable = true, length = 2048)
402406
private String userData;
403407

@@ -1089,4 +1093,8 @@ public void setLeaseExpiryAction(String leaseExpiryAction) {
10891093
public String getLeaseActionExecution() {
10901094
return leaseActionExecution;
10911095
}
1096+
1097+
public String getDnsRecordUrl() {
1098+
return dnsRecordUrl;
1099+
}
10921100
}

0 commit comments

Comments
 (0)