Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions compute/src/main/java/org/zstack/compute/vm/VmInstanceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -7226,6 +7226,7 @@ protected void scripts() {
self.setZoneUuid(spec.getDestHost().getZoneUuid());
}
}.execute());
syncVmDevicesAddressInfo(self.getUuid());
logger.debug(String.format("vm[uuid:%s] is running ..", self.getUuid()));
VmInstanceInventory inv = VmInstanceInventory.valueOf(self);
extEmitter.afterStartVm(inv);
Expand Down Expand Up @@ -7495,6 +7496,9 @@ public void run(FlowTrigger trigger, Map data) {
self.setHypervisorType(spec.getDestHost().getHypervisorType());
self.setRootVolumeUuid(spec.getDestRootVolume().getUuid());
});
if (struct.getStrategy() == VmCreationStrategy.InstantStart) {
syncVmDevicesAddressInfo(self.getUuid());
}
logger.debug(String.format("vm[uuid:%s] is started ..", self.getUuid()));
VmInstanceInventory inv = VmInstanceInventory.valueOf(self);
extEmitter.afterStartNewCreatedVm(inv);
Expand Down Expand Up @@ -7931,6 +7935,7 @@ public void handle(Map data) {
public void done() {
self = changeVmStateInDb(VmInstanceStateEvent.running,
() -> self.setHostUuid(originalCopy.getHostUuid()));
syncVmDevicesAddressInfo(self.getUuid());
VmInstanceInventory inv = VmInstanceInventory.valueOf(self);
extEmitter.afterRebootVm(inv);
new StaticIpOperator().deleteIpChange(self.getUuid());
Expand Down Expand Up @@ -8347,6 +8352,7 @@ protected void resumeVm(final Message msg, Completion completion) {
@Override
public void handle(Map Data) {
self = changeVmStateInDb(VmInstanceStateEvent.running);
syncVmDevicesAddressInfo(self.getUuid());
completion.success();
}
}).error(new FlowErrorHandler(completion) {
Expand Down Expand Up @@ -8467,6 +8473,30 @@ public String getName() {
});
}

private void syncVmDevicesAddressInfo(String vmUuid) {
VmInstanceVO vmVO = dbf.findByUuid(vmUuid, VmInstanceVO.class);
if (vmVO == null || vmVO.getHostUuid() == null) {
return;
}

SyncVmDeviceInfoMsg msg = new SyncVmDeviceInfoMsg();
msg.setVmInstanceUuid(vmUuid);
msg.setHostUuid(vmVO.getHostUuid());
bus.makeTargetServiceIdByResourceUuid(msg, HostConstant.SERVICE_ID, msg.getHostUuid());
bus.send(msg, new CloudBusCallBack(msg) {
@Override
public void run(MessageReply reply) {
if (!reply.isSuccess()) {
logger.warn(String.format("Failed to sync vm device info for vm[uuid:%s], %s",
vmUuid, reply.getError()));
} else {
logger.debug(String.format("Sent SyncVmDeviceInfoMsg for vm[uuid:%s] on host[uuid:%s]",
vmUuid, vmVO.getHostUuid()));
}
}
});
}

private void deleteVmCdRom(String cdRomUuid, Completion completion) {
boolean exist = dbf.isExist(cdRomUuid, VmCdRomVO.class);
if (!exist) {
Expand Down