This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch 4.18
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.18 by this push:
new a8700bff7f7 server: set Default NIC when VM has no default NIC (#7859)
a8700bff7f7 is described below
commit a8700bff7f713cdb60ed96552a4cedaf1872dee6
Author: sato03 <[email protected]>
AuthorDate: Fri Oct 20 06:40:10 2023 -0300
server: set Default NIC when VM has no default NIC (#7859)
Co-authored-by: Henrique Sato <[email protected]>
---
.../engine/orchestration/NetworkOrchestrator.java | 14 +++++++++++++-
server/src/main/java/com/cloud/vm/UserVmManagerImpl.java | 14 ++++++++++++++
ui/public/locales/en.json | 1 +
ui/public/locales/pt_BR.json | 1 +
ui/src/views/tools/ImportUnmanagedInstance.vue | 7 +++++++
5 files changed, 36 insertions(+), 1 deletion(-)
diff --git
a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index 11e27de8e99..ba9ef03ede6 100644
---
a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++
b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@ -4331,7 +4331,9 @@ public class NetworkOrchestrator extends ManagerBase
implements NetworkOrchestra
if (nic == null || vmProfile.getType() == VirtualMachine.Type.User) {
final int deviceId = _nicDao.getFreeDeviceId(vm.getId());
- nic = allocateNic(requested, network, false, deviceId,
vmProfile).first();
+ boolean isDefaultNic = getNicProfileDefaultNic(requested);
+
+ nic = allocateNic(requested, network, isDefaultNic, deviceId,
vmProfile).first();
if (nic == null) {
throw new CloudRuntimeException("Failed to allocate nic for vm
" + vm + " in network " + network);
@@ -4359,6 +4361,16 @@ public class NetworkOrchestrator extends ManagerBase
implements NetworkOrchestra
return nic;
}
+ private boolean getNicProfileDefaultNic(NicProfile nicProfile) {
+ if (nicProfile != null) {
+ s_logger.debug(String.format("Using requested nic profile
isDefaultNic value [%s].", nicProfile.isDefaultNic()));
+ return nicProfile.isDefaultNic();
+ }
+
+ s_logger.debug("Using isDefaultNic default value [false] as requested
nic profile is null.");
+ return false;
+ }
+
@Override
public List<NicProfile> getNicProfiles(final VirtualMachine vm) {
final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
diff --git a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
index c9085b385f5..d2314198d0f 100644
--- a/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
+++ b/server/src/main/java/com/cloud/vm/UserVmManagerImpl.java
@@ -1425,6 +1425,8 @@ public class UserVmManagerImpl extends ManagerBase
implements UserVmManager, Vir
}
}
+ setNicAsDefaultIfNeeded(vmInstance, profile);
+
NicProfile guestNic = null;
boolean cleanUp = true;
@@ -1453,6 +1455,18 @@ public class UserVmManagerImpl extends ManagerBase
implements UserVmManager, Vir
return _vmDao.findById(vmInstance.getId());
}
+ /**
+ * Set NIC as default if VM has no default NIC
+ * @param vmInstance VM instance to be checked
+ * @param nicProfile NIC profile to be updated
+ */
+ public void setNicAsDefaultIfNeeded(UserVmVO vmInstance, NicProfile
nicProfile) {
+ if (_networkModel.getDefaultNic(vmInstance.getId()) == null) {
+ s_logger.debug(String.format("Setting NIC %s as default as VM %s
has no default NIC.", nicProfile.getName(), vmInstance.getName()));
+ nicProfile.setDefaultNic(true);
+ }
+ }
+
/**
* duplicated in {@see VirtualMachineManagerImpl} for a {@see VMInstanceVO}
*/
diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json
index 824638efa4d..55f07357de9 100644
--- a/ui/public/locales/en.json
+++ b/ui/public/locales/en.json
@@ -3079,6 +3079,7 @@
"message.vr.alert.upon.network.offering.creation.l2": "As virtual routers are
not created for L2 networks, the compute offering will not be used.",
"message.vr.alert.upon.network.offering.creation.others": "As none of the
obligatory services for creating a virtual router (VPN, DHCP, DNS, Firewall,
LB, UserData, SourceNat, StaticNat, PortForwarding) are enabled, the virtual
router will not be created and the compute offering will not be used.",
"message.warn.filetype": "jpg, jpeg, png, bmp and svg are the only supported
image formats.",
+"message.warn.importing.instance.without.nic": "WARNING: this instance is
being imported without NICs and many network resources will not be available.
Consider creating a NIC via VCenter before importing or as soon as the instance
is imported.",
"message.warn.zone.mtu.update": "Please note that this limit won't affect
pre-existing network’s MTU settings",
"message.zone.creation.complete": "Zone creation complete.",
"message.zone.detail.description": "Populate zone details.",
diff --git a/ui/public/locales/pt_BR.json b/ui/public/locales/pt_BR.json
index 712d9f13623..c95bb5b90e1 100644
--- a/ui/public/locales/pt_BR.json
+++ b/ui/public/locales/pt_BR.json
@@ -2475,6 +2475,7 @@
"message.vr.alert.upon.network.offering.creation.l2": "Como VRs não são
criados para redes do tipo L2, a oferta de computação não será utilizada.",
"message.vr.alert.upon.network.offering.creation.others": "Como nenhum dos
serviços obrigatórios para criação do VR (VPN, DHCP, DNS, Firewall, LB,
UserData, SourceNat, StaticNat, PortForwarding) foram habilitados, o VR não
será criado e a oferta de computação não será usada.",
"message.warn.filetype": "jpg, jpeg, png, bmp e svg s\u00e3o os \u00fanicos
formatos de imagem suportados",
+"message.warn.importing.instance.without.nic": "AVISO: essa instância está
sendo importada sem NICs e muitos recursos de rede não estarão disponíveis.
Considere criar uma NIC antes de importar via VCenter ou assim que a instância
for importada.",
"message.zone.creation.complete": "Cria\u00e7\u00e3o de zona completa",
"message.zone.detail.description": "Preencha os detalhes da zona",
"message.zone.detail.hint": "Uma zona \u00e9 a maior unidade organizacional no
CloudStack, e normalmente corresponde a um \u00fanico datacenter. As zonas
proporcionam isolamento f\u00edsico e redund\u00e2ncia. Uma zona consiste em um
ou mais pods (cada um contendo hosts e servidores de armazenamento
prim\u00e1rio) e um servidor de armazenamento secund\u00e1rio que \u00e9
compartilhado por todos os pods da zona.",
diff --git a/ui/src/views/tools/ImportUnmanagedInstance.vue
b/ui/src/views/tools/ImportUnmanagedInstance.vue
index 1e5629ba51a..6d90f72c5ee 100644
--- a/ui/src/views/tools/ImportUnmanagedInstance.vue
+++ b/ui/src/views/tools/ImportUnmanagedInstance.vue
@@ -227,6 +227,13 @@
filterMatchKey="broadcasturi"
@select-multi-network="updateMultiNetworkOffering" />
</div>
+ <a-row v-else style="margin: 12px 0">
+ <a-alert type="warning">
+ <template #message>
+ <div
v-html="$t('message.warn.importing.instance.without.nic')"></div>
+ </template>
+ </a-alert>
+ </a-row>
<a-row :gutter="12">
<a-col :md="24" :lg="12">
<a-form-item name="migrateallowed" ref="migrateallowed">