_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q176600
DeleteContainerFile
test
func (r *ProtocolLXD) DeleteContainerFile(containerName string, path string) error { if !r.HasExtension("file_delete") { return fmt.Errorf("The server is missing the required \"file_delete\" API extension") } // Send the request _, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/files?path=%s", url.Query...
go
{ "resource": "" }
q176601
GetContainerSnapshotNames
test
func (r *ProtocolLXD) GetContainerSnapshotNames(containerName string) ([]string, error) { urls := []string{} // Fetch the raw value _, err := r.queryStruct("GET", fmt.Sprintf("/containers/%s/snapshots", url.QueryEscape(containerName)), nil, "", &urls) if err != nil { return nil, err } // Parse it names := []...
go
{ "resource": "" }
q176602
GetContainerSnapshots
test
func (r *ProtocolLXD) GetContainerSnapshots(containerName string) ([]api.ContainerSnapshot, error) { snapshots := []api.ContainerSnapshot{} // Fetch the raw value _, err := r.queryStruct("GET", fmt.Sprintf("/containers/%s/snapshots?recursion=1", url.QueryEscape(containerName)), nil, "", &snapshots) if err != nil {...
go
{ "resource": "" }
q176603
GetContainerSnapshot
test
func (r *ProtocolLXD) GetContainerSnapshot(containerName string, name string) (*api.ContainerSnapshot, string, error) { snapshot := api.ContainerSnapshot{} // Fetch the raw value etag, err := r.queryStruct("GET", fmt.Sprintf("/containers/%s/snapshots/%s", url.QueryEscape(containerName), url.QueryEscape(name)), nil,...
go
{ "resource": "" }
q176604
CreateContainerSnapshot
test
func (r *ProtocolLXD) CreateContainerSnapshot(containerName string, snapshot api.ContainerSnapshotsPost) (Operation, error) { // Validate the request if snapshot.ExpiresAt != nil && !r.HasExtension("snapshot_expiry_creation") { return nil, fmt.Errorf("The server is missing the required \"snapshot_expiry_creation\" ...
go
{ "resource": "" }
q176605
MigrateContainerSnapshot
test
func (r *ProtocolLXD) MigrateContainerSnapshot(containerName string, name string, container api.ContainerSnapshotPost) (Operation, error) { // Sanity check if !container.Migration { return nil, fmt.Errorf("Can't ask for a rename through MigrateContainerSnapshot") } // Send the request op, _, err := r.queryOpera...
go
{ "resource": "" }
q176606
UpdateContainerSnapshot
test
func (r *ProtocolLXD) UpdateContainerSnapshot(containerName string, name string, container api.ContainerSnapshotPut, ETag string) (Operation, error) { if !r.HasExtension("snapshot_expiry") { return nil, fmt.Errorf("The server is missing the required \"snapshot_expiry\" API extension") } // Send the request op, _...
go
{ "resource": "" }
q176607
GetContainerState
test
func (r *ProtocolLXD) GetContainerState(name string) (*api.ContainerState, string, error) { state := api.ContainerState{} // Fetch the raw value etag, err := r.queryStruct("GET", fmt.Sprintf("/containers/%s/state", url.QueryEscape(name)), nil, "", &state) if err != nil { return nil, "", err } return &state, e...
go
{ "resource": "" }
q176608
UpdateContainerState
test
func (r *ProtocolLXD) UpdateContainerState(name string, state api.ContainerStatePut, ETag string) (Operation, error) { // Send the request op, _, err := r.queryOperation("PUT", fmt.Sprintf("/containers/%s/state", url.QueryEscape(name)), state, ETag) if err != nil { return nil, err } return op, nil }
go
{ "resource": "" }
q176609
GetContainerLogfiles
test
func (r *ProtocolLXD) GetContainerLogfiles(name string) ([]string, error) { urls := []string{} // Fetch the raw value _, err := r.queryStruct("GET", fmt.Sprintf("/containers/%s/logs", url.QueryEscape(name)), nil, "", &urls) if err != nil { return nil, err } // Parse it logfiles := []string{} for _, uri := r...
go
{ "resource": "" }
q176610
GetContainerLogfile
test
func (r *ProtocolLXD) GetContainerLogfile(name string, filename string) (io.ReadCloser, error) { // Prepare the HTTP request url := fmt.Sprintf("%s/1.0/containers/%s/logs/%s", r.httpHost, url.QueryEscape(name), url.QueryEscape(filename)) url, err := r.setQueryAttributes(url) if err != nil { return nil, err } ...
go
{ "resource": "" }
q176611
GetContainerMetadata
test
func (r *ProtocolLXD) GetContainerMetadata(name string) (*api.ImageMetadata, string, error) { if !r.HasExtension("container_edit_metadata") { return nil, "", fmt.Errorf("The server is missing the required \"container_edit_metadata\" API extension") } metadata := api.ImageMetadata{} url := fmt.Sprintf("/containe...
go
{ "resource": "" }
q176612
SetContainerMetadata
test
func (r *ProtocolLXD) SetContainerMetadata(name string, metadata api.ImageMetadata, ETag string) error { if !r.HasExtension("container_edit_metadata") { return fmt.Errorf("The server is missing the required \"container_edit_metadata\" API extension") } url := fmt.Sprintf("/containers/%s/metadata", url.QueryEscape...
go
{ "resource": "" }
q176613
GetContainerTemplateFiles
test
func (r *ProtocolLXD) GetContainerTemplateFiles(containerName string) ([]string, error) { if !r.HasExtension("container_edit_metadata") { return nil, fmt.Errorf("The server is missing the required \"container_edit_metadata\" API extension") } templates := []string{} url := fmt.Sprintf("/containers/%s/metadata/t...
go
{ "resource": "" }
q176614
CreateContainerTemplateFile
test
func (r *ProtocolLXD) CreateContainerTemplateFile(containerName string, templateName string, content io.ReadSeeker) error { return r.setContainerTemplateFile(containerName, templateName, content, "POST") }
go
{ "resource": "" }
q176615
DeleteContainerTemplateFile
test
func (r *ProtocolLXD) DeleteContainerTemplateFile(name string, templateName string) error { if !r.HasExtension("container_edit_metadata") { return fmt.Errorf("The server is missing the required \"container_edit_metadata\" API extension") } _, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/metadata/templat...
go
{ "resource": "" }
q176616
ConsoleContainer
test
func (r *ProtocolLXD) ConsoleContainer(containerName string, console api.ContainerConsolePost, args *ContainerConsoleArgs) (Operation, error) { if !r.HasExtension("console") { return nil, fmt.Errorf("The server is missing the required \"console\" API extension") } // Send the request op, _, err := r.queryOperati...
go
{ "resource": "" }
q176617
GetContainerConsoleLog
test
func (r *ProtocolLXD) GetContainerConsoleLog(containerName string, args *ContainerConsoleLogArgs) (io.ReadCloser, error) { if !r.HasExtension("console") { return nil, fmt.Errorf("The server is missing the required \"console\" API extension") } // Prepare the HTTP request url := fmt.Sprintf("%s/1.0/containers/%s/...
go
{ "resource": "" }
q176618
DeleteContainerConsoleLog
test
func (r *ProtocolLXD) DeleteContainerConsoleLog(containerName string, args *ContainerConsoleLogArgs) error { if !r.HasExtension("console") { return fmt.Errorf("The server is missing the required \"console\" API extension") } // Send the request _, _, err := r.query("DELETE", fmt.Sprintf("/containers/%s/console",...
go
{ "resource": "" }
q176619
GetContainerBackups
test
func (r *ProtocolLXD) GetContainerBackups(containerName string) ([]api.ContainerBackup, error) { if !r.HasExtension("container_backup") { return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension") } // Fetch the raw value backups := []api.ContainerBackup{} _, err := r.query...
go
{ "resource": "" }
q176620
GetContainerBackup
test
func (r *ProtocolLXD) GetContainerBackup(containerName string, name string) (*api.ContainerBackup, string, error) { if !r.HasExtension("container_backup") { return nil, "", fmt.Errorf("The server is missing the required \"container_backup\" API extension") } // Fetch the raw value backup := api.ContainerBackup{}...
go
{ "resource": "" }
q176621
CreateContainerBackup
test
func (r *ProtocolLXD) CreateContainerBackup(containerName string, backup api.ContainerBackupsPost) (Operation, error) { if !r.HasExtension("container_backup") { return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension") } // Send the request op, _, err := r.queryOperation("PO...
go
{ "resource": "" }
q176622
RenameContainerBackup
test
func (r *ProtocolLXD) RenameContainerBackup(containerName string, name string, backup api.ContainerBackupPost) (Operation, error) { if !r.HasExtension("container_backup") { return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension") } // Send the request op, _, err := r.queryO...
go
{ "resource": "" }
q176623
DeleteContainerBackup
test
func (r *ProtocolLXD) DeleteContainerBackup(containerName string, name string) (Operation, error) { if !r.HasExtension("container_backup") { return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension") } // Send the request op, _, err := r.queryOperation("DELETE", fmt.Sprintf("...
go
{ "resource": "" }
q176624
GetContainerBackupFile
test
func (r *ProtocolLXD) GetContainerBackupFile(containerName string, name string, req *BackupFileRequest) (*BackupFileResponse, error) { if !r.HasExtension("container_backup") { return nil, fmt.Errorf("The server is missing the required \"container_backup\" API extension") } // Build the URL uri := fmt.Sprintf("%s...
go
{ "resource": "" }
q176625
RsyncSend
test
func RsyncSend(name string, path string, conn *websocket.Conn, readWrapper func(io.ReadCloser) io.ReadCloser, features []string, bwlimit string, execPath string) error { cmd, dataSocket, stderr, err := rsyncSendSetup(name, path, bwlimit, execPath, features) if err != nil { return err } if dataSocket != nil { d...
go
{ "resource": "" }
q176626
patchesGetNames
test
func patchesGetNames() []string { names := make([]string, len(patches)) for i, patch := range patches { names[i] = patch.name } return names }
go
{ "resource": "" }
q176627
patchRenameCustomVolumeLVs
test
func patchRenameCustomVolumeLVs(name string, d *Daemon) error { // Ignore the error since it will also fail if there are no pools. pools, _ := d.cluster.StoragePools() for _, poolName := range pools { poolID, pool, err := d.cluster.StoragePoolGet(poolName) if err != nil { return err } sType, err := stor...
go
{ "resource": "" }
q176628
patchLvmNodeSpecificConfigKeys
test
func patchLvmNodeSpecificConfigKeys(name string, d *Daemon) error { tx, err := d.cluster.Begin() if err != nil { return errors.Wrap(err, "failed to begin transaction") } // Fetch the IDs of all existing nodes. nodeIDs, err := query.SelectIntegers(tx, "SELECT id FROM nodes") if err != nil { return errors.Wrap...
go
{ "resource": "" }
q176629
GetHTTPClient
test
func (r *ProtocolLXD) GetHTTPClient() (*http.Client, error) { if r.http == nil { return nil, fmt.Errorf("HTTP client isn't set, bad connection") } return r.http, nil }
go
{ "resource": "" }
q176630
do
test
func (r *ProtocolLXD) do(req *http.Request) (*http.Response, error) { if r.bakeryClient != nil { r.addMacaroonHeaders(req) return r.bakeryClient.Do(req) } return r.http.Do(req) }
go
{ "resource": "" }
q176631
RawQuery
test
func (r *ProtocolLXD) RawQuery(method string, path string, data interface{}, ETag string) (*api.Response, string, error) { // Generate the URL url := fmt.Sprintf("%s%s", r.httpHost, path) return r.rawQuery(method, url, data, ETag) }
go
{ "resource": "" }
q176632
RawWebsocket
test
func (r *ProtocolLXD) RawWebsocket(path string) (*websocket.Conn, error) { return r.websocket(path) }
go
{ "resource": "" }
q176633
RawOperation
test
func (r *ProtocolLXD) RawOperation(method string, path string, data interface{}, ETag string) (Operation, string, error) { return r.queryOperation(method, path, data, ETag) }
go
{ "resource": "" }
q176634
ProfileToAPI
test
func ProfileToAPI(profile *Profile) *api.Profile { p := &api.Profile{ Name: profile.Name, UsedBy: profile.UsedBy, } p.Description = profile.Description p.Config = profile.Config p.Devices = profile.Devices return p }
go
{ "resource": "" }
q176635
Profiles
test
func (c *Cluster) Profiles(project string) ([]string, error) { err := c.Transaction(func(tx *ClusterTx) error { enabled, err := tx.ProjectHasProfiles(project) if err != nil { return errors.Wrap(err, "Check if project has profiles") } if !enabled { project = "default" } return nil }) if err != nil {...
go
{ "resource": "" }
q176636
ProfileGet
test
func (c *Cluster) ProfileGet(project, name string) (int64, *api.Profile, error) { var result *api.Profile var id int64 err := c.Transaction(func(tx *ClusterTx) error { enabled, err := tx.ProjectHasProfiles(project) if err != nil { return errors.Wrap(err, "Check if project has profiles") } if !enabled { ...
go
{ "resource": "" }
q176637
ProfilesGet
test
func (c *Cluster) ProfilesGet(project string, names []string) ([]api.Profile, error) { profiles := make([]api.Profile, len(names)) err := c.Transaction(func(tx *ClusterTx) error { enabled, err := tx.ProjectHasProfiles(project) if err != nil { return errors.Wrap(err, "Check if project has profiles") } if !...
go
{ "resource": "" }
q176638
ProfileConfig
test
func (c *Cluster) ProfileConfig(project, name string) (map[string]string, error) { err := c.Transaction(func(tx *ClusterTx) error { enabled, err := tx.ProjectHasProfiles(project) if err != nil { return errors.Wrap(err, "Check if project has profiles") } if !enabled { project = "default" } return nil ...
go
{ "resource": "" }
q176639
ProfileConfigClear
test
func ProfileConfigClear(tx *sql.Tx, id int64) error { _, err := tx.Exec("DELETE FROM profiles_config WHERE profile_id=?", id) if err != nil { return err } _, err = tx.Exec(`DELETE FROM profiles_devices_config WHERE id IN (SELECT profiles_devices_config.id FROM profiles_devices_config JOIN profiles_devices ...
go
{ "resource": "" }
q176640
ProfileConfigAdd
test
func ProfileConfigAdd(tx *sql.Tx, id int64, config map[string]string) error { str := fmt.Sprintf("INSERT INTO profiles_config (profile_id, key, value) VALUES(?, ?, ?)") stmt, err := tx.Prepare(str) defer stmt.Close() if err != nil { return err } for k, v := range config { if v == "" { continue } _, e...
go
{ "resource": "" }
q176641
ProfileContainersGet
test
func (c *Cluster) ProfileContainersGet(project, profile string) (map[string][]string, error) { err := c.Transaction(func(tx *ClusterTx) error { enabled, err := tx.ProjectHasProfiles(project) if err != nil { return errors.Wrap(err, "Check if project has profiles") } if !enabled { project = "default" } ...
go
{ "resource": "" }
q176642
ProfileCleanupLeftover
test
func (c *Cluster) ProfileCleanupLeftover() error { stmt := ` DELETE FROM profiles_config WHERE profile_id NOT IN (SELECT id FROM profiles); DELETE FROM profiles_devices WHERE profile_id NOT IN (SELECT id FROM profiles); DELETE FROM profiles_devices_config WHERE profile_device_id NOT IN (SELECT id FROM profiles_devices...
go
{ "resource": "" }
q176643
ProfilesExpandConfig
test
func ProfilesExpandConfig(config map[string]string, profiles []api.Profile) map[string]string { expandedConfig := map[string]string{} // Apply all the profiles profileConfigs := make([]map[string]string, len(profiles)) for i, profile := range profiles { profileConfigs[i] = profile.Config } for i := range prof...
go
{ "resource": "" }
q176644
ProfilesExpandDevices
test
func ProfilesExpandDevices(devices types.Devices, profiles []api.Profile) types.Devices { expandedDevices := types.Devices{} // Apply all the profiles profileDevices := make([]types.Devices, len(profiles)) for i, profile := range profiles { profileDevices[i] = profile.Devices } for i := range profileDevices { ...
go
{ "resource": "" }
q176645
GetServer
test
func (r *ProtocolLXD) GetServer() (*api.Server, string, error) { server := api.Server{} // Fetch the raw value etag, err := r.queryStruct("GET", "", nil, "", &server) if err != nil { return nil, "", err } // Fill in certificate fingerprint if not provided if server.Environment.CertificateFingerprint == "" &&...
go
{ "resource": "" }
q176646
UpdateServer
test
func (r *ProtocolLXD) UpdateServer(server api.ServerPut, ETag string) error { // Send the request _, _, err := r.query("PUT", "", server, ETag) if err != nil { return err } return nil }
go
{ "resource": "" }
q176647
HasExtension
test
func (r *ProtocolLXD) HasExtension(extension string) bool { // If no cached API information, just assume we're good // This is needed for those rare cases where we must avoid a GetServer call if r.server == nil { return true } for _, entry := range r.server.APIExtensions { if entry == extension { return tr...
go
{ "resource": "" }
q176648
GetServerResources
test
func (r *ProtocolLXD) GetServerResources() (*api.Resources, error) { if !r.HasExtension("resources") { return nil, fmt.Errorf("The server is missing the required \"resources\" API extension") } resources := api.Resources{} // Fetch the raw value _, err := r.queryStruct("GET", "/resources", nil, "", &resources)...
go
{ "resource": "" }
q176649
UseProject
test
func (r *ProtocolLXD) UseProject(name string) ContainerServer { return &ProtocolLXD{ server: r.server, http: r.http, httpCertificate: r.httpCertificate, httpHost: r.httpHost, httpProtocol: r.httpProtocol, httpUserAgent: r.httpUserAgent, bakery...
go
{ "resource": "" }
q176650
sqliteOpen
test
func sqliteOpen(path string) (*sql.DB, error) { timeout := 5 // TODO - make this command-line configurable? // These are used to tune the transaction BEGIN behavior instead of using the // similar "locking_mode" pragma (locking for the whole database connection). openPath := fmt.Sprintf("%s?_busy_timeout=%d&_txloc...
go
{ "resource": "" }
q176651
Rebalance
test
func Rebalance(state *state.State, gateway *Gateway) (string, []db.RaftNode, error) { // First get the current raft members, since this method should be // called after a node has left. currentRaftNodes, err := gateway.currentRaftNodes() if err != nil { return "", nil, errors.Wrap(err, "failed to get current raft...
go
{ "resource": "" }
q176652
Promote
test
func Promote(state *state.State, gateway *Gateway, nodes []db.RaftNode) error { logger.Info("Promote node to database node") // Sanity check that this is not already a database node if gateway.IsDatabaseNode() { return fmt.Errorf("this node is already a database node") } // Figure out our own address. address...
go
{ "resource": "" }
q176653
Purge
test
func Purge(cluster *db.Cluster, name string) error { logger.Debugf("Remove node %s from the database", name) return cluster.Transaction(func(tx *db.ClusterTx) error { // Get the node (if it doesn't exists an error is returned). node, err := tx.NodeByName(name) if err != nil { return errors.Wrapf(err, "faile...
go
{ "resource": "" }
q176654
List
test
func List(state *state.State) ([]api.ClusterMember, error) { addresses := []string{} // Addresses of database nodes err := state.Node.Transaction(func(tx *db.NodeTx) error { nodes, err := tx.RaftNodes() if err != nil { return errors.Wrap(err, "failed to fetch current raft nodes") } for _, node := range nod...
go
{ "resource": "" }
q176655
Count
test
func Count(state *state.State) (int, error) { var count int err := state.Cluster.Transaction(func(tx *db.ClusterTx) error { var err error count, err = tx.NodesCount() return err }) return count, err }
go
{ "resource": "" }
q176656
Enabled
test
func Enabled(node *db.Node) (bool, error) { enabled := false err := node.Transaction(func(tx *db.NodeTx) error { addresses, err := tx.RaftNodeAddresses() if err != nil { return err } enabled = len(addresses) > 0 return nil }) return enabled, err }
go
{ "resource": "" }
q176657
membershipCheckNodeStateForBootstrapOrJoin
test
func membershipCheckNodeStateForBootstrapOrJoin(tx *db.NodeTx, address string) error { nodes, err := tx.RaftNodes() if err != nil { return errors.Wrap(err, "failed to fetch current raft nodes") } hasClusterAddress := address != "" hasRaftNodes := len(nodes) > 0 // Sanity check that we're not in an inconsisten...
go
{ "resource": "" }
q176658
membershipCheckClusterStateForBootstrapOrJoin
test
func membershipCheckClusterStateForBootstrapOrJoin(tx *db.ClusterTx) error { nodes, err := tx.Nodes() if err != nil { return errors.Wrap(err, "failed to fetch current cluster nodes") } if len(nodes) != 1 { return fmt.Errorf("inconsistent state: found leftover entries in nodes") } return nil }
go
{ "resource": "" }
q176659
membershipCheckClusterStateForAccept
test
func membershipCheckClusterStateForAccept(tx *db.ClusterTx, name string, address string, schema int, api int) error { nodes, err := tx.Nodes() if err != nil { return errors.Wrap(err, "failed to fetch current cluster nodes") } if len(nodes) == 1 && nodes[0].Address == "0.0.0.0" { return fmt.Errorf("clustering no...
go
{ "resource": "" }
q176660
membershipCheckClusterStateForLeave
test
func membershipCheckClusterStateForLeave(tx *db.ClusterTx, nodeID int64) error { // Check that it has no containers or images. message, err := tx.NodeIsEmpty(nodeID) if err != nil { return err } if message != "" { return fmt.Errorf(message) } // Check that it's not the last node. nodes, err := tx.Nodes() ...
go
{ "resource": "" }
q176661
membershipCheckNoLeftoverClusterCert
test
func membershipCheckNoLeftoverClusterCert(dir string) error { // Sanity check that there's no leftover cluster certificate for _, basename := range []string{"cluster.crt", "cluster.key", "cluster.ca"} { if shared.PathExists(filepath.Join(dir, basename)) { return fmt.Errorf("inconsistent state: found leftover clu...
go
{ "resource": "" }
q176662
ConfigLoad
test
func ConfigLoad(tx *db.NodeTx) (*Config, error) { // Load current raw values from the database, any error is fatal. values, err := tx.Config() if err != nil { return nil, fmt.Errorf("cannot fetch node config from database: %v", err) } m, err := config.SafeLoad(ConfigSchema, values) if err != nil { return nil...
go
{ "resource": "" }
q176663
Replace
test
func (c *Config) Replace(values map[string]interface{}) (map[string]string, error) { return c.update(values) }
go
{ "resource": "" }
q176664
Patch
test
func (c *Config) Patch(patch map[string]interface{}) (map[string]string, error) { values := c.Dump() // Use current values as defaults for name, value := range patch { values[name] = value } return c.update(values) }
go
{ "resource": "" }
q176665
HTTPSAddress
test
func HTTPSAddress(node *db.Node) (string, error) { var config *Config err := node.Transaction(func(tx *db.NodeTx) error { var err error config, err = ConfigLoad(tx) return err }) if err != nil { return "", err } return config.HTTPSAddress(), nil }
go
{ "resource": "" }
q176666
CertificatesGet
test
func (c *Cluster) CertificatesGet() (certs []*CertInfo, err error) { err = c.Transaction(func(tx *ClusterTx) error { rows, err := tx.tx.Query( "SELECT id, fingerprint, type, name, certificate FROM certificates", ) if err != nil { return err } defer rows.Close() for rows.Next() { cert := new(Cert...
go
{ "resource": "" }
q176667
CertificateGet
test
func (c *Cluster) CertificateGet(fingerprint string) (cert *CertInfo, err error) { cert = new(CertInfo) inargs := []interface{}{fingerprint + "%"} outfmt := []interface{}{ &cert.ID, &cert.Fingerprint, &cert.Type, &cert.Name, &cert.Certificate, } query := ` SELECT id, fingerprint, type, name, certi...
go
{ "resource": "" }
q176668
CertSave
test
func (c *Cluster) CertSave(cert *CertInfo) error { err := c.Transaction(func(tx *ClusterTx) error { stmt, err := tx.tx.Prepare(` INSERT INTO certificates ( fingerprint, type, name, certificate ) VALUES (?, ?, ?, ?)`, ) if err != nil { return err } defer stmt.Close() _, err = stmt.E...
go
{ "resource": "" }
q176669
CertDelete
test
func (c *Cluster) CertDelete(fingerprint string) error { err := exec(c.db, "DELETE FROM certificates WHERE fingerprint=?", fingerprint) if err != nil { return err } return nil }
go
{ "resource": "" }
q176670
CertUpdate
test
func (c *Cluster) CertUpdate(fingerprint string, certName string, certType int) error { err := c.Transaction(func(tx *ClusterTx) error { _, err := tx.tx.Exec("UPDATE certificates SET name=?, type=? WHERE fingerprint=?", certName, certType, fingerprint) return err }) return err }
go
{ "resource": "" }
q176671
createDevLxdlListener
test
func createDevLxdlListener(dir string) (net.Listener, error) { path := filepath.Join(dir, "devlxd", "sock") // If this socket exists, that means a previous LXD instance died and // didn't clean up. We assume that such LXD instance is actually dead // if we get this far, since localCreateListener() tries to connect...
go
{ "resource": "" }
q176672
Servers
test
func (i *raftInstance) Servers() ([]raft.Server, error) { if i.raft.State() != raft.Leader { return nil, raft.ErrNotLeader } future := i.raft.GetConfiguration() err := future.Error() if err != nil { return nil, err } configuration := future.Configuration() return configuration.Servers, nil }
go
{ "resource": "" }
q176673
Shutdown
test
func (i *raftInstance) Shutdown() error { logger.Debug("Stop raft instance") // Invoke raft APIs asynchronously to allow for a timeout. timeout := 10 * time.Second errCh := make(chan error) timer := time.After(timeout) go func() { errCh <- i.raft.Shutdown().Error() }() select { case err := <-errCh: if er...
go
{ "resource": "" }
q176674
raftNetworkTransport
test
func raftNetworkTransport( db *db.Node, address string, logger *log.Logger, timeout time.Duration, dial rafthttp.Dial) (raft.Transport, *rafthttp.Handler, *rafthttp.Layer, error) { handler := rafthttp.NewHandlerWithLogger(logger) addr, err := net.ResolveTCPAddr("tcp", address) if err != nil { return nil, nil,...
go
{ "resource": "" }
q176675
raftConfig
test
func raftConfig(latency float64) *raft.Config { config := raft.DefaultConfig() scale := func(duration *time.Duration) { *duration = time.Duration((math.Ceil(float64(*duration) * latency))) } durations := []*time.Duration{ &config.HeartbeatTimeout, &config.ElectionTimeout, &config.CommitTimeout, &config.Le...
go
{ "resource": "" }
q176676
raftMaybeBootstrap
test
func raftMaybeBootstrap( conf *raft.Config, logs *raftboltdb.BoltStore, snaps raft.SnapshotStore, trans raft.Transport) error { // First check if we were already bootstrapped. hasExistingState, err := raft.HasExistingState(logs, logs, snaps) if err != nil { return errors.Wrap(err, "failed to check if raft has ...
go
{ "resource": "" }
q176677
CPUResource
test
func CPUResource() (*api.ResourcesCPU, error) { c := api.ResourcesCPU{} threads, err := getThreads() if err != nil { return nil, err } var cur *api.ResourcesCPUSocket c.Total = uint64(len(threads)) for _, v := range threads { if uint64(len(c.Sockets)) <= v.socketID { c.Sockets = append(c.Sockets, api.R...
go
{ "resource": "" }
q176678
MemoryResource
test
func MemoryResource() (*api.ResourcesMemory, error) { var buffers uint64 var cached uint64 var free uint64 var total uint64 f, err := os.Open("/proc/meminfo") if err != nil { return nil, err } defer f.Close() cleanLine := func(l string) (string, error) { l = strings.TrimSpace(l) idx := strings.LastInde...
go
{ "resource": "" }
q176679
GetOperationUUIDs
test
func (r *ProtocolLXD) GetOperationUUIDs() ([]string, error) { urls := []string{} // Fetch the raw value _, err := r.queryStruct("GET", "/operations", nil, "", &urls) if err != nil { return nil, err } // Parse it uuids := []string{} for _, url := range urls { fields := strings.Split(url, "/operations/") ...
go
{ "resource": "" }
q176680
GetOperations
test
func (r *ProtocolLXD) GetOperations() ([]api.Operation, error) { apiOperations := map[string][]api.Operation{} // Fetch the raw value _, err := r.queryStruct("GET", "/operations?recursion=1", nil, "", &apiOperations) if err != nil { return nil, err } // Turn it into just a list of operations operations := []...
go
{ "resource": "" }
q176681
GetOperation
test
func (r *ProtocolLXD) GetOperation(uuid string) (*api.Operation, string, error) { op := api.Operation{} // Fetch the raw value etag, err := r.queryStruct("GET", fmt.Sprintf("/operations/%s", url.QueryEscape(uuid)), nil, "", &op) if err != nil { return nil, "", err } return &op, etag, nil }
go
{ "resource": "" }
q176682
GetOperationWebsocket
test
func (r *ProtocolLXD) GetOperationWebsocket(uuid string, secret string) (*websocket.Conn, error) { path := fmt.Sprintf("/operations/%s/websocket", url.QueryEscape(uuid)) if secret != "" { path = fmt.Sprintf("%s?secret=%s", path, url.QueryEscape(secret)) } return r.websocket(path) }
go
{ "resource": "" }
q176683
tryMount
test
func tryMount(src string, dst string, fs string, flags uintptr, options string) error { var err error for i := 0; i < 20; i++ { err = syscall.Mount(src, dst, fs, flags, options) if err == nil { break } time.Sleep(500 * time.Millisecond) } if err != nil { return err } return nil }
go
{ "resource": "" }
q176684
lxdUsesPool
test
func lxdUsesPool(dbObj *db.Cluster, onDiskPoolName string, driver string, onDiskProperty string) (bool, string, error) { pools, err := dbObj.StoragePools() if err != nil && err != db.ErrNoSuchObject { return false, "", err } for _, pool := range pools { _, pl, err := dbObj.StoragePoolGet(pool) if err != nil ...
go
{ "resource": "" }
q176685
ProjectURIs
test
func (c *ClusterTx) ProjectURIs(filter ProjectFilter) ([]string, error) { // Check which filter criteria are active. criteria := map[string]interface{}{} if filter.Name != "" { criteria["Name"] = filter.Name } // Pick the prepared statement and arguments to use based on active criteria. var stmt *sql.Stmt var...
go
{ "resource": "" }
q176686
ProjectList
test
func (c *ClusterTx) ProjectList(filter ProjectFilter) ([]api.Project, error) { // Result slice. objects := make([]api.Project, 0) // Check which filter criteria are active. criteria := map[string]interface{}{} if filter.Name != "" { criteria["Name"] = filter.Name } // Pick the prepared statement and argument...
go
{ "resource": "" }
q176687
ProjectGet
test
func (c *ClusterTx) ProjectGet(name string) (*api.Project, error) { filter := ProjectFilter{} filter.Name = name objects, err := c.ProjectList(filter) if err != nil { return nil, errors.Wrap(err, "Failed to fetch Project") } switch len(objects) { case 0: return nil, ErrNoSuchObject case 1: return &objec...
go
{ "resource": "" }
q176688
ProjectExists
test
func (c *ClusterTx) ProjectExists(name string) (bool, error) { _, err := c.ProjectID(name) if err != nil { if err == ErrNoSuchObject { return false, nil } return false, err } return true, nil }
go
{ "resource": "" }
q176689
ProjectCreate
test
func (c *ClusterTx) ProjectCreate(object api.ProjectsPost) (int64, error) { // Check if a project with the same key exists. exists, err := c.ProjectExists(object.Name) if err != nil { return -1, errors.Wrap(err, "Failed to check for duplicates") } if exists { return -1, fmt.Errorf("This project already exists"...
go
{ "resource": "" }
q176690
ProjectUsedByRef
test
func (c *ClusterTx) ProjectUsedByRef(filter ProjectFilter) (map[string][]string, error) { // Result slice. objects := make([]struct { Name string Value string }, 0) // Check which filter criteria are active. criteria := map[string]interface{}{} if filter.Name != "" { criteria["Name"] = filter.Name } //...
go
{ "resource": "" }
q176691
ProjectRename
test
func (c *ClusterTx) ProjectRename(name string, to string) error { stmt := c.stmt(projectRename) result, err := stmt.Exec(to, name) if err != nil { return errors.Wrap(err, "Rename project") } n, err := result.RowsAffected() if err != nil { return errors.Wrap(err, "Fetch affected rows") } if n != 1 { retur...
go
{ "resource": "" }
q176692
ProjectDelete
test
func (c *ClusterTx) ProjectDelete(name string) error { stmt := c.stmt(projectDelete) result, err := stmt.Exec(name) if err != nil { return errors.Wrap(err, "Delete project") } n, err := result.RowsAffected() if err != nil { return errors.Wrap(err, "Fetch affected rows") } if n != 1 { return fmt.Errorf("Q...
go
{ "resource": "" }
q176693
PasswordCheck
test
func PasswordCheck(secret string, password string) error { // No password set if secret == "" { return fmt.Errorf("No password is set") } // Compare the password buff, err := hex.DecodeString(secret) if err != nil { return err } salt := buff[0:32] hash, err := scrypt.Key([]byte(password), salt, 1<<14, 8,...
go
{ "resource": "" }
q176694
LoadCert
test
func LoadCert(dir string) (*shared.CertInfo, error) { prefix := "server" if shared.PathExists(filepath.Join(dir, "cluster.crt")) { prefix = "cluster" } cert, err := shared.KeyPairAndCA(dir, prefix, shared.CertServer) if err != nil { return nil, errors.Wrap(err, "failed to load TLS certificate") } return cert...
go
{ "resource": "" }
q176695
WriteCert
test
func WriteCert(dir, prefix string, cert, key, ca []byte) error { err := ioutil.WriteFile(filepath.Join(dir, prefix+".crt"), cert, 0644) if err != nil { return err } err = ioutil.WriteFile(filepath.Join(dir, prefix+".key"), key, 0600) if err != nil { return err } if ca != nil { err = ioutil.WriteFile(file...
go
{ "resource": "" }
q176696
NewDaemon
test
func NewDaemon(config *DaemonConfig, os *sys.OS) *Daemon { return &Daemon{ config: config, os: os, setupChan: make(chan struct{}), readyChan: make(chan struct{}), shutdownChan: make(chan struct{}), } }
go
{ "resource": "" }
q176697
DefaultDaemon
test
func DefaultDaemon() *Daemon { config := DefaultDaemonConfig() os := sys.DefaultOS() return NewDaemon(config, os) }
go
{ "resource": "" }
q176698
AllowProjectPermission
test
func AllowProjectPermission(feature string, permission string) func(d *Daemon, r *http.Request) Response { return func(d *Daemon, r *http.Request) Response { // Shortcut for speed if d.userIsAdmin(r) { return EmptySyncResponse } // Get the project project := projectParam(r) // Validate whether the use...
go
{ "resource": "" }
q176699
checkTrustedClient
test
func (d *Daemon) checkTrustedClient(r *http.Request) error { trusted, _, _, err := d.Authenticate(r) if !trusted || err != nil { if err != nil { return err } return fmt.Errorf("Not authorized") } return nil }
go
{ "resource": "" }