Search in sources :

Example 6 with PhysicalNetwork

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;
}
Also used : PrivateGatewayResponse(org.apache.cloudstack.api.response.PrivateGatewayResponse) DataCenter(com.cloud.dc.DataCenter) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Vpc(com.cloud.network.vpc.Vpc) NetworkACL(com.cloud.network.vpc.NetworkACL)

Example 7 with PhysicalNetwork

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;
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) TrafficTypeResponse(org.apache.cloudstack.api.response.TrafficTypeResponse)

Example 8 with PhysicalNetwork

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;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) DB(com.cloud.utils.db.DB)

Example 9 with PhysicalNetwork

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;
}
Also used : SignInCommand(com.globo.globodns.cloudstack.commands.SignInCommand) HashMap(java.util.HashMap) TransactionStatus(com.cloud.utils.db.TransactionStatus) Host(com.cloud.host.Host) GloboDnsResource(com.globo.globodns.cloudstack.resource.GloboDnsResource) Answer(com.cloud.agent.api.Answer) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Example 10 with PhysicalNetwork

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");
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) PhysicalNetworkResponse(org.apache.cloudstack.api.response.PhysicalNetworkResponse) PhysicalNetwork(com.cloud.network.PhysicalNetwork)

Aggregations

PhysicalNetwork (com.cloud.network.PhysicalNetwork)34 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)8 ArrayList (java.util.ArrayList)8 HostVO (com.cloud.host.HostVO)7 Network (com.cloud.network.Network)7 Host (com.cloud.host.Host)6 DB (com.cloud.utils.db.DB)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 TransactionStatus (com.cloud.utils.db.TransactionStatus)5 DataCenter (com.cloud.dc.DataCenter)4 ActionEvent (com.cloud.event.ActionEvent)4 NetworkVO (com.cloud.network.dao.NetworkVO)4 Account (com.cloud.user.Account)4 List (java.util.List)4 ConfigurationException (javax.naming.ConfigurationException)4 ServerApiException (com.cloud.api.ServerApiException)3 PhysicalNetworkResponse (com.cloud.api.response.PhysicalNetworkResponse)3 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)3 NetworkOffering (com.cloud.offering.NetworkOffering)3