models

package
v0.0.0-...-3a65669 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2015 License: Apache-2.0 Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var ErrBadCPU = errors.New("cpu must be > 0")

ErrBadCPU is for an invlid CPU in the flavor

View Source
var ErrBadDisk = errors.New("disk must be > 0")

ErrBadDisk is for invalid disk in the flavor

View Source
var ErrBadID = errors.New("invalid id")

ErrBadID is for an invalid id (e.g. non-uuid)

View Source
var ErrBadMemory = errors.New("memory must be > 0")

ErrBadMemory is for invalid memory in the flavor

View Source
var ErrNilData = errors.New("data must not be nil")

ErrNilData is for nil data map in the config

View Source
var ErrNilMetadata = errors.New("metadata must not be nil")

ErrNilMetadata is for nil metadata

View Source
var ErrNoAction = errors.New("missing action")

ErrNoAction is for calling an unconfigured action

View Source
var ErrNoCIDR = errors.New("missing cidr")

ErrNoCIDR is for missing a cidr in the iprange

View Source
var ErrNoEmail = errors.New("missing email")

ErrNoEmail is for missing an email in the user object

View Source
var ErrNoEndIP = errors.New("missing end IP")

ErrNoEndIP is for missing an ending ip in the iprange

View Source
var ErrNoGateway = errors.New("missing gateway")

ErrNoGateway is for missing a gateway in the iprange

View Source
var ErrNoID = errors.New("missing id")

ErrNoID is for a missing id

View Source
var ErrNoIP = errors.New("missing IP")

ErrNoIP is for a missing IP in the hypervisor

View Source
var ErrNoMAC = errors.New("missing MAC")

ErrNoMAC is for a missing MAC in the hypervisor

View Source
var ErrNoName = errors.New("missing name")

ErrNoName is for a missing name

View Source
var ErrNoService = errors.New("missing service")

ErrNoService is for calling an unconfigured service

View Source
var ErrNoStartIP = errors.New("missing start IP")

ErrNoStartIP is for missing a starting ip in the iprange

View Source
var ErrNoUsername = errors.New("missing username")

ErrNoUsername is for missing a username in the user object

Functions

func AddRelation

func AddRelation(tableName string, r1 relatable, r2 relatable) error

AddRelation creates a new relation between two relatable objects in the database

func ClearRelations

func ClearRelations(tableName string, r1 relatable) error

ClearRelations relations removes all relations a relatable object has with another relatable object type

func RemoveRelation

func RemoveRelation(tableName string, r1 relatable, r2 relatable) error

RemoveRelation removes a relation between two relatable objects in the database

func SetRelations

func SetRelations(tableName string, r1 relatable, r2s []relatable) error

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) Decode

func (config *Config) Decode(data io.Reader) error

Decode decodes JSON into a Config

func (*Config) DeleteNamespace

func (config *Config) DeleteNamespace(namespace string)

DeleteNamespace deletes a set namespace. Defaults are not deleted.

func (*Config) DeleteValue

func (config *Config) DeleteValue(namespace string, key string)

DeleteValue deletes a set namespaced key. Defaults are not deleted.

func (*Config) Get

func (config *Config) Get() map[string]map[string]string

Get retrieves the full config with set values taking precedence over defaults

func (*Config) GetNamespace

func (config *Config) GetNamespace(namespace string) map[string]string

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

func (config *Config) GetValue(namespace string, key string) (string, bool)

GetValue retrieves the value of a namespaced key, with set values taking precidence over defaults

func (*Config) Load

func (config *Config) Load() error

Load retrieves the persisted set data

func (*Config) Merge

func (config *Config) Merge(updates *Config)

Merge merges in set values from another Config into the current one

func (*Config) Save

func (config *Config) Save() error

Save persists the set data

func (*Config) SetNamespace

func (config *Config) SetNamespace(namespace string, value map[string]string)

SetNamespace places a set of key/value pairs under a given namespace

func (*Config) SetValue

func (config *Config) SetValue(namespace string, key string, value string)

SetValue sets the value of a namespaced key, creating the namespace if it does not already exist.

func (*Config) Validate

func (config *Config) Validate() error

Validate checks that the properties of Config are valid

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

func FetchFlavor(id string) (*Flavor, error)

FetchFlavor retrieves a flavor object from the database by ID

func ListFlavors

func ListFlavors() ([]*Flavor, error)

ListFlavors retrieves an array of all flavor objects from the database

func NewFlavor

func NewFlavor() *Flavor

NewFlavor creates and initializes a new flavor object

func (*Flavor) Decode

func (flavor *Flavor) Decode(data io.Reader) error

Decode unmarshals JSON into the flavor object

func (*Flavor) Delete

func (flavor *Flavor) Delete() error

Delete removes a flavor from the database

func (*Flavor) Load

func (flavor *Flavor) Load() error

Load retrieves a flavor from the database

func (*Flavor) NewID

func (flavor *Flavor) NewID() string

NewID generates a new uuid ID

func (*Flavor) Save

func (flavor *Flavor) Save() error

Save persists a flavor to the database

func (*Flavor) Validate

func (flavor *Flavor) Validate() error

Validate ensures the flavor properties are set correctly

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

func FetchIPRange(id string) (*IPRange, error)

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

func IPRangesByNetwork(network *Network) ([]*IPRange, error)

IPRangesByNetwork retrieves an array of iprange objects associated with a network from the database

func ListIPRanges

func ListIPRanges() ([]*IPRange, error)

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) Decode

func (iprange *IPRange) Decode(data io.Reader) error

Decode unmarshals JSON into the flavor object

func (*IPRange) Delete

func (iprange *IPRange) Delete() error

Delete removes an iprange from the database

func (*IPRange) Load

func (iprange *IPRange) Load() error

Load retrieves an iprange from the database

func (*IPRange) LoadHypervisors

func (iprange *IPRange) LoadHypervisors() error

LoadHypervisors retrieves the hypervisors associated with the iprange from the database

func (*IPRange) LoadNetwork

func (iprange *IPRange) LoadNetwork() error

LoadNetwork retrieves the network related with the iprange from the database

func (IPRange) MarshalJSON

func (iprange IPRange) MarshalJSON() ([]byte, error)

MarshalJSON marshals an iprange object into JSON

func (*IPRange) NewID

func (iprange *IPRange) NewID() string

NewID generates a new uuid ID

func (*IPRange) RemoveHypervisor

func (iprange *IPRange) RemoveHypervisor(hypervisor *Hypervisor) error

RemoveHypervisor removes a relation from a hypervisor

func (*IPRange) RemoveNetwork

func (iprange *IPRange) RemoveNetwork(network *Network) error

RemoveNetwork clears the network relation

func (*IPRange) Save

func (iprange *IPRange) Save() error

Save persists an iprange to the database

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

func (iprange *IPRange) SetNetwork(network *Network) error

SetNetwork sets the related network

func (*IPRange) UnmarshalJSON

func (iprange *IPRange) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals JSON into an iprange object

func (*IPRange) Validate

func (iprange *IPRange) Validate() error

Validate ensures the iprange proerties are set correctly

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

func FetchNetwork(id string) (*Network, error)

FetchNetwork retrieves a network object from the database by ID

func ListNetworks

func ListNetworks() ([]*Network, error)

ListNetworks retrieves an array of all network objects from the database

func NetworksByIPRange

func NetworksByIPRange(iprange *IPRange) ([]*Network, error)

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

func (network *Network) AddIPRange(iprange *IPRange) error

AddIPRange adds a relation to an iprange

func (*Network) Decode

func (network *Network) Decode(data io.Reader) error

Decode unmarshals JSON into the network object

func (*Network) Delete

func (network *Network) Delete() error

Delete removes a network from the database

func (*Network) Load

func (network *Network) Load() error

Load retrieves a network from the database

func (*Network) LoadIPRanges

func (network *Network) LoadIPRanges() error

LoadIPRanges retrieves the ipranges associated with the network from the database

func (*Network) NewID

func (network *Network) NewID() string

NewID generates a new uuid ID

func (*Network) RemoveIPRange

func (network *Network) RemoveIPRange(iprange *IPRange) error

RemoveIPRange removes a relation with an iprange

func (*Network) Save

func (network *Network) Save() error

Save persists a network to the database

func (*Network) SetIPRanges

func (network *Network) SetIPRanges(ipranges []*IPRange) error

SetIPRanges creates and ensures the only relations the network has with ipranges

func (*Network) Validate

func (network *Network) Validate() error

Validate ensures the network properties are set correctly

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

func FetchProject(id string) (*Project, error)

FetchProject retrieves a project object from the database by ID

func ListProjects

func ListProjects() ([]*Project, error)

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

func ProjectsByUser(user *User) ([]*Project, error)

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) AddUser

func (project *Project) AddUser(user *User) error

AddUser adds a relation to a user

func (*Project) Decode

func (project *Project) Decode(data io.Reader) error

Decode unmarshals JSON into the project object

func (*Project) Delete

func (project *Project) Delete() error

Delete removes a project from the database

func (*Project) Load

func (project *Project) Load() error

Load retrieves a project from the database

func (*Project) LoadPermissions

func (project *Project) LoadPermissions() error

LoadPermissions retrieves the permissions related to the project from the database

func (*Project) LoadUsers

func (project *Project) LoadUsers() error

LoadUsers retrieves the users related to the project from the database

func (*Project) NewID

func (project *Project) NewID() string

NewID generates a new uuid ID

func (*Project) RemovePermission

func (project *Project) RemovePermission(permission *Permission) error

RemovePermission removes a relation with a permission

func (*Project) RemoveUser

func (project *Project) RemoveUser(user *User) error

RemoveUser removes a relation with a user

func (*Project) Save

func (project *Project) Save() error

Save persists a project to the database

func (*Project) SetPermissions

func (project *Project) SetPermissions(permissions []*Permission) error

SetPermissions creates and ensures the only relations teh project has with permissions

func (*Project) SetUsers

func (project *Project) SetUsers(users []*User) error

SetUsers creates and ensures the only relations teh project has with users

func (*Project) Validate

func (project *Project) Validate() error

Validate ensures the project properties are set correctly

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 FetchUser

func FetchUser(id string) (*User, error)

FetchUser retrieves a user from the database by ID

func ListUsers

func ListUsers() ([]*User, error)

ListUsers retrieves an array of all users from the database

func NewUser

func NewUser() *User

NewUser creates and initializes a new user object

func UsersByProject

func UsersByProject(project *Project) ([]*User, error)

UsersByProject retrieves an array of users associated with a project

func (*User) AddProject

func (user *User) AddProject(project *Project) error

AddProject adds a relation to a project

func (*User) Decode

func (user *User) Decode(data io.Reader) error

Decode unmarshals JSON into the user object

func (*User) Delete

func (user *User) Delete() error

Delete removes the user from the database

func (*User) Load

func (user *User) Load() error

Load retrieves the user from the database

func (*User) LoadProjects

func (user *User) LoadProjects() error

LoadProjects retrieves the projects associated with the user

func (*User) NewID

func (user *User) NewID() string

NewID generates a new uuid ID

func (*User) RemoveProject

func (user *User) RemoveProject(project *Project) error

RemoveProject removes a relation with a project

func (*User) Save

func (user *User) Save() error

Save persists the user to the database

func (*User) SetProjects

func (user *User) SetProjects(projects []*Project) error

SetProjects creates and ensures the only relations the user has with projects

func (*User) Validate

func (user *User) Validate() error

Validate ensures the user properties are set correctly

Jump to

Keyboard shortcuts

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