Search in sources :

Example 11 with SetupCommand

use of com.cloud.agent.api.SetupCommand in project cloudstack by apache.

the class DirectAgentManagerSimpleImpl method loadResource.

protected void loadResource(Long hostId) {
    HostVO host = hostDao.findById(hostId);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("guid", host.getGuid());
    params.put("ipaddress", host.getPrivateIpAddress());
    params.put("username", "root");
    params.put("password", "password");
    params.put("zone", String.valueOf(host.getDataCenterId()));
    params.put("pod", String.valueOf(host.getPodId()));
    ServerResource resource = null;
    if (host.getHypervisorType() == HypervisorType.XenServer) {
        resource = new XcpOssResource();
        try {
            resource.configure(host.getName(), params);
        } catch (ConfigurationException e) {
            logger.debug("Failed to load resource:" + e.toString());
        }
    } else if (host.getHypervisorType() == HypervisorType.KVM) {
        resource = new LibvirtComputingResource();
        try {
            params.put("public.network.device", "cloudbr0");
            params.put("private.network.device", "cloudbr0");
            resource.configure(host.getName(), params);
        } catch (ConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if (host.getHypervisorType() == HypervisorType.VMware) {
        ClusterVO cluster = clusterDao.findById(host.getClusterId());
        String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue();
        URI uri;
        try {
            uri = new URI(url);
            String userName = clusterDetailsDao.findDetail(cluster.getId(), "username").getValue();
            String password = clusterDetailsDao.findDetail(cluster.getId(), "password").getValue();
            VmwareServerDiscoverer discover = new VmwareServerDiscoverer();
            Map<? extends ServerResource, Map<String, String>> resources = discover.find(host.getDataCenterId(), host.getPodId(), host.getClusterId(), uri, userName, password, null);
            for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
                resource = entry.getKey();
            }
            if (resource == null) {
                throw new CloudRuntimeException("can't find resource");
            }
        } catch (DiscoveryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    hostResourcesMap.put(hostId, resource);
    HostEnvironment env = new HostEnvironment();
    SetupCommand cmd = new SetupCommand(env);
    cmd.setNeedSetup(true);
    resource.executeRequest(cmd);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) HashMap(java.util.HashMap) ServerResource(com.cloud.resource.ServerResource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) VmwareServerDiscoverer(com.cloud.hypervisor.vmware.VmwareServerDiscoverer) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) XcpOssResource(com.cloud.hypervisor.xenserver.resource.XcpOssResource) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) LibvirtComputingResource(com.cloud.hypervisor.kvm.resource.LibvirtComputingResource) HashMap(java.util.HashMap) Map(java.util.Map) DiscoveryException(com.cloud.exception.DiscoveryException)

Aggregations

SetupCommand (com.cloud.agent.api.SetupCommand)11 HostEnvironment (com.cloud.host.HostEnvironment)10 Answer (com.cloud.agent.api.Answer)9 Test (org.junit.Test)5 SetupAnswer (com.cloud.agent.api.SetupAnswer)4 ClusterVO (com.cloud.dc.ClusterVO)4 HostVO (com.cloud.host.HostVO)4 XsHost (com.cloud.hypervisor.xenserver.resource.XsHost)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)2 PvlanSetupCommand (com.cloud.agent.api.PvlanSetupCommand)2 RebootAnswer (com.cloud.agent.api.RebootAnswer)2 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)2 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 ConnectionException (com.cloud.exception.ConnectionException)2 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)2 ConfigurationException (javax.naming.ConfigurationException)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 AttachIsoAnswer (com.cloud.agent.api.AttachIsoAnswer)1