use of com.cloud.network.element.UserDataServiceProvider in project cloudstack by apache.
the class UserVmManagerTest method testApplyUserDataSuccessful.
@Test
public void testApplyUserDataSuccessful() throws Exception {
UserVm userVm = mock(UserVm.class);
lenient().when(userVm.getId()).thenReturn(1L);
when(_nicMock.getNetworkId()).thenReturn(2L);
when(_networkMock.getNetworkOfferingId()).thenReturn(3L);
when(_networkDao.findById(2L)).thenReturn(_networkMock);
UserDataServiceProvider userDataServiceProvider = mock(UserDataServiceProvider.class);
when(userDataServiceProvider.saveUserData(any(Network.class), any(NicProfile.class), any(VirtualMachineProfile.class))).thenReturn(true);
// Userdata support with implementing element
when(_networkModel.areServicesSupportedByNetworkOffering(3L, Service.UserData)).thenReturn(true);
when(_networkModel.getUserDataUpdateProvider(_networkMock)).thenReturn(userDataServiceProvider);
assertTrue(_userVmMgr.applyUserData(HypervisorType.KVM, userVm, _nicMock));
}
use of com.cloud.network.element.UserDataServiceProvider in project cloudstack by apache.
the class RulesManagerImpl method applyUserDataIfNeeded.
protected void applyUserDataIfNeeded(long vmId, Network network, Nic guestNic) throws ResourceUnavailableException {
UserDataServiceProvider element = null;
try {
element = _networkModel.getUserDataUpdateProvider(network);
} catch (UnsupportedServiceException ex) {
s_logger.info(String.format("%s is not supported by network %s, skipping.", Service.UserData.getName(), network));
return;
}
if (element == null) {
s_logger.error("Can't find network element for " + Service.UserData.getName() + " provider needed for UserData update");
} else {
UserVmVO vm = _vmDao.findById(vmId);
try {
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
NicProfile nicProfile = new NicProfile(guestNic, network, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(template.getHypervisorType(), network));
VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm);
if (!element.saveUserData(network, nicProfile, vmProfile)) {
s_logger.error("Failed to update userdata for vm " + vm + " and nic " + guestNic);
}
} catch (Exception e) {
s_logger.error("Failed to update userdata for vm " + vm + " and nic " + guestNic + " due to " + e.getMessage(), e);
}
}
}
Aggregations