Search in sources :

Example 1 with VpnUsersResponse

use of org.apache.cloudstack.api.response.VpnUsersResponse in project cloudstack by apache.

the class ListVpnUsersCmd method execute.

@Override
public void execute() {
    Pair<List<? extends VpnUser>, Integer> vpnUsers = _ravService.searchForVpnUsers(this);
    ListResponse<VpnUsersResponse> response = new ListResponse<VpnUsersResponse>();
    List<VpnUsersResponse> vpnResponses = new ArrayList<VpnUsersResponse>();
    for (VpnUser vpnUser : vpnUsers.first()) {
        vpnResponses.add(_responseGenerator.createVpnUserResponse(vpnUser));
    }
    response.setResponses(vpnResponses, vpnUsers.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : VpnUser(com.cloud.network.VpnUser) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) VpnUsersResponse(org.apache.cloudstack.api.response.VpnUsersResponse)

Example 2 with VpnUsersResponse

use of org.apache.cloudstack.api.response.VpnUsersResponse in project cloudstack by apache.

the class ApiResponseHelper method createVpnUserResponse.

@Override
public VpnUsersResponse createVpnUserResponse(VpnUser vpnUser) {
    VpnUsersResponse vpnResponse = new VpnUsersResponse();
    vpnResponse.setId(vpnUser.getUuid());
    vpnResponse.setUserName(vpnUser.getUsername());
    vpnResponse.setState(vpnUser.getState().toString());
    populateOwner(vpnResponse, vpnUser);
    vpnResponse.setObjectName("vpnuser");
    return vpnResponse;
}
Also used : VpnUsersResponse(org.apache.cloudstack.api.response.VpnUsersResponse)

Example 3 with VpnUsersResponse

use of org.apache.cloudstack.api.response.VpnUsersResponse in project cloudstack by apache.

the class AddVpnUserCmd method execute.

@Override
public void execute() {
    VpnUser vpnUser = _entityMgr.findById(VpnUser.class, getEntityId());
    Account account = _entityMgr.findById(Account.class, vpnUser.getAccountId());
    try {
        if (!_ravService.applyVpnUsers(vpnUser.getAccountId(), userName)) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user");
        }
    } catch (Exception ex) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add vpn user due to resource unavailable");
    }
    VpnUsersResponse vpnResponse = new VpnUsersResponse();
    vpnResponse.setId(vpnUser.getUuid());
    vpnResponse.setUserName(vpnUser.getUsername());
    vpnResponse.setAccountName(account.getAccountName());
    Domain domain = _entityMgr.findById(Domain.class, account.getDomainId());
    if (domain != null) {
        vpnResponse.setDomainId(domain.getUuid());
        vpnResponse.setDomainName(domain.getName());
    }
    vpnResponse.setResponseName(getCommandName());
    vpnResponse.setObjectName("vpnuser");
    setResponseObject(vpnResponse);
}
Also used : Account(com.cloud.user.Account) VpnUser(com.cloud.network.VpnUser) ServerApiException(org.apache.cloudstack.api.ServerApiException) Domain(com.cloud.domain.Domain) VpnUsersResponse(org.apache.cloudstack.api.response.VpnUsersResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

VpnUsersResponse (org.apache.cloudstack.api.response.VpnUsersResponse)3 VpnUser (com.cloud.network.VpnUser)2 Domain (com.cloud.domain.Domain)1 Account (com.cloud.user.Account)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ServerApiException (org.apache.cloudstack.api.ServerApiException)1 ListResponse (org.apache.cloudstack.api.response.ListResponse)1