-
Notifications
You must be signed in to change notification settings - Fork 22
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
Listing available nodes #966
Open
nieznanysprawiciel
wants to merge
10
commits into
master
Choose a base branch
from
list-nodes-ids-names
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
53db8ea
Listing available nodes
nieznanysprawiciel 6221930
List only unique nodes
nieznanysprawiciel c21fc68
Default subnet
nieznanysprawiciel 668b018
Merge branch 'master' into list-nodes-ids-names
shadeofblue 3217e49
Merge branch 'master' into list-nodes-ids-names
nieznanysprawiciel d58a349
Merge branch 'master' into list-nodes-ids-names
nieznanysprawiciel 56e1ee2
Merge branch 'master' into list-nodes-ids-names
shadeofblue f3517e6
Merge branch 'master' into list-nodes-ids-names
shadeofblue 4c78f1e
Merge branch 'master' into list-nodes-ids-names
prekucki 63575ea
Merge branch 'master' into list-nodes-ids-names
nieznanysprawiciel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#!/usr/bin/env python3 | ||
import asyncio | ||
from asyncio import TimeoutError | ||
from datetime import datetime, timezone | ||
import json | ||
import sys | ||
import pathlib | ||
from typing import AsyncIterator, List | ||
|
||
from yapapi import props as yp | ||
from yapapi.log import enable_default_logger | ||
from yapapi.props.builder import DemandBuilder | ||
from yapapi.rest import Configuration, Market, Activity, Payment # noqa | ||
from yapapi.rest.market import OfferProposal | ||
from examples import utils | ||
|
||
examples_dir = pathlib.Path(__file__).resolve().parent.parent | ||
sys.path.append(str(examples_dir)) | ||
|
||
|
||
class NodeInfo(object): | ||
def __init__(self, offer: OfferProposal): | ||
self.node_id = offer.issuer | ||
self.node_name = offer.props["golem.node.id.name"] | ||
|
||
|
||
async def list_offers(conf: Configuration, subnet_tag: str) -> AsyncIterator[OfferProposal]: | ||
async with conf.market() as client: | ||
market_api = Market(client) | ||
dbuild = DemandBuilder() | ||
dbuild.add(yp.NodeInfo(name="Scanning Node", subnet_tag=subnet_tag)) | ||
dbuild.add(yp.Activity(expiration=datetime.now(timezone.utc))) | ||
|
||
async with market_api.subscribe(dbuild.properties, dbuild.constraints) as subscription: | ||
async for event in subscription.events(): | ||
yield event | ||
|
||
|
||
async def list_nodes(conf: Configuration, subnet_tag: str) -> AsyncIterator[List[NodeInfo]]: | ||
async for offer in list_offers(conf, subnet_tag): | ||
yield NodeInfo(offer) | ||
|
||
|
||
async def print_nodes(conf: Configuration, subnet_tag: str): | ||
async for node in list_nodes(conf, subnet_tag=subnet_tag): | ||
print(f"{node.node_id} {node.node_name}") | ||
|
||
|
||
def main(): | ||
parser = utils.build_parser("List Nodes") | ||
args = parser.parse_args() | ||
|
||
nieznanysprawiciel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
subnet = args.subnet_tag | ||
sys.stderr.write(f"Using subnet: {utils.TEXT_COLOR_YELLOW}{subnet}{utils.TEXT_COLOR_DEFAULT}\n") | ||
|
||
enable_default_logger() | ||
try: | ||
asyncio.get_event_loop().run_until_complete( | ||
asyncio.wait_for( | ||
print_nodes( | ||
Configuration(), | ||
subnet_tag=subnet, | ||
), | ||
timeout=4, | ||
nieznanysprawiciel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
) | ||
except TimeoutError: | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
krunch3r here from the community, nice work!
this won't run on my windows install... i observed that from the perspective of python, the examples module is searched from its parent directory. did you mean:
and to place it above line 15 or is this just extra code?♥️
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.
I'm not sure what you want to achieve. I just copied this part of code from
list-offers.py
example.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.
as is, this will emit:
ModuleNotFoundError: No module named 'examples'
on account of the import statementfrom examples
preceding the module search path modification.ironically i pulled a fix for this issue to list-offers.py some time ago and you must have been looking at another branch when you copied(, and in fact i see shade of blue has merged master into this branch to bring it up to date recently):
aa86ed3
i was originally suggesting here instead:
but i think the modification i made to list-offers.py (see link to commit hash above) is a little more clean/concise