Search in sources :

Example 36 with Ovm3ResourceException

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

the class Ovm3StoragePool method setupSecondaryStorage.

/**
     * The secondary storage mountpoint is a uuid based on the host combined
     * with the path.
     *
     * @param url
     * @return
     * @throws Ovm3ResourceException
     */
public String setupSecondaryStorage(String url) throws Ovm3ResourceException {
    URI uri = URI.create(url);
    if (uri.getHost() == null) {
        throw new Ovm3ResourceException("Secondary storage host can not be empty!");
    }
    String uuid = ovmObject.newUuid(uri.getHost() + ":" + uri.getPath());
    LOGGER.info("Secondary storage with uuid: " + uuid);
    return setupNfsStorage(uri, uuid);
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) URI(java.net.URI)

Example 37 with Ovm3ResourceException

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

the class Ovm3VmSupport method plugNunplugNic.

/**
     * Implements the unplug and plug feature for Nics, the boolan decides
     * to either plug (true) or unplug (false)
     *
     * @param nic
     * @param vmName
     * @param plug
     * @return
     */
private Answer plugNunplugNic(NicTO nic, String vmName, Boolean plug) {
    try {
        Xen xen = new Xen(c);
        Xen.Vm vm = xen.getVmConfig(vmName);
        /* check running */
        if (vm == null) {
            return new Answer(null, false, "Unable to execute command due to missing VM");
        }
        // setup the NIC in the VM config.
        if (plug) {
            createVif(vm, nic);
            vm.setupVifs();
        } else {
            deleteVif(vm, nic);
        }
        // execute the change
        xen.configureVm(ovmObject.deDash(vm.getPrimaryPoolUuid()), vm.getVmUuid());
    } catch (Ovm3ResourceException e) {
        String msg = "Unable to execute command due to " + e.toString();
        LOGGER.debug(msg);
        return new Answer(null, false, msg);
    }
    return new Answer(null, true, "success");
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 38 with Ovm3ResourceException

use of com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException 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)

Example 39 with Ovm3ResourceException

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

the class Ovm3HypervisorSupport method getAllVmStates.

/**
     * getAllVmStates: Get the state of all the VMs
     *
     * @return
     * @throws Ovm3ResourceException
     */
private Map<String, State> getAllVmStates(Map<String, State> vmStateMap) throws Ovm3ResourceException {
    Map<String, Xen.Vm> vms = getAllVms();
    final Map<String, State> states = new HashMap<String, State>();
    for (final Map.Entry<String, Xen.Vm> entry : vms.entrySet()) {
        Xen.Vm vm = entry.getValue();
        State ns = State.Running;
        String as = vm.getVmState();
        if (vm.isControlDomain() || as == null) {
            continue;
        }
        /* need a more exact match! */
        if (as.contains("r")) {
            ns = State.Running;
        /* The domain is blocked, and not running or runnable. */
        } else if (as.contains("b")) {
            ns = State.Running;
        /* The domain has been paused */
        } else if (as.contains("p")) {
            ns = State.Running;
        /* The guest has requested to be shutdown, still migrating... */
        } else if (as.contains("s")) {
            if (vmStateMap.get(vm.getVmName()) == State.Migrating) {
                ns = State.Migrating;
            } else {
                ns = State.Stopped;
            }
        /* The domain has crashed */
        } else if (as.contains("c")) {
            ns = State.Error;
        /*
                 * The domain is in process of dying (if we see this twice we
                 * have a problem ?)
                 */
        } else if (as.contains("d")) {
            ns = State.Stopping;
        } else {
            ns = State.Unknown;
        }
        LOGGER.trace("state " + ns + " for " + vm.getVmName() + " based on " + as);
        states.put(vm.getVmName(), ns);
    }
    return states;
}
Also used : Xen(com.cloud.hypervisor.ovm3.objects.Xen) HashMap(java.util.HashMap) PowerState(com.cloud.vm.VirtualMachine.PowerState) State(com.cloud.vm.VirtualMachine.State) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with Ovm3ResourceException

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

the class Ovm3HypervisorSupport method execute.

/* Check if the host is in ready state for CS */
public ReadyAnswer execute(ReadyCommand cmd) {
    try {
        Linux host = new Linux(c);
        Pool pool = new Pool(c);
        /* only interesting when doing cluster */
        if (!host.getIsMaster() && config.getAgentInOvm3Cluster()) {
            if (pool.getPoolMasterVip().equalsIgnoreCase(c.getIp())) {
                /* check pool state here */
                return new ReadyAnswer(cmd);
            } else {
                LOGGER.debug("Master IP changes to " + pool.getPoolMasterVip() + ", it should be " + c.getIp());
                return new ReadyAnswer(cmd, "I am not the master server");
            }
        } else if (host.getIsMaster()) {
            LOGGER.debug("Master, not clustered " + config.getAgentHostname());
            return new ReadyAnswer(cmd);
        } else {
            LOGGER.debug("No master, not clustered " + config.getAgentHostname());
            return new ReadyAnswer(cmd);
        }
    } catch (CloudRuntimeException | Ovm3ResourceException e) {
        LOGGER.debug("XML RPC Exception" + e.getMessage(), e);
        throw new CloudRuntimeException("XML RPC Exception" + e.getMessage(), e);
    }
}
Also used : Linux(com.cloud.hypervisor.ovm3.objects.Linux) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) Pool(com.cloud.hypervisor.ovm3.objects.Pool) ReadyAnswer(com.cloud.agent.api.ReadyAnswer)

Aggregations

Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)41 Linux (com.cloud.hypervisor.ovm3.objects.Linux)13 Test (org.junit.Test)10 Answer (com.cloud.agent.api.Answer)9 DataTO (com.cloud.agent.api.to.DataTO)9 CloudstackPlugin (com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)9 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)8 StoragePlugin (com.cloud.hypervisor.ovm3.objects.StoragePlugin)7 Xen (com.cloud.hypervisor.ovm3.objects.Xen)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 ConfigurationException (javax.naming.ConfigurationException)6 ConnectionTest (com.cloud.hypervisor.ovm3.objects.ConnectionTest)5 Pool (com.cloud.hypervisor.ovm3.objects.Pool)5 XenTest (com.cloud.hypervisor.ovm3.objects.XenTest)5 XmlTestResultTest (com.cloud.hypervisor.ovm3.objects.XmlTestResultTest)5 Ovm3SupportTest (com.cloud.hypervisor.ovm3.support.Ovm3SupportTest)5 CreateObjectAnswer (org.apache.cloudstack.storage.command.CreateObjectAnswer)5 SnapshotObjectTO (org.apache.cloudstack.storage.to.SnapshotObjectTO)5 CopyVolumeAnswer (com.cloud.agent.api.storage.CopyVolumeAnswer)4 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4