use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpElement method implement.
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
s_logger.debug("entering NiciraNvpElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
if (!canHandle(network, Service.Connectivity)) {
return false;
}
if (network.getBroadcastUri() == null) {
s_logger.error("Nic has no broadcast Uri with the LSwitch Uuid");
return false;
}
List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
hostDao.loadDetails(niciraNvpHost);
Account owner = context.getAccount();
if (network.getGuestType().equals(GuestType.Shared)) {
//Support Shared Networks
String lSwitchUuid = BroadcastDomainType.getValue(network.getBroadcastUri());
String ownerName = context.getDomain().getName() + "-" + context.getAccount().getAccountName();
return sharedNetworkSupport(network, lSwitchUuid, ownerName, niciraNvpHost);
} else if (network.getGuestType().equals(GuestType.Isolated) && networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
// Implement SourceNat immediately as we have al the info already
s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
PublicIp sourceNatIp = ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
String publicCidr = sourceNatIp.getAddress().addr() + "/" + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
String internalCidr = network.getGateway() + "/" + network.getCidr().split("/")[1];
// assuming a vlan:
String vtag = sourceNatIp.getVlanTag();
BroadcastDomainType tiep = null;
try {
tiep = BroadcastDomainType.getTypeOf(vtag);
} catch (URISyntaxException use) {
throw new CloudRuntimeException("vlantag for sourceNatIp is not valid: " + vtag, use);
}
if (tiep == BroadcastDomainType.Vlan) {
vtag = BroadcastDomainType.Vlan.getValueFrom(BroadcastDomainType.fromString(vtag));
} else if (!(tiep == BroadcastDomainType.UnDecided || tiep == BroadcastDomainType.Native)) {
throw new CloudRuntimeException("only vlans are supported for sourceNatIp, at this moment: " + vtag);
}
long vlanid = (Vlan.UNTAGGED.equals(vtag)) ? 0 : Long.parseLong(vtag);
CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid, BroadcastDomainType.getValue(network.getBroadcastUri()), "router-" + network.getDisplayText(), publicCidr, sourceNatIp.getGateway(), internalCidr, context.getDomain().getName() + "-" + context.getAccount().getAccountName());
CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer.getResult() == false) {
s_logger.error("Failed to create Logical Router for network " + network.getDisplayText());
return false;
}
NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
niciraNvpRouterMappingDao.persist(routermapping);
}
return true;
}
use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpElement method applyPFRules.
/**
* From interface PortForwardingServiceProvider
*/
@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException {
if (!canHandle(network, Service.PortForwarding)) {
return false;
}
List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
if (routermapping == null) {
s_logger.error("No logical router uuid found for network " + network.getDisplayText());
return false;
}
List<PortForwardingRuleTO> portForwardingRules = new ArrayList<PortForwardingRuleTO>();
for (PortForwardingRule rule : rules) {
IpAddress sourceIp = networkModel.getIp(rule.getSourceIpAddressId());
Vlan vlan = vlanDao.findById(sourceIp.getVlanId());
PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
portForwardingRules.add(ruleTO);
}
ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
return answer.getResult();
}
use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpElement method applyIps.
/**
* From interface IpDeployer
*
* @param network
* @param ipAddress
* @param services
* @return
* @throws ResourceUnavailableException
*/
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services) throws ResourceUnavailableException {
if (services.contains(Service.SourceNat)) {
// Only if we need to provide SourceNat we need to configure the logical router
// SourceNat is required for StaticNat and PortForwarding
List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
return false;
}
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
hostDao.loadDetails(niciraNvpHost);
NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
if (routermapping == null) {
s_logger.error("No logical router uuid found for network " + network.getDisplayText());
return false;
}
List<String> cidrs = new ArrayList<String>();
for (PublicIpAddress ip : ipAddress) {
if (ip.getState() == IpAddress.State.Releasing) {
// the Logical Router
continue;
}
cidrs.add(ip.getAddress().addr() + "/" + NetUtils.getCidrSize(ip.getNetmask()));
}
ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
//FIXME answer can be null if the host is down
return answer.getResult();
} else {
s_logger.debug("No need to provision ip addresses as we are not providing L3 services.");
}
return true;
}
use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpGuestNetworkGuru method trash.
@Override
public boolean trash(final Network network, final NetworkOffering offering) {
//Since NVP Plugin supports Shared networks, remove mapping when deleting network implemented or allocated
if (network.getGuestType() == GuestType.Shared && niciraNvpRouterMappingDao.existsMappingForNetworkId(network.getId())) {
NiciraNvpRouterMappingVO mappingVO = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
niciraNvpRouterMappingDao.remove(mappingVO.getId());
}
return super.trash(network, offering);
}
use of com.cloud.network.NiciraNvpRouterMappingVO in project cloudstack by apache.
the class NiciraNvpGuestNetworkGuru method sharedNetworksCleanup.
private void sharedNetworksCleanup(NetworkVO networkObject, String logicalSwitchUuid, HostVO niciraNvpHost) {
NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(networkObject.getId());
if (routermapping == null) {
// Case 1: Numerical Vlan Provided -> No lrouter used.
s_logger.info("Shared Network " + networkObject.getDisplayText() + " didn't use Logical Router");
} else {
//Case 2: Logical Router's UUID provided as Vlan id -> Remove lrouter port but not lrouter.
String lRouterUuid = routermapping.getLogicalRouterUuid();
s_logger.debug("Finding Logical Router Port on Logical Router " + lRouterUuid + " with attachment_lswitch_uuid=" + logicalSwitchUuid + " to delete it");
final FindLogicalRouterPortCommand cmd = new FindLogicalRouterPortCommand(lRouterUuid, logicalSwitchUuid);
final FindLogicalRouterPortAnswer answer = (FindLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer != null && answer.getResult()) {
String logicalRouterPortUuid = answer.getLogicalRouterPortUuid();
s_logger.debug("Found Logical Router Port " + logicalRouterPortUuid + ", deleting it");
final DeleteLogicalRouterPortCommand cmdDeletePort = new DeleteLogicalRouterPortCommand(lRouterUuid, logicalRouterPortUuid);
final DeleteLogicalRouterPortAnswer answerDelete = (DeleteLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmdDeletePort);
if (answerDelete != null && answerDelete.getResult()) {
s_logger.info("Successfully deleted Logical Router Port " + logicalRouterPortUuid);
} else {
s_logger.error("Could not delete Logical Router Port " + logicalRouterPortUuid);
}
} else {
s_logger.error("Find Logical Router Port failed");
}
}
}
Aggregations