From ae480d6cc1cfdeb2bac866f7c513e35d7cb3f6e3 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Mon, 21 Jun 2021 17:12:14 -0400 Subject: [PATCH] Add SR-IOV listing/info endpoints to API --- api-daemon/pvcapid/flaskapi.py | 80 ++++++++++++++ docs/manuals/swagger.json | 196 ++++++++++++++++++++++++++++++++- 2 files changed, 274 insertions(+), 2 deletions(-) diff --git a/api-daemon/pvcapid/flaskapi.py b/api-daemon/pvcapid/flaskapi.py index 54691368..dc9cc588 100755 --- a/api-daemon/pvcapid/flaskapi.py +++ b/api-daemon/pvcapid/flaskapi.py @@ -2770,6 +2770,27 @@ class API_SRIOV_PF_Root(Resource): api.add_resource(API_SRIOV_PF_Root, '/sriov/pf') +# /sriov/pf/ +class API_SRIOV_PF_Node(Resource): + @Authenticator + def get(self, node): + """ + Return a list of SR-IOV PFs on node {node} + --- + tags: + - network / sriov + responses: + 200: + description: OK + schema: + $ref: '#/definitions/sriov_pf' + """ + return api_helper.sriov_pf_list(node) + + +api.add_resource(API_SRIOV_PF_Node, '/sriov/pf/') + + # /sriov/vf class API_SRIOV_VF_Root(Resource): @RequestParser([ @@ -2847,6 +2868,65 @@ class API_SRIOV_VF_Root(Resource): api.add_resource(API_SRIOV_VF_Root, '/sriov/vf') +# /sriov/vf/ +class API_SRIOV_VF_Node(Resource): + @RequestParser([ + {'name': 'pf', 'required': False, 'helptext': "A PF parent may be specified."}, + ]) + @Authenticator + def get(self, node, reqargs): + """ + Return a list of SR-IOV VFs on node {node}, optionally limited to those in the specified PF + --- + tags: + - network / sriov + responses: + 200: + description: OK + schema: + $ref: '#/definitions/sriov_vf' + """ + return api_helper.sriov_vf_list(node, reqargs.get('pf', None)) + + +api.add_resource(API_SRIOV_VF_Node, '/sriov/vf/') + + +# /sriov/vf// +class API_SRIOV_VF_Element(Resource): + @Authenticator + def get(self, node, vf): + """ + Return information about {vf} on {node} + --- + tags: + - network / sriov + responses: + 200: + description: OK + schema: + $ref: '#/definitions/sriov_vf' + 404: + description: Not found + schema: + type: object + id: Message + """ + vf_list = list() + full_vf_list, _ = api_helper.sriov_vf_list(node) + for vf_element in full_vf_list: + if vf_element['phy'] == vf: + vf_list.append(vf_element) + + if len(vf_list) == 1: + return vf_list, 200 + else: + return {'message': "No VF '{}' found on node '{}'".format(vf, node)}, 404 + + +api.add_resource(API_SRIOV_VF_Element, '/sriov/vf//') + + ########################################################## # Client API - Storage ########################################################## diff --git a/docs/manuals/swagger.json b/docs/manuals/swagger.json index c52cfc92..af4eafaa 100644 --- a/docs/manuals/swagger.json +++ b/docs/manuals/swagger.json @@ -764,6 +764,99 @@ }, "type": "object" }, + "sriov_pf": { + "properties": { + "mtu": { + "description": "The MTU of the SR-IOV PF device", + "type": "string" + }, + "phy": { + "description": "The name of the SR-IOV PF device", + "type": "string" + }, + "vfs": { + "items": { + "description": "The PHY name of a VF of this PF", + "type": "string" + }, + "type": "list" + } + }, + "type": "object" + }, + "sriov_vf": { + "properties": { + "config": { + "id": "sriov_vf_config", + "properties": { + "link_state": { + "description": "The current SR-IOV VF link state (either enabled, disabled, or auto)", + "type": "string" + }, + "query_rss": { + "description": "Whether VF RSS querying is enabled or disabled", + "type": "boolean" + }, + "spoof_check": { + "description": "Whether device spoof checking is enabled or disabled", + "type": "boolean" + }, + "trust": { + "description": "Whether guest device trust is enabled or disabled", + "type": "boolean" + }, + "tx_rate_max": { + "description": "The maximum TX rate of the SR-IOV VF device", + "type": "string" + }, + "tx_rate_min": { + "description": "The minimum TX rate of the SR-IOV VF device", + "type": "string" + }, + "vlan_id": { + "description": "The tagged vLAN ID of the SR-IOV VF device", + "type": "string" + }, + "vlan_qos": { + "description": "The QOS group of the tagged vLAN", + "type": "string" + } + }, + "type": "object" + }, + "mac": { + "description": "The current MAC address of the VF device", + "type": "string" + }, + "mtu": { + "description": "The current MTU of the VF device", + "type": "integer" + }, + "pf": { + "description": "The name of the SR-IOV PF parent of this VF device", + "type": "string" + }, + "phy": { + "description": "The name of the SR-IOV VF device", + "type": "string" + }, + "usage": { + "id": "sriov_vf_usage", + "properties": { + "domain": { + "description": "The UUID of the domain the SR-IOV VF is currently used by", + "type": "boolean" + }, + "used": { + "description": "Whether the SR-IOV VF is currently used by a VM or not", + "type": "boolean" + } + }, + "type": "object" + } + }, + "type": "object" + }, "storage-template": { "properties": { "disks": { @@ -1459,8 +1552,15 @@ }, "/api/v1/initialize": { "post": { - "description": "Note: Normally used only once during cluster bootstrap; checks for the existence of the \"/primary_node\" key before proceeding and returns 400 if found", + "description": "
If the 'overwrite' option is not True, the cluster will return 400 if the `/config/primary_node` key is found. If 'overwrite' is True, the existing cluster
data will be erased and new, empty data written in its place.

All node daemons should be stopped before running this command, and the API daemon started manually to avoid undefined behavior.", "parameters": [ + { + "description": "A flag to enable or disable (default) overwriting existing data", + "in": "query", + "name": "overwrite", + "required": false, + "type": "bool" + }, { "description": "A confirmation string to ensure that the API consumer really means it", "in": "query", @@ -4453,6 +4553,97 @@ ] } }, + "/api/v1/sriov/pf": { + "get": { + "description": "", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/sriov_pf" + } + } + }, + "summary": "Return a list of SR-IOV PFs on a given node", + "tags": [ + "network / sriov" + ] + } + }, + "/api/v1/sriov/pf/{node}": { + "get": { + "description": "", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/sriov_pf" + } + } + }, + "summary": "Return a list of SR-IOV PFs on node {node}", + "tags": [ + "network / sriov" + ] + } + }, + "/api/v1/sriov/vf": { + "get": { + "description": "", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/sriov_vf" + } + } + }, + "summary": "Return a list of SR-IOV VFs on a given node, optionally limited to those in the specified PF", + "tags": [ + "network / sriov" + ] + } + }, + "/api/v1/sriov/vf/{node}": { + "get": { + "description": "", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/sriov_vf" + } + } + }, + "summary": "Return a list of SR-IOV VFs on node {node}, optionally limited to those in the specified PF", + "tags": [ + "network / sriov" + ] + } + }, + "/api/v1/sriov/vf/{node}/{vf}": { + "get": { + "description": "", + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/sriov_vf" + } + }, + "404": { + "description": "Not found", + "schema": { + "$ref": "#/definitions/Message" + } + } + }, + "summary": "Return information about {vf} on {node}", + "tags": [ + "network / sriov" + ] + } + }, "/api/v1/status": { "get": { "description": "", @@ -5721,7 +5912,8 @@ "mem", "vcpus", "load", - "vms" + "vms", + "none (cluster default)" ], "in": "query", "name": "selector",