Search in sources :

Example 6 with ResourceTag

use of com.cloud.server.ResourceTag in project cloudstack by apache.

the class ApiResponseHelper method createStaticRouteResponse.

@Override
public StaticRouteResponse createStaticRouteResponse(StaticRoute result) {
    StaticRouteResponse response = new StaticRouteResponse();
    response.setId(result.getUuid());
    if (result.getVpcId() != null) {
        Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
        if (vpc != null) {
            response.setVpcId(vpc.getUuid());
        }
    }
    response.setCidr(result.getCidr());
    StaticRoute.State state = result.getState();
    if (state.equals(StaticRoute.State.Revoke)) {
        state = StaticRoute.State.Deleting;
    }
    response.setState(state.toString());
    populateAccount(response, result.getAccountId());
    populateDomain(response, result.getDomainId());
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.StaticRoute, result.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    response.setObjectName("staticroute");
    return response;
}
Also used : StaticRouteResponse(org.apache.cloudstack.api.response.StaticRouteResponse) StaticRoute(com.cloud.network.vpc.StaticRoute) ResourceTag(com.cloud.server.ResourceTag) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse)

Example 7 with ResourceTag

use of com.cloud.server.ResourceTag 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)

Example 8 with ResourceTag

use of com.cloud.server.ResourceTag in project cloudstack by apache.

the class ApiResponseHelper method createIPAddressResponse.

@Override
public IPAddressResponse createIPAddressResponse(ResponseView view, IpAddress ipAddr) {
    VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId());
    boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
    long zoneId = ipAddr.getDataCenterId();
    IPAddressResponse ipResponse = new IPAddressResponse();
    ipResponse.setId(ipAddr.getUuid());
    ipResponse.setIpAddress(ipAddr.getAddress().toString());
    if (ipAddr.getAllocatedTime() != null) {
        ipResponse.setAllocated(ipAddr.getAllocatedTime());
    }
    DataCenter zone = ApiDBUtils.findZoneById(ipAddr.getDataCenterId());
    if (zone != null) {
        ipResponse.setZoneId(zone.getUuid());
        ipResponse.setZoneName(zone.getName());
    }
    ipResponse.setSourceNat(ipAddr.isSourceNat());
    ipResponse.setIsSystem(ipAddr.getSystem());
    // get account information
    if (ipAddr.getAllocatedToAccountId() != null) {
        populateOwner(ipResponse, ipAddr);
    }
    ipResponse.setForVirtualNetwork(forVirtualNetworks);
    ipResponse.setStaticNat(ipAddr.isOneToOneNat());
    if (ipAddr.getAssociatedWithVmId() != null) {
        UserVm vm = ApiDBUtils.findUserVmById(ipAddr.getAssociatedWithVmId());
        if (vm != null) {
            ipResponse.setVirtualMachineId(vm.getUuid());
            ipResponse.setVirtualMachineName(vm.getHostName());
            if (vm.getDisplayName() != null) {
                ipResponse.setVirtualMachineDisplayName(vm.getDisplayName());
            } else {
                ipResponse.setVirtualMachineDisplayName(vm.getHostName());
            }
        }
    }
    if (ipAddr.getVmIp() != null) {
        ipResponse.setVirtualMachineIp(ipAddr.getVmIp());
    }
    if (ipAddr.getAssociatedWithNetworkId() != null) {
        Network ntwk = ApiDBUtils.findNetworkById(ipAddr.getAssociatedWithNetworkId());
        if (ntwk != null) {
            ipResponse.setAssociatedNetworkId(ntwk.getUuid());
            ipResponse.setAssociatedNetworkName(ntwk.getName());
        }
    }
    if (ipAddr.getVpcId() != null) {
        Vpc vpc = ApiDBUtils.findVpcById(ipAddr.getVpcId());
        if (vpc != null) {
            ipResponse.setVpcId(vpc.getUuid());
        }
    }
    // Network id the ip is associated with (if associated networkId is
    // null, try to get this information from vlan)
    Long vlanNetworkId = ApiDBUtils.getVlanNetworkId(ipAddr.getVlanId());
    // Network id the ip belongs to
    Long networkId;
    if (vlanNetworkId != null) {
        networkId = vlanNetworkId;
    } else {
        networkId = ApiDBUtils.getPublicNetworkIdByZone(zoneId);
    }
    if (networkId != null) {
        NetworkVO nw = ApiDBUtils.findNetworkById(networkId);
        if (nw != null) {
            ipResponse.setNetworkId(nw.getUuid());
        }
    }
    ipResponse.setState(ipAddr.getState().toString());
    if (ipAddr.getPhysicalNetworkId() != null) {
        PhysicalNetworkVO pnw = ApiDBUtils.findPhysicalNetworkById(ipAddr.getPhysicalNetworkId());
        if (pnw != null) {
            ipResponse.setPhysicalNetworkId(pnw.getUuid());
        }
    }
    // show this info to full view only
    if (view == ResponseView.Full) {
        VlanVO vl = ApiDBUtils.findVlanById(ipAddr.getVlanId());
        if (vl != null) {
            ipResponse.setVlanId(vl.getUuid());
            ipResponse.setVlanName(vl.getVlanTag());
        }
    }
    if (ipAddr.getSystem()) {
        if (ipAddr.isOneToOneNat()) {
            ipResponse.setPurpose(IpAddress.Purpose.StaticNat.toString());
        } else {
            ipResponse.setPurpose(IpAddress.Purpose.Lb.toString());
        }
    }
    ipResponse.setForDisplay(ipAddr.isDisplay());
    ipResponse.setPortable(ipAddr.isPortable());
    //set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.PublicIpAddress, ipAddr.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    ipResponse.setTags(tagResponses);
    ipResponse.setObjectName("ipaddress");
    return ipResponse;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) Vpc(com.cloud.network.vpc.Vpc) ArrayList(java.util.ArrayList) UserVm(com.cloud.uservm.UserVm) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) VlanVO(com.cloud.dc.VlanVO) IPAddressResponse(org.apache.cloudstack.api.response.IPAddressResponse)

Example 9 with ResourceTag

use of com.cloud.server.ResourceTag 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());
    }
    //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.setObjectName("networkacl");
    return response;
}
Also used : NetworkACLItem(com.cloud.network.vpc.NetworkACLItem) ResourceTag(com.cloud.server.ResourceTag) ArrayList(java.util.ArrayList) ResourceTagResponse(org.apache.cloudstack.api.response.ResourceTagResponse) NetworkACL(com.cloud.network.vpc.NetworkACL) NetworkACLItemResponse(org.apache.cloudstack.api.response.NetworkACLItemResponse)

Example 10 with ResourceTag

use of com.cloud.server.ResourceTag 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());
    }
    //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)

Aggregations

ResourceTag (com.cloud.server.ResourceTag)13 ArrayList (java.util.ArrayList)12 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)10 Network (com.cloud.network.Network)6 PhysicalNetwork (com.cloud.network.PhysicalNetwork)6 DataCenter (com.cloud.dc.DataCenter)5 FirewallRule (com.cloud.network.rules.FirewallRule)4 IpAddress (com.cloud.network.IpAddress)3 Vpc (com.cloud.network.vpc.Vpc)3 UserVm (com.cloud.uservm.UserVm)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ActionEvent (com.cloud.event.ActionEvent)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 Service (com.cloud.network.Network.Service)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 NetworkACL (com.cloud.network.vpc.NetworkACL)2 Account (com.cloud.user.Account)2 VMInstanceVO (com.cloud.vm.VMInstanceVO)2