mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Added support for network shutdown in VPC guest networks
This commit is contained in:
parent
d9fd7e02a5
commit
f28cefc4c3
24
api/src/com/cloud/agent/api/PlugNicAnswer.java
Normal file
24
api/src/com/cloud/agent/api/PlugNicAnswer.java
Normal file
@ -0,0 +1,24 @@
|
||||
// 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;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
public class PlugNicAnswer extends Answer{
|
||||
public PlugNicAnswer() {}
|
||||
|
||||
public PlugNicAnswer(PlugNicCommand cmd, boolean success, String result) {
|
||||
super(cmd, success, result);
|
||||
}
|
||||
}
|
||||
@ -34,6 +34,10 @@ public class PlugNicCommand extends Command {
|
||||
return vm;
|
||||
}
|
||||
|
||||
public NicTO getNic() {
|
||||
return nic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
|
||||
24
api/src/com/cloud/agent/api/UnPlugNicAnswer.java
Normal file
24
api/src/com/cloud/agent/api/UnPlugNicAnswer.java
Normal file
@ -0,0 +1,24 @@
|
||||
// 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;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
public class UnPlugNicAnswer extends Answer{
|
||||
public UnPlugNicAnswer() {}
|
||||
|
||||
public UnPlugNicAnswer(UnPlugNicCommand cmd, boolean success, String result) {
|
||||
super(cmd, success, result);
|
||||
}
|
||||
}
|
||||
45
api/src/com/cloud/agent/api/UnPlugNicCommand.java
Normal file
45
api/src/com/cloud/agent/api/UnPlugNicCommand.java
Normal file
@ -0,0 +1,45 @@
|
||||
// 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 com.cloud.agent.api.to.NicTO;
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
|
||||
/**
|
||||
* @author Alena Prokharchyk
|
||||
*/
|
||||
public class UnPlugNicCommand extends Command{
|
||||
VirtualMachineTO vm;
|
||||
NicTO nic;
|
||||
|
||||
public VirtualMachineTO getVirtualMachine() {
|
||||
return vm;
|
||||
}
|
||||
|
||||
public NicTO getNic() {
|
||||
return nic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected UnPlugNicCommand() {
|
||||
}
|
||||
|
||||
public UnPlugNicCommand(VirtualMachineTO vm, NicTO nic) {
|
||||
this.vm = vm;
|
||||
this.nic = nic;
|
||||
}
|
||||
}
|
||||
@ -35,6 +35,14 @@ public interface VpcProvider extends NetworkElement{
|
||||
*/
|
||||
boolean startVpc(Vpc vpc, DeployDestination dest, ReservationContext context)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
|
||||
|
||||
/**
|
||||
* @param vpc
|
||||
* @return
|
||||
* @throws ConcurrentOperationException
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
boolean stopVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -12,11 +12,8 @@
|
||||
// Automatically generated by addcopyright.py at 04/03/2012
|
||||
package com.cloud.network.vpc;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.acl.ControlledEntity;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.Network.Service;
|
||||
|
||||
|
||||
/**
|
||||
@ -47,5 +44,10 @@ public interface Vpc extends ControlledEntity{
|
||||
long getVpcOfferingId();
|
||||
|
||||
String getDisplayText();
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
String getNetworkDomain();
|
||||
|
||||
}
|
||||
|
||||
@ -38,6 +38,8 @@ public interface VpcVirtualNetworkApplianceService {
|
||||
* @param router
|
||||
* @param network
|
||||
* @return
|
||||
* @throws ResourceUnavailableException
|
||||
* @throws ConcurrentOperationException
|
||||
*/
|
||||
boolean removeVmFromNetwork(VirtualRouter router, Network network);
|
||||
boolean removeVmFromNetwork(VirtualRouter router, Network network) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
}
|
||||
|
||||
@ -49,6 +49,7 @@ import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
@ -372,4 +373,22 @@ public interface NetworkManager extends NetworkService {
|
||||
*/
|
||||
NicProfile prepareNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, DeployDestination dest, ReservationContext context, long nicId, NetworkVO network) throws InsufficientVirtualNetworkCapcityException,
|
||||
InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException;
|
||||
|
||||
|
||||
/**
|
||||
* @param vmProfile
|
||||
* @param network
|
||||
* @return TODO
|
||||
* @throws ConcurrentOperationException
|
||||
* @throws ResourceUnavailableException
|
||||
*/
|
||||
NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
|
||||
/**
|
||||
* @param vm
|
||||
* @param network
|
||||
*/
|
||||
void removeNic(VirtualMachineProfile<? extends VMInstanceVO> vm, Network network);
|
||||
|
||||
}
|
||||
|
||||
@ -2022,11 +2022,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
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);
|
||||
@ -2090,7 +2093,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
Integer networkRate = getNetworkRate(network.getId(), vm.getId());
|
||||
|
||||
NetworkGuru guru = _networkGurus.get(network.getGuruName());
|
||||
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
|
||||
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), networkRate,
|
||||
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
|
||||
guru.updateNicProfile(profile, network);
|
||||
vm.addNic(profile);
|
||||
}
|
||||
@ -2105,6 +2109,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
releaseNic(vmProfile, nic, network);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NicProfile releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NetworkVO network)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vmProfile.getId());
|
||||
releaseNic(vmProfile, nic, network);
|
||||
|
||||
NicProfile profile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), null,
|
||||
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
|
||||
return profile;
|
||||
}
|
||||
|
||||
|
||||
protected void releaseNic(VirtualMachineProfile<? extends VMInstanceVO> vmProfile, NicVO nic, NetworkVO network)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
@ -2283,15 +2299,27 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
|
||||
List<NicVO> nics = _nicDao.listByVmId(vm.getId());
|
||||
for (NicVO nic : nics) {
|
||||
nic.setState(Nic.State.Deallocating);
|
||||
_nicDao.update(nic.getId(), nic);
|
||||
NetworkVO network = _networksDao.findById(nic.getNetworkId());
|
||||
NicProfile profile = new NicProfile(nic, network, null, null, null, isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
|
||||
NetworkGuru guru = _networkGurus.get(network.getGuruName());
|
||||
guru.deallocate(network, profile, vm);
|
||||
_nicDao.remove(nic.getId());
|
||||
removeNic(vm, nic);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNic(VirtualMachineProfile<? extends VMInstanceVO> vm, Network network) {
|
||||
NicVO nic = _nicDao.findByInstanceIdAndNetworkId(network.getId(), vm.getVirtualMachine().getId());
|
||||
removeNic(vm, nic);
|
||||
}
|
||||
|
||||
protected void removeNic(VirtualMachineProfile<? extends VMInstanceVO> vm, NicVO nic) {
|
||||
nic.setState(Nic.State.Deallocating);
|
||||
_nicDao.update(nic.getId(), nic);
|
||||
NetworkVO network = _networksDao.findById(nic.getNetworkId());
|
||||
NicProfile profile = new NicProfile(nic, network, null, null, null,
|
||||
isSecurityGroupSupportedInNetwork(network), getNetworkTag(vm.getHypervisorType(), network));
|
||||
NetworkGuru guru = _networkGurus.get(network.getGuruName());
|
||||
guru.deallocate(network, profile, vm);
|
||||
_nicDao.remove(nic.getId());
|
||||
s_logger.debug("Removed nic id=" + nic.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void expungeNics(VirtualMachineProfile<? extends VMInstanceVO> vm) {
|
||||
@ -2629,21 +2657,18 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
||||
PhysicalNetwork pNtwk, long zoneId, ACLType aclType, Boolean subdomainAccess, long vpcId)
|
||||
throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
|
||||
|
||||
Vpc vpc = _vpcMgr.getVpc(vpcId);
|
||||
//1) Validate if network can be created for VPC
|
||||
_vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner,
|
||||
_vpcMgr.getVpc(vpcId));
|
||||
_vpcMgr.validateGuestNtkwForVpc(_configMgr.getNetworkOffering(ntwkOffId), cidr, networkDomain, owner, vpc);
|
||||
|
||||
if (networkDomain == null) {
|
||||
networkDomain = vpc.getNetworkDomain();
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ import java.util.List;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.GenericSearchBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
|
||||
@ -25,6 +26,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
|
||||
*/
|
||||
public class RouterNetworkDaoImpl extends GenericDaoBase<RouterNetworkVO, Long> implements GenericDao<RouterNetworkVO, Long>{
|
||||
protected final GenericSearchBuilder<RouterNetworkVO, Long> RouterNetworksSearch;
|
||||
protected final SearchBuilder<RouterNetworkVO> AllFieldsSearch;
|
||||
|
||||
public RouterNetworkDaoImpl() {
|
||||
super();
|
||||
@ -33,6 +35,11 @@ public class RouterNetworkDaoImpl extends GenericDaoBase<RouterNetworkVO, Long>
|
||||
RouterNetworksSearch.selectField(RouterNetworksSearch.entity().getNetworkId());
|
||||
RouterNetworksSearch.and("routerId", RouterNetworksSearch.entity().getRouterId(), Op.EQ);
|
||||
RouterNetworksSearch.done();
|
||||
|
||||
AllFieldsSearch = createSearchBuilder();
|
||||
AllFieldsSearch.and("routerId", AllFieldsSearch.entity().getRouterId(), Op.EQ);
|
||||
AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
}
|
||||
|
||||
public List<Long> getRouterNetworks(long routerId) {
|
||||
@ -40,4 +47,12 @@ public class RouterNetworkDaoImpl extends GenericDaoBase<RouterNetworkVO, Long>
|
||||
sc.setParameters("routerId", routerId);
|
||||
return customSearch(sc, null);
|
||||
}
|
||||
|
||||
public RouterNetworkVO findByRouterAndNetwork (long routerId, long networkId) {
|
||||
SearchCriteria<RouterNetworkVO> sc = AllFieldsSearch.create();
|
||||
sc.setParameters("routerId", routerId);
|
||||
sc.setParameters("networkId", networkId);
|
||||
return findOneBy(sc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -65,4 +65,8 @@ public class RouterNetworkVO{
|
||||
public Network.GuestType getGuestType() {
|
||||
return guestType;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.dc.DataCenter;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
@ -33,9 +34,11 @@ 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.VpcService;
|
||||
import com.cloud.network.vpc.VpcVirtualNetworkApplianceService;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.vm.DomainRouterVO;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
@ -51,6 +54,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
||||
NetworkService _ntwkService;
|
||||
@Inject
|
||||
VpcVirtualNetworkApplianceService _vpcElementService;
|
||||
@Inject
|
||||
VpcService _vpcService;
|
||||
|
||||
|
||||
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
|
||||
@ -70,6 +75,19 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
List<DomainRouterVO> routers = _routerDao.listRoutersByVpcId(vpc.getId());
|
||||
if (routers == null || routers.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
boolean result = true;
|
||||
for (DomainRouterVO router : routers) {
|
||||
result = result && (_routerMgr.destroyRouter(router.getId()) != null);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context)
|
||||
throws ResourceUnavailableException, ConcurrentOperationException,
|
||||
@ -81,26 +99,34 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean success = super.implement(network, offering, dest, context);
|
||||
Vpc vpc = _vpcService.getVpc(vpcId);
|
||||
|
||||
if (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 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);
|
||||
}
|
||||
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
|
||||
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
|
||||
|
||||
List<DomainRouterVO> routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params);
|
||||
if ((routers == null) || (routers.size() == 0)) {
|
||||
throw new ResourceUnavailableException("Can't find at least one running router!",
|
||||
DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
||||
boolean success = true;
|
||||
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;
|
||||
}
|
||||
@ -116,26 +142,35 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean success = super.prepare(network, nic, vm, dest, context);
|
||||
Vpc vpc = _vpcService.getVpc(vpcId);
|
||||
|
||||
if (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 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);
|
||||
}
|
||||
Map<VirtualMachineProfile.Param, Object> params = new HashMap<VirtualMachineProfile.Param, Object>(1);
|
||||
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
|
||||
|
||||
List<DomainRouterVO> routers = _vpcRouterMgr.deployVirtualRouterInVpc(vpc, dest, _accountMgr.getAccount(vpc.getAccountId()), params);
|
||||
if ((routers == null) || (routers.size() == 0)) {
|
||||
throw new ResourceUnavailableException("Can't find at least one running router!",
|
||||
DataCenter.class, network.getDataCenterId());
|
||||
}
|
||||
|
||||
boolean success = true;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,6 @@
|
||||
// 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;
|
||||
|
||||
@ -20,19 +19,13 @@ 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;
|
||||
@ -152,27 +145,34 @@ VpcVirtualNetworkApplianceManager{
|
||||
|
||||
boolean result = true;
|
||||
|
||||
//add router to network
|
||||
DomainRouterVO router = _routerDao.findById(vm.getId());
|
||||
s_logger.debug("Adding router " + router + " to network " + network);
|
||||
_routerDao.addRouterToNetwork(router, network);
|
||||
|
||||
|
||||
//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);
|
||||
}
|
||||
// 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);
|
||||
//
|
||||
// PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.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() + " in network " + network,
|
||||
// dest.getHost().getId(), e);
|
||||
// }
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -182,7 +182,30 @@ VpcVirtualNetworkApplianceManager{
|
||||
ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
|
||||
//FIXME - Anthony, add unplug nic agent command
|
||||
return true;
|
||||
boolean result = true;
|
||||
// try {
|
||||
// UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(vm, nic);
|
||||
// Commands cmds = new Commands(OnError.Stop);
|
||||
// cmds.addCommand("unplugnic", unplugNicCmd);
|
||||
// _agentMgr.send(dest.getHost().getId(), cmds);
|
||||
//
|
||||
// UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class);
|
||||
// if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) {
|
||||
// s_logger.warn("Unable to unplug nic from vm " + vm.getHostName());
|
||||
// result = false;
|
||||
// }
|
||||
//
|
||||
// } catch (OperationTimedoutException e) {
|
||||
// throw new AgentUnavailableException("Unable to unplug nic from vm " + vm.getHostName() + " from network " + network,
|
||||
// dest.getHost().getId(), e);
|
||||
// }
|
||||
//
|
||||
if (result) {
|
||||
s_logger.debug("Removing router " + vm.getHostName() + " from network " + network);
|
||||
_routerDao.removeRouterFromNetwork(vm.getId(), network.getId());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,7 +216,8 @@ VpcVirtualNetworkApplianceManager{
|
||||
|
||||
|
||||
@Override
|
||||
public boolean removeVmFromNetwork(VirtualRouter router, Network network) {
|
||||
public boolean removeVmFromNetwork(VirtualRouter router, Network network)
|
||||
throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
return _itMgr.removeVmFromNetwork(router, network);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,4 +172,8 @@ public class VpcVO implements Vpc, Identity {
|
||||
return buf.append(id).append("-").append(name).append("]").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNetworkDomain() {
|
||||
return networkDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,7 +149,9 @@ public interface VirtualMachineManager extends Manager {
|
||||
* @param vm
|
||||
* @param network
|
||||
* @return
|
||||
* @throws ResourceUnavailableException
|
||||
* @throws ConcurrentOperationException
|
||||
*/
|
||||
boolean removeVmFromNetwork(VirtualMachine vm, Network network);
|
||||
boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException;
|
||||
|
||||
}
|
||||
|
||||
@ -2431,6 +2431,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException,
|
||||
ResourceUnavailableException, InsufficientCapacityException {
|
||||
|
||||
@ -2448,34 +2449,80 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
|
||||
s_logger.debug("Adding vm " + vm + " to network " + network);
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
//1) allocate nic
|
||||
NicProfile nic = _networkMgr.allocateNic(null, network, false,
|
||||
100, vmProfile).first();
|
||||
|
||||
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
|
||||
|
||||
//2) Prepare nic
|
||||
nic = _networkMgr.prepareNic(vmProfile, dest, context, nic.getId(), networkVO);
|
||||
|
||||
//3) plug the nic to the vm
|
||||
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
|
||||
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
|
||||
|
||||
//4) Convert vmProfile to vmTO
|
||||
txn.commit();
|
||||
|
||||
//3) Convert vmProfile to vmTO
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
|
||||
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
|
||||
|
||||
//5) Convert nicProfile to NicTO
|
||||
//4) Convert nicProfile to NicTO
|
||||
NicTO nicTO = hvGuru.toNicTO(nic);
|
||||
|
||||
return vmGuru.plugNic(network, nicTO, vmTO, context, null);
|
||||
//5) plug the nic to the vm
|
||||
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
|
||||
|
||||
if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) {
|
||||
s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now");
|
||||
return true;
|
||||
} else {
|
||||
s_logger.warn("Failed to plug nic to the vm " + vm + " in network " + network);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeVmFromNetwork(VirtualMachine vm, Network network) {
|
||||
//1) TODO - release the nic
|
||||
public boolean removeVmFromNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
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);
|
||||
|
||||
//1) Release the nic
|
||||
NicProfile nic = _networkMgr.releaseNic(vmProfile, networkVO);
|
||||
|
||||
//2) TODO - unplug the nic
|
||||
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
|
||||
|
||||
return true;
|
||||
//3) Convert vmProfile to vmTO
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
|
||||
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
|
||||
|
||||
//4) Convert nicProfile to NicTO
|
||||
NicTO nicTO = hvGuru.toNicTO(nic);
|
||||
|
||||
boolean result = vmGuru.unplugNic(network, nicTO, vmTO, context, dest);
|
||||
//5) Unplug the nic
|
||||
if (result) {
|
||||
s_logger.debug("Nic is unplugged successfully for vm " + vm + " in network " + network );
|
||||
} else {
|
||||
s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network);
|
||||
return false;
|
||||
}
|
||||
|
||||
//6) Remove the nic
|
||||
_networkMgr.removeNic(vmProfile, network);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -117,4 +117,10 @@ public interface DomainRouterDao extends GenericDao<DomainRouterVO, Long> {
|
||||
* @param guestNetwork
|
||||
*/
|
||||
void addRouterToNetwork(DomainRouterVO router, Network guestNetwork);
|
||||
|
||||
/**
|
||||
* @param routerId
|
||||
* @param guestNetworkId
|
||||
*/
|
||||
void removeRouterFromNetwork(long routerId, long guestNetworkId);
|
||||
}
|
||||
|
||||
@ -275,7 +275,8 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
||||
@Override
|
||||
@DB
|
||||
public void addRouterToNetwork(DomainRouterVO router, Network guestNetwork) {
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
//1) add router to network
|
||||
RouterNetworkVO routerNtwkMap = new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType());
|
||||
_routerNetworkDao.persist(routerNtwkMap);
|
||||
@ -287,6 +288,13 @@ public class DomainRouterDaoImpl extends GenericDaoBase<DomainRouterVO, Long> im
|
||||
router.getType().toString(), guestNetwork.getId());
|
||||
_userStatsDao.persist(stats);
|
||||
}
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRouterFromNetwork(long routerId, long guestNetworkId) {
|
||||
RouterNetworkVO routerNtwkMap = _routerNetworkDao.findByRouterAndNetwork(routerId, guestNetworkId);
|
||||
_routerNetworkDao.remove(routerNtwkMap.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -29,6 +29,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;
|
||||
@ -235,4 +236,22 @@ public class MockVirtualMachineManagerImpl implements VirtualMachineManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.vm.VirtualMachineManager#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network)
|
||||
*/
|
||||
@Override
|
||||
public boolean addVmToNetwork(VirtualMachine vm, Network network) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.vm.VirtualMachineManager#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network)
|
||||
*/
|
||||
@Override
|
||||
public boolean removeVmFromNetwork(VirtualMachine vm, Network network) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
2
wscript
2
wscript
@ -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-23T23:17:18Z'
|
||||
VERSION = '3.0.3.2012-05-24T22:26:07Z'
|
||||
APPNAME = 'cloud'
|
||||
|
||||
import shutil,os
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user