Plug nic support

Conflicts:

	server/src/com/cloud/consoleproxy/AgentBasedConsoleProxyManager.java
	server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
	server/src/com/cloud/network/NetworkManagerImpl.java
	server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java
This commit is contained in:
Alena Prokharchyk 2012-05-23 16:18:41 -07:00
parent f4060c3c1d
commit d9fd7e02a5
37 changed files with 890 additions and 418 deletions

View File

@ -0,0 +1,50 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.agent.api;
import java.util.Map;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
/**
* @author Alena Prokharchyk
*/
public class PlugNicCommand extends Command {
public enum Param {
DhcpRange,
NetworkDomain
}
VirtualMachineTO vm;
NicTO nic;
Map<Param, String> params;
public VirtualMachineTO getVirtualMachine() {
return vm;
}
@Override
public boolean executeInSequence() {
return true;
}
protected PlugNicCommand() {
}
public PlugNicCommand(VirtualMachineTO vm, NicTO nic, Map<Param, String> params) {
this.vm = vm;
this.nic = nic;
this.params = params;
}
}

View File

@ -21,8 +21,6 @@ import java.util.List;
import java.util.Set;
import com.cloud.agent.api.to.FirewallRuleTO;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.utils.StringUtils;
/**
*

View File

@ -177,5 +177,4 @@ public class NetworkTO {
public boolean isSecurityGroupEnabled() {
return this.isSecurityGroupEnabled;
}
}

View File

@ -17,9 +17,11 @@
package com.cloud.hypervisor;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.utils.component.Adapter;
import com.cloud.vm.NicProfile;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@ -49,4 +51,10 @@ public interface HypervisorGuru extends Adapter {
*
*/
boolean trackVmHostChange();
/**
* @param profile
* @return
*/
NicTO toNicTO(NicProfile profile);
}

View File

@ -36,7 +36,6 @@ import com.cloud.network.Networks.TrafficType;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.utils.Pair;
import com.cloud.vm.VirtualMachine;
public interface NetworkService {
@ -149,10 +148,5 @@ public interface NetworkService {
List<? extends Network> listNetworksByVpc(long vpcId);
boolean addVmToNetwork(VirtualMachine vm, Network network);
boolean removeVmFromNetwork(VirtualMachine vm, Network network);
boolean isVmPartOfNetwork(long vmId, long ntwkId);
}

View File

@ -36,32 +36,5 @@ public interface VpcProvider extends NetworkElement{
boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
/**
* Prepare for a nic to be plugged into the network.
* @param network
* @param nic
* @param vm
* @param context
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
* @throws InsufficientNetworkCapacityException
*/
boolean plugNic(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm,
ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException;
/**
* A nic is unplugged from this network.
* @param network
* @param nic
* @param vm
* @param context
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
*/
boolean unplugNic(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm,
ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException;
}

View File

@ -0,0 +1,43 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by the License.
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.vpc;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.router.VirtualRouter;
/**
* @author Alena Prokharchyk
*/
public interface VpcVirtualNetworkApplianceService {
/**
* @param router
* @param network
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
* @throws InsufficientCapacityException
*/
public boolean addVmToNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException;
/**
* @param router
* @param network
* @return
*/
boolean removeVmFromNetwork(VirtualRouter router, Network network);
}

View File

@ -35,7 +35,8 @@ public interface Nic {
}
public enum State implements FiniteState<State, Event> {
Allocated("Resource is allocated but not reserved"), Reserving("Resource is being reserved right now"), Reserved("Resource has been reserved."), Releasing("Resource is being released"), Deallocating(
Allocated("Resource is allocated but not reserved"), Reserving("Resource is being reserved right now"),
Reserved("Resource has been reserved."), Releasing("Resource is being released"), Deallocating(
"Resource is being deallocated");
String _description;

View File

@ -54,7 +54,6 @@ import com.cloud.template.VirtualMachineTemplate;
import com.cloud.user.Account;
import com.cloud.uservm.UserVm;
import com.cloud.utils.exception.ExecutionException;
import com.cloud.vm.VirtualMachineProfile.Param;
public interface UserVmService {
/**

View File

@ -88,7 +88,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
boolean isPriorityBumpUp,
RedundantState redundantState,
boolean haEnabled,
boolean stopPending) {
boolean stopPending, Long vpcId) {
super(id, serviceOfferingId, name, name, Type.DomainRouter, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
this.elementId = elementId;
this.isRedundantRouter = isRedundantRouter;
@ -96,6 +96,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
this.redundantState = redundantState;
this.isPriorityBumpUp = isPriorityBumpUp;
this.stopPending = stopPending;
this.vpcId = vpcId;
}
public DomainRouterVO(long id,
@ -113,7 +114,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
RedundantState redundantState,
boolean haEnabled,
boolean stopPending,
VirtualMachine.Type vmType) {
VirtualMachine.Type vmType, Long vpcId) {
super(id, serviceOfferingId, name, name, vmType, templateId, hypervisorType, guestOSId, domainId, accountId, haEnabled);
this.elementId = elementId;
this.isRedundantRouter = isRedundantRouter;
@ -121,6 +122,7 @@ public class DomainRouterVO extends VMInstanceVO implements VirtualRouter {
this.redundantState = redundantState;
this.isPriorityBumpUp = isPriorityBumpUp;
this.stopPending = stopPending;
this.vpcId = vpcId;
}
public long getElementId() {

View File

@ -1612,7 +1612,8 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
userNetwork.setBroadcastDomainType(broadcastDomainType);
userNetwork.setNetworkDomain(networkDomain);
_networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, Domain.ROOT_DOMAIN, null, null);
_networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false,
Domain.ROOT_DOMAIN, null, null, null);
}
}
}

View File

@ -29,13 +29,19 @@ import com.cloud.agent.api.GetVncPortCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupProxyCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.info.ConsoleProxyInfo;
import com.cloud.network.Network;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.Inject;
@ -341,4 +347,20 @@ public class AgentBasedConsoleProxyManager implements ConsoleProxyManager, Virtu
@Override
public void finalizeExpunge(ConsoleProxyVO proxy) {
}
}
@Override
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
//not supported
throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType());
}
@Override
public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
//not supported
throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
}
}

View File

@ -43,6 +43,8 @@ import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer;
import com.cloud.agent.api.proxy.StartConsoleProxyAgentHttpHandlerCommand;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.api.ServerApiException;
import com.cloud.api.commands.DestroyConsoleProxyCmd;
@ -82,6 +84,7 @@ import com.cloud.keystore.KeystoreDao;
import com.cloud.keystore.KeystoreManager;
import com.cloud.keystore.KeystoreVO;
import com.cloud.network.IPAddressVO;
import com.cloud.network.Network;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.TrafficType;
@ -95,7 +98,6 @@ import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceStateAdapter;
import com.cloud.resource.ServerResource;
import com.cloud.resource.UnableDeleteHostException;
import com.cloud.server.ManagementServer;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.servlet.ConsoleProxyServlet;
@ -133,7 +135,6 @@ import com.cloud.uuididentity.dao.IdentityDao;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.SystemVmLoadScanHandler;
import com.cloud.vm.SystemVmLoadScanner;
import com.cloud.vm.SystemVmLoadScanner.AfterScanAction;
@ -1989,4 +1990,20 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, ConsoleProx
}
return _hashKey;
}
@Override
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
//not supported
throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType());
}
@Override
public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
//not supported
throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
}
}

View File

@ -35,7 +35,8 @@ public abstract class HypervisorGuruBase extends AdapterBase implements Hypervis
super();
}
protected NicTO toNicTO(NicProfile profile) {
@Override
public NicTO toNicTO(NicProfile profile) {
NicTO to = new NicTO();
to.setDeviceId(profile.getDeviceId());
to.setBroadcastType(profile.getBroadcastType());

View File

@ -109,7 +109,7 @@ public interface NetworkManager extends NetworkService {
throws ConcurrentOperationException;
List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId,
ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException;
ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException;
List<NetworkOfferingVO> getSystemAccountNetworkOfferings(String... offeringNames);
@ -231,8 +231,6 @@ public interface NetworkManager extends NetworkService {
boolean canElementEnableIndividualServices(Provider provider);
PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId);
boolean areServicesSupportedInNetwork(long networkId, Service... services);
boolean isNetworkSystem(Network network);
@ -252,9 +250,6 @@ public interface NetworkManager extends NetworkService {
void canProviderSupportServices(Map<Provider, Set<Service>> providersMap);
PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(
long physicalNetworkId);
List<PhysicalNetworkSetupInfo> getPhysicalNetworkInfo(long dcId,
HypervisorType hypervisorType);
@ -344,4 +339,37 @@ public interface NetworkManager extends NetworkService {
* @return
*/
List<Provider> getNtwkOffDistinctProviders(long networkId);
/**
* @param requested
* @param network
* @param isDefaultNic
* @param deviceId
* @param vm
* @return
* @throws InsufficientVirtualNetworkCapcityException
* @throws InsufficientAddressCapacityException
* @throws ConcurrentOperationException
*/
Pair<NicProfile,Integer> allocateNic(NicProfile requested, Network network, Boolean isDefaultNic, int deviceId,
VirtualMachineProfile<? extends VMInstanceVO> vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException;
/**
* @param vmProfile
* @param dest
* @param context
* @param nicId
* @param network
* @return
* @throws InsufficientVirtualNetworkCapcityException
* @throws InsufficientAddressCapacityException
* @throws ConcurrentOperationException
* @throws InsufficientCapacityException
* @throws ResourceUnavailableException
*/
NicProfile prepareNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
}

View File

@ -188,6 +188,7 @@ import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
@ -1513,16 +1514,17 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
@Override
public List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name, String displayText, boolean isDefault)
public List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, DeploymentPlan plan, String name,
String displayText, boolean isDefault)
throws ConcurrentOperationException {
return setupNetwork(owner, offering, null, plan, name, displayText, false, null, null, null);
return setupNetwork(owner, offering, null, plan, name, displayText, false, null, null, null, null);
}
@Override
@DB
public List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan
plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId,
ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException {
ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException {
Account locked = _accountDao.acquireInLockTable(owner.getId());
if (locked == null) {
@ -1594,9 +1596,11 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Transaction txn = Transaction.currentTxn();
txn.start();
NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(), related, name, displayText, predefined.getNetworkDomain(),
offering.getGuestType(), plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges());
networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated, finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
NetworkVO vo = new NetworkVO(id, network, offering.getId(), guru.getName(), owner.getDomainId(), owner.getId(),
related, name, displayText, predefined.getNetworkDomain(), offering.getGuestType(),
plan.getDataCenterId(), plan.getPhysicalNetworkId(), aclType, offering.getSpecifyIpRanges(), vpcId);
networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated,
finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
if (domainId != null && aclType == ACLType.Domain) {
_networksDao.addDomainToNetwork(id, domainId, subdomainAccess);
@ -1634,7 +1638,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
@Override
@DB
public void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair<NetworkVO, NicProfile>> networks) throws InsufficientCapacityException, ConcurrentOperationException {
public void allocate(VirtualMachineProfile<? extends VMInstanceVO> vm, List<Pair<NetworkVO, NicProfile>> networks)
throws InsufficientCapacityException, ConcurrentOperationException {
Transaction txn = Transaction.currentTxn();
txn.start();
@ -1643,64 +1648,53 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
boolean[] deviceIds = new boolean[networks.size()];
Arrays.fill(deviceIds, false);
List<NicVO> nics = new ArrayList<NicVO>(networks.size());
NicVO defaultNic = null;
List<NicProfile> nics = new ArrayList<NicProfile>(networks.size());
NicProfile defaultNic = null;
for (Pair<NetworkVO, NicProfile> network : networks) {
NetworkVO config = network.first();
NetworkGuru guru = _networkGurus.get(config.getGuruName());
NicProfile requested = network.second();
if (requested != null && requested.getMode() == null) {
requested.setMode(config.getMode());
Boolean isDefaultNic = false;
if (vm != null && (requested != null && requested.isDefaultNic())) {
isDefaultNic = true;
}
NicProfile profile = guru.allocate(config, requested, vm);
if (vm != null && vm.getVirtualMachine().getType() == Type.User && (requested != null && requested.isDefaultNic())) {
profile.setDefaultNic(true);
}
if (profile == null) {
continue;
}
if (requested != null && requested.getMode() == null) {
profile.setMode(requested.getMode());
} else {
profile.setMode(config.getMode());
}
NicVO vo = new NicVO(guru.getName(), vm.getId(), config.getId(), vm.getType());
while (deviceIds[deviceId] && deviceId < deviceIds.length) {
deviceId++;
}
deviceId = applyProfileToNic(vo, profile, deviceId);
vo = _nicDao.persist(vo);
if (vo.isDefaultNic()) {
if (defaultNic != null) {
throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " + defaultNic + "; nic 2 = " + vo);
}
defaultNic = vo;
Pair<NicProfile,Integer> vmNicPair = allocateNic(requested, config, isDefaultNic,
deviceId, vm);
NicProfile vmNic = vmNicPair.first();
if (vmNic == null) {
continue;
}
int devId = vo.getDeviceId();
deviceId = vmNicPair.second();
int devId = vmNic.getDeviceId();
if (devId > deviceIds.length) {
throw new IllegalArgumentException("Device id for nic is too large: " + vo);
throw new IllegalArgumentException("Device id for nic is too large: " + vmNic);
}
if (deviceIds[devId]) {
throw new IllegalArgumentException("Conflicting device id for two different nics: " + devId);
throw new IllegalArgumentException("Conflicting device id for two different nics: " + vmNic);
}
deviceIds[devId] = true;
nics.add(vo);
Integer networkRate = getNetworkRate(config.getId(), vm.getId());
vm.addNic(new NicProfile(vo, network.first(), vo.getBroadcastUri(), vo.getIsolationUri(), networkRate,
isSecurityGroupSupportedInNetwork(network.first()), getNetworkTag(vm.getHypervisorType(),
network.first())));
if (vmNic.isDefaultNic()) {
if (defaultNic != null) {
throw new IllegalArgumentException("You cannot specify two nics as default nics: nic 1 = " +
defaultNic + "; nic 2 = " + vmNic);
}
defaultNic = vmNic;
}
nics.add(vmNic);
vm.addNic(vmNic);
}
if (nics.size() != networks.size()) {
@ -1714,6 +1708,49 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
txn.commit();
}
@DB
@Override
public Pair<NicProfile,Integer> allocateNic(NicProfile requested, Network network, Boolean isDefaultNic,
int deviceId, VirtualMachineProfile<? extends VMInstanceVO> vm) throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException, ConcurrentOperationException{
NetworkVO ntwkVO = _networksDao.findById(network.getId());
s_logger.debug("Allocating nic for vm " + vm.getVirtualMachine() + " in network " + network);
NetworkGuru guru = _networkGurus.get(ntwkVO.getGuruName());
if (requested != null && requested.getMode() == null) {
requested.setMode(network.getMode());
}
NicProfile profile = guru.allocate(network, requested, vm);
if (isDefaultNic != null) {
profile.setDefaultNic(isDefaultNic);
}
if (profile == null) {
return null;
}
if (requested != null && requested.getMode() == null) {
profile.setMode(requested.getMode());
} else {
profile.setMode(network.getMode());
}
NicVO vo = new NicVO(guru.getName(), vm.getId(), network.getId(), vm.getType());
deviceId = applyProfileToNic(vo, profile, deviceId);
vo = _nicDao.persist(vo);
Integer networkRate = getNetworkRate(network.getId(), vm.getId());
NicProfile vmNic = new NicProfile(vo, network, vo.getBroadcastUri(), vo.getIsolationUri(), networkRate,
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(),
network));
return new Pair<NicProfile,Integer>(vmNic, Integer.valueOf(deviceId));
}
protected Integer applyProfileToNic(NicVO vo, NicProfile profile, Integer deviceId) {
if (profile.getDeviceId() != null) {
@ -1799,7 +1836,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
Integer networkRate = getNetworkRate(config.getId(), null);
to.setNetworkRateMbps(networkRate);
return to;
}
@ -1963,9 +2000,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId());
// we have to implement default nics first - to ensure that default network elements start up first in multiple
// nics
// case)
// (need for setting DNS on Dhcp to domR's Ip4 address)
// nics case)(need for setting DNS on Dhcp to domR's Ip4 address)
Collections.sort(nics, new Comparator<NicVO>() {
@Override
@ -1979,59 +2014,74 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
for (NicVO nic : nics) {
Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context);
NetworkGuru guru = implemented.first();
NetworkVO network = implemented.second();
Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId());
NicProfile profile = null;
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
nic.setState(Nic.State.Reserving);
nic.setReservationId(context.getReservationId());
_nicDao.update(nic.getId(), nic);
URI broadcastUri = nic.getBroadcastUri();
if (broadcastUri == null) {
broadcastUri = network.getBroadcastUri();
}
URI isolationUri = nic.getIsolationUri();
profile = new NicProfile(nic, network, broadcastUri, isolationUri, networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network));
guru.reserve(profile, network, vmProfile, dest, context);
nic.setIp4Address(profile.getIp4Address());
nic.setAddressFormat(profile.getFormat());
nic.setIp6Address(profile.getIp6Address());
nic.setMacAddress(profile.getMacAddress());
nic.setIsolationUri(profile.getIsolationUri());
nic.setBroadcastUri(profile.getBroadCastUri());
nic.setReserver(guru.getName());
nic.setState(Nic.State.Reserved);
nic.setNetmask(profile.getNetmask());
nic.setGateway(profile.getGateway());
if (profile.getStrategy() != null) {
nic.setReservationStrategy(profile.getStrategy());
}
updateNic(nic, network.getId(), 1);
} else {
profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network));
guru.updateNicProfile(profile, network);
nic.setState(Nic.State.Reserved);
updateNic(nic, network.getId(), 1);
}
for (NetworkElement element : _networkElements) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
}
prepareElement(element, network, profile, vmProfile, dest, context);
}
profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network));
guru.updateNicProfile(profile, network);
NetworkVO network = implemented.second();
NicProfile profile = prepareNic(vmProfile, dest, context, nic.getId(), network);
vmProfile.addNic(profile);
}
}
@Override
public NicProfile prepareNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, DeployDestination
dest, ReservationContext context, long nicId, NetworkVO network)
throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException,
ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
Integer networkRate = getNetworkRate(network.getId(), vmProfile.getId());
NetworkGuru guru = _networkGurus.get(network.getGuruName());
NicVO nic = _nicDao.findById(nicId);
NicProfile profile = null;
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
nic.setState(Nic.State.Reserving);
nic.setReservationId(context.getReservationId());
_nicDao.update(nic.getId(), nic);
URI broadcastUri = nic.getBroadcastUri();
if (broadcastUri == null) {
broadcastUri = network.getBroadcastUri();
}
URI isolationUri = nic.getIsolationUri();
profile = new NicProfile(nic, network, broadcastUri, isolationUri,
networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network));
guru.reserve(profile, network, vmProfile, dest, context);
nic.setIp4Address(profile.getIp4Address());
nic.setAddressFormat(profile.getFormat());
nic.setIp6Address(profile.getIp6Address());
nic.setMacAddress(profile.getMacAddress());
nic.setIsolationUri(profile.getIsolationUri());
nic.setBroadcastUri(profile.getBroadCastUri());
nic.setReserver(guru.getName());
nic.setState(Nic.State.Reserved);
nic.setNetmask(profile.getNetmask());
nic.setGateway(profile.getGateway());
if (profile.getStrategy() != null) {
nic.setReservationStrategy(profile.getStrategy());
}
updateNic(nic, network.getId(), 1);
} else {
profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network));
guru.updateNicProfile(profile, network);
nic.setState(Nic.State.Reserved);
updateNic(nic, network.getId(), 1);
}
for (NetworkElement element : _networkElements) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to prepare for " + nic);
}
prepareElement(element, network, profile, vmProfile, dest, context);
}
profile.setSecurityGroupEnabled(isSecurityGroupSupportedInNetwork(network));
guru.updateNicProfile(profile, network);
return profile;
}
@Override
public <T extends VMInstanceVO> void prepareNicForMigration(VirtualMachineProfile<T> vm, DeployDestination dest) {
List<NicVO> nics = _nicDao.listByVmId(vm.getId());
@ -2052,36 +2102,42 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
List<NicVO> nics = _nicDao.listByVmId(vmProfile.getId());
for (NicVO nic : nics) {
NetworkVO network = _networksDao.findById(nic.getNetworkId());
if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) {
Nic.State originalState = nic.getState();
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
NetworkGuru guru = _networkGurus.get(network.getGuruName());
nic.setState(Nic.State.Releasing);
_nicDao.update(nic.getId(), nic);
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network));
if (guru.release(profile, vmProfile, nic.getReservationId())) {
applyProfileToNicForRelease(nic, profile);
nic.setState(Nic.State.Allocated);
if (originalState == Nic.State.Reserved) {
updateNic(nic, network.getId(), -1);
} else {
_nicDao.update(nic.getId(), nic);
}
}
// Perform release on network elements
for (NetworkElement element : _networkElements) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to release " + nic);
}
//NOTE: Context appear to never be used in release method
//implementations. Consider removing it from interface Element
element.release(network, profile, vmProfile, null);
}
} else {
releaseNic(vmProfile, nic, network);
}
}
protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NicVO nic, NetworkVO network)
throws ConcurrentOperationException, ResourceUnavailableException {
if (nic.getState() == Nic.State.Reserved || nic.getState() == Nic.State.Reserving) {
Nic.State originalState = nic.getState();
if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
NetworkGuru guru = _networkGurus.get(network.getGuruName());
nic.setState(Nic.State.Releasing);
_nicDao.update(nic.getId(), nic);
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null,
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getHypervisorType(), network));
if (guru.release(profile, vmProfile, nic.getReservationId())) {
applyProfileToNicForRelease(nic, profile);
nic.setState(Nic.State.Allocated);
updateNic(nic, network.getId(), -1);
if (originalState == Nic.State.Reserved) {
updateNic(nic, network.getId(), -1);
} else {
_nicDao.update(nic.getId(), nic);
}
}
// Perform release on network elements
for (NetworkElement element : _networkElements) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Asking " + element.getName() + " to release " + nic);
}
//NOTE: Context appear to never be used in release method
//implementations. Consider removing it from interface Element
element.release(network, profile, vmProfile, null);
}
} else {
nic.setState(Nic.State.Allocated);
updateNic(nic, network.getId(), -1);
}
}
}
@ -2567,16 +2623,28 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return network;
}
public Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, String gateway,
@DB
protected Network createVpcGuestNetwork(long ntwkOffId, String name, String displayText, String gateway,
String cidr, String vlanId, String networkDomain, Account owner, Long domainId,
PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, long vpcId)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
//1) Validate if network can be created for VPC
_vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner,
_vpcMgr.getVpc(vpcId));
return createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId,
//2) Create network
Network guestNetwork = createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId,
networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId);
//3) Add network to all VPC's routers
List<DomainRouterVO> routers = _routerDao.listRoutersByVpcId(vpcId);
for (DomainRouterVO router : routers) {
s_logger.debug("Adding router " + router + " to network " + guestNetwork);
_routerDao.addRouterToNetwork(router, guestNetwork);
}
return guestNetwork;
}
@Override
@ -2779,7 +2847,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
List<NetworkVO> networks = setupNetwork(owner, ntwkOff, userNetwork, plan, name, displayText, true, domainId,
aclType, subdomainAccess);
aclType, subdomainAccess, vpcId);
Network network = null;
if (networks == null || networks.isEmpty()) {
@ -4911,6 +4979,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
// add security group provider to the physical network
addDefaultSecurityGroupProviderToPhysicalNetwork(pNetwork.getId());
// add VPCVirtualRouter as the defualt network service provider
addDefaultVpcVirtualRouterToPhysicalNetwork(pNetwork.getId());
txn.commit();
return pNetwork;
@ -6254,7 +6325,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
} else {
// locate physicalNetwork with supported traffic type
// We can make this assumptions based on the fact that Public/Management/Control traffic types are
// supported only in one physical network in the zone in 3.0
// supported only in one physical network in the zone in 3.0
for (PhysicalNetworkVO pNtwk : pNtwks) {
if (_pNTrafficTypeDao.isTrafficTypeSupported(pNtwk.getId(), network.getTrafficType())) {
physicalNetworkId = pNtwk.getId();
@ -6281,8 +6352,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return networks.get(0);
}
@Override
public PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId) {
protected PhysicalNetworkServiceProvider addDefaultVirtualRouterToPhysicalNetwork(long physicalNetworkId) {
PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.VirtualRouter.getName(), null, null);
// add instance of the provider
@ -6294,9 +6364,16 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return nsp;
}
protected PhysicalNetworkServiceProvider addDefaultVpcVirtualRouterToPhysicalNetwork(long physicalNetworkId) {
@Override
public PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long physicalNetworkId) {
PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId,
Network.Provider.VPCVirtualRouter.getName(), null, null);
return nsp;
}
protected PhysicalNetworkServiceProvider addDefaultSecurityGroupProviderToPhysicalNetwork(long physicalNetworkId) {
PhysicalNetworkServiceProvider nsp = addProviderToPhysicalNetwork(physicalNetworkId, Network.Provider.SecurityGroupProvider.getName(), null, null);
@ -6323,7 +6400,7 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
for (NetworkOfferingServiceMapVO serviceMap : servicesMap) {
if (svcProviders.containsKey(serviceMap.getService())) {
// FIXME - right now we pick up the first provider from the list, need to add more logic based on
// provider load, etc
// provider load, etc
continue;
}
@ -6337,7 +6414,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
// check that provider is supported
if (checkPhysicalNetwork) {
if (!_pNSPDao.isServiceProviderEnabled(physicalNetworkId, provider, service)) {
throw new UnsupportedServiceException("Provider " + provider + " is either not enabled or doesn't support service " + service + " in physical network id=" + physicalNetworkId);
throw new UnsupportedServiceException("Provider " + provider + " is either not enabled or doesn't " +
"support service " + service + " in physical network id=" + physicalNetworkId);
}
}
@ -6703,7 +6781,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
}
} catch (Exception ex) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Failed to retrieve the default label for guest traffic." + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to: " + ex.getMessage());
s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId +
" hypervisor: " + hypervisorType + " due to:" + ex.getMessage());
}
}
return null;
@ -6746,18 +6825,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return providers;
}
/* (non-Javadoc)
* @see com.cloud.network.NetworkService#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network)
*/
@Override
public boolean addVmToNetwork(VirtualMachine vm, Network network) {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see com.cloud.network.NetworkService#isVmPartOfNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network)
*/
@Override
public boolean isVmPartOfNetwork(long vmId, long ntwkId) {
if (_nicDao.findByInstanceIdAndNetworkId(ntwkId, vmId) != null) {
@ -6766,12 +6833,4 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
return false;
}
/* (non-Javadoc)
* @see com.cloud.network.NetworkService#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network)
*/
@Override
public boolean removeVmFromNetwork(VirtualMachine vm, Network network) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -179,9 +179,9 @@ public class NetworkVO implements Network, Identity {
public NetworkVO(long id, Network that, long offeringId, String guruName, long domainId, long accountId,
long related, String name, String displayText, String networkDomain, GuestType guestType, long dcId,
Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) {
Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) {
this(id, that.getTrafficType(), that.getMode(), that.getBroadcastDomainType(), offeringId, domainId, accountId,
related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges);
related, name, displayText, networkDomain, guestType, dcId, physicalNetworkId, aclType, specifyIpRanges, vpcId);
this.gateway = that.getGateway();
this.cidr = that.getCidr();
this.broadcastUri = that.getBroadcastUri();
@ -208,11 +208,12 @@ public class NetworkVO implements Network, Identity {
* @param guestType TODO
* @param aclType TODO
* @param specifyIpRanges TODO
* @param vpcId TODO
* @param dataCenterId
*/
public NetworkVO(long id, TrafficType trafficType, Mode mode, BroadcastDomainType broadcastDomainType,
long networkOfferingId, long domainId, long accountId, long related, String name, String displayText,
String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges) {
String networkDomain, GuestType guestType, long dcId, Long physicalNetworkId, ACLType aclType, boolean specifyIpRanges, Long vpcId) {
this(trafficType, mode, broadcastDomainType, networkOfferingId, State.Allocated, dcId, physicalNetworkId);
this.domainId = domainId;
this.accountId = accountId;
@ -225,6 +226,7 @@ public class NetworkVO implements Network, Identity {
this.uuid = UUID.randomUUID().toString();
this.guestType = guestType;
this.specifyIpRanges = specifyIpRanges;
this.vpcId = vpcId;
}
@Override

View File

@ -14,6 +14,7 @@ package com.cloud.network.element;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.Local;
@ -29,8 +30,10 @@ import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkService;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.router.VpcVirtualNetworkApplianceManager;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcVirtualNetworkApplianceService;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.component.Inject;
import com.cloud.vm.NicProfile;
@ -45,9 +48,10 @@ import com.cloud.vm.VirtualMachineProfile;
public class VpcVirtualRouterElement extends VirtualRouterElement implements VpcProvider{
private static final Logger s_logger = Logger.getLogger(VpcVirtualRouterElement.class);
@Inject
NetworkService _ntwkSvc;
NetworkService _ntwkService;
@Inject
VpcVirtualNetworkApplianceManager _vpcElementMgr;
VpcVirtualNetworkApplianceService _vpcElementService;
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@ -71,17 +75,34 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
throws ResourceUnavailableException, ConcurrentOperationException,
InsufficientCapacityException {
if (network.getVpcId() == null) {
Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.warn("Network " + network + " is not associated with any VPC");
return false;
}
boolean success = super.implement(network, offering, dest, context);
if (success) {
success = success && _vpcElementMgr.addVpcElementToNetwork(network);
List<? extends VirtualRouter> routers = _routerDao.listRoutersByVpcId(vpcId);
for (VirtualRouter router : routers) {
//1) Check if router is already a part of the network
if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) {
s_logger.debug("Router " + router + " is already part of the network " + network);
continue;
}
//2) Call plugNics in the network service
success = success && _vpcElementService.addVmToNetwork(router, network);
}
if (!success) {
s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId);
} else {
s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId);
}
}
return success;
return success;
}
@Override
@ -89,30 +110,92 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
if (network.getVpcId() == null) {
Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.warn("Network " + network + " is not associated with any VPC");
return false;
}
boolean success = super.prepare(network, nic, vm, dest, context);
if (success) {
success = success && _vpcElementMgr.addVpcElementToNetwork(network);
List<? extends VirtualRouter> routers = _routerDao.listRoutersByVpcId(vpcId);
for (VirtualRouter router : routers) {
//1) Check if router is already a part of the network
if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) {
s_logger.debug("Router " + router + " is already part of the network " + network);
continue;
}
//2) Call plugNics in the network service
success = success && _vpcElementService.addVmToNetwork(router, network);
}
if (!success) {
s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId);
} else {
s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId);
}
}
return success;
}
@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup)
throws ConcurrentOperationException, ResourceUnavailableException {
return _vpcElementMgr.removeVpcElementFromNetwork(network);
boolean success = true;
Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part");
return success;
}
List<? extends VirtualRouter> routers = _routerDao.listRoutersByVpcId(vpcId);
for (VirtualRouter router : routers) {
//1) Check if router is already a part of the network
if (!_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) {
s_logger.debug("Router " + router + " is not a part the network " + network);
continue;
}
//2) Call unplugNics in the network service
success = success && _vpcElementService.removeVmFromNetwork(router, network);
}
if (!success) {
s_logger.warn("Failed to unplug nic in network " + network + " for virtual router in vpc id=" + vpcId);
} else {
s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router in vpc id=" + vpcId);
}
return success;
}
@Override
public boolean destroy(Network config) throws ConcurrentOperationException, ResourceUnavailableException {
return _vpcElementMgr.removeVpcElementFromNetwork(config);
boolean success = true;
Long vpcId = config.getVpcId();
if (vpcId == null) {
s_logger.debug("Network " + config + " doesn't belong to any vpc, so skipping unplug nic part");
return success;
}
List<? extends VirtualRouter> routers = _routerDao.listRoutersByVpcId(vpcId);
for (VirtualRouter router : routers) {
//1) Check if router is already a part of the network
if (!_ntwkService.isVmPartOfNetwork(router.getId(), config.getId())) {
s_logger.debug("Router " + router + " is not a part the network " + config);
continue;
}
//2) Call unplugNics in the network service
success = success && _vpcElementService.removeVmFromNetwork(router, config);
}
if (!success) {
s_logger.warn("Failed to unplug nic in network " + config + " for virtual router in vpc id=" + vpcId);
} else {
s_logger.debug("Successfully unplugged nic in network " + config + " for virtual router in vpc id=" + vpcId);
}
return success;
}
@Override
@ -135,20 +218,4 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
return capabilities;
}
@Override
public boolean plugNic(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm,
ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean unplugNic(Network network, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm,
ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -42,11 +42,11 @@ import com.cloud.network.Network.State;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkProfile;
import com.cloud.network.NetworkVO;
import com.cloud.network.PhysicalNetworkVO;
import com.cloud.network.Networks.AddressFormat;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkVO;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.PhysicalNetworkDao;
@ -312,16 +312,21 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
if (nic.getIp4Address() == null) {
nic.setBroadcastUri(network.getBroadcastUri());
nic.setIsolationUri(network.getBroadcastUri());
nic.setGateway(network.getGateway());
String guestIp = null;
if (network.getSpecifyIpRanges()) {
_networkMgr.allocateDirectIp(nic, dc, vm, network, nic.getRequestedIp());
} else {
guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp());
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" +
" address for network " + network, DataCenter.class, dc.getId());
//if Vm is router vm, set ip4 to the network gateway
if (vm.getVirtualMachine().getType() == VirtualMachine.Type.DomainRouter) {
guestIp = network.getGateway();
} else {
nic.setGateway(network.getGateway());
guestIp = _networkMgr.acquireGuestIpAddress(network, nic.getRequestedIp());
if (guestIp == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to acquire Guest IP" +
" address for network " + network, DataCenter.class, dc.getId());
}
}
nic.setIp4Address(guestIp);

View File

@ -39,6 +39,8 @@ import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
import com.cloud.agent.api.routing.NetworkElementCommand;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.api.commands.CreateLoadBalancerRuleCmd;
import com.cloud.configuration.Config;
@ -512,8 +514,10 @@ public class ElasticLoadBalancerManagerImpl implements
throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
}
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN, _elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm);
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(),
VirtualMachineName.getSystemVmName(id, _instance, _elbVmNamePrefix), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN,
_elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null);
elbVm.setRole(Role.LB);
elbVm = _itMgr.allocate(elbVm, template, _elasticLbVmOffering, networks, plan, null, owner);
//TODO: create usage stats
@ -984,7 +988,6 @@ public class ElasticLoadBalancerManagerImpl implements
}
@Override
public Long convertToId(String vmName) {
if (!VirtualMachineName.isValidSystemVmName(vmName, _instance, _elbVmNamePrefix)) {
@ -993,4 +996,20 @@ public class ElasticLoadBalancerManagerImpl implements
return VirtualMachineName.getSystemVmId(vmName);
}
@Override
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
//not supported
throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType());
}
@Override
public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
//not supported
throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
}
}

View File

@ -67,8 +67,10 @@ import com.cloud.agent.api.routing.VpnUsersCfgCommand;
import com.cloud.agent.api.to.FirewallRuleTO;
import com.cloud.agent.api.to.IpAddressTO;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.PortForwardingRuleTO;
import com.cloud.agent.api.to.StaticNatRuleTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.alert.AlertManager;
import com.cloud.api.commands.UpgradeRouterCmd;
@ -1252,7 +1254,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToGuestNetwork(owner, guestNetwork);
for (int i = 0; i < count; i++) {
DomainRouterVO router = deployRouter(owner, dest, plan, params, publicNetwork, guestNetwork, isRedundant,
vrProvider, offeringId, sourceNatIp);
vrProvider, offeringId, sourceNatIp, null);
routers.add(router);
}
} finally {
@ -1265,7 +1267,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
protected DomainRouterVO deployRouter(Account owner, DeployDestination dest, DeploymentPlan plan, Map<Param, Object> params,
boolean setupPublicNetwork, Network guestNetwork, boolean isRedundant,
VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp) throws ConcurrentOperationException,
VirtualRouterProvider vrProvider, long svcOffId, PublicIp sourceNatIp, Long vpcId) throws ConcurrentOperationException,
InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
StorageUnavailableException, ResourceUnavailableException {
@ -1332,7 +1334,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
router = new DomainRouterVO(id, routerOffering.getId(), vrProvider.getId(),
VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), isRedundant, 0, false,
RedundantState.UNKNOWN, offerHA, false);
RedundantState.UNKNOWN, offerHA, false, vpcId);
router.setRole(Role.VIRTUAL_ROUTER);
router = _itMgr.allocate(router, template, routerOffering, networks, plan, null, owner);
} catch (InsufficientCapacityException ex) {
@ -1374,8 +1376,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
//1) Guest network
boolean hasGuestNetwork = false;
if (guestNetwork != null) {
String defaultNetworkStartIp = null;
s_logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
String defaultNetworkStartIp = null;
if (guestNetwork.getCidr() != null && !setupPublicNetwork) {
String startIp = _networkMgr.getStartIpAddress(guestNetwork.getId());
if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
@ -1385,8 +1387,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
" is already allocated, can't use it for domain router; will get random ip address from the range");
}
}
NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp);
if (setupPublicNetwork) {
@ -1572,6 +1572,9 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterVO> profile, DeployDestination dest,
ReservationContext context) {
boolean dnsProvided = true;
boolean dhcpProvided = true;
DataCenterVO dc = _dcDao.findById(dest.getDataCenter().getId());
_dcDao.loadDetails(dc);
@ -1637,6 +1640,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
}
}
} else if (nic.getTrafficType() == TrafficType.Guest) {
dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dns, Provider.VirtualRouter);
dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(nic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter);
//build bootloader parameter for the guest
buf.append(createGuestBootLoadArgs(nic, defaultDns1, defaultDns2, router));
} else if (nic.getTrafficType() == TrafficType.Public) {
@ -1676,77 +1681,8 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
if (profile.getHypervisorType() == HypervisorType.VMware) {
buf.append(" extra_pubnics=" + _routerExtraPublicNics);
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Boot Args for " + profile + ": " + buf.toString());
}
return true;
}
protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1,
String defaultDns2, DomainRouterVO router) {
long guestNetworkId = guestNic.getNetworkId();
NetworkVO guestNetwork = _networkDao.findById(guestNetworkId);
String dhcpRange = null;
DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId());
if (dc.getNetworkType() == NetworkType.Advanced) {
String cidr = guestNetwork.getCidr();
if (cidr != null) {
dhcpRange = NetUtils.getDhcpRange(cidr);
}
}
StringBuilder buf = new StringBuilder();
boolean isRedundant = router.getIsRedundantRouter();
if (isRedundant) {
buf.append(" redundant_router=1");
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER);
try {
int priority = getUpdatedPriority(guestNetwork, routers, router);
router.setPriority(priority);
} catch (InsufficientVirtualNetworkCapcityException e) {
s_logger.error("Failed to get update priority!", e);
throw new CloudRuntimeException("Failed to get update priority!");
}
}
if (guestNic.isDefaultNic() && dc.getNetworkType() == NetworkType.Basic) {
long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask());
String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize);
if (cidr != null) {
dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize);
}
}
if (dhcpRange != null) {
buf.append(" dhcprange=" + dhcpRange);
}
if (isRedundant) {
Network net = _networkMgr.getNetwork(guestNic.getNetworkId());
buf.append(" guestgw=").append(net.getGateway());
String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask()));
buf.append(" guestbrd=").append(brd);
buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask()));
buf.append(" router_pr=").append(router.getPriority());
}
String domain = guestNetwork.getNetworkDomain();
if (domain != null) {
buf.append(" domain=" + domain);
}
boolean dnsProvided = false;
boolean dhcpProvided = false;
if (guestNic.getTrafficType() == TrafficType.Guest) {
//FiXME - for multiple guest network case this should be set individually
dnsProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dns, Provider.VirtualRouter);
dhcpProvided = _networkMgr.isProviderSupportServiceInNetwork(guestNic.getNetworkId(), Service.Dhcp, Provider.VirtualRouter);
}
/* If virtual router didn't provide DNS service but provide DHCP service, we need to override the DHCP response
* to return DNS server rather than
* virtual router itself. */
@ -1767,6 +1703,67 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
buf.append(" useextdns=true");
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Boot Args for " + profile + ": " + buf.toString());
}
return true;
}
protected StringBuilder createGuestBootLoadArgs(NicProfile guestNic, String defaultDns1,
String defaultDns2, DomainRouterVO router) {
long guestNetworkId = guestNic.getNetworkId();
NetworkVO guestNetwork = _networkDao.findById(guestNetworkId);
String dhcpRange = null;
DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId());
StringBuilder buf = new StringBuilder();
boolean isRedundant = router.getIsRedundantRouter();
if (isRedundant) {
buf.append(" redundant_router=1");
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(guestNetwork.getId(), Role.VIRTUAL_ROUTER);
try {
int priority = getUpdatedPriority(guestNetwork, routers, router);
router.setPriority(priority);
} catch (InsufficientVirtualNetworkCapcityException e) {
s_logger.error("Failed to get update priority!", e);
throw new CloudRuntimeException("Failed to get update priority!");
}
Network net = _networkMgr.getNetwork(guestNic.getNetworkId());
buf.append(" guestgw=").append(net.getGateway());
String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIp4Address()) | ~NetUtils.ip2Long(guestNic.getNetmask()));
buf.append(" guestbrd=").append(brd);
buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getNetmask()));
buf.append(" router_pr=").append(router.getPriority());
}
//setup network domain
String domain = guestNetwork.getNetworkDomain();
if (domain != null) {
buf.append(" domain=" + domain);
}
//setup dhcp range
if (dc.getNetworkType() == NetworkType.Basic) {
if (guestNic.isDefaultNic()) {
long cidrSize = NetUtils.getCidrSize(guestNic.getNetmask());
String cidr = NetUtils.getCidrSubNet(guestNic.getGateway(), cidrSize);
if (cidr != null) {
dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize);
}
}
} else if (dc.getNetworkType() == NetworkType.Advanced) {
String cidr = guestNetwork.getCidr();
if (cidr != null) {
dhcpRange = NetUtils.getDhcpRange(cidr);
}
}
if (dhcpRange != null) {
buf.append(" dhcprange=" + dhcpRange);
}
return buf;
}
@ -3055,4 +3052,20 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
return routerControlIpAddress;
}
@Override
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
//not supported
throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType());
}
@Override
public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
//not supported
throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
}
}

View File

@ -19,8 +19,8 @@ import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcVirtualNetworkApplianceService;
import com.cloud.user.Account;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.VirtualMachineProfile.Param;
@ -28,7 +28,7 @@ import com.cloud.vm.VirtualMachineProfile.Param;
/**
* @author Alena Prokharchyk
*/
public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager{
public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplianceManager, VpcVirtualNetworkApplianceService{
/**
* @param vpc
@ -44,16 +44,4 @@ public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplian
throws InsufficientCapacityException, ConcurrentOperationException,
ResourceUnavailableException;
/**
* @param network
* @return
*/
boolean addVpcElementToNetwork(Network network);
/**
* @param network
* @return
*/
boolean removeVpcElementFromNetwork(Network network);
}

View File

@ -12,6 +12,7 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.network.router;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -19,11 +20,19 @@ import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.agent.AgentManager.OnError;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.PlugNicCommand;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
import com.cloud.network.NetworkService;
@ -33,21 +42,25 @@ import com.cloud.network.VirtualRouterProvider.VirtualRouterProviderType;
import com.cloud.network.addr.PublicIp;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcVirtualNetworkApplianceService;
import com.cloud.network.vpc.Dao.VpcDao;
import com.cloud.network.vpc.Dao.VpcOfferingDao;
import com.cloud.user.Account;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Inject;
import com.cloud.utils.db.DB;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachineProfile.Param;
/**
* @author Alena Prokharchyk
*/
@Local(value = { VpcVirtualNetworkApplianceManager.class})
public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements VpcVirtualNetworkApplianceManager{
@Local(value = { VpcVirtualNetworkApplianceManager.class, VpcVirtualNetworkApplianceService.class,})
public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplianceManagerImpl implements
VpcVirtualNetworkApplianceManager{
private static final Logger s_logger = Logger.getLogger(VpcVirtualNetworkApplianceManagerImpl.class);
@Inject
@ -105,7 +118,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
PublicIp sourceNatIp = _networkMgr.assignSourceNatIpAddressToVpc(owner, vpc);
DomainRouterVO router = deployRouter(owner, dest, plan, params, true, null, false,
vrProvider, offeringId, sourceNatIp);
vrProvider, offeringId, sourceNatIp, vpc.getId());
routers.add(router);
} finally {
@ -126,60 +139,61 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
@Override
public boolean addVpcElementToNetwork(Network network) {
boolean success = true;
Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping plug nic part");
return success;
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
String networkDomain = network.getNetworkDomain();
String cidr = network.getCidr();
String dhcpRange = null;
if (cidr != null) {
dhcpRange = NetUtils.getDhcpRange(cidr);
}
List<? extends VirtualRouter> routers = _routerDao.listRoutersByVpcId(vpcId);
for (VirtualRouter router : routers) {
//1) Check if router is already a part of the network
if (_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) {
s_logger.debug("Router " + router + " is already part of the network " + network);
continue;
}
//2) Call plugNics in the network service
success = success && _ntwkService.addVmToNetwork(router, network);
boolean result = true;
//FIXME - Anthony, here I send plug nic command
try {
Map<PlugNicCommand.Param, String> params = new HashMap<PlugNicCommand.Param, String>();
params.put(PlugNicCommand.Param.NetworkDomain, networkDomain);
params.put(PlugNicCommand.Param.DhcpRange, dhcpRange);
PlugNicCommand plugNicCmd = new PlugNicCommand(vm, nic, params);
Commands cmds = new Commands(OnError.Stop);
cmds.addCommand("plugnic", plugNicCmd);
_agentMgr.send(dest.getHost().getId(), cmds);
Answer plugNicAnswer = cmds.getAnswer(Answer.class);
if (!(plugNicAnswer != null && plugNicAnswer.getResult())) {
s_logger.warn("Unable to plug nic for vm " + vm.getHostName());
result = false;
}
} catch (OperationTimedoutException e) {
throw new AgentUnavailableException("Unable to plug nic for vm " + vm.getHostName(), dest.getHost().getId(), e);
}
if (!success) {
s_logger.warn("Failed to plug nic in network " + network + " for virtual router in vpc id=" + vpcId);
} else {
s_logger.debug("Successfully plugged nic in network " + network + " for virtual router in vpc id=" + vpcId);
}
return success;
return result;
}
@Override
public boolean removeVpcElementFromNetwork(Network network) {
boolean success = true;
Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.debug("Network " + network + " doesn't belong to any vpc, so skipping unplug nic part");
return success;
}
public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
List<? extends VirtualRouter> routers = _routerDao.listRoutersByVpcId(vpcId);
for (VirtualRouter router : routers) {
//1) Check if router is already a part of the network
if (!_ntwkService.isVmPartOfNetwork(router.getId(), network.getId())) {
s_logger.debug("Router " + router + " is not a part the network " + network);
continue;
}
//2) Call unplugNics in the network service
success = success && _ntwkService.removeVmFromNetwork(router, network);
}
if (!success) {
s_logger.warn("Failed to unplug nic in network " + network + " for virtual router in vpc id=" + vpcId);
} else {
s_logger.debug("Successfully unplugged nic in network " + network + " for virtual router in vpc id=" + vpcId);
}
return success;
//FIXME - Anthony, add unplug nic agent command
return true;
}
@Override
public boolean addVmToNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
return _itMgr.addVmToNetwork(router, network);
}
@Override
public boolean removeVmFromNetwork(VirtualRouter router, Network network) {
return _itMgr.removeVmFromNetwork(router, network);
}
}

View File

@ -19,6 +19,7 @@ import java.util.Set;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.element.VpcProvider;
import com.cloud.network.vpc.VpcOffering.State;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
@ -70,6 +71,11 @@ public interface VpcManager extends VpcService{
* @return
* @throws ConcurrentOperationException
*/
void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, Account networkOwner, Vpc vpc) throws ConcurrentOperationException;
void validateGuestNtkwForVpc(NetworkOffering guestNtwkOff, String cidr, String networkDomain, Account networkOwner,
Vpc vpc) throws ConcurrentOperationException;
/**
* @return
*/
VpcProvider getVpcElement();
}

View File

@ -686,7 +686,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
try {
//1) CIDR is required
if (cidr == null) {
throw new InvalidParameterValueException("CIDR is required when create network for VPC");
throw new InvalidParameterValueException("Gateway/netmask are required when create network for VPC");
}
//2) Network cidr should be within vpcCidr
@ -738,7 +738,8 @@ public class VpcManagerImpl implements VpcManager, Manager{
}
}
private VpcProvider getVpcElement() {
@Override
public VpcProvider getVpcElement() {
if (vpcElement == null) {
vpcElement = ((VpcProvider)_ntwkMgr.getElementImplementingProvider(Provider.VPCVirtualRouter.getName()));
}

View File

@ -130,7 +130,6 @@ public class VpcOfferingVO implements VpcOffering{
return buf.append(id).append("-").append(name).append("]").toString();
}
public void setName(String name) {
this.name = name;
}

View File

@ -165,5 +165,11 @@ public class VpcVO implements Vpc, Identity {
public void setDisplayText(String displayText) {
this.displayText = displayText;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder("[VPC [");
return buf.append(id).append("-").append(name).append("]").toString();
}
}

View File

@ -1092,8 +1092,9 @@ public class ConfigurationServerImpl implements ConfigurationServer {
}
if (broadcastDomainType != null) {
NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId, domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null,
null, specifyIpRanges);
NetworkVO network = new NetworkVO(id, trafficType, mode, broadcastDomainType, networkOfferingId,
domainId, accountId, related, null, null, networkDomain, Network.GuestType.Shared, zoneId, null,
null, specifyIpRanges, null);
network.setGuruName(guruNames.get(network.getTrafficType()));
network.setDns1(zone.getDns1());
network.setDns2(zone.getDns2());

View File

@ -42,6 +42,8 @@ import com.cloud.agent.api.StartupStorageCommand;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.check.CheckSshAnswer;
import com.cloud.agent.api.check.CheckSshCommand;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.cluster.ClusterManager;
@ -69,6 +71,7 @@ import com.cloud.info.RunningHostInfoAgregator;
import com.cloud.info.RunningHostInfoAgregator.ZoneHostInfo;
import com.cloud.keystore.KeystoreManager;
import com.cloud.network.IPAddressVO;
import com.cloud.network.Network;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.Networks.TrafficType;
@ -1444,4 +1447,20 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
}
return null;
}
@Override
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
//not supported
throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType());
}
@Override
public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
//not supported
throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
}
}

View File

@ -3596,5 +3596,20 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
return vm;
}
@Override
public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
//not supported
throw new UnsupportedOperationException("Plug nic is not supported for vm of type " + vm.getType());
}
@Override
public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
//not supported
throw new UnsupportedOperationException("Unplug nic is not supported for vm of type " + vm.getType());
}
}

View File

@ -13,9 +13,15 @@
package com.cloud.vm;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientNetworkCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network;
/**
* A VirtualMachineGuru knows how to process a certain type of virtual machine.
@ -68,4 +74,34 @@ public interface VirtualMachineGuru<T extends VirtualMachine> {
* @return id if the handler works for this vm and can parse id. null if not.
*/
Long convertToId(String vmName);
/**
* Prepare for a nic to be plugged into the network.
* @param network
* @param nic
* @param vm
* @param context
* @param dest TODO
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
* @throws InsufficientNetworkCapacityException
*/
boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException;
/**
* A nic is unplugged from this network.
* @param network
* @param nic
* @param vm
* @param context
* @param dest TODO
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
*/
boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException;
}

View File

@ -15,6 +15,7 @@ package com.cloud.vm;
import java.util.List;
import java.util.Map;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.AgentUnavailableException;
@ -26,6 +27,7 @@ import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.exception.VirtualMachineMigrationException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.Network;
import com.cloud.network.NetworkVO;
import com.cloud.offering.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
@ -132,4 +134,22 @@ public interface VirtualMachineManager extends Manager {
*/
boolean upgradeVmDb(long vmId, long serviceOfferingId);
/**
* @param vm
* @param network
* @return
* @throws ConcurrentOperationException
* @throws ResourceUnavailableException
* @throws InsufficientCapacityException
*/
boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException;
/**
* @param vm
* @param network
* @return
*/
boolean removeVmFromNetwork(VirtualMachine vm, Network network);
}

View File

@ -57,6 +57,7 @@ import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.StartupRoutingCommand.VmState;
import com.cloud.agent.api.StopAnswer;
import com.cloud.agent.api.StopCommand;
import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.manager.Commands;
import com.cloud.agent.manager.allocator.HostAllocator;
@ -103,6 +104,7 @@ import com.cloud.hypervisor.HypervisorGuruManager;
import com.cloud.network.Network;
import com.cloud.network.NetworkManager;
import com.cloud.network.NetworkVO;
import com.cloud.network.dao.NetworkDao;
import com.cloud.offering.ServiceOffering;
import com.cloud.org.Cluster;
import com.cloud.resource.ResourceManager;
@ -217,6 +219,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
protected StoragePoolDao _storagePoolDao;
@Inject
protected HypervisorGuruManager _hvGuruMgr;
@Inject
protected NetworkDao _networkDao;
@Inject(adapter = DeploymentPlanner.class)
protected Adapters<DeploymentPlanner> _planners;
@ -748,11 +752,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
reuseVolume = true;
}
VirtualMachineTO vmTO = null;
Commands cmds = null;
vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, ctx);
vmTO = hvGuru.implement(vmProfile);
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
cmds = new Commands(OnError.Stop);
cmds.addCommand(new StartCommand(vmTO));
@ -2426,4 +2429,53 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
vmForUpdate.setServiceOfferingId(newSvcOff.getId());
return _vmDao.update(vmId, vmForUpdate);
}
@Override
public boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
NetworkVO networkVO = _networkDao.findById(network.getId());
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
null, null, null);
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
Host host = _hostDao.findById(vm.getHostId());
DeployDestination dest = new DeployDestination(dc, null, null, host);
s_logger.debug("Adding vm " + vm + " to network " + network);
//1) allocate nic
NicProfile nic = _networkMgr.allocateNic(null, network, false,
100, vmProfile).first();
//2) Prepare nic
nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
//3) plug the nic to the vm
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
//4) Convert vmProfile to vmTO
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
//5) Convert nicProfile to NicTO
NicTO nicTO = hvGuru.toNicTO(nic);
return vmGuru.plugNic(network, nicTO, vmTO, context, null);
}
@Override
public boolean removeVmFromNetwork(VirtualMachine vm, Network network) {
//1) TODO - release the nic
//2) TODO - unplug the nic
return true;
}
}

View File

@ -111,4 +111,10 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
* @return
*/
List<DomainRouterVO> listRoutersByVpcId(long vpcId);
/**
* @param routerId
* @param guestNetwork
*/
void addRouterToNetwork(DomainRouterVO router, Network guestNetwork);
}

View File

@ -47,7 +47,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
HostDaoImpl _hostsDao = ComponentLocator.inject(HostDaoImpl.class);
RouterNetworkDaoImpl _routerNetworkDao = ComponentLocator.inject(RouterNetworkDaoImpl.class);
UserStatisticsDaoImpl _userStatsDao = ComponentLocator.inject(UserStatisticsDaoImpl.class);
protected final SearchBuilder<DomainRouterVO> VpcSearch;
protected DomainRouterDaoImpl() {
AllFieldsSearch = createSearchBuilder();
@ -65,6 +65,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
AllFieldsSearch.and("elementId", AllFieldsSearch.entity().getElementId(), Op.EQ);
AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ);
AllFieldsSearch.done();
VpcSearch = createSearchBuilder();
VpcSearch.and("role", VpcSearch.entity().getRole(), Op.EQ);
VpcSearch.and("vpcId", VpcSearch.entity().getVpcId(), Op.EQ);
VpcSearch.done();
IdNetworkIdStatesSearch = createSearchBuilder();
IdNetworkIdStatesSearch.and("id", IdNetworkIdStatesSearch.entity().getId(), Op.EQ);
@ -259,15 +264,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
if (guestNetworks != null && !guestNetworks.isEmpty()) {
// 2) add router to the network
for (Network guestNetwork : guestNetworks) {
addRouterToNetwork(router.getId(), guestNetwork);
// 3) create user stats entry
UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(),
guestNetwork.getId(), null, router.getId(), router.getType().toString());
if (stats == null) {
stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(),
router.getType().toString(), guestNetwork.getId());
_userStatsDao.persist(stats);
}
addRouterToNetwork(router, guestNetwork);
}
}
@ -275,10 +272,21 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
return newRouter;
}
protected void addRouterToNetwork(long routerId, Network guestNetwork) {
RouterNetworkVO routerNtwkMap = new RouterNetworkVO(routerId, guestNetwork.getId(), guestNetwork.getGuestType());
@Override
@DB
public void addRouterToNetwork(DomainRouterVO router, Network guestNetwork) {
//1) add router to network
RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType());
_routerNetworkDao.persist(routerNtwkMap);
//2) create user stats entry for the network
UserStatisticsVO stats = _userStatsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(),
guestNetwork.getId(), null, router.getId(), router.getType().toString());
if (stats == null) {
stats = new UserStatisticsVO(router.getAccountId(), router.getDataCenterIdToDeployIn(), null, router.getId(),
router.getType().toString(), guestNetwork.getId());
_userStatsDao.persist(stats);
}
}
@Override
@ -288,7 +296,7 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
@Override
public List<DomainRouterVO> listRoutersByVpcId(long vpcId) {
SearchCriteria<DomainRouterVO> sc = AllFieldsSearch.create();
SearchCriteria<DomainRouterVO> sc = VpcSearch.create();
sc.setParameters("vpcId", vpcId);
sc.setParameters("role", Role.VIRTUAL_ROUTER);
return listBy(sc);

View File

@ -201,7 +201,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
@Override
public List<NetworkVO> setupNetwork(Account owner, NetworkOfferingVO offering, Network predefined, DeploymentPlan plan, String name, String displayText, boolean errorIfAlreadySetup, Long domainId,
ACLType aclType, Boolean subdomainAccess) throws ConcurrentOperationException {
ACLType aclType, Boolean subdomainAccess, Long vpcId) throws ConcurrentOperationException {
// TODO Auto-generated method stub
return null;
}

View File

@ -3,7 +3,7 @@
# the following two variables are used by the target "waf dist"
# if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog
VERSION = '3.0.3.2012-05-22T23:46:23Z'
VERSION = '3.0.3.2012-05-23T23:17:18Z'
APPNAME = 'cloud'
import shutil,os