use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createPhysicalNetworkResponse.
@Override
public PhysicalNetworkResponse createPhysicalNetworkResponse(final PhysicalNetwork result) {
final PhysicalNetworkResponse response = new PhysicalNetworkResponse();
final DataCenter zone = ApiDBUtils.findZoneById(result.getDataCenterId());
if (zone != null) {
response.setZoneId(zone.getUuid());
}
response.setNetworkSpeed(result.getSpeed());
response.setVlan(result.getVnetString());
if (result.getDomainId() != null) {
final Domain domain = ApiDBUtils.findDomainById(result.getDomainId());
if (domain != null) {
response.setDomainId(domain.getUuid());
}
}
response.setId(result.getUuid());
if (result.getBroadcastDomainRange() != null) {
response.setBroadcastDomainRange(result.getBroadcastDomainRange().toString());
}
response.setIsolationMethods(result.getIsolationMethods());
response.setTags(result.getTags());
if (result.getState() != null) {
response.setState(result.getState().toString());
}
response.setName(result.getName());
response.setObjectName("physicalnetwork");
return response;
}
use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class PrivateNetworkGuru method design.
@Override
public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) {
final PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId());
final DataCenter dc = _entityMgr.findById(DataCenter.class, plan.getDataCenterId());
if (!canHandle(offering, dc, physnet)) {
return null;
}
final BroadcastDomainType broadcastType;
if (userSpecified != null && userSpecified.getBroadcastDomainType() != null) {
broadcastType = userSpecified.getBroadcastDomainType();
} else {
broadcastType = BroadcastDomainType.Vlan;
}
final NetworkVO network = new NetworkVO(offering.getTrafficType(), DHCPMode.Static, broadcastType, offering.getId(), State.Allocated, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
if (userSpecified != null) {
if (!GuestType.Private.equals(offering.getGuestType()) && ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null))) {
throw new InvalidParameterValueException("CIDR and gateway must be specified together or the CIDR must represents the gateway.");
}
if (userSpecified.getCidr() != null) {
network.setCidr(userSpecified.getCidr());
network.setGateway(userSpecified.getGateway());
} else {
throw new InvalidParameterValueException("Can't design network " + network + "; netmask/gateway or cidr must be passed in");
}
if (offering.getSpecifyVlan()) {
network.setBroadcastUri(userSpecified.getBroadcastUri());
network.setState(State.Setup);
}
} else {
throw new CloudRuntimeException("Can't design network " + network + "; netmask/gateway or cidr must be passed in");
}
return network;
}
use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class PublicNetworkGuru method updateNicProfile.
@Override
public void updateNicProfile(final NicProfile profile, final Network network) {
final DataCenter dc = _dcDao.findById(network.getDataCenterId());
if (profile != null) {
profile.setIPv4Dns1(dc.getDns1());
profile.setIPv4Dns2(dc.getDns2());
}
}
use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class DirectNetworkGuru method design.
@Override
public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) {
final DataCenter dc = _dcDao.findById(plan.getDataCenterId());
if (!canHandle(offering, dc)) {
return null;
}
State state = State.Allocated;
if (dc.getNetworkType() == NetworkType.Basic) {
state = State.Setup;
}
final NetworkVO config = new NetworkVO(offering.getTrafficType(), DHCPMode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), state, plan.getDataCenterId(), plan.getPhysicalNetworkId(), offering.getRedundantRouter());
if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) || (userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
throw new InvalidParameterValueException("CIDR and gateway must be specified together or the CIDR must represents the gateway.");
}
if ((userSpecified.getIp6Cidr() == null && userSpecified.getIp6Gateway() != null) || (userSpecified.getIp6Cidr() != null && userSpecified.getIp6Gateway() == null)) {
throw new InvalidParameterValueException("CIDRv6 and gatewayv6 must be specified together or the CIDRv6 must represents the gateway.");
}
if (userSpecified.getCidr() != null) {
config.setCidr(userSpecified.getCidr());
config.setGateway(userSpecified.getGateway());
}
if (userSpecified.getIp6Cidr() != null) {
config.setIp6Cidr(userSpecified.getIp6Cidr());
config.setIp6Gateway(userSpecified.getIp6Gateway());
}
if (userSpecified.getBroadcastUri() != null) {
config.setBroadcastUri(userSpecified.getBroadcastUri());
config.setState(State.Setup);
}
if (userSpecified.getBroadcastDomainType() != null) {
config.setBroadcastDomainType(userSpecified.getBroadcastDomainType());
}
}
return config;
}
use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class DirectPodBasedNetworkGuru method getIp.
@DB
protected void getIp(final NicProfile nic, final Pod pod, final VirtualMachineProfile vm, final Network network) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException {
final DataCenter dc = _dcDao.findById(pod.getDataCenterId());
if (nic.getIPv4Address() == null) {
Transaction.execute(new TransactionCallbackWithExceptionNoReturn<InsufficientAddressCapacityException>() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) throws InsufficientAddressCapacityException {
PublicIp ip = null;
final List<PodVlanMapVO> podRefs = _podVlanDao.listPodVlanMapsByPod(pod.getId());
String podRangeGateway = null;
if (!podRefs.isEmpty()) {
podRangeGateway = _vlanDao.findById(podRefs.get(0).getVlanDbId()).getVlanGateway();
}
// Get ip address from the placeholder and don't allocate a new one
if (vm.getType() == VirtualMachineType.DomainRouter) {
final Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
if (placeholderNic != null) {
final IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(network.getId(), placeholderNic.getIPv4Address());
ip = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
s_logger.debug("Nic got an ip address " + placeholderNic.getIPv4Address() + " stored in placeholder nic for the network " + network + " and gateway " + podRangeGateway);
}
}
if (ip == null) {
ip = _ipAddrMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId(), null, false);
}
nic.setIPv4Address(ip.getAddress().toString());
nic.setFormat(IpAddressFormat.Ip4);
nic.setIPv4Gateway(ip.getGateway());
nic.setIPv4Netmask(ip.getNetmask());
if (ip.getVlanTag() != null && ip.getVlanTag().equalsIgnoreCase(Vlan.UNTAGGED)) {
nic.setIsolationUri(IsolationType.Ec2.toUri(Vlan.UNTAGGED));
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(Vlan.UNTAGGED));
nic.setBroadcastType(BroadcastDomainType.Native);
}
nic.setReservationId(String.valueOf(ip.getVlanTag()));
nic.setMacAddress(ip.getMacAddress());
// save the placeholder nic if the vm is the Virtual router
if (vm.getType() == VirtualMachineType.DomainRouter) {
final Nic placeholderNic = _networkModel.getPlaceholderNicForRouter(network, pod.getId());
if (placeholderNic == null) {
s_logger.debug("Saving placeholder nic with ip4 address " + nic.getIPv4Address() + " for the network " + network);
_networkMgr.savePlaceholderNic(network, nic.getIPv4Address(), null, VirtualMachineType.DomainRouter);
}
}
}
});
}
nic.setIPv4Dns1(dc.getDns1());
nic.setIPv4Dns2(dc.getDns2());
}
Aggregations