本文整理汇总了Java中com.cloud.network.dao.IPAddressVO.setAssociatedWithNetworkId方法的典型用法代码示例。如果您正苦于以下问题:Java IPAddressVO.setAssociatedWithNetworkId方法的具体用法?Java IPAddressVO.setAssociatedWithNetworkId怎么用?Java IPAddressVO.setAssociatedWithNetworkId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.cloud.network.dao.IPAddressVO
的用法示例。
在下文中一共展示了IPAddressVO.setAssociatedWithNetworkId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyIpAssociations
import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@Override
public boolean applyIpAssociations(final Network network, final boolean continueOnError) throws ResourceUnavailableException {
final List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
boolean success = true;
// CloudStack will take a lazy approach to associate an acquired public IP to a network service provider as
// it will not know what service an acquired IP will be used for. An IP is actually associated with a provider when first
// rule is applied. Similarly when last rule on the acquired IP is revoked, IP is not associated with any provider
// but still be associated with the account. At this point just mark IP as allocated or released.
for (final IPAddressVO addr : userIps) {
if (addr.getState() == IpAddress.State.Allocating) {
addr.setAssociatedWithNetworkId(network.getId());
markPublicIpAsAllocated(addr);
} else if (addr.getState() == IpAddress.State.Releasing) {
// Cleanup all the resources for ip address if there are any, and only then un-assign ip in the system
if (cleanupIpResources(addr.getId(), Account.ACCOUNT_ID_SYSTEM, _accountMgr.getSystemAccount())) {
_ipAddressDao.unassignIpAddress(addr.getId());
} else {
success = false;
s_logger.warn("Failed to release resources for ip address id=" + addr.getId());
}
}
}
return success;
}
示例2: applyIpAssociations
import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@Override
public boolean applyIpAssociations(Network network, boolean continueOnError) throws ResourceUnavailableException {
List<IPAddressVO> userIps = _ipAddressDao.listByAssociatedNetwork(network.getId(), null);
boolean success = true;
// CloudStack will take a lazy approach to associate an acquired public IP to a network service provider as
// it will not know what service an acquired IP will be used for. An IP is actually associated with a provider when first
// rule is applied. Similarly when last rule on the acquired IP is revoked, IP is not associated with any provider
// but still be associated with the account. At this point just mark IP as allocated or released.
for (IPAddressVO addr : userIps) {
if (addr.getState() == IpAddress.State.Allocating) {
addr.setAssociatedWithNetworkId(network.getId());
markPublicIpAsAllocated(addr);
} else if (addr.getState() == IpAddress.State.Releasing) {
// Cleanup all the resources for ip address if there are any, and only then un-assign ip in the system
if (cleanupIpResources(addr.getId(), Account.ACCOUNT_ID_SYSTEM, _accountMgr.getSystemAccount())) {
_ipAddressDao.unassignIpAddress(addr.getId());
} else {
success = false;
s_logger.warn("Failed to release resources for ip address id=" + addr.getId());
}
}
}
return success;
}
示例3: assignUserNicsToNewNetwork
import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
/**
* reassigns the nics to the new network from the src network.
* @param srcNetworkId
* @param dstNetworkId
*/
private void assignUserNicsToNewNetwork(long srcNetworkId, long dstNetworkId) {
List<NicVO> nics = _nicDao.listByNetworkId(srcNetworkId);
for (NicVO nic : nics) {
if (nic.getVmType() == VirtualMachine.Type.User) {
nic.setNetworkId(dstNetworkId);
_nicDao.persist(nic);
//update the number of active nics in both networks after migration.
if (nic.getState() == Nic.State.Reserved) {
_networksDao.changeActiveNicsBy(srcNetworkId, -1);
_networksDao.changeActiveNicsBy(dstNetworkId, 1);
}
}
}
List<? extends IPAddressVO> publicIps = _ipAddressDao.listByAssociatedNetwork(srcNetworkId, null);
for (IPAddressVO ipAddress : publicIps) {
ipAddress.setAssociatedWithNetworkId(dstNetworkId);
_ipAddressDao.persist(ipAddress);
}
}
示例4: reapplyPublicIps
import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
private void reapplyPublicIps(Network networkInOldPhysicalNetwork, Network networkInNewPhysicalNet) {
CallContext ctx = CallContext.current();
long callerUserId = ctx.getCallingUserId();
Account caller = ctx.getCallingAccount();
AccountVO networkAccount = _accountDao.findById(networkInNewPhysicalNet.getAccountId());
List<? extends IPAddressVO> staticNatIps = _ipAddressDao.listStaticNatPublicIps(networkInOldPhysicalNetwork.getId());
List<String> providers = _networkOfferingServiceDao.listProvidersForServiceForNetworkOffering(networkInNewPhysicalNet.getNetworkOfferingId(), Network.Service.SourceNat);
boolean isSrcNatIpNeeded = providers.stream().anyMatch(provider -> provider.contains(Network.Provider.VirtualRouter.getName()));
for (IPAddressVO ipAddress : staticNatIps) {
if (!ipAddress.isSourceNat() || isSrcNatIpNeeded) {
ipAddress.setAssociatedWithNetworkId(networkInNewPhysicalNet.getId());
_ipAddressDao.persist(ipAddress);
} else {
_ipAddressManager.disassociatePublicIpAddress(ipAddress.getId(), callerUserId, caller);
}
}
_rulesMgr.applyStaticNatsForNetwork(networkInNewPhysicalNet.getId(), false, networkAccount);
}
示例5: unassignIPFromVpcNetwork
import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@Override
public void unassignIPFromVpcNetwork(final long ipId, final long networkId) {
final IPAddressVO ip = _ipAddressDao.findById(ipId);
if (isIpAllocatedToVpc(ip)) {
return;
}
if (ip == null || ip.getVpcId() == null) {
return;
}
s_logger.debug("Releasing VPC ip address " + ip + " from vpc network id=" + networkId);
final long vpcId = ip.getVpcId();
final boolean success;
try {
// unassign ip from the VPC router
success = _ipAddrMgr.applyIpAssociations(_ntwkModel.getNetwork(networkId), true);
} catch (final ResourceUnavailableException ex) {
throw new CloudRuntimeException("Failed to apply ip associations for network id=" + networkId
+ " as a part of unassigning ip " + ipId + " from vpc", ex);
}
if (success) {
ip.setAssociatedWithNetworkId(null);
_ipAddressDao.update(ipId, ip);
s_logger.debug("IP address " + ip + " is no longer associated with the network inside vpc id=" + vpcId);
} else {
throw new CloudRuntimeException("Failed to apply ip associations for network id=" + networkId
+ " as a part of unassigning ip " + ipId + " from vpc");
}
s_logger.debug("Successfully released VPC ip address " + ip + " back to VPC pool ");
}
示例6: unassignIPFromVpcNetwork
import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
@Override
public void unassignIPFromVpcNetwork(final long ipId, final long networkId) {
final IPAddressVO ip = _ipAddressDao.findById(ipId);
if (isIpAllocatedToVpc(ip)) {
return;
}
if (ip == null || ip.getVpcId() == null) {
return;
}
s_logger.debug("Releasing VPC ip address " + ip + " from vpc network id=" + networkId);
final long vpcId = ip.getVpcId();
boolean success = false;
try {
// unassign ip from the VPC router
success = _ipAddrMgr.applyIpAssociations(_ntwkModel.getNetwork(networkId), true);
} catch (final ResourceUnavailableException ex) {
throw new CloudRuntimeException("Failed to apply ip associations for network id=" + networkId + " as a part of unassigning ip " + ipId + " from vpc", ex);
}
if (success) {
ip.setAssociatedWithNetworkId(null);
_ipAddressDao.update(ipId, ip);
s_logger.debug("IP address " + ip + " is no longer associated with the network inside vpc id=" + vpcId);
} else {
throw new CloudRuntimeException("Failed to apply ip associations for network id=" + networkId + " as a part of unassigning ip " + ipId + " from vpc");
}
s_logger.debug("Successfully released VPC ip address " + ip + " back to VPC pool ");
}
示例7: releaseIp
import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
private void releaseIp(final long ipId, final long userId, final Account caller) {
s_logger.info("ELB: Release public IP for loadbalancing " + ipId);
final IPAddressVO ipvo = _ipAddressDao.findById(ipId);
ipvo.setAssociatedWithNetworkId(null);
_ipAddressDao.update(ipvo.getId(), ipvo);
_ipAddrMgr.disassociatePublicIpAddress(ipId, userId, caller);
_ipAddressDao.unassignIpAddress(ipId);
}
示例8: cleanupVpcResources
import com.cloud.network.dao.IPAddressVO; //导入方法依赖的package包/类
public boolean cleanupVpcResources(final long vpcId, final Account caller, final long callerUserId) throws ResourceUnavailableException, ConcurrentOperationException {
s_logger.debug("Cleaning up resources for vpc id=" + vpcId);
boolean success = true;
// 1) Remove VPN connections and VPN gateway
s_logger.debug("Cleaning up existed site to site VPN connections");
_s2sVpnMgr.cleanupVpnConnectionByVpc(vpcId);
s_logger.debug("Cleaning up existed site to site VPN gateways");
_s2sVpnMgr.cleanupVpnGatewayByVpc(vpcId);
// 2) release all ip addresses
final List<IPAddressVO> ipsToRelease = _ipAddressDao.listByAssociatedVpc(vpcId, null);
s_logger.debug("Releasing ips for vpc id=" + vpcId + " as a part of vpc cleanup");
for (final IPAddressVO ipToRelease : ipsToRelease) {
if (ipToRelease.isPortable()) {
// portable IP address are associated with owner, until
// explicitly requested to be disassociated.
// so as part of VPC clean up just break IP association with VPC
ipToRelease.setVpcId(null);
ipToRelease.setAssociatedWithNetworkId(null);
_ipAddressDao.update(ipToRelease.getId(), ipToRelease);
s_logger.debug("Portable IP address " + ipToRelease + " is no longer associated with any VPC");
} else {
success = success && _ipAddrMgr.disassociatePublicIpAddress(ipToRelease.getId(), callerUserId, caller);
if (!success) {
s_logger.warn("Failed to cleanup ip " + ipToRelease + " as a part of vpc id=" + vpcId + " cleanup");
}
}
}
if (success) {
s_logger.debug("Released ip addresses for vpc id=" + vpcId + " as a part of cleanup vpc process");
} else {
s_logger.warn("Failed to release ip addresses for vpc id=" + vpcId + " as a part of cleanup vpc process");
// although it failed, proceed to the next cleanup step as it
// doesn't depend on the public ip release
}
// 3) Delete all static route rules
if (!revokeStaticRoutesForVpc(vpcId, caller)) {
s_logger.warn("Failed to revoke static routes for vpc " + vpcId + " as a part of cleanup vpc process");
return false;
}
// 4) Delete private gateways
final List<PrivateGateway> gateways = getVpcPrivateGateways(vpcId);
if (gateways != null) {
for (final PrivateGateway gateway : gateways) {
if (gateway != null) {
s_logger.debug("Deleting private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
if (!deleteVpcPrivateGateway(gateway.getId())) {
success = false;
s_logger.debug("Failed to delete private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
} else {
s_logger.debug("Deleted private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
}
}
}
}
//5) Delete ACLs
final SearchBuilder<NetworkACLVO> searchBuilder = _networkAclDao.createSearchBuilder();
searchBuilder.and("vpcId", searchBuilder.entity().getVpcId(), Op.IN);
final SearchCriteria<NetworkACLVO> searchCriteria = searchBuilder.create();
searchCriteria.setParameters("vpcId", vpcId, 0);
final Filter filter = new Filter(NetworkACLVO.class, "id", false, null, null);
final Pair<List<NetworkACLVO>, Integer> aclsCountPair = _networkAclDao.searchAndCount(searchCriteria, filter);
final List<NetworkACLVO> acls = aclsCountPair.first();
for (final NetworkACLVO networkAcl : acls) {
if (networkAcl.getId() != NetworkACL.DEFAULT_ALLOW && networkAcl.getId() != NetworkACL.DEFAULT_DENY) {
_networkAclMgr.deleteNetworkACL(networkAcl);
}
}
return success;
}