Skip to content

Commit

Permalink
Remove duplicate get_cloud_connection methods (#1114)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Berendt <[email protected]>
  • Loading branch information
berendt authored Nov 3, 2024
1 parent cd5f971 commit 70ea6c6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 33 deletions.
20 changes: 20 additions & 0 deletions osism/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# SPDX-License-Identifier: Apache-2.0

from functools import lru_cache
import keystoneauth1
import openstack


@lru_cache
def get_cloud_connection(profile="admin"):
try:
conn = openstack.connect(cloud=profile)
except keystoneauth1.exceptions.auth_plugins.MissingRequiredOptions:
pass

return conn


@lru_cache
def get_cloud_project(project_id):
conn = get_cloud_connection()
return conn.identity.get_project(project_id)
14 changes: 3 additions & 11 deletions osism/commands/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@
import time

from cliff.command import Command
import keystoneauth1
from loguru import logger
import openstack
from tabulate import tabulate
from prompt_toolkit import prompt


def get_cloud_connection():
try:
conn = openstack.connect(cloud="admin")
except keystoneauth1.exceptions.auth_plugins.MissingRequiredOptions:
pass

return conn
from osism.commands import get_cloud_connection, get_cloud_project


class ComputeEnable(Command):
Expand Down Expand Up @@ -303,8 +295,8 @@ def take_action(self, parsed_args):
if project and server.project_id == project:
result.append([server.id, server.name, server.status])
elif domain:
project = conn.identity.get_project(server.project_id)
if project.domain_id == domain:
server_project = get_cloud_project(server.project_id)
if server_project.domain_id == domain:
result.append([server.id, server.name, server.status])
else:
result.append([server.id, server.name, server.status])
Expand Down
11 changes: 1 addition & 10 deletions osism/commands/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@

from cliff.command import Command
import dateutil
import keystoneauth1
from loguru import logger
import openstack
from tabulate import tabulate
from prompt_toolkit import prompt


def get_cloud_connection():
try:
conn = openstack.connect(cloud="admin")
except keystoneauth1.exceptions.auth_plugins.MissingRequiredOptions:
pass

return conn
from osism.commands import get_cloud_connection


class ServerMigrate(Command):
Expand Down
13 changes: 1 addition & 12 deletions osism/commands/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,11 @@

from cliff.command import Command
import dateutil
import keystoneauth1
from loguru import logger
import openstack
import pytz
from tabulate import tabulate

# from prompt_toolkit import prompt


def get_cloud_connection():
try:
conn = openstack.connect(cloud="admin")
except keystoneauth1.exceptions.auth_plugins.MissingRequiredOptions:
pass

return conn
from osism.commands import get_cloud_connection


class VolumeList(Command):
Expand Down

0 comments on commit 70ea6c6

Please sign in to comment.