You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2013/01/11 01:01:21 UTC
[31/32] pulled from master
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1294cdc7/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
----------------------------------------------------------------------
diff --cc plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
index 78fa083,22fab50..36d4580
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/element/NiciraNvpElement.java
@@@ -25,11 -25,10 +25,12 @@@ import java.util.Set
import java.util.UUID;
import javax.ejb.Local;
+import javax.inject.Inject;
import javax.naming.ConfigurationException;
-import com.cloud.utils.PropertiesUtil;
++import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
import org.apache.log4j.Logger;
+import org.springframework.stereotype.Component;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer;
@@@ -72,16 -71,16 +73,15 @@@ import com.cloud.host.Host
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
++import com.cloud.network.IpAddress;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
++import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks;
import com.cloud.network.Networks.BroadcastDomainType;
--import com.cloud.network.IpAddress;
--import com.cloud.network.NetworkManager;
import com.cloud.network.NiciraNvpDeviceVO;
import com.cloud.network.NiciraNvpNicMappingVO;
import com.cloud.network.NiciraNvpRouterMappingVO;
@@@ -108,7 -107,8 +108,8 @@@ import com.cloud.resource.ResourceState
import com.cloud.resource.ServerResource;
import com.cloud.resource.UnableDeleteHostException;
import com.cloud.user.Account;
++import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.component.AdapterBase;
-import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
@@@ -120,833 -120,833 +121,834 @@@ import com.cloud.vm.VirtualMachine
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao;
+@Component
@Local(value = NetworkElement.class)
public class NiciraNvpElement extends AdapterBase implements
-- ConnectivityProvider, SourceNatServiceProvider,
-- PortForwardingServiceProvider, StaticNatServiceProvider,
-- NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
-- private static final Logger s_logger = Logger
-- .getLogger(NiciraNvpElement.class);
-
-
- private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
-
- @Inject
- NicDao _nicDao;
- @Inject
- ResourceManager _resourceMgr;
- @Inject
- PhysicalNetworkDao _physicalNetworkDao;
- @Inject
- PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
- @Inject
- NiciraNvpDao _niciraNvpDao;
- @Inject
- HostDetailsDao _hostDetailsDao;
- @Inject
- HostDao _hostDao;
- @Inject
- AgentManager _agentMgr;
- @Inject
- NiciraNvpNicMappingDao _niciraNvpNicMappingDao;
- @Inject
- NiciraNvpRouterMappingDao _niciraNvpRouterMappingDao;
- @Inject
- NetworkDao _networkDao;
- @Inject
- NetworkManager _networkManager;
- @Inject
- ConfigurationManager _configMgr;
- @Inject
- NetworkServiceMapDao _ntwkSrvcDao;
- @Inject
- VlanDao _vlanDao;
-
- @Override
- public Map<Service, Map<Capability, String>> getCapabilities() {
- return capabilities;
- }
-
- @Override
- public Provider getProvider() {
- return Provider.NiciraNvp;
- }
-
- protected boolean canHandle(Network network, Service service) {
- s_logger.debug("Checking if NiciraNvpElement can handle service "
- + service.getName() + " on network " + network.getDisplayText());
- if (network.getBroadcastDomainType() != BroadcastDomainType.Lswitch) {
- return false;
- }
-
- if (!_networkManager.isProviderForNetwork(getProvider(),
- network.getId())) {
- s_logger.debug("NiciraNvpElement is not a provider for network "
- + network.getDisplayText());
- return false;
- }
-
- if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(),
- service, Network.Provider.NiciraNvp)) {
- s_logger.debug("NiciraNvpElement can't provide the "
- + service.getName() + " service on network "
- + network.getDisplayText());
- return false;
- }
-
- return true;
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> params)
- throws ConfigurationException {
- super.configure(name, params);
- _resourceMgr.registerResourceStateAdapter(this.getClass()
- .getSimpleName(), this);
- return true;
- }
-
- @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();
-
- /**
- * Lock the network as we might need to do multiple operations that
- * should be done only once.
- */
- Network lock = _networkDao.acquireInLockTable(network.getId(),
- _networkManager.getNetworkLockTimeout());
- if (lock == null) {
- throw new ConcurrentOperationException("Unable to lock network "
- + network.getId());
- }
- try {
- // Implement SourceNat immediately as we have al the info already
- if (_networkManager.isProviderSupportServiceInNetwork(
- network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
- s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
-
- PublicIp sourceNatIp = _networkManager
- .assignSourceNatIpAddressToGuestNetwork(owner, network);
- String publicCidr = sourceNatIp.getAddress().addr() + "/"
- + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
- String internalCidr = network.getGateway() + "/"
- + network.getCidr().split("/")[1];
- long vlanid = (Vlan.UNTAGGED.equals(sourceNatIp.getVlanTag())) ? 0
- : Long.parseLong(sourceNatIp.getVlanTag());
-
- CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(
- niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid,
- network.getBroadcastUri().getSchemeSpecificPart(),
- "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;
- }
-
- // Store the uuid so we can easily find it during cleanup
- NiciraNvpRouterMappingVO routermapping =
- new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
- _niciraNvpRouterMappingDao.persist(routermapping);
- }
- } finally {
- if (lock != null) {
- _networkDao.releaseFromLockTable(lock.getId());
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Lock is released for network id "
- + lock.getId() + " as a part of router startup in "
- + dest);
- }
- }
- }
- return true;
- }
-
- @Override
- public boolean prepare(Network network, NicProfile nic,
- VirtualMachineProfile<? extends VirtualMachine> vm,
- DeployDestination dest, ReservationContext context)
- throws ConcurrentOperationException, ResourceUnavailableException,
- InsufficientCapacityException {
-
- 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;
- }
-
- NicVO nicVO = _nicDao.findById(nic.getId());
-
- 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());
-
- NiciraNvpNicMappingVO existingNicMap = _niciraNvpNicMappingDao
- .findByNicUuid(nicVO.getUuid());
- if (existingNicMap != null) {
- FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(
- existingNicMap.getLogicalSwitchUuid(),
- existingNicMap.getLogicalSwitchPortUuid());
- FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer) _agentMgr
- .easySend(niciraNvpHost.getId(), findCmd);
-
- if (answer.getResult()) {
- s_logger.warn("Existing Logical Switchport found for nic "
- + nic.getName() + " with uuid "
- + existingNicMap.getLogicalSwitchPortUuid());
- UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(
- existingNicMap.getLogicalSwitchPortUuid(), network
- .getBroadcastUri().getSchemeSpecificPart(),
- nicVO.getUuid(), context.getDomain().getName() + "-"
- + context.getAccount().getAccountName(),
- nic.getName());
- _agentMgr.easySend(niciraNvpHost.getId(), cmd);
- return true;
- } else {
- s_logger.error("Stale entry found for nic " + nic.getName()
- + " with logical switchport uuid "
- + existingNicMap.getLogicalSwitchPortUuid());
- _niciraNvpNicMappingDao.remove(existingNicMap.getId());
- }
- }
-
- CreateLogicalSwitchPortCommand cmd = new CreateLogicalSwitchPortCommand(
- network.getBroadcastUri().getSchemeSpecificPart(),
- nicVO.getUuid(), context.getDomain().getName() + "-"
- + context.getAccount().getAccountName(), nic.getName());
- CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer) _agentMgr
- .easySend(niciraNvpHost.getId(), cmd);
-
- if (answer == null || !answer.getResult()) {
- s_logger.error("CreateLogicalSwitchPortCommand failed");
- return false;
- }
-
- NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(network
- .getBroadcastUri().getSchemeSpecificPart(),
- answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
- _niciraNvpNicMappingDao.persist(nicMap);
-
- return true;
- }
-
- @Override
- public boolean release(Network network, NicProfile nic,
- VirtualMachineProfile<? extends VirtualMachine> vm,
- ReservationContext context) throws ConcurrentOperationException,
- ResourceUnavailableException {
-
- 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;
- }
-
- NicVO nicVO = _nicDao.findById(nic.getId());
-
- 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());
-
- NiciraNvpNicMappingVO nicMap = _niciraNvpNicMappingDao
- .findByNicUuid(nicVO.getUuid());
- if (nicMap == null) {
- s_logger.error("No mapping for nic " + nic.getName());
- return false;
- }
-
- DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(
- nicMap.getLogicalSwitchUuid(),
- nicMap.getLogicalSwitchPortUuid());
- DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) _agentMgr
- .easySend(niciraNvpHost.getId(), cmd);
-
- if (answer == null || !answer.getResult()) {
- s_logger.error("DeleteLogicalSwitchPortCommand failed");
- return false;
- }
-
- _niciraNvpNicMappingDao.remove(nicMap.getId());
-
- return true;
- }
-
- @Override
- public boolean shutdown(Network network, ReservationContext context,
- boolean cleanup) throws ConcurrentOperationException,
- ResourceUnavailableException {
- if (!canHandle(network, Service.Connectivity)) {
- 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());
-
- if (_networkManager.isProviderSupportServiceInNetwork(network.getId(),
- Service.SourceNat, Provider.NiciraNvp)) {
- s_logger.debug("Apparently we were providing SourceNat on this network");
-
- // Deleting the LogicalRouter will also take care of all provisioned
- // nat rules.
- NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao
- .findByNetworkId(network.getId());
- if (routermapping == null) {
- s_logger.warn("No logical router uuid found for network "
- + network.getDisplayText());
- // This might be cause by a failed deployment, so don't make shutdown fail as well.
- return true;
- }
-
- DeleteLogicalRouterCommand cmd = new DeleteLogicalRouterCommand(routermapping.getLogicalRouterUuid());
- DeleteLogicalRouterAnswer answer =
- (DeleteLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
- if (answer.getResult() == false) {
- s_logger.error("Failed to delete LogicalRouter for network "
- + network.getDisplayText());
- return false;
- }
-
- _niciraNvpRouterMappingDao.remove(routermapping.getId());
- }
-
- return true;
- }
-
- @Override
- public boolean destroy(Network network, ReservationContext context)
- throws ConcurrentOperationException, ResourceUnavailableException {
- if (!canHandle(network, Service.Connectivity)) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public boolean isReady(PhysicalNetworkServiceProvider provider) {
- return true;
- }
-
- @Override
- public boolean shutdownProviderInstances(
- PhysicalNetworkServiceProvider provider, ReservationContext context)
- throws ConcurrentOperationException, ResourceUnavailableException {
- // Nothing to do here.
- return true;
- }
-
- @Override
- public boolean canEnableIndividualServices() {
- return true;
- }
-
- @Override
- public boolean verifyServicesCombination(Set<Service> services) {
- // This element can only function in a Nicra Nvp based
- // SDN network, so Connectivity needs to be present here
- if (!services.contains(Service.Connectivity)) {
- s_logger.warn("Unable to provide services without Connectivity service enabled for this element");
- return false;
- }
- if ((services.contains(Service.PortForwarding) || services.contains(Service.StaticNat)) && !services.contains(Service.SourceNat)) {
- s_logger.warn("Unable to provide StaticNat and/or PortForwarding without the SourceNat service");
- return false;
- }
- return true;
- }
-
- private static Map<Service, Map<Capability, String>> setCapabilities() {
- Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
-
- // L2 Support : SDN provisioning
- capabilities.put(Service.Connectivity, null);
-
- // L3 Support : Generic?
- capabilities.put(Service.Gateway, null);
-
- // L3 Support : SourceNat
- Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
- sourceNatCapabilities.put(Capability.SupportedSourceNatTypes,
- "peraccount");
- sourceNatCapabilities.put(Capability.RedundantRouter, "false");
- capabilities.put(Service.SourceNat, sourceNatCapabilities);
-
- // L3 Support : Port Forwarding
- capabilities.put(Service.PortForwarding, null);
-
- // L3 support : StaticNat
- capabilities.put(Service.StaticNat, null);
-
- return capabilities;
- }
-
- @Override
- public Map<String, String> getProperties() {
- return PropertiesUtil.processConfigFile(new String[]
++ConnectivityProvider, SourceNatServiceProvider,
++PortForwardingServiceProvider, StaticNatServiceProvider,
++NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
++ private static final Logger s_logger = Logger
++ .getLogger(NiciraNvpElement.class);
++
+ private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
-
++
+ @Inject
+ NicDao _nicDao;
+ @Inject
+ ResourceManager _resourceMgr;
+ @Inject
+ PhysicalNetworkDao _physicalNetworkDao;
+ @Inject
+ PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao;
+ @Inject
+ NiciraNvpDao _niciraNvpDao;
+ @Inject
+ HostDetailsDao _hostDetailsDao;
+ @Inject
+ HostDao _hostDao;
+ @Inject
+ AgentManager _agentMgr;
+ @Inject
+ NiciraNvpNicMappingDao _niciraNvpNicMappingDao;
+ @Inject
- NiciraNvpRouterMappingDao _niciraNvpRouterMappingDao;
- @Inject
++ NiciraNvpRouterMappingDao _niciraNvpRouterMappingDao;
++ @Inject
+ NetworkDao _networkDao;
- @Inject
- NetworkManager _networkManager;
- @Inject
- ConfigurationManager _configMgr;
- @Inject
- NetworkServiceMapDao _ntwkSrvcDao;
- @Inject
- VlanDao _vlanDao;
-
++ @Inject
++ NetworkManager _networkManager;
++ @Inject
++ ConfigurationManager _configMgr;
++ @Inject
++ NetworkServiceMapDao _ntwkSrvcDao;
++ @Inject
++ VlanDao _vlanDao;
++
+ @Override
+ public Map<Service, Map<Capability, String>> getCapabilities() {
+ return capabilities;
+ }
+
+ @Override
+ public Provider getProvider() {
+ return Provider.NiciraNvp;
+ }
-
- protected boolean canHandle(Network network, Service service) {
- s_logger.debug("Checking if NiciraNvpElement can handle service "
- + service.getName() + " on network " + network.getDisplayText());
++
++ protected boolean canHandle(Network network, Service service) {
++ s_logger.debug("Checking if NiciraNvpElement can handle service "
++ + service.getName() + " on network " + network.getDisplayText());
+ if (network.getBroadcastDomainType() != BroadcastDomainType.Lswitch) {
+ return false;
+ }
-
- if (!_networkManager.isProviderForNetwork(getProvider(),
- network.getId())) {
- s_logger.debug("NiciraNvpElement is not a provider for network "
- + network.getDisplayText());
- return false;
- }
-
- if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(),
- service, Network.Provider.NiciraNvp)) {
- s_logger.debug("NiciraNvpElement can't provide the "
- + service.getName() + " service on network "
- + network.getDisplayText());
- return false;
- }
++
++ if (!_networkManager.isProviderForNetwork(getProvider(),
++ network.getId())) {
++ s_logger.debug("NiciraNvpElement is not a provider for network "
++ + network.getDisplayText());
++ return false;
++ }
++
++ if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(),
++ service, Network.Provider.NiciraNvp)) {
++ s_logger.debug("NiciraNvpElement can't provide the "
++ + service.getName() + " service on network "
++ + network.getDisplayText());
++ return false;
++ }
+
+ return true;
+ }
-
++
+ @Override
+ public boolean configure(String name, Map<String, Object> params)
+ throws ConfigurationException {
+ super.configure(name, params);
- _resourceMgr.registerResourceStateAdapter(this.getClass()
- .getSimpleName(), this);
++ _resourceMgr.registerResourceStateAdapter(this.getClass()
++ .getSimpleName(), this);
+ return true;
+ }
+
+ @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");
++ 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;
+ }
-
- 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();
-
- /**
- * Lock the network as we might need to do multiple operations that
- * should be done only once.
- */
- Network lock = _networkDao.acquireInLockTable(network.getId(),
- _networkManager.getNetworkLockTimeout());
- if (lock == null) {
- throw new ConcurrentOperationException("Unable to lock network "
- + network.getId());
- }
- try {
- // Implement SourceNat immediately as we have al the info already
- if (_networkManager.isProviderSupportServiceInNetwork(
- network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
- s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
-
- PublicIp sourceNatIp = _networkManager
- .assignSourceNatIpAddressToGuestNetwork(owner, network);
- String publicCidr = sourceNatIp.getAddress().addr() + "/"
- + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
- String internalCidr = network.getGateway() + "/"
- + network.getCidr().split("/")[1];
- long vlanid = (Vlan.UNTAGGED.equals(sourceNatIp.getVlanTag())) ? 0
- : Long.parseLong(sourceNatIp.getVlanTag());
-
- CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(
- niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid,
- network.getBroadcastUri().getSchemeSpecificPart(),
- "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;
- }
-
- // Store the uuid so we can easily find it during cleanup
- NiciraNvpRouterMappingVO routermapping =
- new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
- _niciraNvpRouterMappingDao.persist(routermapping);
- }
- } finally {
- if (lock != null) {
- _networkDao.releaseFromLockTable(lock.getId());
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Lock is released for network id "
- + lock.getId() + " as a part of router startup in "
- + dest);
- }
- }
- }
++ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
++ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
++ _hostDao.loadDetails(niciraNvpHost);
++
++ Account owner = context.getAccount();
++
++ /**
++ * Lock the network as we might need to do multiple operations that
++ * should be done only once.
++ */
++ Network lock = _networkDao.acquireInLockTable(network.getId(),
++ _networkManager.getNetworkLockTimeout());
++ if (lock == null) {
++ throw new ConcurrentOperationException("Unable to lock network "
++ + network.getId());
++ }
++ try {
++ // Implement SourceNat immediately as we have al the info already
++ if (_networkManager.isProviderSupportServiceInNetwork(
++ network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
++ s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
++
++ PublicIp sourceNatIp = _networkManager
++ .assignSourceNatIpAddressToGuestNetwork(owner, network);
++ String publicCidr = sourceNatIp.getAddress().addr() + "/"
++ + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
++ String internalCidr = network.getGateway() + "/"
++ + network.getCidr().split("/")[1];
++ long vlanid = (Vlan.UNTAGGED.equals(sourceNatIp.getVlanTag())) ? 0
++ : Long.parseLong(sourceNatIp.getVlanTag());
++
++ CreateLogicalRouterCommand cmd = new CreateLogicalRouterCommand(
++ niciraNvpHost.getDetail("l3gatewayserviceuuid"), vlanid,
++ network.getBroadcastUri().getSchemeSpecificPart(),
++ "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;
++ }
++
++ // Store the uuid so we can easily find it during cleanup
++ NiciraNvpRouterMappingVO routermapping =
++ new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
++ _niciraNvpRouterMappingDao.persist(routermapping);
++ }
++ } finally {
++ if (lock != null) {
++ _networkDao.releaseFromLockTable(lock.getId());
++ if (s_logger.isDebugEnabled()) {
++ s_logger.debug("Lock is released for network id "
++ + lock.getId() + " as a part of router startup in "
++ + dest);
++ }
++ }
++ }
+ return true;
+ }
+
+ @Override
+ public boolean prepare(Network network, NicProfile nic,
+ VirtualMachineProfile<? extends VirtualMachine> vm,
+ DeployDestination dest, ReservationContext context)
- throws ConcurrentOperationException, ResourceUnavailableException,
- InsufficientCapacityException {
-
- if (!canHandle(network, Service.Connectivity)) {
++ throws ConcurrentOperationException, ResourceUnavailableException,
++ InsufficientCapacityException {
++
++ 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;
+ }
+
+ NicVO nicVO = _nicDao.findById(nic.getId());
+
- List<NiciraNvpDeviceVO> devices = _niciraNvpDao
- .listByPhysicalNetwork(network.getPhysicalNetworkId());
++ List<NiciraNvpDeviceVO> devices = _niciraNvpDao
++ .listByPhysicalNetwork(network.getPhysicalNetworkId());
+ if (devices.isEmpty()) {
- s_logger.error("No NiciraNvp Controller on physical network "
- + network.getPhysicalNetworkId());
++ s_logger.error("No NiciraNvp Controller on physical network "
++ + network.getPhysicalNetworkId());
+ return false;
+ }
+ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
+
- NiciraNvpNicMappingVO existingNicMap = _niciraNvpNicMappingDao
- .findByNicUuid(nicVO.getUuid());
++ NiciraNvpNicMappingVO existingNicMap = _niciraNvpNicMappingDao
++ .findByNicUuid(nicVO.getUuid());
+ if (existingNicMap != null) {
- FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(
- existingNicMap.getLogicalSwitchUuid(),
- existingNicMap.getLogicalSwitchPortUuid());
- FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer) _agentMgr
- .easySend(niciraNvpHost.getId(), findCmd);
-
++ FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(
++ existingNicMap.getLogicalSwitchUuid(),
++ existingNicMap.getLogicalSwitchPortUuid());
++ FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer) _agentMgr
++ .easySend(niciraNvpHost.getId(), findCmd);
++
+ if (answer.getResult()) {
- s_logger.warn("Existing Logical Switchport found for nic "
- + nic.getName() + " with uuid "
- + existingNicMap.getLogicalSwitchPortUuid());
- UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(
- existingNicMap.getLogicalSwitchPortUuid(), network
- .getBroadcastUri().getSchemeSpecificPart(),
- nicVO.getUuid(), context.getDomain().getName() + "-"
- + context.getAccount().getAccountName(),
- nic.getName());
- _agentMgr.easySend(niciraNvpHost.getId(), cmd);
- return true;
- } else {
- s_logger.error("Stale entry found for nic " + nic.getName()
- + " with logical switchport uuid "
- + existingNicMap.getLogicalSwitchPortUuid());
- _niciraNvpNicMappingDao.remove(existingNicMap.getId());
++ s_logger.warn("Existing Logical Switchport found for nic "
++ + nic.getName() + " with uuid "
++ + existingNicMap.getLogicalSwitchPortUuid());
++ UpdateLogicalSwitchPortCommand cmd = new UpdateLogicalSwitchPortCommand(
++ existingNicMap.getLogicalSwitchPortUuid(), network
++ .getBroadcastUri().getSchemeSpecificPart(),
++ nicVO.getUuid(), context.getDomain().getName() + "-"
++ + context.getAccount().getAccountName(),
++ nic.getName());
++ _agentMgr.easySend(niciraNvpHost.getId(), cmd);
++ return true;
++ } else {
++ s_logger.error("Stale entry found for nic " + nic.getName()
++ + " with logical switchport uuid "
++ + existingNicMap.getLogicalSwitchPortUuid());
++ _niciraNvpNicMappingDao.remove(existingNicMap.getId());
+ }
+ }
-
- CreateLogicalSwitchPortCommand cmd = new CreateLogicalSwitchPortCommand(
- network.getBroadcastUri().getSchemeSpecificPart(),
- nicVO.getUuid(), context.getDomain().getName() + "-"
- + context.getAccount().getAccountName(), nic.getName());
- CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer) _agentMgr
- .easySend(niciraNvpHost.getId(), cmd);
-
++
++ CreateLogicalSwitchPortCommand cmd = new CreateLogicalSwitchPortCommand(
++ network.getBroadcastUri().getSchemeSpecificPart(),
++ nicVO.getUuid(), context.getDomain().getName() + "-"
++ + context.getAccount().getAccountName(), nic.getName());
++ CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer) _agentMgr
++ .easySend(niciraNvpHost.getId(), cmd);
++
+ if (answer == null || !answer.getResult()) {
- s_logger.error("CreateLogicalSwitchPortCommand failed");
++ s_logger.error("CreateLogicalSwitchPortCommand failed");
+ return false;
+ }
-
- NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(network
- .getBroadcastUri().getSchemeSpecificPart(),
- answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
++
++ NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(network
++ .getBroadcastUri().getSchemeSpecificPart(),
++ answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
+ _niciraNvpNicMappingDao.persist(nicMap);
+
+ return true;
+ }
+
+ @Override
+ public boolean release(Network network, NicProfile nic,
+ VirtualMachineProfile<? extends VirtualMachine> vm,
+ ReservationContext context) throws ConcurrentOperationException,
+ ResourceUnavailableException {
+
- if (!canHandle(network, Service.Connectivity)) {
++ 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;
+ }
-
++
+ NicVO nicVO = _nicDao.findById(nic.getId());
+
- List<NiciraNvpDeviceVO> devices = _niciraNvpDao
- .listByPhysicalNetwork(network.getPhysicalNetworkId());
++ List<NiciraNvpDeviceVO> devices = _niciraNvpDao
++ .listByPhysicalNetwork(network.getPhysicalNetworkId());
+ if (devices.isEmpty()) {
- s_logger.error("No NiciraNvp Controller on physical network "
- + network.getPhysicalNetworkId());
++ s_logger.error("No NiciraNvp Controller on physical network "
++ + network.getPhysicalNetworkId());
+ return false;
+ }
+ NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
+ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
-
- NiciraNvpNicMappingVO nicMap = _niciraNvpNicMappingDao
- .findByNicUuid(nicVO.getUuid());
++
++ NiciraNvpNicMappingVO nicMap = _niciraNvpNicMappingDao
++ .findByNicUuid(nicVO.getUuid());
+ if (nicMap == null) {
+ s_logger.error("No mapping for nic " + nic.getName());
+ return false;
+ }
-
- DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(
- nicMap.getLogicalSwitchUuid(),
- nicMap.getLogicalSwitchPortUuid());
- DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) _agentMgr
- .easySend(niciraNvpHost.getId(), cmd);
-
++
++ DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(
++ nicMap.getLogicalSwitchUuid(),
++ nicMap.getLogicalSwitchPortUuid());
++ DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer) _agentMgr
++ .easySend(niciraNvpHost.getId(), cmd);
++
+ if (answer == null || !answer.getResult()) {
- s_logger.error("DeleteLogicalSwitchPortCommand failed");
++ s_logger.error("DeleteLogicalSwitchPortCommand failed");
+ return false;
+ }
-
++
+ _niciraNvpNicMappingDao.remove(nicMap.getId());
-
++
+ return true;
+ }
+
+ @Override
+ public boolean shutdown(Network network, ReservationContext context,
+ boolean cleanup) throws ConcurrentOperationException,
+ ResourceUnavailableException {
- if (!canHandle(network, Service.Connectivity)) {
- 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());
-
- if (_networkManager.isProviderSupportServiceInNetwork(network.getId(),
- Service.SourceNat, Provider.NiciraNvp)) {
- s_logger.debug("Apparently we were providing SourceNat on this network");
-
- // Deleting the LogicalRouter will also take care of all provisioned
- // nat rules.
- NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao
- .findByNetworkId(network.getId());
- if (routermapping == null) {
- s_logger.warn("No logical router uuid found for network "
- + network.getDisplayText());
- // This might be cause by a failed deployment, so don't make shutdown fail as well.
- return true;
- }
-
- DeleteLogicalRouterCommand cmd = new DeleteLogicalRouterCommand(routermapping.getLogicalRouterUuid());
- DeleteLogicalRouterAnswer answer =
- (DeleteLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
- if (answer.getResult() == false) {
- s_logger.error("Failed to delete LogicalRouter for network "
- + network.getDisplayText());
++ if (!canHandle(network, Service.Connectivity)) {
++ 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());
++
++ if (_networkManager.isProviderSupportServiceInNetwork(network.getId(),
++ Service.SourceNat, Provider.NiciraNvp)) {
++ s_logger.debug("Apparently we were providing SourceNat on this network");
++
++ // Deleting the LogicalRouter will also take care of all provisioned
++ // nat rules.
++ NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao
++ .findByNetworkId(network.getId());
++ if (routermapping == null) {
++ s_logger.warn("No logical router uuid found for network "
++ + network.getDisplayText());
++ // This might be cause by a failed deployment, so don't make shutdown fail as well.
++ return true;
++ }
++
++ DeleteLogicalRouterCommand cmd = new DeleteLogicalRouterCommand(routermapping.getLogicalRouterUuid());
++ DeleteLogicalRouterAnswer answer =
++ (DeleteLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
++ if (answer.getResult() == false) {
++ s_logger.error("Failed to delete LogicalRouter for network "
++ + network.getDisplayText());
++ return false;
++ }
+
- _niciraNvpRouterMappingDao.remove(routermapping.getId());
- }
++ _niciraNvpRouterMappingDao.remove(routermapping.getId());
++ }
+
+ return true;
+ }
+
+ @Override
- public boolean destroy(Network network, ReservationContext context)
++ public boolean destroy(Network network, ReservationContext context)
+ throws ConcurrentOperationException, ResourceUnavailableException {
- if (!canHandle(network, Service.Connectivity)) {
++ if (!canHandle(network, Service.Connectivity)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean isReady(PhysicalNetworkServiceProvider provider) {
+ return true;
+ }
+
+ @Override
+ public boolean shutdownProviderInstances(
+ PhysicalNetworkServiceProvider provider, ReservationContext context)
- throws ConcurrentOperationException, ResourceUnavailableException {
++ throws ConcurrentOperationException, ResourceUnavailableException {
+ // Nothing to do here.
+ return true;
+ }
+
+ @Override
+ public boolean canEnableIndividualServices() {
- return true;
++ return true;
+ }
+
+ @Override
+ public boolean verifyServicesCombination(Set<Service> services) {
- // This element can only function in a Nicra Nvp based
- // SDN network, so Connectivity needs to be present here
- if (!services.contains(Service.Connectivity)) {
- s_logger.warn("Unable to provide services without Connectivity service enabled for this element");
- return false;
- }
- if ((services.contains(Service.PortForwarding) || services.contains(Service.StaticNat)) && !services.contains(Service.SourceNat)) {
- s_logger.warn("Unable to provide StaticNat and/or PortForwarding without the SourceNat service");
- return false;
- }
++ // This element can only function in a Nicra Nvp based
++ // SDN network, so Connectivity needs to be present here
++ if (!services.contains(Service.Connectivity)) {
++ s_logger.warn("Unable to provide services without Connectivity service enabled for this element");
++ return false;
++ }
++ if ((services.contains(Service.PortForwarding) || services.contains(Service.StaticNat)) && !services.contains(Service.SourceNat)) {
++ s_logger.warn("Unable to provide StaticNat and/or PortForwarding without the SourceNat service");
++ return false;
++ }
+ return true;
+ }
+
+ private static Map<Service, Map<Capability, String>> setCapabilities() {
+ Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
+
- // L2 Support : SDN provisioning
++ // L2 Support : SDN provisioning
+ capabilities.put(Service.Connectivity, null);
+
- // L3 Support : Generic?
- capabilities.put(Service.Gateway, null);
++ // L3 Support : Generic?
++ capabilities.put(Service.Gateway, null);
+
- // L3 Support : SourceNat
- Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
- sourceNatCapabilities.put(Capability.SupportedSourceNatTypes,
- "peraccount");
- sourceNatCapabilities.put(Capability.RedundantRouter, "false");
- capabilities.put(Service.SourceNat, sourceNatCapabilities);
++ // L3 Support : SourceNat
++ Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
++ sourceNatCapabilities.put(Capability.SupportedSourceNatTypes,
++ "peraccount");
++ sourceNatCapabilities.put(Capability.RedundantRouter, "false");
++ capabilities.put(Service.SourceNat, sourceNatCapabilities);
+
- // L3 Support : Port Forwarding
- capabilities.put(Service.PortForwarding, null);
++ // L3 Support : Port Forwarding
++ capabilities.put(Service.PortForwarding, null);
+
- // L3 support : StaticNat
- capabilities.put(Service.StaticNat, null);
++ // L3 support : StaticNat
++ capabilities.put(Service.StaticNat, null);
+
+ return capabilities;
+ }
+
+ @Override
- public String[] getPropertiesFiles() {
- return new String[] { "nicira-nvp_commands.properties" };
++ public Map<String, String> getProperties() {
++ return PropertiesUtil.processConfigFile(new String[]
+ { "nicira-nvp_commands.properties" });
- }
-
- @Override
- @DB
- public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) {
- ServerResource resource = new NiciraNvpResource();
- String deviceName = Network.Provider.NiciraNvp.getName();
- NetworkDevice networkDevice = NetworkDevice
- .getNetworkDevice(deviceName);
- Long physicalNetworkId = cmd.getPhysicalNetworkId();
- NiciraNvpDeviceVO niciraNvpDevice = null;
-
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
- .findById(physicalNetworkId);
- if (physicalNetwork == null) {
- throw new InvalidParameterValueException(
- "Could not find phyical network with ID: "
- + physicalNetworkId);
- }
- long zoneId = physicalNetwork.getDataCenterId();
-
- 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");
- }
-
- if (_niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
- throw new CloudRuntimeException(
- "A NiciraNvp device is already configured on this physical network");
- }
-
- Map<String, String> params = new HashMap<String, String>();
- params.put("guid", UUID.randomUUID().toString());
- params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
- params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
- params.put("name", "Nicira Controller - " + cmd.getHost());
- params.put("ip", cmd.getHost());
- params.put("adminuser", cmd.getUsername());
- params.put("adminpass", cmd.getPassword());
- params.put("transportzoneuuid", cmd.getTransportzoneUuid());
- // FIXME What to do with multiple isolation types
- params.put("transportzoneisotype",
- physicalNetwork.getIsolationMethods().get(0).toLowerCase());
- if (cmd.getL3GatewayServiceUuid() != null) {
- params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
- }
-
- Map<String, Object> hostdetails = new HashMap<String, Object>();
- hostdetails.putAll(params);
-
- Transaction txn = Transaction.currentTxn();
- try {
- resource.configure(cmd.getHost(), hostdetails);
-
- Host host = _resourceMgr.addHost(zoneId, resource,
- Host.Type.L2Networking, params);
- if (host != null) {
- txn.start();
-
- niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(),
- physicalNetworkId, ntwkSvcProvider.getProviderName(),
- deviceName);
- _niciraNvpDao.persist(niciraNvpDevice);
-
- DetailVO detail = new DetailVO(host.getId(),
- "niciranvpdeviceid", String.valueOf(niciraNvpDevice
- .getId()));
- _hostDetailsDao.persist(detail);
-
- txn.commit();
- return niciraNvpDevice;
- } else {
- throw new CloudRuntimeException(
- "Failed to add Nicira Nvp Device due to internal error.");
- }
- } catch (ConfigurationException e) {
- txn.rollback();
- throw new CloudRuntimeException(e.getMessage());
- }
- }
-
- @Override
- public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(
- NiciraNvpDeviceVO niciraNvpDeviceVO) {
- HostVO niciraNvpHost = _hostDao.findById(niciraNvpDeviceVO.getHostId());
- _hostDao.loadDetails(niciraNvpHost);
-
- NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse();
- response.setDeviceName(niciraNvpDeviceVO.getDeviceName());
+ }
+
+ @Override
+ @DB
+ public NiciraNvpDeviceVO addNiciraNvpDevice(AddNiciraNvpDeviceCmd cmd) {
+ ServerResource resource = new NiciraNvpResource();
+ String deviceName = Network.Provider.NiciraNvp.getName();
- NetworkDevice networkDevice = NetworkDevice
- .getNetworkDevice(deviceName);
++ NetworkDevice networkDevice = NetworkDevice
++ .getNetworkDevice(deviceName);
+ Long physicalNetworkId = cmd.getPhysicalNetworkId();
+ NiciraNvpDeviceVO niciraNvpDevice = null;
-
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
- .findById(physicalNetworkId);
++
++ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
++ .findById(physicalNetworkId);
+ if (physicalNetwork == null) {
- throw new InvalidParameterValueException(
- "Could not find phyical network with ID: "
- + physicalNetworkId);
++ throw new InvalidParameterValueException(
++ "Could not find phyical network with ID: "
++ + physicalNetworkId);
+ }
+ long zoneId = physicalNetwork.getDataCenterId();
+
- PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao
- .findByServiceProvider(physicalNetwork.getId(),
- networkDevice.getNetworkServiceProvder());
++ 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");
++ 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");
++ throw new CloudRuntimeException("Network Service Provider: "
++ + ntwkSvcProvider.getProviderName()
++ + " is in shutdown state in the physical network: "
++ + physicalNetworkId + "to add this device");
+ }
-
++
+ if (_niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
- throw new CloudRuntimeException(
- "A NiciraNvp device is already configured on this physical network");
++ throw new CloudRuntimeException(
++ "A NiciraNvp device is already configured on this physical network");
+ }
-
- Map<String, String> params = new HashMap<String, String>();
++
++ Map<String, String> params = new HashMap<String, String>();
+ params.put("guid", UUID.randomUUID().toString());
+ params.put("zoneId", String.valueOf(physicalNetwork.getDataCenterId()));
+ params.put("physicalNetworkId", String.valueOf(physicalNetwork.getId()));
+ params.put("name", "Nicira Controller - " + cmd.getHost());
+ params.put("ip", cmd.getHost());
+ params.put("adminuser", cmd.getUsername());
+ params.put("adminpass", cmd.getPassword());
+ params.put("transportzoneuuid", cmd.getTransportzoneUuid());
- // FIXME What to do with multiple isolation types
- params.put("transportzoneisotype",
- physicalNetwork.getIsolationMethods().get(0).toLowerCase());
- if (cmd.getL3GatewayServiceUuid() != null) {
- params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
- }
-
- Map<String, Object> hostdetails = new HashMap<String, Object>();
++ // FIXME What to do with multiple isolation types
++ params.put("transportzoneisotype",
++ physicalNetwork.getIsolationMethods().get(0).toLowerCase());
++ if (cmd.getL3GatewayServiceUuid() != null) {
++ params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
++ }
++
++ Map<String, Object> hostdetails = new HashMap<String, Object>();
+ hostdetails.putAll(params);
-
++
+ Transaction txn = Transaction.currentTxn();
+ try {
+ resource.configure(cmd.getHost(), hostdetails);
-
- Host host = _resourceMgr.addHost(zoneId, resource,
- Host.Type.L2Networking, params);
++
++ Host host = _resourceMgr.addHost(zoneId, resource,
++ Host.Type.L2Networking, params);
+ if (host != null) {
+ txn.start();
-
- niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(),
- physicalNetworkId, ntwkSvcProvider.getProviderName(),
- deviceName);
++
++ niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(),
++ physicalNetworkId, ntwkSvcProvider.getProviderName(),
++ deviceName);
+ _niciraNvpDao.persist(niciraNvpDevice);
-
- DetailVO detail = new DetailVO(host.getId(),
- "niciranvpdeviceid", String.valueOf(niciraNvpDevice
- .getId()));
++
++ DetailVO detail = new DetailVO(host.getId(),
++ "niciranvpdeviceid", String.valueOf(niciraNvpDevice
++ .getId()));
+ _hostDetailsDao.persist(detail);
+
+ txn.commit();
+ return niciraNvpDevice;
+ } else {
- throw new CloudRuntimeException(
- "Failed to add Nicira Nvp Device due to internal error.");
++ throw new CloudRuntimeException(
++ "Failed to add Nicira Nvp Device due to internal error.");
+ }
+ } catch (ConfigurationException e) {
+ txn.rollback();
+ throw new CloudRuntimeException(e.getMessage());
+ }
+ }
+
+ @Override
+ public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(
+ NiciraNvpDeviceVO niciraNvpDeviceVO) {
- HostVO niciraNvpHost = _hostDao.findById(niciraNvpDeviceVO.getHostId());
- _hostDao.loadDetails(niciraNvpHost);
++ HostVO niciraNvpHost = _hostDao.findById(niciraNvpDeviceVO.getHostId());
++ _hostDao.loadDetails(niciraNvpHost);
+
+ NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse();
+ response.setDeviceName(niciraNvpDeviceVO.getDeviceName());
PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(niciraNvpDeviceVO.getPhysicalNetworkId());
if (pnw != null) {
response.setPhysicalNetworkId(pnw.getUuid());
}
-- response.setId(niciraNvpDeviceVO.getUuid());
- response.setProviderName(niciraNvpDeviceVO.getProviderName());
- response.setHostName(niciraNvpHost.getDetail("ip"));
- response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid"));
- response.setL3GatewayServiceUuid(niciraNvpHost.getDetail("l3gatewayserviceuuid"));
- response.setObjectName("niciranvpdevice");
- return response;
- }
-
- @Override
- public boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd) {
- Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
- NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
- .findById(niciraDeviceId);
- if (niciraNvpDevice == null) {
- throw new InvalidParameterValueException(
- "Could not find a nicira device with id " + niciraDeviceId);
- }
-
- // Find the physical network we work for
- Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
- .findById(physicalNetworkId);
- if (physicalNetwork != null) {
- // Lets see if there are networks that use us
- // Find the nicira networks on this physical network
- List<NetworkVO> networkList = _networkDao
- .listByPhysicalNetwork(physicalNetworkId);
-
- // Networks with broadcast type lswitch are ours
- for (NetworkVO network : networkList) {
- if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
- if ((network.getState() != Network.State.Shutdown)
- && (network.getState() != Network.State.Destroy)) {
- throw new CloudRuntimeException(
- "This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
- }
- }
- }
- }
-
- HostVO niciraHost = _hostDao.findById(niciraNvpDevice.getHostId());
- Long hostId = niciraHost.getId();
-
- niciraHost.setResourceState(ResourceState.Maintenance);
- _hostDao.update(hostId, niciraHost);
- _resourceMgr.deleteHost(hostId, false, false);
-
- _niciraNvpDao.remove(niciraDeviceId);
- return true;
- }
-
- @Override
- public List<NiciraNvpDeviceVO> listNiciraNvpDevices(
- ListNiciraNvpDevicesCmd cmd) {
- Long physicalNetworkId = cmd.getPhysicalNetworkId();
- Long niciraNvpDeviceId = cmd.getNiciraNvpDeviceId();
- List<NiciraNvpDeviceVO> responseList = new ArrayList<NiciraNvpDeviceVO>();
-
- if (physicalNetworkId == null && niciraNvpDeviceId == null) {
- throw new InvalidParameterValueException(
- "Either physical network Id or nicira device Id must be specified");
- }
-
- if (niciraNvpDeviceId != null) {
- NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
- .findById(niciraNvpDeviceId);
- if (niciraNvpDevice == null) {
- throw new InvalidParameterValueException(
- "Could not find Nicira Nvp device with id: "
- + niciraNvpDevice);
- }
- responseList.add(niciraNvpDevice);
- } else {
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
- .findById(physicalNetworkId);
- if (physicalNetwork == null) {
- throw new InvalidParameterValueException(
- "Could not find a physical network with id: "
- + physicalNetworkId);
- }
- responseList = _niciraNvpDao
- .listByPhysicalNetwork(physicalNetworkId);
- }
-
- return responseList;
- }
-
- @Override
- public List<? extends Network> listNiciraNvpDeviceNetworks(
- ListNiciraNvpDeviceNetworksCmd cmd) {
- Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
- NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
- .findById(niciraDeviceId);
- if (niciraNvpDevice == null) {
- throw new InvalidParameterValueException(
- "Could not find a nicira device with id " + niciraDeviceId);
- }
-
- // Find the physical network we work for
- Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
- .findById(physicalNetworkId);
- if (physicalNetwork == null) {
- // No such physical network, so no provisioned networks
- return Collections.emptyList();
- }
-
- // Find the nicira networks on this physical network
- List<NetworkVO> networkList = _networkDao
- .listByPhysicalNetwork(physicalNetworkId);
-
- // Networks with broadcast type lswitch are ours
- List<NetworkVO> responseList = new ArrayList<NetworkVO>();
- for (NetworkVO network : networkList) {
- if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
- responseList.add(network);
- }
- }
-
- return responseList;
- }
-
- @Override
- public HostVO createHostVOForConnectedAgent(HostVO host,
- StartupCommand[] cmd) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public HostVO createHostVOForDirectConnectAgent(HostVO host,
- StartupCommand[] startup, ServerResource resource,
- Map<String, String> details, List<String> hostTags) {
- if (!(startup[0] instanceof StartupNiciraNvpCommand)) {
- return null;
- }
- host.setType(Host.Type.L2Networking);
- return host;
- }
-
- @Override
- public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
- boolean isForceDeleteStorage) throws UnableDeleteHostException {
- if (!(host.getType() == Host.Type.L2Networking)) {
- return null;
- }
- return new DeleteHostAnswer(true);
- }
-
- /**
- * From interface SourceNatServiceProvider
- */
- @Override
- public IpDeployer getIpDeployer(Network network) {
- return this;
- }
-
- /**
- * 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) {
- 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;
- }
-
- /**
- * From interface StaticNatServiceProvider
- */
- @Override
- public boolean applyStaticNats(Network network,
- List<? extends StaticNat> rules)
- throws ResourceUnavailableException {
++ response.setId(niciraNvpDeviceVO.getUuid());
+ response.setProviderName(niciraNvpDeviceVO.getProviderName());
- response.setHostName(niciraNvpHost.getDetail("ip"));
- response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid"));
- response.setL3GatewayServiceUuid(niciraNvpHost.getDetail("l3gatewayserviceuuid"));
- response.setObjectName("niciranvpdevice");
++ response.setHostName(niciraNvpHost.getDetail("ip"));
++ response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid"));
++ response.setL3GatewayServiceUuid(niciraNvpHost.getDetail("l3gatewayserviceuuid"));
++ response.setObjectName("niciranvpdevice");
+ return response;
+ }
-
++
+ @Override
+ public boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd) {
+ Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
- NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
- .findById(niciraDeviceId);
++ NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
++ .findById(niciraDeviceId);
+ if (niciraNvpDevice == null) {
- throw new InvalidParameterValueException(
- "Could not find a nicira device with id " + niciraDeviceId);
++ throw new InvalidParameterValueException(
++ "Could not find a nicira device with id " + niciraDeviceId);
+ }
-
++
+ // Find the physical network we work for
+ Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
- .findById(physicalNetworkId);
++ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
++ .findById(physicalNetworkId);
+ if (physicalNetwork != null) {
+ // Lets see if there are networks that use us
+ // Find the nicira networks on this physical network
- List<NetworkVO> networkList = _networkDao
- .listByPhysicalNetwork(physicalNetworkId);
-
++ List<NetworkVO> networkList = _networkDao
++ .listByPhysicalNetwork(physicalNetworkId);
++
+ // Networks with broadcast type lswitch are ours
+ for (NetworkVO network : networkList) {
+ if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
- if ((network.getState() != Network.State.Shutdown)
- && (network.getState() != Network.State.Destroy)) {
- throw new CloudRuntimeException(
- "This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
++ if ((network.getState() != Network.State.Shutdown)
++ && (network.getState() != Network.State.Destroy)) {
++ throw new CloudRuntimeException(
++ "This Nicira Nvp device can not be deleted as there are one or more logical networks provisioned by cloudstack.");
+ }
+ }
+ }
+ }
-
++
+ HostVO niciraHost = _hostDao.findById(niciraNvpDevice.getHostId());
+ Long hostId = niciraHost.getId();
-
++
+ niciraHost.setResourceState(ResourceState.Maintenance);
+ _hostDao.update(hostId, niciraHost);
+ _resourceMgr.deleteHost(hostId, false, false);
-
++
+ _niciraNvpDao.remove(niciraDeviceId);
+ return true;
+ }
-
++
+ @Override
- public List<NiciraNvpDeviceVO> listNiciraNvpDevices(
- ListNiciraNvpDevicesCmd cmd) {
++ public List<NiciraNvpDeviceVO> listNiciraNvpDevices(
++ ListNiciraNvpDevicesCmd cmd) {
+ Long physicalNetworkId = cmd.getPhysicalNetworkId();
+ Long niciraNvpDeviceId = cmd.getNiciraNvpDeviceId();
+ List<NiciraNvpDeviceVO> responseList = new ArrayList<NiciraNvpDeviceVO>();
-
++
+ if (physicalNetworkId == null && niciraNvpDeviceId == null) {
- throw new InvalidParameterValueException(
- "Either physical network Id or nicira device Id must be specified");
++ throw new InvalidParameterValueException(
++ "Either physical network Id or nicira device Id must be specified");
+ }
-
++
+ if (niciraNvpDeviceId != null) {
- NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
- .findById(niciraNvpDeviceId);
++ NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
++ .findById(niciraNvpDeviceId);
+ if (niciraNvpDevice == null) {
- throw new InvalidParameterValueException(
- "Could not find Nicira Nvp device with id: "
- + niciraNvpDevice);
++ throw new InvalidParameterValueException(
++ "Could not find Nicira Nvp device with id: "
++ + niciraNvpDevice);
+ }
+ responseList.add(niciraNvpDevice);
- } else {
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
- .findById(physicalNetworkId);
++ } else {
++ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
++ .findById(physicalNetworkId);
+ if (physicalNetwork == null) {
- throw new InvalidParameterValueException(
- "Could not find a physical network with id: "
- + physicalNetworkId);
++ throw new InvalidParameterValueException(
++ "Could not find a physical network with id: "
++ + physicalNetworkId);
+ }
- responseList = _niciraNvpDao
- .listByPhysicalNetwork(physicalNetworkId);
++ responseList = _niciraNvpDao
++ .listByPhysicalNetwork(physicalNetworkId);
+ }
-
++
+ return responseList;
+ }
-
++
+ @Override
- public List<? extends Network> listNiciraNvpDeviceNetworks(
- ListNiciraNvpDeviceNetworksCmd cmd) {
++ public List<? extends Network> listNiciraNvpDeviceNetworks(
++ ListNiciraNvpDeviceNetworksCmd cmd) {
+ Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
- NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
- .findById(niciraDeviceId);
++ NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao
++ .findById(niciraDeviceId);
+ if (niciraNvpDevice == null) {
- throw new InvalidParameterValueException(
- "Could not find a nicira device with id " + niciraDeviceId);
++ throw new InvalidParameterValueException(
++ "Could not find a nicira device with id " + niciraDeviceId);
+ }
-
++
+ // Find the physical network we work for
+ Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
- PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
- .findById(physicalNetworkId);
++ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao
++ .findById(physicalNetworkId);
+ if (physicalNetwork == null) {
+ // No such physical network, so no provisioned networks
+ return Collections.emptyList();
+ }
-
++
+ // Find the nicira networks on this physical network
- List<NetworkVO> networkList = _networkDao
- .listByPhysicalNetwork(physicalNetworkId);
-
++ List<NetworkVO> networkList = _networkDao
++ .listByPhysicalNetwork(physicalNetworkId);
++
+ // Networks with broadcast type lswitch are ours
+ List<NetworkVO> responseList = new ArrayList<NetworkVO>();
+ for (NetworkVO network : networkList) {
+ if (network.getBroadcastDomainType() == Networks.BroadcastDomainType.Lswitch) {
+ responseList.add(network);
+ }
+ }
-
++
+ return responseList;
+ }
-
++
+ @Override
+ public HostVO createHostVOForConnectedAgent(HostVO host,
+ StartupCommand[] cmd) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public HostVO createHostVOForDirectConnectAgent(HostVO host,
+ StartupCommand[] startup, ServerResource resource,
+ Map<String, String> details, List<String> hostTags) {
+ if (!(startup[0] instanceof StartupNiciraNvpCommand)) {
+ return null;
+ }
+ host.setType(Host.Type.L2Networking);
+ return host;
+ }
+
+ @Override
+ public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
+ boolean isForceDeleteStorage) throws UnableDeleteHostException {
+ if (!(host.getType() == Host.Type.L2Networking)) {
+ return null;
+ }
+ return new DeleteHostAnswer(true);
+ }
+
- /**
- * From interface SourceNatServiceProvider
- */
- @Override
- public IpDeployer getIpDeployer(Network network) {
- return this;
- }
-
- /**
- * 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) {
- 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;
- }
-
- /**
- * From interface StaticNatServiceProvider
- */
- @Override
- public boolean applyStaticNats(Network network,
- List<? extends StaticNat> rules)
- throws ResourceUnavailableException {
++ /**
++ * From interface SourceNatServiceProvider
++ */
++ @Override
++ public IpDeployer getIpDeployer(Network network) {
++ return this;
++ }
++
++ /**
++ * 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) {
++ 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;
++ }
++
++ /**
++ * From interface StaticNatServiceProvider
++ */
++ @Override
++ public boolean applyStaticNats(Network network,
++ List<? extends StaticNat> rules)
++ throws ResourceUnavailableException {
if (!canHandle(network, Service.StaticNat)) {
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<StaticNatRuleTO> staticNatRules = new ArrayList<StaticNatRuleTO>();
++ 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<StaticNatRuleTO> staticNatRules = new ArrayList<StaticNatRuleTO>();
for (StaticNat rule : rules) {
IpAddress sourceIp = _networkManager.getIp(rule.getSourceIpAddressId());
// Force the nat rule into the StaticNatRuleTO, no use making a new TO object
// we only need the source and destination ip. Unfortunately no mention if a rule
// is new.
StaticNatRuleTO ruleTO = new StaticNatRuleTO(1,
-- sourceIp.getAddress().addr(), 0, 65535,
-- rule.getDestIpAddress(), 0, 65535,
-- "any", rule.isForRevoke(), false);
++ sourceIp.getAddress().addr(), 0, 65535,
++ rule.getDestIpAddress(), 0, 65535,
++ "any", rule.isForRevoke(), false);
staticNatRules.add(ruleTO);
}
ConfigureStaticNatRulesOnLogicalRouterCommand cmd =
-- new ConfigureStaticNatRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), staticNatRules);
++ new ConfigureStaticNatRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), staticNatRules);
ConfigureStaticNatRulesOnLogicalRouterAnswer answer = (ConfigureStaticNatRulesOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
return answer.getResult();
-- }
--
-- /**
-- * From interface PortForwardingServiceProvider
-- */
-- @Override
-- public boolean applyPFRules(Network network, List<PortForwardingRule> rules)
-- throws ResourceUnavailableException {
++ }
++
++ /**
++ * 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>();
++ 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 = _networkManager.getIp(rule.getSourceIpAddressId());
Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
-- PortForwardingRuleTO ruleTO = new PortForwardingRuleTO((PortForwardingRule) rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
++ PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
portForwardingRules.add(ruleTO);
}
ConfigurePortForwardingRulesOnLogicalRouterCommand cmd =
-- new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
++ new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
return answer.getResult();
-- }
++ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1294cdc7/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --cc server/src/com/cloud/api/ApiServer.java
index c9cabf0,7387125..c0eedc1
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@@ -51,20 -50,11 +51,19 @@@ import javax.inject.Inject
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import com.cloud.utils.ReflectUtil;
import org.apache.cloudstack.acl.APIAccessChecker;
-import org.apache.cloudstack.acl.ControlledEntity;
+ import org.apache.cloudstack.acl.RoleType;
-import org.apache.cloudstack.api.*;
++import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.ResponseObject;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
+import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
+import org.apache.cloudstack.api.command.admin.storage.ListStoragePoolsCmd;
+import org.apache.cloudstack.api.command.admin.user.ListUsersCmd;
- import org.apache.cloudstack.acl.ControlledEntity;
- import org.apache.cloudstack.acl.RoleType;
- import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.command.user.account.ListAccountsCmd;
import org.apache.cloudstack.api.command.user.account.ListProjectAccountsCmd;
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
@@@ -75,13 -61,8 +74,9 @@@ import org.apache.cloudstack.api.comman
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.cloudstack.api.command.user.volume.ListVolumesCmd;
- <<<<<<< HEAD
+import org.apache.cloudstack.api.response.ExceptionResponse;
+import org.apache.cloudstack.api.response.ListResponse;
- import org.apache.cloudstack.discovery.ApiDiscoveryService;
- =======
- >>>>>>> master
import org.apache.commons.codec.binary.Base64;
-import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.ConnectionClosedException;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
@@@ -133,9 -124,10 +128,10 @@@ import com.cloud.user.UserAccount
import com.cloud.user.UserContext;
import com.cloud.user.UserVO;
import com.cloud.utils.Pair;
-import com.cloud.utils.component.Adapters;
++import com.cloud.utils.ReflectUtil;
import com.cloud.utils.StringUtils;
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.component.Inject;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.component.PluggableService;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
@@@ -177,9 -164,9 +173,9 @@@ public class ApiServer implements HttpR
public static void initApiServer() {
if (s_instance == null) {
- //Injection will create ApiServer and all its fields which have @Inject
- s_instance = ComponentLocator.inject(ApiServer.class);
+ s_instance = new ApiServer();
+ s_instance = ComponentContext.inject(s_instance);
- s_instance.init(apiConfig);
+ s_instance.init();
}
}