use of com.cloud.network.PhysicalNetwork in project cloudstack by apache.
the class ApiResponseHelper method createPrivateGatewayResponse.
@Override
public PrivateGatewayResponse createPrivateGatewayResponse(PrivateGateway result) {
PrivateGatewayResponse response = new PrivateGatewayResponse();
response.setId(result.getUuid());
response.setBroadcastUri(result.getBroadcastUri());
response.setGateway(result.getGateway());
response.setNetmask(result.getNetmask());
if (result.getVpcId() != null) {
Vpc vpc = ApiDBUtils.findVpcById(result.getVpcId());
response.setVpcId(vpc.getUuid());
}
DataCenter zone = ApiDBUtils.findZoneById(result.getZoneId());
if (zone != null) {
response.setZoneId(zone.getUuid());
response.setZoneName(zone.getName());
}
response.setAddress(result.getIp4Address());
PhysicalNetwork pnet = ApiDBUtils.findPhysicalNetworkById(result.getPhysicalNetworkId());
if (pnet != null) {
response.setPhysicalNetworkId(pnet.getUuid());
}
populateAccount(response, result.getAccountId());
populateDomain(response, result.getDomainId());
response.setState(result.getState().toString());
response.setSourceNat(result.getSourceNat());
NetworkACL acl = ApiDBUtils.findByNetworkACLId(result.getNetworkACLId());
if (acl != null) {
response.setAclId(acl.getUuid());
}
response.setObjectName("privategateway");
return response;
}
use of com.cloud.network.PhysicalNetwork in project cloudstack by apache.
the class ApiResponseHelper method createTrafficTypeResponse.
@Override
public TrafficTypeResponse createTrafficTypeResponse(PhysicalNetworkTrafficType result) {
TrafficTypeResponse response = new TrafficTypeResponse();
response.setId(result.getUuid());
PhysicalNetwork pnet = ApiDBUtils.findPhysicalNetworkById(result.getPhysicalNetworkId());
if (pnet != null) {
response.setPhysicalNetworkId(pnet.getUuid());
}
if (result.getTrafficType() != null) {
response.setTrafficType(result.getTrafficType().toString());
}
response.setXenLabel(result.getXenNetworkLabel());
response.setKvmLabel(result.getKvmNetworkLabel());
response.setVmwareLabel(result.getVmwareNetworkLabel());
response.setHypervLabel(result.getHypervNetworkLabel());
response.setOvm3Label(result.getOvm3NetworkLabel());
response.setObjectName("traffictype");
return response;
}
use of com.cloud.network.PhysicalNetwork in project cloudstack by apache.
the class VpcManagerImpl method createVpcGuestNetwork.
@DB
@Override
public Network createVpcGuestNetwork(final long ntwkOffId, final String name, final String displayText, final String gateway, final String cidr, final String vlanId, String networkDomain, final Account owner, final Long domainId, final PhysicalNetwork pNtwk, final long zoneId, final ACLType aclType, final Boolean subdomainAccess, final long vpcId, final Long aclId, final Account caller, final Boolean isDisplayNetworkEnabled) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
final Vpc vpc = getActiveVpc(vpcId);
if (vpc == null) {
final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find Enabled VPC ");
ex.addProxyObject(String.valueOf(vpcId), "VPC");
throw ex;
}
_accountMgr.checkAccess(caller, null, false, vpc);
if (networkDomain == null) {
networkDomain = vpc.getNetworkDomain();
}
if (!vpc.isRegionLevelVpc() && vpc.getZoneId() != zoneId) {
throw new InvalidParameterValueException("New network doesn't belong to vpc zone");
}
// 1) Validate if network can be created for VPC
validateNtwkOffForNtwkInVpc(null, ntwkOffId, cidr, networkDomain, vpc, gateway, owner, aclId);
// 2) Create network
final Network guestNetwork = _ntwkMgr.createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId, networkDomain, owner, domainId, pNtwk, zoneId, aclType, subdomainAccess, vpcId, null, null, isDisplayNetworkEnabled, null);
if (guestNetwork != null) {
guestNetwork.setNetworkACLId(aclId);
_ntwkDao.update(guestNetwork.getId(), (NetworkVO) guestNetwork);
}
return guestNetwork;
}
use of com.cloud.network.PhysicalNetwork in project cloudstack by apache.
the class GloboDnsElement method addGloboDnsHost.
@Override
@DB
public Host addGloboDnsHost(Long physicalNetworkId, final String username, final String password, String url) {
if (username == null || username.trim().isEmpty()) {
throw new InvalidParameterValueException("Invalid username: " + username);
}
if (password == null || password.trim().isEmpty()) {
throw new InvalidParameterValueException("Invalid password: " + password);
}
if (url == null || url.trim().isEmpty()) {
throw new InvalidParameterValueException("Invalid url: " + url);
}
// validate physical network and zone
// Check if physical network exists
PhysicalNetwork pNtwk = null;
if (physicalNetworkId != null) {
pNtwk = _physicalNetworkDao.findById(physicalNetworkId);
if (pNtwk == null) {
throw new InvalidParameterValueException("Unable to find a physical network having the specified physical network id");
}
} else {
throw new InvalidParameterValueException("Invalid physicalNetworkId: " + physicalNetworkId);
}
final Long zoneId = pNtwk.getDataCenterId();
final Map<String, String> params = new HashMap<String, String>();
params.put("guid", "globodns-" + String.valueOf(zoneId));
params.put("zoneId", String.valueOf(zoneId));
params.put("name", Provider.GloboDns.getName());
params.put("url", url);
params.put("username", username);
params.put("password", password);
final Map<String, Object> hostDetails = new HashMap<String, Object>();
hostDetails.putAll(params);
Host host = Transaction.execute(new TransactionCallbackWithException<Host, CloudRuntimeException>() {
@Override
public Host doInTransaction(TransactionStatus status) throws CloudRuntimeException {
try {
GloboDnsResource resource = new GloboDnsResource();
resource.configure(Provider.GloboDns.getName(), hostDetails);
Host host = _resourceMgr.addHost(zoneId, resource, resource.getType(), params);
if (host == null) {
throw new CloudRuntimeException("Failed to add GloboDNS host");
}
// Validate username and password by logging in
SignInCommand cmd = new SignInCommand(username, password);
Answer answer = callCommand(cmd, zoneId);
if (answer == null || !answer.getResult()) {
// Could not sign in on GloboDNS
throw new ConfigurationException("Could not sign in on GloboDNS. Please verify URL, username and password.");
}
return host;
} catch (ConfigurationException e) {
throw new CloudRuntimeException(e);
}
}
});
return host;
}
use of com.cloud.network.PhysicalNetwork in project cloudstack by apache.
the class CreatePhysicalNetworkCmd method execute.
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() {
CallContext.current().setEventDetails("Physical Network Id: " + getEntityId());
PhysicalNetwork result = _networkService.getCreatedPhysicalNetwork(getEntityId());
if (result != null) {
PhysicalNetworkResponse response = _responseGenerator.createPhysicalNetworkResponse(result);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create physical network");
}
}
Aggregations