@Override public boolean stopRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router) throws ResourceUnavailableException { boolean result = true; if (router.getState() == State.Running) { final Commands cmds = new Commands(Command.OnError.Continue); _commandSetupHelper.createApplyVpnCommands(false, vpn, router, cmds); result = result && _nwHelper.sendCommandsToRouter(router, cmds); } else if (router.getState() == State.Stopped) { s_logger.debug( "Router " + router + " is in Stopped state, not sending deleteRemoteAccessVpn command to it"); } else { s_logger.warn( "Failed to delete remote access VPN: domR " + router + " is not in right state " + router.getState()); throw new ResourceUnavailableException( "Failed to delete remote access VPN: domR is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId()); } return true; }
@Override public boolean removeVpcRouterFromGuestNetwork(final VirtualRouter router, final Network network) throws ConcurrentOperationException, ResourceUnavailableException { if (network.getTrafficType() != TrafficType.Guest) { s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); return false; } boolean result = true; try { // Check if router is a part of the Guest network if (!_networkModel.isVmPartOfNetwork(router.getId(), network.getId())) { s_logger.debug("Router " + router + " is not a part of the Guest network " + network); return result; } result = setupVpcGuestNetwork( network, router, false, _networkModel.getNicProfile(router, network.getId(), null)); if (!result) { s_logger.warn("Failed to destroy guest network config " + network + " on router " + router); return false; } result = result && _itMgr.removeVmFromNetwork(router, network, null); } finally { if (result) { _routerDao.removeRouterFromGuestNetwork(router.getId(), network.getId()); } } return result; }
@Test public void info() { res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vrouter.getName().equals(name)); }
@Test public void attributes() { res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vrouter.xpath("NAME").equals(name)); }
@Override protected void finalizeIpAssocForNetwork( final Commands cmds, final VirtualRouter domainRouterVO, final Provider provider, final Long guestNetworkId, final Map<String, String> vlanMacAddress) { if (domainRouterVO.getVpcId() == null) { super.finalizeIpAssocForNetwork( cmds, domainRouterVO, provider, guestNetworkId, vlanMacAddress); return; } if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState() == State.Running) { final ArrayList<? extends PublicIpAddress> publicIps = getPublicIpsToApply(domainRouterVO, provider, guestNetworkId, IpAddress.State.Releasing); if (publicIps != null && !publicIps.isEmpty()) { s_logger.debug( "Found " + publicIps.size() + " ip(s) to apply as a part of domR " + domainRouterVO + " start."); // Re-apply public ip addresses - should come before PF/LB/VPN _commandSetupHelper.createVpcAssociatePublicIPCommands( domainRouterVO, publicIps, cmds, vlanMacAddress); } } }
@Test public void publish() { res = vrouter.publish(); assertTrue(res.getErrorMessage(), !res.isError()); vrouter.info(); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_U").equals("1")); }
@Test public void delete() { res = vrouter.delete(); assertTrue(res.getErrorMessage(), !res.isError()); res = vrouter.info(); assertTrue(res.isError()); }
@Override public boolean checkRouterVersion(final VirtualRouter router) { if (!VirtualNetworkApplianceManagerImpl.routerVersionCheckEnabled.value()) { // Router version check is disabled. return true; } if (router.getTemplateVersion() == null) { return false; } final long dcid = router.getDataCenterId(); final String trimmedVersion = Version.trimRouterVersion(router.getTemplateVersion()); return Version.compare(trimmedVersion, NetworkOrchestrationService.MinVRVersion.valueIn(dcid)) >= 0; }
@Override public boolean stopSite2SiteVpn(final Site2SiteVpnConnection conn, final VirtualRouter router) throws ResourceUnavailableException { if (router.getState() != State.Running) { s_logger.warn( "Unable to apply site-to-site VPN configuration, virtual router is not in the right state " + router.getState()); throw new ResourceUnavailableException( "Unable to apply site 2 site VPN configuration," + " virtual router is not in the right state", DataCenter.class, router.getDataCenterId()); } return applySite2SiteVpn(false, router, conn); }
/** @throws java.lang.Exception */ @Before public void setUp() throws Exception { res = VirtualRouter.allocate(client, template_str); int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage()); vrouter = new VirtualRouter(oid, client); }
@Override public NicTO getNicTO( final VirtualRouter router, final Long networkId, final String broadcastUri) { final NicProfile nicProfile = _networkModel.getNicProfile(router, networkId, broadcastUri); return _itMgr.toNicTO(nicProfile, router.getHypervisorType()); }
@Test public void allocate() { vrouter.delete(); res = VirtualRouter.allocate(client, template_str); assertTrue(res.getErrorMessage(), !res.isError()); int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage()); vrouter = new VirtualRouter(oid, client); vrouterPool.info(); boolean found = false; for (VirtualRouter temp : vrouterPool) { found = found || temp.getName().equals(name); } assertTrue(found); }
@Override public void handleSingleWorkingRedundantRouter( final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters, final String reason) throws ResourceUnavailableException { if (connectedRouters.isEmpty() || disconnectedRouters.isEmpty()) { return; } for (final VirtualRouter virtualRouter : connectedRouters) { if (!virtualRouter.getIsRedundantRouter()) { throw new ResourceUnavailableException( "Who is calling this with non-redundant router or non-domain router?", DataCenter.class, virtualRouter.getDataCenterId()); } } for (final VirtualRouter virtualRouter : disconnectedRouters) { if (!virtualRouter.getIsRedundantRouter()) { throw new ResourceUnavailableException( "Who is calling this with non-redundant router or non-domain router?", DataCenter.class, virtualRouter.getDataCenterId()); } } final DomainRouterVO connectedRouter = (DomainRouterVO) connectedRouters.get(0); DomainRouterVO disconnectedRouter = (DomainRouterVO) disconnectedRouters.get(0); if (s_logger.isDebugEnabled()) { s_logger.debug( "About to stop the router " + disconnectedRouter.getInstanceName() + " due to: " + reason); } final String title = "Virtual router " + disconnectedRouter.getInstanceName() + " would be stopped after connecting back, due to " + reason; final String context = "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId() + ") would be stopped after connecting back, due to: " + reason; _alertMgr.sendAlert( AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(), title, context); disconnectedRouter.setStopPending(true); disconnectedRouter = _routerDao.persist(disconnectedRouter); }
protected boolean setupVpcGuestNetwork( final Network network, final VirtualRouter router, final boolean add, final NicProfile guestNic) throws ConcurrentOperationException, ResourceUnavailableException { boolean result = true; if (router.getState() == State.Running) { final SetupGuestNetworkCommand setupCmd = _commandSetupHelper.createSetupGuestNetworkCommand( (DomainRouterVO) router, add, guestNic); final Commands cmds = new Commands(Command.OnError.Stop); cmds.addCommand("setupguestnetwork", setupCmd); _nwHelper.sendCommandsToRouter(router, cmds); final Answer setupAnswer = cmds.getAnswer("setupguestnetwork"); final String setup = add ? "set" : "destroy"; if (!(setupAnswer != null && setupAnswer.getResult())) { s_logger.warn("Unable to " + setup + " guest network on router " + router); result = false; } return result; } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) { s_logger.debug( "Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending setup guest network command to the backend"); return true; } else { s_logger.warn( "Unable to setup guest network on virtual router " + router + " is not in the right state " + router.getState()); throw new ResourceUnavailableException( "Unable to setup guest network on the backend," + " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterId()); } }
@Test public void chmod() { res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); String owner_a = vrouter.xpath("PERMISSIONS/OWNER_A"); String group_a = vrouter.xpath("PERMISSIONS/GROUP_A"); res = vrouter.chmod(0, 1, -1, 1, 0, -1, 1, 1, 0); assertTrue(res.getErrorMessage(), !res.isError()); res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vrouter.xpath("PERMISSIONS/OWNER_U").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/OWNER_M").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/OWNER_A").equals(owner_a)); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_U").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_M").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_A").equals(group_a)); assertTrue(vrouter.xpath("PERMISSIONS/OTHER_U").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/OTHER_M").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/OTHER_A").equals("0")); }
@Override public void reallocateRouterNetworks( final RouterDeploymentDefinition routerDeploymentDefinition, final VirtualRouter router, final VMTemplateVO template, final HypervisorType hType) throws ConcurrentOperationException, InsufficientCapacityException { final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getServiceOfferingId()); final LinkedHashMap<Network, List<? extends NicProfile>> networks = configureDefaultNics(routerDeploymentDefinition); _itMgr.allocate( router.getInstanceName(), template, routerOffering, networks, routerDeploymentDefinition.getPlan(), hType); }
@Override public boolean destroyPrivateGateway(final PrivateGateway gateway, final VirtualRouter router) throws ConcurrentOperationException, ResourceUnavailableException { if (!_networkModel.isVmPartOfNetwork(router.getId(), gateway.getNetworkId())) { s_logger.debug( "Router doesn't have nic for gateway " + gateway + " so no need to removed it"); return true; } final Network privateNetwork = _networkModel.getNetwork(gateway.getNetworkId()); s_logger.debug("Releasing private ip for gateway " + gateway + " from " + router); boolean result = setupVpcPrivateNetwork( router, false, _networkModel.getNicProfile(router, privateNetwork.getId(), null)); if (!result) { s_logger.warn("Failed to release private ip for gateway " + gateway + " on router " + router); return false; } // revoke network acl on the private gateway. if (!_networkACLMgr.revokeACLItemsForPrivateGw(gateway)) { s_logger.debug("Failed to delete network acl items on " + gateway + " from router " + router); return false; } s_logger.debug( "Removing router " + router + " from private network " + privateNetwork + " as a part of delete private gateway"); result = result && _itMgr.removeVmFromNetwork(router, privateNetwork, null); s_logger.debug("Private gateawy " + gateway + " is removed from router " + router); return result; }
@Test public void instantiate() { VirtualMachinePool vmPool = new VirtualMachinePool(client); res = vmPool.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vmPool.getLength() == 0); String tmpl_str = "NAME = vrtemplate\n" + "CPU = 0.1\n" + "MEMORY = 64\n"; res = Template.allocate(client, tmpl_str); assertTrue(res.getErrorMessage(), !res.isError()); int tmplid = Integer.parseInt(res.getMessage()); res = vrouter.instantiate(3, tmplid); assertTrue(res.getErrorMessage(), !res.isError()); res = vmPool.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vmPool.getLength() == 3); }
@Override public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException, ResourceUnavailableException { if (!checkRouterVersion(router)) { s_logger.debug( "Router requires upgrade. Unable to send command to router:" + router.getId() + ", router template version : " + router.getTemplateVersion() + ", minimal required version : " + NetworkOrchestrationService.MinVRVersion.valueIn(router.getDataCenterId())); throw new ResourceUnavailableException( "Unable to send command. Router requires upgrade", VirtualRouter.class, router.getId()); } Answer[] answers = null; try { answers = _agentMgr.send(router.getHostId(), cmds); } catch (final OperationTimedoutException e) { s_logger.warn("Timed Out", e); throw new AgentUnavailableException( "Unable to send commands to virtual router ", router.getHostId(), e); } if (answers == null || answers.length != cmds.size()) { return false; } // FIXME: Have to return state for individual command in the future boolean result = true; for (final Answer answer : answers) { if (!answer.getResult()) { result = false; break; } } return result; }
@Test public void chown() { // Create a new User and Group res = User.allocate(client, "template_test_user", "password"); assertTrue(res.getErrorMessage(), !res.isError()); int uid = Integer.parseInt(res.getMessage()); res = Group.allocate(client, "template_test_group"); assertTrue(res.getErrorMessage(), !res.isError()); int gid = Integer.parseInt(res.getMessage()); res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vrouter.uid() == 0); assertTrue(vrouter.gid() == 0); res = vrouter.chown(uid, gid); assertTrue(res.getErrorMessage(), !res.isError()); res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vrouter.uid() == uid); assertTrue(vrouter.gid() == gid); res = vrouter.chgrp(0); res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vrouter.uid() == uid); assertTrue(vrouter.gid() == 0); }
/** @throws java.lang.Exception */ @After public void tearDown() throws Exception { vrouter.delete(); }
@Override @DB public NicProfile createPrivateNicProfileForGateway( final VpcGateway privateGateway, final VirtualRouter router) { final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId()); PrivateIpVO ipVO = _privateIpDao.allocateIpAddress( privateNetwork.getDataCenterId(), privateNetwork.getId(), privateGateway.getIp4Address()); final Long vpcId = privateGateway.getVpcId(); final Vpc activeVpc = _vpcMgr.getActiveVpc(vpcId); if (activeVpc.isRedundant() && ipVO == null) { ipVO = _privateIpDao.findByIpAndVpcId(vpcId, privateGateway.getIp4Address()); } Nic privateNic = null; if (ipVO != null) { privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId()); } NicProfile privateNicProfile = new NicProfile(); if (privateNic != null) { privateNicProfile = new NicProfile( privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate(privateNetwork.getId(), router.getId()), _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), privateNetwork)); if (router.getIsRedundantRouter()) { String newMacAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())); privateNicProfile.setMacAddress(newMacAddress); } } else { final String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr()); final PrivateIpAddress ip = new PrivateIpAddress( ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask, NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()))); final URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri()); privateNicProfile.setIPv4Address(ip.getIpAddress()); privateNicProfile.setIPv4Gateway(ip.getGateway()); privateNicProfile.setIPv4Netmask(ip.getNetmask()); privateNicProfile.setIsolationUri(netUri); privateNicProfile.setBroadcastUri(netUri); // can we solve this in setBroadcastUri()??? // or more plugable construct is desirable privateNicProfile.setBroadcastType(BroadcastDomainType.getSchemeValue(netUri)); privateNicProfile.setFormat(AddressFormat.Ip4); privateNicProfile.setReservationId(String.valueOf(ip.getBroadcastUri())); privateNicProfile.setMacAddress(ip.getMacAddress()); } return privateNicProfile; }
@Override public boolean addVpcRouterToGuestNetwork( final VirtualRouter router, final Network network, final Map<VirtualMachineProfile.Param, Object> params) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { if (network.getTrafficType() != TrafficType.Guest) { s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest); return false; } // Add router to the Guest network boolean result = true; try { // 1) add nic to the router _routerDao.addRouterToGuestNetwork(router, network); final NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null); // 2) setup guest network if (guestNic != null) { result = setupVpcGuestNetwork(network, router, true, guestNic); } else { s_logger.warn("Failed to add router " + router + " to guest network " + network); result = false; } // 3) apply networking rules if (result && params.get(Param.ReProgramGuestNetworks) != null && (Boolean) params.get(Param.ReProgramGuestNetworks) == true) { sendNetworkRulesToRouter(router.getId(), network.getId()); } } catch (final Exception ex) { s_logger.warn("Failed to add router " + router + " to network " + network + " due to ", ex); result = false; } finally { if (!result) { s_logger.debug( "Removing the router " + router + " from network " + network + " as a part of cleanup"); if (removeVpcRouterFromGuestNetwork(router, network)) { s_logger.debug( "Removed the router " + router + " from network " + network + " as a part of cleanup"); } else { s_logger.warn( "Failed to remove the router " + router + " from network " + network + " as a part of cleanup"); } } else { s_logger.debug("Succesfully added router " + router + " to guest network " + network); } } return result; }
@Override public boolean startRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router) throws ResourceUnavailableException { if (router.getState() != State.Running) { s_logger.warn( "Unable to apply remote access VPN configuration, virtual router is not in the right state " + router.getState()); throw new ResourceUnavailableException( "Unable to apply remote access VPN configuration," + " virtual router is not in the right state", DataCenter.class, router.getDataCenterId()); } final Commands cmds = new Commands(Command.OnError.Stop); _commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds); try { _agentMgr.send(router.getHostId(), cmds); } catch (final OperationTimedoutException e) { s_logger.debug("Failed to start remote access VPN: ", e); throw new AgentUnavailableException( "Unable to send commands to virtual router ", router.getHostId(), e); } Answer answer = cmds.getAnswer("users"); if (!answer.getResult()) { s_logger.error( "Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails()); throw new ResourceUnavailableException( "Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId()); } answer = cmds.getAnswer("startVpn"); if (!answer.getResult()) { s_logger.error( "Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails()); throw new ResourceUnavailableException( "Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId()); } return true; }
protected Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> getNicsToChangeOnRouter( final List<? extends PublicIpAddress> publicIps, final VirtualRouter router) { // 1) check which nics need to be plugged/unplugged and plug/unplug them final Map<String, PublicIpAddress> nicsToPlug = new HashMap<String, PublicIpAddress>(); final Map<String, PublicIpAddress> nicsToUnplug = new HashMap<String, PublicIpAddress>(); // find out nics to unplug for (final PublicIpAddress ip : publicIps) { final long publicNtwkId = ip.getNetworkId(); // if ip is not associated to any network, and there are no firewall // rules, release it on the backend if (!_vpcMgr.isIpAllocatedToVpc(ip)) { ip.setState(IpAddress.State.Releasing); } if (ip.getState() == IpAddress.State.Releasing) { final Nic nic = _nicDao.findByIp4AddressAndNetworkIdAndInstanceId( publicNtwkId, router.getId(), ip.getAddress().addr()); if (nic != null) { nicsToUnplug.put(ip.getVlanTag(), ip); s_logger.debug( "Need to unplug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() + " in public network id =" + publicNtwkId); } } } // find out nics to plug for (final PublicIpAddress ip : publicIps) { final URI broadcastUri = BroadcastDomainType.Vlan.toUri(ip.getVlanTag()); final long publicNtwkId = ip.getNetworkId(); // if ip is not associated to any network, and there are no firewall // rules, release it on the backend if (!_vpcMgr.isIpAllocatedToVpc(ip)) { ip.setState(IpAddress.State.Releasing); } if (ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating) { // nic has to be plugged only when there are no nics for this // vlan tag exist on VR final Nic nic = _nicDao.findByNetworkIdInstanceIdAndBroadcastUri( publicNtwkId, router.getId(), broadcastUri.toString()); if (nic == null && nicsToPlug.get(ip.getVlanTag()) == null) { nicsToPlug.put(ip.getVlanTag(), ip); s_logger.debug( "Need to plug the nic for ip=" + ip + "; vlan=" + ip.getVlanTag() + " in public network id =" + publicNtwkId); } else { final PublicIpAddress nicToUnplug = nicsToUnplug.get(ip.getVlanTag()); if (nicToUnplug != null) { final NicVO nicVO = _nicDao.findByIp4AddressAndNetworkIdAndInstanceId( publicNtwkId, router.getId(), nicToUnplug.getAddress().addr()); nicVO.setIPv4Address(ip.getAddress().addr()); _nicDao.update(nicVO.getId(), nicVO); s_logger.debug( "Updated the nic " + nicVO + " with the new ip address " + ip.getAddress().addr()); nicsToUnplug.remove(ip.getVlanTag()); } } } } final Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>> nicsToChange = new Pair<Map<String, PublicIpAddress>, Map<String, PublicIpAddress>>( nicsToPlug, nicsToUnplug); return nicsToChange; }
@Test public void chmod_octet() { res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); res = vrouter.chmod(640); assertTrue(res.getErrorMessage(), !res.isError()); res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vrouter.xpath("PERMISSIONS/OWNER_U").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/OWNER_M").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/OWNER_A").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_U").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_M").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_A").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/OTHER_U").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/OTHER_M").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/OTHER_A").equals("0")); res = vrouter.chmod("147"); assertTrue(res.getErrorMessage(), !res.isError()); res = vrouter.info(); assertTrue(res.getErrorMessage(), !res.isError()); assertTrue(vrouter.xpath("PERMISSIONS/OWNER_U").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/OWNER_M").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/OWNER_A").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_U").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_M").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/GROUP_A").equals("0")); assertTrue(vrouter.xpath("PERMISSIONS/OTHER_U").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/OTHER_M").equals("1")); assertTrue(vrouter.xpath("PERMISSIONS/OTHER_A").equals("1")); }
/** * @param router * @param add * @param privateNic * @return * @throws ResourceUnavailableException */ protected boolean setupVpcPrivateNetwork( final VirtualRouter router, final boolean add, final NicProfile privateNic) throws ResourceUnavailableException { if (router.getState() == State.Running) { final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId( privateNic.getNetworkId(), privateNic.getIPv4Address()); final Network network = _networkDao.findById(privateNic.getNetworkId()); final String netmask = NetUtils.getCidrNetmask(network.getCidr()); final PrivateIpAddress ip = new PrivateIpAddress( ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, privateNic.getMacAddress()); final List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1); privateIps.add(ip); final Commands cmds = new Commands(Command.OnError.Stop); _commandSetupHelper.createVpcAssociatePrivateIPCommands(router, privateIps, cmds, add); try { if (_nwHelper.sendCommandsToRouter(router, cmds)) { s_logger.debug( "Successfully applied ip association for ip " + ip + " in vpc network " + network); return true; } else { s_logger.warn("Failed to associate ip address " + ip + " in vpc network " + network); return false; } } catch (final Exception ex) { s_logger.warn( "Failed to send " + (add ? "add " : "delete ") + " private network " + network + " commands to rotuer "); return false; } } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) { s_logger.debug( "Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending setup private network command to the backend"); } else { s_logger.warn( "Unable to setup private gateway, virtual router " + router + " is not in the right state " + router.getState()); throw new ResourceUnavailableException( "Unable to setup Private gateway on the backend," + " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterId()); } return true; }