use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class VMwareGuru method finalizeExpungeNics.
@Override
public List<Command> finalizeExpungeNics(VirtualMachine vm, List<NicProfile> nics) {
List<Command> commands = new ArrayList<Command>();
List<NicVO> nicVOs = _nicDao.listByVmId(vm.getId());
for (NicVO nic : nicVOs) {
NetworkVO network = _networkDao.findById(nic.getNetworkId());
if (network.getBroadcastDomainType() == BroadcastDomainType.Lswitch) {
s_logger.debug("Nic " + nic.toString() + " is connected to an lswitch, cleanup required");
NetworkVO networkVO = _networkDao.findById(nic.getNetworkId());
// We need the traffic label to figure out which vSwitch has the
// portgroup
PhysicalNetworkTrafficTypeVO trafficTypeVO = _physicalNetworkTrafficTypeDao.findBy(networkVO.getPhysicalNetworkId(), networkVO.getTrafficType());
UnregisterNicCommand unregisterNicCommand = new UnregisterNicCommand(vm.getInstanceName(), trafficTypeVO.getVmwareNetworkLabel(), UUID.fromString(nic.getUuid()));
commands.add(unregisterNicCommand);
}
}
return commands;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class NetworkPolicyModel method build.
public void build(ModelController controller, List<? extends NetworkACLItem> rules) throws Exception {
String projectName = null;
if (_project != null) {
_fqName = StringUtils.join(_project.getQualifiedName(), ':') + ":" + _name;
projectName = StringUtils.join(_project.getQualifiedName(), ':');
} else {
_fqName = ContrailManager.VNC_ROOT_DOMAIN + ":" + ContrailManager.VNC_DEFAULT_PROJECT + ":" + _name;
projectName = ContrailManager.VNC_ROOT_DOMAIN + ":" + ContrailManager.VNC_DEFAULT_PROJECT;
}
PolicyEntriesType policyMap = new PolicyEntriesType();
for (NetworkACLItem rule : rules) {
if (rule.getState() != NetworkACLItem.State.Active && rule.getState() != NetworkACLItem.State.Add) {
continue;
}
String action = null;
if (rule.getAction() == Action.Allow) {
action = "pass";
} else if (rule.getAction() == Action.Deny) {
action = "deny";
}
List<String> cidrList = rule.getSourceCidrList();
String protocol = rule.getProtocol();
if (protocol == null || protocol.equalsIgnoreCase("ALL") || protocol.isEmpty()) {
protocol = "any";
} else {
protocol = protocol.toLowerCase();
}
Integer portStart = rule.getSourcePortStart();
Integer portEnd = rule.getSourcePortEnd();
if (portStart == null) {
portStart = 0;
}
if (portEnd == null) {
portEnd = 65535;
}
List<PolicyRuleType.AddressType> srcList = new ArrayList<PolicyRuleType.AddressType>();
List<PolicyRuleType.AddressType> dstList = new ArrayList<PolicyRuleType.AddressType>();
List<PolicyRuleType.PortType> srcPorts = new ArrayList<PolicyRuleType.PortType>();
List<PolicyRuleType.PortType> dstPorts = new ArrayList<PolicyRuleType.PortType>();
if (rule.getTrafficType() == NetworkACLItem.TrafficType.Egress) {
for (String cidr : cidrList) {
NetworkVO net = cidrToNetwork(controller, cidr);
/*String[] maskInfo = StringUtils.splitByWholeSeparator(cidr, "/");
SubnetType subnet = new SubnetType();
subnet.setIpPrefix(maskInfo[0]);
subnet.setIpPrefixLen(Integer.parseInt(maskInfo[1]));
*/
String netName = projectName + ":" + controller.getManager().getCanonicalName(net);
dstList.add(new PolicyRuleType.AddressType(null, netName, null));
}
dstPorts.add(new PolicyRuleType.PortType(portStart, portEnd));
srcList.add(new PolicyRuleType.AddressType(null, "local", null));
srcPorts.add(new PolicyRuleType.PortType(0, 65535));
} else {
for (String cidr : cidrList) {
NetworkVO net = cidrToNetwork(controller, cidr);
String netName = projectName + ":" + controller.getManager().getCanonicalName(net);
srcList.add(new PolicyRuleType.AddressType(null, netName, null));
}
dstPorts.add(new PolicyRuleType.PortType(portStart, portEnd));
dstList.add(new PolicyRuleType.AddressType(null, "local", null));
srcPorts.add(new PolicyRuleType.PortType(0, 65535));
}
PolicyRuleType vnRule = new PolicyRuleType(new PolicyRuleType.SequenceType(1, 0), rule.getUuid(), "<>", protocol, srcList, srcPorts, null, dstList, dstPorts, new PolicyRuleType.ActionListType(action, null, null, null));
policyMap.addPolicyRule(vnRule);
}
_policyMap = policyMap;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class ServerDBSyncImpl method syncVirtualNetwork.
/*
* Virtual Network Synchronization methods
*/
@SuppressWarnings({ "unchecked" })
public boolean syncVirtualNetwork() throws Exception {
final ApiConnector api = _manager.getApiConnector();
try {
List<TrafficType> types = new ArrayList<TrafficType>();
types.add(TrafficType.Public);
types.add(TrafficType.Guest);
List<NetworkVO> dbNets = _manager.findManagedNetworks(types);
List<VirtualNetwork> vList = (List<VirtualNetwork>) api.list(VirtualNetwork.class, null);
List<VirtualNetwork> vncList = new ArrayList<VirtualNetwork>();
for (VirtualNetwork vn : vList) {
if (!_manager.isSystemDefaultNetwork(vn)) {
vncList.add(vn);
}
}
s_logger.debug("sync VN - DB size: " + dbNets.size() + " VNC Size: " + vncList.size());
return _dbSync.syncGeneric(VirtualNetwork.class, dbNets, vncList);
} catch (Exception ex) {
s_logger.warn("sync virtual-networks", ex);
throw ex;
}
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class OpendaylightGuestNetworkGuru method release.
@Override
public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
boolean success = super.release(nic, vm, reservationId);
if (success) {
//get physical network id
NetworkVO network = _networkDao.findById(nic.getNetworkId());
Long physicalNetworkId = network.getPhysicalNetworkId();
List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No Controller on physical network " + physicalNetworkId);
throw new CloudRuntimeException("No OpenDaylight controller on this physical network");
}
OpenDaylightControllerVO controller = devices.get(0);
DestroyPortCommand cmd = new DestroyPortCommand(UUID.fromString(nic.getUuid()));
DestroyPortAnswer answer = (DestroyPortAnswer) agentManager.easySend(controller.getHostId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("DestroyPortCommand failed");
success = false;
}
}
return success;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class OpendaylightGuestNetworkGuru method implement.
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
long dcId = dest.getDataCenter().getId();
//get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
// physical network id can be null in Guest Network in Basic zone, so locate the physical network
if (physicalNetworkId == null) {
physicalNetworkId = networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
}
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
// Name is either the given name or the uuid
String name = network.getName();
if (name == null || name.isEmpty()) {
name = ((NetworkVO) network).getUuid();
}
List<OpenDaylightControllerVO> devices = openDaylightControllerMappingDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) {
s_logger.error("No Controller on physical network " + physicalNetworkId);
return null;
}
OpenDaylightControllerVO controller = devices.get(0);
ConfigureNetworkCommand cmd = new ConfigureNetworkCommand(name, context.getAccount().getAccountName());
ConfigureNetworkAnswer answer = (ConfigureNetworkAnswer) agentManager.easySend(controller.getHostId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("ConfigureNetworkCommand failed");
return null;
}
implemented.setBroadcastUri(BroadcastDomainType.OpenDaylight.toUri(answer.getNetworkUuid()));
implemented.setBroadcastDomainType(BroadcastDomainType.OpenDaylight);
s_logger.info("Implemented OK, network linked to = " + implemented.getBroadcastUri().toString());
return implemented;
}
Aggregations