use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method finalizeCommandsOnStart.
@Override
public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) {
final DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId());
final NicProfile controlNic = getNicProfileByTrafficType(profile, TrafficType.Control);
if (controlNic == null) {
s_logger.error("Control network doesn't exist for the internal LB vm " + internalLbVm);
return false;
}
finalizeSshAndVersionOnStart(cmds, profile, internalLbVm, controlNic);
// restart network if restartNetwork = false is not specified in profile parameters
boolean reprogramGuestNtwk = true;
if (profile.getParameter(Param.ReProgramGuestNetworks) != null && (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
reprogramGuestNtwk = false;
}
final VirtualRouterProvider lbProvider = _vrProviderDao.findById(internalLbVm.getElementId());
if (lbProvider == null) {
throw new CloudRuntimeException("Cannot find related element " + Type.InternalLbVm + " of vm: " + internalLbVm.getHostName());
}
final Provider provider = Network.Provider.getProvider(lbProvider.getType().toString());
if (provider == null) {
throw new CloudRuntimeException("Cannot find related provider of provider: " + lbProvider.getType().toString());
}
if (reprogramGuestNtwk) {
final NicProfile guestNic = getNicProfileByTrafficType(profile, TrafficType.Guest);
finalizeLbRulesForIp(cmds, internalLbVm, provider, new Ip(guestNic.getIPv4Address()), guestNic.getNetworkId());
}
return true;
}
use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class NetworkModelImpl method getNicProfile.
@Override
public NicProfile getNicProfile(VirtualMachine vm, long networkId, String broadcastUri) {
NicVO nic = null;
if (broadcastUri != null) {
nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri(networkId, vm.getId(), broadcastUri);
} else {
nic = _nicDao.findByNtwkIdAndInstanceId(networkId, vm.getId());
}
if (nic == null) {
return null;
}
NetworkVO network = _networksDao.findById(networkId);
Integer networkRate = getNetworkRate(network.getId(), vm.getId());
// NetworkGuru guru = _networkGurus.get(network.getGuruName());
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
// guru.updateNicProfile(profile, network);
return profile;
}
use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class HypervGuru method implement.
@Override
public final VirtualMachineTO implement(VirtualMachineProfile vm) {
VirtualMachineTO to = toVirtualMachineTO(vm);
List<NicProfile> nicProfiles = vm.getNics();
if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) {
NicProfile publicNicProfile = null;
NicProfile controlNicProfile = null;
NicProfile profile = null;
for (NicProfile nicProfile : nicProfiles) {
if (nicProfile.getTrafficType() == TrafficType.Public) {
publicNicProfile = nicProfile;
break;
} else if (nicProfile.getTrafficType() == TrafficType.Control) {
controlNicProfile = nicProfile;
}
}
if (publicNicProfile != null || controlNicProfile != null) {
NicTO[] nics = to.getNics();
// reserve extra NICs
NicTO[] expandedNics = new NicTO[MaxNicSupported];
int i = 0;
int deviceId = -1;
for (i = 0; i < nics.length; i++) {
expandedNics[i] = nics[i];
if (nics[i].getDeviceId() > deviceId)
deviceId = nics[i].getDeviceId();
}
deviceId++;
long networkId = 0;
if (publicNicProfile != null) {
networkId = publicNicProfile.getNetworkId();
profile = publicNicProfile;
} else {
networkId = controlNicProfile.getNetworkId();
profile = controlNicProfile;
}
NetworkVO network = _networkDao.findById(networkId);
// creating the VR with extra nics (actual nics(3) + extra nics) will be 8
for (; i < MaxNicSupported; i++) {
NicTO nicTo = new NicTO();
nicTo.setDeviceId(deviceId++);
nicTo.setBroadcastType(BroadcastDomainType.Vlan);
nicTo.setType(TrafficType.Public);
nicTo.setIp("0.0.0.0");
nicTo.setNetmask("255.255.255.255");
nicTo.setName(profile.getName());
try {
String mac = _networkMgr.getNextAvailableMacAddressInNetwork(networkId);
nicTo.setMac(mac);
} catch (InsufficientAddressCapacityException e) {
throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId);
}
nicTo.setDns1(profile.getIPv4Dns1());
nicTo.setDns2(profile.getIPv4Dns2());
if (publicNicProfile != null && publicNicProfile.getIPv4Gateway() != null) {
nicTo.setGateway(publicNicProfile.getIPv4Gateway());
} else {
nicTo.setGateway(network.getGateway());
}
nicTo.setDefaultNic(false);
nicTo.setBroadcastUri(profile.getBroadCastUri());
nicTo.setIsolationuri(profile.getIsolationUri());
Integer networkRate = _networkMgr.getNetworkRate(network.getId(), null);
nicTo.setNetworkRateMbps(networkRate);
expandedNics[i] = nicTo;
}
to.setNics(expandedNics);
}
StringBuffer sbMacSequence = new StringBuffer();
for (NicTO nicTo : sortNicsByDeviceId(to.getNics())) {
sbMacSequence.append(nicTo.getMac()).append("|");
}
if (!sbMacSequence.toString().isEmpty()) {
sbMacSequence.deleteCharAt(sbMacSequence.length() - 1);
String bootArgs = to.getBootArgs();
to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString());
}
}
// Determine the VM's OS description
GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
to.setOs(guestOS.getDisplayName());
return to;
}
use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class GloboDnsElementTest method testPrepareMethodCallGloboDnsToRegisterHostName.
@Test
public void testPrepareMethodCallGloboDnsToRegisterHostName() throws Exception {
Network network = mock(Network.class);
when(network.getDataCenterId()).thenReturn(zoneId);
when(network.getId()).thenReturn(1l);
NicProfile nic = new NicProfile();
nic.setIPv4Address("10.11.12.13");
VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
when(vm.getHostName()).thenReturn("vm-name");
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
DataCenterVO dataCenterVO = mock(DataCenterVO.class);
when(dataCenterVO.getId()).thenReturn(zoneId);
when(_datacenterDao.findById(zoneId)).thenReturn(dataCenterVO);
DeployDestination dest = new DeployDestination();
ReservationContext context = new ReservationContextImpl(null, null, user);
HostVO hostVO = mock(HostVO.class);
when(hostVO.getId()).thenReturn(globoDnsHostId);
when(_hostDao.findByTypeNameAndZoneId(eq(zoneId), eq(Provider.GloboDns.getName()), eq(Type.L2Networking))).thenReturn(hostVO);
when(_agentMgr.easySend(eq(globoDnsHostId), isA(CreateOrUpdateRecordAndReverseCommand.class))).then(new org.mockito.stubbing.Answer<Answer>() {
@Override
public Answer answer(InvocationOnMock invocation) throws Throwable {
Command cmd = (Command) invocation.getArguments()[1];
return new Answer(cmd);
}
});
_globodnsElement.prepare(network, nic, vm, dest, context);
verify(_agentMgr, times(1)).easySend(eq(globoDnsHostId), isA(CreateOrUpdateRecordAndReverseCommand.class));
}
use of com.cloud.vm.NicProfile in project cloudstack by apache.
the class GloboDnsElementTest method testUpperCaseCharactersAreNotAllowed.
@Test(expected = InvalidParameterValueException.class)
public void testUpperCaseCharactersAreNotAllowed() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
Network network = mock(Network.class);
when(network.getDataCenterId()).thenReturn(zoneId);
when(network.getId()).thenReturn(1l);
NicProfile nic = new NicProfile();
VirtualMachineProfile vm = mock(VirtualMachineProfile.class);
when(vm.getHostName()).thenReturn("UPPERCASENAME");
when(vm.getType()).thenReturn(VirtualMachine.Type.User);
when(_datacenterDao.findById(zoneId)).thenReturn(mock(DataCenterVO.class));
DeployDestination dest = new DeployDestination();
ReservationContext context = new ReservationContextImpl(null, null, user);
_globodnsElement.prepare(network, nic, vm, dest, context);
}
Aggregations