bug 7878: Fixed Basic zone functionality - uservm/systemvm/domR start

status 7878: resolved fixed
This commit is contained in:
alena 2011-01-06 00:47:50 -08:00
parent 02dc187a0c
commit 916b516d13
43 changed files with 636 additions and 524 deletions

View File

@ -65,10 +65,10 @@ public class CreateNetworkCmd extends BaseCmd {
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the VLAN. Default is an \"untagged\" VLAN.")
private String vlan;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the VLAN. If VLAN is Zone wide, this parameter should be ommited")
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the network")
private String accountName;
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a VLAN")
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a network")
private Long domainId;
@Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network offering supports vlans")

View File

@ -26,8 +26,8 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.NetworkOfferingResponse;
import com.cloud.network.Networks.Availability;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Availability;
@Implementation(description="Creates a network offering.", responseObject=NetworkOfferingResponse.class)
public class CreateNetworkOfferingCmd extends BaseCmd {
@ -44,9 +44,6 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network offering")
private String displayText;
@Parameter(name=ApiConstants.TYPE, type=CommandType.STRING, required=true, description="type of the network. Supported types Virtual, Direct")
private String type;
@Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, required=true, description="the traffic type for the network offering, supported types are Public, Management, Control, Guest, Vlan or Storage.")
private String traffictype;
@ -78,10 +75,6 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
return tags;
}
public String getType() {
return type;
}
public String getTraffictype() {
return traffictype;
}

View File

@ -17,8 +17,6 @@
*/
package com.cloud.api.commands;
import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
@ -32,10 +30,10 @@ import com.cloud.api.response.SuccessResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.user.UserContext;
@Implementation(description="Reapplies all ip addresses for the particular network", responseObject=IPAddressResponse.class)
public class RestartNetworkCmd extends BaseAsyncCmd {
@ -46,12 +44,6 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account to associate with this IP address")
private String accountName;
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the domain to associate with this IP address")
private Long domainId;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the ID of the availability zone you want to acquire an public IP address from")
private Long zoneId;
@ -63,20 +55,6 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public String getAccountName() {
if (accountName != null) {
return accountName;
}
return UserContext.current().getCaller().getAccountName();
}
public long getDomainId() {
if (domainId != null) {
return domainId;
}
return UserContext.current().getCaller().getDomainId();
}
public long getZoneId() {
return zoneId;
}
@ -90,26 +68,16 @@ public class RestartNetworkCmd extends BaseAsyncCmd {
}
public long getEntityOwnerId() {
List<? extends Network> networks = _networkService.getVirtualNetworksOwnedByAccountInZone(getAccountName(), getDomainId(), getZoneId());
if (networks.size() == 0) {
assert (networks.size() <= 1) : "No virtual network is found";
}
assert (networks.size() <= 1) : "Too many virtual networks. This logic should be obsolete";
return networks.get(0).getAccountId();
return _networkService.getNetwork(networkId).getAccountId();
}
public Long getNetworkId() {
if (networkId != null) {
return networkId;
Network network = _networkService.getNetwork(networkId);
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by id " + networkId);
} else {
return network.getId();
}
List<? extends Network> networks = _networkService.getVirtualNetworksOwnedByAccountInZone(getAccountName(), getDomainId(), getZoneId());
if (networks.size() == 0) {
return null;
}
assert (networks.size() <= 1) : "Too many virtual networks. This logic should be obsolete";
return networks.get(0).getId();
}

View File

@ -26,8 +26,8 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.NetworkOfferingResponse;
import com.cloud.network.Networks.Availability;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Availability;
@Implementation(description="Updates a network offering.", responseObject=NetworkOfferingResponse.class)
public class UpdateNetworkOfferingCmd extends BaseCmd {

View File

@ -24,9 +24,6 @@ public class NetworkOfferingResponse extends BaseResponse{
@SerializedName("maxconnections") @Param(description="the max number of concurrent connection the network offering supports")
private Integer maxConnections;
@SerializedName("type") @Param(description="type of the network. Supported types are Virtualized, DirectSingle, DirectDual")
private String type;
@SerializedName("traffictype") @Param(description="the traffic type for the network offering, supported types are Public, Management, Control, Guest, Vlan or Storage.")
private String trafficType;
@ -87,14 +84,6 @@ public class NetworkOfferingResponse extends BaseResponse{
this.maxConnections = maxConnections;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getTrafficType() {
return trafficType;
}

View File

@ -55,4 +55,6 @@ public interface NetworkService {
int getActiveNicsInNetwork(long networkId);
Network getNetwork(long networkId);
}

View File

@ -36,12 +36,6 @@ public class Networks {
Firewall
}
public enum Availability {
Required,
Optional,
Unavailable;
}
/**
* Different ways to assign ip address to this network.
*/

View File

@ -61,5 +61,7 @@ public interface LoadBalancingRulesService {
* @return list of load balancers that match the criteria
*/
List<? extends LoadBalancer> searchForLoadBalancers(ListLoadBalancerRulesCmd cmd);
List<LoadBalancingRule> listByNetworkId(long networkId);
}

View File

@ -17,7 +17,6 @@
*/
package com.cloud.offering;
import com.cloud.network.Networks.Availability;
import com.cloud.network.Networks.TrafficType;
/**
@ -29,13 +28,23 @@ public interface NetworkOffering {
public enum GuestIpType {
Virtual,
Direct,
DirectPodBased,
}
public final String DefaultVirtualizedNetworkOffering = "DefaultVirtualizedNetworkOffering";
public final String DefaultDirectNetworkOffering = "DefaultDirectNetworkOffering";
public final String DefaultDirectPodBasedNetworkOffering = "DefaultDirectPodBasedNetworkOffering";
public final String DefaultDirectChooseVlanNetworkOffering = "DefaultDirectChooseVlanNetworkOffering";
public enum Availability {
Required,
Optional,
Unavailable;
}
public final static String SystemPublicNetwork = "System-Public-Network";
public final static String SystemControlNetwork = "System-Control-Network";
public final static String SystemManagementNetwork = "System-Management-Network";
public final static String SystemStorageNetwork = "System-Storage-Network";
public final static String SysteGuestNetwork = "System-Guest-Network";
public final static String DefaultVirtualizedNetworkOffering = "DefaultVirtualizedNetworkOffering";
public final static String DefaultDirectNetworkOffering = "DefaultDirectNetworkOffering";
public final static String DefaultDirectChooseVlanNetworkOffering = "DefaultDirectChooseVlanNetworkOffering";
long getId();
@ -59,11 +68,6 @@ public interface NetworkOffering {
*/
Integer getMulticastRateMbps();
/**
* @return the type of IP address to allocate as the primary ip address to a guest
*/
GuestIpType getGuestIpType();
/**
* @return concurrent connections to be supported.
*/

View File

@ -104,7 +104,6 @@ public interface AccountService {
* @param cmd - the LockAccount command defining the accountId to be locked.
* @return account object
*/
//Account lockAccount(LockAccountCmd cmd);
Account lockAccount(DisableAccountCmd cmd);
/**
@ -139,6 +138,14 @@ public interface AccountService {
User createUser(CreateUserCmd cmd);
boolean deleteUser(DeleteUserCmd deleteUserCmd);
boolean isAdmin(short accountType);
Account finalizeOwner(Account caller, String accountName, Long domainId);
Account getActiveAccount(String accountName, Long domainId);
Account getAccount(Long accountId);
}

View File

@ -45,6 +45,7 @@
<adapter name="PodBasedNetworkGuru" class="com.cloud.network.guru.PodBasedNetworkGuru"/>
<adapter name="ControlNetworkGuru" class="com.cloud.network.guru.ControlNetworkGuru"/>
<adapter name="DirectNetworkGuru" class="com.cloud.network.guru.DirectNetworkGuru"/>
<adapter name="DirectPodBasedNetworkGuru" class="com.cloud.network.guru.DirectPodBasedNetworkGuru"/>
</adapters>
<adapters key="com.cloud.storage.secondary.SecondaryStorageVmAllocator">
<adapter name="Balance" class="com.cloud.storage.secondary.SecondaryStorageVmDefaultAllocator"/>

View File

@ -151,6 +151,7 @@ import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.api.to.VirtualMachineTO.Monitor;
import com.cloud.agent.api.to.VirtualMachineTO.SshMonitor;
import com.cloud.agent.api.to.VolumeTO;
import com.cloud.dc.Vlan;
import com.cloud.exception.InternalErrorException;
import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@ -2942,7 +2943,7 @@ public abstract class CitrixResourceBase implements ServerResource {
Set<VIF> routerVIFs = router.getVIFs(conn);
for (VIF vif : routerVIFs) {
Network vifNetwork = vif.getNetwork(conn);
if (vlanId.equals("untagged")) {
if (vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
if (vifNetwork.getUuid(conn).equals(_host.publicNetwork)) {
return vif;
}

View File

@ -509,7 +509,7 @@ public class ApiDBUtils {
}
public static long getPublicNetworkIdByZone(long zoneId) {
return _networkMgr.getSystemNetworkIdByZoneAndTrafficTypeAndGuestType(zoneId, TrafficType.Public, null);
return _networkMgr.getSystemNetworkByZoneAndTrafficType(zoneId, TrafficType.Public).getId();
}
public static Long getVlanNetworkId(long vlanId) {

View File

@ -113,7 +113,6 @@ import com.cloud.network.security.SecurityGroup;
import com.cloud.network.security.SecurityGroupRules;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offering.ServiceOffering;
import com.cloud.org.Cluster;
import com.cloud.server.Criteria;
@ -1090,10 +1089,7 @@ public class ApiResponseHelper implements ResponseGenerator {
nicResponse.setTrafficType(network.getTrafficType().toString());
//Set type
NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
if (networkOffering.getGuestIpType() != null) {
nicResponse.setType(networkOffering.getGuestIpType().toString());
}
nicResponse.setType(network.getGuestType().toString());
nicResponse.setObjectName("nic");
@ -2174,9 +2170,6 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setDisplayText(offering.getDisplayText());
response.setTags(offering.getTags());
response.setTrafficType(offering.getTrafficType().toString());
if (offering.getGuestIpType() != null) {
response.setType(offering.getGuestIpType().toString());
}
response.setMaxconnections(offering.getConcurrentConnections());
response.setIsDefault(offering.isDefault());
response.setSpecifyVlan(offering.getSpecifyVlan());

View File

@ -29,9 +29,9 @@ import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.network.Networks.Availability;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering.Availability;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offering.ServiceOffering;
import com.cloud.offerings.NetworkOfferingVO;

View File

@ -93,13 +93,13 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.IPAddressVO;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.Availability;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Availability;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offering.ServiceOffering;
import com.cloud.offerings.NetworkOfferingVO;
@ -1212,14 +1212,18 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
} else if (offering.getTrafficType() == TrafficType.Control) {
broadcastDomainType = BroadcastDomainType.LinkLocal;
} else if (offering.getTrafficType() == TrafficType.Public) {
if (zone.getNetworkType() == NetworkType.Basic && offering.getGuestIpType() == GuestIpType.DirectPodBased) {
broadcastDomainType = BroadcastDomainType.Native;
} else if (zone.getNetworkType() == NetworkType.Advanced && offering.getGuestIpType() == null) {
if (zone.getNetworkType() == NetworkType.Advanced) {
broadcastDomainType = BroadcastDomainType.Vlan;
} else {
continue;
}
}
} else if (offering.getTrafficType() == TrafficType.Guest) {
if (zone.getNetworkType() == NetworkType.Basic) {
broadcastDomainType = BroadcastDomainType.Native;
} else {
continue;
}
}
userNetwork.setBroadcastDomainType(broadcastDomainType);
_networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, true);
}
@ -1648,14 +1652,14 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (forVirtualNetwork){
if (network == null) {
//find default public network in the zone
networkId = _networkMgr.getSystemNetworkIdByZoneAndTrafficTypeAndGuestType(zoneId, TrafficType.Public, null);
networkId = _networkMgr.getSystemNetworkByZoneAndTrafficType(zoneId, TrafficType.Public).getId();
} else if (network.getGuestType() != null || network.getTrafficType() != TrafficType.Public){
throw new InvalidParameterValueException("Can't find Public network by id=" + networkId);
}
} else {
if (network == null) {
if (zone.getNetworkType() == DataCenter.NetworkType.Basic) {
networkId = _networkMgr.getSystemNetworkIdByZoneAndTrafficTypeAndGuestType(zoneId, TrafficType.Public, GuestIpType.DirectPodBased);
networkId = _networkMgr.getSystemNetworkByZoneAndTrafficType(zoneId, TrafficType.Guest).getId();
} else {
throw new InvalidParameterValueException("Nework id is required for Direct vlan creation ");
}
@ -1677,11 +1681,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
//check if startIp and endIp belong to network Cidr
String networkCidr = network.getCidr();
String networkGateway = network.getGateway();
Long networkZoneId = network.getDataCenterId();
String[] splitResult = networkCidr.split("\\/");
long size = Long.valueOf(splitResult[1]);
String networkNetmask = NetUtils.getCidrNetmask(size);
String networkNetmask = NetUtils.getCidrNetmask(networkCidr);
//Check if ip addresses are in network range
if (!NetUtils.sameSubnet(startIP, networkGateway, networkNetmask)) {
@ -1719,7 +1720,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException("Please specify a valid pod.");
}
if (podId != null && _podDao.findById(podId).getDataCenterId() != zoneId) {
throw new InvalidParameterValueException("Pod id=" + podId + " doesn't belong to zone id=" + zoneId);
}
@ -1753,7 +1753,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if(hypervisorType.equalsIgnoreCase("xenserver")) {
//check for the vlan being added before going to db, to see if it is untagged
if(vlanType.toString().equalsIgnoreCase("VirtualNetwork") && vlanId.equalsIgnoreCase("untagged"))
if(vlanType.toString().equalsIgnoreCase("VirtualNetwork") && vlanId.equalsIgnoreCase(Vlan.UNTAGGED))
{
if(_configDao.getValue("xen.public.network.device") == null || _configDao.getValue("xen.public.network.device").equals(""))
{
@ -1774,13 +1774,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
}
// //check if the account's domain is a child of the zone's domain, for adding vlan ip ranges
// if(domainId != null && !_domainDao.isChildDomain(zone.getDomainId(), domainId)){
// //this is for account specific case, as domainId != null
// throw new PermissionDeniedException("The account associated with specific domain id:"+domainId+" doesn't have permissions to add vlan ip ranges for the zone:"+zone.getId());
// }
//ACL check
checkAccess(account, zone);
@ -1909,6 +1902,19 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for the guest network in zone " + zone.getName());
}
//For untagged vlan check if vlan per pod already exists. If yes, verify that new vlan range has the same netmask and gateway
if (zone.getNetworkType() == NetworkType.Basic && vlanId.equalsIgnoreCase(Vlan.UNTAGGED) && podId != null){
List<VlanVO> podVlans = _vlanDao.listVlansForPodByType(podId, VlanType.DirectAttached);
if (podVlans != null && !podVlans.isEmpty()) {
VlanVO podVlan = podVlans.get(0);
if (!podVlan.getVlanNetmask().equals(vlanNetmask)) {
throw new InvalidParameterValueException("Vlan netmask is different from the netmask of Untagged vlan id=" + podVlan.getId() + " existing in the pod " + podId);
} else if (!podVlan.getVlanGateway().equals(vlanGateway)) {
throw new InvalidParameterValueException("Vlan gateway is different from the gateway of Untagged vlan id=" + podVlan.getId() + " existing in the pod " + podId);
}
}
}
// Everything was fine, so persist the VLAN
String ipRange = startIP;
if (endIP != null) {
@ -2665,7 +2671,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
String name = cmd.getNetworkOfferingName();
String displayText = cmd.getDisplayText();
String tags = cmd.getTags();
String typeString = cmd.getType();
String trafficTypeString = cmd.getTraffictype();
Boolean specifyVlan = cmd.getSpecifyVlan();
String availabilityStr = cmd.getAvailability();
@ -2685,16 +2690,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException("Invalid value for traffictype. Supported traffic types: Public, Management, Control, Guest, Vlan or Storage");
}
//Verify type
for (GuestIpType gType : GuestIpType.values()) {
if (gType.name().equalsIgnoreCase(typeString)) {
type = gType;
}
}
if (type == null || type == GuestIpType.DirectPodBased) {
throw new InvalidParameterValueException("Invalid value for type. Supported types: Virtual, Direct");
}
//Verify availability
for (Availability avlb : Availability.values()) {
if (avlb.name().equalsIgnoreCase(availabilityStr)) {
@ -2717,7 +2712,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
int networkRate = ((networkRateStr == null) ? 200 : Integer.parseInt(networkRateStr));
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
tags = cleanupTags(tags);
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, type, false, specifyVlan, networkRate, multicastRate, maxConnections, false, availability, false, false, false, false, false, false, false);
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, false, specifyVlan, networkRate, multicastRate, maxConnections, false, availability, false, false, false, false, false, false, false);
if ((offering = _networkOfferingDao.persist(offering)) != null) {
saveConfigurationEvent(userId, null, EventTypes.EVENT_NETWORK_OFFERING_CREATE, "Successfully created new network offering with name: " + name + ".", "noId=" + offering.getId(), "name=" + name,

View File

@ -72,6 +72,8 @@ import com.cloud.certificate.dao.CertificateDao;
import com.cloud.cluster.ClusterManager;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.dao.DataCenterDao;
@ -697,8 +699,12 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
List<NetworkOfferingVO> defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmPublicNetwork);
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork, NetworkOfferingVO.SystemVmManagementNetwork);
List<NetworkOfferingVO> defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork);
if (dc.getNetworkType() == NetworkType.Basic) {
defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SysteGuestNetwork);
}
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork);
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
@ -2020,10 +2026,11 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
cmds.addCommand("checkSsh", check);
ConsoleProxyVO proxy = profile.getVirtualMachine();
DataCenter dc = dest.getDataCenter();
List<NicVO> nics = _nicDao.listBy(proxy.getId());
for (NicVO nic : nics) {
NetworkVO network = _networkDao.findById(nic.getNetworkId());
if (network.getTrafficType() == TrafficType.Public) {
if ((network.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (network.getTrafficType() == TrafficType.Guest && dc.getNetworkType() == NetworkType.Basic)) {
proxy.setPublicIpAddress(nic.getIp4Address());
proxy.setPublicNetmask(nic.getNetmask());
proxy.setPublicMacAddress(nic.getMacAddress());

View File

@ -40,13 +40,9 @@ public interface VlanDao extends GenericDao<VlanVO, Long> {
List<VlanVO> listVlansForPodByType(long podId, Vlan.VlanType vlanType);
void addToPod(long podId, long vlanDbId);
// Pair<String, VlanVO> assignIpAddress(long zoneId, long accountId, long domainId, VlanType vlanType, boolean sourceNat);
List<VlanVO> listVlansForAccountByType(Long zoneId, long accountId, VlanType vlanType);
// Pair<String, VlanVO> assignPodDirectAttachIpAddress(long zoneId, long podId, long accountId, long domainId);
boolean zoneHasDirectAttachUntaggedVlans(long zoneId);
List<VlanVO> listZoneWideVlans(long zoneId, VlanType vlanType, String vlanId);

View File

@ -33,9 +33,7 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.vpn.RemoteAccessVpnElement;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.user.Account;
import com.cloud.user.AccountVO;
import com.cloud.utils.Pair;
@ -59,13 +57,14 @@ public interface NetworkManager extends NetworkService {
* Assigns a new public ip address.
*
* @param dcId
* @param podId TODO
* @param owner
* @param type
* @param networkId
* @return
* @throws InsufficientAddressCapacityException
*/
PublicIp assignPublicIpAddress(long dcId, Account owner, VlanType type, Long networkId) throws InsufficientAddressCapacityException;
PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId) throws InsufficientAddressCapacityException;
/**
* assigns a source nat ip address to an account within a network.
@ -125,21 +124,19 @@ public interface NetworkManager extends NetworkService {
AccountVO getNetworkOwner(long configurationId);
List<NetworkVO> getNetworksforOffering(long offeringId, long dataCenterId, long accountId);
List<NetworkVO> setupNetwork(Account owner, ServiceOfferingVO offering, DeploymentPlan plan) throws ConcurrentOperationException;
Network getNetwork(long id);
String getNextAvailableMacAddressInNetwork(long networkConfigurationId) throws InsufficientAddressCapacityException;
boolean applyRules(List<? extends FirewallRule> rules, boolean continueOnError) throws ResourceUnavailableException;
Map<Service, Map<Capability, String>> getZoneCapabilities(long zoneId);
long getSystemNetworkIdByZoneAndTrafficTypeAndGuestType(long zoneId, TrafficType trafficType, GuestIpType guestType);
Network getSystemNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType);
List<? extends RemoteAccessVpnElement> getRemoteAccessVpnElements();
PublicIpAddress getPublicIpAddress(Ip ipAddress);
Network getBasicZoneDefaultPublicNetwork(long zoneId);
String getPodVlanGateway(long podId);
}

View File

@ -43,30 +43,30 @@ import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.manager.Commands;
import com.cloud.alert.AlertManager;
import com.cloud.api.BaseCmd;
import com.cloud.api.ServerApiException;
import com.cloud.api.commands.AssociateIPAddrCmd;
import com.cloud.api.commands.CreateNetworkCmd;
import com.cloud.api.commands.DisassociateIPAddrCmd;
import com.cloud.api.commands.ListNetworksCmd;
import com.cloud.api.commands.RestartNetworkCmd;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.ResourceCount.ResourceType;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.configuration.dao.ResourceLimitDao;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.PodVlanMapVO;
import com.cloud.dc.Vlan;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.VlanVO;
import com.cloud.dc.dao.AccountVlanMapDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.PodVlanMapDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.domain.Domain;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.EventTypes;
import com.cloud.event.EventUtils;
@ -87,20 +87,15 @@ 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;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.FirewallRulesDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.RemoteAccessVpnDao;
import com.cloud.network.dao.VpnUserDao;
import com.cloud.network.element.NetworkElement;
import com.cloud.network.guru.NetworkGuru;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
import com.cloud.network.lb.LoadBalancingRulesManager;
import com.cloud.network.router.VirtualNetworkApplianceManager;
import com.cloud.network.rules.FirewallRule;
@ -109,13 +104,12 @@ import com.cloud.network.rules.RulesManager;
import com.cloud.network.rules.dao.PortForwardingRulesDao;
import com.cloud.network.vpn.RemoteAccessVpnElement;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.Availability;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.resource.Resource;
import com.cloud.resource.Resource.ReservationStrategy;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
import com.cloud.user.AccountVO;
@ -170,27 +164,21 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Inject EventDao _eventDao = null;
@Inject ConfigurationDao _configDao;
@Inject UserVmDao _vmDao = null;
@Inject ResourceLimitDao _limitDao = null;
@Inject CapacityDao _capacityDao = null;
@Inject AgentManager _agentMgr;
@Inject AlertManager _alertMgr;
@Inject AccountManager _accountMgr;
@Inject ConfigurationManager _configMgr;
@Inject ServiceOfferingDao _serviceOfferingDao = null;
@Inject AccountVlanMapDao _accountVlanMapDao;
@Inject UserStatisticsDao _statsDao = null;
@Inject NetworkOfferingDao _networkOfferingDao = null;
@Inject NetworkDao _networksDao = null;
@Inject NicDao _nicDao = null;
@Inject RemoteAccessVpnDao _remoteAccessVpnDao = null;
@Inject VpnUserDao _vpnUsersDao = null;
@Inject VirtualNetworkApplianceManager _routerMgr;
@Inject RulesManager _rulesMgr;
@Inject LoadBalancingRulesManager _lbMgr;
@Inject FirewallRulesDao _firewallRulesDao;
@Inject LoadBalancerDao _lbDao;
@Inject PortForwardingRulesDao _pfRulesDao;
@Inject UsageEventDao _usageEventDao;
@Inject PodVlanMapDao _podVlanMapDao;
@Inject(adapter=NetworkGuru.class)
Adapters<NetworkGuru> _networkGurus;
@ -203,7 +191,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
SearchBuilder<AccountVO> AccountsUsingNetworkSearch;
SearchBuilder<IPAddressVO> AssignIpAddressSearch;
SearchBuilder<IPAddressVO> AssignIpAddressFromPodVlanSearch;
SearchBuilder<IPAddressVO> IpAddressSearch;
int _networkGcWait;
int _networkGcInterval;
@ -212,15 +202,22 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
HashMap<Long, Long> _lastNetworkIdsToFree = new HashMap<Long, Long>();
@Override
public PublicIp assignPublicIpAddress(long dcId, Account owner, VlanType type, Long networkId) throws InsufficientAddressCapacityException {
return fetchNewPublicIp(dcId, owner, type, networkId, false, true);
public PublicIp assignPublicIpAddress(long dcId, Long podId, Account owner, VlanType type, Long networkId) throws InsufficientAddressCapacityException {
return fetchNewPublicIp(dcId, podId, owner, type, networkId, false, true);
}
@DB
public PublicIp fetchNewPublicIp(long dcId, Account owner, VlanType vlanUse, Long networkId, boolean sourceNat, boolean assign) throws InsufficientAddressCapacityException {
public PublicIp fetchNewPublicIp(long dcId, Long podId, Account owner, VlanType vlanUse, Long networkId, boolean sourceNat, boolean assign) throws InsufficientAddressCapacityException {
Transaction txn = Transaction.currentTxn();
txn.start();
SearchCriteria<IPAddressVO> sc = AssignIpAddressSearch.create();
SearchCriteria<IPAddressVO> sc = null;
if (podId != null) {
sc = AssignIpAddressFromPodVlanSearch.create();
sc.setJoinParameters("podVlanMapSB", "podId", podId);
} else {
sc = AssignIpAddressSearch.create();
}
sc.setParameters("dc", dcId);
//for direct network take ip addresses only from the vlans belonging to the network
@ -303,7 +300,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
s_logger.debug("assigning a new ip address in " + dcId + " to " + owner);
}
ip = fetchNewPublicIp(dcId, owner, VlanType.VirtualNetwork, network.getId(), true, false);
ip = fetchNewPublicIp(dcId, null, owner, VlanType.VirtualNetwork, network.getId(), true, false);
sourceNat = ip.ip();
sourceNat.setState(IpAddress.State.Allocated);
_ipAddressDao.update(sourceNat.getAddress(), sourceNat);
@ -441,26 +438,24 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
protected Account getAccountForApiCommand(String accountName, Long domainId) throws InvalidParameterValueException, PermissionDeniedException{
Account account = UserContext.current().getCaller();
if ((account == null) || isAdmin(account.getType())) {
if (_accountMgr.isAdmin(account.getType())) {
//The admin is making the call, determine if it is for someone else or for himself
if (domainId != null) {
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
throw new PermissionDeniedException("Invalid domain id (" + domainId + ") given, , permission denied");
}
if (accountName != null) {
Account userAccount = _accountDao.findActiveAccount(accountName, domainId);
Account userAccount = _accountMgr.getActiveAccount(accountName, domainId);
if (userAccount != null) {
account = userAccount;
} else {
throw new PermissionDeniedException("Unable to find account " + accountName + " in domain " + domainId + ", permission denied");
}
}
} else if (account != null) {
} else {
// the admin is calling the api on his own behalf
return account;
} else {
throw new InvalidParameterValueException("Account information is not specified.");
}
}
}
return account;
}
@ -506,7 +501,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
public List<? extends Network> getVirtualNetworksOwnedByAccountInZone(String accountName, long domainId, long zoneId) {
Account owner = _accountDao.findActiveAccount(accountName, domainId);
Account owner = _accountMgr.getActiveAccount(accountName, domainId);
if (owner == null) {
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId + ", permission denied");
}
@ -522,7 +517,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Account caller = UserContext.current().getCaller();
long userId = UserContext.current().getCallerUserId();
Account owner = _accountDao.findActiveAccount(accountName, domainId);
Account owner = _accountMgr.getActiveAccount(accountName, domainId);
if (owner == null) {
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId + ", permission denied");
}
@ -572,7 +567,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
txn.start();
ip = fetchNewPublicIp(zoneId, owner, VlanType.VirtualNetwork, network.getId(), false, false);
ip = fetchNewPublicIp(zoneId, null, owner, VlanType.VirtualNetwork, network.getId(), false, false);
if (ip == null) {
throw new InsufficientAddressCapacityException("Unable to find available public IP addresses", DataCenter.class, zoneId);
@ -701,26 +696,27 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
_networkGcWait = NumbersUtil.parseInt(_configs.get(Config.NetworkGcWait.key()), 600);
_networkGcInterval = NumbersUtil.parseInt(_configs.get(Config.NetworkGcInterval.key()), 600);
NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmPublicNetwork, TrafficType.Public, null);
NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public, null);
publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemVmPublicNetwork, publicNetworkOffering);
NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmManagementNetwork, TrafficType.Management, null);
_systemNetworks.put(NetworkOfferingVO.SystemPublicNetwork, publicNetworkOffering);
NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management, null);
managementNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(managementNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemVmManagementNetwork, managementNetworkOffering);
NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmControlNetwork, TrafficType.Control, null);
_systemNetworks.put(NetworkOfferingVO.SystemManagementNetwork, managementNetworkOffering);
NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control, null);
controlNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(controlNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemVmControlNetwork, controlNetworkOffering);
NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmStorageNetwork, TrafficType.Storage, null);
_systemNetworks.put(NetworkOfferingVO.SystemControlNetwork, controlNetworkOffering);
NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage, null);
storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemVmStorageNetwork, storageNetworkOffering);
NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, GuestIpType.Virtual, false, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering);
NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Public, GuestIpType.Direct, false, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering);
NetworkOfferingVO defaultGuestDirectPodBasedNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectPodBasedNetworkOffering, "DirectPodBased", TrafficType.Public, GuestIpType.DirectPodBased, true, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectPodBasedNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemStorageNetwork, storageNetworkOffering);
NetworkOfferingVO guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SysteGuestNetwork, TrafficType.Guest, null);
guestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(guestNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SysteGuestNetwork, guestNetworkOffering);
NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, false, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering);
NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Public, false, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
defaultGuestDirectNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering);
AccountsUsingNetworkSearch = _accountDao.createSearchBuilder();
SearchBuilder<NetworkAccountVO> networkAccountSearch = _networksDao.createSearchBuilderForAccount();
AccountsUsingNetworkSearch.join("nc", networkAccountSearch, AccountsUsingNetworkSearch.entity().getId(), networkAccountSearch.entity().getAccountId(), JoinType.INNER);
@ -729,14 +725,26 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
AccountsUsingNetworkSearch.done();
AssignIpAddressSearch = _ipAddressDao.createSearchBuilder();
SearchBuilder<VlanVO> vlanSearch = _vlanDao.createSearchBuilder();
AssignIpAddressSearch.and("dc", AssignIpAddressSearch.entity().getDataCenterId(), Op.EQ);
AssignIpAddressSearch.and("allocated", AssignIpAddressSearch.entity().getAllocatedTime(), Op.NULL);
AssignIpAddressSearch.join("vlan", vlanSearch, vlanSearch.entity().getId(), AssignIpAddressSearch.entity().getVlanId(), JoinType.INNER);
SearchBuilder<VlanVO> vlanSearch = _vlanDao.createSearchBuilder();
vlanSearch.and("type", vlanSearch.entity().getVlanType(), Op.EQ);
vlanSearch.and("networkId", vlanSearch.entity().getNetworkId(), Op.EQ);
AssignIpAddressSearch.join("vlan", vlanSearch, vlanSearch.entity().getId(), AssignIpAddressSearch.entity().getVlanId(), JoinType.INNER);
AssignIpAddressSearch.done();
AssignIpAddressFromPodVlanSearch = _ipAddressDao.createSearchBuilder();
AssignIpAddressFromPodVlanSearch.and("dc", AssignIpAddressFromPodVlanSearch.entity().getDataCenterId(), Op.EQ);
AssignIpAddressFromPodVlanSearch.and("allocated", AssignIpAddressFromPodVlanSearch.entity().getAllocatedTime(), Op.NULL);
SearchBuilder<VlanVO> podVlanSearch = _vlanDao.createSearchBuilder();
podVlanSearch.and("type", podVlanSearch.entity().getVlanType(), Op.EQ);
podVlanSearch.and("networkId", podVlanSearch.entity().getNetworkId(), Op.EQ);
SearchBuilder<PodVlanMapVO> podVlanMapSB = _podVlanMapDao.createSearchBuilder();
podVlanMapSB.and("podId", podVlanMapSB.entity().getPodId(), Op.EQ);
AssignIpAddressFromPodVlanSearch.join("podVlanMapSB", podVlanMapSB, podVlanMapSB.entity().getVlanDbId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(), JoinType.INNER);
AssignIpAddressFromPodVlanSearch.join("vlan", podVlanSearch, podVlanSearch.entity().getId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(), JoinType.INNER);
AssignIpAddressFromPodVlanSearch.done();
IpAddressSearch = _ipAddressDao.createSearchBuilder();
IpAddressSearch.and("accountId", IpAddressSearch.entity().getAllocatedToAccountId(), Op.EQ);
IpAddressSearch.and("dataCenterId", IpAddressSearch.entity().getDataCenterId(), Op.EQ);
@ -1114,16 +1122,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return _nicDao.listBy(vm.getId());
}
public static boolean isAdmin(short accountType) {
return ((accountType == Account.ACCOUNT_TYPE_ADMIN) ||
(accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) ||
(accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
}
private Account findAccountByIpAddress(Ip ipAddress) {
IPAddressVO address = _ipAddressDao.findById(ipAddress);
if ((address != null) && (address.getAllocatedToAccountId() != null)) {
return _accountDao.findById(address.getAllocatedToAccountId());
return _accountMgr.getAccount(address.getAllocatedToAccountId());
}
return null;
}
@ -1133,29 +1135,23 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
public boolean disassociateIpAddress(DisassociateIPAddrCmd cmd) throws PermissionDeniedException, IllegalArgumentException {
Long userId = UserContext.current().getCallerUserId();
Account account = UserContext.current().getCaller();
Account caller = UserContext.current().getCaller();
Ip ipAddress = cmd.getIpAddress();
// Verify input parameters
Account accountByIp = findAccountByIpAddress(ipAddress);
if(accountByIp == null) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to find account owner for ip " + ipAddress);
throw new InvalidParameterValueException("Unable to find account owner for ip " + ipAddress);
}
Long accountId = accountByIp.getId();
if (account != null) {
if (!isAdmin(account.getType())) {
if (account.getId() != accountId.longValue()) {
throw new ServerApiException(BaseCmd.PARAM_ERROR, "account " + account.getAccountName() + " doesn't own ip address " + ipAddress);
}
} else if (!_domainDao.isChildDomain(account.getDomainId(), accountByIp.getDomainId())) {
throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, "Unable to disassociate IP address " + ipAddress + ", permission denied.");
if (!_accountMgr.isAdmin(caller.getType())) {
if (caller.getId() != accountId.longValue()) {
throw new PermissionDeniedException("account " + caller.getAccountName() + " doesn't own ip address " + ipAddress);
}
}
// If command is executed via 8096 port, set userId to the id of System account (1)
if (userId == null) {
userId = Long.valueOf(1);
} else {
Domain domain = _domainDao.findById(accountByIp.getDomainId());
_accountMgr.checkAccess(caller, domain);
}
try {
@ -1168,7 +1164,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return true;
}
Account Account = _accountDao.findById(accountId);
Account Account = _accountMgr.getAccount(accountId);
if (Account == null) {
return false;
}
@ -1240,12 +1236,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return _networksDao.getNetworksForOffering(offeringId, dataCenterId, accountId);
}
@Override
public List<NetworkVO> setupNetwork(Account owner, ServiceOfferingVO offering, DeploymentPlan plan) throws ConcurrentOperationException {
NetworkOfferingVO networkOffering = _networkOfferingDao.findByServiceOffering(offering);
return setupNetwork(owner, networkOffering, plan, null, null, false);
}
@Override
public List<NetworkOfferingVO> listNetworkOfferings() {
return _networkOfferingDao.listNonSystemNetworkOfferings();
@ -1312,8 +1302,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
String name = cmd.getNetworkName();
String displayText = cmd.getDisplayText();
Boolean isShared = cmd.getIsShared();
Account owner = null;
Long ownerId = null;
//if end ip is not specified, default it to startIp
if (endIP == null && startIP != null) {
@ -1329,65 +1317,24 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
//Check if zone exists
if (zoneId == null || ((_dcDao.findById(zoneId)) == null)) {
throw new InvalidParameterValueException("Please specify a valid zone.");
}
DataCenter zone = _dcDao.findById(zoneId);
if (zone.getNetworkType() == NetworkType.Basic) {
throw new InvalidParameterValueException("Network creation is not allowed in zone with network type " + NetworkType.Basic);
}
//Check permissions
if (isAdmin(ctxAccount.getType())) {
if (domainId != null) {
if ((ctxAccount != null) && !_domainDao.isChildDomain(ctxAccount.getDomainId(), domainId)) {
throw new PermissionDeniedException("Failed to create a newtwork, invalid domain id (" + domainId + ") given.");
}
if (accountName != null) {
owner = _accountDao.findActiveAccount(accountName, domainId);
if (owner == null) {
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
}
}
} else {
owner = ctxAccount;
}
} else {
//regular user can't create networks for anybody else but himself
owner = ctxAccount;
}
ownerId = owner.getId();
Account owner = _accountMgr.finalizeOwner(ctxAccount, accountName, domainId);
//Don't allow to create network with vlan that already exists in the system
if (networkOffering.getGuestIpType() == GuestIpType.Direct && vlanId != null) {
if (vlanId != null) {
String uri ="vlan://" + vlanId;
List<NetworkVO> networks = _networksDao.listBy(zoneId, uri);
if ((networks != null && !networks.isEmpty())) {
throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId);
}
}
//if VlanId is Direct untagged, verify if there is already network of this type in the zone
if (networkOffering.getGuestIpType() == GuestIpType.DirectPodBased && vlanId != null && vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
SearchBuilder<NetworkVO> sb = _networksDao.createSearchBuilder();
sb.and("broadcastDomainType", sb.entity().getBroadcastDomainType(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
SearchBuilder<NetworkOfferingVO> networkSearch = _networkOfferingDao.createSearchBuilder();
networkSearch.and("guestIpType", networkSearch.entity().getGuestIpType(), SearchCriteria.Op.EQ);
sb.join("networkSearch", networkSearch, sb.entity().getNetworkOfferingId(), networkSearch.entity().getId(), JoinBuilder.JoinType.INNER);
SearchCriteria<NetworkVO> sc = sb.create();
sc.setParameters("broadcastDomainType", BroadcastDomainType.Native);
sc.setParameters("dataCenterId", zoneId);
sc.setJoinParameters("networkSearch", "guestIpType", GuestIpType.DirectPodBased);
List<NetworkVO> networks = _networksDao.search(sc, null);
if (networks!= null && !networks.isEmpty()) {
throw new InvalidParameterValueException("Network with untagged vlan already exists for the zone " + zoneId);
}
}
//Regular user can create only network of Virtual type
if (ctxAccount.getType() == Account.ACCOUNT_TYPE_NORMAL && networkOffering.getGuestIpType() != GuestIpType.Virtual) {
throw new InvalidParameterValueException("Regular user can create only networ of type " + GuestIpType.Virtual);
}
//VlanId can be specified only when network offering supports it
if (ctxAccount.getType() == Account.ACCOUNT_TYPE_NORMAL && vlanId != null && !networkOffering.getSpecifyVlan()) {
throw new InvalidParameterValueException("Can't specify vlan because network offering doesn't support it");
@ -1420,14 +1367,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
List<NetworkVO> networks = setupNetwork(owner, networkOffering, userNetwork, plan, name, displayText, isShared);
Long networkId = null;
Network network = null;
if (networks == null || networks.isEmpty()) {
txn.rollback();
throw new CloudRuntimeException("Fail to create a network");
} else {
network = networks.get(0);
networkId = networks.get(0).getId();
}
for (Network network : networks) {
if (network.getGuestType() == GuestIpType.Virtual) {
s_logger.debug("Creating a source natp ip for " + network);
PublicIp ip = assignSourceNatIpAddress(owner, network, userId);
@ -1437,12 +1383,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
Long ownerId = owner.getId();
//Don't pass owner to create vlan when network offering is of type Direct - done to prevent accountVlanMap entry creation when vlan is mapped to network
if (networkOffering.getGuestIpType() == GuestIpType.Direct) {
if (network.getGuestType() == GuestIpType.Direct) {
owner = null;
}
if (ctxAccount.getType() == Account.ACCOUNT_TYPE_ADMIN && networkOffering.getGuestIpType() == GuestIpType.Direct && startIP != null && endIP != null && gateway != null) {
if (ctxAccount.getType() == Account.ACCOUNT_TYPE_ADMIN && network.getGuestType() == GuestIpType.Direct && startIP != null && endIP != null && gateway != null) {
//Create vlan ip range
Vlan vlan = _configMgr.createVlanAndPublicIpRange(userId, zoneId, null, startIP, endIP, gateway, netmask, false, vlanId, owner, networkId);
if (vlan == null) {
@ -1493,14 +1440,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
isSystem = false;
}
if (isAdmin(account.getType())) {
if (_accountMgr.isAdmin(account.getType())) {
if (domainId != null) {
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
throw new PermissionDeniedException("Invalid domain id (" + domainId + ") given, unable to list networks");
}
if (accountName != null) {
account = _accountDao.findActiveAccount(accountName, domainId);
account = _accountMgr.getActiveAccount(accountName, domainId);
if (account == null) {
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
}
@ -1567,7 +1514,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override @DB
public boolean deleteNetwork(long networkId) throws InvalidParameterValueException, PermissionDeniedException{
Long userId = UserContext.current().getCallerUserId();
Account account = UserContext.current().getCaller();
Account caller = UserContext.current().getCaller();
//Verify network id
NetworkVO network = _networksDao.findById(networkId);
@ -1580,14 +1527,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
String name = network.getName();
//Perform permission check
if (account != null) {
if (!isAdmin(account.getType())) {
if (network.getAccountId() != account.getId()) {
throw new PermissionDeniedException("Account " + account.getAccountName() + " does not own network id=" + networkId + ", permission denied");
}
} else if (!(account.getType() == Account.ACCOUNT_TYPE_ADMIN) && !_domainDao.isChildDomain(account.getDomainId(), _accountDao.findById(network.getAccountId()).getId())) {
throw new PermissionDeniedException("Unable to delete network " + networkId + ", permission denied.");
if (!_accountMgr.isAdmin(caller.getType())) {
if (network.getAccountId() != caller.getId()) {
throw new PermissionDeniedException("Account " + caller.getAccountName() + " does not own network id=" + networkId + ", permission denied");
}
} else {
Account owner = _accountMgr.getAccount(network.getAccountId());
Domain domain = _domainDao.findById(owner.getDomainId());
_accountMgr.checkAccess(caller, domain);
}
//Don't allow to remove network if there are non-destroyed vms using it
@ -1757,16 +1704,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
public boolean restartNetwork(RestartNetworkCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException {
//This method reapplies Ip addresses, LoadBalancer and PortForwarding rules
String accountName = cmd.getAccountName();
long domainId = cmd.getDomainId();
Account caller = UserContext.current().getCaller();
Account owner = _accountDao.findActiveAccount(accountName, domainId);
if (owner == null) {
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId + ", permission denied");
}
_accountMgr.checkAccess(caller, owner);
Long networkId = cmd.getNetworkId();
Network network = null;
@ -1777,28 +1715,28 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
if (!_accountMgr.isAdmin(caller.getType())) {
_accountMgr.checkAccess(caller, network);
} else {
Domain domain = _domainDao.findById(owner.getDomainId());
_accountMgr.checkAccess(caller, domain);
}
s_logger.debug("Restarting network " + networkId + "...");
boolean success = true;
if (!applyIpAssociations(network, false)) {
s_logger.warn("Failed to apply ips as a part of network " + networkId + " restart");
success = false;
return false;
} else {
s_logger.debug("Ip addresses are reapplied successfully as a part of network " + networkId + " restart");
}
//Reapply lb rules
List<LoadBalancerVO> lbs = _lbDao.listByNetworkId(networkId);
List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
for (LoadBalancerVO lb : lbs) {
List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
lbRules.add(loadBalancing);
}
List<LoadBalancingRule> lbRules = _lbMgr.listByNetworkId(networkId);
if (!applyRules(lbRules, true)) {
s_logger.warn("Failed to apply load balancing rules as a part of network " + network.getId() + " restart");
success = false;
return false;
} else {
s_logger.debug("Load balancing rules are reapplied successfully as a part of network " + networkId + " restart");
}
@ -1807,15 +1745,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
List<PortForwardingRuleVO> pfRules = _pfRulesDao.listByNetworkId(networkId);
if (!applyRules(pfRules, true)) {
s_logger.warn("Failed to apply port forwarding rules as a part of network " + network.getId() + " restart");
success = false;
return false;
} else {
s_logger.debug("Port forwarding rules are reapplied successfully as a part of network " + networkId + " restart");
}
if (success){
s_logger.debug("Network " + networkId + " is restarted successfully.");
}
return success;
s_logger.debug("Network " + networkId + " is restarted successfully.");
return true;
}
@Override
@ -1874,26 +1810,26 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public long getSystemNetworkIdByZoneAndTrafficTypeAndGuestType(long zoneId, TrafficType trafficType, GuestIpType guestType) {
public Network getSystemNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType) {
//find system public network offering
Long networkOfferingId = null;
List<NetworkOfferingVO> offerings = _networkOfferingDao.listSystemNetworkOfferings();
for (NetworkOfferingVO offering: offerings) {
if (offering.getTrafficType() == trafficType && offering.getGuestIpType() == guestType) {
if (offering.getTrafficType() == trafficType) {
networkOfferingId = offering.getId();
break;
}
}
if (networkOfferingId == null) {
throw new InvalidParameterValueException("Unable to find system network offering with traffic type " + trafficType + " and guestIpType " + guestType);
throw new InvalidParameterValueException("Unable to find system network offering with traffic type " + trafficType);
}
List<NetworkVO> networks = _networksDao.listBy(Account.ACCOUNT_ID_SYSTEM, networkOfferingId, zoneId);
if (networks == null) {
throw new InvalidParameterValueException("Unable to find network with traffic type " + trafficType + " in zone " + zoneId);
}
return networks.get(0).getId();
return networks.get(0);
}
@Override
@ -1907,21 +1843,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public Network getBasicZoneDefaultPublicNetwork(long zoneId) {
SearchBuilder<NetworkVO> sb = _networksDao.createSearchBuilder();
sb.and("trafficType", sb.entity().getTrafficType(), SearchCriteria.Op.EQ);
sb.and("guestType", sb.entity().getGuestType(), SearchCriteria.Op.EQ);
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
SearchCriteria<NetworkVO> sc = sb.create();
sc.setParameters("trafficType", TrafficType.Public);
sc.setParameters("guestType", GuestIpType.DirectPodBased);
sc.setParameters("dataCenterId", zoneId);
List<NetworkVO> networks = _networksDao.search(sc, null);
if (networks == null || networks.isEmpty()) {
return null;
public String getPodVlanGateway(long podId) {
List<VlanVO> vlans = _vlanDao.listVlansForPodByType(podId, VlanType.DirectAttached);
//we don't allow vlans to have different gateways, so take the value from the first one
if (vlans == null || !vlans.isEmpty()) {
return vlans.get(0).getVlanGateway();
} else {
return networks.get(0);
return null;
}
}
}

View File

@ -142,14 +142,19 @@ public class NetworkVO implements Network {
* @param broadcastDomainType
* @param networkOfferingId
* @param dataCenterId
* @param state TODO
*/
public NetworkVO(TrafficType trafficType, GuestIpType guestType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId) {
public NetworkVO(TrafficType trafficType, GuestIpType guestType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId, State state) {
this.trafficType = trafficType;
this.mode = mode;
this.broadcastDomainType = broadcastDomainType;
this.networkOfferingId = networkOfferingId;
this.dataCenterId = dataCenterId;
this.state = State.Allocated;
if (state == null) {
state = State.Allocated;
} else {
this.state = state;
}
this.id = -1;
this.guestType = guestType;
}
@ -183,7 +188,7 @@ public class NetworkVO implements Network {
* @param isShared TODO
*/
public NetworkVO(long id, TrafficType trafficType, GuestIpType guestType, Mode mode, BroadcastDomainType broadcastDomainType, long networkOfferingId, long dataCenterId, long domainId, long accountId, long related, String name, String displayText, Boolean isShared) {
this(trafficType, guestType, mode, broadcastDomainType, networkOfferingId, dataCenterId);
this(trafficType, guestType, mode, broadcastDomainType, networkOfferingId, dataCenterId, State.Allocated);
this.domainId = domainId;
this.accountId = accountId;
this.related = related;

View File

@ -26,6 +26,7 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
@ -35,6 +36,7 @@ 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.Networks.TrafficType;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.router.VirtualNetworkApplianceManager;
@ -67,16 +69,24 @@ public class DhcpElement extends AdapterBase implements NetworkElement{
@Inject UserVmDao _userVmDao;
@Inject DomainRouterDao _routerDao;
private boolean canHandle(GuestIpType ipType, DeployDestination dest) {
private boolean canHandle(GuestIpType ipType, DeployDestination dest, TrafficType trafficType) {
DataCenter dc = dest.getDataCenter();
String provider = dc.getGatewayProvider();
return ((ipType == GuestIpType.Virtual && !provider.equals(Provider.VirtualRouter.getName())) || (provider.equals(Provider.VirtualRouter.getName()) && (ipType == GuestIpType.Direct || ipType == GuestIpType.DirectPodBased)));
if (provider.equals(Provider.VirtualRouter.getName())) {
if (dc.getNetworkType() == NetworkType.Basic) {
return (ipType == GuestIpType.Direct && trafficType == TrafficType.Guest);
} else {
return (ipType == GuestIpType.Direct);
}
} else {
return (ipType == GuestIpType.Virtual);
}
}
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
if (!canHandle(offering.getGuestIpType(), dest)) {
if (!canHandle(network.getGuestType(), dest, offering.getTrafficType())) {
return false;
}
_routerMgr.deployDhcp(network, dest, context.getAccount());
@ -85,7 +95,7 @@ public class DhcpElement extends AdapterBase implements NetworkElement{
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (canHandle(network.getGuestType(), dest)) {
if (canHandle(network.getGuestType(), dest, network.getTrafficType())) {
if (vm.getType() != VirtualMachine.Type.User) {
return false;

View File

@ -93,7 +93,7 @@ public class VirtualRouterElement extends AdapterBase implements NetworkElement,
@Override
public boolean implement(Network guestConfig, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
if (!canHandle(offering.getGuestIpType(), dest.getDataCenter())) {
if (!canHandle(guestConfig.getGuestType(), dest.getDataCenter())) {
return false;
}
_routerMgr.deployVirtualRouter(guestConfig, dest, context.getAccount());

View File

@ -1,4 +1,18 @@
/**
* 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.network.guru;
@ -25,6 +39,7 @@ import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.resource.Resource.ReservationStrategy;
import com.cloud.user.Account;
import com.cloud.utils.component.ComponentLocator;
@ -40,16 +55,26 @@ import com.cloud.vm.VirtualMachineProfile;
public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(ControlNetworkGuru.class);
@Inject DataCenterDao _dcDao;
@Inject NetworkOfferingDao _networkOfferingDao;
String _cidr;
String _gateway;
protected boolean canHandle(NetworkOffering offering) {
if (offering.isSystemOnly() && offering.getTrafficType() == TrafficType.Control) {
return true;
} else {
s_logger.trace("We only care about System only Control network");
return false;
}
}
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network specifiedConfig, Account owner) {
if (offering.getTrafficType() != TrafficType.Control) {
if (!canHandle(offering)) {
return null;
}
NetworkVO config = new NetworkVO(offering.getTrafficType(), offering.getGuestIpType(), Mode.Static, BroadcastDomainType.LinkLocal, offering.getId(), plan.getDataCenterId());
NetworkVO config = new NetworkVO(offering.getTrafficType(), null, Mode.Static, BroadcastDomainType.LinkLocal, offering.getId(), plan.getDataCenterId(), Network.State.Setup);
config.setCidr(_cidr);
config.setGateway(_gateway);
@ -64,8 +89,9 @@ public class ControlNetworkGuru extends PodBasedNetworkGuru implements NetworkGu
public NicProfile allocate(Network config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
if (config.getTrafficType() != TrafficType.Control) {
return null;
NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(config.getNetworkOfferingId());
if (!canHandle(offering)) {
return null;
}
if(vm.getHypervisorType() == HypervisorType.VmWare && vm.getType() != VirtualMachine.Type.DomainRouter) {

View File

@ -1,4 +1,18 @@
/**
* 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.network.guru;
@ -8,7 +22,7 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.VlanDao;
@ -31,6 +45,7 @@ import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.resource.Resource.ReservationStrategy;
import com.cloud.user.Account;
import com.cloud.utils.component.AdapterBase;
@ -48,16 +63,32 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@Inject VlanDao _vlanDao;
@Inject NetworkManager _networkMgr;
@Inject IPAddressDao _ipAddressDao;
@Inject NetworkOfferingDao _networkOfferingDao;
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
//this guru handles only non-system Public network
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Public && !offering.isSystemOnly()) {
return true;
} else {
s_logger.trace("We only take care of Public Direct networks");
return false;
}
}
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
if (!(offering.getTrafficType() == TrafficType.Public && (offering.getGuestIpType() == GuestIpType.Direct || offering.getGuestIpType() == GuestIpType.DirectPodBased))) {
s_logger.trace("We only take care of public direct network, so this is no ours");
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
if (!canHandle(offering, dc)) {
return null;
}
NetworkVO config = new NetworkVO(offering.getTrafficType(), offering.getGuestIpType(), Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId());
DataCenterVO dc = _dcDao.findById(plan.getDataCenterId());
State state = State.Allocated;
if (offering.isSystemOnly()) {
state = State.Setup;
}
NetworkVO config = new NetworkVO(offering.getTrafficType(), GuestIpType.Direct, Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), state);
if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
@ -92,10 +123,10 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
if (nic.getIp4Address() == null) {
PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId());
PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.DirectAttached, network.getId());
nic.setIp4Address(ip.getAddress().toString());
nic.setGateway(ip.getGateway());
nic.setNetmask(ip.getNetmask());
nic.setNetmask(ip.getNetmask());
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
nic.setBroadcastType(BroadcastDomainType.Vlan);
nic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(ip.getVlanTag()));
@ -110,6 +141,12 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException {
DataCenter dc = _dcDao.findById(network.getDataCenterId());
NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
if (!canHandle(offering, dc)) {
return null;
}
if (nic == null) {
nic = new NicProfile(ReservationStrategy.Create, null, null, null, null);
@ -119,7 +156,6 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
nic.setStrategy(ReservationStrategy.Create);
}
DataCenter dc = _dcDao.findById(network.getDataCenterId());
getIp(nic, dc, vm, network);
return nic;

View File

@ -0,0 +1,123 @@
/**
* 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.network.guru;
import java.net.URI;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.dc.DataCenter;
import com.cloud.dc.Pod;
import com.cloud.dc.Vlan;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.Network;
import com.cloud.network.NetworkManager;
import com.cloud.network.Networks.AddressFormat;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.resource.Resource.ReservationStrategy;
import com.cloud.utils.component.Inject;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@Local(value=NetworkGuru.class)
public class DirectPodBasedNetworkGuru extends DirectNetworkGuru{
private static final Logger s_logger = Logger.getLogger(DirectPodBasedNetworkGuru.class);
@Inject DataCenterDao _dcDao;
@Inject VlanDao _vlanDao;
@Inject NetworkManager _networkMgr;
@Inject IPAddressDao _ipAddressDao;
@Inject NetworkOfferingDao _networkOfferingDao;
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
//this guru handles system Direct pod based network
if (dc.getNetworkType() == NetworkType.Basic && offering.getTrafficType() == TrafficType.Guest && offering.isSystemOnly()) {
return true;
} else {
s_logger.trace("We only take care of Guest Direct Pod based networks");
return false;
}
}
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException {
DataCenter dc = _dcDao.findById(network.getDataCenterId());
NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
if (!canHandle(offering, dc)) {
return null;
}
if (nic == null) {
nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
} else {
nic.setStrategy(ReservationStrategy.Start);
}
return nic;
}
@Override
public void reserve(NicProfile nic, Network network, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
if (nic.getIp4Address() == null) {
getIp(nic, dest.getPod(), vm, network);
}
}
protected void getIp(NicProfile nic, Pod pod, VirtualMachineProfile<? extends VirtualMachine> vm, Network network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
DataCenter dc = _dcDao.findById(pod.getDataCenterId());
if (nic.getIp4Address() == null) {
PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), pod.getId(), vm.getOwner(), VlanType.DirectAttached, network.getId());
nic.setIp4Address(ip.getAddress().toString());
nic.setGateway(ip.getGateway());
nic.setNetmask(ip.getNetmask());
if(ip.getVlanTag() != null && ip.getVlanTag().equalsIgnoreCase(Vlan.UNTAGGED)) {
nic.setIsolationUri(URI.create("vlan://" + Vlan.UNTAGGED));
nic.setBroadcastUri(URI.create("vlan://" + Vlan.UNTAGGED));
nic.setBroadcastType(BroadcastDomainType.Native);
}
nic.setFormat(AddressFormat.Ip4);
nic.setReservationId(String.valueOf(ip.getVlanTag()));
nic.setMacAddress(ip.getMacAddress());
}
nic.setDns1(dc.getDns1());
nic.setDns2(dc.getDns2());
}
}

View File

@ -24,7 +24,10 @@ import java.util.TreeSet;
import javax.ejb.Local;
import com.cloud.dc.DataCenterVO;
import org.apache.log4j.Logger;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DeployDestination;
@ -56,6 +59,7 @@ import com.cloud.vm.dao.NicDao;
@Local(value=NetworkGuru.class)
public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
private static final Logger s_logger = Logger.getLogger(GuestNetworkGuru.class);
@Inject protected NetworkManager _networkMgr;
@Inject protected DataCenterDao _dcDao;
@Inject protected VlanDao _vlanDao;
@ -69,25 +73,24 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
super();
}
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
//This guru handles only non-system Guest network
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Guest && !offering.isSystemOnly()) {
return true;
} else {
s_logger.trace("We only take care of Guest networks in zone of type " + NetworkType.Advanced);
return false;
}
}
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
if (offering.getTrafficType() != TrafficType.Guest || offering.getGuestIpType() != GuestIpType.Virtual) {
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
if (!canHandle(offering, dc)) {
return null;
}
BroadcastDomainType broadcastType = null;
Mode mode = null;
GuestIpType ipType = offering.getGuestIpType();
if (ipType == GuestIpType.Virtual) {
mode = Mode.Dhcp;
broadcastType = BroadcastDomainType.Vlan;
} else {
broadcastType = BroadcastDomainType.Native;
mode = Mode.Dhcp;
}
DataCenterVO dc = _dcDao.findById(plan.getDataCenterId());
NetworkVO network = new NetworkVO(offering.getTrafficType(), offering.getGuestIpType(), mode, broadcastType, offering.getId(), plan.getDataCenterId());
NetworkVO network = new NetworkVO(offering.getTrafficType(), GuestIpType.Virtual, Mode.Dhcp, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), State.Allocated);
if (userSpecified != null) {
if ((userSpecified.getCidr() == null && userSpecified.getGateway() != null) ||
(userSpecified.getCidr() != null && userSpecified.getGateway() == null)) {
@ -135,7 +138,9 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
long dcId = dest.getDataCenter().getId();
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getGuestType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), network.getDataCenterId());
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getGuestType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), network.getDataCenterId(), State.Allocated);
if (network.getBroadcastUri() == null) {
String vnet = _dcDao.allocateVnet(dcId, network.getAccountId(), context.getReservationId());

View File

@ -50,7 +50,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
return null;
}
NetworkVO config = new NetworkVO(type, offering.getGuestIpType(), Mode.Static, BroadcastDomainType.Native, offering.getId(), plan.getDataCenterId());
NetworkVO config = new NetworkVO(type, null, Mode.Static, BroadcastDomainType.Native, offering.getId(), plan.getDataCenterId(), Network.State.Setup);
DataCenterVO dc = _dcDao.findById(plan.getDataCenterId());
config.setDns1(dc.getDns1());
config.setDns2(dc.getDns2());

View File

@ -3,15 +3,12 @@
*/
package com.cloud.network.guru;
import java.net.URI;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.VlanDao;
@ -23,6 +20,7 @@ import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.Network;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Network.State;
import com.cloud.network.Networks.AddressFormat;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.IsolationType;
@ -31,7 +29,7 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.resource.Resource.ReservationStrategy;
import com.cloud.user.Account;
import com.cloud.utils.component.AdapterBase;
@ -50,19 +48,28 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
@Inject VlanDao _vlanDao;
@Inject NetworkManager _networkMgr;
@Inject IPAddressDao _ipAddressDao;
@Inject NetworkOfferingDao _networkOfferingDao;
protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
if (dc.getNetworkType() == NetworkType.Advanced && offering.getTrafficType() == TrafficType.Public && offering.isSystemOnly()) {
return true;
} else {
s_logger.trace("We only take care of System only Public Virtual Network");
return false;
}
}
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network network, Account owner) {
if (offering.getTrafficType() != TrafficType.Public || (offering.getGuestIpType() != null && offering.getGuestIpType() != GuestIpType.Virtual)) {
s_logger.trace("We only take care of Public Virtual Network");
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
if (!canHandle(offering, dc)) {
return null;
}
if (offering.getTrafficType() == TrafficType.Public) {
NetworkVO ntwk = new NetworkVO(offering.getTrafficType(), offering.getGuestIpType(), Mode.Static, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId());
DataCenterVO dc = _dcDao.findById(plan.getDataCenterId());
NetworkVO ntwk = new NetworkVO(offering.getTrafficType(), null, Mode.Static, BroadcastDomainType.Vlan, offering.getId(), plan.getDataCenterId(), State.Setup);
ntwk.setDns1(dc.getDns1());
ntwk.setDns2(dc.getDns2());
return ntwk;
@ -77,20 +84,13 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
protected void getIp(NicProfile nic, DataCenter dc, VirtualMachineProfile<? extends VirtualMachine> vm, Network network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException {
if (nic.getIp4Address() == null) {
PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), vm.getOwner(), dc.getNetworkType().equals(NetworkType.Basic) ? VlanType.DirectAttached : VlanType.VirtualNetwork, null);
PublicIp ip = _networkMgr.assignPublicIpAddress(dc.getId(), null, vm.getOwner(), VlanType.VirtualNetwork, null);
nic.setIp4Address(ip.getAddress().toString());
nic.setGateway(ip.getGateway());
nic.setNetmask(ip.getNetmask());
if(ip.getVlanTag() != null && ip.getVlanTag().equalsIgnoreCase("untagged")) {
nic.setIsolationUri(URI.create("vlan://untagged"));
nic.setBroadcastUri(URI.create("vlan://untagged"));
nic.setBroadcastType(BroadcastDomainType.Native);
} else if (ip.getVlanTag() != null){
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
nic.setBroadcastUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
nic.setBroadcastType(BroadcastDomainType.Vlan);
}
nic.setNetmask(ip.getNetmask());
nic.setIsolationUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
nic.setBroadcastUri(IsolationType.Vlan.toUri(ip.getVlanTag()));
nic.setBroadcastType(BroadcastDomainType.Vlan);
nic.setFormat(AddressFormat.Ip4);
nic.setReservationId(String.valueOf(ip.getVlanTag()));
nic.setMacAddress(ip.getMacAddress());
@ -102,7 +102,10 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
@Override
public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException {
if (network.getTrafficType() != TrafficType.Public) {
DataCenter dc = _dcDao.findById(network.getDataCenterId());
NetworkOffering offering = _networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
if (!canHandle(offering, dc)) {
return null;
}
@ -110,7 +113,6 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
nic = new NicProfile(ReservationStrategy.Create, null, null, null, null);
}
DataCenter dc = _dcDao.findById(network.getDataCenterId());
getIp(nic, dc, vm, network);
if (nic.getIp4Address() == null) {

View File

@ -1329,18 +1329,17 @@ public class LoadBalancingRulesManagerImpl implements LoadBalancingRulesManager,
return _lbDao.search(sc, searchFilter);
}
// @Override
// public LoadBalancerVO findLoadBalancer(Long accountId, String name) {
// SearchCriteria<LoadBalancerVO> sc = _loadBalancerDao.createSearchCriteria();
// sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId);
// sc.addAnd("name", SearchCriteria.Op.EQ, name);
// List<LoadBalancerVO> loadBalancers = _loadBalancerDao.search(sc, null);
// if ((loadBalancers != null) && !loadBalancers.isEmpty()) {
// return loadBalancers.get(0);
// }
// return null;
// }
@Override
public List<LoadBalancingRule> listByNetworkId(long networkId) {
List<LoadBalancerVO> lbs = _lbDao.listByNetworkId(networkId);
List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
for (LoadBalancerVO lb : lbs) {
List<LbDestination> dstList = getExistingDestinations(lb.getId());
LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList);
lbRules.add(loadBalancing);
}
return lbRules;
}
}

View File

@ -72,8 +72,10 @@ import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.configuration.dao.ResourceLimitDao;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.Vlan;
import com.cloud.dc.dao.AccountVlanMapDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
@ -1022,12 +1024,12 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddress(owner, guestNetwork, _accountService.getSystemUser().getId());
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork);
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork);
NetworkOfferingVO controlOffering = offerings.get(0);
NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(3);
NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmPublicNetwork).get(0);
NetworkOfferingVO publicOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork).get(0);
List<NetworkVO> publicConfigs = _networkMgr.setupNetwork(_systemAcct, publicOffering, plan, null, null, false);
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
@ -1036,7 +1038,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
defaultNic.setNetmask(sourceNatIp.getNetmask());
defaultNic.setTrafficType(TrafficType.Public);
defaultNic.setMacAddress(sourceNatIp.getMacAddress());
if (sourceNatIp.getVlanTag().equals("untagged")) {
if (sourceNatIp.getVlanTag().equals(Vlan.UNTAGGED)) {
defaultNic.setBroadcastType(BroadcastDomainType.Native);
} else {
defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
@ -1053,9 +1055,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
gatewayNic.setMode(guestNetwork.getMode());
String gatewayCidr = guestNetwork.getCidr();
String[] cidrPair = gatewayCidr.split("\\/");
long guestCidrSize = Long.parseLong(cidrPair[1]);
gatewayNic.setNetmask(NetUtils.getCidrNetmask(guestCidrSize));
gatewayNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, gatewayNic));
networks.add(new Pair<NetworkVO, NicProfile>(controlConfig, null));
@ -1096,8 +1096,17 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
+ guestNetwork;
DataCenterDeployment plan = new DataCenterDeployment(dcId);
DomainRouterVO router = _routerDao.findByNetworkConfiguration(guestNetwork.getId());
DataCenter dc = _dcDao.findById(dcId);
DomainRouterVO router = null;
Long podId = dest.getPod().getId();
//In Basic zone and Guest network we have to start domR per pod, not per network
if (dc.getNetworkType() == NetworkType.Basic && guestNetwork.getTrafficType() == TrafficType.Guest) {
router = _routerDao.findByNetworkConfigurationAndPod(guestNetwork.getId(), podId);
} else {
router = _routerDao.findByNetworkConfiguration(guestNetwork.getId());
}
if (router == null) {
long startEventId = EventUtils.saveStartedEvent(User.UID_SYSTEM, owner.getId(), EventTypes.EVENT_ROUTER_CREATE, "Starting to create router for accountId : " +owner.getAccountId());
long id = _routerDao.getNextInSequence(Long.class, "id");
@ -1105,7 +1114,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
s_logger.debug("Creating the router " + id);
}
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork);
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork);
NetworkOfferingVO controlOffering = offerings.get(0);
NetworkVO controlConfig = _networkMgr.setupNetwork(_systemAcct, controlOffering, plan, null, null, false).get(0);
@ -1147,12 +1156,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
String type = null;
String dhcpRange = null;
// get first ip address from network cidr
String cidr = network.getCidr();
String[] splitResult = cidr.split("\\/");
long size = Long.valueOf(splitResult[1]);
dhcpRange = NetUtils.getIpRangeStartIpFromCidr(splitResult[0], size);
DataCenter dc = dest.getDataCenter();
if (dc.getNetworkType() == NetworkType.Advanced) {
String cidr = network.getCidr();
dhcpRange = NetUtils.getDhcpRange(cidr);
}
String domain = network.getNetworkDomain();
if (router.getRole() == Role.DHCP_USERDATA) {
type = "dhcpsrvr";
@ -1176,6 +1186,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (nic.getDns2() != null) {
buf.append(" dns2=").append(nic.getDns2());
}
if (dc.getNetworkType() == NetworkType.Basic) {
long cidrSize = NetUtils.getCidrSize(nic.getNetmask());
String cidr = NetUtils.getCidrSubNet(nic.getGateway(), cidrSize);
if (cidr != null) {
dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize);
}
}
}
if (nic.getTrafficType() == TrafficType.Management) {
buf.append(" localgw=").append(dest.getPod().getGateway());

View File

@ -28,7 +28,6 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.cloud.network.Networks.Availability;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.NetworkOffering;
import com.cloud.service.ServiceOfferingVO;
@ -37,11 +36,7 @@ import com.cloud.utils.db.GenericDao;
@Entity
@Table(name="network_offerings")
public class NetworkOfferingVO implements NetworkOffering {
public final static String SystemVmPublicNetwork = "System-Public-Network";
public final static String SystemVmControlNetwork = "System-Control-Network";
public final static String SystemVmManagementNetwork = "System-Management-Network";
public final static String SystemVmStorageNetwork = "System-Storage-Network";
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
@ -62,10 +57,6 @@ public class NetworkOfferingVO implements NetworkOffering {
@Column(name="concurrent_connections")
Integer concurrentConnections;
@Column(name="type")
@Enumerated(value=EnumType.STRING)
GuestIpType guestIpType;
@Column(name="traffic_type")
@Enumerated(value=EnumType.STRING)
TrafficType trafficType;
@ -121,11 +112,6 @@ public class NetworkOfferingVO implements NetworkOffering {
return displayText;
}
@Override
public GuestIpType getGuestIpType() {
return guestIpType;
}
@Override
public long getId() {
return id;
@ -200,10 +186,6 @@ public class NetworkOfferingVO implements NetworkOffering {
this.concurrentConnections = concurrentConnections;
}
public void setGuestIpType(GuestIpType guestIpType) {
this.guestIpType = guestIpType;
}
public void setTrafficType(TrafficType trafficType) {
this.trafficType = trafficType;
}
@ -311,10 +293,9 @@ public class NetworkOfferingVO implements NetworkOffering {
this.dhcpService = dhcpService;
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, GuestIpType type, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault, Availability availability, boolean lbService, boolean gatewayService, boolean dhcpService, boolean firewallService, boolean dnsService, boolean userDataService, boolean vpnService) {
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault, Availability availability, boolean lbService, boolean gatewayService, boolean dhcpService, boolean firewallService, boolean dnsService, boolean userDataService, boolean vpnService) {
this.name = name;
this.displayText = displayText;
this.guestIpType = type;
this.rateMbps = rateMbps;
this.multicastRateMbps = multicastRateMbps;
this.concurrentConnections = concurrentConnections;
@ -333,7 +314,7 @@ public class NetworkOfferingVO implements NetworkOffering {
}
public NetworkOfferingVO(ServiceOfferingVO offering) {
this("Network Offering for " + offering.getName(), "Network Offering for " + offering.getDisplayText(), TrafficType.Guest, offering.getGuestIpType(), false, false, offering.getRateMbps(), offering.getMulticastRateMbps(), null, false, Availability.Required, false, false, false, false, false, false, false);
this("Network Offering for " + offering.getName(), "Network Offering for " + offering.getDisplayText(), TrafficType.Guest, false, false, offering.getRateMbps(), offering.getMulticastRateMbps(), null, false, Availability.Required, false, false, false, false, false, false, false);
this.serviceOfferingId = offering.getId();
}
@ -345,12 +326,12 @@ public class NetworkOfferingVO implements NetworkOffering {
* @param type
*/
public NetworkOfferingVO(String name, TrafficType trafficType, GuestIpType type) {
this(name, "System Offering for " + name, trafficType, type, true, false, null, null, null, false, Availability.Required, false, false, false, false, false, false, false);
this(name, "System Offering for " + name, trafficType, true, false, null, null, null, false, Availability.Required, false, false, false, false, false, false, false);
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder("[Network Offering [");
return buf.append(id).append("-").append(trafficType).append("-").append(name).append("-").append(guestIpType).append("]").toString();
return buf.append(id).append("-").append(trafficType).append("-").append(name).append("]").toString();
}
}

View File

@ -5,9 +5,7 @@ package com.cloud.offerings.dao;
import java.util.List;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.utils.db.GenericDao;
/**
@ -33,11 +31,8 @@ public interface NetworkOfferingDao extends GenericDao<NetworkOfferingVO, Long>
*/
NetworkOfferingVO persistDefaultNetworkOffering(NetworkOfferingVO offering);
NetworkOfferingVO findByServiceOffering(ServiceOfferingVO offering);
List<NetworkOfferingVO> listNonSystemNetworkOfferings();
List<NetworkOfferingVO> listSystemNetworkOfferings();
List<NetworkOfferingVO> findByType(GuestIpType type);
}

View File

@ -11,14 +11,11 @@ import javax.persistence.EntityExistsException;
import org.apache.log4j.Logger;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.exception.CloudRuntimeException;
@Local(value=NetworkOfferingDao.class) @DB(txn=false)
public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Long> implements NetworkOfferingDao {
@ -26,9 +23,7 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
private final static Logger s_logger = Logger.getLogger(NetworkOfferingDaoImpl.class);
final SearchBuilder<NetworkOfferingVO> NameSearch;
final SearchBuilder<NetworkOfferingVO> ServiceOfferingSearch;
final SearchBuilder<NetworkOfferingVO> SystemOfferingSearch;
final SearchBuilder<NetworkOfferingVO> TypeSearch;
protected NetworkOfferingDaoImpl() {
super();
@ -37,14 +32,6 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
NameSearch.done();
TypeSearch = createSearchBuilder();
TypeSearch.and("guestIpType", TypeSearch.entity().getGuestIpType(), SearchCriteria.Op.EQ);
TypeSearch.done();
ServiceOfferingSearch = createSearchBuilder();
ServiceOfferingSearch.and("serviceoffering", ServiceOfferingSearch.entity().getGuestIpType(), SearchCriteria.Op.EQ);
ServiceOfferingSearch.done();
SystemOfferingSearch = createSearchBuilder();
SystemOfferingSearch.and("system", SystemOfferingSearch.entity().isSystemOnly(), SearchCriteria.Op.EQ);
SystemOfferingSearch.done();
@ -76,30 +63,6 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
}
}
@Override
public NetworkOfferingVO findByServiceOffering(ServiceOfferingVO offering) {
SearchCriteria<NetworkOfferingVO> sc = ServiceOfferingSearch.create();
sc.setParameters("serviceoffering", offering.getGuestIpType());
NetworkOfferingVO vo = findOneBy(sc);
if (vo != null) {
return vo;
}
vo = new NetworkOfferingVO(offering);
try {
return persist(vo);
} catch (Exception e) {
s_logger.debug("Got a persistence exception. Assuming it's because service offering id is duplicate");
vo = findOneBy(sc);
if (vo != null) {
return vo;
}
throw new CloudRuntimeException("Unable to persist network offering", e);
}
}
@Override
public List<NetworkOfferingVO> listNonSystemNetworkOfferings() {
SearchCriteria<NetworkOfferingVO> sc = SystemOfferingSearch.create();
@ -107,13 +70,6 @@ public class NetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Lo
return this.listIncludingRemovedBy(sc, null);
}
@Override
public List<NetworkOfferingVO> findByType(GuestIpType type) {
SearchCriteria<NetworkOfferingVO> sc = TypeSearch.create();
sc.setParameters("guestIpType", type);
return listBy(sc);
}
@Override
public List<NetworkOfferingVO> listSystemNetworkOfferings() {
SearchCriteria<NetworkOfferingVO> sc = SystemOfferingSearch.create();

View File

@ -47,7 +47,6 @@ import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.dc.VlanVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
@ -59,13 +58,12 @@ import com.cloud.exception.InvalidParameterValueException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network.State;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.Availability;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.dao.NetworkDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.NetworkOffering.GuestIpType;
import com.cloud.offering.NetworkOffering.Availability;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.service.ServiceOfferingVO;
@ -694,20 +692,21 @@ public class ConfigurationServerImpl implements ConfigurationServer {
Integer rateMbps = getIntegerConfigValue(Config.NetworkThrottlingRate.key(), null);
Integer multicastRateMbps = getIntegerConfigValue(Config.MulticastThrottlingRate.key(), null);
NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmPublicNetwork, TrafficType.Public, null);
NetworkOfferingVO publicNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemPublicNetwork, TrafficType.Public, null);
publicNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(publicNetworkOffering);
NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmManagementNetwork, TrafficType.Management, null);
NetworkOfferingVO managementNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemManagementNetwork, TrafficType.Management, null);
managementNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(managementNetworkOffering);
NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmControlNetwork, TrafficType.Control, null);
NetworkOfferingVO controlNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemControlNetwork, TrafficType.Control, null);
controlNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(controlNetworkOffering);
NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemVmStorageNetwork, TrafficType.Storage, null);
NetworkOfferingVO storageNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SystemStorageNetwork, TrafficType.Storage, null);
storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering);
NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, GuestIpType.Virtual, false, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
NetworkOfferingVO guestNetworkOffering = new NetworkOfferingVO(NetworkOfferingVO.SysteGuestNetwork, TrafficType.Guest, null);
guestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(guestNetworkOffering);
NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, false, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering);
NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Public, GuestIpType.Direct, false, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Public, false, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering);
NetworkOfferingVO defaultGuestDirectPodBasedNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectPodBasedNetworkOffering, "DirectPodBased", TrafficType.Public, GuestIpType.DirectPodBased, true, false, rateMbps, multicastRateMbps, null, true, Availability.Required, false, false, false, false, false, false, false);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectPodBasedNetworkOffering);
}
private Integer getIntegerConfigValue(String configKey, Integer dflt) {
@ -727,6 +726,8 @@ public class ConfigurationServerImpl implements ConfigurationServer {
guruNames.put(TrafficType.Management, "PodBasedNetworkGuru-com.cloud.network.guru.PodBasedNetworkGuru");
guruNames.put(TrafficType.Control, "ControlNetworkGuru-com.cloud.network.guru.ControlNetworkGuru");
guruNames.put(TrafficType.Storage, "PodBasedNetworkGuru-com.cloud.network.guru.PodBasedNetworkGuru");
guruNames.put(TrafficType.Guest, "DirectPodBasedNetworkGuru-com.cloud.network.guru.DirectPodBasedNetworkGuru");
for (DataCenterVO zone : zones) {
long zoneId = zone.getId();
@ -747,24 +748,27 @@ public class ConfigurationServerImpl implements ConfigurationServer {
BroadcastDomainType broadcastDomainType = null;
TrafficType trafficType= offering.getTrafficType();
GuestIpType guestIpType = offering.getGuestIpType();
if (trafficType == TrafficType.Management || trafficType == TrafficType.Storage) {
broadcastDomainType = BroadcastDomainType.Native;
} else if (trafficType == TrafficType.Control) {
broadcastDomainType = BroadcastDomainType.LinkLocal;
} else if (offering.getTrafficType() == TrafficType.Public) {
if (zone.getNetworkType() == NetworkType.Basic && offering.getGuestIpType() == GuestIpType.DirectPodBased) {
broadcastDomainType = BroadcastDomainType.Native;
} else if (zone.getNetworkType() == NetworkType.Advanced && offering.getGuestIpType() == null) {
} else if (offering.getTrafficType() == TrafficType.Public) {
if (zone.getNetworkType() == NetworkType.Advanced) {
broadcastDomainType = BroadcastDomainType.Vlan;
} else {
continue;
}
}
} else if (offering.getTrafficType() == TrafficType.Guest) {
if (zone.getNetworkType() == NetworkType.Basic) {
broadcastDomainType = BroadcastDomainType.Native;
} else {
continue;
}
}
if (broadcastDomainType != null) {
NetworkVO network = new NetworkVO(id, trafficType, guestIpType, mode, broadcastDomainType, networkOfferingId, zoneId, domainId, accountId, related, null, null, true);
NetworkVO network = new NetworkVO(id, trafficType, null, mode, broadcastDomainType, networkOfferingId, zoneId, domainId, accountId, related, null, null, true);
network.setGuruName(guruNames.get(network.getTrafficType()));
network.setDns1(zone.getDns1());
network.setDns2(zone.getDns2());
@ -781,33 +785,35 @@ public class ConfigurationServerImpl implements ConfigurationServer {
private void updateVlanWithNetworkId(VlanVO vlan) {
long zoneId = vlan.getDataCenterId();
long networkId = 0L;
if (vlan.getVlanType() == VlanType.VirtualNetwork) {
networkId = getSystemNetworkIdByZoneAndTrafficTypeAndGuestType(zoneId, TrafficType.Public, null);
} else if (vlan.getVlanType() == VlanType.DirectAttached) {
networkId = getSystemNetworkIdByZoneAndTrafficTypeAndGuestType(zoneId, TrafficType.Public, GuestIpType.DirectPodBased);
DataCenterVO zone = _zoneDao.findById(zoneId);
if (zone.getNetworkType() == NetworkType.Advanced) {
networkId = getSystemNetworkIdByZoneAndTrafficType(zoneId, TrafficType.Public);
} else {
networkId = getSystemNetworkIdByZoneAndTrafficType(zoneId, TrafficType.Guest);
}
vlan.setNetworkId(networkId);
_vlanDao.update(vlan.getId(), vlan);
}
private long getSystemNetworkIdByZoneAndTrafficTypeAndGuestType(long zoneId, TrafficType trafficType, GuestIpType guestType) {
private long getSystemNetworkIdByZoneAndTrafficType(long zoneId, TrafficType trafficType) {
//find system public network offering
Long networkOfferingId = null;
List<NetworkOfferingVO> offerings = _networkOfferingDao.listSystemNetworkOfferings();
for (NetworkOfferingVO offering: offerings) {
if (offering.getTrafficType() == trafficType && offering.getGuestIpType() == guestType) {
if (offering.getTrafficType() == trafficType) {
networkOfferingId = offering.getId();
break;
}
}
if (networkOfferingId == null) {
throw new InvalidParameterValueException("Unable to find system network offering with traffic type " + trafficType + " and guestIpType " + guestType);
throw new InvalidParameterValueException("Unable to find system network offering with traffic type " + trafficType);
}
List<NetworkVO> networks = _networkDao.listBy(Account.ACCOUNT_ID_SYSTEM, networkOfferingId, zoneId);
if (networks == null) {
if (networks == null || networks.isEmpty()) {
throw new InvalidParameterValueException("Unable to find network with traffic type " + trafficType + " in zone " + zoneId);
}
return networks.get(0).getId();

View File

@ -56,6 +56,8 @@ import com.cloud.async.BaseAsyncJobExecutor;
import com.cloud.cluster.ClusterManager;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.dao.DataCenterDao;
@ -440,9 +442,14 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
Account systemAcct = _accountMgr.getSystemAccount();
DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
List<NetworkOfferingVO> defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmPublicNetwork);
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork, NetworkOfferingVO.SystemVmManagementNetwork);
List<NetworkOfferingVO> defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemPublicNetwork);
if (dc.getNetworkType() == NetworkType.Basic) {
defaultOffering = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SysteGuestNetwork);
}
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemControlNetwork, NetworkOfferingVO.SystemManagementNetwork);
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(offerings.size() + 1);
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
@ -1504,10 +1511,11 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
cmds.addCommand("checkSsh", check);
SecondaryStorageVmVO secVm = profile.getVirtualMachine();
List<NicVO> nics = _nicDao.listBy(secVm.getId());
DataCenter dc = dest.getDataCenter();
List<NicVO> nics = _nicDao.listBy(secVm.getId());
for (NicVO nic : nics) {
NetworkVO network = _networkDao.findById(nic.getNetworkId());
if (network.getTrafficType() == TrafficType.Public) {
if ((network.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (network.getTrafficType() == TrafficType.Guest && dc.getNetworkType() == NetworkType.Basic)) {
secVm.setPublicIpAddress(nic.getIp4Address());
secVm.setPublicNetmask(nic.getNetmask());
secVm.setPublicMacAddress(nic.getMacAddress());

View File

@ -98,8 +98,6 @@ public interface AccountManager extends AccountService {
List<ResourceLimitVO> searchForLimits(Criteria c);
/**
* Disables an account by accountId
* @param accountId

View File

@ -74,7 +74,6 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.IPAddressVO;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.VirtualNetworkApplianceService;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.router.VirtualNetworkApplianceManager;
@ -674,7 +673,8 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
return _systemAccount;
}
public static boolean isAdmin(short accountType) {
@Override
public boolean isAdmin(short accountType) {
return ((accountType == Account.ACCOUNT_TYPE_ADMIN) ||
(accountType == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) ||
(accountType == Account.ACCOUNT_TYPE_READ_ONLY_ADMIN));
@ -1576,4 +1576,49 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
}
}
}
public Account finalizeOwner(Account caller, String accountName, Long domainId) {
if (isAdmin(caller.getType())) {
if (domainId != null) {
DomainVO domain = _domainDao.findById(domainId);
if (domain == null) {
throw new InvalidParameterValueException("Unable to find the domain by id=" + domainId);
}
if (accountName != null) {
Account owner = _accountDao.findActiveAccount(accountName, domainId);
if (owner == null) {
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
}
checkAccess(caller, domain);
return owner;
} else {
throw new InvalidParameterValueException("Account have to be specified along with domainId");
}
} else {
return caller;
}
} else {
//regular user can't create resources for other people
return caller;
}
}
@Override
public Account getActiveAccount(String accountName, Long domainId) {
if (accountName == null || domainId == null) {
throw new InvalidParameterValueException("Both accountName and domainId are required for finding active account in the system");
} else {
return _accountDao.findActiveAccount(accountName, domainId);
}
}
@Override
public Account getAccount(Long accountId) {
if (accountId == null) {
throw new InvalidParameterValueException("AccountId is required by account search");
} else {
return _accountDao.findById(accountId);
}
}
}

View File

@ -2239,9 +2239,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
s_logger.debug("Allocating in the DB for vm");
if (dc.getNetworkType() == NetworkType.Basic && networkList == null) {
Network defaultNetwork = _networkMgr.getBasicZoneDefaultPublicNetwork(dc.getId());
Network defaultNetwork = _networkMgr.getSystemNetworkByZoneAndTrafficType(dc.getId(), TrafficType.Guest);
if (defaultNetwork == null) {
throw new InvalidParameterValueException("Unable to find a default directPodBased network to start a vm");
throw new InvalidParameterValueException("Unable to find a default Direct network to start a vm");
} else {
networkList = new ArrayList<Long>();
networkList.add(defaultNetwork.getId());

View File

@ -122,4 +122,6 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long>, State
DomainRouterVO findByNetworkConfiguration(long networkConfigurationId);
DomainRouterVO findByNetworkConfigurationIncludingRemoved(long networkConfigurationId);
DomainRouterVO findByNetworkConfigurationAndPod(long networkConfigurationId, long podId);
}

View File

@ -126,6 +126,8 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
NetworkConfigSearch = createSearchBuilder();
NetworkConfigSearch.and("network", NetworkConfigSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
NetworkConfigSearch.and("podId", NetworkConfigSearch.entity().getPodId(), SearchCriteria.Op.EQ);
NetworkConfigSearch.done();
_updateTimeAttr = _allAttributes.get("updateTime");
assert _updateTimeAttr != null : "Couldn't get this updateTime attribute";
@ -366,4 +368,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
sc.setParameters("state", State.Stopped);
return listBy(sc);
}
@Override
public DomainRouterVO findByNetworkConfigurationAndPod(long networkConfigurationId, long podId) {
SearchCriteria<DomainRouterVO> sc = NetworkConfigSearch.create();
sc.setParameters("network", networkConfigurationId);
sc.setParameters("podId", podId);
return findOneBy(sc);
}
}

View File

@ -200,7 +200,6 @@ CREATE TABLE `cloud`.`nics` (
CREATE TABLE `cloud`.`network_offerings` (
`id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id',
`name` varchar(64) NOT NULL unique COMMENT 'network offering',
`type` varchar(32) COMMENT 'type of network',
`display_text` varchar(255) NOT NULL COMMENT 'text to display to users',
`nw_rate` smallint unsigned COMMENT 'network rate throttle mbits/s',
`mc_rate` smallint unsigned COMMENT 'mcast rate throttle mbits/s',

View File

@ -691,6 +691,12 @@ public class NetUtils {
return long2Ip(numericNetmask);
}
public static String getCidrNetmask(String cidr) {
String[] cidrPair = cidr.split("\\/");
long guestCidrSize = Long.parseLong(cidrPair[1]);
return getCidrNetmask(guestCidrSize);
}
public static String cidr2Netmask(String cidr) {
String[] tokens = cidr.split("\\/");
return getCidrNetmask(Integer.parseInt(tokens[1]));
@ -879,6 +885,12 @@ public class NetUtils {
return result;
}
public static String getDhcpRange(String cidr) {
String[] splitResult = cidr.split("\\/");
long size = Long.valueOf(splitResult[1]);
return NetUtils.getIpRangeStartIpFromCidr(splitResult[0], size);
}
}