Package com.xensource.xenapi

Examples of com.xensource.xenapi.Host


            String msg = "Connect some parameter are null hostUuid:" + hostUuid + " ,poolUuid:" + poolUuid
                    + " ,ipAddress:" + ipAddress;
            s_logger.debug(msg);
            throw new CloudRuntimeException(msg);
        }
        Host host = null;
        synchronized (poolUuid.intern()) {
            // Let's see if it is an existing connection.
            mConn = getConnect(poolUuid);
            if (mConn != null){
                try{
                    host = Host.getByUuid(mConn, hostUuid);
                } catch (Types.SessionInvalid e) {
                    s_logger.debug("Session thgrough ip " + mConn.getIp() + " is invalid for pool(" + poolUuid + ") due to " + e.toString());
                    try {
                        loginWithPassword(mConn, mConn.getUsername(), mConn.getPassword(), APIVersion.latest().toString());
                    } catch (Exception e1) {
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug("connect through IP(" + mConn.getIp() + " for pool(" + poolUuid + ") is broken due to " + e.toString());
                       
                        removeConnect(poolUuid);
                        mConn = null;
                    }
                } catch (UuidInvalid e) {
                    String msg = "Host(" + hostUuid + ") doesn't belong to pool(" + poolUuid + "), please execute 'xe pool-join master-address=" + mConn.getIp()
                        + " master-username=" + mConn.getUsername();
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug(msg);
                    }
                    throw new CloudRuntimeException(msg, e);
                } catch (Exception e) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("connect through IP(" + mConn.getIp() + " for pool(" + poolUuid + ") is broken due to " + e.toString());
                    }
                    removeConnect(poolUuid);
                    mConn = null;
                }
            }  
           
            if ( mConn == null ) {
                try {
                    try {
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug("Logging on as the slave to " + ipAddress);
                        }
                        sConn = new Connection(getURL(ipAddress), 5);
                        slaveLocalLoginWithPassword(sConn, username, password);
                    } catch (Exception e){
                        String msg = "Unable to create slave connection to host(" + hostUuid +") due to " + e.toString();
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug(msg);                          
                        }
                        throw new CloudRuntimeException(msg, e);
                    }
                    Pool.Record pr = null;
                    try {
                        pr = getPoolRecord(sConn);
                    } catch (Exception e) {
                        PoolEmergencyTransitionToMaster(ipAddress, username, password);
                        mConn = new XenServerConnection(getURL(ipAddress), ipAddress, username, password, _retries, _interval, wait);
                        try {
                            loginWithPassword(mConn, username, password, APIVersion.latest().toString());
                            pr = getPoolRecord(mConn);
                        catch (Exception e1) {
                            String msg = "Unable to create master connection to host(" + hostUuid +") after transition it to master, due to " + e1.toString();
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug(msg);                          
                            }
                            throw new CloudRuntimeException(msg, e1);
                        }
                        if ( !pr.uuid.equals(poolUuid) ) {
                            String msg = "host(" + hostUuid +") should be in pool(" + poolUuid + "), but it is actually in pool(" + pr.uuid + ")";
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug(msg);                          
                            }
                            throw new CloudRuntimeException(msg);
                        } else {
                            if (s_managePool) {
                                ensurePoolIntegrity(mConn, ipAddress, username, password,  wait);
                            }
                            addConnect(poolUuid, mConn);
                            return mConn;
                        }
                    }
                    if ( !pr.uuid.equals(poolUuid) ) {
                        String msg = "host(" + hostUuid +") should be in pool(" + poolUuid + "), but it is actually in pool(" + pr.uuid + ")";
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug(msg);                          
                        }
                        throw new CloudRuntimeException(msg);
                    }
                    try {
                        masterIp = pr.master.getAddress(sConn);
                        mConn = new XenServerConnection(getURL(masterIp), masterIp, username, password, _retries, _interval, wait);
                        loginWithPassword(mConn, username, password, APIVersion.latest().toString());
                        addConnect(poolUuid, mConn);
                        return mConn;              
                    } catch (Exception e) {
                        String msg = "Unable to logon in " + masterIp + " as master in pool(" + poolUuid + ")";
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug(msg);                          
                        }
                        throw new CloudRuntimeException(msg);
                    }
                } finally {
                    localLogout(sConn);
                    sConn = null;
                }
            }
        }
   
        if ( mConn != null ) {
            if (s_managePool) {
                try {
                    Map<String, String> args = new HashMap<String, String>();
                    host.callPlugin(mConn, "echo", "main", args);
                } catch (Types.SessionInvalid e) {
                    if (s_logger.isDebugEnabled()) {
                        String msg = "Catch Exception: " + e.getClass().getName() + " Can't connect host " + ipAddress + " due to " + e.toString();
                        s_logger.debug(msg);
                    }
View Full Code Here


                    if (vlannum.equals("-1")) {
                        return;
                    }
                    try {
                        vlan.destroy(conn);
                        Host host = Host.getByUuid(conn, _host.uuid);
                        host.forgetDataSourceArchives(conn, "pif_" + bridge + "_tx");
                        host.forgetDataSourceArchives(conn, "pif_" + bridge + "_rx");
                        host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_tx");
                        host.forgetDataSourceArchives(conn, "pif_" + device + "." + vlannum + "_rx");
                    } catch (XenAPIException e) {
                        s_logger.info("Catch " + e.getClass().getName() + ": failed to destory VLAN " + device + " on host " + _host.uuid
                                + " due to "  + e.toString());
                    }
                }
View Full Code Here

    @Override
    protected Answer execute(PoolEjectCommand cmd) {
        Connection conn = getConnection();
        String hostuuid = cmd.getHostuuid();
        try {
            Host host = Host.getByUuid(conn, hostuuid);
            // remove all tags cloud stack add before eject
            Host.Record hr = host.getRecord(conn);
            Iterator<String> it = hr.tags.iterator();
            while (it.hasNext()) {
                String tag = it.next();
                if (tag.contains("cloud-heartbeat-")) {
                    it.remove();
View Full Code Here

        s_statesTable.put(Types.VmPowerState.UNRECOGNIZED, State.Unknown);
    }


    protected boolean cleanupHaltedVms(Connection conn) throws XenAPIException, XmlRpcException {
        Host host = Host.getByUuid(conn, _host.uuid);
        Map<VM, VM.Record> vms = VM.getAllRecords(conn);
        boolean success = true;
        for (Map.Entry<VM, VM.Record> entry : vms.entrySet()) {
            VM vm = entry.getKey();
            VM.Record vmRec = entry.getValue();
View Full Code Here

                    if ( pbdr.host.getUuid(conn).equals(_host.uuid)) {
                        return;
                    }
                }
                sr.setShared(conn, true);
                Host host = Host.getByUuid(conn, _host.uuid);
                PBD.Record pbdr = pbds.iterator().next().getRecord(conn);
                pbdr.host = host;
                pbdr.uuid = "";
                PBD pbd = PBD.create(conn, pbdr);
                pbdPlug(conn, pbd, pbd.getUuid(conn));
View Full Code Here

            synchronized (_cluster.intern()) {
              s_vms.put(_cluster, _name, vmName, State.Starting);
            }
            s_logger.debug("1. The VM " + vmName + " is in Starting state.");

            Host host = Host.getByUuid(conn, _host.uuid);
            vm = createVmFromTemplate(conn, vmSpec, host);

            for (VolumeTO disk : vmSpec.getDisks()) {
                createVbd(conn, disk, vmName, vm, vmSpec.getBootloader());
            }
View Full Code Here

            Map<Host, Host.Record> hostMap = Host.getAllRecords(conn);
            if (hostMap.size() == 1) {
                s_logger.debug("There is the last host in pool " + poolr.uuid );
                return new MaintainAnswer(cmd);
            }
            Host newMaster = null;
            Host.Record newMasterRecord = null;
            for (Map.Entry<Host, Host.Record> entry : hostMap.entrySet()) {
                if (!_host.uuid.equals(entry.getValue().uuid)) {
                    newMaster = entry.getKey();
                    newMasterRecord = entry.getValue();
View Full Code Here

            VmPowerState ps = record.powerState;
            final State state = convertToState(ps);
            if (s_logger.isTraceEnabled()) {
                s_logger.trace("VM " + record.nameLabel + ": powerstate = " + ps + "; vm state=" + state.toString());
            }
            Host host = record.residentOn;
            String host_uuid = null;
            if( ! isRefNull(host) ) {
                try {
                    host_uuid = host.getUuid(conn);
                } catch (BadServerResponse e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (XenAPIException e) {
                    // TODO Auto-generated catch block
View Full Code Here

            Set<VM> vms = VM.getByNameLabel(conn, vmName);

            String ipaddr = cmd.getDestinationIp();

            Set<Host> hosts = Host.getAll(conn);
            Host dsthost = null;
            for (Host host : hosts) {
                if (host.getAddress(conn).equals(ipaddr)) {
                    dsthost = host;
                    break;
                }
View Full Code Here

        }
        return State.Stopped;
    }

    protected Pair<VM, VM.Record> getControlDomain(Connection conn) throws XenAPIException, XmlRpcException {
        Host host = Host.getByUuid(conn, _host.uuid);
        Set<VM> vms = null;
        vms = host.getResidentVMs(conn);
        for (VM vm : vms) {
            if (vm.getIsControlDomain(conn)) {
                return new Pair<VM, VM.Record>(vm, vm.getRecord(conn));
            }
        }
View Full Code Here

TOP

Related Classes of com.xensource.xenapi.Host

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.