web

package
v0.0.0-...-9a65667 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2020 License: MIT Imports: 10 Imported by: 0

README

WEB Service

This package provides Web APIs to control BMC operations. The original purpose is to make a VM where the provisioning service is located to call this application in host OS directly.

By default, Web APIs can be access via HTTP with port 9090.

APIs

Currently, we supports the following APIs with JSON data as their context types:

  • GET /api/BMCs
    • Get all BMC information
  • GET /api/BMCs/<BMC_IP>
    • Get the information of the specified BMC
  • PUT /api/BMCs/<BMC_IP>/power
    • Send power operation to the BMC
  • PUT /api/BMCs/<BMC_IP>/bootdev
    • Set boot device to the BMC

More information can be refer to the following sessions

GET /api/BMCs
  • Description: Get all BMC information
  • Request Body: NONE
  • Response Example:
{
    "BMCs": [
        {
            "IP": "127.0.1.1",
            "PowerStatus": "ON"
        },
        {
            "IP": "127.0.1.2",
            "PowerStatus": "OFF"
        },
        {
            "IP": "127.0.1.3",
            "PowerStatus": "ON"
        }
    ]
}
  • Response Data Fields:
    • BMCs: A list contains all BMC information.
      • IP: BMC IP Address
      • PowerStatus: Current power status. (ON / OFF)
GET /api/BMCs/<BMC_IP>
  • Description: Get the information of the specified BMC
  • Request Body: NONE
  • Response Example:
{
    "IP": "127.0.1.1",
    "PowerStatus": "ON"
}
  • Response Data Fields:
    • IP: BMC IP Address
    • PowerStatus: Current power status. (ON / OFF)
PUT /api/BMCs/{BMC_IP}/power
  • Description: Send power operation to the BMC
  • Request Body:
{
    "Operation": <POWER_OPERATION>
}
  • Request Body Fields:
    • Operation: Power operation (ON / OFF / RESET / CYCLE)
  • Response Example:
{
    "IP": "127.0.1.1",
    "Operation": "OFF",
    "Status": "OK"
}
  • Response Data Fields:

    • IP: BMC IP Address
    • Operation: The power operation we want to perform.
    • Status: Operation result
  • Note: It may take some time to make power operation effect. After this API is called, you can use GET /api/BMCs/<BMC_IP> to fetch the current power states.

PUT /api/BMCs/{BMC_IP}/bootdev
  • Description: Set boot device to the BMC
  • Request Body:
{
    "Device": <BOOT_DEVICE_NAME>
}
  • Request Body Fields:
    • Device: Device name which we want to specify. ( DISK / PXE )
  • Response Example:
{
    "IP": "127.0.1.1",
    "Device": "DISK",
    "Status": "OK"
}
  • Response Data Fields:
    • IP: BMC IP Address
    • Device: The boot device value we want to set.
    • Status: Operation result

Reference

All the Restful API Web Server implementation idea is from Making a RESTful JSON API in Go.

In this package, routes and logger implementation are based on this tutorial.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ListenPort int

Functions

func GetAllBMCs

func GetAllBMCs(writer http.ResponseWriter, request *http.Request)

func GetBMC

func GetBMC(writer http.ResponseWriter, request *http.Request)

func NewRouter

func NewRouter() *mux.Router

Utility function

func SetBootDevice

func SetBootDevice(writer http.ResponseWriter, request *http.Request)

func SetPowerStatus

func SetPowerStatus(writer http.ResponseWriter, request *http.Request)

func WebAPIServiceRun

func WebAPIServiceRun()

func WebLogger

func WebLogger(handler http.HandlerFunc, name string) http.Handler

Types

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

type WebReqBootDev

type WebReqBootDev struct {
	Device string
}

type WebReqPowerOp

type WebReqPowerOp struct {
	Operation string
}

type WebRespBMC

type WebRespBMC struct {
	IP          string
	PowerStatus string
}

type WebRespBMCList

type WebRespBMCList struct {
	BMCs []WebRespBMC
}

type WebRespBootDev

type WebRespBootDev struct {
	IP     string
	Device string
	Status string
}

type WebRespPowerOp

type WebRespPowerOp struct {
	IP        string
	Operation string
	Status    string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL