repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
lxc/lxd
client/lxd_certificates.go
GetCertificate
func (r *ProtocolLXD) GetCertificate(fingerprint string) (*api.Certificate, string, error) { certificate := api.Certificate{} // Fetch the raw value etag, err := r.queryStruct("GET", fmt.Sprintf("/certificates/%s", url.QueryEscape(fingerprint)), nil, "", &certificate) if err != nil { return nil, "", err } return &certificate, etag, nil }
go
func (r *ProtocolLXD) GetCertificate(fingerprint string) (*api.Certificate, string, error) { certificate := api.Certificate{} // Fetch the raw value etag, err := r.queryStruct("GET", fmt.Sprintf("/certificates/%s", url.QueryEscape(fingerprint)), nil, "", &certificate) if err != nil { return nil, "", err } return &certificate, etag, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetCertificate", "(", "fingerprint", "string", ")", "(", "*", "api", ".", "Certificate", ",", "string", ",", "error", ")", "{", "certificate", ":=", "api", ".", "Certificate", "{", "}", "\n", "etag", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "fmt", ".", "Sprintf", "(", "\"/certificates/%s\"", ",", "url", ".", "QueryEscape", "(", "fingerprint", ")", ")", ",", "nil", ",", "\"\"", ",", "&", "certificate", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "\"\"", ",", "err", "\n", "}", "\n", "return", "&", "certificate", ",", "etag", ",", "nil", "\n", "}" ]
// GetCertificate returns the certificate entry for the provided fingerprint
[ "GetCertificate", "returns", "the", "certificate", "entry", "for", "the", "provided", "fingerprint" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_certificates.go#L47-L57
test
lxc/lxd
client/lxd_certificates.go
CreateCertificate
func (r *ProtocolLXD) CreateCertificate(certificate api.CertificatesPost) error { // Send the request _, _, err := r.query("POST", "/certificates", certificate, "") if err != nil { return err } return nil }
go
func (r *ProtocolLXD) CreateCertificate(certificate api.CertificatesPost) error { // Send the request _, _, err := r.query("POST", "/certificates", certificate, "") if err != nil { return err } return nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "CreateCertificate", "(", "certificate", "api", ".", "CertificatesPost", ")", "error", "{", "_", ",", "_", ",", "err", ":=", "r", ".", "query", "(", "\"POST\"", ",", "\"/certificates\"", ",", "certificate", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// CreateCertificate adds a new certificate to the LXD trust store
[ "CreateCertificate", "adds", "a", "new", "certificate", "to", "the", "LXD", "trust", "store" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_certificates.go#L60-L68
test
lxc/lxd
client/lxd_certificates.go
UpdateCertificate
func (r *ProtocolLXD) UpdateCertificate(fingerprint string, certificate api.CertificatePut, ETag string) error { if !r.HasExtension("certificate_update") { return fmt.Errorf("The server is missing the required \"certificate_update\" API extension") } // Send the request _, _, err := r.query("PUT", fmt.Sprintf("/certificates/%s", url.QueryEscape(fingerprint)), certificate, ETag) if err != nil { return err } return nil }
go
func (r *ProtocolLXD) UpdateCertificate(fingerprint string, certificate api.CertificatePut, ETag string) error { if !r.HasExtension("certificate_update") { return fmt.Errorf("The server is missing the required \"certificate_update\" API extension") } // Send the request _, _, err := r.query("PUT", fmt.Sprintf("/certificates/%s", url.QueryEscape(fingerprint)), certificate, ETag) if err != nil { return err } return nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "UpdateCertificate", "(", "fingerprint", "string", ",", "certificate", "api", ".", "CertificatePut", ",", "ETag", "string", ")", "error", "{", "if", "!", "r", ".", "HasExtension", "(", "\"certificate_update\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"certificate_update\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "_", ",", "_", ",", "err", ":=", "r", ".", "query", "(", "\"PUT\"", ",", "fmt", ".", "Sprintf", "(", "\"/certificates/%s\"", ",", "url", ".", "QueryEscape", "(", "fingerprint", ")", ")", ",", "certificate", ",", "ETag", ")", "\n", "}" ]
// UpdateCertificate updates the certificate definition
[ "UpdateCertificate", "updates", "the", "certificate", "definition" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_certificates.go#L71-L83
test
lxc/lxd
client/lxd_certificates.go
DeleteCertificate
func (r *ProtocolLXD) DeleteCertificate(fingerprint string) error { // Send the request _, _, err := r.query("DELETE", fmt.Sprintf("/certificates/%s", url.QueryEscape(fingerprint)), nil, "") if err != nil { return err } return nil }
go
func (r *ProtocolLXD) DeleteCertificate(fingerprint string) error { // Send the request _, _, err := r.query("DELETE", fmt.Sprintf("/certificates/%s", url.QueryEscape(fingerprint)), nil, "") if err != nil { return err } return nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "DeleteCertificate", "(", "fingerprint", "string", ")", "error", "{", "_", ",", "_", ",", "err", ":=", "r", ".", "query", "(", "\"DELETE\"", ",", "fmt", ".", "Sprintf", "(", "\"/certificates/%s\"", ",", "url", ".", "QueryEscape", "(", "fingerprint", ")", ")", ",", "nil", ",", "\"\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteCertificate removes a certificate from the LXD trust store
[ "DeleteCertificate", "removes", "a", "certificate", "from", "the", "LXD", "trust", "store" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_certificates.go#L86-L94
test
lxc/lxd
lxd/container_metadata.go
containerMetadataTemplatesGet
func containerMetadataTemplatesGet(d *Daemon, r *http.Request) Response { project := projectParam(r) name := mux.Vars(r)["name"] // Handle requests targeted to a container on a different node response, err := ForwardedResponseIfContainerIsRemote(d, r, project, name) if err != nil { return SmartError(err) } if response != nil { return response } // Load the container c, err := containerLoadByProjectAndName(d.State(), project, name) if err != nil { return SmartError(err) } // Start the storage if needed ourStart, err := c.StorageStart() if err != nil { return SmartError(err) } if ourStart { defer c.StorageStop() } // Look at the request templateName := r.FormValue("path") if templateName == "" { // List templates templatesPath := filepath.Join(c.Path(), "templates") filesInfo, err := ioutil.ReadDir(templatesPath) if err != nil { return InternalError(err) } templates := []string{} for _, info := range filesInfo { if !info.IsDir() { templates = append(templates, info.Name()) } } return SyncResponse(true, templates) } // Check if the template exists templatePath, err := getContainerTemplatePath(c, templateName) if err != nil { return SmartError(err) } if !shared.PathExists(templatePath) { return NotFound(fmt.Errorf("Path '%s' not found", templatePath)) } // Create a temporary file with the template content (since the container // storage might not be available when the file is read from FileResponse) template, err := os.Open(templatePath) if err != nil { return SmartError(err) } defer template.Close() tempfile, err := ioutil.TempFile("", "lxd_template") if err != nil { return SmartError(err) } defer tempfile.Close() _, err = io.Copy(tempfile, template) if err != nil { return InternalError(err) } files := make([]fileResponseEntry, 1) files[0].identifier = templateName files[0].path = tempfile.Name() files[0].filename = templateName return FileResponse(r, files, nil, true) }
go
func containerMetadataTemplatesGet(d *Daemon, r *http.Request) Response { project := projectParam(r) name := mux.Vars(r)["name"] // Handle requests targeted to a container on a different node response, err := ForwardedResponseIfContainerIsRemote(d, r, project, name) if err != nil { return SmartError(err) } if response != nil { return response } // Load the container c, err := containerLoadByProjectAndName(d.State(), project, name) if err != nil { return SmartError(err) } // Start the storage if needed ourStart, err := c.StorageStart() if err != nil { return SmartError(err) } if ourStart { defer c.StorageStop() } // Look at the request templateName := r.FormValue("path") if templateName == "" { // List templates templatesPath := filepath.Join(c.Path(), "templates") filesInfo, err := ioutil.ReadDir(templatesPath) if err != nil { return InternalError(err) } templates := []string{} for _, info := range filesInfo { if !info.IsDir() { templates = append(templates, info.Name()) } } return SyncResponse(true, templates) } // Check if the template exists templatePath, err := getContainerTemplatePath(c, templateName) if err != nil { return SmartError(err) } if !shared.PathExists(templatePath) { return NotFound(fmt.Errorf("Path '%s' not found", templatePath)) } // Create a temporary file with the template content (since the container // storage might not be available when the file is read from FileResponse) template, err := os.Open(templatePath) if err != nil { return SmartError(err) } defer template.Close() tempfile, err := ioutil.TempFile("", "lxd_template") if err != nil { return SmartError(err) } defer tempfile.Close() _, err = io.Copy(tempfile, template) if err != nil { return InternalError(err) } files := make([]fileResponseEntry, 1) files[0].identifier = templateName files[0].path = tempfile.Name() files[0].filename = templateName return FileResponse(r, files, nil, true) }
[ "func", "containerMetadataTemplatesGet", "(", "d", "*", "Daemon", ",", "r", "*", "http", ".", "Request", ")", "Response", "{", "project", ":=", "projectParam", "(", "r", ")", "\n", "name", ":=", "mux", ".", "Vars", "(", "r", ")", "[", "\"name\"", "]", "\n", "response", ",", "err", ":=", "ForwardedResponseIfContainerIsRemote", "(", "d", ",", "r", ",", "project", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "if", "response", "!=", "nil", "{", "return", "response", "\n", "}", "\n", "c", ",", "err", ":=", "containerLoadByProjectAndName", "(", "d", ".", "State", "(", ")", ",", "project", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "ourStart", ",", "err", ":=", "c", ".", "StorageStart", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "if", "ourStart", "{", "defer", "c", ".", "StorageStop", "(", ")", "\n", "}", "\n", "templateName", ":=", "r", ".", "FormValue", "(", "\"path\"", ")", "\n", "if", "templateName", "==", "\"\"", "{", "templatesPath", ":=", "filepath", ".", "Join", "(", "c", ".", "Path", "(", ")", ",", "\"templates\"", ")", "\n", "filesInfo", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "templatesPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "InternalError", "(", "err", ")", "\n", "}", "\n", "templates", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "info", ":=", "range", "filesInfo", "{", "if", "!", "info", ".", "IsDir", "(", ")", "{", "templates", "=", "append", "(", "templates", ",", "info", ".", "Name", "(", ")", ")", "\n", "}", "\n", "}", "\n", "return", "SyncResponse", "(", "true", ",", "templates", ")", "\n", "}", "\n", "templatePath", ",", "err", ":=", "getContainerTemplatePath", "(", "c", ",", "templateName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "if", "!", "shared", ".", "PathExists", "(", "templatePath", ")", "{", "return", "NotFound", "(", "fmt", ".", "Errorf", "(", "\"Path '%s' not found\"", ",", "templatePath", ")", ")", "\n", "}", "\n", "template", ",", "err", ":=", "os", ".", "Open", "(", "templatePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "defer", "template", ".", "Close", "(", ")", "\n", "tempfile", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "\"\"", ",", "\"lxd_template\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "defer", "tempfile", ".", "Close", "(", ")", "\n", "_", ",", "err", "=", "io", ".", "Copy", "(", "tempfile", ",", "template", ")", "\n", "if", "err", "!=", "nil", "{", "return", "InternalError", "(", "err", ")", "\n", "}", "\n", "files", ":=", "make", "(", "[", "]", "fileResponseEntry", ",", "1", ")", "\n", "files", "[", "0", "]", ".", "identifier", "=", "templateName", "\n", "files", "[", "0", "]", ".", "path", "=", "tempfile", ".", "Name", "(", ")", "\n", "files", "[", "0", "]", ".", "filename", "=", "templateName", "\n", "return", "FileResponse", "(", "r", ",", "files", ",", "nil", ",", "true", ")", "\n", "}" ]
// Return a list of templates used in a container or the content of a template
[ "Return", "a", "list", "of", "templates", "used", "in", "a", "container", "or", "the", "content", "of", "a", "template" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_metadata.go#L121-L203
test
lxc/lxd
lxd/container_metadata.go
containerMetadataTemplatesPostPut
func containerMetadataTemplatesPostPut(d *Daemon, r *http.Request) Response { project := projectParam(r) name := mux.Vars(r)["name"] // Handle requests targeted to a container on a different node response, err := ForwardedResponseIfContainerIsRemote(d, r, project, name) if err != nil { return SmartError(err) } if response != nil { return response } // Load the container c, err := containerLoadByProjectAndName(d.State(), project, name) if err != nil { return SmartError(err) } // Start the storage if needed ourStart, err := c.StorageStart() if err != nil { return SmartError(err) } if ourStart { defer c.StorageStop() } // Look at the request templateName := r.FormValue("path") if templateName == "" { return BadRequest(fmt.Errorf("missing path argument")) } // Check if the template already exists templatePath, err := getContainerTemplatePath(c, templateName) if err != nil { return SmartError(err) } if r.Method == "POST" && shared.PathExists(templatePath) { return BadRequest(fmt.Errorf("Template already exists")) } // Write the new template template, err := os.OpenFile(templatePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return SmartError(err) } defer template.Close() _, err = io.Copy(template, r.Body) if err != nil { return InternalError(err) } return EmptySyncResponse }
go
func containerMetadataTemplatesPostPut(d *Daemon, r *http.Request) Response { project := projectParam(r) name := mux.Vars(r)["name"] // Handle requests targeted to a container on a different node response, err := ForwardedResponseIfContainerIsRemote(d, r, project, name) if err != nil { return SmartError(err) } if response != nil { return response } // Load the container c, err := containerLoadByProjectAndName(d.State(), project, name) if err != nil { return SmartError(err) } // Start the storage if needed ourStart, err := c.StorageStart() if err != nil { return SmartError(err) } if ourStart { defer c.StorageStop() } // Look at the request templateName := r.FormValue("path") if templateName == "" { return BadRequest(fmt.Errorf("missing path argument")) } // Check if the template already exists templatePath, err := getContainerTemplatePath(c, templateName) if err != nil { return SmartError(err) } if r.Method == "POST" && shared.PathExists(templatePath) { return BadRequest(fmt.Errorf("Template already exists")) } // Write the new template template, err := os.OpenFile(templatePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return SmartError(err) } defer template.Close() _, err = io.Copy(template, r.Body) if err != nil { return InternalError(err) } return EmptySyncResponse }
[ "func", "containerMetadataTemplatesPostPut", "(", "d", "*", "Daemon", ",", "r", "*", "http", ".", "Request", ")", "Response", "{", "project", ":=", "projectParam", "(", "r", ")", "\n", "name", ":=", "mux", ".", "Vars", "(", "r", ")", "[", "\"name\"", "]", "\n", "response", ",", "err", ":=", "ForwardedResponseIfContainerIsRemote", "(", "d", ",", "r", ",", "project", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "if", "response", "!=", "nil", "{", "return", "response", "\n", "}", "\n", "c", ",", "err", ":=", "containerLoadByProjectAndName", "(", "d", ".", "State", "(", ")", ",", "project", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "ourStart", ",", "err", ":=", "c", ".", "StorageStart", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "if", "ourStart", "{", "defer", "c", ".", "StorageStop", "(", ")", "\n", "}", "\n", "templateName", ":=", "r", ".", "FormValue", "(", "\"path\"", ")", "\n", "if", "templateName", "==", "\"\"", "{", "return", "BadRequest", "(", "fmt", ".", "Errorf", "(", "\"missing path argument\"", ")", ")", "\n", "}", "\n", "templatePath", ",", "err", ":=", "getContainerTemplatePath", "(", "c", ",", "templateName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "if", "r", ".", "Method", "==", "\"POST\"", "&&", "shared", ".", "PathExists", "(", "templatePath", ")", "{", "return", "BadRequest", "(", "fmt", ".", "Errorf", "(", "\"Template already exists\"", ")", ")", "\n", "}", "\n", "template", ",", "err", ":=", "os", ".", "OpenFile", "(", "templatePath", ",", "os", ".", "O_WRONLY", "|", "os", ".", "O_CREATE", "|", "os", ".", "O_TRUNC", ",", "0644", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "defer", "template", ".", "Close", "(", ")", "\n", "_", ",", "err", "=", "io", ".", "Copy", "(", "template", ",", "r", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "InternalError", "(", "err", ")", "\n", "}", "\n", "return", "EmptySyncResponse", "\n", "}" ]
// Add a container template file
[ "Add", "a", "container", "template", "file" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_metadata.go#L206-L263
test
lxc/lxd
lxd/container_metadata.go
containerMetadataTemplatesDelete
func containerMetadataTemplatesDelete(d *Daemon, r *http.Request) Response { project := projectParam(r) name := mux.Vars(r)["name"] // Handle requests targeted to a container on a different node response, err := ForwardedResponseIfContainerIsRemote(d, r, project, name) if err != nil { return SmartError(err) } if response != nil { return response } // Load the container c, err := containerLoadByProjectAndName(d.State(), project, name) if err != nil { return SmartError(err) } // Start the storage if needed ourStart, err := c.StorageStart() if err != nil { return SmartError(err) } if ourStart { defer c.StorageStop() } // Look at the request templateName := r.FormValue("path") if templateName == "" { return BadRequest(fmt.Errorf("missing path argument")) } templatePath, err := getContainerTemplatePath(c, templateName) if err != nil { return SmartError(err) } if !shared.PathExists(templatePath) { return NotFound(fmt.Errorf("Path '%s' not found", templatePath)) } // Delete the template err = os.Remove(templatePath) if err != nil { return InternalError(err) } return EmptySyncResponse }
go
func containerMetadataTemplatesDelete(d *Daemon, r *http.Request) Response { project := projectParam(r) name := mux.Vars(r)["name"] // Handle requests targeted to a container on a different node response, err := ForwardedResponseIfContainerIsRemote(d, r, project, name) if err != nil { return SmartError(err) } if response != nil { return response } // Load the container c, err := containerLoadByProjectAndName(d.State(), project, name) if err != nil { return SmartError(err) } // Start the storage if needed ourStart, err := c.StorageStart() if err != nil { return SmartError(err) } if ourStart { defer c.StorageStop() } // Look at the request templateName := r.FormValue("path") if templateName == "" { return BadRequest(fmt.Errorf("missing path argument")) } templatePath, err := getContainerTemplatePath(c, templateName) if err != nil { return SmartError(err) } if !shared.PathExists(templatePath) { return NotFound(fmt.Errorf("Path '%s' not found", templatePath)) } // Delete the template err = os.Remove(templatePath) if err != nil { return InternalError(err) } return EmptySyncResponse }
[ "func", "containerMetadataTemplatesDelete", "(", "d", "*", "Daemon", ",", "r", "*", "http", ".", "Request", ")", "Response", "{", "project", ":=", "projectParam", "(", "r", ")", "\n", "name", ":=", "mux", ".", "Vars", "(", "r", ")", "[", "\"name\"", "]", "\n", "response", ",", "err", ":=", "ForwardedResponseIfContainerIsRemote", "(", "d", ",", "r", ",", "project", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "if", "response", "!=", "nil", "{", "return", "response", "\n", "}", "\n", "c", ",", "err", ":=", "containerLoadByProjectAndName", "(", "d", ".", "State", "(", ")", ",", "project", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "ourStart", ",", "err", ":=", "c", ".", "StorageStart", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "if", "ourStart", "{", "defer", "c", ".", "StorageStop", "(", ")", "\n", "}", "\n", "templateName", ":=", "r", ".", "FormValue", "(", "\"path\"", ")", "\n", "if", "templateName", "==", "\"\"", "{", "return", "BadRequest", "(", "fmt", ".", "Errorf", "(", "\"missing path argument\"", ")", ")", "\n", "}", "\n", "templatePath", ",", "err", ":=", "getContainerTemplatePath", "(", "c", ",", "templateName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "SmartError", "(", "err", ")", "\n", "}", "\n", "if", "!", "shared", ".", "PathExists", "(", "templatePath", ")", "{", "return", "NotFound", "(", "fmt", ".", "Errorf", "(", "\"Path '%s' not found\"", ",", "templatePath", ")", ")", "\n", "}", "\n", "err", "=", "os", ".", "Remove", "(", "templatePath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "InternalError", "(", "err", ")", "\n", "}", "\n", "return", "EmptySyncResponse", "\n", "}" ]
// Delete a container template
[ "Delete", "a", "container", "template" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_metadata.go#L266-L317
test
lxc/lxd
lxd/container_metadata.go
getContainerTemplatePath
func getContainerTemplatePath(c container, filename string) (string, error) { if strings.Contains(filename, "/") { return "", fmt.Errorf("Invalid template filename") } return filepath.Join(c.Path(), "templates", filename), nil }
go
func getContainerTemplatePath(c container, filename string) (string, error) { if strings.Contains(filename, "/") { return "", fmt.Errorf("Invalid template filename") } return filepath.Join(c.Path(), "templates", filename), nil }
[ "func", "getContainerTemplatePath", "(", "c", "container", ",", "filename", "string", ")", "(", "string", ",", "error", ")", "{", "if", "strings", ".", "Contains", "(", "filename", ",", "\"/\"", ")", "{", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"Invalid template filename\"", ")", "\n", "}", "\n", "return", "filepath", ".", "Join", "(", "c", ".", "Path", "(", ")", ",", "\"templates\"", ",", "filename", ")", ",", "nil", "\n", "}" ]
// Return the full path of a container template.
[ "Return", "the", "full", "path", "of", "a", "container", "template", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/container_metadata.go#L320-L326
test
lxc/lxd
lxd/config/errors.go
Error
func (e Error) Error() string { message := fmt.Sprintf("cannot set '%s'", e.Name) if e.Value != nil { message += fmt.Sprintf(" to '%v'", e.Value) } return message + fmt.Sprintf(": %s", e.Reason) }
go
func (e Error) Error() string { message := fmt.Sprintf("cannot set '%s'", e.Name) if e.Value != nil { message += fmt.Sprintf(" to '%v'", e.Value) } return message + fmt.Sprintf(": %s", e.Reason) }
[ "func", "(", "e", "Error", ")", "Error", "(", ")", "string", "{", "message", ":=", "fmt", ".", "Sprintf", "(", "\"cannot set '%s'\"", ",", "e", ".", "Name", ")", "\n", "if", "e", ".", "Value", "!=", "nil", "{", "message", "+=", "fmt", ".", "Sprintf", "(", "\" to '%v'\"", ",", "e", ".", "Value", ")", "\n", "}", "\n", "return", "message", "+", "fmt", ".", "Sprintf", "(", "\": %s\"", ",", "e", ".", "Reason", ")", "\n", "}" ]
// Error implements the error interface.
[ "Error", "implements", "the", "error", "interface", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/errors.go#L16-L22
test
lxc/lxd
lxd/config/errors.go
Error
func (l ErrorList) Error() string { switch len(l) { case 0: return "no errors" case 1: return l[0].Error() } return fmt.Sprintf("%s (and %d more errors)", l[0], len(l)-1) }
go
func (l ErrorList) Error() string { switch len(l) { case 0: return "no errors" case 1: return l[0].Error() } return fmt.Sprintf("%s (and %d more errors)", l[0], len(l)-1) }
[ "func", "(", "l", "ErrorList", ")", "Error", "(", ")", "string", "{", "switch", "len", "(", "l", ")", "{", "case", "0", ":", "return", "\"no errors\"", "\n", "case", "1", ":", "return", "l", "[", "0", "]", ".", "Error", "(", ")", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"%s (and %d more errors)\"", ",", "l", "[", "0", "]", ",", "len", "(", "l", ")", "-", "1", ")", "\n", "}" ]
// ErrorList implements the error interface.
[ "ErrorList", "implements", "the", "error", "interface", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/errors.go#L29-L37
test
lxc/lxd
lxd/config/errors.go
add
func (l *ErrorList) add(name string, value interface{}, reason string) { *l = append(*l, &Error{name, value, reason}) }
go
func (l *ErrorList) add(name string, value interface{}, reason string) { *l = append(*l, &Error{name, value, reason}) }
[ "func", "(", "l", "*", "ErrorList", ")", "add", "(", "name", "string", ",", "value", "interface", "{", "}", ",", "reason", "string", ")", "{", "*", "l", "=", "append", "(", "*", "l", ",", "&", "Error", "{", "name", ",", "value", ",", "reason", "}", ")", "\n", "}" ]
// Add adds an Error with given key name, value and reason.
[ "Add", "adds", "an", "Error", "with", "given", "key", "name", "value", "and", "reason", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/config/errors.go#L48-L50
test
lxc/lxd
shared/generate/db/schema.go
UpdateSchema
func UpdateSchema() error { err := cluster.SchemaDotGo() if err != nil { return errors.Wrap(err, "Update cluster database schema") } err = node.SchemaDotGo() if err != nil { return errors.Wrap(err, "Update node database schema") } return nil }
go
func UpdateSchema() error { err := cluster.SchemaDotGo() if err != nil { return errors.Wrap(err, "Update cluster database schema") } err = node.SchemaDotGo() if err != nil { return errors.Wrap(err, "Update node database schema") } return nil }
[ "func", "UpdateSchema", "(", ")", "error", "{", "err", ":=", "cluster", ".", "SchemaDotGo", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"Update cluster database schema\"", ")", "\n", "}", "\n", "err", "=", "node", ".", "SchemaDotGo", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"Update node database schema\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdateSchema updates the schema.go file of the cluster and node databases.
[ "UpdateSchema", "updates", "the", "schema", ".", "go", "file", "of", "the", "cluster", "and", "node", "databases", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/generate/db/schema.go#L11-L23
test
lxc/lxd
lxd/profiles_utils.go
doProfileUpdateCluster
func doProfileUpdateCluster(d *Daemon, project, name string, old api.ProfilePut) error { nodeName := "" err := d.cluster.Transaction(func(tx *db.ClusterTx) error { var err error nodeName, err = tx.NodeName() return err }) if err != nil { return errors.Wrap(err, "failed to query local node name") } containers, err := getProfileContainersInfo(d.cluster, project, name) if err != nil { return errors.Wrapf(err, "failed to query containers associated with profile '%s'", name) } failures := map[string]error{} for _, args := range containers { err := doProfileUpdateContainer(d, name, old, nodeName, args) if err != nil { failures[args.Name] = err } } if len(failures) != 0 { msg := "The following containers failed to update (profile change still saved):\n" for cname, err := range failures { msg += fmt.Sprintf(" - %s: %s\n", cname, err) } return fmt.Errorf("%s", msg) } return nil }
go
func doProfileUpdateCluster(d *Daemon, project, name string, old api.ProfilePut) error { nodeName := "" err := d.cluster.Transaction(func(tx *db.ClusterTx) error { var err error nodeName, err = tx.NodeName() return err }) if err != nil { return errors.Wrap(err, "failed to query local node name") } containers, err := getProfileContainersInfo(d.cluster, project, name) if err != nil { return errors.Wrapf(err, "failed to query containers associated with profile '%s'", name) } failures := map[string]error{} for _, args := range containers { err := doProfileUpdateContainer(d, name, old, nodeName, args) if err != nil { failures[args.Name] = err } } if len(failures) != 0 { msg := "The following containers failed to update (profile change still saved):\n" for cname, err := range failures { msg += fmt.Sprintf(" - %s: %s\n", cname, err) } return fmt.Errorf("%s", msg) } return nil }
[ "func", "doProfileUpdateCluster", "(", "d", "*", "Daemon", ",", "project", ",", "name", "string", ",", "old", "api", ".", "ProfilePut", ")", "error", "{", "nodeName", ":=", "\"\"", "\n", "err", ":=", "d", ".", "cluster", ".", "Transaction", "(", "func", "(", "tx", "*", "db", ".", "ClusterTx", ")", "error", "{", "var", "err", "error", "\n", "nodeName", ",", "err", "=", "tx", ".", "NodeName", "(", ")", "\n", "return", "err", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"failed to query local node name\"", ")", "\n", "}", "\n", "containers", ",", "err", ":=", "getProfileContainersInfo", "(", "d", ".", "cluster", ",", "project", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to query containers associated with profile '%s'\"", ",", "name", ")", "\n", "}", "\n", "failures", ":=", "map", "[", "string", "]", "error", "{", "}", "\n", "for", "_", ",", "args", ":=", "range", "containers", "{", "err", ":=", "doProfileUpdateContainer", "(", "d", ",", "name", ",", "old", ",", "nodeName", ",", "args", ")", "\n", "if", "err", "!=", "nil", "{", "failures", "[", "args", ".", "Name", "]", "=", "err", "\n", "}", "\n", "}", "\n", "if", "len", "(", "failures", ")", "!=", "0", "{", "msg", ":=", "\"The following containers failed to update (profile change still saved):\\n\"", "\n", "\\n", "\n", "for", "cname", ",", "err", ":=", "range", "failures", "{", "msg", "+=", "fmt", ".", "Sprintf", "(", "\" - %s: %s\\n\"", ",", "\\n", ",", "cname", ")", "\n", "}", "\n", "}", "\n", "err", "\n", "}" ]
// Like doProfileUpdate but does not update the database, since it was already // updated by doProfileUpdate itself, called on the notifying node.
[ "Like", "doProfileUpdate", "but", "does", "not", "update", "the", "database", "since", "it", "was", "already", "updated", "by", "doProfileUpdate", "itself", "called", "on", "the", "notifying", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/profiles_utils.go#L152-L185
test
lxc/lxd
lxd/profiles_utils.go
doProfileUpdateContainer
func doProfileUpdateContainer(d *Daemon, name string, old api.ProfilePut, nodeName string, args db.ContainerArgs) error { if args.Node != "" && args.Node != nodeName { // No-op, this container does not belong to this node. return nil } profiles, err := d.cluster.ProfilesGet(args.Project, args.Profiles) if err != nil { return err } for i, profileName := range args.Profiles { if profileName == name { // Use the old config and devices. profiles[i].Config = old.Config profiles[i].Devices = old.Devices break } } c := containerLXCInstantiate(d.State(), args) c.expandConfig(profiles) c.expandDevices(profiles) return c.Update(db.ContainerArgs{ Architecture: c.Architecture(), Config: c.LocalConfig(), Description: c.Description(), Devices: c.LocalDevices(), Ephemeral: c.IsEphemeral(), Profiles: c.Profiles(), Project: c.Project(), }, true) }
go
func doProfileUpdateContainer(d *Daemon, name string, old api.ProfilePut, nodeName string, args db.ContainerArgs) error { if args.Node != "" && args.Node != nodeName { // No-op, this container does not belong to this node. return nil } profiles, err := d.cluster.ProfilesGet(args.Project, args.Profiles) if err != nil { return err } for i, profileName := range args.Profiles { if profileName == name { // Use the old config and devices. profiles[i].Config = old.Config profiles[i].Devices = old.Devices break } } c := containerLXCInstantiate(d.State(), args) c.expandConfig(profiles) c.expandDevices(profiles) return c.Update(db.ContainerArgs{ Architecture: c.Architecture(), Config: c.LocalConfig(), Description: c.Description(), Devices: c.LocalDevices(), Ephemeral: c.IsEphemeral(), Profiles: c.Profiles(), Project: c.Project(), }, true) }
[ "func", "doProfileUpdateContainer", "(", "d", "*", "Daemon", ",", "name", "string", ",", "old", "api", ".", "ProfilePut", ",", "nodeName", "string", ",", "args", "db", ".", "ContainerArgs", ")", "error", "{", "if", "args", ".", "Node", "!=", "\"\"", "&&", "args", ".", "Node", "!=", "nodeName", "{", "return", "nil", "\n", "}", "\n", "profiles", ",", "err", ":=", "d", ".", "cluster", ".", "ProfilesGet", "(", "args", ".", "Project", ",", "args", ".", "Profiles", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "i", ",", "profileName", ":=", "range", "args", ".", "Profiles", "{", "if", "profileName", "==", "name", "{", "profiles", "[", "i", "]", ".", "Config", "=", "old", ".", "Config", "\n", "profiles", "[", "i", "]", ".", "Devices", "=", "old", ".", "Devices", "\n", "break", "\n", "}", "\n", "}", "\n", "c", ":=", "containerLXCInstantiate", "(", "d", ".", "State", "(", ")", ",", "args", ")", "\n", "c", ".", "expandConfig", "(", "profiles", ")", "\n", "c", ".", "expandDevices", "(", "profiles", ")", "\n", "return", "c", ".", "Update", "(", "db", ".", "ContainerArgs", "{", "Architecture", ":", "c", ".", "Architecture", "(", ")", ",", "Config", ":", "c", ".", "LocalConfig", "(", ")", ",", "Description", ":", "c", ".", "Description", "(", ")", ",", "Devices", ":", "c", ".", "LocalDevices", "(", ")", ",", "Ephemeral", ":", "c", ".", "IsEphemeral", "(", ")", ",", "Profiles", ":", "c", ".", "Profiles", "(", ")", ",", "Project", ":", "c", ".", "Project", "(", ")", ",", "}", ",", "true", ")", "\n", "}" ]
// Profile update of a single container.
[ "Profile", "update", "of", "a", "single", "container", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/profiles_utils.go#L188-L221
test
lxc/lxd
lxd/profiles_utils.go
getProfileContainersInfo
func getProfileContainersInfo(cluster *db.Cluster, project, profile string) ([]db.ContainerArgs, error) { // Query the db for information about containers associated with the // given profile. names, err := cluster.ProfileContainersGet(project, profile) if err != nil { return nil, errors.Wrapf(err, "failed to query containers with profile '%s'", profile) } containers := []db.ContainerArgs{} err = cluster.Transaction(func(tx *db.ClusterTx) error { for ctProject, ctNames := range names { for _, ctName := range ctNames { container, err := tx.ContainerGet(ctProject, ctName) if err != nil { return err } containers = append(containers, db.ContainerToArgs(container)) } } return nil }) if err != nil { return nil, errors.Wrapf(err, "Failed to fetch containers") } return containers, nil }
go
func getProfileContainersInfo(cluster *db.Cluster, project, profile string) ([]db.ContainerArgs, error) { // Query the db for information about containers associated with the // given profile. names, err := cluster.ProfileContainersGet(project, profile) if err != nil { return nil, errors.Wrapf(err, "failed to query containers with profile '%s'", profile) } containers := []db.ContainerArgs{} err = cluster.Transaction(func(tx *db.ClusterTx) error { for ctProject, ctNames := range names { for _, ctName := range ctNames { container, err := tx.ContainerGet(ctProject, ctName) if err != nil { return err } containers = append(containers, db.ContainerToArgs(container)) } } return nil }) if err != nil { return nil, errors.Wrapf(err, "Failed to fetch containers") } return containers, nil }
[ "func", "getProfileContainersInfo", "(", "cluster", "*", "db", ".", "Cluster", ",", "project", ",", "profile", "string", ")", "(", "[", "]", "db", ".", "ContainerArgs", ",", "error", ")", "{", "names", ",", "err", ":=", "cluster", ".", "ProfileContainersGet", "(", "project", ",", "profile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to query containers with profile '%s'\"", ",", "profile", ")", "\n", "}", "\n", "containers", ":=", "[", "]", "db", ".", "ContainerArgs", "{", "}", "\n", "err", "=", "cluster", ".", "Transaction", "(", "func", "(", "tx", "*", "db", ".", "ClusterTx", ")", "error", "{", "for", "ctProject", ",", "ctNames", ":=", "range", "names", "{", "for", "_", ",", "ctName", ":=", "range", "ctNames", "{", "container", ",", "err", ":=", "tx", ".", "ContainerGet", "(", "ctProject", ",", "ctName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "containers", "=", "append", "(", "containers", ",", "db", ".", "ContainerToArgs", "(", "container", ")", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"Failed to fetch containers\"", ")", "\n", "}", "\n", "return", "containers", ",", "nil", "\n", "}" ]
// Query the db for information about containers associated with the given // profile.
[ "Query", "the", "db", "for", "information", "about", "containers", "associated", "with", "the", "given", "profile", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/profiles_utils.go#L225-L253
test
lxc/lxd
client/lxd_networks.go
GetNetworkNames
func (r *ProtocolLXD) GetNetworkNames() ([]string, error) { if !r.HasExtension("network") { return nil, fmt.Errorf("The server is missing the required \"network\" API extension") } urls := []string{} // Fetch the raw value _, err := r.queryStruct("GET", "/networks", nil, "", &urls) if err != nil { return nil, err } // Parse it names := []string{} for _, url := range urls { fields := strings.Split(url, "/networks/") names = append(names, fields[len(fields)-1]) } return names, nil }
go
func (r *ProtocolLXD) GetNetworkNames() ([]string, error) { if !r.HasExtension("network") { return nil, fmt.Errorf("The server is missing the required \"network\" API extension") } urls := []string{} // Fetch the raw value _, err := r.queryStruct("GET", "/networks", nil, "", &urls) if err != nil { return nil, err } // Parse it names := []string{} for _, url := range urls { fields := strings.Split(url, "/networks/") names = append(names, fields[len(fields)-1]) } return names, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetNetworkNames", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"network\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"network\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "urls", ":=", "[", "]", "string", "{", "}", "\n", "_", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "\"/networks\"", ",", "nil", ",", "\"\"", ",", "&", "urls", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "names", ":=", "[", "]", "string", "{", "}", "\n", "}" ]
// GetNetworkNames returns a list of network names
[ "GetNetworkNames", "returns", "a", "list", "of", "network", "names" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_networks.go#L12-L33
test
lxc/lxd
client/lxd_networks.go
GetNetworks
func (r *ProtocolLXD) GetNetworks() ([]api.Network, error) { if !r.HasExtension("network") { return nil, fmt.Errorf("The server is missing the required \"network\" API extension") } networks := []api.Network{} // Fetch the raw value _, err := r.queryStruct("GET", "/networks?recursion=1", nil, "", &networks) if err != nil { return nil, err } return networks, nil }
go
func (r *ProtocolLXD) GetNetworks() ([]api.Network, error) { if !r.HasExtension("network") { return nil, fmt.Errorf("The server is missing the required \"network\" API extension") } networks := []api.Network{} // Fetch the raw value _, err := r.queryStruct("GET", "/networks?recursion=1", nil, "", &networks) if err != nil { return nil, err } return networks, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetNetworks", "(", ")", "(", "[", "]", "api", ".", "Network", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"network\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"network\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "networks", ":=", "[", "]", "api", ".", "Network", "{", "}", "\n", "_", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "\"/networks?recursion=1\"", ",", "nil", ",", "\"\"", ",", "&", "networks", ")", "\n", "}" ]
// GetNetworks returns a list of Network struct
[ "GetNetworks", "returns", "a", "list", "of", "Network", "struct" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_networks.go#L36-L50
test
lxc/lxd
client/lxd_networks.go
GetNetwork
func (r *ProtocolLXD) GetNetwork(name string) (*api.Network, string, error) { if !r.HasExtension("network") { return nil, "", fmt.Errorf("The server is missing the required \"network\" API extension") } network := api.Network{} // Fetch the raw value etag, err := r.queryStruct("GET", fmt.Sprintf("/networks/%s", url.QueryEscape(name)), nil, "", &network) if err != nil { return nil, "", err } return &network, etag, nil }
go
func (r *ProtocolLXD) GetNetwork(name string) (*api.Network, string, error) { if !r.HasExtension("network") { return nil, "", fmt.Errorf("The server is missing the required \"network\" API extension") } network := api.Network{} // Fetch the raw value etag, err := r.queryStruct("GET", fmt.Sprintf("/networks/%s", url.QueryEscape(name)), nil, "", &network) if err != nil { return nil, "", err } return &network, etag, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetNetwork", "(", "name", "string", ")", "(", "*", "api", ".", "Network", ",", "string", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"network\"", ")", "{", "return", "nil", ",", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"network\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "network", ":=", "api", ".", "Network", "{", "}", "\n", "etag", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "fmt", ".", "Sprintf", "(", "\"/networks/%s\"", ",", "url", ".", "QueryEscape", "(", "name", ")", ")", ",", "nil", ",", "\"\"", ",", "&", "network", ")", "\n", "}" ]
// GetNetwork returns a Network entry for the provided name
[ "GetNetwork", "returns", "a", "Network", "entry", "for", "the", "provided", "name" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_networks.go#L53-L67
test
lxc/lxd
client/lxd_networks.go
GetNetworkLeases
func (r *ProtocolLXD) GetNetworkLeases(name string) ([]api.NetworkLease, error) { if !r.HasExtension("network_leases") { return nil, fmt.Errorf("The server is missing the required \"network_leases\" API extension") } leases := []api.NetworkLease{} // Fetch the raw value _, err := r.queryStruct("GET", fmt.Sprintf("/networks/%s/leases", url.QueryEscape(name)), nil, "", &leases) if err != nil { return nil, err } return leases, nil }
go
func (r *ProtocolLXD) GetNetworkLeases(name string) ([]api.NetworkLease, error) { if !r.HasExtension("network_leases") { return nil, fmt.Errorf("The server is missing the required \"network_leases\" API extension") } leases := []api.NetworkLease{} // Fetch the raw value _, err := r.queryStruct("GET", fmt.Sprintf("/networks/%s/leases", url.QueryEscape(name)), nil, "", &leases) if err != nil { return nil, err } return leases, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetNetworkLeases", "(", "name", "string", ")", "(", "[", "]", "api", ".", "NetworkLease", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"network_leases\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"network_leases\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "leases", ":=", "[", "]", "api", ".", "NetworkLease", "{", "}", "\n", "_", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "fmt", ".", "Sprintf", "(", "\"/networks/%s/leases\"", ",", "url", ".", "QueryEscape", "(", "name", ")", ")", ",", "nil", ",", "\"\"", ",", "&", "leases", ")", "\n", "}" ]
// GetNetworkLeases returns a list of Network struct
[ "GetNetworkLeases", "returns", "a", "list", "of", "Network", "struct" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_networks.go#L70-L84
test
lxc/lxd
client/lxd_networks.go
GetNetworkState
func (r *ProtocolLXD) GetNetworkState(name string) (*api.NetworkState, error) { if !r.HasExtension("network_state") { return nil, fmt.Errorf("The server is missing the required \"network_state\" API extension") } state := api.NetworkState{} // Fetch the raw value _, err := r.queryStruct("GET", fmt.Sprintf("/networks/%s/state", url.QueryEscape(name)), nil, "", &state) if err != nil { return nil, err } return &state, nil }
go
func (r *ProtocolLXD) GetNetworkState(name string) (*api.NetworkState, error) { if !r.HasExtension("network_state") { return nil, fmt.Errorf("The server is missing the required \"network_state\" API extension") } state := api.NetworkState{} // Fetch the raw value _, err := r.queryStruct("GET", fmt.Sprintf("/networks/%s/state", url.QueryEscape(name)), nil, "", &state) if err != nil { return nil, err } return &state, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetNetworkState", "(", "name", "string", ")", "(", "*", "api", ".", "NetworkState", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"network_state\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"network_state\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "state", ":=", "api", ".", "NetworkState", "{", "}", "\n", "_", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "fmt", ".", "Sprintf", "(", "\"/networks/%s/state\"", ",", "url", ".", "QueryEscape", "(", "name", ")", ")", ",", "nil", ",", "\"\"", ",", "&", "state", ")", "\n", "}" ]
// GetNetworkState returns metrics and information on the running network
[ "GetNetworkState", "returns", "metrics", "and", "information", "on", "the", "running", "network" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_networks.go#L87-L101
test
lxc/lxd
client/lxd_networks.go
CreateNetwork
func (r *ProtocolLXD) CreateNetwork(network api.NetworksPost) error { if !r.HasExtension("network") { return fmt.Errorf("The server is missing the required \"network\" API extension") } // Send the request _, _, err := r.query("POST", "/networks", network, "") if err != nil { return err } return nil }
go
func (r *ProtocolLXD) CreateNetwork(network api.NetworksPost) error { if !r.HasExtension("network") { return fmt.Errorf("The server is missing the required \"network\" API extension") } // Send the request _, _, err := r.query("POST", "/networks", network, "") if err != nil { return err } return nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "CreateNetwork", "(", "network", "api", ".", "NetworksPost", ")", "error", "{", "if", "!", "r", ".", "HasExtension", "(", "\"network\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"network\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "_", ",", "_", ",", "err", ":=", "r", ".", "query", "(", "\"POST\"", ",", "\"/networks\"", ",", "network", ",", "\"\"", ")", "\n", "}" ]
// CreateNetwork defines a new network using the provided Network struct
[ "CreateNetwork", "defines", "a", "new", "network", "using", "the", "provided", "Network", "struct" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_networks.go#L104-L116
test
lxc/lxd
client/lxd_networks.go
UpdateNetwork
func (r *ProtocolLXD) UpdateNetwork(name string, network api.NetworkPut, ETag string) error { if !r.HasExtension("network") { return fmt.Errorf("The server is missing the required \"network\" API extension") } // Send the request _, _, err := r.query("PUT", fmt.Sprintf("/networks/%s", url.QueryEscape(name)), network, ETag) if err != nil { return err } return nil }
go
func (r *ProtocolLXD) UpdateNetwork(name string, network api.NetworkPut, ETag string) error { if !r.HasExtension("network") { return fmt.Errorf("The server is missing the required \"network\" API extension") } // Send the request _, _, err := r.query("PUT", fmt.Sprintf("/networks/%s", url.QueryEscape(name)), network, ETag) if err != nil { return err } return nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "UpdateNetwork", "(", "name", "string", ",", "network", "api", ".", "NetworkPut", ",", "ETag", "string", ")", "error", "{", "if", "!", "r", ".", "HasExtension", "(", "\"network\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"network\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "_", ",", "_", ",", "err", ":=", "r", ".", "query", "(", "\"PUT\"", ",", "fmt", ".", "Sprintf", "(", "\"/networks/%s\"", ",", "url", ".", "QueryEscape", "(", "name", ")", ")", ",", "network", ",", "ETag", ")", "\n", "}" ]
// UpdateNetwork updates the network to match the provided Network struct
[ "UpdateNetwork", "updates", "the", "network", "to", "match", "the", "provided", "Network", "struct" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_networks.go#L119-L131
test
lxc/lxd
client/lxd_networks.go
RenameNetwork
func (r *ProtocolLXD) RenameNetwork(name string, network api.NetworkPost) error { if !r.HasExtension("network") { return fmt.Errorf("The server is missing the required \"network\" API extension") } // Send the request _, _, err := r.query("POST", fmt.Sprintf("/networks/%s", url.QueryEscape(name)), network, "") if err != nil { return err } return nil }
go
func (r *ProtocolLXD) RenameNetwork(name string, network api.NetworkPost) error { if !r.HasExtension("network") { return fmt.Errorf("The server is missing the required \"network\" API extension") } // Send the request _, _, err := r.query("POST", fmt.Sprintf("/networks/%s", url.QueryEscape(name)), network, "") if err != nil { return err } return nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "RenameNetwork", "(", "name", "string", ",", "network", "api", ".", "NetworkPost", ")", "error", "{", "if", "!", "r", ".", "HasExtension", "(", "\"network\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"network\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "_", ",", "_", ",", "err", ":=", "r", ".", "query", "(", "\"POST\"", ",", "fmt", ".", "Sprintf", "(", "\"/networks/%s\"", ",", "url", ".", "QueryEscape", "(", "name", ")", ")", ",", "network", ",", "\"\"", ")", "\n", "}" ]
// RenameNetwork renames an existing network entry
[ "RenameNetwork", "renames", "an", "existing", "network", "entry" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_networks.go#L134-L146
test
lxc/lxd
lxd/db/cluster/open.go
Open
func Open(name string, store dqlite.ServerStore, options ...dqlite.DriverOption) (*sql.DB, error) { driver, err := dqlite.NewDriver(store, options...) if err != nil { return nil, errors.Wrap(err, "Failed to create dqlite driver") } driverName := dqliteDriverName() sql.Register(driverName, driver) // Create the cluster db. This won't immediately establish any network // connection, that will happen only when a db transaction is started // (see the database/sql connection pooling code for more details). if name == "" { name = "db.bin" } db, err := sql.Open(driverName, name) if err != nil { return nil, fmt.Errorf("cannot open cluster database: %v", err) } return db, nil }
go
func Open(name string, store dqlite.ServerStore, options ...dqlite.DriverOption) (*sql.DB, error) { driver, err := dqlite.NewDriver(store, options...) if err != nil { return nil, errors.Wrap(err, "Failed to create dqlite driver") } driverName := dqliteDriverName() sql.Register(driverName, driver) // Create the cluster db. This won't immediately establish any network // connection, that will happen only when a db transaction is started // (see the database/sql connection pooling code for more details). if name == "" { name = "db.bin" } db, err := sql.Open(driverName, name) if err != nil { return nil, fmt.Errorf("cannot open cluster database: %v", err) } return db, nil }
[ "func", "Open", "(", "name", "string", ",", "store", "dqlite", ".", "ServerStore", ",", "options", "...", "dqlite", ".", "DriverOption", ")", "(", "*", "sql", ".", "DB", ",", "error", ")", "{", "driver", ",", "err", ":=", "dqlite", ".", "NewDriver", "(", "store", ",", "options", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"Failed to create dqlite driver\"", ")", "\n", "}", "\n", "driverName", ":=", "dqliteDriverName", "(", ")", "\n", "sql", ".", "Register", "(", "driverName", ",", "driver", ")", "\n", "if", "name", "==", "\"\"", "{", "name", "=", "\"db.bin\"", "\n", "}", "\n", "db", ",", "err", ":=", "sql", ".", "Open", "(", "driverName", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"cannot open cluster database: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "db", ",", "nil", "\n", "}" ]
// Open the cluster database object. // // The name argument is the name of the cluster database. It defaults to // 'db.bin', but can be overwritten for testing. // // The dialer argument is a function that returns a gRPC dialer that can be // used to connect to a database node using the gRPC SQL package.
[ "Open", "the", "cluster", "database", "object", ".", "The", "name", "argument", "is", "the", "name", "of", "the", "cluster", "database", ".", "It", "defaults", "to", "db", ".", "bin", "but", "can", "be", "overwritten", "for", "testing", ".", "The", "dialer", "argument", "is", "a", "function", "that", "returns", "a", "gRPC", "dialer", "that", "can", "be", "used", "to", "connect", "to", "a", "database", "node", "using", "the", "gRPC", "SQL", "package", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/cluster/open.go#L26-L47
test
lxc/lxd
shared/util.go
URLEncode
func URLEncode(path string, query map[string]string) (string, error) { u, err := url.Parse(path) if err != nil { return "", err } params := url.Values{} for key, value := range query { params.Add(key, value) } u.RawQuery = params.Encode() return u.String(), nil }
go
func URLEncode(path string, query map[string]string) (string, error) { u, err := url.Parse(path) if err != nil { return "", err } params := url.Values{} for key, value := range query { params.Add(key, value) } u.RawQuery = params.Encode() return u.String(), nil }
[ "func", "URLEncode", "(", "path", "string", ",", "query", "map", "[", "string", "]", "string", ")", "(", "string", ",", "error", ")", "{", "u", ",", "err", ":=", "url", ".", "Parse", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "params", ":=", "url", ".", "Values", "{", "}", "\n", "for", "key", ",", "value", ":=", "range", "query", "{", "params", ".", "Add", "(", "key", ",", "value", ")", "\n", "}", "\n", "u", ".", "RawQuery", "=", "params", ".", "Encode", "(", ")", "\n", "return", "u", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// URLEncode encodes a path and query parameters to a URL.
[ "URLEncode", "encodes", "a", "path", "and", "query", "parameters", "to", "a", "URL", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/util.go#L38-L50
test
lxc/lxd
shared/util.go
IsUnixSocket
func IsUnixSocket(path string) bool { stat, err := os.Stat(path) if err != nil { return false } return (stat.Mode() & os.ModeSocket) == os.ModeSocket }
go
func IsUnixSocket(path string) bool { stat, err := os.Stat(path) if err != nil { return false } return (stat.Mode() & os.ModeSocket) == os.ModeSocket }
[ "func", "IsUnixSocket", "(", "path", "string", ")", "bool", "{", "stat", ",", "err", ":=", "os", ".", "Stat", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", "\n", "}", "\n", "return", "(", "stat", ".", "Mode", "(", ")", "&", "os", ".", "ModeSocket", ")", "==", "os", ".", "ModeSocket", "\n", "}" ]
// IsUnixSocket returns true if the given path is either a Unix socket // or a symbolic link pointing at a Unix socket.
[ "IsUnixSocket", "returns", "true", "if", "the", "given", "path", "is", "either", "a", "Unix", "socket", "or", "a", "symbolic", "link", "pointing", "at", "a", "Unix", "socket", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/util.go#L100-L106
test
lxc/lxd
shared/util.go
HostPath
func HostPath(path string) string { // Ignore empty paths if len(path) == 0 { return path } // Don't prefix stdin/stdout if path == "-" { return path } // Check if we're running in a snap package snap := os.Getenv("SNAP") snapName := os.Getenv("SNAP_NAME") if snap == "" || snapName != "lxd" { return path } // Handle relative paths if path[0] != os.PathSeparator { // Use the cwd of the parent as snap-confine alters our own cwd on launch ppid := os.Getppid() if ppid < 1 { return path } pwd, err := os.Readlink(fmt.Sprintf("/proc/%d/cwd", ppid)) if err != nil { return path } path = filepath.Clean(strings.Join([]string{pwd, path}, string(os.PathSeparator))) } // Check if the path is already snap-aware for _, prefix := range []string{"/dev", "/snap", "/var/snap", "/var/lib/snapd"} { if path == prefix || strings.HasPrefix(path, fmt.Sprintf("%s/", prefix)) { return path } } return fmt.Sprintf("/var/lib/snapd/hostfs%s", path) }
go
func HostPath(path string) string { // Ignore empty paths if len(path) == 0 { return path } // Don't prefix stdin/stdout if path == "-" { return path } // Check if we're running in a snap package snap := os.Getenv("SNAP") snapName := os.Getenv("SNAP_NAME") if snap == "" || snapName != "lxd" { return path } // Handle relative paths if path[0] != os.PathSeparator { // Use the cwd of the parent as snap-confine alters our own cwd on launch ppid := os.Getppid() if ppid < 1 { return path } pwd, err := os.Readlink(fmt.Sprintf("/proc/%d/cwd", ppid)) if err != nil { return path } path = filepath.Clean(strings.Join([]string{pwd, path}, string(os.PathSeparator))) } // Check if the path is already snap-aware for _, prefix := range []string{"/dev", "/snap", "/var/snap", "/var/lib/snapd"} { if path == prefix || strings.HasPrefix(path, fmt.Sprintf("%s/", prefix)) { return path } } return fmt.Sprintf("/var/lib/snapd/hostfs%s", path) }
[ "func", "HostPath", "(", "path", "string", ")", "string", "{", "if", "len", "(", "path", ")", "==", "0", "{", "return", "path", "\n", "}", "\n", "if", "path", "==", "\"-\"", "{", "return", "path", "\n", "}", "\n", "snap", ":=", "os", ".", "Getenv", "(", "\"SNAP\"", ")", "\n", "snapName", ":=", "os", ".", "Getenv", "(", "\"SNAP_NAME\"", ")", "\n", "if", "snap", "==", "\"\"", "||", "snapName", "!=", "\"lxd\"", "{", "return", "path", "\n", "}", "\n", "if", "path", "[", "0", "]", "!=", "os", ".", "PathSeparator", "{", "ppid", ":=", "os", ".", "Getppid", "(", ")", "\n", "if", "ppid", "<", "1", "{", "return", "path", "\n", "}", "\n", "pwd", ",", "err", ":=", "os", ".", "Readlink", "(", "fmt", ".", "Sprintf", "(", "\"/proc/%d/cwd\"", ",", "ppid", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "path", "\n", "}", "\n", "path", "=", "filepath", ".", "Clean", "(", "strings", ".", "Join", "(", "[", "]", "string", "{", "pwd", ",", "path", "}", ",", "string", "(", "os", ".", "PathSeparator", ")", ")", ")", "\n", "}", "\n", "for", "_", ",", "prefix", ":=", "range", "[", "]", "string", "{", "\"/dev\"", ",", "\"/snap\"", ",", "\"/var/snap\"", ",", "\"/var/lib/snapd\"", "}", "{", "if", "path", "==", "prefix", "||", "strings", ".", "HasPrefix", "(", "path", ",", "fmt", ".", "Sprintf", "(", "\"%s/\"", ",", "prefix", ")", ")", "{", "return", "path", "\n", "}", "\n", "}", "\n", "return", "fmt", ".", "Sprintf", "(", "\"/var/lib/snapd/hostfs%s\"", ",", "path", ")", "\n", "}" ]
// HostPath returns the host path for the provided path // On a normal system, this does nothing // When inside of a snap environment, returns the real path
[ "HostPath", "returns", "the", "host", "path", "for", "the", "provided", "path", "On", "a", "normal", "system", "this", "does", "nothing", "When", "inside", "of", "a", "snap", "environment", "returns", "the", "real", "path" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/util.go#L111-L153
test
lxc/lxd
shared/util.go
FileMove
func FileMove(oldPath string, newPath string) error { err := os.Rename(oldPath, newPath) if err == nil { return nil } err = FileCopy(oldPath, newPath) if err != nil { return err } os.Remove(oldPath) return nil }
go
func FileMove(oldPath string, newPath string) error { err := os.Rename(oldPath, newPath) if err == nil { return nil } err = FileCopy(oldPath, newPath) if err != nil { return err } os.Remove(oldPath) return nil }
[ "func", "FileMove", "(", "oldPath", "string", ",", "newPath", "string", ")", "error", "{", "err", ":=", "os", ".", "Rename", "(", "oldPath", ",", "newPath", ")", "\n", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "err", "=", "FileCopy", "(", "oldPath", ",", "newPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "os", ".", "Remove", "(", "oldPath", ")", "\n", "return", "nil", "\n", "}" ]
// FileMove tries to move a file by using os.Rename, // if that fails it tries to copy the file and remove the source.
[ "FileMove", "tries", "to", "move", "a", "file", "by", "using", "os", ".", "Rename", "if", "that", "fails", "it", "tries", "to", "copy", "the", "file", "and", "remove", "the", "source", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/util.go#L332-L346
test
lxc/lxd
shared/util.go
DirCopy
func DirCopy(source string, dest string) error { // Get info about source. info, err := os.Stat(source) if err != nil { return errors.Wrapf(err, "failed to get source directory info") } if !info.IsDir() { return fmt.Errorf("source is not a directory") } // Remove dest if it already exists. if PathExists(dest) { err := os.RemoveAll(dest) if err != nil { return errors.Wrapf(err, "failed to remove destination directory %s", dest) } } // Create dest. err = os.MkdirAll(dest, info.Mode()) if err != nil { return errors.Wrapf(err, "failed to create destination directory %s", dest) } // Copy all files. entries, err := ioutil.ReadDir(source) if err != nil { return errors.Wrapf(err, "failed to read source directory %s", source) } for _, entry := range entries { sourcePath := filepath.Join(source, entry.Name()) destPath := filepath.Join(dest, entry.Name()) if entry.IsDir() { err := DirCopy(sourcePath, destPath) if err != nil { return errors.Wrapf(err, "failed to copy sub-directory from %s to %s", sourcePath, destPath) } } else { err := FileCopy(sourcePath, destPath) if err != nil { return errors.Wrapf(err, "failed to copy file from %s to %s", sourcePath, destPath) } } } return nil }
go
func DirCopy(source string, dest string) error { // Get info about source. info, err := os.Stat(source) if err != nil { return errors.Wrapf(err, "failed to get source directory info") } if !info.IsDir() { return fmt.Errorf("source is not a directory") } // Remove dest if it already exists. if PathExists(dest) { err := os.RemoveAll(dest) if err != nil { return errors.Wrapf(err, "failed to remove destination directory %s", dest) } } // Create dest. err = os.MkdirAll(dest, info.Mode()) if err != nil { return errors.Wrapf(err, "failed to create destination directory %s", dest) } // Copy all files. entries, err := ioutil.ReadDir(source) if err != nil { return errors.Wrapf(err, "failed to read source directory %s", source) } for _, entry := range entries { sourcePath := filepath.Join(source, entry.Name()) destPath := filepath.Join(dest, entry.Name()) if entry.IsDir() { err := DirCopy(sourcePath, destPath) if err != nil { return errors.Wrapf(err, "failed to copy sub-directory from %s to %s", sourcePath, destPath) } } else { err := FileCopy(sourcePath, destPath) if err != nil { return errors.Wrapf(err, "failed to copy file from %s to %s", sourcePath, destPath) } } } return nil }
[ "func", "DirCopy", "(", "source", "string", ",", "dest", "string", ")", "error", "{", "info", ",", "err", ":=", "os", ".", "Stat", "(", "source", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to get source directory info\"", ")", "\n", "}", "\n", "if", "!", "info", ".", "IsDir", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"source is not a directory\"", ")", "\n", "}", "\n", "if", "PathExists", "(", "dest", ")", "{", "err", ":=", "os", ".", "RemoveAll", "(", "dest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to remove destination directory %s\"", ",", "dest", ")", "\n", "}", "\n", "}", "\n", "err", "=", "os", ".", "MkdirAll", "(", "dest", ",", "info", ".", "Mode", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to create destination directory %s\"", ",", "dest", ")", "\n", "}", "\n", "entries", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "source", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to read source directory %s\"", ",", "source", ")", "\n", "}", "\n", "for", "_", ",", "entry", ":=", "range", "entries", "{", "sourcePath", ":=", "filepath", ".", "Join", "(", "source", ",", "entry", ".", "Name", "(", ")", ")", "\n", "destPath", ":=", "filepath", ".", "Join", "(", "dest", ",", "entry", ".", "Name", "(", ")", ")", "\n", "if", "entry", ".", "IsDir", "(", ")", "{", "err", ":=", "DirCopy", "(", "sourcePath", ",", "destPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to copy sub-directory from %s to %s\"", ",", "sourcePath", ",", "destPath", ")", "\n", "}", "\n", "}", "else", "{", "err", ":=", "FileCopy", "(", "sourcePath", ",", "destPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to copy file from %s to %s\"", ",", "sourcePath", ",", "destPath", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DirCopy copies a directory recursively, overwriting the target if it exists.
[ "DirCopy", "copies", "a", "directory", "recursively", "overwriting", "the", "target", "if", "it", "exists", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/util.go#L389-L440
test
lxc/lxd
shared/util.go
StringMapHasStringKey
func StringMapHasStringKey(m map[string]string, keys ...string) bool { for _, k := range keys { if _, ok := m[k]; ok { return true } } return false }
go
func StringMapHasStringKey(m map[string]string, keys ...string) bool { for _, k := range keys { if _, ok := m[k]; ok { return true } } return false }
[ "func", "StringMapHasStringKey", "(", "m", "map", "[", "string", "]", "string", ",", "keys", "...", "string", ")", "bool", "{", "for", "_", ",", "k", ":=", "range", "keys", "{", "if", "_", ",", "ok", ":=", "m", "[", "k", "]", ";", "ok", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// StringMapHasStringKey returns true if any of the supplied keys are present in the map.
[ "StringMapHasStringKey", "returns", "true", "if", "any", "of", "the", "supplied", "keys", "are", "present", "in", "the", "map", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/util.go#L551-L559
test
lxc/lxd
shared/util.go
TextEditor
func TextEditor(inPath string, inContent []byte) ([]byte, error) { var f *os.File var err error var path string // Detect the text editor to use editor := os.Getenv("VISUAL") if editor == "" { editor = os.Getenv("EDITOR") if editor == "" { for _, p := range []string{"editor", "vi", "emacs", "nano"} { _, err := exec.LookPath(p) if err == nil { editor = p break } } if editor == "" { return []byte{}, fmt.Errorf("No text editor found, please set the EDITOR environment variable") } } } if inPath == "" { // If provided input, create a new file f, err = ioutil.TempFile("", "lxd_editor_") if err != nil { return []byte{}, err } err = os.Chmod(f.Name(), 0600) if err != nil { f.Close() os.Remove(f.Name()) return []byte{}, err } f.Write(inContent) f.Close() path = fmt.Sprintf("%s.yaml", f.Name()) os.Rename(f.Name(), path) defer os.Remove(path) } else { path = inPath } cmdParts := strings.Fields(editor) cmd := exec.Command(cmdParts[0], append(cmdParts[1:], path)...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err = cmd.Run() if err != nil { return []byte{}, err } content, err := ioutil.ReadFile(path) if err != nil { return []byte{}, err } return content, nil }
go
func TextEditor(inPath string, inContent []byte) ([]byte, error) { var f *os.File var err error var path string // Detect the text editor to use editor := os.Getenv("VISUAL") if editor == "" { editor = os.Getenv("EDITOR") if editor == "" { for _, p := range []string{"editor", "vi", "emacs", "nano"} { _, err := exec.LookPath(p) if err == nil { editor = p break } } if editor == "" { return []byte{}, fmt.Errorf("No text editor found, please set the EDITOR environment variable") } } } if inPath == "" { // If provided input, create a new file f, err = ioutil.TempFile("", "lxd_editor_") if err != nil { return []byte{}, err } err = os.Chmod(f.Name(), 0600) if err != nil { f.Close() os.Remove(f.Name()) return []byte{}, err } f.Write(inContent) f.Close() path = fmt.Sprintf("%s.yaml", f.Name()) os.Rename(f.Name(), path) defer os.Remove(path) } else { path = inPath } cmdParts := strings.Fields(editor) cmd := exec.Command(cmdParts[0], append(cmdParts[1:], path)...) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr err = cmd.Run() if err != nil { return []byte{}, err } content, err := ioutil.ReadFile(path) if err != nil { return []byte{}, err } return content, nil }
[ "func", "TextEditor", "(", "inPath", "string", ",", "inContent", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "f", "*", "os", ".", "File", "\n", "var", "err", "error", "\n", "var", "path", "string", "\n", "editor", ":=", "os", ".", "Getenv", "(", "\"VISUAL\"", ")", "\n", "if", "editor", "==", "\"\"", "{", "editor", "=", "os", ".", "Getenv", "(", "\"EDITOR\"", ")", "\n", "if", "editor", "==", "\"\"", "{", "for", "_", ",", "p", ":=", "range", "[", "]", "string", "{", "\"editor\"", ",", "\"vi\"", ",", "\"emacs\"", ",", "\"nano\"", "}", "{", "_", ",", "err", ":=", "exec", ".", "LookPath", "(", "p", ")", "\n", "if", "err", "==", "nil", "{", "editor", "=", "p", "\n", "break", "\n", "}", "\n", "}", "\n", "if", "editor", "==", "\"\"", "{", "return", "[", "]", "byte", "{", "}", ",", "fmt", ".", "Errorf", "(", "\"No text editor found, please set the EDITOR environment variable\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "inPath", "==", "\"\"", "{", "f", ",", "err", "=", "ioutil", ".", "TempFile", "(", "\"\"", ",", "\"lxd_editor_\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n", "err", "=", "os", ".", "Chmod", "(", "f", ".", "Name", "(", ")", ",", "0600", ")", "\n", "if", "err", "!=", "nil", "{", "f", ".", "Close", "(", ")", "\n", "os", ".", "Remove", "(", "f", ".", "Name", "(", ")", ")", "\n", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n", "f", ".", "Write", "(", "inContent", ")", "\n", "f", ".", "Close", "(", ")", "\n", "path", "=", "fmt", ".", "Sprintf", "(", "\"%s.yaml\"", ",", "f", ".", "Name", "(", ")", ")", "\n", "os", ".", "Rename", "(", "f", ".", "Name", "(", ")", ",", "path", ")", "\n", "defer", "os", ".", "Remove", "(", "path", ")", "\n", "}", "else", "{", "path", "=", "inPath", "\n", "}", "\n", "cmdParts", ":=", "strings", ".", "Fields", "(", "editor", ")", "\n", "cmd", ":=", "exec", ".", "Command", "(", "cmdParts", "[", "0", "]", ",", "append", "(", "cmdParts", "[", "1", ":", "]", ",", "path", ")", "...", ")", "\n", "cmd", ".", "Stdin", "=", "os", ".", "Stdin", "\n", "cmd", ".", "Stdout", "=", "os", ".", "Stdout", "\n", "cmd", ".", "Stderr", "=", "os", ".", "Stderr", "\n", "err", "=", "cmd", ".", "Run", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n", "content", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "byte", "{", "}", ",", "err", "\n", "}", "\n", "return", "content", ",", "nil", "\n", "}" ]
// Spawn the editor with a temporary YAML file for editing configs
[ "Spawn", "the", "editor", "with", "a", "temporary", "YAML", "file", "for", "editing", "configs" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/util.go#L666-L729
test
lxc/lxd
shared/util.go
WriteTempFile
func WriteTempFile(dir string, prefix string, content string) (string, error) { f, err := ioutil.TempFile(dir, prefix) if err != nil { return "", err } defer f.Close() _, err = f.WriteString(content) return f.Name(), err }
go
func WriteTempFile(dir string, prefix string, content string) (string, error) { f, err := ioutil.TempFile(dir, prefix) if err != nil { return "", err } defer f.Close() _, err = f.WriteString(content) return f.Name(), err }
[ "func", "WriteTempFile", "(", "dir", "string", ",", "prefix", "string", ",", "content", "string", ")", "(", "string", ",", "error", ")", "{", "f", ",", "err", ":=", "ioutil", ".", "TempFile", "(", "dir", ",", "prefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n", "_", ",", "err", "=", "f", ".", "WriteString", "(", "content", ")", "\n", "return", "f", ".", "Name", "(", ")", ",", "err", "\n", "}" ]
// WriteTempFile creates a temp file with the specified content
[ "WriteTempFile", "creates", "a", "temp", "file", "with", "the", "specified", "content" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/util.go#L999-L1008
test
lxc/lxd
shared/util.go
RenderTemplate
func RenderTemplate(template string, ctx pongo2.Context) (string, error) { // Load template from string tpl, err := pongo2.FromString("{% autoescape off %}" + template + "{% endautoescape %}") if err != nil { return "", err } // Get rendered template ret, err := tpl.Execute(ctx) if err != nil { return ret, err } // Looks like we're nesting templates so run pongo again if strings.Contains(ret, "{{") || strings.Contains(ret, "{%") { return RenderTemplate(ret, ctx) } return ret, err }
go
func RenderTemplate(template string, ctx pongo2.Context) (string, error) { // Load template from string tpl, err := pongo2.FromString("{% autoescape off %}" + template + "{% endautoescape %}") if err != nil { return "", err } // Get rendered template ret, err := tpl.Execute(ctx) if err != nil { return ret, err } // Looks like we're nesting templates so run pongo again if strings.Contains(ret, "{{") || strings.Contains(ret, "{%") { return RenderTemplate(ret, ctx) } return ret, err }
[ "func", "RenderTemplate", "(", "template", "string", ",", "ctx", "pongo2", ".", "Context", ")", "(", "string", ",", "error", ")", "{", "tpl", ",", "err", ":=", "pongo2", ".", "FromString", "(", "\"{% autoescape off %}\"", "+", "template", "+", "\"{% endautoescape %}\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "ret", ",", "err", ":=", "tpl", ".", "Execute", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "ret", ",", "err", "\n", "}", "\n", "if", "strings", ".", "Contains", "(", "ret", ",", "\"{{\"", ")", "||", "strings", ".", "Contains", "(", "ret", ",", "\"{%\"", ")", "{", "return", "RenderTemplate", "(", "ret", ",", "ctx", ")", "\n", "}", "\n", "return", "ret", ",", "err", "\n", "}" ]
// RenderTemplate renders a pongo2 template.
[ "RenderTemplate", "renders", "a", "pongo2", "template", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/util.go#L1153-L1172
test
lxc/lxd
lxd/task/schedule.go
Every
func Every(interval time.Duration, options ...EveryOption) Schedule { every := &every{} for _, option := range options { option(every) } first := true return func() (time.Duration, error) { var err error if first && every.skipFirst { err = ErrSkip } first = false return interval, err } }
go
func Every(interval time.Duration, options ...EveryOption) Schedule { every := &every{} for _, option := range options { option(every) } first := true return func() (time.Duration, error) { var err error if first && every.skipFirst { err = ErrSkip } first = false return interval, err } }
[ "func", "Every", "(", "interval", "time", ".", "Duration", ",", "options", "...", "EveryOption", ")", "Schedule", "{", "every", ":=", "&", "every", "{", "}", "\n", "for", "_", ",", "option", ":=", "range", "options", "{", "option", "(", "every", ")", "\n", "}", "\n", "first", ":=", "true", "\n", "return", "func", "(", ")", "(", "time", ".", "Duration", ",", "error", ")", "{", "var", "err", "error", "\n", "if", "first", "&&", "every", ".", "skipFirst", "{", "err", "=", "ErrSkip", "\n", "}", "\n", "first", "=", "false", "\n", "return", "interval", ",", "err", "\n", "}", "\n", "}" ]
// Every returns a Schedule that always returns the given time interval.
[ "Every", "returns", "a", "Schedule", "that", "always", "returns", "the", "given", "time", "interval", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/task/schedule.go#L33-L47
test
lxc/lxd
lxd/storage_lvm.go
StoragePoolMount
func (s *storageLvm) StoragePoolMount() (bool, error) { source := s.pool.Config["source"] if source == "" { return false, fmt.Errorf("no \"source\" property found for the storage pool") } if !filepath.IsAbs(source) { return true, nil } poolMountLockID := getPoolMountLockID(s.pool.Name) lxdStorageMapLock.Lock() if waitChannel, ok := lxdStorageOngoingOperationMap[poolMountLockID]; ok { lxdStorageMapLock.Unlock() if _, ok := <-waitChannel; ok { logger.Warnf("Received value over semaphore, this should not have happened") } // Give the benefit of the doubt and assume that the other // thread actually succeeded in mounting the storage pool. return false, nil } lxdStorageOngoingOperationMap[poolMountLockID] = make(chan bool) lxdStorageMapLock.Unlock() removeLockFromMap := func() { lxdStorageMapLock.Lock() if waitChannel, ok := lxdStorageOngoingOperationMap[poolMountLockID]; ok { close(waitChannel) delete(lxdStorageOngoingOperationMap, poolMountLockID) } lxdStorageMapLock.Unlock() } defer removeLockFromMap() if filepath.IsAbs(source) && !shared.IsBlockdevPath(source) { // Try to prepare new loop device. loopF, loopErr := prepareLoopDev(source, 0) if loopErr != nil { return false, loopErr } // Make sure that LO_FLAGS_AUTOCLEAR is unset. loopErr = unsetAutoclearOnLoopDev(int(loopF.Fd())) if loopErr != nil { return false, loopErr } s.loopInfo = loopF } return true, nil }
go
func (s *storageLvm) StoragePoolMount() (bool, error) { source := s.pool.Config["source"] if source == "" { return false, fmt.Errorf("no \"source\" property found for the storage pool") } if !filepath.IsAbs(source) { return true, nil } poolMountLockID := getPoolMountLockID(s.pool.Name) lxdStorageMapLock.Lock() if waitChannel, ok := lxdStorageOngoingOperationMap[poolMountLockID]; ok { lxdStorageMapLock.Unlock() if _, ok := <-waitChannel; ok { logger.Warnf("Received value over semaphore, this should not have happened") } // Give the benefit of the doubt and assume that the other // thread actually succeeded in mounting the storage pool. return false, nil } lxdStorageOngoingOperationMap[poolMountLockID] = make(chan bool) lxdStorageMapLock.Unlock() removeLockFromMap := func() { lxdStorageMapLock.Lock() if waitChannel, ok := lxdStorageOngoingOperationMap[poolMountLockID]; ok { close(waitChannel) delete(lxdStorageOngoingOperationMap, poolMountLockID) } lxdStorageMapLock.Unlock() } defer removeLockFromMap() if filepath.IsAbs(source) && !shared.IsBlockdevPath(source) { // Try to prepare new loop device. loopF, loopErr := prepareLoopDev(source, 0) if loopErr != nil { return false, loopErr } // Make sure that LO_FLAGS_AUTOCLEAR is unset. loopErr = unsetAutoclearOnLoopDev(int(loopF.Fd())) if loopErr != nil { return false, loopErr } s.loopInfo = loopF } return true, nil }
[ "func", "(", "s", "*", "storageLvm", ")", "StoragePoolMount", "(", ")", "(", "bool", ",", "error", ")", "{", "source", ":=", "s", ".", "pool", ".", "Config", "[", "\"source\"", "]", "\n", "if", "source", "==", "\"\"", "{", "return", "false", ",", "fmt", ".", "Errorf", "(", "\"no \\\"source\\\" property found for the storage pool\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "if", "!", "filepath", ".", "IsAbs", "(", "source", ")", "{", "return", "true", ",", "nil", "\n", "}", "\n", "poolMountLockID", ":=", "getPoolMountLockID", "(", "s", ".", "pool", ".", "Name", ")", "\n", "lxdStorageMapLock", ".", "Lock", "(", ")", "\n", "if", "waitChannel", ",", "ok", ":=", "lxdStorageOngoingOperationMap", "[", "poolMountLockID", "]", ";", "ok", "{", "lxdStorageMapLock", ".", "Unlock", "(", ")", "\n", "if", "_", ",", "ok", ":=", "<-", "waitChannel", ";", "ok", "{", "logger", ".", "Warnf", "(", "\"Received value over semaphore, this should not have happened\"", ")", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}", "\n", "lxdStorageOngoingOperationMap", "[", "poolMountLockID", "]", "=", "make", "(", "chan", "bool", ")", "\n", "lxdStorageMapLock", ".", "Unlock", "(", ")", "\n", "removeLockFromMap", ":=", "func", "(", ")", "{", "lxdStorageMapLock", ".", "Lock", "(", ")", "\n", "if", "waitChannel", ",", "ok", ":=", "lxdStorageOngoingOperationMap", "[", "poolMountLockID", "]", ";", "ok", "{", "close", "(", "waitChannel", ")", "\n", "delete", "(", "lxdStorageOngoingOperationMap", ",", "poolMountLockID", ")", "\n", "}", "\n", "lxdStorageMapLock", ".", "Unlock", "(", ")", "\n", "}", "\n", "defer", "removeLockFromMap", "(", ")", "\n", "}" ]
// Currently only used for loop-backed LVM storage pools. Can be called without // overhead since it is essentially a noop for non-loop-backed LVM storage // pools.
[ "Currently", "only", "used", "for", "loop", "-", "backed", "LVM", "storage", "pools", ".", "Can", "be", "called", "without", "overhead", "since", "it", "is", "essentially", "a", "noop", "for", "non", "-", "loop", "-", "backed", "LVM", "storage", "pools", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/storage_lvm.go#L423-L474
test
lxc/lxd
lxd/db/query/dump.go
Dump
func Dump(tx *sql.Tx, schema string, schemaOnly bool) (string, error) { schemas := dumpParseSchema(schema) // Begin dump := `PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; ` // Schema table tableDump, err := dumpTable(tx, "schema", dumpSchemaTable) if err != nil { return "", errors.Wrapf(err, "failed to dump table schema") } dump += tableDump // All other tables tables := make([]string, 0) for table := range schemas { tables = append(tables, table) } sort.Strings(tables) for _, table := range tables { if schemaOnly { // Dump only the schema. dump += schemas[table] + "\n" continue } tableDump, err := dumpTable(tx, table, schemas[table]) if err != nil { return "", errors.Wrapf(err, "failed to dump table %s", table) } dump += tableDump } // Sequences (unless the schemaOnly flag is true) if !schemaOnly { tableDump, err = dumpTable(tx, "sqlite_sequence", "DELETE FROM sqlite_sequence;") if err != nil { return "", errors.Wrapf(err, "failed to dump table sqlite_sequence") } dump += tableDump } // Commit dump += "COMMIT;\n" return dump, nil }
go
func Dump(tx *sql.Tx, schema string, schemaOnly bool) (string, error) { schemas := dumpParseSchema(schema) // Begin dump := `PRAGMA foreign_keys=OFF; BEGIN TRANSACTION; ` // Schema table tableDump, err := dumpTable(tx, "schema", dumpSchemaTable) if err != nil { return "", errors.Wrapf(err, "failed to dump table schema") } dump += tableDump // All other tables tables := make([]string, 0) for table := range schemas { tables = append(tables, table) } sort.Strings(tables) for _, table := range tables { if schemaOnly { // Dump only the schema. dump += schemas[table] + "\n" continue } tableDump, err := dumpTable(tx, table, schemas[table]) if err != nil { return "", errors.Wrapf(err, "failed to dump table %s", table) } dump += tableDump } // Sequences (unless the schemaOnly flag is true) if !schemaOnly { tableDump, err = dumpTable(tx, "sqlite_sequence", "DELETE FROM sqlite_sequence;") if err != nil { return "", errors.Wrapf(err, "failed to dump table sqlite_sequence") } dump += tableDump } // Commit dump += "COMMIT;\n" return dump, nil }
[ "func", "Dump", "(", "tx", "*", "sql", ".", "Tx", ",", "schema", "string", ",", "schemaOnly", "bool", ")", "(", "string", ",", "error", ")", "{", "schemas", ":=", "dumpParseSchema", "(", "schema", ")", "\n", "dump", ":=", "`PRAGMA foreign_keys=OFF;BEGIN TRANSACTION;`", "\n", "tableDump", ",", "err", ":=", "dumpTable", "(", "tx", ",", "\"schema\"", ",", "dumpSchemaTable", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to dump table schema\"", ")", "\n", "}", "\n", "dump", "+=", "tableDump", "\n", "tables", ":=", "make", "(", "[", "]", "string", ",", "0", ")", "\n", "for", "table", ":=", "range", "schemas", "{", "tables", "=", "append", "(", "tables", ",", "table", ")", "\n", "}", "\n", "sort", ".", "Strings", "(", "tables", ")", "\n", "for", "_", ",", "table", ":=", "range", "tables", "{", "if", "schemaOnly", "{", "dump", "+=", "schemas", "[", "table", "]", "+", "\"\\n\"", "\n", "\\n", "\n", "}", "\n", "continue", "\n", "tableDump", ",", "err", ":=", "dumpTable", "(", "tx", ",", "table", ",", "schemas", "[", "table", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to dump table %s\"", ",", "table", ")", "\n", "}", "\n", "}", "\n", "dump", "+=", "tableDump", "\n", "if", "!", "schemaOnly", "{", "tableDump", ",", "err", "=", "dumpTable", "(", "tx", ",", "\"sqlite_sequence\"", ",", "\"DELETE FROM sqlite_sequence;\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to dump table sqlite_sequence\"", ")", "\n", "}", "\n", "dump", "+=", "tableDump", "\n", "}", "\n", "dump", "+=", "\"COMMIT;\\n\"", "\n", "}" ]
// Dump returns a SQL text dump of all rows across all tables, similar to // sqlite3's dump feature
[ "Dump", "returns", "a", "SQL", "text", "dump", "of", "all", "rows", "across", "all", "tables", "similar", "to", "sqlite3", "s", "dump", "feature" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/query/dump.go#L16-L62
test
lxc/lxd
lxd/db/query/dump.go
dumpTable
func dumpTable(tx *sql.Tx, table, schema string) (string, error) { statements := []string{schema} // Query all rows. rows, err := tx.Query(fmt.Sprintf("SELECT * FROM %s ORDER BY rowid", table)) if err != nil { return "", errors.Wrap(err, "failed to fetch rows") } defer rows.Close() // Figure column names columns, err := rows.Columns() if err != nil { return "", errors.Wrap(err, "failed to get columns") } // Generate an INSERT statement for each row. for i := 0; rows.Next(); i++ { raw := make([]interface{}, len(columns)) // Raw column values row := make([]interface{}, len(columns)) for i := range raw { row[i] = &raw[i] } err := rows.Scan(row...) if err != nil { return "", errors.Wrapf(err, "failed to scan row %d", i) } values := make([]string, len(columns)) for j, v := range raw { switch v := v.(type) { case int64: values[j] = strconv.FormatInt(v, 10) case string: values[j] = fmt.Sprintf("'%s'", v) case []byte: values[j] = fmt.Sprintf("'%s'", string(v)) case time.Time: values[j] = strconv.FormatInt(v.Unix(), 10) default: if v != nil { return "", fmt.Errorf("bad type in column %s of row %d", columns[j], i) } values[j] = "NULL" } } statement := fmt.Sprintf("INSERT INTO %s VALUES(%s);", table, strings.Join(values, ",")) statements = append(statements, statement) } return strings.Join(statements, "\n") + "\n", nil }
go
func dumpTable(tx *sql.Tx, table, schema string) (string, error) { statements := []string{schema} // Query all rows. rows, err := tx.Query(fmt.Sprintf("SELECT * FROM %s ORDER BY rowid", table)) if err != nil { return "", errors.Wrap(err, "failed to fetch rows") } defer rows.Close() // Figure column names columns, err := rows.Columns() if err != nil { return "", errors.Wrap(err, "failed to get columns") } // Generate an INSERT statement for each row. for i := 0; rows.Next(); i++ { raw := make([]interface{}, len(columns)) // Raw column values row := make([]interface{}, len(columns)) for i := range raw { row[i] = &raw[i] } err := rows.Scan(row...) if err != nil { return "", errors.Wrapf(err, "failed to scan row %d", i) } values := make([]string, len(columns)) for j, v := range raw { switch v := v.(type) { case int64: values[j] = strconv.FormatInt(v, 10) case string: values[j] = fmt.Sprintf("'%s'", v) case []byte: values[j] = fmt.Sprintf("'%s'", string(v)) case time.Time: values[j] = strconv.FormatInt(v.Unix(), 10) default: if v != nil { return "", fmt.Errorf("bad type in column %s of row %d", columns[j], i) } values[j] = "NULL" } } statement := fmt.Sprintf("INSERT INTO %s VALUES(%s);", table, strings.Join(values, ",")) statements = append(statements, statement) } return strings.Join(statements, "\n") + "\n", nil }
[ "func", "dumpTable", "(", "tx", "*", "sql", ".", "Tx", ",", "table", ",", "schema", "string", ")", "(", "string", ",", "error", ")", "{", "statements", ":=", "[", "]", "string", "{", "schema", "}", "\n", "rows", ",", "err", ":=", "tx", ".", "Query", "(", "fmt", ".", "Sprintf", "(", "\"SELECT * FROM %s ORDER BY rowid\"", ",", "table", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "errors", ".", "Wrap", "(", "err", ",", "\"failed to fetch rows\"", ")", "\n", "}", "\n", "defer", "rows", ".", "Close", "(", ")", "\n", "columns", ",", "err", ":=", "rows", ".", "Columns", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "errors", ".", "Wrap", "(", "err", ",", "\"failed to get columns\"", ")", "\n", "}", "\n", "for", "i", ":=", "0", ";", "rows", ".", "Next", "(", ")", ";", "i", "++", "{", "raw", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "columns", ")", ")", "\n", "row", ":=", "make", "(", "[", "]", "interface", "{", "}", ",", "len", "(", "columns", ")", ")", "\n", "for", "i", ":=", "range", "raw", "{", "row", "[", "i", "]", "=", "&", "raw", "[", "i", "]", "\n", "}", "\n", "err", ":=", "rows", ".", "Scan", "(", "row", "...", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"failed to scan row %d\"", ",", "i", ")", "\n", "}", "\n", "values", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "columns", ")", ")", "\n", "for", "j", ",", "v", ":=", "range", "raw", "{", "switch", "v", ":=", "v", ".", "(", "type", ")", "{", "case", "int64", ":", "values", "[", "j", "]", "=", "strconv", ".", "FormatInt", "(", "v", ",", "10", ")", "\n", "case", "string", ":", "values", "[", "j", "]", "=", "fmt", ".", "Sprintf", "(", "\"'%s'\"", ",", "v", ")", "\n", "case", "[", "]", "byte", ":", "values", "[", "j", "]", "=", "fmt", ".", "Sprintf", "(", "\"'%s'\"", ",", "string", "(", "v", ")", ")", "\n", "case", "time", ".", "Time", ":", "values", "[", "j", "]", "=", "strconv", ".", "FormatInt", "(", "v", ".", "Unix", "(", ")", ",", "10", ")", "\n", "default", ":", "if", "v", "!=", "nil", "{", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"bad type in column %s of row %d\"", ",", "columns", "[", "j", "]", ",", "i", ")", "\n", "}", "\n", "values", "[", "j", "]", "=", "\"NULL\"", "\n", "}", "\n", "}", "\n", "statement", ":=", "fmt", ".", "Sprintf", "(", "\"INSERT INTO %s VALUES(%s);\"", ",", "table", ",", "strings", ".", "Join", "(", "values", ",", "\",\"", ")", ")", "\n", "statements", "=", "append", "(", "statements", ",", "statement", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "statements", ",", "\"\\n\"", ")", "+", "\\n", ",", "nil", "\n", "}" ]
// Dump a single table, returning a SQL text containing statements for its // schema and data.
[ "Dump", "a", "single", "table", "returning", "a", "SQL", "text", "containing", "statements", "for", "its", "schema", "and", "data", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/query/dump.go#L81-L130
test
lxc/lxd
lxd/db/projects.go
ProjectHasProfiles
func (c *ClusterTx) ProjectHasProfiles(name string) (bool, error) { return projectHasProfiles(c.tx, name) }
go
func (c *ClusterTx) ProjectHasProfiles(name string) (bool, error) { return projectHasProfiles(c.tx, name) }
[ "func", "(", "c", "*", "ClusterTx", ")", "ProjectHasProfiles", "(", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "return", "projectHasProfiles", "(", "c", ".", "tx", ",", "name", ")", "\n", "}" ]
// ProjectHasProfiles is a helper to check if a project has the profiles // feature enabled.
[ "ProjectHasProfiles", "is", "a", "helper", "to", "check", "if", "a", "project", "has", "the", "profiles", "feature", "enabled", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.go#L50-L52
test
lxc/lxd
lxd/db/projects.go
ProjectNames
func (c *ClusterTx) ProjectNames() ([]string, error) { stmt := "SELECT name FROM projects" names, err := query.SelectStrings(c.tx, stmt) if err != nil { return nil, errors.Wrap(err, "Fetch project names") } return names, nil }
go
func (c *ClusterTx) ProjectNames() ([]string, error) { stmt := "SELECT name FROM projects" names, err := query.SelectStrings(c.tx, stmt) if err != nil { return nil, errors.Wrap(err, "Fetch project names") } return names, nil }
[ "func", "(", "c", "*", "ClusterTx", ")", "ProjectNames", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "stmt", ":=", "\"SELECT name FROM projects\"", "\n", "names", ",", "err", ":=", "query", ".", "SelectStrings", "(", "c", ".", "tx", ",", "stmt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"Fetch project names\"", ")", "\n", "}", "\n", "return", "names", ",", "nil", "\n", "}" ]
// ProjectNames returns the names of all available projects.
[ "ProjectNames", "returns", "the", "names", "of", "all", "available", "projects", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.go#L55-L64
test
lxc/lxd
lxd/db/projects.go
ProjectMap
func (c *ClusterTx) ProjectMap() (map[int64]string, error) { stmt := "SELECT id, name FROM projects" rows, err := c.tx.Query(stmt) if err != nil { return nil, err } defer rows.Close() result := map[int64]string{} for i := 0; rows.Next(); i++ { var id int64 var name string err := rows.Scan(&id, &name) if err != nil { return nil, err } result[id] = name } err = rows.Err() if err != nil { return nil, err } return result, nil }
go
func (c *ClusterTx) ProjectMap() (map[int64]string, error) { stmt := "SELECT id, name FROM projects" rows, err := c.tx.Query(stmt) if err != nil { return nil, err } defer rows.Close() result := map[int64]string{} for i := 0; rows.Next(); i++ { var id int64 var name string err := rows.Scan(&id, &name) if err != nil { return nil, err } result[id] = name } err = rows.Err() if err != nil { return nil, err } return result, nil }
[ "func", "(", "c", "*", "ClusterTx", ")", "ProjectMap", "(", ")", "(", "map", "[", "int64", "]", "string", ",", "error", ")", "{", "stmt", ":=", "\"SELECT id, name FROM projects\"", "\n", "rows", ",", "err", ":=", "c", ".", "tx", ".", "Query", "(", "stmt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "rows", ".", "Close", "(", ")", "\n", "result", ":=", "map", "[", "int64", "]", "string", "{", "}", "\n", "for", "i", ":=", "0", ";", "rows", ".", "Next", "(", ")", ";", "i", "++", "{", "var", "id", "int64", "\n", "var", "name", "string", "\n", "err", ":=", "rows", ".", "Scan", "(", "&", "id", ",", "&", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "result", "[", "id", "]", "=", "name", "\n", "}", "\n", "err", "=", "rows", ".", "Err", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// ProjectMap returns the names and ids of all available projects.
[ "ProjectMap", "returns", "the", "names", "and", "ids", "of", "all", "available", "projects", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.go#L67-L95
test
lxc/lxd
lxd/db/projects.go
ProjectHasImages
func (c *ClusterTx) ProjectHasImages(name string) (bool, error) { project, err := c.ProjectGet(name) if err != nil { return false, errors.Wrap(err, "fetch project") } enabled := project.Config["features.images"] == "true" return enabled, nil }
go
func (c *ClusterTx) ProjectHasImages(name string) (bool, error) { project, err := c.ProjectGet(name) if err != nil { return false, errors.Wrap(err, "fetch project") } enabled := project.Config["features.images"] == "true" return enabled, nil }
[ "func", "(", "c", "*", "ClusterTx", ")", "ProjectHasImages", "(", "name", "string", ")", "(", "bool", ",", "error", ")", "{", "project", ",", "err", ":=", "c", ".", "ProjectGet", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrap", "(", "err", ",", "\"fetch project\"", ")", "\n", "}", "\n", "enabled", ":=", "project", ".", "Config", "[", "\"features.images\"", "]", "==", "\"true\"", "\n", "return", "enabled", ",", "nil", "\n", "}" ]
// ProjectHasImages is a helper to check if a project has the images // feature enabled.
[ "ProjectHasImages", "is", "a", "helper", "to", "check", "if", "a", "project", "has", "the", "images", "feature", "enabled", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.go#L118-L127
test
lxc/lxd
lxd/db/projects.go
ProjectUpdate
func (c *ClusterTx) ProjectUpdate(name string, object api.ProjectPut) error { stmt := c.stmt(projectUpdate) result, err := stmt.Exec(object.Description, name) if err != nil { return errors.Wrap(err, "Update project") } n, err := result.RowsAffected() if err != nil { return errors.Wrap(err, "Fetch affected rows") } if n != 1 { return fmt.Errorf("Query updated %d rows instead of 1", n) } id, err := c.ProjectID(name) if err != nil { return errors.Wrap(err, "Fetch project ID") } // Clear config. _, err = c.tx.Exec(` DELETE FROM projects_config WHERE projects_config.project_id = ? `, id) if err != nil { return errors.Wrap(err, "Delete project config") } // Insert new config. stmt = c.stmt(projectCreateConfigRef) for key, value := range object.Config { _, err := stmt.Exec(id, key, value) if err != nil { return errors.Wrap(err, "Insert config for project") } } return nil }
go
func (c *ClusterTx) ProjectUpdate(name string, object api.ProjectPut) error { stmt := c.stmt(projectUpdate) result, err := stmt.Exec(object.Description, name) if err != nil { return errors.Wrap(err, "Update project") } n, err := result.RowsAffected() if err != nil { return errors.Wrap(err, "Fetch affected rows") } if n != 1 { return fmt.Errorf("Query updated %d rows instead of 1", n) } id, err := c.ProjectID(name) if err != nil { return errors.Wrap(err, "Fetch project ID") } // Clear config. _, err = c.tx.Exec(` DELETE FROM projects_config WHERE projects_config.project_id = ? `, id) if err != nil { return errors.Wrap(err, "Delete project config") } // Insert new config. stmt = c.stmt(projectCreateConfigRef) for key, value := range object.Config { _, err := stmt.Exec(id, key, value) if err != nil { return errors.Wrap(err, "Insert config for project") } } return nil }
[ "func", "(", "c", "*", "ClusterTx", ")", "ProjectUpdate", "(", "name", "string", ",", "object", "api", ".", "ProjectPut", ")", "error", "{", "stmt", ":=", "c", ".", "stmt", "(", "projectUpdate", ")", "\n", "result", ",", "err", ":=", "stmt", ".", "Exec", "(", "object", ".", "Description", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"Update project\"", ")", "\n", "}", "\n", "n", ",", "err", ":=", "result", ".", "RowsAffected", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"Fetch affected rows\"", ")", "\n", "}", "\n", "if", "n", "!=", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"Query updated %d rows instead of 1\"", ",", "n", ")", "\n", "}", "\n", "id", ",", "err", ":=", "c", ".", "ProjectID", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"Fetch project ID\"", ")", "\n", "}", "\n", "_", ",", "err", "=", "c", ".", "tx", ".", "Exec", "(", "`DELETE FROM projects_config WHERE projects_config.project_id = ?`", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"Delete project config\"", ")", "\n", "}", "\n", "stmt", "=", "c", ".", "stmt", "(", "projectCreateConfigRef", ")", "\n", "for", "key", ",", "value", ":=", "range", "object", ".", "Config", "{", "_", ",", "err", ":=", "stmt", ".", "Exec", "(", "id", ",", "key", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"Insert config for project\"", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// ProjectUpdate updates the project matching the given key parameters.
[ "ProjectUpdate", "updates", "the", "project", "matching", "the", "given", "key", "parameters", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/projects.go#L130-L168
test
lxc/lxd
client/lxd_cluster.go
GetCluster
func (r *ProtocolLXD) GetCluster() (*api.Cluster, string, error) { if !r.HasExtension("clustering") { return nil, "", fmt.Errorf("The server is missing the required \"clustering\" API extension") } cluster := &api.Cluster{} etag, err := r.queryStruct("GET", "/cluster", nil, "", &cluster) if err != nil { return nil, "", err } return cluster, etag, nil }
go
func (r *ProtocolLXD) GetCluster() (*api.Cluster, string, error) { if !r.HasExtension("clustering") { return nil, "", fmt.Errorf("The server is missing the required \"clustering\" API extension") } cluster := &api.Cluster{} etag, err := r.queryStruct("GET", "/cluster", nil, "", &cluster) if err != nil { return nil, "", err } return cluster, etag, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetCluster", "(", ")", "(", "*", "api", ".", "Cluster", ",", "string", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"clustering\"", ")", "{", "return", "nil", ",", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"clustering\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "cluster", ":=", "&", "api", ".", "Cluster", "{", "}", "\n", "etag", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "\"/cluster\"", ",", "nil", ",", "\"\"", ",", "&", "cluster", ")", "\n", "}" ]
// GetCluster returns information about a cluster // // If this client is not trusted, the password must be supplied
[ "GetCluster", "returns", "information", "about", "a", "cluster", "If", "this", "client", "is", "not", "trusted", "the", "password", "must", "be", "supplied" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_cluster.go#L12-L24
test
lxc/lxd
client/lxd_cluster.go
UpdateCluster
func (r *ProtocolLXD) UpdateCluster(cluster api.ClusterPut, ETag string) (Operation, error) { if !r.HasExtension("clustering") { return nil, fmt.Errorf("The server is missing the required \"clustering\" API extension") } if cluster.ServerAddress != "" || cluster.ClusterPassword != "" || len(cluster.MemberConfig) > 0 { if !r.HasExtension("clustering_join") { return nil, fmt.Errorf("The server is missing the required \"clustering_join\" API extension") } } op, _, err := r.queryOperation("PUT", "/cluster", cluster, "") if err != nil { return nil, err } return op, nil }
go
func (r *ProtocolLXD) UpdateCluster(cluster api.ClusterPut, ETag string) (Operation, error) { if !r.HasExtension("clustering") { return nil, fmt.Errorf("The server is missing the required \"clustering\" API extension") } if cluster.ServerAddress != "" || cluster.ClusterPassword != "" || len(cluster.MemberConfig) > 0 { if !r.HasExtension("clustering_join") { return nil, fmt.Errorf("The server is missing the required \"clustering_join\" API extension") } } op, _, err := r.queryOperation("PUT", "/cluster", cluster, "") if err != nil { return nil, err } return op, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "UpdateCluster", "(", "cluster", "api", ".", "ClusterPut", ",", "ETag", "string", ")", "(", "Operation", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"clustering\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"clustering\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "if", "cluster", ".", "ServerAddress", "!=", "\"\"", "||", "cluster", ".", "ClusterPassword", "!=", "\"\"", "||", "len", "(", "cluster", ".", "MemberConfig", ")", ">", "0", "{", "if", "!", "r", ".", "HasExtension", "(", "\"clustering_join\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"clustering_join\\\" API extension\"", ")", "\n", "}", "\n", "}", "\n", "\\\"", "\n", "}" ]
// UpdateCluster requests to bootstrap a new cluster or join an existing one.
[ "UpdateCluster", "requests", "to", "bootstrap", "a", "new", "cluster", "or", "join", "an", "existing", "one", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_cluster.go#L27-L44
test
lxc/lxd
client/lxd_cluster.go
GetClusterMemberNames
func (r *ProtocolLXD) GetClusterMemberNames() ([]string, error) { if !r.HasExtension("clustering") { return nil, fmt.Errorf("The server is missing the required \"clustering\" API extension") } urls := []string{} _, err := r.queryStruct("GET", "/cluster/members", nil, "", &urls) if err != nil { return nil, err } return urls, nil }
go
func (r *ProtocolLXD) GetClusterMemberNames() ([]string, error) { if !r.HasExtension("clustering") { return nil, fmt.Errorf("The server is missing the required \"clustering\" API extension") } urls := []string{} _, err := r.queryStruct("GET", "/cluster/members", nil, "", &urls) if err != nil { return nil, err } return urls, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetClusterMemberNames", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"clustering\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"clustering\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "urls", ":=", "[", "]", "string", "{", "}", "\n", "_", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "\"/cluster/members\"", ",", "nil", ",", "\"\"", ",", "&", "urls", ")", "\n", "}" ]
// GetClusterMemberNames returns the URLs of the current members in the cluster
[ "GetClusterMemberNames", "returns", "the", "URLs", "of", "the", "current", "members", "in", "the", "cluster" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_cluster.go#L67-L79
test
lxc/lxd
client/lxd_cluster.go
GetClusterMembers
func (r *ProtocolLXD) GetClusterMembers() ([]api.ClusterMember, error) { if !r.HasExtension("clustering") { return nil, fmt.Errorf("The server is missing the required \"clustering\" API extension") } members := []api.ClusterMember{} _, err := r.queryStruct("GET", "/cluster/members?recursion=1", nil, "", &members) if err != nil { return nil, err } return members, nil }
go
func (r *ProtocolLXD) GetClusterMembers() ([]api.ClusterMember, error) { if !r.HasExtension("clustering") { return nil, fmt.Errorf("The server is missing the required \"clustering\" API extension") } members := []api.ClusterMember{} _, err := r.queryStruct("GET", "/cluster/members?recursion=1", nil, "", &members) if err != nil { return nil, err } return members, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetClusterMembers", "(", ")", "(", "[", "]", "api", ".", "ClusterMember", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"clustering\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"clustering\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "members", ":=", "[", "]", "api", ".", "ClusterMember", "{", "}", "\n", "_", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "\"/cluster/members?recursion=1\"", ",", "nil", ",", "\"\"", ",", "&", "members", ")", "\n", "}" ]
// GetClusterMembers returns the current members of the cluster
[ "GetClusterMembers", "returns", "the", "current", "members", "of", "the", "cluster" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_cluster.go#L82-L94
test
lxc/lxd
client/lxd_cluster.go
GetClusterMember
func (r *ProtocolLXD) GetClusterMember(name string) (*api.ClusterMember, string, error) { if !r.HasExtension("clustering") { return nil, "", fmt.Errorf("The server is missing the required \"clustering\" API extension") } member := api.ClusterMember{} etag, err := r.queryStruct("GET", fmt.Sprintf("/cluster/members/%s", name), nil, "", &member) if err != nil { return nil, "", err } return &member, etag, nil }
go
func (r *ProtocolLXD) GetClusterMember(name string) (*api.ClusterMember, string, error) { if !r.HasExtension("clustering") { return nil, "", fmt.Errorf("The server is missing the required \"clustering\" API extension") } member := api.ClusterMember{} etag, err := r.queryStruct("GET", fmt.Sprintf("/cluster/members/%s", name), nil, "", &member) if err != nil { return nil, "", err } return &member, etag, nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "GetClusterMember", "(", "name", "string", ")", "(", "*", "api", ".", "ClusterMember", ",", "string", ",", "error", ")", "{", "if", "!", "r", ".", "HasExtension", "(", "\"clustering\"", ")", "{", "return", "nil", ",", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"clustering\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "member", ":=", "api", ".", "ClusterMember", "{", "}", "\n", "etag", ",", "err", ":=", "r", ".", "queryStruct", "(", "\"GET\"", ",", "fmt", ".", "Sprintf", "(", "\"/cluster/members/%s\"", ",", "name", ")", ",", "nil", ",", "\"\"", ",", "&", "member", ")", "\n", "}" ]
// GetClusterMember returns information about the given member
[ "GetClusterMember", "returns", "information", "about", "the", "given", "member" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_cluster.go#L97-L109
test
lxc/lxd
client/lxd_cluster.go
RenameClusterMember
func (r *ProtocolLXD) RenameClusterMember(name string, member api.ClusterMemberPost) error { if !r.HasExtension("clustering") { return fmt.Errorf("The server is missing the required \"clustering\" API extension") } _, _, err := r.query("POST", fmt.Sprintf("/cluster/members/%s", name), member, "") if err != nil { return err } return nil }
go
func (r *ProtocolLXD) RenameClusterMember(name string, member api.ClusterMemberPost) error { if !r.HasExtension("clustering") { return fmt.Errorf("The server is missing the required \"clustering\" API extension") } _, _, err := r.query("POST", fmt.Sprintf("/cluster/members/%s", name), member, "") if err != nil { return err } return nil }
[ "func", "(", "r", "*", "ProtocolLXD", ")", "RenameClusterMember", "(", "name", "string", ",", "member", "api", ".", "ClusterMemberPost", ")", "error", "{", "if", "!", "r", ".", "HasExtension", "(", "\"clustering\"", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"The server is missing the required \\\"clustering\\\" API extension\"", ")", "\n", "}", "\n", "\\\"", "\n", "\\\"", "\n", "_", ",", "_", ",", "err", ":=", "r", ".", "query", "(", "\"POST\"", ",", "fmt", ".", "Sprintf", "(", "\"/cluster/members/%s\"", ",", "name", ")", ",", "member", ",", "\"\"", ")", "\n", "}" ]
// RenameClusterMember changes the name of an existing member
[ "RenameClusterMember", "changes", "the", "name", "of", "an", "existing", "member" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/lxd_cluster.go#L112-L123
test
lxc/lxd
client/events.go
Disconnect
func (e *EventListener) Disconnect() { if e.disconnected { return } // Handle locking e.r.eventListenersLock.Lock() defer e.r.eventListenersLock.Unlock() // Locate and remove it from the global list for i, listener := range e.r.eventListeners { if listener == e { copy(e.r.eventListeners[i:], e.r.eventListeners[i+1:]) e.r.eventListeners[len(e.r.eventListeners)-1] = nil e.r.eventListeners = e.r.eventListeners[:len(e.r.eventListeners)-1] break } } // Turn off the handler e.err = nil e.disconnected = true close(e.chActive) }
go
func (e *EventListener) Disconnect() { if e.disconnected { return } // Handle locking e.r.eventListenersLock.Lock() defer e.r.eventListenersLock.Unlock() // Locate and remove it from the global list for i, listener := range e.r.eventListeners { if listener == e { copy(e.r.eventListeners[i:], e.r.eventListeners[i+1:]) e.r.eventListeners[len(e.r.eventListeners)-1] = nil e.r.eventListeners = e.r.eventListeners[:len(e.r.eventListeners)-1] break } } // Turn off the handler e.err = nil e.disconnected = true close(e.chActive) }
[ "func", "(", "e", "*", "EventListener", ")", "Disconnect", "(", ")", "{", "if", "e", ".", "disconnected", "{", "return", "\n", "}", "\n", "e", ".", "r", ".", "eventListenersLock", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "r", ".", "eventListenersLock", ".", "Unlock", "(", ")", "\n", "for", "i", ",", "listener", ":=", "range", "e", ".", "r", ".", "eventListeners", "{", "if", "listener", "==", "e", "{", "copy", "(", "e", ".", "r", ".", "eventListeners", "[", "i", ":", "]", ",", "e", ".", "r", ".", "eventListeners", "[", "i", "+", "1", ":", "]", ")", "\n", "e", ".", "r", ".", "eventListeners", "[", "len", "(", "e", ".", "r", ".", "eventListeners", ")", "-", "1", "]", "=", "nil", "\n", "e", ".", "r", ".", "eventListeners", "=", "e", ".", "r", ".", "eventListeners", "[", ":", "len", "(", "e", ".", "r", ".", "eventListeners", ")", "-", "1", "]", "\n", "break", "\n", "}", "\n", "}", "\n", "e", ".", "err", "=", "nil", "\n", "e", ".", "disconnected", "=", "true", "\n", "close", "(", "e", ".", "chActive", ")", "\n", "}" ]
// Disconnect must be used once done listening for events
[ "Disconnect", "must", "be", "used", "once", "done", "listening", "for", "events" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/client/events.go#L73-L96
test
lxc/lxd
lxd/util/version.go
CompareVersions
func CompareVersions(version1, version2 [2]int) (int, error) { schema1, extensions1 := version1[0], version1[1] schema2, extensions2 := version2[0], version2[1] if schema1 == schema2 && extensions1 == extensions2 { return 0, nil } if schema1 >= schema2 && extensions1 >= extensions2 { return 1, nil } if schema1 <= schema2 && extensions1 <= extensions2 { return 2, nil } return -1, fmt.Errorf("nodes have inconsistent versions") }
go
func CompareVersions(version1, version2 [2]int) (int, error) { schema1, extensions1 := version1[0], version1[1] schema2, extensions2 := version2[0], version2[1] if schema1 == schema2 && extensions1 == extensions2 { return 0, nil } if schema1 >= schema2 && extensions1 >= extensions2 { return 1, nil } if schema1 <= schema2 && extensions1 <= extensions2 { return 2, nil } return -1, fmt.Errorf("nodes have inconsistent versions") }
[ "func", "CompareVersions", "(", "version1", ",", "version2", "[", "2", "]", "int", ")", "(", "int", ",", "error", ")", "{", "schema1", ",", "extensions1", ":=", "version1", "[", "0", "]", ",", "version1", "[", "1", "]", "\n", "schema2", ",", "extensions2", ":=", "version2", "[", "0", "]", ",", "version2", "[", "1", "]", "\n", "if", "schema1", "==", "schema2", "&&", "extensions1", "==", "extensions2", "{", "return", "0", ",", "nil", "\n", "}", "\n", "if", "schema1", ">=", "schema2", "&&", "extensions1", ">=", "extensions2", "{", "return", "1", ",", "nil", "\n", "}", "\n", "if", "schema1", "<=", "schema2", "&&", "extensions1", "<=", "extensions2", "{", "return", "2", ",", "nil", "\n", "}", "\n", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"nodes have inconsistent versions\"", ")", "\n", "}" ]
// CompareVersions the versions of two LXD nodes. // // A version consists of the version the node's schema and the number of API // extensions it supports. // // Return 0 if they equal, 1 if the first version is greater than the second // and 2 if the second is greater than the first. // // Return an error if inconsistent versions are detected, for example the first // node's schema is greater than the second's, but the number of extensions is // smaller.
[ "CompareVersions", "the", "versions", "of", "two", "LXD", "nodes", ".", "A", "version", "consists", "of", "the", "version", "the", "node", "s", "schema", "and", "the", "number", "of", "API", "extensions", "it", "supports", ".", "Return", "0", "if", "they", "equal", "1", "if", "the", "first", "version", "is", "greater", "than", "the", "second", "and", "2", "if", "the", "second", "is", "greater", "than", "the", "first", ".", "Return", "an", "error", "if", "inconsistent", "versions", "are", "detected", "for", "example", "the", "first", "node", "s", "schema", "is", "greater", "than", "the", "second", "s", "but", "the", "number", "of", "extensions", "is", "smaller", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/version.go#L16-L31
test
lxc/lxd
lxc/config/cert.go
HasClientCertificate
func (c *Config) HasClientCertificate() bool { certf := c.ConfigPath("client.crt") keyf := c.ConfigPath("client.key") if !shared.PathExists(certf) || !shared.PathExists(keyf) { return false } return true }
go
func (c *Config) HasClientCertificate() bool { certf := c.ConfigPath("client.crt") keyf := c.ConfigPath("client.key") if !shared.PathExists(certf) || !shared.PathExists(keyf) { return false } return true }
[ "func", "(", "c", "*", "Config", ")", "HasClientCertificate", "(", ")", "bool", "{", "certf", ":=", "c", ".", "ConfigPath", "(", "\"client.crt\"", ")", "\n", "keyf", ":=", "c", ".", "ConfigPath", "(", "\"client.key\"", ")", "\n", "if", "!", "shared", ".", "PathExists", "(", "certf", ")", "||", "!", "shared", ".", "PathExists", "(", "keyf", ")", "{", "return", "false", "\n", "}", "\n", "return", "true", "\n", "}" ]
// HasClientCertificate will return true if a client certificate has already been generated
[ "HasClientCertificate", "will", "return", "true", "if", "a", "client", "certificate", "has", "already", "been", "generated" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxc/config/cert.go#L8-L16
test
lxc/lxd
lxc/config/cert.go
GenerateClientCertificate
func (c *Config) GenerateClientCertificate() error { if c.HasClientCertificate() { return nil } certf := c.ConfigPath("client.crt") keyf := c.ConfigPath("client.key") return shared.FindOrGenCert(certf, keyf, true) }
go
func (c *Config) GenerateClientCertificate() error { if c.HasClientCertificate() { return nil } certf := c.ConfigPath("client.crt") keyf := c.ConfigPath("client.key") return shared.FindOrGenCert(certf, keyf, true) }
[ "func", "(", "c", "*", "Config", ")", "GenerateClientCertificate", "(", ")", "error", "{", "if", "c", ".", "HasClientCertificate", "(", ")", "{", "return", "nil", "\n", "}", "\n", "certf", ":=", "c", ".", "ConfigPath", "(", "\"client.crt\"", ")", "\n", "keyf", ":=", "c", ".", "ConfigPath", "(", "\"client.key\"", ")", "\n", "return", "shared", ".", "FindOrGenCert", "(", "certf", ",", "keyf", ",", "true", ")", "\n", "}" ]
// GenerateClientCertificate will generate the needed client.crt and client.key if needed
[ "GenerateClientCertificate", "will", "generate", "the", "needed", "client", ".", "crt", "and", "client", ".", "key", "if", "needed" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxc/config/cert.go#L19-L28
test
lxc/lxd
lxd/util/kernel.go
LoadModule
func LoadModule(module string) error { if shared.PathExists(fmt.Sprintf("/sys/module/%s", module)) { return nil } _, err := shared.RunCommand("modprobe", module) return err }
go
func LoadModule(module string) error { if shared.PathExists(fmt.Sprintf("/sys/module/%s", module)) { return nil } _, err := shared.RunCommand("modprobe", module) return err }
[ "func", "LoadModule", "(", "module", "string", ")", "error", "{", "if", "shared", ".", "PathExists", "(", "fmt", ".", "Sprintf", "(", "\"/sys/module/%s\"", ",", "module", ")", ")", "{", "return", "nil", "\n", "}", "\n", "_", ",", "err", ":=", "shared", ".", "RunCommand", "(", "\"modprobe\"", ",", "module", ")", "\n", "return", "err", "\n", "}" ]
// LoadModule loads the kernel module with the given name, by invoking // modprobe.
[ "LoadModule", "loads", "the", "kernel", "module", "with", "the", "given", "name", "by", "invoking", "modprobe", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/util/kernel.go#L11-L18
test
lxc/lxd
shared/generate/lex/parse.go
Parse
func Parse(name string) (*ast.Package, error) { base := os.Getenv("GOPATH") if base == "" { base = "~/go" } dir := filepath.Join(base, "src", name) fset := token.NewFileSet() paths, err := filepath.Glob(filepath.Join(dir, "*.go")) if err != nil { return nil, errors.Wrap(err, "Search source file") } files := map[string]*ast.File{} for _, path := range paths { // Skip test files. if strings.Contains(path, "_test.go") { continue } file, err := parser.ParseFile(fset, path, nil, parser.ParseComments) if err != nil { return nil, fmt.Errorf("Parse Go source file %q", path) } files[path] = file } // Ignore errors because they are typically about unresolved symbols. pkg, _ := ast.NewPackage(fset, files, nil, nil) return pkg, nil }
go
func Parse(name string) (*ast.Package, error) { base := os.Getenv("GOPATH") if base == "" { base = "~/go" } dir := filepath.Join(base, "src", name) fset := token.NewFileSet() paths, err := filepath.Glob(filepath.Join(dir, "*.go")) if err != nil { return nil, errors.Wrap(err, "Search source file") } files := map[string]*ast.File{} for _, path := range paths { // Skip test files. if strings.Contains(path, "_test.go") { continue } file, err := parser.ParseFile(fset, path, nil, parser.ParseComments) if err != nil { return nil, fmt.Errorf("Parse Go source file %q", path) } files[path] = file } // Ignore errors because they are typically about unresolved symbols. pkg, _ := ast.NewPackage(fset, files, nil, nil) return pkg, nil }
[ "func", "Parse", "(", "name", "string", ")", "(", "*", "ast", ".", "Package", ",", "error", ")", "{", "base", ":=", "os", ".", "Getenv", "(", "\"GOPATH\"", ")", "\n", "if", "base", "==", "\"\"", "{", "base", "=", "\"~/go\"", "\n", "}", "\n", "dir", ":=", "filepath", ".", "Join", "(", "base", ",", "\"src\"", ",", "name", ")", "\n", "fset", ":=", "token", ".", "NewFileSet", "(", ")", "\n", "paths", ",", "err", ":=", "filepath", ".", "Glob", "(", "filepath", ".", "Join", "(", "dir", ",", "\"*.go\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"Search source file\"", ")", "\n", "}", "\n", "files", ":=", "map", "[", "string", "]", "*", "ast", ".", "File", "{", "}", "\n", "for", "_", ",", "path", ":=", "range", "paths", "{", "if", "strings", ".", "Contains", "(", "path", ",", "\"_test.go\"", ")", "{", "continue", "\n", "}", "\n", "file", ",", "err", ":=", "parser", ".", "ParseFile", "(", "fset", ",", "path", ",", "nil", ",", "parser", ".", "ParseComments", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Parse Go source file %q\"", ",", "path", ")", "\n", "}", "\n", "files", "[", "path", "]", "=", "file", "\n", "}", "\n", "pkg", ",", "_", ":=", "ast", ".", "NewPackage", "(", "fset", ",", "files", ",", "nil", ",", "nil", ")", "\n", "return", "pkg", ",", "nil", "\n", "}" ]
// Parse runs the Go parser against the given package name.
[ "Parse", "runs", "the", "Go", "parser", "against", "the", "given", "package", "name", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/generate/lex/parse.go#L16-L49
test
lxc/lxd
lxd/endpoints/pprof.go
PprofAddress
func (e *Endpoints) PprofAddress() string { e.mu.RLock() defer e.mu.RUnlock() listener := e.listeners[pprof] if listener == nil { return "" } return listener.Addr().String() }
go
func (e *Endpoints) PprofAddress() string { e.mu.RLock() defer e.mu.RUnlock() listener := e.listeners[pprof] if listener == nil { return "" } return listener.Addr().String() }
[ "func", "(", "e", "*", "Endpoints", ")", "PprofAddress", "(", ")", "string", "{", "e", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "e", ".", "mu", ".", "RUnlock", "(", ")", "\n", "listener", ":=", "e", ".", "listeners", "[", "pprof", "]", "\n", "if", "listener", "==", "nil", "{", "return", "\"\"", "\n", "}", "\n", "return", "listener", ".", "Addr", "(", ")", ".", "String", "(", ")", "\n", "}" ]
// PprofAddress returns the network addresss of the pprof endpoint, or an empty string if there's no pprof endpoint
[ "PprofAddress", "returns", "the", "network", "addresss", "of", "the", "pprof", "endpoint", "or", "an", "empty", "string", "if", "there", "s", "no", "pprof", "endpoint" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/endpoints/pprof.go#L33-L43
test
lxc/lxd
lxd/endpoints/pprof.go
PprofUpdateAddress
func (e *Endpoints) PprofUpdateAddress(address string) error { if address != "" { address = util.CanonicalNetworkAddress(address) } oldAddress := e.NetworkAddress() if address == oldAddress { return nil } logger.Infof("Update pprof address") e.mu.Lock() defer e.mu.Unlock() // Close the previous socket e.closeListener(pprof) // If turning off listening, we're done if address == "" { return nil } // Attempt to setup the new listening socket getListener := func(address string) (*net.Listener, error) { var err error var listener net.Listener for i := 0; i < 10; i++ { // Ten retries over a second seems reasonable. listener, err = net.Listen("tcp", address) if err == nil { break } time.Sleep(100 * time.Millisecond) } if err != nil { return nil, fmt.Errorf("Cannot listen on http socket: %v", err) } return &listener, nil } // If setting a new address, setup the listener if address != "" { listener, err := getListener(address) if err != nil { // Attempt to revert to the previous address listener, err1 := getListener(oldAddress) if err1 == nil { e.listeners[pprof] = *listener e.serveHTTP(pprof) } return err } e.listeners[pprof] = *listener e.serveHTTP(pprof) } return nil }
go
func (e *Endpoints) PprofUpdateAddress(address string) error { if address != "" { address = util.CanonicalNetworkAddress(address) } oldAddress := e.NetworkAddress() if address == oldAddress { return nil } logger.Infof("Update pprof address") e.mu.Lock() defer e.mu.Unlock() // Close the previous socket e.closeListener(pprof) // If turning off listening, we're done if address == "" { return nil } // Attempt to setup the new listening socket getListener := func(address string) (*net.Listener, error) { var err error var listener net.Listener for i := 0; i < 10; i++ { // Ten retries over a second seems reasonable. listener, err = net.Listen("tcp", address) if err == nil { break } time.Sleep(100 * time.Millisecond) } if err != nil { return nil, fmt.Errorf("Cannot listen on http socket: %v", err) } return &listener, nil } // If setting a new address, setup the listener if address != "" { listener, err := getListener(address) if err != nil { // Attempt to revert to the previous address listener, err1 := getListener(oldAddress) if err1 == nil { e.listeners[pprof] = *listener e.serveHTTP(pprof) } return err } e.listeners[pprof] = *listener e.serveHTTP(pprof) } return nil }
[ "func", "(", "e", "*", "Endpoints", ")", "PprofUpdateAddress", "(", "address", "string", ")", "error", "{", "if", "address", "!=", "\"\"", "{", "address", "=", "util", ".", "CanonicalNetworkAddress", "(", "address", ")", "\n", "}", "\n", "oldAddress", ":=", "e", ".", "NetworkAddress", "(", ")", "\n", "if", "address", "==", "oldAddress", "{", "return", "nil", "\n", "}", "\n", "logger", ".", "Infof", "(", "\"Update pprof address\"", ")", "\n", "e", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "e", ".", "mu", ".", "Unlock", "(", ")", "\n", "e", ".", "closeListener", "(", "pprof", ")", "\n", "if", "address", "==", "\"\"", "{", "return", "nil", "\n", "}", "\n", "getListener", ":=", "func", "(", "address", "string", ")", "(", "*", "net", ".", "Listener", ",", "error", ")", "{", "var", "err", "error", "\n", "var", "listener", "net", ".", "Listener", "\n", "for", "i", ":=", "0", ";", "i", "<", "10", ";", "i", "++", "{", "listener", ",", "err", "=", "net", ".", "Listen", "(", "\"tcp\"", ",", "address", ")", "\n", "if", "err", "==", "nil", "{", "break", "\n", "}", "\n", "time", ".", "Sleep", "(", "100", "*", "time", ".", "Millisecond", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Cannot listen on http socket: %v\"", ",", "err", ")", "\n", "}", "\n", "return", "&", "listener", ",", "nil", "\n", "}", "\n", "if", "address", "!=", "\"\"", "{", "listener", ",", "err", ":=", "getListener", "(", "address", ")", "\n", "if", "err", "!=", "nil", "{", "listener", ",", "err1", ":=", "getListener", "(", "oldAddress", ")", "\n", "if", "err1", "==", "nil", "{", "e", ".", "listeners", "[", "pprof", "]", "=", "*", "listener", "\n", "e", ".", "serveHTTP", "(", "pprof", ")", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "e", ".", "listeners", "[", "pprof", "]", "=", "*", "listener", "\n", "e", ".", "serveHTTP", "(", "pprof", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// PprofUpdateAddress updates the address for the pprof endpoint, shutting it down and restarting it.
[ "PprofUpdateAddress", "updates", "the", "address", "for", "the", "pprof", "endpoint", "shutting", "it", "down", "and", "restarting", "it", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/endpoints/pprof.go#L46-L109
test
lxc/lxd
shared/generate/db/method.go
NewMethod
func NewMethod(database, pkg, entity, kind string, config map[string]string) (*Method, error) { packages, err := Packages() if err != nil { return nil, err } method := &Method{ db: database, pkg: pkg, entity: entity, kind: kind, config: config, packages: packages, } return method, nil }
go
func NewMethod(database, pkg, entity, kind string, config map[string]string) (*Method, error) { packages, err := Packages() if err != nil { return nil, err } method := &Method{ db: database, pkg: pkg, entity: entity, kind: kind, config: config, packages: packages, } return method, nil }
[ "func", "NewMethod", "(", "database", ",", "pkg", ",", "entity", ",", "kind", "string", ",", "config", "map", "[", "string", "]", "string", ")", "(", "*", "Method", ",", "error", ")", "{", "packages", ",", "err", ":=", "Packages", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "method", ":=", "&", "Method", "{", "db", ":", "database", ",", "pkg", ":", "pkg", ",", "entity", ":", "entity", ",", "kind", ":", "kind", ",", "config", ":", "config", ",", "packages", ":", "packages", ",", "}", "\n", "return", "method", ",", "nil", "\n", "}" ]
// NewMethod return a new method code snippet for executing a certain mapping.
[ "NewMethod", "return", "a", "new", "method", "code", "snippet", "for", "executing", "a", "certain", "mapping", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/generate/db/method.go#L24-L40
test
lxc/lxd
shared/generate/db/method.go
Generate
func (m *Method) Generate(buf *file.Buffer) error { if strings.HasSuffix(m.kind, "Ref") { return m.ref(buf) } switch m.kind { case "URIs": return m.uris(buf) case "List": return m.list(buf) case "Get": return m.get(buf) case "ID": return m.id(buf) case "Exists": return m.exists(buf) case "Create": return m.create(buf) case "Rename": return m.rename(buf) case "Update": return m.update(buf) case "Delete": return m.delete(buf) default: return fmt.Errorf("Unknown method kind '%s'", m.kind) } }
go
func (m *Method) Generate(buf *file.Buffer) error { if strings.HasSuffix(m.kind, "Ref") { return m.ref(buf) } switch m.kind { case "URIs": return m.uris(buf) case "List": return m.list(buf) case "Get": return m.get(buf) case "ID": return m.id(buf) case "Exists": return m.exists(buf) case "Create": return m.create(buf) case "Rename": return m.rename(buf) case "Update": return m.update(buf) case "Delete": return m.delete(buf) default: return fmt.Errorf("Unknown method kind '%s'", m.kind) } }
[ "func", "(", "m", "*", "Method", ")", "Generate", "(", "buf", "*", "file", ".", "Buffer", ")", "error", "{", "if", "strings", ".", "HasSuffix", "(", "m", ".", "kind", ",", "\"Ref\"", ")", "{", "return", "m", ".", "ref", "(", "buf", ")", "\n", "}", "\n", "switch", "m", ".", "kind", "{", "case", "\"URIs\"", ":", "return", "m", ".", "uris", "(", "buf", ")", "\n", "case", "\"List\"", ":", "return", "m", ".", "list", "(", "buf", ")", "\n", "case", "\"Get\"", ":", "return", "m", ".", "get", "(", "buf", ")", "\n", "case", "\"ID\"", ":", "return", "m", ".", "id", "(", "buf", ")", "\n", "case", "\"Exists\"", ":", "return", "m", ".", "exists", "(", "buf", ")", "\n", "case", "\"Create\"", ":", "return", "m", ".", "create", "(", "buf", ")", "\n", "case", "\"Rename\"", ":", "return", "m", ".", "rename", "(", "buf", ")", "\n", "case", "\"Update\"", ":", "return", "m", ".", "update", "(", "buf", ")", "\n", "case", "\"Delete\"", ":", "return", "m", ".", "delete", "(", "buf", ")", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"Unknown method kind '%s'\"", ",", "m", ".", "kind", ")", "\n", "}", "\n", "}" ]
// Generate the desired method.
[ "Generate", "the", "desired", "method", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/generate/db/method.go#L43-L69
test
lxc/lxd
shared/generate/db/method.go
fillSliceReferenceField
func (m *Method) fillSliceReferenceField(buf *file.Buffer, nk []*Field, field *Field) error { objectsVar := fmt.Sprintf("%sObjects", lex.Minuscule(field.Name)) methodName := fmt.Sprintf("%s%sRef", lex.Capital(m.entity), field.Name) buf.L("// Fill field %s.", field.Name) buf.L("%s, err := c.%s(filter)", objectsVar, methodName) buf.L("if err != nil {") buf.L(" return nil, errors.Wrap(err, \"Failed to fetch field %s\")", field.Name) buf.L("}") buf.N() buf.L("for i := range objects {") needle := "" for i, key := range nk[:len(nk)-1] { needle += fmt.Sprintf("[objects[i].%s]", key.Name) subIndexTyp := indexType(nk[i+1:], field.Type.Name) buf.L(" _, ok := %s%s", objectsVar, needle) buf.L(" if !ok {") buf.L(" subIndex := %s{}", subIndexTyp) buf.L(" %s%s = subIndex", objectsVar, needle) buf.L(" }") buf.N() } needle += fmt.Sprintf("[objects[i].%s]", nk[len(nk)-1].Name) buf.L(" value := %s%s", objectsVar, needle) buf.L(" if value == nil {") buf.L(" value = %s{}", field.Type.Name) buf.L(" }") buf.L(" objects[i].%s = value", field.Name) buf.L("}") buf.N() return nil }
go
func (m *Method) fillSliceReferenceField(buf *file.Buffer, nk []*Field, field *Field) error { objectsVar := fmt.Sprintf("%sObjects", lex.Minuscule(field.Name)) methodName := fmt.Sprintf("%s%sRef", lex.Capital(m.entity), field.Name) buf.L("// Fill field %s.", field.Name) buf.L("%s, err := c.%s(filter)", objectsVar, methodName) buf.L("if err != nil {") buf.L(" return nil, errors.Wrap(err, \"Failed to fetch field %s\")", field.Name) buf.L("}") buf.N() buf.L("for i := range objects {") needle := "" for i, key := range nk[:len(nk)-1] { needle += fmt.Sprintf("[objects[i].%s]", key.Name) subIndexTyp := indexType(nk[i+1:], field.Type.Name) buf.L(" _, ok := %s%s", objectsVar, needle) buf.L(" if !ok {") buf.L(" subIndex := %s{}", subIndexTyp) buf.L(" %s%s = subIndex", objectsVar, needle) buf.L(" }") buf.N() } needle += fmt.Sprintf("[objects[i].%s]", nk[len(nk)-1].Name) buf.L(" value := %s%s", objectsVar, needle) buf.L(" if value == nil {") buf.L(" value = %s{}", field.Type.Name) buf.L(" }") buf.L(" objects[i].%s = value", field.Name) buf.L("}") buf.N() return nil }
[ "func", "(", "m", "*", "Method", ")", "fillSliceReferenceField", "(", "buf", "*", "file", ".", "Buffer", ",", "nk", "[", "]", "*", "Field", ",", "field", "*", "Field", ")", "error", "{", "objectsVar", ":=", "fmt", ".", "Sprintf", "(", "\"%sObjects\"", ",", "lex", ".", "Minuscule", "(", "field", ".", "Name", ")", ")", "\n", "methodName", ":=", "fmt", ".", "Sprintf", "(", "\"%s%sRef\"", ",", "lex", ".", "Capital", "(", "m", ".", "entity", ")", ",", "field", ".", "Name", ")", "\n", "buf", ".", "L", "(", "\"// Fill field %s.\"", ",", "field", ".", "Name", ")", "\n", "buf", ".", "L", "(", "\"%s, err := c.%s(filter)\"", ",", "objectsVar", ",", "methodName", ")", "\n", "buf", ".", "L", "(", "\"if err != nil {\"", ")", "\n", "buf", ".", "L", "(", "\" return nil, errors.Wrap(err, \\\"Failed to fetch field %s\\\")\"", ",", "\\\"", ")", "\n", "\\\"", "\n", "field", ".", "Name", "\n", "buf", ".", "L", "(", "\"}\"", ")", "\n", "buf", ".", "N", "(", ")", "\n", "buf", ".", "L", "(", "\"for i := range objects {\"", ")", "\n", "needle", ":=", "\"\"", "\n", "for", "i", ",", "key", ":=", "range", "nk", "[", ":", "len", "(", "nk", ")", "-", "1", "]", "{", "needle", "+=", "fmt", ".", "Sprintf", "(", "\"[objects[i].%s]\"", ",", "key", ".", "Name", ")", "\n", "subIndexTyp", ":=", "indexType", "(", "nk", "[", "i", "+", "1", ":", "]", ",", "field", ".", "Type", ".", "Name", ")", "\n", "buf", ".", "L", "(", "\" _, ok := %s%s\"", ",", "objectsVar", ",", "needle", ")", "\n", "buf", ".", "L", "(", "\" if !ok {\"", ")", "\n", "buf", ".", "L", "(", "\" subIndex := %s{}\"", ",", "subIndexTyp", ")", "\n", "buf", ".", "L", "(", "\" %s%s = subIndex\"", ",", "objectsVar", ",", "needle", ")", "\n", "buf", ".", "L", "(", "\" }\"", ")", "\n", "buf", ".", "N", "(", ")", "\n", "}", "\n", "needle", "+=", "fmt", ".", "Sprintf", "(", "\"[objects[i].%s]\"", ",", "nk", "[", "len", "(", "nk", ")", "-", "1", "]", ".", "Name", ")", "\n", "buf", ".", "L", "(", "\" value := %s%s\"", ",", "objectsVar", ",", "needle", ")", "\n", "buf", ".", "L", "(", "\" if value == nil {\"", ")", "\n", "buf", ".", "L", "(", "\" value = %s{}\"", ",", "field", ".", "Type", ".", "Name", ")", "\n", "buf", ".", "L", "(", "\" }\"", ")", "\n", "buf", ".", "L", "(", "\" objects[i].%s = value\"", ",", "field", ".", "Name", ")", "\n", "buf", ".", "L", "(", "\"}\"", ")", "\n", "}" ]
// Populate a field consisting of a slice of objects referencing the // entity. This information is available by joining a the view or table // associated with the type of the referenced objects, which must contain the // natural key of the entity.
[ "Populate", "a", "field", "consisting", "of", "a", "slice", "of", "objects", "referencing", "the", "entity", ".", "This", "information", "is", "available", "by", "joining", "a", "the", "view", "or", "table", "associated", "with", "the", "type", "of", "the", "referenced", "objects", "which", "must", "contain", "the", "natural", "key", "of", "the", "entity", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/shared/generate/db/method.go#L506-L539
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolID
func (c *ClusterTx) StoragePoolID(name string) (int64, error) { stmt := "SELECT id FROM storage_pools WHERE name=?" ids, err := query.SelectIntegers(c.tx, stmt, name) if err != nil { return -1, err } switch len(ids) { case 0: return -1, ErrNoSuchObject case 1: return int64(ids[0]), nil default: return -1, fmt.Errorf("more than one pool has the given name") } }
go
func (c *ClusterTx) StoragePoolID(name string) (int64, error) { stmt := "SELECT id FROM storage_pools WHERE name=?" ids, err := query.SelectIntegers(c.tx, stmt, name) if err != nil { return -1, err } switch len(ids) { case 0: return -1, ErrNoSuchObject case 1: return int64(ids[0]), nil default: return -1, fmt.Errorf("more than one pool has the given name") } }
[ "func", "(", "c", "*", "ClusterTx", ")", "StoragePoolID", "(", "name", "string", ")", "(", "int64", ",", "error", ")", "{", "stmt", ":=", "\"SELECT id FROM storage_pools WHERE name=?\"", "\n", "ids", ",", "err", ":=", "query", ".", "SelectIntegers", "(", "c", ".", "tx", ",", "stmt", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n", "switch", "len", "(", "ids", ")", "{", "case", "0", ":", "return", "-", "1", ",", "ErrNoSuchObject", "\n", "case", "1", ":", "return", "int64", "(", "ids", "[", "0", "]", ")", ",", "nil", "\n", "default", ":", "return", "-", "1", ",", "fmt", ".", "Errorf", "(", "\"more than one pool has the given name\"", ")", "\n", "}", "\n", "}" ]
// StoragePoolID returns the ID of the pool with the given name.
[ "StoragePoolID", "returns", "the", "ID", "of", "the", "pool", "with", "the", "given", "name", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L39-L53
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolIDsNotPending
func (c *ClusterTx) StoragePoolIDsNotPending() (map[string]int64, error) { pools := []struct { id int64 name string }{} dest := func(i int) []interface{} { pools = append(pools, struct { id int64 name string }{}) return []interface{}{&pools[i].id, &pools[i].name} } stmt, err := c.tx.Prepare("SELECT id, name FROM storage_pools WHERE NOT state=?") if err != nil { return nil, err } defer stmt.Close() err = query.SelectObjects(stmt, dest, storagePoolPending) if err != nil { return nil, err } ids := map[string]int64{} for _, pool := range pools { ids[pool.name] = pool.id } return ids, nil }
go
func (c *ClusterTx) StoragePoolIDsNotPending() (map[string]int64, error) { pools := []struct { id int64 name string }{} dest := func(i int) []interface{} { pools = append(pools, struct { id int64 name string }{}) return []interface{}{&pools[i].id, &pools[i].name} } stmt, err := c.tx.Prepare("SELECT id, name FROM storage_pools WHERE NOT state=?") if err != nil { return nil, err } defer stmt.Close() err = query.SelectObjects(stmt, dest, storagePoolPending) if err != nil { return nil, err } ids := map[string]int64{} for _, pool := range pools { ids[pool.name] = pool.id } return ids, nil }
[ "func", "(", "c", "*", "ClusterTx", ")", "StoragePoolIDsNotPending", "(", ")", "(", "map", "[", "string", "]", "int64", ",", "error", ")", "{", "pools", ":=", "[", "]", "struct", "{", "id", "int64", "\n", "name", "string", "\n", "}", "{", "}", "\n", "dest", ":=", "func", "(", "i", "int", ")", "[", "]", "interface", "{", "}", "{", "pools", "=", "append", "(", "pools", ",", "struct", "{", "id", "int64", "\n", "name", "string", "\n", "}", "{", "}", ")", "\n", "return", "[", "]", "interface", "{", "}", "{", "&", "pools", "[", "i", "]", ".", "id", ",", "&", "pools", "[", "i", "]", ".", "name", "}", "\n", "}", "\n", "stmt", ",", "err", ":=", "c", ".", "tx", ".", "Prepare", "(", "\"SELECT id, name FROM storage_pools WHERE NOT state=?\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "stmt", ".", "Close", "(", ")", "\n", "err", "=", "query", ".", "SelectObjects", "(", "stmt", ",", "dest", ",", "storagePoolPending", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ids", ":=", "map", "[", "string", "]", "int64", "{", "}", "\n", "for", "_", ",", "pool", ":=", "range", "pools", "{", "ids", "[", "pool", ".", "name", "]", "=", "pool", ".", "id", "\n", "}", "\n", "return", "ids", ",", "nil", "\n", "}" ]
// StoragePoolIDsNotPending returns a map associating each storage pool name to its ID. // // Pending storage pools are skipped.
[ "StoragePoolIDsNotPending", "returns", "a", "map", "associating", "each", "storage", "pool", "name", "to", "its", "ID", ".", "Pending", "storage", "pools", "are", "skipped", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L75-L102
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolNodeJoin
func (c *ClusterTx) StoragePoolNodeJoin(poolID, nodeID int64) error { columns := []string{"storage_pool_id", "node_id"} values := []interface{}{poolID, nodeID} _, err := query.UpsertObject(c.tx, "storage_pools_nodes", columns, values) if err != nil { return errors.Wrap(err, "failed to add storage pools node entry") } return nil }
go
func (c *ClusterTx) StoragePoolNodeJoin(poolID, nodeID int64) error { columns := []string{"storage_pool_id", "node_id"} values := []interface{}{poolID, nodeID} _, err := query.UpsertObject(c.tx, "storage_pools_nodes", columns, values) if err != nil { return errors.Wrap(err, "failed to add storage pools node entry") } return nil }
[ "func", "(", "c", "*", "ClusterTx", ")", "StoragePoolNodeJoin", "(", "poolID", ",", "nodeID", "int64", ")", "error", "{", "columns", ":=", "[", "]", "string", "{", "\"storage_pool_id\"", ",", "\"node_id\"", "}", "\n", "values", ":=", "[", "]", "interface", "{", "}", "{", "poolID", ",", "nodeID", "}", "\n", "_", ",", "err", ":=", "query", ".", "UpsertObject", "(", "c", ".", "tx", ",", "\"storage_pools_nodes\"", ",", "columns", ",", "values", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"failed to add storage pools node entry\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// StoragePoolNodeJoin adds a new entry in the storage_pools_nodes table. // // It should only be used when a new node joins the cluster, when it's safe to // assume that the relevant pool has already been created on the joining node, // and we just need to track it.
[ "StoragePoolNodeJoin", "adds", "a", "new", "entry", "in", "the", "storage_pools_nodes", "table", ".", "It", "should", "only", "be", "used", "when", "a", "new", "node", "joins", "the", "cluster", "when", "it", "s", "safe", "to", "assume", "that", "the", "relevant", "pool", "has", "already", "been", "created", "on", "the", "joining", "node", "and", "we", "just", "need", "to", "track", "it", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L109-L118
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolNodeJoinCeph
func (c *ClusterTx) StoragePoolNodeJoinCeph(poolID, nodeID int64) error { // Get the IDs of the other nodes (they should be all linked to // the pool). stmt := "SELECT node_id FROM storage_pools_nodes WHERE storage_pool_id=?" nodeIDs, err := query.SelectIntegers(c.tx, stmt, poolID) if err != nil { return errors.Wrap(err, "failed to fetch IDs of nodes with ceph pool") } if len(nodeIDs) == 0 { return fmt.Errorf("ceph pool is not linked to any node") } otherNodeID := nodeIDs[0] // Create entries of all the ceph volumes for the new node. _, err = c.tx.Exec(` INSERT INTO storage_volumes(name, storage_pool_id, node_id, type, description, project_id) SELECT name, storage_pool_id, ?, type, description, 1 FROM storage_volumes WHERE storage_pool_id=? AND node_id=? `, nodeID, poolID, otherNodeID) if err != nil { return errors.Wrap(err, "failed to create node ceph volumes") } // Create entries of all the ceph volumes configs for the new node. stmt = ` SELECT id FROM storage_volumes WHERE storage_pool_id=? AND node_id=? ORDER BY name, type ` volumeIDs, err := query.SelectIntegers(c.tx, stmt, poolID, nodeID) if err != nil { return errors.Wrap(err, "failed to get joining node's ceph volume IDs") } otherVolumeIDs, err := query.SelectIntegers(c.tx, stmt, poolID, otherNodeID) if err != nil { return errors.Wrap(err, "failed to get other node's ceph volume IDs") } if len(volumeIDs) != len(otherVolumeIDs) { // Sanity check return fmt.Errorf("not all ceph volumes were copied") } for i, otherVolumeID := range otherVolumeIDs { config, err := query.SelectConfig( c.tx, "storage_volumes_config", "storage_volume_id=?", otherVolumeID) if err != nil { return errors.Wrap(err, "failed to get storage volume config") } for key, value := range config { _, err := c.tx.Exec(` INSERT INTO storage_volumes_config(storage_volume_id, key, value) VALUES(?, ?, ?) `, volumeIDs[i], key, value) if err != nil { return errors.Wrap(err, "failed to copy volume config") } } } return nil }
go
func (c *ClusterTx) StoragePoolNodeJoinCeph(poolID, nodeID int64) error { // Get the IDs of the other nodes (they should be all linked to // the pool). stmt := "SELECT node_id FROM storage_pools_nodes WHERE storage_pool_id=?" nodeIDs, err := query.SelectIntegers(c.tx, stmt, poolID) if err != nil { return errors.Wrap(err, "failed to fetch IDs of nodes with ceph pool") } if len(nodeIDs) == 0 { return fmt.Errorf("ceph pool is not linked to any node") } otherNodeID := nodeIDs[0] // Create entries of all the ceph volumes for the new node. _, err = c.tx.Exec(` INSERT INTO storage_volumes(name, storage_pool_id, node_id, type, description, project_id) SELECT name, storage_pool_id, ?, type, description, 1 FROM storage_volumes WHERE storage_pool_id=? AND node_id=? `, nodeID, poolID, otherNodeID) if err != nil { return errors.Wrap(err, "failed to create node ceph volumes") } // Create entries of all the ceph volumes configs for the new node. stmt = ` SELECT id FROM storage_volumes WHERE storage_pool_id=? AND node_id=? ORDER BY name, type ` volumeIDs, err := query.SelectIntegers(c.tx, stmt, poolID, nodeID) if err != nil { return errors.Wrap(err, "failed to get joining node's ceph volume IDs") } otherVolumeIDs, err := query.SelectIntegers(c.tx, stmt, poolID, otherNodeID) if err != nil { return errors.Wrap(err, "failed to get other node's ceph volume IDs") } if len(volumeIDs) != len(otherVolumeIDs) { // Sanity check return fmt.Errorf("not all ceph volumes were copied") } for i, otherVolumeID := range otherVolumeIDs { config, err := query.SelectConfig( c.tx, "storage_volumes_config", "storage_volume_id=?", otherVolumeID) if err != nil { return errors.Wrap(err, "failed to get storage volume config") } for key, value := range config { _, err := c.tx.Exec(` INSERT INTO storage_volumes_config(storage_volume_id, key, value) VALUES(?, ?, ?) `, volumeIDs[i], key, value) if err != nil { return errors.Wrap(err, "failed to copy volume config") } } } return nil }
[ "func", "(", "c", "*", "ClusterTx", ")", "StoragePoolNodeJoinCeph", "(", "poolID", ",", "nodeID", "int64", ")", "error", "{", "stmt", ":=", "\"SELECT node_id FROM storage_pools_nodes WHERE storage_pool_id=?\"", "\n", "nodeIDs", ",", "err", ":=", "query", ".", "SelectIntegers", "(", "c", ".", "tx", ",", "stmt", ",", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"failed to fetch IDs of nodes with ceph pool\"", ")", "\n", "}", "\n", "if", "len", "(", "nodeIDs", ")", "==", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"ceph pool is not linked to any node\"", ")", "\n", "}", "\n", "otherNodeID", ":=", "nodeIDs", "[", "0", "]", "\n", "_", ",", "err", "=", "c", ".", "tx", ".", "Exec", "(", "`INSERT INTO storage_volumes(name, storage_pool_id, node_id, type, description, project_id) SELECT name, storage_pool_id, ?, type, description, 1 FROM storage_volumes WHERE storage_pool_id=? AND node_id=?`", ",", "nodeID", ",", "poolID", ",", "otherNodeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"failed to create node ceph volumes\"", ")", "\n", "}", "\n", "stmt", "=", "`SELECT id FROM storage_volumes WHERE storage_pool_id=? AND node_id=? ORDER BY name, type`", "\n", "volumeIDs", ",", "err", ":=", "query", ".", "SelectIntegers", "(", "c", ".", "tx", ",", "stmt", ",", "poolID", ",", "nodeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"failed to get joining node's ceph volume IDs\"", ")", "\n", "}", "\n", "otherVolumeIDs", ",", "err", ":=", "query", ".", "SelectIntegers", "(", "c", ".", "tx", ",", "stmt", ",", "poolID", ",", "otherNodeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"failed to get other node's ceph volume IDs\"", ")", "\n", "}", "\n", "if", "len", "(", "volumeIDs", ")", "!=", "len", "(", "otherVolumeIDs", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"not all ceph volumes were copied\"", ")", "\n", "}", "\n", "for", "i", ",", "otherVolumeID", ":=", "range", "otherVolumeIDs", "{", "config", ",", "err", ":=", "query", ".", "SelectConfig", "(", "c", ".", "tx", ",", "\"storage_volumes_config\"", ",", "\"storage_volume_id=?\"", ",", "otherVolumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"failed to get storage volume config\"", ")", "\n", "}", "\n", "for", "key", ",", "value", ":=", "range", "config", "{", "_", ",", "err", ":=", "c", ".", "tx", ".", "Exec", "(", "`INSERT INTO storage_volumes_config(storage_volume_id, key, value) VALUES(?, ?, ?)`", ",", "volumeIDs", "[", "i", "]", ",", "key", ",", "value", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"failed to copy volume config\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// StoragePoolNodeJoinCeph updates internal state to reflect that nodeID is // joining a cluster where poolID is a ceph pool.
[ "StoragePoolNodeJoinCeph", "updates", "internal", "state", "to", "reflect", "that", "nodeID", "is", "joining", "a", "cluster", "where", "poolID", "is", "a", "ceph", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L122-L178
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolConfigAdd
func (c *ClusterTx) StoragePoolConfigAdd(poolID, nodeID int64, config map[string]string) error { return storagePoolConfigAdd(c.tx, poolID, nodeID, config) }
go
func (c *ClusterTx) StoragePoolConfigAdd(poolID, nodeID int64, config map[string]string) error { return storagePoolConfigAdd(c.tx, poolID, nodeID, config) }
[ "func", "(", "c", "*", "ClusterTx", ")", "StoragePoolConfigAdd", "(", "poolID", ",", "nodeID", "int64", ",", "config", "map", "[", "string", "]", "string", ")", "error", "{", "return", "storagePoolConfigAdd", "(", "c", ".", "tx", ",", "poolID", ",", "nodeID", ",", "config", ")", "\n", "}" ]
// StoragePoolConfigAdd adds a new entry in the storage_pools_config table
[ "StoragePoolConfigAdd", "adds", "a", "new", "entry", "in", "the", "storage_pools_config", "table" ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L181-L183
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolCreatePending
func (c *ClusterTx) StoragePoolCreatePending(node, name, driver string, conf map[string]string) error { // First check if a storage pool with the given name exists, and, if // so, that it has a matching driver and it's in the pending state. pool := struct { id int64 driver string state int }{} var errConsistency error dest := func(i int) []interface{} { // Sanity check that there is at most one pool with the given name. if i != 0 { errConsistency = fmt.Errorf("more than one pool exists with the given name") } return []interface{}{&pool.id, &pool.driver, &pool.state} } stmt, err := c.tx.Prepare("SELECT id, driver, state FROM storage_pools WHERE name=?") if err != nil { return err } defer stmt.Close() err = query.SelectObjects(stmt, dest, name) if err != nil { return err } if errConsistency != nil { return errConsistency } var poolID = pool.id if poolID == 0 { // No existing pool with the given name was found, let's create // one. columns := []string{"name", "driver"} values := []interface{}{name, driver} poolID, err = query.UpsertObject(c.tx, "storage_pools", columns, values) if err != nil { return err } } else { // Check that the existing pools matches the given driver and // is in the pending state. if pool.driver != driver { return fmt.Errorf("pool already exists with a different driver") } if pool.state != storagePoolPending { return fmt.Errorf("pool is not in pending state") } } // Get the ID of the node with the given name. nodeInfo, err := c.NodeByName(node) if err != nil { return err } // Check that no storage_pool entry of this node and pool exists yet. count, err := query.Count( c.tx, "storage_pools_nodes", "storage_pool_id=? AND node_id=?", poolID, nodeInfo.ID) if err != nil { return err } if count != 0 { return ErrAlreadyDefined } // Insert the node-specific configuration. columns := []string{"storage_pool_id", "node_id"} values := []interface{}{poolID, nodeInfo.ID} _, err = query.UpsertObject(c.tx, "storage_pools_nodes", columns, values) if err != nil { return err } err = c.StoragePoolConfigAdd(poolID, nodeInfo.ID, conf) if err != nil { return err } return nil }
go
func (c *ClusterTx) StoragePoolCreatePending(node, name, driver string, conf map[string]string) error { // First check if a storage pool with the given name exists, and, if // so, that it has a matching driver and it's in the pending state. pool := struct { id int64 driver string state int }{} var errConsistency error dest := func(i int) []interface{} { // Sanity check that there is at most one pool with the given name. if i != 0 { errConsistency = fmt.Errorf("more than one pool exists with the given name") } return []interface{}{&pool.id, &pool.driver, &pool.state} } stmt, err := c.tx.Prepare("SELECT id, driver, state FROM storage_pools WHERE name=?") if err != nil { return err } defer stmt.Close() err = query.SelectObjects(stmt, dest, name) if err != nil { return err } if errConsistency != nil { return errConsistency } var poolID = pool.id if poolID == 0 { // No existing pool with the given name was found, let's create // one. columns := []string{"name", "driver"} values := []interface{}{name, driver} poolID, err = query.UpsertObject(c.tx, "storage_pools", columns, values) if err != nil { return err } } else { // Check that the existing pools matches the given driver and // is in the pending state. if pool.driver != driver { return fmt.Errorf("pool already exists with a different driver") } if pool.state != storagePoolPending { return fmt.Errorf("pool is not in pending state") } } // Get the ID of the node with the given name. nodeInfo, err := c.NodeByName(node) if err != nil { return err } // Check that no storage_pool entry of this node and pool exists yet. count, err := query.Count( c.tx, "storage_pools_nodes", "storage_pool_id=? AND node_id=?", poolID, nodeInfo.ID) if err != nil { return err } if count != 0 { return ErrAlreadyDefined } // Insert the node-specific configuration. columns := []string{"storage_pool_id", "node_id"} values := []interface{}{poolID, nodeInfo.ID} _, err = query.UpsertObject(c.tx, "storage_pools_nodes", columns, values) if err != nil { return err } err = c.StoragePoolConfigAdd(poolID, nodeInfo.ID, conf) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "ClusterTx", ")", "StoragePoolCreatePending", "(", "node", ",", "name", ",", "driver", "string", ",", "conf", "map", "[", "string", "]", "string", ")", "error", "{", "pool", ":=", "struct", "{", "id", "int64", "\n", "driver", "string", "\n", "state", "int", "\n", "}", "{", "}", "\n", "var", "errConsistency", "error", "\n", "dest", ":=", "func", "(", "i", "int", ")", "[", "]", "interface", "{", "}", "{", "if", "i", "!=", "0", "{", "errConsistency", "=", "fmt", ".", "Errorf", "(", "\"more than one pool exists with the given name\"", ")", "\n", "}", "\n", "return", "[", "]", "interface", "{", "}", "{", "&", "pool", ".", "id", ",", "&", "pool", ".", "driver", ",", "&", "pool", ".", "state", "}", "\n", "}", "\n", "stmt", ",", "err", ":=", "c", ".", "tx", ".", "Prepare", "(", "\"SELECT id, driver, state FROM storage_pools WHERE name=?\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "stmt", ".", "Close", "(", ")", "\n", "err", "=", "query", ".", "SelectObjects", "(", "stmt", ",", "dest", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "errConsistency", "!=", "nil", "{", "return", "errConsistency", "\n", "}", "\n", "var", "poolID", "=", "pool", ".", "id", "\n", "if", "poolID", "==", "0", "{", "columns", ":=", "[", "]", "string", "{", "\"name\"", ",", "\"driver\"", "}", "\n", "values", ":=", "[", "]", "interface", "{", "}", "{", "name", ",", "driver", "}", "\n", "poolID", ",", "err", "=", "query", ".", "UpsertObject", "(", "c", ".", "tx", ",", "\"storage_pools\"", ",", "columns", ",", "values", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "else", "{", "if", "pool", ".", "driver", "!=", "driver", "{", "return", "fmt", ".", "Errorf", "(", "\"pool already exists with a different driver\"", ")", "\n", "}", "\n", "if", "pool", ".", "state", "!=", "storagePoolPending", "{", "return", "fmt", ".", "Errorf", "(", "\"pool is not in pending state\"", ")", "\n", "}", "\n", "}", "\n", "nodeInfo", ",", "err", ":=", "c", ".", "NodeByName", "(", "node", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "count", ",", "err", ":=", "query", ".", "Count", "(", "c", ".", "tx", ",", "\"storage_pools_nodes\"", ",", "\"storage_pool_id=? AND node_id=?\"", ",", "poolID", ",", "nodeInfo", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "count", "!=", "0", "{", "return", "ErrAlreadyDefined", "\n", "}", "\n", "columns", ":=", "[", "]", "string", "{", "\"storage_pool_id\"", ",", "\"node_id\"", "}", "\n", "values", ":=", "[", "]", "interface", "{", "}", "{", "poolID", ",", "nodeInfo", ".", "ID", "}", "\n", "_", ",", "err", "=", "query", ".", "UpsertObject", "(", "c", ".", "tx", ",", "\"storage_pools_nodes\"", ",", "columns", ",", "values", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "StoragePoolConfigAdd", "(", "poolID", ",", "nodeInfo", ".", "ID", ",", "conf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// StoragePoolCreatePending creates a new pending storage pool on the node with // the given name.
[ "StoragePoolCreatePending", "creates", "a", "new", "pending", "storage", "pool", "on", "the", "node", "with", "the", "given", "name", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L194-L274
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolCreated
func (c *ClusterTx) StoragePoolCreated(name string) error { return c.storagePoolState(name, storagePoolCreated) }
go
func (c *ClusterTx) StoragePoolCreated(name string) error { return c.storagePoolState(name, storagePoolCreated) }
[ "func", "(", "c", "*", "ClusterTx", ")", "StoragePoolCreated", "(", "name", "string", ")", "error", "{", "return", "c", ".", "storagePoolState", "(", "name", ",", "storagePoolCreated", ")", "\n", "}" ]
// StoragePoolCreated sets the state of the given pool to "Created".
[ "StoragePoolCreated", "sets", "the", "state", "of", "the", "given", "pool", "to", "Created", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L277-L279
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolErrored
func (c *ClusterTx) StoragePoolErrored(name string) error { return c.storagePoolState(name, storagePoolErrored) }
go
func (c *ClusterTx) StoragePoolErrored(name string) error { return c.storagePoolState(name, storagePoolErrored) }
[ "func", "(", "c", "*", "ClusterTx", ")", "StoragePoolErrored", "(", "name", "string", ")", "error", "{", "return", "c", ".", "storagePoolState", "(", "name", ",", "storagePoolErrored", ")", "\n", "}" ]
// StoragePoolErrored sets the state of the given pool to "Errored".
[ "StoragePoolErrored", "sets", "the", "state", "of", "the", "given", "pool", "to", "Errored", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L282-L284
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolNodeConfigs
func (c *ClusterTx) StoragePoolNodeConfigs(poolID int64) (map[string]map[string]string, error) { // Fetch all nodes. nodes, err := c.Nodes() if err != nil { return nil, err } // Fetch the names of the nodes where the storage pool is defined. stmt := ` SELECT nodes.name FROM nodes LEFT JOIN storage_pools_nodes ON storage_pools_nodes.node_id = nodes.id LEFT JOIN storage_pools ON storage_pools_nodes.storage_pool_id = storage_pools.id WHERE storage_pools.id = ? AND storage_pools.state = ? ` defined, err := query.SelectStrings(c.tx, stmt, poolID, storagePoolPending) if err != nil { return nil, err } // Figure which nodes are missing missing := []string{} for _, node := range nodes { if !shared.StringInSlice(node.Name, defined) { missing = append(missing, node.Name) } } if len(missing) > 0 { return nil, fmt.Errorf("Pool not defined on nodes: %s", strings.Join(missing, ", ")) } configs := map[string]map[string]string{} for _, node := range nodes { config, err := query.SelectConfig( c.tx, "storage_pools_config", "storage_pool_id=? AND node_id=?", poolID, node.ID) if err != nil { return nil, err } configs[node.Name] = config } return configs, nil }
go
func (c *ClusterTx) StoragePoolNodeConfigs(poolID int64) (map[string]map[string]string, error) { // Fetch all nodes. nodes, err := c.Nodes() if err != nil { return nil, err } // Fetch the names of the nodes where the storage pool is defined. stmt := ` SELECT nodes.name FROM nodes LEFT JOIN storage_pools_nodes ON storage_pools_nodes.node_id = nodes.id LEFT JOIN storage_pools ON storage_pools_nodes.storage_pool_id = storage_pools.id WHERE storage_pools.id = ? AND storage_pools.state = ? ` defined, err := query.SelectStrings(c.tx, stmt, poolID, storagePoolPending) if err != nil { return nil, err } // Figure which nodes are missing missing := []string{} for _, node := range nodes { if !shared.StringInSlice(node.Name, defined) { missing = append(missing, node.Name) } } if len(missing) > 0 { return nil, fmt.Errorf("Pool not defined on nodes: %s", strings.Join(missing, ", ")) } configs := map[string]map[string]string{} for _, node := range nodes { config, err := query.SelectConfig( c.tx, "storage_pools_config", "storage_pool_id=? AND node_id=?", poolID, node.ID) if err != nil { return nil, err } configs[node.Name] = config } return configs, nil }
[ "func", "(", "c", "*", "ClusterTx", ")", "StoragePoolNodeConfigs", "(", "poolID", "int64", ")", "(", "map", "[", "string", "]", "map", "[", "string", "]", "string", ",", "error", ")", "{", "nodes", ",", "err", ":=", "c", ".", "Nodes", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "stmt", ":=", "`SELECT nodes.name FROM nodes LEFT JOIN storage_pools_nodes ON storage_pools_nodes.node_id = nodes.id LEFT JOIN storage_pools ON storage_pools_nodes.storage_pool_id = storage_pools.idWHERE storage_pools.id = ? AND storage_pools.state = ?`", "\n", "defined", ",", "err", ":=", "query", ".", "SelectStrings", "(", "c", ".", "tx", ",", "stmt", ",", "poolID", ",", "storagePoolPending", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "missing", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "node", ":=", "range", "nodes", "{", "if", "!", "shared", ".", "StringInSlice", "(", "node", ".", "Name", ",", "defined", ")", "{", "missing", "=", "append", "(", "missing", ",", "node", ".", "Name", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "missing", ")", ">", "0", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"Pool not defined on nodes: %s\"", ",", "strings", ".", "Join", "(", "missing", ",", "\", \"", ")", ")", "\n", "}", "\n", "configs", ":=", "map", "[", "string", "]", "map", "[", "string", "]", "string", "{", "}", "\n", "for", "_", ",", "node", ":=", "range", "nodes", "{", "config", ",", "err", ":=", "query", ".", "SelectConfig", "(", "c", ".", "tx", ",", "\"storage_pools_config\"", ",", "\"storage_pool_id=? AND node_id=?\"", ",", "poolID", ",", "node", ".", "ID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "configs", "[", "node", ".", "Name", "]", "=", "config", "\n", "}", "\n", "return", "configs", ",", "nil", "\n", "}" ]
// StoragePoolNodeConfigs returns the node-specific configuration of all // nodes grouped by node name, for the given poolID. // // If the storage pool is not defined on all nodes, an error is returned.
[ "StoragePoolNodeConfigs", "returns", "the", "node", "-", "specific", "configuration", "of", "all", "nodes", "grouped", "by", "node", "name", "for", "the", "given", "poolID", ".", "If", "the", "storage", "pool", "is", "not", "defined", "on", "all", "nodes", "an", "error", "is", "returned", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L306-L348
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolsGetDrivers
func (c *Cluster) StoragePoolsGetDrivers() ([]string, error) { var poolDriver string query := "SELECT DISTINCT driver FROM storage_pools" inargs := []interface{}{} outargs := []interface{}{poolDriver} result, err := queryScan(c.db, query, inargs, outargs) if err != nil { return []string{}, err } if len(result) == 0 { return []string{}, ErrNoSuchObject } drivers := []string{} for _, driver := range result { drivers = append(drivers, driver[0].(string)) } return drivers, nil }
go
func (c *Cluster) StoragePoolsGetDrivers() ([]string, error) { var poolDriver string query := "SELECT DISTINCT driver FROM storage_pools" inargs := []interface{}{} outargs := []interface{}{poolDriver} result, err := queryScan(c.db, query, inargs, outargs) if err != nil { return []string{}, err } if len(result) == 0 { return []string{}, ErrNoSuchObject } drivers := []string{} for _, driver := range result { drivers = append(drivers, driver[0].(string)) } return drivers, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolsGetDrivers", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "poolDriver", "string", "\n", "query", ":=", "\"SELECT DISTINCT driver FROM storage_pools\"", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "}", "\n", "outargs", ":=", "[", "]", "interface", "{", "}", "{", "poolDriver", "}", "\n", "result", ",", "err", ":=", "queryScan", "(", "c", ".", "db", ",", "query", ",", "inargs", ",", "outargs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "string", "{", "}", ",", "err", "\n", "}", "\n", "if", "len", "(", "result", ")", "==", "0", "{", "return", "[", "]", "string", "{", "}", ",", "ErrNoSuchObject", "\n", "}", "\n", "drivers", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "driver", ":=", "range", "result", "{", "drivers", "=", "append", "(", "drivers", ",", "driver", "[", "0", "]", ".", "(", "string", ")", ")", "\n", "}", "\n", "return", "drivers", ",", "nil", "\n", "}" ]
// StoragePoolsGetDrivers returns the names of all storage volumes attached to // a given storage pool.
[ "StoragePoolsGetDrivers", "returns", "the", "names", "of", "all", "storage", "volumes", "attached", "to", "a", "given", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L394-L415
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolGetID
func (c *Cluster) StoragePoolGetID(poolName string) (int64, error) { poolID := int64(-1) query := "SELECT id FROM storage_pools WHERE name=?" inargs := []interface{}{poolName} outargs := []interface{}{&poolID} err := dbQueryRowScan(c.db, query, inargs, outargs) if err != nil { if err == sql.ErrNoRows { return -1, ErrNoSuchObject } } return poolID, nil }
go
func (c *Cluster) StoragePoolGetID(poolName string) (int64, error) { poolID := int64(-1) query := "SELECT id FROM storage_pools WHERE name=?" inargs := []interface{}{poolName} outargs := []interface{}{&poolID} err := dbQueryRowScan(c.db, query, inargs, outargs) if err != nil { if err == sql.ErrNoRows { return -1, ErrNoSuchObject } } return poolID, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolGetID", "(", "poolName", "string", ")", "(", "int64", ",", "error", ")", "{", "poolID", ":=", "int64", "(", "-", "1", ")", "\n", "query", ":=", "\"SELECT id FROM storage_pools WHERE name=?\"", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "poolName", "}", "\n", "outargs", ":=", "[", "]", "interface", "{", "}", "{", "&", "poolID", "}", "\n", "err", ":=", "dbQueryRowScan", "(", "c", ".", "db", ",", "query", ",", "inargs", ",", "outargs", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "sql", ".", "ErrNoRows", "{", "return", "-", "1", ",", "ErrNoSuchObject", "\n", "}", "\n", "}", "\n", "return", "poolID", ",", "nil", "\n", "}" ]
// StoragePoolGetID returns the id of a single storage pool.
[ "StoragePoolGetID", "returns", "the", "id", "of", "a", "single", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L418-L432
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolGet
func (c *Cluster) StoragePoolGet(poolName string) (int64, *api.StoragePool, error) { var poolDriver string poolID := int64(-1) description := sql.NullString{} var state int query := "SELECT id, driver, description, state FROM storage_pools WHERE name=?" inargs := []interface{}{poolName} outargs := []interface{}{&poolID, &poolDriver, &description, &state} err := dbQueryRowScan(c.db, query, inargs, outargs) if err != nil { if err == sql.ErrNoRows { return -1, nil, ErrNoSuchObject } return -1, nil, err } config, err := c.StoragePoolConfigGet(poolID) if err != nil { return -1, nil, err } storagePool := api.StoragePool{ Name: poolName, Driver: poolDriver, } storagePool.Description = description.String storagePool.Config = config switch state { case storagePoolPending: storagePool.Status = "Pending" case storagePoolCreated: storagePool.Status = "Created" default: storagePool.Status = "Unknown" } nodes, err := c.storagePoolNodes(poolID) if err != nil { return -1, nil, err } storagePool.Locations = nodes return poolID, &storagePool, nil }
go
func (c *Cluster) StoragePoolGet(poolName string) (int64, *api.StoragePool, error) { var poolDriver string poolID := int64(-1) description := sql.NullString{} var state int query := "SELECT id, driver, description, state FROM storage_pools WHERE name=?" inargs := []interface{}{poolName} outargs := []interface{}{&poolID, &poolDriver, &description, &state} err := dbQueryRowScan(c.db, query, inargs, outargs) if err != nil { if err == sql.ErrNoRows { return -1, nil, ErrNoSuchObject } return -1, nil, err } config, err := c.StoragePoolConfigGet(poolID) if err != nil { return -1, nil, err } storagePool := api.StoragePool{ Name: poolName, Driver: poolDriver, } storagePool.Description = description.String storagePool.Config = config switch state { case storagePoolPending: storagePool.Status = "Pending" case storagePoolCreated: storagePool.Status = "Created" default: storagePool.Status = "Unknown" } nodes, err := c.storagePoolNodes(poolID) if err != nil { return -1, nil, err } storagePool.Locations = nodes return poolID, &storagePool, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolGet", "(", "poolName", "string", ")", "(", "int64", ",", "*", "api", ".", "StoragePool", ",", "error", ")", "{", "var", "poolDriver", "string", "\n", "poolID", ":=", "int64", "(", "-", "1", ")", "\n", "description", ":=", "sql", ".", "NullString", "{", "}", "\n", "var", "state", "int", "\n", "query", ":=", "\"SELECT id, driver, description, state FROM storage_pools WHERE name=?\"", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "poolName", "}", "\n", "outargs", ":=", "[", "]", "interface", "{", "}", "{", "&", "poolID", ",", "&", "poolDriver", ",", "&", "description", ",", "&", "state", "}", "\n", "err", ":=", "dbQueryRowScan", "(", "c", ".", "db", ",", "query", ",", "inargs", ",", "outargs", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "sql", ".", "ErrNoRows", "{", "return", "-", "1", ",", "nil", ",", "ErrNoSuchObject", "\n", "}", "\n", "return", "-", "1", ",", "nil", ",", "err", "\n", "}", "\n", "config", ",", "err", ":=", "c", ".", "StoragePoolConfigGet", "(", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "nil", ",", "err", "\n", "}", "\n", "storagePool", ":=", "api", ".", "StoragePool", "{", "Name", ":", "poolName", ",", "Driver", ":", "poolDriver", ",", "}", "\n", "storagePool", ".", "Description", "=", "description", ".", "String", "\n", "storagePool", ".", "Config", "=", "config", "\n", "switch", "state", "{", "case", "storagePoolPending", ":", "storagePool", ".", "Status", "=", "\"Pending\"", "\n", "case", "storagePoolCreated", ":", "storagePool", ".", "Status", "=", "\"Created\"", "\n", "default", ":", "storagePool", ".", "Status", "=", "\"Unknown\"", "\n", "}", "\n", "nodes", ",", "err", ":=", "c", ".", "storagePoolNodes", "(", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "nil", ",", "err", "\n", "}", "\n", "storagePool", ".", "Locations", "=", "nodes", "\n", "return", "poolID", ",", "&", "storagePool", ",", "nil", "\n", "}" ]
// StoragePoolGet returns a single storage pool.
[ "StoragePoolGet", "returns", "a", "single", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L435-L481
test
lxc/lxd
lxd/db/storage_pools.go
storagePoolNodes
func (c *Cluster) storagePoolNodes(poolID int64) ([]string, error) { stmt := ` SELECT nodes.name FROM nodes JOIN storage_pools_nodes ON storage_pools_nodes.node_id = nodes.id WHERE storage_pools_nodes.storage_pool_id = ? ` var nodes []string err := c.Transaction(func(tx *ClusterTx) error { var err error nodes, err = query.SelectStrings(tx.tx, stmt, poolID) return err }) if err != nil { return nil, err } return nodes, nil }
go
func (c *Cluster) storagePoolNodes(poolID int64) ([]string, error) { stmt := ` SELECT nodes.name FROM nodes JOIN storage_pools_nodes ON storage_pools_nodes.node_id = nodes.id WHERE storage_pools_nodes.storage_pool_id = ? ` var nodes []string err := c.Transaction(func(tx *ClusterTx) error { var err error nodes, err = query.SelectStrings(tx.tx, stmt, poolID) return err }) if err != nil { return nil, err } return nodes, nil }
[ "func", "(", "c", "*", "Cluster", ")", "storagePoolNodes", "(", "poolID", "int64", ")", "(", "[", "]", "string", ",", "error", ")", "{", "stmt", ":=", "`SELECT nodes.name FROM nodes JOIN storage_pools_nodes ON storage_pools_nodes.node_id = nodes.id WHERE storage_pools_nodes.storage_pool_id = ?`", "\n", "var", "nodes", "[", "]", "string", "\n", "err", ":=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "ClusterTx", ")", "error", "{", "var", "err", "error", "\n", "nodes", ",", "err", "=", "query", ".", "SelectStrings", "(", "tx", ".", "tx", ",", "stmt", ",", "poolID", ")", "\n", "return", "err", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "nodes", ",", "nil", "\n", "}" ]
// Return the names of the nodes the given pool is defined on.
[ "Return", "the", "names", "of", "the", "nodes", "the", "given", "pool", "is", "defined", "on", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L484-L500
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolConfigGet
func (c *Cluster) StoragePoolConfigGet(poolID int64) (map[string]string, error) { var key, value string query := "SELECT key, value FROM storage_pools_config WHERE storage_pool_id=? AND (node_id=? OR node_id IS NULL)" inargs := []interface{}{poolID, c.nodeID} outargs := []interface{}{key, value} results, err := queryScan(c.db, query, inargs, outargs) if err != nil { return nil, err } config := map[string]string{} for _, r := range results { key = r[0].(string) value = r[1].(string) config[key] = value } return config, nil }
go
func (c *Cluster) StoragePoolConfigGet(poolID int64) (map[string]string, error) { var key, value string query := "SELECT key, value FROM storage_pools_config WHERE storage_pool_id=? AND (node_id=? OR node_id IS NULL)" inargs := []interface{}{poolID, c.nodeID} outargs := []interface{}{key, value} results, err := queryScan(c.db, query, inargs, outargs) if err != nil { return nil, err } config := map[string]string{} for _, r := range results { key = r[0].(string) value = r[1].(string) config[key] = value } return config, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolConfigGet", "(", "poolID", "int64", ")", "(", "map", "[", "string", "]", "string", ",", "error", ")", "{", "var", "key", ",", "value", "string", "\n", "query", ":=", "\"SELECT key, value FROM storage_pools_config WHERE storage_pool_id=? AND (node_id=? OR node_id IS NULL)\"", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "poolID", ",", "c", ".", "nodeID", "}", "\n", "outargs", ":=", "[", "]", "interface", "{", "}", "{", "key", ",", "value", "}", "\n", "results", ",", "err", ":=", "queryScan", "(", "c", ".", "db", ",", "query", ",", "inargs", ",", "outargs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "config", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "for", "_", ",", "r", ":=", "range", "results", "{", "key", "=", "r", "[", "0", "]", ".", "(", "string", ")", "\n", "value", "=", "r", "[", "1", "]", ".", "(", "string", ")", "\n", "config", "[", "key", "]", "=", "value", "\n", "}", "\n", "return", "config", ",", "nil", "\n", "}" ]
// StoragePoolConfigGet returns the config of a storage pool.
[ "StoragePoolConfigGet", "returns", "the", "config", "of", "a", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L503-L524
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolCreate
func (c *Cluster) StoragePoolCreate(poolName string, poolDescription string, poolDriver string, poolConfig map[string]string) (int64, error) { var id int64 err := c.Transaction(func(tx *ClusterTx) error { result, err := tx.tx.Exec("INSERT INTO storage_pools (name, description, driver, state) VALUES (?, ?, ?, ?)", poolName, poolDescription, poolDriver, storagePoolCreated) if err != nil { return err } id, err = result.LastInsertId() if err != nil { return err } // Insert a node-specific entry pointing to ourselves. columns := []string{"storage_pool_id", "node_id"} values := []interface{}{id, c.nodeID} _, err = query.UpsertObject(tx.tx, "storage_pools_nodes", columns, values) if err != nil { return err } err = storagePoolConfigAdd(tx.tx, id, c.nodeID, poolConfig) if err != nil { return err } return nil }) if err != nil { id = -1 } return id, nil }
go
func (c *Cluster) StoragePoolCreate(poolName string, poolDescription string, poolDriver string, poolConfig map[string]string) (int64, error) { var id int64 err := c.Transaction(func(tx *ClusterTx) error { result, err := tx.tx.Exec("INSERT INTO storage_pools (name, description, driver, state) VALUES (?, ?, ?, ?)", poolName, poolDescription, poolDriver, storagePoolCreated) if err != nil { return err } id, err = result.LastInsertId() if err != nil { return err } // Insert a node-specific entry pointing to ourselves. columns := []string{"storage_pool_id", "node_id"} values := []interface{}{id, c.nodeID} _, err = query.UpsertObject(tx.tx, "storage_pools_nodes", columns, values) if err != nil { return err } err = storagePoolConfigAdd(tx.tx, id, c.nodeID, poolConfig) if err != nil { return err } return nil }) if err != nil { id = -1 } return id, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolCreate", "(", "poolName", "string", ",", "poolDescription", "string", ",", "poolDriver", "string", ",", "poolConfig", "map", "[", "string", "]", "string", ")", "(", "int64", ",", "error", ")", "{", "var", "id", "int64", "\n", "err", ":=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "ClusterTx", ")", "error", "{", "result", ",", "err", ":=", "tx", ".", "tx", ".", "Exec", "(", "\"INSERT INTO storage_pools (name, description, driver, state) VALUES (?, ?, ?, ?)\"", ",", "poolName", ",", "poolDescription", ",", "poolDriver", ",", "storagePoolCreated", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "id", ",", "err", "=", "result", ".", "LastInsertId", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "columns", ":=", "[", "]", "string", "{", "\"storage_pool_id\"", ",", "\"node_id\"", "}", "\n", "values", ":=", "[", "]", "interface", "{", "}", "{", "id", ",", "c", ".", "nodeID", "}", "\n", "_", ",", "err", "=", "query", ".", "UpsertObject", "(", "tx", ".", "tx", ",", "\"storage_pools_nodes\"", ",", "columns", ",", "values", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "storagePoolConfigAdd", "(", "tx", ".", "tx", ",", "id", ",", "c", ".", "nodeID", ",", "poolConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "id", "=", "-", "1", "\n", "}", "\n", "return", "id", ",", "nil", "\n", "}" ]
// StoragePoolCreate creates new storage pool.
[ "StoragePoolCreate", "creates", "new", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L527-L559
test
lxc/lxd
lxd/db/storage_pools.go
storagePoolConfigAdd
func storagePoolConfigAdd(tx *sql.Tx, poolID, nodeID int64, poolConfig map[string]string) error { str := "INSERT INTO storage_pools_config (storage_pool_id, node_id, key, value) VALUES(?, ?, ?, ?)" stmt, err := tx.Prepare(str) defer stmt.Close() if err != nil { return err } for k, v := range poolConfig { if v == "" { continue } var nodeIDValue interface{} if !shared.StringInSlice(k, StoragePoolNodeConfigKeys) { nodeIDValue = nil } else { nodeIDValue = nodeID } _, err = stmt.Exec(poolID, nodeIDValue, k, v) if err != nil { return err } } return nil }
go
func storagePoolConfigAdd(tx *sql.Tx, poolID, nodeID int64, poolConfig map[string]string) error { str := "INSERT INTO storage_pools_config (storage_pool_id, node_id, key, value) VALUES(?, ?, ?, ?)" stmt, err := tx.Prepare(str) defer stmt.Close() if err != nil { return err } for k, v := range poolConfig { if v == "" { continue } var nodeIDValue interface{} if !shared.StringInSlice(k, StoragePoolNodeConfigKeys) { nodeIDValue = nil } else { nodeIDValue = nodeID } _, err = stmt.Exec(poolID, nodeIDValue, k, v) if err != nil { return err } } return nil }
[ "func", "storagePoolConfigAdd", "(", "tx", "*", "sql", ".", "Tx", ",", "poolID", ",", "nodeID", "int64", ",", "poolConfig", "map", "[", "string", "]", "string", ")", "error", "{", "str", ":=", "\"INSERT INTO storage_pools_config (storage_pool_id, node_id, key, value) VALUES(?, ?, ?, ?)\"", "\n", "stmt", ",", "err", ":=", "tx", ".", "Prepare", "(", "str", ")", "\n", "defer", "stmt", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "for", "k", ",", "v", ":=", "range", "poolConfig", "{", "if", "v", "==", "\"\"", "{", "continue", "\n", "}", "\n", "var", "nodeIDValue", "interface", "{", "}", "\n", "if", "!", "shared", ".", "StringInSlice", "(", "k", ",", "StoragePoolNodeConfigKeys", ")", "{", "nodeIDValue", "=", "nil", "\n", "}", "else", "{", "nodeIDValue", "=", "nodeID", "\n", "}", "\n", "_", ",", "err", "=", "stmt", ".", "Exec", "(", "poolID", ",", "nodeIDValue", ",", "k", ",", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Add new storage pool config.
[ "Add", "new", "storage", "pool", "config", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L562-L588
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolUpdate
func (c *Cluster) StoragePoolUpdate(poolName, description string, poolConfig map[string]string) error { poolID, _, err := c.StoragePoolGet(poolName) if err != nil { return err } err = c.Transaction(func(tx *ClusterTx) error { err = StoragePoolUpdateDescription(tx.tx, poolID, description) if err != nil { return err } err = StoragePoolConfigClear(tx.tx, poolID, c.nodeID) if err != nil { return err } err = storagePoolConfigAdd(tx.tx, poolID, c.nodeID, poolConfig) if err != nil { return err } return nil }) return err }
go
func (c *Cluster) StoragePoolUpdate(poolName, description string, poolConfig map[string]string) error { poolID, _, err := c.StoragePoolGet(poolName) if err != nil { return err } err = c.Transaction(func(tx *ClusterTx) error { err = StoragePoolUpdateDescription(tx.tx, poolID, description) if err != nil { return err } err = StoragePoolConfigClear(tx.tx, poolID, c.nodeID) if err != nil { return err } err = storagePoolConfigAdd(tx.tx, poolID, c.nodeID, poolConfig) if err != nil { return err } return nil }) return err }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolUpdate", "(", "poolName", ",", "description", "string", ",", "poolConfig", "map", "[", "string", "]", "string", ")", "error", "{", "poolID", ",", "_", ",", "err", ":=", "c", ".", "StoragePoolGet", "(", "poolName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "ClusterTx", ")", "error", "{", "err", "=", "StoragePoolUpdateDescription", "(", "tx", ".", "tx", ",", "poolID", ",", "description", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "StoragePoolConfigClear", "(", "tx", ".", "tx", ",", "poolID", ",", "c", ".", "nodeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "storagePoolConfigAdd", "(", "tx", ".", "tx", ",", "poolID", ",", "c", ".", "nodeID", ",", "poolConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "err", "\n", "}" ]
// StoragePoolUpdate updates a storage pool.
[ "StoragePoolUpdate", "updates", "a", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L608-L633
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolConfigClear
func StoragePoolConfigClear(tx *sql.Tx, poolID, nodeID int64) error { _, err := tx.Exec("DELETE FROM storage_pools_config WHERE storage_pool_id=? AND (node_id=? OR node_id IS NULL)", poolID, nodeID) if err != nil { return err } return nil }
go
func StoragePoolConfigClear(tx *sql.Tx, poolID, nodeID int64) error { _, err := tx.Exec("DELETE FROM storage_pools_config WHERE storage_pool_id=? AND (node_id=? OR node_id IS NULL)", poolID, nodeID) if err != nil { return err } return nil }
[ "func", "StoragePoolConfigClear", "(", "tx", "*", "sql", ".", "Tx", ",", "poolID", ",", "nodeID", "int64", ")", "error", "{", "_", ",", "err", ":=", "tx", ".", "Exec", "(", "\"DELETE FROM storage_pools_config WHERE storage_pool_id=? AND (node_id=? OR node_id IS NULL)\"", ",", "poolID", ",", "nodeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// StoragePoolConfigClear deletes the storage pool config.
[ "StoragePoolConfigClear", "deletes", "the", "storage", "pool", "config", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L642-L649
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolDelete
func (c *Cluster) StoragePoolDelete(poolName string) (*api.StoragePool, error) { poolID, pool, err := c.StoragePoolGet(poolName) if err != nil { return nil, err } err = exec(c.db, "DELETE FROM storage_pools WHERE id=?", poolID) if err != nil { return nil, err } return pool, nil }
go
func (c *Cluster) StoragePoolDelete(poolName string) (*api.StoragePool, error) { poolID, pool, err := c.StoragePoolGet(poolName) if err != nil { return nil, err } err = exec(c.db, "DELETE FROM storage_pools WHERE id=?", poolID) if err != nil { return nil, err } return pool, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolDelete", "(", "poolName", "string", ")", "(", "*", "api", ".", "StoragePool", ",", "error", ")", "{", "poolID", ",", "pool", ",", "err", ":=", "c", ".", "StoragePoolGet", "(", "poolName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "err", "=", "exec", "(", "c", ".", "db", ",", "\"DELETE FROM storage_pools WHERE id=?\"", ",", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "pool", ",", "nil", "\n", "}" ]
// StoragePoolDelete deletes storage pool.
[ "StoragePoolDelete", "deletes", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L652-L664
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumesGetNames
func (c *Cluster) StoragePoolVolumesGetNames(poolID int64) ([]string, error) { var volumeName string query := "SELECT name FROM storage_volumes WHERE storage_pool_id=? AND node_id=?" inargs := []interface{}{poolID, c.nodeID} outargs := []interface{}{volumeName} result, err := queryScan(c.db, query, inargs, outargs) if err != nil { return []string{}, err } var out []string for _, r := range result { out = append(out, r[0].(string)) } return out, nil }
go
func (c *Cluster) StoragePoolVolumesGetNames(poolID int64) ([]string, error) { var volumeName string query := "SELECT name FROM storage_volumes WHERE storage_pool_id=? AND node_id=?" inargs := []interface{}{poolID, c.nodeID} outargs := []interface{}{volumeName} result, err := queryScan(c.db, query, inargs, outargs) if err != nil { return []string{}, err } var out []string for _, r := range result { out = append(out, r[0].(string)) } return out, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumesGetNames", "(", "poolID", "int64", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "volumeName", "string", "\n", "query", ":=", "\"SELECT name FROM storage_volumes WHERE storage_pool_id=? AND node_id=?\"", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "poolID", ",", "c", ".", "nodeID", "}", "\n", "outargs", ":=", "[", "]", "interface", "{", "}", "{", "volumeName", "}", "\n", "result", ",", "err", ":=", "queryScan", "(", "c", ".", "db", ",", "query", ",", "inargs", ",", "outargs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "string", "{", "}", ",", "err", "\n", "}", "\n", "var", "out", "[", "]", "string", "\n", "for", "_", ",", "r", ":=", "range", "result", "{", "out", "=", "append", "(", "out", ",", "r", "[", "0", "]", ".", "(", "string", ")", ")", "\n", "}", "\n", "return", "out", ",", "nil", "\n", "}" ]
// StoragePoolVolumesGetNames gets the names of all storage volumes attached to // a given storage pool.
[ "StoragePoolVolumesGetNames", "gets", "the", "names", "of", "all", "storage", "volumes", "attached", "to", "a", "given", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L668-L686
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumesGet
func (c *Cluster) StoragePoolVolumesGet(project string, poolID int64, volumeTypes []int) ([]*api.StorageVolume, error) { var nodeIDs []int err := c.Transaction(func(tx *ClusterTx) error { var err error nodeIDs, err = query.SelectIntegers(tx.tx, ` SELECT DISTINCT node_id FROM storage_volumes JOIN projects ON projects.id = storage_volumes.project_id WHERE (projects.name=? OR storage_volumes.type=?) AND storage_pool_id=? `, project, StoragePoolVolumeTypeCustom, poolID) return err }) if err != nil { return nil, err } volumes := []*api.StorageVolume{} for _, nodeID := range nodeIDs { nodeVolumes, err := c.storagePoolVolumesGet(project, poolID, int64(nodeID), volumeTypes) if err != nil { return nil, err } volumes = append(volumes, nodeVolumes...) } return volumes, nil }
go
func (c *Cluster) StoragePoolVolumesGet(project string, poolID int64, volumeTypes []int) ([]*api.StorageVolume, error) { var nodeIDs []int err := c.Transaction(func(tx *ClusterTx) error { var err error nodeIDs, err = query.SelectIntegers(tx.tx, ` SELECT DISTINCT node_id FROM storage_volumes JOIN projects ON projects.id = storage_volumes.project_id WHERE (projects.name=? OR storage_volumes.type=?) AND storage_pool_id=? `, project, StoragePoolVolumeTypeCustom, poolID) return err }) if err != nil { return nil, err } volumes := []*api.StorageVolume{} for _, nodeID := range nodeIDs { nodeVolumes, err := c.storagePoolVolumesGet(project, poolID, int64(nodeID), volumeTypes) if err != nil { return nil, err } volumes = append(volumes, nodeVolumes...) } return volumes, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumesGet", "(", "project", "string", ",", "poolID", "int64", ",", "volumeTypes", "[", "]", "int", ")", "(", "[", "]", "*", "api", ".", "StorageVolume", ",", "error", ")", "{", "var", "nodeIDs", "[", "]", "int", "\n", "err", ":=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "ClusterTx", ")", "error", "{", "var", "err", "error", "\n", "nodeIDs", ",", "err", "=", "query", ".", "SelectIntegers", "(", "tx", ".", "tx", ",", "`SELECT DISTINCT node_id FROM storage_volumes JOIN projects ON projects.id = storage_volumes.project_id WHERE (projects.name=? OR storage_volumes.type=?) AND storage_pool_id=?`", ",", "project", ",", "StoragePoolVolumeTypeCustom", ",", "poolID", ")", "\n", "return", "err", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "volumes", ":=", "[", "]", "*", "api", ".", "StorageVolume", "{", "}", "\n", "for", "_", ",", "nodeID", ":=", "range", "nodeIDs", "{", "nodeVolumes", ",", "err", ":=", "c", ".", "storagePoolVolumesGet", "(", "project", ",", "poolID", ",", "int64", "(", "nodeID", ")", ",", "volumeTypes", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "volumes", "=", "append", "(", "volumes", ",", "nodeVolumes", "...", ")", "\n", "}", "\n", "return", "volumes", ",", "nil", "\n", "}" ]
// StoragePoolVolumesGet returns all storage volumes attached to a given // storage pool on any node.
[ "StoragePoolVolumesGet", "returns", "all", "storage", "volumes", "attached", "to", "a", "given", "storage", "pool", "on", "any", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L690-L716
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolNodeVolumesGet
func (c *Cluster) StoragePoolNodeVolumesGet(poolID int64, volumeTypes []int) ([]*api.StorageVolume, error) { return c.storagePoolVolumesGet("default", poolID, c.nodeID, volumeTypes) }
go
func (c *Cluster) StoragePoolNodeVolumesGet(poolID int64, volumeTypes []int) ([]*api.StorageVolume, error) { return c.storagePoolVolumesGet("default", poolID, c.nodeID, volumeTypes) }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolNodeVolumesGet", "(", "poolID", "int64", ",", "volumeTypes", "[", "]", "int", ")", "(", "[", "]", "*", "api", ".", "StorageVolume", ",", "error", ")", "{", "return", "c", ".", "storagePoolVolumesGet", "(", "\"default\"", ",", "poolID", ",", "c", ".", "nodeID", ",", "volumeTypes", ")", "\n", "}" ]
// StoragePoolNodeVolumesGet returns all storage volumes attached to a given // storage pool on the current node.
[ "StoragePoolNodeVolumesGet", "returns", "all", "storage", "volumes", "attached", "to", "a", "given", "storage", "pool", "on", "the", "current", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L720-L722
test
lxc/lxd
lxd/db/storage_pools.go
storagePoolVolumesGet
func (c *Cluster) storagePoolVolumesGet(project string, poolID, nodeID int64, volumeTypes []int) ([]*api.StorageVolume, error) { // Get all storage volumes of all types attached to a given storage // pool. result := []*api.StorageVolume{} for _, volumeType := range volumeTypes { volumeNames, err := c.StoragePoolVolumesGetType(project, volumeType, poolID, nodeID) if err != nil && err != sql.ErrNoRows { return nil, errors.Wrap(err, "failed to fetch volume types") } for _, volumeName := range volumeNames { _, volume, err := c.StoragePoolVolumeGetType(project, volumeName, volumeType, poolID, nodeID) if err != nil { return nil, errors.Wrap(err, "failed to fetch volume type") } result = append(result, volume) } } if len(result) == 0 { return result, ErrNoSuchObject } return result, nil }
go
func (c *Cluster) storagePoolVolumesGet(project string, poolID, nodeID int64, volumeTypes []int) ([]*api.StorageVolume, error) { // Get all storage volumes of all types attached to a given storage // pool. result := []*api.StorageVolume{} for _, volumeType := range volumeTypes { volumeNames, err := c.StoragePoolVolumesGetType(project, volumeType, poolID, nodeID) if err != nil && err != sql.ErrNoRows { return nil, errors.Wrap(err, "failed to fetch volume types") } for _, volumeName := range volumeNames { _, volume, err := c.StoragePoolVolumeGetType(project, volumeName, volumeType, poolID, nodeID) if err != nil { return nil, errors.Wrap(err, "failed to fetch volume type") } result = append(result, volume) } } if len(result) == 0 { return result, ErrNoSuchObject } return result, nil }
[ "func", "(", "c", "*", "Cluster", ")", "storagePoolVolumesGet", "(", "project", "string", ",", "poolID", ",", "nodeID", "int64", ",", "volumeTypes", "[", "]", "int", ")", "(", "[", "]", "*", "api", ".", "StorageVolume", ",", "error", ")", "{", "result", ":=", "[", "]", "*", "api", ".", "StorageVolume", "{", "}", "\n", "for", "_", ",", "volumeType", ":=", "range", "volumeTypes", "{", "volumeNames", ",", "err", ":=", "c", ".", "StoragePoolVolumesGetType", "(", "project", ",", "volumeType", ",", "poolID", ",", "nodeID", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "sql", ".", "ErrNoRows", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"failed to fetch volume types\"", ")", "\n", "}", "\n", "for", "_", ",", "volumeName", ":=", "range", "volumeNames", "{", "_", ",", "volume", ",", "err", ":=", "c", ".", "StoragePoolVolumeGetType", "(", "project", ",", "volumeName", ",", "volumeType", ",", "poolID", ",", "nodeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"failed to fetch volume type\"", ")", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "volume", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "result", ")", "==", "0", "{", "return", "result", ",", "ErrNoSuchObject", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// Returns all storage volumes attached to a given storage pool on the given // node.
[ "Returns", "all", "storage", "volumes", "attached", "to", "a", "given", "storage", "pool", "on", "the", "given", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L726-L749
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumesGetType
func (c *Cluster) StoragePoolVolumesGetType(project string, volumeType int, poolID, nodeID int64) ([]string, error) { var poolName string query := ` SELECT storage_volumes.name FROM storage_volumes JOIN projects ON projects.id=storage_volumes.project_id WHERE (projects.name=? OR storage_volumes.type=?) AND storage_pool_id=? AND node_id=? AND type=? ` inargs := []interface{}{project, StoragePoolVolumeTypeCustom, poolID, nodeID, volumeType} outargs := []interface{}{poolName} result, err := queryScan(c.db, query, inargs, outargs) if err != nil { return []string{}, err } response := []string{} for _, r := range result { response = append(response, r[0].(string)) } return response, nil }
go
func (c *Cluster) StoragePoolVolumesGetType(project string, volumeType int, poolID, nodeID int64) ([]string, error) { var poolName string query := ` SELECT storage_volumes.name FROM storage_volumes JOIN projects ON projects.id=storage_volumes.project_id WHERE (projects.name=? OR storage_volumes.type=?) AND storage_pool_id=? AND node_id=? AND type=? ` inargs := []interface{}{project, StoragePoolVolumeTypeCustom, poolID, nodeID, volumeType} outargs := []interface{}{poolName} result, err := queryScan(c.db, query, inargs, outargs) if err != nil { return []string{}, err } response := []string{} for _, r := range result { response = append(response, r[0].(string)) } return response, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumesGetType", "(", "project", "string", ",", "volumeType", "int", ",", "poolID", ",", "nodeID", "int64", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "poolName", "string", "\n", "query", ":=", "`SELECT storage_volumes.name FROM storage_volumes JOIN projects ON projects.id=storage_volumes.project_id WHERE (projects.name=? OR storage_volumes.type=?) AND storage_pool_id=? AND node_id=? AND type=?`", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "project", ",", "StoragePoolVolumeTypeCustom", ",", "poolID", ",", "nodeID", ",", "volumeType", "}", "\n", "outargs", ":=", "[", "]", "interface", "{", "}", "{", "poolName", "}", "\n", "result", ",", "err", ":=", "queryScan", "(", "c", ".", "db", ",", "query", ",", "inargs", ",", "outargs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "string", "{", "}", ",", "err", "\n", "}", "\n", "response", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "r", ":=", "range", "result", "{", "response", "=", "append", "(", "response", ",", "r", "[", "0", "]", ".", "(", "string", ")", ")", "\n", "}", "\n", "return", "response", ",", "nil", "\n", "}" ]
// StoragePoolVolumesGetType get all storage volumes attached to a given // storage pool of a given volume type, on the given node.
[ "StoragePoolVolumesGetType", "get", "all", "storage", "volumes", "attached", "to", "a", "given", "storage", "pool", "of", "a", "given", "volume", "type", "on", "the", "given", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L753-L775
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumeSnapshotsGetType
func (c *Cluster) StoragePoolVolumeSnapshotsGetType(volumeName string, volumeType int, poolID int64) ([]string, error) { result := []string{} regexp := volumeName + shared.SnapshotDelimiter length := len(regexp) query := "SELECT name FROM storage_volumes WHERE storage_pool_id=? AND node_id=? AND type=? AND snapshot=? AND SUBSTR(name,1,?)=?" inargs := []interface{}{poolID, c.nodeID, volumeType, true, length, regexp} outfmt := []interface{}{volumeName} dbResults, err := queryScan(c.db, query, inargs, outfmt) if err != nil { return result, err } for _, r := range dbResults { result = append(result, r[0].(string)) } return result, nil }
go
func (c *Cluster) StoragePoolVolumeSnapshotsGetType(volumeName string, volumeType int, poolID int64) ([]string, error) { result := []string{} regexp := volumeName + shared.SnapshotDelimiter length := len(regexp) query := "SELECT name FROM storage_volumes WHERE storage_pool_id=? AND node_id=? AND type=? AND snapshot=? AND SUBSTR(name,1,?)=?" inargs := []interface{}{poolID, c.nodeID, volumeType, true, length, regexp} outfmt := []interface{}{volumeName} dbResults, err := queryScan(c.db, query, inargs, outfmt) if err != nil { return result, err } for _, r := range dbResults { result = append(result, r[0].(string)) } return result, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumeSnapshotsGetType", "(", "volumeName", "string", ",", "volumeType", "int", ",", "poolID", "int64", ")", "(", "[", "]", "string", ",", "error", ")", "{", "result", ":=", "[", "]", "string", "{", "}", "\n", "regexp", ":=", "volumeName", "+", "shared", ".", "SnapshotDelimiter", "\n", "length", ":=", "len", "(", "regexp", ")", "\n", "query", ":=", "\"SELECT name FROM storage_volumes WHERE storage_pool_id=? AND node_id=? AND type=? AND snapshot=? AND SUBSTR(name,1,?)=?\"", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "poolID", ",", "c", ".", "nodeID", ",", "volumeType", ",", "true", ",", "length", ",", "regexp", "}", "\n", "outfmt", ":=", "[", "]", "interface", "{", "}", "{", "volumeName", "}", "\n", "dbResults", ",", "err", ":=", "queryScan", "(", "c", ".", "db", ",", "query", ",", "inargs", ",", "outfmt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "result", ",", "err", "\n", "}", "\n", "for", "_", ",", "r", ":=", "range", "dbResults", "{", "result", "=", "append", "(", "result", ",", "r", "[", "0", "]", ".", "(", "string", ")", ")", "\n", "}", "\n", "return", "result", ",", "nil", "\n", "}" ]
// StoragePoolVolumeSnapshotsGetType get all snapshots of a storage volume // attached to a given storage pool of a given volume type, on the given node.
[ "StoragePoolVolumeSnapshotsGetType", "get", "all", "snapshots", "of", "a", "storage", "volume", "attached", "to", "a", "given", "storage", "pool", "of", "a", "given", "volume", "type", "on", "the", "given", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L779-L798
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolNodeVolumesGetType
func (c *Cluster) StoragePoolNodeVolumesGetType(volumeType int, poolID int64) ([]string, error) { return c.StoragePoolVolumesGetType("default", volumeType, poolID, c.nodeID) }
go
func (c *Cluster) StoragePoolNodeVolumesGetType(volumeType int, poolID int64) ([]string, error) { return c.StoragePoolVolumesGetType("default", volumeType, poolID, c.nodeID) }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolNodeVolumesGetType", "(", "volumeType", "int", ",", "poolID", "int64", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "c", ".", "StoragePoolVolumesGetType", "(", "\"default\"", ",", "volumeType", ",", "poolID", ",", "c", ".", "nodeID", ")", "\n", "}" ]
// StoragePoolNodeVolumesGetType returns all storage volumes attached to a // given storage pool of a given volume type, on the current node.
[ "StoragePoolNodeVolumesGetType", "returns", "all", "storage", "volumes", "attached", "to", "a", "given", "storage", "pool", "of", "a", "given", "volume", "type", "on", "the", "current", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L802-L804
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumeGetType
func (c *Cluster) StoragePoolVolumeGetType(project string, volumeName string, volumeType int, poolID, nodeID int64) (int64, *api.StorageVolume, error) { // Custom volumes are "global", i.e. they are associated with the // default project. if volumeType == StoragePoolVolumeTypeCustom { project = "default" } volumeID, err := c.StoragePoolVolumeGetTypeID(project, volumeName, volumeType, poolID, nodeID) if err != nil { return -1, nil, err } volumeNode, err := c.StorageVolumeNodeGet(volumeID) if err != nil { return -1, nil, err } volumeConfig, err := c.StorageVolumeConfigGet(volumeID) if err != nil { return -1, nil, err } volumeDescription, err := c.StorageVolumeDescriptionGet(volumeID) if err != nil { return -1, nil, err } volumeTypeName, err := StoragePoolVolumeTypeToName(volumeType) if err != nil { return -1, nil, err } storageVolume := api.StorageVolume{ Type: volumeTypeName, } storageVolume.Name = volumeName storageVolume.Description = volumeDescription storageVolume.Config = volumeConfig storageVolume.Location = volumeNode return volumeID, &storageVolume, nil }
go
func (c *Cluster) StoragePoolVolumeGetType(project string, volumeName string, volumeType int, poolID, nodeID int64) (int64, *api.StorageVolume, error) { // Custom volumes are "global", i.e. they are associated with the // default project. if volumeType == StoragePoolVolumeTypeCustom { project = "default" } volumeID, err := c.StoragePoolVolumeGetTypeID(project, volumeName, volumeType, poolID, nodeID) if err != nil { return -1, nil, err } volumeNode, err := c.StorageVolumeNodeGet(volumeID) if err != nil { return -1, nil, err } volumeConfig, err := c.StorageVolumeConfigGet(volumeID) if err != nil { return -1, nil, err } volumeDescription, err := c.StorageVolumeDescriptionGet(volumeID) if err != nil { return -1, nil, err } volumeTypeName, err := StoragePoolVolumeTypeToName(volumeType) if err != nil { return -1, nil, err } storageVolume := api.StorageVolume{ Type: volumeTypeName, } storageVolume.Name = volumeName storageVolume.Description = volumeDescription storageVolume.Config = volumeConfig storageVolume.Location = volumeNode return volumeID, &storageVolume, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumeGetType", "(", "project", "string", ",", "volumeName", "string", ",", "volumeType", "int", ",", "poolID", ",", "nodeID", "int64", ")", "(", "int64", ",", "*", "api", ".", "StorageVolume", ",", "error", ")", "{", "if", "volumeType", "==", "StoragePoolVolumeTypeCustom", "{", "project", "=", "\"default\"", "\n", "}", "\n", "volumeID", ",", "err", ":=", "c", ".", "StoragePoolVolumeGetTypeID", "(", "project", ",", "volumeName", ",", "volumeType", ",", "poolID", ",", "nodeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "nil", ",", "err", "\n", "}", "\n", "volumeNode", ",", "err", ":=", "c", ".", "StorageVolumeNodeGet", "(", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "nil", ",", "err", "\n", "}", "\n", "volumeConfig", ",", "err", ":=", "c", ".", "StorageVolumeConfigGet", "(", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "nil", ",", "err", "\n", "}", "\n", "volumeDescription", ",", "err", ":=", "c", ".", "StorageVolumeDescriptionGet", "(", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "nil", ",", "err", "\n", "}", "\n", "volumeTypeName", ",", "err", ":=", "StoragePoolVolumeTypeToName", "(", "volumeType", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "nil", ",", "err", "\n", "}", "\n", "storageVolume", ":=", "api", ".", "StorageVolume", "{", "Type", ":", "volumeTypeName", ",", "}", "\n", "storageVolume", ".", "Name", "=", "volumeName", "\n", "storageVolume", ".", "Description", "=", "volumeDescription", "\n", "storageVolume", ".", "Config", "=", "volumeConfig", "\n", "storageVolume", ".", "Location", "=", "volumeNode", "\n", "return", "volumeID", ",", "&", "storageVolume", ",", "nil", "\n", "}" ]
// StoragePoolVolumeGetType returns a single storage volume attached to a // given storage pool of a given type, on the node with the given ID.
[ "StoragePoolVolumeGetType", "returns", "a", "single", "storage", "volume", "attached", "to", "a", "given", "storage", "pool", "of", "a", "given", "type", "on", "the", "node", "with", "the", "given", "ID", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L808-L849
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolNodeVolumeGetType
func (c *Cluster) StoragePoolNodeVolumeGetType(volumeName string, volumeType int, poolID int64) (int64, *api.StorageVolume, error) { return c.StoragePoolNodeVolumeGetTypeByProject("default", volumeName, volumeType, poolID) }
go
func (c *Cluster) StoragePoolNodeVolumeGetType(volumeName string, volumeType int, poolID int64) (int64, *api.StorageVolume, error) { return c.StoragePoolNodeVolumeGetTypeByProject("default", volumeName, volumeType, poolID) }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolNodeVolumeGetType", "(", "volumeName", "string", ",", "volumeType", "int", ",", "poolID", "int64", ")", "(", "int64", ",", "*", "api", ".", "StorageVolume", ",", "error", ")", "{", "return", "c", ".", "StoragePoolNodeVolumeGetTypeByProject", "(", "\"default\"", ",", "volumeName", ",", "volumeType", ",", "poolID", ")", "\n", "}" ]
// StoragePoolNodeVolumeGetType gets a single storage volume attached to a // given storage pool of a given type, on the current node.
[ "StoragePoolNodeVolumeGetType", "gets", "a", "single", "storage", "volume", "attached", "to", "a", "given", "storage", "pool", "of", "a", "given", "type", "on", "the", "current", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L853-L855
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolNodeVolumeGetTypeByProject
func (c *Cluster) StoragePoolNodeVolumeGetTypeByProject(project, volumeName string, volumeType int, poolID int64) (int64, *api.StorageVolume, error) { return c.StoragePoolVolumeGetType(project, volumeName, volumeType, poolID, c.nodeID) }
go
func (c *Cluster) StoragePoolNodeVolumeGetTypeByProject(project, volumeName string, volumeType int, poolID int64) (int64, *api.StorageVolume, error) { return c.StoragePoolVolumeGetType(project, volumeName, volumeType, poolID, c.nodeID) }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolNodeVolumeGetTypeByProject", "(", "project", ",", "volumeName", "string", ",", "volumeType", "int", ",", "poolID", "int64", ")", "(", "int64", ",", "*", "api", ".", "StorageVolume", ",", "error", ")", "{", "return", "c", ".", "StoragePoolVolumeGetType", "(", "project", ",", "volumeName", ",", "volumeType", ",", "poolID", ",", "c", ".", "nodeID", ")", "\n", "}" ]
// StoragePoolNodeVolumeGetTypeByProject gets a single storage volume attached to a // given storage pool of a given type, on the current node in the given project.
[ "StoragePoolNodeVolumeGetTypeByProject", "gets", "a", "single", "storage", "volume", "attached", "to", "a", "given", "storage", "pool", "of", "a", "given", "type", "on", "the", "current", "node", "in", "the", "given", "project", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L859-L861
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumeUpdate
func (c *Cluster) StoragePoolVolumeUpdate(volumeName string, volumeType int, poolID int64, volumeDescription string, volumeConfig map[string]string) error { volumeID, _, err := c.StoragePoolNodeVolumeGetType(volumeName, volumeType, poolID) if err != nil { return err } err = c.Transaction(func(tx *ClusterTx) error { err = storagePoolVolumeReplicateIfCeph(tx.tx, volumeID, "default", volumeName, volumeType, poolID, func(volumeID int64) error { err = StorageVolumeConfigClear(tx.tx, volumeID) if err != nil { return err } err = StorageVolumeConfigAdd(tx.tx, volumeID, volumeConfig) if err != nil { return err } return StorageVolumeDescriptionUpdate(tx.tx, volumeID, volumeDescription) }) if err != nil { return err } return nil }) return err }
go
func (c *Cluster) StoragePoolVolumeUpdate(volumeName string, volumeType int, poolID int64, volumeDescription string, volumeConfig map[string]string) error { volumeID, _, err := c.StoragePoolNodeVolumeGetType(volumeName, volumeType, poolID) if err != nil { return err } err = c.Transaction(func(tx *ClusterTx) error { err = storagePoolVolumeReplicateIfCeph(tx.tx, volumeID, "default", volumeName, volumeType, poolID, func(volumeID int64) error { err = StorageVolumeConfigClear(tx.tx, volumeID) if err != nil { return err } err = StorageVolumeConfigAdd(tx.tx, volumeID, volumeConfig) if err != nil { return err } return StorageVolumeDescriptionUpdate(tx.tx, volumeID, volumeDescription) }) if err != nil { return err } return nil }) return err }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumeUpdate", "(", "volumeName", "string", ",", "volumeType", "int", ",", "poolID", "int64", ",", "volumeDescription", "string", ",", "volumeConfig", "map", "[", "string", "]", "string", ")", "error", "{", "volumeID", ",", "_", ",", "err", ":=", "c", ".", "StoragePoolNodeVolumeGetType", "(", "volumeName", ",", "volumeType", ",", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "ClusterTx", ")", "error", "{", "err", "=", "storagePoolVolumeReplicateIfCeph", "(", "tx", ".", "tx", ",", "volumeID", ",", "\"default\"", ",", "volumeName", ",", "volumeType", ",", "poolID", ",", "func", "(", "volumeID", "int64", ")", "error", "{", "err", "=", "StorageVolumeConfigClear", "(", "tx", ".", "tx", ",", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "StorageVolumeConfigAdd", "(", "tx", ".", "tx", ",", "volumeID", ",", "volumeConfig", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "StorageVolumeDescriptionUpdate", "(", "tx", ".", "tx", ",", "volumeID", ",", "volumeDescription", ")", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "return", "err", "\n", "}" ]
// StoragePoolVolumeUpdate updates the storage volume attached to a given storage // pool.
[ "StoragePoolVolumeUpdate", "updates", "the", "storage", "volume", "attached", "to", "a", "given", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L865-L892
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumeDelete
func (c *Cluster) StoragePoolVolumeDelete(project, volumeName string, volumeType int, poolID int64) error { volumeID, _, err := c.StoragePoolNodeVolumeGetTypeByProject(project, volumeName, volumeType, poolID) if err != nil { return err } err = c.Transaction(func(tx *ClusterTx) error { err := storagePoolVolumeReplicateIfCeph(tx.tx, volumeID, project, volumeName, volumeType, poolID, func(volumeID int64) error { _, err := tx.tx.Exec("DELETE FROM storage_volumes WHERE id=?", volumeID) return err }) return err }) return err }
go
func (c *Cluster) StoragePoolVolumeDelete(project, volumeName string, volumeType int, poolID int64) error { volumeID, _, err := c.StoragePoolNodeVolumeGetTypeByProject(project, volumeName, volumeType, poolID) if err != nil { return err } err = c.Transaction(func(tx *ClusterTx) error { err := storagePoolVolumeReplicateIfCeph(tx.tx, volumeID, project, volumeName, volumeType, poolID, func(volumeID int64) error { _, err := tx.tx.Exec("DELETE FROM storage_volumes WHERE id=?", volumeID) return err }) return err }) return err }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumeDelete", "(", "project", ",", "volumeName", "string", ",", "volumeType", "int", ",", "poolID", "int64", ")", "error", "{", "volumeID", ",", "_", ",", "err", ":=", "c", ".", "StoragePoolNodeVolumeGetTypeByProject", "(", "project", ",", "volumeName", ",", "volumeType", ",", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "ClusterTx", ")", "error", "{", "err", ":=", "storagePoolVolumeReplicateIfCeph", "(", "tx", ".", "tx", ",", "volumeID", ",", "project", ",", "volumeName", ",", "volumeType", ",", "poolID", ",", "func", "(", "volumeID", "int64", ")", "error", "{", "_", ",", "err", ":=", "tx", ".", "tx", ".", "Exec", "(", "\"DELETE FROM storage_volumes WHERE id=?\"", ",", "volumeID", ")", "\n", "return", "err", "\n", "}", ")", "\n", "return", "err", "\n", "}", ")", "\n", "return", "err", "\n", "}" ]
// StoragePoolVolumeDelete deletes the storage volume attached to a given storage // pool.
[ "StoragePoolVolumeDelete", "deletes", "the", "storage", "volume", "attached", "to", "a", "given", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L896-L911
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumeRename
func (c *Cluster) StoragePoolVolumeRename(project, oldVolumeName string, newVolumeName string, volumeType int, poolID int64) error { volumeID, _, err := c.StoragePoolNodeVolumeGetTypeByProject(project, oldVolumeName, volumeType, poolID) if err != nil { return err } err = c.Transaction(func(tx *ClusterTx) error { err := storagePoolVolumeReplicateIfCeph(tx.tx, volumeID, project, oldVolumeName, volumeType, poolID, func(volumeID int64) error { _, err := tx.tx.Exec("UPDATE storage_volumes SET name=? WHERE id=? AND type=?", newVolumeName, volumeID, volumeType) return err }) return err }) return err }
go
func (c *Cluster) StoragePoolVolumeRename(project, oldVolumeName string, newVolumeName string, volumeType int, poolID int64) error { volumeID, _, err := c.StoragePoolNodeVolumeGetTypeByProject(project, oldVolumeName, volumeType, poolID) if err != nil { return err } err = c.Transaction(func(tx *ClusterTx) error { err := storagePoolVolumeReplicateIfCeph(tx.tx, volumeID, project, oldVolumeName, volumeType, poolID, func(volumeID int64) error { _, err := tx.tx.Exec("UPDATE storage_volumes SET name=? WHERE id=? AND type=?", newVolumeName, volumeID, volumeType) return err }) return err }) return err }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumeRename", "(", "project", ",", "oldVolumeName", "string", ",", "newVolumeName", "string", ",", "volumeType", "int", ",", "poolID", "int64", ")", "error", "{", "volumeID", ",", "_", ",", "err", ":=", "c", ".", "StoragePoolNodeVolumeGetTypeByProject", "(", "project", ",", "oldVolumeName", ",", "volumeType", ",", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "ClusterTx", ")", "error", "{", "err", ":=", "storagePoolVolumeReplicateIfCeph", "(", "tx", ".", "tx", ",", "volumeID", ",", "project", ",", "oldVolumeName", ",", "volumeType", ",", "poolID", ",", "func", "(", "volumeID", "int64", ")", "error", "{", "_", ",", "err", ":=", "tx", ".", "tx", ".", "Exec", "(", "\"UPDATE storage_volumes SET name=? WHERE id=? AND type=?\"", ",", "newVolumeName", ",", "volumeID", ",", "volumeType", ")", "\n", "return", "err", "\n", "}", ")", "\n", "return", "err", "\n", "}", ")", "\n", "return", "err", "\n", "}" ]
// StoragePoolVolumeRename renames the storage volume attached to a given storage pool.
[ "StoragePoolVolumeRename", "renames", "the", "storage", "volume", "attached", "to", "a", "given", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L914-L929
test
lxc/lxd
lxd/db/storage_pools.go
storagePoolVolumeReplicateIfCeph
func storagePoolVolumeReplicateIfCeph(tx *sql.Tx, volumeID int64, project, volumeName string, volumeType int, poolID int64, f func(int64) error) error { driver, err := storagePoolDriverGet(tx, poolID) if err != nil { return err } volumeIDs := []int64{volumeID} // If this is a ceph volume, we want to duplicate the change across the // the rows for all other nodes. if driver == "ceph" { volumeIDs, err = storageVolumeIDsGet(tx, project, volumeName, volumeType, poolID) if err != nil { return err } } for _, volumeID := range volumeIDs { err := f(volumeID) if err != nil { return err } } return nil }
go
func storagePoolVolumeReplicateIfCeph(tx *sql.Tx, volumeID int64, project, volumeName string, volumeType int, poolID int64, f func(int64) error) error { driver, err := storagePoolDriverGet(tx, poolID) if err != nil { return err } volumeIDs := []int64{volumeID} // If this is a ceph volume, we want to duplicate the change across the // the rows for all other nodes. if driver == "ceph" { volumeIDs, err = storageVolumeIDsGet(tx, project, volumeName, volumeType, poolID) if err != nil { return err } } for _, volumeID := range volumeIDs { err := f(volumeID) if err != nil { return err } } return nil }
[ "func", "storagePoolVolumeReplicateIfCeph", "(", "tx", "*", "sql", ".", "Tx", ",", "volumeID", "int64", ",", "project", ",", "volumeName", "string", ",", "volumeType", "int", ",", "poolID", "int64", ",", "f", "func", "(", "int64", ")", "error", ")", "error", "{", "driver", ",", "err", ":=", "storagePoolDriverGet", "(", "tx", ",", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "volumeIDs", ":=", "[", "]", "int64", "{", "volumeID", "}", "\n", "if", "driver", "==", "\"ceph\"", "{", "volumeIDs", ",", "err", "=", "storageVolumeIDsGet", "(", "tx", ",", "project", ",", "volumeName", ",", "volumeType", ",", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "for", "_", ",", "volumeID", ":=", "range", "volumeIDs", "{", "err", ":=", "f", "(", "volumeID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// This a convenience to replicate a certain volume change to all nodes if the // underlying driver is ceph.
[ "This", "a", "convenience", "to", "replicate", "a", "certain", "volume", "change", "to", "all", "nodes", "if", "the", "underlying", "driver", "is", "ceph", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L933-L957
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumeCreate
func (c *Cluster) StoragePoolVolumeCreate(project, volumeName, volumeDescription string, volumeType int, snapshot bool, poolID int64, volumeConfig map[string]string) (int64, error) { var thisVolumeID int64 err := c.Transaction(func(tx *ClusterTx) error { nodeIDs := []int{int(c.nodeID)} driver, err := storagePoolDriverGet(tx.tx, poolID) if err != nil { return err } // If the driver is ceph, create a volume entry for each node. if driver == "ceph" { nodeIDs, err = query.SelectIntegers(tx.tx, "SELECT id FROM nodes") if err != nil { return err } } for _, nodeID := range nodeIDs { result, err := tx.tx.Exec(` INSERT INTO storage_volumes (storage_pool_id, node_id, type, snapshot, name, description, project_id) VALUES (?, ?, ?, ?, ?, ?, (SELECT id FROM projects WHERE name = ?)) `, poolID, nodeID, volumeType, snapshot, volumeName, volumeDescription, project) if err != nil { return err } volumeID, err := result.LastInsertId() if err != nil { return err } if int64(nodeID) == c.nodeID { // Return the ID of the volume created on this node. thisVolumeID = volumeID } err = StorageVolumeConfigAdd(tx.tx, volumeID, volumeConfig) if err != nil { tx.tx.Rollback() return err } } return nil }) if err != nil { thisVolumeID = -1 } return thisVolumeID, err }
go
func (c *Cluster) StoragePoolVolumeCreate(project, volumeName, volumeDescription string, volumeType int, snapshot bool, poolID int64, volumeConfig map[string]string) (int64, error) { var thisVolumeID int64 err := c.Transaction(func(tx *ClusterTx) error { nodeIDs := []int{int(c.nodeID)} driver, err := storagePoolDriverGet(tx.tx, poolID) if err != nil { return err } // If the driver is ceph, create a volume entry for each node. if driver == "ceph" { nodeIDs, err = query.SelectIntegers(tx.tx, "SELECT id FROM nodes") if err != nil { return err } } for _, nodeID := range nodeIDs { result, err := tx.tx.Exec(` INSERT INTO storage_volumes (storage_pool_id, node_id, type, snapshot, name, description, project_id) VALUES (?, ?, ?, ?, ?, ?, (SELECT id FROM projects WHERE name = ?)) `, poolID, nodeID, volumeType, snapshot, volumeName, volumeDescription, project) if err != nil { return err } volumeID, err := result.LastInsertId() if err != nil { return err } if int64(nodeID) == c.nodeID { // Return the ID of the volume created on this node. thisVolumeID = volumeID } err = StorageVolumeConfigAdd(tx.tx, volumeID, volumeConfig) if err != nil { tx.tx.Rollback() return err } } return nil }) if err != nil { thisVolumeID = -1 } return thisVolumeID, err }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumeCreate", "(", "project", ",", "volumeName", ",", "volumeDescription", "string", ",", "volumeType", "int", ",", "snapshot", "bool", ",", "poolID", "int64", ",", "volumeConfig", "map", "[", "string", "]", "string", ")", "(", "int64", ",", "error", ")", "{", "var", "thisVolumeID", "int64", "\n", "err", ":=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "ClusterTx", ")", "error", "{", "nodeIDs", ":=", "[", "]", "int", "{", "int", "(", "c", ".", "nodeID", ")", "}", "\n", "driver", ",", "err", ":=", "storagePoolDriverGet", "(", "tx", ".", "tx", ",", "poolID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "driver", "==", "\"ceph\"", "{", "nodeIDs", ",", "err", "=", "query", ".", "SelectIntegers", "(", "tx", ".", "tx", ",", "\"SELECT id FROM nodes\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "for", "_", ",", "nodeID", ":=", "range", "nodeIDs", "{", "result", ",", "err", ":=", "tx", ".", "tx", ".", "Exec", "(", "`INSERT INTO storage_volumes (storage_pool_id, node_id, type, snapshot, name, description, project_id) VALUES (?, ?, ?, ?, ?, ?, (SELECT id FROM projects WHERE name = ?))`", ",", "poolID", ",", "nodeID", ",", "volumeType", ",", "snapshot", ",", "volumeName", ",", "volumeDescription", ",", "project", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "volumeID", ",", "err", ":=", "result", ".", "LastInsertId", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "int64", "(", "nodeID", ")", "==", "c", ".", "nodeID", "{", "thisVolumeID", "=", "volumeID", "\n", "}", "\n", "err", "=", "StorageVolumeConfigAdd", "(", "tx", ".", "tx", ",", "volumeID", ",", "volumeConfig", ")", "\n", "if", "err", "!=", "nil", "{", "tx", ".", "tx", ".", "Rollback", "(", ")", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "thisVolumeID", "=", "-", "1", "\n", "}", "\n", "return", "thisVolumeID", ",", "err", "\n", "}" ]
// StoragePoolVolumeCreate creates a new storage volume attached to a given // storage pool.
[ "StoragePoolVolumeCreate", "creates", "a", "new", "storage", "volume", "attached", "to", "a", "given", "storage", "pool", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L961-L1009
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumeGetTypeID
func (c *Cluster) StoragePoolVolumeGetTypeID(project string, volumeName string, volumeType int, poolID, nodeID int64) (int64, error) { volumeID := int64(-1) query := `SELECT storage_volumes.id FROM storage_volumes JOIN storage_pools ON storage_volumes.storage_pool_id = storage_pools.id JOIN projects ON storage_volumes.project_id = projects.id WHERE projects.name=? AND storage_volumes.storage_pool_id=? AND storage_volumes.node_id=? AND storage_volumes.name=? AND storage_volumes.type=?` inargs := []interface{}{project, poolID, nodeID, volumeName, volumeType} outargs := []interface{}{&volumeID} err := dbQueryRowScan(c.db, query, inargs, outargs) if err != nil { if err == sql.ErrNoRows { return -1, ErrNoSuchObject } return -1, err } return volumeID, nil }
go
func (c *Cluster) StoragePoolVolumeGetTypeID(project string, volumeName string, volumeType int, poolID, nodeID int64) (int64, error) { volumeID := int64(-1) query := `SELECT storage_volumes.id FROM storage_volumes JOIN storage_pools ON storage_volumes.storage_pool_id = storage_pools.id JOIN projects ON storage_volumes.project_id = projects.id WHERE projects.name=? AND storage_volumes.storage_pool_id=? AND storage_volumes.node_id=? AND storage_volumes.name=? AND storage_volumes.type=?` inargs := []interface{}{project, poolID, nodeID, volumeName, volumeType} outargs := []interface{}{&volumeID} err := dbQueryRowScan(c.db, query, inargs, outargs) if err != nil { if err == sql.ErrNoRows { return -1, ErrNoSuchObject } return -1, err } return volumeID, nil }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolVolumeGetTypeID", "(", "project", "string", ",", "volumeName", "string", ",", "volumeType", "int", ",", "poolID", ",", "nodeID", "int64", ")", "(", "int64", ",", "error", ")", "{", "volumeID", ":=", "int64", "(", "-", "1", ")", "\n", "query", ":=", "`SELECT storage_volumes.idFROM storage_volumesJOIN storage_pools ON storage_volumes.storage_pool_id = storage_pools.idJOIN projects ON storage_volumes.project_id = projects.idWHERE projects.name=? AND storage_volumes.storage_pool_id=? AND storage_volumes.node_id=?AND storage_volumes.name=? AND storage_volumes.type=?`", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "project", ",", "poolID", ",", "nodeID", ",", "volumeName", ",", "volumeType", "}", "\n", "outargs", ":=", "[", "]", "interface", "{", "}", "{", "&", "volumeID", "}", "\n", "err", ":=", "dbQueryRowScan", "(", "c", ".", "db", ",", "query", ",", "inargs", ",", "outargs", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "sql", ".", "ErrNoRows", "{", "return", "-", "1", ",", "ErrNoSuchObject", "\n", "}", "\n", "return", "-", "1", ",", "err", "\n", "}", "\n", "return", "volumeID", ",", "nil", "\n", "}" ]
// StoragePoolVolumeGetTypeID returns the ID of a storage volume on a given // storage pool of a given storage volume type, on the given node.
[ "StoragePoolVolumeGetTypeID", "returns", "the", "ID", "of", "a", "storage", "volume", "on", "a", "given", "storage", "pool", "of", "a", "given", "storage", "volume", "type", "on", "the", "given", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L1013-L1033
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolNodeVolumeGetTypeID
func (c *Cluster) StoragePoolNodeVolumeGetTypeID(volumeName string, volumeType int, poolID int64) (int64, error) { return c.StoragePoolVolumeGetTypeID("default", volumeName, volumeType, poolID, c.nodeID) }
go
func (c *Cluster) StoragePoolNodeVolumeGetTypeID(volumeName string, volumeType int, poolID int64) (int64, error) { return c.StoragePoolVolumeGetTypeID("default", volumeName, volumeType, poolID, c.nodeID) }
[ "func", "(", "c", "*", "Cluster", ")", "StoragePoolNodeVolumeGetTypeID", "(", "volumeName", "string", ",", "volumeType", "int", ",", "poolID", "int64", ")", "(", "int64", ",", "error", ")", "{", "return", "c", ".", "StoragePoolVolumeGetTypeID", "(", "\"default\"", ",", "volumeName", ",", "volumeType", ",", "poolID", ",", "c", ".", "nodeID", ")", "\n", "}" ]
// StoragePoolNodeVolumeGetTypeID get the ID of a storage volume on a given // storage pool of a given storage volume type, on the current node.
[ "StoragePoolNodeVolumeGetTypeID", "get", "the", "ID", "of", "a", "storage", "volume", "on", "a", "given", "storage", "pool", "of", "a", "given", "storage", "volume", "type", "on", "the", "current", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L1037-L1039
test
lxc/lxd
lxd/db/storage_pools.go
StoragePoolVolumeTypeToName
func StoragePoolVolumeTypeToName(volumeType int) (string, error) { switch volumeType { case StoragePoolVolumeTypeContainer: return StoragePoolVolumeTypeNameContainer, nil case StoragePoolVolumeTypeImage: return StoragePoolVolumeTypeNameImage, nil case StoragePoolVolumeTypeCustom: return StoragePoolVolumeTypeNameCustom, nil } return "", fmt.Errorf("invalid storage volume type") }
go
func StoragePoolVolumeTypeToName(volumeType int) (string, error) { switch volumeType { case StoragePoolVolumeTypeContainer: return StoragePoolVolumeTypeNameContainer, nil case StoragePoolVolumeTypeImage: return StoragePoolVolumeTypeNameImage, nil case StoragePoolVolumeTypeCustom: return StoragePoolVolumeTypeNameCustom, nil } return "", fmt.Errorf("invalid storage volume type") }
[ "func", "StoragePoolVolumeTypeToName", "(", "volumeType", "int", ")", "(", "string", ",", "error", ")", "{", "switch", "volumeType", "{", "case", "StoragePoolVolumeTypeContainer", ":", "return", "StoragePoolVolumeTypeNameContainer", ",", "nil", "\n", "case", "StoragePoolVolumeTypeImage", ":", "return", "StoragePoolVolumeTypeNameImage", ",", "nil", "\n", "case", "StoragePoolVolumeTypeCustom", ":", "return", "StoragePoolVolumeTypeNameCustom", ",", "nil", "\n", "}", "\n", "return", "\"\"", ",", "fmt", ".", "Errorf", "(", "\"invalid storage volume type\"", ")", "\n", "}" ]
// StoragePoolVolumeTypeToName converts a volume integer type code to its // human-readable name.
[ "StoragePoolVolumeTypeToName", "converts", "a", "volume", "integer", "type", "code", "to", "its", "human", "-", "readable", "name", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/storage_pools.go#L1071-L1082
test
lxc/lxd
lxd/db/devices.go
DevicesAdd
func DevicesAdd(tx *sql.Tx, w string, cID int64, devices types.Devices) error { // Prepare the devices entry SQL str1 := fmt.Sprintf("INSERT INTO %ss_devices (%s_id, name, type) VALUES (?, ?, ?)", w, w) stmt1, err := tx.Prepare(str1) if err != nil { return err } defer stmt1.Close() // Prepare the devices config entry SQL str2 := fmt.Sprintf("INSERT INTO %ss_devices_config (%s_device_id, key, value) VALUES (?, ?, ?)", w, w) stmt2, err := tx.Prepare(str2) if err != nil { return err } defer stmt2.Close() // Insert all the devices for k, v := range devices { t, err := dbDeviceTypeToInt(v["type"]) if err != nil { return err } result, err := stmt1.Exec(cID, k, t) if err != nil { return err } id64, err := result.LastInsertId() if err != nil { return fmt.Errorf("Error inserting device %s into database", k) } id := int(id64) for ck, cv := range v { // The type is stored as int in the parent entry if ck == "type" || cv == "" { continue } _, err = stmt2.Exec(id, ck, cv) if err != nil { return err } } } return nil }
go
func DevicesAdd(tx *sql.Tx, w string, cID int64, devices types.Devices) error { // Prepare the devices entry SQL str1 := fmt.Sprintf("INSERT INTO %ss_devices (%s_id, name, type) VALUES (?, ?, ?)", w, w) stmt1, err := tx.Prepare(str1) if err != nil { return err } defer stmt1.Close() // Prepare the devices config entry SQL str2 := fmt.Sprintf("INSERT INTO %ss_devices_config (%s_device_id, key, value) VALUES (?, ?, ?)", w, w) stmt2, err := tx.Prepare(str2) if err != nil { return err } defer stmt2.Close() // Insert all the devices for k, v := range devices { t, err := dbDeviceTypeToInt(v["type"]) if err != nil { return err } result, err := stmt1.Exec(cID, k, t) if err != nil { return err } id64, err := result.LastInsertId() if err != nil { return fmt.Errorf("Error inserting device %s into database", k) } id := int(id64) for ck, cv := range v { // The type is stored as int in the parent entry if ck == "type" || cv == "" { continue } _, err = stmt2.Exec(id, ck, cv) if err != nil { return err } } } return nil }
[ "func", "DevicesAdd", "(", "tx", "*", "sql", ".", "Tx", ",", "w", "string", ",", "cID", "int64", ",", "devices", "types", ".", "Devices", ")", "error", "{", "str1", ":=", "fmt", ".", "Sprintf", "(", "\"INSERT INTO %ss_devices (%s_id, name, type) VALUES (?, ?, ?)\"", ",", "w", ",", "w", ")", "\n", "stmt1", ",", "err", ":=", "tx", ".", "Prepare", "(", "str1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "stmt1", ".", "Close", "(", ")", "\n", "str2", ":=", "fmt", ".", "Sprintf", "(", "\"INSERT INTO %ss_devices_config (%s_device_id, key, value) VALUES (?, ?, ?)\"", ",", "w", ",", "w", ")", "\n", "stmt2", ",", "err", ":=", "tx", ".", "Prepare", "(", "str2", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "stmt2", ".", "Close", "(", ")", "\n", "for", "k", ",", "v", ":=", "range", "devices", "{", "t", ",", "err", ":=", "dbDeviceTypeToInt", "(", "v", "[", "\"type\"", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "result", ",", "err", ":=", "stmt1", ".", "Exec", "(", "cID", ",", "k", ",", "t", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "id64", ",", "err", ":=", "result", ".", "LastInsertId", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"Error inserting device %s into database\"", ",", "k", ")", "\n", "}", "\n", "id", ":=", "int", "(", "id64", ")", "\n", "for", "ck", ",", "cv", ":=", "range", "v", "{", "if", "ck", "==", "\"type\"", "||", "cv", "==", "\"\"", "{", "continue", "\n", "}", "\n", "_", ",", "err", "=", "stmt2", ".", "Exec", "(", "id", ",", "ck", ",", "cv", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DevicesAdd adds a new device.
[ "DevicesAdd", "adds", "a", "new", "device", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/devices.go#L61-L110
test
lxc/lxd
lxd/db/devices.go
Devices
func (c *Cluster) Devices(project, qName string, isprofile bool) (types.Devices, error) { err := c.Transaction(func(tx *ClusterTx) error { enabled, err := tx.ProjectHasProfiles(project) if err != nil { return err } if !enabled { project = "default" } return nil }) if err != nil { return nil, err } var q string if isprofile { q = `SELECT profiles_devices.id, profiles_devices.name, profiles_devices.type FROM profiles_devices JOIN profiles ON profiles_devices.profile_id = profiles.id JOIN projects ON projects.id=profiles.project_id WHERE projects.name=? AND profiles.name=?` } else { q = `SELECT containers_devices.id, containers_devices.name, containers_devices.type FROM containers_devices JOIN containers ON containers_devices.container_id = containers.id JOIN projects ON projects.id=containers.project_id WHERE projects.name=? AND containers.name=?` } var id, dtype int var name, stype string inargs := []interface{}{project, qName} outfmt := []interface{}{id, name, dtype} results, err := queryScan(c.db, q, inargs, outfmt) if err != nil { return nil, err } devices := types.Devices{} for _, r := range results { id = r[0].(int) name = r[1].(string) stype, err = dbDeviceTypeToString(r[2].(int)) if err != nil { return nil, err } newdev, err := dbDeviceConfig(c.db, id, isprofile) if err != nil { return nil, err } newdev["type"] = stype devices[name] = newdev } return devices, nil }
go
func (c *Cluster) Devices(project, qName string, isprofile bool) (types.Devices, error) { err := c.Transaction(func(tx *ClusterTx) error { enabled, err := tx.ProjectHasProfiles(project) if err != nil { return err } if !enabled { project = "default" } return nil }) if err != nil { return nil, err } var q string if isprofile { q = `SELECT profiles_devices.id, profiles_devices.name, profiles_devices.type FROM profiles_devices JOIN profiles ON profiles_devices.profile_id = profiles.id JOIN projects ON projects.id=profiles.project_id WHERE projects.name=? AND profiles.name=?` } else { q = `SELECT containers_devices.id, containers_devices.name, containers_devices.type FROM containers_devices JOIN containers ON containers_devices.container_id = containers.id JOIN projects ON projects.id=containers.project_id WHERE projects.name=? AND containers.name=?` } var id, dtype int var name, stype string inargs := []interface{}{project, qName} outfmt := []interface{}{id, name, dtype} results, err := queryScan(c.db, q, inargs, outfmt) if err != nil { return nil, err } devices := types.Devices{} for _, r := range results { id = r[0].(int) name = r[1].(string) stype, err = dbDeviceTypeToString(r[2].(int)) if err != nil { return nil, err } newdev, err := dbDeviceConfig(c.db, id, isprofile) if err != nil { return nil, err } newdev["type"] = stype devices[name] = newdev } return devices, nil }
[ "func", "(", "c", "*", "Cluster", ")", "Devices", "(", "project", ",", "qName", "string", ",", "isprofile", "bool", ")", "(", "types", ".", "Devices", ",", "error", ")", "{", "err", ":=", "c", ".", "Transaction", "(", "func", "(", "tx", "*", "ClusterTx", ")", "error", "{", "enabled", ",", "err", ":=", "tx", ".", "ProjectHasProfiles", "(", "project", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "enabled", "{", "project", "=", "\"default\"", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "var", "q", "string", "\n", "if", "isprofile", "{", "q", "=", "`SELECT profiles_devices.id, profiles_devices.name, profiles_devices.type\t\t\tFROM profiles_devices JOIN profiles ON profiles_devices.profile_id = profiles.id JOIN projects ON projects.id=profiles.project_id \t\tWHERE projects.name=? AND profiles.name=?`", "\n", "}", "else", "{", "q", "=", "`SELECT containers_devices.id, containers_devices.name, containers_devices.type\t\t\tFROM containers_devices JOIN containers\tON containers_devices.container_id = containers.id JOIN projects ON projects.id=containers.project_id\t\t\tWHERE projects.name=? AND containers.name=?`", "\n", "}", "\n", "var", "id", ",", "dtype", "int", "\n", "var", "name", ",", "stype", "string", "\n", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "project", ",", "qName", "}", "\n", "outfmt", ":=", "[", "]", "interface", "{", "}", "{", "id", ",", "name", ",", "dtype", "}", "\n", "results", ",", "err", ":=", "queryScan", "(", "c", ".", "db", ",", "q", ",", "inargs", ",", "outfmt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "devices", ":=", "types", ".", "Devices", "{", "}", "\n", "for", "_", ",", "r", ":=", "range", "results", "{", "id", "=", "r", "[", "0", "]", ".", "(", "int", ")", "\n", "name", "=", "r", "[", "1", "]", ".", "(", "string", ")", "\n", "stype", ",", "err", "=", "dbDeviceTypeToString", "(", "r", "[", "2", "]", ".", "(", "int", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "newdev", ",", "err", ":=", "dbDeviceConfig", "(", "c", ".", "db", ",", "id", ",", "isprofile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "newdev", "[", "\"type\"", "]", "=", "stype", "\n", "devices", "[", "name", "]", "=", "newdev", "\n", "}", "\n", "return", "devices", ",", "nil", "\n", "}" ]
// Devices returns the devices matching the given filters.
[ "Devices", "returns", "the", "devices", "matching", "the", "given", "filters", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/devices.go#L141-L196
test
lxc/lxd
lxd/db/patches.go
Patches
func (n *Node) Patches() ([]string, error) { inargs := []interface{}{} outfmt := []interface{}{""} query := fmt.Sprintf("SELECT name FROM patches") result, err := queryScan(n.db, query, inargs, outfmt) if err != nil { return []string{}, err } response := []string{} for _, r := range result { response = append(response, r[0].(string)) } return response, nil }
go
func (n *Node) Patches() ([]string, error) { inargs := []interface{}{} outfmt := []interface{}{""} query := fmt.Sprintf("SELECT name FROM patches") result, err := queryScan(n.db, query, inargs, outfmt) if err != nil { return []string{}, err } response := []string{} for _, r := range result { response = append(response, r[0].(string)) } return response, nil }
[ "func", "(", "n", "*", "Node", ")", "Patches", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "inargs", ":=", "[", "]", "interface", "{", "}", "{", "}", "\n", "outfmt", ":=", "[", "]", "interface", "{", "}", "{", "\"\"", "}", "\n", "query", ":=", "fmt", ".", "Sprintf", "(", "\"SELECT name FROM patches\"", ")", "\n", "result", ",", "err", ":=", "queryScan", "(", "n", ".", "db", ",", "query", ",", "inargs", ",", "outfmt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "string", "{", "}", ",", "err", "\n", "}", "\n", "response", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "r", ":=", "range", "result", "{", "response", "=", "append", "(", "response", ",", "r", "[", "0", "]", ".", "(", "string", ")", ")", "\n", "}", "\n", "return", "response", ",", "nil", "\n", "}" ]
// Patches returns the names of all patches currently applied on this node.
[ "Patches", "returns", "the", "names", "of", "all", "patches", "currently", "applied", "on", "this", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/patches.go#L8-L24
test
lxc/lxd
lxd/db/patches.go
PatchesMarkApplied
func (n *Node) PatchesMarkApplied(patch string) error { stmt := `INSERT INTO patches (name, applied_at) VALUES (?, strftime("%s"));` _, err := n.db.Exec(stmt, patch) return err }
go
func (n *Node) PatchesMarkApplied(patch string) error { stmt := `INSERT INTO patches (name, applied_at) VALUES (?, strftime("%s"));` _, err := n.db.Exec(stmt, patch) return err }
[ "func", "(", "n", "*", "Node", ")", "PatchesMarkApplied", "(", "patch", "string", ")", "error", "{", "stmt", ":=", "`INSERT INTO patches (name, applied_at) VALUES (?, strftime(\"%s\"));`", "\n", "_", ",", "err", ":=", "n", ".", "db", ".", "Exec", "(", "stmt", ",", "patch", ")", "\n", "return", "err", "\n", "}" ]
// PatchesMarkApplied marks the patch with the given name as applied on this node.
[ "PatchesMarkApplied", "marks", "the", "patch", "with", "the", "given", "name", "as", "applied", "on", "this", "node", "." ]
7a41d14e4c1a6bc25918aca91004d594774dcdd3
https://github.com/lxc/lxd/blob/7a41d14e4c1a6bc25918aca91004d594774dcdd3/lxd/db/patches.go#L27-L31
test