python-sdbus / python-sdbus-networkmanager

python-sdbus binds for NetworkManager
GNU Lesser General Public License v2.1
30 stars 6 forks source link

Added async vpn example #58

Closed andrey-pr closed 1 year ago

igo95862 commented 1 year ago

Thank you for submitting pull request. Allow me to review it.

andrey-pr commented 1 year ago

How to allow?

andrey-pr commented 1 year ago

Resolved issues

andrey-pr commented 1 year ago

Pls review again

igo95862 commented 1 year ago

Pls review again

Could you do the args unpacking?

It would be asyncio.run(add_vpn_connection_async(**vars(args))). This allows for better typing as there will be explicit keywords instead of opaque args.

andrey-pr commented 1 year ago

It would be asyncio.run(add_vpn_connection_async(**vars(args))). This allows for better typing as there will be explicit keywords instead of opaque args.

Ok, but how to accept this kind of arguments in function?

igo95862 commented 1 year ago

Ok, but how to accept this kind of arguments in function?

Add the keyword arguments matching the args attributes.

For example, there is args.conn_id so the keyword argument would be conn_id: str.

The function would look like this:

async def add_vpn_connection_async(
   conn_id: str,
   dev: str,
   ...............
) -> str:

Instead of ............... are all the keywords that args has.

Probably better to use default=str(uuid4()) straight away so it the type can simple be str.

andrey-pr commented 1 year ago

Fixed

andrey-pr commented 1 year ago

I have one question about further library usage. How to connect existing connection?

igo95862 commented 1 year ago

I have one question about further library usage. How to connect existing connection?

Probably using NetworkManager.activate_connection.

andrey-pr commented 1 year ago

Probably using NetworkManager.activate_connection.

I can not understand how to create object of NetworkManagerInterfaceAsync. Can you show me some example how to do it?

igo95862 commented 1 year ago

Probably using NetworkManager.activate_connection.

I can not understand how to create object of NetworkManagerInterfaceAsync. Can you show me some example how to do it?

Just use the NetworkManager class. It inherits from NetworkManagerInterfaceAsync.

The difference is NetworkManager is an object that automatically proxies to /org/freedesktop/NetworkManager and NetworkManagerInterfaceAsync is an interface class that has all the methods and properties definitions.

So it would look something like this:

nm = NetworkManager()
nm.activate_connection(vpn_connection_path, "/", "/")
andrey-pr commented 1 year ago

It works. Thank you.

await nm.activate_connection(vpn_connection_path, "/", "/")