Search in sources :

Example 1 with NicTO

use of com.cloud.agent.api.to.NicTO in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private synchronized Answer execute(PrepareForMigrationCommand cmd) {
    VirtualMachineTO vm = cmd.getVirtualMachine();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Preparing host for migrating " + vm);
    }
    NicTO[] nics = vm.getNics();
    try {
        Connect conn = LibvirtConnection.getConnection();
        for (NicTO nic : nics) {
            String vlanId = null;
            if (nic.getBroadcastType() == BroadcastDomainType.Vlan) {
                URI broadcastUri = nic.getBroadcastUri();
                vlanId = broadcastUri.getHost();
            }
            if (nic.getType() == TrafficType.Guest) {
                if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
                    createVlanBr(vlanId, _pifs.first());
                }
            } else if (nic.getType() == TrafficType.Control) {
                /* Make sure the network is still there */
                createControlNetwork(conn);
            } else if (nic.getType() == TrafficType.Public) {
                if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
                    createVlanBr(vlanId, _pifs.second());
                }
            }
        }
        /* setup disks, e.g for iso */
        VolumeTO[] volumes = vm.getDisks();
        for (VolumeTO volume : volumes) {
            if (volume.getType() == Volume.Type.ISO) {
                getVolumePath(conn, volume);
            }
        }
        synchronized (_vms) {
            _vms.put(vm.getName(), State.Migrating);
        }
        return new PrepareForMigrationAnswer(cmd);
    } catch (LibvirtException e) {
        return new PrepareForMigrationAnswer(cmd, e.toString());
    } catch (InternalErrorException e) {
        return new PrepareForMigrationAnswer(cmd, e.toString());
    } catch (URISyntaxException e) {
        return new PrepareForMigrationAnswer(cmd, e.toString());
    }
}
Also used : VolumeTO(com.cloud.agent.api.to.VolumeTO) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) InternalErrorException(com.cloud.exception.InternalErrorException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) NicTO(com.cloud.agent.api.to.NicTO) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer)

Example 2 with NicTO

use of com.cloud.agent.api.to.NicTO in project CloudStack-archive by CloudStack-extras.

the class FakeComputingResource method execute.

protected synchronized StartAnswer execute(StartCommand cmd) {
    VmMgr vmMgr = getVmManager();
    VirtualMachineTO vmSpec = cmd.getVirtualMachine();
    String vmName = vmSpec.getName();
    State state = State.Stopped;
    try {
        if (!_vms.containsKey(vmName)) {
            synchronized (_vms) {
                _vms.put(vmName, State.Starting);
            }
            MockVm vm = vmMgr.createVmFromSpec(vmSpec);
            vmMgr.createVbd(vmSpec, vmName, vm);
            vmMgr.createVif(vmSpec, vmName, vm);
            state = State.Running;
            for (NicTO nic : cmd.getVirtualMachine().getNics()) {
                if (nic.getType() == TrafficType.Guest) {
                    InetAddress addr = _dhcpSnooper.getIPAddr(nic.getMac(), vmName);
                    nic.setIp(addr.getHostAddress());
                }
            }
            _vmDataServer.handleVmStarted(cmd.getVirtualMachine());
            return new StartAnswer(cmd);
        } else {
            String msg = "There is already a VM having the same name " + vmName;
            s_logger.warn(msg);
            return new StartAnswer(cmd, msg);
        }
    } catch (Exception ex) {
    } finally {
        synchronized (_vms) {
            _vms.put(vmName, state);
        }
    }
    return new StartAnswer(cmd);
}
Also used : StartAnswer(com.cloud.agent.api.StartAnswer) VmState(com.cloud.agent.api.StartupRoutingCommand.VmState) State(com.cloud.vm.VirtualMachine.State) InetAddress(java.net.InetAddress) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) MockVm(com.cloud.agent.mockvm.MockVm) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) VmMgr(com.cloud.agent.mockvm.VmMgr) MockVmMgr(com.cloud.agent.mockvm.MockVmMgr) NicTO(com.cloud.agent.api.to.NicTO)

Example 3 with NicTO

use of com.cloud.agent.api.to.NicTO in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

protected synchronized StartAnswer execute(StartCommand cmd) {
    VirtualMachineTO vmSpec = cmd.getVirtualMachine();
    String vmName = vmSpec.getName();
    LibvirtVMDef vm = null;
    State state = State.Stopped;
    Connect conn = null;
    try {
        conn = LibvirtConnection.getConnection();
        synchronized (_vms) {
            _vms.put(vmName, State.Starting);
        }
        vm = createVMFromSpec(vmSpec);
        createVbd(conn, vmSpec, vmName, vm);
        createVifs(conn, vmSpec, vm);
        s_logger.debug("starting " + vmName + ": " + vm.toString());
        startDomain(conn, vmName, vm.toString());
        Script.runSimpleBashScript("virsh schedinfo " + vmName + " --set cpu_shares=" + vmSpec.getCpus() * vmSpec.getSpeed());
        NicTO[] nics = vmSpec.getNics();
        for (NicTO nic : nics) {
            if (nic.getIsolationUri() != null && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString())) {
                if (vmSpec.getType() != VirtualMachine.Type.User) {
                    default_network_rules_for_systemvm(conn, vmName);
                    break;
                } else {
                    default_network_rules(conn, vmName, nic, vmSpec.getId());
                }
            }
        }
        state = State.Running;
        return new StartAnswer(cmd);
    } catch (Exception e) {
        s_logger.warn("Exception ", e);
        if (conn != null) {
            handleVmStartFailure(conn, vmName, vm);
        }
        return new StartAnswer(cmd, e.getMessage());
    } finally {
        synchronized (_vms) {
            if (state != State.Stopped) {
                _vms.put(vmName, state);
            } else {
                _vms.remove(vmName);
            }
        }
    }
}
Also used : StartAnswer(com.cloud.agent.api.StartAnswer) State(com.cloud.vm.VirtualMachine.State) Connect(org.libvirt.Connect) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) URISyntaxException(java.net.URISyntaxException) LibvirtException(org.libvirt.LibvirtException) FileNotFoundException(java.io.FileNotFoundException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) NicTO(com.cloud.agent.api.to.NicTO)

Example 4 with NicTO

use of com.cloud.agent.api.to.NicTO in project CloudStack-archive by CloudStack-extras.

the class MockVmManagerImpl method startVM.

public String startVM(String vmName, NicTO[] nics, int cpuHz, long ramSize, String bootArgs, String hostGuid) {
    MockHost host = _mockHostDao.findByGuid(hostGuid);
    if (host == null) {
        return "can't find host";
    }
    MockVm vm = _mockVmDao.findByVmName(vmName);
    if (vm == null) {
        int vncPort = 0;
        if (vncPort < 0)
            return "Unable to allocate VNC port";
        vm = new MockVMVO();
        vm.setCpu(cpuHz);
        vm.setMemory(ramSize);
        vm.setState(State.Running);
        vm.setName(vmName);
        vm.setVncPort(vncPort);
        vm.setHostId(host.getId());
        if (vmName.startsWith("s-")) {
            vm.setType("SecondaryStorageVm");
        } else if (vmName.startsWith("v-")) {
            vm.setType("ConsoleProxy");
        } else if (vmName.startsWith("r-")) {
            vm.setType("DomainRouter");
        } else if (vmName.startsWith("i-")) {
            vm.setType("User");
        }
        vm = _mockVmDao.persist((MockVMVO) vm);
    } else {
        if (vm.getState() == State.Stopped) {
            vm.setState(State.Running);
            _mockVmDao.update(vm.getId(), (MockVMVO) vm);
        }
    }
    if (vm.getState() == State.Running && vmName.startsWith("s-")) {
        String prvIp = null;
        String prvMac = null;
        String prvNetMask = null;
        for (NicTO nic : nics) {
            if (nic.getType() == TrafficType.Management) {
                prvIp = nic.getIp();
                prvMac = nic.getMac();
                prvNetMask = nic.getNetmask();
            }
        }
        long dcId = 0;
        long podId = 0;
        String name = null;
        String vmType = null;
        String url = null;
        String[] args = bootArgs.trim().split(" ");
        for (String arg : args) {
            String[] params = arg.split("=");
            if (params.length < 1) {
                continue;
            }
            if (params[0].equalsIgnoreCase("zone")) {
                dcId = Long.parseLong(params[1]);
            } else if (params[0].equalsIgnoreCase("name")) {
                name = params[1];
            } else if (params[0].equalsIgnoreCase("type")) {
                vmType = params[1];
            } else if (params[0].equalsIgnoreCase("url")) {
                url = params[1];
            } else if (params[0].equalsIgnoreCase("pod")) {
                podId = Long.parseLong(params[1]);
            }
        }
        _mockAgentMgr.handleSystemVMStart(vm.getId(), prvIp, prvMac, prvNetMask, dcId, podId, name, vmType, url);
    }
    return null;
}
Also used : MockVMVO(com.cloud.simulator.MockVMVO) MockHost(com.cloud.simulator.MockHost) MockVm(com.cloud.simulator.MockVm) NicTO(com.cloud.agent.api.to.NicTO)

Example 5 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)

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