On Sun, Nov 18, 2012 at 10:23 PM, Nirmal Fernando <nir
...@wso2.com> wrote:
> I am using JClouds 1.5.0 and here's how I've done the IP association.
> public String associateAddress(IaasProvider iaasInfo, NodeMetadata node) {
> ComputeServiceContext context =
> iaasInfo.getComputeService().getContext();
> @SuppressWarnings("unchecked")
> RestContext<NovaClient, NovaAsyncClient> restContext =
> context.unwrap(RestContext.class);
> NovaClient novaClient = restContext.getApi();
> String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
> FloatingIPClient floatingIp =
> novaClient.getFloatingIPExtensionForZone(region).get();
> String ip;
> try {
> ip = floatingIp.allocate().getIp();
> } catch (InsufficientResourcesException e) {
> ArrayList<FloatingIP> unassignedIps =
> Lists.newArrayList(Iterables.filter(floatingIp.listFloatingIPs(),
> new Predicate<FloatingIP>() {
> @Override
> public boolean apply(FloatingIP arg0) {
> return arg0.getFixedIp() == null;
> }
> }));
> // try to prevent multiple parallel launches from choosing the
> same
> // ip.
> Collections.shuffle(unassignedIps);
> ip = Iterables.getLast(unassignedIps).getIp();
> }
> // wait till the fixed IP address gets assigned - this is needed
> before we associate a public IP
> do{
> try {
> Thread.sleep(1000);
> } catch (InterruptedException ignore) {}
> }
> while(node.getPrivateAddresses() == null);
> floatingIp.addFloatingIPToServer(ip, node.getProviderId());
> NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of( ip)).build();
> log.info("Successfully associated an IP address "+ip+" for node with
> id: "+node.getId());
> return ip;
> }
> ===========
> Note that above 'wait' is needed or else, you'll encounter following issue.
> Caused by: org.jclouds.http.HttpResponseException: command: POST
> http://192.168.16.20:8774/v2/8cxxxxxxxxxxxx40a821exxxxxxxx/servers/01...
> HTTP/1.1 failed with response: HTTP/1.1 400 Bad Request; content:
> [{"badRequest": {"message": "No fixed ips associated to instance", "code":
> 400}}]
> at
> org.jclouds.openstack.nova.v2_0.handlers.NovaErrorHandler.handleError(NovaE rrorHandler.java:48)
> at
> org.jclouds.http.handlers.DelegatingErrorHandler.handleError(DelegatingErro rHandler.java:69)
> at
> org.jclouds.http.internal.BaseHttpCommandExecutorService$HttpResponseCallab le.shouldContinue(BaseHttpCommandExecutorService.java:197)
> at
> org.jclouds.http.internal.BaseHttpCommandExecutorService$HttpResponseCallab le.call(BaseHttpCommandExecutorService.java:167)
> at
> org.jclouds.http.internal.BaseHttpCommandExecutorService$HttpResponseCallab le.call(BaseHttpCommandExecutorService.java:135)
> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
> at java.util.concurrent.FutureTask.run(FutureTask.java:138)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.j ava:886)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java: 908)
> at java.lang.Thread.run(Thread.java:662)
> One suggestion : this floating API's Java doc needs a revisit.. Its wording
> is bit confusing. (My personal thought, just for your attention)
> Thanks everyone for all the tips!! :-)
> On Fri, Nov 9, 2012 at 7:49 PM, Everett Toews <everett.to...@rackspace.com>
> wrote:
>> To disable auto allocation of IPs you need to override the property.
>> Properties overrides = new Properties();
>> overrides.setProperty(NovaProperties.AUTO_ALLOCATE_FLOATING_IPS, "false");
>> ComputeServiceContext context = ContextBuilder.newBuilder(provider)
>> .credentials(identity, key)
>> .overrides(overrides)
>> .modules(modules)
>> .buildView(ComputeServiceContext.class);
>> compute = context.getComputeService();
>> nova = context.unwrap();
>> To learn how to use the FloatingIPApi first have a look at the Javadoc [1]
>> to see what you can do with the API.
>> Regards,
>> Everett
>> [1]
>> http://demobox.github.com/jclouds-maven-site-1.5.2/1.5.2/jclouds-mult...
>> From: Nirmal Fernando <nir...@wso2.com>
>> Reply-To: "jclouds@googlegroups.com" <jclouds@googlegroups.com>
>> Date: Friday, November 9, 2012 12:57 AM
>> To: "jclouds@googlegroups.com" <jclouds@googlegroups.com>
>> Subject: Re: Associating a public IP for an Openstack-nova instance
>> Hi Adrian,
>> On Fri, Nov 9, 2012 at 12:00 PM, Adrian Cole <adrian.f.c...@gmail.com>
>> wrote:
>>> You can set a property to enable auto up allocation. Check out below:
>> I want to get rid of auto allocation of IPs.
>>> https://github.com/jclouds/jclouds/blob/master/providers/hpcloud-comp...
>>> On Nov 9, 2012 1:36 AM, "Nirmal Fernando" <nir...@wso2.com> wrote:
>>>> Hi,
>>>> I want to do $subject.
>>>> I found following code does floating IP allocation.
>>>> novaClient.getFloatingIPExtensionForZone(region).get().allocate()
>> Is only this what I needed to do? or is there another API call to make
>> this IP associated with the node?
>>>> But does this means that this IP associated to the particular node that
>>>> is just started? It seems not. In that case, how can I associate the IP?
>>>> --
>>>> Thanks & regards,
>>>> Nirmal
>>>> Software Engineer- Platform Technologies Team, WSO2 Inc.
>>>> Mobile: +94715779733
>>>> Blog: http://nirmalfdo.blogspot.com/
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "jclouds" group.
>>>> To post to this group, send email to jclouds@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> jclouds+unsubscribe@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/jclouds?hl=en.
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "jclouds" group.
>>> To post to this group, send email to jclouds@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> jclouds+unsubscribe@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/jclouds?hl=en.
>> --
>> Thanks & regards,
>> Nirmal
>> Software Engineer- Platform Technologies Team, WSO2 Inc.
>> Mobile: +94715779733
>> Blog: http://nirmalfdo.blogspot.com/
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jclouds" group.
>> To post to this group, send email to jclouds@googlegroups.com.
>> To unsubscribe from this group, send email to
>> jclouds+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/jclouds?hl=en.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "jclouds" group.
>> To post to this group, send email to jclouds@googlegroups.com.
>> To unsubscribe from this group, send email to
>> jclouds+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/jclouds?hl=en.
> --
> Thanks & regards,
> Nirmal
> Software Engineer- Platform Technologies Team, WSO2 Inc.
> Mobile: +94715779733
> Blog: http://nirmalfdo.blogspot.com/
> --
> You received this message because you are subscribed to the Google Groups
> "jclouds" group.
> To post to this group, send email to jclouds@googlegroups.com.
> To unsubscribe from this group, send email to
> jclouds+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/jclouds?hl=en.