id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c177100
kind = local case *net.TCPListener: kind = network listener = networkTLSListener(listener, cert) default: continue } listeners[kind] = listener } return listeners }
c177101
c.m.GetInt64("candid.expiry"), c.m.GetString("candid.domains") }
c177102
c.m.GetInt64("rbac.expiry"), c.m.GetString("rbac.agent.url"), c.m.GetString("rbac.agent.username"), c.m.GetString("rbac.agent.private_key"), c.m.GetString("rbac.agent.public_key") }
c177103
:= c.m.GetInt64("images.auto_update_interval") return time.Duration(n) * time.Hour }
c177104
c.m.GetString("maas.api.key") return url, key }
c177105
c.m.GetInt64("cluster.offline_threshold") return time.Duration(n) * time.Second }
c177106
{ return "", err } return config.m.GetString(key), nil }
c177107
return false, err } return config.m.GetBool(key), nil }
c177108
return 0, err } return config.m.GetInt64(key), nil }
c177109
listener := e.listeners[cluster] if listener == nil { return "" } return listener.Addr().String() }
c177110
line, runtime.FuncForPC(pc).Name(), msg) Log.Debug(msg, ctx...) } }
c177111
c) } mux.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { logger.Info("Sending top level 404", log.Ctx{"url": r.URL}) w.Header().Set("Content-Type", "application/json") NotFound(nil).Render(w) }) return &http.Server{Handler: &lxdHttpServer{r: mux, d: d}} }
c177112
== "" { project = "default" } return project }
c177113
if err != nil { logger.Warnf("Failed to parse query string %q: %v", request.URL.RawQuery, err) return "" } } if values == nil { values = make(url.Values) } return values.Get(key) }
c177114
return fmt.Errorf("Not implemented") }, } cmd.AddCommand(newDbSchema()) cmd.AddCommand(newDbMapper()) return cmd }
c177115
return "Image download token" case OperationImageRefresh: return "Refreshing image" case OperationVolumeCopy: return "Copying storage volume" case OperationVolumeCreate: return "Creating storage volume" case OperationVolumeMigrate: return "Migrating storage volume" case OperationVolumeMove: return "Moving storage volume" case OperationVolumeSnapshotCreate: return "Creating storage volume snapshot" case OperationVolumeSnapshotDelete: return "Deleting storage volume snapshot" case OperationVolumeSnapshotUpdate: return "Updating storage volume snapshot" case OperationProjectRename: return "Renaming project" case OperationImagesExpire: return "Cleaning up expired images" case OperationImagesPruneLeftover: return "Pruning leftover image files" case OperationImagesUpdate: return "Updating images" case OperationImagesSynchronize: return "Synchronizing images" case OperationLogsExpire: return "Expiring log files" case OperationInstanceTypesUpdate: return "Updating instance types" case OperationBackupsExpire: return "Cleaning up expired backups" case OperationSnapshotsExpire: return "Cleaning up expired snapshots" default: return "Executing operation" } }
c177116
OperationContainerCreate: return "manage-containers" case OperationContainerUpdate: return "manage-containers" case OperationContainerRename: return "manage-containers" case OperationContainerMigrate: return "manage-containers" case OperationContainerLiveMigrate: return "manage-containers" case OperationContainerDelete: return "manage-containers" case OperationSnapshotRestore: return "manage-containers" case OperationImageDownload: return "manage-images" case OperationImageDelete: return "manage-images" case OperationImageToken: return "manage-images" case OperationImageRefresh: return "manage-images" case OperationImagesUpdate: return "manage-images" case OperationImagesSynchronize: return "manage-images" } return "" }
c177117
"SELECT uuid FROM operations WHERE node_id=?" return query.SelectStrings(c.tx, stmt, c.nodeID) }
c177118
projects ON projects.id = operations.project_id JOIN nodes ON nodes.id = operations.node_id WHERE projects.name = ? OR operations.project_id IS NULL ` return query.SelectStrings(c.tx, stmt, project) }
c177119
0: return null, ErrNoSuchObject case 1: return operations[0], nil default: return null, fmt.Errorf("more than one node matches") } }
c177120
if err != nil { return -1, errors.Wrap(err, "Fetch project ID") } } else { projectID = nil } columns := []string{"uuid", "node_id", "type", "project_id"} values := []interface{}{uuid, c.nodeID, typ, projectID} return query.UpsertObject(c.tx, "operations", columns, values) }
c177121
if err != nil { return err } if n != 1 { return fmt.Errorf("query deleted %d rows instead of 1", n) } return nil }
c177122
where) } sql += "ORDER BY operations.id" stmt, err := c.tx.Prepare(sql) if err != nil { return nil, err } defer stmt.Close() err = query.SelectObjects(stmt, dest, args...) if err != nil { return nil, errors.Wrap(err, "Failed to fetch operations") } return operations, nil }
c177123
opRun, nil, nil) if err != nil { logger.Error("Failed to start log expiry operation", log.Ctx{"err": err}) return } logger.Infof("Expiring log files") _, err = op.Run() if err != nil { logger.Error("Failed to expire logs", log.Ctx{"err": err}) } logger.Infof("Done expiring log files") } return f, task.Daily() }
c177124
{ elems = append([]string{string(filepath.Separator)}, elems[:i]...) elems = append(elems, path) return filepath.Join(elems...) } } log.Fatalf("Could not found root dir of LXD tree source tree") return "" }
c177125
i := 0 for key := range s { keys[i] = key i++ } sort.Strings(keys) return keys }
c177126
len(s)) for name, key := range s { values[name] = key.Default } return values }
c177127
if !ok { panic(fmt.Sprintf("attempt to access unknown key '%s'", name)) } return key }
c177128
'%s' has type code %d, not %d", name, key.Type, code)) } }
c177129
} default: panic(fmt.Sprintf("unexpected value type: %d", v.Type)) } if v.Deprecated != "" && value != v.Default { return fmt.Errorf("deprecated: %s", v.Deprecated) } // Run external validation function return validator(value) }
c177130
err := r.queryStruct("GET", fmt.Sprintf("/storage-pools/%s/volumes?recursion=1", url.QueryEscape(pool)), nil, "", &volumes) if err != nil { return nil, err } return volumes, nil }
c177131
:= fmt.Sprintf("/storage-pools/%s/volumes/%s/%s", url.QueryEscape(pool), url.QueryEscape(volType), url.QueryEscape(name)) etag, err := r.queryStruct("GET", path, nil, "", &volume) if err != nil { return nil, "", err } return &volume, etag, nil }
c177132
\"storage\" API extension") } // Send the request path := fmt.Sprintf("/storage-pools/%s/volumes/%s", url.QueryEscape(pool), url.QueryEscape(volume.Type)) _, _, err := r.query("POST", path, volume, "") if err != nil { return err } return nil }
c177133
:= fmt.Sprintf("/storage-pools/%s/volumes/%s/%s/snapshots", url.QueryEscape(pool), url.QueryEscape(volumeType), url.QueryEscape(volumeName)) op, _, err := r.queryOperation("POST", path, snapshot, "") if err != nil { return nil, err } return op, nil }
c177134
API extension") } snapshots := []api.StorageVolumeSnapshot{} path := fmt.Sprintf("/storage-pools/%s/volumes/%s/%s/snapshots?recursion=1", url.QueryEscape(pool), url.QueryEscape(volumeType), url.QueryEscape(volumeName)) _, err := r.queryStruct("GET", path, nil, "", &snapshots) if err != nil { return nil, err } return snapshots, nil }
c177135
url.QueryEscape(volumeType), url.QueryEscape(volumeName), url.QueryEscape(snapshotName)) etag, err := r.queryStruct("GET", path, nil, "", &snapshot) if err != nil { return nil, "", err } return &snapshot, etag, nil }
c177136
:= fmt.Sprintf("/storage-pools/%s/volumes/%s/%s/snapshots/%s", url.QueryEscape(pool), url.QueryEscape(volumeType), url.QueryEscape(volumeName), url.QueryEscape(snapshotName)) _, _, err := r.queryOperation("PUT", path, volume, ETag) if err != nil { return err } return nil }
c177137
} // Sanity check if !volume.Migration { return nil, fmt.Errorf("Can't ask for a rename through MigrateStoragePoolVolume") } // Send the request path := fmt.Sprintf("/storage-pools/%s/volumes/custom/%s", url.QueryEscape(pool), volume.Name) op, _, err := r.queryOperation("POST", path, volume, "") if err != nil { return nil, err } return op, nil }
c177138
:= r.queryOperation("POST", fmt.Sprintf("/storage-pools/%s/volumes/%s/%s", url.QueryEscape(sourcePool), url.QueryEscape(volume.Type), volume.Name), req, "") if err != nil { return nil, err } rop := remoteOperation{ targetOp: op, chDone: make(chan bool), } // Forward targetOp to remote op go func() { rop.err = rop.targetOp.Wait() close(rop.chDone) }() return &rop, nil }
c177139
} // Send the request path := fmt.Sprintf("/storage-pools/%s/volumes/%s/%s", url.QueryEscape(pool), url.QueryEscape(volType), url.QueryEscape(name)) _, _, err := r.query("PUT", path, volume, ETag) if err != nil { return err } return nil }
c177140
API extension") } // Send the request path := fmt.Sprintf("/storage-pools/%s/volumes/%s/%s", url.QueryEscape(pool), url.QueryEscape(volType), url.QueryEscape(name)) _, _, err := r.query("DELETE", path, nil, "") if err != nil { return err } return nil }
c177141
path := fmt.Sprintf("/storage-pools/%s/volumes/%s/%s", url.QueryEscape(pool), url.QueryEscape(volType), url.QueryEscape(name)) // Send the request _, _, err := r.query("POST", path, volume, "") if err != nil { return err } return nil }
c177142
when we create a loop file image. This means we append ".img" // to the path the user gave us and update the config in the storage // callback. So diff the config here to see if something like this has // happened. postCreateConfig := s.GetStoragePoolWritable().Config configDiff, _ := storageConfigDiff(config, postCreateConfig) if len(configDiff) > 0 { // Create the database entry for the storage pool. err = state.Cluster.StoragePoolUpdate(poolName, poolDescription, postCreateConfig) if err != nil { return fmt.Errorf("Error inserting %s into database: %s", poolName, err) } } // Success, update the closure to mark that the changes should be kept. tryUndo = false return nil }
c177143
shared.SnapshotDelimiter, 2) if len(fields) == 1 { return name, "", false } return fields[0], fields[1], true }
c177144
nil { return nil, err } containers := []container{} for _, project := range projects { projectContainers, err := containerLoadByProject(s, project) if err != nil { return nil, errors.Wrapf(nil, "Load containers in project %s", project) } containers = append(containers, projectContainers...) } return containers, nil }
c177145
!= nil { return err } return nil }) if err != nil { return nil, err } return containerLoadAllInternal(cts, s) }
c177146
!= nil { return err } return nil }) if err != nil { return nil, err } return containerLoadAllInternal(cts, s) }
c177147
!= nil { return err } ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() request = request.WithContext(ctx) request.Close = true // Immediately close the connection after the request is done // Perform the request asynchronously, so we can abort it if the task context is done. errCh := make(chan error) go func() { response, err := client.Do(request) if err != nil { errCh <- errors.Wrap(err, "failed to send HTTP request") return } defer response.Body.Close() if response.StatusCode != http.StatusOK { errCh <- fmt.Errorf("HTTP request failed: %s", response.Status) return } errCh <- nil }() select { case err := <-errCh: return err case <-taskCtx.Done(): return taskCtx.Err() } }
c177148
:= range fullMembs { if !strings.HasPrefix(fullMembs[i], shortMembs[i]) { return false } } return true }
c177149
s.doContainerMount(c.Project(), c.Name(), c.IsPrivileged()) }
c177150
fmt.Sprintf("containers/%s", volumeName) return zfsFilesystemEntityExists(s.getOnDiskPoolName(), fs) }
c177151
:= askQuestion(question, defaultAnswer) if shared.StringInSlice(answer, choices) { return answer } invalidInput() } }
c177152
== -1 || result >= min) && (max == -1 || result <= max) { return result } invalidInput() } }
c177153
fmt.Fprintf(os.Stderr, "Invalid input: %s\n\n", error) continue } return answer } if len(answer) != 0 { return answer } invalidInput() } }
c177154
:= string(pwd) inSecond = strings.TrimSuffix(inSecond, "\n") if inFirst == inSecond { return inFirst } invalidInput() } }
c177155
terminal.ReadPassword(0) fmt.Println("") return string(pwd) }
c177156
return readAnswer(defaultAnswer) }
c177157
answer = strings.TrimSpace(answer) if answer == "" { answer = defaultAnswer } return answer }
c177158
if shared.StringInSlice(req.Name, []string{".", ".."}) { return BadRequest(fmt.Errorf("Invalid profile name '%s'", req.Name)) } err := d.cluster.Transaction(func(tx *db.ClusterTx) error { hasProfiles, err := tx.ProjectHasProfiles(project) if err != nil { return errors.Wrap(err, "Check project features") } if !hasProfiles { project = "default" } // Check that the name isn't already in use _, err = tx.ProfileGet(project, req.Name) if err == nil { return fmt.Errorf("Name '%s' already in use", req.Name) } return tx.ProfileRename(project, name, req.Name) }) if err != nil { return SmartError(err) } return SyncResponseLocation(true, nil, fmt.Sprintf("/%s/profiles/%s", version.APIVersion, req.Name)) }
c177159
profile, err := tx.ProfileGet(project, name) if err != nil { return err } if len(profile.UsedBy) > 0 { return fmt.Errorf("Profile is currently in use") } return tx.ProfileDelete(project, name) }) if err != nil { return SmartError(err) } return EmptySyncResponse }
c177160
== "disk" && device["path"] == "/" && device["source"] == "" { return true } return false }
c177161
if devName != "" { return "", nil, fmt.Errorf("More than one root device found") } devName = n dev = d } } if devName != "" { return devName, dev, nil } return "", nil, fmt.Errorf("No root device could be found") }
c177162
&forwardedResponse{ client: client, request: request, } }
c177163
:= d.endpoints.NetworkCert() client, err := cluster.Connect(address, cert, false) if err != nil { return SmartError(err) } return ForwardedResponse(client, request) } return nil }
c177164
if err != nil { return nil, err } if client == nil { return nil, nil } return ForwardedResponse(client, r), nil }
c177165
&forwardedOperationResponse{ op: op, project: project, } }
c177166
return } // Print the new message if msg != "" { msg += "\n" } if len(msg) > p.maxLength { p.maxLength = len(msg) } else { fmt.Printf("\r%s", strings.Repeat(" ", p.maxLength)) } fmt.Print("\r") fmt.Print(msg) }
c177167
Truncate msg to terminal length msg = "\r" + p.truncate(msg) // Don't print if empty and never printed if len(msg) == 1 && p.maxLength == 0 { return } if len(msg) > p.maxLength { p.maxLength = len(msg) } else { fmt.Printf("\r%s", strings.Repeat(" ", p.maxLength)) } fmt.Print(msg) }
c177168
:= fmt.Sprintf("%s", status) // Truncate msg to terminal length msg = "\r" + p.truncate(msg) // Don't print if empty and never printed if len(msg) == 1 && p.maxLength == 0 { return } if len(msg) > p.maxLength { p.maxLength = len(msg) } else { fmt.Printf("\r%s", strings.Repeat(" ", p.maxLength)) } fmt.Print(msg) }
c177169
ioprogress.ProgressData) { p.Update(progress.Text) }
c177170
if !strings.HasSuffix(key, "_progress") { continue } p.Update(value.(string)) break } }
c177171
DELETE FROM storage_pools_config WHERE key='zfs.pool_name' AND storage_pool_id=? AND node_id IS NULL `, poolID) if err != nil { return errors.Wrap(err, "failed to delete zfs.pool_name config") } // Add zfs.pool_name config entry for each node for _, nodeID := range nodeIDs { _, err := tx.Exec(` INSERT INTO storage_pools_config(storage_pool_id, node_id, key, value) VALUES(?, ?, 'zfs.pool_name', ?) `, poolID, nodeID, poolName) if err != nil { return errors.Wrap(err, "failed to create zfs.pool_name node config") } } } return nil }
c177172
socketUnixListen(path) if err != nil { return nil, err } err = localSetAccess(path, group) if err != nil { listener.Close() return nil, err } return listener, nil }
c177173
entity: entity, kind: kind, config: config, packages: packages, } return stmt, nil }
c177174
return s.id(buf) case "rename": return s.rename(buf) case "update": return s.update(buf) case "delete": return s.delete(buf) default: return fmt.Errorf("Unknown statement '%s'", s.kind) } }
c177175
} buf.L("var %s = %s.RegisterStmt(`\n%s\n`)", stmtCodeVar(s.entity, kind, filters...), s.db, sql) }
c177176
} if args.CookieJar != nil { httpClient.Jar = args.CookieJar } server.http = httpClient if args.AuthType == "candid" { server.setupBakeryClient() } // Test the connection and seed the server information if !args.SkipGetServer { _, _, err := server.GetServer() if err != nil { return nil, err } } return &server, nil }
c177177
Error: return false default: return true } }
c177178
1: return addresses[0], nil default: // This should never happen since we have a UNIQUE constraint // on the raft_nodes.id column. return "", fmt.Errorf("more than one match found") } }
c177179
id, err := query.UpsertObject(n.tx, "raft_nodes", columns, values) if err != nil { return err } if id != 1 { return fmt.Errorf("could not set raft node ID to 1") } return nil }
c177180
return query.UpsertObject(n.tx, "raft_nodes", columns, values) }
c177181
return err } if !deleted { return ErrNoSuchObject } return nil }
c177182
_, err := query.UpsertObject(n.tx, "raft_nodes", columns, values) if err != nil { return err } } return nil }
c177183
&s.CGroupMemoryController, &s.CGroupNetPrioController, &s.CGroupPidsController, &s.CGroupSwapAccounting, } for i, flag := range flags { *flag = shared.PathExists("/sys/fs/cgroup/" + cGroups[i].path) if !*flag { logger.Warnf(cGroups[i].warn) } } }
c177184
return err } // Ensure WAL autocheckpoint is disabled, since checkpoints are // triggered explicitly by dqlite. _, err = conn.Exec("PRAGMA wal_autocheckpoint=0", nil) if err != nil { return err } return nil }
c177185
} switch len(objects) { case 0: return nil, ErrNoSuchObject case 1: return &objects[0], nil default: return nil, fmt.Errorf("More than one container matches") } }
c177186
return -1, errors.Wrap(err, "Failed to scan ID") } if rows.Next() { return -1, fmt.Errorf("More than one row returned") } err = rows.Err() if err != nil { return -1, errors.Wrap(err, "Result set failure") } return id, nil }
c177187
if err == ErrNoSuchObject { return false, nil } return false, err } return true, nil }
c177188
== other.Type.Name { matches[field] = true } } } return len(matches) == len(fields) }
c177189
== name { return field } } return nil }
c177190
fmt.Sprintf("%s.%s", entityTable(m.Name), field.Column()) }
c177191
if field.Type.Code != TypeColumn { return nil, fmt.Errorf("Unknown filter %q not a column", name) } return field, nil }
c177192
if shared.StringInSlice(field.Name, exclude) { continue } if field.Type.Code == TypeColumn { fields = append(fields, field) } } return fields }
c177193
"" { fields = append(fields, field) } } return fields }
c177194
== TypeMap { fields = append(fields, field) } } return fields }
c177195
} column := lex.Snake(f.Name) join := f.Config.Get("join") if join != "" { column = fmt.Sprintf("%s AS %s", join, column) } return column }
c177196
since at the moment integer criteria are // required to be positive. return "-1" default: panic("unsupported zero value") } }
c177197
columns[i] = field.Column() } return strings.Join(columns, ", ") }
c177198
%s", lex.Minuscule(field.Name), field.Type.Name) } return strings.Join(args, ", ") }
c177199
args[i] = lex.Minuscule(field.Name) } return strings.Join(args, ", ") }