Title: How to do equivalent of nmcli connection up 'Wired connection 2'? · python-sdbus/python-sdbus-networkmanager · Discussion #70 · GitHub
Open Graph Title: How to do equivalent of nmcli connection up 'Wired connection 2'? · python-sdbus/python-sdbus-networkmanager · Discussion #70
X Title: How to do equivalent of nmcli connection up 'Wired connection 2'? · python-sdbus/python-sdbus-networkmanager · Discussion #70
Description: How to do equivalent of nmcli connection up 'Wired connection 2'?
Open Graph Description: Hi, I can set the IP etc on my interface and apply to the bus: from sdbus_async.networkmanager import NetworkManagerSettings, NetworkConnectionSettings # Ideally want to look up by device eth1 conn...
X Description: Hi, I can set the IP etc on my interface and apply to the bus: from sdbus_async.networkmanager import NetworkManagerSettings, NetworkConnectionSettings # Ideally want to look up by device eth1 conn...
Opengraph URL: https://github.com/python-sdbus/python-sdbus-networkmanager/discussions/70
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"How to do equivalent of nmcli connection up 'Wired connection 2'?","text":"Hi,
\nI can set the IP etc on my interface and apply to the bus:
\n from sdbus_async.networkmanager import NetworkManagerSettings, NetworkConnectionSettings\n\n# Ideally want to look up by device eth1\n connection_paths = await NetworkManagerSettings().get_connections_by_id(self.connection_id)\n if not connection_paths:\n raise Exception(f\"No connection found with id {self.connection_id}\")\n\n connection_manager = NetworkConnectionSettings(connection_paths[0])\n connection_profile = await connection_manager.get_profile()\n settings = connection_profile.to_settings_dict()\n \n return settings, connection_manager\n\nasync def _network_linux_apply(self):\n from sdbus_async.networkmanager.settings import ConnectionProfile\n settings, connection_manager = await self._network_linux_profile() \n ipv4 = settings['ipv4']\n ipv4['address-data'][0]['address'] = self.ap_ip\n ipv4['address-data'][0]['prefix'] = sum([bin(int(x)).count('1') for x in self.netmask.split('.')])\n ipv4['gateway'] = self.gateway\n ipv4['dns-data'][0] = self.dns \n new_connection_profile = ConnectionProfile.from_settings_dict(settings)\n await connection_manager.update(new_connection_profile.to_dbus())\n await connection_manager.save()\n\n
\nHowever to get the device to use the new IP, I have to issue nmcli connection up 'Wired connection 2'
\nHow can this command by sent via the python AP?
\nThanks in advance
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Thanks so much .. that did the job! You don't need to deactivate on the linux I'm using.
\nHere is the update code should anyone else need it:
\n async def _network_linux_apply(self):\n from sdbus_async.networkmanager.settings import ConnectionProfile\n settings, connection_manager = await self._network_linux_profile() \n ipv4 = settings['ipv4']\n ipv4['address-data'][0]['address'] = self.ap_ip\n ipv4['address-data'][0]['prefix'] = sum([bin(int(x)).count('1') for x in self.netmask.split('.')])\n ipv4['gateway'] = self.gateway\n ipv4['dns-data'][0] = self.dns \n new_connection_profile = ConnectionProfile.from_settings_dict(settings)\n await connection_manager.update(new_connection_profile.to_dbus())\n\n from sdbus_async.networkmanager import NetworkManagerSettings, NetworkManager\n connection_paths = await NetworkManagerSettings().get_connections_by_id(self.connection_id)\n await nm.activate_connection(connection_paths[0])\n
","upvoteCount":0,"url":"https://github.com/python-sdbus/python-sdbus-networkmanager/discussions/70#discussioncomment-12368031"}}}
| route-pattern | /_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format) |
| route-controller | voltron_discussions_fragments |
| route-action | discussion_layout |
| fetch-nonce | v2:7512b24e-c185-094d-a1eb-fb4686caa1d2 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | B3BC:144419:3830FC:48C932:698D4E11 |
| html-safe-nonce | 906263162537de41d0d5b6a8385eb1086fe0b5c3c3a62a8f1c63266f40d5fbe9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCM0JDOjE0NDQxOTozODMwRkM6NDhDOTMyOjY5OEQ0RTExIiwidmlzaXRvcl9pZCI6Ijk4Mzc1MTg3OTk4MzcxMzgwOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6dce05d894c46682238cf7a0a6188729cfe5504d210da66b4e78248fa5ee1904 |
| hovercard-subject-tag | discussion:8022608 |
| github-keyboard-shortcuts | repository,network-graph,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/python-sdbus/python-sdbus-networkmanager/70/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/674185ea5b802367a3c04273cf45575c5f9572e6fe7ca423049fa950baeb201e/python-sdbus/python-sdbus-networkmanager/discussions/70 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/674185ea5b802367a3c04273cf45575c5f9572e6fe7ca423049fa950baeb201e/python-sdbus/python-sdbus-networkmanager/discussions/70 |
| og:image:alt | Hi, I can set the IP etc on my interface and apply to the bus: from sdbus_async.networkmanager import NetworkManagerSettings, NetworkConnectionSettings # Ideally want to look up by device eth1 conn... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | c0818105fa276287e9369cfdefa0a0fa7953719791ceff9b94d69623c0a4fe8a |
| turbo-cache-control | no-preview |
| go-import | github.com/python-sdbus/python-sdbus-networkmanager git https://github.com/python-sdbus/python-sdbus-networkmanager.git |
| octolytics-dimension-user_id | 88226657 |
| octolytics-dimension-user_login | python-sdbus |
| octolytics-dimension-repository_id | 384529652 |
| octolytics-dimension-repository_nwo | python-sdbus/python-sdbus-networkmanager |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 384529652 |
| octolytics-dimension-repository_network_root_nwo | python-sdbus/python-sdbus-networkmanager |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a95a17cc440c14d4fcddc0641bc1136fa8d908f0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width