CloudVE/cloudbridge

Way to get all instances of the availability zones

neelesh-a opened this issue · 2 comments

Currently when registered as AWS provider, and getting the list of instances, I get only the instances of one availability zone.

If I am interested in getting the list of all instances of a particular region in all its availability zone. How to get them?
Example: I have 7 instances in ap-south-1a zone and 3 instances in ap-south-1b zone. Is there any way to retrieve all the 10 instances with a single provider, by providing the zones at configuration?

@neelesh-a Thanks for reporting this. Each instance of a cloudbridge providers is tied to a specific zone. This was a conscious design decision and the reasons are documented here. If you want to work across zones, the easiest way to do this is as follows:

(in pseudocode)

    all_instances = []
    provider = factory.createProvider(....)
    cloned_config = provider.config.copy()
    for zone in provider.compute.regions.current.zones:
        new_config = cloned_config.update({'aws_zone_name': zone.name})
        new_provider = factory.createProvider(new_config)
        all_instances.append(list(new_provider.compute.instances))
    print(all_instances)

However, there is a bit of a shortcoming here because we could make this much simpler if we had a method to easily get a new provider for a different zone, which I thought we had, but apparently don't. Something like:

(in pseudocode)

    all_instances = []
    for zone in provider.compute.regions.current.zones:
        new_provider = provider.clone(zone=zone)
        all_instances.append(list(new_provider.compute.instances))
    print(all_instances)

Will keep this issue open so this method can be added in a future release. @almahmoud