Search in sources :

Example 11 with LibvirtException

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

the class LibvirtComputingResource method execute.

private Answer execute(CheckVirtualMachineCommand cmd) {
    try {
        Connect conn = LibvirtConnection.getConnection();
        final State state = getVmState(conn, cmd.getVmName());
        Integer vncPort = null;
        if (state == State.Running) {
            vncPort = getVncPort(conn, cmd.getVmName());
            synchronized (_vms) {
                _vms.put(cmd.getVmName(), State.Running);
            }
        }
        return new CheckVirtualMachineAnswer(cmd, state, vncPort);
    } catch (LibvirtException e) {
        return new CheckVirtualMachineAnswer(cmd, e.getMessage());
    }
}
Also used : CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) LibvirtException(org.libvirt.LibvirtException) State(com.cloud.vm.VirtualMachine.State) Connect(org.libvirt.Connect)

Example 12 with LibvirtException

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

the class LibvirtComputingResource method getHypervisorPath.

private String getHypervisorPath(Connect conn) {
    File f = new File("/usr/bin/cloud-qemu-kvm");
    if (f.exists()) {
        return "/usr/bin/cloud-qemu-kvm";
    } else {
        f = new File("/usr/libexec/cloud-qemu-kvm");
        if (f.exists()) {
            return "/usr/libexec/cloud-qemu-kvm";
        }
        LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
        try {
            parser.parseCapabilitiesXML(conn.getCapabilities());
        } catch (LibvirtException e) {
        }
        return parser.getEmulator();
    }
}
Also used : LibvirtException(org.libvirt.LibvirtException) File(java.io.File)

Example 13 with LibvirtException

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

the class LibvirtComputingResource method getHostInfo.

protected List<Object> getHostInfo() {
    final ArrayList<Object> info = new ArrayList<Object>();
    long speed = 0;
    long cpus = 0;
    long ram = 0;
    String cap = null;
    try {
        Connect conn = LibvirtConnection.getConnection();
        final NodeInfo hosts = conn.nodeInfo();
        boolean result = false;
        try {
            BufferedReader in = new BufferedReader(new FileReader("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"));
            speed = Long.parseLong(in.readLine()) / 1000;
            result = true;
        } catch (FileNotFoundException e) {
        } catch (IOException e) {
        } catch (NumberFormatException e) {
        }
        if (!result) {
            speed = hosts.mhz;
        }
        cpus = hosts.cpus;
        ram = hosts.memory * 1024L;
        LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
        parser.parseCapabilitiesXML(conn.getCapabilities());
        ArrayList<String> oss = parser.getGuestOsType();
        for (String s : oss) {
            /*
				 * Even host supports guest os type more than hvm, we only
				 * report hvm to management server
				 */
            if (s.equalsIgnoreCase("hvm")) {
                cap = "hvm";
            }
        }
    } catch (LibvirtException e) {
    }
    if (isSnapshotSupported()) {
        cap = cap + ",snapshot";
    }
    info.add((int) cpus);
    info.add(speed);
    info.add(ram);
    info.add(cap);
    // save a maximum
    long dom0ram = Math.min(ram / 10, 768 * 1024 * 1024L);
    // of 10% of
    // system ram or
    // 768M
    dom0ram = Math.max(dom0ram, _dom0MinMem);
    info.add(dom0ram);
    s_logger.debug("cpus=" + cpus + ", speed=" + speed + ", ram=" + ram + ", dom0ram=" + dom0ram);
    return info;
}
Also used : LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) NodeInfo(org.libvirt.NodeInfo) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader)

Example 14 with LibvirtException

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

the class LibvirtComputingResource method execute.

private Answer execute(AttachIsoCommand cmd) {
    try {
        Connect conn = LibvirtConnection.getConnection();
        attachOrDetachISO(conn, cmd.getVmName(), cmd.getIsoPath(), cmd.isAttach());
    } catch (LibvirtException e) {
        return new Answer(cmd, false, e.toString());
    } catch (URISyntaxException e) {
        return new Answer(cmd, false, e.toString());
    } catch (InternalErrorException e) {
        return new Answer(cmd, false, e.toString());
    }
    return new Answer(cmd);
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) ConsoleProxyLoadAnswer(com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer) DeleteSnapshotBackupAnswer(com.cloud.agent.api.DeleteSnapshotBackupAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) AttachVolumeAnswer(com.cloud.agent.api.AttachVolumeAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) LibvirtException(org.libvirt.LibvirtException) Connect(org.libvirt.Connect) URISyntaxException(java.net.URISyntaxException) InternalErrorException(com.cloud.exception.InternalErrorException)

Example 15 with LibvirtException

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

the class LibvirtComputingResource method getDisks.

protected List<DiskDef> getDisks(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.getDisks();
    } catch (LibvirtException e) {
        s_logger.debug("Failed to get dom xml: " + e.toString());
        return new ArrayList<DiskDef>();
    } catch (Exception e) {
        s_logger.debug("Failed to get dom xml: " + e.toString());
        return new ArrayList<DiskDef>();
    } finally {
        try {
            if (dm != null) {
                dm.free();
            }
        } catch (LibvirtException e) {
        }
    }
}
Also used : DiskDef(com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef) 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)

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