use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class NuageVspGuestNetworkGuruTest method testImplementNetwork.
@Test
public void testImplementNetwork() throws URISyntaxException, InsufficientVirtualNetworkCapacityException {
final NetworkVO network = mock(NetworkVO.class);
when(network.getId()).thenReturn(NETWORK_ID);
when(network.getUuid()).thenReturn("aaaaaa");
when(network.getDataCenterId()).thenReturn(NETWORK_ID);
when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(network.getDomainId()).thenReturn(NETWORK_ID);
when(network.getAccountId()).thenReturn(NETWORK_ID);
when(network.getVpcId()).thenReturn(null);
when(network.getState()).thenReturn(com.cloud.network.Network.State.Implementing);
when(network.getTrafficType()).thenReturn(TrafficType.Guest);
when(network.getMode()).thenReturn(Mode.Static);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
when(network.getBroadcastUri()).thenReturn(new URI("vsp://aaaaaa-aavvv/10.1.1.1"));
when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
when(network.getName()).thenReturn("iso");
final NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getTags()).thenReturn("aaaa");
when(offering.getEgressDefaultPolicy()).thenReturn(true);
when(_networkModel.findPhysicalNetworkId(NETWORK_ID, "aaa", TrafficType.Guest)).thenReturn(NETWORK_ID);
final ReservationContext reserveContext = mock(ReservationContext.class);
final Domain domain = mock(Domain.class);
when(domain.getId()).thenReturn(NETWORK_ID);
when(reserveContext.getDomain()).thenReturn(domain);
when(domain.getName()).thenReturn("aaaaa");
final Account account = mock(Account.class);
when(account.getId()).thenReturn(NETWORK_ID);
when(account.getAccountId()).thenReturn(NETWORK_ID);
when(reserveContext.getAccount()).thenReturn(account);
final DomainVO domainVo = mock(DomainVO.class);
when(_domainDao.findById(NETWORK_ID)).thenReturn(domainVo);
final AccountVO accountVo = mock(AccountVO.class);
when(_accountDao.findById(NETWORK_ID)).thenReturn(accountVo);
when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
when(_nuageVspManager.getDnsDetails(network.getDataCenterId())).thenReturn(new ArrayList<String>());
when(_nuageVspManager.getGatewaySystemIds()).thenReturn(new ArrayList<String>());
final DataCenter dc = mock(DataCenter.class);
when(dc.getId()).thenReturn(NETWORK_ID);
final DeployDestination deployDest = mock(DeployDestination.class);
when(deployDest.getDataCenter()).thenReturn(dc);
_nuageVspGuestNetworkGuru.implement(network, offering, deployDest, reserveContext);
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class ExternalFirewallDeviceManagerImpl method applyFirewallRules.
@Override
public boolean applyFirewallRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
// Find the external firewall in this zone
long zoneId = network.getDataCenterId();
DataCenterVO zone = _dcDao.findById(zoneId);
ExternalFirewallDeviceVO fwDeviceVO = getExternalFirewallForNetwork(network);
// During destroy, device reference may already been clean up, then we just return true
if (fwDeviceVO == null) {
return true;
}
HostVO externalFirewall = _hostDao.findById(fwDeviceVO.getHostId());
assert (externalFirewall != null);
if (network.getState() == Network.State.Allocated) {
s_logger.debug("External firewall was asked to apply firewall rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
return true;
}
List<FirewallRuleTO> rulesTO = new ArrayList<FirewallRuleTO>();
NetworkVO networkVO = _networkDao.findById(network.getId());
NetworkOfferingVO offering = _networkOfferingDao.findById(networkVO.getNetworkOfferingId());
Boolean defaultEgressPolicy = offering.getEgressDefaultPolicy();
for (FirewallRule rule : rules) {
if (rule.getSourceCidrList() == null && (rule.getPurpose() == Purpose.Firewall || rule.getPurpose() == Purpose.NetworkACL)) {
_fwRulesDao.loadSourceCidrs((FirewallRuleVO) rule);
}
FirewallRuleTO ruleTO;
if (rule.getPurpose() == Purpose.Firewall && rule.getTrafficType() == FirewallRule.TrafficType.Egress) {
String guestVlanTag = BroadcastDomainType.getValue(network.getBroadcastUri());
String guestCidr = network.getCidr();
ruleTO = new FirewallRuleTO(rule, guestVlanTag, rule.getTrafficType(), guestCidr, defaultEgressPolicy, rule.getType());
} else {
IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
ruleTO = new FirewallRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
}
rulesTO.add(ruleTO);
}
//Firewall rules configured for staticNAT/PF
sendFirewallRules(rulesTO, zone, externalFirewall.getId());
return true;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class HypervisorGuruBase method toNicTO.
@Override
public NicTO toNicTO(NicProfile profile) {
NicTO to = new NicTO();
to.setDeviceId(profile.getDeviceId());
to.setBroadcastType(profile.getBroadcastType());
to.setType(profile.getTrafficType());
to.setIp(profile.getIPv4Address());
to.setNetmask(profile.getIPv4Netmask());
to.setMac(profile.getMacAddress());
to.setDns1(profile.getIPv4Dns1());
to.setDns2(profile.getIPv4Dns2());
to.setGateway(profile.getIPv4Gateway());
to.setDefaultNic(profile.isDefaultNic());
to.setBroadcastUri(profile.getBroadCastUri());
to.setIsolationuri(profile.getIsolationUri());
to.setNetworkRateMbps(profile.getNetworkRate());
to.setName(profile.getName());
to.setSecurityGroupEnabled(profile.isSecurityGroupEnabled());
to.setIp6Address(profile.getIPv6Address());
to.setIp6Cidr(profile.getIPv6Cidr());
NetworkVO network = _networkDao.findById(profile.getNetworkId());
to.setNetworkUuid(network.getUuid());
// Workaround to make sure the TO has the UUID we need for Nicira integration
NicVO nicVO = _nicDao.findById(profile.getId());
if (nicVO != null) {
to.setUuid(nicVO.getUuid());
// disable pxe on system vm nics to speed up boot time
if (nicVO.getVmType() != VirtualMachine.Type.User) {
to.setPxeDisable(true);
}
List<String> secIps = null;
if (nicVO.getSecondaryIp()) {
secIps = _nicSecIpDao.getSecondaryIpAddressesForNic(nicVO.getId());
}
to.setNicSecIps(secIps);
} else {
s_logger.warn("Unabled to load NicVO for NicProfile " + profile.getId());
//Workaround for dynamically created nics
//FixMe: uuid and secondary IPs can be made part of nic profile
to.setUuid(UUID.randomUUID().toString());
}
// configuration. Use full when vm stop/start
return to;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method createGuestBootLoadArgs.
protected StringBuilder createGuestBootLoadArgs(final NicProfile guestNic, final String defaultDns1, final String defaultDns2, final DomainRouterVO router) {
final long guestNetworkId = guestNic.getNetworkId();
final NetworkVO guestNetwork = _networkDao.findById(guestNetworkId);
String dhcpRange = null;
final DataCenterVO dc = _dcDao.findById(guestNetwork.getDataCenterId());
final StringBuilder buf = new StringBuilder();
final boolean isRedundant = router.getIsRedundantRouter();
if (isRedundant) {
buf.append(createRedundantRouterArgs(guestNic, router));
final Network net = _networkModel.getNetwork(guestNic.getNetworkId());
buf.append(" guestgw=").append(net.getGateway());
final String brd = NetUtils.long2Ip(NetUtils.ip2Long(guestNic.getIPv4Address()) | ~NetUtils.ip2Long(guestNic.getIPv4Netmask()));
buf.append(" guestbrd=").append(brd);
buf.append(" guestcidrsize=").append(NetUtils.getCidrSize(guestNic.getIPv4Netmask()));
final int advertInt = NumbersUtil.parseInt(_configDao.getValue(Config.RedundantRouterVrrpInterval.key()), 1);
buf.append(" advert_int=").append(advertInt);
}
// setup network domain
final String domain = guestNetwork.getNetworkDomain();
if (domain != null) {
buf.append(" domain=" + domain);
}
long cidrSize = 0;
// setup dhcp range
if (dc.getNetworkType() == NetworkType.Basic) {
if (guestNic.isDefaultNic()) {
cidrSize = NetUtils.getCidrSize(guestNic.getIPv4Netmask());
final String cidr = NetUtils.getCidrSubNet(guestNic.getIPv4Gateway(), cidrSize);
if (cidr != null) {
dhcpRange = NetUtils.getIpRangeStartIpFromCidr(cidr, cidrSize);
}
}
} else if (dc.getNetworkType() == NetworkType.Advanced) {
final String cidr = guestNetwork.getCidr();
if (cidr != null) {
cidrSize = NetUtils.getCidrSize(NetUtils.getCidrNetmask(cidr));
dhcpRange = NetUtils.getDhcpRange(cidr);
}
}
if (dhcpRange != null) {
// To limit DNS to the cidr range
buf.append(" cidrsize=" + String.valueOf(cidrSize));
buf.append(" dhcprange=" + dhcpRange);
}
return buf;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class VirtualNetworkApplianceManagerImpl method finalizeMonitorServiceOnStrat.
private void finalizeMonitorServiceOnStrat(final Commands cmds, final VirtualMachineProfile profile, final DomainRouterVO router, final Provider provider, final long networkId, final Boolean add) {
final NetworkVO network = _networkDao.findById(networkId);
s_logger.debug("Creating monitoring services on " + router + " start...");
// get the list of sevices for this network to monitor
final List<MonitoringServiceVO> services = new ArrayList<MonitoringServiceVO>();
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, Provider.VirtualRouter) || _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dns, Provider.VirtualRouter)) {
final MonitoringServiceVO dhcpService = _monitorServiceDao.getServiceByName(MonitoringService.Service.Dhcp.toString());
if (dhcpService != null) {
services.add(dhcpService);
}
}
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Lb, Provider.VirtualRouter)) {
final MonitoringServiceVO lbService = _monitorServiceDao.getServiceByName(MonitoringService.Service.LoadBalancing.toString());
if (lbService != null) {
services.add(lbService);
}
}
final List<MonitoringServiceVO> defaultServices = _monitorServiceDao.listDefaultServices(true);
services.addAll(defaultServices);
final List<MonitorServiceTO> servicesTO = new ArrayList<MonitorServiceTO>();
for (final MonitoringServiceVO service : services) {
final MonitorServiceTO serviceTO = new MonitorServiceTO(service.getService(), service.getProcessName(), service.getServiceName(), service.getServicePath(), service.getServicePidFile(), service.isDefaultService());
servicesTO.add(serviceTO);
}
// TODO : This is a hacking fix
// at VR startup time, information in VirtualMachineProfile may not
// updated to DB yet,
// getRouterControlIp() may give wrong IP under basic network mode in
// VMware environment
final NicProfile controlNic = getControlNic(profile);
if (controlNic == null) {
throw new CloudRuntimeException("VirtualMachine " + profile.getInstanceName() + " doesn't have a control interface");
}
final SetMonitorServiceCommand command = new SetMonitorServiceCommand(servicesTO);
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, controlNic.getIPv4Address());
command.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(networkId, router.getId()));
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
if (!add) {
command.setAccessDetail(NetworkElementCommand.ROUTER_MONITORING_ENABLE, add.toString());
}
cmds.addCommand("monitor", command);
}
Aggregations