use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ContrailElementImpl method prepare.
@Override
public boolean prepare(Network network, NicProfile nicProfile, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
s_logger.debug("NetworkElement prepare: " + network.getName() + ", traffic type: " + network.getTrafficType());
if (network.getTrafficType() == TrafficType.Guest) {
s_logger.debug("ignore network " + network.getName());
return true;
}
s_logger.debug("network: " + network.getId());
VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
if (vnModel == null) {
// this may be the first time we see this network.
return false;
}
VirtualMachineModel vmModel = _manager.getDatabase().lookupVirtualMachine(vm.getUuid());
if (vmModel == null) {
VMInstanceVO vmVo = (VMInstanceVO) vm.getVirtualMachine();
vmModel = new VirtualMachineModel(vmVo, vm.getUuid());
vmModel.setProperties(_manager.getModelController(), vmVo);
}
NicVO nic = _nicDao.findById(nicProfile.getId());
assert nic != null;
VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
if (vmiModel == null) {
vmiModel = new VMInterfaceModel(nic.getUuid());
vmiModel.addToVirtualMachine(vmModel);
vmiModel.addToVirtualNetwork(vnModel);
}
try {
vmiModel.build(_manager.getModelController(), (VMInstanceVO) vm.getVirtualMachine(), nic);
} catch (IOException ex) {
s_logger.warn("vm interface set", ex);
return false;
}
InstanceIpModel ipModel = vmiModel.getInstanceIp();
if (ipModel == null) {
ipModel = new InstanceIpModel(vm.getInstanceName(), nic.getDeviceId());
ipModel.addToVMInterface(vmiModel);
}
ipModel.setAddress(nicProfile.getIPv4Address());
try {
vmModel.update(_manager.getModelController());
} catch (Exception ex) {
s_logger.warn("virtual-machine-update", ex);
return false;
}
_manager.getDatabase().getVirtualMachines().add(vmModel);
return true;
}
use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ContrailManagerImpl method lookupPublicNetworkModel.
@Override
public VirtualNetworkModel lookupPublicNetworkModel() {
List<TrafficType> types = new ArrayList<TrafficType>();
types.add(TrafficType.Public);
List<NetworkVO> dbNets = findManagedNetworks(types);
if (dbNets == null) {
return null;
}
NetworkVO net = dbNets.get(0);
VirtualNetworkModel vnModel = getDatabase().lookupVirtualNetwork(net.getUuid(), getCanonicalName(net), TrafficType.Public);
if (vnModel == null) {
vnModel = new VirtualNetworkModel(net, net.getUuid(), getCanonicalName(net), net.getTrafficType());
vnModel.setProperties(getModelController(), net);
}
try {
if (!vnModel.verify(getModelController())) {
vnModel.update(getModelController());
}
getDatabase().getVirtualNetworks().add(vnModel);
} catch (Exception ex) {
s_logger.warn("virtual-network update: ", ex);
}
return vnModel;
}
use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ContrailManagerImpl method deleteFloatingIp.
@Override
public boolean deleteFloatingIp(PublicIpAddress ip) {
VirtualNetworkModel vnModel = lookupPublicNetworkModel();
assert vnModel != null : "public network model is null";
FloatingIpPoolModel fipPoolModel = vnModel.getFipPoolModel();
FloatingIpModel fipModel = fipPoolModel.getFloatingIpModel(ip.getUuid());
if (fipModel != null) {
try {
fipModel.destroy(getModelController());
} catch (IOException ex) {
s_logger.warn("floating ip delete", ex);
return false;
}
fipPoolModel.removeSuccessor(fipModel);
if (!fipPoolModel.hasDescendents()) {
try {
fipPoolModel.delete(getModelController());
vnModel.setFipPoolModel(null);
} catch (IOException e) {
return false;
}
}
}
return true;
}
use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ModelDatabase method lookupVirtualNetwork.
public VirtualNetworkModel lookupVirtualNetwork(String uuid, String name, TrafficType ttype) {
VirtualNetworkModel vnKey = new VirtualNetworkModel(null, uuid, name, ttype);
VirtualNetworkModel current = _vnTable.ceiling(vnKey);
if (current != null) {
if (ttype == TrafficType.Management || ttype == TrafficType.Storage || ttype == TrafficType.Control) {
if (current.getName().equals(name)) {
return current;
}
} else if (current.getUuid().equals(uuid)) {
return current;
}
}
return null;
}
use of org.apache.cloudstack.network.contrail.model.VirtualNetworkModel in project cloudstack by apache.
the class ServerDBSyncImpl method buildNicResources.
private void buildNicResources(VirtualMachineModel vmModel, VMInstanceVO dbVm, StringBuffer syncLogMsg) throws IOException {
List<NicVO> nics = _nicDao.listByVmId(dbVm.getId());
for (NicVO nic : nics) {
VMInterfaceModel vmiModel = vmModel.getVMInterface(nic.getUuid());
if (vmiModel == null) {
vmiModel = new VMInterfaceModel(nic.getUuid());
NetworkVO network = _networksDao.findById(nic.getNetworkId());
VirtualNetworkModel vnModel = _manager.getDatabase().lookupVirtualNetwork(network.getUuid(), _manager.getCanonicalName(network), network.getTrafficType());
if (vnModel == null) {
s_logger.warn("Unable to locate virtual-network for network id " + network.getId());
continue;
}
vmiModel.addToVirtualMachine(vmModel);
vmiModel.addToVirtualNetwork(vnModel);
}
vmiModel.build(_manager.getModelController(), dbVm, nic);
}
}
Aggregations