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 | lxd/backup.go | Rename | func (b *backup) Rename(newName string) error {
oldBackupPath := shared.VarPath("backups", b.name)
newBackupPath := shared.VarPath("backups", newName)
// Create the new backup path
backupsPath := shared.VarPath("backups", b.container.Name())
if !shared.PathExists(backupsPath) {
err := os.MkdirAll(backupsPath, 0... | go | func (b *backup) Rename(newName string) error {
oldBackupPath := shared.VarPath("backups", b.name)
newBackupPath := shared.VarPath("backups", newName)
// Create the new backup path
backupsPath := shared.VarPath("backups", b.container.Name())
if !shared.PathExists(backupsPath) {
err := os.MkdirAll(backupsPath, 0... | [
"func",
"(",
"b",
"*",
"backup",
")",
"Rename",
"(",
"newName",
"string",
")",
"error",
"{",
"oldBackupPath",
":=",
"shared",
".",
"VarPath",
"(",
"\"backups\"",
",",
"b",
".",
"name",
")",
"\n",
"newBackupPath",
":=",
"shared",
".",
"VarPath",
"(",
"\... | // Rename renames a container backup | [
"Rename",
"renames",
"a",
"container",
"backup"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/backup.go#L107-L142 | test |
lxc/lxd | lxd/backup.go | Delete | func (b *backup) Delete() error {
return doBackupDelete(b.state, b.name, b.container.Name())
} | go | func (b *backup) Delete() error {
return doBackupDelete(b.state, b.name, b.container.Name())
} | [
"func",
"(",
"b",
"*",
"backup",
")",
"Delete",
"(",
")",
"error",
"{",
"return",
"doBackupDelete",
"(",
"b",
".",
"state",
",",
"b",
".",
"name",
",",
"b",
".",
"container",
".",
"Name",
"(",
")",
")",
"\n",
"}"
] | // Delete removes a container backup | [
"Delete",
"removes",
"a",
"container",
"backup"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/backup.go#L145-L147 | test |
lxc/lxd | lxd/backup.go | backupFixStoragePool | func backupFixStoragePool(c *db.Cluster, b backupInfo, useDefaultPool bool) error {
var poolName string
if useDefaultPool {
// Get the default profile
_, profile, err := c.ProfileGet("default", "default")
if err != nil {
return err
}
_, v, err := shared.GetRootDiskDevice(profile.Devices)
if err != ni... | go | func backupFixStoragePool(c *db.Cluster, b backupInfo, useDefaultPool bool) error {
var poolName string
if useDefaultPool {
// Get the default profile
_, profile, err := c.ProfileGet("default", "default")
if err != nil {
return err
}
_, v, err := shared.GetRootDiskDevice(profile.Devices)
if err != ni... | [
"func",
"backupFixStoragePool",
"(",
"c",
"*",
"db",
".",
"Cluster",
",",
"b",
"backupInfo",
",",
"useDefaultPool",
"bool",
")",
"error",
"{",
"var",
"poolName",
"string",
"\n",
"if",
"useDefaultPool",
"{",
"_",
",",
"profile",
",",
"err",
":=",
"c",
"."... | // fixBackupStoragePool changes the pool information in the backup.yaml. This
// is done only if the provided pool doesn't exist. In this case, the pool of
// the default profile will be used. | [
"fixBackupStoragePool",
"changes",
"the",
"pool",
"information",
"in",
"the",
"backup",
".",
"yaml",
".",
"This",
"is",
"done",
"only",
"if",
"the",
"provided",
"pool",
"doesn",
"t",
"exist",
".",
"In",
"this",
"case",
"the",
"pool",
"of",
"the",
"default"... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/backup.go#L232-L321 | test |
lxc/lxd | lxd/db/query/count.go | Count | func Count(tx *sql.Tx, table string, where string, args ...interface{}) (int, error) {
stmt := fmt.Sprintf("SELECT COUNT(*) FROM %s", table)
if where != "" {
stmt += fmt.Sprintf(" WHERE %s", where)
}
rows, err := tx.Query(stmt, args...)
if err != nil {
return -1, err
}
defer rows.Close()
// For sanity, mak... | go | func Count(tx *sql.Tx, table string, where string, args ...interface{}) (int, error) {
stmt := fmt.Sprintf("SELECT COUNT(*) FROM %s", table)
if where != "" {
stmt += fmt.Sprintf(" WHERE %s", where)
}
rows, err := tx.Query(stmt, args...)
if err != nil {
return -1, err
}
defer rows.Close()
// For sanity, mak... | [
"func",
"Count",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"table",
"string",
",",
"where",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"int",
",",
"error",
")",
"{",
"stmt",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"SELECT COUNT(*) FROM %... | // Count returns the number of rows in the given table. | [
"Count",
"returns",
"the",
"number",
"of",
"rows",
"in",
"the",
"given",
"table",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/query/count.go#L11-L40 | test |
lxc/lxd | lxd/db/query/count.go | CountAll | func CountAll(tx *sql.Tx) (map[string]int, error) {
tables, err := SelectStrings(tx, "SELECT name FROM sqlite_master WHERE type = 'table'")
if err != nil {
return nil, errors.Wrap(err, "Failed to fetch table names")
}
counts := map[string]int{}
for _, table := range tables {
count, err := Count(tx, table, "")... | go | func CountAll(tx *sql.Tx) (map[string]int, error) {
tables, err := SelectStrings(tx, "SELECT name FROM sqlite_master WHERE type = 'table'")
if err != nil {
return nil, errors.Wrap(err, "Failed to fetch table names")
}
counts := map[string]int{}
for _, table := range tables {
count, err := Count(tx, table, "")... | [
"func",
"CountAll",
"(",
"tx",
"*",
"sql",
".",
"Tx",
")",
"(",
"map",
"[",
"string",
"]",
"int",
",",
"error",
")",
"{",
"tables",
",",
"err",
":=",
"SelectStrings",
"(",
"tx",
",",
"\"SELECT name FROM sqlite_master WHERE type = 'table'\"",
")",
"\n",
"if... | // CountAll returns a map associating each table name in the database
// with the total count of its rows. | [
"CountAll",
"returns",
"a",
"map",
"associating",
"each",
"table",
"name",
"in",
"the",
"database",
"with",
"the",
"total",
"count",
"of",
"its",
"rows",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/query/count.go#L44-L60 | test |
lxc/lxd | shared/network.go | InitTLSConfig | func InitTLSConfig() *tls.Config {
return &tls.Config{
MinVersion: tls.VersionTLS12,
CipherSuites: []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA... | go | func InitTLSConfig() *tls.Config {
return &tls.Config{
MinVersion: tls.VersionTLS12,
CipherSuites: []uint16{
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA... | [
"func",
"InitTLSConfig",
"(",
")",
"*",
"tls",
".",
"Config",
"{",
"return",
"&",
"tls",
".",
"Config",
"{",
"MinVersion",
":",
"tls",
".",
"VersionTLS12",
",",
"CipherSuites",
":",
"[",
"]",
"uint16",
"{",
"tls",
".",
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA38... | // InitTLSConfig returns a tls.Config populated with default encryption
// parameters. This is used as baseline config for both client and server
// certificates used by LXD. | [
"InitTLSConfig",
"returns",
"a",
"tls",
".",
"Config",
"populated",
"with",
"default",
"encryption",
"parameters",
".",
"This",
"is",
"used",
"as",
"baseline",
"config",
"for",
"both",
"client",
"and",
"server",
"certificates",
"used",
"by",
"LXD",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/network.go#L49-L64 | test |
lxc/lxd | lxd/storage_lvm_utils.go | copyContainerThinpool | func (s *storageLvm) copyContainerThinpool(target container, source container, readonly bool) error {
err := s.createSnapshotContainer(target, source, readonly)
if err != nil {
logger.Errorf("Error creating snapshot LV for copy: %s", err)
return err
}
// Generate a new xfs's UUID
LVFilesystem := s.getLvmFiles... | go | func (s *storageLvm) copyContainerThinpool(target container, source container, readonly bool) error {
err := s.createSnapshotContainer(target, source, readonly)
if err != nil {
logger.Errorf("Error creating snapshot LV for copy: %s", err)
return err
}
// Generate a new xfs's UUID
LVFilesystem := s.getLvmFiles... | [
"func",
"(",
"s",
"*",
"storageLvm",
")",
"copyContainerThinpool",
"(",
"target",
"container",
",",
"source",
"container",
",",
"readonly",
"bool",
")",
"error",
"{",
"err",
":=",
"s",
".",
"createSnapshotContainer",
"(",
"target",
",",
"source",
",",
"reado... | // Copy a container on a storage pool that does use a thinpool. | [
"Copy",
"a",
"container",
"on",
"a",
"storage",
"pool",
"that",
"does",
"use",
"a",
"thinpool",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_lvm_utils.go#L302-L338 | test |
lxc/lxd | lxd/storage_lvm_utils.go | copyContainerLv | func (s *storageLvm) copyContainerLv(target container, source container, readonly bool, refresh bool) error {
exists, err := storageLVExists(getLvmDevPath(target.Project(), s.getOnDiskPoolName(),
storagePoolVolumeAPIEndpointContainers, containerNameToLVName(target.Name())))
if err != nil {
return err
}
// Only... | go | func (s *storageLvm) copyContainerLv(target container, source container, readonly bool, refresh bool) error {
exists, err := storageLVExists(getLvmDevPath(target.Project(), s.getOnDiskPoolName(),
storagePoolVolumeAPIEndpointContainers, containerNameToLVName(target.Name())))
if err != nil {
return err
}
// Only... | [
"func",
"(",
"s",
"*",
"storageLvm",
")",
"copyContainerLv",
"(",
"target",
"container",
",",
"source",
"container",
",",
"readonly",
"bool",
",",
"refresh",
"bool",
")",
"error",
"{",
"exists",
",",
"err",
":=",
"storageLVExists",
"(",
"getLvmDevPath",
"(",... | // Copy a container on a storage pool that does not use a thinpool. | [
"Copy",
"a",
"container",
"on",
"a",
"storage",
"pool",
"that",
"does",
"not",
"use",
"a",
"thinpool",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_lvm_utils.go#L369-L441 | test |
lxc/lxd | lxd/storage_lvm_utils.go | copyContainer | func (s *storageLvm) copyContainer(target container, source container, refresh bool) error {
targetPool, err := target.StoragePool()
if err != nil {
return err
}
targetContainerMntPoint := getContainerMountPoint(target.Project(), targetPool, target.Name())
err = createContainerMountpoint(targetContainerMntPoint... | go | func (s *storageLvm) copyContainer(target container, source container, refresh bool) error {
targetPool, err := target.StoragePool()
if err != nil {
return err
}
targetContainerMntPoint := getContainerMountPoint(target.Project(), targetPool, target.Name())
err = createContainerMountpoint(targetContainerMntPoint... | [
"func",
"(",
"s",
"*",
"storageLvm",
")",
"copyContainer",
"(",
"target",
"container",
",",
"source",
"container",
",",
"refresh",
"bool",
")",
"error",
"{",
"targetPool",
",",
"err",
":=",
"target",
".",
"StoragePool",
"(",
")",
"\n",
"if",
"err",
"!=",... | // Copy an lvm container. | [
"Copy",
"an",
"lvm",
"container",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_lvm_utils.go#L444-L480 | test |
lxc/lxd | lxd/storage_lvm_utils.go | copyVolume | func (s *storageLvm) copyVolume(sourcePool string, source string) error {
targetMntPoint := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name)
err := os.MkdirAll(targetMntPoint, 0711)
if err != nil {
return err
}
if s.useThinpool && sourcePool == s.pool.Name {
err = s.copyVolumeThinpool(source, s.vol... | go | func (s *storageLvm) copyVolume(sourcePool string, source string) error {
targetMntPoint := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name)
err := os.MkdirAll(targetMntPoint, 0711)
if err != nil {
return err
}
if s.useThinpool && sourcePool == s.pool.Name {
err = s.copyVolumeThinpool(source, s.vol... | [
"func",
"(",
"s",
"*",
"storageLvm",
")",
"copyVolume",
"(",
"sourcePool",
"string",
",",
"source",
"string",
")",
"error",
"{",
"targetMntPoint",
":=",
"getStoragePoolVolumeMountPoint",
"(",
"s",
".",
"pool",
".",
"Name",
",",
"s",
".",
"volume",
".",
"Na... | // Copy an LVM custom volume. | [
"Copy",
"an",
"LVM",
"custom",
"volume",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_lvm_utils.go#L950-L968 | test |
lxc/lxd | client/simplestreams_images.go | GetPrivateImage | func (r *ProtocolSimpleStreams) GetPrivateImage(fingerprint string, secret string) (*api.Image, string, error) {
return nil, "", fmt.Errorf("Private images aren't supported by the simplestreams protocol")
} | go | func (r *ProtocolSimpleStreams) GetPrivateImage(fingerprint string, secret string) (*api.Image, string, error) {
return nil, "", fmt.Errorf("Private images aren't supported by the simplestreams protocol")
} | [
"func",
"(",
"r",
"*",
"ProtocolSimpleStreams",
")",
"GetPrivateImage",
"(",
"fingerprint",
"string",
",",
"secret",
"string",
")",
"(",
"*",
"api",
".",
"Image",
",",
"string",
",",
"error",
")",
"{",
"return",
"nil",
",",
"\"\"",
",",
"fmt",
".",
"Er... | // GetPrivateImage isn't relevant for the simplestreams protocol | [
"GetPrivateImage",
"isn",
"t",
"relevant",
"for",
"the",
"simplestreams",
"protocol"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/simplestreams_images.go#L199-L201 | test |
lxc/lxd | client/simplestreams_images.go | GetPrivateImageFile | func (r *ProtocolSimpleStreams) GetPrivateImageFile(fingerprint string, secret string, req ImageFileRequest) (*ImageFileResponse, error) {
return nil, fmt.Errorf("Private images aren't supported by the simplestreams protocol")
} | go | func (r *ProtocolSimpleStreams) GetPrivateImageFile(fingerprint string, secret string, req ImageFileRequest) (*ImageFileResponse, error) {
return nil, fmt.Errorf("Private images aren't supported by the simplestreams protocol")
} | [
"func",
"(",
"r",
"*",
"ProtocolSimpleStreams",
")",
"GetPrivateImageFile",
"(",
"fingerprint",
"string",
",",
"secret",
"string",
",",
"req",
"ImageFileRequest",
")",
"(",
"*",
"ImageFileResponse",
",",
"error",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"... | // GetPrivateImageFile isn't relevant for the simplestreams protocol | [
"GetPrivateImageFile",
"isn",
"t",
"relevant",
"for",
"the",
"simplestreams",
"protocol"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/simplestreams_images.go#L204-L206 | test |
lxc/lxd | client/simplestreams_images.go | GetImageAliasNames | func (r *ProtocolSimpleStreams) GetImageAliasNames() ([]string, error) {
// Get all the images from simplestreams
aliases, err := r.ssClient.ListAliases()
if err != nil {
return nil, err
}
// And now extract just the names
names := []string{}
for _, alias := range aliases {
names = append(names, alias.Name)... | go | func (r *ProtocolSimpleStreams) GetImageAliasNames() ([]string, error) {
// Get all the images from simplestreams
aliases, err := r.ssClient.ListAliases()
if err != nil {
return nil, err
}
// And now extract just the names
names := []string{}
for _, alias := range aliases {
names = append(names, alias.Name)... | [
"func",
"(",
"r",
"*",
"ProtocolSimpleStreams",
")",
"GetImageAliasNames",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"aliases",
",",
"err",
":=",
"r",
".",
"ssClient",
".",
"ListAliases",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{"... | // GetImageAliasNames returns the list of available alias names | [
"GetImageAliasNames",
"returns",
"the",
"list",
"of",
"available",
"alias",
"names"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/simplestreams_images.go#L214-L228 | test |
lxc/lxd | lxd/migration/wsproto.go | ProtoRecv | func ProtoRecv(ws *websocket.Conn, msg proto.Message) error {
mt, r, err := ws.NextReader()
if err != nil {
return err
}
if mt != websocket.BinaryMessage {
return fmt.Errorf("Only binary messages allowed")
}
buf, err := ioutil.ReadAll(r)
if err != nil {
return err
}
err = proto.Unmarshal(buf, msg)
if... | go | func ProtoRecv(ws *websocket.Conn, msg proto.Message) error {
mt, r, err := ws.NextReader()
if err != nil {
return err
}
if mt != websocket.BinaryMessage {
return fmt.Errorf("Only binary messages allowed")
}
buf, err := ioutil.ReadAll(r)
if err != nil {
return err
}
err = proto.Unmarshal(buf, msg)
if... | [
"func",
"ProtoRecv",
"(",
"ws",
"*",
"websocket",
".",
"Conn",
",",
"msg",
"proto",
".",
"Message",
")",
"error",
"{",
"mt",
",",
"r",
",",
"err",
":=",
"ws",
".",
"NextReader",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n"... | // ProtoRecv gets a protobuf message from a websocket | [
"ProtoRecv",
"gets",
"a",
"protobuf",
"message",
"from",
"a",
"websocket"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/migration/wsproto.go#L14-L35 | test |
lxc/lxd | lxd/migration/wsproto.go | ProtoSend | func ProtoSend(ws *websocket.Conn, msg proto.Message) error {
w, err := ws.NextWriter(websocket.BinaryMessage)
if err != nil {
return err
}
defer w.Close()
data, err := proto.Marshal(msg)
if err != nil {
return err
}
err = shared.WriteAll(w, data)
if err != nil {
return err
}
return nil
} | go | func ProtoSend(ws *websocket.Conn, msg proto.Message) error {
w, err := ws.NextWriter(websocket.BinaryMessage)
if err != nil {
return err
}
defer w.Close()
data, err := proto.Marshal(msg)
if err != nil {
return err
}
err = shared.WriteAll(w, data)
if err != nil {
return err
}
return nil
} | [
"func",
"ProtoSend",
"(",
"ws",
"*",
"websocket",
".",
"Conn",
",",
"msg",
"proto",
".",
"Message",
")",
"error",
"{",
"w",
",",
"err",
":=",
"ws",
".",
"NextWriter",
"(",
"websocket",
".",
"BinaryMessage",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // ProtoSend sends a protobuf message over a websocket | [
"ProtoSend",
"sends",
"a",
"protobuf",
"message",
"over",
"a",
"websocket"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/migration/wsproto.go#L38-L56 | test |
lxc/lxd | lxd/migration/wsproto.go | ProtoSendControl | func ProtoSendControl(ws *websocket.Conn, err error) {
message := ""
if err != nil {
message = err.Error()
}
msg := MigrationControl{
Success: proto.Bool(err == nil),
Message: proto.String(message),
}
ProtoSend(ws, &msg)
} | go | func ProtoSendControl(ws *websocket.Conn, err error) {
message := ""
if err != nil {
message = err.Error()
}
msg := MigrationControl{
Success: proto.Bool(err == nil),
Message: proto.String(message),
}
ProtoSend(ws, &msg)
} | [
"func",
"ProtoSendControl",
"(",
"ws",
"*",
"websocket",
".",
"Conn",
",",
"err",
"error",
")",
"{",
"message",
":=",
"\"\"",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"message",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"msg",
":=",
"Migrati... | // ProtoSendControl sends a migration control message over a websocket | [
"ProtoSendControl",
"sends",
"a",
"migration",
"control",
"message",
"over",
"a",
"websocket"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/migration/wsproto.go#L59-L71 | test |
lxc/lxd | lxc/console.go | Read | func (er stdinMirror) Read(p []byte) (int, error) {
n, err := er.r.Read(p)
v := rune(p[0])
if v == '\u0001' && !*er.foundEscape {
*er.foundEscape = true
return 0, err
}
if v == 'q' && *er.foundEscape {
select {
case er.consoleDisconnect <- true:
return 0, err
default:
return 0, err
}
}
*er.f... | go | func (er stdinMirror) Read(p []byte) (int, error) {
n, err := er.r.Read(p)
v := rune(p[0])
if v == '\u0001' && !*er.foundEscape {
*er.foundEscape = true
return 0, err
}
if v == 'q' && *er.foundEscape {
select {
case er.consoleDisconnect <- true:
return 0, err
default:
return 0, err
}
}
*er.f... | [
"func",
"(",
"er",
"stdinMirror",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"er",
".",
"r",
".",
"Read",
"(",
"p",
")",
"\n",
"v",
":=",
"rune",
"(",
"p",
"[",
"0",
"]",
")",
... | // The pty has been switched to raw mode so we will only ever read a single
// byte. The buffer size is therefore uninteresting to us. | [
"The",
"pty",
"has",
"been",
"switched",
"to",
"raw",
"mode",
"so",
"we",
"will",
"only",
"ever",
"read",
"a",
"single",
"byte",
".",
"The",
"buffer",
"size",
"is",
"therefore",
"uninteresting",
"to",
"us",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxc/console.go#L86-L106 | test |
lxc/lxd | lxd/containers_get.go | doContainersGetFromNode | func doContainersGetFromNode(project, node string, cert *shared.CertInfo) ([]api.Container, error) {
f := func() ([]api.Container, error) {
client, err := cluster.Connect(node, cert, true)
if err != nil {
return nil, errors.Wrapf(err, "Failed to connect to node %s", node)
}
client = client.UseProject(proje... | go | func doContainersGetFromNode(project, node string, cert *shared.CertInfo) ([]api.Container, error) {
f := func() ([]api.Container, error) {
client, err := cluster.Connect(node, cert, true)
if err != nil {
return nil, errors.Wrapf(err, "Failed to connect to node %s", node)
}
client = client.UseProject(proje... | [
"func",
"doContainersGetFromNode",
"(",
"project",
",",
"node",
"string",
",",
"cert",
"*",
"shared",
".",
"CertInfo",
")",
"(",
"[",
"]",
"api",
".",
"Container",
",",
"error",
")",
"{",
"f",
":=",
"func",
"(",
")",
"(",
"[",
"]",
"api",
".",
"Con... | // Fetch information about the containers on the given remote node, using the
// rest API and with a timeout of 30 seconds. | [
"Fetch",
"information",
"about",
"the",
"containers",
"on",
"the",
"given",
"remote",
"node",
"using",
"the",
"rest",
"API",
"and",
"with",
"a",
"timeout",
"of",
"30",
"seconds",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/containers_get.go#L265-L300 | test |
lxc/lxd | lxd/db/query/retry.go | Retry | func Retry(f func() error) error {
// TODO: the retry loop should be configurable.
var err error
for i := 0; i < 5; i++ {
err = f()
if err != nil {
logger.Debugf("Database error: %#v", err)
if IsRetriableError(err) {
logger.Debugf("Retry failed db interaction (%v)", err)
time.Sleep(250 * time.Mill... | go | func Retry(f func() error) error {
// TODO: the retry loop should be configurable.
var err error
for i := 0; i < 5; i++ {
err = f()
if err != nil {
logger.Debugf("Database error: %#v", err)
if IsRetriableError(err) {
logger.Debugf("Retry failed db interaction (%v)", err)
time.Sleep(250 * time.Mill... | [
"func",
"Retry",
"(",
"f",
"func",
"(",
")",
"error",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"5",
";",
"i",
"++",
"{",
"err",
"=",
"f",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logger",
... | // Retry wraps a function that interacts with the database, and retries it in
// case a transient error is hit.
//
// This should by typically used to wrap transactions. | [
"Retry",
"wraps",
"a",
"function",
"that",
"interacts",
"with",
"the",
"database",
"and",
"retries",
"it",
"in",
"case",
"a",
"transient",
"error",
"is",
"hit",
".",
"This",
"should",
"by",
"typically",
"used",
"to",
"wrap",
"transactions",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/query/retry.go#L16-L33 | test |
lxc/lxd | lxd/db/query/retry.go | IsRetriableError | func IsRetriableError(err error) bool {
err = errors.Cause(err)
if err == nil {
return false
}
if err == sqlite3.ErrLocked || err == sqlite3.ErrBusy {
return true
}
if strings.Contains(err.Error(), "database is locked") {
return true
}
if strings.Contains(err.Error(), "bad connection") {
return true
... | go | func IsRetriableError(err error) bool {
err = errors.Cause(err)
if err == nil {
return false
}
if err == sqlite3.ErrLocked || err == sqlite3.ErrBusy {
return true
}
if strings.Contains(err.Error(), "database is locked") {
return true
}
if strings.Contains(err.Error(), "bad connection") {
return true
... | [
"func",
"IsRetriableError",
"(",
"err",
"error",
")",
"bool",
"{",
"err",
"=",
"errors",
".",
"Cause",
"(",
"err",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"err",
"==",
"sqlite3",
".",
"ErrLocked",
"||",
"... | // IsRetriableError returns true if the given error might be transient and the
// interaction can be safely retried. | [
"IsRetriableError",
"returns",
"true",
"if",
"the",
"given",
"error",
"might",
"be",
"transient",
"and",
"the",
"interaction",
"can",
"be",
"safely",
"retried",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/query/retry.go#L37-L60 | test |
lxc/lxd | lxd/util/apparmor.go | AppArmorProfile | func AppArmorProfile() string {
contents, err := ioutil.ReadFile("/proc/self/attr/current")
if err == nil {
return strings.TrimSpace(string(contents))
}
return ""
} | go | func AppArmorProfile() string {
contents, err := ioutil.ReadFile("/proc/self/attr/current")
if err == nil {
return strings.TrimSpace(string(contents))
}
return ""
} | [
"func",
"AppArmorProfile",
"(",
")",
"string",
"{",
"contents",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"\"/proc/self/attr/current\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"strings",
".",
"TrimSpace",
"(",
"string",
"(",
"contents",
... | // AppArmorProfile returns the current apparmor profile. | [
"AppArmorProfile",
"returns",
"the",
"current",
"apparmor",
"profile",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/apparmor.go#L9-L16 | test |
lxc/lxd | lxd/storage_btrfs.go | StoragePoolVolumeCreate | func (s *storageBtrfs) StoragePoolVolumeCreate() error {
logger.Infof("Creating BTRFS storage volume \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
_, err := s.StoragePoolMount()
if err != nil {
return err
}
isSnapshot := shared.IsSnapshot(s.volume.Name)
// Create subvolume path on the storage p... | go | func (s *storageBtrfs) StoragePoolVolumeCreate() error {
logger.Infof("Creating BTRFS storage volume \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
_, err := s.StoragePoolMount()
if err != nil {
return err
}
isSnapshot := shared.IsSnapshot(s.volume.Name)
// Create subvolume path on the storage p... | [
"func",
"(",
"s",
"*",
"storageBtrfs",
")",
"StoragePoolVolumeCreate",
"(",
")",
"error",
"{",
"logger",
".",
"Infof",
"(",
"\"Creating BTRFS storage volume \\\"%s\\\" on storage pool \\\"%s\\\"\"",
",",
"\\\"",
",",
"\\\"",
")",
"\n",
"\\\"",
"\n",
"\\\"",
"\n",
... | // Functions dealing with storage volumes. | [
"Functions",
"dealing",
"with",
"storage",
"volumes",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_btrfs.go#L552-L607 | test |
lxc/lxd | lxd/storage_btrfs.go | ContainerStorageReady | func (s *storageBtrfs) ContainerStorageReady(container container) bool {
containerMntPoint := getContainerMountPoint(container.Project(), s.pool.Name, container.Name())
return isBtrfsSubVolume(containerMntPoint)
} | go | func (s *storageBtrfs) ContainerStorageReady(container container) bool {
containerMntPoint := getContainerMountPoint(container.Project(), s.pool.Name, container.Name())
return isBtrfsSubVolume(containerMntPoint)
} | [
"func",
"(",
"s",
"*",
"storageBtrfs",
")",
"ContainerStorageReady",
"(",
"container",
"container",
")",
"bool",
"{",
"containerMntPoint",
":=",
"getContainerMountPoint",
"(",
"container",
".",
"Project",
"(",
")",
",",
"s",
".",
"pool",
".",
"Name",
",",
"c... | // Functions dealing with container storage. | [
"Functions",
"dealing",
"with",
"container",
"storage",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_btrfs.go#L817-L820 | test |
lxc/lxd | lxd/storage_btrfs.go | ContainerCreateFromImage | func (s *storageBtrfs) ContainerCreateFromImage(container container, fingerprint string, tracker *ioprogress.ProgressTracker) error {
logger.Debugf("Creating BTRFS storage volume for container \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
source := s.pool.Config["source"]
if source == "" {
return fm... | go | func (s *storageBtrfs) ContainerCreateFromImage(container container, fingerprint string, tracker *ioprogress.ProgressTracker) error {
logger.Debugf("Creating BTRFS storage volume for container \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
source := s.pool.Config["source"]
if source == "" {
return fm... | [
"func",
"(",
"s",
"*",
"storageBtrfs",
")",
"ContainerCreateFromImage",
"(",
"container",
"container",
",",
"fingerprint",
"string",
",",
"tracker",
"*",
"ioprogress",
".",
"ProgressTracker",
")",
"error",
"{",
"logger",
".",
"Debugf",
"(",
"\"Creating BTRFS stora... | // And this function is why I started hating on btrfs... | [
"And",
"this",
"function",
"is",
"why",
"I",
"started",
"hating",
"on",
"btrfs",
"..."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_btrfs.go#L872-L953 | test |
lxc/lxd | lxd/storage_btrfs.go | ContainerSnapshotRename | func (s *storageBtrfs) ContainerSnapshotRename(snapshotContainer container, newName string) error {
logger.Debugf("Renaming BTRFS storage volume for snapshot \"%s\" from %s to %s", s.volume.Name, s.volume.Name, newName)
// The storage pool must be mounted.
_, err := s.StoragePoolMount()
if err != nil {
return er... | go | func (s *storageBtrfs) ContainerSnapshotRename(snapshotContainer container, newName string) error {
logger.Debugf("Renaming BTRFS storage volume for snapshot \"%s\" from %s to %s", s.volume.Name, s.volume.Name, newName)
// The storage pool must be mounted.
_, err := s.StoragePoolMount()
if err != nil {
return er... | [
"func",
"(",
"s",
"*",
"storageBtrfs",
")",
"ContainerSnapshotRename",
"(",
"snapshotContainer",
"container",
",",
"newName",
"string",
")",
"error",
"{",
"logger",
".",
"Debugf",
"(",
"\"Renaming BTRFS storage volume for snapshot \\\"%s\\\" from %s to %s\"",
",",
"\\\"",... | // ContainerSnapshotRename renames a snapshot of a container. | [
"ContainerSnapshotRename",
"renames",
"a",
"snapshot",
"of",
"a",
"container",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_btrfs.go#L1545-L1565 | test |
lxc/lxd | lxd/storage_btrfs.go | ContainerSnapshotCreateEmpty | func (s *storageBtrfs) ContainerSnapshotCreateEmpty(snapshotContainer container) error {
logger.Debugf("Creating empty BTRFS storage volume for snapshot \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
// Mount the storage pool.
_, err := s.StoragePoolMount()
if err != nil {
return err
}
// Create ... | go | func (s *storageBtrfs) ContainerSnapshotCreateEmpty(snapshotContainer container) error {
logger.Debugf("Creating empty BTRFS storage volume for snapshot \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name)
// Mount the storage pool.
_, err := s.StoragePoolMount()
if err != nil {
return err
}
// Create ... | [
"func",
"(",
"s",
"*",
"storageBtrfs",
")",
"ContainerSnapshotCreateEmpty",
"(",
"snapshotContainer",
"container",
")",
"error",
"{",
"logger",
".",
"Debugf",
"(",
"\"Creating empty BTRFS storage volume for snapshot \\\"%s\\\" on storage pool \\\"%s\\\"\"",
",",
"\\\"",
",",
... | // Needed for live migration where an empty snapshot needs to be created before
// rsyncing into it. | [
"Needed",
"for",
"live",
"migration",
"where",
"an",
"empty",
"snapshot",
"needs",
"to",
"be",
"created",
"before",
"rsyncing",
"into",
"it",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_btrfs.go#L1569-L1605 | test |
lxc/lxd | lxd/storage_btrfs.go | btrfsSubVolumesDelete | func btrfsSubVolumesDelete(subvol string) error {
// Delete subsubvols.
subsubvols, err := btrfsSubVolumesGet(subvol)
if err != nil {
return err
}
sort.Sort(sort.Reverse(sort.StringSlice(subsubvols)))
for _, subsubvol := range subsubvols {
err := btrfsSubVolumeDelete(path.Join(subvol, subsubvol))
if err !=... | go | func btrfsSubVolumesDelete(subvol string) error {
// Delete subsubvols.
subsubvols, err := btrfsSubVolumesGet(subvol)
if err != nil {
return err
}
sort.Sort(sort.Reverse(sort.StringSlice(subsubvols)))
for _, subsubvol := range subsubvols {
err := btrfsSubVolumeDelete(path.Join(subvol, subsubvol))
if err !=... | [
"func",
"btrfsSubVolumesDelete",
"(",
"subvol",
"string",
")",
"error",
"{",
"subsubvols",
",",
"err",
":=",
"btrfsSubVolumesGet",
"(",
"subvol",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"sort",
".",
"Sort",
"(",
"sort"... | // btrfsPoolVolumesDelete is the recursive variant on btrfsPoolVolumeDelete,
// it first deletes subvolumes of the subvolume and then the
// subvolume itself. | [
"btrfsPoolVolumesDelete",
"is",
"the",
"recursive",
"variant",
"on",
"btrfsPoolVolumeDelete",
"it",
"first",
"deletes",
"subvolumes",
"of",
"the",
"subvolume",
"and",
"then",
"the",
"subvolume",
"itself",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_btrfs.go#L2242-L2264 | test |
lxc/lxd | lxd/storage_btrfs.go | isBtrfsSubVolume | func isBtrfsSubVolume(subvolPath string) bool {
fs := syscall.Stat_t{}
err := syscall.Lstat(subvolPath, &fs)
if err != nil {
return false
}
// Check if BTRFS_FIRST_FREE_OBJECTID
if fs.Ino != 256 {
return false
}
return true
} | go | func isBtrfsSubVolume(subvolPath string) bool {
fs := syscall.Stat_t{}
err := syscall.Lstat(subvolPath, &fs)
if err != nil {
return false
}
// Check if BTRFS_FIRST_FREE_OBJECTID
if fs.Ino != 256 {
return false
}
return true
} | [
"func",
"isBtrfsSubVolume",
"(",
"subvolPath",
"string",
")",
"bool",
"{",
"fs",
":=",
"syscall",
".",
"Stat_t",
"{",
"}",
"\n",
"err",
":=",
"syscall",
".",
"Lstat",
"(",
"subvolPath",
",",
"&",
"fs",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retur... | // isBtrfsSubVolume returns true if the given Path is a btrfs subvolume else
// false. | [
"isBtrfsSubVolume",
"returns",
"true",
"if",
"the",
"given",
"Path",
"is",
"a",
"btrfs",
"subvolume",
"else",
"false",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_btrfs.go#L2350-L2363 | test |
lxc/lxd | lxd/db/query/config.go | SelectConfig | func SelectConfig(tx *sql.Tx, table string, where string, args ...interface{}) (map[string]string, error) {
query := fmt.Sprintf("SELECT key, value FROM %s", table)
if where != "" {
query += fmt.Sprintf(" WHERE %s", where)
}
rows, err := tx.Query(query, args...)
if err != nil {
return nil, err
}
defer rows.... | go | func SelectConfig(tx *sql.Tx, table string, where string, args ...interface{}) (map[string]string, error) {
query := fmt.Sprintf("SELECT key, value FROM %s", table)
if where != "" {
query += fmt.Sprintf(" WHERE %s", where)
}
rows, err := tx.Query(query, args...)
if err != nil {
return nil, err
}
defer rows.... | [
"func",
"SelectConfig",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"table",
"string",
",",
"where",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"query",
":=",
"fmt",
".",
... | // SelectConfig executes a query statement against a "config" table, which must
// have 'key' and 'value' columns. By default this query returns all keys, but
// additional WHERE filters can be specified.
//
// Returns a map of key names to their associated values. | [
"SelectConfig",
"executes",
"a",
"query",
"statement",
"against",
"a",
"config",
"table",
"which",
"must",
"have",
"key",
"and",
"value",
"columns",
".",
"By",
"default",
"this",
"query",
"returns",
"all",
"keys",
"but",
"additional",
"WHERE",
"filters",
"can"... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/query/config.go#L16-L47 | test |
lxc/lxd | lxd/db/query/config.go | UpdateConfig | func UpdateConfig(tx *sql.Tx, table string, values map[string]string) error {
changes := map[string]string{}
deletes := []string{}
for key, value := range values {
if value == "" {
deletes = append(deletes, key)
continue
}
changes[key] = value
}
err := upsertConfig(tx, table, changes)
if err != nil ... | go | func UpdateConfig(tx *sql.Tx, table string, values map[string]string) error {
changes := map[string]string{}
deletes := []string{}
for key, value := range values {
if value == "" {
deletes = append(deletes, key)
continue
}
changes[key] = value
}
err := upsertConfig(tx, table, changes)
if err != nil ... | [
"func",
"UpdateConfig",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"table",
"string",
",",
"values",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"changes",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"deletes",
":=",
"[",
"]"... | // UpdateConfig updates the given keys in the given table. Config keys set to
// empty values will be deleted. | [
"UpdateConfig",
"updates",
"the",
"given",
"keys",
"in",
"the",
"given",
"table",
".",
"Config",
"keys",
"set",
"to",
"empty",
"values",
"will",
"be",
"deleted",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/query/config.go#L51-L74 | test |
lxc/lxd | lxd/db/query/config.go | deleteConfig | func deleteConfig(tx *sql.Tx, table string, keys []string) error {
n := len(keys)
if n == 0 {
return nil // Nothing to delete.
}
query := fmt.Sprintf("DELETE FROM %s WHERE key IN %s", table, Params(n))
values := make([]interface{}, n)
for i, key := range keys {
values[i] = key
}
_, err := tx.Exec(query, v... | go | func deleteConfig(tx *sql.Tx, table string, keys []string) error {
n := len(keys)
if n == 0 {
return nil // Nothing to delete.
}
query := fmt.Sprintf("DELETE FROM %s WHERE key IN %s", table, Params(n))
values := make([]interface{}, n)
for i, key := range keys {
values[i] = key
}
_, err := tx.Exec(query, v... | [
"func",
"deleteConfig",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"table",
"string",
",",
"keys",
"[",
"]",
"string",
")",
"error",
"{",
"n",
":=",
"len",
"(",
"keys",
")",
"\n",
"if",
"n",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"query"... | // Delete the given key rows from the given config table. | [
"Delete",
"the",
"given",
"key",
"rows",
"from",
"the",
"given",
"config",
"table",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/query/config.go#L96-L110 | test |
lxc/lxd | shared/cmd/format.go | FormatSection | func FormatSection(header string, content string) string {
out := ""
// Add section header
if header != "" {
out += header + ":\n"
}
// Indent the content
for _, line := range strings.Split(content, "\n") {
if line != "" {
out += " "
}
out += line + "\n"
}
if header != "" {
// Section separato... | go | func FormatSection(header string, content string) string {
out := ""
// Add section header
if header != "" {
out += header + ":\n"
}
// Indent the content
for _, line := range strings.Split(content, "\n") {
if line != "" {
out += " "
}
out += line + "\n"
}
if header != "" {
// Section separato... | [
"func",
"FormatSection",
"(",
"header",
"string",
",",
"content",
"string",
")",
"string",
"{",
"out",
":=",
"\"\"",
"\n",
"if",
"header",
"!=",
"\"\"",
"{",
"out",
"+=",
"header",
"+",
"\":\\n\"",
"\n",
"}",
"\n",
"\\n",
"\n",
"for",
"_",
",",
"line... | // FormatSection properly indents a text section | [
"FormatSection",
"properly",
"indents",
"a",
"text",
"section"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/cmd/format.go#L8-L34 | test |
lxc/lxd | client/lxd_projects.go | GetProjects | func (r *ProtocolLXD) GetProjects() ([]api.Project, error) {
if !r.HasExtension("projects") {
return nil, fmt.Errorf("The server is missing the required \"projects\" API extension")
}
projects := []api.Project{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/projects?recursion=1", nil, "", &projects)
... | go | func (r *ProtocolLXD) GetProjects() ([]api.Project, error) {
if !r.HasExtension("projects") {
return nil, fmt.Errorf("The server is missing the required \"projects\" API extension")
}
projects := []api.Project{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/projects?recursion=1", nil, "", &projects)
... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetProjects",
"(",
")",
"(",
"[",
"]",
"api",
".",
"Project",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"projects\"",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
... | // GetProjects returns a list of available Project structs | [
"GetProjects",
"returns",
"a",
"list",
"of",
"available",
"Project",
"structs"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_projects.go#L38-L52 | test |
lxc/lxd | client/lxd_projects.go | GetProject | func (r *ProtocolLXD) GetProject(name string) (*api.Project, string, error) {
if !r.HasExtension("projects") {
return nil, "", fmt.Errorf("The server is missing the required \"projects\" API extension")
}
project := api.Project{}
// Fetch the raw value
etag, err := r.queryStruct("GET", fmt.Sprintf("/projects/%... | go | func (r *ProtocolLXD) GetProject(name string) (*api.Project, string, error) {
if !r.HasExtension("projects") {
return nil, "", fmt.Errorf("The server is missing the required \"projects\" API extension")
}
project := api.Project{}
// Fetch the raw value
etag, err := r.queryStruct("GET", fmt.Sprintf("/projects/%... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetProject",
"(",
"name",
"string",
")",
"(",
"*",
"api",
".",
"Project",
",",
"string",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"projects\"",
")",
"{",
"return",
"nil",
",",
"... | // GetProject returns a Project entry for the provided name | [
"GetProject",
"returns",
"a",
"Project",
"entry",
"for",
"the",
"provided",
"name"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_projects.go#L55-L69 | test |
lxc/lxd | client/lxd_projects.go | CreateProject | func (r *ProtocolLXD) CreateProject(project api.ProjectsPost) error {
if !r.HasExtension("projects") {
return fmt.Errorf("The server is missing the required \"projects\" API extension")
}
// Send the request
_, _, err := r.query("POST", "/projects", project, "")
if err != nil {
return err
}
return nil
} | go | func (r *ProtocolLXD) CreateProject(project api.ProjectsPost) error {
if !r.HasExtension("projects") {
return fmt.Errorf("The server is missing the required \"projects\" API extension")
}
// Send the request
_, _, err := r.query("POST", "/projects", project, "")
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"CreateProject",
"(",
"project",
"api",
".",
"ProjectsPost",
")",
"error",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"projects\"",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"The server is missing the r... | // CreateProject defines a new container project | [
"CreateProject",
"defines",
"a",
"new",
"container",
"project"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_projects.go#L72-L84 | test |
lxc/lxd | client/lxd_projects.go | UpdateProject | func (r *ProtocolLXD) UpdateProject(name string, project api.ProjectPut, ETag string) error {
if !r.HasExtension("projects") {
return fmt.Errorf("The server is missing the required \"projects\" API extension")
}
// Send the request
_, _, err := r.query("PUT", fmt.Sprintf("/projects/%s", url.QueryEscape(name)), p... | go | func (r *ProtocolLXD) UpdateProject(name string, project api.ProjectPut, ETag string) error {
if !r.HasExtension("projects") {
return fmt.Errorf("The server is missing the required \"projects\" API extension")
}
// Send the request
_, _, err := r.query("PUT", fmt.Sprintf("/projects/%s", url.QueryEscape(name)), p... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"UpdateProject",
"(",
"name",
"string",
",",
"project",
"api",
".",
"ProjectPut",
",",
"ETag",
"string",
")",
"error",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"projects\"",
")",
"{",
"return",
"fmt",
... | // UpdateProject updates the project to match the provided Project struct | [
"UpdateProject",
"updates",
"the",
"project",
"to",
"match",
"the",
"provided",
"Project",
"struct"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_projects.go#L87-L99 | test |
lxc/lxd | client/lxd_projects.go | RenameProject | func (r *ProtocolLXD) RenameProject(name string, project api.ProjectPost) (Operation, error) {
if !r.HasExtension("projects") {
return nil, fmt.Errorf("The server is missing the required \"projects\" API extension")
}
// Send the request
op, _, err := r.queryOperation("POST", fmt.Sprintf("/projects/%s", url.Quer... | go | func (r *ProtocolLXD) RenameProject(name string, project api.ProjectPost) (Operation, error) {
if !r.HasExtension("projects") {
return nil, fmt.Errorf("The server is missing the required \"projects\" API extension")
}
// Send the request
op, _, err := r.queryOperation("POST", fmt.Sprintf("/projects/%s", url.Quer... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"RenameProject",
"(",
"name",
"string",
",",
"project",
"api",
".",
"ProjectPost",
")",
"(",
"Operation",
",",
"error",
")",
"{",
"if",
"!",
"r",
".",
"HasExtension",
"(",
"\"projects\"",
")",
"{",
"return",
"... | // RenameProject renames an existing project entry | [
"RenameProject",
"renames",
"an",
"existing",
"project",
"entry"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_projects.go#L102-L114 | test |
lxc/lxd | shared/eagain/file.go | Read | func (er Reader) Read(p []byte) (int, error) {
again:
n, err := er.Reader.Read(p)
if err == nil {
return n, nil
}
// keep retrying on EAGAIN
errno, ok := shared.GetErrno(err)
if ok && (errno == syscall.EAGAIN || errno == syscall.EINTR) {
goto again
}
return n, err
} | go | func (er Reader) Read(p []byte) (int, error) {
again:
n, err := er.Reader.Read(p)
if err == nil {
return n, nil
}
// keep retrying on EAGAIN
errno, ok := shared.GetErrno(err)
if ok && (errno == syscall.EAGAIN || errno == syscall.EINTR) {
goto again
}
return n, err
} | [
"func",
"(",
"er",
"Reader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"again",
":",
"n",
",",
"err",
":=",
"er",
".",
"Reader",
".",
"Read",
"(",
"p",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"retur... | // Read behaves like io.Reader.Read but will retry on EAGAIN | [
"Read",
"behaves",
"like",
"io",
".",
"Reader",
".",
"Read",
"but",
"will",
"retry",
"on",
"EAGAIN"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/eagain/file.go#L16-L30 | test |
lxc/lxd | shared/eagain/file.go | Write | func (ew Writer) Write(p []byte) (int, error) {
again:
n, err := ew.Writer.Write(p)
if err == nil {
return n, nil
}
// keep retrying on EAGAIN
errno, ok := shared.GetErrno(err)
if ok && (errno == syscall.EAGAIN || errno == syscall.EINTR) {
goto again
}
return n, err
} | go | func (ew Writer) Write(p []byte) (int, error) {
again:
n, err := ew.Writer.Write(p)
if err == nil {
return n, nil
}
// keep retrying on EAGAIN
errno, ok := shared.GetErrno(err)
if ok && (errno == syscall.EAGAIN || errno == syscall.EINTR) {
goto again
}
return n, err
} | [
"func",
"(",
"ew",
"Writer",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"again",
":",
"n",
",",
"err",
":=",
"ew",
".",
"Writer",
".",
"Write",
"(",
"p",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"ret... | // Write behaves like io.Writer.Write but will retry on EAGAIN | [
"Write",
"behaves",
"like",
"io",
".",
"Writer",
".",
"Write",
"but",
"will",
"retry",
"on",
"EAGAIN"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/eagain/file.go#L38-L52 | test |
lxc/lxd | shared/cancel/canceler.go | NewCanceler | func NewCanceler() *Canceler {
c := Canceler{}
c.lock.Lock()
c.reqChCancel = make(map[*http.Request]chan struct{})
c.lock.Unlock()
return &c
} | go | func NewCanceler() *Canceler {
c := Canceler{}
c.lock.Lock()
c.reqChCancel = make(map[*http.Request]chan struct{})
c.lock.Unlock()
return &c
} | [
"func",
"NewCanceler",
"(",
")",
"*",
"Canceler",
"{",
"c",
":=",
"Canceler",
"{",
"}",
"\n",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"reqChCancel",
"=",
"make",
"(",
"map",
"[",
"*",
"http",
".",
"Request",
"]",
"chan",
"struct"... | // NewCanceler returns a new Canceler struct | [
"NewCanceler",
"returns",
"a",
"new",
"Canceler",
"struct"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/cancel/canceler.go#L16-L24 | test |
lxc/lxd | shared/cancel/canceler.go | Cancelable | func (c *Canceler) Cancelable() bool {
c.lock.Lock()
length := len(c.reqChCancel)
c.lock.Unlock()
return length > 0
} | go | func (c *Canceler) Cancelable() bool {
c.lock.Lock()
length := len(c.reqChCancel)
c.lock.Unlock()
return length > 0
} | [
"func",
"(",
"c",
"*",
"Canceler",
")",
"Cancelable",
"(",
")",
"bool",
"{",
"c",
".",
"lock",
".",
"Lock",
"(",
")",
"\n",
"length",
":=",
"len",
"(",
"c",
".",
"reqChCancel",
")",
"\n",
"c",
".",
"lock",
".",
"Unlock",
"(",
")",
"\n",
"return... | // Cancelable indicates whether there are operations that support cancelation | [
"Cancelable",
"indicates",
"whether",
"there",
"are",
"operations",
"that",
"support",
"cancelation"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/cancel/canceler.go#L27-L33 | test |
lxc/lxd | shared/cancel/canceler.go | Cancel | func (c *Canceler) Cancel() error {
if !c.Cancelable() {
return fmt.Errorf("This operation can't be canceled at this time")
}
c.lock.Lock()
for req, ch := range c.reqChCancel {
close(ch)
delete(c.reqChCancel, req)
}
c.lock.Unlock()
return nil
} | go | func (c *Canceler) Cancel() error {
if !c.Cancelable() {
return fmt.Errorf("This operation can't be canceled at this time")
}
c.lock.Lock()
for req, ch := range c.reqChCancel {
close(ch)
delete(c.reqChCancel, req)
}
c.lock.Unlock()
return nil
} | [
"func",
"(",
"c",
"*",
"Canceler",
")",
"Cancel",
"(",
")",
"error",
"{",
"if",
"!",
"c",
".",
"Cancelable",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"This operation can't be canceled at this time\"",
")",
"\n",
"}",
"\n",
"c",
".",
"lock",
... | // Cancel will attempt to cancel all ongoing operations | [
"Cancel",
"will",
"attempt",
"to",
"cancel",
"all",
"ongoing",
"operations"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/cancel/canceler.go#L36-L49 | test |
lxc/lxd | shared/cancel/canceler.go | CancelableDownload | func CancelableDownload(c *Canceler, client *http.Client, req *http.Request) (*http.Response, chan bool, error) {
chDone := make(chan bool)
chCancel := make(chan struct{})
if c != nil {
c.lock.Lock()
c.reqChCancel[req] = chCancel
c.lock.Unlock()
}
req.Cancel = chCancel
go func() {
<-chDone
if c != nil ... | go | func CancelableDownload(c *Canceler, client *http.Client, req *http.Request) (*http.Response, chan bool, error) {
chDone := make(chan bool)
chCancel := make(chan struct{})
if c != nil {
c.lock.Lock()
c.reqChCancel[req] = chCancel
c.lock.Unlock()
}
req.Cancel = chCancel
go func() {
<-chDone
if c != nil ... | [
"func",
"CancelableDownload",
"(",
"c",
"*",
"Canceler",
",",
"client",
"*",
"http",
".",
"Client",
",",
"req",
"*",
"http",
".",
"Request",
")",
"(",
"*",
"http",
".",
"Response",
",",
"chan",
"bool",
",",
"error",
")",
"{",
"chDone",
":=",
"make",
... | // CancelableDownload performs an http request and allows for it to be canceled at any time | [
"CancelableDownload",
"performs",
"an",
"http",
"request",
"and",
"allows",
"for",
"it",
"to",
"be",
"canceled",
"at",
"any",
"time"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/cancel/canceler.go#L52-L73 | test |
lxc/lxd | lxd/api_cluster.go | clusterGet | func clusterGet(d *Daemon, r *http.Request) Response {
name := ""
err := d.cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
name, err = tx.NodeName()
return err
})
if err != nil {
return SmartError(err)
}
// If the name is set to the hard-coded default node name, then
// clustering is no... | go | func clusterGet(d *Daemon, r *http.Request) Response {
name := ""
err := d.cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
name, err = tx.NodeName()
return err
})
if err != nil {
return SmartError(err)
}
// If the name is set to the hard-coded default node name, then
// clustering is no... | [
"func",
"clusterGet",
"(",
"d",
"*",
"Daemon",
",",
"r",
"*",
"http",
".",
"Request",
")",
"Response",
"{",
"name",
":=",
"\"\"",
"\n",
"err",
":=",
"d",
".",
"cluster",
".",
"Transaction",
"(",
"func",
"(",
"tx",
"*",
"db",
".",
"ClusterTx",
")",
... | // Return information about the cluster. | [
"Return",
"information",
"about",
"the",
"cluster",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_cluster.go#L68-L97 | test |
lxc/lxd | lxd/api_cluster.go | clusterGetMemberConfig | func clusterGetMemberConfig(cluster *db.Cluster) ([]api.ClusterMemberConfigKey, error) {
var pools map[string]map[string]string
var networks map[string]map[string]string
keys := []api.ClusterMemberConfigKey{}
err := cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
pools, err = tx.StoragePools... | go | func clusterGetMemberConfig(cluster *db.Cluster) ([]api.ClusterMemberConfigKey, error) {
var pools map[string]map[string]string
var networks map[string]map[string]string
keys := []api.ClusterMemberConfigKey{}
err := cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
pools, err = tx.StoragePools... | [
"func",
"clusterGetMemberConfig",
"(",
"cluster",
"*",
"db",
".",
"Cluster",
")",
"(",
"[",
"]",
"api",
".",
"ClusterMemberConfigKey",
",",
"error",
")",
"{",
"var",
"pools",
"map",
"[",
"string",
"]",
"map",
"[",
"string",
"]",
"string",
"\n",
"var",
... | // Fetch information about all node-specific configuration keys set on the
// storage pools and networks of this cluster. | [
"Fetch",
"information",
"about",
"all",
"node",
"-",
"specific",
"configuration",
"keys",
"set",
"on",
"the",
"storage",
"pools",
"and",
"networks",
"of",
"this",
"cluster",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_cluster.go#L101-L159 | test |
lxc/lxd | lxd/api_cluster.go | clusterPutDisable | func clusterPutDisable(d *Daemon) Response {
// Close the cluster database
err := d.cluster.Close()
if err != nil {
return SmartError(err)
}
// Update our TLS configuration using our original certificate.
for _, suffix := range []string{"crt", "key", "ca"} {
path := filepath.Join(d.os.VarDir, "cluster."+suff... | go | func clusterPutDisable(d *Daemon) Response {
// Close the cluster database
err := d.cluster.Close()
if err != nil {
return SmartError(err)
}
// Update our TLS configuration using our original certificate.
for _, suffix := range []string{"crt", "key", "ca"} {
path := filepath.Join(d.os.VarDir, "cluster."+suff... | [
"func",
"clusterPutDisable",
"(",
"d",
"*",
"Daemon",
")",
"Response",
"{",
"err",
":=",
"d",
".",
"cluster",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"SmartError",
"(",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
... | // Disable clustering on a node. | [
"Disable",
"clustering",
"on",
"a",
"node",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_cluster.go#L617-L670 | test |
lxc/lxd | lxd/api_cluster.go | tryClusterRebalance | func tryClusterRebalance(d *Daemon) error {
leader, err := d.gateway.LeaderAddress()
if err != nil {
// This is not a fatal error, so let's just log it.
return errors.Wrap(err, "failed to get current leader node")
}
cert := d.endpoints.NetworkCert()
client, err := cluster.Connect(leader, cert, true)
if err !=... | go | func tryClusterRebalance(d *Daemon) error {
leader, err := d.gateway.LeaderAddress()
if err != nil {
// This is not a fatal error, so let's just log it.
return errors.Wrap(err, "failed to get current leader node")
}
cert := d.endpoints.NetworkCert()
client, err := cluster.Connect(leader, cert, true)
if err !=... | [
"func",
"tryClusterRebalance",
"(",
"d",
"*",
"Daemon",
")",
"error",
"{",
"leader",
",",
"err",
":=",
"d",
".",
"gateway",
".",
"LeaderAddress",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"fail... | // This function is used to notify the leader that a node was removed, it will
// decide whether to promote a new node as database node. | [
"This",
"function",
"is",
"used",
"to",
"notify",
"the",
"leader",
"that",
"a",
"node",
"was",
"removed",
"it",
"will",
"decide",
"whether",
"to",
"promote",
"a",
"new",
"node",
"as",
"database",
"node",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_cluster.go#L954-L970 | test |
lxc/lxd | lxd/api_cluster.go | internalClusterPostRebalance | func internalClusterPostRebalance(d *Daemon, r *http.Request) Response {
// Redirect all requests to the leader, which is the one with with
// up-to-date knowledge of what nodes are part of the raft cluster.
localAddress, err := node.ClusterAddress(d.db)
if err != nil {
return SmartError(err)
}
leader, err := d... | go | func internalClusterPostRebalance(d *Daemon, r *http.Request) Response {
// Redirect all requests to the leader, which is the one with with
// up-to-date knowledge of what nodes are part of the raft cluster.
localAddress, err := node.ClusterAddress(d.db)
if err != nil {
return SmartError(err)
}
leader, err := d... | [
"func",
"internalClusterPostRebalance",
"(",
"d",
"*",
"Daemon",
",",
"r",
"*",
"http",
".",
"Request",
")",
"Response",
"{",
"localAddress",
",",
"err",
":=",
"node",
".",
"ClusterAddress",
"(",
"d",
".",
"db",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{"... | // Used to update the cluster after a database node has been removed, and
// possibly promote another one as database node. | [
"Used",
"to",
"update",
"the",
"cluster",
"after",
"a",
"database",
"node",
"has",
"been",
"removed",
"and",
"possibly",
"promote",
"another",
"one",
"as",
"database",
"node",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_cluster.go#L1056-L1108 | test |
lxc/lxd | lxd/api_cluster.go | internalClusterPostPromote | func internalClusterPostPromote(d *Daemon, r *http.Request) Response {
req := internalClusterPostPromoteRequest{}
// Parse the request
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
return BadRequest(err)
}
// Sanity checks
if len(req.RaftNodes) == 0 {
return BadRequest(fmt.Errorf("No raft nod... | go | func internalClusterPostPromote(d *Daemon, r *http.Request) Response {
req := internalClusterPostPromoteRequest{}
// Parse the request
err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
return BadRequest(err)
}
// Sanity checks
if len(req.RaftNodes) == 0 {
return BadRequest(fmt.Errorf("No raft nod... | [
"func",
"internalClusterPostPromote",
"(",
"d",
"*",
"Daemon",
",",
"r",
"*",
"http",
".",
"Request",
")",
"Response",
"{",
"req",
":=",
"internalClusterPostPromoteRequest",
"{",
"}",
"\n",
"err",
":=",
"json",
".",
"NewDecoder",
"(",
"r",
".",
"Body",
")"... | // Used to promote the local non-database node to be a database one. | [
"Used",
"to",
"promote",
"the",
"local",
"non",
"-",
"database",
"node",
"to",
"be",
"a",
"database",
"one",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_cluster.go#L1111-L1136 | test |
lxc/lxd | shared/generate/db/parse.go | Filters | func Filters(pkg *ast.Package, entity string) [][]string {
objects := pkg.Scope.Objects
filters := [][]string{}
prefix := fmt.Sprintf("%sObjectsBy", entity)
for name := range objects {
if !strings.HasPrefix(name, prefix) {
continue
}
rest := name[len(prefix):]
filters = append(filters, strings.Split(re... | go | func Filters(pkg *ast.Package, entity string) [][]string {
objects := pkg.Scope.Objects
filters := [][]string{}
prefix := fmt.Sprintf("%sObjectsBy", entity)
for name := range objects {
if !strings.HasPrefix(name, prefix) {
continue
}
rest := name[len(prefix):]
filters = append(filters, strings.Split(re... | [
"func",
"Filters",
"(",
"pkg",
"*",
"ast",
".",
"Package",
",",
"entity",
"string",
")",
"[",
"]",
"[",
"]",
"string",
"{",
"objects",
":=",
"pkg",
".",
"Scope",
".",
"Objects",
"\n",
"filters",
":=",
"[",
"]",
"[",
"]",
"string",
"{",
"}",
"\n",... | // Filters parses all filtering statement defined for the given entity. It
// returns all supported combinations of filters, sorted by number of criteria. | [
"Filters",
"parses",
"all",
"filtering",
"statement",
"defined",
"for",
"the",
"given",
"entity",
".",
"It",
"returns",
"all",
"supported",
"combinations",
"of",
"filters",
"sorted",
"by",
"number",
"of",
"criteria",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/generate/db/parse.go#L40-L59 | test |
lxc/lxd | shared/generate/db/parse.go | Parse | func Parse(pkg *ast.Package, name string) (*Mapping, error) {
str := findStruct(pkg.Scope, name)
if str == nil {
return nil, fmt.Errorf("No declaration found for %q", name)
}
fields, err := parseStruct(str)
if err != nil {
return nil, errors.Wrapf(err, "Failed to parse %q", name)
}
m := &Mapping{
Package... | go | func Parse(pkg *ast.Package, name string) (*Mapping, error) {
str := findStruct(pkg.Scope, name)
if str == nil {
return nil, fmt.Errorf("No declaration found for %q", name)
}
fields, err := parseStruct(str)
if err != nil {
return nil, errors.Wrapf(err, "Failed to parse %q", name)
}
m := &Mapping{
Package... | [
"func",
"Parse",
"(",
"pkg",
"*",
"ast",
".",
"Package",
",",
"name",
"string",
")",
"(",
"*",
"Mapping",
",",
"error",
")",
"{",
"str",
":=",
"findStruct",
"(",
"pkg",
".",
"Scope",
",",
"name",
")",
"\n",
"if",
"str",
"==",
"nil",
"{",
"return"... | // Parse the structure declaration with the given name found in the given Go
// package. | [
"Parse",
"the",
"structure",
"declaration",
"with",
"the",
"given",
"name",
"found",
"in",
"the",
"given",
"Go",
"package",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/generate/db/parse.go#L110-L128 | test |
lxc/lxd | shared/generate/db/parse.go | findStruct | func findStruct(scope *ast.Scope, name string) *ast.StructType {
obj := scope.Lookup(name)
if obj == nil {
return nil
}
typ, ok := obj.Decl.(*ast.TypeSpec)
if !ok {
return nil
}
str, ok := typ.Type.(*ast.StructType)
if !ok {
return nil
}
return str
} | go | func findStruct(scope *ast.Scope, name string) *ast.StructType {
obj := scope.Lookup(name)
if obj == nil {
return nil
}
typ, ok := obj.Decl.(*ast.TypeSpec)
if !ok {
return nil
}
str, ok := typ.Type.(*ast.StructType)
if !ok {
return nil
}
return str
} | [
"func",
"findStruct",
"(",
"scope",
"*",
"ast",
".",
"Scope",
",",
"name",
"string",
")",
"*",
"ast",
".",
"StructType",
"{",
"obj",
":=",
"scope",
".",
"Lookup",
"(",
"name",
")",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
... | // Find the StructType node for the structure with the given name | [
"Find",
"the",
"StructType",
"node",
"for",
"the",
"structure",
"with",
"the",
"given",
"name"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/generate/db/parse.go#L131-L148 | test |
lxc/lxd | shared/generate/db/parse.go | parseStruct | func parseStruct(str *ast.StructType) ([]*Field, error) {
fields := make([]*Field, 0)
for _, f := range str.Fields.List {
if len(f.Names) == 0 {
// Check if this is a parent struct.
ident, ok := f.Type.(*ast.Ident)
if !ok {
continue
}
typ, ok := ident.Obj.Decl.(*ast.TypeSpec)
if !ok {
co... | go | func parseStruct(str *ast.StructType) ([]*Field, error) {
fields := make([]*Field, 0)
for _, f := range str.Fields.List {
if len(f.Names) == 0 {
// Check if this is a parent struct.
ident, ok := f.Type.(*ast.Ident)
if !ok {
continue
}
typ, ok := ident.Obj.Decl.(*ast.TypeSpec)
if !ok {
co... | [
"func",
"parseStruct",
"(",
"str",
"*",
"ast",
".",
"StructType",
")",
"(",
"[",
"]",
"*",
"Field",
",",
"error",
")",
"{",
"fields",
":=",
"make",
"(",
"[",
"]",
"*",
"Field",
",",
"0",
")",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"str",
... | // Extract field information from the given structure. | [
"Extract",
"field",
"information",
"from",
"the",
"given",
"structure",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/generate/db/parse.go#L151-L194 | test |
lxc/lxd | client/lxd_profiles.go | GetProfileNames | func (r *ProtocolLXD) GetProfileNames() ([]string, error) {
urls := []string{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/profiles", nil, "", &urls)
if err != nil {
return nil, err
}
// Parse it
names := []string{}
for _, url := range urls {
fields := strings.Split(url, "/profiles/")
names ... | go | func (r *ProtocolLXD) GetProfileNames() ([]string, error) {
urls := []string{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/profiles", nil, "", &urls)
if err != nil {
return nil, err
}
// Parse it
names := []string{}
for _, url := range urls {
fields := strings.Split(url, "/profiles/")
names ... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetProfileNames",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"urls",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"r",
".",
"queryStruct",
"(",
"\"GET\"",
",",
"\"/pr... | // Profile handling functions
// GetProfileNames returns a list of available profile names | [
"Profile",
"handling",
"functions",
"GetProfileNames",
"returns",
"a",
"list",
"of",
"available",
"profile",
"names"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_profiles.go#L14-L31 | test |
lxc/lxd | client/lxd_profiles.go | GetProfiles | func (r *ProtocolLXD) GetProfiles() ([]api.Profile, error) {
profiles := []api.Profile{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/profiles?recursion=1", nil, "", &profiles)
if err != nil {
return nil, err
}
return profiles, nil
} | go | func (r *ProtocolLXD) GetProfiles() ([]api.Profile, error) {
profiles := []api.Profile{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/profiles?recursion=1", nil, "", &profiles)
if err != nil {
return nil, err
}
return profiles, nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetProfiles",
"(",
")",
"(",
"[",
"]",
"api",
".",
"Profile",
",",
"error",
")",
"{",
"profiles",
":=",
"[",
"]",
"api",
".",
"Profile",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"r",
".",
"queryStruct",
... | // GetProfiles returns a list of available Profile structs | [
"GetProfiles",
"returns",
"a",
"list",
"of",
"available",
"Profile",
"structs"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_profiles.go#L34-L44 | test |
lxc/lxd | client/lxd_profiles.go | GetProfile | func (r *ProtocolLXD) GetProfile(name string) (*api.Profile, string, error) {
profile := api.Profile{}
// Fetch the raw value
etag, err := r.queryStruct("GET", fmt.Sprintf("/profiles/%s", url.QueryEscape(name)), nil, "", &profile)
if err != nil {
return nil, "", err
}
return &profile, etag, nil
} | go | func (r *ProtocolLXD) GetProfile(name string) (*api.Profile, string, error) {
profile := api.Profile{}
// Fetch the raw value
etag, err := r.queryStruct("GET", fmt.Sprintf("/profiles/%s", url.QueryEscape(name)), nil, "", &profile)
if err != nil {
return nil, "", err
}
return &profile, etag, nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetProfile",
"(",
"name",
"string",
")",
"(",
"*",
"api",
".",
"Profile",
",",
"string",
",",
"error",
")",
"{",
"profile",
":=",
"api",
".",
"Profile",
"{",
"}",
"\n",
"etag",
",",
"err",
":=",
"r",
".... | // GetProfile returns a Profile entry for the provided name | [
"GetProfile",
"returns",
"a",
"Profile",
"entry",
"for",
"the",
"provided",
"name"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_profiles.go#L47-L57 | test |
lxc/lxd | client/lxd_profiles.go | CreateProfile | func (r *ProtocolLXD) CreateProfile(profile api.ProfilesPost) error {
// Send the request
_, _, err := r.query("POST", "/profiles", profile, "")
if err != nil {
return err
}
return nil
} | go | func (r *ProtocolLXD) CreateProfile(profile api.ProfilesPost) error {
// Send the request
_, _, err := r.query("POST", "/profiles", profile, "")
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"CreateProfile",
"(",
"profile",
"api",
".",
"ProfilesPost",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"r",
".",
"query",
"(",
"\"POST\"",
",",
"\"/profiles\"",
",",
"profile",
",",
"\"\"",
")",
"\... | // CreateProfile defines a new container profile | [
"CreateProfile",
"defines",
"a",
"new",
"container",
"profile"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_profiles.go#L60-L68 | test |
lxc/lxd | client/lxd_profiles.go | UpdateProfile | func (r *ProtocolLXD) UpdateProfile(name string, profile api.ProfilePut, ETag string) error {
// Send the request
_, _, err := r.query("PUT", fmt.Sprintf("/profiles/%s", url.QueryEscape(name)), profile, ETag)
if err != nil {
return err
}
return nil
} | go | func (r *ProtocolLXD) UpdateProfile(name string, profile api.ProfilePut, ETag string) error {
// Send the request
_, _, err := r.query("PUT", fmt.Sprintf("/profiles/%s", url.QueryEscape(name)), profile, ETag)
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"UpdateProfile",
"(",
"name",
"string",
",",
"profile",
"api",
".",
"ProfilePut",
",",
"ETag",
"string",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"r",
".",
"query",
"(",
"\"PUT\"",
",",
"fmt",
"... | // UpdateProfile updates the profile to match the provided Profile struct | [
"UpdateProfile",
"updates",
"the",
"profile",
"to",
"match",
"the",
"provided",
"Profile",
"struct"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_profiles.go#L71-L79 | test |
lxc/lxd | client/lxd_profiles.go | RenameProfile | func (r *ProtocolLXD) RenameProfile(name string, profile api.ProfilePost) error {
// Send the request
_, _, err := r.query("POST", fmt.Sprintf("/profiles/%s", url.QueryEscape(name)), profile, "")
if err != nil {
return err
}
return nil
} | go | func (r *ProtocolLXD) RenameProfile(name string, profile api.ProfilePost) error {
// Send the request
_, _, err := r.query("POST", fmt.Sprintf("/profiles/%s", url.QueryEscape(name)), profile, "")
if err != nil {
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"RenameProfile",
"(",
"name",
"string",
",",
"profile",
"api",
".",
"ProfilePost",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"r",
".",
"query",
"(",
"\"POST\"",
",",
"fmt",
".",
"Sprintf",
"(",
"... | // RenameProfile renames an existing profile entry | [
"RenameProfile",
"renames",
"an",
"existing",
"profile",
"entry"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_profiles.go#L82-L90 | test |
lxc/lxd | lxd/config/map.go | Load | func Load(schema Schema, values map[string]string) (Map, error) {
m := Map{
schema: schema,
}
// Populate the initial values.
_, err := m.update(values)
return m, err
} | go | func Load(schema Schema, values map[string]string) (Map, error) {
m := Map{
schema: schema,
}
// Populate the initial values.
_, err := m.update(values)
return m, err
} | [
"func",
"Load",
"(",
"schema",
"Schema",
",",
"values",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"Map",
",",
"error",
")",
"{",
"m",
":=",
"Map",
"{",
"schema",
":",
"schema",
",",
"}",
"\n",
"_",
",",
"err",
":=",
"m",
".",
"update",
"("... | // Load creates a new configuration Map with the given schema and initial
// values. It is meant to be called with a set of initial values that were set
// at a previous time and persisted to some storage like a database.
//
// If one or more keys fail to be loaded, return an ErrorList describing what
// went wrong. No... | [
"Load",
"creates",
"a",
"new",
"configuration",
"Map",
"with",
"the",
"given",
"schema",
"and",
"initial",
"values",
".",
"It",
"is",
"meant",
"to",
"be",
"called",
"with",
"a",
"set",
"of",
"initial",
"values",
"that",
"were",
"set",
"at",
"a",
"previou... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/map.go#L26-L34 | test |
lxc/lxd | lxd/config/map.go | Dump | func (m *Map) Dump() map[string]interface{} {
values := map[string]interface{}{}
for name, key := range m.schema {
value := m.GetRaw(name)
if value != key.Default {
if key.Hidden {
values[name] = true
} else {
values[name] = value
}
}
}
return values
} | go | func (m *Map) Dump() map[string]interface{} {
values := map[string]interface{}{}
for name, key := range m.schema {
value := m.GetRaw(name)
if value != key.Default {
if key.Hidden {
values[name] = true
} else {
values[name] = value
}
}
}
return values
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"Dump",
"(",
")",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"values",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"}",
"\n",
"for",
"name",
",",
"key",
":=",
"range",
"m",
".",
... | // Dump the current configuration held by this Map.
//
// Keys that match their default value will not be included in the dump. Also,
// if a Key has its Hidden attribute set to true, it will be rendered as
// "true", for obfuscating the actual value. | [
"Dump",
"the",
"current",
"configuration",
"held",
"by",
"this",
"Map",
".",
"Keys",
"that",
"match",
"their",
"default",
"value",
"will",
"not",
"be",
"included",
"in",
"the",
"dump",
".",
"Also",
"if",
"a",
"Key",
"has",
"its",
"Hidden",
"attribute",
"... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/map.go#L95-L110 | test |
lxc/lxd | lxd/config/map.go | GetRaw | func (m *Map) GetRaw(name string) string {
key := m.schema.mustGetKey(name)
value, ok := m.values[name]
if !ok {
value = key.Default
}
return value
} | go | func (m *Map) GetRaw(name string) string {
key := m.schema.mustGetKey(name)
value, ok := m.values[name]
if !ok {
value = key.Default
}
return value
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"GetRaw",
"(",
"name",
"string",
")",
"string",
"{",
"key",
":=",
"m",
".",
"schema",
".",
"mustGetKey",
"(",
"name",
")",
"\n",
"value",
",",
"ok",
":=",
"m",
".",
"values",
"[",
"name",
"]",
"\n",
"if",
"!",... | // GetRaw returns the value of the given key, which must be of type String. | [
"GetRaw",
"returns",
"the",
"value",
"of",
"the",
"given",
"key",
"which",
"must",
"be",
"of",
"type",
"String",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/map.go#L113-L120 | test |
lxc/lxd | lxd/config/map.go | GetString | func (m *Map) GetString(name string) string {
m.schema.assertKeyType(name, String)
return m.GetRaw(name)
} | go | func (m *Map) GetString(name string) string {
m.schema.assertKeyType(name, String)
return m.GetRaw(name)
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"GetString",
"(",
"name",
"string",
")",
"string",
"{",
"m",
".",
"schema",
".",
"assertKeyType",
"(",
"name",
",",
"String",
")",
"\n",
"return",
"m",
".",
"GetRaw",
"(",
"name",
")",
"\n",
"}"
] | // GetString returns the value of the given key, which must be of type String. | [
"GetString",
"returns",
"the",
"value",
"of",
"the",
"given",
"key",
"which",
"must",
"be",
"of",
"type",
"String",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/map.go#L123-L126 | test |
lxc/lxd | lxd/config/map.go | GetBool | func (m *Map) GetBool(name string) bool {
m.schema.assertKeyType(name, Bool)
return shared.IsTrue(m.GetRaw(name))
} | go | func (m *Map) GetBool(name string) bool {
m.schema.assertKeyType(name, Bool)
return shared.IsTrue(m.GetRaw(name))
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"GetBool",
"(",
"name",
"string",
")",
"bool",
"{",
"m",
".",
"schema",
".",
"assertKeyType",
"(",
"name",
",",
"Bool",
")",
"\n",
"return",
"shared",
".",
"IsTrue",
"(",
"m",
".",
"GetRaw",
"(",
"name",
")",
")... | // GetBool returns the value of the given key, which must be of type Bool. | [
"GetBool",
"returns",
"the",
"value",
"of",
"the",
"given",
"key",
"which",
"must",
"be",
"of",
"type",
"Bool",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/map.go#L129-L132 | test |
lxc/lxd | lxd/config/map.go | GetInt64 | func (m *Map) GetInt64(name string) int64 {
m.schema.assertKeyType(name, Int64)
n, err := strconv.ParseInt(m.GetRaw(name), 10, 64)
if err != nil {
panic(fmt.Sprintf("cannot convert to int64: %v", err))
}
return n
} | go | func (m *Map) GetInt64(name string) int64 {
m.schema.assertKeyType(name, Int64)
n, err := strconv.ParseInt(m.GetRaw(name), 10, 64)
if err != nil {
panic(fmt.Sprintf("cannot convert to int64: %v", err))
}
return n
} | [
"func",
"(",
"m",
"*",
"Map",
")",
"GetInt64",
"(",
"name",
"string",
")",
"int64",
"{",
"m",
".",
"schema",
".",
"assertKeyType",
"(",
"name",
",",
"Int64",
")",
"\n",
"n",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"m",
".",
"GetRaw",
"... | // GetInt64 returns the value of the given key, which must be of type Int64. | [
"GetInt64",
"returns",
"the",
"value",
"of",
"the",
"given",
"key",
"which",
"must",
"be",
"of",
"type",
"Int64",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/map.go#L135-L142 | test |
lxc/lxd | lxd/config/map.go | update | func (m *Map) update(values map[string]string) ([]string, error) {
// Detect if this is the first time we're setting values. This happens
// when Load is called.
initial := m.values == nil
if initial {
m.values = make(map[string]string, len(values))
}
// Update our keys with the values from the given map, and... | go | func (m *Map) update(values map[string]string) ([]string, error) {
// Detect if this is the first time we're setting values. This happens
// when Load is called.
initial := m.values == nil
if initial {
m.values = make(map[string]string, len(values))
}
// Update our keys with the values from the given map, and... | [
"func",
"(",
"m",
"*",
"Map",
")",
"update",
"(",
"values",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"initial",
":=",
"m",
".",
"values",
"==",
"nil",
"\n",
"if",
"initial",
"{",
"m",
".",
"valu... | // Update the current values in the map using the newly provided ones. Return a
// list of key names that were actually changed and an ErrorList with possible
// errors. | [
"Update",
"the",
"current",
"values",
"in",
"the",
"map",
"using",
"the",
"newly",
"provided",
"ones",
".",
"Return",
"a",
"list",
"of",
"key",
"names",
"that",
"were",
"actually",
"changed",
"and",
"an",
"ErrorList",
"with",
"possible",
"errors",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/map.go#L147-L179 | test |
lxc/lxd | lxd/config/map.go | set | func (m *Map) set(name string, value string, initial bool) (bool, error) {
key, ok := m.schema[name]
if !ok {
return false, fmt.Errorf("unknown key")
}
err := key.validate(value)
if err != nil {
return false, err
}
// Normalize boolan values, so the comparison below works fine.
current := m.GetRaw(name)
... | go | func (m *Map) set(name string, value string, initial bool) (bool, error) {
key, ok := m.schema[name]
if !ok {
return false, fmt.Errorf("unknown key")
}
err := key.validate(value)
if err != nil {
return false, err
}
// Normalize boolan values, so the comparison below works fine.
current := m.GetRaw(name)
... | [
"func",
"(",
"m",
"*",
"Map",
")",
"set",
"(",
"name",
"string",
",",
"value",
"string",
",",
"initial",
"bool",
")",
"(",
"bool",
",",
"error",
")",
"{",
"key",
",",
"ok",
":=",
"m",
".",
"schema",
"[",
"name",
"]",
"\n",
"if",
"!",
"ok",
"{... | // Set or change an individual key. Empty string means delete this value and
// effectively revert it to the default. Return a boolean indicating whether
// the value has changed, and error if something went wrong. | [
"Set",
"or",
"change",
"an",
"individual",
"key",
".",
"Empty",
"string",
"means",
"delete",
"this",
"value",
"and",
"effectively",
"revert",
"it",
"to",
"the",
"default",
".",
"Return",
"a",
"boolean",
"indicating",
"whether",
"the",
"value",
"has",
"change... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/map.go#L184-L224 | test |
lxc/lxd | lxd/db/schema/query.go | DoesSchemaTableExist | func DoesSchemaTableExist(tx *sql.Tx) (bool, error) {
statement := `
SELECT COUNT(name) FROM sqlite_master WHERE type = 'table' AND name = 'schema'
`
rows, err := tx.Query(statement)
if err != nil {
return false, err
}
defer rows.Close()
if !rows.Next() {
return false, fmt.Errorf("schema table query returned... | go | func DoesSchemaTableExist(tx *sql.Tx) (bool, error) {
statement := `
SELECT COUNT(name) FROM sqlite_master WHERE type = 'table' AND name = 'schema'
`
rows, err := tx.Query(statement)
if err != nil {
return false, err
}
defer rows.Close()
if !rows.Next() {
return false, fmt.Errorf("schema table query returned... | [
"func",
"DoesSchemaTableExist",
"(",
"tx",
"*",
"sql",
".",
"Tx",
")",
"(",
"bool",
",",
"error",
")",
"{",
"statement",
":=",
"`SELECT COUNT(name) FROM sqlite_master WHERE type = 'table' AND name = 'schema'`",
"\n",
"rows",
",",
"err",
":=",
"tx",
".",
"Query",
"... | // DoesSchemaTableExist return whether the schema table is present in the
// database. | [
"DoesSchemaTableExist",
"return",
"whether",
"the",
"schema",
"table",
"is",
"present",
"in",
"the",
"database",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/schema/query.go#L16-L38 | test |
lxc/lxd | lxd/db/schema/query.go | selectSchemaVersions | func selectSchemaVersions(tx *sql.Tx) ([]int, error) {
statement := `
SELECT version FROM schema ORDER BY version
`
return query.SelectIntegers(tx, statement)
} | go | func selectSchemaVersions(tx *sql.Tx) ([]int, error) {
statement := `
SELECT version FROM schema ORDER BY version
`
return query.SelectIntegers(tx, statement)
} | [
"func",
"selectSchemaVersions",
"(",
"tx",
"*",
"sql",
".",
"Tx",
")",
"(",
"[",
"]",
"int",
",",
"error",
")",
"{",
"statement",
":=",
"`SELECT version FROM schema ORDER BY version`",
"\n",
"return",
"query",
".",
"SelectIntegers",
"(",
"tx",
",",
"statement"... | // Return all versions in the schema table, in increasing order. | [
"Return",
"all",
"versions",
"in",
"the",
"schema",
"table",
"in",
"increasing",
"order",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/schema/query.go#L41-L46 | test |
lxc/lxd | lxd/db/schema/query.go | selectTablesSQL | func selectTablesSQL(tx *sql.Tx) ([]string, error) {
statement := `
SELECT sql FROM sqlite_master WHERE
type IN ('table', 'index', 'view') AND
name != 'schema' AND
name NOT LIKE 'sqlite_%'
ORDER BY name
`
return query.SelectStrings(tx, statement)
} | go | func selectTablesSQL(tx *sql.Tx) ([]string, error) {
statement := `
SELECT sql FROM sqlite_master WHERE
type IN ('table', 'index', 'view') AND
name != 'schema' AND
name NOT LIKE 'sqlite_%'
ORDER BY name
`
return query.SelectStrings(tx, statement)
} | [
"func",
"selectTablesSQL",
"(",
"tx",
"*",
"sql",
".",
"Tx",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"statement",
":=",
"`SELECT sql FROM sqlite_master WHERE type IN ('table', 'index', 'view') AND name != 'schema' AND name NOT LIKE 'sqlite_%'ORDER BY name`",
... | // Return a list of SQL statements that can be used to create all tables in the
// database. | [
"Return",
"a",
"list",
"of",
"SQL",
"statements",
"that",
"can",
"be",
"used",
"to",
"create",
"all",
"tables",
"in",
"the",
"database",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/schema/query.go#L50-L59 | test |
lxc/lxd | lxd/db/schema/query.go | createSchemaTable | func createSchemaTable(tx *sql.Tx) error {
statement := `
CREATE TABLE schema (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
version INTEGER NOT NULL,
updated_at DATETIME NOT NULL,
UNIQUE (version)
)
`
_, err := tx.Exec(statement)
return err
} | go | func createSchemaTable(tx *sql.Tx) error {
statement := `
CREATE TABLE schema (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
version INTEGER NOT NULL,
updated_at DATETIME NOT NULL,
UNIQUE (version)
)
`
_, err := tx.Exec(statement)
return err
} | [
"func",
"createSchemaTable",
"(",
"tx",
"*",
"sql",
".",
"Tx",
")",
"error",
"{",
"statement",
":=",
"`CREATE TABLE schema ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, version INTEGER NOT NULL, updated_at DATETIME NOT NULL, UNIQUE (version))`",
"\n",
"_",
"... | // Create the schema table. | [
"Create",
"the",
"schema",
"table",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/schema/query.go#L62-L73 | test |
lxc/lxd | lxd/db/schema/query.go | insertSchemaVersion | func insertSchemaVersion(tx *sql.Tx, new int) error {
statement := `
INSERT INTO schema (version, updated_at) VALUES (?, strftime("%s"))
`
_, err := tx.Exec(statement, new)
return err
} | go | func insertSchemaVersion(tx *sql.Tx, new int) error {
statement := `
INSERT INTO schema (version, updated_at) VALUES (?, strftime("%s"))
`
_, err := tx.Exec(statement, new)
return err
} | [
"func",
"insertSchemaVersion",
"(",
"tx",
"*",
"sql",
".",
"Tx",
",",
"new",
"int",
")",
"error",
"{",
"statement",
":=",
"`INSERT INTO schema (version, updated_at) VALUES (?, strftime(\"%s\"))`",
"\n",
"_",
",",
"err",
":=",
"tx",
".",
"Exec",
"(",
"statement",
... | // Insert a new version into the schema table. | [
"Insert",
"a",
"new",
"version",
"into",
"the",
"schema",
"table",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/schema/query.go#L76-L82 | test |
lxc/lxd | lxd/state/state.go | NewState | func NewState(node *db.Node, cluster *db.Cluster, maas *maas.Controller, os *sys.OS, endpoints *endpoints.Endpoints) *State {
return &State{
Node: node,
Cluster: cluster,
MAAS: maas,
OS: os,
Endpoints: endpoints,
}
} | go | func NewState(node *db.Node, cluster *db.Cluster, maas *maas.Controller, os *sys.OS, endpoints *endpoints.Endpoints) *State {
return &State{
Node: node,
Cluster: cluster,
MAAS: maas,
OS: os,
Endpoints: endpoints,
}
} | [
"func",
"NewState",
"(",
"node",
"*",
"db",
".",
"Node",
",",
"cluster",
"*",
"db",
".",
"Cluster",
",",
"maas",
"*",
"maas",
".",
"Controller",
",",
"os",
"*",
"sys",
".",
"OS",
",",
"endpoints",
"*",
"endpoints",
".",
"Endpoints",
")",
"*",
"Stat... | // NewState returns a new State object with the given database and operating
// system components. | [
"NewState",
"returns",
"a",
"new",
"State",
"object",
"with",
"the",
"given",
"database",
"and",
"operating",
"system",
"components",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/state/state.go#L23-L31 | test |
lxc/lxd | lxd/container_lxc.go | containerLXCUnload | func containerLXCUnload(c *containerLXC) {
runtime.SetFinalizer(c, nil)
if c.c != nil {
c.c.Release()
c.c = nil
}
} | go | func containerLXCUnload(c *containerLXC) {
runtime.SetFinalizer(c, nil)
if c.c != nil {
c.c.Release()
c.c = nil
}
} | [
"func",
"containerLXCUnload",
"(",
"c",
"*",
"containerLXC",
")",
"{",
"runtime",
".",
"SetFinalizer",
"(",
"c",
",",
"nil",
")",
"\n",
"if",
"c",
".",
"c",
"!=",
"nil",
"{",
"c",
".",
"c",
".",
"Release",
"(",
")",
"\n",
"c",
".",
"c",
"=",
"n... | // Unload is called by the garbage collector | [
"Unload",
"is",
"called",
"by",
"the",
"garbage",
"collector"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L512-L518 | test |
lxc/lxd | lxd/container_lxc.go | containerLXCInstantiate | func containerLXCInstantiate(s *state.State, args db.ContainerArgs) *containerLXC {
return &containerLXC{
state: s,
id: args.ID,
project: args.Project,
name: args.Name,
description: args.Description,
ephemeral: args.Ephemeral,
architecture: args.Architecture,
cType: ... | go | func containerLXCInstantiate(s *state.State, args db.ContainerArgs) *containerLXC {
return &containerLXC{
state: s,
id: args.ID,
project: args.Project,
name: args.Name,
description: args.Description,
ephemeral: args.Ephemeral,
architecture: args.Architecture,
cType: ... | [
"func",
"containerLXCInstantiate",
"(",
"s",
"*",
"state",
".",
"State",
",",
"args",
"db",
".",
"ContainerArgs",
")",
"*",
"containerLXC",
"{",
"return",
"&",
"containerLXC",
"{",
"state",
":",
"s",
",",
"id",
":",
"args",
".",
"ID",
",",
"project",
"... | // Create a container struct without initializing it. | [
"Create",
"a",
"container",
"struct",
"without",
"initializing",
"it",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L521-L540 | test |
lxc/lxd | lxd/container_lxc.go | initStorage | func (c *containerLXC) initStorage() error {
if c.storage != nil {
return nil
}
s, err := storagePoolVolumeContainerLoadInit(c.state, c.Project(), c.Name())
if err != nil {
return err
}
c.storage = s
return nil
} | go | func (c *containerLXC) initStorage() error {
if c.storage != nil {
return nil
}
s, err := storagePoolVolumeContainerLoadInit(c.state, c.Project(), c.Name())
if err != nil {
return err
}
c.storage = s
return nil
} | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"initStorage",
"(",
")",
"error",
"{",
"if",
"c",
".",
"storage",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"s",
",",
"err",
":=",
"storagePoolVolumeContainerLoadInit",
"(",
"c",
".",
"state",
",",
... | // Initialize storage interface for this container | [
"Initialize",
"storage",
"interface",
"for",
"this",
"container"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L1843-L1856 | test |
lxc/lxd | lxd/container_lxc.go | OnNetworkUp | func (c *containerLXC) OnNetworkUp(deviceName string, hostName string) error {
device := c.expandedDevices[deviceName]
device["host_name"] = hostName
return c.setupHostVethDevice(device)
} | go | func (c *containerLXC) OnNetworkUp(deviceName string, hostName string) error {
device := c.expandedDevices[deviceName]
device["host_name"] = hostName
return c.setupHostVethDevice(device)
} | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"OnNetworkUp",
"(",
"deviceName",
"string",
",",
"hostName",
"string",
")",
"error",
"{",
"device",
":=",
"c",
".",
"expandedDevices",
"[",
"deviceName",
"]",
"\n",
"device",
"[",
"\"host_name\"",
"]",
"=",
"host... | // OnNetworkUp is called by the LXD callhook when the LXC network up script is run. | [
"OnNetworkUp",
"is",
"called",
"by",
"the",
"LXD",
"callhook",
"when",
"the",
"LXC",
"network",
"up",
"script",
"is",
"run",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L3018-L3022 | test |
lxc/lxd | lxd/container_lxc.go | setupHostVethDevice | func (c *containerLXC) setupHostVethDevice(device types.Device) error {
// If not already, populate network device with host name.
if device["host_name"] == "" {
device["host_name"] = c.getHostInterface(device["name"])
}
// Check whether host device resolution succeeded.
if device["host_name"] == "" {
return ... | go | func (c *containerLXC) setupHostVethDevice(device types.Device) error {
// If not already, populate network device with host name.
if device["host_name"] == "" {
device["host_name"] = c.getHostInterface(device["name"])
}
// Check whether host device resolution succeeded.
if device["host_name"] == "" {
return ... | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"setupHostVethDevice",
"(",
"device",
"types",
".",
"Device",
")",
"error",
"{",
"if",
"device",
"[",
"\"host_name\"",
"]",
"==",
"\"\"",
"{",
"device",
"[",
"\"host_name\"",
"]",
"=",
"c",
".",
"getHostInterface... | // setupHostVethDevice configures a nic device's host side veth settings. | [
"setupHostVethDevice",
"configures",
"a",
"nic",
"device",
"s",
"host",
"side",
"veth",
"settings",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L3025-L3049 | test |
lxc/lxd | lxd/container_lxc.go | getLxcState | func (c *containerLXC) getLxcState() (lxc.State, error) {
if c.IsSnapshot() {
return lxc.StateMap["STOPPED"], nil
}
// Load the go-lxc struct
err := c.initLXC(false)
if err != nil {
return lxc.StateMap["STOPPED"], err
}
monitor := make(chan lxc.State, 1)
go func(c *lxc.Container) {
monitor <- c.State()... | go | func (c *containerLXC) getLxcState() (lxc.State, error) {
if c.IsSnapshot() {
return lxc.StateMap["STOPPED"], nil
}
// Load the go-lxc struct
err := c.initLXC(false)
if err != nil {
return lxc.StateMap["STOPPED"], err
}
monitor := make(chan lxc.State, 1)
go func(c *lxc.Container) {
monitor <- c.State()... | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"getLxcState",
"(",
")",
"(",
"lxc",
".",
"State",
",",
"error",
")",
"{",
"if",
"c",
".",
"IsSnapshot",
"(",
")",
"{",
"return",
"lxc",
".",
"StateMap",
"[",
"\"STOPPED\"",
"]",
",",
"nil",
"\n",
"}",
... | // Get lxc container state, with 1 second timeout
// If we don't get a reply, assume the lxc monitor is hung | [
"Get",
"lxc",
"container",
"state",
"with",
"1",
"second",
"timeout",
"If",
"we",
"don",
"t",
"get",
"a",
"reply",
"assume",
"the",
"lxc",
"monitor",
"is",
"hung"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L3149-L3172 | test |
lxc/lxd | lxd/container_lxc.go | StorageStartSensitive | func (c *containerLXC) StorageStartSensitive() (bool, error) {
// Initialize storage interface for the container.
err := c.initStorage()
if err != nil {
return false, err
}
var isOurOperation bool
if c.IsSnapshot() {
isOurOperation, err = c.storage.ContainerSnapshotStart(c)
} else {
isOurOperation, err = ... | go | func (c *containerLXC) StorageStartSensitive() (bool, error) {
// Initialize storage interface for the container.
err := c.initStorage()
if err != nil {
return false, err
}
var isOurOperation bool
if c.IsSnapshot() {
isOurOperation, err = c.storage.ContainerSnapshotStart(c)
} else {
isOurOperation, err = ... | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"StorageStartSensitive",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"err",
":=",
"c",
".",
"initStorage",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",... | // Kill this function as soon as zfs is fixed. | [
"Kill",
"this",
"function",
"as",
"soon",
"as",
"zfs",
"is",
"fixed",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L6553-L6568 | test |
lxc/lxd | lxd/container_lxc.go | deviceExistsInDevicesFolder | func (c *containerLXC) deviceExistsInDevicesFolder(prefix string, path string) bool {
relativeDestPath := strings.TrimPrefix(path, "/")
devName := fmt.Sprintf("%s.%s", strings.Replace(prefix, "/", "-", -1), strings.Replace(relativeDestPath, "/", "-", -1))
devPath := filepath.Join(c.DevicesPath(), devName)
return s... | go | func (c *containerLXC) deviceExistsInDevicesFolder(prefix string, path string) bool {
relativeDestPath := strings.TrimPrefix(path, "/")
devName := fmt.Sprintf("%s.%s", strings.Replace(prefix, "/", "-", -1), strings.Replace(relativeDestPath, "/", "-", -1))
devPath := filepath.Join(c.DevicesPath(), devName)
return s... | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"deviceExistsInDevicesFolder",
"(",
"prefix",
"string",
",",
"path",
"string",
")",
"bool",
"{",
"relativeDestPath",
":=",
"strings",
".",
"TrimPrefix",
"(",
"path",
",",
"\"/\"",
")",
"\n",
"devName",
":=",
"fmt",... | // Check if the unix device already exists. | [
"Check",
"if",
"the",
"unix",
"device",
"already",
"exists",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L6698-L6704 | test |
lxc/lxd | lxd/container_lxc.go | createDiskDevice | func (c *containerLXC) createDiskDevice(name string, m types.Device) (string, error) {
// source paths
relativeDestPath := strings.TrimPrefix(m["path"], "/")
devName := fmt.Sprintf("disk.%s.%s", strings.Replace(name, "/", "-", -1), strings.Replace(relativeDestPath, "/", "-", -1))
devPath := filepath.Join(c.DevicesP... | go | func (c *containerLXC) createDiskDevice(name string, m types.Device) (string, error) {
// source paths
relativeDestPath := strings.TrimPrefix(m["path"], "/")
devName := fmt.Sprintf("disk.%s.%s", strings.Replace(name, "/", "-", -1), strings.Replace(relativeDestPath, "/", "-", -1))
devPath := filepath.Join(c.DevicesP... | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"createDiskDevice",
"(",
"name",
"string",
",",
"m",
"types",
".",
"Device",
")",
"(",
"string",
",",
"error",
")",
"{",
"relativeDestPath",
":=",
"strings",
".",
"TrimPrefix",
"(",
"m",
"[",
"\"path\"",
"]",
... | // Disk device handling | [
"Disk",
"device",
"handling"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L8116-L8241 | test |
lxc/lxd | lxd/container_lxc.go | setNetworkRoutes | func (c *containerLXC) setNetworkRoutes(m types.Device) error {
if !shared.PathExists(fmt.Sprintf("/sys/class/net/%s", m["host_name"])) {
return fmt.Errorf("Unknown or missing host side veth: %s", m["host_name"])
}
// Flush all IPv4 routes
_, err := shared.RunCommand("ip", "-4", "route", "flush", "dev", m["host_... | go | func (c *containerLXC) setNetworkRoutes(m types.Device) error {
if !shared.PathExists(fmt.Sprintf("/sys/class/net/%s", m["host_name"])) {
return fmt.Errorf("Unknown or missing host side veth: %s", m["host_name"])
}
// Flush all IPv4 routes
_, err := shared.RunCommand("ip", "-4", "route", "flush", "dev", m["host_... | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"setNetworkRoutes",
"(",
"m",
"types",
".",
"Device",
")",
"error",
"{",
"if",
"!",
"shared",
".",
"PathExists",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"/sys/class/net/%s\"",
",",
"m",
"[",
"\"host_name\"",
"]",
")... | // setNetworkRoutes applies any static routes configured from the host to the container nic. | [
"setNetworkRoutes",
"applies",
"any",
"static",
"routes",
"configured",
"from",
"the",
"host",
"to",
"the",
"container",
"nic",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L8649-L8689 | test |
lxc/lxd | lxd/container_lxc.go | Path | func (c *containerLXC) Path() string {
name := projectPrefix(c.Project(), c.Name())
return containerPath(name, c.IsSnapshot())
} | go | func (c *containerLXC) Path() string {
name := projectPrefix(c.Project(), c.Name())
return containerPath(name, c.IsSnapshot())
} | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"Path",
"(",
")",
"string",
"{",
"name",
":=",
"projectPrefix",
"(",
"c",
".",
"Project",
"(",
")",
",",
"c",
".",
"Name",
"(",
")",
")",
"\n",
"return",
"containerPath",
"(",
"name",
",",
"c",
".",
"Is... | // Various container paths | [
"Various",
"container",
"paths"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L8913-L8916 | test |
lxc/lxd | lxd/container_lxc.go | maasInterfaces | func (c *containerLXC) maasInterfaces() ([]maas.ContainerInterface, error) {
interfaces := []maas.ContainerInterface{}
for k, m := range c.expandedDevices {
if m["type"] != "nic" {
continue
}
if m["maas.subnet.ipv4"] == "" && m["maas.subnet.ipv6"] == "" {
continue
}
m, err := c.fillNetworkDevice(k, ... | go | func (c *containerLXC) maasInterfaces() ([]maas.ContainerInterface, error) {
interfaces := []maas.ContainerInterface{}
for k, m := range c.expandedDevices {
if m["type"] != "nic" {
continue
}
if m["maas.subnet.ipv4"] == "" && m["maas.subnet.ipv6"] == "" {
continue
}
m, err := c.fillNetworkDevice(k, ... | [
"func",
"(",
"c",
"*",
"containerLXC",
")",
"maasInterfaces",
"(",
")",
"(",
"[",
"]",
"maas",
".",
"ContainerInterface",
",",
"error",
")",
"{",
"interfaces",
":=",
"[",
"]",
"maas",
".",
"ContainerInterface",
"{",
"}",
"\n",
"for",
"k",
",",
"m",
"... | // Internal MAAS handling | [
"Internal",
"MAAS",
"handling"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_lxc.go#L9001-L9049 | test |
lxc/lxd | shared/logging/log_posix.go | getSystemHandler | func getSystemHandler(syslog string, debug bool, format log.Format) log.Handler {
// SyslogHandler
if syslog != "" {
if !debug {
return log.LvlFilterHandler(
log.LvlInfo,
log.Must.SyslogHandler(syslog, format),
)
}
return log.Must.SyslogHandler(syslog, format)
}
return nil
} | go | func getSystemHandler(syslog string, debug bool, format log.Format) log.Handler {
// SyslogHandler
if syslog != "" {
if !debug {
return log.LvlFilterHandler(
log.LvlInfo,
log.Must.SyslogHandler(syslog, format),
)
}
return log.Must.SyslogHandler(syslog, format)
}
return nil
} | [
"func",
"getSystemHandler",
"(",
"syslog",
"string",
",",
"debug",
"bool",
",",
"format",
"log",
".",
"Format",
")",
"log",
".",
"Handler",
"{",
"if",
"syslog",
"!=",
"\"\"",
"{",
"if",
"!",
"debug",
"{",
"return",
"log",
".",
"LvlFilterHandler",
"(",
... | // getSystemHandler on Linux writes messages to syslog. | [
"getSystemHandler",
"on",
"Linux",
"writes",
"messages",
"to",
"syslog",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/logging/log_posix.go#L10-L24 | test |
lxc/lxd | lxd/devices.go | findNvidiaMinor | func findNvidiaMinor(pci string) (string, error) {
nvidiaPath := fmt.Sprintf("/proc/driver/nvidia/gpus/%s/information", pci)
buf, err := ioutil.ReadFile(nvidiaPath)
if err != nil {
return "", err
}
strBuf := strings.TrimSpace(string(buf))
idx := strings.Index(strBuf, "Device Minor:")
if idx != -1 {
idx += l... | go | func findNvidiaMinor(pci string) (string, error) {
nvidiaPath := fmt.Sprintf("/proc/driver/nvidia/gpus/%s/information", pci)
buf, err := ioutil.ReadFile(nvidiaPath)
if err != nil {
return "", err
}
strBuf := strings.TrimSpace(string(buf))
idx := strings.Index(strBuf, "Device Minor:")
if idx != -1 {
idx += l... | [
"func",
"findNvidiaMinor",
"(",
"pci",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"nvidiaPath",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"/proc/driver/nvidia/gpus/%s/information\"",
",",
"pci",
")",
"\n",
"buf",
",",
"err",
":=",
"ioutil",
".",
"ReadFi... | // Return string for minor number of nvidia device corresponding to the given pci id | [
"Return",
"string",
"for",
"minor",
"number",
"of",
"nvidia",
"device",
"corresponding",
"to",
"the",
"given",
"pci",
"id"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/devices.go#L177-L203 | test |
lxc/lxd | shared/logging/log.go | GetLogger | func GetLogger(syslog string, logfile string, verbose bool, debug bool, customHandler log.Handler) (logger.Logger, error) {
Log := log.New()
var handlers []log.Handler
var syshandler log.Handler
// System specific handler
syshandler = getSystemHandler(syslog, debug, LogfmtFormat())
if syshandler != nil {
hand... | go | func GetLogger(syslog string, logfile string, verbose bool, debug bool, customHandler log.Handler) (logger.Logger, error) {
Log := log.New()
var handlers []log.Handler
var syshandler log.Handler
// System specific handler
syshandler = getSystemHandler(syslog, debug, LogfmtFormat())
if syshandler != nil {
hand... | [
"func",
"GetLogger",
"(",
"syslog",
"string",
",",
"logfile",
"string",
",",
"verbose",
"bool",
",",
"debug",
"bool",
",",
"customHandler",
"log",
".",
"Handler",
")",
"(",
"logger",
".",
"Logger",
",",
"error",
")",
"{",
"Log",
":=",
"log",
".",
"New"... | // GetLogger returns a logger suitable for using as logger.Log. | [
"GetLogger",
"returns",
"a",
"logger",
"suitable",
"for",
"using",
"as",
"logger",
".",
"Log",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/logging/log.go#L16-L82 | test |
lxc/lxd | shared/logging/log.go | SetLogger | func SetLogger(newLogger logger.Logger) func() {
origLog := logger.Log
logger.Log = newLogger
return func() {
logger.Log = origLog
}
} | go | func SetLogger(newLogger logger.Logger) func() {
origLog := logger.Log
logger.Log = newLogger
return func() {
logger.Log = origLog
}
} | [
"func",
"SetLogger",
"(",
"newLogger",
"logger",
".",
"Logger",
")",
"func",
"(",
")",
"{",
"origLog",
":=",
"logger",
".",
"Log",
"\n",
"logger",
".",
"Log",
"=",
"newLogger",
"\n",
"return",
"func",
"(",
")",
"{",
"logger",
".",
"Log",
"=",
"origLo... | // SetLogger installs the given logger as global logger. It returns a function
// that can be used to restore whatever logger was installed beforehand. | [
"SetLogger",
"installs",
"the",
"given",
"logger",
"as",
"global",
"logger",
".",
"It",
"returns",
"a",
"function",
"that",
"can",
"be",
"used",
"to",
"restore",
"whatever",
"logger",
"was",
"installed",
"beforehand",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/logging/log.go#L86-L92 | test |
lxc/lxd | shared/logging/log.go | WaitRecord | func WaitRecord(ch chan *log.Record, timeout time.Duration) *log.Record {
select {
case record := <-ch:
return record
case <-time.After(timeout):
return nil
}
} | go | func WaitRecord(ch chan *log.Record, timeout time.Duration) *log.Record {
select {
case record := <-ch:
return record
case <-time.After(timeout):
return nil
}
} | [
"func",
"WaitRecord",
"(",
"ch",
"chan",
"*",
"log",
".",
"Record",
",",
"timeout",
"time",
".",
"Duration",
")",
"*",
"log",
".",
"Record",
"{",
"select",
"{",
"case",
"record",
":=",
"<-",
"ch",
":",
"return",
"record",
"\n",
"case",
"<-",
"time",
... | // WaitRecord blocks until a log.Record is received on the given channel. It
// returns the emitted record, or nil if no record was received within the
// given timeout. Useful in conjunction with log.ChannelHandler, for
// asynchronous testing. | [
"WaitRecord",
"blocks",
"until",
"a",
"log",
".",
"Record",
"is",
"received",
"on",
"the",
"given",
"channel",
".",
"It",
"returns",
"the",
"emitted",
"record",
"or",
"nil",
"if",
"no",
"record",
"was",
"received",
"within",
"the",
"given",
"timeout",
".",... | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/logging/log.go#L98-L105 | test |
lxc/lxd | shared/logging/log.go | AddContext | func AddContext(logger logger.Logger, ctx log.Ctx) logger.Logger {
log15logger, ok := logger.(log.Logger)
if !ok {
logger.Error("couldn't downcast logger to add context", log.Ctx{"logger": log15logger, "ctx": ctx})
return logger
}
return log15logger.New(ctx)
} | go | func AddContext(logger logger.Logger, ctx log.Ctx) logger.Logger {
log15logger, ok := logger.(log.Logger)
if !ok {
logger.Error("couldn't downcast logger to add context", log.Ctx{"logger": log15logger, "ctx": ctx})
return logger
}
return log15logger.New(ctx)
} | [
"func",
"AddContext",
"(",
"logger",
"logger",
".",
"Logger",
",",
"ctx",
"log",
".",
"Ctx",
")",
"logger",
".",
"Logger",
"{",
"log15logger",
",",
"ok",
":=",
"logger",
".",
"(",
"log",
".",
"Logger",
")",
"\n",
"if",
"!",
"ok",
"{",
"logger",
"."... | // AddContext will return a copy of the logger with extra context added | [
"AddContext",
"will",
"return",
"a",
"copy",
"of",
"the",
"logger",
"with",
"extra",
"context",
"added"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/logging/log.go#L108-L116 | test |
lxc/lxd | shared/version/version.go | NewDottedVersion | func NewDottedVersion(versionString string) (*DottedVersion, error) {
formatError := fmt.Errorf("Invalid version format: %s", versionString)
split := strings.Split(versionString, ".")
if len(split) < 2 {
return nil, formatError
}
maj, err := strconv.Atoi(split[0])
if err != nil {
return nil, formatError
}
... | go | func NewDottedVersion(versionString string) (*DottedVersion, error) {
formatError := fmt.Errorf("Invalid version format: %s", versionString)
split := strings.Split(versionString, ".")
if len(split) < 2 {
return nil, formatError
}
maj, err := strconv.Atoi(split[0])
if err != nil {
return nil, formatError
}
... | [
"func",
"NewDottedVersion",
"(",
"versionString",
"string",
")",
"(",
"*",
"DottedVersion",
",",
"error",
")",
"{",
"formatError",
":=",
"fmt",
".",
"Errorf",
"(",
"\"Invalid version format: %s\"",
",",
"versionString",
")",
"\n",
"split",
":=",
"strings",
".",
... | // NewDottedVersion returns a new Version. | [
"NewDottedVersion",
"returns",
"a",
"new",
"Version",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/version/version.go#L18-L48 | test |
lxc/lxd | shared/version/version.go | Parse | func Parse(s string) (*DottedVersion, error) {
r, _ := regexp.Compile(`^([0-9]+.[0-9]+(.[0-9]+))?.*`)
matches := r.FindAllStringSubmatch(s, -1)
if len(matches[0]) < 2 {
return nil, fmt.Errorf("Can't parse a version")
}
return NewDottedVersion(matches[0][1])
} | go | func Parse(s string) (*DottedVersion, error) {
r, _ := regexp.Compile(`^([0-9]+.[0-9]+(.[0-9]+))?.*`)
matches := r.FindAllStringSubmatch(s, -1)
if len(matches[0]) < 2 {
return nil, fmt.Errorf("Can't parse a version")
}
return NewDottedVersion(matches[0][1])
} | [
"func",
"Parse",
"(",
"s",
"string",
")",
"(",
"*",
"DottedVersion",
",",
"error",
")",
"{",
"r",
",",
"_",
":=",
"regexp",
".",
"Compile",
"(",
"`^([0-9]+.[0-9]+(.[0-9]+))?.*`",
")",
"\n",
"matches",
":=",
"r",
".",
"FindAllStringSubmatch",
"(",
"s",
",... | // Parse parses a string starting with a dotted version and returns it. | [
"Parse",
"parses",
"a",
"string",
"starting",
"with",
"a",
"dotted",
"version",
"and",
"returns",
"it",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/version/version.go#L51-L58 | test |
lxc/lxd | shared/version/version.go | String | func (v *DottedVersion) String() string {
version := fmt.Sprintf("%d.%d", v.Major, v.Minor)
if v.Patch != -1 {
version += fmt.Sprintf(".%d", v.Patch)
}
return version
} | go | func (v *DottedVersion) String() string {
version := fmt.Sprintf("%d.%d", v.Major, v.Minor)
if v.Patch != -1 {
version += fmt.Sprintf(".%d", v.Patch)
}
return version
} | [
"func",
"(",
"v",
"*",
"DottedVersion",
")",
"String",
"(",
")",
"string",
"{",
"version",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"%d.%d\"",
",",
"v",
".",
"Major",
",",
"v",
".",
"Minor",
")",
"\n",
"if",
"v",
".",
"Patch",
"!=",
"-",
"1",
"{",
"... | // String returns version as a string | [
"String",
"returns",
"version",
"as",
"a",
"string"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/version/version.go#L61-L67 | test |
lxc/lxd | shared/version/version.go | Compare | func (v *DottedVersion) Compare(other *DottedVersion) int {
result := compareInts(v.Major, other.Major)
if result != 0 {
return result
}
result = compareInts(v.Minor, other.Minor)
if result != 0 {
return result
}
return compareInts(v.Patch, other.Patch)
} | go | func (v *DottedVersion) Compare(other *DottedVersion) int {
result := compareInts(v.Major, other.Major)
if result != 0 {
return result
}
result = compareInts(v.Minor, other.Minor)
if result != 0 {
return result
}
return compareInts(v.Patch, other.Patch)
} | [
"func",
"(",
"v",
"*",
"DottedVersion",
")",
"Compare",
"(",
"other",
"*",
"DottedVersion",
")",
"int",
"{",
"result",
":=",
"compareInts",
"(",
"v",
".",
"Major",
",",
"other",
".",
"Major",
")",
"\n",
"if",
"result",
"!=",
"0",
"{",
"return",
"resu... | // Compare returns result of comparison between two versions | [
"Compare",
"returns",
"result",
"of",
"comparison",
"between",
"two",
"versions"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/version/version.go#L70-L80 | test |
lxc/lxd | lxd/api_project.go | projectCreateDefaultProfile | func projectCreateDefaultProfile(tx *db.ClusterTx, project string) error {
// Create a default profile
profile := db.Profile{}
profile.Project = project
profile.Name = "default"
profile.Description = fmt.Sprintf("Default LXD profile for project %s", project)
profile.Config = map[string]string{}
profile.Devices =... | go | func projectCreateDefaultProfile(tx *db.ClusterTx, project string) error {
// Create a default profile
profile := db.Profile{}
profile.Project = project
profile.Name = "default"
profile.Description = fmt.Sprintf("Default LXD profile for project %s", project)
profile.Config = map[string]string{}
profile.Devices =... | [
"func",
"projectCreateDefaultProfile",
"(",
"tx",
"*",
"db",
".",
"ClusterTx",
",",
"project",
"string",
")",
"error",
"{",
"profile",
":=",
"db",
".",
"Profile",
"{",
"}",
"\n",
"profile",
".",
"Project",
"=",
"project",
"\n",
"profile",
".",
"Name",
"=... | // Create the default profile of a project. | [
"Create",
"the",
"default",
"profile",
"of",
"a",
"project",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_project.go#L164-L178 | test |
lxc/lxd | lxd/api_project.go | projectChange | func projectChange(d *Daemon, project *api.Project, req api.ProjectPut) Response {
// Flag indicating if any feature has changed.
featuresChanged := req.Config["features.images"] != project.Config["features.images"] || req.Config["features.profiles"] != project.Config["features.profiles"]
// Sanity checks
if proje... | go | func projectChange(d *Daemon, project *api.Project, req api.ProjectPut) Response {
// Flag indicating if any feature has changed.
featuresChanged := req.Config["features.images"] != project.Config["features.images"] || req.Config["features.profiles"] != project.Config["features.profiles"]
// Sanity checks
if proje... | [
"func",
"projectChange",
"(",
"d",
"*",
"Daemon",
",",
"project",
"*",
"api",
".",
"Project",
",",
"req",
"api",
".",
"ProjectPut",
")",
"Response",
"{",
"featuresChanged",
":=",
"req",
".",
"Config",
"[",
"\"features.images\"",
"]",
"!=",
"project",
".",
... | // Common logic between PUT and PATCH. | [
"Common",
"logic",
"between",
"PUT",
"and",
"PATCH",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_project.go#L317-L367 | test |
lxc/lxd | lxd/api_project.go | projectIsEmpty | func projectIsEmpty(project *api.Project) bool {
if len(project.UsedBy) > 0 {
// Check if the only entity is the default profile.
if len(project.UsedBy) == 1 && strings.Contains(project.UsedBy[0], "/profiles/default") {
return true
}
return false
}
return true
} | go | func projectIsEmpty(project *api.Project) bool {
if len(project.UsedBy) > 0 {
// Check if the only entity is the default profile.
if len(project.UsedBy) == 1 && strings.Contains(project.UsedBy[0], "/profiles/default") {
return true
}
return false
}
return true
} | [
"func",
"projectIsEmpty",
"(",
"project",
"*",
"api",
".",
"Project",
")",
"bool",
"{",
"if",
"len",
"(",
"project",
".",
"UsedBy",
")",
">",
"0",
"{",
"if",
"len",
"(",
"project",
".",
"UsedBy",
")",
"==",
"1",
"&&",
"strings",
".",
"Contains",
"(... | // Check if a project is empty. | [
"Check",
"if",
"a",
"project",
"is",
"empty",
"."
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/api_project.go#L477-L486 | test |
lxc/lxd | client/lxd_certificates.go | GetCertificateFingerprints | func (r *ProtocolLXD) GetCertificateFingerprints() ([]string, error) {
certificates := []string{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/certificates", nil, "", &certificates)
if err != nil {
return nil, err
}
// Parse it
fingerprints := []string{}
for _, fingerprint := range certificates {... | go | func (r *ProtocolLXD) GetCertificateFingerprints() ([]string, error) {
certificates := []string{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/certificates", nil, "", &certificates)
if err != nil {
return nil, err
}
// Parse it
fingerprints := []string{}
for _, fingerprint := range certificates {... | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetCertificateFingerprints",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"certificates",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"r",
".",
"queryStruct",
"(",
"\"GET\... | // Certificate handling functions
// GetCertificateFingerprints returns a list of certificate fingerprints | [
"Certificate",
"handling",
"functions",
"GetCertificateFingerprints",
"returns",
"a",
"list",
"of",
"certificate",
"fingerprints"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_certificates.go#L14-L31 | test |
lxc/lxd | client/lxd_certificates.go | GetCertificates | func (r *ProtocolLXD) GetCertificates() ([]api.Certificate, error) {
certificates := []api.Certificate{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/certificates?recursion=1", nil, "", &certificates)
if err != nil {
return nil, err
}
return certificates, nil
} | go | func (r *ProtocolLXD) GetCertificates() ([]api.Certificate, error) {
certificates := []api.Certificate{}
// Fetch the raw value
_, err := r.queryStruct("GET", "/certificates?recursion=1", nil, "", &certificates)
if err != nil {
return nil, err
}
return certificates, nil
} | [
"func",
"(",
"r",
"*",
"ProtocolLXD",
")",
"GetCertificates",
"(",
")",
"(",
"[",
"]",
"api",
".",
"Certificate",
",",
"error",
")",
"{",
"certificates",
":=",
"[",
"]",
"api",
".",
"Certificate",
"{",
"}",
"\n",
"_",
",",
"err",
":=",
"r",
".",
... | // GetCertificates returns a list of certificates | [
"GetCertificates",
"returns",
"a",
"list",
"of",
"certificates"
] | 7a41d14e4c1a6bc25918aca91004d594774dcdd3 | https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_certificates.go#L34-L44 | test |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.