mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
a bunch of other changes for network refactoring
This commit is contained in:
parent
2be0cd6a95
commit
aca8ef79cd
@ -22,12 +22,15 @@ import com.cloud.utils.fsm.StateMachine;
|
|||||||
public interface NetworkConfiguration extends ControlledEntity {
|
public interface NetworkConfiguration extends ControlledEntity {
|
||||||
enum Event {
|
enum Event {
|
||||||
ImplementNetwork,
|
ImplementNetwork,
|
||||||
DestroyNetwork;
|
DestroyNetwork,
|
||||||
|
OperationSucceeded,
|
||||||
|
OperationFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum State implements FiniteState<State, Event> {
|
enum State implements FiniteState<State, Event> {
|
||||||
Allocated("Indicates the network configuration is in allocated but not setup"),
|
Allocated("Indicates the network configuration is in allocated but not setup"),
|
||||||
Setup("Indicates the network configuration is setup"),
|
Setup("Indicates the network configuration is setup"),
|
||||||
|
Implementing("Indicates the network configuration is being implemented"),
|
||||||
Implemented("Indicates the network configuration is in use"),
|
Implemented("Indicates the network configuration is in use"),
|
||||||
Destroying("Indicates the network configuration is being destroyed");
|
Destroying("Indicates the network configuration is being destroyed");
|
||||||
|
|
||||||
@ -64,13 +67,15 @@ public interface NetworkConfiguration extends ControlledEntity {
|
|||||||
|
|
||||||
private static StateMachine<State, Event> s_fsm = new StateMachine<State, Event>();
|
private static StateMachine<State, Event> s_fsm = new StateMachine<State, Event>();
|
||||||
static {
|
static {
|
||||||
s_fsm.addTransition(State.Allocated, Event.ImplementNetwork, State.Implemented);
|
s_fsm.addTransition(State.Allocated, Event.ImplementNetwork, State.Implementing);
|
||||||
|
s_fsm.addTransition(State.Implementing, Event.OperationSucceeded, State.Implemented);
|
||||||
|
s_fsm.addTransition(State.Implementing, Event.OperationFailed, State.Destroying);
|
||||||
s_fsm.addTransition(State.Implemented, Event.DestroyNetwork, State.Destroying);
|
s_fsm.addTransition(State.Implemented, Event.DestroyNetwork, State.Destroying);
|
||||||
|
s_fsm.addTransition(State.Destroying, Event.OperationSucceeded, State.Allocated);
|
||||||
|
s_fsm.addTransition(State.Destroying, Event.OperationFailed, State.Implemented);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return id of the network profile. Null means the network profile is not from the database.
|
* @return id of the network profile. Null means the network profile is not from the database.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -64,9 +64,9 @@ public interface NetworkGuru extends Adapter {
|
|||||||
* @throws InsufficientVirtualNetworkCapcityException
|
* @throws InsufficientVirtualNetworkCapcityException
|
||||||
* @throws InsufficientAddressCapacityException
|
* @throws InsufficientAddressCapacityException
|
||||||
*/
|
*/
|
||||||
String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException;
|
void reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException;
|
||||||
|
|
||||||
boolean release(String uniqueId);
|
boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, String reservationId);
|
||||||
|
|
||||||
void deallocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm);
|
void deallocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm);
|
||||||
|
|
||||||
|
|||||||
@ -117,9 +117,9 @@ listLoadBalancerRules=com.cloud.api.commands.ListLoadBalancerRulesCmd;15
|
|||||||
listLoadBalancerRuleInstances=com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;15
|
listLoadBalancerRuleInstances=com.cloud.api.commands.ListLoadBalancerRuleInstancesCmd;15
|
||||||
|
|
||||||
#### router commands
|
#### router commands
|
||||||
startRouter=com.cloud.api.commands.StartRouterCmd;3
|
startRouter=com.cloud.api.commands.StartRouter2Cmd;3
|
||||||
rebootRouter=com.cloud.api.commands.RebootRouterCmd;3
|
rebootRouter=com.cloud.api.commands.RebootRouterCmd;3
|
||||||
stopRouter=com.cloud.api.commands.StopRouterCmd;3
|
stopRouter=com.cloud.api.commands.StopRouter2Cmd;3
|
||||||
changeServiceForRouter=com.cloud.api.commands.UpgradeRouterCmd;3
|
changeServiceForRouter=com.cloud.api.commands.UpgradeRouterCmd;3
|
||||||
listRouters=com.cloud.api.commands.ListRoutersCmd;7
|
listRouters=com.cloud.api.commands.ListRoutersCmd;7
|
||||||
|
|
||||||
|
|||||||
@ -50,12 +50,23 @@ public class DataCenterIpAddressVO {
|
|||||||
@Column(name="pod_id", updatable=false, nullable=false)
|
@Column(name="pod_id", updatable=false, nullable=false)
|
||||||
private long podId;
|
private long podId;
|
||||||
|
|
||||||
|
@Column(name="reservation_id")
|
||||||
|
String reservationId;
|
||||||
|
|
||||||
@Column(name="instance_id")
|
@Column(name="instance_id")
|
||||||
private Long instanceId;
|
private Long instanceId;
|
||||||
|
|
||||||
protected DataCenterIpAddressVO() {
|
protected DataCenterIpAddressVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getReservationId() {
|
||||||
|
return reservationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReservationId(String reservationId) {
|
||||||
|
this.reservationId = reservationId;
|
||||||
|
}
|
||||||
|
|
||||||
public DataCenterIpAddressVO(String ipAddress, long dataCenterId, long podId) {
|
public DataCenterIpAddressVO(String ipAddress, long dataCenterId, long podId) {
|
||||||
this.ipAddress = ipAddress;
|
this.ipAddress = ipAddress;
|
||||||
this.dataCenterId = dataCenterId;
|
this.dataCenterId = dataCenterId;
|
||||||
|
|||||||
@ -53,6 +53,9 @@ public class DataCenterLinkLocalIpAddressVO {
|
|||||||
@Column(name="instance_id")
|
@Column(name="instance_id")
|
||||||
private Long instanceId;
|
private Long instanceId;
|
||||||
|
|
||||||
|
@Column(name="reservation_id")
|
||||||
|
private String reservationId;
|
||||||
|
|
||||||
protected DataCenterLinkLocalIpAddressVO() {
|
protected DataCenterLinkLocalIpAddressVO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +85,14 @@ public class DataCenterLinkLocalIpAddressVO {
|
|||||||
this.takenAt = takenDate;
|
this.takenAt = takenDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setReservationId(String reservationId) {
|
||||||
|
this.reservationId = reservationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReservationId() {
|
||||||
|
return reservationId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getIpAddress() {
|
public String getIpAddress() {
|
||||||
return ipAddress;
|
return ipAddress;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,7 @@ public class PodVlanMapVO {
|
|||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||||
@Column(name="id")
|
@Column(name="id")
|
||||||
private Long id;
|
private long id;
|
||||||
|
|
||||||
@Column(name="pod_id")
|
@Column(name="pod_id")
|
||||||
private long podId;
|
private long podId;
|
||||||
@ -46,10 +46,9 @@ public class PodVlanMapVO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PodVlanMapVO() {
|
public PodVlanMapVO() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -33,21 +33,21 @@ public interface DataCenterDao extends GenericDao<DataCenterVO, Long> {
|
|||||||
*/
|
*/
|
||||||
String[] getNextAvailableMacAddressPair(long id);
|
String[] getNextAvailableMacAddressPair(long id);
|
||||||
String[] getNextAvailableMacAddressPair(long id, long mask);
|
String[] getNextAvailableMacAddressPair(long id, long mask);
|
||||||
String allocatePrivateIpAddress(long id, long podId, long instanceId);
|
String allocatePrivateIpAddress(long id, long podId, long instanceId, String reservationId);
|
||||||
String allocateLinkLocalPrivateIpAddress(long id, long podId, long instanceId);
|
String allocateLinkLocalIpAddress(long id, long podId, long instanceId, String reservationId);
|
||||||
String allocateVnet(long dcId, long accountId);
|
String allocateVnet(long dcId, long accountId);
|
||||||
|
|
||||||
void releaseVnet(String vnet, long dcId, long accountId);
|
void releaseVnet(String vnet, long dcId, long accountId);
|
||||||
void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId);
|
void releasePrivateIpAddress(String ipAddress, long dcId, Long instanceId);
|
||||||
void releasePrivateIpAddress(long nicId);
|
void releasePrivateIpAddress(long nicId, String reservationId);
|
||||||
void releaseLinkLocalPrivateIpAddress(String ipAddress, long dcId, Long instanceId);
|
void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long instanceId);
|
||||||
void releaseLinkLocalPrivateIpAddress(long nicId);
|
void releaseLinkLocalIpAddress(long nicId, String reservationId);
|
||||||
|
|
||||||
boolean deletePrivateIpAddressByPod(long podId);
|
boolean deletePrivateIpAddressByPod(long podId);
|
||||||
boolean deleteLinkLocalPrivateIpAddressByPod(long podId);
|
boolean deleteLinkLocalIpAddressByPod(long podId);
|
||||||
|
|
||||||
void addPrivateIpAddress(long dcId,long podId, String start, String end);
|
void addPrivateIpAddress(long dcId,long podId, String start, String end);
|
||||||
void addLinkLocalPrivateIpAddress(long dcId,long podId, String start, String end);
|
void addLinkLocalIpAddress(long dcId,long podId, String start, String end);
|
||||||
|
|
||||||
List<DataCenterVnetVO> findVnet(long dcId, String vnet);
|
List<DataCenterVnetVO> findVnet(long dcId, String vnet);
|
||||||
|
|
||||||
|
|||||||
@ -109,17 +109,17 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releasePrivateIpAddress(long nicId) {
|
public void releasePrivateIpAddress(long nicId, String reservationId) {
|
||||||
_ipAllocDao.releaseIpAddress(nicId);
|
_ipAllocDao.releaseIpAddress(nicId, reservationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseLinkLocalPrivateIpAddress(long nicId) {
|
public void releaseLinkLocalIpAddress(long nicId, String reservationId) {
|
||||||
_LinkLocalIpAllocDao.releaseIpAddress(nicId);
|
_LinkLocalIpAllocDao.releaseIpAddress(nicId, reservationId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseLinkLocalPrivateIpAddress(String ipAddress, long dcId, Long instanceId) {
|
public void releaseLinkLocalIpAddress(String ipAddress, long dcId, Long instanceId) {
|
||||||
_LinkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, instanceId);
|
_LinkLocalIpAllocDao.releaseIpAddress(ipAddress, dcId, instanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteLinkLocalPrivateIpAddressByPod(long podId) {
|
public boolean deleteLinkLocalIpAddressByPod(long podId) {
|
||||||
return _LinkLocalIpAllocDao.deleteIpAddressByPod(podId);
|
return _LinkLocalIpAllocDao.deleteIpAddressByPod(podId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,8 +172,8 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String allocatePrivateIpAddress(long dcId, long podId, long instanceId) {
|
public String allocatePrivateIpAddress(long dcId, long podId, long instanceId, String reservationId) {
|
||||||
DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dcId, podId, instanceId);
|
DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId);
|
||||||
if (vo == null) {
|
if (vo == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -181,8 +181,8 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String allocateLinkLocalPrivateIpAddress(long dcId, long podId, long instanceId) {
|
public String allocateLinkLocalIpAddress(long dcId, long podId, long instanceId, String reservationId) {
|
||||||
DataCenterLinkLocalIpAddressVO vo = _LinkLocalIpAllocDao.takeIpAddress(dcId, podId, instanceId);
|
DataCenterLinkLocalIpAddressVO vo = _LinkLocalIpAllocDao.takeIpAddress(dcId, podId, instanceId, reservationId);
|
||||||
if (vo == null) {
|
if (vo == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ public class DataCenterDaoImpl extends GenericDaoBase<DataCenterVO, Long> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addLinkLocalPrivateIpAddress(long dcId,long podId, String start, String end) {
|
public void addLinkLocalIpAddress(long dcId,long podId, String start, String end) {
|
||||||
_LinkLocalIpAllocDao.addIpRange(dcId, podId, start, end);
|
_LinkLocalIpAllocDao.addIpRange(dcId, podId, start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import com.cloud.dc.DataCenterIpAddressVO;
|
|||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public interface DataCenterIpAddressDao extends GenericDao<DataCenterIpAddressVO, Long> {
|
public interface DataCenterIpAddressDao extends GenericDao<DataCenterIpAddressVO, Long> {
|
||||||
|
|
||||||
boolean mark(long dcId, long podId, String ip);
|
boolean mark(long dcId, long podId, String ip);
|
||||||
List<DataCenterIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress);
|
List<DataCenterIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress);
|
||||||
int countIPs(long podId, long dcId, boolean onlyCountAllocated);
|
int countIPs(long podId, long dcId, boolean onlyCountAllocated);
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
package com.cloud.dc.dao;
|
package com.cloud.dc.dao;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -27,67 +27,55 @@ import javax.ejb.Local;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.dc.DataCenterIpAddressVO;
|
import com.cloud.dc.DataCenterIpAddressVO;
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.GenericSearchBuilder;
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.SearchCriteria.Func;
|
||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.utils.net.NetUtils;
|
import com.cloud.utils.net.NetUtils;
|
||||||
|
|
||||||
@Local(value={DataCenterIpAddressDao.class})
|
@Local(value={DataCenterIpAddressDao.class}) @DB(txn=false)
|
||||||
public class DataCenterIpAddressDaoImpl extends GenericDaoBase<DataCenterIpAddressVO, Long> implements DataCenterIpAddressDao {
|
public class DataCenterIpAddressDaoImpl extends GenericDaoBase<DataCenterIpAddressVO, Long> implements DataCenterIpAddressDao {
|
||||||
private static final Logger s_logger = Logger.getLogger(DataCenterIpAddressDaoImpl.class);
|
private static final Logger s_logger = Logger.getLogger(DataCenterIpAddressDaoImpl.class);
|
||||||
|
|
||||||
private static final String COUNT_ALL_PRIVATE_IPS = "SELECT count(*) from `cloud`.`op_dc_ip_address_alloc` where pod_id = ? AND data_center_id = ?";
|
private final SearchBuilder<DataCenterIpAddressVO> AllFieldsSearch;
|
||||||
private static final String COUNT_ALLOCATED_PRIVATE_IPS = "SELECT count(*) from `cloud`.`op_dc_ip_address_alloc` where pod_id = ? AND data_center_id = ? AND taken is not null";
|
private final GenericSearchBuilder<DataCenterIpAddressVO, Integer> AllIpCount;
|
||||||
|
private final GenericSearchBuilder<DataCenterIpAddressVO, Integer> AllAllocatedIpCount;
|
||||||
|
|
||||||
private final SearchBuilder<DataCenterIpAddressVO> FreeIpSearch;
|
@DB
|
||||||
private final SearchBuilder<DataCenterIpAddressVO> IpDcSearch;
|
public DataCenterIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId) {
|
||||||
private final SearchBuilder<DataCenterIpAddressVO> PodDcSearch;
|
SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
private final SearchBuilder<DataCenterIpAddressVO> PodDcIpSearch;
|
|
||||||
private final SearchBuilder<DataCenterIpAddressVO> FreePodDcIpSearch;
|
|
||||||
|
|
||||||
public DataCenterIpAddressVO takeIpAddress(long dcId, long podId, long instanceId) {
|
|
||||||
SearchCriteria<DataCenterIpAddressVO> sc = FreeIpSearch.create();
|
|
||||||
sc.setParameters("dc", dcId);
|
|
||||||
sc.setParameters("pod", podId);
|
sc.setParameters("pod", podId);
|
||||||
|
sc.setParameters("taken", (Date)null);
|
||||||
|
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
try {
|
|
||||||
txn.start();
|
txn.start();
|
||||||
|
|
||||||
DataCenterIpAddressVO vo = lockOneRandomRow(sc, true);
|
DataCenterIpAddressVO vo = lockOneRandomRow(sc, true);
|
||||||
if (vo == null) {
|
if (vo == null) {
|
||||||
txn.rollback();
|
return null;
|
||||||
return vo;
|
|
||||||
}
|
}
|
||||||
vo.setTakenAt(new Date());
|
vo.setTakenAt(new Date());
|
||||||
vo.setInstanceId(instanceId);
|
vo.setInstanceId(instanceId);
|
||||||
|
vo.setReservationId(reservationId);
|
||||||
update(vo.getId(), vo);
|
update(vo.getId(), vo);
|
||||||
txn.commit();
|
txn.commit();
|
||||||
return vo;
|
return vo;
|
||||||
} catch (Exception e) {
|
|
||||||
txn.rollback();
|
|
||||||
throw new CloudRuntimeException("Caught Exception ", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean deleteIpAddressByPod(long podId) {
|
public boolean deleteIpAddressByPod(long podId) {
|
||||||
Transaction txn = Transaction.currentTxn();
|
SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
try {
|
sc.setParameters("pod", podId);
|
||||||
String deleteSql = "DELETE FROM `cloud`.`op_dc_ip_address_alloc` WHERE `pod_id` = ?";
|
return remove(sc) > 0;
|
||||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(deleteSql);
|
|
||||||
stmt.setLong(1, podId);
|
|
||||||
return stmt.execute();
|
|
||||||
} catch(Exception e) {
|
|
||||||
throw new CloudRuntimeException("Caught Exception ", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean mark(long dcId, long podId, String ip) {
|
public boolean mark(long dcId, long podId, String ip) {
|
||||||
SearchCriteria<DataCenterIpAddressVO> sc = FreePodDcIpSearch.create();
|
SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
sc.setParameters("podId", podId);
|
sc.setParameters("pod", podId);
|
||||||
sc.setParameters("dcId", dcId);
|
|
||||||
sc.setParameters("ipAddress", ip);
|
sc.setParameters("ipAddress", ip);
|
||||||
|
|
||||||
DataCenterIpAddressVO vo = createForUpdate();
|
DataCenterIpAddressVO vo = createForUpdate();
|
||||||
@ -96,26 +84,27 @@ public class DataCenterIpAddressDaoImpl extends GenericDaoBase<DataCenterIpAddre
|
|||||||
return update(vo, sc) >= 1;
|
return update(vo, sc) >= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DB
|
||||||
public void addIpRange(long dcId, long podId, String start, String end) {
|
public void addIpRange(long dcId, long podId, String start, String end) {
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
|
String insertSql = "INSERT INTO op_dc_ip_address_alloc (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
|
||||||
long startIP = NetUtils.ip2Long(start);
|
long startIP = NetUtils.ip2Long(start);
|
||||||
long endIP = NetUtils.ip2Long(end);
|
long endIP = NetUtils.ip2Long(end);
|
||||||
|
|
||||||
while (startIP <= endIP) {
|
|
||||||
try {
|
try {
|
||||||
|
txn.start();
|
||||||
stmt = txn.prepareAutoCloseStatement(insertSql);
|
stmt = txn.prepareAutoCloseStatement(insertSql);
|
||||||
stmt.setString(1, NetUtils.long2Ip(startIP));
|
while (startIP <= endIP) {
|
||||||
|
stmt.setString(1, NetUtils.long2Ip(startIP++));
|
||||||
stmt.setLong(2, dcId);
|
stmt.setLong(2, dcId);
|
||||||
stmt.setLong(3, podId);
|
stmt.setLong(3, podId);
|
||||||
stmt.executeUpdate();
|
stmt.addBatch();
|
||||||
stmt.close();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
s_logger.warn("Unable to persist " + NetUtils.long2Ip(startIP) + " due to " + ex.getMessage());
|
|
||||||
}
|
}
|
||||||
startIP++;
|
txn.commit();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new CloudRuntimeException("Unable to persist ip address range ", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +112,7 @@ public class DataCenterIpAddressDaoImpl extends GenericDaoBase<DataCenterIpAddre
|
|||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId);
|
s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId);
|
||||||
}
|
}
|
||||||
SearchCriteria<DataCenterIpAddressVO> sc = IpDcSearch.create();
|
SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
sc.setParameters("ip", ipAddress);
|
sc.setParameters("ip", ipAddress);
|
||||||
sc.setParameters("dc", dcId);
|
sc.setParameters("dc", dcId);
|
||||||
sc.setParameters("instance", instanceId);
|
sc.setParameters("instance", instanceId);
|
||||||
@ -132,86 +121,75 @@ public class DataCenterIpAddressDaoImpl extends GenericDaoBase<DataCenterIpAddre
|
|||||||
|
|
||||||
vo.setTakenAt(null);
|
vo.setTakenAt(null);
|
||||||
vo.setInstanceId(null);
|
vo.setInstanceId(null);
|
||||||
|
vo.setReservationId(null);
|
||||||
update(vo, sc);
|
update(vo, sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseIpAddress(long nicId) {
|
public void releaseIpAddress(long nicId, String reservationId) {
|
||||||
SearchCriteria<DataCenterIpAddressVO> sc = IpDcSearch.create();
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
s_logger.debug("Releasing ip address for reservationId=" + reservationId + ", instance=" + nicId);
|
||||||
|
}
|
||||||
|
SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
sc.setParameters("instance", nicId);
|
sc.setParameters("instance", nicId);
|
||||||
|
sc.setParameters("reservation", reservationId);
|
||||||
|
|
||||||
DataCenterIpAddressVO vo = createForUpdate();
|
DataCenterIpAddressVO vo = createForUpdate();
|
||||||
vo.setTakenAt(null);
|
vo.setTakenAt(null);
|
||||||
vo.setInstanceId(null);
|
vo.setInstanceId(null);
|
||||||
|
vo.setReservationId(null);
|
||||||
update(vo, sc);
|
update(vo, sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DataCenterIpAddressVO> listByPodIdDcId(long podId, long dcId) {
|
||||||
|
SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("pod", podId);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DataCenterIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress) {
|
||||||
|
SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("pod", podId);
|
||||||
|
sc.setParameters("ipAddress", ipAddress);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int countIPs(long podId, long dcId, boolean onlyCountAllocated) {
|
||||||
|
SearchCriteria<Integer> sc;
|
||||||
|
if (onlyCountAllocated) {
|
||||||
|
sc = AllAllocatedIpCount.create();
|
||||||
|
} else {
|
||||||
|
sc = AllIpCount.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.setParameters("pod", podId);
|
||||||
|
List<Integer> count = customSearch(sc, null);
|
||||||
|
return count.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
protected DataCenterIpAddressDaoImpl() {
|
protected DataCenterIpAddressDaoImpl() {
|
||||||
super();
|
super();
|
||||||
FreeIpSearch = createSearchBuilder();
|
|
||||||
FreeIpSearch.and("dc", FreeIpSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
|
||||||
FreeIpSearch.and("pod", FreeIpSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
|
||||||
FreeIpSearch.and("taken", FreeIpSearch.entity().getTakenAt(), SearchCriteria.Op.NULL);
|
|
||||||
FreeIpSearch.done();
|
|
||||||
|
|
||||||
IpDcSearch = createSearchBuilder();
|
AllFieldsSearch = createSearchBuilder();
|
||||||
IpDcSearch.and("ip", IpDcSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
||||||
IpDcSearch.and("dc", IpDcSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||||
IpDcSearch.and("instance", IpDcSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
|
AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||||
IpDcSearch.done();
|
AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("ipAddress", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("reservation", AllFieldsSearch.entity().getReservationId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.done();
|
||||||
|
|
||||||
PodDcSearch = createSearchBuilder();
|
AllIpCount = createSearchBuilder(Integer.class);
|
||||||
PodDcSearch.and("podId", PodDcSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getId());
|
||||||
PodDcSearch.and("dataCenterId", PodDcSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
AllIpCount.and("pod", AllIpCount.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||||
PodDcSearch.done();
|
AllIpCount.done();
|
||||||
|
|
||||||
PodDcIpSearch = createSearchBuilder();
|
AllAllocatedIpCount = createSearchBuilder(Integer.class);
|
||||||
PodDcIpSearch.and("dcId", PodDcIpSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
AllAllocatedIpCount.select(null, Func.COUNT, AllIpCount.entity().getId());
|
||||||
PodDcIpSearch.and("podId", PodDcIpSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
AllAllocatedIpCount.and("pod", AllAllocatedIpCount.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||||
PodDcIpSearch.and("ipAddress", PodDcIpSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
AllAllocatedIpCount.and("removed", AllAllocatedIpCount.entity().getTakenAt(), SearchCriteria.Op.NNULL);
|
||||||
PodDcIpSearch.done();
|
AllAllocatedIpCount.done();
|
||||||
|
|
||||||
FreePodDcIpSearch = createSearchBuilder();
|
|
||||||
FreePodDcIpSearch.and("dcId", FreePodDcIpSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
|
||||||
FreePodDcIpSearch.and("podId", FreePodDcIpSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
|
||||||
FreePodDcIpSearch.and("ipAddress", FreePodDcIpSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
|
||||||
FreePodDcIpSearch.and("taken", FreePodDcIpSearch.entity().getTakenAt(), SearchCriteria.Op.EQ);
|
|
||||||
FreePodDcIpSearch.done();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DataCenterIpAddressVO> listByPodIdDcId(long podId, long dcId) {
|
|
||||||
SearchCriteria<DataCenterIpAddressVO> sc = PodDcSearch.create();
|
|
||||||
sc.setParameters("podId", podId);
|
|
||||||
sc.setParameters("dataCenterId", dcId);
|
|
||||||
return listIncludingRemovedBy(sc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DataCenterIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress) {
|
|
||||||
SearchCriteria<DataCenterIpAddressVO> sc = PodDcIpSearch.create();
|
|
||||||
sc.setParameters("dcId", dcId);
|
|
||||||
sc.setParameters("podId", podId);
|
|
||||||
sc.setParameters("ipAddress", ipAddress);
|
|
||||||
return listIncludingRemovedBy(sc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int countIPs(long podId, long dcId, boolean onlyCountAllocated) {
|
|
||||||
Transaction txn = Transaction.currentTxn();
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
int ipCount = 0;
|
|
||||||
try {
|
|
||||||
String sql = "";
|
|
||||||
if (onlyCountAllocated) sql = COUNT_ALLOCATED_PRIVATE_IPS;
|
|
||||||
else sql = COUNT_ALL_PRIVATE_IPS;
|
|
||||||
|
|
||||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
|
||||||
pstmt.setLong(1, podId);
|
|
||||||
pstmt.setLong(2, dcId);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
|
|
||||||
if (rs.next()) ipCount = rs.getInt(1);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
s_logger.warn("Exception searching for routers and proxies", e);
|
|
||||||
}
|
|
||||||
return ipCount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,114 +18,93 @@
|
|||||||
package com.cloud.dc.dao;
|
package com.cloud.dc.dao;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.ejb.Local;
|
import javax.ejb.Local;
|
||||||
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.dc.DataCenterLinkLocalIpAddressVO;
|
import com.cloud.dc.DataCenterLinkLocalIpAddressVO;
|
||||||
|
import com.cloud.utils.db.DB;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
import com.cloud.utils.db.GenericDaoBase;
|
import com.cloud.utils.db.GenericDaoBase;
|
||||||
|
import com.cloud.utils.db.GenericSearchBuilder;
|
||||||
import com.cloud.utils.db.SearchBuilder;
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
import com.cloud.utils.db.SearchCriteria;
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
|
import com.cloud.utils.db.SearchCriteria.Func;
|
||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.utils.net.NetUtils;
|
import com.cloud.utils.net.NetUtils;
|
||||||
|
|
||||||
@Local(value={DataCenterLinkLocalIpAddressDaoImpl.class})
|
@Local(value={DataCenterLinkLocalIpAddressDaoImpl.class}) @DB(txn=false)
|
||||||
public class DataCenterLinkLocalIpAddressDaoImpl extends GenericDaoBase<DataCenterLinkLocalIpAddressVO, Long> implements GenericDao<DataCenterLinkLocalIpAddressVO, Long> {
|
public class DataCenterLinkLocalIpAddressDaoImpl extends GenericDaoBase<DataCenterLinkLocalIpAddressVO, Long> implements GenericDao<DataCenterLinkLocalIpAddressVO, Long> {
|
||||||
private static final Logger s_logger = Logger.getLogger(DataCenterLinkLocalIpAddressDaoImpl.class);
|
private static final Logger s_logger = Logger.getLogger(DataCenterLinkLocalIpAddressDaoImpl.class);
|
||||||
|
|
||||||
private static final String COUNT_ALL_PRIVATE_IPS = "SELECT count(*) from `cloud`.`op_dc_link_local_ip_address_alloc` where pod_id = ? AND data_center_id = ?";
|
private final SearchBuilder<DataCenterLinkLocalIpAddressVO> AllFieldsSearch;
|
||||||
private static final String COUNT_ALLOCATED_PRIVATE_IPS = "SELECT count(*) from `cloud`.`op_dc_link_local_ip_address_alloc` where pod_id = ? AND data_center_id = ? AND taken is not null";
|
private final GenericSearchBuilder<DataCenterLinkLocalIpAddressVO, Integer> AllIpCount;
|
||||||
|
private final GenericSearchBuilder<DataCenterLinkLocalIpAddressVO, Integer> AllAllocatedIpCount;
|
||||||
|
|
||||||
private final SearchBuilder<DataCenterLinkLocalIpAddressVO> FreeIpSearch;
|
@DB
|
||||||
private final SearchBuilder<DataCenterLinkLocalIpAddressVO> IpDcSearch;
|
public DataCenterLinkLocalIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId) {
|
||||||
private final SearchBuilder<DataCenterLinkLocalIpAddressVO> PodDcSearch;
|
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
private final SearchBuilder<DataCenterLinkLocalIpAddressVO> PodDcIpSearch;
|
|
||||||
private final SearchBuilder<DataCenterLinkLocalIpAddressVO> FreePodDcIpSearch;
|
|
||||||
|
|
||||||
public DataCenterLinkLocalIpAddressVO takeIpAddress(long dcId, long podId, long instanceId) {
|
|
||||||
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = FreeIpSearch.create();
|
|
||||||
sc.setParameters("dc", dcId);
|
|
||||||
sc.setParameters("pod", podId);
|
sc.setParameters("pod", podId);
|
||||||
sc.setParameters("ipAddr", NetUtils.getLinkLocalGateway()); /*explicitly removing the gateway*/
|
sc.setParameters("taken", (Date)null);
|
||||||
|
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
try {
|
|
||||||
txn.start();
|
txn.start();
|
||||||
|
|
||||||
DataCenterLinkLocalIpAddressVO vo = lockOneRandomRow(sc, true);
|
DataCenterLinkLocalIpAddressVO vo = lockOneRandomRow(sc, true);
|
||||||
if (vo == null) {
|
if (vo == null) {
|
||||||
txn.rollback();
|
return null;
|
||||||
return vo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vo.setTakenAt(new Date());
|
vo.setTakenAt(new Date());
|
||||||
vo.setInstanceId(instanceId);
|
vo.setInstanceId(instanceId);
|
||||||
|
vo.setReservationId(reservationId);
|
||||||
update(vo.getId(), vo);
|
update(vo.getId(), vo);
|
||||||
txn.commit();
|
txn.commit();
|
||||||
return vo;
|
return vo;
|
||||||
} catch (Exception e) {
|
|
||||||
txn.rollback();
|
|
||||||
throw new CloudRuntimeException("Caught Exception ", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deleteIpAddressByPod(long podId) {
|
public boolean deleteIpAddressByPod(long podId) {
|
||||||
Transaction txn = Transaction.currentTxn();
|
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
try {
|
sc.setParameters("pod", podId);
|
||||||
String deleteSql = "DELETE FROM `cloud`.`op_dc_link_local_ip_address_alloc` WHERE `pod_id` = ?";
|
return remove(sc) > 0;
|
||||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(deleteSql);
|
|
||||||
stmt.setLong(1, podId);
|
|
||||||
return stmt.execute();
|
|
||||||
} catch(Exception e) {
|
|
||||||
throw new CloudRuntimeException("Caught Exception ", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean mark(long dcId, long podId, String ip) {
|
|
||||||
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = FreePodDcIpSearch.create();
|
|
||||||
sc.setParameters("podId", podId);
|
|
||||||
sc.setParameters("dcId", dcId);
|
|
||||||
sc.setParameters("ipAddress", ip);
|
|
||||||
|
|
||||||
DataCenterLinkLocalIpAddressVO vo = createForUpdate();
|
|
||||||
vo.setTakenAt(new Date());
|
|
||||||
|
|
||||||
return update(vo, sc) >= 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DB
|
||||||
public void addIpRange(long dcId, long podId, String start, String end) {
|
public void addIpRange(long dcId, long podId, String start, String end) {
|
||||||
Transaction txn = Transaction.currentTxn();
|
|
||||||
String insertSql = "INSERT INTO `cloud`.`op_dc_link_local_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
|
String insertSql = "INSERT INTO `cloud`.`op_dc_link_local_ip_address_alloc` (ip_address, data_center_id, pod_id) VALUES (?, ?, ?)";
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
|
|
||||||
long startIP = NetUtils.ip2Long(start);
|
long startIP = NetUtils.ip2Long(start);
|
||||||
long endIP = NetUtils.ip2Long(end);
|
long endIP = NetUtils.ip2Long(end);
|
||||||
|
|
||||||
while (startIP <= endIP) {
|
Transaction txn = Transaction.currentTxn();
|
||||||
try {
|
try {
|
||||||
|
txn.start();
|
||||||
stmt = txn.prepareAutoCloseStatement(insertSql);
|
stmt = txn.prepareAutoCloseStatement(insertSql);
|
||||||
stmt.setString(1, NetUtils.long2Ip(startIP));
|
while (startIP <= endIP) {
|
||||||
|
stmt.setString(1, NetUtils.long2Ip(startIP++));
|
||||||
stmt.setLong(2, dcId);
|
stmt.setLong(2, dcId);
|
||||||
stmt.setLong(3, podId);
|
stmt.setLong(3, podId);
|
||||||
stmt.executeUpdate();
|
stmt.addBatch();
|
||||||
stmt.close();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
s_logger.warn("Unable to persist " + NetUtils.long2Ip(startIP) + " due to " + ex.getMessage());
|
|
||||||
}
|
}
|
||||||
startIP++;
|
txn.commit();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new CloudRuntimeException("Unable to insert", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseIpAddress(String ipAddress, long dcId, Long instanceId) {
|
public void releaseIpAddress(String ipAddress, long dcId, long instanceId) {
|
||||||
if (s_logger.isDebugEnabled()) {
|
if (s_logger.isDebugEnabled()) {
|
||||||
s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId);
|
s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId);
|
||||||
}
|
}
|
||||||
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = IpDcSearch.create();
|
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
sc.setParameters("ip", ipAddress);
|
sc.setParameters("ip", ipAddress);
|
||||||
sc.setParameters("dc", dcId);
|
sc.setParameters("dc", dcId);
|
||||||
sc.setParameters("instance", instanceId);
|
sc.setParameters("instance", instanceId);
|
||||||
@ -134,88 +113,74 @@ public class DataCenterLinkLocalIpAddressDaoImpl extends GenericDaoBase<DataCent
|
|||||||
|
|
||||||
vo.setTakenAt(null);
|
vo.setTakenAt(null);
|
||||||
vo.setInstanceId(null);
|
vo.setInstanceId(null);
|
||||||
|
vo.setReservationId(null);
|
||||||
update(vo, sc);
|
update(vo, sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseIpAddress(long nicId) {
|
public void releaseIpAddress(long nicId, String reservationId) {
|
||||||
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = IpDcSearch.create();
|
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
sc.setParameters("instance", nicId);
|
sc.setParameters("instance", nicId);
|
||||||
|
sc.setParameters("reservation", reservationId);
|
||||||
|
|
||||||
DataCenterLinkLocalIpAddressVO vo = createForUpdate();
|
DataCenterLinkLocalIpAddressVO vo = createForUpdate();
|
||||||
|
|
||||||
vo.setTakenAt(null);
|
vo.setTakenAt(null);
|
||||||
vo.setInstanceId(null);
|
vo.setInstanceId(null);
|
||||||
|
vo.setReservationId(null);
|
||||||
update(vo, sc);
|
update(vo, sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<DataCenterLinkLocalIpAddressVO> listByPodIdDcId(long podId, long dcId) {
|
||||||
|
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
|
sc.setParameters("pod", podId);
|
||||||
|
return listBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int countIPs(long podId, long dcId, boolean onlyCountAllocated) {
|
||||||
|
SearchCriteria<Integer> sc;
|
||||||
|
if (onlyCountAllocated) {
|
||||||
|
sc = AllAllocatedIpCount.create();
|
||||||
|
} else {
|
||||||
|
sc = AllIpCount.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.setParameters("pod", podId);
|
||||||
|
List<Integer> count = customSearch(sc, null);
|
||||||
|
return count.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
protected DataCenterLinkLocalIpAddressDaoImpl() {
|
protected DataCenterLinkLocalIpAddressDaoImpl() {
|
||||||
super();
|
super();
|
||||||
FreeIpSearch = createSearchBuilder();
|
AllFieldsSearch = createSearchBuilder();
|
||||||
FreeIpSearch.and("dc", FreeIpSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
||||||
FreeIpSearch.and("pod", FreeIpSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||||
FreeIpSearch.and("ipAddr", FreeIpSearch.entity().getIpAddress(), SearchCriteria.Op.NEQ);
|
AllFieldsSearch.and("pod", AllFieldsSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||||
FreeIpSearch.and("taken", FreeIpSearch.entity().getTakenAt(), SearchCriteria.Op.NULL);
|
AllFieldsSearch.and("instance", AllFieldsSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
|
||||||
FreeIpSearch.done();
|
AllFieldsSearch.and("reservation", AllFieldsSearch.entity().getReservationId(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.and("taken", AllFieldsSearch.entity().getTakenAt(), SearchCriteria.Op.EQ);
|
||||||
|
AllFieldsSearch.done();
|
||||||
|
|
||||||
IpDcSearch = createSearchBuilder();
|
AllIpCount = createSearchBuilder(Integer.class);
|
||||||
IpDcSearch.and("ip", IpDcSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getId());
|
||||||
IpDcSearch.and("dc", IpDcSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
AllIpCount.and("pod", AllIpCount.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||||
IpDcSearch.and("instance", IpDcSearch.entity().getInstanceId(), SearchCriteria.Op.EQ);
|
AllIpCount.done();
|
||||||
IpDcSearch.done();
|
|
||||||
|
|
||||||
PodDcSearch = createSearchBuilder();
|
AllAllocatedIpCount = createSearchBuilder(Integer.class);
|
||||||
PodDcSearch.and("podId", PodDcSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
AllAllocatedIpCount.select(null, Func.COUNT, AllIpCount.entity().getId());
|
||||||
PodDcSearch.and("dataCenterId", PodDcSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
AllAllocatedIpCount.and("pod", AllAllocatedIpCount.entity().getPodId(), SearchCriteria.Op.EQ);
|
||||||
PodDcSearch.done();
|
AllAllocatedIpCount.and("removed", AllAllocatedIpCount.entity().getTakenAt(), SearchCriteria.Op.NNULL);
|
||||||
|
AllAllocatedIpCount.done();
|
||||||
|
|
||||||
PodDcIpSearch = createSearchBuilder();
|
|
||||||
PodDcIpSearch.and("dcId", PodDcIpSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
|
||||||
PodDcIpSearch.and("podId", PodDcIpSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
|
||||||
PodDcIpSearch.and("ipAddress", PodDcIpSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
|
||||||
PodDcIpSearch.done();
|
|
||||||
|
|
||||||
FreePodDcIpSearch = createSearchBuilder();
|
|
||||||
FreePodDcIpSearch.and("dcId", FreePodDcIpSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
|
||||||
FreePodDcIpSearch.and("podId", FreePodDcIpSearch.entity().getPodId(), SearchCriteria.Op.EQ);
|
|
||||||
FreePodDcIpSearch.and("ipAddress", FreePodDcIpSearch.entity().getIpAddress(), SearchCriteria.Op.EQ);
|
|
||||||
FreePodDcIpSearch.and("taken", FreePodDcIpSearch.entity().getTakenAt(), SearchCriteria.Op.EQ);
|
|
||||||
FreePodDcIpSearch.done();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DataCenterLinkLocalIpAddressVO> listByPodIdDcId(long podId, long dcId) {
|
@Override
|
||||||
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = PodDcSearch.create();
|
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||||
sc.setParameters("podId", podId);
|
super.configure(name, params);
|
||||||
sc.setParameters("dataCenterId", dcId);
|
|
||||||
return listIncludingRemovedBy(sc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<DataCenterLinkLocalIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress) {
|
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = AllFieldsSearch.create();
|
||||||
SearchCriteria<DataCenterLinkLocalIpAddressVO> sc = PodDcIpSearch.create();
|
sc.setParameters("ip", NetUtils.getLinkLocalGateway());
|
||||||
sc.setParameters("dcId", dcId);
|
remove(sc);
|
||||||
sc.setParameters("podId", podId);
|
|
||||||
sc.setParameters("ipAddress", ipAddress);
|
|
||||||
return listIncludingRemovedBy(sc);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int countIPs(long podId, long dcId, boolean onlyCountAllocated) {
|
return true;
|
||||||
Transaction txn = Transaction.currentTxn();
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
int ipCount = 0;
|
|
||||||
try {
|
|
||||||
String sql = "";
|
|
||||||
if (onlyCountAllocated) sql = COUNT_ALLOCATED_PRIVATE_IPS;
|
|
||||||
else sql = COUNT_ALL_PRIVATE_IPS;
|
|
||||||
|
|
||||||
pstmt = txn.prepareAutoCloseStatement(sql);
|
|
||||||
pstmt.setLong(1, podId);
|
|
||||||
pstmt.setLong(2, dcId);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
|
|
||||||
if (rs.next()) ipCount = rs.getInt(1);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
s_logger.warn("Exception searching for routers and proxies", e);
|
|
||||||
}
|
|
||||||
return ipCount;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* This software is licensed under the GNU General Public License v3 or later.
|
* This software is licensed under the GNU General License v3 or later.
|
||||||
*
|
*
|
||||||
* It is free software: you can redistribute it and/or modify
|
* It is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -21,35 +21,34 @@ package com.cloud.dc.dao;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cloud.dc.Vlan;
|
import com.cloud.dc.Vlan;
|
||||||
import com.cloud.dc.VlanVO;
|
|
||||||
import com.cloud.dc.Vlan.VlanType;
|
import com.cloud.dc.Vlan.VlanType;
|
||||||
|
import com.cloud.dc.VlanVO;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.db.GenericDao;
|
import com.cloud.utils.db.GenericDao;
|
||||||
|
|
||||||
public interface VlanDao extends GenericDao<VlanVO, Long> {
|
public interface VlanDao extends GenericDao<VlanVO, Long> {
|
||||||
|
|
||||||
public VlanVO findByZoneAndVlanId(long zoneId, String vlanId);
|
VlanVO findByZoneAndVlanId(long zoneId, String vlanId);
|
||||||
|
|
||||||
public List<VlanVO> findByZone(long zoneId);
|
List<VlanVO> listByZone(long zoneId);
|
||||||
|
|
||||||
public List<VlanVO> listByZoneAndType(long zoneId, Vlan.VlanType vlanType);
|
List<VlanVO> listByZoneAndType(long zoneId, Vlan.VlanType vlanType);
|
||||||
|
|
||||||
public List<VlanVO> listVlansForPod(long podId);
|
List<VlanVO> listVlansForPod(long podId);
|
||||||
|
|
||||||
public List<VlanVO> listVlansForPodByType(long podId, Vlan.VlanType vlanType);
|
List<VlanVO> listVlansForPodByType(long podId, Vlan.VlanType vlanType);
|
||||||
|
|
||||||
public void addToPod(long podId, long vlanDbId);
|
void addToPod(long podId, long vlanDbId);
|
||||||
|
|
||||||
public Pair<String, VlanVO> assignIpAddress(long zoneId, long accountId, long domainId, VlanType vlanType, boolean sourceNat);
|
Pair<String, VlanVO> assignIpAddress(long zoneId, long accountId, long domainId, VlanType vlanType, boolean sourceNat);
|
||||||
|
|
||||||
List<VlanVO> listVlansForAccountByType(Long zoneId, long accountId, VlanType vlanType);
|
List<VlanVO> listVlansForAccountByType(Long zoneId, long accountId, VlanType vlanType);
|
||||||
|
|
||||||
public Pair<String, VlanVO> assignPodDirectAttachIpAddress(long zoneId, long podId, long accountId, long domainId);
|
Pair<String, VlanVO> assignPodDirectAttachIpAddress(long zoneId, long podId, long accountId, long domainId);
|
||||||
|
|
||||||
boolean zoneHasDirectAttachUntaggedVlans(long zoneId);
|
boolean zoneHasDirectAttachUntaggedVlans(long zoneId);
|
||||||
|
|
||||||
List<VlanVO> listZoneWideVlans(long zoneId, VlanType vlanType, String vlanId);
|
List<VlanVO> listZoneWideVlans(long zoneId, VlanType vlanType, String vlanId);
|
||||||
|
|
||||||
List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType,String vlanId);
|
List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType,String vlanId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,8 +31,8 @@ import javax.naming.ConfigurationException;
|
|||||||
import com.cloud.dc.AccountVlanMapVO;
|
import com.cloud.dc.AccountVlanMapVO;
|
||||||
import com.cloud.dc.PodVlanMapVO;
|
import com.cloud.dc.PodVlanMapVO;
|
||||||
import com.cloud.dc.Vlan;
|
import com.cloud.dc.Vlan;
|
||||||
import com.cloud.dc.VlanVO;
|
|
||||||
import com.cloud.dc.Vlan.VlanType;
|
import com.cloud.dc.Vlan.VlanType;
|
||||||
|
import com.cloud.dc.VlanVO;
|
||||||
import com.cloud.network.dao.IPAddressDao;
|
import com.cloud.network.dao.IPAddressDao;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
import com.cloud.utils.component.ComponentLocator;
|
import com.cloud.utils.component.ComponentLocator;
|
||||||
@ -69,10 +69,10 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VlanVO> findByZone(long zoneId) {
|
public List<VlanVO> listByZone(long zoneId) {
|
||||||
SearchCriteria<VlanVO> sc = ZoneSearch.create();
|
SearchCriteria<VlanVO> sc = ZoneSearch.create();
|
||||||
sc.setParameters("zoneId", zoneId);
|
sc.setParameters("zoneId", zoneId);
|
||||||
return listIncludingRemovedBy(sc);
|
return listBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VlanDaoImpl() {
|
public VlanDaoImpl() {
|
||||||
@ -106,7 +106,7 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
|
|||||||
SearchCriteria<VlanVO> sc = ZoneTypeSearch.create();
|
SearchCriteria<VlanVO> sc = ZoneTypeSearch.create();
|
||||||
sc.setParameters("zoneId", zoneId);
|
sc.setParameters("zoneId", zoneId);
|
||||||
sc.setParameters("vlanType", vlanType);
|
sc.setParameters("vlanType", vlanType);
|
||||||
return listIncludingRemovedBy(sc);
|
return listBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -623,7 +623,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||||||
|
|
||||||
String[] linkLocalIpRanges = getLinkLocalIPRange();
|
String[] linkLocalIpRanges = getLinkLocalIPRange();
|
||||||
if (linkLocalIpRanges != null) {
|
if (linkLocalIpRanges != null) {
|
||||||
_zoneDao.addLinkLocalPrivateIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]);
|
_zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
@ -1495,7 +1495,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
|
|||||||
// 1. Another VLAN in the same zone has a different tag but the same subnet as the new VLAN
|
// 1. Another VLAN in the same zone has a different tag but the same subnet as the new VLAN
|
||||||
// 2. Another VLAN in the same zone that has the same tag and subnet as the new VLAN has IPs that overlap with the IPs being added
|
// 2. Another VLAN in the same zone that has the same tag and subnet as the new VLAN has IPs that overlap with the IPs being added
|
||||||
// 3. Another VLAN in the same zone that has the same tag and subnet as the new VLAN has a different gateway than the new VLAN
|
// 3. Another VLAN in the same zone that has the same tag and subnet as the new VLAN has a different gateway than the new VLAN
|
||||||
List<VlanVO> vlans = _vlanDao.findByZone(zone.getId());
|
List<VlanVO> vlans = _vlanDao.listByZone(zone.getId());
|
||||||
for (VlanVO vlan : vlans) {
|
for (VlanVO vlan : vlans) {
|
||||||
String otherVlanGateway = vlan.getVlanGateway();
|
String otherVlanGateway = vlan.getVlanGateway();
|
||||||
String otherVlanSubnet = NetUtils.getSubNet(vlan.getVlanGateway(), vlan.getVlanNetmask());
|
String otherVlanSubnet = NetUtils.getSubNet(vlan.getVlanGateway(), vlan.getVlanNetmask());
|
||||||
|
|||||||
@ -662,7 +662,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
|
|||||||
}
|
}
|
||||||
|
|
||||||
proxy.setPrivateIpAddress(privateIpAddress);
|
proxy.setPrivateIpAddress(privateIpAddress);
|
||||||
String guestIpAddress = _dcDao.allocateLinkLocalPrivateIpAddress(proxy.getDataCenterId(), routingHost.getPodId(), proxy.getId());
|
String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(proxy.getDataCenterId(), routingHost.getPodId(), proxy.getId(), null);
|
||||||
proxy.setGuestIpAddress(guestIpAddress);
|
proxy.setGuestIpAddress(guestIpAddress);
|
||||||
|
|
||||||
_consoleProxyDao.updateIf(proxy, Event.OperationRetry, routingHost.getId());
|
_consoleProxyDao.updateIf(proxy, Event.OperationRetry, routingHost.getId());
|
||||||
@ -745,7 +745,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
|
|||||||
proxy.setPrivateIpAddress(null);
|
proxy.setPrivateIpAddress(null);
|
||||||
freePrivateIpAddress(privateIpAddress, proxy.getDataCenterId(), proxy.getId());
|
freePrivateIpAddress(privateIpAddress, proxy.getDataCenterId(), proxy.getId());
|
||||||
proxy.setGuestIpAddress(null);
|
proxy.setGuestIpAddress(null);
|
||||||
_dcDao.releaseLinkLocalPrivateIpAddress(guestIpAddress, proxy.getDataCenterId(), proxy.getId());
|
_dcDao.releaseLinkLocalIpAddress(guestIpAddress, proxy.getDataCenterId(), proxy.getId());
|
||||||
_storageMgr.unshare(proxy, vols, routingHost);
|
_storageMgr.unshare(proxy, vols, routingHost);
|
||||||
} while (--retry > 0
|
} while (--retry > 0
|
||||||
&& (routingHost = (HostVO) _agentMgr
|
&& (routingHost = (HostVO) _agentMgr
|
||||||
@ -1163,7 +1163,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
|
|||||||
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
|
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
|
||||||
return _IpAllocator.getPrivateIpAddress(macAddr, dcId, podId).ipaddr;
|
return _IpAllocator.getPrivateIpAddress(macAddr, dcId, podId).ipaddr;
|
||||||
} else {
|
} else {
|
||||||
return _dcDao.allocatePrivateIpAddress(dcId, podId, proxyId);
|
return _dcDao.allocatePrivateIpAddress(dcId, podId, proxyId, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1804,7 +1804,7 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, VirtualMach
|
|||||||
String guestIpAddress = proxy.getGuestIpAddress();
|
String guestIpAddress = proxy.getGuestIpAddress();
|
||||||
if (guestIpAddress != null) {
|
if (guestIpAddress != null) {
|
||||||
proxy.setGuestIpAddress(null);
|
proxy.setGuestIpAddress(null);
|
||||||
_dcDao.releaseLinkLocalPrivateIpAddress(guestIpAddress, proxy.getDataCenterId(), proxy.getId());
|
_dcDao.releaseLinkLocalIpAddress(guestIpAddress, proxy.getDataCenterId(), proxy.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_consoleProxyDao.updateIf(proxy, ev, null)) {
|
if (!_consoleProxyDao.updateIf(proxy, ev, null)) {
|
||||||
|
|||||||
@ -179,7 +179,7 @@ public class Db20to21MigrationUtil {
|
|||||||
|
|
||||||
/*local link ip address starts from 169.254.0.2 - 169.254.(nums)*/
|
/*local link ip address starts from 169.254.0.2 - 169.254.(nums)*/
|
||||||
String[] ipRanges = NetUtils.getLinkLocalIPRange(nums);
|
String[] ipRanges = NetUtils.getLinkLocalIPRange(nums);
|
||||||
_dcDao.addLinkLocalPrivateIpAddress(zoneId, pod.getId(), ipRanges[0], ipRanges[1]);
|
_dcDao.addLinkLocalIpAddress(zoneId, pod.getId(), ipRanges[0], ipRanges[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -568,7 +568,7 @@ public class Db20to21MigrationUtil {
|
|||||||
proxy.setState(State.Stopping);
|
proxy.setState(State.Stopping);
|
||||||
}
|
}
|
||||||
|
|
||||||
String guestIpAddress = _dcDao.allocateLinkLocalPrivateIpAddress(proxy.getDataCenterId(), proxy.getPodId(), proxy.getId());
|
String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(proxy.getDataCenterId(), proxy.getPodId(), proxy.getId(), null);
|
||||||
proxy.setGuestIpAddress(guestIpAddress);
|
proxy.setGuestIpAddress(guestIpAddress);
|
||||||
proxy.setGuestNetmask("255.255.0.0");
|
proxy.setGuestNetmask("255.255.0.0");
|
||||||
|
|
||||||
@ -595,7 +595,7 @@ public class Db20to21MigrationUtil {
|
|||||||
secStorageVm.setState(State.Stopping);
|
secStorageVm.setState(State.Stopping);
|
||||||
}
|
}
|
||||||
|
|
||||||
String guestIpAddress = _dcDao.allocateLinkLocalPrivateIpAddress(secStorageVm.getDataCenterId(), secStorageVm.getPodId(), secStorageVm.getId());
|
String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(secStorageVm.getDataCenterId(), secStorageVm.getPodId(), secStorageVm.getId(), null);
|
||||||
secStorageVm.setGuestIpAddress(guestIpAddress);
|
secStorageVm.setGuestIpAddress(guestIpAddress);
|
||||||
secStorageVm.setGuestNetmask("255.255.0.0");
|
secStorageVm.setGuestNetmask("255.255.0.0");
|
||||||
|
|
||||||
|
|||||||
@ -328,8 +328,8 @@ public class NetworkConfigurationVO implements NetworkConfiguration {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder buf = new StringBuilder("NtwkCfg:");
|
StringBuilder buf = new StringBuilder("NtwkCfg[");
|
||||||
buf.append(id).append("-").append(trafficType.toString()).append("-").append(networkOfferingId);
|
buf.append(id).append("|").append(trafficType.toString()).append("|").append(networkOfferingId).append("]");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -356,4 +356,6 @@ public interface NetworkManager {
|
|||||||
VpnUserVO addVpnUser(AddVpnUserCmd cmd) throws ConcurrentOperationException;
|
VpnUserVO addVpnUser(AddVpnUserCmd cmd) throws ConcurrentOperationException;
|
||||||
|
|
||||||
boolean removeVpnUser(RemoveVpnUserCmd cmd) throws ConcurrentOperationException;
|
boolean removeVpnUser(RemoveVpnUserCmd cmd) throws ConcurrentOperationException;
|
||||||
|
|
||||||
|
String getNextAvailableMacAddressInNetwork(long networkConfigurationId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -372,9 +372,9 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||||||
@Override @DB
|
@Override @DB
|
||||||
public String assignSourceNatIpAddress(Account account, DataCenter dc) throws InsufficientAddressCapacityException {
|
public String assignSourceNatIpAddress(Account account, DataCenter dc) throws InsufficientAddressCapacityException {
|
||||||
final long dcId = dc.getId();
|
final long dcId = dc.getId();
|
||||||
|
final long accountId = account.getId();
|
||||||
String sourceNat = null;
|
String sourceNat = null;
|
||||||
|
|
||||||
final long accountId = account.getId();
|
|
||||||
|
|
||||||
Transaction txn = Transaction.currentTxn();
|
Transaction txn = Transaction.currentTxn();
|
||||||
try {
|
try {
|
||||||
@ -2043,13 +2043,12 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||||||
URI isolationUri = nic.getIsolationUri();
|
URI isolationUri = nic.getIsolationUri();
|
||||||
|
|
||||||
profile = new NicProfile(nic, config, broadcastUri, isolationUri);
|
profile = new NicProfile(nic, config, broadcastUri, isolationUri);
|
||||||
String reservationId = concierge.reserve(profile, config, vmProfile, dest, context);
|
concierge.reserve(profile, config, vmProfile, dest, context);
|
||||||
nic.setIp4Address(profile.getIp4Address());
|
nic.setIp4Address(profile.getIp4Address());
|
||||||
nic.setIp6Address(profile.getIp6Address());
|
nic.setIp6Address(profile.getIp6Address());
|
||||||
nic.setMacAddress(profile.getMacAddress());
|
nic.setMacAddress(profile.getMacAddress());
|
||||||
nic.setIsolationUri(profile.getIsolationUri());
|
nic.setIsolationUri(profile.getIsolationUri());
|
||||||
nic.setBroadcastUri(profile.getBroadCastUri());
|
nic.setBroadcastUri(profile.getBroadCastUri());
|
||||||
nic.setReservationId(reservationId);
|
|
||||||
nic.setReserver(concierge.getName());
|
nic.setReserver(concierge.getName());
|
||||||
nic.setState(Resource.State.Reserved);
|
nic.setState(Resource.State.Reserved);
|
||||||
nic.setNetmask(profile.getNetmask());
|
nic.setNetmask(profile.getNetmask());
|
||||||
@ -2077,25 +2076,14 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||||||
NetworkGuru concierge = _networkGurus.get(config.getGuruName());
|
NetworkGuru concierge = _networkGurus.get(config.getGuruName());
|
||||||
nic.setState(Resource.State.Releasing);
|
nic.setState(Resource.State.Releasing);
|
||||||
_nicDao.update(nic.getId(), nic);
|
_nicDao.update(nic.getId(), nic);
|
||||||
concierge.release(nic.getReservationId());
|
NicProfile profile = new NicProfile(nic, config, null, null);
|
||||||
}
|
if (!concierge.release(profile, vmProfile, nic.getReservationId())) {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void release(long vmId) {
|
|
||||||
List<NicVO> nics = _nicDao.listBy(vmId);
|
|
||||||
|
|
||||||
for (NicVO nic : nics) {
|
|
||||||
nic.setState(Resource.State.Releasing);
|
|
||||||
_nicDao.update(nic.getId(), nic);
|
|
||||||
NetworkGuru concierge = _networkGurus.get(nic.getReserver());
|
|
||||||
if (!concierge.release(nic.getReservationId())) {
|
|
||||||
s_logger.warn("Unable to release " + nic + " using " + concierge.getName());
|
|
||||||
}
|
|
||||||
nic.setState(Resource.State.Allocated);
|
nic.setState(Resource.State.Allocated);
|
||||||
_nicDao.update(nic.getId(), nic);
|
_nicDao.update(nic.getId(), nic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<NicVO> getNics(VMInstanceVO vm) {
|
public List<NicVO> getNics(VMInstanceVO vm) {
|
||||||
@ -2932,4 +2920,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||||||
return _networkOfferingDao.listNonSystemNetworkOfferings();
|
return _networkOfferingDao.listNonSystemNetworkOfferings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNextAvailableMacAddressInNetwork(long networkConfigurationId) {
|
||||||
|
return _networkConfigDao.getNextAvailableMacAddress(networkConfigurationId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,30 +60,6 @@ public class ControlNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
|
||||||
super.configure(name, params);
|
|
||||||
|
|
||||||
ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
|
||||||
|
|
||||||
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
|
|
||||||
Map<String, String> dbParams = configDao.getConfiguration(params);
|
|
||||||
|
|
||||||
_cidr = dbParams.get(Config.ControlCidr);
|
|
||||||
if (_cidr == null) {
|
|
||||||
_cidr = "169.254.0.0/16";
|
|
||||||
}
|
|
||||||
|
|
||||||
_gateway = dbParams.get(Config.ControlGateway);
|
|
||||||
if (_gateway == null) {
|
|
||||||
_gateway = "169.254.0.1";
|
|
||||||
}
|
|
||||||
|
|
||||||
s_logger.info("Control network setup: cidr=" + _cidr + "; gateway = " + _gateway);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
|
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
|
||||||
InsufficientAddressCapacityException {
|
InsufficientAddressCapacityException {
|
||||||
@ -103,29 +79,65 @@ public class ControlNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
|
public void reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
|
||||||
InsufficientAddressCapacityException {
|
InsufficientAddressCapacityException {
|
||||||
String ip = _dcDao.allocateLinkLocalPrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), vm.getId());
|
assert nic.getTrafficType() == TrafficType.Control;
|
||||||
|
|
||||||
|
String ip = _dcDao.allocateLinkLocalIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), vm.getId(), context.getReservationId());
|
||||||
nic.setIp4Address(ip);
|
nic.setIp4Address(ip);
|
||||||
nic.setMacAddress(NetUtils.long2Mac(NetUtils.ip2Long(ip) | (14l << 40)));
|
nic.setMacAddress(NetUtils.long2Mac(NetUtils.ip2Long(ip) | (14l << 40)));
|
||||||
nic.setNetmask("255.255.0.0");
|
nic.setNetmask("255.255.0.0");
|
||||||
nic.setFormat(AddressFormat.Ip4);
|
nic.setFormat(AddressFormat.Ip4);
|
||||||
|
nic.setGateway(NetUtils.getLinkLocalGateway());
|
||||||
return Long.toString(nic.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean release(String uniqueId) {
|
public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, String reservationId) {
|
||||||
_dcDao.releaseLinkLocalPrivateIpAddress(Long.parseLong(uniqueId));
|
assert nic.getTrafficType() == TrafficType.Control;
|
||||||
|
|
||||||
|
_dcDao.releaseLinkLocalIpAddress(nic.getId(), reservationId);
|
||||||
|
nic.setIp4Address(null);
|
||||||
|
nic.setMacAddress(null);
|
||||||
|
nic.setNetmask(null);
|
||||||
|
nic.setFormat(null);
|
||||||
|
nic.setGateway(null);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination, ReservationContext context) {
|
public NetworkConfiguration implement(NetworkConfiguration config, NetworkOffering offering, DeployDestination destination, ReservationContext context) {
|
||||||
|
assert config.getTrafficType() == TrafficType.Control : "Why are you sending this configuration to me " + config;
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy(NetworkConfiguration config, NetworkOffering offering) {
|
public void destroy(NetworkConfiguration config, NetworkOffering offering) {
|
||||||
|
assert false : "Destroying a link local...Either you're out of your mind or something has changed.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||||
|
super.configure(name, params);
|
||||||
|
|
||||||
|
ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||||
|
|
||||||
|
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
|
||||||
|
Map<String, String> dbParams = configDao.getConfiguration(params);
|
||||||
|
|
||||||
|
_cidr = dbParams.get(Config.ControlCidr);
|
||||||
|
if (_cidr == null) {
|
||||||
|
_cidr = "169.254.0.0/16";
|
||||||
|
}
|
||||||
|
|
||||||
|
_gateway = dbParams.get(Config.ControlGateway);
|
||||||
|
if (_gateway == null) {
|
||||||
|
_gateway = NetUtils.getLinkLocalGateway();
|
||||||
|
}
|
||||||
|
|
||||||
|
s_logger.info("Control network setup: cidr=" + _cidr + "; gateway = " + _gateway);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,18 @@
|
|||||||
/**
|
/**
|
||||||
|
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is licensed under the GNU General Public License v3 or later.
|
||||||
|
*
|
||||||
|
* It is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package com.cloud.network.configuration;
|
package com.cloud.network.configuration;
|
||||||
@ -24,7 +38,7 @@ import com.cloud.network.Network.TrafficType;
|
|||||||
import com.cloud.network.NetworkConfiguration;
|
import com.cloud.network.NetworkConfiguration;
|
||||||
import com.cloud.network.NetworkConfiguration.State;
|
import com.cloud.network.NetworkConfiguration.State;
|
||||||
import com.cloud.network.NetworkConfigurationVO;
|
import com.cloud.network.NetworkConfigurationVO;
|
||||||
import com.cloud.network.dao.NetworkConfigurationDao;
|
import com.cloud.network.NetworkManager;
|
||||||
import com.cloud.offering.NetworkOffering;
|
import com.cloud.offering.NetworkOffering;
|
||||||
import com.cloud.offering.NetworkOffering.GuestIpType;
|
import com.cloud.offering.NetworkOffering.GuestIpType;
|
||||||
import com.cloud.resource.Resource.ReservationStrategy;
|
import com.cloud.resource.Resource.ReservationStrategy;
|
||||||
@ -41,7 +55,7 @@ import com.cloud.vm.dao.NicDao;
|
|||||||
|
|
||||||
@Local(value=NetworkGuru.class)
|
@Local(value=NetworkGuru.class)
|
||||||
public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||||
@Inject protected NetworkConfigurationDao _networkConfigDao;
|
@Inject protected NetworkManager _networkMgr;
|
||||||
@Inject protected DataCenterDao _dcDao;
|
@Inject protected DataCenterDao _dcDao;
|
||||||
@Inject protected VlanDao _vlanDao;
|
@Inject protected VlanDao _vlanDao;
|
||||||
@Inject protected NicDao _nicDao;
|
@Inject protected NicDao _nicDao;
|
||||||
@ -158,7 +172,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (nic.getMacAddress() == null) {
|
if (nic.getMacAddress() == null) {
|
||||||
nic.setMacAddress(_networkConfigDao.getNextAvailableMacAddress(config.getId()));
|
nic.setMacAddress(_networkMgr.getNextAvailableMacAddressInNetwork(config.getId()));
|
||||||
if (nic.getMacAddress() == null) {
|
if (nic.getMacAddress() == null) {
|
||||||
throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses");
|
throw new InsufficientAddressCapacityException("Unable to allocate more mac addresses");
|
||||||
}
|
}
|
||||||
@ -187,7 +201,7 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
|
public void reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
|
||||||
InsufficientAddressCapacityException {
|
InsufficientAddressCapacityException {
|
||||||
assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";
|
assert (nic.getReservationStrategy() == ReservationStrategy.Start) : "What can I do for nics that are not allocated at start? ";
|
||||||
|
|
||||||
@ -198,11 +212,12 @@ public class GuestNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
nic.setNetmask(NetUtils.cidr2Netmask(config.getCidr()));
|
nic.setNetmask(NetUtils.cidr2Netmask(config.getCidr()));
|
||||||
nic.setDns1(config.getDns1());
|
nic.setDns1(config.getDns1());
|
||||||
nic.setDns2(config.getDns2());
|
nic.setDns2(config.getDns2());
|
||||||
return "ABCD";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean release(String uniqueId) {
|
public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, String reservationId) {
|
||||||
|
nic.setBroadcastUri(null);
|
||||||
|
nic.setIsolationUri(null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import javax.ejb.Local;
|
|||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.dc.DataCenter;
|
|
||||||
import com.cloud.dc.Pod;
|
import com.cloud.dc.Pod;
|
||||||
import com.cloud.dc.dao.DataCenterDao;
|
import com.cloud.dc.dao.DataCenterDao;
|
||||||
import com.cloud.deploy.DeployDestination;
|
import com.cloud.deploy.DeployDestination;
|
||||||
@ -20,6 +19,7 @@ import com.cloud.network.Network.Mode;
|
|||||||
import com.cloud.network.Network.TrafficType;
|
import com.cloud.network.Network.TrafficType;
|
||||||
import com.cloud.network.NetworkConfiguration;
|
import com.cloud.network.NetworkConfiguration;
|
||||||
import com.cloud.network.NetworkConfigurationVO;
|
import com.cloud.network.NetworkConfigurationVO;
|
||||||
|
import com.cloud.network.NetworkManager;
|
||||||
import com.cloud.offering.NetworkOffering;
|
import com.cloud.offering.NetworkOffering;
|
||||||
import com.cloud.resource.Resource.ReservationStrategy;
|
import com.cloud.resource.Resource.ReservationStrategy;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
@ -35,6 +35,7 @@ import com.cloud.vm.VirtualMachineProfile;
|
|||||||
public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
||||||
private static final Logger s_logger = Logger.getLogger(PodBasedNetworkGuru.class);
|
private static final Logger s_logger = Logger.getLogger(PodBasedNetworkGuru.class);
|
||||||
@Inject DataCenterDao _dcDao;
|
@Inject DataCenterDao _dcDao;
|
||||||
|
@Inject NetworkManager _networkMgr;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkConfiguration design(NetworkOffering offering, DeploymentPlan plan, NetworkConfiguration userSpecified, Account owner) {
|
public NetworkConfiguration design(NetworkOffering offering, DeploymentPlan plan, NetworkConfiguration userSpecified, Account owner) {
|
||||||
@ -61,9 +62,7 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
|
public NicProfile allocate(NetworkConfiguration config, NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm) throws InsufficientVirtualNetworkCapcityException,
|
||||||
InsufficientAddressCapacityException {
|
InsufficientAddressCapacityException {
|
||||||
TrafficType trafficType = config.getTrafficType();
|
TrafficType trafficType = config.getTrafficType();
|
||||||
if (trafficType != TrafficType.Storage && trafficType != TrafficType.Management) {
|
assert (trafficType == TrafficType.Storage || trafficType == TrafficType.Management) : "Well, I can't take care of this config now can I? " + config;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nic != null) {
|
if (nic != null) {
|
||||||
nic.setStrategy(ReservationStrategy.Start);
|
nic.setStrategy(ReservationStrategy.Start);
|
||||||
@ -71,35 +70,33 @@ public class PodBasedNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
|
nic = new NicProfile(ReservationStrategy.Start, null, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId());
|
||||||
|
nic.setMacAddress(mac);
|
||||||
|
|
||||||
return nic;
|
return nic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
|
public void reserve(NicProfile nic, NetworkConfiguration config, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException,
|
||||||
InsufficientAddressCapacityException {
|
InsufficientAddressCapacityException {
|
||||||
DataCenter dc = dest.getDataCenter();
|
|
||||||
Pod pod = dest.getPod();
|
Pod pod = dest.getPod();
|
||||||
|
|
||||||
String ip = _dcDao.allocatePrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId());
|
String ip = _dcDao.allocatePrivateIpAddress(dest.getDataCenter().getId(), dest.getPod().getId(), nic.getId(), context.getReservationId());
|
||||||
if (ip == null) {
|
if (ip == null) {
|
||||||
throw new InsufficientAddressCapacityException("Unable to get a management ip address");
|
throw new InsufficientAddressCapacityException("Unable to get a management ip address");
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] macs = _dcDao.getNextAvailableMacAddressPair(dc.getId());
|
|
||||||
|
|
||||||
nic.setIp4Address(ip);
|
nic.setIp4Address(ip);
|
||||||
nic.setGateway(pod.getGateway());
|
nic.setGateway(pod.getGateway());
|
||||||
nic.setMacAddress(macs[0]);
|
|
||||||
nic.setFormat(AddressFormat.Ip4);
|
nic.setFormat(AddressFormat.Ip4);
|
||||||
String netmask = NetUtils.getCidrSubNet(pod.getCidrAddress(), pod.getCidrSize());
|
String netmask = NetUtils.getCidrSubNet(pod.getCidrAddress(), pod.getCidrSize());
|
||||||
nic.setNetmask(netmask);
|
nic.setNetmask(netmask);
|
||||||
|
|
||||||
return Long.toString(nic.getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean release(String uniqueId) {
|
public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, String reservationId) {
|
||||||
_dcDao.releasePrivateIpAddress(Long.parseLong(uniqueId));
|
_dcDao.releasePrivateIpAddress(nic.getId(), reservationId);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,8 @@ import com.cloud.network.Network.Mode;
|
|||||||
import com.cloud.network.Network.TrafficType;
|
import com.cloud.network.Network.TrafficType;
|
||||||
import com.cloud.network.NetworkConfiguration;
|
import com.cloud.network.NetworkConfiguration;
|
||||||
import com.cloud.network.NetworkConfigurationVO;
|
import com.cloud.network.NetworkConfigurationVO;
|
||||||
import com.cloud.network.dao.NetworkConfigurationDao;
|
import com.cloud.network.NetworkManager;
|
||||||
|
import com.cloud.network.dao.IPAddressDao;
|
||||||
import com.cloud.offering.NetworkOffering;
|
import com.cloud.offering.NetworkOffering;
|
||||||
import com.cloud.resource.Resource.ReservationStrategy;
|
import com.cloud.resource.Resource.ReservationStrategy;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
@ -41,7 +42,8 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
|
|
||||||
@Inject DataCenterDao _dcDao;
|
@Inject DataCenterDao _dcDao;
|
||||||
@Inject VlanDao _vlanDao;
|
@Inject VlanDao _vlanDao;
|
||||||
@Inject NetworkConfigurationDao _networkConfigDao;
|
@Inject NetworkManager _networkMgr;
|
||||||
|
@Inject IPAddressDao _ipAddressDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NetworkConfiguration design(NetworkOffering offering, DeploymentPlan plan, NetworkConfiguration config, Account owner) {
|
public NetworkConfiguration design(NetworkOffering offering, DeploymentPlan plan, NetworkConfiguration config, Account owner) {
|
||||||
@ -89,7 +91,7 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
nic.setStrategy(ReservationStrategy.Create);
|
nic.setStrategy(ReservationStrategy.Create);
|
||||||
}
|
}
|
||||||
|
|
||||||
String mac = _networkConfigDao.getNextAvailableMacAddress(config.getId());
|
String mac = _networkMgr.getNextAvailableMacAddressInNetwork(config.getId());
|
||||||
if (mac == null) {
|
if (mac == null) {
|
||||||
throw new InsufficientAddressCapacityException("Not enough mac addresses");
|
throw new InsufficientAddressCapacityException("Not enough mac addresses");
|
||||||
}
|
}
|
||||||
@ -102,21 +104,16 @@ public class PublicNetworkGuru extends AdapterBase implements NetworkGuru {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String reserve(NicProfile nic, NetworkConfiguration configuration, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
|
public void reserve(NicProfile nic, NetworkConfiguration configuration, VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException {
|
||||||
if (nic.getReservationId() != null) {
|
|
||||||
return nic.getReservationId();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nic.getIp4Address() == null) {
|
if (nic.getIp4Address() == null) {
|
||||||
getIp(nic, dest.getDataCenter(), vm);
|
getIp(nic, dest.getDataCenter(), vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nic.getReservationId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean release(String uniqueId) {
|
public boolean release(NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, String reservationId) {
|
||||||
return _vlanDao.releaseFromLockTable(Long.parseLong(uniqueId));
|
_ipAddressDao.unassignIpAddress(reservationId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -914,10 +914,10 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||||||
String privateNetMask = null;
|
String privateNetMask = null;
|
||||||
|
|
||||||
if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString())) {
|
if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString())) {
|
||||||
privateIpAddress = _dcDao.allocateLinkLocalPrivateIpAddress(router.getDataCenterId(), routingHost.getPodId(), router.getId());
|
privateIpAddress = _dcDao.allocateLinkLocalIpAddress(router.getDataCenterId(), routingHost.getPodId(), router.getId(), null);
|
||||||
privateNetMask = NetUtils.getLinkLocalNetMask();
|
privateNetMask = NetUtils.getLinkLocalNetMask();
|
||||||
} else {
|
} else {
|
||||||
privateIpAddress = _dcDao.allocatePrivateIpAddress(router.getDataCenterId(), routingHost.getPodId(), router.getId());
|
privateIpAddress = _dcDao.allocatePrivateIpAddress(router.getDataCenterId(), routingHost.getPodId(), router.getId(), null);
|
||||||
privateNetMask = NetUtils.getCidrNetmask(pod.getCidrSize());
|
privateNetMask = NetUtils.getCidrNetmask(pod.getCidrSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1023,7 +1023,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||||||
router.setPrivateIpAddress(null);
|
router.setPrivateIpAddress(null);
|
||||||
|
|
||||||
if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString()))
|
if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString()))
|
||||||
_dcDao.releaseLinkLocalPrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
|
_dcDao.releaseLinkLocalIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
|
||||||
else
|
else
|
||||||
_dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
|
_dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
|
||||||
|
|
||||||
@ -1571,7 +1571,7 @@ public class DomainRouterManagerImpl implements DomainRouterManager, DomainRoute
|
|||||||
|
|
||||||
if (privateIpAddress != null) {
|
if (privateIpAddress != null) {
|
||||||
if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString()))
|
if(_defaultHypervisorType == null || !_defaultHypervisorType.equalsIgnoreCase(Hypervisor.HypervisorType.VmWare.toString()))
|
||||||
_dcDao.releaseLinkLocalPrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
|
_dcDao.releaseLinkLocalIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
|
||||||
else
|
else
|
||||||
_dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
|
_dcDao.releasePrivateIpAddress(privateIpAddress, router.getDataCenterId(), router.getId());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -625,7 +625,7 @@ public class ConfigurationServerImpl implements ConfigurationServer {
|
|||||||
if (linkLocalIpRanges == null) {
|
if (linkLocalIpRanges == null) {
|
||||||
throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "may be wrong, should be 1~16");
|
throw new InvalidParameterValueException("The linkLocalIp.nums: " + nums + "may be wrong, should be 1~16");
|
||||||
} else {
|
} else {
|
||||||
_zoneDao.addLinkLocalPrivateIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]);
|
_zoneDao.addLinkLocalIpAddress(zoneId, pod.getId(), linkLocalIpRanges[0], linkLocalIpRanges[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
|||||||
@ -363,7 +363,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
|||||||
}
|
}
|
||||||
|
|
||||||
secStorageVm.setPrivateIpAddress(privateIpAddress);
|
secStorageVm.setPrivateIpAddress(privateIpAddress);
|
||||||
String guestIpAddress = _dcDao.allocateLinkLocalPrivateIpAddress(secStorageVm.getDataCenterId(), routingHost.getPodId(), secStorageVm.getId());
|
String guestIpAddress = _dcDao.allocateLinkLocalIpAddress(secStorageVm.getDataCenterId(), routingHost.getPodId(), secStorageVm.getId(), null);
|
||||||
secStorageVm.setGuestIpAddress(guestIpAddress);
|
secStorageVm.setGuestIpAddress(guestIpAddress);
|
||||||
_secStorageVmDao.updateIf(secStorageVm, Event.OperationRetry, routingHost.getId());
|
_secStorageVmDao.updateIf(secStorageVm, Event.OperationRetry, routingHost.getId());
|
||||||
secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
|
secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
|
||||||
@ -452,7 +452,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
|||||||
freePrivateIpAddress(privateIpAddress, secStorageVm
|
freePrivateIpAddress(privateIpAddress, secStorageVm
|
||||||
.getDataCenterId(), secStorageVm.getId());
|
.getDataCenterId(), secStorageVm.getId());
|
||||||
secStorageVm.setGuestIpAddress(null);
|
secStorageVm.setGuestIpAddress(null);
|
||||||
_dcDao.releaseLinkLocalPrivateIpAddress(guestIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId());
|
_dcDao.releaseLinkLocalIpAddress(guestIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId());
|
||||||
_storageMgr.unshare(secStorageVm, vols, routingHost);
|
_storageMgr.unshare(secStorageVm, vols, routingHost);
|
||||||
} while (--retry > 0 && (routingHost = (HostVO) _agentMgr.findHost(
|
} while (--retry > 0 && (routingHost = (HostVO) _agentMgr.findHost(
|
||||||
Host.Type.Routing, dc, pod, sp, _serviceOffering, _template,
|
Host.Type.Routing, dc, pod, sp, _serviceOffering, _template,
|
||||||
@ -859,7 +859,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
|||||||
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
|
if (_IpAllocator != null && _IpAllocator.exteralIpAddressAllocatorEnabled()) {
|
||||||
return _IpAllocator.getPrivateIpAddress(macAddr, dcId, podId).ipaddr;
|
return _IpAllocator.getPrivateIpAddress(macAddr, dcId, podId).ipaddr;
|
||||||
} else {
|
} else {
|
||||||
return _dcDao.allocatePrivateIpAddress(dcId, podId, proxyId);
|
return _dcDao.allocatePrivateIpAddress(dcId, podId, proxyId, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1447,7 +1447,7 @@ public class SecondaryStorageManagerImpl implements SecondaryStorageVmManager, V
|
|||||||
String guestIpAddress = secStorageVm.getGuestIpAddress();
|
String guestIpAddress = secStorageVm.getGuestIpAddress();
|
||||||
if (guestIpAddress != null) {
|
if (guestIpAddress != null) {
|
||||||
secStorageVm.setGuestIpAddress(null);
|
secStorageVm.setGuestIpAddress(null);
|
||||||
_dcDao.releaseLinkLocalPrivateIpAddress(guestIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId());
|
_dcDao.releaseLinkLocalIpAddress(guestIpAddress, secStorageVm.getDataCenterId(), secStorageVm.getId());
|
||||||
}
|
}
|
||||||
if (!_secStorageVmDao.updateIf(secStorageVm, ev, null)) {
|
if (!_secStorageVmDao.updateIf(secStorageVm, ev, null)) {
|
||||||
s_logger.debug("Unable to update the secondary storage vm");
|
s_logger.debug("Unable to update the secondary storage vm");
|
||||||
|
|||||||
@ -403,6 +403,7 @@ CREATE TABLE `cloud`.`op_dc_link_local_ip_address_alloc` (
|
|||||||
`data_center_id` bigint unsigned NOT NULL COMMENT 'data center it belongs to',
|
`data_center_id` bigint unsigned NOT NULL COMMENT 'data center it belongs to',
|
||||||
`pod_id` bigint unsigned NOT NULL COMMENT 'pod it belongs to',
|
`pod_id` bigint unsigned NOT NULL COMMENT 'pod it belongs to',
|
||||||
`instance_id` bigint unsigned NULL COMMENT 'instance id',
|
`instance_id` bigint unsigned NULL COMMENT 'instance id',
|
||||||
|
`reservation_id` char(40) NULL COMMENT 'reservation id used to reserve this network',
|
||||||
`taken` datetime COMMENT 'Date taken',
|
`taken` datetime COMMENT 'Date taken',
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user