use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createFirewallResponse.
@Override
public FirewallResponse createFirewallResponse(final FirewallRule fwRule) {
final 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());
}
final List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(fwRule.getId());
response.setCidrList(StringUtils.join(cidrs, ","));
if (fwRule.getTrafficType() == FirewallRule.TrafficType.Ingress) {
final IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
response.setPublicIpAddressId(ip.getUuid());
response.setPublicIpAddress(ip.getAddress().addr());
}
final Network network = ApiDBUtils.findNetworkById(fwRule.getNetworkId());
response.setNetworkId(network.getUuid());
final 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
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.FirewallRule, 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.setObjectName("firewallrule");
return response;
}
use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createStaticRouteResponse.
@Override
public StaticRouteResponse createStaticRouteResponse(final StaticRoute result) {
final StaticRouteResponse response = new StaticRouteResponse();
response.setId(result.getUuid());
if (result.getVpcId() != null) {
final Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
if (vpc != null) {
response.setVpcId(vpc.getUuid());
}
}
response.setCidr(result.getCidr());
response.setGwIpAddress(result.getGwIpAddress());
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
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.StaticRoute, result.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("staticroute");
return response;
}
use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createSnapshotResponse.
@Override
public SnapshotResponse createSnapshotResponse(final Snapshot snapshot) {
final SnapshotResponse snapshotResponse = new SnapshotResponse();
snapshotResponse.setId(snapshot.getUuid());
populateOwner(snapshotResponse, snapshot);
final VolumeVO volume = findVolumeById(snapshot.getVolumeId());
final String snapshotTypeStr = snapshot.getRecurringType().name();
snapshotResponse.setSnapshotType(snapshotTypeStr);
if (volume != null) {
snapshotResponse.setVolumeId(volume.getUuid());
snapshotResponse.setVolumeName(volume.getName());
snapshotResponse.setVolumeType(volume.getVolumeType().name());
final DataCenter zone = ApiDBUtils.findZoneById(volume.getDataCenterId());
if (zone != null) {
snapshotResponse.setZoneId(zone.getUuid());
}
}
snapshotResponse.setCreated(snapshot.getCreated());
snapshotResponse.setName(snapshot.getName());
snapshotResponse.setIntervalType(ApiDBUtils.getSnapshotIntervalTypes(snapshot.getId()));
snapshotResponse.setState(snapshot.getState());
final SnapshotInfo snapshotInfo;
if (snapshot instanceof SnapshotInfo) {
snapshotInfo = (SnapshotInfo) snapshot;
} else {
final DataStoreRole dataStoreRole = getDataStoreRole(snapshot, _snapshotStoreDao, _dataStoreMgr);
snapshotInfo = snapshotfactory.getSnapshot(snapshot.getId(), dataStoreRole);
}
if (snapshotInfo == null) {
s_logger.debug("Unable to find info for image store snapshot with uuid " + snapshot.getUuid());
snapshotResponse.setRevertable(false);
} else {
snapshotResponse.setRevertable(snapshotInfo.isRevertable());
snapshotResponse.setPhysicaSize(snapshotInfo.getPhysicalSize());
}
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Snapshot, snapshot.getId());
final List<ResourceTagResponse> tagResponses = new ArrayList<>();
for (final ResourceTag tag : tags) {
final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
snapshotResponse.setTags(tagResponses);
snapshotResponse.setObjectName("snapshot");
return snapshotResponse;
}
use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createNetworkResponse.
@Override
public NetworkResponse createNetworkResponse(final ResponseView view, final Network network) {
// need to get network profile in order to retrieve dns information from
// there
final NetworkProfile profile = ApiDBUtils.getNetworkProfile(network.getId());
final NetworkResponse response = new NetworkResponse();
response.setId(network.getUuid());
response.setName(network.getName());
response.setDisplaytext(network.getDisplayText());
if (network.getBroadcastDomainType() != null) {
response.setBroadcastDomainType(network.getBroadcastDomainType().toString());
}
if (network.getTrafficType() != null) {
response.setTrafficType(network.getTrafficType().name());
}
if (network.getGuestType() != null) {
response.setType(network.getGuestType().toString());
}
response.setGateway(network.getGateway());
// FIXME - either set netmask or cidr
response.setCidr(network.getCidr());
response.setNetworkCidr(network.getNetworkCidr());
// network cidr
if (network.getNetworkCidr() != null) {
response.setNetmask(NetUtils.cidr2Netmask(network.getNetworkCidr()));
}
if (network.getCidr() != null && network.getNetworkCidr() == null) {
response.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
}
response.setIpExclusionList(((NetworkVO) network).getIpExclusionList());
response.setIp6Gateway(network.getIp6Gateway());
response.setIp6Cidr(network.getIp6Cidr());
// create response for reserved IP ranges that can be used for
// non-cloudstack purposes
String reservation = null;
if (network.getCidr() != null && NetUtils.isNetworkAWithinNetworkB(network.getCidr(), network.getNetworkCidr())) {
final String[] guestVmCidrPair = network.getCidr().split("\\/");
final String[] guestCidrPair = network.getNetworkCidr().split("\\/");
final Long guestVmCidrSize = Long.valueOf(guestVmCidrPair[1]);
final Long guestCidrSize = Long.valueOf(guestCidrPair[1]);
final String[] guestVmIpRange = NetUtils.getIpRangeFromCidr(guestVmCidrPair[0], guestVmCidrSize);
final String[] guestIpRange = NetUtils.getIpRangeFromCidr(guestCidrPair[0], guestCidrSize);
final long startGuestIp = NetUtils.ip2Long(guestIpRange[0]);
final long endGuestIp = NetUtils.ip2Long(guestIpRange[1]);
final long startVmIp = NetUtils.ip2Long(guestVmIpRange[0]);
final long endVmIp = NetUtils.ip2Long(guestVmIpRange[1]);
if (startVmIp == startGuestIp && endVmIp < endGuestIp - 1) {
reservation = NetUtils.long2Ip(endVmIp + 1) + "-" + NetUtils.long2Ip(endGuestIp);
}
if (endVmIp == endGuestIp && startVmIp > startGuestIp + 1) {
reservation = NetUtils.long2Ip(startGuestIp) + "-" + NetUtils.long2Ip(startVmIp - 1);
}
if (startVmIp > startGuestIp + 1 && endVmIp < endGuestIp - 1) {
reservation = NetUtils.long2Ip(startGuestIp) + "-" + NetUtils.long2Ip(startVmIp - 1) + " , " + NetUtils.long2Ip(endVmIp + 1) + "-" + NetUtils.long2Ip(endGuestIp);
}
}
response.setReservedIpRange(reservation);
if (network.getBroadcastUri() != null) {
final String broadcastUri = network.getBroadcastUri().toString();
response.setBroadcastUri(broadcastUri);
String vlan = "N/A";
switch(BroadcastDomainType.getSchemeValue(network.getBroadcastUri())) {
case Vlan:
case Vxlan:
vlan = BroadcastDomainType.getValue(network.getBroadcastUri());
break;
}
response.setVlan(vlan);
}
final DataCenter zone = ApiDBUtils.findZoneById(network.getDataCenterId());
if (zone != null) {
response.setZoneId(zone.getUuid());
response.setZoneName(zone.getName());
}
if (network.getPhysicalNetworkId() != null) {
final PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(network.getPhysicalNetworkId());
response.setPhysicalNetworkId(pnet.getUuid());
}
// populate network offering information
final NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
if (networkOffering != null) {
response.setNetworkOfferingId(networkOffering.getUuid());
response.setNetworkOfferingName(networkOffering.getName());
response.setNetworkOfferingDisplayText(networkOffering.getDisplayText());
response.setNetworkOfferingConserveMode(networkOffering.isConserveMode());
response.setIsSystem(networkOffering.isSystemOnly());
response.setNetworkOfferingAvailability(networkOffering.getAvailability().toString());
response.setIsPersistent(networkOffering.getIsPersistent());
}
if (network.getAclType() != null) {
response.setAclType(network.getAclType().toString());
}
response.setDisplayNetwork(network.getDisplayNetwork());
response.setState(network.getState().toString());
response.setRestartRequired(network.isRestartRequired());
final NetworkVO nw = ApiDBUtils.findNetworkById(network.getRelated());
if (nw != null) {
response.setRelated(nw.getUuid());
}
response.setNetworkDomain(network.getNetworkDomain());
response.setDns1(profile.getDns1());
response.setDns2(profile.getDns2());
// populate capability
final Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(network.getId(), network.getDataCenterId());
final List<ServiceResponse> serviceResponses = new ArrayList<>();
if (serviceCapabilitiesMap != null) {
for (final Map.Entry<Service, Map<Capability, String>> entry : serviceCapabilitiesMap.entrySet()) {
final Service service = entry.getKey();
final ServiceResponse serviceResponse = new ServiceResponse();
// skip gateway service
if (service == Service.Gateway) {
continue;
}
serviceResponse.setName(service.getName());
// set list of capabilities for the service
final List<CapabilityResponse> capabilityResponses = new ArrayList<>();
final Map<Capability, String> serviceCapabilities = entry.getValue();
if (serviceCapabilities != null) {
for (final Map.Entry<Capability, String> ser_cap_entries : serviceCapabilities.entrySet()) {
final Capability capability = ser_cap_entries.getKey();
final CapabilityResponse capabilityResponse = new CapabilityResponse();
final String capabilityValue = ser_cap_entries.getValue();
capabilityResponse.setName(capability.getName());
capabilityResponse.setValue(capabilityValue);
capabilityResponse.setObjectName("capability");
capabilityResponses.add(capabilityResponse);
}
serviceResponse.setCapabilities(capabilityResponses);
}
serviceResponse.setObjectName("service");
serviceResponses.add(serviceResponse);
}
}
response.setServices(serviceResponses);
if (network.getAclType() == null || network.getAclType() == ACLType.Account) {
populateOwner(response, network);
} else {
// get domain from network_domain table
final Pair<Long, Boolean> domainNetworkDetails = ApiDBUtils.getDomainNetworkDetails(network.getId());
if (domainNetworkDetails.first() != null) {
final Domain domain = ApiDBUtils.findDomainById(domainNetworkDetails.first());
if (domain != null) {
response.setDomainId(domain.getUuid());
}
}
response.setSubdomainAccess(domainNetworkDetails.second());
}
final Long dedicatedDomainId = ApiDBUtils.getDedicatedNetworkDomain(network.getId());
if (dedicatedDomainId != null) {
final Domain domain = ApiDBUtils.findDomainById(dedicatedDomainId);
if (domain != null) {
response.setDomainId(domain.getUuid());
response.setDomainName(domain.getName());
}
}
response.setSpecifyIpRanges(network.getSpecifyIpRanges());
if (network.getVpcId() != null) {
final Vpc vpc = ApiDBUtils.findVpcById(network.getVpcId());
if (vpc != null) {
response.setVpcId(vpc.getUuid());
response.setVpcName(vpc.getName());
}
}
response.setCanUseForDeploy(ApiDBUtils.canUseForDeploy(network));
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Network, network.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);
if (network.getNetworkACLId() != null) {
final NetworkACL acl = ApiDBUtils.findByNetworkACLId(network.getNetworkACLId());
if (acl != null) {
response.setAclId(acl.getUuid());
response.setAclName(acl.getName());
}
}
response.setStrechedL2Subnet(network.isStrechedL2Network());
if (network.isStrechedL2Network()) {
final Set<String> networkSpannedZones = new HashSet<>();
final List<VMInstanceVO> vmInstances = new ArrayList<>();
vmInstances.addAll(ApiDBUtils.listUserVMsByNetworkId(network.getId()));
vmInstances.addAll(ApiDBUtils.listDomainRoutersByNetworkId(network.getId()));
for (final VirtualMachine vm : vmInstances) {
final DataCenter vmZone = ApiDBUtils.findZoneById(vm.getDataCenterId());
networkSpannedZones.add(vmZone.getUuid());
}
response.setNetworkSpannedZones(networkSpannedZones);
}
response.setObjectName("network");
return response;
}
use of com.cloud.api.response.ResourceTagResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createLoadBalancerResponse.
@Override
public LoadBalancerResponse createLoadBalancerResponse(final LoadBalancer loadBalancer) {
final LoadBalancerResponse lbResponse = new LoadBalancerResponse();
lbResponse.setId(loadBalancer.getUuid());
lbResponse.setName(loadBalancer.getName());
lbResponse.setDescription(loadBalancer.getDescription());
final List<String> cidrs = ApiDBUtils.findFirewallSourceCidrs(loadBalancer.getId());
lbResponse.setCidrList(StringUtils.join(cidrs, ","));
final 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());
lbResponse.setClientTimeout(loadBalancer.getClientTimeout());
lbResponse.setServerTimeout(loadBalancer.getServerTimeout());
final FirewallRule.State state = loadBalancer.getState();
String stateToSet = state.toString();
if (state.equals(FirewallRule.State.Revoke)) {
stateToSet = "Deleting";
}
lbResponse.setState(stateToSet);
populateOwner(lbResponse, loadBalancer);
final DataCenter zone = ApiDBUtils.findZoneById(publicIp.getDataCenterId());
if (zone != null) {
lbResponse.setZoneId(zone.getUuid());
}
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.LoadBalancer, loadBalancer.getId());
final List<ResourceTagResponse> tagResponses = new ArrayList<>();
for (final ResourceTag tag : tags) {
final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
lbResponse.setTags(tagResponses);
final Network ntwk = ApiDBUtils.findNetworkById(loadBalancer.getNetworkId());
lbResponse.setNetworkId(ntwk.getUuid());
lbResponse.setObjectName("loadbalancer");
return lbResponse;
}
Aggregations