mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
bug 7619: Added list of Capabilities parameter for Network
status 7619: resolved fixed
This commit is contained in:
parent
9fd24869fa
commit
ec9260ce62
@ -15,10 +15,33 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.network.service;
|
||||
package com.cloud.api.response;
|
||||
|
||||
public class Providers {
|
||||
public final static String VirtualRouter = "VirtualRouter";
|
||||
public final static String ExternalFirewall = "ExternalFirewall";
|
||||
public final static String ExternalLoadBalancer = "ExternalLoadBalancer";
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class CapabilityResponse extends BaseResponse {
|
||||
|
||||
@SerializedName(ApiConstants.NAME) @Param(description="the capability name")
|
||||
private String name;
|
||||
|
||||
@SerializedName(ApiConstants.VALUE) @Param(description="the capability value")
|
||||
private String value;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
package com.cloud.api.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
@ -102,6 +104,9 @@ public class NetworkResponse extends BaseResponse{
|
||||
|
||||
@SerializedName(ApiConstants.DOMAIN) @Param(description="the domain associated with the network")
|
||||
private String domain;
|
||||
|
||||
@SerializedName("service") @Param(description="the list of services")
|
||||
private List<ServiceResponse> services;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@ -310,6 +315,12 @@ public class NetworkResponse extends BaseResponse{
|
||||
public void setNetworkOfferingAvailability(String networkOfferingAvailability) {
|
||||
this.networkOfferingAvailability = networkOfferingAvailability;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<ServiceResponse> getServices() {
|
||||
return services;
|
||||
}
|
||||
|
||||
public void setServices(List<ServiceResponse> services) {
|
||||
this.services = services;
|
||||
}
|
||||
}
|
||||
|
||||
49
api/src/com/cloud/api/response/ServiceResponse.java
Normal file
49
api/src/com/cloud/api/response/ServiceResponse.java
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.api.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ServiceResponse extends BaseResponse {
|
||||
|
||||
@SerializedName(ApiConstants.NAME) @Param(description="the service name")
|
||||
private String name;
|
||||
|
||||
@SerializedName("capability") @Param(description="the list of capabilities")
|
||||
private List<CapabilityResponse> capabilities;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<CapabilityResponse> getCapabilities() {
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
public void setCapabilities(List<CapabilityResponse> capabilities) {
|
||||
this.capabilities = capabilities;
|
||||
}
|
||||
}
|
||||
@ -142,12 +142,12 @@ public class UserVmResponse extends BaseResponse {
|
||||
@SerializedName("jobstatus") @Param(description="shows the current pending asynchronous job status")
|
||||
private Integer jobStatus;
|
||||
|
||||
@SerializedName("nic") @Param(description="the list of nics associated with vm")
|
||||
private List<NicResponse> nics;
|
||||
|
||||
public Long getObjectId() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@SerializedName("nic") @Param(description="the list of nics associated with vm")
|
||||
private List<NicResponse> nics;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
|
||||
@ -20,6 +20,73 @@ import com.cloud.utils.fsm.StateMachine;
|
||||
* owned by an account.
|
||||
*/
|
||||
public interface Network extends ControlledEntity {
|
||||
|
||||
public static class Service {
|
||||
|
||||
public static final Service Vpn = new Service("Vpn");
|
||||
public static final Service Dhcp = new Service("Dhcp");
|
||||
public static final Service Dns = new Service("Dns");
|
||||
public static final Service Gateway = new Service("Gateway");
|
||||
public static final Service Firewall = new Service("Firewall", Capability.PortForwarding, Capability.StaticNat);
|
||||
public static final Service Lb = new Service("Lb");
|
||||
public static final Service UserData = new Service("UserData");
|
||||
|
||||
private String name;
|
||||
private Capability[] caps;
|
||||
|
||||
public Service(String name, Capability... caps) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Capability[] getCapabilities() {
|
||||
return caps;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Provider {
|
||||
|
||||
public static final Provider VirtualRouter = new Provider("VirtualRouter");
|
||||
public static final Provider DhcpServer = new Provider("DhcpServer");
|
||||
public static final Provider ExternalFirewall = new Provider("ExternalFirewall");
|
||||
public static final Provider ExternalLoadBalancer = new Provider("ExternalLoadBalancer");
|
||||
|
||||
private String name;
|
||||
|
||||
public Provider(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Capability {
|
||||
|
||||
public static final Capability PortForwarding = new Capability("PortForwarding");
|
||||
public static final Capability StaticNat = new Capability("StaticNat");
|
||||
public static final Capability SupportedProtocols = new Capability("SupportedProtocols");
|
||||
public static final Capability SupportedLBAlgorithms = new Capability("SupportedLBAlgorithms");
|
||||
public static final Capability Vpn = new Capability("VPN");
|
||||
public static final Capability MultipleIps = new Capability("MultipleIps");
|
||||
public static final Capability SupportedSourceNatTypes = new Capability("SupportedSourceNatTypes");
|
||||
public static final Capability SupportedVpnTypes = new Capability("SupportedVpnTypes");
|
||||
|
||||
private String name;
|
||||
|
||||
public Capability(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
enum Event {
|
||||
ImplementNetwork,
|
||||
DestroyNetwork,
|
||||
@ -114,4 +181,5 @@ public interface Network extends ControlledEntity {
|
||||
boolean isShared();
|
||||
|
||||
String getReservationId();
|
||||
|
||||
}
|
||||
|
||||
@ -90,4 +90,5 @@ public interface NetworkService {
|
||||
boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
int getActiveNicsInNetwork(long networkId);
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
package com.cloud.network.element;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
@ -11,6 +12,9 @@ import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.InsufficientNetworkCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
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.PublicIpAddress;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
@ -24,6 +28,11 @@ import com.cloud.vm.VirtualMachineProfile;
|
||||
* Represents one network element that exists in a network.
|
||||
*/
|
||||
public interface NetworkElement extends Adapter {
|
||||
|
||||
Map<Service, Map<Capability, String>> getCapabilities();
|
||||
|
||||
Provider getProvider();
|
||||
|
||||
/**
|
||||
* Implement the network configuration as specified.
|
||||
* @param config fully specified network configuration.
|
||||
|
||||
@ -2,6 +2,7 @@ package com.cloud.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
@ -32,6 +33,8 @@ import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.NetworkRuleConfigVO;
|
||||
import com.cloud.network.NetworkVO;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
@ -508,4 +511,8 @@ public class ApiDBUtils {
|
||||
return _networkDao.findById(id);
|
||||
}
|
||||
|
||||
public static Map<Service, Map<Capability, String>> getZoneCapabilities(long zoneId) {
|
||||
return _networkMgr.getZoneCapabilities(zoneId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ import com.cloud.api.commands.QueryAsyncJobResultCmd;
|
||||
import com.cloud.api.response.AccountResponse;
|
||||
import com.cloud.api.response.ApiResponseSerializer;
|
||||
import com.cloud.api.response.AsyncJobResponse;
|
||||
import com.cloud.api.response.CapabilityResponse;
|
||||
import com.cloud.api.response.CapacityResponse;
|
||||
import com.cloud.api.response.ClusterResponse;
|
||||
import com.cloud.api.response.ConfigurationResponse;
|
||||
@ -60,6 +61,7 @@ import com.cloud.api.response.RemoteAccessVpnResponse;
|
||||
import com.cloud.api.response.ResourceLimitResponse;
|
||||
import com.cloud.api.response.SecurityGroupResponse;
|
||||
import com.cloud.api.response.ServiceOfferingResponse;
|
||||
import com.cloud.api.response.ServiceResponse;
|
||||
import com.cloud.api.response.SnapshotPolicyResponse;
|
||||
import com.cloud.api.response.SnapshotResponse;
|
||||
import com.cloud.api.response.StoragePoolResponse;
|
||||
@ -97,6 +99,8 @@ import com.cloud.host.HostStats;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.network.IpAddress;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.RemoteAccessVpn;
|
||||
import com.cloud.network.VpnUser;
|
||||
@ -2209,7 +2213,36 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
response.setRelated(network.getRelated());
|
||||
response.setDns1(network.getDns1());
|
||||
response.setDns2(network.getDns2());
|
||||
|
||||
|
||||
//populate capability
|
||||
Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getZoneCapabilities(network.getDataCenterId());
|
||||
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
|
||||
if (serviceCapabilitiesMap != null) {
|
||||
for (Service service : serviceCapabilitiesMap.keySet()) {
|
||||
ServiceResponse serviceResponse = new ServiceResponse();
|
||||
serviceResponse.setName(service.getName());
|
||||
|
||||
//set list of capabilities for the service
|
||||
List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
|
||||
Map<Capability, String> serviceCapabilities = serviceCapabilitiesMap.get(service);
|
||||
if (serviceCapabilities != null) {
|
||||
for (Capability capability : serviceCapabilities.keySet()) {
|
||||
CapabilityResponse capabilityResponse = new CapabilityResponse();
|
||||
String capabilityValue = serviceCapabilities.get(capability);
|
||||
capabilityResponse.setName(capability.getName());
|
||||
capabilityResponse.setValue(capabilityValue);
|
||||
capabilityResponse.setObjectName("capability");
|
||||
capabilityResponses.add(capabilityResponse);
|
||||
}
|
||||
serviceResponse.setCapabilities(capabilityResponses);
|
||||
}
|
||||
|
||||
serviceResponse.setObjectName("service");
|
||||
serviceResponses.add(serviceResponse);
|
||||
}
|
||||
}
|
||||
response.setServices(serviceResponses);
|
||||
|
||||
Account account = ApiDBUtils.findAccountById(network.getAccountId());
|
||||
if (account != null) {
|
||||
response.setAccountName(account.getAccountName());
|
||||
|
||||
@ -28,7 +28,7 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
import com.cloud.network.service.Providers;
|
||||
import com.cloud.network.Network.Provider;
|
||||
|
||||
@Entity
|
||||
@Table(name="data_center")
|
||||
@ -77,13 +77,13 @@ public class DataCenterVO implements DataCenter {
|
||||
NetworkType networkType;
|
||||
|
||||
@Column(name="dns_provider")
|
||||
private String dnsProvider = "VirtualRouter";
|
||||
private String dnsProvider = Provider.VirtualRouter.getName();
|
||||
|
||||
@Column(name="dhcp_provider")
|
||||
private String dhcpProvider = "VirtualRouter";
|
||||
private String dhcpProvider = Provider.VirtualRouter.getName();
|
||||
|
||||
@Column(name="gateway_provider")
|
||||
private String gatewayProvider = "VirtualRouter";
|
||||
private String gatewayProvider = Provider.VirtualRouter.getName();
|
||||
|
||||
@Column(name="vpn_provider")
|
||||
private String vpnProvider;
|
||||
@ -163,13 +163,13 @@ public class DataCenterVO implements DataCenter {
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.networkType = zoneType;
|
||||
loadBalancerProvider = Providers.VirtualRouter;
|
||||
firewallProvider = Providers.VirtualRouter;
|
||||
dhcpProvider = Providers.VirtualRouter;
|
||||
dnsProvider = Providers.VirtualRouter;
|
||||
gatewayProvider = Providers.VirtualRouter;
|
||||
vpnProvider = Providers.VirtualRouter;
|
||||
userDataProvider = Providers.VirtualRouter;
|
||||
loadBalancerProvider = Provider.VirtualRouter.getName();
|
||||
firewallProvider = Provider.VirtualRouter.getName();
|
||||
dhcpProvider = Provider.VirtualRouter.getName();
|
||||
dnsProvider = Provider.VirtualRouter.getName();
|
||||
gatewayProvider = Provider.VirtualRouter.getName();
|
||||
vpnProvider = Provider.VirtualRouter.getName();
|
||||
userDataProvider = Provider.VirtualRouter.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
package com.cloud.network;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.cloud.dc.Vlan.VlanType;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
@ -26,6 +27,8 @@ import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientAddressCapacityException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.addr.PublicIp;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.offerings.NetworkOfferingVO;
|
||||
@ -123,4 +126,6 @@ public interface NetworkManager extends NetworkService {
|
||||
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
|
||||
|
||||
boolean applyRules(List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException;
|
||||
|
||||
Map<Service, Map<Capability, String>> getZoneCapabilities(long zoneId);
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -87,6 +88,8 @@ import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.Networks.AddressFormat;
|
||||
import com.cloud.network.Networks.Availability;
|
||||
import com.cloud.network.Networks.BroadcastDomainType;
|
||||
@ -1781,7 +1784,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
throw new CloudRuntimeException("Failed to create a vlan");
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
txn.commit();
|
||||
|
||||
return networks.get(0);
|
||||
} catch (Exception ex) {
|
||||
s_logger.warn("Unexpected exception while creating network ", ex);
|
||||
@ -1878,7 +1882,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
}
|
||||
sc.addAnd("accountId", SearchCriteria.Op.SC, ssc);
|
||||
|
||||
return _networksDao.search(sc, searchFilter);
|
||||
List<NetworkVO> networks = _networksDao.search(sc, searchFilter);
|
||||
|
||||
return networks;
|
||||
}
|
||||
|
||||
@Override @DB
|
||||
@ -2131,4 +2137,43 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
public int getActiveNicsInNetwork(long networkId) {
|
||||
return _networksDao.getActiveNicsIn(networkId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Service, Map<Capability, String>> getZoneCapabilities(long zoneId) {
|
||||
DataCenterVO dc = _dcDao.findById(zoneId);
|
||||
if (dc == null) {
|
||||
throw new InvalidParameterValueException("Zone id=" + dc.getId() + " doesn't exist in the system.");
|
||||
}
|
||||
|
||||
//Get all service providers from the datacenter
|
||||
Map<Service,String> providers = new HashMap<Service,String>();
|
||||
providers.put(Service.Firewall, dc.getFirewallProvider());
|
||||
providers.put(Service.Lb, dc.getLoadBalancerProvider());
|
||||
providers.put(Service.Vpn, dc.getVpnProvider());
|
||||
providers.put(Service.Dns, dc.getDnsProvider());
|
||||
providers.put(Service.Gateway, dc.getGatewayProvider());
|
||||
providers.put(Service.UserData, dc.getUserDataProvider());
|
||||
providers.put(Service.Dhcp, dc.getDhcpProvider());
|
||||
|
||||
Map<Service, Map<Capability, String>> networkCapabilities = new HashMap<Service, Map<Capability, String>>();
|
||||
|
||||
for (NetworkElement element : _networkElements) {
|
||||
if (providers.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
Map<Service, Map<Capability, String>> elementCapabilities = element.getCapabilities();
|
||||
if (elementCapabilities != null) {
|
||||
Iterator<Service> it = providers.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Service service = it.next();
|
||||
if (providers.get(service).equals(element.getProvider().getName())) {
|
||||
networkCapabilities.put(service, elementCapabilities.get(service));
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return networkCapabilities;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ public class NetworkVO implements Network {
|
||||
Date created;
|
||||
|
||||
@Column(name="reservation_id")
|
||||
String reservationId;
|
||||
String reservationId;
|
||||
|
||||
public NetworkVO() {
|
||||
}
|
||||
|
||||
@ -17,7 +17,9 @@
|
||||
*/
|
||||
package com.cloud.network.element;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
@ -29,12 +31,14 @@ import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
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.PublicIpAddress;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.service.Providers;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.NetworkOffering.GuestIpType;
|
||||
import com.cloud.uservm.UserVm;
|
||||
@ -51,9 +55,11 @@ import com.cloud.vm.dao.UserVmDao;
|
||||
|
||||
|
||||
@Local(value=NetworkElement.class)
|
||||
public class DhcpElement extends AdapterBase implements NetworkElement {
|
||||
public class DhcpElement extends AdapterBase implements NetworkElement{
|
||||
private static final Logger s_logger = Logger.getLogger(DhcpElement.class);
|
||||
|
||||
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
|
||||
|
||||
@Inject NetworkDao _networkConfigDao;
|
||||
@Inject NetworkManager _networkMgr;
|
||||
@Inject VirtualNetworkApplianceManager _routerMgr;
|
||||
@ -64,10 +70,10 @@ public class DhcpElement extends AdapterBase implements NetworkElement {
|
||||
private boolean canHandle(GuestIpType ipType, DeployDestination dest) {
|
||||
DataCenter dc = dest.getDataCenter();
|
||||
String provider = dc.getGatewayProvider();
|
||||
if (!dc.getDhcpProvider().equals(Providers.VirtualRouter)) {
|
||||
if (!dc.getDhcpProvider().equals(Provider.VirtualRouter.getName())) {
|
||||
return false;
|
||||
}
|
||||
return ((ipType == GuestIpType.Virtual && !provider.equals(Providers.VirtualRouter)) || (ipType == GuestIpType.Direct || ipType == GuestIpType.DirectPodBased));
|
||||
return ((ipType == GuestIpType.Virtual && !provider.equals(Provider.VirtualRouter.getName())) || (ipType == GuestIpType.Direct || ipType == GuestIpType.DirectPodBased));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,7 +106,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement {
|
||||
public boolean release(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, ReservationContext context) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shutdown(Network config, ReservationContext context) throws ConcurrentOperationException {
|
||||
DomainRouterVO router = _routerDao.findByNetworkConfiguration(config.getId());
|
||||
@ -112,11 +118,33 @@ public class DhcpElement extends AdapterBase implements NetworkElement {
|
||||
|
||||
@Override
|
||||
public boolean applyRules(Network config, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress) throws ResourceUnavailableException {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Provider getProvider() {
|
||||
return Provider.DhcpServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Service, Map<Capability, String>> getCapabilities() {
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
private static Map<Service, Map<Capability, String>> setCapabilities() {
|
||||
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
|
||||
|
||||
capabilities.put(Service.Dns, null);
|
||||
capabilities.put(Service.UserData, null);
|
||||
capabilities.put(Service.Dhcp, null);
|
||||
capabilities.put(Service.Gateway, null);
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,9 @@
|
||||
package com.cloud.network.element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
@ -32,6 +34,9 @@ import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.network.LoadBalancerVO;
|
||||
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.PublicIpAddress;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
@ -42,7 +47,6 @@ import com.cloud.network.lb.LoadBalancingRulesManager;
|
||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||
import com.cloud.network.rules.FirewallRule;
|
||||
import com.cloud.network.rules.FirewallRule.Purpose;
|
||||
import com.cloud.network.service.Providers;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.offering.NetworkOffering.GuestIpType;
|
||||
import com.cloud.offerings.dao.NetworkOfferingDao;
|
||||
@ -65,6 +69,8 @@ import com.cloud.vm.dao.UserVmDao;
|
||||
public class VirtualRouterElement extends AdapterBase implements NetworkElement {
|
||||
private static final Logger s_logger = Logger.getLogger(VirtualRouterElement.class);
|
||||
|
||||
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
|
||||
|
||||
@Inject NetworkDao _networkConfigDao;
|
||||
@Inject NetworkManager _networkMgr;
|
||||
@Inject LoadBalancingRulesManager _lbMgr;
|
||||
@ -76,10 +82,9 @@ public class VirtualRouterElement extends AdapterBase implements NetworkElement
|
||||
@Inject DataCenterDao _dataCenterDao;
|
||||
@Inject LoadBalancerDao _lbDao;
|
||||
|
||||
|
||||
private boolean canHandle(GuestIpType ipType, DataCenter dc) {
|
||||
String provider = dc.getGatewayProvider();
|
||||
return (ipType == GuestIpType.Virtual && provider.equals(Providers.VirtualRouter));
|
||||
return (ipType == GuestIpType.Virtual && provider.equals(Provider.VirtualRouter.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -174,5 +179,49 @@ public class VirtualRouterElement extends AdapterBase implements NetworkElement
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Provider getProvider() {
|
||||
return Provider.VirtualRouter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Service, Map<Capability, String>> getCapabilities() {
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
private static Map<Service, Map<Capability, String>> setCapabilities() {
|
||||
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
|
||||
|
||||
//Set capabilities for LB service
|
||||
Map<Capability, String> lbCapabilities = new HashMap<Capability, String>();
|
||||
lbCapabilities.put(Capability.SupportedLBAlgorithms, "roundrobin,leastconn,sourceip");
|
||||
lbCapabilities.put(Capability.SupportedProtocols, "tcp, udp");
|
||||
|
||||
capabilities.put(Service.Lb, lbCapabilities);
|
||||
|
||||
//Set capabilities for Firewall service
|
||||
Map<Capability, String> firewallCapabilities = new HashMap<Capability, String>();
|
||||
firewallCapabilities.put(Capability.PortForwarding, "true");
|
||||
firewallCapabilities.put(Capability.StaticNat, "true");
|
||||
firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp");
|
||||
firewallCapabilities.put(Capability.MultipleIps, "true");
|
||||
firewallCapabilities.put(Capability.SupportedSourceNatTypes, "per account");
|
||||
|
||||
capabilities.put(Service.Firewall, firewallCapabilities);
|
||||
|
||||
//Set capabilities for vpn
|
||||
Map<Capability, String> vpnCapabilities = new HashMap<Capability, String>();
|
||||
vpnCapabilities.put(Capability.SupportedVpnTypes, "pptp,l2tp,ipsec");
|
||||
|
||||
capabilities.put(Service.Vpn, vpnCapabilities);
|
||||
capabilities.put(Service.Dns, null);
|
||||
capabilities.put(Service.UserData, null);
|
||||
capabilities.put(Service.Dhcp, null);
|
||||
capabilities.put(Service.Gateway, null);
|
||||
|
||||
return capabilities;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user