public boolean associateAddress( EC2AssociateAddress request ) {
try {
List<CloudStackIpAddress> cloudIps = getApi().listPublicIpAddresses(null, null, null, null, null, request.getPublicIp(), null, null, null);
if (cloudIps == null)
throw new EC2ServiceException(ServerError.InternalError, "Specified ipAddress doesn't exist");
CloudStackIpAddress cloudIp = cloudIps.get(0);
List<CloudStackUserVm> vmList = getApi().listVirtualMachines(null, null, true, null, null, null, null,
request.getInstanceId(), null, null, null, null, null, null, null, null, null);
if (vmList == null || vmList.size() == 0) {
throw new EC2ServiceException(ServerError.InternalError, "Specified instance-id doesn't exist");
}
CloudStackUserVm cloudVm = vmList.get(0);
CloudStackInfoResponse resp = getApi().enableStaticNat(cloudIp.getId(), cloudVm.getId());
if (resp != null) {
return resp.getSuccess();
}
} catch(Exception e) {
logger.error( "EC2 AssociateAddress - ", e);