Search in sources :

Example 26 with NicTO

use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.

the class HypervisorGuruBase method toNicTO.

@Override
public NicTO toNicTO(NicProfile profile) {
    NicTO to = new NicTO();
    to.setDeviceId(profile.getDeviceId());
    to.setBroadcastType(profile.getBroadcastType());
    to.setType(profile.getTrafficType());
    to.setIp(profile.getIPv4Address());
    to.setNetmask(profile.getIPv4Netmask());
    to.setMac(profile.getMacAddress());
    to.setDns1(profile.getIPv4Dns1());
    to.setDns2(profile.getIPv4Dns2());
    to.setGateway(profile.getIPv4Gateway());
    to.setDefaultNic(profile.isDefaultNic());
    to.setBroadcastUri(profile.getBroadCastUri());
    to.setIsolationuri(profile.getIsolationUri());
    to.setNetworkRateMbps(profile.getNetworkRate());
    to.setName(profile.getName());
    to.setSecurityGroupEnabled(profile.isSecurityGroupEnabled());
    to.setIp6Address(profile.getIPv6Address());
    to.setIp6Cidr(profile.getIPv6Cidr());
    NetworkVO network = _networkDao.findById(profile.getNetworkId());
    to.setNetworkUuid(network.getUuid());
    // Workaround to make sure the TO has the UUID we need for Nicira integration
    NicVO nicVO = _nicDao.findById(profile.getId());
    if (nicVO != null) {
        to.setUuid(nicVO.getUuid());
        // disable pxe on system vm nics to speed up boot time
        if (nicVO.getVmType() != VirtualMachine.Type.User) {
            to.setPxeDisable(true);
        }
        List<String> secIps = null;
        if (nicVO.getSecondaryIp()) {
            secIps = _nicSecIpDao.getSecondaryIpAddressesForNic(nicVO.getId());
        }
        to.setNicSecIps(secIps);
    } else {
        s_logger.warn("Unabled to load NicVO for NicProfile " + profile.getId());
        //Workaround for dynamically created nics
        //FixMe: uuid and secondary IPs can be made part of nic profile
        to.setUuid(UUID.randomUUID().toString());
    }
    // configuration. Use full when vm stop/start
    return to;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) NicVO(com.cloud.vm.NicVO) NicTO(com.cloud.agent.api.to.NicTO)

Example 27 with NicTO

use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.

the class OvmResourceBase method execute.

protected PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) {
    VirtualMachineTO vm = cmd.getVirtualMachine();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    NicTO[] nics = vm.getNics();
    try {
        for (NicTO nic : nics) {
            getNetwork(nic);
        }
        return new PrepareForMigrationAnswer(cmd);
    } catch (Exception e) {
        s_logger.warn("Catch Exception " + e.getClass().getName() + " prepare for migration failed due to " + e.toString(), e);
        return new PrepareForMigrationAnswer(cmd, e);
    }
}
Also used : VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) NicTO(com.cloud.agent.api.to.NicTO) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer)

Example 28 with NicTO

use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.

the class OvmResourceBase method execute.

@Override
public synchronized StartAnswer execute(StartCommand cmd) {
    VirtualMachineTO vmSpec = cmd.getVirtualMachine();
    String vmName = vmSpec.getName();
    OvmVm.Details vmDetails = null;
    try {
        vmDetails = new OvmVm.Details();
        applySpecToVm(vmDetails, vmSpec);
        createVbds(vmDetails, vmSpec);
        createVifs(vmDetails, vmSpec);
        startVm(vmDetails);
        // Add security group rules
        NicTO[] nics = vmSpec.getNics();
        for (NicTO nic : nics) {
            if (nic.isSecurityGroupEnabled()) {
                if (vmSpec.getType().equals(VirtualMachine.Type.User)) {
                    defaultNetworkRulesForUserVm(vmName, vmSpec.getId(), nic);
                }
            }
        }
        return new StartAnswer(cmd);
    } catch (Exception e) {
        s_logger.debug("Start vm " + vmName + " failed", e);
        cleanup(vmDetails);
        return new StartAnswer(cmd, e.getMessage());
    }
}
Also used : StartAnswer(com.cloud.agent.api.StartAnswer) OvmVm(com.cloud.ovm.object.OvmVm) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException) NicTO(com.cloud.agent.api.to.NicTO)

Example 29 with NicTO

use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.

the class OvmResourceBase method createVifs.

protected void createVifs(OvmVm.Details vm, VirtualMachineTO spec) throws CloudRuntimeException, XmlRpcException {
    NicTO[] nics = spec.getNics();
    List<OvmVif.Details> vifs = new ArrayList<OvmVif.Details>(nics.length);
    for (NicTO nic : nics) {
        OvmVif.Details vif = createVif(nic);
        vifs.add(nic.getDeviceId(), vif);
    }
    vm.vifs.addAll(vifs);
}
Also used : ArrayList(java.util.ArrayList) OvmVif(com.cloud.ovm.object.OvmVif) NicTO(com.cloud.agent.api.to.NicTO)

Example 30 with NicTO

use of com.cloud.agent.api.to.NicTO in project cloudstack by apache.

the class VirtualMachineManagerImpl method orchestrateRemoveNicFromVm.

private boolean orchestrateRemoveNicFromVm(final VirtualMachine vm, final Nic nic) throws ConcurrentOperationException, ResourceUnavailableException {
    final CallContext cctx = CallContext.current();
    final VMInstanceVO vmVO = _vmDao.findById(vm.getId());
    final NetworkVO network = _networkDao.findById(nic.getNetworkId());
    final ReservationContext context = new ReservationContextImpl(null, null, cctx.getCallingUser(), cctx.getCallingAccount());
    final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vmVO, null, null, null, null);
    final DataCenter dc = _entityMgr.findById(DataCenter.class, network.getDataCenterId());
    final Host host = _hostDao.findById(vm.getHostId());
    final DeployDestination dest = new DeployDestination(dc, null, null, host);
    final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
    final VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
    final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(network.getId(), vm.getId()), _networkModel.isSecurityGroupSupportedInNetwork(network), _networkModel.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
    //1) Unplug the nic
    if (vm.getState() == State.Running) {
        final NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
        s_logger.debug("Un-plugging nic " + nic + " for vm " + vm + " from network " + network);
        final boolean result = unplugNic(network, nicTO, vmTO, context, dest);
        if (result) {
            s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network);
            final long isDefault = nic.isDefaultNic() ? 1 : 0;
            UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NETWORK_OFFERING_REMOVE, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), Long.toString(nic.getId()), network.getNetworkOfferingId(), null, isDefault, VirtualMachine.class.getName(), vm.getUuid(), vm.isDisplay());
        } else {
            s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network);
            return false;
        }
    } else if (vm.getState() != State.Stopped) {
        s_logger.warn("Unable to remove vm " + vm + " from network  " + network);
        throw new ResourceUnavailableException("Unable to remove vm " + vm + " from network, is not in the right state", DataCenter.class, vm.getDataCenterId());
    }
    //2) Release the nic
    _networkMgr.releaseNic(vmProfile, nic);
    s_logger.debug("Successfully released nic " + nic + "for vm " + vm);
    //3) Remove the nic
    _networkMgr.removeNic(vmProfile, nic);
    _nicsDao.expunge(nic.getId());
    return true;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) Host(com.cloud.host.Host) CallContext(org.apache.cloudstack.context.CallContext) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) DataCenter(com.cloud.dc.DataCenter) HypervisorGuru(com.cloud.hypervisor.HypervisorGuru) DeployDestination(com.cloud.deploy.DeployDestination) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) NicTO(com.cloud.agent.api.to.NicTO)

Aggregations

NicTO (com.cloud.agent.api.to.NicTO)99 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)42 Answer (com.cloud.agent.api.Answer)31 Test (org.junit.Test)30 InternalErrorException (com.cloud.exception.InternalErrorException)28 LibvirtException (org.libvirt.LibvirtException)27 ArrayList (java.util.ArrayList)25 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)24 ConfigurationException (javax.naming.ConfigurationException)23 Connect (org.libvirt.Connect)23 URISyntaxException (java.net.URISyntaxException)22 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)21 IOException (java.io.IOException)20 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)19 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)19 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)19 Connection (com.xensource.xenapi.Connection)18 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)14 UnPlugNicCommand (com.cloud.agent.api.UnPlugNicCommand)13 URI (java.net.URI)12