Search in sources :

Example 41 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class DirectPodBasedNetworkGuru method allocate.

@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
    DataCenterVO dc = _dcDao.findById(network.getDataCenterId());
    ReservationStrategy rsStrategy = ReservationStrategy.Start;
    _dcDao.loadDetails(dc);
    String dhcpStrategy = dc.getDetail(ZoneConfig.DhcpStrategy.key());
    if ("external".equalsIgnoreCase(dhcpStrategy)) {
        rsStrategy = ReservationStrategy.Create;
    }
    if (nic != null && nic.getRequestedIPv4() != null) {
        throw new CloudRuntimeException("Does not support custom ip allocation at this time: " + nic);
    }
    if (nic == null) {
        nic = new NicProfile(rsStrategy, null, null, null, null);
    } else if (nic.getIPv4Address() == null) {
        nic.setReservationStrategy(ReservationStrategy.Start);
    } else {
        nic.setReservationStrategy(ReservationStrategy.Create);
    }
    if (rsStrategy == ReservationStrategy.Create) {
        String mac = _networkModel.getNextAvailableMacAddressInNetwork(network.getId());
        nic.setMacAddress(mac);
    }
    return nic;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ReservationStrategy(com.cloud.vm.Nic.ReservationStrategy) NicProfile(com.cloud.vm.NicProfile)

Example 42 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class VirtualRouterElement method commitMigration.

@Override
public void commitMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) {
    if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
        return;
    }
    if (vm.getType() == VirtualMachine.Type.DomainRouter) {
        assert vm instanceof DomainRouterVO;
        final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        try {
            networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nic);
        } catch (final ResourceUnavailableException e) {
            s_logger.warn("Timed Out", e);
        }
    } else if (vm.getType() == VirtualMachine.Type.User) {
        assert vm instanceof UserVmVO;
        final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
        _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic);
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 43 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class ResourceManagerImpl method discoverHostsFull.

private List<HostVO> discoverHostsFull(final Long dcId, final Long podId, Long clusterId, final String clusterName, String url, String username, String password, final String hypervisorType, final List<String> hostTags, final Map<String, String> params, final boolean deferAgentCreation) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
    URI uri = null;
    // Check if the zone exists in the system
    final DataCenterVO zone = _dcDao.findById(dcId);
    if (zone == null) {
        throw new InvalidParameterValueException("Can't find zone by id " + dcId);
    }
    final Account account = CallContext.current().getCallingAccount();
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getId())) {
        final PermissionDeniedException ex = new PermissionDeniedException("Cannot perform this operation, Zone with specified id is currently disabled");
        ex.addProxyObject(zone.getUuid(), "dcId");
        throw ex;
    }
    // Check if the pod exists in the system
    if (podId != null) {
        final HostPodVO pod = _podDao.findById(podId);
        if (pod == null) {
            throw new InvalidParameterValueException("Can't find pod by id " + podId);
        }
        // check if pod belongs to the zone
        if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) {
            final InvalidParameterValueException ex = new InvalidParameterValueException("Pod with specified podId" + podId + " doesn't belong to the zone with specified zoneId" + dcId);
            ex.addProxyObject(pod.getUuid(), "podId");
            ex.addProxyObject(zone.getUuid(), "dcId");
            throw ex;
        }
    }
    // Verify cluster information and create a new cluster if needed
    if (clusterName != null && clusterId != null) {
        throw new InvalidParameterValueException("Can't specify cluster by both id and name");
    }
    if (hypervisorType == null || hypervisorType.isEmpty()) {
        throw new InvalidParameterValueException("Need to specify Hypervisor Type");
    }
    if ((clusterName != null || clusterId != null) && podId == null) {
        throw new InvalidParameterValueException("Can't specify cluster without specifying the pod");
    }
    if (clusterId != null) {
        if (_clusterDao.findById(clusterId) == null) {
            throw new InvalidParameterValueException("Can't find cluster by id " + clusterId);
        }
        if (hypervisorType.equalsIgnoreCase(HypervisorType.VMware.toString())) {
            // VMware only allows adding host to an existing cluster, as we
            // already have a lot of information
            // in cluster object, to simplify user input, we will construct
            // neccessary information here
            final Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
            username = clusterDetails.get("username");
            assert username != null;
            password = clusterDetails.get("password");
            assert password != null;
            try {
                uri = new URI(UriUtils.encodeURIComponent(url));
                url = clusterDetails.get("url") + "/" + uri.getHost();
            } catch (final URISyntaxException e) {
                throw new InvalidParameterValueException(url + " is not a valid uri");
            }
        }
    }
    if ((hypervisorType.equalsIgnoreCase(HypervisorType.BareMetal.toString()))) {
        if (hostTags.isEmpty()) {
            throw new InvalidParameterValueException("hosttag is mandatory while adding host of type Baremetal");
        }
    }
    if (clusterName != null) {
        final HostPodVO pod = _podDao.findById(podId);
        if (pod == null) {
            throw new InvalidParameterValueException("Can't find pod by id " + podId);
        }
        ClusterVO cluster = new ClusterVO(dcId, podId, clusterName);
        cluster.setHypervisorType(hypervisorType);
        try {
            cluster = _clusterDao.persist(cluster);
        } catch (final Exception e) {
            cluster = _clusterDao.findBy(clusterName, podId);
            if (cluster == null) {
                final CloudRuntimeException ex = new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod with specified podId and data center with specified dcID", e);
                ex.addProxyObject(pod.getUuid(), "podId");
                ex.addProxyObject(zone.getUuid(), "dcId");
                throw ex;
            }
        }
        clusterId = cluster.getId();
        if (_clusterDetailsDao.findDetail(clusterId, "cpuOvercommitRatio") == null) {
            final ClusterDetailsVO cluster_cpu_detail = new ClusterDetailsVO(clusterId, "cpuOvercommitRatio", "1");
            final ClusterDetailsVO cluster_memory_detail = new ClusterDetailsVO(clusterId, "memoryOvercommitRatio", "1");
            _clusterDetailsDao.persist(cluster_cpu_detail);
            _clusterDetailsDao.persist(cluster_memory_detail);
        }
    }
    try {
        uri = new URI(UriUtils.encodeURIComponent(url));
        if (uri.getScheme() == null) {
            throw new InvalidParameterValueException("uri.scheme is null " + url + ", add nfs:// (or cifs://) as a prefix");
        } else if (uri.getScheme().equalsIgnoreCase("nfs")) {
            if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("")) {
                throw new InvalidParameterValueException("Your host and/or path is wrong.  Make sure it's of the format nfs://hostname/path");
            }
        } else if (uri.getScheme().equalsIgnoreCase("cifs")) {
            // Don't validate against a URI encoded URI.
            final URI cifsUri = new URI(url);
            final String warnMsg = UriUtils.getCifsUriParametersProblems(cifsUri);
            if (warnMsg != null) {
                throw new InvalidParameterValueException(warnMsg);
            }
        }
    } catch (final URISyntaxException e) {
        throw new InvalidParameterValueException(url + " is not a valid uri");
    }
    final List<HostVO> hosts = new ArrayList<HostVO>();
    s_logger.info("Trying to add a new host at " + url + " in data center " + dcId);
    boolean isHypervisorTypeSupported = false;
    for (final Discoverer discoverer : _discoverers) {
        if (params != null) {
            discoverer.putParam(params);
        }
        if (!discoverer.matchHypervisor(hypervisorType)) {
            continue;
        }
        isHypervisorTypeSupported = true;
        Map<? extends ServerResource, Map<String, String>> resources = null;
        processResourceEvent(ResourceListener.EVENT_DISCOVER_BEFORE, dcId, podId, clusterId, uri, username, password, hostTags);
        try {
            resources = discoverer.find(dcId, podId, clusterId, uri, username, password, hostTags);
        } catch (final DiscoveryException e) {
            throw e;
        } catch (final Exception e) {
            s_logger.info("Exception in host discovery process with discoverer: " + discoverer.getName() + ", skip to another discoverer if there is any");
        }
        processResourceEvent(ResourceListener.EVENT_DISCOVER_AFTER, resources);
        if (resources != null) {
            for (final Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
                final ServerResource resource = entry.getKey();
                /*
                     * For KVM, if we go to here, that means kvm agent is
                     * already connected to mgt svr.
                     */
                if (resource instanceof KvmDummyResourceBase) {
                    final Map<String, String> details = entry.getValue();
                    final String guid = details.get("guid");
                    final List<HostVO> kvmHosts = listAllUpAndEnabledHosts(Host.Type.Routing, clusterId, podId, dcId);
                    for (final HostVO host : kvmHosts) {
                        if (host.getGuid().equalsIgnoreCase(guid)) {
                            if (hostTags != null) {
                                if (s_logger.isTraceEnabled()) {
                                    s_logger.trace("Adding Host Tags for KVM host, tags:  :" + hostTags);
                                }
                                _hostTagsDao.persist(host.getId(), hostTags);
                            }
                            hosts.add(host);
                            _agentMgr.notifyMonitorsOfNewlyAddedHost(host.getId());
                            return hosts;
                        }
                    }
                    return null;
                }
                HostVO host = null;
                if (deferAgentCreation) {
                    host = (HostVO) createHostAndAgentDeferred(resource, entry.getValue(), true, hostTags, false);
                } else {
                    host = (HostVO) createHostAndAgent(resource, entry.getValue(), true, hostTags, false);
                }
                if (host != null) {
                    hosts.add(host);
                }
                discoverer.postDiscovery(hosts, _nodeId);
            }
            s_logger.info("server resources successfully discovered by " + discoverer.getName());
            return hosts;
        }
    }
    if (!isHypervisorTypeSupported) {
        final String msg = "Do not support HypervisorType " + hypervisorType + " for " + url;
        s_logger.warn(msg);
        throw new DiscoveryException(msg);
    }
    s_logger.warn("Unable to find the server resources at " + url);
    throw new DiscoveryException("Unable to add the host");
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HostPodVO(com.cloud.dc.HostPodVO) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceInUseException(com.cloud.exception.ResourceInUseException) URISyntaxException(java.net.URISyntaxException) DiscoveryException(com.cloud.exception.DiscoveryException) SshException(com.cloud.utils.ssh.SshException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) StoragePoolHostVO(com.cloud.storage.StoragePoolHostVO) HostVO(com.cloud.host.HostVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) KvmDummyResourceBase(com.cloud.hypervisor.kvm.discoverer.KvmDummyResourceBase) PermissionDeniedException(com.cloud.exception.PermissionDeniedException) ClusterDetailsVO(com.cloud.dc.ClusterDetailsVO) Map(java.util.Map) HashMap(java.util.HashMap) DiscoveryException(com.cloud.exception.DiscoveryException)

Example 44 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class ResourceManagerImpl method fillRoutingHostVO.

@Override
public HostVO fillRoutingHostVO(final HostVO host, final StartupRoutingCommand ssCmd, final HypervisorType hyType, Map<String, String> details, final List<String> hostTags) {
    if (host.getPodId() == null) {
        s_logger.error("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null");
        throw new IllegalArgumentException("Host " + ssCmd.getPrivateIpAddress() + " sent incorrect pod, pod id is null");
    }
    final ClusterVO clusterVO = _clusterDao.findById(host.getClusterId());
    if (clusterVO.getHypervisorType() != hyType) {
        throw new IllegalArgumentException("Can't add host whose hypervisor type is: " + hyType + " into cluster: " + clusterVO.getId() + " whose hypervisor type is: " + clusterVO.getHypervisorType());
    }
    final Map<String, String> hostDetails = ssCmd.getHostDetails();
    if (hostDetails != null) {
        if (details != null) {
            details.putAll(hostDetails);
        } else {
            details = hostDetails;
        }
    }
    final HostPodVO pod = _podDao.findById(host.getPodId());
    final DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
    checkIPConflicts(pod, dc, ssCmd.getPrivateIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicIpAddress(), ssCmd.getPublicNetmask());
    host.setType(com.cloud.host.Host.Type.Routing);
    host.setDetails(details);
    host.setCaps(ssCmd.getCapabilities());
    host.setCpuSockets(ssCmd.getCpuSockets());
    host.setCpus(ssCmd.getCpus());
    host.setTotalMemory(ssCmd.getMemory());
    host.setSpeed(ssCmd.getSpeed());
    host.setHypervisorType(hyType);
    host.setHypervisorVersion(ssCmd.getHypervisorVersion());
    host.setGpuGroups(ssCmd.getGpuGroupDetails());
    return host;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) HostPodVO(com.cloud.dc.HostPodVO)

Example 45 with DataCenterVO

use of com.cloud.dc.DataCenterVO in project cloudstack by apache.

the class ConfigurationServerImpl method createDefaultNetworks.

private void createDefaultNetworks() {
    List<DataCenterVO> zones = _dataCenterDao.listAll();
    long id = 1;
    HashMap<TrafficType, String> guruNames = new HashMap<TrafficType, String>();
    guruNames.put(TrafficType.Public, PublicNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Management, PodBasedNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Control, ControlNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Storage, StorageNetworkGuru.class.getSimpleName());
    guruNames.put(TrafficType.Guest, DirectPodBasedNetworkGuru.class.getSimpleName());
    for (DataCenterVO zone : zones) {
        long zoneId = zone.getId();
        long accountId = 1L;
        Long domainId = zone.getDomainId();
        if (domainId == null) {
            domainId = 1L;
        }
        // Create default networks - system only
        List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
        for (NetworkOfferingVO offering : ntwkOff) {
            if (offering.isSystemOnly()) {
                long related = id;
                long networkOfferingId = offering.getId();
                Mode mode = Mode.Static;
                String networkDomain = null;
                BroadcastDomainType broadcastDomainType = null;
                TrafficType trafficType = offering.getTrafficType();
                boolean specifyIpRanges = false;
                if (trafficType == TrafficType.Management) {
                    broadcastDomainType = BroadcastDomainType.Native;
                } else if (trafficType == TrafficType.Storage) {
                    broadcastDomainType = BroadcastDomainType.Native;
                    specifyIpRanges = true;
                } else if (trafficType == TrafficType.Control) {
                    broadcastDomainType = BroadcastDomainType.LinkLocal;
                } else if (offering.getTrafficType() == TrafficType.Public) {
                    if ((zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled()) || zone.getNetworkType() == NetworkType.Basic) {
                        specifyIpRanges = true;
                        broadcastDomainType = BroadcastDomainType.Vlan;
                    } else {
                        continue;
                    }
                }
                if (broadcastDomainType != null) {
                    NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null, null, specifyIpRanges, null, offering.getRedundantRouter());
                    network.setGuruName(guruNames.get(network.getTrafficType()));
                    network.setDns1(zone.getDns1());
                    network.setDns2(zone.getDns2());
                    network.setState(State.Implemented);
                    _networkDao.persist(network, false, getServicesAndProvidersForNetwork(networkOfferingId));
                    id++;
                }
            }
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkVO(com.cloud.network.dao.NetworkVO) HashMap(java.util.HashMap) Mode(com.cloud.network.Networks.Mode) StorageNetworkGuru(com.cloud.network.guru.StorageNetworkGuru) PublicNetworkGuru(com.cloud.network.guru.PublicNetworkGuru) ControlNetworkGuru(com.cloud.network.guru.ControlNetworkGuru) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) PodBasedNetworkGuru(com.cloud.network.guru.PodBasedNetworkGuru) DirectPodBasedNetworkGuru(com.cloud.network.guru.DirectPodBasedNetworkGuru) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) DirectPodBasedNetworkGuru(com.cloud.network.guru.DirectPodBasedNetworkGuru) TrafficType(com.cloud.network.Networks.TrafficType)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)214 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)54 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)53 HostVO (com.cloud.host.HostVO)42 Account (com.cloud.user.Account)37 NetworkVO (com.cloud.network.dao.NetworkVO)35 DomainRouterVO (com.cloud.vm.DomainRouterVO)33 HostPodVO (com.cloud.dc.HostPodVO)32 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)30 ClusterVO (com.cloud.dc.ClusterVO)27 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 DB (com.cloud.utils.db.DB)26 Network (com.cloud.network.Network)25 HashMap (java.util.HashMap)25 ConfigurationException (javax.naming.ConfigurationException)25 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)20 Test (org.junit.Test)20 NicProfile (com.cloud.vm.NicProfile)19 ActionEvent (com.cloud.event.ActionEvent)18