project

package
v0.0.0-...-c012b7a Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const Default = "default"

Default is the string used for a default project.

Variables

View Source
var AllRestrictions = []string{
	"restricted.backups",
	"restricted.cluster.target",
	"restricted.containers.nesting",
	"restricted.containers.lowlevel",
	"restricted.containers.privilege",
	"restricted.virtual-machines.lowlevel",
	"restricted.devices.unix-char",
	"restricted.devices.unix-block",
	"restricted.devices.unix-hotplug",
	"restricted.devices.infiniband",
	"restricted.devices.gpu",
	"restricted.devices.usb",
	"restricted.devices.nic",
	"restricted.devices.disk",
	"restricted.snapshots",
}

AllRestrictions lists all available 'restrict.*' config keys.

Functions

func AllowBackupCreation

func AllowBackupCreation(tx *db.ClusterTx, projectName string) error

AllowBackupCreation returns an error if any project-specific restriction is violated when creating a new backup in a project.

func AllowInstanceCreation

func AllowInstanceCreation(tx *db.ClusterTx, projectName string, req api.InstancesPost) error

AllowInstanceCreation returns an error if any project-specific limit or restriction is violated when creating a new instance.

func AllowInstanceUpdate

func AllowInstanceUpdate(tx *db.ClusterTx, projectName, instanceName string, req api.InstancePut, currentConfig map[string]string) error

AllowInstanceUpdate returns an error if any project-specific limit or restriction is violated when updating an existing instance.

func AllowProfileUpdate

func AllowProfileUpdate(tx *db.ClusterTx, projectName, profileName string, req api.ProfilePut) error

AllowProfileUpdate checks that project limits and restrictions are not violated when changing a profile.

func AllowProjectUpdate

func AllowProjectUpdate(tx *db.ClusterTx, projectName string, config map[string]string, changed []string) error

AllowProjectUpdate checks the new config to be set on a project is valid.

func AllowSnapshotCreation

func AllowSnapshotCreation(tx *db.ClusterTx, projectName string) error

AllowSnapshotCreation returns an error if any project-specific restriction is violated when creating a new snapshot in a project.

func AllowVolumeCreation

func AllowVolumeCreation(tx *db.ClusterTx, projectName string, req api.StorageVolumesPost) error

AllowVolumeCreation returns an error if any project-specific limit or restriction is violated when creating a new custom volume in a project.

func AllowVolumeUpdate

func AllowVolumeUpdate(tx *db.ClusterTx, projectName, volumeName string, req api.StorageVolumePut, currentConfig map[string]string) error

AllowVolumeUpdate returns an error if any project-specific limit or restriction is violated when updating an existing custom volume.

func CheckClusterTargetRestriction

func CheckClusterTargetRestriction(tx *db.ClusterTx, r *http.Request, projectName string, targetFlag string) error

CheckClusterTargetRestriction check if user is allowed to use cluster member targeting

func DNS

func DNS(projectName string, instanceName string) string

DNS adds ".<project>" as a suffix to instance name when the given project name is not "default".

func FilterUsedBy

func FilterUsedBy(r *http.Request, entries []string) []string

FilterUsedBy filters a UsedBy list based on project access

func GetCurrentAllocations

func GetCurrentAllocations(tx *db.ClusterTx, projectName string) (map[string]api.ProjectStateResource, error)

GetCurrentAllocations returns the current resource utilization for a given project.

func GetImageSpaceBudget

func GetImageSpaceBudget(tx *db.ClusterTx, projectName string) (int64, error)

GetImageSpaceBudget returns how much disk space is left in the given project for writing images.

If no limit is in place, return -1.

func Instance

func Instance(projectName string, instanceName string) string

Instance adds the "<project>_" prefix to instance name when the given project name is not "default".

Example
package main

import (
	"fmt"

	"github.com/lxc/lxd/lxd/project"
)

func main() {
	prefixed := project.Instance(project.Default, "test")
	fmt.Println(prefixed)

	prefixed = project.Instance("project_name", "test1")
	fmt.Println(prefixed)
}
Output:

test
project_name_test1

func InstanceParts

func InstanceParts(projectInstanceName string) (string, string)

InstanceParts takes a project prefixed Instance name string and returns the project and instance name. If a non-project prefixed Instance name is supplied, then the project is returned as "default" and the instance name is returned unmodified in the 2nd return value. This is suitable for passing back into Prefix(). Note: This should only be used with Instance names (because they cannot contain the project separator) and this function relies on this rule as project names can contain the project separator.

Example
package main

import (
	"fmt"

	"github.com/lxc/lxd/lxd/project"
)

func main() {
	projectName, name := project.InstanceParts("unprefixed")
	fmt.Println(projectName, name)

	projectName, name = project.InstanceParts(project.Instance(project.Default, "test"))
	fmt.Println(projectName, name)

	projectName, name = project.InstanceParts("project_name_test")
	fmt.Println(projectName, name)

	projectName, name = project.InstanceParts(project.Instance("proj", "test1"))
	fmt.Println(projectName, name)

}
Output:

default unprefixed
default test
project_name test
proj test1

func NetworkProject

func NetworkProject(c *db.Cluster, projectName string) (string, map[string]string, error)

NetworkProject returns the project name to use for the network based on the requested project. If the project specified has the "features.networks" flag enabled then the project name is returned, otherwise the default project name is returned. The second return value is the project's config if non-default project is being returned, nil if not.

func NetworkProjectFromRecord

func NetworkProjectFromRecord(p *api.Project) string

NetworkProjectFromRecord returns the project name to use for the network based on the supplied project. If the project supplied has the "features.networks" flag enabled then the project name is returned, otherwise the default project name is returned.

func ProfileProject

func ProfileProject(c *db.Cluster, projectName string) (string, map[string]string, error)

ProfileProject returns the project name to use for the profile based on the requested project. If the project specified has the "features.profiles" flag enabled then the project name is returned, otherwise the default project name is returned. The second return value is the project's config if non-default project is being returned, nil if not.

func ProfileProjectFromRecord

func ProfileProjectFromRecord(p *api.Project) string

ProfileProjectFromRecord returns the project name to use for the profile based on the supplied project. If the project supplied has the "features.profiles" flag enabled then the project name is returned, otherwise the default project name is returned.

func StorageVolume

func StorageVolume(projectName string, storageVolumeName string) string

StorageVolume adds the "<project>_prefix" to the storage volume name. Even if the project name is "default".

Example
package main

import (
	"fmt"

	"github.com/lxc/lxd/lxd/project"
)

func main() {
	prefixed := project.StorageVolume(project.Default, "test")
	fmt.Println(prefixed)

	prefixed = project.StorageVolume("project_name", "test1")
	fmt.Println(prefixed)
}
Output:

default_test
project_name_test1

func StorageVolumeParts

func StorageVolumeParts(projectStorageVolumeName string) (string, string)

StorageVolumeParts takes a project prefixed storage volume name and returns the project and storage volume name as separate variables.

func StorageVolumeProject

func StorageVolumeProject(c *db.Cluster, projectName string, volumeType int) (string, error)

StorageVolumeProject returns the project name to use to for the volume based on the requested project. For custom volume type, if the project specified has the "features.storage.volumes" flag enabled then the project name is returned, otherwise the default project name is returned. For all other volume types the supplied project name is returned.

func StorageVolumeProjectFromRecord

func StorageVolumeProjectFromRecord(p *api.Project, volumeType int) string

StorageVolumeProjectFromRecord returns the project name to use to for the volume based on the supplied project. For custom volume type, if the project supplied has the "features.storage.volumes" flag enabled then the project name is returned, otherwise the default project name is returned. For all other volume types the supplied project's name is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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