Skip to content

Commit c5499d1

Browse files
committed
Merge branch 'release/1.2.0'
2 parents 687f661 + d95166d commit c5499d1

6 files changed

Lines changed: 882 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,29 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7-
#### [1.1.0](https://rdkcentral.com/rdkcentral/xts_core/compare/1.0.0...1.1.0)
7+
#### [1.2.0](https://github.com/rdkcentral/xts_core/compare/1.1.0...1.2.0)
88

9-
- gh6 - create xts allocator client [`#8`](https://rdkcentral.com/rdkcentral/xts_core/pull/8)
10-
- added functionality to send rest api requests for allocation, deallocation, search, and listing slots [`f3b8316`](https://rdkcentral.com/rdkcentral/xts_core/commit/f3b831652421017e47288d15379317aed0f7e1b7)
11-
- Update #6: Initial creation of xts server client [`c892524`](https://rdkcentral.com/rdkcentral/xts_core/commit/c89252466d2a78138e58cdc5514862535f955be9)
12-
- clean up allocate_slot() and get_command_choices() methods and add docstrings [`91d0429`](https://rdkcentral.com/rdkcentral/xts_core/commit/91d0429a45f3a5b2066bb80f479268221a4f6964)
9+
- GH12 - add / update / remove slots [`#16`](https://github.com/rdkcentral/xts_core/pull/16)
10+
- Release 1.1.0: master -> develop [`#15`](https://github.com/rdkcentral/xts_core/pull/15)
11+
- added functionality to send rest api requests for allocation, deallocation, search, and listing slots [`3b6a890`](https://github.com/rdkcentral/xts_core/commit/3b6a890c27c1c15eb3140138ffb39427c3961704)
12+
- clean up allocate_slot() and get_command_choices() methods and add docstrings [`0a1f9df`](https://github.com/rdkcentral/xts_core/commit/0a1f9dfba429b1d839fd52d4e470b9e75a521db7)
13+
- add methdods for add, update and remove slots [`09a0cee`](https://github.com/rdkcentral/xts_core/commit/09a0ceed910baf0db304ce93cc24d43b9be2c77c)
14+
15+
#### [1.1.0](https://github.com/rdkcentral/xts_core/compare/1.0.0...1.1.0)
16+
17+
> 13 February 2025
18+
19+
- Release 1.1.0: release -> master [`#14`](https://github.com/rdkcentral/xts_core/pull/14)
20+
- gh6 - create xts allocator client [`#8`](https://github.com/rdkcentral/xts_core/pull/8)
21+
- Bumped changelog [`5cd1a5a`](https://github.com/rdkcentral/xts_core/commit/5cd1a5aa84a891b710f91fd724f012eccb2a7e10)
22+
- Merge tag '1.0.0' into develop [`a65520a`](https://github.com/rdkcentral/xts_core/commit/a65520a890e8af910b03015c03187f4e4101be6e)
23+
- added functionality to send rest api requests for allocation, deallocation, search, and listing slots [`34c2e7c`](https://github.com/rdkcentral/xts_core/commit/34c2e7cd5af09a79a0b51d75fedf536ad3e2fabe)
1324

1425
#### 1.0.0
1526

16-
> 8 August 2024
27+
> 12 February 2025
1728
18-
- Fix #1: Fixes based on review comments [`#1`](https://rdkcentral.com/rdkcentral/xts_core/issues/1)
19-
- gh1 - Initial creation of xts script [`c8cb23c`](https://rdkcentral.com/rdkcentral/xts_core/commit/c8cb23cb3b40bb26a2b89cbb45f6116d3a2f6226)
20-
- Initial commit [`967162d`](https://rdkcentral.com/rdkcentral/xts_core/commit/967162d11398f87f42417e9b9e066f051bed3b5d)
21-
- Update #1: Updated README.md with information about xts [`287e630`](https://rdkcentral.com/rdkcentral/xts_core/commit/287e630f8b815e59262bbea20ce17ba3cc245f7f)
29+
- Fix #1: Fixes based on review comments [`#1`](https://github.com/rdkcentral/xts_core/issues/1)
30+
- gh1 - Initial creation of xts script [`b9658ea`](https://github.com/rdkcentral/xts_core/commit/b9658ea9e7bccd7b69456ccb1021533fef85ebf7)
31+
- Initial commit [`f001c2f`](https://github.com/rdkcentral/xts_core/commit/f001c2ffb745d07ea96e100a8cb267da1c016c8a)
32+
- Update #1: Updated README.md with information about xts [`d159145`](https://github.com/rdkcentral/xts_core/commit/d159145202aa4f06f369629ad028cf564b41a0d8)

src/plugins/xts_allocator_client.py

Lines changed: 149 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class XTSAllocatorClient():
3030
('deallocate', 'Free an allocated slot.'),
3131
('dealloc', 'Alias of deallocate'),
3232
('free', 'Alias of deallocate'),
33-
('search', 'Search available slots.'),
34-
('list', 'List all slots.')
3533
]
3634

3735
def __init__(self):
@@ -118,10 +116,6 @@ def run(self, args: list):
118116
self._allocator(remaining_args)
119117
elif parsed_args.command in ('deallocate', 'dealloc', 'free'):
120118
self._deallocate_slot(remaining_args)
121-
elif parsed_args.command == 'search':
122-
self._search_slots(remaining_args)
123-
elif parsed_args.command == 'list':
124-
self._list_slots(remaining_args)
125119
else:
126120
print(self._initial_help)
127121
raise SystemExit(0)
@@ -217,10 +211,14 @@ def _allocator(self, args: list):
217211
args (list): Command-line arguments.
218212
"""
219213
allocator_parser = self._subparsers.add_parser('allocator', add_help=False)
220-
allocator_choices = [('list', 'List all known allocators'),
214+
allocator_choices = [('search', 'Search for slots on an allocator server'),
215+
('list', 'List all known allocators'),
221216
('add', 'Add an allocator server'),
222-
('remove', 'Remove an allocator server')]
223-
217+
('remove', 'Remove an allocator server'),
218+
('add-slot', 'Add a slot to the allocator server'),
219+
('update-slot', 'Update an existing slot on the allocator server'),
220+
('remove-slot', 'Remove a slot from the allocator server')]
221+
224222
# extract only the command names for argparse choices
225223
allocator_commands = [cmd[0] for cmd in allocator_choices]
226224

@@ -241,8 +239,7 @@ def _allocator(self, args: list):
241239
allocator_parser.print_help()
242240
raise SystemExit(0)
243241

244-
245-
parsed_args = allocator_parser.parse_args(args)
242+
parsed_args, remaining_args = allocator_parser.parse_known_args(args)
246243
servers = self.load_servers()
247244

248245

@@ -270,6 +267,41 @@ def _allocator(self, args: list):
270267
else:
271268
rich.print("[yellow]No servers configured.[/yellow]")
272269

270+
elif parsed_args.command == 'search':
271+
if not parsed_args.server:
272+
rich.print("[red]Error: --server is required for search.[/red]")
273+
raise SystemExit(1)
274+
275+
search_filters = {}
276+
if parsed_args.platform:
277+
search_filters["platform"] = parsed_args.platform
278+
if parsed_args.description:
279+
search_filters["description"] = parsed_args.description
280+
if parsed_args.tags:
281+
search_filters["tags"] = parsed_args.tags
282+
283+
response = self.send_request("POST", f"{parsed_args.server}/list_slots", search_filters)
284+
285+
if response and "slots" in response:
286+
slots = response["slots"]
287+
if slots:
288+
rich.print("[blue]Matching slots:[/blue]")
289+
for slot in slots:
290+
rich.print(f" - {slot['rackName']} / {slot['slotName']} - {slot['description']} - Tags: {', '.join(slot['tags'])}")
291+
else:
292+
rich.print("[yellow]No matching slots found.[/yellow]")
293+
else:
294+
rich.print("[red]Error retrieving slots.[/red]")
295+
296+
elif parsed_args.command == 'add-slot':
297+
self._add_slot(parsed_args.server, remaining_args)
298+
299+
elif parsed_args.command == 'update-slot':
300+
self._update_slot(parsed_args.server, remaining_args)
301+
302+
elif parsed_args.command == 'remove-slot':
303+
self._remove_slot(parsed_args.server, remaining_args)
304+
273305

274306
def _deallocate_slot(self, args: list):
275307
"""
@@ -338,6 +370,112 @@ def _list_slots(self, args: list):
338370
response = self.send_request("GET", f"{parsed_args.server}/list")
339371
if response:
340372
rich.print(f"[green]Available slots: {response}[/green]")
373+
374+
def _add_slot(self, server, args: list):
375+
"""
376+
Add a new slot to the allocator server.
377+
378+
Args:
379+
args (list): Command-line arguments.
380+
"""
381+
add_slot_parser = self._subparsers.add_parser('add-slot')
382+
add_slot_parser.add_argument('--rackName', required=True, help='Rack name of the slot.')
383+
add_slot_parser.add_argument('--slotName', required=True, help='Slot name.')
384+
add_slot_parser.add_argument('--description', help='Description of the slot.')
385+
add_slot_parser.add_argument('--tags', nargs='+', help='Tags for the slot.')
386+
add_slot_parser.add_argument('--platform', required=True, help='Platform associated with the slot.')
387+
add_slot_parser.add_argument('--state', choices=['free', 'allocated'], default='free', help='State of the slot.')
388+
add_slot_parser.add_argument('--owner_email', help='Owner email (if allocated).')
389+
390+
parsed_args = add_slot_parser.parse_args(args)
391+
392+
if not server or not parsed_args.rackName or not parsed_args.slotName or not parsed_args.platform:
393+
rich.print("[red]Error: --server, --rackName, --slotName, and --platform are required for add-slot.[/red]")
394+
raise SystemExit(1)
395+
396+
payload = {
397+
"rackName": parsed_args.rackName,
398+
"slotName": parsed_args.slotName,
399+
"description": parsed_args.description or "",
400+
"tags": parsed_args.tags if parsed_args.tags else [],
401+
"platform": parsed_args.platform or "",
402+
"state": parsed_args.state,
403+
"owner_email": parsed_args.owner_email or None,
404+
}
405+
406+
response = self.send_request("POST", f"{parsed_args.server}/add_slot", payload)
407+
408+
if response:
409+
rich.print(f"[green]Slot added successfully: {response}[/green]")
410+
411+
def _update_slot(self, server, args: list):
412+
"""
413+
Update an existing slot in the allocator server.
414+
415+
Args:
416+
args (list): Command-line arguments.
417+
"""
418+
update_slot_parser = self._subparsers.add_parser('update-slot')
419+
update_slot_parser.add_argument('--slot_id', required=True, type=int, help='ID of the slot to update.')
420+
update_slot_parser.add_argument('--rackName', help='New rack name.')
421+
update_slot_parser.add_argument('--slotName', help='New slot name.')
422+
update_slot_parser.add_argument('--description', help='Updated description of the slot.')
423+
update_slot_parser.add_argument('--tags', nargs='+', help='Updated tags for the slot.')
424+
update_slot_parser.add_argument('--platform', help='Updated platform associated with the slot.')
425+
update_slot_parser.add_argument('--state', choices=['free', 'allocated'], help='Updated state of the slot.')
426+
update_slot_parser.add_argument('--owner_email', help='Updated owner email.')
427+
428+
parsed_args = update_slot_parser.parse_args(args)
429+
430+
if not server or not args.slot_id:
431+
rich.print("[red]Error: --server and --slot_id are required for update-slot.[/red]")
432+
raise SystemExit(1)
433+
434+
if not any([parsed_args.rackName, parsed_args.slotName, parsed_args.description, parsed_args.tags,
435+
parsed_args.platform, parsed_args.state, parsed_args.owner_email]):
436+
rich.print("[red]Error: At least one field must be provided for update.[/red]")
437+
sys.exit(1)
438+
439+
# Required fields
440+
payload = {
441+
"slot_id": parsed_args.slot_id,
442+
"server": parsed_args.server
443+
}
444+
445+
# Optional fields
446+
optional_fields = ["rackName", "slotName", "description", "tags", "platform", "state", "owner_email"]
447+
448+
for field in optional_fields:
449+
value = getattr(parsed_args, field)
450+
if value is not None:
451+
payload[field] = value
452+
453+
response = self.send_request("POST", f"{parsed_args.server}/update_slot", payload)
454+
455+
if response:
456+
rich.print(f"[green]Slot updated successfully: {response}[/green]")
457+
458+
def _remove_slot(self, server, args: list):
459+
"""
460+
Remove a slot from the allocator server.
461+
462+
Args:
463+
args (list): Command-line arguments.
464+
"""
465+
remove_slot_parser = self._subparsers.add_parser('remove-slot')
466+
remove_slot_parser.add_argument('--slot_id', required=True, type=int, help='ID of the slot to remove.')
467+
468+
parsed_args = remove_slot_parser.parse_args(args)
469+
470+
if not server or not parsed_args.slot_id:
471+
rich.print("[red]Error: --server and --slot_id are required for remove-slot.[/red]")
472+
raise SystemExit(1)
473+
474+
payload = {"slot_id": parsed_args.slot_id}
475+
response = self.send_request("POST", f"{parsed_args.server}/delete_slot", payload)
476+
477+
if response:
478+
rich.print(f"[green]Slot removed successfully: {response}[/green]")
341479

342480
if __name__ == '__main__':
343481
import sys

src/yaml_runner/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
#** *****************************************************************************
3+
# *
4+
# * If not stated otherwise in this file or this component's LICENSE file the
5+
# * following copyright and licenses apply:
6+
# *
7+
# * Copyright 2024 RDK Management
8+
# *
9+
# * Licensed under the Apache License, Version 2.0 (the "License");
10+
# * you may not use this file except in compliance with the License.
11+
# * You may obtain a copy of the License at
12+
# *
13+
# *
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
# *
16+
# * Unless required by applicable law or agreed to in writing, software
17+
# * distributed under the License is distributed on an "AS IS" BASIS,
18+
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# * See the License for the specific language governing permissions and
20+
# * limitations under the License.
21+
# *
22+
#* ******************************************************************************
23+
24+
from .yaml_runner import YamlRunner, add_choices_to_help

0 commit comments

Comments
 (0)