cluster

package
v0.0.0-...-433fd04 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeContainer             = 0
	TypeImage                 = 1
	TypeProfile               = 2
	TypeProject               = 3
	TypeCertificate           = 4
	TypeInstance              = 5
	TypeInstanceBackup        = 6
	TypeInstanceSnapshot      = 7
	TypeNetwork               = 8
	TypeNetworkACL            = 9
	TypeNode                  = 10
	TypeOperation             = 11
	TypeStoragePool           = 12
	TypeStorageVolume         = 13
	TypeStorageVolumeBackup   = 14
	TypeStorageVolumeSnapshot = 15
	TypeWarning               = 16
)

Numeric type codes identifying different kind of entities.

Variables

View Source
var EntityFormatURIs = map[int]func(a ...interface{}) string{
	TypeContainer: func(a ...interface{}) string {
		uri := fmt.Sprintf(EntityURIs[TypeContainer], a[1], a[0])
		if a[0] == "default" {
			return strings.Split(uri, fmt.Sprintf("?project=%s", a[0]))[0]
		}

		return uri
	},
	TypeProfile: func(a ...interface{}) string {
		uri := fmt.Sprintf(EntityURIs[TypeProfile], a[1], a[0])
		if a[0] == "default" {
			return strings.Split(uri, fmt.Sprintf("?project=%s", a[0]))[0]
		}

		return uri
	},
	TypeProject: func(a ...interface{}) string {
		uri := fmt.Sprintf(EntityURIs[TypeProject], a[0])
		return uri
	},
}

EntityFormatURIs associates an entity code to a formatter function that can be used to format its URI.

View Source
var EntityNames = map[int]string{
	TypeContainer:             "container",
	TypeImage:                 "image",
	TypeProfile:               "profile",
	TypeProject:               "project",
	TypeCertificate:           "certificate",
	TypeInstance:              "instance",
	TypeInstanceBackup:        "instance backup",
	TypeInstanceSnapshot:      "instance snapshot",
	TypeNetwork:               "network",
	TypeNetworkACL:            "network acl",
	TypeNode:                  "node",
	TypeOperation:             "operation",
	TypeStoragePool:           "storage pool",
	TypeStorageVolume:         "storage volume",
	TypeStorageVolumeBackup:   "storage volume backup",
	TypeStorageVolumeSnapshot: "storage volume snapshot",
	TypeWarning:               "warning",
}

EntityNames associates an entity code to its name.

View Source
var EntityTypes = map[string]int{}

EntityTypes associates an entity name to its type code.

View Source
var EntityURIs = map[int]string{
	TypeContainer:             "/" + version.APIVersion + "/containers/%s?project=%s",
	TypeImage:                 "/" + version.APIVersion + "/images/%s?project=%s",
	TypeProfile:               "/" + version.APIVersion + "/profiles/%s?project=%s",
	TypeProject:               "/" + version.APIVersion + "/projects/%s",
	TypeCertificate:           "/" + version.APIVersion + "/certificates/%s",
	TypeInstance:              "/" + version.APIVersion + "/instances/%s?project=%s",
	TypeInstanceBackup:        "/" + version.APIVersion + "/instances/%s/backups/%s?project=%s",
	TypeInstanceSnapshot:      "/" + version.APIVersion + "/instances/%s/snapshots/%s?project=%s",
	TypeNetwork:               "/" + version.APIVersion + "/networks/%s?project=%s",
	TypeNetworkACL:            "/" + version.APIVersion + "/network-acls/%s?project=%s",
	TypeNode:                  "/" + version.APIVersion + "/cluster/members/%s",
	TypeOperation:             "/" + version.APIVersion + "/operations/%s",
	TypeStoragePool:           "/" + version.APIVersion + "/storage-pools/%s",
	TypeStorageVolume:         "/" + version.APIVersion + "/storage-pools/%s/volumes/%s/%s?project=%s",
	TypeStorageVolumeBackup:   "/" + version.APIVersion + "/storage-pools/%s/volumes/%s/%s/backups/%s?project=%s",
	TypeStorageVolumeSnapshot: "/" + version.APIVersion + "/storage-pools/%s/volumes/%s/%s/snapshots/%s?project=%s",
	TypeWarning:               "/" + version.APIVersion + "/warnings/%s",
}

EntityURIs associates an entity code to its URI pattern.

View Source
var SchemaVersion = len(updates)

SchemaVersion is the current version of the cluster database schema.

Functions

func EnsureSchema

func EnsureSchema(db *sql.DB, address string, dir string) (bool, error)

EnsureSchema applies all relevant schema updates to the cluster database.

Before actually doing anything, this function will make sure that all nodes in the cluster have a schema version and a number of API extensions that match our one. If it's not the case, we either return an error (if some nodes have version greater than us and we need to be upgraded), or return false and no error (if some nodes have a lower version, and we need to wait till they get upgraded and restarted).

func FreshSchema

func FreshSchema() string

FreshSchema returns the fresh schema definition of the global database.

func Open

func Open(name string, store driver.NodeStore, options ...driver.Option) (*sql.DB, error)

Open the cluster database object.

The name argument is the name of the cluster database. It defaults to 'db.bin', but can be overwritten for testing.

The dialer argument is a function that returns a gRPC dialer that can be used to connect to a database node using the gRPC SQL package.

func PrepareStmts

func PrepareStmts(db *sql.DB, skipErrors bool) (map[int]*sql.Stmt, error)

PrepareStmts prepares all registered statements and returns an index from statement code to prepared statement object.

func RegisterStmt

func RegisterStmt(sql string) int

RegisterStmt register a SQL statement.

Registered statements will be prepared upfront and re-used, to speed up execution.

Return a unique registration code.

func Schema

func Schema() *schema.Schema

Schema for the cluster database.

func SchemaDotGo

func SchemaDotGo() error

SchemaDotGo refreshes the schema.go file in this package, using the updates defined here.

Types

This section is empty.

Jump to

Keyboard shortcuts

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