Skip to content

Commit

Permalink
Extend the client to use ESI SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNiESh committed Apr 30, 2024
1 parent 562f3a4 commit 457ac29
Show file tree
Hide file tree
Showing 23 changed files with 1,676 additions and 39 deletions.
46 changes: 29 additions & 17 deletions esileapclient/osc/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,25 @@
# License for the specific language governing permissions and limitations
# under the License.

from esi import connection
import logging

from osc_lib import utils
from openstackclient.i18n import _


DEFAULT_API_VERSION = '1'
DEFAULT_API_VERSION = '2'

# Required by the OSC plugin interface
API_NAME = 'lease'
API_VERSION_OPTION = 'os_lease_api_version'
API_VERSION_OPTION = 'os_esileap_api_version'
API_VERSIONS = {
'1': 'esileapclient.v1.client.Client',
'2': 'esi.connection.ESIConnection',
}

OS_LEASE_API_LATEST = True
LAST_KNOWN_API_VERSION = '1'
LATEST_VERSION = '1'
LAST_KNOWN_API_VERSION = '2'
LATEST_VERSION = '2'


LOG = logging.getLogger(__name__)
Expand All @@ -42,20 +44,22 @@ def make_client(instance):
"""

requested_api_version = instance._api_version[API_NAME]
if requested_api_version == '1':
plugin_client = utils.get_client_class(
API_NAME,
requested_api_version,
API_VERSIONS)

plugin_client = utils.get_client_class(
API_NAME,
requested_api_version,
API_VERSIONS)

client = plugin_client(
os_esileap_api_version=requested_api_version,
session=instance.session,
region_name=instance._region_name,
endpoint_override=None
)
client = plugin_client(
os_esileap_api_version=requested_api_version,
session=instance.session,
region_name=instance._region_name,
endpoint_override=None
)

return client
return client
elif requested_api_version == '2':
return connection.ESIConnection(config=instance._cli_options).lease


def build_option_parser(parser):
Expand All @@ -69,4 +73,12 @@ def build_option_parser(parser):
:param argparse.ArgumentParser parser: The parser object that has been
initialized by OpenStackShell.
"""
parser.add_argument(
'--os-esileap-api-version',
metavar='<os_esileap_api_version>',
default=DEFAULT_API_VERSION,
help=_('ESI-LEAP API version, default=%s')
% DEFAULT_API_VERSION,
)

return parser
Empty file.
80 changes: 80 additions & 0 deletions esileapclient/osc/v2/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import logging

from osc_lib.command import command
from osc_lib import utils as oscutils

from esileapclient.v1.event import Event as EVENT_RESOURCE

LOG = logging.getLogger(__name__)


class ListEvent(command.Lister):
"""List events."""

log = logging.getLogger(__name__ + ".ListEvent")

def get_parser(self, prog_name):
parser = super(ListEvent, self).get_parser(prog_name)

parser.add_argument(
'--project',
dest='project_id',
required=False,
help="Show all events associated with given project ID or name.")
parser.add_argument(
'--last-event-id',
dest='last_event_id',
required=False,
help="Show events after this event ID.")
parser.add_argument(
'--last-notification-time',
dest='last_event_time',
required=False,
help="Show events after this notification time.")
parser.add_argument(
'--event-type',
dest='event_type',
required=False,
help="Show events matching this event type.")
parser.add_argument(
'--resource-type',
dest='resource_type',
required=False,
help="Show events matching this resource type.")
parser.add_argument(
'--resource-uuid',
dest='resource_uuid',
required=False,
help="Show events matching this resource ID or name.")

return parser

def take_action(self, parsed_args):
client = self.app.client_manager.lease

filters = {
'lessee_or_owner_id': parsed_args.project_id,
'last_event_id': parsed_args.last_event_id,
'last_event_time': parsed_args.last_event_time,
'event_type': parsed_args.event_type,
'resource_type': parsed_args.resource_type,
'resource_uuid': parsed_args.resource_uuid,
}

data = list(client.events(**filters))
columns = EVENT_RESOURCE.fields.keys()
labels = EVENT_RESOURCE.fields.values()
return (labels,
(oscutils.get_item_properties(s, columns) for s in data))
Loading

0 comments on commit 457ac29

Please sign in to comment.