use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ServerDBSyncImpl method equalFloatingIp.
public Boolean equalFloatingIp(IPAddressVO db, FloatingIp vnc, StringBuffer syncLogMsg) throws IOException {
syncLogMsg.append("fip# DB: " + db.getAddress().addr() + "; VNC: " + vnc.getAddress() + "; action: equal" + "\n");
VirtualNetworkModel vnModel = _manager.lookupPublicNetworkModel();
assert vnModel != null : "public network vn model is null";
FloatingIpPoolModel fipPoolModel = vnModel.getFipPoolModel();
if (fipPoolModel == null) {
fipPoolModel = new FloatingIpPoolModel();
fipPoolModel.addToVirtualNetwork(vnModel);
fipPoolModel.build(_manager.getModelController());
try {
fipPoolModel.update(_manager.getModelController());
vnModel.setFipPoolModel(fipPoolModel);
} catch (Exception ex) {
s_logger.warn("floating-ip-pool create: ", ex);
return false;
}
}
FloatingIpModel current = fipPoolModel.getFloatingIpModel(db.getUuid());
if (current == null) {
s_logger.debug("add model " + db.getAddress().addr());
FloatingIpModel fipModel = new FloatingIpModel(db.getUuid());
fipModel.addToFloatingIpPool(fipPoolModel);
fipModel.build(_manager.getModelController(), PublicIp.createFromAddrAndVlan(db, _vlanDao.findById(db.getVlanId())));
try {
fipModel.update(_manager.getModelController());
} catch (Exception ex) {
s_logger.warn("floating-ip create: ", ex);
return false;
}
}
return true;
}
use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ServerDBSyncImpl method createVirtualNetwork.
public void createVirtualNetwork(NetworkVO dbNet, StringBuffer syncLogMesg) throws IOException {
syncLogMesg.append("VN# DB: " + _manager.getCanonicalName(dbNet) + "(" + dbNet.getUuid() + "); VNC: none; action: create\n");
if (_manager.getDatabase().lookupVirtualNetwork(dbNet.getUuid(), _manager.getCanonicalName(dbNet), dbNet.getTrafficType()) != null) {
s_logger.warn("VN model object is already present in DB: " + dbNet.getUuid() + ", name: " + dbNet.getName());
}
VirtualNetworkModel vnModel = new VirtualNetworkModel(dbNet, dbNet.getUuid(), _manager.getCanonicalName(dbNet), dbNet.getTrafficType());
if (dbNet.getTrafficType() == TrafficType.Guest && dbNet.getNetworkACLId() != null) {
NetworkACLVO acl = _networkACLDao.findById(dbNet.getNetworkACLId());
NetworkPolicyModel policyModel = _manager.getDatabase().lookupNetworkPolicy(acl.getUuid());
if (policyModel == null) {
s_logger.error("Network(" + dbNet.getName() + ") has ACL but policy model not created: " + acl.getUuid() + ", name: " + acl.getName());
} else {
vnModel.addToNetworkPolicy(policyModel);
}
}
vnModel.build(_manager.getModelController(), dbNet);
if (_rwMode) {
try {
if (!vnModel.verify(_manager.getModelController())) {
vnModel.update(_manager.getModelController());
}
} catch (InternalErrorException ex) {
s_logger.warn("create virtual-network", ex);
syncLogMesg.append("Error: VN# VNC : Unable to create network " + dbNet.getName() + "\n");
return;
}
s_logger.debug("add model " + vnModel.getName());
_manager.getDatabase().getVirtualNetworks().add(vnModel);
syncLogMesg.append("VN# VNC: " + dbNet.getUuid() + ", " + vnModel.getName() + " created\n");
} else {
syncLogMesg.append("VN# VNC: " + vnModel.getName() + " created \n");
}
}
use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ContrailGuru method implement.
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination destination, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
s_logger.debug("Implement network: " + network.getName() + ", traffic type: " + network.getTrafficType());
VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
if (vnModel == null) {
vnModel = new VirtualNetworkModel(network, network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
vnModel.setProperties(_manager.getModelController(), network);
}
try {
if (!vnModel.verify(_manager.getModelController())) {
vnModel.update(_manager.getModelController());
}
} catch (Exception ex) {
s_logger.warn("virtual-network update: ", ex);
return network;
}
_manager.getDatabase().getVirtualNetworks().add(vnModel);
if (network.getVpcId() != null) {
List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(network.getVpcId(), true);
if (ips.isEmpty()) {
s_logger.debug("Creating a source nat ip for network " + network);
Account owner = _accountMgr.getAccount(network.getAccountId());
try {
PublicIp publicIp = _ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
IPAddressVO ip = publicIp.ip();
ip.setVpcId(network.getVpcId());
_ipAddressDao.acquireInLockTable(ip.getId());
_ipAddressDao.update(ip.getId(), ip);
_ipAddressDao.releaseFromLockTable(ip.getId());
} catch (Exception e) {
s_logger.error("Unable to allocate source nat ip: " + e);
}
}
}
return network;
}
use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ContrailGuru method shutdown.
@Override
public void shutdown(NetworkProfile network, NetworkOffering offering) {
s_logger.debug("NetworkGuru shutdown");
VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
if (vnModel == null) {
return;
}
try {
_manager.getDatabase().getVirtualNetworks().remove(vnModel);
vnModel.delete(_manager.getModelController());
} catch (IOException e) {
s_logger.warn("virtual-network delete", e);
}
}
use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ContrailElementImpl method implement.
/**
* Network add/update.
*/
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
s_logger.debug("NetworkElement implement: " + network.getName() + ", traffic type: " + network.getTrafficType());
if (network.getTrafficType() == TrafficType.Guest) {
s_logger.debug("ignore network " + network.getName());
return true;
}
VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
if (vnModel == null) {
vnModel = new VirtualNetworkModel(network, network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
vnModel.setProperties(_manager.getModelController(), network);
}
try {
if (!vnModel.verify(_manager.getModelController())) {
vnModel.update(_manager.getModelController());
}
_manager.getDatabase().getVirtualNetworks().add(vnModel);
} catch (Exception ex) {
s_logger.warn("virtual-network update: ", ex);
}
return true;
}
Aggregations