-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
231 additions
and
14 deletions.
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
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
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
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
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
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,70 @@ | ||
/* | ||
* Copyright (c) [2022] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import React, { useEffect, useState } from "react"; | ||
import { useInstallerClient } from "./context/installer"; | ||
import Popup from "./Popup"; | ||
import { Button, Text } from "@patternfly/react-core"; | ||
|
||
const initIpData = { | ||
addresses: [], | ||
hostname: "" | ||
}; | ||
|
||
function formatIp(address, prefix) { | ||
return address + "/" + prefix; | ||
} | ||
|
||
export default function TargetIpsPopup() { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const open = () => setIsOpen(true); | ||
const close = () => setIsOpen(false); | ||
const client = useInstallerClient(); | ||
const [state, setState] = useState(initIpData); | ||
const ips = state.addresses.map((addr) => formatIp(addr.address, addr.prefix)); | ||
const firstIp = ips.length > 0 ? ips[0] : ""; | ||
|
||
useEffect(() => { | ||
client.network.config().then((data) => { | ||
setState(data); | ||
}); | ||
}, [client.network]); | ||
|
||
return ( | ||
<> | ||
<Button variant="link" onClick={open}> | ||
{ firstIp } ({state.hostname}) | ||
</Button> | ||
|
||
<Popup | ||
isOpen={isOpen} | ||
title={state.hostname} | ||
aria-label="IP Addresses" | ||
> | ||
{ ips.map((ip) => <Text key={ip}> {ip} </Text>) } | ||
<Popup.Actions> | ||
<Popup.Confirm onClick={close} autoFocus>Close</Popup.Confirm> | ||
</Popup.Actions> | ||
</Popup> | ||
</> | ||
); | ||
} |
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
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
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,118 @@ | ||
/* | ||
* Copyright (c) [2022] SUSE LLC | ||
* | ||
* All Rights Reserved. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2 of the GNU General Public License as published | ||
* by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, contact SUSE LLC. | ||
* | ||
* To contact SUSE LLC about this file by physical or electronic mail, you may | ||
* find current contact information at www.suse.com. | ||
*/ | ||
|
||
import { applyMixin, withDBus } from "./mixins"; | ||
|
||
const NM_IFACE = "org.freedesktop.NetworkManager"; | ||
|
||
export default class NetworkClient { | ||
constructor(dbusClient) { | ||
this._client = dbusClient; | ||
} | ||
|
||
/** | ||
* Returns IP config overview - addresses and hostname | ||
* | ||
* @return {Promise.<Objects>} address key stores list of addresses, | ||
* hostname stores target's hostname | ||
*/ | ||
async config() { | ||
const data = await this.#addresses(); | ||
const addresses = data.map(a => { | ||
return { | ||
address: a.address.v, | ||
prefix: a.prefix.v | ||
}; | ||
}); | ||
|
||
return { | ||
addresses, | ||
hostname: await this.hostname() | ||
}; | ||
} | ||
|
||
/** | ||
* Returns the computer's hostname | ||
* | ||
* https://developer-old.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.Settings.html | ||
* | ||
* @return {Promise.<String>} | ||
*/ | ||
async hostname() { | ||
const proxy = await this.proxy(NM_IFACE + ".Settings"); | ||
|
||
return proxy.Hostname; | ||
} | ||
|
||
/* | ||
* Returns list of active NM connections | ||
* | ||
* Private method. | ||
* See NM API documentation for details. | ||
* https://developer-old.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.html | ||
* | ||
* @return {Promis.<Array>} | ||
*/ | ||
async #connections() { | ||
const proxy = await this.proxy(NM_IFACE); | ||
|
||
return proxy.ActiveConnections; | ||
} | ||
|
||
/* | ||
* Returns NM IP config for the particular connection | ||
* | ||
* Private method. | ||
* See NM API documentation for details | ||
* https://developer-old.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.Connection.Active.html | ||
* https://developer-old.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.IP4Config.html | ||
* | ||
* @return {Promise.<Map>} | ||
*/ | ||
async #address(connection) { | ||
const configPath = await this.proxy(NM_IFACE + ".Connection.Active", connection); | ||
const ipConfigs = await this.proxy(NM_IFACE + ".IP4Config", configPath.Ip4Config); | ||
|
||
return ipConfigs.AddressData; | ||
} | ||
|
||
/* | ||
* Returns list of IP addresses for all active NM connections | ||
* | ||
* Private method. | ||
* | ||
* @return {Promise.<Array>} | ||
*/ | ||
async #addresses() { | ||
const conns = await this.#connections(); | ||
|
||
let result = []; | ||
|
||
for (const i in conns) { | ||
const addr = await this.#address(conns[i]); | ||
result = [...result, ...addr]; | ||
} | ||
|
||
return result; | ||
} | ||
} | ||
|
||
applyMixin(NetworkClient, withDBus); |
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