repo stringlengths 5 67 | path stringlengths 4 218 | func_name stringlengths 0 151 | original_string stringlengths 52 373k | language stringclasses 6
values | code stringlengths 52 373k | code_tokens listlengths 10 512 | docstring stringlengths 3 47.2k | docstring_tokens listlengths 3 234 | sha stringlengths 40 40 | url stringlengths 85 339 | partition stringclasses 3
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
lxc/lxd | client/lxd_containers.go | GetContainerTemplateFiles | func (r *ProtocolLXD) GetContainerTemplateFiles(containerName string) ([]string, error) {
if !r.HasExtension("container_edit_metadata") {
return nil, fmt.Errorf("The server is missing the required \"container_edit_metadata\" API extension")
}
templates := []string{}
url := fmt.Sprintf("/containers/%s/metadata/t... | go | func (r *ProtocolLXD) GetContainerTemplateFiles(containerName string) ([]string, error) {
if !r.HasExtension("container_edit_metadata") {
return nil, fmt.Errorf("The server is missing the required \"container_edit_metadata\" API extension")
}
templates := []string{}
url := fmt.Sprintf("/containers/%s/metadata/t... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetContainerTemplateFiles",
"(",
"containerName",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"container_edit_metadata\"",
")",
"{",
"return",
"nil",
... | // GetContainerTemplateFiles returns the list of names of template files for a container. | [
"GetContainerTemplateFiles",
"returns",
"the",
"list",
"of",
"names",
"of",
"template",
"files",
"for",
"a",
"container",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1503-L1517 | test |
lxc/lxd | client/lxd_containers.go | CreateContainerTemplateFile | func (r *ProtocolLXD) CreateContainerTemplateFile(containerName string, templateName string, content io.ReadSeeker) error {
return r.setContainerTemplateFile(containerName, templateName, content, "POST")
} | go | func (r *ProtocolLXD) CreateContainerTemplateFile(containerName string, templateName string, content io.ReadSeeker) error {
return r.setContainerTemplateFile(containerName, templateName, content, "POST")
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"CreateContainerTemplateFile",
"(",
"containerName",
"string",
",",
"templateName",
"string",
",",
"content",
"io",
".",
"ReadSeeker",
")",
"error",
"{",
"return",
"r",
".",
"setContainerTemplateFile",
"(",
"containerName... | // CreateContainerTemplateFile creates an a template for a container. | [
"CreateContainerTemplateFile",
"creates",
"an",
"a",
"template",
"for",
"a",
"container",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1560-L1562 | test |
lxc/lxd | client/lxd_containers.go | DeleteContainerTemplateFile | func (r *ProtocolLXD) DeleteContainerTemplateFile(name string, templateName string) error {
if !r.HasExtension("container_edit_metadata") {
return fmt.Errorf("The server is missing the required \"container_edit_metadata\" API extension")
}
_, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/metadata/templat... | go | func (r *ProtocolLXD) DeleteContainerTemplateFile(name string, templateName string) error {
if !r.HasExtension("container_edit_metadata") {
return fmt.Errorf("The server is missing the required \"container_edit_metadata\" API extension")
}
_, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/metadata/templat... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"DeleteContainerTemplateFile",
"(",
"name",
"string",
",",
"templateName",
"string",
")",
"error",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"container_edit_metadata\"",
")",
"{",
"return",
"fmt",
".",
"Errorf"... | // DeleteContainerTemplateFile deletes a template file for a container. | [
"DeleteContainerTemplateFile",
"deletes",
"a",
"template",
"file",
"for",
"a",
"container",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1605-L1611 | test |
lxc/lxd | client/lxd_containers.go | ConsoleContainer | func (r *ProtocolLXD) ConsoleContainer(containerName string, console api.ContainerConsolePost, args *ContainerConsoleArgs) (Operation, error) {
if !r.HasExtension("console") {
return nil, fmt.Errorf("The server is missing the required \"console\" API extension")
}
// Send the request
op, _, err := r.queryOperati... | go | func (r *ProtocolLXD) ConsoleContainer(containerName string, console api.ContainerConsolePost, args *ContainerConsoleArgs) (Operation, error) {
if !r.HasExtension("console") {
return nil, fmt.Errorf("The server is missing the required \"console\" API extension")
}
// Send the request
op, _, err := r.queryOperati... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"ConsoleContainer",
"(",
"containerName",
"string",
",",
"console",
"api",
".",
"ContainerConsolePost",
",",
"args",
"*",
"ContainerConsoleArgs",
")",
"(",
"Operation",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
... | // ConsoleContainer requests that LXD attaches to the console device of a container. | [
"ConsoleContainer",
"requests",
"that",
"LXD",
"attaches",
"to",
"the",
"console",
"device",
"of",
"a",
"container",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1614-L1681 | test |
lxc/lxd | client/lxd_containers.go | GetContainerConsoleLog | func (r *ProtocolLXD) GetContainerConsoleLog(containerName string, args *ContainerConsoleLogArgs) (io.ReadCloser, error) {
if !r.HasExtension("console") {
return nil, fmt.Errorf("The server is missing the required \"console\" API extension")
}
// Prepare the HTTP request
url := fmt.Sprintf("%s/1.0/containers/%s/... | go | func (r *ProtocolLXD) GetContainerConsoleLog(containerName string, args *ContainerConsoleLogArgs) (io.ReadCloser, error) {
if !r.HasExtension("console") {
return nil, fmt.Errorf("The server is missing the required \"console\" API extension")
}
// Prepare the HTTP request
url := fmt.Sprintf("%s/1.0/containers/%s/... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetContainerConsoleLog",
"(",
"containerName",
"string",
",",
"args",
"*",
"ContainerConsoleLogArgs",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"console\... | // GetContainerConsoleLog requests that LXD attaches to the console device of a container.
//
// Note that it's the caller's responsibility to close the returned ReadCloser | [
"GetContainerConsoleLog",
"requests",
"that",
"LXD",
"attaches",
"to",
"the",
"console",
"device",
"of",
"a",
"container",
".",
"Note",
"that",
"it",
"s",
"the",
"caller",
"s",
"responsibility",
"to",
"close",
"the",
"returned",
"ReadCloser"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1686-L1724 | test |
lxc/lxd | client/lxd_containers.go | DeleteContainerConsoleLog | func (r *ProtocolLXD) DeleteContainerConsoleLog(containerName string, args *ContainerConsoleLogArgs) error {
if !r.HasExtension("console") {
return fmt.Errorf("The server is missing the required \"console\" API extension")
}
// Send the request
_, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/console",... | go | func (r *ProtocolLXD) DeleteContainerConsoleLog(containerName string, args *ContainerConsoleLogArgs) error {
if !r.HasExtension("console") {
return fmt.Errorf("The server is missing the required \"console\" API extension")
}
// Send the request
_, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/console",... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"DeleteContainerConsoleLog",
"(",
"containerName",
"string",
",",
"args",
"*",
"ContainerConsoleLogArgs",
")",
"error",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"console\"",
")",
"{",
"return",
"fmt",
".",
"... | // DeleteContainerConsoleLog deletes the requested container's console log | [
"DeleteContainerConsoleLog",
"deletes",
"the",
"requested",
"container",
"s",
"console",
"log"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1727-L1739 | test |
lxc/lxd | client/lxd_containers.go | GetContainerBackups | func (r *ProtocolLXD) GetContainerBackups(containerName string) ([]api.ContainerBackup, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Fetch the raw value
backups := []api.ContainerBackup{}
_, err := r.query... | go | func (r *ProtocolLXD) GetContainerBackups(containerName string) ([]api.ContainerBackup, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Fetch the raw value
backups := []api.ContainerBackup{}
_, err := r.query... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetContainerBackups",
"(",
"containerName",
"string",
")",
"(",
"[",
"]",
"api",
".",
"ContainerBackup",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"container_backup\"",
")",
"{",
"return... | // GetContainerBackups returns a list of backups for the container | [
"GetContainerBackups",
"returns",
"a",
"list",
"of",
"backups",
"for",
"the",
"container"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1767-L1781 | test |
lxc/lxd | client/lxd_containers.go | GetContainerBackup | func (r *ProtocolLXD) GetContainerBackup(containerName string, name string) (*api.ContainerBackup, string, error) {
if !r.HasExtension("container_backup") {
return nil, "", fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Fetch the raw value
backup := api.ContainerBackup{}... | go | func (r *ProtocolLXD) GetContainerBackup(containerName string, name string) (*api.ContainerBackup, string, error) {
if !r.HasExtension("container_backup") {
return nil, "", fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Fetch the raw value
backup := api.ContainerBackup{}... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetContainerBackup",
"(",
"containerName",
"string",
",",
"name",
"string",
")",
"(",
"*",
"api",
".",
"ContainerBackup",
",",
"string",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"cont... | // GetContainerBackup returns a Backup struct for the provided container and backup names | [
"GetContainerBackup",
"returns",
"a",
"Backup",
"struct",
"for",
"the",
"provided",
"container",
"and",
"backup",
"names"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1784-L1797 | test |
lxc/lxd | client/lxd_containers.go | CreateContainerBackup | func (r *ProtocolLXD) CreateContainerBackup(containerName string, backup api.ContainerBackupsPost) (Operation, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Send the request
op, _, err := r.queryOperation("PO... | go | func (r *ProtocolLXD) CreateContainerBackup(containerName string, backup api.ContainerBackupsPost) (Operation, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Send the request
op, _, err := r.queryOperation("PO... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"CreateContainerBackup",
"(",
"containerName",
"string",
",",
"backup",
"api",
".",
"ContainerBackupsPost",
")",
"(",
"Operation",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"container_backup\... | // CreateContainerBackup requests that LXD creates a new backup for the container | [
"CreateContainerBackup",
"requests",
"that",
"LXD",
"creates",
"a",
"new",
"backup",
"for",
"the",
"container"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1800-L1813 | test |
lxc/lxd | client/lxd_containers.go | RenameContainerBackup | func (r *ProtocolLXD) RenameContainerBackup(containerName string, name string, backup api.ContainerBackupPost) (Operation, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Send the request
op, _, err := r.queryO... | go | func (r *ProtocolLXD) RenameContainerBackup(containerName string, name string, backup api.ContainerBackupPost) (Operation, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Send the request
op, _, err := r.queryO... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"RenameContainerBackup",
"(",
"containerName",
"string",
",",
"name",
"string",
",",
"backup",
"api",
".",
"ContainerBackupPost",
")",
"(",
"Operation",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
... | // RenameContainerBackup requests that LXD renames the backup | [
"RenameContainerBackup",
"requests",
"that",
"LXD",
"renames",
"the",
"backup"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1816-L1829 | test |
lxc/lxd | client/lxd_containers.go | DeleteContainerBackup | func (r *ProtocolLXD) DeleteContainerBackup(containerName string, name string) (Operation, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Send the request
op, _, err := r.queryOperation("DELETE", fmt.Sprintf("... | go | func (r *ProtocolLXD) DeleteContainerBackup(containerName string, name string) (Operation, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Send the request
op, _, err := r.queryOperation("DELETE", fmt.Sprintf("... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"DeleteContainerBackup",
"(",
"containerName",
"string",
",",
"name",
"string",
")",
"(",
"Operation",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"container_backup\"",
")",
"{",
"return",
... | // DeleteContainerBackup requests that LXD deletes the container backup | [
"DeleteContainerBackup",
"requests",
"that",
"LXD",
"deletes",
"the",
"container",
"backup"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1832-L1845 | test |
lxc/lxd | client/lxd_containers.go | GetContainerBackupFile | func (r *ProtocolLXD) GetContainerBackupFile(containerName string, name string, req *BackupFileRequest) (*BackupFileResponse, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Build the URL
uri := fmt.Sprintf("%s... | go | func (r *ProtocolLXD) GetContainerBackupFile(containerName string, name string, req *BackupFileRequest) (*BackupFileResponse, error) {
if !r.HasExtension("container_backup") {
return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension")
}
// Build the URL
uri := fmt.Sprintf("%s... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetContainerBackupFile",
"(",
"containerName",
"string",
",",
"name",
"string",
",",
"req",
"*",
"BackupFileRequest",
")",
"(",
"*",
"BackupFileResponse",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension"... | // GetContainerBackupFile requests the container backup content | [
"GetContainerBackupFile",
"requests",
"the",
"container",
"backup",
"content"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_containers.go#L1848-L1908 | test |
lxc/lxd | lxd/rsync.go | RsyncSend | func RsyncSend(name string, path string, conn *websocket.Conn, readWrapper func(io.ReadCloser) io.ReadCloser, features []string, bwlimit string, execPath string) error {
cmd, dataSocket, stderr, err := rsyncSendSetup(name, path, bwlimit, execPath, features)
if err != nil {
return err
}
if dataSocket != nil {
d... | go | func RsyncSend(name string, path string, conn *websocket.Conn, readWrapper func(io.ReadCloser) io.ReadCloser, features []string, bwlimit string, execPath string) error {
cmd, dataSocket, stderr, err := rsyncSendSetup(name, path, bwlimit, execPath, features)
if err != nil {
return err
}
if dataSocket != nil {
d... | [
"func",
"RsyncSend",
"(",
"name",
"string",
",",
"path",
"string",
",",
"conn",
"*",
"websocket",
".",
"Conn",
",",
"readWrapper",
"func",
"(",
"io",
".",
"ReadCloser",
")",
"io",
".",
"ReadCloser",
",",
"features",
"[",
"]",
"string",
",",
"bwlimit",
... | // RsyncSend sets up the sending half of an rsync, to recursively send the
// directory pointed to by path over the websocket. | [
"RsyncSend",
"sets",
"up",
"the",
"sending",
"half",
"of",
"an",
"rsync",
"to",
"recursively",
"send",
"the",
"directory",
"pointed",
"to",
"by",
"path",
"over",
"the",
"websocket",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/rsync.go#L172-L213 | test |
lxc/lxd | lxd/patches.go | patchesGetNames | func patchesGetNames() []string {
names := make([]string, len(patches))
for i, patch := range patches {
names[i] = patch.name
}
return names
} | go | func patchesGetNames() []string {
names := make([]string, len(patches))
for i, patch := range patches {
names[i] = patch.name
}
return names
} | [
"func",
"patchesGetNames",
"(",
")",
"[",
"]",
"string",
"{",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"patches",
")",
")",
"\n",
"for",
"i",
",",
"patch",
":=",
"range",
"patches",
"{",
"names",
"[",
"i",
"]",
"=",
"patch... | // Return the names of all available patches. | [
"Return",
"the",
"names",
"of",
"all",
"available",
"patches",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/patches.go#L96-L102 | test |
lxc/lxd | lxd/patches.go | patchRenameCustomVolumeLVs | func patchRenameCustomVolumeLVs(name string, d *Daemon) error {
// Ignore the error since it will also fail if there are no pools.
pools, _ := d.cluster.StoragePools()
for _, poolName := range pools {
poolID, pool, err := d.cluster.StoragePoolGet(poolName)
if err != nil {
return err
}
sType, err := stor... | go | func patchRenameCustomVolumeLVs(name string, d *Daemon) error {
// Ignore the error since it will also fail if there are no pools.
pools, _ := d.cluster.StoragePools()
for _, poolName := range pools {
poolID, pool, err := d.cluster.StoragePoolGet(poolName)
if err != nil {
return err
}
sType, err := stor... | [
"func",
"patchRenameCustomVolumeLVs",
"(",
"name",
"string",
",",
"d",
"*",
"Daemon",
")",
"error",
"{",
"pools",
",",
"_",
":=",
"d",
".",
"cluster",
".",
"StoragePools",
"(",
")",
"\n",
"for",
"_",
",",
"poolName",
":=",
"range",
"pools",
"{",
"poolI... | // Patches begin here | [
"Patches",
"begin",
"here"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/patches.go#L125-L177 | test |
lxc/lxd | lxd/patches.go | patchLvmNodeSpecificConfigKeys | func patchLvmNodeSpecificConfigKeys(name string, d *Daemon) error {
tx, err := d.cluster.Begin()
if err != nil {
return errors.Wrap(err, "failed to begin transaction")
}
// Fetch the IDs of all existing nodes.
nodeIDs, err := query.SelectIntegers(tx, "SELECT id FROM nodes")
if err != nil {
return errors.Wrap... | go | func patchLvmNodeSpecificConfigKeys(name string, d *Daemon) error {
tx, err := d.cluster.Begin()
if err != nil {
return errors.Wrap(err, "failed to begin transaction")
}
// Fetch the IDs of all existing nodes.
nodeIDs, err := query.SelectIntegers(tx, "SELECT id FROM nodes")
if err != nil {
return errors.Wrap... | [
"func",
"patchLvmNodeSpecificConfigKeys",
"(",
"name",
"string",
",",
"d",
"*",
"Daemon",
")",
"error",
"{",
"tx",
",",
"err",
":=",
"d",
".",
"cluster",
".",
"Begin",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(... | // The lvm.thinpool_name and lvm.vg_name config keys are node-specific and need
// to be linked to nodes. | [
"The",
"lvm",
".",
"thinpool_name",
"and",
"lvm",
".",
"vg_name",
"config",
"keys",
"are",
"node",
"-",
"specific",
"and",
"need",
"to",
"be",
"linked",
"to",
"nodes",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/patches.go#L2123-L2183 | test |
lxc/lxd | client/lxd.go | GetHTTPClient | func (r *ProtocolLXD) GetHTTPClient() (*http.Client, error) {
if r.http == nil {
return nil, fmt.Errorf("HTTP client isn't set, bad connection")
}
return r.http, nil
} | go | func (r *ProtocolLXD) GetHTTPClient() (*http.Client, error) {
if r.http == nil {
return nil, fmt.Errorf("HTTP client isn't set, bad connection")
}
return r.http, nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetHTTPClient",
"(",
")",
"(",
"*",
"http",
".",
"Client",
",",
"error",
")",
"{",
"if",
"r",
".",
"http",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"HTTP client isn't set, bad conn... | // GetHTTPClient returns the http client used for the connection. This can be used to set custom http options. | [
"GetHTTPClient",
"returns",
"the",
"http",
"client",
"used",
"for",
"the",
"connection",
".",
"This",
"can",
"be",
"used",
"to",
"set",
"custom",
"http",
"options",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd.go#L76-L82 | test |
lxc/lxd | client/lxd.go | do | func (r *ProtocolLXD) do(req *http.Request) (*http.Response, error) {
if r.bakeryClient != nil {
r.addMacaroonHeaders(req)
return r.bakeryClient.Do(req)
}
return r.http.Do(req)
} | go | func (r *ProtocolLXD) do(req *http.Request) (*http.Response, error) {
if r.bakeryClient != nil {
r.addMacaroonHeaders(req)
return r.bakeryClient.Do(req)
}
return r.http.Do(req)
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"do",
"(",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"if",
"r",
".",
"bakeryClient",
"!=",
"nil",
"{",
"r",
".",
"addMacaroonHeaders",
"(",
"req",
... | // Do performs a Request, using macaroon authentication if set. | [
"Do",
"performs",
"a",
"Request",
"using",
"macaroon",
"authentication",
"if",
"set",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd.go#L85-L92 | test |
lxc/lxd | client/lxd.go | RawQuery | func (r *ProtocolLXD) RawQuery(method string, path string, data interface{}, ETag string) (*api.Response, string, error) {
// Generate the URL
url := fmt.Sprintf("%s%s", r.httpHost, path)
return r.rawQuery(method, url, data, ETag)
} | go | func (r *ProtocolLXD) RawQuery(method string, path string, data interface{}, ETag string) (*api.Response, string, error) {
// Generate the URL
url := fmt.Sprintf("%s%s", r.httpHost, path)
return r.rawQuery(method, url, data, ETag)
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"RawQuery",
"(",
"method",
"string",
",",
"path",
"string",
",",
"data",
"interface",
"{",
"}",
",",
"ETag",
"string",
")",
"(",
"*",
"api",
".",
"Response",
",",
"string",
",",
"error",
")",
"{",
"url",
"... | // RawQuery allows directly querying the LXD API
//
// This should only be used by internal LXD tools. | [
"RawQuery",
"allows",
"directly",
"querying",
"the",
"LXD",
"API",
"This",
"should",
"only",
"be",
"used",
"by",
"internal",
"LXD",
"tools",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd.go#L110-L115 | test |
lxc/lxd | client/lxd.go | RawWebsocket | func (r *ProtocolLXD) RawWebsocket(path string) (*websocket.Conn, error) {
return r.websocket(path)
} | go | func (r *ProtocolLXD) RawWebsocket(path string) (*websocket.Conn, error) {
return r.websocket(path)
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"RawWebsocket",
"(",
"path",
"string",
")",
"(",
"*",
"websocket",
".",
"Conn",
",",
"error",
")",
"{",
"return",
"r",
".",
"websocket",
"(",
"path",
")",
"\n",
"}"
] | // RawWebsocket allows directly connection to LXD API websockets
//
// This should only be used by internal LXD tools. | [
"RawWebsocket",
"allows",
"directly",
"connection",
"to",
"LXD",
"API",
"websockets",
"This",
"should",
"only",
"be",
"used",
"by",
"internal",
"LXD",
"tools",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd.go#L120-L122 | test |
lxc/lxd | client/lxd.go | RawOperation | func (r *ProtocolLXD) RawOperation(method string, path string, data interface{}, ETag string) (Operation, string, error) {
return r.queryOperation(method, path, data, ETag)
} | go | func (r *ProtocolLXD) RawOperation(method string, path string, data interface{}, ETag string) (Operation, string, error) {
return r.queryOperation(method, path, data, ETag)
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"RawOperation",
"(",
"method",
"string",
",",
"path",
"string",
",",
"data",
"interface",
"{",
"}",
",",
"ETag",
"string",
")",
"(",
"Operation",
",",
"string",
",",
"error",
")",
"{",
"return",
"r",
".",
"q... | // RawOperation allows direct querying of a LXD API endpoint returning
// background operations. | [
"RawOperation",
"allows",
"direct",
"querying",
"of",
"a",
"LXD",
"API",
"endpoint",
"returning",
"background",
"operations",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd.go#L126-L128 | test |
lxc/lxd | lxd/db/profiles.go | ProfileToAPI | func ProfileToAPI(profile *Profile) *api.Profile {
p := &api.Profile{
Name: profile.Name,
UsedBy: profile.UsedBy,
}
p.Description = profile.Description
p.Config = profile.Config
p.Devices = profile.Devices
return p
} | go | func ProfileToAPI(profile *Profile) *api.Profile {
p := &api.Profile{
Name: profile.Name,
UsedBy: profile.UsedBy,
}
p.Description = profile.Description
p.Config = profile.Config
p.Devices = profile.Devices
return p
} | [
"func",
"ProfileToAPI",
"(",
"profile",
"*",
"Profile",
")",
"*",
"api",
".",
"Profile",
"{",
"p",
":=",
"&",
"api",
".",
"Profile",
"{",
"Name",
":",
"profile",
".",
"Name",
",",
"UsedBy",
":",
"profile",
".",
"UsedBy",
",",
"}",
"\n",
"p",
".",
... | // ProfileToAPI is a convenience to convert a Profile db struct into
// an API profile struct. | [
"ProfileToAPI",
"is",
"a",
"convenience",
"to",
"convert",
"a",
"Profile",
"db",
"struct",
"into",
"an",
"API",
"profile",
"struct",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L64-L74 | test |
lxc/lxd | lxd/db/profiles.go | Profiles | func (c *Cluster) Profiles(project string) ([]string, error) {
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !enabled {
project = "default"
}
return nil
})
if err != nil {... | go | func (c *Cluster) Profiles(project string) ([]string, error) {
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !enabled {
project = "default"
}
return nil
})
if err != nil {... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"Profiles",
"(",
"project",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"err",
":=",
"c",
".",
"Transaction",
"(",
"func",
"(",
"tx",
"*",
"ClusterTx",
")",
"error",
"{",
"enabled",
",",
... | // Profiles returns a string list of profiles. | [
"Profiles",
"returns",
"a",
"string",
"list",
"of",
"profiles",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L83-L118 | test |
lxc/lxd | lxd/db/profiles.go | ProfileGet | func (c *Cluster) ProfileGet(project, name string) (int64, *api.Profile, error) {
var result *api.Profile
var id int64
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !enabled {
... | go | func (c *Cluster) ProfileGet(project, name string) (int64, *api.Profile, error) {
var result *api.Profile
var id int64
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !enabled {
... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"ProfileGet",
"(",
"project",
",",
"name",
"string",
")",
"(",
"int64",
",",
"*",
"api",
".",
"Profile",
",",
"error",
")",
"{",
"var",
"result",
"*",
"api",
".",
"Profile",
"\n",
"var",
"id",
"int64",
"\n",
... | // ProfileGet returns the profile with the given name. | [
"ProfileGet",
"returns",
"the",
"profile",
"with",
"the",
"given",
"name",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L121-L149 | test |
lxc/lxd | lxd/db/profiles.go | ProfilesGet | func (c *Cluster) ProfilesGet(project string, names []string) ([]api.Profile, error) {
profiles := make([]api.Profile, len(names))
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !... | go | func (c *Cluster) ProfilesGet(project string, names []string) ([]api.Profile, error) {
profiles := make([]api.Profile, len(names))
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"ProfilesGet",
"(",
"project",
"string",
",",
"names",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"api",
".",
"Profile",
",",
"error",
")",
"{",
"profiles",
":=",
"make",
"(",
"[",
"]",
"api",
".",
"Profile",
"... | // ProfilesGet returns the profiles with the given names in the given project. | [
"ProfilesGet",
"returns",
"the",
"profiles",
"with",
"the",
"given",
"names",
"in",
"the",
"given",
"project",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L152-L179 | test |
lxc/lxd | lxd/db/profiles.go | ProfileConfig | func (c *Cluster) ProfileConfig(project, name string) (map[string]string, error) {
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !enabled {
project = "default"
}
return nil
... | go | func (c *Cluster) ProfileConfig(project, name string) (map[string]string, error) {
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !enabled {
project = "default"
}
return nil
... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"ProfileConfig",
"(",
"project",
",",
"name",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"err",
":=",
"c",
".",
"Transaction",
"(",
"func",
"(",
"tx",
"*",
"ClusterTx",
")... | // ProfileConfig gets the profile configuration map from the DB. | [
"ProfileConfig",
"gets",
"the",
"profile",
"configuration",
"map",
"from",
"the",
"DB",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L182-L239 | test |
lxc/lxd | lxd/db/profiles.go | ProfileConfigClear | func ProfileConfigClear(tx *sql.Tx, id int64) error {
_, err := tx.Exec("DELETE FROM profiles_config WHERE profile_id=?", id)
if err != nil {
return err
}
_, err = tx.Exec(`DELETE FROM profiles_devices_config WHERE id IN
(SELECT profiles_devices_config.id
FROM profiles_devices_config JOIN profiles_devices
... | go | func ProfileConfigClear(tx *sql.Tx, id int64) error {
_, err := tx.Exec("DELETE FROM profiles_config WHERE profile_id=?", id)
if err != nil {
return err
}
_, err = tx.Exec(`DELETE FROM profiles_devices_config WHERE id IN
(SELECT profiles_devices_config.id
FROM profiles_devices_config JOIN profiles_devices
... | [
"func",
"ProfileConfigClear",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"id",
"int64",
")",
"error",
"{",
"_",
",",
"err",
":=",
"tx",
".",
"Exec",
"(",
"\"DELETE FROM profiles_config WHERE profile_id=?\"",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{... | // ProfileConfigClear resets the config of the profile with the given ID. | [
"ProfileConfigClear",
"resets",
"the",
"config",
"of",
"the",
"profile",
"with",
"the",
"given",
"ID",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L248-L267 | test |
lxc/lxd | lxd/db/profiles.go | ProfileConfigAdd | func ProfileConfigAdd(tx *sql.Tx, id int64, config map[string]string) error {
str := fmt.Sprintf("INSERT INTO profiles_config (profile_id, key, value) VALUES(?, ?, ?)")
stmt, err := tx.Prepare(str)
defer stmt.Close()
if err != nil {
return err
}
for k, v := range config {
if v == "" {
continue
}
_, e... | go | func ProfileConfigAdd(tx *sql.Tx, id int64, config map[string]string) error {
str := fmt.Sprintf("INSERT INTO profiles_config (profile_id, key, value) VALUES(?, ?, ?)")
stmt, err := tx.Prepare(str)
defer stmt.Close()
if err != nil {
return err
}
for k, v := range config {
if v == "" {
continue
}
_, e... | [
"func",
"ProfileConfigAdd",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"id",
"int64",
",",
"config",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"str",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"INSERT INTO profiles_config (profile_id, key, value) VALUES(?, ?,... | // ProfileConfigAdd adds a config to the profile with the given ID. | [
"ProfileConfigAdd",
"adds",
"a",
"config",
"to",
"the",
"profile",
"with",
"the",
"given",
"ID",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L270-L290 | test |
lxc/lxd | lxd/db/profiles.go | ProfileContainersGet | func (c *Cluster) ProfileContainersGet(project, profile string) (map[string][]string, error) {
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !enabled {
project = "default"
}
... | go | func (c *Cluster) ProfileContainersGet(project, profile string) (map[string][]string, error) {
err := c.Transaction(func(tx *ClusterTx) error {
enabled, err := tx.ProjectHasProfiles(project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
}
if !enabled {
project = "default"
}
... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"ProfileContainersGet",
"(",
"project",
",",
"profile",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
",",
"error",
")",
"{",
"err",
":=",
"c",
".",
"Transaction",
"(",
"func",
"(",
"tx",
... | // ProfileContainersGet gets the names of the containers associated with the
// profile with the given name. | [
"ProfileContainersGet",
"gets",
"the",
"names",
"of",
"the",
"containers",
"associated",
"with",
"the",
"profile",
"with",
"the",
"given",
"name",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L294-L337 | test |
lxc/lxd | lxd/db/profiles.go | ProfileCleanupLeftover | func (c *Cluster) ProfileCleanupLeftover() error {
stmt := `
DELETE FROM profiles_config WHERE profile_id NOT IN (SELECT id FROM profiles);
DELETE FROM profiles_devices WHERE profile_id NOT IN (SELECT id FROM profiles);
DELETE FROM profiles_devices_config WHERE profile_device_id NOT IN (SELECT id FROM profiles_devices... | go | func (c *Cluster) ProfileCleanupLeftover() error {
stmt := `
DELETE FROM profiles_config WHERE profile_id NOT IN (SELECT id FROM profiles);
DELETE FROM profiles_devices WHERE profile_id NOT IN (SELECT id FROM profiles);
DELETE FROM profiles_devices_config WHERE profile_device_id NOT IN (SELECT id FROM profiles_devices... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"ProfileCleanupLeftover",
"(",
")",
"error",
"{",
"stmt",
":=",
"`DELETE FROM profiles_config WHERE profile_id NOT IN (SELECT id FROM profiles);DELETE FROM profiles_devices WHERE profile_id NOT IN (SELECT id FROM profiles);DELETE FROM profiles_devices... | // ProfileCleanupLeftover removes unreferenced profiles. | [
"ProfileCleanupLeftover",
"removes",
"unreferenced",
"profiles",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L340-L352 | test |
lxc/lxd | lxd/db/profiles.go | ProfilesExpandConfig | func ProfilesExpandConfig(config map[string]string, profiles []api.Profile) map[string]string {
expandedConfig := map[string]string{}
// Apply all the profiles
profileConfigs := make([]map[string]string, len(profiles))
for i, profile := range profiles {
profileConfigs[i] = profile.Config
}
for i := range prof... | go | func ProfilesExpandConfig(config map[string]string, profiles []api.Profile) map[string]string {
expandedConfig := map[string]string{}
// Apply all the profiles
profileConfigs := make([]map[string]string, len(profiles))
for i, profile := range profiles {
profileConfigs[i] = profile.Config
}
for i := range prof... | [
"func",
"ProfilesExpandConfig",
"(",
"config",
"map",
"[",
"string",
"]",
"string",
",",
"profiles",
"[",
"]",
"api",
".",
"Profile",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"expandedConfig",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
... | // ProfilesExpandConfig expands the given container config with the config
// values of the given profiles. | [
"ProfilesExpandConfig",
"expands",
"the",
"given",
"container",
"config",
"with",
"the",
"config",
"values",
"of",
"the",
"given",
"profiles",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L356-L377 | test |
lxc/lxd | lxd/db/profiles.go | ProfilesExpandDevices | func ProfilesExpandDevices(devices types.Devices, profiles []api.Profile) types.Devices {
expandedDevices := types.Devices{}
// Apply all the profiles
profileDevices := make([]types.Devices, len(profiles))
for i, profile := range profiles {
profileDevices[i] = profile.Devices
}
for i := range profileDevices {
... | go | func ProfilesExpandDevices(devices types.Devices, profiles []api.Profile) types.Devices {
expandedDevices := types.Devices{}
// Apply all the profiles
profileDevices := make([]types.Devices, len(profiles))
for i, profile := range profiles {
profileDevices[i] = profile.Devices
}
for i := range profileDevices {
... | [
"func",
"ProfilesExpandDevices",
"(",
"devices",
"types",
".",
"Devices",
",",
"profiles",
"[",
"]",
"api",
".",
"Profile",
")",
"types",
".",
"Devices",
"{",
"expandedDevices",
":=",
"types",
".",
"Devices",
"{",
"}",
"\n",
"profileDevices",
":=",
"make",
... | // ProfilesExpandDevices expands the given container devices with the devices
// defined in the given profiles. | [
"ProfilesExpandDevices",
"expands",
"the",
"given",
"container",
"devices",
"with",
"the",
"devices",
"defined",
"in",
"the",
"given",
"profiles",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/profiles.go#L381-L401 | test |
lxc/lxd | client/lxd_server.go | GetServer | func (r *ProtocolLXD) GetServer() (*api.Server, string, error) {
server := api.Server{}
// Fetch the raw value
etag, err := r.queryStruct("GET", "", nil, "", &server)
if err != nil {
return nil, "", err
}
// Fill in certificate fingerprint if not provided
if server.Environment.CertificateFingerprint == "" &&... | go | func (r *ProtocolLXD) GetServer() (*api.Server, string, error) {
server := api.Server{}
// Fetch the raw value
etag, err := r.queryStruct("GET", "", nil, "", &server)
if err != nil {
return nil, "", err
}
// Fill in certificate fingerprint if not provided
if server.Environment.CertificateFingerprint == "" &&... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetServer",
"(",
")",
"(",
"*",
"api",
".",
"Server",
",",
"string",
",",
"error",
")",
"{",
"server",
":=",
"api",
".",
"Server",
"{",
"}",
"\n",
"etag",
",",
"err",
":=",
"r",
".",
"queryStruct",
"(",... | // Server handling functions
// GetServer returns the server status as a Server struct | [
"Server",
"handling",
"functions",
"GetServer",
"returns",
"the",
"server",
"status",
"as",
"a",
"Server",
"struct"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_server.go#L13-L40 | test |
lxc/lxd | client/lxd_server.go | UpdateServer | func (r *ProtocolLXD) UpdateServer(server api.ServerPut, ETag string) error {
// Send the request
_, _, err := r.query("PUT", "", server, ETag)
if err != nil {
return err
}
return nil
} | go | func (r *ProtocolLXD) UpdateServer(server api.ServerPut, ETag string) error {
// Send the request
_, _, err := r.query("PUT", "", server, ETag)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"UpdateServer",
"(",
"server",
"api",
".",
"ServerPut",
",",
"ETag",
"string",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"r",
".",
"query",
"(",
"\"PUT\"",
",",
"\"\"",
",",
"server",
",",
"ETag"... | // UpdateServer updates the server status to match the provided Server struct | [
"UpdateServer",
"updates",
"the",
"server",
"status",
"to",
"match",
"the",
"provided",
"Server",
"struct"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_server.go#L43-L51 | test |
lxc/lxd | client/lxd_server.go | HasExtension | func (r *ProtocolLXD) HasExtension(extension string) bool {
// If no cached API information, just assume we're good
// This is needed for those rare cases where we must avoid a GetServer call
if r.server == nil {
return true
}
for _, entry := range r.server.APIExtensions {
if entry == extension {
return tr... | go | func (r *ProtocolLXD) HasExtension(extension string) bool {
// If no cached API information, just assume we're good
// This is needed for those rare cases where we must avoid a GetServer call
if r.server == nil {
return true
}
for _, entry := range r.server.APIExtensions {
if entry == extension {
return tr... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"HasExtension",
"(",
"extension",
"string",
")",
"bool",
"{",
"if",
"r",
".",
"server",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n",
"for",
"_",
",",
"entry",
":=",
"range",
"r",
".",
"server",
"."... | // HasExtension returns true if the server supports a given API extension | [
"HasExtension",
"returns",
"true",
"if",
"the",
"server",
"supports",
"a",
"given",
"API",
"extension"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_server.go#L54-L68 | test |
lxc/lxd | client/lxd_server.go | GetServerResources | func (r *ProtocolLXD) GetServerResources() (*api.Resources, error) {
if !r.HasExtension("resources") {
return nil, fmt.Errorf("The server is missing the required \"resources\" API extension")
}
resources := api.Resources{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/resources", nil, "", &resources)... | go | func (r *ProtocolLXD) GetServerResources() (*api.Resources, error) {
if !r.HasExtension("resources") {
return nil, fmt.Errorf("The server is missing the required \"resources\" API extension")
}
resources := api.Resources{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/resources", nil, "", &resources)... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetServerResources",
"(",
")",
"(",
"*",
"api",
".",
"Resources",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"resources\"",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"("... | // GetServerResources returns the resources available to a given LXD server | [
"GetServerResources",
"returns",
"the",
"resources",
"available",
"to",
"a",
"given",
"LXD",
"server"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_server.go#L76-L90 | test |
lxc/lxd | client/lxd_server.go | UseProject | func (r *ProtocolLXD) UseProject(name string) ContainerServer {
return &ProtocolLXD{
server: r.server,
http: r.http,
httpCertificate: r.httpCertificate,
httpHost: r.httpHost,
httpProtocol: r.httpProtocol,
httpUserAgent: r.httpUserAgent,
bakery... | go | func (r *ProtocolLXD) UseProject(name string) ContainerServer {
return &ProtocolLXD{
server: r.server,
http: r.http,
httpCertificate: r.httpCertificate,
httpHost: r.httpHost,
httpProtocol: r.httpProtocol,
httpUserAgent: r.httpUserAgent,
bakery... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"UseProject",
"(",
"name",
"string",
")",
"ContainerServer",
"{",
"return",
"&",
"ProtocolLXD",
"{",
"server",
":",
"r",
".",
"server",
",",
"http",
":",
"r",
".",
"http",
",",
"httpCertificate",
":",
"r",
"."... | // UseProject returns a client that will use a specific project. | [
"UseProject",
"returns",
"a",
"client",
"that",
"will",
"use",
"a",
"specific",
"project",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_server.go#L93-L107 | test |
lxc/lxd | lxd/db/node/sqlite.go | sqliteOpen | func sqliteOpen(path string) (*sql.DB, error) {
timeout := 5 // TODO - make this command-line configurable?
// These are used to tune the transaction BEGIN behavior instead of using the
// similar "locking_mode" pragma (locking for the whole database connection).
openPath := fmt.Sprintf("%s?_busy_timeout=%d&_txloc... | go | func sqliteOpen(path string) (*sql.DB, error) {
timeout := 5 // TODO - make this command-line configurable?
// These are used to tune the transaction BEGIN behavior instead of using the
// similar "locking_mode" pragma (locking for the whole database connection).
openPath := fmt.Sprintf("%s?_busy_timeout=%d&_txloc... | [
"func",
"sqliteOpen",
"(",
"path",
"string",
")",
"(",
"*",
"sql",
".",
"DB",
",",
"error",
")",
"{",
"timeout",
":=",
"5",
"\n",
"openPath",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%s?_busy_timeout=%d&_txlock=exclusive\"",
",",
"path",
",",
"timeout",
"*",
... | // Opens the node-level database with the correct parameters for LXD. | [
"Opens",
"the",
"node",
"-",
"level",
"database",
"with",
"the",
"correct",
"parameters",
"for",
"LXD",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/node/sqlite.go#L15-L24 | test |
lxc/lxd | lxd/cluster/membership.go | Rebalance | func Rebalance(state *state.State, gateway *Gateway) (string, []db.RaftNode, error) {
// First get the current raft members, since this method should be
// called after a node has left.
currentRaftNodes, err := gateway.currentRaftNodes()
if err != nil {
return "", nil, errors.Wrap(err, "failed to get current raft... | go | func Rebalance(state *state.State, gateway *Gateway) (string, []db.RaftNode, error) {
// First get the current raft members, since this method should be
// called after a node has left.
currentRaftNodes, err := gateway.currentRaftNodes()
if err != nil {
return "", nil, errors.Wrap(err, "failed to get current raft... | [
"func",
"Rebalance",
"(",
"state",
"*",
"state",
".",
"State",
",",
"gateway",
"*",
"Gateway",
")",
"(",
"string",
",",
"[",
"]",
"db",
".",
"RaftNode",
",",
"error",
")",
"{",
"currentRaftNodes",
",",
"err",
":=",
"gateway",
".",
"currentRaftNodes",
"... | // Rebalance the raft cluster, trying to see if we have a spare online node
// that we can promote to database node if we are below membershipMaxRaftNodes.
//
// If there's such spare node, return its address as well as the new list of
// raft nodes. | [
"Rebalance",
"the",
"raft",
"cluster",
"trying",
"to",
"see",
"if",
"we",
"have",
"a",
"spare",
"online",
"node",
"that",
"we",
"can",
"promote",
"to",
"database",
"node",
"if",
"we",
"are",
"below",
"membershipMaxRaftNodes",
".",
"If",
"there",
"s",
"such... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L429-L501 | test |
lxc/lxd | lxd/cluster/membership.go | Promote | func Promote(state *state.State, gateway *Gateway, nodes []db.RaftNode) error {
logger.Info("Promote node to database node")
// Sanity check that this is not already a database node
if gateway.IsDatabaseNode() {
return fmt.Errorf("this node is already a database node")
}
// Figure out our own address.
address... | go | func Promote(state *state.State, gateway *Gateway, nodes []db.RaftNode) error {
logger.Info("Promote node to database node")
// Sanity check that this is not already a database node
if gateway.IsDatabaseNode() {
return fmt.Errorf("this node is already a database node")
}
// Figure out our own address.
address... | [
"func",
"Promote",
"(",
"state",
"*",
"state",
".",
"State",
",",
"gateway",
"*",
"Gateway",
",",
"nodes",
"[",
"]",
"db",
".",
"RaftNode",
")",
"error",
"{",
"logger",
".",
"Info",
"(",
"\"Promote node to database node\"",
")",
"\n",
"if",
"gateway",
".... | // Promote makes a LXD node which is not a database node, become part of the
// raft cluster. | [
"Promote",
"makes",
"a",
"LXD",
"node",
"which",
"is",
"not",
"a",
"database",
"node",
"become",
"part",
"of",
"the",
"raft",
"cluster",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L505-L606 | test |
lxc/lxd | lxd/cluster/membership.go | Purge | func Purge(cluster *db.Cluster, name string) error {
logger.Debugf("Remove node %s from the database", name)
return cluster.Transaction(func(tx *db.ClusterTx) error {
// Get the node (if it doesn't exists an error is returned).
node, err := tx.NodeByName(name)
if err != nil {
return errors.Wrapf(err, "faile... | go | func Purge(cluster *db.Cluster, name string) error {
logger.Debugf("Remove node %s from the database", name)
return cluster.Transaction(func(tx *db.ClusterTx) error {
// Get the node (if it doesn't exists an error is returned).
node, err := tx.NodeByName(name)
if err != nil {
return errors.Wrapf(err, "faile... | [
"func",
"Purge",
"(",
"cluster",
"*",
"db",
".",
"Cluster",
",",
"name",
"string",
")",
"error",
"{",
"logger",
".",
"Debugf",
"(",
"\"Remove node %s from the database\"",
",",
"name",
")",
"\n",
"return",
"cluster",
".",
"Transaction",
"(",
"func",
"(",
"... | // Purge removes a node entirely from the cluster database. | [
"Purge",
"removes",
"a",
"node",
"entirely",
"from",
"the",
"cluster",
"database",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L691-L712 | test |
lxc/lxd | lxd/cluster/membership.go | List | func List(state *state.State) ([]api.ClusterMember, error) {
addresses := []string{} // Addresses of database nodes
err := state.Node.Transaction(func(tx *db.NodeTx) error {
nodes, err := tx.RaftNodes()
if err != nil {
return errors.Wrap(err, "failed to fetch current raft nodes")
}
for _, node := range nod... | go | func List(state *state.State) ([]api.ClusterMember, error) {
addresses := []string{} // Addresses of database nodes
err := state.Node.Transaction(func(tx *db.NodeTx) error {
nodes, err := tx.RaftNodes()
if err != nil {
return errors.Wrap(err, "failed to fetch current raft nodes")
}
for _, node := range nod... | [
"func",
"List",
"(",
"state",
"*",
"state",
".",
"State",
")",
"(",
"[",
"]",
"api",
".",
"ClusterMember",
",",
"error",
")",
"{",
"addresses",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"err",
":=",
"state",
".",
"Node",
".",
"Transaction",
"(",
... | // List the nodes of the cluster. | [
"List",
"the",
"nodes",
"of",
"the",
"cluster",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L715-L798 | test |
lxc/lxd | lxd/cluster/membership.go | Count | func Count(state *state.State) (int, error) {
var count int
err := state.Cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
count, err = tx.NodesCount()
return err
})
return count, err
} | go | func Count(state *state.State) (int, error) {
var count int
err := state.Cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
count, err = tx.NodesCount()
return err
})
return count, err
} | [
"func",
"Count",
"(",
"state",
"*",
"state",
".",
"State",
")",
"(",
"int",
",",
"error",
")",
"{",
"var",
"count",
"int",
"\n",
"err",
":=",
"state",
".",
"Cluster",
".",
"Transaction",
"(",
"func",
"(",
"tx",
"*",
"db",
".",
"ClusterTx",
")",
"... | // Count is a convenience for checking the current number of nodes in the
// cluster. | [
"Count",
"is",
"a",
"convenience",
"for",
"checking",
"the",
"current",
"number",
"of",
"nodes",
"in",
"the",
"cluster",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L802-L810 | test |
lxc/lxd | lxd/cluster/membership.go | Enabled | func Enabled(node *db.Node) (bool, error) {
enabled := false
err := node.Transaction(func(tx *db.NodeTx) error {
addresses, err := tx.RaftNodeAddresses()
if err != nil {
return err
}
enabled = len(addresses) > 0
return nil
})
return enabled, err
} | go | func Enabled(node *db.Node) (bool, error) {
enabled := false
err := node.Transaction(func(tx *db.NodeTx) error {
addresses, err := tx.RaftNodeAddresses()
if err != nil {
return err
}
enabled = len(addresses) > 0
return nil
})
return enabled, err
} | [
"func",
"Enabled",
"(",
"node",
"*",
"db",
".",
"Node",
")",
"(",
"bool",
",",
"error",
")",
"{",
"enabled",
":=",
"false",
"\n",
"err",
":=",
"node",
".",
"Transaction",
"(",
"func",
"(",
"tx",
"*",
"db",
".",
"NodeTx",
")",
"error",
"{",
"addre... | // Enabled is a convenience that returns true if clustering is enabled on this
// node. | [
"Enabled",
"is",
"a",
"convenience",
"that",
"returns",
"true",
"if",
"clustering",
"is",
"enabled",
"on",
"this",
"node",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L814-L825 | test |
lxc/lxd | lxd/cluster/membership.go | membershipCheckNodeStateForBootstrapOrJoin | func membershipCheckNodeStateForBootstrapOrJoin(tx *db.NodeTx, address string) error {
nodes, err := tx.RaftNodes()
if err != nil {
return errors.Wrap(err, "failed to fetch current raft nodes")
}
hasClusterAddress := address != ""
hasRaftNodes := len(nodes) > 0
// Sanity check that we're not in an inconsisten... | go | func membershipCheckNodeStateForBootstrapOrJoin(tx *db.NodeTx, address string) error {
nodes, err := tx.RaftNodes()
if err != nil {
return errors.Wrap(err, "failed to fetch current raft nodes")
}
hasClusterAddress := address != ""
hasRaftNodes := len(nodes) > 0
// Sanity check that we're not in an inconsisten... | [
"func",
"membershipCheckNodeStateForBootstrapOrJoin",
"(",
"tx",
"*",
"db",
".",
"NodeTx",
",",
"address",
"string",
")",
"error",
"{",
"nodes",
",",
"err",
":=",
"tx",
".",
"RaftNodes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
... | // Check that node-related preconditions are met for bootstrapping or joining a
// cluster. | [
"Check",
"that",
"node",
"-",
"related",
"preconditions",
"are",
"met",
"for",
"bootstrapping",
"or",
"joining",
"a",
"cluster",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L829-L853 | test |
lxc/lxd | lxd/cluster/membership.go | membershipCheckClusterStateForBootstrapOrJoin | func membershipCheckClusterStateForBootstrapOrJoin(tx *db.ClusterTx) error {
nodes, err := tx.Nodes()
if err != nil {
return errors.Wrap(err, "failed to fetch current cluster nodes")
}
if len(nodes) != 1 {
return fmt.Errorf("inconsistent state: found leftover entries in nodes")
}
return nil
} | go | func membershipCheckClusterStateForBootstrapOrJoin(tx *db.ClusterTx) error {
nodes, err := tx.Nodes()
if err != nil {
return errors.Wrap(err, "failed to fetch current cluster nodes")
}
if len(nodes) != 1 {
return fmt.Errorf("inconsistent state: found leftover entries in nodes")
}
return nil
} | [
"func",
"membershipCheckClusterStateForBootstrapOrJoin",
"(",
"tx",
"*",
"db",
".",
"ClusterTx",
")",
"error",
"{",
"nodes",
",",
"err",
":=",
"tx",
".",
"Nodes",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",... | // Check that cluster-related preconditions are met for bootstrapping or
// joining a cluster. | [
"Check",
"that",
"cluster",
"-",
"related",
"preconditions",
"are",
"met",
"for",
"bootstrapping",
"or",
"joining",
"a",
"cluster",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L857-L866 | test |
lxc/lxd | lxd/cluster/membership.go | membershipCheckClusterStateForAccept | func membershipCheckClusterStateForAccept(tx *db.ClusterTx, name string, address string, schema int, api int) error {
nodes, err := tx.Nodes()
if err != nil {
return errors.Wrap(err, "failed to fetch current cluster nodes")
}
if len(nodes) == 1 && nodes[0].Address == "0.0.0.0" {
return fmt.Errorf("clustering no... | go | func membershipCheckClusterStateForAccept(tx *db.ClusterTx, name string, address string, schema int, api int) error {
nodes, err := tx.Nodes()
if err != nil {
return errors.Wrap(err, "failed to fetch current cluster nodes")
}
if len(nodes) == 1 && nodes[0].Address == "0.0.0.0" {
return fmt.Errorf("clustering no... | [
"func",
"membershipCheckClusterStateForAccept",
"(",
"tx",
"*",
"db",
".",
"ClusterTx",
",",
"name",
"string",
",",
"address",
"string",
",",
"schema",
"int",
",",
"api",
"int",
")",
"error",
"{",
"nodes",
",",
"err",
":=",
"tx",
".",
"Nodes",
"(",
")",
... | // Check that cluster-related preconditions are met for accepting a new node. | [
"Check",
"that",
"cluster",
"-",
"related",
"preconditions",
"are",
"met",
"for",
"accepting",
"a",
"new",
"node",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L869-L894 | test |
lxc/lxd | lxd/cluster/membership.go | membershipCheckClusterStateForLeave | func membershipCheckClusterStateForLeave(tx *db.ClusterTx, nodeID int64) error {
// Check that it has no containers or images.
message, err := tx.NodeIsEmpty(nodeID)
if err != nil {
return err
}
if message != "" {
return fmt.Errorf(message)
}
// Check that it's not the last node.
nodes, err := tx.Nodes()
... | go | func membershipCheckClusterStateForLeave(tx *db.ClusterTx, nodeID int64) error {
// Check that it has no containers or images.
message, err := tx.NodeIsEmpty(nodeID)
if err != nil {
return err
}
if message != "" {
return fmt.Errorf(message)
}
// Check that it's not the last node.
nodes, err := tx.Nodes()
... | [
"func",
"membershipCheckClusterStateForLeave",
"(",
"tx",
"*",
"db",
".",
"ClusterTx",
",",
"nodeID",
"int64",
")",
"error",
"{",
"message",
",",
"err",
":=",
"tx",
".",
"NodeIsEmpty",
"(",
"nodeID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"e... | // Check that cluster-related preconditions are met for leaving a cluster. | [
"Check",
"that",
"cluster",
"-",
"related",
"preconditions",
"are",
"met",
"for",
"leaving",
"a",
"cluster",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L897-L916 | test |
lxc/lxd | lxd/cluster/membership.go | membershipCheckNoLeftoverClusterCert | func membershipCheckNoLeftoverClusterCert(dir string) error {
// Sanity check that there's no leftover cluster certificate
for _, basename := range []string{"cluster.crt", "cluster.key", "cluster.ca"} {
if shared.PathExists(filepath.Join(dir, basename)) {
return fmt.Errorf("inconsistent state: found leftover clu... | go | func membershipCheckNoLeftoverClusterCert(dir string) error {
// Sanity check that there's no leftover cluster certificate
for _, basename := range []string{"cluster.crt", "cluster.key", "cluster.ca"} {
if shared.PathExists(filepath.Join(dir, basename)) {
return fmt.Errorf("inconsistent state: found leftover clu... | [
"func",
"membershipCheckNoLeftoverClusterCert",
"(",
"dir",
"string",
")",
"error",
"{",
"for",
"_",
",",
"basename",
":=",
"range",
"[",
"]",
"string",
"{",
"\"cluster.crt\"",
",",
"\"cluster.key\"",
",",
"\"cluster.ca\"",
"}",
"{",
"if",
"shared",
".",
"Path... | // Check that there is no left-over cluster certificate in the LXD var dir of
// this node. | [
"Check",
"that",
"there",
"is",
"no",
"left",
"-",
"over",
"cluster",
"certificate",
"in",
"the",
"LXD",
"var",
"dir",
"of",
"this",
"node",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/membership.go#L920-L928 | test |
lxc/lxd | lxd/node/config.go | ConfigLoad | func ConfigLoad(tx *db.NodeTx) (*Config, error) {
// Load current raw values from the database, any error is fatal.
values, err := tx.Config()
if err != nil {
return nil, fmt.Errorf("cannot fetch node config from database: %v", err)
}
m, err := config.SafeLoad(ConfigSchema, values)
if err != nil {
return nil... | go | func ConfigLoad(tx *db.NodeTx) (*Config, error) {
// Load current raw values from the database, any error is fatal.
values, err := tx.Config()
if err != nil {
return nil, fmt.Errorf("cannot fetch node config from database: %v", err)
}
m, err := config.SafeLoad(ConfigSchema, values)
if err != nil {
return nil... | [
"func",
"ConfigLoad",
"(",
"tx",
"*",
"db",
".",
"NodeTx",
")",
"(",
"*",
"Config",
",",
"error",
")",
"{",
"values",
",",
"err",
":=",
"tx",
".",
"Config",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Error... | // ConfigLoad loads a new Config object with the current node-local configuration
// values fetched from the database. An optional list of config value triggers
// can be passed, each config key must have at most one trigger. | [
"ConfigLoad",
"loads",
"a",
"new",
"Config",
"object",
"with",
"the",
"current",
"node",
"-",
"local",
"configuration",
"values",
"fetched",
"from",
"the",
"database",
".",
"An",
"optional",
"list",
"of",
"config",
"value",
"triggers",
"can",
"be",
"passed",
... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/node/config.go#L19-L32 | test |
lxc/lxd | lxd/node/config.go | Replace | func (c *Config) Replace(values map[string]interface{}) (map[string]string, error) {
return c.update(values)
} | go | func (c *Config) Replace(values map[string]interface{}) (map[string]string, error) {
return c.update(values)
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Replace",
"(",
"values",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"return",
"c",
".",
"update",
"(",
"values",
")",
"\n",
"}"
] | // Replace the current configuration with the given values. | [
"Replace",
"the",
"current",
"configuration",
"with",
"the",
"given",
"values",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/node/config.go#L64-L66 | test |
lxc/lxd | lxd/node/config.go | Patch | func (c *Config) Patch(patch map[string]interface{}) (map[string]string, error) {
values := c.Dump() // Use current values as defaults
for name, value := range patch {
values[name] = value
}
return c.update(values)
} | go | func (c *Config) Patch(patch map[string]interface{}) (map[string]string, error) {
values := c.Dump() // Use current values as defaults
for name, value := range patch {
values[name] = value
}
return c.update(values)
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"Patch",
"(",
"patch",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"values",
":=",
"c",
".",
"Dump",
"(",
")",
"\n",
"for",
"name... | // Patch changes only the configuration keys in the given map. | [
"Patch",
"changes",
"only",
"the",
"configuration",
"keys",
"in",
"the",
"given",
"map",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/node/config.go#L69-L76 | test |
lxc/lxd | lxd/node/config.go | HTTPSAddress | func HTTPSAddress(node *db.Node) (string, error) {
var config *Config
err := node.Transaction(func(tx *db.NodeTx) error {
var err error
config, err = ConfigLoad(tx)
return err
})
if err != nil {
return "", err
}
return config.HTTPSAddress(), nil
} | go | func HTTPSAddress(node *db.Node) (string, error) {
var config *Config
err := node.Transaction(func(tx *db.NodeTx) error {
var err error
config, err = ConfigLoad(tx)
return err
})
if err != nil {
return "", err
}
return config.HTTPSAddress(), nil
} | [
"func",
"HTTPSAddress",
"(",
"node",
"*",
"db",
".",
"Node",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"config",
"*",
"Config",
"\n",
"err",
":=",
"node",
".",
"Transaction",
"(",
"func",
"(",
"tx",
"*",
"db",
".",
"NodeTx",
")",
"error",
... | // HTTPSAddress is a convenience for loading the node configuration and
// returning the value of core.https_address. | [
"HTTPSAddress",
"is",
"a",
"convenience",
"for",
"loading",
"the",
"node",
"configuration",
"and",
"returning",
"the",
"value",
"of",
"core",
".",
"https_address",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/node/config.go#L80-L92 | test |
lxc/lxd | lxd/db/certificates.go | CertificatesGet | func (c *Cluster) CertificatesGet() (certs []*CertInfo, err error) {
err = c.Transaction(func(tx *ClusterTx) error {
rows, err := tx.tx.Query(
"SELECT id, fingerprint, type, name, certificate FROM certificates",
)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
cert := new(Cert... | go | func (c *Cluster) CertificatesGet() (certs []*CertInfo, err error) {
err = c.Transaction(func(tx *ClusterTx) error {
rows, err := tx.tx.Query(
"SELECT id, fingerprint, type, name, certificate FROM certificates",
)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
cert := new(Cert... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"CertificatesGet",
"(",
")",
"(",
"certs",
"[",
"]",
"*",
"CertInfo",
",",
"err",
"error",
")",
"{",
"err",
"=",
"c",
".",
"Transaction",
"(",
"func",
"(",
"tx",
"*",
"ClusterTx",
")",
"error",
"{",
"rows",
... | // CertificatesGet returns all certificates from the DB as CertBaseInfo objects. | [
"CertificatesGet",
"returns",
"all",
"certificates",
"from",
"the",
"DB",
"as",
"CertBaseInfo",
"objects",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/certificates.go#L18-L48 | test |
lxc/lxd | lxd/db/certificates.go | CertificateGet | func (c *Cluster) CertificateGet(fingerprint string) (cert *CertInfo, err error) {
cert = new(CertInfo)
inargs := []interface{}{fingerprint + "%"}
outfmt := []interface{}{
&cert.ID,
&cert.Fingerprint,
&cert.Type,
&cert.Name,
&cert.Certificate,
}
query := `
SELECT
id, fingerprint, type, name, certi... | go | func (c *Cluster) CertificateGet(fingerprint string) (cert *CertInfo, err error) {
cert = new(CertInfo)
inargs := []interface{}{fingerprint + "%"}
outfmt := []interface{}{
&cert.ID,
&cert.Fingerprint,
&cert.Type,
&cert.Name,
&cert.Certificate,
}
query := `
SELECT
id, fingerprint, type, name, certi... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"CertificateGet",
"(",
"fingerprint",
"string",
")",
"(",
"cert",
"*",
"CertInfo",
",",
"err",
"error",
")",
"{",
"cert",
"=",
"new",
"(",
"CertInfo",
")",
"\n",
"inargs",
":=",
"[",
"]",
"interface",
"{",
"}",
... | // CertificateGet gets an CertBaseInfo object from the database.
// The argument fingerprint will be queried with a LIKE query, means you can
// pass a shortform and will get the full fingerprint.
// There can never be more than one image with a given fingerprint, as it is
// enforced by a UNIQUE constraint in the sche... | [
"CertificateGet",
"gets",
"an",
"CertBaseInfo",
"object",
"from",
"the",
"database",
".",
"The",
"argument",
"fingerprint",
"will",
"be",
"queried",
"with",
"a",
"LIKE",
"query",
"means",
"you",
"can",
"pass",
"a",
"shortform",
"and",
"will",
"get",
"the",
"... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/certificates.go#L55-L83 | test |
lxc/lxd | lxd/db/certificates.go | CertSave | func (c *Cluster) CertSave(cert *CertInfo) error {
err := c.Transaction(func(tx *ClusterTx) error {
stmt, err := tx.tx.Prepare(`
INSERT INTO certificates (
fingerprint,
type,
name,
certificate
) VALUES (?, ?, ?, ?)`,
)
if err != nil {
return err
}
defer stmt.Close()
_, err = stmt.E... | go | func (c *Cluster) CertSave(cert *CertInfo) error {
err := c.Transaction(func(tx *ClusterTx) error {
stmt, err := tx.tx.Prepare(`
INSERT INTO certificates (
fingerprint,
type,
name,
certificate
) VALUES (?, ?, ?, ?)`,
)
if err != nil {
return err
}
defer stmt.Close()
_, err = stmt.E... | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"CertSave",
"(",
"cert",
"*",
"CertInfo",
")",
"error",
"{",
"err",
":=",
"c",
".",
"Transaction",
"(",
"func",
"(",
"tx",
"*",
"ClusterTx",
")",
"error",
"{",
"stmt",
",",
"err",
":=",
"tx",
".",
"tx",
".",... | // CertSave stores a CertBaseInfo object in the db,
// it will ignore the ID field from the CertInfo. | [
"CertSave",
"stores",
"a",
"CertBaseInfo",
"object",
"in",
"the",
"db",
"it",
"will",
"ignore",
"the",
"ID",
"field",
"from",
"the",
"CertInfo",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/certificates.go#L87-L113 | test |
lxc/lxd | lxd/db/certificates.go | CertDelete | func (c *Cluster) CertDelete(fingerprint string) error {
err := exec(c.db, "DELETE FROM certificates WHERE fingerprint=?", fingerprint)
if err != nil {
return err
}
return nil
} | go | func (c *Cluster) CertDelete(fingerprint string) error {
err := exec(c.db, "DELETE FROM certificates WHERE fingerprint=?", fingerprint)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"CertDelete",
"(",
"fingerprint",
"string",
")",
"error",
"{",
"err",
":=",
"exec",
"(",
"c",
".",
"db",
",",
"\"DELETE FROM certificates WHERE fingerprint=?\"",
",",
"fingerprint",
")",
"\n",
"if",
"err",
"!=",
"nil",
... | // CertDelete deletes a certificate from the db. | [
"CertDelete",
"deletes",
"a",
"certificate",
"from",
"the",
"db",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/certificates.go#L116-L123 | test |
lxc/lxd | lxd/db/certificates.go | CertUpdate | func (c *Cluster) CertUpdate(fingerprint string, certName string, certType int) error {
err := c.Transaction(func(tx *ClusterTx) error {
_, err := tx.tx.Exec("UPDATE certificates SET name=?, type=? WHERE fingerprint=?", certName, certType, fingerprint)
return err
})
return err
} | go | func (c *Cluster) CertUpdate(fingerprint string, certName string, certType int) error {
err := c.Transaction(func(tx *ClusterTx) error {
_, err := tx.tx.Exec("UPDATE certificates SET name=?, type=? WHERE fingerprint=?", certName, certType, fingerprint)
return err
})
return err
} | [
"func",
"(",
"c",
"*",
"Cluster",
")",
"CertUpdate",
"(",
"fingerprint",
"string",
",",
"certName",
"string",
",",
"certType",
"int",
")",
"error",
"{",
"err",
":=",
"c",
".",
"Transaction",
"(",
"func",
"(",
"tx",
"*",
"ClusterTx",
")",
"error",
"{",
... | // CertUpdate updates the certificate with the given fingerprint. | [
"CertUpdate",
"updates",
"the",
"certificate",
"with",
"the",
"given",
"fingerprint",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/certificates.go#L126-L132 | test |
lxc/lxd | lxd/endpoints/devlxd.go | createDevLxdlListener | func createDevLxdlListener(dir string) (net.Listener, error) {
path := filepath.Join(dir, "devlxd", "sock")
// If this socket exists, that means a previous LXD instance died and
// didn't clean up. We assume that such LXD instance is actually dead
// if we get this far, since localCreateListener() tries to connect... | go | func createDevLxdlListener(dir string) (net.Listener, error) {
path := filepath.Join(dir, "devlxd", "sock")
// If this socket exists, that means a previous LXD instance died and
// didn't clean up. We assume that such LXD instance is actually dead
// if we get this far, since localCreateListener() tries to connect... | [
"func",
"createDevLxdlListener",
"(",
"dir",
"string",
")",
"(",
"net",
".",
"Listener",
",",
"error",
")",
"{",
"path",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"devlxd\"",
",",
"\"sock\"",
")",
"\n",
"err",
":=",
"socketUnixRemoveStale",
"(",
... | // Create a new net.Listener bound to the unix socket of the devlxd endpoint. | [
"Create",
"a",
"new",
"net",
".",
"Listener",
"bound",
"to",
"the",
"unix",
"socket",
"of",
"the",
"devlxd",
"endpoint",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/endpoints/devlxd.go#L9-L40 | test |
lxc/lxd | lxd/cluster/raft.go | Servers | func (i *raftInstance) Servers() ([]raft.Server, error) {
if i.raft.State() != raft.Leader {
return nil, raft.ErrNotLeader
}
future := i.raft.GetConfiguration()
err := future.Error()
if err != nil {
return nil, err
}
configuration := future.Configuration()
return configuration.Servers, nil
} | go | func (i *raftInstance) Servers() ([]raft.Server, error) {
if i.raft.State() != raft.Leader {
return nil, raft.ErrNotLeader
}
future := i.raft.GetConfiguration()
err := future.Error()
if err != nil {
return nil, err
}
configuration := future.Configuration()
return configuration.Servers, nil
} | [
"func",
"(",
"i",
"*",
"raftInstance",
")",
"Servers",
"(",
")",
"(",
"[",
"]",
"raft",
".",
"Server",
",",
"error",
")",
"{",
"if",
"i",
".",
"raft",
".",
"State",
"(",
")",
"!=",
"raft",
".",
"Leader",
"{",
"return",
"nil",
",",
"raft",
".",
... | // Servers returns the servers that are currently part of the cluster.
//
// If this raft instance is not the leader, an error is returned. | [
"Servers",
"returns",
"the",
"servers",
"that",
"are",
"currently",
"part",
"of",
"the",
"cluster",
".",
"If",
"this",
"raft",
"instance",
"is",
"not",
"the",
"leader",
"an",
"error",
"is",
"returned",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/raft.go#L239-L250 | test |
lxc/lxd | lxd/cluster/raft.go | Shutdown | func (i *raftInstance) Shutdown() error {
logger.Debug("Stop raft instance")
// Invoke raft APIs asynchronously to allow for a timeout.
timeout := 10 * time.Second
errCh := make(chan error)
timer := time.After(timeout)
go func() {
errCh <- i.raft.Shutdown().Error()
}()
select {
case err := <-errCh:
if er... | go | func (i *raftInstance) Shutdown() error {
logger.Debug("Stop raft instance")
// Invoke raft APIs asynchronously to allow for a timeout.
timeout := 10 * time.Second
errCh := make(chan error)
timer := time.After(timeout)
go func() {
errCh <- i.raft.Shutdown().Error()
}()
select {
case err := <-errCh:
if er... | [
"func",
"(",
"i",
"*",
"raftInstance",
")",
"Shutdown",
"(",
")",
"error",
"{",
"logger",
".",
"Debug",
"(",
"\"Stop raft instance\"",
")",
"\n",
"timeout",
":=",
"10",
"*",
"time",
".",
"Second",
"\n",
"errCh",
":=",
"make",
"(",
"chan",
"error",
")",... | // Shutdown raft and any raft-related resource we have instantiated. | [
"Shutdown",
"raft",
"and",
"any",
"raft",
"-",
"related",
"resource",
"we",
"have",
"instantiated",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/raft.go#L273-L299 | test |
lxc/lxd | lxd/cluster/raft.go | raftNetworkTransport | func raftNetworkTransport(
db *db.Node,
address string,
logger *log.Logger,
timeout time.Duration,
dial rafthttp.Dial) (raft.Transport, *rafthttp.Handler, *rafthttp.Layer, error) {
handler := rafthttp.NewHandlerWithLogger(logger)
addr, err := net.ResolveTCPAddr("tcp", address)
if err != nil {
return nil, nil,... | go | func raftNetworkTransport(
db *db.Node,
address string,
logger *log.Logger,
timeout time.Duration,
dial rafthttp.Dial) (raft.Transport, *rafthttp.Handler, *rafthttp.Layer, error) {
handler := rafthttp.NewHandlerWithLogger(logger)
addr, err := net.ResolveTCPAddr("tcp", address)
if err != nil {
return nil, nil,... | [
"func",
"raftNetworkTransport",
"(",
"db",
"*",
"db",
".",
"Node",
",",
"address",
"string",
",",
"logger",
"*",
"log",
".",
"Logger",
",",
"timeout",
"time",
".",
"Duration",
",",
"dial",
"rafthttp",
".",
"Dial",
")",
"(",
"raft",
".",
"Transport",
",... | // Create a network raft transport that will handle connections using a
// rafthttp.Handler. | [
"Create",
"a",
"network",
"raft",
"transport",
"that",
"will",
"handle",
"connections",
"using",
"a",
"rafthttp",
".",
"Handler",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/raft.go#L326-L349 | test |
lxc/lxd | lxd/cluster/raft.go | raftConfig | func raftConfig(latency float64) *raft.Config {
config := raft.DefaultConfig()
scale := func(duration *time.Duration) {
*duration = time.Duration((math.Ceil(float64(*duration) * latency)))
}
durations := []*time.Duration{
&config.HeartbeatTimeout,
&config.ElectionTimeout,
&config.CommitTimeout,
&config.Le... | go | func raftConfig(latency float64) *raft.Config {
config := raft.DefaultConfig()
scale := func(duration *time.Duration) {
*duration = time.Duration((math.Ceil(float64(*duration) * latency)))
}
durations := []*time.Duration{
&config.HeartbeatTimeout,
&config.ElectionTimeout,
&config.CommitTimeout,
&config.Le... | [
"func",
"raftConfig",
"(",
"latency",
"float64",
")",
"*",
"raft",
".",
"Config",
"{",
"config",
":=",
"raft",
".",
"DefaultConfig",
"(",
")",
"\n",
"scale",
":=",
"func",
"(",
"duration",
"*",
"time",
".",
"Duration",
")",
"{",
"*",
"duration",
"=",
... | // Create a base raft configuration tweaked for a network with the given latency measure. | [
"Create",
"a",
"base",
"raft",
"configuration",
"tweaked",
"for",
"a",
"network",
"with",
"the",
"given",
"latency",
"measure",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/raft.go#L378-L397 | test |
lxc/lxd | lxd/cluster/raft.go | raftMaybeBootstrap | func raftMaybeBootstrap(
conf *raft.Config,
logs *raftboltdb.BoltStore,
snaps raft.SnapshotStore,
trans raft.Transport) error {
// First check if we were already bootstrapped.
hasExistingState, err := raft.HasExistingState(logs, logs, snaps)
if err != nil {
return errors.Wrap(err, "failed to check if raft has ... | go | func raftMaybeBootstrap(
conf *raft.Config,
logs *raftboltdb.BoltStore,
snaps raft.SnapshotStore,
trans raft.Transport) error {
// First check if we were already bootstrapped.
hasExistingState, err := raft.HasExistingState(logs, logs, snaps)
if err != nil {
return errors.Wrap(err, "failed to check if raft has ... | [
"func",
"raftMaybeBootstrap",
"(",
"conf",
"*",
"raft",
".",
"Config",
",",
"logs",
"*",
"raftboltdb",
".",
"BoltStore",
",",
"snaps",
"raft",
".",
"SnapshotStore",
",",
"trans",
"raft",
".",
"Transport",
")",
"error",
"{",
"hasExistingState",
",",
"err",
... | // Helper to bootstrap the raft cluster if needed. | [
"Helper",
"to",
"bootstrap",
"the",
"raft",
"cluster",
"if",
"needed",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/cluster/raft.go#L400-L421 | test |
lxc/lxd | lxd/util/resources.go | CPUResource | func CPUResource() (*api.ResourcesCPU, error) {
c := api.ResourcesCPU{}
threads, err := getThreads()
if err != nil {
return nil, err
}
var cur *api.ResourcesCPUSocket
c.Total = uint64(len(threads))
for _, v := range threads {
if uint64(len(c.Sockets)) <= v.socketID {
c.Sockets = append(c.Sockets, api.R... | go | func CPUResource() (*api.ResourcesCPU, error) {
c := api.ResourcesCPU{}
threads, err := getThreads()
if err != nil {
return nil, err
}
var cur *api.ResourcesCPUSocket
c.Total = uint64(len(threads))
for _, v := range threads {
if uint64(len(c.Sockets)) <= v.socketID {
c.Sockets = append(c.Sockets, api.R... | [
"func",
"CPUResource",
"(",
")",
"(",
"*",
"api",
".",
"ResourcesCPU",
",",
"error",
")",
"{",
"c",
":=",
"api",
".",
"ResourcesCPU",
"{",
"}",
"\n",
"threads",
",",
"err",
":=",
"getThreads",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return"... | // CPUResource returns the system CPU information | [
"CPUResource",
"returns",
"the",
"system",
"CPU",
"information"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/resources.go#L266-L307 | test |
lxc/lxd | lxd/util/resources.go | MemoryResource | func MemoryResource() (*api.ResourcesMemory, error) {
var buffers uint64
var cached uint64
var free uint64
var total uint64
f, err := os.Open("/proc/meminfo")
if err != nil {
return nil, err
}
defer f.Close()
cleanLine := func(l string) (string, error) {
l = strings.TrimSpace(l)
idx := strings.LastInde... | go | func MemoryResource() (*api.ResourcesMemory, error) {
var buffers uint64
var cached uint64
var free uint64
var total uint64
f, err := os.Open("/proc/meminfo")
if err != nil {
return nil, err
}
defer f.Close()
cleanLine := func(l string) (string, error) {
l = strings.TrimSpace(l)
idx := strings.LastInde... | [
"func",
"MemoryResource",
"(",
")",
"(",
"*",
"api",
".",
"ResourcesMemory",
",",
"error",
")",
"{",
"var",
"buffers",
"uint64",
"\n",
"var",
"cached",
"uint64",
"\n",
"var",
"free",
"uint64",
"\n",
"var",
"total",
"uint64",
"\n",
"f",
",",
"err",
":="... | // MemoryResource returns the system memory information | [
"MemoryResource",
"returns",
"the",
"system",
"memory",
"information"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/resources.go#L310-L398 | test |
lxc/lxd | client/lxd_operations.go | GetOperationUUIDs | func (r *ProtocolLXD) GetOperationUUIDs() ([]string, error) {
urls := []string{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/operations", nil, "", &urls)
if err != nil {
return nil, err
}
// Parse it
uuids := []string{}
for _, url := range urls {
fields := strings.Split(url, "/operations/")
... | go | func (r *ProtocolLXD) GetOperationUUIDs() ([]string, error) {
urls := []string{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/operations", nil, "", &urls)
if err != nil {
return nil, err
}
// Parse it
uuids := []string{}
for _, url := range urls {
fields := strings.Split(url, "/operations/")
... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetOperationUUIDs",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"urls",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"r",
".",
"queryStruct",
"(",
"\"GET\"",
",",
"\"/... | // GetOperationUUIDs returns a list of operation uuids | [
"GetOperationUUIDs",
"returns",
"a",
"list",
"of",
"operation",
"uuids"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_operations.go#L14-L31 | test |
lxc/lxd | client/lxd_operations.go | GetOperations | func (r *ProtocolLXD) GetOperations() ([]api.Operation, error) {
apiOperations := map[string][]api.Operation{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/operations?recursion=1", nil, "", &apiOperations)
if err != nil {
return nil, err
}
// Turn it into just a list of operations
operations := []... | go | func (r *ProtocolLXD) GetOperations() ([]api.Operation, error) {
apiOperations := map[string][]api.Operation{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/operations?recursion=1", nil, "", &apiOperations)
if err != nil {
return nil, err
}
// Turn it into just a list of operations
operations := []... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetOperations",
"(",
")",
"(",
"[",
"]",
"api",
".",
"Operation",
",",
"error",
")",
"{",
"apiOperations",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"api",
".",
"Operation",
"{",
"}",
"\n",
"_",
",",
"... | // GetOperations returns a list of Operation struct | [
"GetOperations",
"returns",
"a",
"list",
"of",
"Operation",
"struct"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_operations.go#L34-L52 | test |
lxc/lxd | client/lxd_operations.go | GetOperation | func (r *ProtocolLXD) GetOperation(uuid string) (*api.Operation, string, error) {
op := api.Operation{}
// Fetch the raw value
etag, err := r.queryStruct("GET", fmt.Sprintf("/operations/%s", url.QueryEscape(uuid)), nil, "", &op)
if err != nil {
return nil, "", err
}
return &op, etag, nil
} | go | func (r *ProtocolLXD) GetOperation(uuid string) (*api.Operation, string, error) {
op := api.Operation{}
// Fetch the raw value
etag, err := r.queryStruct("GET", fmt.Sprintf("/operations/%s", url.QueryEscape(uuid)), nil, "", &op)
if err != nil {
return nil, "", err
}
return &op, etag, nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetOperation",
"(",
"uuid",
"string",
")",
"(",
"*",
"api",
".",
"Operation",
",",
"string",
",",
"error",
")",
"{",
"op",
":=",
"api",
".",
"Operation",
"{",
"}",
"\n",
"etag",
",",
"err",
":=",
"r",
"... | // GetOperation returns an Operation entry for the provided uuid | [
"GetOperation",
"returns",
"an",
"Operation",
"entry",
"for",
"the",
"provided",
"uuid"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_operations.go#L55-L65 | test |
lxc/lxd | client/lxd_operations.go | GetOperationWebsocket | func (r *ProtocolLXD) GetOperationWebsocket(uuid string, secret string) (*websocket.Conn, error) {
path := fmt.Sprintf("/operations/%s/websocket", url.QueryEscape(uuid))
if secret != "" {
path = fmt.Sprintf("%s?secret=%s", path, url.QueryEscape(secret))
}
return r.websocket(path)
} | go | func (r *ProtocolLXD) GetOperationWebsocket(uuid string, secret string) (*websocket.Conn, error) {
path := fmt.Sprintf("/operations/%s/websocket", url.QueryEscape(uuid))
if secret != "" {
path = fmt.Sprintf("%s?secret=%s", path, url.QueryEscape(secret))
}
return r.websocket(path)
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetOperationWebsocket",
"(",
"uuid",
"string",
",",
"secret",
"string",
")",
"(",
"*",
"websocket",
".",
"Conn",
",",
"error",
")",
"{",
"path",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"/operations/%s/websocket\"",
"... | // GetOperationWebsocket returns a websocket connection for the provided operation | [
"GetOperationWebsocket",
"returns",
"a",
"websocket",
"connection",
"for",
"the",
"provided",
"operation"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_operations.go#L81-L88 | test |
lxc/lxd | lxd/storage_utils.go | tryMount | func tryMount(src string, dst string, fs string, flags uintptr, options string) error {
var err error
for i := 0; i < 20; i++ {
err = syscall.Mount(src, dst, fs, flags, options)
if err == nil {
break
}
time.Sleep(500 * time.Millisecond)
}
if err != nil {
return err
}
return nil
} | go | func tryMount(src string, dst string, fs string, flags uintptr, options string) error {
var err error
for i := 0; i < 20; i++ {
err = syscall.Mount(src, dst, fs, flags, options)
if err == nil {
break
}
time.Sleep(500 * time.Millisecond)
}
if err != nil {
return err
}
return nil
} | [
"func",
"tryMount",
"(",
"src",
"string",
",",
"dst",
"string",
",",
"fs",
"string",
",",
"flags",
"uintptr",
",",
"options",
"string",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"20",
";",
"i",
"++",
"{... | // Useful functions for unreliable backends | [
"Useful",
"functions",
"for",
"unreliable",
"backends"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_utils.go#L83-L100 | test |
lxc/lxd | lxd/storage_utils.go | lxdUsesPool | func lxdUsesPool(dbObj *db.Cluster, onDiskPoolName string, driver string, onDiskProperty string) (bool, string, error) {
pools, err := dbObj.StoragePools()
if err != nil && err != db.ErrNoSuchObject {
return false, "", err
}
for _, pool := range pools {
_, pl, err := dbObj.StoragePoolGet(pool)
if err != nil ... | go | func lxdUsesPool(dbObj *db.Cluster, onDiskPoolName string, driver string, onDiskProperty string) (bool, string, error) {
pools, err := dbObj.StoragePools()
if err != nil && err != db.ErrNoSuchObject {
return false, "", err
}
for _, pool := range pools {
_, pl, err := dbObj.StoragePoolGet(pool)
if err != nil ... | [
"func",
"lxdUsesPool",
"(",
"dbObj",
"*",
"db",
".",
"Cluster",
",",
"onDiskPoolName",
"string",
",",
"driver",
"string",
",",
"onDiskProperty",
"string",
")",
"(",
"bool",
",",
"string",
",",
"error",
")",
"{",
"pools",
",",
"err",
":=",
"dbObj",
".",
... | // Detect whether LXD already uses the given storage pool. | [
"Detect",
"whether",
"LXD",
"already",
"uses",
"the",
"given",
"storage",
"pool",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_utils.go#L172-L194 | test |
lxc/lxd | lxd/db/projects.mapper.go | ProjectURIs | func (c *ClusterTx) ProjectURIs(filter ProjectFilter) ([]string, error) {
// Check which filter criteria are active.
criteria := map[string]interface{}{}
if filter.Name != "" {
criteria["Name"] = filter.Name
}
// Pick the prepared statement and arguments to use based on active criteria.
var stmt *sql.Stmt
var... | go | func (c *ClusterTx) ProjectURIs(filter ProjectFilter) ([]string, error) {
// Check which filter criteria are active.
criteria := map[string]interface{}{}
if filter.Name != "" {
criteria["Name"] = filter.Name
}
// Pick the prepared statement and arguments to use based on active criteria.
var stmt *sql.Stmt
var... | [
"func",
"(",
"c",
"*",
"ClusterTx",
")",
"ProjectURIs",
"(",
"filter",
"ProjectFilter",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"criteria",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"if",
"filter",
".",
"... | // ProjectURIs returns all available project URIs. | [
"ProjectURIs",
"returns",
"all",
"available",
"project",
"URIs",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.mapper.go#L86-L111 | test |
lxc/lxd | lxd/db/projects.mapper.go | ProjectList | func (c *ClusterTx) ProjectList(filter ProjectFilter) ([]api.Project, error) {
// Result slice.
objects := make([]api.Project, 0)
// Check which filter criteria are active.
criteria := map[string]interface{}{}
if filter.Name != "" {
criteria["Name"] = filter.Name
}
// Pick the prepared statement and argument... | go | func (c *ClusterTx) ProjectList(filter ProjectFilter) ([]api.Project, error) {
// Result slice.
objects := make([]api.Project, 0)
// Check which filter criteria are active.
criteria := map[string]interface{}{}
if filter.Name != "" {
criteria["Name"] = filter.Name
}
// Pick the prepared statement and argument... | [
"func",
"(",
"c",
"*",
"ClusterTx",
")",
"ProjectList",
"(",
"filter",
"ProjectFilter",
")",
"(",
"[",
"]",
"api",
".",
"Project",
",",
"error",
")",
"{",
"objects",
":=",
"make",
"(",
"[",
"]",
"api",
".",
"Project",
",",
"0",
")",
"\n",
"criteria... | // ProjectList returns all available projects. | [
"ProjectList",
"returns",
"all",
"available",
"projects",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.mapper.go#L114-L182 | test |
lxc/lxd | lxd/db/projects.mapper.go | ProjectGet | func (c *ClusterTx) ProjectGet(name string) (*api.Project, error) {
filter := ProjectFilter{}
filter.Name = name
objects, err := c.ProjectList(filter)
if err != nil {
return nil, errors.Wrap(err, "Failed to fetch Project")
}
switch len(objects) {
case 0:
return nil, ErrNoSuchObject
case 1:
return &objec... | go | func (c *ClusterTx) ProjectGet(name string) (*api.Project, error) {
filter := ProjectFilter{}
filter.Name = name
objects, err := c.ProjectList(filter)
if err != nil {
return nil, errors.Wrap(err, "Failed to fetch Project")
}
switch len(objects) {
case 0:
return nil, ErrNoSuchObject
case 1:
return &objec... | [
"func",
"(",
"c",
"*",
"ClusterTx",
")",
"ProjectGet",
"(",
"name",
"string",
")",
"(",
"*",
"api",
".",
"Project",
",",
"error",
")",
"{",
"filter",
":=",
"ProjectFilter",
"{",
"}",
"\n",
"filter",
".",
"Name",
"=",
"name",
"\n",
"objects",
",",
"... | // ProjectGet returns the project with the given key. | [
"ProjectGet",
"returns",
"the",
"project",
"with",
"the",
"given",
"key",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.mapper.go#L185-L202 | test |
lxc/lxd | lxd/db/projects.mapper.go | ProjectExists | func (c *ClusterTx) ProjectExists(name string) (bool, error) {
_, err := c.ProjectID(name)
if err != nil {
if err == ErrNoSuchObject {
return false, nil
}
return false, err
}
return true, nil
} | go | func (c *ClusterTx) ProjectExists(name string) (bool, error) {
_, err := c.ProjectID(name)
if err != nil {
if err == ErrNoSuchObject {
return false, nil
}
return false, err
}
return true, nil
} | [
"func",
"(",
"c",
"*",
"ClusterTx",
")",
"ProjectExists",
"(",
"name",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"c",
".",
"ProjectID",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"... | // ProjectExists checks if a project with the given key exists. | [
"ProjectExists",
"checks",
"if",
"a",
"project",
"with",
"the",
"given",
"key",
"exists",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.mapper.go#L270-L280 | test |
lxc/lxd | lxd/db/projects.mapper.go | ProjectCreate | func (c *ClusterTx) ProjectCreate(object api.ProjectsPost) (int64, error) {
// Check if a project with the same key exists.
exists, err := c.ProjectExists(object.Name)
if err != nil {
return -1, errors.Wrap(err, "Failed to check for duplicates")
}
if exists {
return -1, fmt.Errorf("This project already exists"... | go | func (c *ClusterTx) ProjectCreate(object api.ProjectsPost) (int64, error) {
// Check if a project with the same key exists.
exists, err := c.ProjectExists(object.Name)
if err != nil {
return -1, errors.Wrap(err, "Failed to check for duplicates")
}
if exists {
return -1, fmt.Errorf("This project already exists"... | [
"func",
"(",
"c",
"*",
"ClusterTx",
")",
"ProjectCreate",
"(",
"object",
"api",
".",
"ProjectsPost",
")",
"(",
"int64",
",",
"error",
")",
"{",
"exists",
",",
"err",
":=",
"c",
".",
"ProjectExists",
"(",
"object",
".",
"Name",
")",
"\n",
"if",
"err",... | // ProjectCreate adds a new project to the database. | [
"ProjectCreate",
"adds",
"a",
"new",
"project",
"to",
"the",
"database",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.mapper.go#L283-L323 | test |
lxc/lxd | lxd/db/projects.mapper.go | ProjectUsedByRef | func (c *ClusterTx) ProjectUsedByRef(filter ProjectFilter) (map[string][]string, error) {
// Result slice.
objects := make([]struct {
Name string
Value string
}, 0)
// Check which filter criteria are active.
criteria := map[string]interface{}{}
if filter.Name != "" {
criteria["Name"] = filter.Name
}
//... | go | func (c *ClusterTx) ProjectUsedByRef(filter ProjectFilter) (map[string][]string, error) {
// Result slice.
objects := make([]struct {
Name string
Value string
}, 0)
// Check which filter criteria are active.
criteria := map[string]interface{}{}
if filter.Name != "" {
criteria["Name"] = filter.Name
}
//... | [
"func",
"(",
"c",
"*",
"ClusterTx",
")",
"ProjectUsedByRef",
"(",
"filter",
"ProjectFilter",
")",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
",",
"error",
")",
"{",
"objects",
":=",
"make",
"(",
"[",
"]",
"struct",
"{",
"Name",
"string",
"\n... | // ProjectUsedByRef returns entities used by projects. | [
"ProjectUsedByRef",
"returns",
"entities",
"used",
"by",
"projects",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.mapper.go#L326-L384 | test |
lxc/lxd | lxd/db/projects.mapper.go | ProjectRename | func (c *ClusterTx) ProjectRename(name string, to string) error {
stmt := c.stmt(projectRename)
result, err := stmt.Exec(to, name)
if err != nil {
return errors.Wrap(err, "Rename project")
}
n, err := result.RowsAffected()
if err != nil {
return errors.Wrap(err, "Fetch affected rows")
}
if n != 1 {
retur... | go | func (c *ClusterTx) ProjectRename(name string, to string) error {
stmt := c.stmt(projectRename)
result, err := stmt.Exec(to, name)
if err != nil {
return errors.Wrap(err, "Rename project")
}
n, err := result.RowsAffected()
if err != nil {
return errors.Wrap(err, "Fetch affected rows")
}
if n != 1 {
retur... | [
"func",
"(",
"c",
"*",
"ClusterTx",
")",
"ProjectRename",
"(",
"name",
"string",
",",
"to",
"string",
")",
"error",
"{",
"stmt",
":=",
"c",
".",
"stmt",
"(",
"projectRename",
")",
"\n",
"result",
",",
"err",
":=",
"stmt",
".",
"Exec",
"(",
"to",
",... | // ProjectRename renames the project matching the given key parameters. | [
"ProjectRename",
"renames",
"the",
"project",
"matching",
"the",
"given",
"key",
"parameters",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.mapper.go#L416-L431 | test |
lxc/lxd | lxd/db/projects.mapper.go | ProjectDelete | func (c *ClusterTx) ProjectDelete(name string) error {
stmt := c.stmt(projectDelete)
result, err := stmt.Exec(name)
if err != nil {
return errors.Wrap(err, "Delete project")
}
n, err := result.RowsAffected()
if err != nil {
return errors.Wrap(err, "Fetch affected rows")
}
if n != 1 {
return fmt.Errorf("Q... | go | func (c *ClusterTx) ProjectDelete(name string) error {
stmt := c.stmt(projectDelete)
result, err := stmt.Exec(name)
if err != nil {
return errors.Wrap(err, "Delete project")
}
n, err := result.RowsAffected()
if err != nil {
return errors.Wrap(err, "Fetch affected rows")
}
if n != 1 {
return fmt.Errorf("Q... | [
"func",
"(",
"c",
"*",
"ClusterTx",
")",
"ProjectDelete",
"(",
"name",
"string",
")",
"error",
"{",
"stmt",
":=",
"c",
".",
"stmt",
"(",
"projectDelete",
")",
"\n",
"result",
",",
"err",
":=",
"stmt",
".",
"Exec",
"(",
"name",
")",
"\n",
"if",
"err... | // ProjectDelete deletes the project matching the given key parameters. | [
"ProjectDelete",
"deletes",
"the",
"project",
"matching",
"the",
"given",
"key",
"parameters",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.mapper.go#L434-L450 | test |
lxc/lxd | lxd/util/encryption.go | PasswordCheck | func PasswordCheck(secret string, password string) error {
// No password set
if secret == "" {
return fmt.Errorf("No password is set")
}
// Compare the password
buff, err := hex.DecodeString(secret)
if err != nil {
return err
}
salt := buff[0:32]
hash, err := scrypt.Key([]byte(password), salt, 1<<14, 8,... | go | func PasswordCheck(secret string, password string) error {
// No password set
if secret == "" {
return fmt.Errorf("No password is set")
}
// Compare the password
buff, err := hex.DecodeString(secret)
if err != nil {
return err
}
salt := buff[0:32]
hash, err := scrypt.Key([]byte(password), salt, 1<<14, 8,... | [
"func",
"PasswordCheck",
"(",
"secret",
"string",
",",
"password",
"string",
")",
"error",
"{",
"if",
"secret",
"==",
"\"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"No password is set\"",
")",
"\n",
"}",
"\n",
"buff",
",",
"err",
":=",
"hex",
".",
... | // PasswordCheck validates the provided password against the encoded secret | [
"PasswordCheck",
"validates",
"the",
"provided",
"password",
"against",
"the",
"encoded",
"secret"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/encryption.go#L17-L40 | test |
lxc/lxd | lxd/util/encryption.go | LoadCert | func LoadCert(dir string) (*shared.CertInfo, error) {
prefix := "server"
if shared.PathExists(filepath.Join(dir, "cluster.crt")) {
prefix = "cluster"
}
cert, err := shared.KeyPairAndCA(dir, prefix, shared.CertServer)
if err != nil {
return nil, errors.Wrap(err, "failed to load TLS certificate")
}
return cert... | go | func LoadCert(dir string) (*shared.CertInfo, error) {
prefix := "server"
if shared.PathExists(filepath.Join(dir, "cluster.crt")) {
prefix = "cluster"
}
cert, err := shared.KeyPairAndCA(dir, prefix, shared.CertServer)
if err != nil {
return nil, errors.Wrap(err, "failed to load TLS certificate")
}
return cert... | [
"func",
"LoadCert",
"(",
"dir",
"string",
")",
"(",
"*",
"shared",
".",
"CertInfo",
",",
"error",
")",
"{",
"prefix",
":=",
"\"server\"",
"\n",
"if",
"shared",
".",
"PathExists",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"\"cluster.crt\"",
")",
")... | // LoadCert reads the LXD server certificate from the given var dir.
//
// If a cluster certificate is found it will be loaded instead. | [
"LoadCert",
"reads",
"the",
"LXD",
"server",
"certificate",
"from",
"the",
"given",
"var",
"dir",
".",
"If",
"a",
"cluster",
"certificate",
"is",
"found",
"it",
"will",
"be",
"loaded",
"instead",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/encryption.go#L45-L55 | test |
lxc/lxd | lxd/util/encryption.go | WriteCert | func WriteCert(dir, prefix string, cert, key, ca []byte) error {
err := ioutil.WriteFile(filepath.Join(dir, prefix+".crt"), cert, 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(dir, prefix+".key"), key, 0600)
if err != nil {
return err
}
if ca != nil {
err = ioutil.WriteFile(file... | go | func WriteCert(dir, prefix string, cert, key, ca []byte) error {
err := ioutil.WriteFile(filepath.Join(dir, prefix+".crt"), cert, 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(filepath.Join(dir, prefix+".key"), key, 0600)
if err != nil {
return err
}
if ca != nil {
err = ioutil.WriteFile(file... | [
"func",
"WriteCert",
"(",
"dir",
",",
"prefix",
"string",
",",
"cert",
",",
"key",
",",
"ca",
"[",
"]",
"byte",
")",
"error",
"{",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"filepath",
".",
"Join",
"(",
"dir",
",",
"prefix",
"+",
"\".crt\"",
")... | // WriteCert writes the given material to the appropriate certificate files in
// the given LXD var directory. | [
"WriteCert",
"writes",
"the",
"given",
"material",
"to",
"the",
"appropriate",
"certificate",
"files",
"in",
"the",
"given",
"LXD",
"var",
"directory",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/encryption.go#L59-L78 | test |
lxc/lxd | lxd/daemon.go | NewDaemon | func NewDaemon(config *DaemonConfig, os *sys.OS) *Daemon {
return &Daemon{
config: config,
os: os,
setupChan: make(chan struct{}),
readyChan: make(chan struct{}),
shutdownChan: make(chan struct{}),
}
} | go | func NewDaemon(config *DaemonConfig, os *sys.OS) *Daemon {
return &Daemon{
config: config,
os: os,
setupChan: make(chan struct{}),
readyChan: make(chan struct{}),
shutdownChan: make(chan struct{}),
}
} | [
"func",
"NewDaemon",
"(",
"config",
"*",
"DaemonConfig",
",",
"os",
"*",
"sys",
".",
"OS",
")",
"*",
"Daemon",
"{",
"return",
"&",
"Daemon",
"{",
"config",
":",
"config",
",",
"os",
":",
"os",
",",
"setupChan",
":",
"make",
"(",
"chan",
"struct",
"... | // NewDaemon returns a new Daemon object with the given configuration. | [
"NewDaemon",
"returns",
"a",
"new",
"Daemon",
"object",
"with",
"the",
"given",
"configuration",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L124-L132 | test |
lxc/lxd | lxd/daemon.go | DefaultDaemon | func DefaultDaemon() *Daemon {
config := DefaultDaemonConfig()
os := sys.DefaultOS()
return NewDaemon(config, os)
} | go | func DefaultDaemon() *Daemon {
config := DefaultDaemonConfig()
os := sys.DefaultOS()
return NewDaemon(config, os)
} | [
"func",
"DefaultDaemon",
"(",
")",
"*",
"Daemon",
"{",
"config",
":=",
"DefaultDaemonConfig",
"(",
")",
"\n",
"os",
":=",
"sys",
".",
"DefaultOS",
"(",
")",
"\n",
"return",
"NewDaemon",
"(",
"config",
",",
"os",
")",
"\n",
"}"
] | // DefaultDaemon returns a new, un-initialized Daemon object with default values. | [
"DefaultDaemon",
"returns",
"a",
"new",
"un",
"-",
"initialized",
"Daemon",
"object",
"with",
"default",
"values",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L143-L147 | test |
lxc/lxd | lxd/daemon.go | AllowProjectPermission | func AllowProjectPermission(feature string, permission string) func(d *Daemon, r *http.Request) Response {
return func(d *Daemon, r *http.Request) Response {
// Shortcut for speed
if d.userIsAdmin(r) {
return EmptySyncResponse
}
// Get the project
project := projectParam(r)
// Validate whether the use... | go | func AllowProjectPermission(feature string, permission string) func(d *Daemon, r *http.Request) Response {
return func(d *Daemon, r *http.Request) Response {
// Shortcut for speed
if d.userIsAdmin(r) {
return EmptySyncResponse
}
// Get the project
project := projectParam(r)
// Validate whether the use... | [
"func",
"AllowProjectPermission",
"(",
"feature",
"string",
",",
"permission",
"string",
")",
"func",
"(",
"d",
"*",
"Daemon",
",",
"r",
"*",
"http",
".",
"Request",
")",
"Response",
"{",
"return",
"func",
"(",
"d",
"*",
"Daemon",
",",
"r",
"*",
"http"... | // AllowProjectPermission is a wrapper to check access against the project, its features and RBAC permission | [
"AllowProjectPermission",
"is",
"a",
"wrapper",
"to",
"check",
"access",
"against",
"the",
"project",
"its",
"features",
"and",
"RBAC",
"permission"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L172-L189 | test |
lxc/lxd | lxd/daemon.go | checkTrustedClient | func (d *Daemon) checkTrustedClient(r *http.Request) error {
trusted, _, _, err := d.Authenticate(r)
if !trusted || err != nil {
if err != nil {
return err
}
return fmt.Errorf("Not authorized")
}
return nil
} | go | func (d *Daemon) checkTrustedClient(r *http.Request) error {
trusted, _, _, err := d.Authenticate(r)
if !trusted || err != nil {
if err != nil {
return err
}
return fmt.Errorf("Not authorized")
}
return nil
} | [
"func",
"(",
"d",
"*",
"Daemon",
")",
"checkTrustedClient",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"trusted",
",",
"_",
",",
"_",
",",
"err",
":=",
"d",
".",
"Authenticate",
"(",
"r",
")",
"\n",
"if",
"!",
"trusted",
"||",
"err... | // Convenience function around Authenticate | [
"Convenience",
"function",
"around",
"Authenticate"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L192-L203 | test |
lxc/lxd | lxd/daemon.go | Authenticate | func (d *Daemon) Authenticate(r *http.Request) (bool, string, string, error) {
// Allow internal cluster traffic
if r.TLS != nil {
cert, _ := x509.ParseCertificate(d.endpoints.NetworkCert().KeyPair().Certificate[0])
clusterCerts := map[string]x509.Certificate{"0": *cert}
for i := range r.TLS.PeerCertificates {
... | go | func (d *Daemon) Authenticate(r *http.Request) (bool, string, string, error) {
// Allow internal cluster traffic
if r.TLS != nil {
cert, _ := x509.ParseCertificate(d.endpoints.NetworkCert().KeyPair().Certificate[0])
clusterCerts := map[string]x509.Certificate{"0": *cert}
for i := range r.TLS.PeerCertificates {
... | [
"func",
"(",
"d",
"*",
"Daemon",
")",
"Authenticate",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"(",
"bool",
",",
"string",
",",
"string",
",",
"error",
")",
"{",
"if",
"r",
".",
"TLS",
"!=",
"nil",
"{",
"cert",
",",
"_",
":=",
"x509",
".",
... | // Authenticate validates an incoming http Request
// It will check over what protocol it came, what type of request it is and
// will validate the TLS certificate or Macaroon.
//
// This does not perform authorization, only validates authentication | [
"Authenticate",
"validates",
"an",
"incoming",
"http",
"Request",
"It",
"will",
"check",
"over",
"what",
"protocol",
"it",
"came",
"what",
"type",
"of",
"request",
"it",
"is",
"and",
"will",
"validate",
"the",
"TLS",
"certificate",
"or",
"Macaroon",
".",
"Th... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L210-L278 | test |
lxc/lxd | lxd/daemon.go | State | func (d *Daemon) State() *state.State {
return state.NewState(d.db, d.cluster, d.maas, d.os, d.endpoints)
} | go | func (d *Daemon) State() *state.State {
return state.NewState(d.db, d.cluster, d.maas, d.os, d.endpoints)
} | [
"func",
"(",
"d",
"*",
"Daemon",
")",
"State",
"(",
")",
"*",
"state",
".",
"State",
"{",
"return",
"state",
".",
"NewState",
"(",
"d",
".",
"db",
",",
"d",
".",
"cluster",
",",
"d",
".",
"maas",
",",
"d",
".",
"os",
",",
"d",
".",
"endpoints... | // State creates a new State instance linked to our internal db and os. | [
"State",
"creates",
"a",
"new",
"State",
"instance",
"linked",
"to",
"our",
"internal",
"db",
"and",
"os",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L317-L319 | test |
lxc/lxd | lxd/daemon.go | UnixSocket | func (d *Daemon) UnixSocket() string {
path := os.Getenv("LXD_SOCKET")
if path != "" {
return path
}
return filepath.Join(d.os.VarDir, "unix.socket")
} | go | func (d *Daemon) UnixSocket() string {
path := os.Getenv("LXD_SOCKET")
if path != "" {
return path
}
return filepath.Join(d.os.VarDir, "unix.socket")
} | [
"func",
"(",
"d",
"*",
"Daemon",
")",
"UnixSocket",
"(",
")",
"string",
"{",
"path",
":=",
"os",
".",
"Getenv",
"(",
"\"LXD_SOCKET\"",
")",
"\n",
"if",
"path",
"!=",
"\"\"",
"{",
"return",
"path",
"\n",
"}",
"\n",
"return",
"filepath",
".",
"Join",
... | // UnixSocket returns the full path to the unix.socket file that this daemon is
// listening on. Used by tests. | [
"UnixSocket",
"returns",
"the",
"full",
"path",
"to",
"the",
"unix",
".",
"socket",
"file",
"that",
"this",
"daemon",
"is",
"listening",
"on",
".",
"Used",
"by",
"tests",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L323-L330 | test |
lxc/lxd | lxd/daemon.go | Stop | func (d *Daemon) Stop() error {
logger.Info("Starting shutdown sequence")
errs := []error{}
trackError := func(err error) {
if err != nil {
errs = append(errs, err)
}
}
if d.endpoints != nil {
trackError(d.endpoints.Down())
}
trackError(d.tasks.Stop(3 * time.Second)) // Give tasks a bit of time... | go | func (d *Daemon) Stop() error {
logger.Info("Starting shutdown sequence")
errs := []error{}
trackError := func(err error) {
if err != nil {
errs = append(errs, err)
}
}
if d.endpoints != nil {
trackError(d.endpoints.Down())
}
trackError(d.tasks.Stop(3 * time.Second)) // Give tasks a bit of time... | [
"func",
"(",
"d",
"*",
"Daemon",
")",
"Stop",
"(",
")",
"error",
"{",
"logger",
".",
"Info",
"(",
"\"Starting shutdown sequence\"",
")",
"\n",
"errs",
":=",
"[",
"]",
"error",
"{",
"}",
"\n",
"trackError",
":=",
"func",
"(",
"err",
"error",
")",
"{",... | // Stop stops the shared daemon. | [
"Stop",
"stops",
"the",
"shared",
"daemon",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L997-L1081 | test |
lxc/lxd | lxd/daemon.go | setupExternalAuthentication | func (d *Daemon) setupExternalAuthentication(authEndpoint string, authPubkey string, expiry int64, domains string) error {
// Parse the list of domains
authDomains := []string{}
for _, domain := range strings.Split(domains, ",") {
if domain == "" {
continue
}
authDomains = append(authDomains, strings.TrimS... | go | func (d *Daemon) setupExternalAuthentication(authEndpoint string, authPubkey string, expiry int64, domains string) error {
// Parse the list of domains
authDomains := []string{}
for _, domain := range strings.Split(domains, ",") {
if domain == "" {
continue
}
authDomains = append(authDomains, strings.TrimS... | [
"func",
"(",
"d",
"*",
"Daemon",
")",
"setupExternalAuthentication",
"(",
"authEndpoint",
"string",
",",
"authPubkey",
"string",
",",
"expiry",
"int64",
",",
"domains",
"string",
")",
"error",
"{",
"authDomains",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"... | // Setup external authentication | [
"Setup",
"external",
"authentication"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L1084-L1164 | test |
lxc/lxd | lxd/daemon.go | initializeDbObject | func initializeDbObject(d *Daemon) (*db.Dump, error) {
logger.Info("Initializing local database")
// Rename the old database name if needed.
if shared.PathExists(d.os.LegacyLocalDatabasePath()) {
if shared.PathExists(d.os.LocalDatabasePath()) {
return nil, fmt.Errorf("Both legacy and new local database files ex... | go | func initializeDbObject(d *Daemon) (*db.Dump, error) {
logger.Info("Initializing local database")
// Rename the old database name if needed.
if shared.PathExists(d.os.LegacyLocalDatabasePath()) {
if shared.PathExists(d.os.LocalDatabasePath()) {
return nil, fmt.Errorf("Both legacy and new local database files ex... | [
"func",
"initializeDbObject",
"(",
"d",
"*",
"Daemon",
")",
"(",
"*",
"db",
".",
"Dump",
",",
"error",
")",
"{",
"logger",
".",
"Info",
"(",
"\"Initializing local database\"",
")",
"\n",
"if",
"shared",
".",
"PathExists",
"(",
"d",
".",
"os",
".",
"Leg... | // Create a database connection and perform any updates needed. | [
"Create",
"a",
"database",
"connection",
"and",
"perform",
"any",
"updates",
"needed",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/daemon.go#L1255-L1314 | test |
lxc/lxd | lxd/util/http.go | WriteJSON | func WriteJSON(w http.ResponseWriter, body interface{}, debug bool) error {
var output io.Writer
var captured *bytes.Buffer
output = w
if debug {
captured = &bytes.Buffer{}
output = io.MultiWriter(w, captured)
}
err := json.NewEncoder(output).Encode(body)
if captured != nil {
shared.DebugJson(captured)
... | go | func WriteJSON(w http.ResponseWriter, body interface{}, debug bool) error {
var output io.Writer
var captured *bytes.Buffer
output = w
if debug {
captured = &bytes.Buffer{}
output = io.MultiWriter(w, captured)
}
err := json.NewEncoder(output).Encode(body)
if captured != nil {
shared.DebugJson(captured)
... | [
"func",
"WriteJSON",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"body",
"interface",
"{",
"}",
",",
"debug",
"bool",
")",
"error",
"{",
"var",
"output",
"io",
".",
"Writer",
"\n",
"var",
"captured",
"*",
"bytes",
".",
"Buffer",
"\n",
"output",
"=",
... | // WriteJSON encodes the body as JSON and sends it back to the client | [
"WriteJSON",
"encodes",
"the",
"body",
"as",
"JSON",
"and",
"sends",
"it",
"back",
"to",
"the",
"client"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/http.go#L29-L46 | test |
lxc/lxd | lxd/util/http.go | EtagHash | func EtagHash(data interface{}) (string, error) {
etag := sha256.New()
err := json.NewEncoder(etag).Encode(data)
if err != nil {
return "", err
}
return fmt.Sprintf("%x", etag.Sum(nil)), nil
} | go | func EtagHash(data interface{}) (string, error) {
etag := sha256.New()
err := json.NewEncoder(etag).Encode(data)
if err != nil {
return "", err
}
return fmt.Sprintf("%x", etag.Sum(nil)), nil
} | [
"func",
"EtagHash",
"(",
"data",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"error",
")",
"{",
"etag",
":=",
"sha256",
".",
"New",
"(",
")",
"\n",
"err",
":=",
"json",
".",
"NewEncoder",
"(",
"etag",
")",
".",
"Encode",
"(",
"data",
")",
"\n... | // EtagHash hashes the provided data and returns the sha256 | [
"EtagHash",
"hashes",
"the",
"provided",
"data",
"and",
"returns",
"the",
"sha256"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/http.go#L49-L57 | test |
lxc/lxd | lxd/util/http.go | EtagCheck | func EtagCheck(r *http.Request, data interface{}) error {
match := r.Header.Get("If-Match")
if match == "" {
return nil
}
hash, err := EtagHash(data)
if err != nil {
return err
}
if hash != match {
return fmt.Errorf("ETag doesn't match: %s vs %s", hash, match)
}
return nil
} | go | func EtagCheck(r *http.Request, data interface{}) error {
match := r.Header.Get("If-Match")
if match == "" {
return nil
}
hash, err := EtagHash(data)
if err != nil {
return err
}
if hash != match {
return fmt.Errorf("ETag doesn't match: %s vs %s", hash, match)
}
return nil
} | [
"func",
"EtagCheck",
"(",
"r",
"*",
"http",
".",
"Request",
",",
"data",
"interface",
"{",
"}",
")",
"error",
"{",
"match",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"If-Match\"",
")",
"\n",
"if",
"match",
"==",
"\"\"",
"{",
"return",
"nil",
"\n... | // EtagCheck validates the hash of the current state with the hash
// provided by the client | [
"EtagCheck",
"validates",
"the",
"hash",
"of",
"the",
"current",
"state",
"with",
"the",
"hash",
"provided",
"by",
"the",
"client"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/http.go#L61-L77 | test |
lxc/lxd | lxd/util/http.go | HTTPClient | func HTTPClient(certificate string, proxy proxyFunc) (*http.Client, error) {
var err error
var cert *x509.Certificate
if certificate != "" {
certBlock, _ := pem.Decode([]byte(certificate))
if certBlock == nil {
return nil, fmt.Errorf("Invalid certificate")
}
cert, err = x509.ParseCertificate(certBlock.B... | go | func HTTPClient(certificate string, proxy proxyFunc) (*http.Client, error) {
var err error
var cert *x509.Certificate
if certificate != "" {
certBlock, _ := pem.Decode([]byte(certificate))
if certBlock == nil {
return nil, fmt.Errorf("Invalid certificate")
}
cert, err = x509.ParseCertificate(certBlock.B... | [
"func",
"HTTPClient",
"(",
"certificate",
"string",
",",
"proxy",
"proxyFunc",
")",
"(",
"*",
"http",
".",
"Client",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"cert",
"*",
"x509",
".",
"Certificate",
"\n",
"if",
"certificate",
"!=",
"... | // HTTPClient returns an http.Client using the given certificate and proxy. | [
"HTTPClient",
"returns",
"an",
"http",
".",
"Client",
"using",
"the",
"given",
"certificate",
"and",
"proxy",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/http.go#L80-L121 | test |
lxc/lxd | lxd/util/http.go | IsRecursionRequest | func IsRecursionRequest(r *http.Request) bool {
recursionStr := r.FormValue("recursion")
recursion, err := strconv.Atoi(recursionStr)
if err != nil {
return false
}
return recursion != 0
} | go | func IsRecursionRequest(r *http.Request) bool {
recursionStr := r.FormValue("recursion")
recursion, err := strconv.Atoi(recursionStr)
if err != nil {
return false
}
return recursion != 0
} | [
"func",
"IsRecursionRequest",
"(",
"r",
"*",
"http",
".",
"Request",
")",
"bool",
"{",
"recursionStr",
":=",
"r",
".",
"FormValue",
"(",
"\"recursion\"",
")",
"\n",
"recursion",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"recursionStr",
")",
"\n",
"i... | // IsRecursionRequest checks whether the given HTTP request is marked with the
// "recursion" flag in its form values. | [
"IsRecursionRequest",
"checks",
"whether",
"the",
"given",
"HTTP",
"request",
"is",
"marked",
"with",
"the",
"recursion",
"flag",
"in",
"its",
"form",
"values",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/http.go#L153-L162 | test |
lxc/lxd | lxd/util/http.go | GetListeners | func GetListeners(start int) []net.Listener {
defer func() {
os.Unsetenv("LISTEN_PID")
os.Unsetenv("LISTEN_FDS")
}()
pid, err := strconv.Atoi(os.Getenv("LISTEN_PID"))
if err != nil {
return nil
}
if pid != os.Getpid() {
return nil
}
fds, err := strconv.Atoi(os.Getenv("LISTEN_FDS"))
if err != nil {
... | go | func GetListeners(start int) []net.Listener {
defer func() {
os.Unsetenv("LISTEN_PID")
os.Unsetenv("LISTEN_FDS")
}()
pid, err := strconv.Atoi(os.Getenv("LISTEN_PID"))
if err != nil {
return nil
}
if pid != os.Getpid() {
return nil
}
fds, err := strconv.Atoi(os.Getenv("LISTEN_FDS"))
if err != nil {
... | [
"func",
"GetListeners",
"(",
"start",
"int",
")",
"[",
"]",
"net",
".",
"Listener",
"{",
"defer",
"func",
"(",
")",
"{",
"os",
".",
"Unsetenv",
"(",
"\"LISTEN_PID\"",
")",
"\n",
"os",
".",
"Unsetenv",
"(",
"\"LISTEN_FDS\"",
")",
"\n",
"}",
"(",
")",
... | // GetListeners returns the socket-activated network listeners, if any.
//
// The 'start' parameter must be SystemdListenFDsStart, except in unit tests,
// see the docstring of SystemdListenFDsStart below. | [
"GetListeners",
"returns",
"the",
"socket",
"-",
"activated",
"network",
"listeners",
"if",
"any",
".",
"The",
"start",
"parameter",
"must",
"be",
"SystemdListenFDsStart",
"except",
"in",
"unit",
"tests",
"see",
"the",
"docstring",
"of",
"SystemdListenFDsStart",
"... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/http.go#L229-L264 | test |
lxc/lxd | lxd/api_internal.go | internalSQLGet | func internalSQLGet(d *Daemon, r *http.Request) Response {
database := r.FormValue("database")
if !shared.StringInSlice(database, []string{"local", "global"}) {
return BadRequest(fmt.Errorf("Invalid database"))
}
schemaFormValue := r.FormValue("schema")
schemaOnly, err := strconv.Atoi(schemaFormValue)
if err ... | go | func internalSQLGet(d *Daemon, r *http.Request) Response {
database := r.FormValue("database")
if !shared.StringInSlice(database, []string{"local", "global"}) {
return BadRequest(fmt.Errorf("Invalid database"))
}
schemaFormValue := r.FormValue("schema")
schemaOnly, err := strconv.Atoi(schemaFormValue)
if err ... | [
"func",
"internalSQLGet",
"(",
"d",
"*",
"Daemon",
",",
"r",
"*",
"http",
".",
"Request",
")",
"Response",
"{",
"database",
":=",
"r",
".",
"FormValue",
"(",
"\"database\"",
")",
"\n",
"if",
"!",
"shared",
".",
"StringInSlice",
"(",
"database",
",",
"[... | // Perform a database dump. | [
"Perform",
"a",
"database",
"dump",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_internal.go#L205-L238 | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.