Search in sources :

Example 11 with ResourceTagResponse

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

the class ApiResponseHelper method createNetworkACLItemResponse.

@Override
public NetworkACLItemResponse createNetworkACLItemResponse(NetworkACLItem aclItem) {
    NetworkACLItemResponse response = new NetworkACLItemResponse();
    response.setId(aclItem.getUuid());
    response.setProtocol(aclItem.getProtocol());
    if (aclItem.getSourcePortStart() != null) {
        response.setStartPort(Integer.toString(aclItem.getSourcePortStart()));
    }
    if (aclItem.getSourcePortEnd() != null) {
        response.setEndPort(Integer.toString(aclItem.getSourcePortEnd()));
    }
    response.setCidrList(StringUtils.join(aclItem.getSourceCidrList(), ","));
    response.setTrafficType(aclItem.getTrafficType().toString());
    NetworkACLItem.State state = aclItem.getState();
    String stateToSet = state.toString();
    if (state.equals(NetworkACLItem.State.Revoke)) {
        stateToSet = "Deleting";
    }
    response.setIcmpCode(aclItem.getIcmpCode());
    response.setIcmpType(aclItem.getIcmpType());
    response.setState(stateToSet);
    response.setNumber(aclItem.getNumber());
    response.setAction(aclItem.getAction().toString());
    response.setForDisplay(aclItem.isDisplay());
    NetworkACL acl = ApiDBUtils.findByNetworkACLId(aclItem.getAclId());
    if (acl != null) {
        response.setAclId(acl.getUuid());
        response.setAclName(acl.getName());
    }
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.NetworkACL, aclItem.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    response.setReason(aclItem.getReason());
    response.setObjectName("networkacl");
    return response;
}
Also used : NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) ResourceTag(com.cloud.server.ResourceTag) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) ArrayList(java.util.ArrayList) NetworkACL(com.cloud.network.vpc.NetworkACL) NetworkACLItemResponse(org.apache.cloudstack.api.response.NetworkACLItemResponse)

Example 12 with ResourceTagResponse

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

the class ApiResponseHelper method createVMSnapshotResponse.

@Override
public VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot) {
    VMSnapshotResponse vmSnapshotResponse = new VMSnapshotResponse();
    vmSnapshotResponse.setId(vmSnapshot.getUuid());
    vmSnapshotResponse.setName(vmSnapshot.getName());
    vmSnapshotResponse.setState(vmSnapshot.getState());
    vmSnapshotResponse.setCreated(vmSnapshot.getCreated());
    vmSnapshotResponse.setDescription(vmSnapshot.getDescription());
    vmSnapshotResponse.setDisplayName(vmSnapshot.getDisplayName());
    UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());
    if (vm != null) {
        vmSnapshotResponse.setVirtualMachineId(vm.getUuid());
        vmSnapshotResponse.setVirtualMachineName(StringUtils.isEmpty(vm.getDisplayName()) ? vm.getHostName() : vm.getDisplayName());
        vmSnapshotResponse.setHypervisor(vm.getHypervisorType());
        DataCenterVO datacenter = ApiDBUtils.findZoneById(vm.getDataCenterId());
        if (datacenter != null) {
            vmSnapshotResponse.setZoneId(datacenter.getUuid());
            vmSnapshotResponse.setZoneName(datacenter.getName());
        }
    }
    if (vmSnapshot.getParent() != null) {
        VMSnapshot vmSnapshotParent = ApiDBUtils.getVMSnapshotById(vmSnapshot.getParent());
        if (vmSnapshotParent != null) {
            vmSnapshotResponse.setParent(vmSnapshotParent.getUuid());
            vmSnapshotResponse.setParentName(vmSnapshotParent.getDisplayName());
        }
    }
    populateOwner(vmSnapshotResponse, vmSnapshot);
    Project project = ApiDBUtils.findProjectByProjectAccountId(vmSnapshot.getAccountId());
    if (project != null) {
        vmSnapshotResponse.setProjectId(project.getUuid());
        vmSnapshotResponse.setProjectName(project.getName());
    }
    Account account = ApiDBUtils.findAccountById(vmSnapshot.getAccountId());
    if (account != null) {
        vmSnapshotResponse.setAccountName(account.getAccountName());
    }
    DomainVO domain = ApiDBUtils.findDomainById(vmSnapshot.getDomainId());
    if (domain != null) {
        vmSnapshotResponse.setDomainId(domain.getUuid());
        vmSnapshotResponse.setDomainName(domain.getName());
    }
    List<? extends ResourceTag> tags = _resourceTagDao.listBy(vmSnapshot.getId(), ResourceObjectType.VMSnapshot);
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, false);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    vmSnapshotResponse.setTags(new HashSet<>(tagResponses));
    vmSnapshotResponse.setHasAnnotation(annotationDao.hasAnnotations(vmSnapshot.getUuid(), AnnotationService.EntityType.VM_SNAPSHOT.name(), _accountMgr.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    vmSnapshotResponse.setCurrent(vmSnapshot.getCurrent());
    vmSnapshotResponse.setType(vmSnapshot.getType().toString());
    vmSnapshotResponse.setObjectName("vmsnapshot");
    return vmSnapshotResponse;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Project(com.cloud.projects.Project) DomainVO(com.cloud.domain.DomainVO) UserVm(com.cloud.uservm.UserVm) ResourceTag(com.cloud.server.ResourceTag) VMSnapshotResponse(org.apache.cloudstack.api.response.VMSnapshotResponse) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse)

Example 13 with ResourceTagResponse

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

the class ApiResponseHelper method createFirewallResponse.

@Override
public FirewallResponse createFirewallResponse(FirewallRule fwRule) {
    FirewallResponse response = new FirewallResponse();
    response.setId(fwRule.getUuid());
    response.setProtocol(fwRule.getProtocol());
    if (fwRule.getSourcePortStart() != null) {
        response.setStartPort(fwRule.getSourcePortStart());
    }
    if (fwRule.getSourcePortEnd() != null) {
        response.setEndPort(fwRule.getSourcePortEnd());
    }
    List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(fwRule.getId());
    response.setCidrList(StringUtils.join(cidrs, ","));
    if (fwRule.getTrafficType() == FirewallRule.TrafficType.Egress) {
        List<String> destCidrs = ApiDBUtils.findFirewallDestCidrs(fwRule.getId());
        response.setDestCidr(StringUtils.join(destCidrs, ","));
    }
    if (fwRule.getTrafficType() == FirewallRule.TrafficType.Ingress) {
        IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
        response.setPublicIpAddressId(ip.getUuid());
        response.setPublicIpAddress(ip.getAddress().addr());
    }
    Network network = ApiDBUtils.findNetworkById(fwRule.getNetworkId());
    response.setNetworkId(network.getUuid());
    FirewallRule.State state = fwRule.getState();
    String stateToSet = state.toString();
    if (state.equals(FirewallRule.State.Revoke)) {
        stateToSet = "Deleting";
    }
    response.setIcmpCode(fwRule.getIcmpCode());
    response.setIcmpType(fwRule.getIcmpType());
    response.setForDisplay(fwRule.isDisplay());
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.FirewallRule, fwRule.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    response.setState(stateToSet);
    response.setObjectName("firewallrule");
    return response;
}
Also used : ResourceTag(com.cloud.server.ResourceTag) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) FirewallRule(com.cloud.network.rules.FirewallRule) FirewallResponse(org.apache.cloudstack.api.response.FirewallResponse)

Example 14 with ResourceTagResponse

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

the class ApiResponseHelper method createLoadBalancerResponse.

@Override
public LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer) {
    LoadBalancerResponse lbResponse = new LoadBalancerResponse();
    lbResponse.setId(loadBalancer.getUuid());
    lbResponse.setName(loadBalancer.getName());
    lbResponse.setDescription(loadBalancer.getDescription());
    List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(loadBalancer.getId());
    lbResponse.setCidrList(StringUtils.join(cidrs, ","));
    IPAddressVO publicIp = ApiDBUtils.findIpAddressById(loadBalancer.getSourceIpAddressId());
    lbResponse.setPublicIpId(publicIp.getUuid());
    lbResponse.setPublicIp(publicIp.getAddress().addr());
    lbResponse.setPublicPort(Integer.toString(loadBalancer.getSourcePortStart()));
    lbResponse.setPrivatePort(Integer.toString(loadBalancer.getDefaultPortStart()));
    lbResponse.setAlgorithm(loadBalancer.getAlgorithm());
    lbResponse.setLbProtocol(loadBalancer.getLbProtocol());
    lbResponse.setForDisplay(loadBalancer.isDisplay());
    FirewallRule.State state = loadBalancer.getState();
    String stateToSet = state.toString();
    if (state.equals(FirewallRule.State.Revoke)) {
        stateToSet = "Deleting";
    }
    lbResponse.setState(stateToSet);
    populateOwner(lbResponse, loadBalancer);
    DataCenter zone = ApiDBUtils.findZoneById(publicIp.getDataCenterId());
    if (zone != null) {
        lbResponse.setZoneId(zone.getUuid());
        lbResponse.setZoneName(zone.getName());
    }
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.LoadBalancer, loadBalancer.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    lbResponse.setTags(tagResponses);
    Network ntwk = ApiDBUtils.findNetworkById(loadBalancer.getNetworkId());
    lbResponse.setNetworkId(ntwk.getUuid());
    lbResponse.setObjectName("loadbalancer");
    return lbResponse;
}
Also used : ArrayList(java.util.ArrayList) GlobalLoadBalancerResponse(org.apache.cloudstack.api.response.GlobalLoadBalancerResponse) ApplicationLoadBalancerResponse(org.apache.cloudstack.api.response.ApplicationLoadBalancerResponse) LoadBalancerResponse(org.apache.cloudstack.api.response.LoadBalancerResponse) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) IPAddressVO(com.cloud.network.dao.IPAddressVO) FirewallRule(com.cloud.network.rules.FirewallRule)

Example 15 with ResourceTagResponse

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

the class ApiResponseHelper method createPortForwardingRuleResponse.

@Override
public FirewallRuleResponse createPortForwardingRuleResponse(PortForwardingRule fwRule) {
    FirewallRuleResponse response = new FirewallRuleResponse();
    response.setId(fwRule.getUuid());
    response.setPrivateStartPort(Integer.toString(fwRule.getDestinationPortStart()));
    response.setPrivateEndPort(Integer.toString(fwRule.getDestinationPortEnd()));
    response.setProtocol(fwRule.getProtocol());
    response.setPublicStartPort(Integer.toString(fwRule.getSourcePortStart()));
    response.setPublicEndPort(Integer.toString(fwRule.getSourcePortEnd()));
    List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(fwRule.getId());
    response.setCidrList(StringUtils.join(cidrs, ","));
    Network guestNtwk = ApiDBUtils.findNetworkById(fwRule.getNetworkId());
    response.setNetworkId(guestNtwk.getUuid());
    IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
    if (ip != null) {
        response.setPublicIpAddressId(ip.getUuid());
        response.setPublicIpAddress(ip.getAddress().addr());
        if (fwRule.getDestinationIpAddress() != null) {
            response.setDestNatVmIp(fwRule.getDestinationIpAddress().toString());
            UserVm vm = ApiDBUtils.findUserVmById(fwRule.getVirtualMachineId());
            if (vm != null) {
                response.setVirtualMachineId(vm.getUuid());
                response.setVirtualMachineName(vm.getHostName());
                if (vm.getDisplayName() != null) {
                    response.setVirtualMachineDisplayName(vm.getDisplayName());
                } else {
                    response.setVirtualMachineDisplayName(vm.getHostName());
                }
            }
        }
    }
    FirewallRule.State state = fwRule.getState();
    String stateToSet = state.toString();
    if (state.equals(FirewallRule.State.Revoke)) {
        stateToSet = "Deleting";
    }
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.PortForwardingRule, fwRule.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    response.setState(stateToSet);
    response.setForDisplay(fwRule.isDisplay());
    response.setObjectName("portforwardingrule");
    return response;
}
Also used : ArrayList(java.util.ArrayList) UserVm(com.cloud.uservm.UserVm) ResourceTag(com.cloud.server.ResourceTag) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) IpAddress(com.cloud.network.IpAddress) FirewallRuleResponse(org.apache.cloudstack.api.response.FirewallRuleResponse) FirewallRule(com.cloud.network.rules.FirewallRule)

Aggregations

ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)18 ResourceTag (com.cloud.server.ResourceTag)12 ArrayList (java.util.ArrayList)12 Network (com.cloud.network.Network)6 PhysicalNetwork (com.cloud.network.PhysicalNetwork)6 DataCenter (com.cloud.dc.DataCenter)5 HashSet (java.util.HashSet)5 FirewallRule (com.cloud.network.rules.FirewallRule)4 HashMap (java.util.HashMap)4 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)3 IpAddress (com.cloud.network.IpAddress)3 Vpc (com.cloud.network.vpc.Vpc)3 UserVm (com.cloud.uservm.UserVm)3 Map (java.util.Map)3 Set (java.util.Set)3 SecurityGroupJoinVO (com.cloud.api.query.vo.SecurityGroupJoinVO)2 Provider (com.cloud.network.Network.Provider)2 Service (com.cloud.network.Network.Service)2 OvsProvider (com.cloud.network.OvsProvider)2 PhysicalNetworkServiceProvider (com.cloud.network.PhysicalNetworkServiceProvider)2