-
Notifications
You must be signed in to change notification settings - Fork 3
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
Make it possible to list all hosts of an aggregate #1116
base: main
Are you sure you want to change the base?
Conversation
osism/commands/compute.py
Outdated
|
||
else: | ||
for service in conn.compute.services(**{"binary": "nova-compute"}): | ||
print(service) | ||
result.append( | ||
[ | ||
service.id, |
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 loop in lines [140-146] prints each compute service and also appends its details to a list result
. This approach can be optimized. If the intent is only to display the services, appending to result
might be unnecessary unless it's used later which isn't evident from the snippet. Conversely, if the data is needed for further processing not shown here, consider collecting all data first and then printing it in one go to improve efficiency.
Recommendation:
- If
result
is not used later, remove the append operation. - If it is used, consider restructuring to collect all data first and then output it, reducing the number of print operations.
conn = get_cloud_connection() | ||
domain = parsed_args.domain | ||
project = parsed_args.project | ||
aggregate = parsed_args.aggregate | ||
|
||
result = [] | ||
if host: |
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 method take_action
uses all_projects=True
when retrieving servers, which could lead to unauthorized access to data across different projects if not properly handled or intended. This could be a significant security risk depending on the deployment environment.
Recommendation:
- Ensure that the use of
all_projects=True
is intentional and consider implementing additional checks or permissions to restrict access based on user roles or specific conditions.
conn = get_cloud_connection() | ||
domain = parsed_args.domain | ||
project = parsed_args.project | ||
aggregate = parsed_args.aggregate | ||
|
||
result = [] | ||
if host: |
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 take_action
method lacks validation for the host
parameter before it's used to filter servers. This could lead to errors or unexpected behavior if an invalid or null host
is provided.
Recommendation:
- Implement validation for the
host
parameter to ensure it is not null and possibly verify its format or existence in the system before proceeding with the operation.
conn = get_cloud_connection() | ||
domain = parsed_args.domain | ||
project = parsed_args.project | ||
aggregate = parsed_args.aggregate | ||
|
||
result = [] | ||
if host: |
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 current implementation in lines [116-122] does not handle potential exceptions that might arise from network issues or API errors when interacting with the cloud services. This could lead to unhandled exceptions and application crashes.
Recommendation:
- Implement exception handling around the cloud service interactions to manage errors gracefully and provide feedback to the user.
osism/commands/compute.py
Outdated
) | ||
|
||
else: | ||
hypervisors = conn.compute.hypervisors() | ||
for service in conn.compute.services(**{"binary": "nova-compute"}): | ||
result.append( | ||
[ |
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 loop in lines [139-145] could be optimized further by checking if the result
list is necessary for later use. If the list is only used for printing, this could be simplified by printing directly within the loop, thus avoiding the overhead of list operations.
Recommendation:
- If the
result
list is not used after printing, eliminate the list and print directly within the loop to reduce memory usage and improve performance.
type=str, | ||
help="Filter by domain ID", | ||
) | ||
parser.add_argument( | ||
"--aggregate", | ||
default=None, | ||
type=str, | ||
help="Filter by aggregate", | ||
) | ||
parser.add_argument( | ||
"host", | ||
nargs="?", |
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 method get_parser
in the ComputeList
class defines several command-line arguments for filtering compute resources. While the implementation is straightforward, it lacks explicit validation or sanitization of the input parameters such as project
, domain
, aggregate
, and host
. This could potentially lead to issues if malformed or unexpected inputs are provided.
Recommendation:
- Implement input validation and sanitization for the command-line arguments to ensure they meet expected formats and criteria before being used in further operations. This will enhance the security and robustness of the command handling.
osism/commands/compute.py
Outdated
) | ||
|
||
else: | ||
hypervisors = conn.compute.hypervisors() | ||
print(hypervisors) | ||
for service in conn.compute.services(**{"binary": "nova-compute"}): | ||
result.append( | ||
[ |
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 loop in lines [139-146] prints hypervisor details and appends them to a list result
. While a previous comment suggested optimizing this process, another aspect to consider is the potential for data inconsistency if the state of the hypervisors changes during the execution of this loop. This could lead to displaying outdated or incorrect information.
Recommendation:
- Consider fetching all relevant data into the list first and then iterating over it to print. This approach minimizes the time window in which data inconsistencies could occur, ensuring more accurate output.
conn = get_cloud_connection() | ||
domain = parsed_args.domain | ||
project = parsed_args.project | ||
aggregate = parsed_args.aggregate | ||
|
||
result = [] | ||
if host: |
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 filtering logic in lines [116-122] does not account for the possibility that both project
and domain
filters might be provided simultaneously. This could lead to unexpected behavior where servers are filtered by project
only if they match, ignoring the domain
condition unless project
is not specified. This is a logical flaw that could confuse users expecting both conditions to be applied.
Recommendation:
- Modify the filtering logic to ensure that both
project
anddomain
conditions are evaluated independently. This could involve restructuring the if-else chain to check each condition separately and combining the results appropriately.
osism/commands/compute.py
Outdated
) | ||
|
||
else: | ||
hypervisors = conn.compute.hypervisors() | ||
for hyypervisor in conn.compute.hypervisors(): | ||
print(hypervisor) | ||
|
||
for service in conn.compute.services(**{"binary": "nova-compute"}): | ||
result.append( | ||
[ |
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.
In lines [139-148], the loop iterates over hypervisors and compute services, appending their details to the result
list and printing them. However, the variable hyypervisor
in line 143 is misspelled, which would cause a runtime error since it does not match the variable hypervisor
used in the loop. This is a critical typo that will prevent the code from executing correctly.
Recommendation:
- Correct the typo in line 143 from
hyypervisor
tohypervisor
to ensure the loop can iterate over the hypervisors correctly and avoid runtime errors.
osism/commands/compute.py
Outdated
) | ||
|
||
else: | ||
hypervisors = conn.compute.hypervisors() | ||
for hypervisor in conn.compute.hypervisors(): | ||
print(hypervisor) | ||
|
||
for service in conn.compute.services(**{"binary": "nova-compute"}): | ||
result.append( | ||
[ |
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.
In the take_action
method of the ComputeList
class, the loop iterates over hypervisors and compute services, appending their details to the result
list and printing them. However, the loop calls conn.compute.hypervisors()
twice (lines 142 and 143), which is inefficient as it may result in making the same API call twice, consuming extra resources and potentially slowing down the execution.
Recommendation:
- Remove the duplicate call to
conn.compute.hypervisors()
in line 143 to optimize performance and reduce unnecessary API calls.
Signed-off-by: Christian Berendt <[email protected]>
conn = get_cloud_connection() | ||
domain = parsed_args.domain | ||
project = parsed_args.project | ||
aggregate = parsed_args.aggregate | ||
|
||
result = [] | ||
if host: |
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 take_action
method in lines [116-122] lacks comprehensive error handling for the operations involving cloud service interactions. Given the critical nature of these operations, any failure in the cloud API calls, such as network issues or service unavailability, could lead to unhandled exceptions and potentially crash the application.
Recommendation:
- Wrap the cloud service interactions within a try-except block to catch exceptions like
openstack.exceptions.HttpException
and handle them gracefully. Provide meaningful error messages to the user and ensure the application can continue running or exit cleanly.
) | ||
|
||
else: | ||
hypervisors = conn.compute.hypervisors() | ||
for hypervisor in conn.compute.hypervisors(details=True): | ||
print(hypervisor) | ||
|
||
for service in conn.compute.services(**{"binary": "nova-compute"}): | ||
result.append( | ||
[ |
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.
In lines [139-148], the method prints details of hypervisors and compute services. However, the loop in lines [143-145] that prints each hypervisor detail is inefficient as it makes a redundant API call to conn.compute.hypervisors(details=True)
inside the loop. This results in unnecessary network requests, reducing the performance of the method.
Recommendation:
- Fetch the list of hypervisors with details once before the loop starts and store it in a variable. Use this variable inside the loop to access hypervisor details. This change will reduce the number of API calls and improve the method's efficiency.
No description provided.