Search in sources :

Example 1 with VpnUser

use of com.cloud.network.VpnUser in project CloudStack-archive by CloudStack-extras.

the class AddVpnUserCmd method create.

@Override
public void create() {
    Account owner = _accountService.getAccount(getEntityOwnerId());
    VpnUser vpnUser = _ravService.addVpnUser(owner.getId(), userName, password);
    if (vpnUser == null) {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add vpn user");
    }
    setEntityId(vpnUser.getId());
}
Also used : Account(com.cloud.user.Account) VpnUser(com.cloud.network.VpnUser) ServerApiException(com.cloud.api.ServerApiException)

Example 2 with VpnUser

use of com.cloud.network.VpnUser in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElementTest method testApplyVpnUsers.

@Test
public void testApplyVpnUsers() {
    vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr;
    final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class);
    final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class);
    networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology);
    networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology);
    networkTopologyContext.init();
    final Vpc vpc = Mockito.mock(Vpc.class);
    final Zone zone = Mockito.mock(Zone.class);
    final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class);
    final DomainRouterVO domainRouterVO1 = Mockito.mock(DomainRouterVO.class);
    final DomainRouterVO domainRouterVO2 = Mockito.mock(DomainRouterVO.class);
    final VpnUser vpnUser1 = Mockito.mock(VpnUser.class);
    final VpnUser vpnUser2 = Mockito.mock(VpnUser.class);
    final List<VpnUser> users = new ArrayList<>();
    users.add(vpnUser1);
    users.add(vpnUser2);
    final List<DomainRouterVO> routers = new ArrayList<>();
    routers.add(domainRouterVO1);
    routers.add(domainRouterVO2);
    final Long vpcId = new Long(1l);
    final Long zoneId = new Long(1l);
    when(remoteAccessVpn.getVpcId()).thenReturn(vpcId);
    when(_vpcRouterMgr.getVpcRouters(vpcId)).thenReturn(routers);
    when(_entityMgr.findById(Vpc.class, vpcId)).thenReturn(vpc);
    when(vpc.getZoneId()).thenReturn(zoneId);
    when(zoneRepository.findOne(zoneId)).thenReturn(zone);
    when(networkTopologyContext.retrieveNetworkTopology(zone)).thenReturn(advancedNetworkTopology);
    try {
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO1)).thenReturn(new String[] { "user1", "user2" });
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO2)).thenReturn(new String[] { "user3", "user4" });
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    try {
        final String[] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn, users);
        assertNotNull(results);
        assertEquals(results[0], "user1");
        assertEquals(results[1], "user2");
        assertEquals(results[2], "user3");
        assertEquals(results[3], "user4");
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    verify(remoteAccessVpn, times(1)).getVpcId();
    verify(vpc, times(1)).getZoneId();
    verify(zoneRepository, times(1)).findOne(zoneId);
    verify(networkTopologyContext, times(1)).retrieveNetworkTopology(zone);
}
Also used : BasicNetworkTopology(com.cloud.network.topology.BasicNetworkTopology) Zone(com.cloud.db.model.Zone) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) AdvancedNetworkTopology(com.cloud.network.topology.AdvancedNetworkTopology) VpnUser(com.cloud.network.VpnUser) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 3 with VpnUser

use of com.cloud.network.VpnUser in project cloudstack by apache.

the class CommandSetupHelper method createApplyVpnUsersCommand.

public void createApplyVpnUsersCommand(final List<? extends VpnUser> users, final VirtualRouter router, final Commands cmds) {
    final List<VpnUser> addUsers = new ArrayList<VpnUser>();
    final List<VpnUser> removeUsers = new ArrayList<VpnUser>();
    for (final VpnUser user : users) {
        if (user.getState() == VpnUser.State.Add || user.getState() == VpnUser.State.Active) {
            addUsers.add(user);
        } else if (user.getState() == VpnUser.State.Revoke) {
            removeUsers.add(user);
        }
    }
    final VpnUsersCfgCommand cmd = new VpnUsersCfgCommand(addUsers, removeUsers);
    cmd.setAccessDetail(NetworkElementCommand.ACCOUNT_ID, String.valueOf(router.getAccountId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand("users", cmd);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) VpnUsersCfgCommand(com.cloud.agent.api.routing.VpnUsersCfgCommand) VpnUser(com.cloud.network.VpnUser) ArrayList(java.util.ArrayList)

Example 4 with VpnUser

use of com.cloud.network.VpnUser in project cloudstack by apache.

the class VpcVirtualRouterElementTest method testApplyVpnUsers.

@Test
public void testApplyVpnUsers() {
    vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr;
    final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class);
    final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class);
    networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology);
    networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology);
    networkTopologyContext.init();
    final Vpc vpc = Mockito.mock(Vpc.class);
    final DataCenterVO dataCenterVO = Mockito.mock(DataCenterVO.class);
    final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class);
    final DomainRouterVO domainRouterVO1 = Mockito.mock(DomainRouterVO.class);
    final DomainRouterVO domainRouterVO2 = Mockito.mock(DomainRouterVO.class);
    final VpnUser vpnUser1 = Mockito.mock(VpnUser.class);
    final VpnUser vpnUser2 = Mockito.mock(VpnUser.class);
    final List<VpnUser> users = new ArrayList<VpnUser>();
    users.add(vpnUser1);
    users.add(vpnUser2);
    final List<DomainRouterVO> routers = new ArrayList<DomainRouterVO>();
    routers.add(domainRouterVO1);
    routers.add(domainRouterVO2);
    final Long vpcId = new Long(1l);
    final Long zoneId = new Long(1l);
    when(remoteAccessVpn.getVpcId()).thenReturn(vpcId);
    when(_vpcRouterMgr.getVpcRouters(vpcId)).thenReturn(routers);
    when(_entityMgr.findById(Vpc.class, vpcId)).thenReturn(vpc);
    when(vpc.getZoneId()).thenReturn(zoneId);
    when(_dcDao.findById(zoneId)).thenReturn(dataCenterVO);
    when(networkTopologyContext.retrieveNetworkTopology(dataCenterVO)).thenReturn(advancedNetworkTopology);
    try {
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO1)).thenReturn(new String[] { "user1", "user2" });
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO2)).thenReturn(new String[] { "user3", "user4" });
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    try {
        final String[] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn, users);
        assertNotNull(results);
        assertEquals(results[0], "user1");
        assertEquals(results[1], "user2");
        assertEquals(results[2], "user3");
        assertEquals(results[3], "user4");
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    verify(remoteAccessVpn, times(1)).getVpcId();
    verify(vpc, times(1)).getZoneId();
    verify(_dcDao, times(1)).findById(zoneId);
    verify(networkTopologyContext, times(1)).retrieveNetworkTopology(dataCenterVO);
}
Also used : BasicNetworkTopology(org.apache.cloudstack.network.topology.BasicNetworkTopology) DataCenterVO(com.cloud.dc.DataCenterVO) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) AdvancedNetworkTopology(org.apache.cloudstack.network.topology.AdvancedNetworkTopology) VpnUser(com.cloud.network.VpnUser) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 5 with VpnUser

use of com.cloud.network.VpnUser in project cloudstack by apache.

the class VpcVirtualRouterElementTest method testApplyVpnUsersException2.

@Test
public void testApplyVpnUsersException2() {
    vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr;
    final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class);
    final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class);
    networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology);
    networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology);
    networkTopologyContext.init();
    final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class);
    final List<VpnUser> users = new ArrayList<VpnUser>();
    final Long vpcId = new Long(1l);
    when(remoteAccessVpn.getVpcId()).thenReturn(vpcId);
    when(_vpcRouterMgr.getVpcRouters(vpcId)).thenReturn(null);
    try {
        final String[] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn, users);
        assertNull(results);
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    verify(remoteAccessVpn, times(1)).getVpcId();
}
Also used : BasicNetworkTopology(org.apache.cloudstack.network.topology.BasicNetworkTopology) VpnUser(com.cloud.network.VpnUser) ArrayList(java.util.ArrayList) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) AdvancedNetworkTopology(org.apache.cloudstack.network.topology.AdvancedNetworkTopology) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) Test(org.junit.Test)

Aggregations

VpnUser (com.cloud.network.VpnUser)19 ArrayList (java.util.ArrayList)11 Account (com.cloud.user.Account)8 Test (org.junit.Test)8 RemoteAccessVpn (com.cloud.network.RemoteAccessVpn)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)6 ServerApiException (com.cloud.api.ServerApiException)4 VpnUsersResponse (com.cloud.api.response.VpnUsersResponse)4 Vpc (com.cloud.network.vpc.Vpc)3 DomainRouterVO (com.cloud.vm.DomainRouterVO)3 List (java.util.List)3 AdvancedNetworkTopology (org.apache.cloudstack.network.topology.AdvancedNetworkTopology)3 BasicNetworkTopology (org.apache.cloudstack.network.topology.BasicNetworkTopology)3 ListResponse (com.cloud.api.response.ListResponse)2 Zone (com.cloud.db.model.Zone)2 DataCenterVO (com.cloud.dc.DataCenterVO)2 Domain (com.cloud.domain.Domain)2 AdvancedNetworkTopology (com.cloud.network.topology.AdvancedNetworkTopology)2 BasicNetworkTopology (com.cloud.network.topology.BasicNetworkTopology)2 RemoteAccessVpnService (com.cloud.network.vpn.RemoteAccessVpnService)2