-
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.
feat(instance) introduce dedicated InstanceIps component
- Loading branch information
Showing
6 changed files
with
53 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React, { FC } from "react"; | ||
import { getIpAddresses } from "util/networks"; | ||
import { LxdInstance } from "types/instance"; | ||
import ExpandableList from "components/ExpandableList"; | ||
|
||
interface Props { | ||
instance: LxdInstance; | ||
family: "inet" | "inet6"; | ||
} | ||
|
||
const InstanceIps: FC<Props> = ({ instance, family }) => { | ||
const addresses = getIpAddresses(instance, family); | ||
return addresses.length ? ( | ||
<ExpandableList | ||
items={addresses.map((address) => ( | ||
<div key={address} className="ip u-truncate" title={address}> | ||
{address} | ||
</div> | ||
))} | ||
/> | ||
) : ( | ||
<>-</> | ||
); | ||
}; | ||
|
||
export default InstanceIps; |
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 |
---|---|---|
@@ -1,38 +1,13 @@ | ||
import React from "react"; | ||
import { LxdInstance } from "types/instance"; | ||
|
||
export const getIpAddresses = ( | ||
instance: LxdInstance, | ||
family?: string, | ||
showLocal = true | ||
family: "inet" | "inet6" | ||
) => { | ||
if (!instance.state?.network) return []; | ||
const interfaces = Object.entries(instance.state.network).filter( | ||
([key, _value]) => key !== "lo" | ||
); | ||
const addresses = interfaces.flatMap(([_key, value]) => value.addresses); | ||
const filteredAddresses = | ||
!family && showLocal | ||
? addresses | ||
: addresses.filter( | ||
(item) => | ||
(family ? item.family === family : true) && | ||
(showLocal | ||
? true | ||
: !( | ||
item.address.startsWith("127") || | ||
item.address.startsWith("fe80") | ||
)) | ||
); | ||
return filteredAddresses.map((item) => item.address); | ||
}; | ||
|
||
export const getIpAddressElements = (instance: LxdInstance, family: string) => { | ||
return getIpAddresses(instance, family).map((address) => { | ||
return ( | ||
<div key={address} className="ip u-truncate" title={address}> | ||
{address} | ||
</div> | ||
); | ||
}); | ||
return Object.entries(instance.state.network) | ||
.filter(([key, _value]) => key !== "lo") | ||
.flatMap(([_key, value]) => value.addresses) | ||
.filter((item) => item.family === family) | ||
.map((item) => item.address); | ||
}; |