project-safari / zebra

lab resource inventory and reservation system
Apache License 2.0
6 stars 8 forks source link

Refactor zebra model and type system #121

Closed rchamarthy closed 1 year ago

rchamarthy commented 1 year ago

Zebra model

The Zebra data model is defined by custom zebra resources that are extensible. We can add new resource types and register with the zebra server to manage the life cycle of these resources. The zebra API is a generic resource API used to create/update/delete, and read any resources. As zebra is geared toward a generic resource management system, it becomes essential to define a specific contract on how to define a new resource and plug it into the zebra server, client, and simulator services.

Resource Type contract

model
  - types.go - registry of all types
  - compute
    - doc.go - contains compute package documentation
    - server.go - containers server resource definitions
    - ...
  - network
    - doc.go - contains network package documentation
    - switch.go - containers server resource definitions 
    - ...
func ServerType() zebra.Type {
    return zebra.Type{
        Name:        "compute.server",
        Description: "a rack mountable compute server",
        Constructor: func() zebra.Resource { return new(Server) },
    }
}
package compute

type Server struct {
...
}

func NewServer(name string, serial string) zebra.Resource {
....
}
func NewMockServerList(court int) zebra.ResourceList {
...
}
{
  "type": "object",
  "required": ["name", "serialNumber"],
  "properties": {
    "name" : {
      "type": "string",
      "description": "host name of the server management board"
    },
    "serialNumber" : {
      "type": "string",
      "description": "serial number of the server"
    }
  }
}