use of com.cloud.network.element.UserDataServiceProvider in project cloudstack by apache.
the class NetworkOrchestrator method prepareElement.
protected boolean prepareElement(final NetworkElement element, final Network network, final NicProfile profile, final VirtualMachineProfile vmProfile, final DeployDestination dest, final ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
element.prepare(network, profile, vmProfile, dest, context);
if (vmProfile.getType() == Type.User && element.getProvider() != null) {
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) && element instanceof DhcpServiceProvider) {
final DhcpServiceProvider sp = (DhcpServiceProvider) element;
final Map<Capability, String> dhcpCapabilities = element.getCapabilities().get(Service.Dhcp);
final String supportsMultipleSubnets = dhcpCapabilities.get(Capability.DhcpAccrossMultipleSubnets);
if (supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets) && profile.getIPv6Address() == null) {
if (!sp.configDhcpSupportForSubnet(network, profile, vmProfile, dest, context)) {
return false;
}
}
if (!sp.addDhcpEntry(network, profile, vmProfile, dest, context)) {
return false;
}
}
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dns) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, element.getProvider()) && element instanceof DnsServiceProvider) {
final DnsServiceProvider sp = (DnsServiceProvider) element;
if (profile.getIPv6Address() == null) {
if (!sp.configDnsSupportForSubnet(network, profile, vmProfile, dest, context)) {
return false;
}
}
if (!sp.addDnsEntry(network, profile, vmProfile, dest, context)) {
return false;
}
}
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.UserData, element.getProvider()) && element instanceof UserDataServiceProvider) {
final UserDataServiceProvider sp = (UserDataServiceProvider) element;
if (!sp.addPasswordAndUserdata(network, profile, vmProfile, dest, context)) {
return false;
}
}
}
return true;
}
use of com.cloud.network.element.UserDataServiceProvider in project cosmic by MissionCriticalCloud.
the class UserVmManagerImpl method resetVMSSHKeyInternal.
private boolean resetVMSSHKeyInternal(final Long vmId, final String sshPublicKey, final String password) throws ResourceUnavailableException, InsufficientCapacityException {
final Long userId = CallContext.current().getCallingUserId();
final VMInstanceVO vmInstance = _vmDao.findById(vmId);
final VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId());
final Nic defaultNic = _networkModel.getDefaultNic(vmId);
if (defaultNic == null) {
s_logger.error("Unable to reset SSH Key for vm " + vmInstance + " as the instance doesn't have default nic");
return false;
}
final Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId());
final NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork));
final VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance);
if (template.getEnablePassword()) {
vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password);
}
final UserDataServiceProvider element = _networkMgr.getSSHKeyResetProvider(defaultNetwork);
if (element == null) {
throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for SSH Key reset");
}
final boolean result = element.saveSSHKey(defaultNetwork, defaultNicProfile, vmProfile, sshPublicKey);
// Need to reboot the virtual machine so that the password gets redownloaded from the DomR, and reset on the VM
if (!result) {
s_logger.debug("Failed to reset SSH Key for the virutal machine; no need to reboot the vm");
return false;
} else {
if (vmInstance.getState() == State.Stopped) {
s_logger.debug("Vm " + vmInstance + " is stopped, not rebooting it as a part of SSH Key reset");
return true;
}
if (rebootVirtualMachine(userId, vmId) == null) {
s_logger.warn("Failed to reboot the vm " + vmInstance);
return false;
} else {
s_logger.debug("Vm " + vmInstance + " is rebooted successfully as a part of SSH Key reset");
return true;
}
}
}
use of com.cloud.network.element.UserDataServiceProvider in project cosmic by MissionCriticalCloud.
the class UserVmManagerImpl method updateUserDataInternal.
private boolean updateUserDataInternal(final UserVm vm) throws ResourceUnavailableException, InsufficientCapacityException {
final VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vm.getTemplateId());
final List<? extends Nic> nics = _nicDao.listByVmId(vm.getId());
if (nics == null || nics.isEmpty()) {
s_logger.error("unable to find any nics for vm " + vm.getUuid());
return false;
}
for (final Nic nic : nics) {
final Network network = _networkDao.findById(nic.getNetworkId());
final NicProfile nicProfile = new NicProfile(nic, network, null, null, null, _networkModel.getNetworkTag(template.getHypervisorType(), network));
final VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vm);
final UserDataServiceProvider element = _networkModel.getUserDataUpdateProvider(network);
if (element == null) {
throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for UserData update");
}
final boolean result = element.saveUserData(network, nicProfile, vmProfile);
if (!result) {
s_logger.error("Failed to update userdata for vm " + vm + " and nic " + nic);
}
}
return true;
}
use of com.cloud.network.element.UserDataServiceProvider in project cloudstack by apache.
the class NetworkOrchestrator method setHypervisorHostname.
@Override
public void setHypervisorHostname(VirtualMachineProfile vm, DeployDestination dest, boolean migrationSuccessful) throws ResourceUnavailableException {
final List<NicVO> nics = _nicDao.listByVmId(vm.getId());
for (final NicVO nic : nics) {
final NetworkVO network = _networksDao.findById(nic.getNetworkId());
final Integer networkRate = _networkModel.getNetworkRate(network.getId(), vm.getId());
final NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vm.getHypervisorType(), network));
for (final NetworkElement element : networkElements) {
if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.UserData) && element instanceof UserDataServiceProvider) {
if (element instanceof ConfigDriveNetworkElement && !migrationSuccessful || element instanceof VirtualRouterElement && migrationSuccessful) {
final UserDataServiceProvider sp = (UserDataServiceProvider) element;
if (!sp.saveHypervisorHostname(profile, network, vm, dest)) {
throw new CloudRuntimeException("Failed to Add hypervisor hostname");
}
}
}
}
}
}
use of com.cloud.network.element.UserDataServiceProvider in project cloudstack by apache.
the class UserVmManagerImpl method resetVMPasswordInternal.
private boolean resetVMPasswordInternal(Long vmId, String password) throws ResourceUnavailableException, InsufficientCapacityException {
Long userId = CallContext.current().getCallingUserId();
VMInstanceVO vmInstance = _vmDao.findById(vmId);
if (password == null || password.equals("")) {
return false;
}
VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId());
if (template.isEnablePassword()) {
Nic defaultNic = _networkModel.getDefaultNic(vmId);
if (defaultNic == null) {
s_logger.error("Unable to reset password for vm " + vmInstance + " as the instance doesn't have default nic");
return false;
}
Network defaultNetwork = _networkDao.findById(defaultNic.getNetworkId());
NicProfile defaultNicProfile = new NicProfile(defaultNic, defaultNetwork, null, null, null, _networkModel.isSecurityGroupSupportedInNetwork(defaultNetwork), _networkModel.getNetworkTag(template.getHypervisorType(), defaultNetwork));
VirtualMachineProfile vmProfile = new VirtualMachineProfileImpl(vmInstance);
vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password);
UserDataServiceProvider element = _networkMgr.getPasswordResetProvider(defaultNetwork);
if (element == null) {
throw new CloudRuntimeException("Can't find network element for " + Service.UserData.getName() + " provider needed for password reset");
}
boolean result = element.savePassword(defaultNetwork, defaultNicProfile, vmProfile);
// redownloaded from the DomR, and reset on the VM
if (!result) {
s_logger.debug("Failed to reset password for the virtual machine; no need to reboot the vm");
return false;
} else {
final UserVmVO userVm = _vmDao.findById(vmId);
_vmDao.loadDetails(userVm);
// update the password in vm_details table too
// Check if an SSH key pair was selected for the instance and if so
// use it to encrypt & save the vm password
encryptAndStorePassword(userVm, password);
if (vmInstance.getState() == State.Stopped) {
s_logger.debug("Vm " + vmInstance + " is stopped, not rebooting it as a part of password reset");
return true;
}
if (rebootVirtualMachine(userId, vmId, false, false) == null) {
s_logger.warn("Failed to reboot the vm " + vmInstance);
return false;
} else {
s_logger.debug("Vm " + vmInstance + " is rebooted successfully as a part of password reset");
return true;
}
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Reset password called for a vm that is not using a password enabled template");
}
return false;
}
}
Aggregations