_id
stringlengths
2
7
title
stringlengths
1
118
partition
stringclasses
3 values
text
stringlengths
52
85.5k
language
stringclasses
1 value
meta_information
dict
q176800
TrimAboveName
test
func (pcs Trace) TrimAboveName(name string) Trace { for len(pcs) > 0 && pcs[len(pcs)-1].name() != name { pcs = pcs[:len(pcs)-1] } return pcs }
go
{ "resource": "" }
q176801
TrimRuntime
test
func (pcs Trace) TrimRuntime() Trace { for len(pcs) > 0 && inGoroot(pcs[len(pcs)-1].file()) { pcs = pcs[:len(pcs)-1] } return pcs }
go
{ "resource": "" }
q176802
GetCaps
test
func GetCaps(path string) ([]byte, error) { xattrs, err := shared.GetAllXattr(path) if err != nil { return nil, err } valueStr, ok := xattrs["security.capability"] if !ok { return nil, nil } return []byte(valueStr), nil }
go
{ "resource": "" }
q176803
SetCaps
test
func SetCaps(path string, caps []byte, uid int64) error { cpath := C.CString(path) defer C.free(unsafe.Pointer(cpath)) ccaps := C.CString(string(caps)) defer C.free(unsafe.Pointer(ccaps)) r := C.set_vfs_ns_caps(cpath, ccaps, C.ssize_t(len(caps)), C.uint32_t(uid)) if r != 0 { return fmt.Errorf("Failed to apply...
go
{ "resource": "" }
q176804
Read
test
func (pt *ProgressReader) Read(p []byte) (int, error) { // Do normal reader tasks n, err := pt.ReadCloser.Read(p) // Do the actual progress tracking if pt.Tracker != nil { pt.Tracker.total += int64(n) pt.Tracker.update(n) } return n, err }
go
{ "resource": "" }
q176805
Supported
test
func Supported(path string) (bool, error) { // Get the backing device devPath, err := devForPath(path) if err != nil { return false, err } // Call quotactl through CGo cDevPath := C.CString(devPath) defer C.free(unsafe.Pointer(cDevPath)) return C.quota_supported(cDevPath) == 0, nil }
go
{ "resource": "" }
q176806
GetProject
test
func GetProject(path string) (uint32, error) { // Call ioctl through CGo cPath := C.CString(path) defer C.free(unsafe.Pointer(cPath)) id := C.quota_get_path(cPath) if id < 0 { return 0, fmt.Errorf("Failed to get project from '%s'", path) } return uint32(id), nil }
go
{ "resource": "" }
q176807
SetProject
test
func SetProject(path string, id uint32) error { // Call ioctl through CGo cPath := C.CString(path) defer C.free(unsafe.Pointer(cPath)) if C.quota_set_path(cPath, C.uint32_t(id)) != 0 { return fmt.Errorf("Failed to set project id '%d' on '%s'", id, path) } return nil }
go
{ "resource": "" }
q176808
DeleteProject
test
func DeleteProject(path string, id uint32) error { // Unset the project from the path err := SetProject(path, 0) if err != nil { return err } // Unset the quota on the project err = SetProjectQuota(path, id, 0) if err != nil { return err } return nil }
go
{ "resource": "" }
q176809
GetProjectUsage
test
func GetProjectUsage(path string, id uint32) (int64, error) { // Get the backing device devPath, err := devForPath(path) if err != nil { return -1, err } // Call quotactl through CGo cDevPath := C.CString(devPath) defer C.free(unsafe.Pointer(cDevPath)) size := C.quota_get_usage(cDevPath, C.uint32_t(id)) if...
go
{ "resource": "" }
q176810
SetProjectQuota
test
func SetProjectQuota(path string, id uint32, bytes int64) error { // Get the backing device devPath, err := devForPath(path) if err != nil { return err } // Call quotactl through CGo cDevPath := C.CString(devPath) defer C.free(unsafe.Pointer(cDevPath)) if C.quota_set(cDevPath, C.uint32_t(id), C.int(bytes/10...
go
{ "resource": "" }
q176811
backupLoadByName
test
func backupLoadByName(s *state.State, project, name string) (*backup, error) { // Get the backup database record args, err := s.Cluster.ContainerGetBackup(project, name) if err != nil { return nil, errors.Wrap(err, "Load backup from database") } // Load the container it belongs to c, err := containerLoadById(s...
go
{ "resource": "" }
q176812
backupCreate
test
func backupCreate(s *state.State, args db.ContainerBackupArgs, sourceContainer container) error { // Create the database entry err := s.Cluster.ContainerBackupCreate(args) if err != nil { if err == db.ErrAlreadyDefined { return fmt.Errorf("backup '%s' already exists", args.Name) } return errors.Wrap(err, "...
go
{ "resource": "" }
q176813
Rename
test
func (b *backup) Rename(newName string) error { oldBackupPath := shared.VarPath("backups", b.name) newBackupPath := shared.VarPath("backups", newName) // Create the new backup path backupsPath := shared.VarPath("backups", b.container.Name()) if !shared.PathExists(backupsPath) { err := os.MkdirAll(backupsPath, 0...
go
{ "resource": "" }
q176814
Delete
test
func (b *backup) Delete() error { return doBackupDelete(b.state, b.name, b.container.Name()) }
go
{ "resource": "" }
q176815
backupFixStoragePool
test
func backupFixStoragePool(c *db.Cluster, b backupInfo, useDefaultPool bool) error { var poolName string if useDefaultPool { // Get the default profile _, profile, err := c.ProfileGet("default", "default") if err != nil { return err } _, v, err := shared.GetRootDiskDevice(profile.Devices) if err != ni...
go
{ "resource": "" }
q176816
Count
test
func Count(tx *sql.Tx, table string, where string, args ...interface{}) (int, error) { stmt := fmt.Sprintf("SELECT COUNT(*) FROM %s", table) if where != "" { stmt += fmt.Sprintf(" WHERE %s", where) } rows, err := tx.Query(stmt, args...) if err != nil { return -1, err } defer rows.Close() // For sanity, mak...
go
{ "resource": "" }
q176817
CountAll
test
func CountAll(tx *sql.Tx) (map[string]int, error) { tables, err := SelectStrings(tx, "SELECT name FROM sqlite_master WHERE type = 'table'") if err != nil { return nil, errors.Wrap(err, "Failed to fetch table names") } counts := map[string]int{} for _, table := range tables { count, err := Count(tx, table, "")...
go
{ "resource": "" }
q176818
InitTLSConfig
test
func InitTLSConfig() *tls.Config { return &tls.Config{ MinVersion: tls.VersionTLS12, CipherSuites: []uint16{ tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, tls.TLS_ECDHE_RSA...
go
{ "resource": "" }
q176819
copyContainerThinpool
test
func (s *storageLvm) copyContainerThinpool(target container, source container, readonly bool) error { err := s.createSnapshotContainer(target, source, readonly) if err != nil { logger.Errorf("Error creating snapshot LV for copy: %s", err) return err } // Generate a new xfs's UUID LVFilesystem := s.getLvmFiles...
go
{ "resource": "" }
q176820
copyContainerLv
test
func (s *storageLvm) copyContainerLv(target container, source container, readonly bool, refresh bool) error { exists, err := storageLVExists(getLvmDevPath(target.Project(), s.getOnDiskPoolName(), storagePoolVolumeAPIEndpointContainers, containerNameToLVName(target.Name()))) if err != nil { return err } // Only...
go
{ "resource": "" }
q176821
copyContainer
test
func (s *storageLvm) copyContainer(target container, source container, refresh bool) error { targetPool, err := target.StoragePool() if err != nil { return err } targetContainerMntPoint := getContainerMountPoint(target.Project(), targetPool, target.Name()) err = createContainerMountpoint(targetContainerMntPoint...
go
{ "resource": "" }
q176822
copyVolume
test
func (s *storageLvm) copyVolume(sourcePool string, source string) error { targetMntPoint := getStoragePoolVolumeMountPoint(s.pool.Name, s.volume.Name) err := os.MkdirAll(targetMntPoint, 0711) if err != nil { return err } if s.useThinpool && sourcePool == s.pool.Name { err = s.copyVolumeThinpool(source, s.vol...
go
{ "resource": "" }
q176823
GetPrivateImage
test
func (r *ProtocolSimpleStreams) GetPrivateImage(fingerprint string, secret string) (*api.Image, string, error) { return nil, "", fmt.Errorf("Private images aren't supported by the simplestreams protocol") }
go
{ "resource": "" }
q176824
GetPrivateImageFile
test
func (r *ProtocolSimpleStreams) GetPrivateImageFile(fingerprint string, secret string, req ImageFileRequest) (*ImageFileResponse, error) { return nil, fmt.Errorf("Private images aren't supported by the simplestreams protocol") }
go
{ "resource": "" }
q176825
GetImageAliasNames
test
func (r *ProtocolSimpleStreams) GetImageAliasNames() ([]string, error) { // Get all the images from simplestreams aliases, err := r.ssClient.ListAliases() if err != nil { return nil, err } // And now extract just the names names := []string{} for _, alias := range aliases { names = append(names, alias.Name)...
go
{ "resource": "" }
q176826
ProtoRecv
test
func ProtoRecv(ws *websocket.Conn, msg proto.Message) error { mt, r, err := ws.NextReader() if err != nil { return err } if mt != websocket.BinaryMessage { return fmt.Errorf("Only binary messages allowed") } buf, err := ioutil.ReadAll(r) if err != nil { return err } err = proto.Unmarshal(buf, msg) if...
go
{ "resource": "" }
q176827
ProtoSend
test
func ProtoSend(ws *websocket.Conn, msg proto.Message) error { w, err := ws.NextWriter(websocket.BinaryMessage) if err != nil { return err } defer w.Close() data, err := proto.Marshal(msg) if err != nil { return err } err = shared.WriteAll(w, data) if err != nil { return err } return nil }
go
{ "resource": "" }
q176828
ProtoSendControl
test
func ProtoSendControl(ws *websocket.Conn, err error) { message := "" if err != nil { message = err.Error() } msg := MigrationControl{ Success: proto.Bool(err == nil), Message: proto.String(message), } ProtoSend(ws, &msg) }
go
{ "resource": "" }
q176829
Read
test
func (er stdinMirror) Read(p []byte) (int, error) { n, err := er.r.Read(p) v := rune(p[0]) if v == '\u0001' && !*er.foundEscape { *er.foundEscape = true return 0, err } if v == 'q' && *er.foundEscape { select { case er.consoleDisconnect <- true: return 0, err default: return 0, err } } *er.f...
go
{ "resource": "" }
q176830
doContainersGetFromNode
test
func doContainersGetFromNode(project, node string, cert *shared.CertInfo) ([]api.Container, error) { f := func() ([]api.Container, error) { client, err := cluster.Connect(node, cert, true) if err != nil { return nil, errors.Wrapf(err, "Failed to connect to node %s", node) } client = client.UseProject(proje...
go
{ "resource": "" }
q176831
Retry
test
func Retry(f func() error) error { // TODO: the retry loop should be configurable. var err error for i := 0; i < 5; i++ { err = f() if err != nil { logger.Debugf("Database error: %#v", err) if IsRetriableError(err) { logger.Debugf("Retry failed db interaction (%v)", err) time.Sleep(250 * time.Mill...
go
{ "resource": "" }
q176832
IsRetriableError
test
func IsRetriableError(err error) bool { err = errors.Cause(err) if err == nil { return false } if err == sqlite3.ErrLocked || err == sqlite3.ErrBusy { return true } if strings.Contains(err.Error(), "database is locked") { return true } if strings.Contains(err.Error(), "bad connection") { return true ...
go
{ "resource": "" }
q176833
AppArmorProfile
test
func AppArmorProfile() string { contents, err := ioutil.ReadFile("/proc/self/attr/current") if err == nil { return strings.TrimSpace(string(contents)) } return "" }
go
{ "resource": "" }
q176834
StoragePoolVolumeCreate
test
func (s *storageBtrfs) StoragePoolVolumeCreate() error { logger.Infof("Creating BTRFS storage volume \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name) _, err := s.StoragePoolMount() if err != nil { return err } isSnapshot := shared.IsSnapshot(s.volume.Name) // Create subvolume path on the storage p...
go
{ "resource": "" }
q176835
ContainerStorageReady
test
func (s *storageBtrfs) ContainerStorageReady(container container) bool { containerMntPoint := getContainerMountPoint(container.Project(), s.pool.Name, container.Name()) return isBtrfsSubVolume(containerMntPoint) }
go
{ "resource": "" }
q176836
ContainerCreateFromImage
test
func (s *storageBtrfs) ContainerCreateFromImage(container container, fingerprint string, tracker *ioprogress.ProgressTracker) error { logger.Debugf("Creating BTRFS storage volume for container \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name) source := s.pool.Config["source"] if source == "" { return fm...
go
{ "resource": "" }
q176837
ContainerSnapshotRename
test
func (s *storageBtrfs) ContainerSnapshotRename(snapshotContainer container, newName string) error { logger.Debugf("Renaming BTRFS storage volume for snapshot \"%s\" from %s to %s", s.volume.Name, s.volume.Name, newName) // The storage pool must be mounted. _, err := s.StoragePoolMount() if err != nil { return er...
go
{ "resource": "" }
q176838
ContainerSnapshotCreateEmpty
test
func (s *storageBtrfs) ContainerSnapshotCreateEmpty(snapshotContainer container) error { logger.Debugf("Creating empty BTRFS storage volume for snapshot \"%s\" on storage pool \"%s\"", s.volume.Name, s.pool.Name) // Mount the storage pool. _, err := s.StoragePoolMount() if err != nil { return err } // Create ...
go
{ "resource": "" }
q176839
btrfsSubVolumesDelete
test
func btrfsSubVolumesDelete(subvol string) error { // Delete subsubvols. subsubvols, err := btrfsSubVolumesGet(subvol) if err != nil { return err } sort.Sort(sort.Reverse(sort.StringSlice(subsubvols))) for _, subsubvol := range subsubvols { err := btrfsSubVolumeDelete(path.Join(subvol, subsubvol)) if err !=...
go
{ "resource": "" }
q176840
isBtrfsSubVolume
test
func isBtrfsSubVolume(subvolPath string) bool { fs := syscall.Stat_t{} err := syscall.Lstat(subvolPath, &fs) if err != nil { return false } // Check if BTRFS_FIRST_FREE_OBJECTID if fs.Ino != 256 { return false } return true }
go
{ "resource": "" }
q176841
SelectConfig
test
func SelectConfig(tx *sql.Tx, table string, where string, args ...interface{}) (map[string]string, error) { query := fmt.Sprintf("SELECT key, value FROM %s", table) if where != "" { query += fmt.Sprintf(" WHERE %s", where) } rows, err := tx.Query(query, args...) if err != nil { return nil, err } defer rows....
go
{ "resource": "" }
q176842
UpdateConfig
test
func UpdateConfig(tx *sql.Tx, table string, values map[string]string) error { changes := map[string]string{} deletes := []string{} for key, value := range values { if value == "" { deletes = append(deletes, key) continue } changes[key] = value } err := upsertConfig(tx, table, changes) if err != nil ...
go
{ "resource": "" }
q176843
deleteConfig
test
func deleteConfig(tx *sql.Tx, table string, keys []string) error { n := len(keys) if n == 0 { return nil // Nothing to delete. } query := fmt.Sprintf("DELETE FROM %s WHERE key IN %s", table, Params(n)) values := make([]interface{}, n) for i, key := range keys { values[i] = key } _, err := tx.Exec(query, v...
go
{ "resource": "" }
q176844
FormatSection
test
func FormatSection(header string, content string) string { out := "" // Add section header if header != "" { out += header + ":\n" } // Indent the content for _, line := range strings.Split(content, "\n") { if line != "" { out += " " } out += line + "\n" } if header != "" { // Section separato...
go
{ "resource": "" }
q176845
GetProjects
test
func (r *ProtocolLXD) GetProjects() ([]api.Project, error) { if !r.HasExtension("projects") { return nil, fmt.Errorf("The server is missing the required \"projects\" API extension") } projects := []api.Project{} // Fetch the raw value _, err := r.queryStruct("GET", "/projects?recursion=1", nil, "", &projects) ...
go
{ "resource": "" }
q176846
GetProject
test
func (r *ProtocolLXD) GetProject(name string) (*api.Project, string, error) { if !r.HasExtension("projects") { return nil, "", fmt.Errorf("The server is missing the required \"projects\" API extension") } project := api.Project{} // Fetch the raw value etag, err := r.queryStruct("GET", fmt.Sprintf("/projects/%...
go
{ "resource": "" }
q176847
CreateProject
test
func (r *ProtocolLXD) CreateProject(project api.ProjectsPost) error { if !r.HasExtension("projects") { return fmt.Errorf("The server is missing the required \"projects\" API extension") } // Send the request _, _, err := r.query("POST", "/projects", project, "") if err != nil { return err } return nil }
go
{ "resource": "" }
q176848
UpdateProject
test
func (r *ProtocolLXD) UpdateProject(name string, project api.ProjectPut, ETag string) error { if !r.HasExtension("projects") { return fmt.Errorf("The server is missing the required \"projects\" API extension") } // Send the request _, _, err := r.query("PUT", fmt.Sprintf("/projects/%s", url.QueryEscape(name)), p...
go
{ "resource": "" }
q176849
RenameProject
test
func (r *ProtocolLXD) RenameProject(name string, project api.ProjectPost) (Operation, error) { if !r.HasExtension("projects") { return nil, fmt.Errorf("The server is missing the required \"projects\" API extension") } // Send the request op, _, err := r.queryOperation("POST", fmt.Sprintf("/projects/%s", url.Quer...
go
{ "resource": "" }
q176850
Read
test
func (er Reader) Read(p []byte) (int, error) { again: n, err := er.Reader.Read(p) if err == nil { return n, nil } // keep retrying on EAGAIN errno, ok := shared.GetErrno(err) if ok && (errno == syscall.EAGAIN || errno == syscall.EINTR) { goto again } return n, err }
go
{ "resource": "" }
q176851
Write
test
func (ew Writer) Write(p []byte) (int, error) { again: n, err := ew.Writer.Write(p) if err == nil { return n, nil } // keep retrying on EAGAIN errno, ok := shared.GetErrno(err) if ok && (errno == syscall.EAGAIN || errno == syscall.EINTR) { goto again } return n, err }
go
{ "resource": "" }
q176852
NewCanceler
test
func NewCanceler() *Canceler { c := Canceler{} c.lock.Lock() c.reqChCancel = make(map[*http.Request]chan struct{}) c.lock.Unlock() return &c }
go
{ "resource": "" }
q176853
Cancelable
test
func (c *Canceler) Cancelable() bool { c.lock.Lock() length := len(c.reqChCancel) c.lock.Unlock() return length > 0 }
go
{ "resource": "" }
q176854
Cancel
test
func (c *Canceler) Cancel() error { if !c.Cancelable() { return fmt.Errorf("This operation can't be canceled at this time") } c.lock.Lock() for req, ch := range c.reqChCancel { close(ch) delete(c.reqChCancel, req) } c.lock.Unlock() return nil }
go
{ "resource": "" }
q176855
CancelableDownload
test
func CancelableDownload(c *Canceler, client *http.Client, req *http.Request) (*http.Response, chan bool, error) { chDone := make(chan bool) chCancel := make(chan struct{}) if c != nil { c.lock.Lock() c.reqChCancel[req] = chCancel c.lock.Unlock() } req.Cancel = chCancel go func() { <-chDone if c != nil ...
go
{ "resource": "" }
q176856
clusterGet
test
func clusterGet(d *Daemon, r *http.Request) Response { name := "" err := d.cluster.Transaction(func(tx *db.ClusterTx) error { var err error name, err = tx.NodeName() return err }) if err != nil { return SmartError(err) } // If the name is set to the hard-coded default node name, then // clustering is no...
go
{ "resource": "" }
q176857
clusterGetMemberConfig
test
func clusterGetMemberConfig(cluster *db.Cluster) ([]api.ClusterMemberConfigKey, error) { var pools map[string]map[string]string var networks map[string]map[string]string keys := []api.ClusterMemberConfigKey{} err := cluster.Transaction(func(tx *db.ClusterTx) error { var err error pools, err = tx.StoragePools...
go
{ "resource": "" }
q176858
clusterPutDisable
test
func clusterPutDisable(d *Daemon) Response { // Close the cluster database err := d.cluster.Close() if err != nil { return SmartError(err) } // Update our TLS configuration using our original certificate. for _, suffix := range []string{"crt", "key", "ca"} { path := filepath.Join(d.os.VarDir, "cluster."+suff...
go
{ "resource": "" }
q176859
tryClusterRebalance
test
func tryClusterRebalance(d *Daemon) error { leader, err := d.gateway.LeaderAddress() if err != nil { // This is not a fatal error, so let's just log it. return errors.Wrap(err, "failed to get current leader node") } cert := d.endpoints.NetworkCert() client, err := cluster.Connect(leader, cert, true) if err !=...
go
{ "resource": "" }
q176860
internalClusterPostRebalance
test
func internalClusterPostRebalance(d *Daemon, r *http.Request) Response { // Redirect all requests to the leader, which is the one with with // up-to-date knowledge of what nodes are part of the raft cluster. localAddress, err := node.ClusterAddress(d.db) if err != nil { return SmartError(err) } leader, err := d...
go
{ "resource": "" }
q176861
internalClusterPostPromote
test
func internalClusterPostPromote(d *Daemon, r *http.Request) Response { req := internalClusterPostPromoteRequest{} // Parse the request err := json.NewDecoder(r.Body).Decode(&req) if err != nil { return BadRequest(err) } // Sanity checks if len(req.RaftNodes) == 0 { return BadRequest(fmt.Errorf("No raft nod...
go
{ "resource": "" }
q176862
Filters
test
func Filters(pkg *ast.Package, entity string) [][]string { objects := pkg.Scope.Objects filters := [][]string{} prefix := fmt.Sprintf("%sObjectsBy", entity) for name := range objects { if !strings.HasPrefix(name, prefix) { continue } rest := name[len(prefix):] filters = append(filters, strings.Split(re...
go
{ "resource": "" }
q176863
Parse
test
func Parse(pkg *ast.Package, name string) (*Mapping, error) { str := findStruct(pkg.Scope, name) if str == nil { return nil, fmt.Errorf("No declaration found for %q", name) } fields, err := parseStruct(str) if err != nil { return nil, errors.Wrapf(err, "Failed to parse %q", name) } m := &Mapping{ Package...
go
{ "resource": "" }
q176864
findStruct
test
func findStruct(scope *ast.Scope, name string) *ast.StructType { obj := scope.Lookup(name) if obj == nil { return nil } typ, ok := obj.Decl.(*ast.TypeSpec) if !ok { return nil } str, ok := typ.Type.(*ast.StructType) if !ok { return nil } return str }
go
{ "resource": "" }
q176865
parseStruct
test
func parseStruct(str *ast.StructType) ([]*Field, error) { fields := make([]*Field, 0) for _, f := range str.Fields.List { if len(f.Names) == 0 { // Check if this is a parent struct. ident, ok := f.Type.(*ast.Ident) if !ok { continue } typ, ok := ident.Obj.Decl.(*ast.TypeSpec) if !ok { co...
go
{ "resource": "" }
q176866
GetProfileNames
test
func (r *ProtocolLXD) GetProfileNames() ([]string, error) { urls := []string{} // Fetch the raw value _, err := r.queryStruct("GET", "/profiles", nil, "", &urls) if err != nil { return nil, err } // Parse it names := []string{} for _, url := range urls { fields := strings.Split(url, "/profiles/") names ...
go
{ "resource": "" }
q176867
GetProfiles
test
func (r *ProtocolLXD) GetProfiles() ([]api.Profile, error) { profiles := []api.Profile{} // Fetch the raw value _, err := r.queryStruct("GET", "/profiles?recursion=1", nil, "", &profiles) if err != nil { return nil, err } return profiles, nil }
go
{ "resource": "" }
q176868
GetProfile
test
func (r *ProtocolLXD) GetProfile(name string) (*api.Profile, string, error) { profile := api.Profile{} // Fetch the raw value etag, err := r.queryStruct("GET", fmt.Sprintf("/profiles/%s", url.QueryEscape(name)), nil, "", &profile) if err != nil { return nil, "", err } return &profile, etag, nil }
go
{ "resource": "" }
q176869
CreateProfile
test
func (r *ProtocolLXD) CreateProfile(profile api.ProfilesPost) error { // Send the request _, _, err := r.query("POST", "/profiles", profile, "") if err != nil { return err } return nil }
go
{ "resource": "" }
q176870
UpdateProfile
test
func (r *ProtocolLXD) UpdateProfile(name string, profile api.ProfilePut, ETag string) error { // Send the request _, _, err := r.query("PUT", fmt.Sprintf("/profiles/%s", url.QueryEscape(name)), profile, ETag) if err != nil { return err } return nil }
go
{ "resource": "" }
q176871
RenameProfile
test
func (r *ProtocolLXD) RenameProfile(name string, profile api.ProfilePost) error { // Send the request _, _, err := r.query("POST", fmt.Sprintf("/profiles/%s", url.QueryEscape(name)), profile, "") if err != nil { return err } return nil }
go
{ "resource": "" }
q176872
Load
test
func Load(schema Schema, values map[string]string) (Map, error) { m := Map{ schema: schema, } // Populate the initial values. _, err := m.update(values) return m, err }
go
{ "resource": "" }
q176873
Dump
test
func (m *Map) Dump() map[string]interface{} { values := map[string]interface{}{} for name, key := range m.schema { value := m.GetRaw(name) if value != key.Default { if key.Hidden { values[name] = true } else { values[name] = value } } } return values }
go
{ "resource": "" }
q176874
GetRaw
test
func (m *Map) GetRaw(name string) string { key := m.schema.mustGetKey(name) value, ok := m.values[name] if !ok { value = key.Default } return value }
go
{ "resource": "" }
q176875
GetString
test
func (m *Map) GetString(name string) string { m.schema.assertKeyType(name, String) return m.GetRaw(name) }
go
{ "resource": "" }
q176876
GetBool
test
func (m *Map) GetBool(name string) bool { m.schema.assertKeyType(name, Bool) return shared.IsTrue(m.GetRaw(name)) }
go
{ "resource": "" }
q176877
GetInt64
test
func (m *Map) GetInt64(name string) int64 { m.schema.assertKeyType(name, Int64) n, err := strconv.ParseInt(m.GetRaw(name), 10, 64) if err != nil { panic(fmt.Sprintf("cannot convert to int64: %v", err)) } return n }
go
{ "resource": "" }
q176878
update
test
func (m *Map) update(values map[string]string) ([]string, error) { // Detect if this is the first time we're setting values. This happens // when Load is called. initial := m.values == nil if initial { m.values = make(map[string]string, len(values)) } // Update our keys with the values from the given map, and...
go
{ "resource": "" }
q176879
set
test
func (m *Map) set(name string, value string, initial bool) (bool, error) { key, ok := m.schema[name] if !ok { return false, fmt.Errorf("unknown key") } err := key.validate(value) if err != nil { return false, err } // Normalize boolan values, so the comparison below works fine. current := m.GetRaw(name) ...
go
{ "resource": "" }
q176880
DoesSchemaTableExist
test
func DoesSchemaTableExist(tx *sql.Tx) (bool, error) { statement := ` SELECT COUNT(name) FROM sqlite_master WHERE type = 'table' AND name = 'schema' ` rows, err := tx.Query(statement) if err != nil { return false, err } defer rows.Close() if !rows.Next() { return false, fmt.Errorf("schema table query returned...
go
{ "resource": "" }
q176881
selectSchemaVersions
test
func selectSchemaVersions(tx *sql.Tx) ([]int, error) { statement := ` SELECT version FROM schema ORDER BY version ` return query.SelectIntegers(tx, statement) }
go
{ "resource": "" }
q176882
selectTablesSQL
test
func selectTablesSQL(tx *sql.Tx) ([]string, error) { statement := ` SELECT sql FROM sqlite_master WHERE type IN ('table', 'index', 'view') AND name != 'schema' AND name NOT LIKE 'sqlite_%' ORDER BY name ` return query.SelectStrings(tx, statement) }
go
{ "resource": "" }
q176883
createSchemaTable
test
func createSchemaTable(tx *sql.Tx) error { statement := ` CREATE TABLE schema ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, version INTEGER NOT NULL, updated_at DATETIME NOT NULL, UNIQUE (version) ) ` _, err := tx.Exec(statement) return err }
go
{ "resource": "" }
q176884
insertSchemaVersion
test
func insertSchemaVersion(tx *sql.Tx, new int) error { statement := ` INSERT INTO schema (version, updated_at) VALUES (?, strftime("%s")) ` _, err := tx.Exec(statement, new) return err }
go
{ "resource": "" }
q176885
NewState
test
func NewState(node *db.Node, cluster *db.Cluster, maas *maas.Controller, os *sys.OS, endpoints *endpoints.Endpoints) *State { return &State{ Node: node, Cluster: cluster, MAAS: maas, OS: os, Endpoints: endpoints, } }
go
{ "resource": "" }
q176886
containerLXCUnload
test
func containerLXCUnload(c *containerLXC) { runtime.SetFinalizer(c, nil) if c.c != nil { c.c.Release() c.c = nil } }
go
{ "resource": "" }
q176887
containerLXCInstantiate
test
func containerLXCInstantiate(s *state.State, args db.ContainerArgs) *containerLXC { return &containerLXC{ state: s, id: args.ID, project: args.Project, name: args.Name, description: args.Description, ephemeral: args.Ephemeral, architecture: args.Architecture, cType: ...
go
{ "resource": "" }
q176888
initStorage
test
func (c *containerLXC) initStorage() error { if c.storage != nil { return nil } s, err := storagePoolVolumeContainerLoadInit(c.state, c.Project(), c.Name()) if err != nil { return err } c.storage = s return nil }
go
{ "resource": "" }
q176889
OnNetworkUp
test
func (c *containerLXC) OnNetworkUp(deviceName string, hostName string) error { device := c.expandedDevices[deviceName] device["host_name"] = hostName return c.setupHostVethDevice(device) }
go
{ "resource": "" }
q176890
setupHostVethDevice
test
func (c *containerLXC) setupHostVethDevice(device types.Device) error { // If not already, populate network device with host name. if device["host_name"] == "" { device["host_name"] = c.getHostInterface(device["name"]) } // Check whether host device resolution succeeded. if device["host_name"] == "" { return ...
go
{ "resource": "" }
q176891
getLxcState
test
func (c *containerLXC) getLxcState() (lxc.State, error) { if c.IsSnapshot() { return lxc.StateMap["STOPPED"], nil } // Load the go-lxc struct err := c.initLXC(false) if err != nil { return lxc.StateMap["STOPPED"], err } monitor := make(chan lxc.State, 1) go func(c *lxc.Container) { monitor <- c.State()...
go
{ "resource": "" }
q176892
StorageStartSensitive
test
func (c *containerLXC) StorageStartSensitive() (bool, error) { // Initialize storage interface for the container. err := c.initStorage() if err != nil { return false, err } var isOurOperation bool if c.IsSnapshot() { isOurOperation, err = c.storage.ContainerSnapshotStart(c) } else { isOurOperation, err = ...
go
{ "resource": "" }
q176893
deviceExistsInDevicesFolder
test
func (c *containerLXC) deviceExistsInDevicesFolder(prefix string, path string) bool { relativeDestPath := strings.TrimPrefix(path, "/") devName := fmt.Sprintf("%s.%s", strings.Replace(prefix, "/", "-", -1), strings.Replace(relativeDestPath, "/", "-", -1)) devPath := filepath.Join(c.DevicesPath(), devName) return s...
go
{ "resource": "" }
q176894
createDiskDevice
test
func (c *containerLXC) createDiskDevice(name string, m types.Device) (string, error) { // source paths relativeDestPath := strings.TrimPrefix(m["path"], "/") devName := fmt.Sprintf("disk.%s.%s", strings.Replace(name, "/", "-", -1), strings.Replace(relativeDestPath, "/", "-", -1)) devPath := filepath.Join(c.DevicesP...
go
{ "resource": "" }
q176895
setNetworkRoutes
test
func (c *containerLXC) setNetworkRoutes(m types.Device) error { if !shared.PathExists(fmt.Sprintf("/sys/class/net/%s", m["host_name"])) { return fmt.Errorf("Unknown or missing host side veth: %s", m["host_name"]) } // Flush all IPv4 routes _, err := shared.RunCommand("ip", "-4", "route", "flush", "dev", m["host_...
go
{ "resource": "" }
q176896
Path
test
func (c *containerLXC) Path() string { name := projectPrefix(c.Project(), c.Name()) return containerPath(name, c.IsSnapshot()) }
go
{ "resource": "" }
q176897
maasInterfaces
test
func (c *containerLXC) maasInterfaces() ([]maas.ContainerInterface, error) { interfaces := []maas.ContainerInterface{} for k, m := range c.expandedDevices { if m["type"] != "nic" { continue } if m["maas.subnet.ipv4"] == "" && m["maas.subnet.ipv6"] == "" { continue } m, err := c.fillNetworkDevice(k, ...
go
{ "resource": "" }
q176898
getSystemHandler
test
func getSystemHandler(syslog string, debug bool, format log.Format) log.Handler { // SyslogHandler if syslog != "" { if !debug { return log.LvlFilterHandler( log.LvlInfo, log.Must.SyslogHandler(syslog, format), ) } return log.Must.SyslogHandler(syslog, format) } return nil }
go
{ "resource": "" }
q176899
findNvidiaMinor
test
func findNvidiaMinor(pci string) (string, error) { nvidiaPath := fmt.Sprintf("/proc/driver/nvidia/gpus/%s/information", pci) buf, err := ioutil.ReadFile(nvidiaPath) if err != nil { return "", err } strBuf := strings.TrimSpace(string(buf)) idx := strings.Index(strBuf, "Device Minor:") if idx != -1 { idx += l...
go
{ "resource": "" }