Search in sources :

Example 1 with Network

use of com.cloud.hypervisor.ovm3.objects.Network in project cloudstack by apache.

the class Ovm3HypervisorResource method execute.

@Override
public synchronized StartAnswer execute(StartCommand cmd) {
    VirtualMachineTO vmSpec = cmd.getVirtualMachine();
    String vmName = vmSpec.getName();
    State state = State.Stopped;
    Xen xen = new Xen(c);
    try {
        hypervisorsupport.setVmStateStarting(vmName);
        Xen.Vm vm = xen.getVmConfig();
        /* max and min ? */
        vm.setVmCpus(vmSpec.getCpus());
        /* in mb not in bytes */
        vm.setVmMemory(vmSpec.getMinRam() / 1024 / 1024);
        vm.setVmUuid(UUID.nameUUIDFromBytes(vmSpec.getName().getBytes(Charset.defaultCharset())).toString());
        vm.setVmName(vmName);
        String domType = guesttypes.getOvm3GuestType(vmSpec.getOs());
        if (domType == null || domType.isEmpty()) {
            domType = "default";
            LOGGER.debug("VM Virt type missing setting to: " + domType);
        } else {
            LOGGER.debug("VM Virt type set to " + domType + " for " + vmSpec.getOs());
        }
        vm.setVmDomainType(domType);
        if (vmSpec.getBootloader() == BootloaderType.CD) {
            LOGGER.warn("CD booting is not supported");
        }
        /*
             * officially CD boot is only supported on HVM, although there is a
             * simple way around it..
             */
        vmsupport.createVbds(vm, vmSpec);
        if (vmSpec.getType() != VirtualMachine.Type.User) {
            // double check control network if we run a non user VM
            hypervisornetwork.configureNetworking();
            vm.setVmExtra(vmSpec.getBootArgs().replace(" ", "%"));
            String svmPath = configuration.getAgentOvmRepoPath() + "/" + ovmObject.deDash(vm.getPrimaryPoolUuid()) + "/ISOs";
            String svmIso = svmPath + "/" + storagepool.getSystemVMPatchIsoFile().getName();
            vm.addIso(svmIso);
        }
        /* OVS/Network stuff should go here! */
        vmsupport.createVifs(vm, vmSpec);
        vm.setupVifs();
        vm.setVnc("0.0.0.0", vmSpec.getVncPassword());
        xen.createVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
        xen.startVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
        state = State.Running;
        if (vmSpec.getType() != VirtualMachine.Type.User) {
            String controlIp = null;
            for (NicTO nic : vmSpec.getNics()) {
                if (nic.getType() == TrafficType.Control) {
                    controlIp = nic.getIp();
                }
            }
            /* fix is in cloudstack.py for xend restart timer */
            for (int count = 0; count < 60; count++) {
                CloudstackPlugin cSp = new CloudstackPlugin(c);
                /* skip a beat to make sure we didn't miss start */
                if (hypervisorsupport.getVmState(vmName) == null && count > 1) {
                    String msg = "VM " + vmName + " went missing on " + configuration.getAgentHostname() + ", returning stopped";
                    LOGGER.debug(msg);
                    state = State.Stopped;
                    return new StartAnswer(cmd, msg);
                }
                /* creative fix? */
                try {
                    Boolean res = cSp.domrCheckSsh(controlIp);
                    LOGGER.debug("connected to " + controlIp + " on attempt " + count + " result: " + res);
                    if (res) {
                        break;
                    }
                } catch (Exception x) {
                    LOGGER.trace("unable to connect to " + controlIp + " on attempt " + count + " " + x.getMessage(), x);
                }
                Thread.sleep(5000);
            }
        }
        /*
             * Can't remember if HA worked if we were only a pool ?
             */
        if (configuration.getAgentInOvm3Pool() && configuration.getAgentInOvm3Cluster()) {
            xen.configureVmHa(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid(), true);
        }
        /* should be starting no ? */
        state = State.Running;
        return new StartAnswer(cmd);
    } catch (Exception e) {
        LOGGER.debug("Start vm " + vmName + " failed", e);
        state = State.Stopped;
        return new StartAnswer(cmd, e.getMessage());
    } finally {
        hypervisorsupport.setVmState(vmName, state);
    }
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) StartAnswer(com.cloud.agent.api.StartAnswer) State(com.cloud.vm.VirtualMachine.State) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) NicTO(com.cloud.agent.api.to.NicTO)

Example 2 with Network

use of com.cloud.hypervisor.ovm3.objects.Network in project cloudstack by apache.

the class Ovm3HypervisorNetwork method isNetworkSetupByName.

/**/
private boolean isNetworkSetupByName(String nameTag) {
    if (nameTag != null) {
        LOGGER.debug("Looking for network setup by name " + nameTag);
        try {
            Network net = new Network(c);
            net.getInterfaceList();
            if (net.getBridgeByName(nameTag) != null) {
                LOGGER.debug("Found bridge with name: " + nameTag);
                return true;
            }
        } catch (Ovm3ResourceException e) {
            LOGGER.debug("Unxpected error looking for name: " + nameTag, e);
            return false;
        }
    }
    LOGGER.debug("No bridge with name: " + nameTag);
    return false;
}
Also used : Network(com.cloud.hypervisor.ovm3.objects.Network) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 3 with Network

use of com.cloud.hypervisor.ovm3.objects.Network in project cloudstack by apache.

the class Ovm3HypervisorNetwork method createVlanBridge.

private String createVlanBridge(String networkName, Integer vlanId) throws Ovm3ResourceException {
    if (vlanId < 1 || vlanId > 4094) {
        String msg = "Incorrect vlan " + vlanId + ", needs to be between 1 and 4094";
        LOGGER.error(msg);
        throw new CloudRuntimeException(msg);
    }
    Network net = new Network(c);
    /* figure out if our bridged vlan exists, if not then create */
    String brName = networkName + "." + vlanId.toString();
    try {
        String physInterface = net.getPhysicalByBridgeName(networkName);
        if (net.getInterfaceByName(brName) == null) {
            net.startOvsVlanBridge(brName, physInterface, vlanId);
        } else {
            LOGGER.debug("Interface " + brName + " already exists");
        }
    } catch (Ovm3ResourceException e) {
        String msg = "Unable to create vlan " + vlanId.toString() + " bridge for " + networkName;
        LOGGER.warn(msg + ": " + e);
        throw new CloudRuntimeException(msg + ":" + e.getMessage());
    }
    return brName;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.hypervisor.ovm3.objects.Network) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 4 with Network

use of com.cloud.hypervisor.ovm3.objects.Network in project cloudstack by apache.

the class Ovm3VmSupport method deleteVif.

private Boolean deleteVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException {
    /* here we should use the housekeeping of VLANs/Networks etc..
         * so we can clean after the last VM is gone
         */
    try {
        String net = network.getNetwork(nic);
        if (net != null) {
            LOGGER.debug("Removing vif " + nic.getDeviceId() + " " + " " + nic.getMac() + " " + net + " from " + vm.getVmName());
            vm.removeVif(net, nic.getMac());
        } else {
            LOGGER.debug("Unable to remove vif " + nic.getDeviceId() + " no network for " + vm.getVmName());
            return false;
        }
    } catch (Exception e) {
        String msg = "Unable to remove vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage();
        LOGGER.debug(msg);
        throw new Ovm3ResourceException(msg);
    }
    return true;
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 5 with Network

use of com.cloud.hypervisor.ovm3.objects.Network in project cloudstack by apache.

the class Ovm3VmSupport method createVif.

/* should add bitrates and latency... */
private Boolean createVif(Xen.Vm vm, NicTO nic) throws Ovm3ResourceException {
    try {
        String net = network.getNetwork(nic);
        if (net != null) {
            LOGGER.debug("Adding vif " + nic.getDeviceId() + " " + nic.getMac() + " " + net + " to " + vm.getVmName());
            vm.addVif(nic.getDeviceId(), net, nic.getMac());
        } else {
            LOGGER.debug("Unable to add vif " + nic.getDeviceId() + " no network for " + vm.getVmName());
            return false;
        }
    } catch (Exception e) {
        String msg = "Unable to add vif " + nic.getType() + " for " + vm.getVmName() + " " + e.getMessage();
        LOGGER.debug(msg);
        throw new Ovm3ResourceException(msg);
    }
    return true;
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Aggregations

Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 Network (com.cloud.hypervisor.ovm3.objects.Network)4 CloudstackPlugin (com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)2 ConfigurationException (javax.naming.ConfigurationException)2 XmlRpcException (org.apache.xmlrpc.XmlRpcException)2 StartAnswer (com.cloud.agent.api.StartAnswer)1 NicTO (com.cloud.agent.api.to.NicTO)1 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)1 Linux (com.cloud.hypervisor.ovm3.objects.Linux)1 Xen (com.cloud.hypervisor.ovm3.objects.Xen)1 State (com.cloud.vm.VirtualMachine.State)1 BigInteger (java.math.BigInteger)1