Skip to content

Commit

Permalink
Merge pull request #48 from skanthed/purpose-field
Browse files Browse the repository at this point in the history
Add purpose field to esi lease command
  • Loading branch information
tzumainn authored Jun 15, 2023
2 parents 238feb4 + a5cc3b7 commit 6ca2d8c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 11 deletions.
14 changes: 12 additions & 2 deletions esileapclient/osc/v1/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def get_parser(self, prog_name):
dest='start_time',
required=False,
help="Time when the resource will become usable.")
parser.add_argument(
'--purpose',
dest='purpose',
required=False,
help="Specify the purpose for leasing the node")
return parser

def take_action(self, parsed_args):
Expand Down Expand Up @@ -147,7 +152,11 @@ def get_parser(self, prog_name):
dest='resource_class',
required=False,
help="Show all leases with given resource-class.")

parser.add_argument(
'--purpose',
dest='purpose',
required=False,
help="Show the purpose of leasing the node")
return parser

def take_action(self, parsed_args):
Expand All @@ -166,7 +175,8 @@ def take_action(self, parsed_args):
'view': 'all' if parsed_args.all else None,
'resource_type': parsed_args.resource_type,
'resource_uuid': parsed_args.resource_uuid,
'resource_class': parsed_args.resource_class
'resource_class': parsed_args.resource_class,
'purpose': parsed_args.purpose
}

data = client.lease.list(filters)
Expand Down
7 changes: 6 additions & 1 deletion esileapclient/osc/v1/mdc/mdc_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ def get_parser(self, prog_name):
dest='resource_class',
required=False,
help="Show all leases with given resource-class.")

parser.add_argument(
'--purpose',
dest='purpose',
required=False,
help="Show all the leases with given purpose")
return parser

def take_action(self, parsed_args):
Expand All @@ -82,6 +86,7 @@ def take_action(self, parsed_args):
parsed_args.time_range else None,
'resource_type': parsed_args.resource_type,
'resource_class': parsed_args.resource_class,
'purpose': parsed_args.purpose,
}

for c in cloud_regions:
Expand Down
4 changes: 3 additions & 1 deletion esileapclient/tests/unit/osc/v1/fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
lease_fulfill_time = "2010"
lease_status = "fake_status"
lease_uuid = "9999999"
lease_purpose = "fake_purpose"
offer_uuid = "111111111"
offer_lessee = 'lease-project'
offer_lessee_id = "zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz"
Expand Down Expand Up @@ -76,7 +77,8 @@
'resource_class': lease_resource_class,
'start_time': lease_start_time,
'status': lease_status,
'uuid': lease_uuid
'uuid': lease_uuid,
'purpose': lease_purpose,
}

NODE = {
Expand Down
7 changes: 7 additions & 0 deletions esileapclient/tests/unit/osc/v1/mdc/test_mdc_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_mdc_lease_list(self, mock_clouds, mock_client):
parsed_args.time_range else None,
'resource_type': parsed_args.resource_type,
'resource_class': parsed_args.resource_class,
'purpose': parsed_args.purpose,
}

self.client_mock.lease.list.assert_called_with(filters)
Expand All @@ -82,6 +83,7 @@ def test_mdc_lease_list(self, mock_clouds, mock_client):
"End Time",
"Offer UUID",
"Status",
"Purpose",
]

self.assertEqual(collist, list(columns))
Expand All @@ -95,6 +97,7 @@ def test_mdc_lease_list(self, mock_clouds, mock_client):
fakes.lease_end_time,
fakes.offer_uuid,
fakes.lease_status,
fakes.lease_purpose,
),
('cloud2', 'regionTwo',
fakes.lease_uuid,
Expand All @@ -105,6 +108,7 @@ def test_mdc_lease_list(self, mock_clouds, mock_client):
fakes.lease_end_time,
fakes.offer_uuid,
fakes.lease_status,
fakes.lease_purpose,
))
self.assertEqual(datalist, tuple(data))

Expand All @@ -129,6 +133,7 @@ def test_mdc_lease_list_filter(self, mock_clouds, mock_client):
parsed_args.time_range else None,
'resource_type': parsed_args.resource_type,
'resource_class': parsed_args.resource_class,
'purpose': parsed_args.purpose,
}

self.client_mock.lease.list.assert_called_with(filters)
Expand All @@ -144,6 +149,7 @@ def test_mdc_lease_list_filter(self, mock_clouds, mock_client):
"End Time",
"Offer UUID",
"Status",
"Purpose",
]

self.assertEqual(collist, list(columns))
Expand All @@ -157,5 +163,6 @@ def test_mdc_lease_list_filter(self, mock_clouds, mock_client):
fakes.lease_end_time,
fakes.offer_uuid,
fakes.lease_status,
fakes.lease_purpose,
),)
self.assertEqual(datalist, tuple(data))
9 changes: 7 additions & 2 deletions esileapclient/tests/unit/osc/v1/mdc/test_mdc_offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def test_mdc_offer_claim(self, mock_clouds, mock_client):
"End Time",
"Offer UUID",
"Status",
"Purpose",
]

self.assertEqual(collist, list(columns))
Expand All @@ -247,7 +248,8 @@ def test_mdc_offer_claim(self, mock_clouds, mock_client):
fakes.lease_start_time,
fakes.lease_end_time,
fakes.offer_uuid,
fakes.lease_status
fakes.lease_status,
fakes.lease_purpose
)
cloud2_lease = ('cloud2', 'regionTwo',
fakes.lease_uuid,
Expand All @@ -257,7 +259,8 @@ def test_mdc_offer_claim(self, mock_clouds, mock_client):
fakes.lease_start_time,
fakes.lease_end_time,
fakes.offer_uuid,
fakes.lease_status
fakes.lease_status,
fakes.lease_purpose
)

parsed_data = tuple(data)
Expand Down Expand Up @@ -305,6 +308,7 @@ def test_mdc_offer_claim_filter(self, mock_clouds, mock_client):
"End Time",
"Offer UUID",
"Status",
"Purpose",
]

self.assertEqual(collist, list(columns))
Expand All @@ -318,6 +322,7 @@ def test_mdc_offer_claim_filter(self, mock_clouds, mock_client):
fakes.lease_end_time,
fakes.offer_uuid,
fakes.lease_status,
fakes.lease_purpose,
)

parsed_data = tuple(data)
Expand Down
19 changes: 15 additions & 4 deletions esileapclient/tests/unit/osc/v1/test_lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_lease_create(self):
'--properties', fakes.lease_properties,
'--resource-type', fakes.lease_resource_type,
'--start-time', fakes.lease_start_time,
'--purpose', fakes.lease_purpose,
]

verifylist = [
Expand All @@ -60,6 +61,7 @@ def test_lease_create(self):
('resource_type', fakes.lease_resource_type),
('resource_uuid', fakes.lease_resource_uuid),
('start_time', fakes.lease_start_time),
('purpose', fakes.lease_purpose),
]

parsed_args = self.check_parser(self.cmd, arglist, verifylist)
Expand All @@ -74,6 +76,7 @@ def test_lease_create(self):
'name': fakes.lease_name,
'properties': json.loads(fakes.lease_properties),
'start_time': fakes.lease_start_time,
'purpose': fakes.lease_purpose,
}

self.client_mock.lease.create.assert_called_once_with(**args)
Expand Down Expand Up @@ -108,7 +111,8 @@ def test_lease_list(self):
'view': 'all' if parsed_args.all else None,
'resource_type': parsed_args.resource_type,
'resource_uuid': parsed_args.resource_uuid,
'resource_class': parsed_args.resource_class
'resource_class': parsed_args.resource_class,
'purpose': parsed_args.purpose
}

self.client_mock.lease.list.assert_called_with(filters)
Expand All @@ -122,6 +126,7 @@ def test_lease_list(self):
"End Time",
"Offer UUID",
"Status",
"Purpose",
]

self.assertEqual(collist, list(columns))
Expand All @@ -133,7 +138,8 @@ def test_lease_list(self):
fakes.lease_start_time,
fakes.lease_end_time,
fakes.offer_uuid,
fakes.lease_status
fakes.lease_status,
fakes.lease_purpose
),)
self.assertEqual(datalist, tuple(data))

Expand All @@ -156,7 +162,8 @@ def test_lease_list_long(self):
'view': 'all' if parsed_args.all else None,
'resource_type': parsed_args.resource_type,
'resource_uuid': parsed_args.resource_uuid,
'resource_class': parsed_args.resource_class
'resource_class': parsed_args.resource_class,
'purpose': parsed_args.purpose
}

self.client_mock.lease.list.assert_called_with(filters)
Expand All @@ -180,6 +187,7 @@ def test_lease_list_long(self):
"Start Time",
"Status",
"UUID",
"Purpose",
]

self.assertEqual(long_collist, list(columns))
Expand All @@ -201,7 +209,8 @@ def test_lease_list_long(self):
fakes.lease_resource_uuid,
fakes.lease_start_time,
fakes.lease_status,
fakes.lease_uuid
fakes.lease_uuid,
fakes.lease_purpose
),)
self.assertEqual(datalist, tuple(data))

Expand Down Expand Up @@ -237,6 +246,7 @@ def test_lease_show(self):
"project",
"project_id",
"properties",
"purpose",
"resource",
"resource_class",
"resource_type",
Expand All @@ -259,6 +269,7 @@ def test_lease_show(self):
fakes.lease_project,
fakes.lease_project_id,
json.loads(fakes.lease_properties),
fakes.lease_purpose,
fakes.lease_resource,
fakes.lease_resource_class,
fakes.lease_resource_type,
Expand Down
4 changes: 3 additions & 1 deletion esileapclient/v1/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Lease(base.Resource):
'start_time': "Start Time",
'status': "Status",
'uuid': "UUID",
'purpose': "Purpose",
}

fields = {
Expand All @@ -50,11 +51,12 @@ class Lease(base.Resource):
'end_time': "End Time",
'offer_uuid': "Offer UUID",
'status': "Status",
'purpose': "Purpose",
}

_creation_attributes = ['start_time', 'end_time', 'status', 'name',
'properties', 'project_id', 'resource_type',
'resource_uuid']
'resource_uuid', 'purpose']

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

0 comments on commit 6ca2d8c

Please sign in to comment.