Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the client to use ESI SDK #52

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions esileapclient/common/http.py

This file was deleted.

33 changes: 13 additions & 20 deletions esileapclient/osc/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
# 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'

# 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',
'1': 'esi.connection.ESIConnection',
}

OS_LEASE_API_LATEST = True
Expand All @@ -40,22 +40,7 @@ def make_client(instance):

:param ClientManager instance: The ClientManager that owns the new client
"""

requested_api_version = instance._api_version[API_NAME]

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
)

return client
return connection.ESIConnection(config=instance._cli_options).lease


def build_option_parser(parser):
Expand All @@ -69,4 +54,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
3 changes: 1 addition & 2 deletions esileapclient/osc/v1/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ def take_action(self, parsed_args):
'resource_uuid': parsed_args.resource_uuid,
}

data = client.event.list(filters)
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))
22 changes: 11 additions & 11 deletions esileapclient/osc/v1/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def take_action(self, parsed_args):
if 'properties' in fields:
fields['properties'] = json.loads(fields['properties'])

lease = client.lease.create(**fields)
lease = client.create_lease(**fields)

data = dict([(f, getattr(lease, f, '')) for f in
LEASE_RESOURCE.fields])
Expand Down Expand Up @@ -114,11 +114,9 @@ def take_action(self, parsed_args):
fields = dict((k, v) for (k, v) in vars(parsed_args).items()
if k in field_list and v is not None)

lease = client.lease.update(parsed_args.uuid, **fields)

data = dict([(f, getattr(lease, f, '')) for f in
lease = client.update_lease(parsed_args.uuid, **fields)
data = dict([(f, lease.get(f, '')) for f in
LEASE_RESOURCE.fields])

return self.dict2columns(data)


Expand Down Expand Up @@ -213,7 +211,7 @@ def take_action(self, parsed_args):
'purpose': parsed_args.purpose
}

data = client.lease.list(filters)
data = list(client.leases(**filters))

if parsed_args.long:
columns = LEASE_RESOURCE.long_fields.keys()
Expand Down Expand Up @@ -245,13 +243,15 @@ def get_parser(self, prog_name):
def take_action(self, parsed_args):

client = self.app.client_manager.lease
lease = client.get_lease(parsed_args.uuid)

lease = client.lease.get(parsed_args.uuid)._info
resource_properties = lease['resource_properties']
lease['resource_properties'] = oscutils.format_dict(
lease_info = {k: getattr(lease, k, '') for k in
LEASE_RESOURCE.detailed_fields}
resource_properties = lease_info['resource_properties']
lease_info['resource_properties'] = oscutils.format_dict(
resource_properties)

return zip(*sorted(lease.items()))
return zip(*sorted(lease_info.items()))


class DeleteLease(command.Command):
Expand All @@ -271,5 +271,5 @@ def get_parser(self, prog_name):
def take_action(self, parsed_args):

client = self.app.client_manager.lease
client.lease.delete(parsed_args.uuid)
client.delete_lease(parsed_args.uuid)
print('Deleted lease %s' % parsed_args.uuid)
7 changes: 3 additions & 4 deletions esileapclient/osc/v1/mdc/mdc_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import openstack
from osc_lib.command import command
from osc_lib import utils as oscutils

from esileapclient.v1 import client as esileapclient
from esi import connection
from esileapclient.v1.lease import Lease as LEASE_RESOURCE

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -90,9 +89,9 @@ def take_action(self, parsed_args):
}

for c in cloud_regions:
client = esileapclient.Client(session=c.get_session())
client = connection.ESIConnection(config=c).lease

leases = client.lease.list(filters)
leases = list(client.leases(**filters))
for lease in leases:
lease.cloud = c.name
lease.region = c.config['region_name']
Expand Down
17 changes: 7 additions & 10 deletions esileapclient/osc/v1/mdc/mdc_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils as oscutils

from esileapclient.v1 import client as esileapclient
from esi import connection
from esileapclient.v1.lease import Lease as LEASE_RESOURCE
from esileapclient.v1.offer import Offer as OFFER_RESOURCE

Expand Down Expand Up @@ -104,9 +103,8 @@ def take_action(self, parsed_args):
}

for c in cloud_regions:
client = esileapclient.Client(session=c.get_session())

offers = client.offer.list(filters)
client = connection.ESIConnection(config=c).lease
offers = list(client.offers(**filters))
for offer in offers:
offer.cloud = c.name
offer.region = c.config['region_name']
Expand Down Expand Up @@ -179,8 +177,8 @@ def take_action(self, parsed_args):

available_offers = []
for c in cloud_regions:
client = esileapclient.Client(session=c.get_session())
offers = client.offer.list(filters)
client = connection.ESIConnection(config=c).lease
offers = list(client.offers(**filters))
for offer in offers:
offer.cloud_region = c
offer.cloud = c.name
Expand All @@ -194,10 +192,9 @@ def take_action(self, parsed_args):
offers_to_claim = random.sample(available_offers, node_count)
leases = []
for offer in offers_to_claim:
client = esileapclient.Client(
session=offer.cloud_region.get_session())
client = connection.ESIConnection(config=offer.cloud_region).lease
try:
lease = client.offer.claim(
lease = client.claim_offer(
offer.uuid,
**{'start_time': parsed_args.start_time,
'end_time': parsed_args.end_time})
Expand Down
2 changes: 1 addition & 1 deletion esileapclient/osc/v1/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def take_action(self, parsed_args):
filters = {
}

data = client.node.list(filters)
data = list(client.nodes(**filters))

if parsed_args.long:
columns = NODE_RESOURCE.detailed_fields.keys()
Expand Down
21 changes: 12 additions & 9 deletions esileapclient/osc/v1/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def take_action(self, parsed_args):
if 'properties' in fields:
fields['properties'] = json.loads(fields['properties'])

offer = client.offer.create(**fields)
offer = client.create_offer(**fields)

data = dict([(f, getattr(offer, f, '')) for f in
OFFER_RESOURCE.fields])
Expand Down Expand Up @@ -174,7 +174,7 @@ def take_action(self, parsed_args):
'resource_class': parsed_args.resource_class
}

data = client.offer.list(filters)
data = list(client.offers(**filters))

if parsed_args.long:
columns = OFFER_RESOURCE.long_fields.keys()
Expand Down Expand Up @@ -207,12 +207,15 @@ def take_action(self, parsed_args):

client = self.app.client_manager.lease

offer = client.offer.get(parsed_args.uuid)._info
resource_properties = offer['resource_properties']
offer['resource_properties'] = oscutils.format_dict(
offer = client.get_offer(parsed_args.uuid)

offer_info = {k: getattr(offer, k, '') for k in
OFFER_RESOURCE.detailed_fields}
resource_properties = offer_info['resource_properties']
offer_info['resource_properties'] = oscutils.format_dict(
resource_properties)

return zip(*sorted(offer.items()))
return zip(*sorted(offer_info.items()))


class DeleteOffer(command.Command):
Expand All @@ -232,7 +235,7 @@ def get_parser(self, prog_name):
def take_action(self, parsed_args):

client = self.app.client_manager.lease
client.offer.delete(parsed_args.uuid)
client.delete_offer(parsed_args.uuid)
print('Deleted offer %s' % parsed_args.uuid)


Expand Down Expand Up @@ -280,9 +283,9 @@ def take_action(self, parsed_args):
if 'properties' in fields:
fields['properties'] = json.loads(fields['properties'])

lease = client.offer.claim(parsed_args.offer_uuid, **fields)
lease = client.claim_offer(parsed_args.offer_uuid, **fields)

data = dict([(f, getattr(lease, f, '')) for f in
data = dict([(f, lease.get(f, '')) for f in
LEASE_RESOURCE.fields])

return self.dict2columns(data)
Loading
Loading