Search in sources :

Example 66 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class ApiResponseHelper method createSystemVmInstanceResponse.

@Override
public SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine vm) {
    SystemVmInstanceResponse vmResponse = new SystemVmInstanceResponse();
    vmResponse.setId(vm.getUuid());
    vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
    vmResponse.setName(vm.getHostName());
    if (vm.getHostId() != null) {
        Host host = ApiDBUtils.findHostById(vm.getHostId());
        if (host != null) {
            vmResponse.setHostId(host.getUuid());
        }
    }
    if (vm.getState() != null) {
        vmResponse.setState(vm.getState().toString());
    }
    if (vm.getType() == Type.DomainRouter) {
        VirtualRouter router = (VirtualRouter) vm;
        if (router.getRole() != null) {
            vmResponse.setRole(router.getRole().toString());
        }
    }
    vmResponse.setObjectName("systemvminstance");
    return vmResponse;
}
Also used : SystemVmInstanceResponse(org.apache.cloudstack.api.response.SystemVmInstanceResponse) Host(com.cloud.host.Host) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 67 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class ApiResponseHelper method createTemplateResponses.

@Override
public List<TemplateResponse> createTemplateResponses(ResponseView view, long templateId, Long vmId) {
    UserVm vm = findUserVmById(vmId);
    Long hostId = (vm.getHostId() == null ? vm.getLastHostId() : vm.getHostId());
    Host host = findHostById(hostId);
    return createTemplateResponses(view, templateId, host.getDataCenterId(), true);
}
Also used : UserVm(com.cloud.uservm.UserVm) Host(com.cloud.host.Host)

Example 68 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class BigSwitchBcfElement method addBigSwitchBcfDevice.

@Override
@DB
public BigSwitchBcfDeviceVO addBigSwitchBcfDevice(AddBigSwitchBcfDeviceCmd cmd) {
    BigSwitchBcfDeviceVO newBcfDevice;
    bcfUtilsInit();
    ServerResource resource = new BigSwitchBcfResource();
    final String deviceName = BcfConstants.BIG_SWITCH_BCF.getName();
    NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    final String hostname = cmd.getHost();
    final String username = cmd.getUsername();
    final String password = cmd.getPassword();
    final Boolean nat = cmd.getNat();
    PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if (physicalNetwork == null) {
        throw new InvalidParameterValueException("Could not find phyical network with ID: " + physicalNetworkId);
    }
    long zoneId = physicalNetwork.getDataCenterId();
    final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(physicalNetwork.getId(), networkDevice.getNetworkServiceProvder());
    if (ntwkSvcProvider == null) {
        throw new CloudRuntimeException("Network Service Provider: " + networkDevice.getNetworkServiceProvder() + " is not enabled in the physical network: " + physicalNetworkId + "to add this device");
    } else if (ntwkSvcProvider.getState() == PhysicalNetworkServiceProvider.State.Shutdown) {
        throw new CloudRuntimeException("Network Service Provider: " + ntwkSvcProvider.getProviderName() + " is in shutdown state in the physical network: " + physicalNetworkId + "to add this device");
    }
    ntwkSvcProvider.setFirewallServiceProvided(true);
    ntwkSvcProvider.setGatewayServiceProvided(true);
    ntwkSvcProvider.setNetworkAclServiceProvided(true);
    ntwkSvcProvider.setSourcenatServiceProvided(true);
    ntwkSvcProvider.setStaticnatServiceProvided(true);
    if (_bigswitchBcfDao.listByPhysicalNetwork(physicalNetworkId).size() > 1) {
        throw new CloudRuntimeException("At most two BCF controllers can be configured");
    }
    DataCenterVO zone = _zoneDao.findById(physicalNetwork.getDataCenterId());
    String zoneName;
    if (zone != null) {
        zoneName = zone.getName();
    } else {
        zoneName = String.valueOf(zoneId);
    }
    Boolean natNow = _bcfUtils.isNatEnabled();
    if (!nat && natNow) {
        throw new CloudRuntimeException("NAT is enabled in existing controller. Enable NAT for new controller or remove existing controller first.");
    } else if (nat && !natNow) {
        throw new CloudRuntimeException("NAT is disabled in existing controller. Disable NAT for new controller or remove existing controller first.");
    }
    Map<String, String> params = new HashMap<String, String>();
    params.put("guid", UUID.randomUUID().toString());
    params.put("zoneId", zoneName);
    params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
    params.put("name", "BigSwitch Controller - " + cmd.getHost());
    params.put("hostname", cmd.getHost());
    params.put("username", username);
    params.put("password", password);
    params.put("nat", nat.toString());
    // FIXME What to do with multiple isolation types
    params.put("transportzoneisotype", physicalNetwork.getIsolationMethods().get(0).toLowerCase());
    Map<String, Object> hostdetails = new HashMap<String, Object>();
    hostdetails.putAll(params);
    try {
        resource.configure(cmd.getHost(), hostdetails);
        // store current topology in bcf resource
        TopologyData topo = _bcfUtils.getTopology(physicalNetwork.getId());
        ((BigSwitchBcfResource) resource).setTopology(topo);
        final Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, params);
        if (host != null) {
            newBcfDevice = Transaction.execute(new TransactionCallback<BigSwitchBcfDeviceVO>() {

                @Override
                public BigSwitchBcfDeviceVO doInTransaction(TransactionStatus status) {
                    BigSwitchBcfDeviceVO bigswitchBcfDevice = new BigSwitchBcfDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName, hostname, username, password, nat, BigSwitchBcfApi.HASH_IGNORE);
                    _bigswitchBcfDao.persist(bigswitchBcfDevice);
                    DetailVO detail = new DetailVO(host.getId(), "bigswitchbcfdeviceid", String.valueOf(bigswitchBcfDevice.getId()));
                    _hostDetailsDao.persist(detail);
                    return bigswitchBcfDevice;
                }
            });
        } else {
            throw new CloudRuntimeException("Failed to add BigSwitch BCF Controller Device due to internal error.");
        }
    } catch (ConfigurationException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    // initial topology sync to newly added BCF controller
    HostVO bigswitchBcfHost = _hostDao.findById(newBcfDevice.getHostId());
    _bcfUtils.syncTopologyToBcfHost(bigswitchBcfHost, nat);
    return newBcfDevice;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ServerResource(com.cloud.resource.ServerResource) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) HostVO(com.cloud.host.HostVO) TransactionCallback(com.cloud.utils.db.TransactionCallback) BigSwitchBcfResource(com.cloud.network.resource.BigSwitchBcfResource) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DetailVO(com.cloud.host.DetailVO) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) TopologyData(com.cloud.network.bigswitch.TopologyData) BigSwitchBcfDeviceVO(com.cloud.network.BigSwitchBcfDeviceVO) DB(com.cloud.utils.db.DB)

Example 69 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class XenServer56WrapperTest method testFenceCommand.

@Test
public void testFenceCommand() {
    final VMInstanceVO vm = Mockito.mock(VMInstanceVO.class);
    final Host host = Mockito.mock(Host.class);
    final Connection conn = Mockito.mock(Connection.class);
    final FenceCommand fenceCommand = new FenceCommand(vm, host);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(xenServer56Resource.getConnection()).thenReturn(conn);
    final Answer answer = wrapper.execute(fenceCommand, xenServer56Resource);
    verify(xenServer56Resource, times(1)).getConnection();
    verify(xenServer56Resource, times(1)).checkHeartbeat(fenceCommand.getHostGuid());
    assertFalse(answer.getResult());
}
Also used : Answer(com.cloud.agent.api.Answer) FenceCommand(com.cloud.agent.api.FenceCommand) Connection(com.xensource.xenapi.Connection) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) Test(org.junit.Test)

Example 70 with Host

use of com.cloud.host.Host in project cloudstack by apache.

the class OvsTunnelManagerImpl method prepareVpcTopologyUpdate.

OvsVpcPhysicalTopologyConfigCommand prepareVpcTopologyUpdate(long vpcId) {
    VpcVO vpc = _vpcDao.findById(vpcId);
    assert (vpc != null) : "invalid vpc id";
    List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
    List<Long> hostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
    List<Long> vmIds = _ovsNetworkToplogyGuru.getAllActiveVmsInVpc(vpcId);
    List<OvsVpcPhysicalTopologyConfigCommand.Host> hosts = new ArrayList<>();
    List<OvsVpcPhysicalTopologyConfigCommand.Tier> tiers = new ArrayList<>();
    List<OvsVpcPhysicalTopologyConfigCommand.Vm> vms = new ArrayList<>();
    for (Long hostId : hostIds) {
        HostVO hostDetails = _hostDao.findById(hostId);
        String remoteIp = null;
        for (Network network : vpcNetworks) {
            try {
                remoteIp = getGreEndpointIP(hostDetails, network);
            } catch (Exception e) {
                s_logger.info("[ignored]" + "error getting GRE endpoint: " + e.getLocalizedMessage());
            }
        }
        OvsVpcPhysicalTopologyConfigCommand.Host host = new OvsVpcPhysicalTopologyConfigCommand.Host(hostId, remoteIp);
        hosts.add(host);
    }
    for (Network network : vpcNetworks) {
        String key = network.getBroadcastUri().getAuthority();
        long gre_key;
        if (key.contains(".")) {
            String[] parts = key.split("\\.");
            gre_key = Long.parseLong(parts[1]);
        } else {
            try {
                gre_key = Long.parseLong(BroadcastDomainType.getValue(key));
            } catch (Exception e) {
                return null;
            }
        }
        NicVO nic = _nicDao.findByIp4AddressAndNetworkId(network.getGateway(), network.getId());
        OvsVpcPhysicalTopologyConfigCommand.Tier tier = new OvsVpcPhysicalTopologyConfigCommand.Tier(gre_key, network.getUuid(), network.getGateway(), nic.getMacAddress(), network.getCidr());
        tiers.add(tier);
    }
    for (long vmId : vmIds) {
        VirtualMachine vmInstance = _vmInstanceDao.findById(vmId);
        List<OvsVpcPhysicalTopologyConfigCommand.Nic> vmNics = new ArrayList<OvsVpcPhysicalTopologyConfigCommand.Nic>();
        for (Nic vmNic : _nicDao.listByVmId(vmId)) {
            Network network = _networkDao.findById(vmNic.getNetworkId());
            if (network.getTrafficType() == TrafficType.Guest) {
                OvsVpcPhysicalTopologyConfigCommand.Nic nic = new OvsVpcPhysicalTopologyConfigCommand.Nic(vmNic.getIPv4Address(), vmNic.getMacAddress(), network.getUuid());
                vmNics.add(nic);
            }
        }
        OvsVpcPhysicalTopologyConfigCommand.Vm vm = new OvsVpcPhysicalTopologyConfigCommand.Vm(vmInstance.getHostId(), vmNics.toArray(new OvsVpcPhysicalTopologyConfigCommand.Nic[vmNics.size()]));
        vms.add(vm);
    }
    return new OvsVpcPhysicalTopologyConfigCommand(hosts.toArray(new OvsVpcPhysicalTopologyConfigCommand.Host[hosts.size()]), tiers.toArray(new OvsVpcPhysicalTopologyConfigCommand.Tier[tiers.size()]), vms.toArray(new OvsVpcPhysicalTopologyConfigCommand.Vm[vms.size()]), vpc.getCidr());
}
Also used : ArrayList(java.util.ArrayList) Network(com.cloud.network.Network) NicVO(com.cloud.vm.NicVO) OvsVpcPhysicalTopologyConfigCommand(com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand) Nic(com.cloud.vm.Nic) Host(com.cloud.host.Host) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) EntityExistsException(javax.persistence.EntityExistsException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VpcVO(com.cloud.network.vpc.VpcVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

Host (com.cloud.host.Host)112 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)37 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)31 ArrayList (java.util.ArrayList)31 HashMap (java.util.HashMap)29 ServerApiException (org.apache.cloudstack.api.ServerApiException)20 ConfigurationException (javax.naming.ConfigurationException)17 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)16 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)16 DB (com.cloud.utils.db.DB)14 Map (java.util.Map)14 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)13 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)13 Answer (com.cloud.agent.api.Answer)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)11 DataCenter (com.cloud.dc.DataCenter)10 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)10 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)10 HostVO (com.cloud.host.HostVO)9 StoragePool (com.cloud.storage.StoragePool)9