Package org.libvirt

Examples of org.libvirt.Connect


        synchronized (_vms) {
            _vms.put(cmd.getVmName(), State.Starting);
        }

        try {
            Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
            final String result = rebootVM(conn, cmd.getVmName());
            if (result == null) {
                Integer vncPort = null;
                try {
                    vncPort = getVncPort(conn, cmd.getVmName());
View Full Code Here


    protected GetVmDiskStatsAnswer execute(GetVmDiskStatsCommand cmd) {
        List<String> vmNames = cmd.getVmNames();
        try {
            HashMap<String, List<VmDiskStatsEntry>> vmDiskStatsNameMap = new HashMap<String, List<VmDiskStatsEntry>>();
            Connect conn = LibvirtConnection.getConnection();
            for (String vmName : vmNames) {
                List<VmDiskStatsEntry> statEntry = getVmDiskStat(conn, vmName);
                if (statEntry == null) {
                    continue;
                }
View Full Code Here

    protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
        List<String> vmNames = cmd.getVmNames();
        try {
            HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String, VmStatsEntry>();
            for (String vmName : vmNames) {
                Connect conn = LibvirtConnection.getConnectionByVmName(vmName);
                VmStatsEntry statEntry = getVmStat(conn, vmName);
                if (statEntry == null) {
                    continue;
                }
View Full Code Here

        synchronized (_vms) {
            state = _vms.get(vmName);
            _vms.put(vmName, State.Stopping);
        }
        try {
            Connect conn = LibvirtConnection.getConnectionByVmName(vmName);

            List<DiskDef> disks = getDisks(conn, vmName);
            List<InterfaceDef> ifaces = getInterfaces(conn, vmName);

            destroy_network_rules_for_vm(conn, vmName);
View Full Code Here

        vmSpec.setVncAddr(cmd.getHostIp());
        String vmName = vmSpec.getName();
        LibvirtVMDef vm = null;

        State state = State.Stopped;
        Connect conn = null;
        try {
            synchronized (_vms) {
                _vms.put(vmName, State.Starting);
            }

            vm = createVMFromSpec(vmSpec);

            conn = LibvirtConnection.getConnectionByType(vm.getHvsType());

            createVbd(conn, vmSpec, vmName, vm);

            _storagePoolMgr.connectPhysicalDisksViaVmSpec(vmSpec);

            createVifs(vmSpec, vm);

            s_logger.debug("starting " + vmName + ": " + vm.toString());
            startVM(conn, vmName, vm.toString());

            NicTO[] nics = vmSpec.getNics();
            for (NicTO nic : nics) {
                if (nic.isSecurityGroupEnabled() || ( nic.getIsolationUri() != null
                         && nic.getIsolationUri().getScheme().equalsIgnoreCase(IsolationType.Ec2.toString()))) {
                    if (vmSpec.getType() != VirtualMachine.Type.User) {
                        default_network_rules_for_systemvm(conn, vmName);
                        break;
                    } else {
                        List<String> nicSecIps = nic.getNicSecIps();
                        String secIpsStr;
                        StringBuilder sb = new StringBuilder();
                        if (nicSecIps != null) {
                            for (String ip : nicSecIps) {
                                sb.append(ip).append(":");
                            }
                            secIpsStr = sb.toString();
                        } else {
                            secIpsStr = "0:";
                        }
                        default_network_rules(conn, vmName, nic, vmSpec.getId(), secIpsStr);
                    }
                }
            }

            // pass cmdline info to system vms
            if (vmSpec.getType() != VirtualMachine.Type.User) {
                if ((conn.getVersion() < 1001000)) { // CLOUDSTACK-2823: try passCmdLine some times if kernel < 2.6.34 and qemu < 1.1.0 on hypervisor (for instance, CentOS 6.4)
                    //wait for 5 minutes at most
                    String controlIp = null;
                    for (NicTO nic : nics) {
                        if (nic.getType() == TrafficType.Control) {
                            controlIp = nic.getIp();
View Full Code Here

        int i = 0;
        s_logger.trace("Checking on the HALTED State");
        Domain dm = null;
        for (; i < 5; i++) {
            try {
                Connect conn = LibvirtConnection.getConnectionByVmName(vm);
                dm = conn.domainLookupByName(vm);
                DomainInfo.DomainState vps = dm.getInfo().state;
                if (vps != null
                        && vps != DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF
                        && vps != DomainInfo.DomainState.VIR_DOMAIN_NOSTATE) {
                    return convertToState(vps);
View Full Code Here

        return la;
    }

    private HashMap<String, State> getAllVms() {
        final HashMap<String, State> vmStates = new HashMap<String, State>();
        Connect conn = null;

        if (_hypervisorType == HypervisorType.LXC) {
        try {
            conn = LibvirtConnection.getConnectionByType(HypervisorType.LXC.toString());
            vmStates.putAll(getAllVms(conn));
View Full Code Here

        return vmStates;
    }
   
    private HashMap<String, HostVmStateReportEntry> getHostVmStateReport() {
        final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<String, HostVmStateReportEntry>();
        Connect conn = null;

        if (_hypervisorType == HypervisorType.LXC) {
        try {
            conn = LibvirtConnection.getConnectionByType(HypervisorType.LXC.toString());
            vmStates.putAll(getHostVmStateReport(conn));
View Full Code Here

        long cpus = 0;
        long ram = 0;
        int cpuSockets = 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;
            }

            cpuSockets = hosts.sockets;
            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
View Full Code Here

        }
    }

    private Answer execute(NetworkRulesSystemVmCommand cmd) {
        boolean success = false;
        Connect conn;
        try {
            conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
            success = default_network_rules_for_systemvm(conn, cmd.getVmName());
        } catch (LibvirtException e) {
            s_logger.trace("Ignoring libvirt error.", e);
View Full Code Here

TOP

Related Classes of org.libvirt.Connect

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.