Search in sources :

Example 6 with ResourceTagResponse

use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createVpcResponse.

@Override
public VpcResponse createVpcResponse(final ResponseView view, final Vpc vpc) {
    final VpcResponse response = new VpcResponse();
    response.setId(vpc.getUuid());
    response.setName(vpc.getName());
    response.setDisplayText(vpc.getDisplayText());
    response.setState(vpc.getState().name());
    final VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
    if (voff != null) {
        response.setVpcOfferingId(voff.getUuid());
        response.setVpcOfferingName(voff.getName());
        response.setVpcOfferingDisplayText(voff.getDisplayText());
    }
    response.setCidr(vpc.getCidr());
    response.setRestartRequired(vpc.isRestartRequired());
    response.setNetworkDomain(vpc.getNetworkDomain());
    response.setForDisplay(vpc.isDisplay());
    response.setRedundantRouter(vpc.isRedundant());
    response.setSourceNatList(vpc.getSourceNatList());
    response.setSyslogServerList(vpc.getSyslogServerList());
    final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
    final List<ServiceResponse> serviceResponses = getServiceResponses(serviceProviderMap);
    final List<NetworkResponse> networkResponses = new ArrayList<>();
    final List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
    for (final Network network : networks) {
        final NetworkResponse ntwkRsp = createNetworkResponse(view, network);
        networkResponses.add(ntwkRsp);
    }
    final DataCenter zone = ApiDBUtils.findZoneById(vpc.getZoneId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setNetworks(networkResponses);
    response.setServices(serviceResponses);
    populateOwner(response, vpc);
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Vpc, vpc.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    response.setObjectName("vpc");
    return response;
}
Also used : EnumSet(java.util.EnumSet) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Service(com.cloud.network.Network.Service) ServiceResponse(com.cloud.api.response.ServiceResponse) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) VpcResponse(com.cloud.api.response.VpcResponse) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VpcOffering(com.cloud.network.vpc.VpcOffering) NetworkResponse(com.cloud.api.response.NetworkResponse) PhysicalNetworkResponse(com.cloud.api.response.PhysicalNetworkResponse) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse)

Example 7 with ResourceTagResponse

use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createPortForwardingRuleResponse.

@Override
public FirewallRuleResponse createPortForwardingRuleResponse(final PortForwardingRule fwRule) {
    final 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()));
    final List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(fwRule.getId());
    response.setCidrList(StringUtils.join(cidrs, ","));
    final Network guestNtwk = ApiDBUtils.findNetworkById(fwRule.getNetworkId());
    response.setNetworkId(guestNtwk.getUuid());
    final 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());
            final 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());
                }
            }
        }
    }
    final FirewallRule.State state = fwRule.getState();
    String stateToSet = state.toString();
    if (state.equals(FirewallRule.State.Revoke)) {
        stateToSet = "Deleting";
    }
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.PortForwardingRule, fwRule.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final 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(com.cloud.api.response.ResourceTagResponse) IpAddress(com.cloud.network.IpAddress) FirewallRuleResponse(com.cloud.api.response.FirewallRuleResponse) FirewallRule(com.cloud.network.rules.FirewallRule)

Example 8 with ResourceTagResponse

use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createNetworkACLItemResponse.

@Override
public NetworkACLItemResponse createNetworkACLItemResponse(final NetworkACLItem aclItem) {
    final 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());
    final 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());
    final NetworkACL acl = ApiDBUtils.findByNetworkACLId(aclItem.getAclId());
    if (acl != null) {
        response.setAclId(acl.getUuid());
    }
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.NetworkACL, aclItem.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final 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) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) ArrayList(java.util.ArrayList) NetworkACL(com.cloud.network.vpc.NetworkACL) NetworkACLItemResponse(com.cloud.api.response.NetworkACLItemResponse)

Example 9 with ResourceTagResponse

use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createIPAddressResponse.

@Override
public IPAddressResponse createIPAddressResponse(final ResponseView view, final IpAddress ipAddr) {
    final VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId());
    final boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
    final long zoneId = ipAddr.getDataCenterId();
    final IPAddressResponse ipResponse = new IPAddressResponse();
    ipResponse.setId(ipAddr.getUuid());
    ipResponse.setIpAddress(ipAddr.getAddress().toString());
    if (ipAddr.getAllocatedTime() != null) {
        ipResponse.setAllocated(ipAddr.getAllocatedTime());
    }
    final 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) {
        final 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) {
        final Network ntwk = ApiDBUtils.findNetworkById(ipAddr.getAssociatedWithNetworkId());
        if (ntwk != null) {
            ipResponse.setAssociatedNetworkId(ntwk.getUuid());
            ipResponse.setAssociatedNetworkName(ntwk.getName());
        }
    }
    if (ipAddr.getVpcId() != null) {
        final 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)
    final Long vlanNetworkId = ApiDBUtils.getVlanNetworkId(ipAddr.getVlanId());
    // Network id the ip belongs to
    final Long networkId;
    if (vlanNetworkId != null) {
        networkId = vlanNetworkId;
    } else {
        networkId = ApiDBUtils.getPublicNetworkIdByZone(zoneId);
    }
    if (networkId != null) {
        final NetworkVO nw = ApiDBUtils.findNetworkById(networkId);
        if (nw != null) {
            ipResponse.setNetworkId(nw.getUuid());
            ipResponse.setAssociatedNetworkName(nw.getName());
        }
    }
    ipResponse.setState(ipAddr.getState().toString());
    final NetworkACL acl = ApiDBUtils.findByNetworkACLId(ipAddr.getIpACLId());
    if (acl != null) {
        ipResponse.setAclId(acl.getUuid());
        ipResponse.setAclName(acl.getName());
    }
    if (ipAddr.getPhysicalNetworkId() != null) {
        final PhysicalNetworkVO pnw = ApiDBUtils.findPhysicalNetworkById(ipAddr.getPhysicalNetworkId());
        if (pnw != null) {
            ipResponse.setPhysicalNetworkId(pnw.getUuid());
        }
    }
    // show this info to full view only
    if (view == ResponseView.Full) {
        final 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());
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.PublicIpAddress, ipAddr.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final 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) NetworkACL(com.cloud.network.vpc.NetworkACL) 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(com.cloud.api.response.ResourceTagResponse) VlanVO(com.cloud.dc.VlanVO) IPAddressResponse(com.cloud.api.response.IPAddressResponse)

Example 10 with ResourceTagResponse

use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.

the class DataCenterJoinDaoImpl method newDataCenterResponse.

@Override
public ZoneResponse newDataCenterResponse(final ResponseView view, final DataCenterJoinVO dataCenter, final Boolean showCapacities) {
    final ZoneResponse zoneResponse = new ZoneResponse();
    zoneResponse.setId(dataCenter.getUuid());
    zoneResponse.setName(dataCenter.getName());
    zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled());
    if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) {
        zoneResponse.setDescription(dataCenter.getDescription());
    }
    if (view == ResponseView.Full) {
        zoneResponse.setDns1(dataCenter.getDns1());
        zoneResponse.setDns2(dataCenter.getDns2());
        zoneResponse.setIp6Dns1(dataCenter.getIp6Dns1());
        zoneResponse.setIp6Dns2(dataCenter.getIp6Dns2());
        zoneResponse.setInternalDns1(dataCenter.getInternalDns1());
        zoneResponse.setInternalDns2(dataCenter.getInternalDns2());
        // FIXME zoneResponse.setVlan(dataCenter.get.getVnet());
        zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr());
        if (showCapacities != null && showCapacities) {
            zoneResponse.setCapacitites(ApiResponseHelper.getDataCenterCapacityResponse(dataCenter.getId()));
        }
    }
    // set network domain info
    zoneResponse.setDomain(dataCenter.getDomain());
    // set domain info
    zoneResponse.setDomainId(dataCenter.getDomainUuid());
    zoneResponse.setDomainName(dataCenter.getDomainName());
    zoneResponse.setType(dataCenter.getNetworkType().toString());
    zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
    zoneResponse.setZoneToken(dataCenter.getZoneToken());
    zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
    // update tag information
    final List<ResourceTagJoinVO> resourceTags = ApiDBUtils.listResourceTagViewByResourceUUID(dataCenter.getUuid(), ResourceObjectType.Zone);
    for (final ResourceTagJoinVO resourceTag : resourceTags) {
        final ResourceTagResponse tagResponse = ApiDBUtils.newResourceTagResponse(resourceTag, false);
        zoneResponse.addTag(tagResponse);
    }
    zoneResponse.setResourceDetails(ApiDBUtils.getResourceDetails(dataCenter.getId(), ResourceObjectType.Zone));
    zoneResponse.setObjectName("zone");
    return zoneResponse;
}
Also used : ZoneResponse(com.cloud.api.response.ZoneResponse) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Aggregations

ResourceTagResponse (com.cloud.api.response.ResourceTagResponse)11 ResourceTag (com.cloud.server.ResourceTag)9 ArrayList (java.util.ArrayList)9 DataCenter (com.cloud.dc.DataCenter)5 Network (com.cloud.network.Network)5 PhysicalNetwork (com.cloud.network.PhysicalNetwork)5 FirewallRule (com.cloud.network.rules.FirewallRule)3 NetworkACL (com.cloud.network.vpc.NetworkACL)3 Vpc (com.cloud.network.vpc.Vpc)3 NetworkResponse (com.cloud.api.response.NetworkResponse)2 PhysicalNetworkResponse (com.cloud.api.response.PhysicalNetworkResponse)2 ServiceResponse (com.cloud.api.response.ServiceResponse)2 IpAddress (com.cloud.network.IpAddress)2 Service (com.cloud.network.Network.Service)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 UserVm (com.cloud.uservm.UserVm)2 HashSet (java.util.HashSet)2 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)1 CapabilityResponse (com.cloud.api.response.CapabilityResponse)1