Search in sources :

Example 51 with HostVO

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

the class DataMigrationUtility method activeSSVMCount.

/**
 * Returns the count of active SSVMs - SSVM with agents in connected state, so as to dynamically increase the thread pool
 * size when SSVMs scale
 */
protected int activeSSVMCount(DataStore dataStore) {
    long datacenterId = dataStore.getScope().getScopeId();
    List<SecondaryStorageVmVO> ssvms = secStorageVmDao.getSecStorageVmListInStates(null, datacenterId, VirtualMachine.State.Running, VirtualMachine.State.Migrating);
    int activeSSVMs = 0;
    for (SecondaryStorageVmVO vm : ssvms) {
        String name = "s-" + vm.getId() + "-VM";
        HostVO ssHost = hostDao.findByName(name);
        if (ssHost != null) {
            if (ssHost.getState() == Status.Up) {
                activeSSVMs++;
            }
        }
    }
    return activeSSVMs;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) HostVO(com.cloud.host.HostVO)

Example 52 with HostVO

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

the class VolumeOrchestrator method revokeAccess.

@Override
public void revokeAccess(long vmId, long hostId) {
    HostVO host = _hostDao.findById(hostId);
    List<VolumeVO> volumesForVm = _volsDao.findByInstance(vmId);
    if (volumesForVm != null) {
        for (VolumeVO volumeForVm : volumesForVm) {
            VolumeInfo volumeInfo = volFactory.getVolume(volumeForVm.getId());
            // pool id can be null for the VM's volumes in Allocated state
            if (volumeForVm.getPoolId() != null) {
                DataStore dataStore = dataStoreMgr.getDataStore(volumeForVm.getPoolId(), DataStoreRole.Primary);
                volService.revokeAccess(volumeInfo, host, dataStore);
            }
        }
    }
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) HostVO(com.cloud.host.HostVO)

Example 53 with HostVO

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

the class NetworkOrchestrator method cleanupPersistentnNetworkResources.

private void cleanupPersistentnNetworkResources(NetworkVO network) {
    long networkOfferingId = network.getNetworkOfferingId();
    NetworkOfferingVO offering = _networkOfferingDao.findById(networkOfferingId);
    if (offering != null) {
        if (networkMeetsPersistenceCriteria(network, offering, true) && _networksDao.getOtherPersistentNetworksCount(network.getId(), network.getBroadcastUri().toString(), offering.isPersistent()) == 0) {
            List<HostVO> hosts = resourceManager.listAllUpAndEnabledHostsInOneZoneByType(Host.Type.Routing, network.getDataCenterId());
            for (HostVO host : hosts) {
                try {
                    NicTO to = createNicTOFromNetworkAndOffering(network, offering, host);
                    CleanupPersistentNetworkResourceCommand cmd = new CleanupPersistentNetworkResourceCommand(to);
                    CleanupPersistentNetworkResourceAnswer answer = (CleanupPersistentNetworkResourceAnswer) _agentMgr.send(host.getId(), cmd);
                    if (answer == null) {
                        s_logger.warn("Unable to get an answer to the CleanupPersistentNetworkResourceCommand from agent:" + host.getId());
                        continue;
                    }
                    if (!answer.getResult()) {
                        s_logger.warn("Unable to setup agent " + host.getId() + " due to " + answer.getDetails());
                    }
                } catch (Exception e) {
                    s_logger.warn("Failed to cleanup network resources on host: " + host.getName());
                }
            }
        }
    }
}
Also used : CleanupPersistentNetworkResourceAnswer(com.cloud.agent.api.CleanupPersistentNetworkResourceAnswer) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) HostVO(com.cloud.host.HostVO) CleanupPersistentNetworkResourceCommand(com.cloud.agent.api.CleanupPersistentNetworkResourceCommand) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) ConfigurationException(javax.naming.ConfigurationException) NicTO(com.cloud.agent.api.to.NicTO)

Example 54 with HostVO

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

the class BigSwitchBcfElement method createBigSwitchBcfDeviceResponse.

@Override
public BigSwitchBcfDeviceResponse createBigSwitchBcfDeviceResponse(BigSwitchBcfDeviceVO bigswitchBcfDeviceVO) {
    HostVO bigswitchBcfHost = _hostDao.findById(bigswitchBcfDeviceVO.getHostId());
    _hostDao.loadDetails(bigswitchBcfHost);
    BigSwitchBcfDeviceResponse response = new BigSwitchBcfDeviceResponse();
    response.setDeviceName(bigswitchBcfDeviceVO.getDeviceName());
    PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(bigswitchBcfDeviceVO.getPhysicalNetworkId());
    if (pnw != null) {
        response.setPhysicalNetworkId(pnw.getUuid());
    }
    response.setId(bigswitchBcfDeviceVO.getUuid());
    response.setProviderName(bigswitchBcfDeviceVO.getProviderName());
    response.setHostName(bigswitchBcfHost.getDetail("hostname"));
    response.setObjectName("bigswitchbcfdevice");
    return response;
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) BigSwitchBcfDeviceResponse(com.cloud.api.response.BigSwitchBcfDeviceResponse) HostVO(com.cloud.host.HostVO)

Example 55 with HostVO

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

the class BigSwitchBcfUtils method getTopology.

public TopologyData getTopology(long physicalNetworkId) {
    List<NetworkVO> networks;
    List<NicVO> nics;
    networks = _networkDao.listByPhysicalNetworkTrafficType(physicalNetworkId, TrafficType.Guest);
    TopologyData topo = new TopologyData();
    // handle external network first, only if NAT service is enabled
    if (networks != null) {
        if (!(networks.isEmpty()) && isNatEnabled()) {
            // get public net info - needed to set up source nat gateway
            NetworkVO pubNet = getPublicNetwork(physicalNetworkId);
            // locate subnet info
            SearchCriteria<VlanVO> sc = _vlanDao.createSearchCriteria();
            sc.setParameters("network_id", pubNet.getId());
            VlanVO vlanVO = _vlanDao.findOneBy(sc);
            // add tenant external network external
            TopologyData.Network network = topo.new Network();
            network.setId("external");
            network.setName("external");
            network.setTenantId("external");
            network.setTenantName("external");
            String pubVlan = null;
            try {
                pubVlan = BroadcastDomainType.getValue(vlanVO.getVlanTag());
                if (StringUtils.isNumeric(pubVlan)) {
                    network.setVlan(Integer.valueOf(pubVlan));
                } else {
                    // untagged
                    pubVlan = "0";
                }
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
            topo.addNetwork(network);
        }
    }
    // routerMap used internally for multiple updates to same tenant's router
    // add back to topo.routers after loop
    HashMap<String, RouterData> routerMap = new HashMap<String, RouterData>();
    for (NetworkVO netVO : networks) {
        TopologyData.Network network = topo.new Network();
        network.setId(netVO.getUuid());
        network.setName(netVO.getName());
        Integer vlan = null;
        if (netVO.getBroadcastUri() != null) {
            String vlanStr = BroadcastDomainType.getValue(netVO.getBroadcastUri());
            if (StringUtils.isNumeric(vlanStr)) {
                vlan = Integer.valueOf(vlanStr);
            } else {
                // untagged
                vlan = 0;
            }
        }
        network.setVlan(vlan);
        network.setState(netVO.getState().name());
        nics = _nicDao.listByNetworkId(netVO.getId());
        List<Port> ports = new ArrayList<Port>();
        String tenantId = null;
        String tenantName = null;
        // if VPC network, assign BCF tenant id with vpc uuid
        Vpc vpc = null;
        if (netVO.getVpcId() != null) {
            vpc = _vpcDao.acquireInLockTable(netVO.getVpcId());
        }
        if (vpc != null) {
            tenantId = vpc.getUuid();
            tenantName = vpc.getName();
        } else {
            tenantId = netVO.getUuid();
            tenantName = netVO.getName();
        }
        for (NicVO nic : nics) {
            NetworkData netData = new NetworkData();
            TopologyData.Port p = topo.new Port();
            p.setAttachmentInfo(netData.new AttachmentInfo(nic.getUuid(), nic.getMacAddress()));
            VMInstanceVO vm = _vmDao.findById(nic.getInstanceId());
            HostVO host = _hostDao.findById(vm.getHostId());
            // if host not found, ignore this nic
            if (host == null) {
                continue;
            }
            String hostname = host.getName();
            long zoneId = netVO.getDataCenterId();
            String vmwareVswitchLabel = _networkModel.getDefaultGuestTrafficLabel(zoneId, HypervisorType.VMware);
            String[] labelArray = null;
            String vswitchName = null;
            if (vmwareVswitchLabel != null) {
                labelArray = vmwareVswitchLabel.split(",");
                vswitchName = labelArray[0];
            }
            // hypervisor type:
            // kvm: ivs port name
            // vmware: specific portgroup naming convention
            String pgName = "";
            if (host.getHypervisorType() == HypervisorType.KVM) {
                pgName = hostname;
            } else if (host.getHypervisorType() == HypervisorType.VMware) {
                pgName = hostname + "-" + vswitchName;
            }
            p.setHostId(pgName);
            p.setSegmentInfo(netData.new SegmentInfo(BroadcastDomainType.Vlan.name(), vlan));
            p.setOwner(BigSwitchBcfApi.getCloudstackInstanceId());
            List<AttachmentData.Attachment.IpAddress> ipList = new ArrayList<AttachmentData.Attachment.IpAddress>();
            ipList.add(new AttachmentData().getAttachment().new IpAddress(nic.getIPv4Address()));
            p.setIpAddresses(ipList);
            p.setId(nic.getUuid());
            p.setMac(nic.getMacAddress());
            netData.getNetwork().setId(network.getId());
            netData.getNetwork().setName(network.getName());
            netData.getNetwork().setTenantId(tenantId);
            netData.getNetwork().setTenantName(tenantName);
            netData.getNetwork().setState(netVO.getState().name());
            p.setNetwork(netData.getNetwork());
            ports.add(p);
        }
        network.setTenantId(tenantId);
        network.setTenantName(tenantName);
        network.setPorts(ports);
        topo.addNetwork(network);
        // add router for network
        RouterData routerData;
        if (tenantId != null) {
            if (!routerMap.containsKey(tenantId)) {
                routerData = new RouterData(tenantId);
                routerMap.put(tenantId, routerData);
            } else {
                routerData = routerMap.get(tenantId);
            }
            routerData.getRouter().getAcls().addAll(listACLbyNetwork(netVO));
            if (vpc != null) {
                routerData.getRouter().addExternalGateway(getPublicIpByVpc(vpc));
            } else {
                routerData.getRouter().addExternalGateway(getPublicIpByNetwork(netVO));
            }
            RouterInterfaceData intf = new RouterInterfaceData(tenantId, netVO.getGateway(), netVO.getCidr(), netVO.getUuid(), netVO.getName());
            routerData.getRouter().addInterface(intf);
        }
    }
    for (RouterData rd : routerMap.values()) {
        topo.addRouter(rd.getRouter());
    }
    return topo;
}
Also used : HashMap(java.util.HashMap) Port(com.cloud.network.bigswitch.TopologyData.Port) ArrayList(java.util.ArrayList) Vpc(com.cloud.network.vpc.Vpc) URISyntaxException(java.net.URISyntaxException) Network(com.cloud.network.Network) VlanVO(com.cloud.dc.VlanVO) NicVO(com.cloud.vm.NicVO) NetworkVO(com.cloud.network.dao.NetworkVO) Port(com.cloud.network.bigswitch.TopologyData.Port) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostVO(com.cloud.host.HostVO)

Aggregations

HostVO (com.cloud.host.HostVO)631 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)223 ArrayList (java.util.ArrayList)178 Answer (com.cloud.agent.api.Answer)105 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)95 StoragePoolHostVO (com.cloud.storage.StoragePoolHostVO)91 Test (org.junit.Test)81 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)75 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)74 ClusterVO (com.cloud.dc.ClusterVO)72 Account (com.cloud.user.Account)67 HashMap (java.util.HashMap)67 VMInstanceVO (com.cloud.vm.VMInstanceVO)60 ConfigurationException (javax.naming.ConfigurationException)60 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)58 DataCenterVO (com.cloud.dc.DataCenterVO)50 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)48 HostPodVO (com.cloud.dc.HostPodVO)47 DB (com.cloud.utils.db.DB)47 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)46