Skip to content
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

207 adding creation of an instance with payg #208

Closed
wants to merge 29 commits into from

Conversation

Antonyjin
Copy link
Member

@Antonyjin Antonyjin commented May 22, 2024

  • Use of a constant instead of None to indicate the end of processing
  • Use a structrure type instead of a dictionary
  • Specify caught exceptions
  • Put the MachineUsage -> array list transformation into a function
  • Pass Structure to the queue and specify its type as an annotation
  • Run mypy and ruff and fix problems encountered
  • Move instance-related code to another file (refactor page in general)
  • Add unit tests + Learn more about TDD: Test-Driven Development
  • Add docstrings
  • Check presence of type annotations (mypy can help)
  • Change the hardcoded string about version

Antonyjin added 3 commits May 21, 2024 15:10
…om the CLI

The user don't have the possibility to create an instance using a CRN with PAYG
by passing by the CLI

Solution: Adding and ask if the user wants to create a PAYG instance.
For now, we only ask if the user wants to create a PAYG instance. If yes,
it shows a list of every compatible CRN. It takes some time, about 5 minutes
to fetch the data.

To do:
Show the available ressources.
Create the instance with PAYG
Modify the instance message
While fetching compatible nodes, there is only a loading bar with
a pourcentage. And then only at the end it displays the whole tab
with every CRN hashes

Solution: Display the tab within the fetch of nodes
That way user have a visibiity on the fetch process and it's more
visual
The hash given for the payg crn was not checked.

Solution: Adding an error handling to check if the hash given by
the user is a correct and compatible hash from the fetched list
@Antonyjin Antonyjin requested a review from nesitor May 22, 2024 13:22
@Antonyjin Antonyjin self-assigned this May 22, 2024
@Antonyjin Antonyjin linked an issue May 22, 2024 that may be closed by this pull request
Antonyjin added 3 commits May 24, 2024 15:09
Tab didn't show enough info about the CRN such as the console:
(RAM, HDD, Version ...)

Solution: Replace old info by these ones
Code did not checked if the payment was none in the case where it's not PAYG instance

Solution: Default setting payment as None to pass in the message if it's not PAYG
Getting information and dislaying a live tab took too long

Solution: Adding timeout and queue system for gain some time on
the execution.
@Antonyjin Antonyjin requested a review from hoh May 29, 2024 09:59
Copy link
Member

@hoh hoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice start.

I added comments to improve the structure of the code.

Can you add type annotations and check the output of mypy and ruff check on the new code ?

src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
@@ -178,6 +199,9 @@ def validate_ssh_pubkey_file(file: Union[str, Path]) -> Path:
async with AuthenticatedAlephHttpClient(
account=account, api_server=sdk_settings.API_HOST
) as client:
payment = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a typing annotation ?

src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
Antonyjin added 5 commits May 30, 2024 17:00
Originally the fetch of the version is about parsing an HTML text
which was not the best thing to do

Solution:  use the last server header in the response instead to get
the version of the CRN
I checked the request only with the status 200 which is not enough

Solution: Using raise_for_status()
Some varibles don't have types

Solution: Adding typing notation to them
Some of the request returned an error which wasn't checked
This result to the end of execution of the script

Solution: Adding a check about Exception and add
the possibility to debug inside the logger
To stop it, we add 'None' at the end of the queue. But this could
be more specific and clear in the code

Solution: Creating a local variable which clearly tells that it
is the end of the queuing process
src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
src/aleph_client/commands/utils.py Outdated Show resolved Hide resolved
Antonyjin and others added 13 commits June 4, 2024 18:17
Basically, we added a list of str inside the queue and then adding
them inside the Live tab but this is unclear and could cause some
misunderstanding from the users

Solution: Creating a structure and pass this inside the queue
The structure contains a field for MachineUsage and more for
the required string such as the name, version, address, etc ...
This permits to exactly know what is inside the queue and retrieve more
easily the different information about it
Solution: Checking every error raised by my py and fix them
Solution: Fix them one by one
This documentation inside the functions is needed to a better understanding of
how they works

Solution: Adding docstring to each function
If the fetch of the version wasn't found (Timeout, connectionError, etc ...)
There was a hardcoded string that replaced the version field. But this wasn't the best
option.

Solution: Return Optionnal[str] instead for being able to return a None value
Changed import paths to use explicit imports from specific modules
within aleph_message.models, fixing incorrect or missing import paths.

Solution: Specify the whole path for imports that wasn't well written
Changed import paths to use explicit imports from specific modules
within aleph_message.models, fixing incorrect or missing import paths.

Solution: Specify the whole path for imports that wasn't well written
Solution: Changed the way hypervisor is selected to ensure type safety and consistency with HypervisorType enum.
Previously, the hypervisor selection was done using Prompt.ask which returns a string.
Now, the selected string is used to fetch the corresponding HypervisorType from the HypervisorType enum dictionary.
This could be simplified by calling get_message() function

Solution: Instead of retrieving all messages and then selecting the program message
from the list, this commit refactors the `unpersist` function to directly fetch
the program message using the `get_message` method. This change simplifies the
logic by ensuring that only the relevant program message is retrieved and processed.
@hoh
Copy link
Member

hoh commented Jun 25, 2024

Replaced with #216

@hoh hoh closed this Jun 25, 2024
@Psycojoker Psycojoker deleted the 207-adding-creation-of-an-instance-with-payg branch July 24, 2024 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding creation of an instance with PAYG
2 participants