Documentation ¶
Overview ¶
Package models provides an interface for persisting and retrieving data to and from the database, as well as JSON marshalling/unmarshalling aids for such data.
Index ¶
- Variables
- func AddRelation(tableName string, r1 relatable, r2 relatable) error
- func ClearRelations(tableName string, r1 relatable) error
- func RemoveRelation(tableName string, r1 relatable, r2 relatable) error
- func SetRelations(tableName string, r1 relatable, r2s []relatable) error
- type Config
- func (config *Config) Clean()
- func (config *Config) Decode(data io.Reader) error
- func (config *Config) DeleteNamespace(namespace string)
- func (config *Config) DeleteValue(namespace string, key string)
- func (config *Config) Get() map[string]map[string]string
- func (config *Config) GetNamespace(namespace string) map[string]string
- func (config *Config) GetValue(namespace string, key string) (string, bool)
- func (config *Config) Load() error
- func (config *Config) Merge(updates *Config)
- func (config *Config) Save() error
- func (config *Config) SetNamespace(namespace string, value map[string]string)
- func (config *Config) SetValue(namespace string, key string, value string)
- func (config *Config) Validate() error
- type Flavor
- type Hypervisor
- func (hypervisor *Hypervisor) AddIPRange(iprange *IPRange) error
- func (hypervisor *Hypervisor) Decode(data io.Reader) error
- func (hypervisor *Hypervisor) Delete() error
- func (hypervisor *Hypervisor) Load() error
- func (hypervisor *Hypervisor) LoadIPRanges() error
- func (hypervisor Hypervisor) MarshalJSON() ([]byte, error)
- func (hypervisor *Hypervisor) NewID() string
- func (hypervisor *Hypervisor) RemoveIPRange(iprange *IPRange) error
- func (hypervisor *Hypervisor) Save() error
- func (hypervisor *Hypervisor) SetIPRanges(ipranges []*IPRange) error
- func (hypervisor *Hypervisor) UnmarshalJSON(b []byte) error
- func (hypervisor *Hypervisor) Validate() error
- type IPRange
- func (iprange *IPRange) AddHypervisor(hypervisor *Hypervisor) error
- func (iprange *IPRange) Decode(data io.Reader) error
- func (iprange *IPRange) Delete() error
- func (iprange *IPRange) Load() error
- func (iprange *IPRange) LoadHypervisors() error
- func (iprange *IPRange) LoadNetwork() error
- func (iprange IPRange) MarshalJSON() ([]byte, error)
- func (iprange *IPRange) NewID() string
- func (iprange *IPRange) RemoveHypervisor(hypervisor *Hypervisor) error
- func (iprange *IPRange) RemoveNetwork(network *Network) error
- func (iprange *IPRange) Save() error
- func (iprange *IPRange) SetHypervisors(hypervisors []*Hypervisor) error
- func (iprange *IPRange) SetNetwork(network *Network) error
- func (iprange *IPRange) UnmarshalJSON(b []byte) error
- func (iprange *IPRange) Validate() error
- type Network
- func (network *Network) AddIPRange(iprange *IPRange) error
- func (network *Network) Decode(data io.Reader) error
- func (network *Network) Delete() error
- func (network *Network) Load() error
- func (network *Network) LoadIPRanges() error
- func (network *Network) NewID() string
- func (network *Network) RemoveIPRange(iprange *IPRange) error
- func (network *Network) Save() error
- func (network *Network) SetIPRanges(ipranges []*IPRange) error
- func (network *Network) Validate() error
- type Permission
- func (permission *Permission) AddProject(project *Project) error
- func (permission *Permission) Decode(data io.Reader) error
- func (permission *Permission) Delete() error
- func (permission *Permission) Load() error
- func (permission *Permission) LoadProjects() error
- func (permission *Permission) NewID() string
- func (permission *Permission) RemoveProject(project *Project) error
- func (permission *Permission) Save() error
- func (permission *Permission) SetProjects(projects []*Project) error
- func (permission *Permission) Validate() error
- type Project
- func (project *Project) AddPermission(permission *Permission) error
- func (project *Project) AddUser(user *User) error
- func (project *Project) Decode(data io.Reader) error
- func (project *Project) Delete() error
- func (project *Project) Load() error
- func (project *Project) LoadPermissions() error
- func (project *Project) LoadUsers() error
- func (project *Project) NewID() string
- func (project *Project) RemovePermission(permission *Permission) error
- func (project *Project) RemoveUser(user *User) error
- func (project *Project) Save() error
- func (project *Project) SetPermissions(permissions []*Permission) error
- func (project *Project) SetUsers(users []*User) error
- func (project *Project) Validate() error
- type User
- func (user *User) AddProject(project *Project) error
- func (user *User) Decode(data io.Reader) error
- func (user *User) Delete() error
- func (user *User) Load() error
- func (user *User) LoadProjects() error
- func (user *User) NewID() string
- func (user *User) RemoveProject(project *Project) error
- func (user *User) Save() error
- func (user *User) SetProjects(projects []*Project) error
- func (user *User) Validate() error
Constants ¶
This section is empty.
Variables ¶
var ErrBadCPU = errors.New("cpu must be > 0")
ErrBadCPU is for an invlid CPU in the flavor
var ErrBadDisk = errors.New("disk must be > 0")
ErrBadDisk is for invalid disk in the flavor
var ErrBadID = errors.New("invalid id")
ErrBadID is for an invalid id (e.g. non-uuid)
var ErrBadMemory = errors.New("memory must be > 0")
ErrBadMemory is for invalid memory in the flavor
var ErrNilData = errors.New("data must not be nil")
ErrNilData is for nil data map in the config
var ErrNilMetadata = errors.New("metadata must not be nil")
ErrNilMetadata is for nil metadata
var ErrNoAction = errors.New("missing action")
ErrNoAction is for calling an unconfigured action
var ErrNoCIDR = errors.New("missing cidr")
ErrNoCIDR is for missing a cidr in the iprange
var ErrNoEmail = errors.New("missing email")
ErrNoEmail is for missing an email in the user object
var ErrNoEndIP = errors.New("missing end IP")
ErrNoEndIP is for missing an ending ip in the iprange
var ErrNoGateway = errors.New("missing gateway")
ErrNoGateway is for missing a gateway in the iprange
var ErrNoID = errors.New("missing id")
ErrNoID is for a missing id
var ErrNoIP = errors.New("missing IP")
ErrNoIP is for a missing IP in the hypervisor
var ErrNoMAC = errors.New("missing MAC")
ErrNoMAC is for a missing MAC in the hypervisor
var ErrNoName = errors.New("missing name")
ErrNoName is for a missing name
var ErrNoService = errors.New("missing service")
ErrNoService is for calling an unconfigured service
var ErrNoStartIP = errors.New("missing start IP")
ErrNoStartIP is for missing a starting ip in the iprange
var ErrNoUsername = errors.New("missing username")
ErrNoUsername is for missing a username in the user object
Functions ¶
func AddRelation ¶
AddRelation creates a new relation between two relatable objects in the database
func ClearRelations ¶
ClearRelations relations removes all relations a relatable object has with another relatable object type
func RemoveRelation ¶
RemoveRelation removes a relation between two relatable objects in the database
func SetRelations ¶
SetRelations creates and ensures the only relations between a relatable object and another relatable type is the provided set
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config persists and retrieves arbitrary namespaced key/value pairs with support for default values.
func NewConfig ¶
func NewConfig() *Config
NewConfig creates a new Config instance and initializes the internal data map
func (*Config) Clean ¶
func (config *Config) Clean()
Clean will remove any set values that match defaults and any empty set namespaces. Primarilly used before persisting to reduce redundant and unnecessary data.
func (*Config) DeleteNamespace ¶
DeleteNamespace deletes a set namespace. Defaults are not deleted.
func (*Config) DeleteValue ¶
DeleteValue deletes a set namespaced key. Defaults are not deleted.
func (*Config) GetNamespace ¶
GetNamespace returns a map of config key/value pairs with set values merged on top of defaults. It is a new map, so modifications will not be stored
func (*Config) GetValue ¶
GetValue retrieves the value of a namespaced key, with set values taking precidence over defaults
func (*Config) SetNamespace ¶
SetNamespace places a set of key/value pairs under a given namespace
type Flavor ¶
type Flavor struct { ID string `json:"id"` Name string `json:"name"` CPU int `json:"cpu"` // Number of Cores Memory int `json:"memory"` // Size in MB Disk int `json:"disk"` // Size in MB Metadata map[string]string `json:"metadata"` }
Flavor describes a unit of resources, similar to an AWS EC2 type
func FetchFlavor ¶
FetchFlavor retrieves a flavor object from the database by ID
func ListFlavors ¶
ListFlavors retrieves an array of all flavor objects from the database
type Hypervisor ¶
type Hypervisor struct { ID string `json:"id"` MAC net.HardwareAddr `json:"mac"` IP net.IP `json:"ip"` Metadata map[string]string `json:"metadata"` IPRanges []*IPRange `json:"-"` }
Hypervisor describes a machine where guests will be running
func FetchHypervisor ¶
func FetchHypervisor(id string) (*Hypervisor, error)
FetchHypervisor retrieves a hypervisor object from the database by ID
func HypervisorsByIPRange ¶
func HypervisorsByIPRange(iprange *IPRange) ([]*Hypervisor, error)
HypervisorsByIPRange retrieves an array of hypervisors associated with an iprange from the database
func ListHypervisors ¶
func ListHypervisors() ([]*Hypervisor, error)
ListHypervisors retrieves an array of all hypervisor objects from the database
func NewHypervisor ¶
func NewHypervisor() *Hypervisor
NewHypervisor creates and initializes a new hypervisor object
func (*Hypervisor) AddIPRange ¶
func (hypervisor *Hypervisor) AddIPRange(iprange *IPRange) error
AddIPRange adds a relation to an iprange
func (*Hypervisor) Decode ¶
func (hypervisor *Hypervisor) Decode(data io.Reader) error
Decode unmarshals JSON into the flavor object
func (*Hypervisor) Delete ¶
func (hypervisor *Hypervisor) Delete() error
Delete removes a hypervisor from the database
func (*Hypervisor) Load ¶
func (hypervisor *Hypervisor) Load() error
Load retrieves a hypervisor from the database
func (*Hypervisor) LoadIPRanges ¶
func (hypervisor *Hypervisor) LoadIPRanges() error
LoadIPRanges retrieves all of the ipranges related to the hypervisor
func (Hypervisor) MarshalJSON ¶
func (hypervisor Hypervisor) MarshalJSON() ([]byte, error)
MarshalJSON marshals a hypervisor into JSON
func (*Hypervisor) NewID ¶
func (hypervisor *Hypervisor) NewID() string
NewID generates a new uuid ID
func (*Hypervisor) RemoveIPRange ¶
func (hypervisor *Hypervisor) RemoveIPRange(iprange *IPRange) error
RemoveIPRange removes a relation with an iprange
func (*Hypervisor) Save ¶
func (hypervisor *Hypervisor) Save() error
Save persists a hypervisor to the database
func (*Hypervisor) SetIPRanges ¶
func (hypervisor *Hypervisor) SetIPRanges(ipranges []*IPRange) error
SetIPRanges creates and ensures the only relations the hypervisor has with ipranges
func (*Hypervisor) UnmarshalJSON ¶
func (hypervisor *Hypervisor) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals JSON into a hypervisor
func (*Hypervisor) Validate ¶
func (hypervisor *Hypervisor) Validate() error
Validate ensures the hypervisor properties are set correctly
type IPRange ¶
type IPRange struct { ID string `json:"id"` CIDR *net.IPNet `json:"cidr"` Gateway net.IP `json:"gateway"` Start net.IP `json:"start"` End net.IP `json:"end"` Metadata map[string]string `json:"metadata"` Network *Network `json:"-"` Hypervisors []*Hypervisor `json:"-"` }
IPRange describes a segment of IP addresses
func FetchIPRange ¶
FetchIPRange retrieves an iprange object from the database by ID
func IPRangesByHypervisor ¶
func IPRangesByHypervisor(hypervisor *Hypervisor) ([]*IPRange, error)
IPRangesByHypervisor retrieves an array of iprange objects associated with a hypervisor from the database
func IPRangesByNetwork ¶
IPRangesByNetwork retrieves an array of iprange objects associated with a network from the database
func ListIPRanges ¶
ListIPRanges retrieves an array of all iprange objects from the database
func NewIPRange ¶
func NewIPRange() *IPRange
NewIPRange creates and initializes a new iprange object
func (*IPRange) AddHypervisor ¶
func (iprange *IPRange) AddHypervisor(hypervisor *Hypervisor) error
AddHypervisor adds a relation to a hypervisor
func (*IPRange) LoadHypervisors ¶
LoadHypervisors retrieves the hypervisors associated with the iprange from the database
func (*IPRange) LoadNetwork ¶
LoadNetwork retrieves the network related with the iprange from the database
func (IPRange) MarshalJSON ¶
MarshalJSON marshals an iprange object into JSON
func (*IPRange) RemoveHypervisor ¶
func (iprange *IPRange) RemoveHypervisor(hypervisor *Hypervisor) error
RemoveHypervisor removes a relation from a hypervisor
func (*IPRange) RemoveNetwork ¶
RemoveNetwork clears the network relation
func (*IPRange) SetHypervisors ¶
func (iprange *IPRange) SetHypervisors(hypervisors []*Hypervisor) error
SetHypervisors creates and ensures the only relations the iprange has with hypervisors
func (*IPRange) SetNetwork ¶
SetNetwork sets the related network
func (*IPRange) UnmarshalJSON ¶
UnmarshalJSON unmarshals JSON into an iprange object
type Network ¶
type Network struct { ID string `json:"id"` Name string `json:"name"` Metadata map[string]string `json:"metadata"` IPRanges []*IPRange `json:"-"` }
Network describes a set of ipranges
func FetchNetwork ¶
FetchNetwork retrieves a network object from the database by ID
func ListNetworks ¶
ListNetworks retrieves an array of all network objects from the database
func NetworksByIPRange ¶
NetworksByIPRange retrieves an array of all network objects associated with an iprange from the database
func NewNetwork ¶
func NewNetwork() *Network
NewNetwork creates and initializes a new network object
func (*Network) AddIPRange ¶
AddIPRange adds a relation to an iprange
func (*Network) LoadIPRanges ¶
LoadIPRanges retrieves the ipranges associated with the network from the database
func (*Network) RemoveIPRange ¶
RemoveIPRange removes a relation with an iprange
func (*Network) SetIPRanges ¶
SetIPRanges creates and ensures the only relations the network has with ipranges
type Permission ¶
type Permission struct { ID string `json:"id"` Name string `json:"name"` Service string `json:"service"` Action string `json:"action"` EntityType string `json:"entityType"` Owner bool `json:"owner"` Description string `json:"description"` Metadata map[string]string `json:"metadata"` Projects []*Project `json:"-"` }
Permission represents an action that can be taken on an entity by a user
func FetchPermission ¶
func FetchPermission(id string) (*Permission, error)
FetchPermission retrieves a permission object from the database by ID
func ListPermissions ¶
func ListPermissions() ([]*Permission, error)
ListPermissions retrieve an array of all permission objects from the database
func NewPermission ¶
func NewPermission() *Permission
NewPermission creates and initializes a new permission object
func PermissionsByProject ¶
func PermissionsByProject(project *Project) ([]*Permission, error)
PermissionsByProject retrieves an array of permission related to a project
func (*Permission) AddProject ¶
func (permission *Permission) AddProject(project *Project) error
AddProject adds a relation to a project
func (*Permission) Decode ¶
func (permission *Permission) Decode(data io.Reader) error
Decode unmarshals JSON into the permission object
func (*Permission) Delete ¶
func (permission *Permission) Delete() error
Delete deletes the permission from the database
func (*Permission) Load ¶
func (permission *Permission) Load() error
Load retrieves the permission from the database
func (*Permission) LoadProjects ¶
func (permission *Permission) LoadProjects() error
LoadProjects retrieves the projects associated with the permission
func (*Permission) NewID ¶
func (permission *Permission) NewID() string
NewID generates a new uuid ID
func (*Permission) RemoveProject ¶
func (permission *Permission) RemoveProject(project *Project) error
RemoveProject removes a relation with a project
func (*Permission) Save ¶
func (permission *Permission) Save() error
Save persists the permission to the database
func (*Permission) SetProjects ¶
func (permission *Permission) SetProjects(projects []*Project) error
SetProjects creates and ensures the only relations the permission has with projects
func (*Permission) Validate ¶
func (permission *Permission) Validate() error
Validate ensures the permission properties are set correctly
type Project ¶
type Project struct { ID string `json:"id"` Name string `json:"name"` Metadata map[string]string `json:"metadata"` Users []*User `json:"-"` Permissions []*Permission `json:"-"` }
Project describes a set of users and is what is given ownership of resources
func FetchProject ¶
FetchProject retrieves a project object from the database by ID
func ListProjects ¶
ListProjects retrieves an array of all projects from the database
func NewProject ¶
func NewProject() *Project
NewProject creates and initializes a new project object
func ProjectsByPermission ¶
func ProjectsByPermission(permission *Permission) ([]*Project, error)
ProjectsByPermission retrieves an array of projects related to a permission
func ProjectsByUser ¶
ProjectsByUser retrieves an array of projects related to a user
func (*Project) AddPermission ¶
func (project *Project) AddPermission(permission *Permission) error
AddPermission adds a relation to a permission
func (*Project) LoadPermissions ¶
LoadPermissions retrieves the permissions related to the project from the database
func (*Project) RemovePermission ¶
func (project *Project) RemovePermission(permission *Permission) error
RemovePermission removes a relation with a permission
func (*Project) RemoveUser ¶
RemoveUser removes a relation with a user
func (*Project) SetPermissions ¶
func (project *Project) SetPermissions(permissions []*Permission) error
SetPermissions creates and ensures the only relations teh project has with permissions
type User ¶
type User struct { ID string `json:"id"` Username string `json:"username"` Email string `json:"email"` Metadata map[string]string `json:"metadata"` Projects []*Project `json:"-"` }
User is an entity that can interact with mistify
func UsersByProject ¶
UsersByProject retrieves an array of users associated with a project
func (*User) AddProject ¶
AddProject adds a relation to a project
func (*User) LoadProjects ¶
LoadProjects retrieves the projects associated with the user
func (*User) RemoveProject ¶
RemoveProject removes a relation with a project
func (*User) SetProjects ¶
SetProjects creates and ensures the only relations the user has with projects