Search in sources :

Example 86 with LibvirtException

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

the class LibvirtComputingResource method getInterfaces.

protected List<InterfaceDef> getInterfaces(Connect conn, String vmName) {
    LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
    Domain dm = null;
    try {
        dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
        parser.parseDomainXML(dm.getXMLDesc(0));
        return parser.getInterfaces();
    } catch (LibvirtException e) {
        s_logger.debug("Failed to get dom xml: " + e.toString());
        return new ArrayList<InterfaceDef>();
    } catch (Exception e) {
        s_logger.debug("Failed to get dom xml: " + e.toString());
        return new ArrayList<InterfaceDef>();
    } finally {
        try {
            if (dm != null) {
                dm.free();
            }
        } catch (LibvirtException e) {
        }
    }
}
Also used : InterfaceDef(com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef) 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 87 with LibvirtException

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

the class LibvirtComputingResource method execute.

private synchronized Answer execute(MigrateCommand cmd) {
    String vmName = cmd.getVmName();
    State state = null;
    String result = null;
    synchronized (_vms) {
        state = _vms.get(vmName);
        _vms.put(vmName, State.Stopping);
    }
    Domain dm = null;
    Connect dconn = null;
    Domain destDomain = null;
    Connect conn = null;
    try {
        conn = LibvirtConnection.getConnection();
        dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName.getBytes()));
        dconn = new Connect("qemu+tcp://" + cmd.getDestinationIp() + "/system");
        /*
			 * Hard code lm flags: VIR_MIGRATE_LIVE(1<<0) and
			 * VIR_MIGRATE_PERSIST_DEST(1<<3)
			 */
        destDomain = dm.migrate(dconn, (1 << 0) | (1 << 3), vmName, "tcp:" + cmd.getDestinationIp(), _migrateSpeed);
    } catch (LibvirtException e) {
        s_logger.debug("Can't migrate domain: " + e.getMessage());
        result = e.getMessage();
    } catch (Exception e) {
        s_logger.debug("Can't migrate domain: " + e.getMessage());
        result = e.getMessage();
    } finally {
        try {
            if (dm != null) {
                dm.free();
            }
            if (dconn != null) {
                dconn.close();
            }
            if (destDomain != null) {
                destDomain.free();
            }
        } catch (final LibvirtException e) {
        }
    }
    if (result != null) {
        synchronized (_vms) {
            _vms.put(vmName, state);
        }
    } else {
        destroy_network_rules_for_vm(conn, vmName);
        cleanupVM(conn, vmName, getVnetId(VirtualMachineName.getVnet(vmName)));
    }
    return new MigrateAnswer(cmd, result == null, result, null);
}
Also used : MigrateAnswer(com.cloud.agent.api.MigrateAnswer) LibvirtException(org.libvirt.LibvirtException) State(com.cloud.vm.VirtualMachine.State) Connect(org.libvirt.Connect) 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 88 with LibvirtException

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

the class CloudZonesComputingResource method configure.

@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    boolean success = super.configure(name, params);
    if (!success) {
        return false;
    }
    _parent = (String) params.get("mount.path");
    try {
        _dhcpTimeout = Long.parseLong((String) params.get("dhcp.timeout"));
    } catch (Exception e) {
        _dhcpTimeout = 1200000;
    }
    _hostIp = (String) params.get("host.ip");
    _hostMacAddress = (String) params.get("host.mac.address");
    try {
        Connect conn;
        conn = LibvirtConnection.getConnection();
        setupDhcpManager(conn, _guestBridgeName);
    } catch (LibvirtException e) {
        s_logger.debug("Failed to get libvirt connection:" + e.toString());
        return false;
    }
    _dhcpSnooper.configure(name, params);
    _vmDataServer.configure(name, params);
    return true;
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) ConfigurationException(javax.naming.ConfigurationException) LibvirtException(org.libvirt.LibvirtException)

Example 89 with LibvirtException

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

the class CloudZonesComputingResource method setupDhcpManager.

private void setupDhcpManager(Connect conn, String bridgeName) {
    _dhcpSnooper = new DhcpSnooperImpl(bridgeName, _dhcpTimeout);
    List<Pair<String, String>> macs = new ArrayList<Pair<String, String>>();
    try {
        int[] domainIds = conn.listDomains();
        for (int i = 0; i < domainIds.length; i++) {
            Domain vm = conn.domainLookupByID(domainIds[i]);
            if (vm.getName().startsWith("i-")) {
                List<InterfaceDef> nics = getInterfaces(conn, vm.getName());
                InterfaceDef nic = nics.get(0);
                macs.add(new Pair<String, String>(nic.getMacAddress(), vm.getName()));
            }
        }
    } catch (LibvirtException e) {
        s_logger.debug("Failed to get MACs: " + e.toString());
    }
    _dhcpSnooper.initializeMacTable(macs);
}
Also used : InterfaceDef(com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef) LibvirtException(org.libvirt.LibvirtException) DhcpSnooperImpl(com.cloud.agent.dhcp.DhcpSnooperImpl) ArrayList(java.util.ArrayList) Domain(org.libvirt.Domain) Pair(com.cloud.utils.Pair)

Example 90 with LibvirtException

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

the class LibvirtComputingResource method getRealPowerState.

protected State getRealPowerState(String vm) {
    int i = 0;
    s_logger.trace("Checking on the HALTED State");
    Domain dm = null;
    for (; i < 5; i++) {
        try {
            Connect conn = LibvirtConnection.getConnection();
            dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vm.getBytes()));
            DomainInfo.DomainState vps = dm.getInfo().state;
            if (vps != null && vps != DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF && vps != DomainInfo.DomainState.VIR_DOMAIN_NOSTATE) {
                return convertToState(vps);
            }
        } catch (final LibvirtException e) {
            s_logger.trace(e.getMessage());
        } catch (Exception e) {
            s_logger.trace(e.getMessage());
        } finally {
            try {
                if (dm != null) {
                    dm.free();
                }
            } catch (final LibvirtException e) {
            }
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
    }
    return State.Stopped;
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) DomainInfo(org.libvirt.DomainInfo) 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)

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