-
Notifications
You must be signed in to change notification settings - Fork 0
add logic for slot config #44
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -76,7 +76,6 @@ 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 | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -199,6 +198,7 @@ def _setup_allocator_args(self): | |||||||||||||||||||||||||||||||||||||||
| add_slot_parser.add_argument('--rack-name', required=True, help='Rack name of the slot.', dest='rack_name') | ||||||||||||||||||||||||||||||||||||||||
| add_slot_parser.add_argument('--slot-name', required=True, help='Slot name.', dest='slot_name') | ||||||||||||||||||||||||||||||||||||||||
| add_slot_parser.add_argument('--state', choices=['free', 'allocated'], default='free', help='State of the slot.') | ||||||||||||||||||||||||||||||||||||||||
| add_slot_parser.add_argument('--config', required=False, help='path to a YAML or JSON slot config file.') | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # update-slot | ||||||||||||||||||||||||||||||||||||||||
| update_slot_parser= allocator_subparsers.add_parser('update-slot', | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -462,13 +462,31 @@ def _add_slot(self, | |||||||||||||||||||||||||||||||||||||||
| owner_email:str|None, | ||||||||||||||||||||||||||||||||||||||||
| state:str='', | ||||||||||||||||||||||||||||||||||||||||
| description:str='', | ||||||||||||||||||||||||||||||||||||||||
| tags:list[str]=[]): | ||||||||||||||||||||||||||||||||||||||||
| tags:list[str]=[], | ||||||||||||||||||||||||||||||||||||||||
| config: str|None=None): | ||||||||||||||||||||||||||||||||||||||||
| ''' | ||||||||||||||||||||||||||||||||||||||||
| Add a new slot to the allocator server. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||
| args (list): Command-line arguments. | ||||||||||||||||||||||||||||||||||||||||
| ''' | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| configuration = None | ||||||||||||||||||||||||||||||||||||||||
| if config: | ||||||||||||||||||||||||||||||||||||||||
| import json, yaml | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||
| if config.endswith(('.yaml', '.yml')): | ||||||||||||||||||||||||||||||||||||||||
| with open(config, 'r') as f: | ||||||||||||||||||||||||||||||||||||||||
| configuration = yaml.safe_load(f) | ||||||||||||||||||||||||||||||||||||||||
| elif config.endswith('.json'): | ||||||||||||||||||||||||||||||||||||||||
| with open(config, 'r') as f: | ||||||||||||||||||||||||||||||||||||||||
| configuration = json.load(f) | ||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||
| plugin_utils.warning(f"Unsupported config format for file: {config}") | ||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||
| plugin_utils.error(f"Failed to load configuration file: {e}") | ||||||||||||||||||||||||||||||||||||||||
| configuration = None | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| configuration = None |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider catching more specific exceptions instead of the broad Exception. For file operations, FileNotFoundError, PermissionError, and IOError are more appropriate. For parsing errors, yaml.YAMLError and json.JSONDecodeError should be caught separately to provide more specific error messages to the user.
| except Exception as e: | |
| plugin_utils.error(f"Failed to load configuration file: {e}") | |
| configuration = None | |
| except FileNotFoundError as e: | |
| plugin_utils.error(f"Configuration file not found: {e}") | |
| configuration = None | |
| except PermissionError as e: | |
| plugin_utils.error(f"Permission denied when accessing configuration file: {e}") | |
| configuration = None | |
| except IOError as e: | |
| plugin_utils.error(f"I/O error when accessing configuration file: {e}") | |
| configuration = None | |
| except yaml.YAMLError as e: | |
| plugin_utils.error(f"YAML parsing error in configuration file: {e}") | |
| configuration = None | |
| except json.JSONDecodeError as e: | |
| plugin_utils.error(f"JSON parsing error in configuration file: {e}") | |
| configuration = None |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected. Please remove the trailing spaces at the end of this line.
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider validating that the loaded configuration is a dictionary before adding it to the payload. Both yaml.safe_load() and json.load() can return various types (None, lists, strings, etc.) depending on the file content. If the configuration is not a dictionary, it could cause issues with the API endpoint.
| payload['configuration'] = configuration | |
| if isinstance(configuration, dict): | |
| payload['configuration'] = configuration | |
| else: | |
| plugin_utils.warning(f"Configuration loaded from {config} is not a dictionary and will be ignored.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring is outdated. It states "Args: args (list): Command-line arguments" but the function signature shows multiple specific parameters. Please update the docstring to document all parameters:
server,rack_name,slot_name,platform,owner_email,state,description,tags, and the newly addedconfig.