Search in sources :

Example 1 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method getGuestType.

private String getGuestType(Connect conn, String vmName) {
    LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
    Domain dm = null;
    try {
        dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
        String xmlDesc = dm.getXMLDesc(0);
        parser.parseDomainXML(xmlDesc);
        return parser.getDescription();
    } catch (LibvirtException e) {
        return null;
    } catch (Exception e) {
        return null;
    } finally {
        try {
            if (dm != null) {
                dm.free();
            }
        } catch (LibvirtException l) {
        }
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Domain(org.libvirt.Domain) 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)

Example 2 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private Answer execute(RebootCommand cmd) {
    Long bytesReceived = null;
    Long bytesSent = null;
    synchronized (_vms) {
        _vms.put(cmd.getVmName(), State.Starting);
    }
    try {
        Connect conn = LibvirtConnection.getConnection();
        final String result = rebootVM(conn, cmd.getVmName());
        if (result == null) {
            Integer vncPort = null;
            try {
                vncPort = getVncPort(conn, cmd.getVmName());
            } catch (Exception e) {
            }
            get_rule_logs_for_vms();
            return new RebootAnswer(cmd, null, bytesSent, bytesReceived, vncPort);
        } else {
            return new RebootAnswer(cmd, result);
        }
    } catch (LibvirtException e) {
        return new RebootAnswer(cmd, e.getMessage());
    } finally {
        synchronized (_vms) {
            _vms.put(cmd.getVmName(), State.Running);
        }
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) RebootAnswer(com.cloud.agent.api.RebootAnswer) 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)

Example 3 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method execute.

private Answer execute(SecurityGroupRulesCmd cmd) {
    String vif = null;
    String brname = null;
    try {
        Connect conn = LibvirtConnection.getConnection();
        List<InterfaceDef> nics = getInterfaces(conn, cmd.getVmName());
        vif = nics.get(0).getDevName();
        brname = nics.get(0).getBrName();
    } catch (LibvirtException e) {
        return new SecurityGroupRuleAnswer(cmd, false, e.toString());
    }
    boolean result = add_network_rules(cmd.getVmName(), Long.toString(cmd.getVmId()), cmd.getGuestIp(), cmd.getSignature(), Long.toString(cmd.getSeqNum()), cmd.getGuestMac(), cmd.stringifyRules(), vif, brname);
    if (!result) {
        s_logger.warn("Failed to program network rules for vm " + cmd.getVmName());
        return new SecurityGroupRuleAnswer(cmd, false, "programming network rules failed");
    } else {
        s_logger.debug("Programmed network rules for vm " + cmd.getVmName() + " guestIp=" + cmd.getGuestIp() + ",ingress numrules=" + cmd.getIngressRuleSet().length + ",egress numrules=" + cmd.getEgressRuleSet().length);
        return new SecurityGroupRuleAnswer(cmd);
    }
}
Also used : InterfaceDef(com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer)

Example 4 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method attachOrDetachDevice.

protected synchronized String attachOrDetachDevice(Connect conn, boolean attach, String vmName, String xml) throws LibvirtException, InternalErrorException {
    Domain dm = null;
    try {
        dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes((vmName.getBytes())));
        if (attach) {
            s_logger.debug("Attaching device: " + xml);
            dm.attachDevice(xml);
        } else {
            s_logger.debug("Detaching device: " + xml);
            dm.detachDevice(xml);
        }
    } catch (LibvirtException e) {
        if (attach) {
            s_logger.warn("Failed to attach device to " + vmName + ": " + e.getMessage());
        } else {
            s_logger.warn("Failed to detach device from " + vmName + ": " + e.getMessage());
        }
        throw e;
    } catch (Exception e) {
        throw new InternalErrorException(e.toString());
    } finally {
        if (dm != null) {
            try {
                dm.free();
            } catch (LibvirtException l) {
            }
        }
    }
    return null;
}
Also used : LibvirtException(org.libvirt.LibvirtException) InternalErrorException(com.cloud.exception.InternalErrorException) Domain(org.libvirt.Domain) 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)

Example 5 with LibvirtException

use of org.libvirt.LibvirtException in project CloudStack-archive by CloudStack-extras.

the class LibvirtComputingResource method getVncPort.

protected Integer getVncPort(Connect conn, String vmName) throws LibvirtException {
    LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
    Domain dm = null;
    try {
        dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
        String xmlDesc = dm.getXMLDesc(0);
        parser.parseDomainXML(xmlDesc);
        return parser.getVncPort();
    } finally {
        try {
            if (dm != null) {
                dm.free();
            }
        } catch (LibvirtException l) {
        }
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) Domain(org.libvirt.Domain)

Aggregations

LibvirtException (org.libvirt.LibvirtException)176 Connect (org.libvirt.Connect)109 Answer (com.cloud.agent.api.Answer)63 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)58 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)55 LibvirtRequestWrapper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtRequestWrapper)55 LibvirtUtilitiesHelper (com.cloud.hypervisor.kvm.resource.wrapper.LibvirtUtilitiesHelper)55 Test (org.junit.Test)55 Domain (org.libvirt.Domain)53 InternalErrorException (com.cloud.exception.InternalErrorException)41 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)41 URISyntaxException (java.net.URISyntaxException)32 StoragePool (org.libvirt.StoragePool)27 NicTO (com.cloud.agent.api.to.NicTO)25 InterfaceDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef)23 KVMStoragePoolManager (com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager)22 ConfigurationException (javax.naming.ConfigurationException)22 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)21 FileNotFoundException (java.io.FileNotFoundException)17