-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from openebs/rdma-device-create-delete
feat(RDMA): add support to create and delete rdma device on node
- Loading branch information
Showing
7 changed files
with
222 additions
and
3 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,43 @@ | ||
package k8stest | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
agent "github.com/openebs/openebs-e2e/common/e2e_agent" | ||
logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
type RdmaDeviceNetworkInterface struct { | ||
IfIndex int `json:"ifindex"` | ||
IfName string `json:"ifname"` | ||
Port int `json:"port"` | ||
State string `json:"state"` | ||
PhysicalState string `json:"physical_state"` | ||
NetDev string `json:"netdev"` | ||
NetDevIndex int `json:"netdev_index"` | ||
} | ||
|
||
func ListRdmaDevice(node string) ([]RdmaDeviceNetworkInterface, error) { | ||
var rdmaDeiceList []RdmaDeviceNetworkInterface | ||
nodeIp, err := GetNodeIPAddress(node) | ||
if err != nil { | ||
return rdmaDeiceList, fmt.Errorf("failed to get node %s ip, error: %v", node, err) | ||
} | ||
|
||
rdmaDevice, err := agent.ListRdmaDevice(*nodeIp) | ||
if err != nil { | ||
return rdmaDeiceList, fmt.Errorf("failed to list RDMA device on node %s , error: %v", node, err) | ||
} | ||
if rdmaDevice == "" { | ||
logf.Log.Info("RDMA device list failed with empty string", "output", rdmaDevice) | ||
return rdmaDeiceList, fmt.Errorf("failed to list RDMA device on node %s", node) | ||
} | ||
output := trimForJson(rdmaDevice) | ||
if err = json.Unmarshal([]byte(output), &rdmaDeiceList); err != nil { | ||
logf.Log.Info("Failed to unmarshal rdma list", "output", output) | ||
return rdmaDeiceList, fmt.Errorf("failed to unmarshal rdma list on node %s , output: %s,error: %v", node, output, err) | ||
} | ||
logf.Log.Info("RDMA device", "node", node, "list", rdmaDeiceList) | ||
return rdmaDeiceList, nil | ||
} |
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,96 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"k8s.io/klog/v2" | ||
) | ||
|
||
type Rdma struct { | ||
DeviceName string `json:"deviceName"` | ||
InterfaceName string `json:"interfaceName"` | ||
} | ||
|
||
// ListRdmaDevice list RDMA device | ||
func ListRdmaDevice(w http.ResponseWriter, r *http.Request) { | ||
var msg string | ||
klog.Info("List available RDMA device") | ||
|
||
rdmaDeviceListCommand := "rdma link -j" | ||
output, err := bashLocal(rdmaDeviceListCommand) | ||
if err != nil { | ||
msg = fmt.Sprintf("cannot list RDMA device. Error %s", err.Error()) | ||
klog.Error(msg) | ||
WrapResult(msg, ErrExecFailed, w) | ||
return | ||
} | ||
WrapResult(string(output), ErrNone, w) | ||
} | ||
|
||
// CreateRdmaDevice create rdma device | ||
func CreateRdmaDevice(w http.ResponseWriter, r *http.Request) { | ||
var msg string | ||
var rdma Rdma | ||
d := json.NewDecoder(r.Body) | ||
if err := d.Decode(&rdma); err != nil { | ||
msg = fmt.Sprintf("failed to read JSON encoded data, Error: %s", err.Error()) | ||
klog.Error(msg) | ||
WrapResult(msg, ErrJsonDecode, w) | ||
return | ||
} | ||
if rdma.DeviceName == "" { | ||
msg = "no device name passed" | ||
klog.Error(msg) | ||
WrapResult(msg, UnprocessableEntityErrorCode, w) | ||
return | ||
} | ||
if rdma.InterfaceName == "" { | ||
msg = "no interface name passed" | ||
klog.Error(msg) | ||
WrapResult(msg, UnprocessableEntityErrorCode, w) | ||
return | ||
} | ||
klog.Info("creates rdma device, data: %v", rdma) | ||
|
||
rdmaDeviceCreateCommand := fmt.Sprintf("rdma link add %s type rxe netdev %s", rdma.DeviceName, rdma.InterfaceName) | ||
output, err := bashLocal(rdmaDeviceCreateCommand) | ||
if err != nil { | ||
msg = fmt.Sprintf("cannot create rdma device, Error %s", err.Error()) | ||
klog.Error(msg) | ||
WrapResult(msg, ErrExecFailed, w) | ||
return | ||
} | ||
WrapResult(string(output), ErrNone, w) | ||
} | ||
|
||
// DeleteRdmaDevice destroy rdma device | ||
func DeleteRdmaDevice(w http.ResponseWriter, r *http.Request) { | ||
var msg string | ||
var rdma Rdma | ||
d := json.NewDecoder(r.Body) | ||
if err := d.Decode(&rdma); err != nil { | ||
msg = fmt.Sprintf("failed to read JSON encoded data, Error: %s", err.Error()) | ||
klog.Error(msg) | ||
WrapResult(msg, ErrJsonDecode, w) | ||
return | ||
} | ||
if rdma.DeviceName == "" { | ||
msg = "no rdma device name passed" | ||
klog.Error(msg) | ||
WrapResult(msg, UnprocessableEntityErrorCode, w) | ||
return | ||
} | ||
|
||
klog.Info("delete rdma device, data: %v", rdma) | ||
rdmaDeviceDeleteCommand := fmt.Sprintf("rdma link delete %s", rdma.DeviceName) | ||
output, err := bashLocal(rdmaDeviceDeleteCommand) | ||
if err != nil { | ||
msg = fmt.Sprintf("cannot delete rdma device, Error %s", err.Error()) | ||
klog.Error(msg) | ||
WrapResult(msg, ErrExecFailed, w) | ||
return | ||
} | ||
WrapResult(string(output), ErrNone, w) | ||
} |
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