|
| 1 | +# CNS IBDevice API Contracts |
| 2 | + |
| 3 | +## Overview |
| 4 | +Two new APIs for managing InfiniBand devices in Azure Container Network Service (CNS): |
| 5 | + |
| 6 | +1. **Assign IB Devices to Pod** - Assigns multiple InfiniBand devices to a pod |
| 7 | +2. **Get IB Device Info** - Retrieves information about a specific InfiniBand device |
| 8 | + |
| 9 | +These APIs support **gRPC**, **REST**, and **Unix Domain Socket** transports based on `cnsconfig.GRPCSettings.Enable` configuration. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## API 1: Assign InfiniBand Devices to Pod |
| 14 | + |
| 15 | +### Endpoint |
| 16 | +``` |
| 17 | +PUT /ibdevices/pod/{podname-podnamespace} |
| 18 | +``` |
| 19 | + |
| 20 | +### Request Body |
| 21 | +```json |
| 22 | +{ |
| 23 | + "podID": "my-pod-my-namespace", |
| 24 | + "deviceIds": ["60:45:bd:a4:b5:7a", "7c:1e:52:07:11:36"] |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +### Success Response |
| 29 | +```json |
| 30 | +{ |
| 31 | + "response": { |
| 32 | + "errorCode": 0, |
| 33 | + "message": "Successfully assigned 2 devices to pod my-pod-my-namespace" |
| 34 | + } |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +### Error Response |
| 39 | +```json |
| 40 | +{ |
| 41 | + "response": { |
| 42 | + "errorCode": 23, |
| 43 | + "message": "Device 60:45:bd:a4:b5:7a is already assigned to another pod" |
| 44 | + } |
| 45 | +} |
| 46 | +``` |
| 47 | + |
| 48 | +--- |
| 49 | + |
| 50 | +## API 2: Get InfiniBand Device Information |
| 51 | + |
| 52 | +### Endpoint |
| 53 | +``` |
| 54 | +GET /ibdevices/{mac-address-of-device} |
| 55 | +``` |
| 56 | + |
| 57 | +### Request |
| 58 | +No request body (MAC address provided in URL path) |
| 59 | + |
| 60 | +### Success Response |
| 61 | +```json |
| 62 | +{ |
| 63 | + "deviceID": "60:45:bd:a4:b5:7a", |
| 64 | + "podID": "my-pod-my-namespace", |
| 65 | + "status": "assigned", |
| 66 | + "errorCode": 0, |
| 67 | + "msg": "" |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### Device Not Found Response |
| 72 | +```json |
| 73 | +{ |
| 74 | + "deviceID": "60:45:bd:a4:b5:7a", |
| 75 | + "podID": "", |
| 76 | + "status": "", |
| 77 | + "errorCode": 14, |
| 78 | + "msg": "Device not found" |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +## Go Data Structures |
| 85 | +See [api.go](../cns/api.go) |
| 86 | + |
| 87 | +- `AssignIBDevicesToPodRequest` |
| 88 | +- `AssignIBDevicesToPodResponse` |
| 89 | +- `GetIBDeviceInfoRequest` |
| 90 | +- `GetIBDeviceInfoResponse` |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## gRPC Protocol Buffers |
| 95 | + |
| 96 | +### Service Definition |
| 97 | +```protobuf |
| 98 | +service CNS { |
| 99 | + rpc AssignIBDevicesToPod(AssignIBDevicesToPodRequest) returns (AssignIBDevicesToPodResponse); |
| 100 | + rpc GetIBDeviceInfo(GetIBDeviceInfoRequest) returns (GetIBDeviceInfoResponse); |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +### Message Definitions |
| 105 | +```protobuf |
| 106 | +message AssignIBDevicesToPodRequest { |
| 107 | + string podID = 1; // podname-podnamespace |
| 108 | + repeated string deviceIds = 2; // MAC addresses |
| 109 | +} |
| 110 | +
|
| 111 | +message AssignIBDevicesToPodResponse { |
| 112 | + int32 returnCode = 1; // 0 for success |
| 113 | + string message = 2; // Response message |
| 114 | +} |
| 115 | +
|
| 116 | +message GetIBDeviceInfoRequest { |
| 117 | + string deviceID = 1; // MAC address |
| 118 | +} |
| 119 | +
|
| 120 | +message GetIBDeviceInfoResponse { |
| 121 | + string deviceID = 1; // MAC address |
| 122 | + string podID = 2; // Assigned pod |
| 123 | + string status = 3; // Device status |
| 124 | + int32 errorCode = 4; // Error code |
| 125 | + string msg = 5; // Additional message |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +--- |
| 130 | + |
| 131 | +## Unix Domain Socket Support |
| 132 | + |
| 133 | +### Configuration |
| 134 | +```yaml |
| 135 | +cnsconfig: |
| 136 | + grpcSettings: |
| 137 | + enable: true |
| 138 | + socketPath: "/var/run/cns/grpc.sock" |
| 139 | +``` |
| 140 | +
|
| 141 | +### gRPC Client Example |
| 142 | +```go |
| 143 | +conn, err := grpc.Dial("unix:///var/run/cns/grpc.sock", grpc.WithInsecure()) |
| 144 | +client := pb.NewCNSClient(conn) |
| 145 | + |
| 146 | +// Assign devices |
| 147 | +resp, err := client.AssignIBDevicesToPod(ctx, &pb.AssignIBDevicesToPodRequest{ |
| 148 | + PodID: "my-pod-my-namespace", |
| 149 | + DeviceIds: []string{"60:45:bd:a4:b5:7a"}, |
| 150 | +}) |
| 151 | +``` |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## Response Codes |
| 156 | + |
| 157 | +| Code | Name | Description | |
| 158 | +|------|-------------------|---------------------------------------| |
| 159 | +| 0 | Success | Operation completed successfully | |
| 160 | +| 23 | InvalidRequest | Invalid request parameters | |
| 161 | +| 14 | NotFound | Device not found | |
| 162 | +See [codes.go](../cns/types/codes.go) |
| 163 | +- Not all of these codes are relevant, but we will take from this list |
| 164 | + |
| 165 | +--- |
| 166 | + |
| 167 | +## Path Constants |
| 168 | + |
| 169 | +```go |
| 170 | +const ( |
| 171 | + IBDevicesPodPath = "/ibdevices/pod/" // PUT /ibdevices/pod/{podname-podnamespace} |
| 172 | + IBDevicesPath = "/ibdevices/" // GET /ibdevices/{mac-address-of-device} |
| 173 | +) |
| 174 | +``` |
0 commit comments