Skip to content

Commit

Permalink
feat: show nic type
Browse files Browse the repository at this point in the history
Co-authored-by: Julian Geywitz <geywitz@sipgate.de>
Co-authored-by: Paul Schwoerer <schwoerer@sipgate.de>
Co-authored-by: Rudolph Bott <bott@sipgate.de>
  • Loading branch information
4 people committed Dec 9, 2022
1 parent 68ec9b0 commit 49f5197
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 16 deletions.
28 changes: 17 additions & 11 deletions api/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ type GntNic struct {
Vlan string `json:"vlan"`
}

type GntNicInfo struct {
NicType string `json:"nicType"`
NicTypeFriendly string `json:"nicTypeFriendly"`
}

type GntInstance struct {
Name string `json:"name"`
PrimaryNode string `json:"primaryNode"`
SecondaryNodes []string `json:"secondaryNodes"`
CpuCount int `json:"cpuCount"`
MemoryTotal int `json:"memoryTotal"`
IsRunning bool `json:"isRunning"`
OffersVNC bool `json:"offersVnc"`
Disks []GntDisk `json:"disks"`
Nics []GntNic `json:"nics"`
Tags []string `json:"tags"`
OS string `json:"OS"`
Name string `json:"name"`
PrimaryNode string `json:"primaryNode"`
SecondaryNodes []string `json:"secondaryNodes"`
CpuCount int `json:"cpuCount"`
MemoryTotal int `json:"memoryTotal"`
IsRunning bool `json:"isRunning"`
OffersVNC bool `json:"offersVnc"`
Disks []GntDisk `json:"disks"`
Nics []GntNic `json:"nics"`
NicInfo GntNicInfo `json:"nicInfo"`
Tags []string `json:"tags"`
OS string `json:"OS"`
}

type GntCluster struct {
Expand Down
30 changes: 28 additions & 2 deletions api/repository/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ type (
}
)

var (
nicTypeMapping = map[string]string{
"e1000": "Intel E1000",
"i82551": "Intel 82551",
"i82559er": "Intel I82559ER",
"i82557b": "Intel I82557B",
"ne2k_isa": "NE2000 (ISA)",
"ne2k_pci": "NE2000 (PCI)",
"paravirtual": "VirtIO",
"pcnet": "AMD PCnet",
"rtl8139": "Realtek RTL8139",
}
)

func (repo *InstanceRepository) Get(clusterName string, instanceName string) (model.InstanceResult, error) {
slug := fmt.Sprintf("/2/instances/%s", instanceName)
response, err := repo.RAPIClient.Get(clusterName, slug)
Expand Down Expand Up @@ -53,8 +67,12 @@ func (repo *InstanceRepository) Get(clusterName string, instanceName string) (mo
OffersVNC: parsedInstance.HvParams.VncBindAddress != "",
Disks: extractDisks(parsedInstance),
Nics: extractNics(parsedInstance),
Tags: parsedInstance.Tags,
OS: parsedInstance.OS,
NicInfo: model.GntNicInfo{
NicType: parsedInstance.HvParams.NicType,
NicTypeFriendly: getNicFriendlyType(parsedInstance.HvParams.NicType),
},
Tags: parsedInstance.Tags,
OS: parsedInstance.OS,
},
}, nil
}
Expand Down Expand Up @@ -206,3 +224,11 @@ func extractNics(instance rapiInstanceResponse) []model.GntNic {

return nics
}

func getNicFriendlyType(nicType string) string {
friendlyType, ok := nicTypeMapping[nicType]
if !ok {
return nicType
}
return friendlyType
}
6 changes: 6 additions & 0 deletions web/src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export type GntNic = {
vlan: string;
};

export type GntNicInfo = {
nicType: string;
nicTypeFriendly: string;
};

export type GntInstance = {
name: string;
primaryNode: string;
Expand All @@ -24,6 +29,7 @@ export type GntInstance = {
offersVnc: boolean;
disks: GntDisk[];
nics: GntNic[];
nicInfo: GntNicInfo;
tags: string[];
OS: string;
};
Expand Down
4 changes: 4 additions & 0 deletions web/src/components/InstanceActions/InstanceActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ function createMockInstance(overrideParams: Partial<GntInstance>): GntInstance {
isRunning: true,
memoryTotal: 1024,
nics: [],
nicInfo: {
nicTypeFriendly: "Realtek RTL8139",
nicType: "rtl8139",
},
offersVnc: false,
primaryNode: "",
secondaryNodes: [],
Expand Down
16 changes: 16 additions & 0 deletions web/src/views/InstanceDetail/InstanceDetail.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@
margin: 0 0 0.25rem;
font-size: 1.25em;
}

.nicParamList {
list-style: none;
margin: 0;
padding: 0;

li {
display: flex;
justify-content: space-between;
padding: 0.5rem 0;
}

li:not(:last-child) {
border-bottom: 1px solid var(--color-separator);
}
}
24 changes: 21 additions & 3 deletions web/src/views/InstanceDetail/InstanceDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {
faComputer,
faEthernet,
faHdd,
faMemory,
faMicrochip,
faNetworkWired,
faServer,
faTag,
} from "@fortawesome/free-solid-svg-icons";
import React, { ReactElement } from "react";
import React, { PropsWithChildren, ReactElement } from "react";
import { useParams } from "react-router-dom";
import { useApi } from "../../api";
import { GntDisk, GntInstance, GntNic } from "../../api/models";
import { GntDisk, GntInstance, GntNic, GntNicInfo } from "../../api/models";
import ApiDataRenderer from "../../components/ApiDataRenderer/ApiDataRenderer";
import Card from "../../components/Card/Card";
import CardGrid from "../../components/CardGrid/CardGrid";
Expand Down Expand Up @@ -62,7 +63,7 @@ function NodeCard({ name, primary }: NodeCardProps): ReactElement {
function NicCard({ name, mode, mac, bridge, vlan }: GntNic): ReactElement {
return (
<Card
icon={faNetworkWired}
icon={faEthernet}
title={name}
badge={<StatusBadge>{mode}</StatusBadge>}
>
Expand All @@ -77,6 +78,22 @@ function NicCard({ name, mode, mac, bridge, vlan }: GntNic): ReactElement {
);
}

function NetworkCard({
nicType,
nicTypeFriendly: nicFriendlyType,
}: GntNicInfo): ReactElement {
return (
<Card icon={faNetworkWired} title={"Info"}>
<ul className={styles.nicParamList}>
<li>
<span>NIC Type</span>
<span title={nicType}>{nicFriendlyType}</span>
</li>
</ul>
</Card>
);
}

type InstanceResponse = {
instance: GntInstance;
};
Expand Down Expand Up @@ -147,6 +164,7 @@ const InstanceDetail = (): ReactElement => {
))}
</CardGrid.Section>
<CardGrid.Section headline="Networking">
<NetworkCard {...instance.nicInfo} />
{instance.nics.map((nic) => (
<NicCard key={nic.name} {...nic} />
))}
Expand Down

0 comments on commit 49f5197

Please sign in to comment.