use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class OvsGuestNetworkGuru method shutdown.
@Override
public void shutdown(NetworkProfile profile, NetworkOffering offering) {
NetworkVO networkObject = _networkDao.findById(profile.getId());
if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Vswitch || networkObject.getBroadcastUri() == null) {
s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText());
return;
}
if (profile.getBroadcastDomainType() == BroadcastDomainType.Vswitch) {
s_logger.debug("Releasing vnet for the network id=" + profile.getId());
_dcDao.releaseVnet(BroadcastDomainType.getValue(profile.getBroadcastUri()), profile.getDataCenterId(), profile.getPhysicalNetworkId(), profile.getAccountId(), profile.getReservationId());
}
profile.setBroadcastUri(null);
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class OvsGuestNetworkGuru method implement.
@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
long dcId = dest.getDataCenter().getId();
NetworkType nwType = dest.getDataCenter().getNetworkType();
// get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
// locate the physical network
if (physicalNetworkId == null) {
physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
}
PhysicalNetworkVO physnet = _physicalNetworkDao.findById(physicalNetworkId);
if (!canHandle(offering, nwType, physnet)) {
s_logger.debug("Refusing to design this network");
return null;
}
NetworkVO implemented = (NetworkVO) super.implement(network, offering, dest, context);
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
implemented.setBroadcastDomainType(BroadcastDomainType.Vswitch);
// for the networks that are part of VPC enabled for distributed routing use scheme vs://vpcid.GRE key for network
if (network.getVpcId() != null && isVpcEnabledForDistributedRouter(network.getVpcId())) {
String keyStr = BroadcastDomainType.getValue(implemented.getBroadcastUri());
Long vpcid = network.getVpcId();
implemented.setBroadcastUri(BroadcastDomainType.Vswitch.toUri(vpcid.toString() + "." + keyStr));
}
return implemented;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class OvsGuestNetworkGuru method design.
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
if (!canHandle(offering, dc.getNetworkType(), physnet)) {
s_logger.debug("Refusing to design this network");
return null;
}
NetworkVO config = (NetworkVO) super.design(offering, plan, userSpecified, owner);
if (config == null) {
return null;
}
config.setBroadcastDomainType(BroadcastDomainType.Vswitch);
return config;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class ApiResponseHelper method createUsageResponse.
@Override
public UsageRecordResponse createUsageResponse(Usage usageRecord) {
UsageRecordResponse usageRecResponse = new UsageRecordResponse();
Account account = ApiDBUtils.findAccountById(usageRecord.getAccountId());
if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
//find the project
Project project = ApiDBUtils.findProjectByProjectAccountIdIncludingRemoved(account.getId());
if (project != null) {
usageRecResponse.setProjectId(project.getUuid());
usageRecResponse.setProjectName(project.getName());
}
} else {
usageRecResponse.setAccountId(account.getUuid());
usageRecResponse.setAccountName(account.getAccountName());
}
Domain domain = ApiDBUtils.findDomainById(usageRecord.getDomainId());
if (domain != null) {
usageRecResponse.setDomainId(domain.getUuid());
usageRecResponse.setDomainName(domain.getName());
}
if (usageRecord.getZoneId() != null) {
DataCenter zone = ApiDBUtils.findZoneById(usageRecord.getZoneId());
if (zone != null) {
usageRecResponse.setZoneId(zone.getUuid());
}
}
usageRecResponse.setDescription(usageRecord.getDescription());
usageRecResponse.setUsage(usageRecord.getUsageDisplay());
usageRecResponse.setUsageType(usageRecord.getUsageType());
if (usageRecord.getVmInstanceId() != null) {
VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getVmInstanceId());
if (vm != null) {
usageRecResponse.setVirtualMachineId(vm.getUuid());
}
}
usageRecResponse.setVmName(usageRecord.getVmName());
if (usageRecord.getTemplateId() != null) {
VMTemplateVO template = ApiDBUtils.findTemplateById(usageRecord.getTemplateId());
if (template != null) {
usageRecResponse.setTemplateId(template.getUuid());
}
}
if (usageRecord.getUsageType() == UsageTypes.RUNNING_VM || usageRecord.getUsageType() == UsageTypes.ALLOCATED_VM) {
ServiceOfferingVO svcOffering = _entityMgr.findByIdIncludingRemoved(ServiceOfferingVO.class, usageRecord.getOfferingId().toString());
//Service Offering Id
usageRecResponse.setOfferingId(svcOffering.getUuid());
//VM Instance ID
VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString());
if (vm != null) {
usageRecResponse.setUsageId(vm.getUuid());
}
//Hypervisor Type
usageRecResponse.setType(usageRecord.getType());
//Dynamic compute offerings details
usageRecResponse.setCpuNumber(usageRecord.getCpuCores());
usageRecResponse.setCpuSpeed(usageRecord.getCpuSpeed());
usageRecResponse.setMemory(usageRecord.getMemory());
} else if (usageRecord.getUsageType() == UsageTypes.IP_ADDRESS) {
//isSourceNAT
usageRecResponse.setSourceNat((usageRecord.getType().equals("SourceNat")) ? true : false);
//isSystem
usageRecResponse.setSystem((usageRecord.getSize() == 1) ? true : false);
//IP Address ID
IPAddressVO ip = _entityMgr.findByIdIncludingRemoved(IPAddressVO.class, usageRecord.getUsageId().toString());
if (ip != null) {
usageRecResponse.setUsageId(ip.getUuid());
}
} else if (usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_SENT || usageRecord.getUsageType() == UsageTypes.NETWORK_BYTES_RECEIVED) {
//Device Type
usageRecResponse.setType(usageRecord.getType());
if (usageRecord.getType().equals("DomainRouter")) {
//Domain Router Id
VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getUsageId().toString());
if (vm != null) {
usageRecResponse.setUsageId(vm.getUuid());
}
} else {
//External Device Host Id
HostVO host = _entityMgr.findByIdIncludingRemoved(HostVO.class, usageRecord.getUsageId().toString());
if (host != null) {
usageRecResponse.setUsageId(host.getUuid());
}
}
//Network ID
if ((usageRecord.getNetworkId() != null) && (usageRecord.getNetworkId() != 0)) {
NetworkVO network = _entityMgr.findByIdIncludingRemoved(NetworkVO.class, usageRecord.getNetworkId().toString());
if (network != null) {
usageRecResponse.setNetworkId(network.getUuid());
}
}
} else if (usageRecord.getUsageType() == UsageTypes.VM_DISK_IO_READ || usageRecord.getUsageType() == UsageTypes.VM_DISK_IO_WRITE || usageRecord.getUsageType() == UsageTypes.VM_DISK_BYTES_READ || usageRecord.getUsageType() == UsageTypes.VM_DISK_BYTES_WRITE) {
//Device Type
usageRecResponse.setType(usageRecord.getType());
//VM Instance Id
VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getVmInstanceId().toString());
if (vm != null) {
usageRecResponse.setVirtualMachineId(vm.getUuid());
}
//Volume ID
VolumeVO volume = _entityMgr.findByIdIncludingRemoved(VolumeVO.class, usageRecord.getUsageId().toString());
if (volume != null) {
usageRecResponse.setUsageId(volume.getUuid());
}
} else if (usageRecord.getUsageType() == UsageTypes.VOLUME) {
//Volume ID
VolumeVO volume = _entityMgr.findByIdIncludingRemoved(VolumeVO.class, usageRecord.getUsageId().toString());
if (volume != null) {
usageRecResponse.setUsageId(volume.getUuid());
}
//Volume Size
usageRecResponse.setSize(usageRecord.getSize());
//Disk Offering Id
if (usageRecord.getOfferingId() != null) {
DiskOfferingVO diskOff = _entityMgr.findByIdIncludingRemoved(DiskOfferingVO.class, usageRecord.getOfferingId().toString());
usageRecResponse.setOfferingId(diskOff.getUuid());
}
} else if (usageRecord.getUsageType() == UsageTypes.TEMPLATE || usageRecord.getUsageType() == UsageTypes.ISO) {
//Template/ISO ID
VMTemplateVO tmpl = _entityMgr.findByIdIncludingRemoved(VMTemplateVO.class, usageRecord.getUsageId().toString());
if (tmpl != null) {
usageRecResponse.setUsageId(tmpl.getUuid());
}
//Template/ISO Size
usageRecResponse.setSize(usageRecord.getSize());
if (usageRecord.getUsageType() == UsageTypes.ISO) {
usageRecResponse.setVirtualSize(usageRecord.getSize());
} else {
usageRecResponse.setVirtualSize(usageRecord.getVirtualSize());
}
} else if (usageRecord.getUsageType() == UsageTypes.SNAPSHOT) {
//Snapshot ID
SnapshotVO snap = _entityMgr.findByIdIncludingRemoved(SnapshotVO.class, usageRecord.getUsageId().toString());
if (snap != null) {
usageRecResponse.setUsageId(snap.getUuid());
}
//Snapshot Size
usageRecResponse.setSize(usageRecord.getSize());
} else if (usageRecord.getUsageType() == UsageTypes.LOAD_BALANCER_POLICY) {
//Load Balancer Policy ID
LoadBalancerVO lb = _entityMgr.findByIdIncludingRemoved(LoadBalancerVO.class, usageRecord.getUsageId().toString());
if (lb != null) {
usageRecResponse.setUsageId(lb.getUuid());
}
} else if (usageRecord.getUsageType() == UsageTypes.PORT_FORWARDING_RULE) {
//Port Forwarding Rule ID
PortForwardingRuleVO pf = _entityMgr.findByIdIncludingRemoved(PortForwardingRuleVO.class, usageRecord.getUsageId().toString());
if (pf != null) {
usageRecResponse.setUsageId(pf.getUuid());
}
} else if (usageRecord.getUsageType() == UsageTypes.NETWORK_OFFERING) {
//Network Offering Id
NetworkOfferingVO netOff = _entityMgr.findByIdIncludingRemoved(NetworkOfferingVO.class, usageRecord.getOfferingId().toString());
usageRecResponse.setOfferingId(netOff.getUuid());
//is Default
usageRecResponse.setDefault((usageRecord.getUsageId() == 1) ? true : false);
} else if (usageRecord.getUsageType() == UsageTypes.VPN_USERS) {
//VPN User ID
VpnUserVO vpnUser = _entityMgr.findByIdIncludingRemoved(VpnUserVO.class, usageRecord.getUsageId().toString());
if (vpnUser != null) {
usageRecResponse.setUsageId(vpnUser.getUuid());
}
} else if (usageRecord.getUsageType() == UsageTypes.SECURITY_GROUP) {
//Security Group Id
SecurityGroupVO sg = _entityMgr.findByIdIncludingRemoved(SecurityGroupVO.class, usageRecord.getUsageId().toString());
if (sg != null) {
usageRecResponse.setUsageId(sg.getUuid());
}
} else if (usageRecord.getUsageType() == UsageTypes.VM_SNAPSHOT) {
VMInstanceVO vm = _entityMgr.findByIdIncludingRemoved(VMInstanceVO.class, usageRecord.getVmInstanceId().toString());
if (vm != null) {
usageRecResponse.setVmName(vm.getInstanceName());
usageRecResponse.setUsageId(vm.getUuid());
}
usageRecResponse.setSize(usageRecord.getSize());
if (usageRecord.getOfferingId() != null) {
usageRecResponse.setOfferingId(usageRecord.getOfferingId().toString());
}
}
if (usageRecord.getRawUsage() != null) {
DecimalFormat decimalFormat = new DecimalFormat("###########.######");
usageRecResponse.setRawUsage(decimalFormat.format(usageRecord.getRawUsage()));
}
if (usageRecord.getStartDate() != null) {
usageRecResponse.setStartDate(getDateStringInternal(usageRecord.getStartDate()));
}
if (usageRecord.getEndDate() != null) {
usageRecResponse.setEndDate(getDateStringInternal(usageRecord.getEndDate()));
}
return usageRecResponse;
}
use of com.cloud.network.dao.NetworkVO in project cloudstack by apache.
the class ApiResponseHelper method createNetworkResponse.
@Override
public NetworkResponse createNetworkResponse(ResponseView view, Network network) {
// need to get network profile in order to retrieve dns information from
// there
NetworkProfile profile = ApiDBUtils.getNetworkProfile(network.getId());
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.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()))) {
String[] guestVmCidrPair = network.getCidr().split("\\/");
String[] guestCidrPair = network.getNetworkCidr().split("\\/");
Long guestVmCidrSize = Long.valueOf(guestVmCidrPair[1]);
Long guestCidrSize = Long.valueOf(guestCidrPair[1]);
String[] guestVmIpRange = NetUtils.getIpRangeFromCidr(guestVmCidrPair[0], guestVmCidrSize);
String[] guestIpRange = NetUtils.getIpRangeFromCidr(guestCidrPair[0], guestCidrSize);
long startGuestIp = NetUtils.ip2Long(guestIpRange[0]);
long endGuestIp = NetUtils.ip2Long(guestIpRange[1]);
long startVmIp = NetUtils.ip2Long(guestVmIpRange[0]);
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);
// return vlan information only to Root admin
if (network.getBroadcastUri() != null && view == ResponseView.Full) {
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;
}
// return vlan information only to Root admin
response.setVlan(vlan);
}
DataCenter zone = ApiDBUtils.findZoneById(network.getDataCenterId());
if (zone != null) {
response.setZoneId(zone.getUuid());
response.setZoneName(zone.getName());
}
if (network.getPhysicalNetworkId() != null) {
PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(network.getPhysicalNetworkId());
response.setPhysicalNetworkId(pnet.getUuid());
}
// populate network offering information
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());
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
Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(network.getId(), network.getDataCenterId());
List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
if (serviceCapabilitiesMap != null) {
for (Map.Entry<Service, Map<Capability, String>> entry : serviceCapabilitiesMap.entrySet()) {
Service service = entry.getKey();
ServiceResponse serviceResponse = new ServiceResponse();
// skip gateway service
if (service == Service.Gateway) {
continue;
}
serviceResponse.setName(service.getName());
// set list of capabilities for the service
List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
Map<Capability, String> serviceCapabilities = entry.getValue();
if (serviceCapabilities != null) {
for (Map.Entry<Capability, String> ser_cap_entries : serviceCapabilities.entrySet()) {
Capability capability = ser_cap_entries.getKey();
CapabilityResponse capabilityResponse = new CapabilityResponse();
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
Pair<Long, Boolean> domainNetworkDetails = ApiDBUtils.getDomainNetworkDetails(network.getId());
if (domainNetworkDetails.first() != null) {
Domain domain = ApiDBUtils.findDomainById(domainNetworkDetails.first());
if (domain != null) {
response.setDomainId(domain.getUuid());
}
}
response.setSubdomainAccess(domainNetworkDetails.second());
}
Long dedicatedDomainId = ApiDBUtils.getDedicatedNetworkDomain(network.getId());
if (dedicatedDomainId != null) {
Domain domain = ApiDBUtils.findDomainById(dedicatedDomainId);
if (domain != null) {
response.setDomainId(domain.getUuid());
response.setDomainName(domain.getName());
}
}
response.setSpecifyIpRanges(network.getSpecifyIpRanges());
if (network.getVpcId() != null) {
Vpc vpc = ApiDBUtils.findVpcById(network.getVpcId());
if (vpc != null) {
response.setVpcId(vpc.getUuid());
}
}
response.setCanUseForDeploy(ApiDBUtils.canUseForDeploy(network));
// set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Network, network.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
response.setTags(tagResponses);
if (network.getNetworkACLId() != null) {
NetworkACL acl = ApiDBUtils.findByNetworkACLId(network.getNetworkACLId());
if (acl != null) {
response.setAclId(acl.getUuid());
}
}
response.setStrechedL2Subnet(network.isStrechedL2Network());
if (network.isStrechedL2Network()) {
Set<String> networkSpannedZones = new HashSet<String>();
List<VMInstanceVO> vmInstances = new ArrayList<VMInstanceVO>();
vmInstances.addAll(ApiDBUtils.listUserVMsByNetworkId(network.getId()));
vmInstances.addAll(ApiDBUtils.listDomainRoutersByNetworkId(network.getId()));
for (VirtualMachine vm : vmInstances) {
DataCenter vmZone = ApiDBUtils.findZoneById(vm.getDataCenterId());
networkSpannedZones.add(vmZone.getUuid());
}
response.setNetworkSpannedZones(networkSpannedZones);
}
response.setObjectName("network");
return response;
}
Aggregations