project

package
v0.0.0-...-ff4e629 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRestrictedDevicesDiskPaths

func CheckRestrictedDevicesDiskPaths(projectConfig map[string]string, sourcePath string) (bool, string)

CheckRestrictedDevicesDiskPaths checks whether the disk's source path is within the allowed paths specified in the project's restricted.devices.disk.paths config setting. If no allowed paths are specified in project, then it allows all paths, and returns true and empty string. If allowed paths are specified, and one matches, returns true and the matching allowed parent source path. Otherwise if sourcePath not allowed returns false and empty string.

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(authorizer auth.Authorizer, r *http.Request, entries []string) []string

FilterUsedBy filters a UsedBy list based on the entities that the requestor is able to view.

func ImageProject

func ImageProject(ctx context.Context, tx *sql.Tx, requestProjectName string) (string, error)

ImageProject returns the effective project for images based on the value of `features.images` in the given project.

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/canonical/lxd/lxd/project"
	"github.com/canonical/lxd/shared/api"
)

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

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

test
project_name_test1

func InstanceParts

func InstanceParts(projectInstanceName string) (projectName string, instanceName 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 Instance(). 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/canonical/lxd/lxd/project"
	"github.com/canonical/lxd/shared/api"
)

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

	projectName, name = project.InstanceParts(project.Instance(api.ProjectDefaultName, "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 NetworkAllowed

func NetworkAllowed(reqProjectConfig map[string]string, networkName string, isManaged bool) bool

NetworkAllowed returns whether access is allowed to a particular network based on projectConfig.

func NetworkProject

func NetworkProject(c *db.Cluster, projectName string) (string, *api.Project, error)

NetworkProject returns the effective project name to use for the network based on the requested project. If the requested project has the "features.networks" flag enabled then the requested project's name is returned, otherwise the default project name is returned. The second return value is always the requested project's info.

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 NetworkZoneProject

func NetworkZoneProject(c *db.Cluster, projectName string) (string, *api.Project, error)

NetworkZoneProject returns the effective project name to use for network zone based on the requested project. If the requested project has the "features.networks.zones" flag enabled then the requested project's name is returned, otherwise the default project name is returned. The second return value is always the requested project's info.

func NetworkZoneProjectFromRecord

func NetworkZoneProjectFromRecord(p *api.Project) string

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

func ProfileProject

func ProfileProject(c *db.Cluster, projectName string) (*api.Project, error)

ProfileProject returns the effective project to use for the profile based on the requested project. If the requested project has the "features.profiles" flag enabled then the requested project's info is returned, otherwise the default project's info is returned.

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 StorageBucketProject

func StorageBucketProject(ctx context.Context, c *db.Cluster, projectName string) (string, error)

StorageBucketProject returns the effective project name to use to for the bucket based on the requested project. If the project specified has the "features.storage.buckets" flag enabled then the project name is returned, otherwise the default project name is returned.

func StorageBucketProjectFromRecord

func StorageBucketProjectFromRecord(p *api.Project) string

StorageBucketProjectFromRecord returns the project name to use to for the bucket based on the supplied project. If the project supplied has the "features.storage.buckets" 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/canonical/lxd/lxd/project"
	"github.com/canonical/lxd/shared/api"
)

func main() {
	prefixed := project.StorageVolume(api.ProjectDefaultName, "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) (projectName string, storageVolumeName 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 image volume types the default project is always returned. 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 image volume types the default project is always returned. 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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