swagger: '2.0'
info:
    title: KloudBuster Rest API Specification
    description: |
        A tool to load OpenStack clouds end to end in both control plane and
        data plane.
    version: "0.1.0"
host: 127.0.0.1:8080
basePath: /api
schemes:
    - http
    - https
consumes:
    - application/json
produces:
    - application/json
paths:
    /config/default_config:
        get:
            description: |
                Get the default KloudBuster configuration from server
            tags:
                - config
            responses:
                200:
                    description: The default configuration
                    schema:
                        type: string
                        format: json

    /config/az_list/{session_id}:
        get:
            description: |
                Get the available availability zone list
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: The session to be queried
                  required: true
            tags:
                - config
            responses:
                200:
                    description: |
                        The available availability zones for the session
                    schema:
                        $ref: '#/definitions/AZ_List'
                400:
                    description: Cannot get the availability zone list
                404:
                    description: The session_id is not found or invalid

    /config/hypervisor_list/{session_id}:
        get:
            description: |
                Get the available hypervisor list
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: The session to be queried
                  required: true
            tags:
                - config
            responses:
                200:
                    description: |
                        The available hypervisors for the session
                    schema:
                        $ref: '#/definitions/Hypervisor_List'
                400:
                    description: Cannot get the hypervisor list
                404:
                    description: The session_id is not found or invalid

    /config/running_config:
        post:
            description: |
                Create a new KloudBuster session with provided configuration
            parameters:
                - name: arg
                  in: body
                  description: The configuration for KloudBuster
                  required: true
                  schema:
                      $ref: '#/definitions/Configuration_New'
            tags:
                - config
            responses:
                200:
                    description: Session is already existed
                    schema:
                        type: string
                        format: md5sum
                        description: The existed session ID
                201:
                    description: Session is created successfully
                    schema:
                        type: string
                        format: md5sum
                        description: The newly created session ID
                400:
                    description: Error while parsing the configuration file
                    schema:
                        type: string
                        description: Errors in details

    /config/topology_config/{session_id}:
        get:
            description: |
                Get the topology configuration of a KloudBuster session
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: The session to be queried
                  required: true
            tags:
                - config
            responses:
                200:
                    description: The topology configuration
                    schema:
                        $ref: '#/definitions/Topology_Config'
                404:
                    description: The session_id is not found or invalid

    /config/running_config/{session_id}:
        get:
            description: |
                Get the running configuration of a KloudBuster session
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: The session to be queried
                  required: true
            tags:
                - config
            responses:
                200:
                    description: The running configuration
                    schema:
                        type: string
                        format: json
                404:
                    description: The session_id is not found or invalid

        put:
            description: |
                Update KloudBuster configuration for an existing session
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: |
                      The session to be updated
                  required: true
                - name: arg
                  in: body
                  description: The configuration to be updated
                  required: true
                  schema:
                      $ref: '#/definitions/Configuration_Update'
            tags:
                - config
            responses:
                200:
                    description: |
                        Configuration of given session is updated successfully
                400:
                    description: Invalid JSON or error while parsing the configuration file
                    schema:
                        type: string
                        description: Errors in details
                403:
                    description: |
                        Cannot update configuration if KloudBuster is busy or in error state
                404:
                    description: The session_id is not found or invalid
        delete:
            description: |
                Terminate the given session in KloudBuster server
            parameters:
                - name: session_id
                  type: string
                  in: path
                  description: |
                      The session to be terminated
                  required: true
            tags:
                - config
            responses:
                200:
                    description: The session is terminated successfully
                403:
                    description: Session can be destroyed only if it is at READY
                404:
                    description: The session_id is not found or invalid

    /kloudbuster/version:
        get:
            description: Get KloudBuster server version
            tags:
                - kloudbuster
            responses:
                200:
                    description: OK
                    schema:
                        type: string
                        description: The version of the KloudBuster server

    /kloudbuster/status/{session_id}:
        get:
            description: |
                Get KloudBuster server status for a given session
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: The session to be queried
                  required: true
            tags:
                - kloudbuster
            responses:
                200:
                    description: OK
                    schema:
                        type: string
                        format: json
                        description: The status of the given session
                404:
                    description: The session_id is not found or invalid

    /kloudbuster/log/{session_id}:
        get:
            description: |
                Get KloudBuster console log for a given session
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: The session to be queried
                  required: true
                - name: offset
                  type: integer
                  in: query
                  description: The offset of the log file to read
                  required: false
            tags:
                - kloudbuster
            responses:
                200:
                    description: OK
                    schema:
                        type: string
                        description: The console log of the given session
                400:
                    description: Parameter is missing or invalid
                404:
                    description: The session_id is not found or invalid

    /kloudbuster/report/{session_id}:
        get:
            description: |
                Get the latest KloudBuster periodical report for a given session.
                Set final to true to retrieve the final report.
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: The session to be queried
                  required: true
                - name: final
                  type: boolean
                  in: query
                  description: Set to true to retrieve the final report
                  required: false
            tags:
                - kloudbuster
            responses:
                200:
                    description: OK
                    schema:
                        type: string
                        description: The periodical report of the given session
                404:
                    description: The session_id is not found or invalid

    /kloudbuster/stage/{session_id}:
        post:
            description: |
                Stage all resources to run KloudBuster for a given session
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: |
                      The session to be staged
                  required: true
            tags:
                - kloudbuster
            responses:
                200:
                    description: |
                        Successfully staged all resources for the given session
                403:
                    description: |
                        Unable to stage resources when status is not at READY
                404:
                    description: The session_id is not found or invalid

    /kloudbuster/run_test/{session_id}:
        post:
            description: |
                Run KloudBuster for a given session
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: |
                      The session to be run
                  required: true
            tags:
                - kloudbuster
            responses:
                200:
                    description: Successfully start the given session
                403:
                    description: |
                        Unable to start the tests when status is not at STAGED
                404:
                    description: The session_id is not found or invalid

    /kloudbuster/stop_test/{session_id}:
        post:
            description: |
                Stop the KloudBuster tests for a given session
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: |
                      The session to be stopped
                  required: true
            tags:
                - kloudbuster
            responses:
                200:
                    description: Scheduled to stop the tests for the given session
                403:
                    description: |
                        Unable to stop the tests when status is not at RUNNING
                404:
                    description: The session_id is not found or invalid

    /kloudbuster/cleanup/{session_id}:
        post:
            description: |
                Cleanup KloudBuster for a given session
            parameters:
                - name: session_id
                  type: string
                  format: md5sum
                  in: path
                  description: |
                      The session to be run
                  required: true
            tags:
                - kloudbuster
            responses:
                200:
                    description: Successfully cleaned up the given session
                403:
                    description: |
                        No resources has been staged, or session is busy
                404:
                    description: The session_id is not found or invalid

definitions:
    Configuration_New:
        required:
            - credentials
            - kb_cfg
        properties:
            credentials:
                type: string
                format: json
                description: Credentials for the clouds
            kb_cfg:
                type: string
                format: json
                description: User overrided configs
            topo_cfg:
                type: string
                format: json
                description: Topology config
            tenants_cfg:
                type: string
                format: json
                description: Tenant and User list for reusing
            storage_mode:
                type: boolean
                description: Running web UI for storage testing
    Configuration_Update:
        properties:
            kb_cfg:
                type: string
                format: json
                description: User overrided configs
            topo_cfg:
                type: string
                format: json
                description: Topology config
            tenants_cfg:
                type: string
                format: json
                description: Tenant and User list for reusing
    AZ_List:
        properties:
            server:
                type: array
                items:
                    type: string
                format: json
                description: Available availability zones for server cloud
            client:
                type: array
                items:
                    type: string
                format: json
                description: Available availability zones for client cloud
    Hypervisor_List:
        properties:
            server:
                type: array
                items:
                    type: string
                format: json
                description: Available hypervisors for server cloud
            client:
                type: array
                items:
                    type: string
                format: json
                description: Available hypervisors for client cloud
    Topology_Config:
        properties:
            servers_rack:
                type: array
                items:
                    type: string
                format: json
                description: Hypervisors to hold server VMs
            clients_rack:
                type: array
                items:
                    type: string
                format: json
                description: Hypervisors to hold client VMs
