1) isShared attribute belongs to Network now, not NetworkOffering

2) Added list by networkId support to listVirtualMachines command.
3) Implemented search by zoneId in listNetworks command
This commit is contained in:
alena 2010-12-03 18:38:50 -08:00
parent 280884f6d7
commit 150d684e05
28 changed files with 181 additions and 97 deletions

View File

@ -170,6 +170,7 @@ public class ApiConstants {
public static final String MAX_CONNECTIONS = "maxconnections";
public static final String NETWORK_OFFERING_ID = "networkofferingid";
public static final String NETWORK_IDS = "networkids";
public static final String NETWORK_ID = "networkid";
public static final String SPECIFY_VLAN = "specifyvlan";
public static final String IS_DEFAULT = "isdefault";
}

View File

@ -27,6 +27,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.StoragePoolResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.storage.StoragePool;
import com.cloud.user.Account;
@ -67,6 +68,14 @@ public class CancelPrimaryStorageMaintenanceCmd extends BaseAsyncCmd {
public static String getResultObjectName() {
return "primarystorage";
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
}
public Long getInstanceId() {
return getId();
}
@Override
public long getEntityOwnerId() {

View File

@ -76,6 +76,9 @@ public class CreateNetworkCmd extends BaseCmd {
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a VLAN")
private Long domainId;
@Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network offering supports vlans")
private Boolean isShared;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -131,6 +134,10 @@ public class CreateNetworkCmd extends BaseCmd {
public String getDisplayText() {
return displayText;
}
public Boolean getIsShared() {
return isShared;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -57,9 +57,6 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
@Parameter(name=ApiConstants.SPECIFY_VLAN, type=CommandType.BOOLEAN, description="true is network offering supports vlans")
private Boolean specifyVlan;
@Parameter(name=ApiConstants.IS_SHARED, type=CommandType.BOOLEAN, description="true is network offering supports vlans")
private Boolean isShared;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -92,10 +89,6 @@ public class CreateNetworkOfferingCmd extends BaseCmd {
public Boolean getSpecifyVlan() {
return specifyVlan;
}
public Boolean getIsShared() {
return isShared;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -31,13 +31,15 @@ import com.cloud.api.ServerApiException;
import com.cloud.api.response.UserVmResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.exception.InsufficientStorageCapacityException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.StorageUnavailableException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.user.UserContext;
import com.cloud.uservm.UserVm;
import com.cloud.utils.exception.ExecutionException;
@Implementation(description="Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.", responseObject=UserVmResponse.class)
public class DeployVMCmd extends BaseAsyncCmd {
@ -227,17 +229,20 @@ public class DeployVMCmd extends BaseAsyncCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to deploy vm");
}
} catch (ResourceAllocationException ex) {
s_logger.warn("Exception: ", ex);
s_logger.info(ex);
throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, ex.getMessage());
} catch (InsufficientStorageCapacityException ex) {
s_logger.warn("Exception: ", ex);
} catch (InsufficientCapacityException ex) {
s_logger.info(ex);
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
} catch (StorageUnavailableException ex) {
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
} catch (Exception ex) {
} catch (ExecutionException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
} catch (ConcurrentOperationException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
}
}

View File

@ -27,6 +27,7 @@ import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListCmd;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.NetworkResponse;
import com.cloud.network.Network;
@ -48,6 +49,9 @@ public class ListNetworksCmd extends BaseListCmd {
@Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a VLAN")
private Long domainId;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="the Zone ID of the network")
private Long zoneId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -64,6 +68,11 @@ public class ListNetworksCmd extends BaseListCmd {
public Long getDomainId() {
return domainId;
}
public Long getZoneId() {
return zoneId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

View File

@ -29,6 +29,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.ListResponse;
import com.cloud.api.response.StoragePoolResponse;
import com.cloud.async.AsyncJob;
import com.cloud.storage.StoragePool;
@Implementation(description="Lists storage pools.", responseObject=StoragePoolResponse.class)
@ -94,6 +95,10 @@ public class ListStoragePoolsCmd extends BaseListCmd {
@Override
public String getName() {
return s_name;
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
}
@Override

View File

@ -70,6 +70,9 @@ public class ListVMsCmd extends BaseListCmd {
@Parameter(name=ApiConstants.FOR_VIRTUAL_NETWORK, type=CommandType.BOOLEAN, description="list by network type; true if need to list vms using Virtual Network, false otherwise")
private Boolean forVirtualNetwork;
@Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="list by network id")
private Long networkId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
@ -118,6 +121,10 @@ public class ListVMsCmd extends BaseListCmd {
public void setForVirtualNetwork(Boolean forVirtualNetwork) {
this.forVirtualNetwork = forVirtualNetwork;
}
public Long getNetworkId() {
return networkId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -26,6 +26,7 @@ import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.response.StoragePoolResponse;
import com.cloud.async.AsyncJob;
import com.cloud.event.EventTypes;
import com.cloud.storage.StoragePool;
import com.cloud.user.Account;
@ -63,6 +64,14 @@ public class PreparePrimaryStorageForMaintenanceCmd extends BaseAsyncCmd {
public static String getResultObjectName() {
return "primarystorage";
}
public AsyncJob.Type getInstanceType() {
return AsyncJob.Type.Host;
}
public Long getInstanceId() {
return getId();
}
@Override
public long getEntityOwnerId() {

View File

@ -32,10 +32,7 @@ public class NetworkOfferingResponse extends BaseResponse{
@SerializedName("isdefault") @Param(description="true if network offering is default, false otherwise")
private Boolean isDefault;
@SerializedName("isshared") @Param(description="true if network offering is shared, false otherwise")
private Boolean isShared;
@SerializedName("specifyvlan") @Param(description="true if network offering supports vlans, false otherwise")
private Boolean specifyVlan;
@ -126,12 +123,4 @@ public class NetworkOfferingResponse extends BaseResponse{
public void setSpecifyVlan(Boolean specifyVlan) {
this.specifyVlan = specifyVlan;
}
public Boolean getIsShared() {
return isShared;
}
public void setIsShared(Boolean isShared) {
this.isShared = isShared;
}
}

View File

@ -110,4 +110,6 @@ public interface Network extends ControlledEntity {
GuestIpType getGuestType();
String getDisplayText();
boolean isShared();
}

View File

@ -73,7 +73,5 @@ public interface NetworkOffering {
String getTags();
boolean isShared();
boolean isDefault();
}

View File

@ -2305,7 +2305,6 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setMaxconnections(offering.getConcurrentConnections());
response.setIsDefault(offering.isDefault());
response.setSpecifyVlan(offering.getSpecifyVlan());
response.setIsShared(offering.isShared());
response.setObjectName("networkoffering");
return response;
}
@ -2340,8 +2339,9 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setNetworkOfferingId(networkOffering.getId());
response.setNetworkOfferingName(networkOffering.getName());
response.setNetworkOfferingDisplayText(networkOffering.getDisplayText());
response.setIsShared(networkOffering.isShared());
}
response.setIsShared(network.isShared());
response.setState(network.getState().toString());
response.setRelated(network.getRelated());
response.setDns1(network.getDns1());

View File

@ -170,17 +170,17 @@ public interface ConfigurationManager extends Manager {
/**
* Creates a new network offering
* @param id
* @param name
* @param displayText
* @param type
* @param trafficType
* @param tags
* @param maxConnections
* @param name
* @param displayText
* @param type
* @param trafficType
* @param tags
* @param maxConnections
* @param id
* @param specifyVlan;
* @return network offering object
*/
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, boolean isShared);
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan);
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;

View File

@ -2391,7 +2391,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
String typeString = cmd.getType();
String trafficTypeString = cmd.getTraffictype();
Boolean specifyVlan = cmd.getSpecifyVlan();
Boolean isShared = cmd.getIsShared();
TrafficType trafficType = null;
GuestIpType type = null;
@ -2418,23 +2417,19 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (specifyVlan == null) {
specifyVlan = false;
}
if (isShared == null) {
isShared = false;
}
Integer maxConnections = cmd.getMaxconnections();
return createNetworkOffering(userId, name, displayText, type, trafficType, tags, maxConnections, specifyVlan, isShared);
return createNetworkOffering(userId, name, displayText, type, trafficType, tags, maxConnections, specifyVlan);
}
@Override
public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, boolean isShared) {
public NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, GuestIpType type, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan) {
String networkRateStr = _configDao.getValue("network.throttling.rate");
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
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, isShared, false);
NetworkOfferingVO offering = new NetworkOfferingVO(name, displayText, trafficType, type, false, specifyVlan, networkRate, multicastRate, maxConnections, 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

@ -1071,9 +1071,9 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
defaultNic.setDeviceId(2);
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null).get(0), defaultNic));
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null, false).get(0), defaultNic));
for (NetworkOfferingVO offering : offerings) {
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null).get(0), null));
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null, false).get(0), null));
}
ConsoleProxyVO proxy = new ConsoleProxyVO(id, _serviceOffering.getId(), name, _template.getId(), _template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), 0);
try {

View File

@ -198,8 +198,8 @@ public interface NetworkManager extends NetworkService {
*/
List<IPAddressVO> listPublicIpAddressesInVirtualNetwork(long accountId, long dcId, Boolean sourceNat);
List<NetworkVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText);
List<NetworkVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText);
List<NetworkVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isShared);
List<NetworkVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isShared);
List<NetworkOfferingVO> getSystemAccountNetworkOfferings(String... offeringNames);

View File

@ -71,7 +71,6 @@ 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.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.EventTypes;
import com.cloud.event.EventUtils;
@ -1003,9 +1002,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
storageNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(storageNetworkOffering);
_systemNetworks.put(NetworkOfferingVO.SystemVmStorageNetwork, storageNetworkOffering);
NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, GuestIpType.Virtualized, false, false, rateMbps, multicastRateMbps, null, false, true);
NetworkOfferingVO defaultGuestNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultVirtualizedNetworkOffering, "Virtual Vlan", TrafficType.Guest, GuestIpType.Virtualized, false, false, rateMbps, multicastRateMbps, null, true);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestNetworkOffering);
NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, GuestIpType.DirectSingle, false, false, rateMbps, multicastRateMbps, null, false, true);
NetworkOfferingVO defaultGuestDirectNetworkOffering = new NetworkOfferingVO(NetworkOffering.DefaultDirectNetworkOffering, "Direct", TrafficType.Guest, GuestIpType.DirectSingle, false, false, rateMbps, multicastRateMbps, null, true);
defaultGuestNetworkOffering = _networkOfferingDao.persistDefaultNetworkOffering(defaultGuestDirectNetworkOffering);
AccountsUsingNetworkConfigurationSearch = _accountDao.createSearchBuilder();
@ -1085,12 +1084,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public List<NetworkVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText) {
return setupNetworkConfiguration(owner, offering, null, plan, name, displayText);
public List<NetworkVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isShared) {
return setupNetworkConfiguration(owner, offering, null, plan, name, displayText, isShared);
}
@Override
public List<NetworkVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText) {
public List<NetworkVO> setupNetworkConfiguration(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean isShared) {
List<NetworkVO> configs = _networkConfigDao.listBy(owner.getId(), offering.getId(), plan.getDataCenterId());
if (configs.size() > 0) {
if (s_logger.isDebugEnabled()) {
@ -1123,7 +1122,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
related = id;
}
NetworkVO vo = new NetworkVO(id, config, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText);
NetworkVO vo = new NetworkVO(id, config, offering.getId(), plan.getDataCenterId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, isShared);
configs.add(_networkConfigDao.persist(vo));
}
@ -1532,7 +1531,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
public List<NetworkVO> setupNetworkConfiguration(Account owner, ServiceOfferingVO offering, DeploymentPlan plan) {
NetworkOfferingVO networkOffering = _networkOfferingDao.findByServiceOffering(offering);
return setupNetworkConfiguration(owner, networkOffering, plan, null, null);
return setupNetworkConfiguration(owner, networkOffering, plan, null, null, false);
}
private String [] getGuestIpRange() {
@ -1895,6 +1894,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
String vlanId = cmd.getVlan();
String name = cmd.getNetworkName();
String displayText = cmd.getDisplayText();
Boolean isShared = cmd.getIsShared();
Account owner = null;
//Check if network offering exists
@ -1926,10 +1926,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
} else {
owner = ctxAccount;
}
if (owner.getId() == Account.ACCOUNT_ID_SYSTEM && !networkOffering.isShared()) {
throw new InvalidParameterValueException("Non-system account is required when create a network from Dedicated network offering with id=" + networkOfferingId);
}
//VlanId can be specified only when network offering supports it
if (vlanId != null && !networkOffering.getSpecifyVlan()) {
@ -1957,7 +1953,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
}
List<NetworkVO> networks = setupNetworkConfiguration(owner, networkOffering, userNetwork, plan, name, displayText);
List<NetworkVO> networks = setupNetworkConfiguration(owner, networkOffering, userNetwork, plan, name, displayText, isShared);
Long networkId = null;
if (networks == null || networks.isEmpty()) {
@ -1967,8 +1963,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
networkId = networks.get(0).getId();
}
//If network offering is shared, don't pass owner account and networkOfferingId for vlan
if (networkOffering.isShared()) {
//Don't pass owner to create vlan when network offering is of type Direct
if (networkOffering.getGuestIpType() == GuestIpType.DirectSingle) {
owner = null;
}
@ -1995,10 +1991,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
public List<? extends Network> searchForNetworks(ListNetworksCmd cmd) {
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Long zoneId= cmd.getZoneId();
Account account = UserContext.current().getAccount();
Long domainId = cmd.getDomainId();
String accountName = cmd.getAccountName();
Long accountId = null;
if (isAdmin(account.getType())) {
if (domainId != null) {
if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(), domainId)) {
@ -2041,6 +2039,10 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
sc.addAnd("id", SearchCriteria.Op.EQ, id);
}
if (zoneId != null) {
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
}
SearchCriteria<NetworkVO> ssc = _networkConfigDao.createSearchCriteria();
ssc.addOr("accountId", SearchCriteria.Op.EQ, accountId);
if (accountName == null && domainId == null) {

View File

@ -115,6 +115,9 @@ public class NetworkVO implements Network {
@Column(name="dns2")
String dns2;
@Column(name="shared")
boolean isShared;
public NetworkVO() {
}
@ -137,8 +140,8 @@ public class NetworkVO implements Network {
this.guestType = guestType;
}
public NetworkVO(long id, Network that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related, String name, String displayText) {
this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related, name, displayText);
public NetworkVO(long id, Network that, long offeringId, long dataCenterId, String guruName, long domainId, long accountId, long related, String name, String displayText, Boolean isShared) {
this(id, that.getTrafficType(), that.getGuestType(), that.getMode(), that.getBroadcastDomainType(), offeringId, dataCenterId, domainId, accountId, related, name, displayText, isShared);
this.gateway = that.getGateway();
this.dns1 = that.getDns1();
this.dns2 = that.getDns2();
@ -162,8 +165,9 @@ public class NetworkVO implements Network {
* @param accountId
* @param name
* @param displayText
* @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) {
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.domainId = domainId;
this.accountId = accountId;
@ -171,6 +175,7 @@ public class NetworkVO implements Network {
this.id = id;
this.name = name;
this.displayText = displayText;
this.isShared = isShared;
}
@Override
@ -327,6 +332,15 @@ public class NetworkVO implements Network {
public void setDisplayText(String displayText) {
this.displayText = displayText;
}
@Override
public boolean isShared() {
return isShared;
}
public void setShared(boolean isShared) {
this.isShared = isShared;
}
@Override
public boolean equals(Object obj) {
@ -359,4 +373,6 @@ public class NetworkVO implements Network {
buf.append(id).append("|").append(trafficType.toString()).append("|").append(networkOfferingId).append("]");
return buf.toString();
}
}

View File

@ -28,8 +28,8 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
List<NetworkVO> listBy(long accountId);
List<NetworkVO> listBy(long accountId, long offeringId, long dataCenterId);
@Override
NetworkVO persist(NetworkVO config);
void addAccountToNetworkConfiguration(long configId, long accountId);
NetworkVO persist(NetworkVO network);
void addAccountToNetworkConfiguration(long networkId, long accountId);
SearchBuilder<NetworkAccountVO> createSearchBuilderForAccount();
List<NetworkVO> getNetworkConfigurationsForOffering(long offeringId, long dataCenterId, long accountId);
List<NetworkVO> getRelatedNetworkConfigurations(long related);
@ -40,4 +40,6 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
* @return mac address if there is one. null if not.
*/
String getNextAvailableMacAddress(long networkConfigId);
List<NetworkVO> listBy(long accountId, long networkId);
}

View File

@ -25,6 +25,7 @@ import java.util.Random;
import javax.ejb.Local;
import javax.persistence.TableGenerator;
import com.cloud.domain.DomainVO;
import com.cloud.network.NetworkAccountDaoImpl;
import com.cloud.network.NetworkAccountVO;
import com.cloud.network.NetworkVO;
@ -49,6 +50,7 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
final SearchBuilder<NetworkVO> OfferingSearch;
final SearchBuilder<NetworkVO> RelatedConfigSearch;
final SearchBuilder<NetworkVO> RelatedConfigsSearch;
final SearchBuilder<NetworkVO> AccountNetworkSearch;
NetworkAccountDaoImpl _accountsDao = new NetworkAccountDaoImpl();
final TableGenerator _tgMacAddress;
@ -90,6 +92,14 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
RelatedConfigsSearch.and("related", RelatedConfigsSearch.entity().getRelated(), SearchCriteria.Op.EQ);
RelatedConfigsSearch.done();
AccountNetworkSearch = createSearchBuilder();
AccountNetworkSearch.and("networkId", AccountNetworkSearch.entity().getId(), SearchCriteria.Op.EQ);
SearchBuilder<NetworkAccountVO> mapJoin = _accountsDao.createSearchBuilder();
mapJoin.and("accountId", mapJoin.entity().getAccountId(), SearchCriteria.Op.EQ);
AccountNetworkSearch.join("networkSearch", mapJoin, AccountNetworkSearch.entity().getId(), mapJoin.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
AccountNetworkSearch.done();
_tgMacAddress = _tgs.get("macAddress");
}
@ -178,4 +188,12 @@ public class NetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implements N
seq = seq | _prefix | ((_rand.nextInt(Short.MAX_VALUE) << 16) & 0x00000000ffff0000l);
return NetUtils.long2Mac(seq);
}
@Override
public List<NetworkVO> listBy(long accountId, long networkId) {
SearchCriteria<NetworkVO> sc = AccountNetworkSearch.create();
sc.setParameters("networkId", networkId);
sc.setJoinParameters("networkSearch", "accountId", accountId);
return listBy(sc);
}
}

View File

@ -2086,11 +2086,11 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
List<NetworkOfferingVO> offerings = _networkMgr.getSystemAccountNetworkOfferings(NetworkOfferingVO.SystemVmControlNetwork);
NetworkOfferingVO controlOffering = offerings.get(0);
NetworkVO controlConfig = _networkMgr.setupNetworkConfiguration(_systemAcct, controlOffering, plan, null, null).get(0);
NetworkVO controlConfig = _networkMgr.setupNetworkConfiguration(_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);
List<NetworkVO> publicConfigs = _networkMgr.setupNetworkConfiguration(_systemAcct, publicOffering, plan, null, null);
List<NetworkVO> publicConfigs = _networkMgr.setupNetworkConfiguration(_systemAcct, publicOffering, plan, null, null, false);
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
//defaultNic.setIp4Address(sourceNatIp);

View File

@ -80,10 +80,7 @@ public class NetworkOfferingVO implements NetworkOffering {
@Column(name="tags")
String tags;
@Column(name="shared")
boolean isShared;
@Column(name="default")
boolean isDefault;
@ -201,15 +198,6 @@ public class NetworkOfferingVO implements NetworkOffering {
this.serviceOfferingId = serviceOfferingId;
}
@Override
public boolean isShared() {
return isShared;
}
public void setShared(boolean isShared) {
this.isShared = isShared;
}
@Override
public boolean isDefault() {
return isDefault;
@ -224,7 +212,7 @@ public class NetworkOfferingVO implements NetworkOffering {
this.created = created;
}
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, GuestIpType type, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isShared, boolean isDefault) {
public NetworkOfferingVO(String name, String displayText, TrafficType trafficType, GuestIpType type, boolean systemOnly, boolean specifyVlan, Integer rateMbps, Integer multicastRateMbps, Integer concurrentConnections, boolean isDefault) {
this.name = name;
this.displayText = displayText;
this.guestIpType = type;
@ -235,11 +223,10 @@ public class NetworkOfferingVO implements NetworkOffering {
this.systemOnly = systemOnly;
this.specifyVlan = specifyVlan;
this.isDefault = isDefault;
this.isShared = isShared;
}
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, false);
this("Network Offering for " + offering.getName(), "Network Offering for " + offering.getDisplayText(), TrafficType.Guest, offering.getGuestIpType(), false, false, offering.getRateMbps(), offering.getMulticastRateMbps(), null, false);
this.serviceOfferingId = offering.getId();
}
@ -251,7 +238,7 @@ 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, false);
this(name, "System Offering for " + name, trafficType, type, true, false, null, null, null, false);
}
@Override

View File

@ -78,6 +78,7 @@ public class Criteria {
public static final String NETWORKGROUP = "networkGroup";
public static final String GROUP = "group";
public static final String EMPTY_GROUP = "emptyGroup";
public static final String NETWORKID = "networkId";
public Criteria(String orderBy, Boolean ascending, Long offset, Long limit) {
this.offset = offset;

View File

@ -190,9 +190,11 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.info.ConsoleProxyInfo;
import com.cloud.network.IPAddressVO;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.RemoteAccessVpnVO;
import com.cloud.network.VpnUserVO;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.RemoteAccessVpnDao;
import com.cloud.network.dao.VpnUserDao;
import com.cloud.network.security.NetworkGroupManager;
@ -274,6 +276,7 @@ import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.InstanceGroupVMMapVO;
import com.cloud.vm.InstanceGroupVO;
import com.cloud.vm.NicVO;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.State;
import com.cloud.vm.UserVmManager;
@ -285,6 +288,7 @@ import com.cloud.vm.dao.ConsoleProxyDao;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.InstanceGroupDao;
import com.cloud.vm.dao.InstanceGroupVMMapDao;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.SecondaryStorageVmDao;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
@ -331,6 +335,8 @@ public class ManagementServerImpl implements ManagementServer {
private final StoragePoolHostDao _poolHostDao;
private final StorageManager _storageMgr;
private final UserVmDao _vmDao;
private final NetworkDao _networkDao;
private final NicDao _nicDao;
private final Adapters<UserAuthenticator> _userAuthenticators;
private final HostPodDao _hostPodDao;
@ -353,6 +359,7 @@ public class ManagementServerImpl implements ManagementServer {
private final RemoteAccessVpnDao _remoteAccessVpnDao;
private final VpnUserDao _vpnUsersDao;
@Inject private UserVmService _userVmService;
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AccountChecker"));
private final ScheduledExecutorService _eventExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("EventChecker"));
@ -391,6 +398,8 @@ public class ManagementServerImpl implements ManagementServer {
_hostPodDao = locator.getDao(HostPodDao.class);
_jobDao = locator.getDao(AsyncJobDao.class);
_clusterDao = locator.getDao(ClusterDao.class);
_networkDao = locator.getDao(NetworkDao.class);
_nicDao = locator.getDao(NicDao.class);
_accountMgr = locator.getManager(AccountManager.class);
_agentMgr = locator.getManager(AgentManager.class);
@ -436,7 +445,7 @@ public class ManagementServerImpl implements ManagementServer {
_asyncMgr = locator.getManager(AsyncJobManager.class);
_tmpltMgr = locator.getManager(TemplateManager.class);
_networkGroupMgr = locator.getManager(NetworkGroupManager.class);
_uploadMonitor = locator.getManager(UploadMonitor.class);
_uploadMonitor = locator.getManager(UploadMonitor.class);
_userAuthenticators = locator.getAdapters(UserAuthenticator.class);
if (_userAuthenticators == null || !_userAuthenticators.isSet()) {
@ -2589,6 +2598,7 @@ public class ManagementServerImpl implements ManagementServer {
c.addCriteria(Criteria.DATACENTERID, cmd.getZoneId());
c.addCriteria(Criteria.GROUPID, cmd.getGroupId());
c.addCriteria(Criteria.FOR_VIRTUAL_NETWORK, cmd.getForVirtualNetwork());
c.addCriteria(Criteria.NETWORKID, cmd.getNetworkId());
if (path != null) {
c.addCriteria(Criteria.PATH, path);
@ -2634,6 +2644,7 @@ public class ManagementServerImpl implements ManagementServer {
Object groupId = c.getCriteria(Criteria.GROUPID);
Object useVirtualNetwork = c.getCriteria(Criteria.FOR_VIRTUAL_NETWORK);
Object path = c.getCriteria(Criteria.PATH);
Object networkId = c.getCriteria(Criteria.NETWORKID);
sb.and("displayName", sb.entity().getDisplayName(), SearchCriteria.Op.LIKE);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
@ -2667,6 +2678,17 @@ public class ManagementServerImpl implements ManagementServer {
sb.join("groupSearch", groupSearch, sb.entity().getId(), groupSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
}
if (networkId != null) {
SearchBuilder<NicVO> nicSearch = _nicDao.createSearchBuilder();
nicSearch.and("networkId", nicSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
SearchBuilder<NetworkVO> networkSearch = _networkDao.createSearchBuilder();
networkSearch.and("networkId", networkSearch.entity().getId(), SearchCriteria.Op.EQ);
nicSearch.join("networkSearch", networkSearch, nicSearch.entity().getNetworkId(), networkSearch.entity().getId(), JoinBuilder.JoinType.INNER);
sb.join("nicSearch", nicSearch, sb.entity().getId(), nicSearch.entity().getInstanceId(), JoinBuilder.JoinType.INNER);
}
if (useVirtualNetwork != null) {
SearchBuilder<ServiceOfferingVO> serviceSearch = _offeringsDao.createSearchBuilder();
if ((Boolean)useVirtualNetwork){
@ -2718,6 +2740,10 @@ public class ManagementServerImpl implements ManagementServer {
if (path != null) {
sc.setJoinParameters("domainSearch", "path", path + "%");
}
if (networkId != null) {
sc.setJoinParameters("nicSearch", "networkId", networkId);
}
if (name != null) {
sc.setParameters("name", "%" + name + "%");

View File

@ -741,9 +741,9 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
NicProfile defaultNic = new NicProfile();
defaultNic.setDefaultNic(true);
defaultNic.setDeviceId(2);
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null).get(0), defaultNic));
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, defaultOffering.get(0), plan, null, null, false).get(0), defaultNic));
for (NetworkOfferingVO offering : offerings) {
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null).get(0), null));
networks.add(new Pair<NetworkVO, NicProfile>(_networkMgr.setupNetworkConfiguration(systemAcct, offering, plan, null, null, false).get(0), null));
}
SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, _serviceOffering.getId(), name, _template.getId(),
_template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId());

View File

@ -143,7 +143,6 @@ import com.cloud.network.security.NetworkGroupManager;
import com.cloud.network.security.NetworkGroupVO;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.offerings.NetworkOfferingVO;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
@ -3701,8 +3700,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, VirtualM
if (network == null) {
throw new InvalidParameterValueException("Unable to find network by id " + networkId);
} else {
if (network.getAccountId() != Account.ACCOUNT_ID_SYSTEM && network.getAccountId() != accountId) {
throw new PermissionDeniedException("Unable to create a vm using network with id " + networkId + ", permission denied");
if (!network.isShared()) {
//Iterate through account/network map
List<NetworkVO> networkMap = _networkDao.listBy(accountId, networkId);
if (networkMap == null || networkMap.isEmpty()) {
throw new PermissionDeniedException("Unable to create a vm using network with id " + networkId + ", permission denied");
}
} else if (network.getTrafficType() != TrafficType.Guest) {
throw new InvalidParameterValueException("Unable to create a vm using network which traffic type is " + network.getTrafficType() + ". " +
"Only Guest traffic type is acceptes");

View File

@ -137,6 +137,7 @@ CREATE TABLE `cloud`.`networks` (
`guru_data` varchar(1024) COMMENT 'data stored by the network guru that setup this network',
`set_fields` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'which fields are set already',
`guest_type` char(32) COMMENT 'type of guest network',
`shared` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '0 if network is shared, 1 if network dedicated',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -197,7 +198,6 @@ CREATE TABLE `cloud`.`network_offerings` (
`service_offering_id` bigint unsigned UNIQUE COMMENT 'service offering id that this network offering is tied to',
`created` datetime NOT NULL COMMENT 'time the entry was created',
`removed` datetime DEFAULT NULL COMMENT 'time the entry was removed',
`shared` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '0 if network is shared, 1 if network dedicated',
`default` int(1) unsigned NOT NULL DEFAULT 0 COMMENT '1 if network is default',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;