diff --git a/cns/api.go b/cns/api.go index 6974a4207f..b05cc24ef6 100644 --- a/cns/api.go +++ b/cns/api.go @@ -7,10 +7,12 @@ import ( "context" "encoding/json" "fmt" + "net" "time" "github.com/Azure/azure-container-networking/cns/common" "github.com/Azure/azure-container-networking/cns/types" + "github.com/Azure/azure-container-networking/cns/types/infiniband" "github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha" "github.com/pkg/errors" ) @@ -32,6 +34,7 @@ const ( V1Prefix = "/v0.1" V2Prefix = "/v0.2" EndpointPath = "/network/endpoints/" + IBDevicesPath = "/ibdevices" // Service Fabric SWIFTV2 mode StandaloneSWIFTV2 SWIFTV2Mode = "StandaloneSWIFTV2" // K8s SWIFTV2 mode @@ -382,3 +385,17 @@ type GetVMUniqueIDResponse struct { Response Response `json:"response"` VMUniqueID string `json:"vmuniqueid"` } + +// AssignIBDevicesToPodResponse represents the response for assigning InfiniBand devices to a pod +type AssignIBDevicesToPodResponse struct { + Message string `json:"message"` // Additional message or error description +} + +// GetIBDeviceStatusResponse represents the response containing InfiniBand device programming status +type GetIBDeviceStatusResponse struct { + MACAddress net.HardwareAddr `json:"macAddress"` // MAC address of the device + PodNamespace string `json:"podNamespace"` // Namespace of pod to which the device is assigned, if any + PodName string `json:"podName"` // Name of pod to which the device is assigned, if any + Status infiniband.Status `json:"status"` // Device status (e.g., "Available", "ProgrammingPending", etc.)" + Message string `json:"message"` // Additional message or error description +} diff --git a/cns/swagger.yaml b/cns/swagger.yaml index 6ed3e0aefd..743ed6cd02 100644 --- a/cns/swagger.yaml +++ b/cns/swagger.yaml @@ -120,6 +120,87 @@ paths: schema: $ref: "#/components/schemas/UnpublishNetworkContainerResponse" + /ibdevices:assign: + post: + summary: Assign IB devices to a pod + description: > + Assigns one or more Infiniband devices by MAC address to a given pod. + parameters: + - name: ibmacs + in: query + required: true + description: Comma-separated list of IB device MAC addresses. + schema: + type: array + items: + type: string + example: ["60:45:bd:a4:b5:7a", "7c:1e:52:07:11:36"] + - name: podnamespace + in: query + required: true + description: The namespace of the target pod. + schema: + type: string + example: "podnamespace" + - name: podname + in: query + required: true + description: The name of the target pod. + schema: + type: string + example: "podname" + responses: + '200': + description: >- + The request passed initial validation and CNS was able to propagate its state. + content: + application/json: + schema: + $ref: "#/components/schemas/AssignIBDevicesToPodResponse" + '404': + description: >- + The pod specified by PodID was not found. + content: + application/json: + schema: + $ref: "#/components/schemas/AssignIBDevicesToPodResponse" + '400': + description: >- + One of the IB devices specified is not available. + content: + application/json: + schema: + $ref: "#/components/schemas/AssignIBDevicesToPodResponse" + + /ibdevices: + get: + summary: Get status of an IB device + description: >- + Retrieves the current programming status of the specified IB device. + parameters: + - name: ibmac + in: query + required: true + description: The MAC address of the IB device. + schema: + type: string + example: "60:45:bd:a4:b5:7a" + responses: + '200': + description: >- + The request was successful and the status of the IB device is returned. + content: + application/json: + schema: + $ref: "#/components/schemas/GetIBDeviceStatusResponse" + '404': + description: >- + The IB device specified by MAC address was not found. + content: + application/json: + schema: + $ref: "#/components/schemas/GetIBDeviceStatusResponse" + components: schemas: UnpublishNetworkContainerResponse: @@ -351,3 +432,56 @@ components: Message: type: string description: The error message + + AssignIBDevicesToPodResponse: + type: object + required: + - Message + properties: + Message: + type: string + description: Human-readable message or error description + + GetIBDeviceStatusResponse: + type: object + required: + - MACAddress + - PodNamespace + - PodName + - Status + - Message + properties: + MACAddress: + type: string + description: MAC address of the IB device + PodNamespace: + type: string + description: namespace of the pod to which the device is assigned, if any + PodName: + type: string + description: name of the pod to which the device is assigned, if any + Status: + $ref: "#/components/schemas/Status" + Message: + type: string + description: Human-readable message or error description + + Status: + type: integer + description: Status of IB device (see cns/types/infiniband/status.go) + oneOf: + - title: Available + const: 0 + description: Device is available for use + - title: ProgrammingPending + const: 1 + description: Programming of device is pending + - title: ProgrammingFailed + const: 2 + description: Programming of device failed + - title: ProgrammingComplete + const: 3 + description: Programming of device is complete + - title: ReleasePending + const: 4 + description: Release of device is pending diff --git a/cns/types/infiniband/status.go b/cns/types/infiniband/status.go new file mode 100644 index 0000000000..31f8149b42 --- /dev/null +++ b/cns/types/infiniband/status.go @@ -0,0 +1,11 @@ +package infiniband + +type Status int + +const ( + Available Status = 0 + ProgrammingPending Status = 1 + ProgrammingFailed Status = 2 + ProgrammingComplete Status = 3 + ReleasePending Status = 4 +)