yaml file multiple groups throws openstack.exceptions.ConfigException Cloud not found

Bug #2049776 reported by Saeed Fazlollahzadeh
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
openstacksdk
New
Undecided
Unassigned

Bug Description

Today I faced an error but I'm not sure what to add in the original module's codes to fix.

This is my yaml file:
```
clouds:

  all:
    region1:
      auth:
        auth_url: http://openstack.me.com:5000
        application_credential_id: "test_creds"
        application_credential_secret: "test_cred_secret"
      regions:
      - RegionOne
      interface: "public"
      identity_api_version: 3
      auth_type: "v3applicationcredential"
    region2:
      auth:
        auth_url: http://openstack.me.com:5000
        application_credential_id: "test_creds"
        application_credential_secret: "test_cred_secret"
      regions:
      - RegionTwo
      interface: "public"
      identity_api_version: 3
      auth_type: "v3applicationcredential"
    region3:
      auth:
        auth_url: http://openstack.me.com:5000
        application_credential_id: "test_creds"
        application_credential_secret: "test_cred_secret"
      regions:
      - RegionThree
      interface: "public"
      identity_api_version: 3
      auth_type: "v3applicationcredential"

  regionA:
    region1:
      auth:
        auth_url: http://openstack.me.com:5000
        application_credential_id: "test_creds"
        application_credential_secret: "test_cred_secret"
      regions:
      - RegionOne
      interface: "public"
      identity_api_version: 3
      auth_type: "v3applicationcredential"

  regionB:
    region2:
      auth:
        auth_url: http://openstack.me.com:5000
        application_credential_id: "test_creds"
        application_credential_secret: "test_cred_secret"
      regions:
      - RegionTwo
      interface: "public"
      identity_api_version: 3
      auth_type: "v3applicationcredential"
    region3:
      auth:
        auth_url: http://openstack.me.com:5000
        application_credential_id: "test_creds"
        application_credential_secret: "test_cred_secret"
      regions:
      - RegionThree
      interface: "public"
      identity_api_version: 3
      auth_type: "v3applicationcredential"
```
This is my python code that I'm trying to iterate over `regionB`'s regions to check the server list:
```
import openstack
import yaml

with open('clouds.yaml', 'r') as f:
    reg = yaml.safe_load(f)

all_regions = []
for name in reg['clouds']['all']:
    all_regions.append(name)

regionA = []
for name in reg['clouds']['regionA']:
    iran_regions.append(name)

regionB = []
for name in reg['clouds']['regionB']:
    foreign_regions.append(name)

# Initialize and turn on debug logging
openstack.enable_logging(debug=False)

# Initialize connection
for region in all_regions:
    conn1 = openstack.connect(cloud=region) # tried this
    # conn2 = openstack.connect(cloud=f"['regionB']['{region}']") # and also tried this
    # List the servers
    for server in conn1.compute.servers():
    # for server in conn2.compute.servers():
        if server['name'] == 'some-name':
            result = server.to_dict()
            result
```
This is the error I get for `conn1`:
```
openstack.exceptions.ConfigException: Cloud region1 was not found.
```
And this is the error of `conn2`:
```
openstack.exceptions.ConfigException: Cloud ["regionB"]["region1"] was not found.
```
I checked [loader.py](https://github.com/openstack/openstacksdk/blob/master/openstack/config/loader.py) file and it seems it only checks if the order is like this in the `clouds.yaml`:
```
clouds:
 region1:
 region2:
 region3:
```
But I'm going to have some groups in a single file. I know I can have multiple file but I'm looking for a way to see if I can do what I'm looking for.

At this moment I'm not sure how to edit the files to achieve what I want, but if I found I'll update this PR.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.