use of com.cloud.network.IpAddress in project cloudstack by apache.
the class ApiResponseHelper method createRemoteAccessVpnResponse.
@Override
public RemoteAccessVpnResponse createRemoteAccessVpnResponse(RemoteAccessVpn vpn) {
RemoteAccessVpnResponse vpnResponse = new RemoteAccessVpnResponse();
IpAddress ip = ApiDBUtils.findIpAddressById(vpn.getServerAddressId());
if (ip != null) {
vpnResponse.setPublicIpId(ip.getUuid());
vpnResponse.setPublicIp(ip.getAddress().addr());
}
vpnResponse.setIpRange(vpn.getIpRange());
vpnResponse.setPresharedKey(vpn.getIpsecPresharedKey());
populateOwner(vpnResponse, vpn);
vpnResponse.setState(vpn.getState().toString());
vpnResponse.setId(vpn.getUuid());
vpnResponse.setForDisplay(vpn.isDisplay());
vpnResponse.setObjectName("remoteaccessvpn");
return vpnResponse;
}
use of com.cloud.network.IpAddress in project cloudstack by apache.
the class ApiResponseHelper method createLoadBalancerContainerReponse.
@Override
public ApplicationLoadBalancerResponse createLoadBalancerContainerReponse(ApplicationLoadBalancerRule lb, Map<Ip, UserVm> lbInstances) {
ApplicationLoadBalancerResponse lbResponse = new ApplicationLoadBalancerResponse();
lbResponse.setId(lb.getUuid());
lbResponse.setName(lb.getName());
lbResponse.setDescription(lb.getDescription());
lbResponse.setAlgorithm(lb.getAlgorithm());
lbResponse.setForDisplay(lb.isDisplay());
Network nw = ApiDBUtils.findNetworkById(lb.getNetworkId());
lbResponse.setNetworkId(nw.getUuid());
populateOwner(lbResponse, lb);
if (lb.getScheme() == Scheme.Internal) {
lbResponse.setSourceIp(lb.getSourceIp().addr());
//TODO - create the view for the load balancer rule to reflect the network uuid
Network network = ApiDBUtils.findNetworkById(lb.getNetworkId());
lbResponse.setSourceIpNetworkId(network.getUuid());
} else {
//for public, populate the ip information from the ip address
IpAddress publicIp = ApiDBUtils.findIpAddressById(lb.getSourceIpAddressId());
lbResponse.setSourceIp(publicIp.getAddress().addr());
Network ntwk = ApiDBUtils.findNetworkById(publicIp.getNetworkId());
lbResponse.setSourceIpNetworkId(ntwk.getUuid());
}
//set load balancer rules information (only one rule per load balancer in this release)
List<ApplicationLoadBalancerRuleResponse> ruleResponses = new ArrayList<ApplicationLoadBalancerRuleResponse>();
ApplicationLoadBalancerRuleResponse ruleResponse = new ApplicationLoadBalancerRuleResponse();
ruleResponse.setInstancePort(lb.getDefaultPortStart());
ruleResponse.setSourcePort(lb.getSourcePortStart());
FirewallRule.State stateToSet = lb.getState();
if (stateToSet.equals(FirewallRule.State.Revoke)) {
stateToSet = FirewallRule.State.Deleting;
}
ruleResponse.setState(stateToSet.toString());
ruleResponse.setObjectName("loadbalancerrule");
ruleResponses.add(ruleResponse);
lbResponse.setLbRules(ruleResponses);
//set Lb instances information
List<ApplicationLoadBalancerInstanceResponse> instanceResponses = new ArrayList<ApplicationLoadBalancerInstanceResponse>();
for (Map.Entry<Ip, UserVm> entry : lbInstances.entrySet()) {
Ip ip = entry.getKey();
UserVm vm = entry.getValue();
ApplicationLoadBalancerInstanceResponse instanceResponse = new ApplicationLoadBalancerInstanceResponse();
instanceResponse.setIpAddress(ip.addr());
instanceResponse.setId(vm.getUuid());
instanceResponse.setName(vm.getInstanceName());
instanceResponse.setObjectName("loadbalancerinstance");
instanceResponses.add(instanceResponse);
}
lbResponse.setLbInstances(instanceResponses);
//set tag information
List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.LoadBalancer, lb.getId());
List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
for (ResourceTag tag : tags) {
ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
}
lbResponse.setTags(tagResponses);
lbResponse.setObjectName("loadbalancer");
return lbResponse;
}
use of com.cloud.network.IpAddress in project cloudstack by apache.
the class ApiResponseHelper method createIpForwardingRuleResponse.
@Override
public IpForwardingRuleResponse createIpForwardingRuleResponse(StaticNatRule fwRule) {
IpForwardingRuleResponse response = new IpForwardingRuleResponse();
response.setId(fwRule.getUuid());
response.setProtocol(fwRule.getProtocol());
IpAddress ip = ApiDBUtils.findIpAddressById(fwRule.getSourceIpAddressId());
if (ip != null) {
response.setPublicIpAddressId(ip.getId());
response.setPublicIpAddress(ip.getAddress().addr());
if (fwRule.getDestIpAddress() != null) {
UserVm vm = ApiDBUtils.findUserVmById(ip.getAssociatedWithVmId());
if (vm != null) {
// vm might be destroyed
response.setVirtualMachineId(vm.getUuid());
response.setVirtualMachineName(vm.getHostName());
if (vm.getDisplayName() != null) {
response.setVirtualMachineDisplayName(vm.getDisplayName());
} else {
response.setVirtualMachineDisplayName(vm.getHostName());
}
}
}
}
FirewallRule.State state = fwRule.getState();
String stateToSet = state.toString();
if (state.equals(FirewallRule.State.Revoke)) {
stateToSet = "Deleting";
}
response.setStartPort(fwRule.getSourcePortStart());
response.setEndPort(fwRule.getSourcePortEnd());
response.setProtocol(fwRule.getProtocol());
response.setState(stateToSet);
response.setObjectName("ipforwardingrule");
return response;
}
use of com.cloud.network.IpAddress in project cloudstack by apache.
the class VpcManagerImpl method associateIPToVpc.
@DB
@Override
@ActionEvent(eventType = EventTypes.EVENT_NET_IP_ASSIGN, eventDescription = "associating Ip", async = true)
public IpAddress associateIPToVpc(final long ipId, final long vpcId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException {
final Account caller = CallContext.current().getCallingAccount();
Account owner = null;
final IpAddress ipToAssoc = _ntwkModel.getIp(ipId);
if (ipToAssoc != null) {
_accountMgr.checkAccess(caller, null, true, ipToAssoc);
owner = _accountMgr.getAccount(ipToAssoc.getAllocatedToAccountId());
} else {
s_logger.debug("Unable to find ip address by id: " + ipId);
return null;
}
final Vpc vpc = _vpcDao.findById(vpcId);
if (vpc == null) {
throw new InvalidParameterValueException("Invalid VPC id provided");
}
// check permissions
_accountMgr.checkAccess(caller, null, true, owner, vpc);
boolean isSourceNat = false;
if (getExistingSourceNatInVpc(owner.getId(), vpcId) == null) {
isSourceNat = true;
}
s_logger.debug("Associating ip " + ipToAssoc + " to vpc " + vpc);
final boolean isSourceNatFinal = isSourceNat;
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
final IPAddressVO ip = _ipAddressDao.findById(ipId);
// update ip address with networkId
ip.setVpcId(vpcId);
ip.setSourceNat(isSourceNatFinal);
_ipAddressDao.update(ipId, ip);
// mark ip as allocated
_ipAddrMgr.markPublicIpAsAllocated(ip);
}
});
s_logger.debug("Successfully assigned ip " + ipToAssoc + " to vpc " + vpc);
return _ipAddressDao.findById(ipId);
}
use of com.cloud.network.IpAddress in project cloudstack by apache.
the class ListPublicIpAddressesCmdByAdmin method execute.
@Override
public void execute() {
Pair<List<? extends IpAddress>, Integer> result = _mgr.searchForIPAddresses(this);
ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
for (IpAddress ipAddress : result.first()) {
IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Full, ipAddress);
ipResponse.setObjectName("publicipaddress");
ipAddrResponses.add(ipResponse);
}
response.setResponses(ipAddrResponses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
Aggregations