diff --git a/src/xts_core/plugins/xts_allocator_client.py b/src/xts_core/plugins/xts_allocator_client.py index ed7f277..2234048 100755 --- a/src/xts_core/plugins/xts_allocator_client.py +++ b/src/xts_core/plugins/xts_allocator_client.py @@ -76,6 +76,7 @@ def _send_request(method, url, data=None) -> dict: except requests.exceptions.RequestException as e: plugin_utils.error(f'Error during request: {e}') + @staticmethod def _format_slots_list_to_table(response:list[dict]) -> Table: '''Format the list of slot dictionaries into a rich table @@ -89,15 +90,16 @@ def _format_slots_list_to_table(response:list[dict]) -> Table: ''' table_headers = map(lambda x: x.capitalize(),response[0].keys()) resp_table = Table(*table_headers) + for entry in response: row_values = [] for value in entry.values(): if isinstance(value, list): - row_values.append(', '.join(value)) + row_values.append(', '.join(map(str, value))) elif isinstance(value, dict): row_values.append(str(value)) else: - row_values.append(value) + row_values.append(str(value) if value is not None else "") resp_table.add_row(*row_values) return resp_table @@ -146,6 +148,11 @@ def _setup_allocate_args(self): dest='server', required=True, help='Allocator server address.') + allocate_parser.add_argument( + '--user-email', + dest='user_email', + required=False, + help='Email of the user performing the allocation') def _setup_allocator_args(self): '''Setup the subparsers for the allocator command. @@ -262,8 +269,8 @@ def _allocate_slot(self, server: str, id: int = None, platform: str = None, - tags: list = None - ): + tags: list = None, + user_email: str = None): ''' Allocate a test slot and retrieve its rack configuration. @@ -275,17 +282,28 @@ def _allocate_slot(self, ''' if tags and not platform: plugin_utils.error('[default]--tags[/default] can only be used if [default]--platform[/default] is specified.') + slot_payload = {} if id: #ignore --platform and --tags - payload = {'id': id} + slot_payload['id'] = id plugin_utils.warning('Ignoring [default]--platform[/default] and [default]--tags[/default] because [default]--id[/default] was provided.') else: #use --platform (required for allocation) if not platform: plugin_utils.error('[default]--platform[/default] is required when [default]--id[/default] is not provided.') - payload = {'platform': platform, 'tags': tags} + slot_payload['platform'] = platform + + if tags: + slot_payload['tags'] = tags + + user_email = user_email or os.getenv("USER_EMAIL", "default@xts.local") + + payload = { + "user": {"email": user_email}, + "slot": slot_payload + } - response = self._send_request('POST', f'{server}/allocate', payload) + response = self._send_request('POST', f'{server}/allocate_slot', payload) if response and 'slot_id' in response: allocated_slot_id = response['slot_id']