Package com.xensource.xenapi

Examples of com.xensource.xenapi.Connection


        return CitrixHelper.getXcpGuestOsType(stdType);
    }

    protected NetworkUsageAnswer execute(NetworkUsageCommand cmd) {
        try {
            Connection conn = getConnection();
            if(cmd.getOption()!=null && cmd.getOption().equals("create") ){
                String result = networkUsage(conn, cmd.getPrivateIP(), "create", null);
                NetworkUsageAnswer answer = new NetworkUsageAnswer(cmd, result, 0L, 0L);
                return answer;
            }
View Full Code Here


        return volumeToList;
    }

    protected MigrateWithStorageAnswer execute(MigrateWithStorageCommand cmd) {
        Connection connection = getConnection();
        VirtualMachineTO vmSpec = cmd.getVirtualMachine();
        Map<VolumeTO, StorageFilerTO> volumeToFiler = cmd.getVolumeToFiler();
        final String vmName = vmSpec.getName();
        State state = s_vms.getState(_cluster, vmName);
        Task task = null;
View Full Code Here

            }
        }
    }

    protected MigrateWithStorageReceiveAnswer execute(MigrateWithStorageReceiveCommand cmd) {
        Connection connection = getConnection();
        VirtualMachineTO vmSpec = cmd.getVirtualMachine();
        Map<VolumeTO, StorageFilerTO> volumeToFiler = cmd.getVolumeToFiler();

        try {
            // Get a map of all the SRs to which the vdis will be migrated.
View Full Code Here

            return new MigrateWithStorageReceiveAnswer(cmd, e);
        }
    }

    protected MigrateWithStorageSendAnswer execute(MigrateWithStorageSendCommand cmd) {
        Connection connection = getConnection();
        VirtualMachineTO vmSpec = cmd.getVirtualMachine();
        Map<VolumeTO, Object> volumeToSr = cmd.getVolumeToSr();
        Map<NicTO, Object> nicToNetwork = cmd.getNicToNetwork();
        Map<String, String> token = cmd.getToken();
        final String vmName = vmSpec.getName();
View Full Code Here

            }
        }
    }

    protected MigrateWithStorageCompleteAnswer execute(MigrateWithStorageCompleteCommand cmd) {
        Connection connection = getConnection();
        VirtualMachineTO vmSpec = cmd.getVirtualMachine();

        try {
            Host host = Host.getByUuid(connection, _host.uuid);
            Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName());
View Full Code Here

            return new MigrateWithStorageCompleteAnswer(cmd, e);
        }
    }

    protected MigrateVolumeAnswer execute(MigrateVolumeCommand cmd) {
        Connection connection = getConnection();
        String volumeUUID = cmd.getVolumePath();
        StorageFilerTO poolTO = cmd.getPool();

        try {
            SR destinationPool = getStorageRepository(connection, poolTO.getUuid());
View Full Code Here

    }

    @Override
    public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException {
        Map<CitrixResourceBase, Map<String, String>> resources = new HashMap<CitrixResourceBase, Map<String, String>>();
        Connection conn = null;
        if (!url.getScheme().equals("http")) {
            String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
            s_logger.debug(msg);
            return null;
        }
        if (clusterId == null) {
            String msg = "must specify cluster Id when add host";
            s_logger.debug(msg);
            throw new RuntimeException(msg);
        }

    if (podId == null) {
      String msg = "must specify pod Id when add host";
      s_logger.debug(msg);
      throw new RuntimeException(msg);
    }

        ClusterVO cluster = _clusterDao.findById(clusterId);
        if(cluster == null || cluster.getHypervisorType() != HypervisorType.XenServer) {
          if(s_logger.isInfoEnabled())
                s_logger.info("invalid cluster id or cluster is not for XenServer hypervisors");
        return null;
        }

        try {
            List<HostVO> eHosts = _resourceMgr.listAllHostsInCluster(clusterId);
            if( eHosts.size() > 0 ) {
              HostVO eHost = eHosts.get(0);
              _hostDao.loadDetails(eHost);
            }
            String hostname = url.getHost();
            InetAddress ia = InetAddress.getByName(hostname);
            String hostIp = ia.getHostAddress();
            Queue<String> pass=new LinkedList<String>();
            pass.add(password);
            String masterIp = _connPool.getMasterIp(hostIp, username, pass);
            conn = _connPool.masterConnect(masterIp, username, pass);
            if (conn == null) {
                String msg = "Unable to get a connection to " + url;
                s_logger.debug(msg);
                throw new DiscoveryException(msg);
            }

            Set<Pool> pools = Pool.getAll(conn);
            Pool pool = pools.iterator().next();
            Pool.Record pr = pool.getRecord(conn);
            String poolUuid = pr.uuid;
            Map<Host, Host.Record> hosts = Host.getAllRecords(conn);

            /*set cluster hypervisor type to xenserver*/
            ClusterVO clu = _clusterDao.findById(clusterId);
            if ( clu.getGuid()== null ) {
                setClusterGuid(clu, poolUuid);
            } else {
                List<HostVO> clusterHosts = _resourceMgr.listAllHostsInCluster(clusterId);
                if( clusterHosts != null && clusterHosts.size() > 0) {
                    if (!clu.getGuid().equals(poolUuid)) {
                        if (hosts.size() == 1) {
                            if (!addHostsToPool(conn, hostIp, clusterId)) {
                                String msg = "Unable to add host(" + hostIp + ") to cluster " + clusterId;
                                s_logger.warn(msg);
                                throw new DiscoveryException(msg);
                            }
                        } else {
                            String msg = "Host (" + hostIp + ") is already in pool(" + poolUuid + "), can to join pool(" + clu.getGuid() + ")";
                            s_logger.warn(msg);
                            throw new DiscoveryException(msg);
                        }
                    }
                } else {
                    setClusterGuid(clu, poolUuid);
                }
            }
            // can not use this conn after this point, because this host may join a pool, this conn is retired
            if (conn != null) {
                try{
                    Session.logout(conn);
                } catch (Exception e ) {
                }
                conn.dispose();
                conn = null;
            }

            poolUuid = clu.getGuid();
            _clusterDao.update(clusterId, clu);
View Full Code Here

            _hostDao.loadDetails(host);
            username = host.getDetail("username");
            password = host.getDetail("password");
            pass.add(password);
            String address = host.getPrivateIpAddress();
            Connection hostConn = _connPool.slaveConnect(address, username, pass);
            if (hostConn == null) {
                continue;
            }
            try {
                Set<Pool> pools = Pool.getAll(hostConn);
                Pool pool = pools.iterator().next();
                masterIp = pool.getMaster(hostConn).getAddress(hostConn);
                break;

            } catch (Exception e ) {
                s_logger.warn("Can not get master ip address from host " + address);
            } finally {
                try{
                    Session.localLogout(hostConn);
                } catch (Exception e ) {
                }
                hostConn.dispose();
                hostConn = null;
            }
        }

        if (masterIp == null) {
View Full Code Here

    }

    protected boolean pingXenServer() {
        Session slaveSession = null;
        Connection slaveConn = null;
        try {
            URL slaveUrl = null;
            slaveUrl = _connPool.getURL(_host.ip);
            slaveConn = new Connection(slaveUrl, 10);
            slaveSession = _connPool.slaveLocalLoginWithPassword(slaveConn, _username, _password);
            return true;
        } catch (Exception e) {
        } finally {
            if( slaveSession != null ){
                try{
                    Session.localLogout(slaveConn);
                } catch (Exception e) {
                }
                slaveConn.dispose();
            }
        }
        return false;
    }
View Full Code Here

    public ScaleVmAnswer execute(ScaleVmCommand cmd) {
        VirtualMachineTO vmSpec = cmd.getVirtualMachine();
        String vmName = vmSpec.getName();
        try {
            Connection conn = getConnection();
            Set<VM> vms = VM.getByNameLabel(conn, vmName);
            Host host = Host.getByUuid(conn, _host.uuid);

            // If DMC is not enable then don't execute this command.
            if (!isDmcEnabled(conn, host)) {
View Full Code Here

TOP

Related Classes of com.xensource.xenapi.Connection

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.