Search in sources :

Example 36 with Nic

use of com.cloud.legacymodel.network.Nic in project cosmic by MissionCriticalCloud.

the class UserVmManagerImpl method finalizeVirtualMachineProfile.

@Override
public boolean finalizeVirtualMachineProfile(final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context) {
    final UserVmVO vm = _vmDao.findById(profile.getId());
    final Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(vm.getId());
    vm.setDetails(details);
    // add userdata info into vm profile
    final Nic defaultNic = _networkModel.getDefaultNic(vm.getId());
    if (defaultNic != null) {
        final Network network = _networkModel.getNetwork(defaultNic.getNetworkId());
        if (_networkModel.isSharedNetworkWithoutServices(network.getId())) {
            final String serviceOffering = _serviceOfferingDao.findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId()).getDisplayText();
            final String zoneName = zoneRepository.findById(vm.getDataCenterId()).orElse(null).getName();
            final boolean isWindows = _guestOSCategoryDao.findById(_guestOSDao.findById(vm.getGuestOSId()).getCategoryId()).getName().equalsIgnoreCase("Windows");
            final List<String[]> vmData = _networkModel.generateVmData(vm.getUserData(), serviceOffering, zoneName, vm.getInstanceName(), vm.getId(), (String) profile.getParameter(VirtualMachineProfile.Param.VmSshPubKey), (String) profile.getParameter(VirtualMachineProfile.Param.VmPassword), isWindows, network);
            final String vmName = vm.getInstanceName();
            final String configDriveIsoRootFolder = "/tmp";
            final String isoFile = configDriveIsoRootFolder + "/" + vmName + "/configDrive/" + vmName + ".iso";
            profile.setVmData(vmData);
            profile.setConfigDriveLabel(VirtualMachineManager.VmConfigDriveLabel.value());
            profile.setConfigDriveIsoRootFolder(configDriveIsoRootFolder);
            profile.setConfigDriveIsoFile(isoFile);
        }
    }
    _templateMgr.prepareIsoForVmProfile(profile);
    return true;
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) Nic(com.cloud.legacymodel.network.Nic)

Example 37 with Nic

use of com.cloud.legacymodel.network.Nic in project cosmic by MissionCriticalCloud.

the class UserVmManagerImpl method resetVMPasswordInternal.

private boolean resetVMPasswordInternal(final Long vmId, final String password) throws ResourceUnavailableException, InsufficientCapacityException {
    final Long userId = CallContext.current().getCallingUserId();
    final VMInstanceVO vmInstance = _vmDao.findById(vmId);
    if (password == null || password.equals("")) {
        return false;
    }
    final VMTemplateVO template = _templateDao.findByIdIncludingRemoved(vmInstance.getTemplateId());
    if (template.getEnablePassword()) {
        final 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;
        }
        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);
        vmProfile.setParameter(VirtualMachineProfile.Param.VmPassword, password);
        final 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");
        }
        final 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 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 password 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 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;
    }
}
Also used : CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Network(com.cloud.legacymodel.network.Network) VMTemplateVO(com.cloud.storage.VMTemplateVO) Nic(com.cloud.legacymodel.network.Nic) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider)

Aggregations

Nic (com.cloud.legacymodel.network.Nic)37 Network (com.cloud.legacymodel.network.Network)19 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)17 ArrayList (java.util.ArrayList)13 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)11 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)11 NicProfile (com.cloud.vm.NicProfile)8 IPAddressVO (com.cloud.network.dao.IPAddressVO)7 DB (com.cloud.utils.db.DB)7 Zone (com.cloud.db.model.Zone)5 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)5 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)5 Ip (com.cloud.legacymodel.network.Ip)5 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)5 UserVm (com.cloud.uservm.UserVm)5 DomainRouterVO (com.cloud.vm.DomainRouterVO)5 CallContext (com.cloud.context.CallContext)4 IpAddress (com.cloud.network.IpAddress)4 PublicIp (com.cloud.network.addr.PublicIp)4 NetworkVO (com.cloud.network.dao.NetworkVO)4