Skip to content

Commit

Permalink
Make "esi mdc baremetal node list" work
Browse files Browse the repository at this point in the history
OpenStackConfig.get_all() will fail with a keystone exception if there are
any OS_* variables set in the environment [1]. This is easy to trigger if,
for example, you have set OS_BAREMETAL_API_VERSION in your environment to
work around [2].

We can avoid the problem by removing the call to get_all(), and
instead initializing the list of clouds using get_cloud_names().

This commit makes a number of additional changes to
esiclient/v1/mdc/mdc_node_baremetal.py:

- Several attribute names appear to have changed since this code was
  written (node.uuid is now node.id; node.instance_uuid is now
  node.instance_id).

- Replace single-letter variable names with more meaningful names.

- Add the '--ignore-invalid' command, which allows the command to continue
  in the event that it cannot successfully connect to one or more clouds.

[1]: https://bugs.launchpad.net/openstacksdk/+bug/2096621
[2]: CCI-MOC/esi#669
  • Loading branch information
larsks committed Jan 24, 2025
1 parent 75d6644 commit dac3cbf
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions esiclient/v1/mdc/mdc_node_baremetal.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ class MDCBaremetalNodeList(command.Lister):
auth_required = False

def get_parser(self, prog_name):
parser = super(MDCBaremetalNodeList, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument("--ignore-invalid", "-i", action="store_true")
parser.add_argument(
"--clouds",
dest="clouds",
"clouds",
metavar="<clouds>",
nargs="+",
nargs="*",
help=_("Specify the cloud to use from clouds.yaml."),
default=openstack.config.OpenStackConfig().get_cloud_names(),
)

return parser

def take_action(self, parsed_args):
columns = [
"Cloud",
"Region",
"UUID",
"Name",
"Instance UUID",
Expand All @@ -48,27 +48,26 @@ def take_action(self, parsed_args):
]
data = []

cloud_regions = openstack.config.loader.OpenStackConfig().get_all_clouds()
if parsed_args.clouds:
cloud_regions = filter(
lambda c: c.name in parsed_args.clouds, cloud_regions
)
for c in cloud_regions:
nodes = openstack.connect(
cloud=c.name, region=c.config["region_name"]
).list_machines()
for n in nodes:
data.append(
for cloud in parsed_args.clouds:
try:
data.extend(
[
c.name,
c.config["region_name"],
n.uuid,
n.name,
n.instance_uuid,
n.power_state,
n.provision_state,
n.maintenance,
cloud,
node.id,
node.name,
node.instance_id,
node.power_state,
node.provision_state,
node.is_maintenance,
]
for node in openstack.connect(cloud=cloud).list_machines()
)
except Exception as err:
if parsed_args.ignore_invalid:
self.log.error(
"failed to retrieve information for cloud %s: %s", cloud, err
)
continue
raise

return columns, data

0 comments on commit dac3cbf

Please sign in to comment.