Skip to content

Commit

Permalink
Merge pull request #50 from tzumainn/node-properties
Browse files Browse the repository at this point in the history
Add node properties/resource class to lease/offer/node results
  • Loading branch information
tzumainn authored Mar 21, 2024
2 parents 6bab2e6 + b8cc0ec commit 3b3d208
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 74 deletions.
11 changes: 8 additions & 3 deletions esileapclient/osc/v1/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,16 @@ def take_action(self, parsed_args):
data = client.lease.list(filters)

if parsed_args.long:
columns = LEASE_RESOURCE.detailed_fields.keys()
labels = LEASE_RESOURCE.detailed_fields.values()
columns = LEASE_RESOURCE.long_fields.keys()
labels = LEASE_RESOURCE.long_fields.values()
else:
columns = LEASE_RESOURCE.fields.keys()
labels = LEASE_RESOURCE.fields.values()

return (labels,
(oscutils.get_item_properties(s, columns) for s in data))
(oscutils.get_item_properties(s, columns, formatters={
'resource_properties': oscutils.format_dict
}) for s in data))


class ShowLease(command.ShowOne):
Expand All @@ -211,6 +213,9 @@ def take_action(self, parsed_args):
client = self.app.client_manager.lease

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

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

Expand Down
4 changes: 3 additions & 1 deletion esileapclient/osc/v1/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ def take_action(self, parsed_args):
labels = NODE_RESOURCE.fields.values()

return (labels,
(oscutils.get_item_properties(s, columns) for s in data))
(oscutils.get_item_properties(s, columns, formatters={
'properties': oscutils.format_dict
}) for s in data))
11 changes: 8 additions & 3 deletions esileapclient/osc/v1/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,16 @@ def take_action(self, parsed_args):
data = client.offer.list(filters)

if parsed_args.long:
columns = OFFER_RESOURCE.detailed_fields.keys()
labels = OFFER_RESOURCE.detailed_fields.values()
columns = OFFER_RESOURCE.long_fields.keys()
labels = OFFER_RESOURCE.long_fields.values()
else:
columns = OFFER_RESOURCE.fields.keys()
labels = OFFER_RESOURCE.fields.values()

return (labels,
(oscutils.get_item_properties(s, columns) for s in data))
(oscutils.get_item_properties(s, columns, formatters={
'resource_properties': oscutils.format_dict
}) for s in data))


class ShowOffer(command.ShowOne):
Expand All @@ -206,6 +208,9 @@ 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(
resource_properties)

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

Expand Down
4 changes: 2 additions & 2 deletions esileapclient/tests/functional/utils/output_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def kwargs_to_flags(valid_flags, arguments):
if val is not None:
if flag in valid_flags:
tmp = ' --%s' % flag.replace('_', '-')
if type(val) == str:
if isinstance(val, str):
flag_string += '%s "%s"' % (tmp, val)
elif type(val) == bool:
elif isinstance(val, bool):
flag_string += tmp if val else ''
else:
raise TypeError('Invalid value for flag %s, expected \
Expand Down
8 changes: 7 additions & 1 deletion esileapclient/tests/unit/osc/v1/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
event_type = 'fake.event'
event_time = "3000-07-01T12"
object_type = 'lease'
node_properties = {'cpu': '40', 'traits': ['trait1', 'trait2']}
formatted_node_properties = "cpu='40', traits='['trait1', 'trait2']'"

OFFER = {
'availabilities': json.loads(lease_availabilities),
Expand All @@ -55,6 +57,7 @@
'project_id': lease_project_id,
'properties': json.loads(lease_properties),
'resource': lease_resource,
'resource_properties': node_properties,
'resource_type': lease_resource_type,
'resource_uuid': lease_resource_uuid,
'resource_class': lease_resource_class,
Expand All @@ -76,6 +79,7 @@
'owner_id': lease_owner_id,
'properties': json.loads(lease_properties),
'resource': lease_resource,
'resource_properties': node_properties,
'resource_type': lease_resource_type,
'resource_uuid': lease_resource_uuid,
'resource_class': lease_resource_class,
Expand All @@ -88,7 +92,9 @@
NODE = {
'name': node_name,
'uuid': node_uuid,
'owner': node_owner
'owner': node_owner,
'resource_class': lease_resource_class,
'properties': node_properties,
}

EVENT = {
Expand Down
56 changes: 24 additions & 32 deletions esileapclient/tests/unit/osc/v1/test_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,48 +169,38 @@ def test_lease_list_long(self):
self.client_mock.lease.list.assert_called_with(filters)

long_collist = [
"End Time",
"Expire Time",
"Fulfill Time",
"Name",
"Offer UUID",
"Owner",
"Owner ID",
"Parent Lease UUID",
"Project",
"Project ID",
"Properties",
"Resource",
"Resource Class",
"Resource Type",
"Resource UUID",
"Start Time",
"Status",
"UUID",
"Purpose",
'UUID',
'Resource',
'Resource Class',
'Resource Properties',
'Project',
'Start Time',
'End Time',
'Expire Time',
'Fulfill Time',
'Offer UUID',
'Owner',
'Parent Lease UUID',
'Status',
'Purpose'
]

self.assertEqual(long_collist, list(columns))

datalist = ((fakes.lease_end_time,
datalist = ((fakes.lease_uuid,
fakes.lease_resource,
fakes.lease_resource_class,
fakes.formatted_node_properties,
fakes.lease_project,
fakes.lease_start_time,
fakes.lease_end_time,
fakes.lease_expire_time,
fakes.lease_fulfill_time,
fakes.lease_name,
fakes.offer_uuid,
fakes.lease_owner,
fakes.lease_owner_id,
fakes.parent_lease_uuid,
fakes.lease_project,
fakes.lease_project_id,
json.loads(fakes.lease_properties),
fakes.lease_resource,
fakes.lease_resource_class,
fakes.lease_resource_type,
fakes.lease_resource_uuid,
fakes.lease_start_time,
fakes.lease_status,
fakes.lease_uuid,
fakes.lease_purpose
fakes.lease_purpose,
),)
self.assertEqual(datalist, tuple(data))

Expand Down Expand Up @@ -249,6 +239,7 @@ def test_lease_show(self):
"purpose",
"resource",
"resource_class",
"resource_properties",
"resource_type",
"resource_uuid",
"start_time",
Expand All @@ -272,6 +263,7 @@ def test_lease_show(self):
fakes.lease_purpose,
fakes.lease_resource,
fakes.lease_resource_class,
fakes.formatted_node_properties,
fakes.lease_resource_type,
fakes.lease_resource_uuid,
fakes.lease_start_time,
Expand Down
24 changes: 22 additions & 2 deletions esileapclient/tests/unit/osc/v1/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_node_list(self):
"Name",
"Owner",
"Lessee",
"Resource Class",
"Provision State",
"Maintenance",
"Offer UUID",
Expand All @@ -50,7 +51,8 @@ def test_node_list(self):

datalist = ((fakes.node_name,
fakes.node_owner,
'', '', '', '', ''
'', fakes.lease_resource_class,
'', '', '', ''
),)
self.assertEqual(datalist, tuple(data))

Expand Down Expand Up @@ -78,12 +80,30 @@ def test_node_list_long(self):
"Future Offers",
"Future Leases"
]
long_collist = [
'UUID',
'Name',
'Owner',
'Lessee',
'Resource Class',
'Provision State',
'Maintenance',
'Properties',
'Offer UUID',
'Lease UUID',
'Future Offers',
'Future Leases'
]

self.assertEqual(long_collist, list(columns))

datalist = ((fakes.node_uuid,
fakes.node_name,
fakes.node_owner,
'', '', '', '', '', '', ''
'',
fakes.lease_resource_class,
'', '',
fakes.formatted_node_properties,
'', '', '', ''
),)
self.assertEqual(datalist, tuple(data))
48 changes: 20 additions & 28 deletions esileapclient/tests/unit/osc/v1/test_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,42 +163,32 @@ def test_offer_list_long(self):
self.client_mock.offer.list.assert_called_with(filters)

long_collist = [
"Availabilities",
"End Time",
"Lessee",
"Lessee ID",
"Name",
"Parent Lease UUID",
"Project",
"Project ID",
"Properties",
"Resource",
"Resource Class",
"Resource Type",
"Resource UUID",
"Start Time",
"Status",
"UUID"
'UUID',
'Resource',
'Resource Class',
'Resource Properties',
'Lessee',
'Start Time',
'End Time',
'Status',
'Availabilities',
'Project',
'Parent Lease UUID'
]

self.assertEqual(long_collist, list(columns))

datalist = ((json.loads(fakes.lease_availabilities),
fakes.lease_end_time,
fakes.offer_lessee,
fakes.offer_lessee_id,
fakes.offer_name,
fakes.parent_lease_uuid,
fakes.lease_project,
fakes.lease_project_id,
json.loads(fakes.lease_properties),
datalist = ((fakes.offer_uuid,
fakes.lease_resource,
fakes.lease_resource_class,
fakes.lease_resource_type,
fakes.lease_resource_uuid,
fakes.formatted_node_properties,
fakes.offer_lessee,
fakes.lease_start_time,
fakes.lease_end_time,
fakes.lease_status,
fakes.offer_uuid
json.loads(fakes.lease_availabilities),
fakes.lease_project,
fakes.parent_lease_uuid
),)
self.assertEqual(datalist, tuple(data))

Expand Down Expand Up @@ -234,6 +224,7 @@ def test_offer_show(self):
"properties",
"resource",
"resource_class",
"resource_properties",
"resource_type",
"resource_uuid",
"start_time",
Expand All @@ -254,6 +245,7 @@ def test_offer_show(self):
json.loads(fakes.lease_properties),
fakes.lease_resource,
fakes.lease_resource_class,
fakes.formatted_node_properties,
fakes.lease_resource_type,
fakes.lease_resource_uuid,
fakes.lease_start_time,
Expand Down
18 changes: 18 additions & 0 deletions esileapclient/v1/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Lease(base.Resource):
'properties': "Properties",
'resource': "Resource",
'resource_class': "Resource Class",
'resource_properties': "Resource Properties",
'resource_type': "Resource Type",
'resource_uuid': "Resource UUID",
'start_time': "Start Time",
Expand All @@ -42,6 +43,23 @@ class Lease(base.Resource):
'purpose': "Purpose",
}

long_fields = {
'uuid': "UUID",
'resource': "Resource",
'resource_class': "Resource Class",
'resource_properties': "Resource Properties",
'project': "Project",
'start_time': "Start Time",
'end_time': "End Time",
'expire_time': "Expire Time",
'fulfill_time': "Fulfill Time",
'offer_uuid': "Offer UUID",
'owner': "Owner",
'parent_lease_uuid': "Parent Lease UUID",
'status': "Status",
'purpose': "Purpose",
}

fields = {
'uuid': "UUID",
'resource': "Resource",
Expand Down
7 changes: 5 additions & 2 deletions esileapclient/v1/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ class Node(base.Resource):
'name': "Name",
'owner': "Owner",
'lessee': "Lessee",
'resource_class': "Resource Class",
'provision_state': "Provision State",
'maintenance': "Maintenance",
'properties': "Properties",
'offer_uuid': "Offer UUID",
'lease_uuid': "Lease UUID",
'future_offers': "Future Offers",
Expand All @@ -37,6 +39,7 @@ class Node(base.Resource):
'name': "Name",
'owner': "Owner",
'lessee': "Lessee",
'resource_class': "Resource Class",
'provision_state': "Provision State",
'maintenance': "Maintenance",
'offer_uuid': "Offer UUID",
Expand All @@ -45,8 +48,8 @@ class Node(base.Resource):

_creation_attributes = ['name', 'uuid', 'owner', 'offer_uuid',
'lessee', 'lease_uuid', 'future_offers',
'future_leases', 'provision_state',
'maintenace']
'future_leases', 'resource_class',
'provision_state', 'maintenance']

def __repr__(self):
return "<Node %s>" % self._info
Expand Down
Loading

0 comments on commit 3b3d208

Please sign in to comment.