mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
add public/private/guest network in each type of vm
This commit is contained in:
parent
495e85f452
commit
20b677be10
@ -2691,7 +2691,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||
}
|
||||
|
||||
|
||||
protected Start2Answer execute(Start2Command cmd) {
|
||||
protected synchronized Start2Answer execute(Start2Command cmd) {
|
||||
VirtualMachineTO vmSpec = cmd.getVirtualMachine();
|
||||
String vmName = vmSpec.getName();
|
||||
LibvirtVMDef vm = null;
|
||||
|
||||
@ -111,6 +111,7 @@ import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
@ -150,6 +151,7 @@ import com.cloud.utils.exception.ExecutionException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.State;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
@ -160,6 +162,7 @@ import com.cloud.vm.VirtualMachineName;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VmManager;
|
||||
import com.cloud.vm.dao.ConsoleProxyDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@ -243,6 +246,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
@Inject GuestOSDao _guestOSDao = null;
|
||||
@Inject ServiceOfferingDao _offeringDao;
|
||||
@Inject NetworkOfferingDao _networkOfferingDao;
|
||||
@Inject NicDao _nicDao;
|
||||
@Inject NetworkDao _networkDao;
|
||||
private IpAddrAllocator _IpAllocator;
|
||||
|
||||
private ConsoleProxyListener _listener;
|
||||
@ -403,6 +408,8 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
} else {
|
||||
proxy.setPort(80);
|
||||
}
|
||||
|
||||
|
||||
return proxy;
|
||||
}
|
||||
} finally {
|
||||
@ -2541,6 +2548,26 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
|
||||
s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
|
||||
return false;
|
||||
}
|
||||
|
||||
ConsoleProxyVO proxy = profile.getVirtualMachine();
|
||||
List<NicVO> nics = _nicDao.listBy(proxy.getId());
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
if (network.getTrafficType() == TrafficType.Public) {
|
||||
proxy.setPublicIpAddress(nic.getIp4Address());
|
||||
proxy.setPublicNetmask(nic.getNetmask());
|
||||
proxy.setPublicMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Control) {
|
||||
proxy.setGuestIpAddress(nic.getIp4Address());
|
||||
proxy.setGuestNetmask(nic.getNetmask());
|
||||
proxy.setGuestMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Management) {
|
||||
proxy.setPrivateIpAddress(nic.getIp4Address());
|
||||
proxy.setPrivateNetmask(nic.getNetmask());
|
||||
proxy.setPrivateMacAddress(nic.getMacAddress());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -237,6 +237,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
||||
@Inject VpnUserDao _vpnUsersDao;
|
||||
@Inject RemoteAccessVpnDao _remoteAccessVpnDao;
|
||||
@Inject RulesManager _rulesMgr;
|
||||
@Inject NetworkDao _networkDao;
|
||||
|
||||
long _routerTemplateId = -1;
|
||||
int _routerRamSize;
|
||||
@ -2175,6 +2176,24 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
||||
s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
|
||||
return false;
|
||||
}
|
||||
|
||||
DomainRouterVO router = profile.getVirtualMachine();
|
||||
List<NicVO> nics = _nicDao.listBy(router.getId());
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
if (network.getTrafficType() == TrafficType.Public) {
|
||||
router.setPublicIpAddress(nic.getIp4Address());
|
||||
router.setPublicNetmask(nic.getNetmask());
|
||||
router.setPublicMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Guest) {
|
||||
router.setGuestIpAddress(nic.getIp4Address());
|
||||
router.setGuestMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Control) {
|
||||
router.setPrivateIpAddress(nic.getIp4Address());
|
||||
router.setPrivateNetmask(nic.getNetmask());
|
||||
router.setPrivateMacAddress(nic.getMacAddress());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -91,6 +91,7 @@ import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
@ -130,6 +131,7 @@ import com.cloud.utils.exception.ExecutionException;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.utils.net.NfsUtils;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.SecondaryStorageVmVO;
|
||||
import com.cloud.vm.State;
|
||||
@ -139,6 +141,7 @@ import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.VirtualMachineName;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.vm.VmManager;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.SecondaryStorageVmDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
@ -220,6 +223,8 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
@Inject private AccountService _accountMgr;
|
||||
@Inject GuestOSDao _guestOSDao = null;
|
||||
@Inject private VmManager _itMgr;
|
||||
@Inject private NicDao _nicDao;
|
||||
@Inject private NetworkDao _networkDao;
|
||||
|
||||
private IpAddrAllocator _IpAllocator;
|
||||
|
||||
@ -255,9 +260,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
@Override
|
||||
public SecondaryStorageVmVO startSecStorageVm(long secStorageVmId, long startEventId) {
|
||||
try {
|
||||
|
||||
return start2(secStorageVmId, startEventId);
|
||||
|
||||
} catch (StorageUnavailableException e) {
|
||||
s_logger.warn("Exception while trying to start secondary storage vm", e);
|
||||
return null;
|
||||
@ -2157,6 +2160,24 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
||||
s_logger.warn("Unable to ssh to the VM: " + answer.getDetails());
|
||||
return false;
|
||||
}
|
||||
SecondaryStorageVmVO secVm = profile.getVirtualMachine();
|
||||
List<NicVO> nics = _nicDao.listBy(secVm.getId());
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
if (network.getTrafficType() == TrafficType.Public) {
|
||||
secVm.setPublicIpAddress(nic.getIp4Address());
|
||||
secVm.setPublicNetmask(nic.getNetmask());
|
||||
secVm.setPublicMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Control) {
|
||||
secVm.setGuestIpAddress(nic.getIp4Address());
|
||||
secVm.setGuestNetmask(nic.getNetmask());
|
||||
secVm.setGuestMacAddress(nic.getMacAddress());
|
||||
} else if (network.getTrafficType() == TrafficType.Management) {
|
||||
secVm.setPrivateIpAddress(nic.getIp4Address());
|
||||
secVm.setPrivateNetmask(nic.getNetmask());
|
||||
secVm.setPrivateMacAddress(nic.getMacAddress());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -62,6 +62,8 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.HypervisorGuru;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
import com.cloud.storage.DiskOfferingVO;
|
||||
@ -88,6 +90,7 @@ import com.cloud.vm.ItWorkVO.Type;
|
||||
import com.cloud.vm.VirtualMachine.Event;
|
||||
import com.cloud.vm.dao.ConsoleProxyDao;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.SecondaryStorageVmDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
@ -113,6 +116,8 @@ public class MauriceMoss implements VmManager, ClusterManagerListener {
|
||||
@Inject private DomainRouterDao _routerDao;
|
||||
@Inject private ConsoleProxyDao _consoleDao;
|
||||
@Inject private SecondaryStorageVmDao _secondaryDao;
|
||||
@Inject private NicDao _nicDao;
|
||||
@Inject private NetworkDao _networkDao;
|
||||
|
||||
@Inject(adapter=DeploymentPlanner.class)
|
||||
private Adapters<DeploymentPlanner> _planners;
|
||||
|
||||
@ -204,6 +204,7 @@ import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.dao.DomainRouterDao;
|
||||
import com.cloud.vm.dao.InstanceGroupDao;
|
||||
import com.cloud.vm.dao.InstanceGroupVMMapDao;
|
||||
import com.cloud.vm.dao.NicDao;
|
||||
import com.cloud.vm.dao.UserVmDao;
|
||||
@Local(value={UserVmManager.class, UserVmService.class})
|
||||
public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualMachineGuru<UserVmVO>, Manager, VirtualMachineManager<UserVmVO> {
|
||||
@ -257,6 +258,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
||||
@Inject VmManager _itMgr;
|
||||
@Inject NetworkDao _networkDao;
|
||||
@Inject DomainRouterManager _routerMgr;
|
||||
@Inject NicDao _nicDao;
|
||||
|
||||
private IpAddrAllocator _IpAllocator;
|
||||
ScheduledExecutorService _executor = null;
|
||||
@ -3806,6 +3808,16 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
|
||||
|
||||
@Override
|
||||
public boolean finalizeStart(Commands cmds, VirtualMachineProfile<UserVmVO> profile, DeployDestination dest, ReservationContext context) {
|
||||
UserVmVO userVm = profile.getVirtualMachine();
|
||||
List<NicVO> nics = _nicDao.listBy(userVm.getId());
|
||||
for (NicVO nic : nics) {
|
||||
NetworkVO network = _networkDao.findById(nic.getNetworkId());
|
||||
if (network.getTrafficType() == TrafficType.Guest) {
|
||||
userVm.setPrivateIpAddress(nic.getIp4Address());
|
||||
userVm.setPrivateNetmask(nic.getNetmask());
|
||||
userVm.setPrivateMacAddress(nic.getMacAddress());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user