repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1 value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
Microsoft/hcsshim | internal/oci/uvm.go | parseAnnotationsBool | func parseAnnotationsBool(a map[string]string, key string, def bool) bool {
if v, ok := a[key]; ok {
switch strings.ToLower(v) {
case "true":
return true
case "false":
return false
default:
logrus.WithFields(logrus.Fields{
logfields.OCIAnnotation: key,
logfields.Value: v,
logfields.ExpectedType: logfields.Bool,
}).Warning("annotation could not be parsed")
}
}
return def
} | go | func parseAnnotationsBool(a map[string]string, key string, def bool) bool {
if v, ok := a[key]; ok {
switch strings.ToLower(v) {
case "true":
return true
case "false":
return false
default:
logrus.WithFields(logrus.Fields{
logfields.OCIAnnotation: key,
logfields.Value: v,
logfields.ExpectedType: logfields.Bool,
}).Warning("annotation could not be parsed")
}
}
return def
} | [
"func",
"parseAnnotationsBool",
"(",
"a",
"map",
"[",
"string",
"]",
"string",
",",
"key",
"string",
",",
"def",
"bool",
")",
"bool",
"{",
"if",
"v",
",",
"ok",
":=",
"a",
"[",
"key",
"]",
";",
"ok",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"v",
")",
"{",
"case",
"\"",
"\"",
":",
"return",
"true",
"\n",
"case",
"\"",
"\"",
":",
"return",
"false",
"\n",
"default",
":",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"OCIAnnotation",
":",
"key",
",",
"logfields",
".",
"Value",
":",
"v",
",",
"logfields",
".",
"ExpectedType",
":",
"logfields",
".",
"Bool",
",",
"}",
")",
".",
"Warning",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // parseAnnotationsBool searches `a` for `key` and if found verifies that the
// value is `true` or `false` in any case. If `key` is not found returns `def`. | [
"parseAnnotationsBool",
"searches",
"a",
"for",
"key",
"and",
"if",
"found",
"verifies",
"that",
"the",
"value",
"is",
"true",
"or",
"false",
"in",
"any",
"case",
".",
"If",
"key",
"is",
"not",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L120-L136 | train |
Microsoft/hcsshim | internal/oci/uvm.go | ParseAnnotationsCPUCount | func ParseAnnotationsCPUCount(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.CPU != nil &&
s.Windows.Resources.CPU.Count != nil &&
*s.Windows.Resources.CPU.Count > 0 {
return int32(*s.Windows.Resources.CPU.Count)
}
return def
} | go | func ParseAnnotationsCPUCount(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.CPU != nil &&
s.Windows.Resources.CPU.Count != nil &&
*s.Windows.Resources.CPU.Count > 0 {
return int32(*s.Windows.Resources.CPU.Count)
}
return def
} | [
"func",
"ParseAnnotationsCPUCount",
"(",
"s",
"*",
"specs",
".",
"Spec",
",",
"annotation",
"string",
",",
"def",
"int32",
")",
"int32",
"{",
"if",
"m",
":=",
"parseAnnotationsUint64",
"(",
"s",
".",
"Annotations",
",",
"annotation",
",",
"0",
")",
";",
"m",
"!=",
"0",
"{",
"return",
"int32",
"(",
"m",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"Windows",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
".",
"Count",
"!=",
"nil",
"&&",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
".",
"Count",
">",
"0",
"{",
"return",
"int32",
"(",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
".",
"Count",
")",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // ParseAnnotationsCPUCount searches `s.Annotations` for the CPU annotation. If
// not found searches `s` for the Windows CPU section. If neither are found
// returns `def`. | [
"ParseAnnotationsCPUCount",
"searches",
"s",
".",
"Annotations",
"for",
"the",
"CPU",
"annotation",
".",
"If",
"not",
"found",
"searches",
"s",
"for",
"the",
"Windows",
"CPU",
"section",
".",
"If",
"neither",
"are",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L141-L153 | train |
Microsoft/hcsshim | internal/oci/uvm.go | ParseAnnotationsCPULimit | func ParseAnnotationsCPULimit(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.CPU != nil &&
s.Windows.Resources.CPU.Maximum != nil &&
*s.Windows.Resources.CPU.Maximum > 0 {
return int32(*s.Windows.Resources.CPU.Maximum)
}
return def
} | go | func ParseAnnotationsCPULimit(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.CPU != nil &&
s.Windows.Resources.CPU.Maximum != nil &&
*s.Windows.Resources.CPU.Maximum > 0 {
return int32(*s.Windows.Resources.CPU.Maximum)
}
return def
} | [
"func",
"ParseAnnotationsCPULimit",
"(",
"s",
"*",
"specs",
".",
"Spec",
",",
"annotation",
"string",
",",
"def",
"int32",
")",
"int32",
"{",
"if",
"m",
":=",
"parseAnnotationsUint64",
"(",
"s",
".",
"Annotations",
",",
"annotation",
",",
"0",
")",
";",
"m",
"!=",
"0",
"{",
"return",
"int32",
"(",
"m",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"Windows",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
".",
"Maximum",
"!=",
"nil",
"&&",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
".",
"Maximum",
">",
"0",
"{",
"return",
"int32",
"(",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
".",
"Maximum",
")",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // ParseAnnotationsCPULimit searches `s.Annotations` for the CPU annotation. If
// not found searches `s` for the Windows CPU section. If neither are found
// returns `def`. | [
"ParseAnnotationsCPULimit",
"searches",
"s",
".",
"Annotations",
"for",
"the",
"CPU",
"annotation",
".",
"If",
"not",
"found",
"searches",
"s",
"for",
"the",
"Windows",
"CPU",
"section",
".",
"If",
"neither",
"are",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L158-L170 | train |
Microsoft/hcsshim | internal/oci/uvm.go | ParseAnnotationsCPUWeight | func ParseAnnotationsCPUWeight(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.CPU != nil &&
s.Windows.Resources.CPU.Shares != nil &&
*s.Windows.Resources.CPU.Shares > 0 {
return int32(*s.Windows.Resources.CPU.Shares)
}
return def
} | go | func ParseAnnotationsCPUWeight(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.CPU != nil &&
s.Windows.Resources.CPU.Shares != nil &&
*s.Windows.Resources.CPU.Shares > 0 {
return int32(*s.Windows.Resources.CPU.Shares)
}
return def
} | [
"func",
"ParseAnnotationsCPUWeight",
"(",
"s",
"*",
"specs",
".",
"Spec",
",",
"annotation",
"string",
",",
"def",
"int32",
")",
"int32",
"{",
"if",
"m",
":=",
"parseAnnotationsUint64",
"(",
"s",
".",
"Annotations",
",",
"annotation",
",",
"0",
")",
";",
"m",
"!=",
"0",
"{",
"return",
"int32",
"(",
"m",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"Windows",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
".",
"Shares",
"!=",
"nil",
"&&",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
".",
"Shares",
">",
"0",
"{",
"return",
"int32",
"(",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"CPU",
".",
"Shares",
")",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // ParseAnnotationsCPUWeight searches `s.Annotations` for the CPU annotation. If
// not found searches `s` for the Windows CPU section. If neither are found
// returns `def`. | [
"ParseAnnotationsCPUWeight",
"searches",
"s",
".",
"Annotations",
"for",
"the",
"CPU",
"annotation",
".",
"If",
"not",
"found",
"searches",
"s",
"for",
"the",
"Windows",
"CPU",
"section",
".",
"If",
"neither",
"are",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L175-L187 | train |
Microsoft/hcsshim | internal/oci/uvm.go | ParseAnnotationsStorageIops | func ParseAnnotationsStorageIops(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.Storage != nil &&
s.Windows.Resources.Storage.Iops != nil &&
*s.Windows.Resources.Storage.Iops > 0 {
return int32(*s.Windows.Resources.Storage.Iops)
}
return def
} | go | func ParseAnnotationsStorageIops(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.Storage != nil &&
s.Windows.Resources.Storage.Iops != nil &&
*s.Windows.Resources.Storage.Iops > 0 {
return int32(*s.Windows.Resources.Storage.Iops)
}
return def
} | [
"func",
"ParseAnnotationsStorageIops",
"(",
"s",
"*",
"specs",
".",
"Spec",
",",
"annotation",
"string",
",",
"def",
"int32",
")",
"int32",
"{",
"if",
"m",
":=",
"parseAnnotationsUint64",
"(",
"s",
".",
"Annotations",
",",
"annotation",
",",
"0",
")",
";",
"m",
"!=",
"0",
"{",
"return",
"int32",
"(",
"m",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"Windows",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"Storage",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"Storage",
".",
"Iops",
"!=",
"nil",
"&&",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"Storage",
".",
"Iops",
">",
"0",
"{",
"return",
"int32",
"(",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"Storage",
".",
"Iops",
")",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // ParseAnnotationsStorageIops searches `s.Annotations` for the `Iops`
// annotation. If not found searches `s` for the Windows Storage section. If
// neither are found returns `def`. | [
"ParseAnnotationsStorageIops",
"searches",
"s",
".",
"Annotations",
"for",
"the",
"Iops",
"annotation",
".",
"If",
"not",
"found",
"searches",
"s",
"for",
"the",
"Windows",
"Storage",
"section",
".",
"If",
"neither",
"are",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L192-L204 | train |
Microsoft/hcsshim | internal/oci/uvm.go | ParseAnnotationsStorageBps | func ParseAnnotationsStorageBps(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.Storage != nil &&
s.Windows.Resources.Storage.Bps != nil &&
*s.Windows.Resources.Storage.Bps > 0 {
return int32(*s.Windows.Resources.Storage.Bps)
}
return def
} | go | func ParseAnnotationsStorageBps(s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
s.Windows.Resources != nil &&
s.Windows.Resources.Storage != nil &&
s.Windows.Resources.Storage.Bps != nil &&
*s.Windows.Resources.Storage.Bps > 0 {
return int32(*s.Windows.Resources.Storage.Bps)
}
return def
} | [
"func",
"ParseAnnotationsStorageBps",
"(",
"s",
"*",
"specs",
".",
"Spec",
",",
"annotation",
"string",
",",
"def",
"int32",
")",
"int32",
"{",
"if",
"m",
":=",
"parseAnnotationsUint64",
"(",
"s",
".",
"Annotations",
",",
"annotation",
",",
"0",
")",
";",
"m",
"!=",
"0",
"{",
"return",
"int32",
"(",
"m",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"Windows",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"Storage",
"!=",
"nil",
"&&",
"s",
".",
"Windows",
".",
"Resources",
".",
"Storage",
".",
"Bps",
"!=",
"nil",
"&&",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"Storage",
".",
"Bps",
">",
"0",
"{",
"return",
"int32",
"(",
"*",
"s",
".",
"Windows",
".",
"Resources",
".",
"Storage",
".",
"Bps",
")",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // ParseAnnotationsStorageBps searches `s.Annotations` for the `Bps` annotation.
// If not found searches `s` for the Windows Storage section. If neither are
// found returns `def`. | [
"ParseAnnotationsStorageBps",
"searches",
"s",
".",
"Annotations",
"for",
"the",
"Bps",
"annotation",
".",
"If",
"not",
"found",
"searches",
"s",
"for",
"the",
"Windows",
"Storage",
"section",
".",
"If",
"neither",
"are",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L209-L221 | train |
Microsoft/hcsshim | internal/oci/uvm.go | parseAnnotationsPreferredRootFSType | func parseAnnotationsPreferredRootFSType(a map[string]string, key string, def uvm.PreferredRootFSType) uvm.PreferredRootFSType {
if v, ok := a[key]; ok {
switch v {
case "initrd":
return uvm.PreferredRootFSTypeInitRd
case "vhd":
return uvm.PreferredRootFSTypeVHD
default:
logrus.Warningf("annotation: '%s', with value: '%s' must be 'initrd' or 'vhd'", key, v)
}
}
return def
} | go | func parseAnnotationsPreferredRootFSType(a map[string]string, key string, def uvm.PreferredRootFSType) uvm.PreferredRootFSType {
if v, ok := a[key]; ok {
switch v {
case "initrd":
return uvm.PreferredRootFSTypeInitRd
case "vhd":
return uvm.PreferredRootFSTypeVHD
default:
logrus.Warningf("annotation: '%s', with value: '%s' must be 'initrd' or 'vhd'", key, v)
}
}
return def
} | [
"func",
"parseAnnotationsPreferredRootFSType",
"(",
"a",
"map",
"[",
"string",
"]",
"string",
",",
"key",
"string",
",",
"def",
"uvm",
".",
"PreferredRootFSType",
")",
"uvm",
".",
"PreferredRootFSType",
"{",
"if",
"v",
",",
"ok",
":=",
"a",
"[",
"key",
"]",
";",
"ok",
"{",
"switch",
"v",
"{",
"case",
"\"",
"\"",
":",
"return",
"uvm",
".",
"PreferredRootFSTypeInitRd",
"\n",
"case",
"\"",
"\"",
":",
"return",
"uvm",
".",
"PreferredRootFSTypeVHD",
"\n",
"default",
":",
"logrus",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"key",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // parseAnnotationsPreferredRootFSType searches `a` for `key` and verifies that the
// value is in the set of allowed values. If `key` is not found returns `def`. | [
"parseAnnotationsPreferredRootFSType",
"searches",
"a",
"for",
"key",
"and",
"verifies",
"that",
"the",
"value",
"is",
"in",
"the",
"set",
"of",
"allowed",
"values",
".",
"If",
"key",
"is",
"not",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L244-L256 | train |
Microsoft/hcsshim | internal/oci/uvm.go | parseAnnotationsUint32 | func parseAnnotationsUint32(a map[string]string, key string, def uint32) uint32 {
if v, ok := a[key]; ok {
countu, err := strconv.ParseUint(v, 10, 32)
if err == nil {
v := uint32(countu)
return v
}
logrus.WithFields(logrus.Fields{
logfields.OCIAnnotation: key,
logfields.Value: v,
logfields.ExpectedType: logfields.Uint32,
logrus.ErrorKey: err,
}).Warning("annotation could not be parsed")
}
return def
} | go | func parseAnnotationsUint32(a map[string]string, key string, def uint32) uint32 {
if v, ok := a[key]; ok {
countu, err := strconv.ParseUint(v, 10, 32)
if err == nil {
v := uint32(countu)
return v
}
logrus.WithFields(logrus.Fields{
logfields.OCIAnnotation: key,
logfields.Value: v,
logfields.ExpectedType: logfields.Uint32,
logrus.ErrorKey: err,
}).Warning("annotation could not be parsed")
}
return def
} | [
"func",
"parseAnnotationsUint32",
"(",
"a",
"map",
"[",
"string",
"]",
"string",
",",
"key",
"string",
",",
"def",
"uint32",
")",
"uint32",
"{",
"if",
"v",
",",
"ok",
":=",
"a",
"[",
"key",
"]",
";",
"ok",
"{",
"countu",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"v",
",",
"10",
",",
"32",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"v",
":=",
"uint32",
"(",
"countu",
")",
"\n",
"return",
"v",
"\n",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"OCIAnnotation",
":",
"key",
",",
"logfields",
".",
"Value",
":",
"v",
",",
"logfields",
".",
"ExpectedType",
":",
"logfields",
".",
"Uint32",
",",
"logrus",
".",
"ErrorKey",
":",
"err",
",",
"}",
")",
".",
"Warning",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // parseAnnotationsUint32 searches `a` for `key` and if found verifies that the
// value is a 32 bit unsigned integer. If `key` is not found returns `def`. | [
"parseAnnotationsUint32",
"searches",
"a",
"for",
"key",
"and",
"if",
"found",
"verifies",
"that",
"the",
"value",
"is",
"a",
"32",
"bit",
"unsigned",
"integer",
".",
"If",
"key",
"is",
"not",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L260-L275 | train |
Microsoft/hcsshim | internal/oci/uvm.go | parseAnnotationsUint64 | func parseAnnotationsUint64(a map[string]string, key string, def uint64) uint64 {
if v, ok := a[key]; ok {
countu, err := strconv.ParseUint(v, 10, 64)
if err == nil {
return countu
}
logrus.WithFields(logrus.Fields{
logfields.OCIAnnotation: key,
logfields.Value: v,
logfields.ExpectedType: logfields.Uint64,
logrus.ErrorKey: err,
}).Warning("annotation could not be parsed")
}
return def
} | go | func parseAnnotationsUint64(a map[string]string, key string, def uint64) uint64 {
if v, ok := a[key]; ok {
countu, err := strconv.ParseUint(v, 10, 64)
if err == nil {
return countu
}
logrus.WithFields(logrus.Fields{
logfields.OCIAnnotation: key,
logfields.Value: v,
logfields.ExpectedType: logfields.Uint64,
logrus.ErrorKey: err,
}).Warning("annotation could not be parsed")
}
return def
} | [
"func",
"parseAnnotationsUint64",
"(",
"a",
"map",
"[",
"string",
"]",
"string",
",",
"key",
"string",
",",
"def",
"uint64",
")",
"uint64",
"{",
"if",
"v",
",",
"ok",
":=",
"a",
"[",
"key",
"]",
";",
"ok",
"{",
"countu",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"v",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"countu",
"\n",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"logfields",
".",
"OCIAnnotation",
":",
"key",
",",
"logfields",
".",
"Value",
":",
"v",
",",
"logfields",
".",
"ExpectedType",
":",
"logfields",
".",
"Uint64",
",",
"logrus",
".",
"ErrorKey",
":",
"err",
",",
"}",
")",
".",
"Warning",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // parseAnnotationsUint64 searches `a` for `key` and if found verifies that the
// value is a 64 bit unsigned integer. If `key` is not found returns `def`. | [
"parseAnnotationsUint64",
"searches",
"a",
"for",
"key",
"and",
"if",
"found",
"verifies",
"that",
"the",
"value",
"is",
"a",
"64",
"bit",
"unsigned",
"integer",
".",
"If",
"key",
"is",
"not",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L279-L293 | train |
Microsoft/hcsshim | internal/oci/uvm.go | parseAnnotationsString | func parseAnnotationsString(a map[string]string, key string, def string) string {
if v, ok := a[key]; ok {
return v
}
return def
} | go | func parseAnnotationsString(a map[string]string, key string, def string) string {
if v, ok := a[key]; ok {
return v
}
return def
} | [
"func",
"parseAnnotationsString",
"(",
"a",
"map",
"[",
"string",
"]",
"string",
",",
"key",
"string",
",",
"def",
"string",
")",
"string",
"{",
"if",
"v",
",",
"ok",
":=",
"a",
"[",
"key",
"]",
";",
"ok",
"{",
"return",
"v",
"\n",
"}",
"\n",
"return",
"def",
"\n",
"}"
] | // parseAnnotationsString searches `a` for `key`. If `key` is not found returns `def`. | [
"parseAnnotationsString",
"searches",
"a",
"for",
"key",
".",
"If",
"key",
"is",
"not",
"found",
"returns",
"def",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L296-L301 | train |
Microsoft/hcsshim | internal/oci/uvm.go | UpdateSpecFromOptions | func UpdateSpecFromOptions(s specs.Spec, opts *runhcsopts.Options) specs.Spec {
if opts != nil && opts.BootFilesRootPath != "" {
s.Annotations[annotationBootFilesRootPath] = opts.BootFilesRootPath
}
return s
} | go | func UpdateSpecFromOptions(s specs.Spec, opts *runhcsopts.Options) specs.Spec {
if opts != nil && opts.BootFilesRootPath != "" {
s.Annotations[annotationBootFilesRootPath] = opts.BootFilesRootPath
}
return s
} | [
"func",
"UpdateSpecFromOptions",
"(",
"s",
"specs",
".",
"Spec",
",",
"opts",
"*",
"runhcsopts",
".",
"Options",
")",
"specs",
".",
"Spec",
"{",
"if",
"opts",
"!=",
"nil",
"&&",
"opts",
".",
"BootFilesRootPath",
"!=",
"\"",
"\"",
"{",
"s",
".",
"Annotations",
"[",
"annotationBootFilesRootPath",
"]",
"=",
"opts",
".",
"BootFilesRootPath",
"\n",
"}",
"\n\n",
"return",
"s",
"\n",
"}"
] | // UpdateSpecFromOptions sets extra annotations on the OCI spec based on the
// `opts` struct. | [
"UpdateSpecFromOptions",
"sets",
"extra",
"annotations",
"on",
"the",
"OCI",
"spec",
"based",
"on",
"the",
"opts",
"struct",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/uvm.go#L347-L353 | train |
Microsoft/hcsshim | internal/uvm/create_lcow.go | defaultLCOWOSBootFilesPath | func defaultLCOWOSBootFilesPath() string {
localDirPath := filepath.Join(filepath.Dir(os.Args[0]), "LinuxBootFiles")
if _, err := os.Stat(localDirPath); err == nil {
return localDirPath
}
return filepath.Join(os.Getenv("ProgramFiles"), "Linux Containers")
} | go | func defaultLCOWOSBootFilesPath() string {
localDirPath := filepath.Join(filepath.Dir(os.Args[0]), "LinuxBootFiles")
if _, err := os.Stat(localDirPath); err == nil {
return localDirPath
}
return filepath.Join(os.Getenv("ProgramFiles"), "Linux Containers")
} | [
"func",
"defaultLCOWOSBootFilesPath",
"(",
")",
"string",
"{",
"localDirPath",
":=",
"filepath",
".",
"Join",
"(",
"filepath",
".",
"Dir",
"(",
"os",
".",
"Args",
"[",
"0",
"]",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"localDirPath",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"localDirPath",
"\n",
"}",
"\n",
"return",
"filepath",
".",
"Join",
"(",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // defaultLCOWOSBootFilesPath returns the default path used to locate the LCOW
// OS kernel and root FS files. This default is the subdirectory
// `LinuxBootFiles` in the directory of the executable that started the current
// process; or, if it does not exist, `%ProgramFiles%\Linux Containers`. | [
"defaultLCOWOSBootFilesPath",
"returns",
"the",
"default",
"path",
"used",
"to",
"locate",
"the",
"LCOW",
"OS",
"kernel",
"and",
"root",
"FS",
"files",
".",
"This",
"default",
"is",
"the",
"subdirectory",
"LinuxBootFiles",
"in",
"the",
"directory",
"of",
"the",
"executable",
"that",
"started",
"the",
"current",
"process",
";",
"or",
"if",
"it",
"does",
"not",
"exist",
"%ProgramFiles%",
"\\",
"Linux",
"Containers",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/create_lcow.go#L69-L75 | train |
Microsoft/hcsshim | internal/uvm/create_lcow.go | NewDefaultOptionsLCOW | func NewDefaultOptionsLCOW(id, owner string) *OptionsLCOW {
// Use KernelDirect boot by default on all builds that support it.
kernelDirectSupported := osversion.Get().Build >= 18286
opts := &OptionsLCOW{
Options: newDefaultOptions(id, owner),
BootFilesPath: defaultLCOWOSBootFilesPath(),
KernelFile: KernelFile,
KernelDirect: kernelDirectSupported,
RootFSFile: InitrdFile,
KernelBootOptions: "",
EnableGraphicsConsole: false,
ConsolePipe: "",
SCSIControllerCount: 1,
UseGuestConnection: true,
ExecCommandLine: fmt.Sprintf("/bin/gcs -log-format json -loglevel %s", logrus.StandardLogger().Level.String()),
ForwardStdout: false,
ForwardStderr: true,
OutputHandler: parseLogrus(id),
VPMemDeviceCount: DefaultVPMEMCount,
VPMemSizeBytes: DefaultVPMemSizeBytes,
PreferredRootFSType: PreferredRootFSTypeInitRd,
}
if _, err := os.Stat(filepath.Join(opts.BootFilesPath, VhdFile)); err == nil {
// We have a rootfs.vhd in the boot files path. Use it over an initrd.img
opts.RootFSFile = VhdFile
opts.PreferredRootFSType = PreferredRootFSTypeVHD
}
if kernelDirectSupported {
// KernelDirect supports uncompressed kernel if the kernel is present.
// Default to uncompressed if on box. NOTE: If `kernel` is already
// uncompressed and simply named 'kernel' it will still be used
// uncompressed automatically.
if _, err := os.Stat(filepath.Join(opts.BootFilesPath, UncompressedKernelFile)); err == nil {
opts.KernelFile = UncompressedKernelFile
}
}
return opts
} | go | func NewDefaultOptionsLCOW(id, owner string) *OptionsLCOW {
// Use KernelDirect boot by default on all builds that support it.
kernelDirectSupported := osversion.Get().Build >= 18286
opts := &OptionsLCOW{
Options: newDefaultOptions(id, owner),
BootFilesPath: defaultLCOWOSBootFilesPath(),
KernelFile: KernelFile,
KernelDirect: kernelDirectSupported,
RootFSFile: InitrdFile,
KernelBootOptions: "",
EnableGraphicsConsole: false,
ConsolePipe: "",
SCSIControllerCount: 1,
UseGuestConnection: true,
ExecCommandLine: fmt.Sprintf("/bin/gcs -log-format json -loglevel %s", logrus.StandardLogger().Level.String()),
ForwardStdout: false,
ForwardStderr: true,
OutputHandler: parseLogrus(id),
VPMemDeviceCount: DefaultVPMEMCount,
VPMemSizeBytes: DefaultVPMemSizeBytes,
PreferredRootFSType: PreferredRootFSTypeInitRd,
}
if _, err := os.Stat(filepath.Join(opts.BootFilesPath, VhdFile)); err == nil {
// We have a rootfs.vhd in the boot files path. Use it over an initrd.img
opts.RootFSFile = VhdFile
opts.PreferredRootFSType = PreferredRootFSTypeVHD
}
if kernelDirectSupported {
// KernelDirect supports uncompressed kernel if the kernel is present.
// Default to uncompressed if on box. NOTE: If `kernel` is already
// uncompressed and simply named 'kernel' it will still be used
// uncompressed automatically.
if _, err := os.Stat(filepath.Join(opts.BootFilesPath, UncompressedKernelFile)); err == nil {
opts.KernelFile = UncompressedKernelFile
}
}
return opts
} | [
"func",
"NewDefaultOptionsLCOW",
"(",
"id",
",",
"owner",
"string",
")",
"*",
"OptionsLCOW",
"{",
"// Use KernelDirect boot by default on all builds that support it.",
"kernelDirectSupported",
":=",
"osversion",
".",
"Get",
"(",
")",
".",
"Build",
">=",
"18286",
"\n",
"opts",
":=",
"&",
"OptionsLCOW",
"{",
"Options",
":",
"newDefaultOptions",
"(",
"id",
",",
"owner",
")",
",",
"BootFilesPath",
":",
"defaultLCOWOSBootFilesPath",
"(",
")",
",",
"KernelFile",
":",
"KernelFile",
",",
"KernelDirect",
":",
"kernelDirectSupported",
",",
"RootFSFile",
":",
"InitrdFile",
",",
"KernelBootOptions",
":",
"\"",
"\"",
",",
"EnableGraphicsConsole",
":",
"false",
",",
"ConsolePipe",
":",
"\"",
"\"",
",",
"SCSIControllerCount",
":",
"1",
",",
"UseGuestConnection",
":",
"true",
",",
"ExecCommandLine",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"logrus",
".",
"StandardLogger",
"(",
")",
".",
"Level",
".",
"String",
"(",
")",
")",
",",
"ForwardStdout",
":",
"false",
",",
"ForwardStderr",
":",
"true",
",",
"OutputHandler",
":",
"parseLogrus",
"(",
"id",
")",
",",
"VPMemDeviceCount",
":",
"DefaultVPMEMCount",
",",
"VPMemSizeBytes",
":",
"DefaultVPMemSizeBytes",
",",
"PreferredRootFSType",
":",
"PreferredRootFSTypeInitRd",
",",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filepath",
".",
"Join",
"(",
"opts",
".",
"BootFilesPath",
",",
"VhdFile",
")",
")",
";",
"err",
"==",
"nil",
"{",
"// We have a rootfs.vhd in the boot files path. Use it over an initrd.img",
"opts",
".",
"RootFSFile",
"=",
"VhdFile",
"\n",
"opts",
".",
"PreferredRootFSType",
"=",
"PreferredRootFSTypeVHD",
"\n",
"}",
"\n\n",
"if",
"kernelDirectSupported",
"{",
"// KernelDirect supports uncompressed kernel if the kernel is present.",
"// Default to uncompressed if on box. NOTE: If `kernel` is already",
"// uncompressed and simply named 'kernel' it will still be used",
"// uncompressed automatically.",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filepath",
".",
"Join",
"(",
"opts",
".",
"BootFilesPath",
",",
"UncompressedKernelFile",
")",
")",
";",
"err",
"==",
"nil",
"{",
"opts",
".",
"KernelFile",
"=",
"UncompressedKernelFile",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"opts",
"\n",
"}"
] | // NewDefaultOptionsLCOW creates the default options for a bootable version of
// LCOW.
//
// `id` the ID of the compute system. If not passed will generate a new GUID.
//
// `owner` the owner of the compute system. If not passed will use the
// executable files name. | [
"NewDefaultOptionsLCOW",
"creates",
"the",
"default",
"options",
"for",
"a",
"bootable",
"version",
"of",
"LCOW",
".",
"id",
"the",
"ID",
"of",
"the",
"compute",
"system",
".",
"If",
"not",
"passed",
"will",
"generate",
"a",
"new",
"GUID",
".",
"owner",
"the",
"owner",
"of",
"the",
"compute",
"system",
".",
"If",
"not",
"passed",
"will",
"use",
"the",
"executable",
"files",
"name",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/create_lcow.go#L84-L123 | train |
Microsoft/hcsshim | internal/wclayer/legacy.go | newLegacyLayerReader | func newLegacyLayerReader(root string) *legacyLayerReader {
r := &legacyLayerReader{
root: root,
result: make(chan *fileEntry),
proceed: make(chan bool),
}
go r.walk()
return r
} | go | func newLegacyLayerReader(root string) *legacyLayerReader {
r := &legacyLayerReader{
root: root,
result: make(chan *fileEntry),
proceed: make(chan bool),
}
go r.walk()
return r
} | [
"func",
"newLegacyLayerReader",
"(",
"root",
"string",
")",
"*",
"legacyLayerReader",
"{",
"r",
":=",
"&",
"legacyLayerReader",
"{",
"root",
":",
"root",
",",
"result",
":",
"make",
"(",
"chan",
"*",
"fileEntry",
")",
",",
"proceed",
":",
"make",
"(",
"chan",
"bool",
")",
",",
"}",
"\n",
"go",
"r",
".",
"walk",
"(",
")",
"\n",
"return",
"r",
"\n",
"}"
] | // newLegacyLayerReader returns a new LayerReader that can read the Windows
// container layer transport format from disk. | [
"newLegacyLayerReader",
"returns",
"a",
"new",
"LayerReader",
"that",
"can",
"read",
"the",
"Windows",
"container",
"layer",
"transport",
"format",
"from",
"disk",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/legacy.go#L60-L68 | train |
Microsoft/hcsshim | internal/wclayer/legacy.go | newLegacyLayerWriter | func newLegacyLayerWriter(root string, parentRoots []string, destRoot string) (w *legacyLayerWriter, err error) {
w = &legacyLayerWriter{
addedFiles: make(map[string]bool),
}
defer func() {
if err != nil {
w.CloseRoots()
w = nil
}
}()
w.root, err = safefile.OpenRoot(root)
if err != nil {
return
}
w.destRoot, err = safefile.OpenRoot(destRoot)
if err != nil {
return
}
for _, r := range parentRoots {
f, err := safefile.OpenRoot(r)
if err != nil {
return w, err
}
w.parentRoots = append(w.parentRoots, f)
}
w.bufWriter = bufio.NewWriterSize(ioutil.Discard, 65536)
return
} | go | func newLegacyLayerWriter(root string, parentRoots []string, destRoot string) (w *legacyLayerWriter, err error) {
w = &legacyLayerWriter{
addedFiles: make(map[string]bool),
}
defer func() {
if err != nil {
w.CloseRoots()
w = nil
}
}()
w.root, err = safefile.OpenRoot(root)
if err != nil {
return
}
w.destRoot, err = safefile.OpenRoot(destRoot)
if err != nil {
return
}
for _, r := range parentRoots {
f, err := safefile.OpenRoot(r)
if err != nil {
return w, err
}
w.parentRoots = append(w.parentRoots, f)
}
w.bufWriter = bufio.NewWriterSize(ioutil.Discard, 65536)
return
} | [
"func",
"newLegacyLayerWriter",
"(",
"root",
"string",
",",
"parentRoots",
"[",
"]",
"string",
",",
"destRoot",
"string",
")",
"(",
"w",
"*",
"legacyLayerWriter",
",",
"err",
"error",
")",
"{",
"w",
"=",
"&",
"legacyLayerWriter",
"{",
"addedFiles",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
",",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"w",
".",
"CloseRoots",
"(",
")",
"\n",
"w",
"=",
"nil",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"w",
".",
"root",
",",
"err",
"=",
"safefile",
".",
"OpenRoot",
"(",
"root",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"w",
".",
"destRoot",
",",
"err",
"=",
"safefile",
".",
"OpenRoot",
"(",
"destRoot",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"parentRoots",
"{",
"f",
",",
"err",
":=",
"safefile",
".",
"OpenRoot",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"w",
",",
"err",
"\n",
"}",
"\n",
"w",
".",
"parentRoots",
"=",
"append",
"(",
"w",
".",
"parentRoots",
",",
"f",
")",
"\n",
"}",
"\n",
"w",
".",
"bufWriter",
"=",
"bufio",
".",
"NewWriterSize",
"(",
"ioutil",
".",
"Discard",
",",
"65536",
")",
"\n",
"return",
"\n",
"}"
] | // newLegacyLayerWriter returns a LayerWriter that can write the contaler layer
// transport format to disk. | [
"newLegacyLayerWriter",
"returns",
"a",
"LayerWriter",
"that",
"can",
"write",
"the",
"contaler",
"layer",
"transport",
"format",
"to",
"disk",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/legacy.go#L353-L380 | train |
Microsoft/hcsshim | internal/wclayer/legacy.go | cloneTree | func cloneTree(srcRoot *os.File, destRoot *os.File, subPath string, mutatedFiles map[string]bool) error {
var di []dirInfo
err := safefile.EnsureNotReparsePointRelative(subPath, srcRoot)
if err != nil {
return err
}
err = filepath.Walk(filepath.Join(srcRoot.Name(), subPath), func(srcFilePath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
relPath, err := filepath.Rel(srcRoot.Name(), srcFilePath)
if err != nil {
return err
}
fileAttributes := info.Sys().(*syscall.Win32FileAttributeData).FileAttributes
// Directories, reparse points, and files that will be mutated during
// utility VM import must be copied. All other files can be hard linked.
isReparsePoint := fileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0
// In go1.9, FileInfo.IsDir() returns false if the directory is also a symlink.
// See: https://github.com/golang/go/commit/1989921aef60c83e6f9127a8448fb5ede10e9acc
// Fixes the problem by checking syscall.FILE_ATTRIBUTE_DIRECTORY directly
isDir := fileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0
if isDir || isReparsePoint || mutatedFiles[relPath] {
fi, err := copyFileWithMetadata(srcRoot, destRoot, relPath, isDir)
if err != nil {
return err
}
if isDir && !isReparsePoint {
di = append(di, dirInfo{path: relPath, fileInfo: *fi})
}
} else {
err = safefile.LinkRelative(relPath, srcRoot, relPath, destRoot)
if err != nil {
return err
}
}
return nil
})
if err != nil {
return err
}
return reapplyDirectoryTimes(destRoot, di)
} | go | func cloneTree(srcRoot *os.File, destRoot *os.File, subPath string, mutatedFiles map[string]bool) error {
var di []dirInfo
err := safefile.EnsureNotReparsePointRelative(subPath, srcRoot)
if err != nil {
return err
}
err = filepath.Walk(filepath.Join(srcRoot.Name(), subPath), func(srcFilePath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
relPath, err := filepath.Rel(srcRoot.Name(), srcFilePath)
if err != nil {
return err
}
fileAttributes := info.Sys().(*syscall.Win32FileAttributeData).FileAttributes
// Directories, reparse points, and files that will be mutated during
// utility VM import must be copied. All other files can be hard linked.
isReparsePoint := fileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0
// In go1.9, FileInfo.IsDir() returns false if the directory is also a symlink.
// See: https://github.com/golang/go/commit/1989921aef60c83e6f9127a8448fb5ede10e9acc
// Fixes the problem by checking syscall.FILE_ATTRIBUTE_DIRECTORY directly
isDir := fileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0
if isDir || isReparsePoint || mutatedFiles[relPath] {
fi, err := copyFileWithMetadata(srcRoot, destRoot, relPath, isDir)
if err != nil {
return err
}
if isDir && !isReparsePoint {
di = append(di, dirInfo{path: relPath, fileInfo: *fi})
}
} else {
err = safefile.LinkRelative(relPath, srcRoot, relPath, destRoot)
if err != nil {
return err
}
}
return nil
})
if err != nil {
return err
}
return reapplyDirectoryTimes(destRoot, di)
} | [
"func",
"cloneTree",
"(",
"srcRoot",
"*",
"os",
".",
"File",
",",
"destRoot",
"*",
"os",
".",
"File",
",",
"subPath",
"string",
",",
"mutatedFiles",
"map",
"[",
"string",
"]",
"bool",
")",
"error",
"{",
"var",
"di",
"[",
"]",
"dirInfo",
"\n",
"err",
":=",
"safefile",
".",
"EnsureNotReparsePointRelative",
"(",
"subPath",
",",
"srcRoot",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"filepath",
".",
"Walk",
"(",
"filepath",
".",
"Join",
"(",
"srcRoot",
".",
"Name",
"(",
")",
",",
"subPath",
")",
",",
"func",
"(",
"srcFilePath",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"relPath",
",",
"err",
":=",
"filepath",
".",
"Rel",
"(",
"srcRoot",
".",
"Name",
"(",
")",
",",
"srcFilePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"fileAttributes",
":=",
"info",
".",
"Sys",
"(",
")",
".",
"(",
"*",
"syscall",
".",
"Win32FileAttributeData",
")",
".",
"FileAttributes",
"\n",
"// Directories, reparse points, and files that will be mutated during",
"// utility VM import must be copied. All other files can be hard linked.",
"isReparsePoint",
":=",
"fileAttributes",
"&",
"syscall",
".",
"FILE_ATTRIBUTE_REPARSE_POINT",
"!=",
"0",
"\n",
"// In go1.9, FileInfo.IsDir() returns false if the directory is also a symlink.",
"// See: https://github.com/golang/go/commit/1989921aef60c83e6f9127a8448fb5ede10e9acc",
"// Fixes the problem by checking syscall.FILE_ATTRIBUTE_DIRECTORY directly",
"isDir",
":=",
"fileAttributes",
"&",
"syscall",
".",
"FILE_ATTRIBUTE_DIRECTORY",
"!=",
"0",
"\n\n",
"if",
"isDir",
"||",
"isReparsePoint",
"||",
"mutatedFiles",
"[",
"relPath",
"]",
"{",
"fi",
",",
"err",
":=",
"copyFileWithMetadata",
"(",
"srcRoot",
",",
"destRoot",
",",
"relPath",
",",
"isDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"isDir",
"&&",
"!",
"isReparsePoint",
"{",
"di",
"=",
"append",
"(",
"di",
",",
"dirInfo",
"{",
"path",
":",
"relPath",
",",
"fileInfo",
":",
"*",
"fi",
"}",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"err",
"=",
"safefile",
".",
"LinkRelative",
"(",
"relPath",
",",
"srcRoot",
",",
"relPath",
",",
"destRoot",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"reapplyDirectoryTimes",
"(",
"destRoot",
",",
"di",
")",
"\n",
"}"
] | // cloneTree clones a directory tree using hard links. It skips hard links for
// the file names in the provided map and just copies those files. | [
"cloneTree",
"clones",
"a",
"directory",
"tree",
"using",
"hard",
"links",
".",
"It",
"skips",
"hard",
"links",
"for",
"the",
"file",
"names",
"in",
"the",
"provided",
"map",
"and",
"just",
"copies",
"those",
"files",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/legacy.go#L528-L575 | train |
Microsoft/hcsshim | hcn/hcnglobals.go | GetGlobals | func GetGlobals() (*Globals, error) {
var version Version
err := hnsCall("GET", "/globals/version", "", &version)
if err != nil {
return nil, err
}
globals := &Globals{
Version: version,
}
return globals, nil
} | go | func GetGlobals() (*Globals, error) {
var version Version
err := hnsCall("GET", "/globals/version", "", &version)
if err != nil {
return nil, err
}
globals := &Globals{
Version: version,
}
return globals, nil
} | [
"func",
"GetGlobals",
"(",
")",
"(",
"*",
"Globals",
",",
"error",
")",
"{",
"var",
"version",
"Version",
"\n",
"err",
":=",
"hnsCall",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"globals",
":=",
"&",
"Globals",
"{",
"Version",
":",
"version",
",",
"}",
"\n\n",
"return",
"globals",
",",
"nil",
"\n",
"}"
] | // GetGlobals returns the global properties of the HCN Service. | [
"GetGlobals",
"returns",
"the",
"global",
"properties",
"of",
"the",
"HCN",
"Service",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnglobals.go#L37-L49 | train |
Microsoft/hcsshim | internal/hns/hnsendpoint.go | HNSListEndpointRequest | func HNSListEndpointRequest() ([]HNSEndpoint, error) {
var endpoint []HNSEndpoint
err := hnsCall("GET", "/endpoints/", "", &endpoint)
if err != nil {
return nil, err
}
return endpoint, nil
} | go | func HNSListEndpointRequest() ([]HNSEndpoint, error) {
var endpoint []HNSEndpoint
err := hnsCall("GET", "/endpoints/", "", &endpoint)
if err != nil {
return nil, err
}
return endpoint, nil
} | [
"func",
"HNSListEndpointRequest",
"(",
")",
"(",
"[",
"]",
"HNSEndpoint",
",",
"error",
")",
"{",
"var",
"endpoint",
"[",
"]",
"HNSEndpoint",
"\n",
"err",
":=",
"hnsCall",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"&",
"endpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"endpoint",
",",
"nil",
"\n",
"}"
] | // HNSListEndpointRequest makes a HNS call to query the list of available endpoints | [
"HNSListEndpointRequest",
"makes",
"a",
"HNS",
"call",
"to",
"query",
"the",
"list",
"of",
"available",
"endpoints"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsendpoint.go#L69-L77 | train |
Microsoft/hcsshim | internal/hns/hnsendpoint.go | GetHNSEndpointByName | func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
hnsResponse, err := HNSListEndpointRequest()
if err != nil {
return nil, err
}
for _, hnsEndpoint := range hnsResponse {
if hnsEndpoint.Name == endpointName {
return &hnsEndpoint, nil
}
}
return nil, EndpointNotFoundError{EndpointName: endpointName}
} | go | func GetHNSEndpointByName(endpointName string) (*HNSEndpoint, error) {
hnsResponse, err := HNSListEndpointRequest()
if err != nil {
return nil, err
}
for _, hnsEndpoint := range hnsResponse {
if hnsEndpoint.Name == endpointName {
return &hnsEndpoint, nil
}
}
return nil, EndpointNotFoundError{EndpointName: endpointName}
} | [
"func",
"GetHNSEndpointByName",
"(",
"endpointName",
"string",
")",
"(",
"*",
"HNSEndpoint",
",",
"error",
")",
"{",
"hnsResponse",
",",
"err",
":=",
"HNSListEndpointRequest",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"hnsEndpoint",
":=",
"range",
"hnsResponse",
"{",
"if",
"hnsEndpoint",
".",
"Name",
"==",
"endpointName",
"{",
"return",
"&",
"hnsEndpoint",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"EndpointNotFoundError",
"{",
"EndpointName",
":",
"endpointName",
"}",
"\n",
"}"
] | // GetHNSEndpointByName gets the endpoint filtered by Name | [
"GetHNSEndpointByName",
"gets",
"the",
"endpoint",
"filtered",
"by",
"Name"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsendpoint.go#L85-L96 | train |
Microsoft/hcsshim | internal/hns/hnsendpoint.go | Delete | func (endpoint *HNSEndpoint) Delete() (*HNSEndpoint, error) {
operation := "Delete"
title := "hcsshim::HNSEndpoint::" + operation
logrus.Debugf(title+" id=%s", endpoint.Id)
return HNSEndpointRequest("DELETE", endpoint.Id, "")
} | go | func (endpoint *HNSEndpoint) Delete() (*HNSEndpoint, error) {
operation := "Delete"
title := "hcsshim::HNSEndpoint::" + operation
logrus.Debugf(title+" id=%s", endpoint.Id)
return HNSEndpointRequest("DELETE", endpoint.Id, "")
} | [
"func",
"(",
"endpoint",
"*",
"HNSEndpoint",
")",
"Delete",
"(",
")",
"(",
"*",
"HNSEndpoint",
",",
"error",
")",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"return",
"HNSEndpointRequest",
"(",
"\"",
"\"",
",",
"endpoint",
".",
"Id",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Delete Endpoint by sending EndpointRequest to HNS | [
"Delete",
"Endpoint",
"by",
"sending",
"EndpointRequest",
"to",
"HNS"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsendpoint.go#L133-L139 | train |
Microsoft/hcsshim | internal/hns/hnsendpoint.go | ApplyACLPolicy | func (endpoint *HNSEndpoint) ApplyACLPolicy(policies ...*ACLPolicy) error {
operation := "ApplyACLPolicy"
title := "hcsshim::HNSEndpoint::" + operation
logrus.Debugf(title+" id=%s", endpoint.Id)
for _, policy := range policies {
if policy == nil {
continue
}
jsonString, err := json.Marshal(policy)
if err != nil {
return err
}
endpoint.Policies = append(endpoint.Policies, jsonString)
}
_, err := endpoint.Update()
return err
} | go | func (endpoint *HNSEndpoint) ApplyACLPolicy(policies ...*ACLPolicy) error {
operation := "ApplyACLPolicy"
title := "hcsshim::HNSEndpoint::" + operation
logrus.Debugf(title+" id=%s", endpoint.Id)
for _, policy := range policies {
if policy == nil {
continue
}
jsonString, err := json.Marshal(policy)
if err != nil {
return err
}
endpoint.Policies = append(endpoint.Policies, jsonString)
}
_, err := endpoint.Update()
return err
} | [
"func",
"(",
"endpoint",
"*",
"HNSEndpoint",
")",
"ApplyACLPolicy",
"(",
"policies",
"...",
"*",
"ACLPolicy",
")",
"error",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"for",
"_",
",",
"policy",
":=",
"range",
"policies",
"{",
"if",
"policy",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"policy",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"endpoint",
".",
"Policies",
"=",
"append",
"(",
"endpoint",
".",
"Policies",
",",
"jsonString",
")",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"endpoint",
".",
"Update",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // ApplyACLPolicy applies a set of ACL Policies on the Endpoint | [
"ApplyACLPolicy",
"applies",
"a",
"set",
"of",
"ACL",
"Policies",
"on",
"the",
"Endpoint"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsendpoint.go#L156-L174 | train |
Microsoft/hcsshim | internal/hns/hnsendpoint.go | ContainerAttach | func (endpoint *HNSEndpoint) ContainerAttach(containerID string, compartmentID uint16) error {
operation := "ContainerAttach"
title := "hcsshim::HNSEndpoint::" + operation
logrus.Debugf(title+" id=%s", endpoint.Id)
requestMessage := &EndpointAttachDetachRequest{
ContainerID: containerID,
CompartmentID: compartmentID,
SystemType: ContainerType,
}
response := &EndpointResquestResponse{}
jsonString, err := json.Marshal(requestMessage)
if err != nil {
return err
}
return hnsCall("POST", "/endpoints/"+endpoint.Id+"/attach", string(jsonString), &response)
} | go | func (endpoint *HNSEndpoint) ContainerAttach(containerID string, compartmentID uint16) error {
operation := "ContainerAttach"
title := "hcsshim::HNSEndpoint::" + operation
logrus.Debugf(title+" id=%s", endpoint.Id)
requestMessage := &EndpointAttachDetachRequest{
ContainerID: containerID,
CompartmentID: compartmentID,
SystemType: ContainerType,
}
response := &EndpointResquestResponse{}
jsonString, err := json.Marshal(requestMessage)
if err != nil {
return err
}
return hnsCall("POST", "/endpoints/"+endpoint.Id+"/attach", string(jsonString), &response)
} | [
"func",
"(",
"endpoint",
"*",
"HNSEndpoint",
")",
"ContainerAttach",
"(",
"containerID",
"string",
",",
"compartmentID",
"uint16",
")",
"error",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"endpoint",
".",
"Id",
")",
"\n\n",
"requestMessage",
":=",
"&",
"EndpointAttachDetachRequest",
"{",
"ContainerID",
":",
"containerID",
",",
"CompartmentID",
":",
"compartmentID",
",",
"SystemType",
":",
"ContainerType",
",",
"}",
"\n",
"response",
":=",
"&",
"EndpointResquestResponse",
"{",
"}",
"\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"requestMessage",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"hnsCall",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"endpoint",
".",
"Id",
"+",
"\"",
"\"",
",",
"string",
"(",
"jsonString",
")",
",",
"&",
"response",
")",
"\n",
"}"
] | // ContainerAttach attaches an endpoint to container | [
"ContainerAttach",
"attaches",
"an",
"endpoint",
"to",
"container"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsendpoint.go#L177-L193 | train |
Microsoft/hcsshim | internal/hns/hnsendpoint.go | HostAttach | func (endpoint *HNSEndpoint) HostAttach(compartmentID uint16) error {
operation := "HostAttach"
title := "hcsshim::HNSEndpoint::" + operation
logrus.Debugf(title+" id=%s", endpoint.Id)
requestMessage := &EndpointAttachDetachRequest{
CompartmentID: compartmentID,
SystemType: HostType,
}
response := &EndpointResquestResponse{}
jsonString, err := json.Marshal(requestMessage)
if err != nil {
return err
}
return hnsCall("POST", "/endpoints/"+endpoint.Id+"/attach", string(jsonString), &response)
} | go | func (endpoint *HNSEndpoint) HostAttach(compartmentID uint16) error {
operation := "HostAttach"
title := "hcsshim::HNSEndpoint::" + operation
logrus.Debugf(title+" id=%s", endpoint.Id)
requestMessage := &EndpointAttachDetachRequest{
CompartmentID: compartmentID,
SystemType: HostType,
}
response := &EndpointResquestResponse{}
jsonString, err := json.Marshal(requestMessage)
if err != nil {
return err
}
return hnsCall("POST", "/endpoints/"+endpoint.Id+"/attach", string(jsonString), &response)
} | [
"func",
"(",
"endpoint",
"*",
"HNSEndpoint",
")",
"HostAttach",
"(",
"compartmentID",
"uint16",
")",
"error",
"{",
"operation",
":=",
"\"",
"\"",
"\n",
"title",
":=",
"\"",
"\"",
"+",
"operation",
"\n",
"logrus",
".",
"Debugf",
"(",
"title",
"+",
"\"",
"\"",
",",
"endpoint",
".",
"Id",
")",
"\n",
"requestMessage",
":=",
"&",
"EndpointAttachDetachRequest",
"{",
"CompartmentID",
":",
"compartmentID",
",",
"SystemType",
":",
"HostType",
",",
"}",
"\n",
"response",
":=",
"&",
"EndpointResquestResponse",
"{",
"}",
"\n\n",
"jsonString",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"requestMessage",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"hnsCall",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"endpoint",
".",
"Id",
"+",
"\"",
"\"",
",",
"string",
"(",
"jsonString",
")",
",",
"&",
"response",
")",
"\n\n",
"}"
] | // HostAttach attaches a nic on the host | [
"HostAttach",
"attaches",
"a",
"nic",
"on",
"the",
"host"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/hns/hnsendpoint.go#L215-L231 | train |
Microsoft/hcsshim | hcn/hcnsupport.go | GetSupportedFeatures | func GetSupportedFeatures() SupportedFeatures {
var features SupportedFeatures
globals, err := GetGlobals()
if err != nil {
// Expected on pre-1803 builds, all features will be false/unsupported
logrus.Debugf("Unable to obtain globals: %s", err)
return features
}
features.Acl = AclFeatures{
AclAddressLists: isFeatureSupported(globals.Version, HNSVersion1803),
AclNoHostRulePriority: isFeatureSupported(globals.Version, HNSVersion1803),
AclPortRanges: isFeatureSupported(globals.Version, HNSVersion1803),
AclRuleId: isFeatureSupported(globals.Version, HNSVersion1803),
}
features.Api = ApiSupport{
V2: isFeatureSupported(globals.Version, V2ApiSupport),
V1: true, // HNSCall is still available.
}
features.RemoteSubnet = isFeatureSupported(globals.Version, RemoteSubnetVersion)
features.HostRoute = isFeatureSupported(globals.Version, HostRouteVersion)
features.DSR = isFeatureSupported(globals.Version, DSRVersion)
return features
} | go | func GetSupportedFeatures() SupportedFeatures {
var features SupportedFeatures
globals, err := GetGlobals()
if err != nil {
// Expected on pre-1803 builds, all features will be false/unsupported
logrus.Debugf("Unable to obtain globals: %s", err)
return features
}
features.Acl = AclFeatures{
AclAddressLists: isFeatureSupported(globals.Version, HNSVersion1803),
AclNoHostRulePriority: isFeatureSupported(globals.Version, HNSVersion1803),
AclPortRanges: isFeatureSupported(globals.Version, HNSVersion1803),
AclRuleId: isFeatureSupported(globals.Version, HNSVersion1803),
}
features.Api = ApiSupport{
V2: isFeatureSupported(globals.Version, V2ApiSupport),
V1: true, // HNSCall is still available.
}
features.RemoteSubnet = isFeatureSupported(globals.Version, RemoteSubnetVersion)
features.HostRoute = isFeatureSupported(globals.Version, HostRouteVersion)
features.DSR = isFeatureSupported(globals.Version, DSRVersion)
return features
} | [
"func",
"GetSupportedFeatures",
"(",
")",
"SupportedFeatures",
"{",
"var",
"features",
"SupportedFeatures",
"\n\n",
"globals",
",",
"err",
":=",
"GetGlobals",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// Expected on pre-1803 builds, all features will be false/unsupported",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"features",
"\n",
"}",
"\n\n",
"features",
".",
"Acl",
"=",
"AclFeatures",
"{",
"AclAddressLists",
":",
"isFeatureSupported",
"(",
"globals",
".",
"Version",
",",
"HNSVersion1803",
")",
",",
"AclNoHostRulePriority",
":",
"isFeatureSupported",
"(",
"globals",
".",
"Version",
",",
"HNSVersion1803",
")",
",",
"AclPortRanges",
":",
"isFeatureSupported",
"(",
"globals",
".",
"Version",
",",
"HNSVersion1803",
")",
",",
"AclRuleId",
":",
"isFeatureSupported",
"(",
"globals",
".",
"Version",
",",
"HNSVersion1803",
")",
",",
"}",
"\n\n",
"features",
".",
"Api",
"=",
"ApiSupport",
"{",
"V2",
":",
"isFeatureSupported",
"(",
"globals",
".",
"Version",
",",
"V2ApiSupport",
")",
",",
"V1",
":",
"true",
",",
"// HNSCall is still available.",
"}",
"\n\n",
"features",
".",
"RemoteSubnet",
"=",
"isFeatureSupported",
"(",
"globals",
".",
"Version",
",",
"RemoteSubnetVersion",
")",
"\n",
"features",
".",
"HostRoute",
"=",
"isFeatureSupported",
"(",
"globals",
".",
"Version",
",",
"HostRouteVersion",
")",
"\n",
"features",
".",
"DSR",
"=",
"isFeatureSupported",
"(",
"globals",
".",
"Version",
",",
"DSRVersion",
")",
"\n\n",
"return",
"features",
"\n",
"}"
] | // GetSupportedFeatures returns the features supported by the Service. | [
"GetSupportedFeatures",
"returns",
"the",
"features",
"supported",
"by",
"the",
"Service",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/hcn/hcnsupport.go#L31-L58 | train |
Microsoft/hcsshim | cmd/runhcs/container.go | startVMShim | func (c *container) startVMShim(logFile string, opts interface{}) (*os.Process, error) {
var os string
if _, ok := opts.(*uvm.OptionsLCOW); ok {
os = "linux"
} else {
os = "windows"
}
args := []string{"--os", os}
if strings.HasPrefix(logFile, runhcs.SafePipePrefix) {
args = append(args, "--log-pipe", logFile)
}
args = append(args, c.VMPipePath())
return launchShim("vmshim", "", logFile, args, opts)
} | go | func (c *container) startVMShim(logFile string, opts interface{}) (*os.Process, error) {
var os string
if _, ok := opts.(*uvm.OptionsLCOW); ok {
os = "linux"
} else {
os = "windows"
}
args := []string{"--os", os}
if strings.HasPrefix(logFile, runhcs.SafePipePrefix) {
args = append(args, "--log-pipe", logFile)
}
args = append(args, c.VMPipePath())
return launchShim("vmshim", "", logFile, args, opts)
} | [
"func",
"(",
"c",
"*",
"container",
")",
"startVMShim",
"(",
"logFile",
"string",
",",
"opts",
"interface",
"{",
"}",
")",
"(",
"*",
"os",
".",
"Process",
",",
"error",
")",
"{",
"var",
"os",
"string",
"\n",
"if",
"_",
",",
"ok",
":=",
"opts",
".",
"(",
"*",
"uvm",
".",
"OptionsLCOW",
")",
";",
"ok",
"{",
"os",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"os",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"os",
"}",
"\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"logFile",
",",
"runhcs",
".",
"SafePipePrefix",
")",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
",",
"logFile",
")",
"\n",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"c",
".",
"VMPipePath",
"(",
")",
")",
"\n",
"return",
"launchShim",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"logFile",
",",
"args",
",",
"opts",
")",
"\n",
"}"
] | // startVMShim starts a vm-shim command with the specified `opts`. `opts` can be `uvm.OptionsWCOW` or `uvm.OptionsLCOW` | [
"startVMShim",
"starts",
"a",
"vm",
"-",
"shim",
"command",
"with",
"the",
"specified",
"opts",
".",
"opts",
"can",
"be",
"uvm",
".",
"OptionsWCOW",
"or",
"uvm",
".",
"OptionsLCOW"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/runhcs/container.go#L229-L242 | train |
Microsoft/hcsshim | internal/appargs/appargs.go | Int | func Int(base int, min int, max int) Validator {
return func(args []string) int {
if len(args) == 0 {
return -1
}
i, err := strconv.ParseInt(args[0], base, 0)
if err != nil || int(i) < min || int(i) > max {
return -1
}
return 1
}
} | go | func Int(base int, min int, max int) Validator {
return func(args []string) int {
if len(args) == 0 {
return -1
}
i, err := strconv.ParseInt(args[0], base, 0)
if err != nil || int(i) < min || int(i) > max {
return -1
}
return 1
}
} | [
"func",
"Int",
"(",
"base",
"int",
",",
"min",
"int",
",",
"max",
"int",
")",
"Validator",
"{",
"return",
"func",
"(",
"args",
"[",
"]",
"string",
")",
"int",
"{",
"if",
"len",
"(",
"args",
")",
"==",
"0",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"i",
",",
"err",
":=",
"strconv",
".",
"ParseInt",
"(",
"args",
"[",
"0",
"]",
",",
"base",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"int",
"(",
"i",
")",
"<",
"min",
"||",
"int",
"(",
"i",
")",
">",
"max",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"return",
"1",
"\n",
"}",
"\n",
"}"
] | // Int returns a validator for integers. | [
"Int",
"returns",
"a",
"validator",
"for",
"integers",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/appargs/appargs.go#L33-L44 | train |
Microsoft/hcsshim | internal/appargs/appargs.go | Optional | func Optional(v Validator) Validator {
return func(args []string) int {
if len(args) == 0 {
return 0
}
return v(args)
}
} | go | func Optional(v Validator) Validator {
return func(args []string) int {
if len(args) == 0 {
return 0
}
return v(args)
}
} | [
"func",
"Optional",
"(",
"v",
"Validator",
")",
"Validator",
"{",
"return",
"func",
"(",
"args",
"[",
"]",
"string",
")",
"int",
"{",
"if",
"len",
"(",
"args",
")",
"==",
"0",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"v",
"(",
"args",
")",
"\n",
"}",
"\n",
"}"
] | // Optional returns a validator that treats an argument as optional. | [
"Optional",
"returns",
"a",
"validator",
"that",
"treats",
"an",
"argument",
"as",
"optional",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/appargs/appargs.go#L47-L54 | train |
Microsoft/hcsshim | internal/appargs/appargs.go | Rest | func Rest(v Validator) Validator {
return func(args []string) int {
count := len(args)
for len(args) != 0 {
n := v(args)
if n < 0 {
return n
}
args = args[n:]
}
return count
}
} | go | func Rest(v Validator) Validator {
return func(args []string) int {
count := len(args)
for len(args) != 0 {
n := v(args)
if n < 0 {
return n
}
args = args[n:]
}
return count
}
} | [
"func",
"Rest",
"(",
"v",
"Validator",
")",
"Validator",
"{",
"return",
"func",
"(",
"args",
"[",
"]",
"string",
")",
"int",
"{",
"count",
":=",
"len",
"(",
"args",
")",
"\n",
"for",
"len",
"(",
"args",
")",
"!=",
"0",
"{",
"n",
":=",
"v",
"(",
"args",
")",
"\n",
"if",
"n",
"<",
"0",
"{",
"return",
"n",
"\n",
"}",
"\n",
"args",
"=",
"args",
"[",
"n",
":",
"]",
"\n",
"}",
"\n",
"return",
"count",
"\n",
"}",
"\n",
"}"
] | // Rest returns a validator that validates each of the remaining arguments. | [
"Rest",
"returns",
"a",
"validator",
"that",
"validates",
"each",
"of",
"the",
"remaining",
"arguments",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/appargs/appargs.go#L57-L69 | train |
Microsoft/hcsshim | internal/appargs/appargs.go | Validate | func Validate(vs ...Validator) cli.BeforeFunc {
return func(context *cli.Context) error {
remaining := context.Args()
for _, v := range vs {
consumed := v(remaining)
if consumed < 0 {
return ErrInvalidUsage
}
remaining = remaining[consumed:]
}
if len(remaining) > 0 {
return ErrInvalidUsage
}
return nil
}
} | go | func Validate(vs ...Validator) cli.BeforeFunc {
return func(context *cli.Context) error {
remaining := context.Args()
for _, v := range vs {
consumed := v(remaining)
if consumed < 0 {
return ErrInvalidUsage
}
remaining = remaining[consumed:]
}
if len(remaining) > 0 {
return ErrInvalidUsage
}
return nil
}
} | [
"func",
"Validate",
"(",
"vs",
"...",
"Validator",
")",
"cli",
".",
"BeforeFunc",
"{",
"return",
"func",
"(",
"context",
"*",
"cli",
".",
"Context",
")",
"error",
"{",
"remaining",
":=",
"context",
".",
"Args",
"(",
")",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"vs",
"{",
"consumed",
":=",
"v",
"(",
"remaining",
")",
"\n",
"if",
"consumed",
"<",
"0",
"{",
"return",
"ErrInvalidUsage",
"\n",
"}",
"\n",
"remaining",
"=",
"remaining",
"[",
"consumed",
":",
"]",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"remaining",
")",
">",
"0",
"{",
"return",
"ErrInvalidUsage",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // Validate can be used as a command's Before function to validate the arguments
// to the command. | [
"Validate",
"can",
"be",
"used",
"as",
"a",
"command",
"s",
"Before",
"function",
"to",
"validate",
"the",
"arguments",
"to",
"the",
"command",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/appargs/appargs.go#L76-L93 | train |
Microsoft/hcsshim | internal/wclayer/layerid.go | LayerID | func LayerID(path string) (guid.GUID, error) {
_, file := filepath.Split(path)
return NameToGuid(file)
} | go | func LayerID(path string) (guid.GUID, error) {
_, file := filepath.Split(path)
return NameToGuid(file)
} | [
"func",
"LayerID",
"(",
"path",
"string",
")",
"(",
"guid",
".",
"GUID",
",",
"error",
")",
"{",
"_",
",",
"file",
":=",
"filepath",
".",
"Split",
"(",
"path",
")",
"\n",
"return",
"NameToGuid",
"(",
"file",
")",
"\n",
"}"
] | // LayerID returns the layer ID of a layer on disk. | [
"LayerID",
"returns",
"the",
"layer",
"ID",
"of",
"a",
"layer",
"on",
"disk",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/layerid.go#L10-L13 | train |
Microsoft/hcsshim | cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go | newWcowPodSandboxTask | func newWcowPodSandboxTask(ctx context.Context, events publisher, id, bundle string, parent *uvm.UtilityVM) shimTask {
logrus.WithFields(logrus.Fields{
"tid": id,
}).Debug("newWcowPodSandboxTask")
wpst := &wcowPodSandboxTask{
events: events,
id: id,
init: newWcowPodSandboxExec(ctx, events, id, bundle),
host: parent,
closed: make(chan struct{}),
}
if parent != nil {
// We have (and own) a parent UVM. Listen for its exit and forcibly
// close this task. This is not expected but in the event of a UVM crash
// we need to handle this case.
go func() {
werr := parent.Wait()
if werr != nil {
logrus.WithFields(logrus.Fields{
"tid": id,
logrus.ErrorKey: werr,
}).Error("newWcowPodSandboxTask - UVM Wait failed")
}
// The UVM came down. Force transition the init task (if it wasn't
// already) to unblock any waiters since the platform wont send any
// events for this fake process.
wpst.init.ForceExit(1)
// Close the host and event the exit.
wpst.close()
}()
}
// In the normal case the `Signal` call from the caller killed this fake
// init process.
go func() {
// Wait for it to exit on its own
wpst.init.Wait(context.Background())
// Close the host and event the exit
wpst.close()
}()
return wpst
} | go | func newWcowPodSandboxTask(ctx context.Context, events publisher, id, bundle string, parent *uvm.UtilityVM) shimTask {
logrus.WithFields(logrus.Fields{
"tid": id,
}).Debug("newWcowPodSandboxTask")
wpst := &wcowPodSandboxTask{
events: events,
id: id,
init: newWcowPodSandboxExec(ctx, events, id, bundle),
host: parent,
closed: make(chan struct{}),
}
if parent != nil {
// We have (and own) a parent UVM. Listen for its exit and forcibly
// close this task. This is not expected but in the event of a UVM crash
// we need to handle this case.
go func() {
werr := parent.Wait()
if werr != nil {
logrus.WithFields(logrus.Fields{
"tid": id,
logrus.ErrorKey: werr,
}).Error("newWcowPodSandboxTask - UVM Wait failed")
}
// The UVM came down. Force transition the init task (if it wasn't
// already) to unblock any waiters since the platform wont send any
// events for this fake process.
wpst.init.ForceExit(1)
// Close the host and event the exit.
wpst.close()
}()
}
// In the normal case the `Signal` call from the caller killed this fake
// init process.
go func() {
// Wait for it to exit on its own
wpst.init.Wait(context.Background())
// Close the host and event the exit
wpst.close()
}()
return wpst
} | [
"func",
"newWcowPodSandboxTask",
"(",
"ctx",
"context",
".",
"Context",
",",
"events",
"publisher",
",",
"id",
",",
"bundle",
"string",
",",
"parent",
"*",
"uvm",
".",
"UtilityVM",
")",
"shimTask",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"id",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"wpst",
":=",
"&",
"wcowPodSandboxTask",
"{",
"events",
":",
"events",
",",
"id",
":",
"id",
",",
"init",
":",
"newWcowPodSandboxExec",
"(",
"ctx",
",",
"events",
",",
"id",
",",
"bundle",
")",
",",
"host",
":",
"parent",
",",
"closed",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"}",
"\n",
"if",
"parent",
"!=",
"nil",
"{",
"// We have (and own) a parent UVM. Listen for its exit and forcibly",
"// close this task. This is not expected but in the event of a UVM crash",
"// we need to handle this case.",
"go",
"func",
"(",
")",
"{",
"werr",
":=",
"parent",
".",
"Wait",
"(",
")",
"\n",
"if",
"werr",
"!=",
"nil",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"id",
",",
"logrus",
".",
"ErrorKey",
":",
"werr",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// The UVM came down. Force transition the init task (if it wasn't",
"// already) to unblock any waiters since the platform wont send any",
"// events for this fake process.",
"wpst",
".",
"init",
".",
"ForceExit",
"(",
"1",
")",
"\n\n",
"// Close the host and event the exit.",
"wpst",
".",
"close",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"// In the normal case the `Signal` call from the caller killed this fake",
"// init process.",
"go",
"func",
"(",
")",
"{",
"// Wait for it to exit on its own",
"wpst",
".",
"init",
".",
"Wait",
"(",
"context",
".",
"Background",
"(",
")",
")",
"\n\n",
"// Close the host and event the exit",
"wpst",
".",
"close",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"return",
"wpst",
"\n",
"}"
] | // newWcowPodSandboxTask creates a fake WCOW task with a fake WCOW `init`
// process as a performance optimization rather than creating an actual
// container and process since it is not needed to hold open any namespaces like
// the equivalent on Linux.
//
// It is assumed that this is the only fake WCOW task and that this task owns
// `parent`. When the fake WCOW `init` process exits via `Signal` `parent` will
// be forcibly closed by this task. | [
"newWcowPodSandboxTask",
"creates",
"a",
"fake",
"WCOW",
"task",
"with",
"a",
"fake",
"WCOW",
"init",
"process",
"as",
"a",
"performance",
"optimization",
"rather",
"than",
"creating",
"an",
"actual",
"container",
"and",
"process",
"since",
"it",
"is",
"not",
"needed",
"to",
"hold",
"open",
"any",
"namespaces",
"like",
"the",
"equivalent",
"on",
"Linux",
".",
"It",
"is",
"assumed",
"that",
"this",
"is",
"the",
"only",
"fake",
"WCOW",
"task",
"and",
"that",
"this",
"task",
"owns",
"parent",
".",
"When",
"the",
"fake",
"WCOW",
"init",
"process",
"exits",
"via",
"Signal",
"parent",
"will",
"be",
"forcibly",
"closed",
"by",
"this",
"task",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go#L28-L71 | train |
Microsoft/hcsshim | cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go | close | func (wpst *wcowPodSandboxTask) close() {
wpst.closeOnce.Do(func() {
logrus.WithFields(logrus.Fields{
"tid": wpst.id,
}).Debug("wcowPodSandboxTask::close")
if wpst.host != nil {
if err := wpst.host.Close(); err != nil {
logrus.WithFields(logrus.Fields{
"tid": wpst.id,
logrus.ErrorKey: err,
}).Error("wcowPodSandboxTask::close - failed host vm shutdown")
}
}
// Send the `init` exec exit notification always.
exit := wpst.init.Status()
wpst.events(
runtime.TaskExitEventTopic,
&eventstypes.TaskExit{
ContainerID: wpst.id,
ID: exit.ID,
Pid: uint32(exit.Pid),
ExitStatus: exit.ExitStatus,
ExitedAt: exit.ExitedAt,
})
close(wpst.closed)
})
} | go | func (wpst *wcowPodSandboxTask) close() {
wpst.closeOnce.Do(func() {
logrus.WithFields(logrus.Fields{
"tid": wpst.id,
}).Debug("wcowPodSandboxTask::close")
if wpst.host != nil {
if err := wpst.host.Close(); err != nil {
logrus.WithFields(logrus.Fields{
"tid": wpst.id,
logrus.ErrorKey: err,
}).Error("wcowPodSandboxTask::close - failed host vm shutdown")
}
}
// Send the `init` exec exit notification always.
exit := wpst.init.Status()
wpst.events(
runtime.TaskExitEventTopic,
&eventstypes.TaskExit{
ContainerID: wpst.id,
ID: exit.ID,
Pid: uint32(exit.Pid),
ExitStatus: exit.ExitStatus,
ExitedAt: exit.ExitedAt,
})
close(wpst.closed)
})
} | [
"func",
"(",
"wpst",
"*",
"wcowPodSandboxTask",
")",
"close",
"(",
")",
"{",
"wpst",
".",
"closeOnce",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"wpst",
".",
"id",
",",
"}",
")",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"wpst",
".",
"host",
"!=",
"nil",
"{",
"if",
"err",
":=",
"wpst",
".",
"host",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithFields",
"(",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"wpst",
".",
"id",
",",
"logrus",
".",
"ErrorKey",
":",
"err",
",",
"}",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// Send the `init` exec exit notification always.",
"exit",
":=",
"wpst",
".",
"init",
".",
"Status",
"(",
")",
"\n",
"wpst",
".",
"events",
"(",
"runtime",
".",
"TaskExitEventTopic",
",",
"&",
"eventstypes",
".",
"TaskExit",
"{",
"ContainerID",
":",
"wpst",
".",
"id",
",",
"ID",
":",
"exit",
".",
"ID",
",",
"Pid",
":",
"uint32",
"(",
"exit",
".",
"Pid",
")",
",",
"ExitStatus",
":",
"exit",
".",
"ExitStatus",
",",
"ExitedAt",
":",
"exit",
".",
"ExitedAt",
",",
"}",
")",
"\n",
"close",
"(",
"wpst",
".",
"closed",
")",
"\n",
"}",
")",
"\n",
"}"
] | // close safely closes the hosting UVM. Because of the specialty of this task it
// is assumed that this is always the owner of `wpst.host`. Once closed and all
// resources released it events the `runtime.TaskExitEventTopic` for all
// upstream listeners.
//
// This call is idempotent and safe to call multiple times. | [
"close",
"safely",
"closes",
"the",
"hosting",
"UVM",
".",
"Because",
"of",
"the",
"specialty",
"of",
"this",
"task",
"it",
"is",
"assumed",
"that",
"this",
"is",
"always",
"the",
"owner",
"of",
"wpst",
".",
"host",
".",
"Once",
"closed",
"and",
"all",
"resources",
"released",
"it",
"events",
"the",
"runtime",
".",
"TaskExitEventTopic",
"for",
"all",
"upstream",
"listeners",
".",
"This",
"call",
"is",
"idempotent",
"and",
"safe",
"to",
"call",
"multiple",
"times",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/task_wcow_podsandbox.go#L205-L232 | train |
Microsoft/hcsshim | pkg/go-runhcs/runhcs_ps.go | Ps | func (r *Runhcs) Ps(context context.Context, id string) ([]int, error) {
data, err := cmdOutput(r.command(context, "ps", "--format=json", id), true)
if err != nil {
return nil, fmt.Errorf("%s: %s", err, data)
}
var out []int
if err := json.Unmarshal(data, &out); err != nil {
return nil, err
}
return out, nil
} | go | func (r *Runhcs) Ps(context context.Context, id string) ([]int, error) {
data, err := cmdOutput(r.command(context, "ps", "--format=json", id), true)
if err != nil {
return nil, fmt.Errorf("%s: %s", err, data)
}
var out []int
if err := json.Unmarshal(data, &out); err != nil {
return nil, err
}
return out, nil
} | [
"func",
"(",
"r",
"*",
"Runhcs",
")",
"Ps",
"(",
"context",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"[",
"]",
"int",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"cmdOutput",
"(",
"r",
".",
"command",
"(",
"context",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"id",
")",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"data",
")",
"\n",
"}",
"\n",
"var",
"out",
"[",
"]",
"int",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"out",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"out",
",",
"nil",
"\n",
"}"
] | // Ps displays the processes running inside a container. | [
"Ps",
"displays",
"the",
"processes",
"running",
"inside",
"a",
"container",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/pkg/go-runhcs/runhcs_ps.go#L10-L20 | train |
Microsoft/hcsshim | internal/schemaversion/schemaversion.go | IsSupported | func IsSupported(sv *hcsschema.Version) error {
if IsV10(sv) {
return nil
}
if IsV21(sv) {
if osversion.Get().Build < osversion.RS5 {
return fmt.Errorf("unsupported on this Windows build")
}
return nil
}
return fmt.Errorf("unknown schema version %s", String(sv))
} | go | func IsSupported(sv *hcsschema.Version) error {
if IsV10(sv) {
return nil
}
if IsV21(sv) {
if osversion.Get().Build < osversion.RS5 {
return fmt.Errorf("unsupported on this Windows build")
}
return nil
}
return fmt.Errorf("unknown schema version %s", String(sv))
} | [
"func",
"IsSupported",
"(",
"sv",
"*",
"hcsschema",
".",
"Version",
")",
"error",
"{",
"if",
"IsV10",
"(",
"sv",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"IsV21",
"(",
"sv",
")",
"{",
"if",
"osversion",
".",
"Get",
"(",
")",
".",
"Build",
"<",
"osversion",
".",
"RS5",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"String",
"(",
"sv",
")",
")",
"\n",
"}"
] | // isSupported determines if a given schema version is supported | [
"isSupported",
"determines",
"if",
"a",
"given",
"schema",
"version",
"is",
"supported"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/schemaversion/schemaversion.go#L25-L36 | train |
Microsoft/hcsshim | internal/schemaversion/schemaversion.go | IsV10 | func IsV10(sv *hcsschema.Version) bool {
if sv.Major == 1 && sv.Minor == 0 {
return true
}
return false
} | go | func IsV10(sv *hcsschema.Version) bool {
if sv.Major == 1 && sv.Minor == 0 {
return true
}
return false
} | [
"func",
"IsV10",
"(",
"sv",
"*",
"hcsschema",
".",
"Version",
")",
"bool",
"{",
"if",
"sv",
".",
"Major",
"==",
"1",
"&&",
"sv",
".",
"Minor",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // IsV10 determines if a given schema version object is 1.0. This was the only thing
// supported in RS1..3. It lives on in RS5, but will be deprecated in a future release. | [
"IsV10",
"determines",
"if",
"a",
"given",
"schema",
"version",
"object",
"is",
"1",
".",
"0",
".",
"This",
"was",
"the",
"only",
"thing",
"supported",
"in",
"RS1",
"..",
"3",
".",
"It",
"lives",
"on",
"in",
"RS5",
"but",
"will",
"be",
"deprecated",
"in",
"a",
"future",
"release",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/schemaversion/schemaversion.go#L40-L45 | train |
Microsoft/hcsshim | internal/schemaversion/schemaversion.go | String | func String(sv *hcsschema.Version) string {
b, err := json.Marshal(sv)
if err != nil {
return ""
}
return string(b[:])
} | go | func String(sv *hcsschema.Version) string {
b, err := json.Marshal(sv)
if err != nil {
return ""
}
return string(b[:])
} | [
"func",
"String",
"(",
"sv",
"*",
"hcsschema",
".",
"Version",
")",
"string",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"sv",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"string",
"(",
"b",
"[",
":",
"]",
")",
"\n",
"}"
] | // String returns a JSON encoding of a schema version object | [
"String",
"returns",
"a",
"JSON",
"encoding",
"of",
"a",
"schema",
"version",
"object"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/schemaversion/schemaversion.go#L58-L64 | train |
Microsoft/hcsshim | internal/schemaversion/schemaversion.go | DetermineSchemaVersion | func DetermineSchemaVersion(requestedSV *hcsschema.Version) *hcsschema.Version {
sv := SchemaV10()
if osversion.Get().Build >= osversion.RS5 {
sv = SchemaV21()
}
if requestedSV != nil {
if err := IsSupported(requestedSV); err == nil {
sv = requestedSV
} else {
logrus.Warnf("Ignoring unsupported requested schema version %+v", requestedSV)
}
}
return sv
} | go | func DetermineSchemaVersion(requestedSV *hcsschema.Version) *hcsschema.Version {
sv := SchemaV10()
if osversion.Get().Build >= osversion.RS5 {
sv = SchemaV21()
}
if requestedSV != nil {
if err := IsSupported(requestedSV); err == nil {
sv = requestedSV
} else {
logrus.Warnf("Ignoring unsupported requested schema version %+v", requestedSV)
}
}
return sv
} | [
"func",
"DetermineSchemaVersion",
"(",
"requestedSV",
"*",
"hcsschema",
".",
"Version",
")",
"*",
"hcsschema",
".",
"Version",
"{",
"sv",
":=",
"SchemaV10",
"(",
")",
"\n",
"if",
"osversion",
".",
"Get",
"(",
")",
".",
"Build",
">=",
"osversion",
".",
"RS5",
"{",
"sv",
"=",
"SchemaV21",
"(",
")",
"\n",
"}",
"\n",
"if",
"requestedSV",
"!=",
"nil",
"{",
"if",
"err",
":=",
"IsSupported",
"(",
"requestedSV",
")",
";",
"err",
"==",
"nil",
"{",
"sv",
"=",
"requestedSV",
"\n",
"}",
"else",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"requestedSV",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"sv",
"\n",
"}"
] | // DetermineSchemaVersion works out what schema version to use based on build and
// requested option. | [
"DetermineSchemaVersion",
"works",
"out",
"what",
"schema",
"version",
"to",
"use",
"based",
"on",
"build",
"and",
"requested",
"option",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/schemaversion/schemaversion.go#L68-L81 | train |
Microsoft/hcsshim | pkg/go-runhcs/runhcs_create-scratch.go | CreateScratch | func (r *Runhcs) CreateScratch(context context.Context, destpath string) error {
return r.runOrError(r.command(context, "create-scratch", "--destpath", destpath))
} | go | func (r *Runhcs) CreateScratch(context context.Context, destpath string) error {
return r.runOrError(r.command(context, "create-scratch", "--destpath", destpath))
} | [
"func",
"(",
"r",
"*",
"Runhcs",
")",
"CreateScratch",
"(",
"context",
"context",
".",
"Context",
",",
"destpath",
"string",
")",
"error",
"{",
"return",
"r",
".",
"runOrError",
"(",
"r",
".",
"command",
"(",
"context",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"destpath",
")",
")",
"\n",
"}"
] | // CreateScratch creates a scratch vhdx at 'destpath' that is ext4 formatted. | [
"CreateScratch",
"creates",
"a",
"scratch",
"vhdx",
"at",
"destpath",
"that",
"is",
"ext4",
"formatted",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/pkg/go-runhcs/runhcs_create-scratch.go#L8-L10 | train |
Microsoft/hcsshim | internal/wclayer/importlayer.go | ImportLayer | func ImportLayer(path string, importFolderPath string, parentLayerPaths []string) (err error) {
title := "hcsshim::ImportLayer"
fields := logrus.Fields{
"path": path,
"importFolderPath": importFolderPath,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
// Generate layer descriptors
layers, err := layerPathsToDescriptors(parentLayerPaths)
if err != nil {
return err
}
err = importLayer(&stdDriverInfo, path, importFolderPath, layers)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
} | go | func ImportLayer(path string, importFolderPath string, parentLayerPaths []string) (err error) {
title := "hcsshim::ImportLayer"
fields := logrus.Fields{
"path": path,
"importFolderPath": importFolderPath,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
// Generate layer descriptors
layers, err := layerPathsToDescriptors(parentLayerPaths)
if err != nil {
return err
}
err = importLayer(&stdDriverInfo, path, importFolderPath, layers)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
} | [
"func",
"ImportLayer",
"(",
"path",
"string",
",",
"importFolderPath",
"string",
",",
"parentLayerPaths",
"[",
"]",
"string",
")",
"(",
"err",
"error",
")",
"{",
"title",
":=",
"\"",
"\"",
"\n",
"fields",
":=",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"path",
",",
"\"",
"\"",
":",
"importFolderPath",
",",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"fields",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"// Generate layer descriptors",
"layers",
",",
"err",
":=",
"layerPathsToDescriptors",
"(",
"parentLayerPaths",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"importLayer",
"(",
"&",
"stdDriverInfo",
",",
"path",
",",
"importFolderPath",
",",
"layers",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ImportLayer will take the contents of the folder at importFolderPath and import
// that into a layer with the id layerId. Note that in order to correctly populate
// the layer and interperet the transport format, all parent layers must already
// be present on the system at the paths provided in parentLayerPaths. | [
"ImportLayer",
"will",
"take",
"the",
"contents",
"of",
"the",
"folder",
"at",
"importFolderPath",
"and",
"import",
"that",
"into",
"a",
"layer",
"with",
"the",
"id",
"layerId",
".",
"Note",
"that",
"in",
"order",
"to",
"correctly",
"populate",
"the",
"layer",
"and",
"interperet",
"the",
"transport",
"format",
"all",
"parent",
"layers",
"must",
"already",
"be",
"present",
"on",
"the",
"system",
"at",
"the",
"paths",
"provided",
"in",
"parentLayerPaths",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/importlayer.go#L18-L45 | train |
Microsoft/hcsshim | internal/wclayer/importlayer.go | NewLayerWriter | func NewLayerWriter(path string, parentLayerPaths []string) (LayerWriter, error) {
if len(parentLayerPaths) == 0 {
// This is a base layer. It gets imported differently.
f, err := safefile.OpenRoot(path)
if err != nil {
return nil, err
}
return &baseLayerWriter{
root: f,
}, nil
}
importPath, err := ioutil.TempDir("", "hcs")
if err != nil {
return nil, err
}
w, err := newLegacyLayerWriter(importPath, parentLayerPaths, path)
if err != nil {
return nil, err
}
return &legacyLayerWriterWrapper{
legacyLayerWriter: w,
path: importPath,
parentLayerPaths: parentLayerPaths,
}, nil
} | go | func NewLayerWriter(path string, parentLayerPaths []string) (LayerWriter, error) {
if len(parentLayerPaths) == 0 {
// This is a base layer. It gets imported differently.
f, err := safefile.OpenRoot(path)
if err != nil {
return nil, err
}
return &baseLayerWriter{
root: f,
}, nil
}
importPath, err := ioutil.TempDir("", "hcs")
if err != nil {
return nil, err
}
w, err := newLegacyLayerWriter(importPath, parentLayerPaths, path)
if err != nil {
return nil, err
}
return &legacyLayerWriterWrapper{
legacyLayerWriter: w,
path: importPath,
parentLayerPaths: parentLayerPaths,
}, nil
} | [
"func",
"NewLayerWriter",
"(",
"path",
"string",
",",
"parentLayerPaths",
"[",
"]",
"string",
")",
"(",
"LayerWriter",
",",
"error",
")",
"{",
"if",
"len",
"(",
"parentLayerPaths",
")",
"==",
"0",
"{",
"// This is a base layer. It gets imported differently.",
"f",
",",
"err",
":=",
"safefile",
".",
"OpenRoot",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"baseLayerWriter",
"{",
"root",
":",
"f",
",",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"importPath",
",",
"err",
":=",
"ioutil",
".",
"TempDir",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"w",
",",
"err",
":=",
"newLegacyLayerWriter",
"(",
"importPath",
",",
"parentLayerPaths",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"legacyLayerWriterWrapper",
"{",
"legacyLayerWriter",
":",
"w",
",",
"path",
":",
"importPath",
",",
"parentLayerPaths",
":",
"parentLayerPaths",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewLayerWriter returns a new layer writer for creating a layer on disk.
// The caller must have taken the SeBackupPrivilege and SeRestorePrivilege privileges
// to call this and any methods on the resulting LayerWriter. | [
"NewLayerWriter",
"returns",
"a",
"new",
"layer",
"writer",
"for",
"creating",
"a",
"layer",
"on",
"disk",
".",
"The",
"caller",
"must",
"have",
"taken",
"the",
"SeBackupPrivilege",
"and",
"SeRestorePrivilege",
"privileges",
"to",
"call",
"this",
"and",
"any",
"methods",
"on",
"the",
"resulting",
"LayerWriter",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/importlayer.go#L110-L135 | train |
Microsoft/hcsshim | internal/uvm/create_wcow.go | NewDefaultOptionsWCOW | func NewDefaultOptionsWCOW(id, owner string) *OptionsWCOW {
return &OptionsWCOW{
Options: newDefaultOptions(id, owner),
}
} | go | func NewDefaultOptionsWCOW(id, owner string) *OptionsWCOW {
return &OptionsWCOW{
Options: newDefaultOptions(id, owner),
}
} | [
"func",
"NewDefaultOptionsWCOW",
"(",
"id",
",",
"owner",
"string",
")",
"*",
"OptionsWCOW",
"{",
"return",
"&",
"OptionsWCOW",
"{",
"Options",
":",
"newDefaultOptions",
"(",
"id",
",",
"owner",
")",
",",
"}",
"\n",
"}"
] | // NewDefaultOptionsWCOW creates the default options for a bootable version of
// WCOW. The caller `MUST` set the `LayerFolders` path on the returned value.
//
// `id` the ID of the compute system. If not passed will generate a new GUID.
//
// `owner` the owner of the compute system. If not passed will use the
// executable files name. | [
"NewDefaultOptionsWCOW",
"creates",
"the",
"default",
"options",
"for",
"a",
"bootable",
"version",
"of",
"WCOW",
".",
"The",
"caller",
"MUST",
"set",
"the",
"LayerFolders",
"path",
"on",
"the",
"returned",
"value",
".",
"id",
"the",
"ID",
"of",
"the",
"compute",
"system",
".",
"If",
"not",
"passed",
"will",
"generate",
"a",
"new",
"GUID",
".",
"owner",
"the",
"owner",
"of",
"the",
"compute",
"system",
".",
"If",
"not",
"passed",
"will",
"use",
"the",
"executable",
"files",
"name",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/uvm/create_wcow.go#L32-L36 | train |
Microsoft/hcsshim | ext4/internal/compactext4/compact.go | Create | func (w *Writer) Create(name string, f *File) error {
if err := w.finishInode(); err != nil {
return err
}
dir, existing, childname, err := w.lookup(name, false)
if err != nil {
return err
}
var reuse *inode
if existing != nil {
if existing.IsDir() {
if f.Mode&TypeMask != S_IFDIR {
return fmt.Errorf("%s: cannot replace a directory with a file", name)
}
reuse = existing
} else if f.Mode&TypeMask == S_IFDIR {
return fmt.Errorf("%s: cannot replace a file with a directory", name)
} else if existing.LinkCount < 2 {
reuse = existing
}
} else {
if f.Mode&TypeMask == S_IFDIR && dir.LinkCount >= format.MaxLinks {
return fmt.Errorf("%s: exceeded parent directory maximum link count", name)
}
}
child, err := w.makeInode(f, reuse)
if err != nil {
return fmt.Errorf("%s: %s", name, err)
}
if existing != child {
if existing != nil {
existing.LinkCount--
}
dir.Children[childname] = child
child.LinkCount++
if child.IsDir() {
dir.LinkCount++
}
}
if child.Mode&format.TypeMask == format.S_IFREG {
w.startInode(name, child, f.Size)
}
return nil
} | go | func (w *Writer) Create(name string, f *File) error {
if err := w.finishInode(); err != nil {
return err
}
dir, existing, childname, err := w.lookup(name, false)
if err != nil {
return err
}
var reuse *inode
if existing != nil {
if existing.IsDir() {
if f.Mode&TypeMask != S_IFDIR {
return fmt.Errorf("%s: cannot replace a directory with a file", name)
}
reuse = existing
} else if f.Mode&TypeMask == S_IFDIR {
return fmt.Errorf("%s: cannot replace a file with a directory", name)
} else if existing.LinkCount < 2 {
reuse = existing
}
} else {
if f.Mode&TypeMask == S_IFDIR && dir.LinkCount >= format.MaxLinks {
return fmt.Errorf("%s: exceeded parent directory maximum link count", name)
}
}
child, err := w.makeInode(f, reuse)
if err != nil {
return fmt.Errorf("%s: %s", name, err)
}
if existing != child {
if existing != nil {
existing.LinkCount--
}
dir.Children[childname] = child
child.LinkCount++
if child.IsDir() {
dir.LinkCount++
}
}
if child.Mode&format.TypeMask == format.S_IFREG {
w.startInode(name, child, f.Size)
}
return nil
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Create",
"(",
"name",
"string",
",",
"f",
"*",
"File",
")",
"error",
"{",
"if",
"err",
":=",
"w",
".",
"finishInode",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"dir",
",",
"existing",
",",
"childname",
",",
"err",
":=",
"w",
".",
"lookup",
"(",
"name",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"reuse",
"*",
"inode",
"\n",
"if",
"existing",
"!=",
"nil",
"{",
"if",
"existing",
".",
"IsDir",
"(",
")",
"{",
"if",
"f",
".",
"Mode",
"&",
"TypeMask",
"!=",
"S_IFDIR",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"reuse",
"=",
"existing",
"\n",
"}",
"else",
"if",
"f",
".",
"Mode",
"&",
"TypeMask",
"==",
"S_IFDIR",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"else",
"if",
"existing",
".",
"LinkCount",
"<",
"2",
"{",
"reuse",
"=",
"existing",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"f",
".",
"Mode",
"&",
"TypeMask",
"==",
"S_IFDIR",
"&&",
"dir",
".",
"LinkCount",
">=",
"format",
".",
"MaxLinks",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"child",
",",
"err",
":=",
"w",
".",
"makeInode",
"(",
"f",
",",
"reuse",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"existing",
"!=",
"child",
"{",
"if",
"existing",
"!=",
"nil",
"{",
"existing",
".",
"LinkCount",
"--",
"\n",
"}",
"\n",
"dir",
".",
"Children",
"[",
"childname",
"]",
"=",
"child",
"\n",
"child",
".",
"LinkCount",
"++",
"\n",
"if",
"child",
".",
"IsDir",
"(",
")",
"{",
"dir",
".",
"LinkCount",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"child",
".",
"Mode",
"&",
"format",
".",
"TypeMask",
"==",
"format",
".",
"S_IFREG",
"{",
"w",
".",
"startInode",
"(",
"name",
",",
"child",
",",
"f",
".",
"Size",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Create adds a file to the file system. | [
"Create",
"adds",
"a",
"file",
"to",
"the",
"file",
"system",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/ext4/internal/compactext4/compact.go#L518-L561 | train |
Microsoft/hcsshim | ext4/internal/compactext4/compact.go | Link | func (w *Writer) Link(oldname, newname string) error {
if err := w.finishInode(); err != nil {
return err
}
newdir, existing, newchildname, err := w.lookup(newname, false)
if err != nil {
return err
}
if existing != nil && (existing.IsDir() || existing.LinkCount < 2) {
return fmt.Errorf("%s: cannot orphan existing file or directory", newname)
}
_, oldfile, _, err := w.lookup(oldname, true)
if err != nil {
return err
}
switch oldfile.Mode & format.TypeMask {
case format.S_IFDIR, format.S_IFLNK:
return fmt.Errorf("%s: link target cannot be a directory or symlink: %s", newname, oldname)
}
if existing != oldfile && oldfile.LinkCount >= format.MaxLinks {
return fmt.Errorf("%s: link target would exceed maximum link count: %s", newname, oldname)
}
if existing != nil {
existing.LinkCount--
}
oldfile.LinkCount++
newdir.Children[newchildname] = oldfile
return nil
} | go | func (w *Writer) Link(oldname, newname string) error {
if err := w.finishInode(); err != nil {
return err
}
newdir, existing, newchildname, err := w.lookup(newname, false)
if err != nil {
return err
}
if existing != nil && (existing.IsDir() || existing.LinkCount < 2) {
return fmt.Errorf("%s: cannot orphan existing file or directory", newname)
}
_, oldfile, _, err := w.lookup(oldname, true)
if err != nil {
return err
}
switch oldfile.Mode & format.TypeMask {
case format.S_IFDIR, format.S_IFLNK:
return fmt.Errorf("%s: link target cannot be a directory or symlink: %s", newname, oldname)
}
if existing != oldfile && oldfile.LinkCount >= format.MaxLinks {
return fmt.Errorf("%s: link target would exceed maximum link count: %s", newname, oldname)
}
if existing != nil {
existing.LinkCount--
}
oldfile.LinkCount++
newdir.Children[newchildname] = oldfile
return nil
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Link",
"(",
"oldname",
",",
"newname",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"w",
".",
"finishInode",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"newdir",
",",
"existing",
",",
"newchildname",
",",
"err",
":=",
"w",
".",
"lookup",
"(",
"newname",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"existing",
"!=",
"nil",
"&&",
"(",
"existing",
".",
"IsDir",
"(",
")",
"||",
"existing",
".",
"LinkCount",
"<",
"2",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"newname",
")",
"\n",
"}",
"\n\n",
"_",
",",
"oldfile",
",",
"_",
",",
"err",
":=",
"w",
".",
"lookup",
"(",
"oldname",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"switch",
"oldfile",
".",
"Mode",
"&",
"format",
".",
"TypeMask",
"{",
"case",
"format",
".",
"S_IFDIR",
",",
"format",
".",
"S_IFLNK",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"newname",
",",
"oldname",
")",
"\n",
"}",
"\n\n",
"if",
"existing",
"!=",
"oldfile",
"&&",
"oldfile",
".",
"LinkCount",
">=",
"format",
".",
"MaxLinks",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"newname",
",",
"oldname",
")",
"\n",
"}",
"\n\n",
"if",
"existing",
"!=",
"nil",
"{",
"existing",
".",
"LinkCount",
"--",
"\n",
"}",
"\n",
"oldfile",
".",
"LinkCount",
"++",
"\n",
"newdir",
".",
"Children",
"[",
"newchildname",
"]",
"=",
"oldfile",
"\n",
"return",
"nil",
"\n",
"}"
] | // Link adds a hard link to the file system. | [
"Link",
"adds",
"a",
"hard",
"link",
"to",
"the",
"file",
"system",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/ext4/internal/compactext4/compact.go#L564-L595 | train |
Microsoft/hcsshim | ext4/internal/compactext4/compact.go | Stat | func (w *Writer) Stat(name string) (*File, error) {
if err := w.finishInode(); err != nil {
return nil, err
}
_, node, _, err := w.lookup(name, true)
if err != nil {
return nil, err
}
f := &File{
Size: node.Size,
Mode: node.Mode,
Uid: node.Uid,
Gid: node.Gid,
Atime: fsTimeToTime(node.Atime),
Ctime: fsTimeToTime(node.Ctime),
Mtime: fsTimeToTime(node.Mtime),
Crtime: fsTimeToTime(node.Crtime),
Devmajor: node.Devmajor,
Devminor: node.Devminor,
}
f.Xattrs = make(map[string][]byte)
if node.XattrBlock != 0 || len(node.XattrInline) != 0 {
if node.XattrBlock != 0 {
orig := w.block()
w.seekBlock(node.XattrBlock)
if w.err != nil {
return nil, w.err
}
var b [blockSize]byte
_, err := w.f.Read(b[:])
w.seekBlock(orig)
if err != nil {
return nil, err
}
getXattrs(b[32:], f.Xattrs, 32)
}
if len(node.XattrInline) != 0 {
getXattrs(node.XattrInline[4:], f.Xattrs, 0)
delete(f.Xattrs, "system.data")
}
}
if node.FileType() == S_IFLNK {
if node.Size > smallSymlinkSize {
return nil, fmt.Errorf("%s: cannot retrieve link information", name)
}
f.Linkname = string(node.Data)
}
return f, nil
} | go | func (w *Writer) Stat(name string) (*File, error) {
if err := w.finishInode(); err != nil {
return nil, err
}
_, node, _, err := w.lookup(name, true)
if err != nil {
return nil, err
}
f := &File{
Size: node.Size,
Mode: node.Mode,
Uid: node.Uid,
Gid: node.Gid,
Atime: fsTimeToTime(node.Atime),
Ctime: fsTimeToTime(node.Ctime),
Mtime: fsTimeToTime(node.Mtime),
Crtime: fsTimeToTime(node.Crtime),
Devmajor: node.Devmajor,
Devminor: node.Devminor,
}
f.Xattrs = make(map[string][]byte)
if node.XattrBlock != 0 || len(node.XattrInline) != 0 {
if node.XattrBlock != 0 {
orig := w.block()
w.seekBlock(node.XattrBlock)
if w.err != nil {
return nil, w.err
}
var b [blockSize]byte
_, err := w.f.Read(b[:])
w.seekBlock(orig)
if err != nil {
return nil, err
}
getXattrs(b[32:], f.Xattrs, 32)
}
if len(node.XattrInline) != 0 {
getXattrs(node.XattrInline[4:], f.Xattrs, 0)
delete(f.Xattrs, "system.data")
}
}
if node.FileType() == S_IFLNK {
if node.Size > smallSymlinkSize {
return nil, fmt.Errorf("%s: cannot retrieve link information", name)
}
f.Linkname = string(node.Data)
}
return f, nil
} | [
"func",
"(",
"w",
"*",
"Writer",
")",
"Stat",
"(",
"name",
"string",
")",
"(",
"*",
"File",
",",
"error",
")",
"{",
"if",
"err",
":=",
"w",
".",
"finishInode",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"node",
",",
"_",
",",
"err",
":=",
"w",
".",
"lookup",
"(",
"name",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"f",
":=",
"&",
"File",
"{",
"Size",
":",
"node",
".",
"Size",
",",
"Mode",
":",
"node",
".",
"Mode",
",",
"Uid",
":",
"node",
".",
"Uid",
",",
"Gid",
":",
"node",
".",
"Gid",
",",
"Atime",
":",
"fsTimeToTime",
"(",
"node",
".",
"Atime",
")",
",",
"Ctime",
":",
"fsTimeToTime",
"(",
"node",
".",
"Ctime",
")",
",",
"Mtime",
":",
"fsTimeToTime",
"(",
"node",
".",
"Mtime",
")",
",",
"Crtime",
":",
"fsTimeToTime",
"(",
"node",
".",
"Crtime",
")",
",",
"Devmajor",
":",
"node",
".",
"Devmajor",
",",
"Devminor",
":",
"node",
".",
"Devminor",
",",
"}",
"\n",
"f",
".",
"Xattrs",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
")",
"\n",
"if",
"node",
".",
"XattrBlock",
"!=",
"0",
"||",
"len",
"(",
"node",
".",
"XattrInline",
")",
"!=",
"0",
"{",
"if",
"node",
".",
"XattrBlock",
"!=",
"0",
"{",
"orig",
":=",
"w",
".",
"block",
"(",
")",
"\n",
"w",
".",
"seekBlock",
"(",
"node",
".",
"XattrBlock",
")",
"\n",
"if",
"w",
".",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"w",
".",
"err",
"\n",
"}",
"\n",
"var",
"b",
"[",
"blockSize",
"]",
"byte",
"\n",
"_",
",",
"err",
":=",
"w",
".",
"f",
".",
"Read",
"(",
"b",
"[",
":",
"]",
")",
"\n",
"w",
".",
"seekBlock",
"(",
"orig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"getXattrs",
"(",
"b",
"[",
"32",
":",
"]",
",",
"f",
".",
"Xattrs",
",",
"32",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"node",
".",
"XattrInline",
")",
"!=",
"0",
"{",
"getXattrs",
"(",
"node",
".",
"XattrInline",
"[",
"4",
":",
"]",
",",
"f",
".",
"Xattrs",
",",
"0",
")",
"\n",
"delete",
"(",
"f",
".",
"Xattrs",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"node",
".",
"FileType",
"(",
")",
"==",
"S_IFLNK",
"{",
"if",
"node",
".",
"Size",
">",
"smallSymlinkSize",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"f",
".",
"Linkname",
"=",
"string",
"(",
"node",
".",
"Data",
")",
"\n",
"}",
"\n",
"return",
"f",
",",
"nil",
"\n",
"}"
] | // Stat returns information about a file that has been written. | [
"Stat",
"returns",
"information",
"about",
"a",
"file",
"that",
"has",
"been",
"written",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/ext4/internal/compactext4/compact.go#L598-L646 | train |
Microsoft/hcsshim | ext4/internal/compactext4/compact.go | NewWriter | func NewWriter(f io.ReadWriteSeeker, opts ...Option) *Writer {
w := &Writer{
f: f,
bw: bufio.NewWriterSize(f, 65536*8),
maxDiskSize: defaultMaxDiskSize,
}
for _, opt := range opts {
opt(w)
}
return w
} | go | func NewWriter(f io.ReadWriteSeeker, opts ...Option) *Writer {
w := &Writer{
f: f,
bw: bufio.NewWriterSize(f, 65536*8),
maxDiskSize: defaultMaxDiskSize,
}
for _, opt := range opts {
opt(w)
}
return w
} | [
"func",
"NewWriter",
"(",
"f",
"io",
".",
"ReadWriteSeeker",
",",
"opts",
"...",
"Option",
")",
"*",
"Writer",
"{",
"w",
":=",
"&",
"Writer",
"{",
"f",
":",
"f",
",",
"bw",
":",
"bufio",
".",
"NewWriterSize",
"(",
"f",
",",
"65536",
"*",
"8",
")",
",",
"maxDiskSize",
":",
"defaultMaxDiskSize",
",",
"}",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"opts",
"{",
"opt",
"(",
"w",
")",
"\n",
"}",
"\n",
"return",
"w",
"\n",
"}"
] | // NewWriter returns a Writer that writes an ext4 file system to the provided
// WriteSeeker. | [
"NewWriter",
"returns",
"a",
"Writer",
"that",
"writes",
"an",
"ext4",
"file",
"system",
"to",
"the",
"provided",
"WriteSeeker",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/ext4/internal/compactext4/compact.go#L1021-L1031 | train |
Microsoft/hcsshim | ext4/internal/compactext4/compact.go | MaximumDiskSize | func MaximumDiskSize(size int64) Option {
return func(w *Writer) {
if size < 0 || size > maxMaxDiskSize {
w.maxDiskSize = maxMaxDiskSize
} else if size == 0 {
w.maxDiskSize = defaultMaxDiskSize
} else {
w.maxDiskSize = (size + blockSize - 1) &^ (blockSize - 1)
}
}
} | go | func MaximumDiskSize(size int64) Option {
return func(w *Writer) {
if size < 0 || size > maxMaxDiskSize {
w.maxDiskSize = maxMaxDiskSize
} else if size == 0 {
w.maxDiskSize = defaultMaxDiskSize
} else {
w.maxDiskSize = (size + blockSize - 1) &^ (blockSize - 1)
}
}
} | [
"func",
"MaximumDiskSize",
"(",
"size",
"int64",
")",
"Option",
"{",
"return",
"func",
"(",
"w",
"*",
"Writer",
")",
"{",
"if",
"size",
"<",
"0",
"||",
"size",
">",
"maxMaxDiskSize",
"{",
"w",
".",
"maxDiskSize",
"=",
"maxMaxDiskSize",
"\n",
"}",
"else",
"if",
"size",
"==",
"0",
"{",
"w",
".",
"maxDiskSize",
"=",
"defaultMaxDiskSize",
"\n",
"}",
"else",
"{",
"w",
".",
"maxDiskSize",
"=",
"(",
"size",
"+",
"blockSize",
"-",
"1",
")",
"&^",
"(",
"blockSize",
"-",
"1",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // MaximumDiskSize instructs the writer to reserve enough metadata space for the
// specified disk size. If not provided, then 16GB is the default. | [
"MaximumDiskSize",
"instructs",
"the",
"writer",
"to",
"reserve",
"enough",
"metadata",
"space",
"for",
"the",
"specified",
"disk",
"size",
".",
"If",
"not",
"provided",
"then",
"16GB",
"is",
"the",
"default",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/ext4/internal/compactext4/compact.go#L1045-L1055 | train |
Microsoft/hcsshim | cmd/containerd-shim-runhcs-v1/service_internal.go | getPod | func (s *service) getPod() (shimPod, error) {
raw := s.taskOrPod.Load()
if raw == nil {
return nil, errors.Wrapf(errdefs.ErrFailedPrecondition, "task with id: '%s' must be created first", s.tid)
}
return raw.(shimPod), nil
} | go | func (s *service) getPod() (shimPod, error) {
raw := s.taskOrPod.Load()
if raw == nil {
return nil, errors.Wrapf(errdefs.ErrFailedPrecondition, "task with id: '%s' must be created first", s.tid)
}
return raw.(shimPod), nil
} | [
"func",
"(",
"s",
"*",
"service",
")",
"getPod",
"(",
")",
"(",
"shimPod",
",",
"error",
")",
"{",
"raw",
":=",
"s",
".",
"taskOrPod",
".",
"Load",
"(",
")",
"\n",
"if",
"raw",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"errdefs",
".",
"ErrFailedPrecondition",
",",
"\"",
"\"",
",",
"s",
".",
"tid",
")",
"\n",
"}",
"\n",
"return",
"raw",
".",
"(",
"shimPod",
")",
",",
"nil",
"\n",
"}"
] | // getPod returns the pod this shim is tracking or else returns `nil`. It is the
// callers responsibility to verify that `s.isSandbox == true` before calling
// this method.
//
//
// If `pod==nil` returns `errdefs.ErrFailedPrecondition`. | [
"getPod",
"returns",
"the",
"pod",
"this",
"shim",
"is",
"tracking",
"or",
"else",
"returns",
"nil",
".",
"It",
"is",
"the",
"callers",
"responsibility",
"to",
"verify",
"that",
"s",
".",
"isSandbox",
"==",
"true",
"before",
"calling",
"this",
"method",
".",
"If",
"pod",
"==",
"nil",
"returns",
"errdefs",
".",
"ErrFailedPrecondition",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/service_internal.go#L32-L38 | train |
Microsoft/hcsshim | cmd/containerd-shim-runhcs-v1/service_internal.go | getTask | func (s *service) getTask(tid string) (shimTask, error) {
raw := s.taskOrPod.Load()
if raw == nil {
return nil, errors.Wrapf(errdefs.ErrNotFound, "task with id: '%s' not found", tid)
}
if s.isSandbox {
p := raw.(shimPod)
return p.GetTask(tid)
}
// When its not a sandbox only the init task is a valid id.
if s.tid != tid {
return nil, errors.Wrapf(errdefs.ErrNotFound, "task with id: '%s' not found", tid)
}
return raw.(shimTask), nil
} | go | func (s *service) getTask(tid string) (shimTask, error) {
raw := s.taskOrPod.Load()
if raw == nil {
return nil, errors.Wrapf(errdefs.ErrNotFound, "task with id: '%s' not found", tid)
}
if s.isSandbox {
p := raw.(shimPod)
return p.GetTask(tid)
}
// When its not a sandbox only the init task is a valid id.
if s.tid != tid {
return nil, errors.Wrapf(errdefs.ErrNotFound, "task with id: '%s' not found", tid)
}
return raw.(shimTask), nil
} | [
"func",
"(",
"s",
"*",
"service",
")",
"getTask",
"(",
"tid",
"string",
")",
"(",
"shimTask",
",",
"error",
")",
"{",
"raw",
":=",
"s",
".",
"taskOrPod",
".",
"Load",
"(",
")",
"\n",
"if",
"raw",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"errdefs",
".",
"ErrNotFound",
",",
"\"",
"\"",
",",
"tid",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"isSandbox",
"{",
"p",
":=",
"raw",
".",
"(",
"shimPod",
")",
"\n",
"return",
"p",
".",
"GetTask",
"(",
"tid",
")",
"\n",
"}",
"\n",
"// When its not a sandbox only the init task is a valid id.",
"if",
"s",
".",
"tid",
"!=",
"tid",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrapf",
"(",
"errdefs",
".",
"ErrNotFound",
",",
"\"",
"\"",
",",
"tid",
")",
"\n",
"}",
"\n",
"return",
"raw",
".",
"(",
"shimTask",
")",
",",
"nil",
"\n",
"}"
] | // getTask returns a task matching `tid` or else returns `nil`. This properly
// handles a task in a pod or a singular task shim.
//
// If `tid` is not found will return `errdefs.ErrNotFound`. | [
"getTask",
"returns",
"a",
"task",
"matching",
"tid",
"or",
"else",
"returns",
"nil",
".",
"This",
"properly",
"handles",
"a",
"task",
"in",
"a",
"pod",
"or",
"a",
"singular",
"task",
"shim",
".",
"If",
"tid",
"is",
"not",
"found",
"will",
"return",
"errdefs",
".",
"ErrNotFound",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/cmd/containerd-shim-runhcs-v1/service_internal.go#L44-L58 | train |
Microsoft/hcsshim | internal/cni/registry.go | NewPersistedNamespaceConfig | func NewPersistedNamespaceConfig(namespaceID, containerID string, containerHostUniqueID guid.GUID) *PersistedNamespaceConfig {
return &PersistedNamespaceConfig{
namespaceID: namespaceID,
ContainerID: containerID,
HostUniqueID: containerHostUniqueID,
}
} | go | func NewPersistedNamespaceConfig(namespaceID, containerID string, containerHostUniqueID guid.GUID) *PersistedNamespaceConfig {
return &PersistedNamespaceConfig{
namespaceID: namespaceID,
ContainerID: containerID,
HostUniqueID: containerHostUniqueID,
}
} | [
"func",
"NewPersistedNamespaceConfig",
"(",
"namespaceID",
",",
"containerID",
"string",
",",
"containerHostUniqueID",
"guid",
".",
"GUID",
")",
"*",
"PersistedNamespaceConfig",
"{",
"return",
"&",
"PersistedNamespaceConfig",
"{",
"namespaceID",
":",
"namespaceID",
",",
"ContainerID",
":",
"containerID",
",",
"HostUniqueID",
":",
"containerHostUniqueID",
",",
"}",
"\n",
"}"
] | // NewPersistedNamespaceConfig creates an in-memory namespace config that can be
// persisted to the registry. | [
"NewPersistedNamespaceConfig",
"creates",
"an",
"in",
"-",
"memory",
"namespace",
"config",
"that",
"can",
"be",
"persisted",
"to",
"the",
"registry",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/cni/registry.go#L27-L33 | train |
Microsoft/hcsshim | internal/cni/registry.go | LoadPersistedNamespaceConfig | func LoadPersistedNamespaceConfig(namespaceID string) (*PersistedNamespaceConfig, error) {
sk, err := regstate.Open(cniRoot, false)
if err != nil {
return nil, err
}
defer sk.Close()
pnc := PersistedNamespaceConfig{
namespaceID: namespaceID,
stored: true,
}
if err := sk.Get(namespaceID, cniKey, &pnc); err != nil {
return nil, err
}
return &pnc, nil
} | go | func LoadPersistedNamespaceConfig(namespaceID string) (*PersistedNamespaceConfig, error) {
sk, err := regstate.Open(cniRoot, false)
if err != nil {
return nil, err
}
defer sk.Close()
pnc := PersistedNamespaceConfig{
namespaceID: namespaceID,
stored: true,
}
if err := sk.Get(namespaceID, cniKey, &pnc); err != nil {
return nil, err
}
return &pnc, nil
} | [
"func",
"LoadPersistedNamespaceConfig",
"(",
"namespaceID",
"string",
")",
"(",
"*",
"PersistedNamespaceConfig",
",",
"error",
")",
"{",
"sk",
",",
"err",
":=",
"regstate",
".",
"Open",
"(",
"cniRoot",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"sk",
".",
"Close",
"(",
")",
"\n\n",
"pnc",
":=",
"PersistedNamespaceConfig",
"{",
"namespaceID",
":",
"namespaceID",
",",
"stored",
":",
"true",
",",
"}",
"\n",
"if",
"err",
":=",
"sk",
".",
"Get",
"(",
"namespaceID",
",",
"cniKey",
",",
"&",
"pnc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"pnc",
",",
"nil",
"\n",
"}"
] | // LoadPersistedNamespaceConfig loads a persisted config from the registry that matches
// `namespaceID`. If not found returns `regstate.NotFoundError` | [
"LoadPersistedNamespaceConfig",
"loads",
"a",
"persisted",
"config",
"from",
"the",
"registry",
"that",
"matches",
"namespaceID",
".",
"If",
"not",
"found",
"returns",
"regstate",
".",
"NotFoundError"
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/cni/registry.go#L37-L52 | train |
Microsoft/hcsshim | internal/cni/registry.go | Store | func (pnc *PersistedNamespaceConfig) Store() error {
if pnc.namespaceID == "" {
return errors.New("invalid namespaceID ''")
}
if pnc.ContainerID == "" {
return errors.New("invalid containerID ''")
}
empty := guid.GUID{}
if pnc.HostUniqueID == empty {
return errors.New("invalid containerHostUniqueID 'empy'")
}
sk, err := regstate.Open(cniRoot, false)
if err != nil {
return err
}
defer sk.Close()
if pnc.stored {
if err := sk.Set(pnc.namespaceID, cniKey, pnc); err != nil {
return err
}
} else {
if err := sk.Create(pnc.namespaceID, cniKey, pnc); err != nil {
return err
}
}
pnc.stored = true
return nil
} | go | func (pnc *PersistedNamespaceConfig) Store() error {
if pnc.namespaceID == "" {
return errors.New("invalid namespaceID ''")
}
if pnc.ContainerID == "" {
return errors.New("invalid containerID ''")
}
empty := guid.GUID{}
if pnc.HostUniqueID == empty {
return errors.New("invalid containerHostUniqueID 'empy'")
}
sk, err := regstate.Open(cniRoot, false)
if err != nil {
return err
}
defer sk.Close()
if pnc.stored {
if err := sk.Set(pnc.namespaceID, cniKey, pnc); err != nil {
return err
}
} else {
if err := sk.Create(pnc.namespaceID, cniKey, pnc); err != nil {
return err
}
}
pnc.stored = true
return nil
} | [
"func",
"(",
"pnc",
"*",
"PersistedNamespaceConfig",
")",
"Store",
"(",
")",
"error",
"{",
"if",
"pnc",
".",
"namespaceID",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"pnc",
".",
"ContainerID",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"empty",
":=",
"guid",
".",
"GUID",
"{",
"}",
"\n",
"if",
"pnc",
".",
"HostUniqueID",
"==",
"empty",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"sk",
",",
"err",
":=",
"regstate",
".",
"Open",
"(",
"cniRoot",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"sk",
".",
"Close",
"(",
")",
"\n\n",
"if",
"pnc",
".",
"stored",
"{",
"if",
"err",
":=",
"sk",
".",
"Set",
"(",
"pnc",
".",
"namespaceID",
",",
"cniKey",
",",
"pnc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"sk",
".",
"Create",
"(",
"pnc",
".",
"namespaceID",
",",
"cniKey",
",",
"pnc",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"pnc",
".",
"stored",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] | // Store stores or updates the in-memory config to its registry state. If the
// store failes returns the store error. | [
"Store",
"stores",
"or",
"updates",
"the",
"in",
"-",
"memory",
"config",
"to",
"its",
"registry",
"state",
".",
"If",
"the",
"store",
"failes",
"returns",
"the",
"store",
"error",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/cni/registry.go#L56-L84 | train |
Microsoft/hcsshim | internal/cni/registry.go | Remove | func (pnc *PersistedNamespaceConfig) Remove() error {
if pnc.stored {
sk, err := regstate.Open(cniRoot, false)
if err != nil {
if regstate.IsNotFoundError(err) {
pnc.stored = false
return nil
}
return err
}
defer sk.Close()
if err := sk.Remove(pnc.namespaceID); err != nil {
if regstate.IsNotFoundError(err) {
pnc.stored = false
return nil
}
return err
}
}
pnc.stored = false
return nil
} | go | func (pnc *PersistedNamespaceConfig) Remove() error {
if pnc.stored {
sk, err := regstate.Open(cniRoot, false)
if err != nil {
if regstate.IsNotFoundError(err) {
pnc.stored = false
return nil
}
return err
}
defer sk.Close()
if err := sk.Remove(pnc.namespaceID); err != nil {
if regstate.IsNotFoundError(err) {
pnc.stored = false
return nil
}
return err
}
}
pnc.stored = false
return nil
} | [
"func",
"(",
"pnc",
"*",
"PersistedNamespaceConfig",
")",
"Remove",
"(",
")",
"error",
"{",
"if",
"pnc",
".",
"stored",
"{",
"sk",
",",
"err",
":=",
"regstate",
".",
"Open",
"(",
"cniRoot",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"regstate",
".",
"IsNotFoundError",
"(",
"err",
")",
"{",
"pnc",
".",
"stored",
"=",
"false",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"sk",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
":=",
"sk",
".",
"Remove",
"(",
"pnc",
".",
"namespaceID",
")",
";",
"err",
"!=",
"nil",
"{",
"if",
"regstate",
".",
"IsNotFoundError",
"(",
"err",
")",
"{",
"pnc",
".",
"stored",
"=",
"false",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"pnc",
".",
"stored",
"=",
"false",
"\n",
"return",
"nil",
"\n",
"}"
] | // Remove removes any persisted state associated with this config. If the config
// is not found in the registery `Remove` returns no error. | [
"Remove",
"removes",
"any",
"persisted",
"state",
"associated",
"with",
"this",
"config",
".",
"If",
"the",
"config",
"is",
"not",
"found",
"in",
"the",
"registery",
"Remove",
"returns",
"no",
"error",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/cni/registry.go#L88-L110 | train |
Microsoft/hcsshim | internal/wclayer/destroylayer.go | DestroyLayer | func DestroyLayer(path string) (err error) {
title := "hcsshim::DestroyLayer"
fields := logrus.Fields{
"path": path,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = destroyLayer(&stdDriverInfo, path)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
} | go | func DestroyLayer(path string) (err error) {
title := "hcsshim::DestroyLayer"
fields := logrus.Fields{
"path": path,
}
logrus.WithFields(fields).Debug(title)
defer func() {
if err != nil {
fields[logrus.ErrorKey] = err
logrus.WithFields(fields).Error(err)
} else {
logrus.WithFields(fields).Debug(title + " - succeeded")
}
}()
err = destroyLayer(&stdDriverInfo, path)
if err != nil {
return hcserror.New(err, title+" - failed", "")
}
return nil
} | [
"func",
"DestroyLayer",
"(",
"path",
"string",
")",
"(",
"err",
"error",
")",
"{",
"title",
":=",
"\"",
"\"",
"\n",
"fields",
":=",
"logrus",
".",
"Fields",
"{",
"\"",
"\"",
":",
"path",
",",
"}",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
")",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"!=",
"nil",
"{",
"fields",
"[",
"logrus",
".",
"ErrorKey",
"]",
"=",
"err",
"\n",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Error",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"WithFields",
"(",
"fields",
")",
".",
"Debug",
"(",
"title",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"err",
"=",
"destroyLayer",
"(",
"&",
"stdDriverInfo",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"hcserror",
".",
"New",
"(",
"err",
",",
"title",
"+",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // DestroyLayer will remove the on-disk files representing the layer with the given
// path, including that layer's containing folder, if any. | [
"DestroyLayer",
"will",
"remove",
"the",
"on",
"-",
"disk",
"files",
"representing",
"the",
"layer",
"with",
"the",
"given",
"path",
"including",
"that",
"layer",
"s",
"containing",
"folder",
"if",
"any",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/wclayer/destroylayer.go#L10-L30 | train |
Microsoft/hcsshim | pkg/go-runhcs/runhcs_resize-tty.go | ResizeTTY | func (r *Runhcs) ResizeTTY(context context.Context, id string, width, height uint16, opts *ResizeTTYOpts) error {
args := []string{"resize-tty"}
if opts != nil {
oargs, err := opts.args()
if err != nil {
return err
}
args = append(args, oargs...)
}
return r.runOrError(r.command(context, append(args, id, strconv.FormatUint(uint64(width), 10), strconv.FormatUint(uint64(height), 10))...))
} | go | func (r *Runhcs) ResizeTTY(context context.Context, id string, width, height uint16, opts *ResizeTTYOpts) error {
args := []string{"resize-tty"}
if opts != nil {
oargs, err := opts.args()
if err != nil {
return err
}
args = append(args, oargs...)
}
return r.runOrError(r.command(context, append(args, id, strconv.FormatUint(uint64(width), 10), strconv.FormatUint(uint64(height), 10))...))
} | [
"func",
"(",
"r",
"*",
"Runhcs",
")",
"ResizeTTY",
"(",
"context",
"context",
".",
"Context",
",",
"id",
"string",
",",
"width",
",",
"height",
"uint16",
",",
"opts",
"*",
"ResizeTTYOpts",
")",
"error",
"{",
"args",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"\n",
"if",
"opts",
"!=",
"nil",
"{",
"oargs",
",",
"err",
":=",
"opts",
".",
"args",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"args",
"=",
"append",
"(",
"args",
",",
"oargs",
"...",
")",
"\n",
"}",
"\n",
"return",
"r",
".",
"runOrError",
"(",
"r",
".",
"command",
"(",
"context",
",",
"append",
"(",
"args",
",",
"id",
",",
"strconv",
".",
"FormatUint",
"(",
"uint64",
"(",
"width",
")",
",",
"10",
")",
",",
"strconv",
".",
"FormatUint",
"(",
"uint64",
"(",
"height",
")",
",",
"10",
")",
")",
"...",
")",
")",
"\n",
"}"
] | // ResizeTTY updates the terminal size for a container process. | [
"ResizeTTY",
"updates",
"the",
"terminal",
"size",
"for",
"a",
"container",
"process",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/pkg/go-runhcs/runhcs_resize-tty.go#L23-L33 | train |
Microsoft/hcsshim | internal/oci/sandbox.go | GetSandboxTypeAndID | func GetSandboxTypeAndID(specAnnotations map[string]string) (KubernetesContainerType, string, error) {
var ct KubernetesContainerType
if t, ok := specAnnotations[KubernetesContainerTypeAnnotation]; ok {
switch t {
case string(KubernetesContainerTypeContainer):
ct = KubernetesContainerTypeContainer
case string(KubernetesContainerTypeSandbox):
ct = KubernetesContainerTypeSandbox
default:
return KubernetesContainerTypeNone, "", fmt.Errorf("invalid '%s': '%s'", KubernetesContainerTypeAnnotation, t)
}
}
id := specAnnotations[KubernetesSandboxIDAnnotation]
switch ct {
case KubernetesContainerTypeContainer, KubernetesContainerTypeSandbox:
if id == "" {
return KubernetesContainerTypeNone, "", fmt.Errorf("cannot specify '%s' without '%s'", KubernetesContainerTypeAnnotation, KubernetesSandboxIDAnnotation)
}
default:
if id != "" {
return KubernetesContainerTypeNone, "", fmt.Errorf("cannot specify '%s' without '%s'", KubernetesSandboxIDAnnotation, KubernetesContainerTypeAnnotation)
}
}
return ct, id, nil
} | go | func GetSandboxTypeAndID(specAnnotations map[string]string) (KubernetesContainerType, string, error) {
var ct KubernetesContainerType
if t, ok := specAnnotations[KubernetesContainerTypeAnnotation]; ok {
switch t {
case string(KubernetesContainerTypeContainer):
ct = KubernetesContainerTypeContainer
case string(KubernetesContainerTypeSandbox):
ct = KubernetesContainerTypeSandbox
default:
return KubernetesContainerTypeNone, "", fmt.Errorf("invalid '%s': '%s'", KubernetesContainerTypeAnnotation, t)
}
}
id := specAnnotations[KubernetesSandboxIDAnnotation]
switch ct {
case KubernetesContainerTypeContainer, KubernetesContainerTypeSandbox:
if id == "" {
return KubernetesContainerTypeNone, "", fmt.Errorf("cannot specify '%s' without '%s'", KubernetesContainerTypeAnnotation, KubernetesSandboxIDAnnotation)
}
default:
if id != "" {
return KubernetesContainerTypeNone, "", fmt.Errorf("cannot specify '%s' without '%s'", KubernetesSandboxIDAnnotation, KubernetesContainerTypeAnnotation)
}
}
return ct, id, nil
} | [
"func",
"GetSandboxTypeAndID",
"(",
"specAnnotations",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"KubernetesContainerType",
",",
"string",
",",
"error",
")",
"{",
"var",
"ct",
"KubernetesContainerType",
"\n",
"if",
"t",
",",
"ok",
":=",
"specAnnotations",
"[",
"KubernetesContainerTypeAnnotation",
"]",
";",
"ok",
"{",
"switch",
"t",
"{",
"case",
"string",
"(",
"KubernetesContainerTypeContainer",
")",
":",
"ct",
"=",
"KubernetesContainerTypeContainer",
"\n",
"case",
"string",
"(",
"KubernetesContainerTypeSandbox",
")",
":",
"ct",
"=",
"KubernetesContainerTypeSandbox",
"\n",
"default",
":",
"return",
"KubernetesContainerTypeNone",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"KubernetesContainerTypeAnnotation",
",",
"t",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"id",
":=",
"specAnnotations",
"[",
"KubernetesSandboxIDAnnotation",
"]",
"\n\n",
"switch",
"ct",
"{",
"case",
"KubernetesContainerTypeContainer",
",",
"KubernetesContainerTypeSandbox",
":",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"KubernetesContainerTypeNone",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"KubernetesContainerTypeAnnotation",
",",
"KubernetesSandboxIDAnnotation",
")",
"\n",
"}",
"\n",
"default",
":",
"if",
"id",
"!=",
"\"",
"\"",
"{",
"return",
"KubernetesContainerTypeNone",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"KubernetesSandboxIDAnnotation",
",",
"KubernetesContainerTypeAnnotation",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"ct",
",",
"id",
",",
"nil",
"\n",
"}"
] | // GetSandboxTypeAndID parses `specAnnotations` searching for the
// `KubernetesContainerTypeAnnotation` and `KubernetesSandboxIDAnnotation`
// annotations and if found validates the set before returning. | [
"GetSandboxTypeAndID",
"parses",
"specAnnotations",
"searching",
"for",
"the",
"KubernetesContainerTypeAnnotation",
"and",
"KubernetesSandboxIDAnnotation",
"annotations",
"and",
"if",
"found",
"validates",
"the",
"set",
"before",
"returning",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/oci/sandbox.go#L33-L59 | train |
Microsoft/hcsshim | internal/safefile/safeopen.go | openRelativeInternal | func openRelativeInternal(path string, root *os.File, accessMask uint32, shareFlags uint32, createDisposition uint32, flags uint32) (*os.File, error) {
var (
h uintptr
iosb ioStatusBlock
oa objectAttributes
)
path16, err := ntRelativePath(path)
if err != nil {
return nil, err
}
if root == nil || root.Fd() == 0 {
return nil, errors.New("missing root directory")
}
upathBuffer := localAlloc(0, int(unsafe.Sizeof(unicodeString{}))+len(path16)*2)
defer localFree(upathBuffer)
upath := (*unicodeString)(unsafe.Pointer(upathBuffer))
upath.Length = uint16(len(path16) * 2)
upath.MaximumLength = upath.Length
upath.Buffer = upathBuffer + unsafe.Sizeof(*upath)
copy((*[32768]uint16)(unsafe.Pointer(upath.Buffer))[:], path16)
oa.Length = unsafe.Sizeof(oa)
oa.ObjectName = upathBuffer
oa.RootDirectory = uintptr(root.Fd())
oa.Attributes = _OBJ_DONT_REPARSE
status := ntCreateFile(
&h,
accessMask|syscall.SYNCHRONIZE,
&oa,
&iosb,
nil,
0,
shareFlags,
createDisposition,
FILE_OPEN_FOR_BACKUP_INTENT|FILE_SYNCHRONOUS_IO_NONALERT|flags,
nil,
0,
)
if status != 0 {
return nil, rtlNtStatusToDosError(status)
}
fullPath, err := longpath.LongAbs(filepath.Join(root.Name(), path))
if err != nil {
syscall.Close(syscall.Handle(h))
return nil, err
}
return os.NewFile(h, fullPath), nil
} | go | func openRelativeInternal(path string, root *os.File, accessMask uint32, shareFlags uint32, createDisposition uint32, flags uint32) (*os.File, error) {
var (
h uintptr
iosb ioStatusBlock
oa objectAttributes
)
path16, err := ntRelativePath(path)
if err != nil {
return nil, err
}
if root == nil || root.Fd() == 0 {
return nil, errors.New("missing root directory")
}
upathBuffer := localAlloc(0, int(unsafe.Sizeof(unicodeString{}))+len(path16)*2)
defer localFree(upathBuffer)
upath := (*unicodeString)(unsafe.Pointer(upathBuffer))
upath.Length = uint16(len(path16) * 2)
upath.MaximumLength = upath.Length
upath.Buffer = upathBuffer + unsafe.Sizeof(*upath)
copy((*[32768]uint16)(unsafe.Pointer(upath.Buffer))[:], path16)
oa.Length = unsafe.Sizeof(oa)
oa.ObjectName = upathBuffer
oa.RootDirectory = uintptr(root.Fd())
oa.Attributes = _OBJ_DONT_REPARSE
status := ntCreateFile(
&h,
accessMask|syscall.SYNCHRONIZE,
&oa,
&iosb,
nil,
0,
shareFlags,
createDisposition,
FILE_OPEN_FOR_BACKUP_INTENT|FILE_SYNCHRONOUS_IO_NONALERT|flags,
nil,
0,
)
if status != 0 {
return nil, rtlNtStatusToDosError(status)
}
fullPath, err := longpath.LongAbs(filepath.Join(root.Name(), path))
if err != nil {
syscall.Close(syscall.Handle(h))
return nil, err
}
return os.NewFile(h, fullPath), nil
} | [
"func",
"openRelativeInternal",
"(",
"path",
"string",
",",
"root",
"*",
"os",
".",
"File",
",",
"accessMask",
"uint32",
",",
"shareFlags",
"uint32",
",",
"createDisposition",
"uint32",
",",
"flags",
"uint32",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"var",
"(",
"h",
"uintptr",
"\n",
"iosb",
"ioStatusBlock",
"\n",
"oa",
"objectAttributes",
"\n",
")",
"\n\n",
"path16",
",",
"err",
":=",
"ntRelativePath",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"root",
"==",
"nil",
"||",
"root",
".",
"Fd",
"(",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"upathBuffer",
":=",
"localAlloc",
"(",
"0",
",",
"int",
"(",
"unsafe",
".",
"Sizeof",
"(",
"unicodeString",
"{",
"}",
")",
")",
"+",
"len",
"(",
"path16",
")",
"*",
"2",
")",
"\n",
"defer",
"localFree",
"(",
"upathBuffer",
")",
"\n\n",
"upath",
":=",
"(",
"*",
"unicodeString",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"upathBuffer",
")",
")",
"\n",
"upath",
".",
"Length",
"=",
"uint16",
"(",
"len",
"(",
"path16",
")",
"*",
"2",
")",
"\n",
"upath",
".",
"MaximumLength",
"=",
"upath",
".",
"Length",
"\n",
"upath",
".",
"Buffer",
"=",
"upathBuffer",
"+",
"unsafe",
".",
"Sizeof",
"(",
"*",
"upath",
")",
"\n",
"copy",
"(",
"(",
"*",
"[",
"32768",
"]",
"uint16",
")",
"(",
"unsafe",
".",
"Pointer",
"(",
"upath",
".",
"Buffer",
")",
")",
"[",
":",
"]",
",",
"path16",
")",
"\n\n",
"oa",
".",
"Length",
"=",
"unsafe",
".",
"Sizeof",
"(",
"oa",
")",
"\n",
"oa",
".",
"ObjectName",
"=",
"upathBuffer",
"\n",
"oa",
".",
"RootDirectory",
"=",
"uintptr",
"(",
"root",
".",
"Fd",
"(",
")",
")",
"\n",
"oa",
".",
"Attributes",
"=",
"_OBJ_DONT_REPARSE",
"\n",
"status",
":=",
"ntCreateFile",
"(",
"&",
"h",
",",
"accessMask",
"|",
"syscall",
".",
"SYNCHRONIZE",
",",
"&",
"oa",
",",
"&",
"iosb",
",",
"nil",
",",
"0",
",",
"shareFlags",
",",
"createDisposition",
",",
"FILE_OPEN_FOR_BACKUP_INTENT",
"|",
"FILE_SYNCHRONOUS_IO_NONALERT",
"|",
"flags",
",",
"nil",
",",
"0",
",",
")",
"\n",
"if",
"status",
"!=",
"0",
"{",
"return",
"nil",
",",
"rtlNtStatusToDosError",
"(",
"status",
")",
"\n",
"}",
"\n\n",
"fullPath",
",",
"err",
":=",
"longpath",
".",
"LongAbs",
"(",
"filepath",
".",
"Join",
"(",
"root",
".",
"Name",
"(",
")",
",",
"path",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"syscall",
".",
"Close",
"(",
"syscall",
".",
"Handle",
"(",
"h",
")",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"os",
".",
"NewFile",
"(",
"h",
",",
"fullPath",
")",
",",
"nil",
"\n",
"}"
] | // openRelativeInternal opens a relative path from the given root, failing if
// any of the intermediate path components are reparse points. | [
"openRelativeInternal",
"opens",
"a",
"relative",
"path",
"from",
"the",
"given",
"root",
"failing",
"if",
"any",
"of",
"the",
"intermediate",
"path",
"components",
"are",
"reparse",
"points",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/safefile/safeopen.go#L110-L163 | train |
Microsoft/hcsshim | internal/safefile/safeopen.go | OpenRelative | func OpenRelative(path string, root *os.File, accessMask uint32, shareFlags uint32, createDisposition uint32, flags uint32) (*os.File, error) {
f, err := openRelativeInternal(path, root, accessMask, shareFlags, createDisposition, flags)
if err != nil {
err = &os.PathError{Op: "open", Path: filepath.Join(root.Name(), path), Err: err}
}
return f, err
} | go | func OpenRelative(path string, root *os.File, accessMask uint32, shareFlags uint32, createDisposition uint32, flags uint32) (*os.File, error) {
f, err := openRelativeInternal(path, root, accessMask, shareFlags, createDisposition, flags)
if err != nil {
err = &os.PathError{Op: "open", Path: filepath.Join(root.Name(), path), Err: err}
}
return f, err
} | [
"func",
"OpenRelative",
"(",
"path",
"string",
",",
"root",
"*",
"os",
".",
"File",
",",
"accessMask",
"uint32",
",",
"shareFlags",
"uint32",
",",
"createDisposition",
"uint32",
",",
"flags",
"uint32",
")",
"(",
"*",
"os",
".",
"File",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"openRelativeInternal",
"(",
"path",
",",
"root",
",",
"accessMask",
",",
"shareFlags",
",",
"createDisposition",
",",
"flags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"&",
"os",
".",
"PathError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Path",
":",
"filepath",
".",
"Join",
"(",
"root",
".",
"Name",
"(",
")",
",",
"path",
")",
",",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n",
"return",
"f",
",",
"err",
"\n",
"}"
] | // OpenRelative opens a relative path from the given root, failing if
// any of the intermediate path components are reparse points. | [
"OpenRelative",
"opens",
"a",
"relative",
"path",
"from",
"the",
"given",
"root",
"failing",
"if",
"any",
"of",
"the",
"intermediate",
"path",
"components",
"are",
"reparse",
"points",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/safefile/safeopen.go#L167-L173 | train |
Microsoft/hcsshim | internal/safefile/safeopen.go | deleteOnClose | func deleteOnClose(f *os.File) error {
disposition := fileDispositionInformationEx{Flags: FILE_DISPOSITION_DELETE}
var iosb ioStatusBlock
status := ntSetInformationFile(
f.Fd(),
&iosb,
uintptr(unsafe.Pointer(&disposition)),
uint32(unsafe.Sizeof(disposition)),
_FileDispositionInformationEx,
)
if status != 0 {
return rtlNtStatusToDosError(status)
}
return nil
} | go | func deleteOnClose(f *os.File) error {
disposition := fileDispositionInformationEx{Flags: FILE_DISPOSITION_DELETE}
var iosb ioStatusBlock
status := ntSetInformationFile(
f.Fd(),
&iosb,
uintptr(unsafe.Pointer(&disposition)),
uint32(unsafe.Sizeof(disposition)),
_FileDispositionInformationEx,
)
if status != 0 {
return rtlNtStatusToDosError(status)
}
return nil
} | [
"func",
"deleteOnClose",
"(",
"f",
"*",
"os",
".",
"File",
")",
"error",
"{",
"disposition",
":=",
"fileDispositionInformationEx",
"{",
"Flags",
":",
"FILE_DISPOSITION_DELETE",
"}",
"\n",
"var",
"iosb",
"ioStatusBlock",
"\n",
"status",
":=",
"ntSetInformationFile",
"(",
"f",
".",
"Fd",
"(",
")",
",",
"&",
"iosb",
",",
"uintptr",
"(",
"unsafe",
".",
"Pointer",
"(",
"&",
"disposition",
")",
")",
",",
"uint32",
"(",
"unsafe",
".",
"Sizeof",
"(",
"disposition",
")",
")",
",",
"_FileDispositionInformationEx",
",",
")",
"\n",
"if",
"status",
"!=",
"0",
"{",
"return",
"rtlNtStatusToDosError",
"(",
"status",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // deleteOnClose marks a file to be deleted when the handle is closed. | [
"deleteOnClose",
"marks",
"a",
"file",
"to",
"be",
"deleted",
"when",
"the",
"handle",
"is",
"closed",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/safefile/safeopen.go#L254-L268 | train |
Microsoft/hcsshim | internal/safefile/safeopen.go | clearReadOnly | func clearReadOnly(f *os.File) error {
bi, err := winio.GetFileBasicInfo(f)
if err != nil {
return err
}
if bi.FileAttributes&syscall.FILE_ATTRIBUTE_READONLY == 0 {
return nil
}
sbi := winio.FileBasicInfo{
FileAttributes: bi.FileAttributes &^ syscall.FILE_ATTRIBUTE_READONLY,
}
if sbi.FileAttributes == 0 {
sbi.FileAttributes = syscall.FILE_ATTRIBUTE_NORMAL
}
return winio.SetFileBasicInfo(f, &sbi)
} | go | func clearReadOnly(f *os.File) error {
bi, err := winio.GetFileBasicInfo(f)
if err != nil {
return err
}
if bi.FileAttributes&syscall.FILE_ATTRIBUTE_READONLY == 0 {
return nil
}
sbi := winio.FileBasicInfo{
FileAttributes: bi.FileAttributes &^ syscall.FILE_ATTRIBUTE_READONLY,
}
if sbi.FileAttributes == 0 {
sbi.FileAttributes = syscall.FILE_ATTRIBUTE_NORMAL
}
return winio.SetFileBasicInfo(f, &sbi)
} | [
"func",
"clearReadOnly",
"(",
"f",
"*",
"os",
".",
"File",
")",
"error",
"{",
"bi",
",",
"err",
":=",
"winio",
".",
"GetFileBasicInfo",
"(",
"f",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"bi",
".",
"FileAttributes",
"&",
"syscall",
".",
"FILE_ATTRIBUTE_READONLY",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"sbi",
":=",
"winio",
".",
"FileBasicInfo",
"{",
"FileAttributes",
":",
"bi",
".",
"FileAttributes",
"&^",
"syscall",
".",
"FILE_ATTRIBUTE_READONLY",
",",
"}",
"\n",
"if",
"sbi",
".",
"FileAttributes",
"==",
"0",
"{",
"sbi",
".",
"FileAttributes",
"=",
"syscall",
".",
"FILE_ATTRIBUTE_NORMAL",
"\n",
"}",
"\n",
"return",
"winio",
".",
"SetFileBasicInfo",
"(",
"f",
",",
"&",
"sbi",
")",
"\n",
"}"
] | // clearReadOnly clears the readonly attribute on a file. | [
"clearReadOnly",
"clears",
"the",
"readonly",
"attribute",
"on",
"a",
"file",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/safefile/safeopen.go#L271-L286 | train |
Microsoft/hcsshim | internal/safefile/safeopen.go | RemoveRelative | func RemoveRelative(path string, root *os.File) error {
f, err := openRelativeInternal(
path,
root,
FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES|DELETE,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
FILE_OPEN,
FILE_OPEN_REPARSE_POINT)
if err == nil {
defer f.Close()
err = deleteOnClose(f)
if err == syscall.ERROR_ACCESS_DENIED {
// Maybe the file is marked readonly. Clear the bit and retry.
clearReadOnly(f)
err = deleteOnClose(f)
}
}
if err != nil {
return &os.PathError{Op: "remove", Path: filepath.Join(root.Name(), path), Err: err}
}
return nil
} | go | func RemoveRelative(path string, root *os.File) error {
f, err := openRelativeInternal(
path,
root,
FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES|DELETE,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
FILE_OPEN,
FILE_OPEN_REPARSE_POINT)
if err == nil {
defer f.Close()
err = deleteOnClose(f)
if err == syscall.ERROR_ACCESS_DENIED {
// Maybe the file is marked readonly. Clear the bit and retry.
clearReadOnly(f)
err = deleteOnClose(f)
}
}
if err != nil {
return &os.PathError{Op: "remove", Path: filepath.Join(root.Name(), path), Err: err}
}
return nil
} | [
"func",
"RemoveRelative",
"(",
"path",
"string",
",",
"root",
"*",
"os",
".",
"File",
")",
"error",
"{",
"f",
",",
"err",
":=",
"openRelativeInternal",
"(",
"path",
",",
"root",
",",
"FILE_READ_ATTRIBUTES",
"|",
"FILE_WRITE_ATTRIBUTES",
"|",
"DELETE",
",",
"syscall",
".",
"FILE_SHARE_READ",
"|",
"syscall",
".",
"FILE_SHARE_WRITE",
"|",
"syscall",
".",
"FILE_SHARE_DELETE",
",",
"FILE_OPEN",
",",
"FILE_OPEN_REPARSE_POINT",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"err",
"=",
"deleteOnClose",
"(",
"f",
")",
"\n",
"if",
"err",
"==",
"syscall",
".",
"ERROR_ACCESS_DENIED",
"{",
"// Maybe the file is marked readonly. Clear the bit and retry.",
"clearReadOnly",
"(",
"f",
")",
"\n",
"err",
"=",
"deleteOnClose",
"(",
"f",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"os",
".",
"PathError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Path",
":",
"filepath",
".",
"Join",
"(",
"root",
".",
"Name",
"(",
")",
",",
"path",
")",
",",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // RemoveRelative removes a file or directory relative to a root, failing if any
// intermediate path components are reparse points. | [
"RemoveRelative",
"removes",
"a",
"file",
"or",
"directory",
"relative",
"to",
"a",
"root",
"failing",
"if",
"any",
"intermediate",
"path",
"components",
"are",
"reparse",
"points",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/safefile/safeopen.go#L290-L311 | train |
Microsoft/hcsshim | internal/safefile/safeopen.go | RemoveAllRelative | func RemoveAllRelative(path string, root *os.File) error {
fi, err := LstatRelative(path, root)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}
fileAttributes := fi.Sys().(*syscall.Win32FileAttributeData).FileAttributes
if fileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY == 0 || fileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0 {
// If this is a reparse point, it can't have children. Simple remove will do.
err := RemoveRelative(path, root)
if err == nil || os.IsNotExist(err) {
return nil
}
return err
}
// It is necessary to use os.Open as Readdirnames does not work with
// OpenRelative. This is safe because the above lstatrelative fails
// if the target is outside the root, and we know this is not a
// symlink from the above FILE_ATTRIBUTE_REPARSE_POINT check.
fd, err := os.Open(filepath.Join(root.Name(), path))
if err != nil {
if os.IsNotExist(err) {
// Race. It was deleted between the Lstat and Open.
// Return nil per RemoveAll's docs.
return nil
}
return err
}
// Remove contents & return first error.
for {
names, err1 := fd.Readdirnames(100)
for _, name := range names {
err1 := RemoveAllRelative(path+string(os.PathSeparator)+name, root)
if err == nil {
err = err1
}
}
if err1 == io.EOF {
break
}
// If Readdirnames returned an error, use it.
if err == nil {
err = err1
}
if len(names) == 0 {
break
}
}
fd.Close()
// Remove directory.
err1 := RemoveRelative(path, root)
if err1 == nil || os.IsNotExist(err1) {
return nil
}
if err == nil {
err = err1
}
return err
} | go | func RemoveAllRelative(path string, root *os.File) error {
fi, err := LstatRelative(path, root)
if err != nil {
if os.IsNotExist(err) {
return nil
}
return err
}
fileAttributes := fi.Sys().(*syscall.Win32FileAttributeData).FileAttributes
if fileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY == 0 || fileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0 {
// If this is a reparse point, it can't have children. Simple remove will do.
err := RemoveRelative(path, root)
if err == nil || os.IsNotExist(err) {
return nil
}
return err
}
// It is necessary to use os.Open as Readdirnames does not work with
// OpenRelative. This is safe because the above lstatrelative fails
// if the target is outside the root, and we know this is not a
// symlink from the above FILE_ATTRIBUTE_REPARSE_POINT check.
fd, err := os.Open(filepath.Join(root.Name(), path))
if err != nil {
if os.IsNotExist(err) {
// Race. It was deleted between the Lstat and Open.
// Return nil per RemoveAll's docs.
return nil
}
return err
}
// Remove contents & return first error.
for {
names, err1 := fd.Readdirnames(100)
for _, name := range names {
err1 := RemoveAllRelative(path+string(os.PathSeparator)+name, root)
if err == nil {
err = err1
}
}
if err1 == io.EOF {
break
}
// If Readdirnames returned an error, use it.
if err == nil {
err = err1
}
if len(names) == 0 {
break
}
}
fd.Close()
// Remove directory.
err1 := RemoveRelative(path, root)
if err1 == nil || os.IsNotExist(err1) {
return nil
}
if err == nil {
err = err1
}
return err
} | [
"func",
"RemoveAllRelative",
"(",
"path",
"string",
",",
"root",
"*",
"os",
".",
"File",
")",
"error",
"{",
"fi",
",",
"err",
":=",
"LstatRelative",
"(",
"path",
",",
"root",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"fileAttributes",
":=",
"fi",
".",
"Sys",
"(",
")",
".",
"(",
"*",
"syscall",
".",
"Win32FileAttributeData",
")",
".",
"FileAttributes",
"\n",
"if",
"fileAttributes",
"&",
"syscall",
".",
"FILE_ATTRIBUTE_DIRECTORY",
"==",
"0",
"||",
"fileAttributes",
"&",
"syscall",
".",
"FILE_ATTRIBUTE_REPARSE_POINT",
"!=",
"0",
"{",
"// If this is a reparse point, it can't have children. Simple remove will do.",
"err",
":=",
"RemoveRelative",
"(",
"path",
",",
"root",
")",
"\n",
"if",
"err",
"==",
"nil",
"||",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// It is necessary to use os.Open as Readdirnames does not work with",
"// OpenRelative. This is safe because the above lstatrelative fails",
"// if the target is outside the root, and we know this is not a",
"// symlink from the above FILE_ATTRIBUTE_REPARSE_POINT check.",
"fd",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filepath",
".",
"Join",
"(",
"root",
".",
"Name",
"(",
")",
",",
"path",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"// Race. It was deleted between the Lstat and Open.",
"// Return nil per RemoveAll's docs.",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Remove contents & return first error.",
"for",
"{",
"names",
",",
"err1",
":=",
"fd",
".",
"Readdirnames",
"(",
"100",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"err1",
":=",
"RemoveAllRelative",
"(",
"path",
"+",
"string",
"(",
"os",
".",
"PathSeparator",
")",
"+",
"name",
",",
"root",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"err1",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err1",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n",
"// If Readdirnames returned an error, use it.",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"err1",
"\n",
"}",
"\n",
"if",
"len",
"(",
"names",
")",
"==",
"0",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"fd",
".",
"Close",
"(",
")",
"\n\n",
"// Remove directory.",
"err1",
":=",
"RemoveRelative",
"(",
"path",
",",
"root",
")",
"\n",
"if",
"err1",
"==",
"nil",
"||",
"os",
".",
"IsNotExist",
"(",
"err1",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"err1",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // RemoveAllRelative removes a directory tree relative to a root, failing if any
// intermediate path components are reparse points. | [
"RemoveAllRelative",
"removes",
"a",
"directory",
"tree",
"relative",
"to",
"a",
"root",
"failing",
"if",
"any",
"intermediate",
"path",
"components",
"are",
"reparse",
"points",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/safefile/safeopen.go#L315-L378 | train |
Microsoft/hcsshim | internal/safefile/safeopen.go | MkdirRelative | func MkdirRelative(path string, root *os.File) error {
f, err := openRelativeInternal(
path,
root,
0,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
FILE_CREATE,
FILE_DIRECTORY_FILE)
if err == nil {
f.Close()
} else {
err = &os.PathError{Op: "mkdir", Path: filepath.Join(root.Name(), path), Err: err}
}
return err
} | go | func MkdirRelative(path string, root *os.File) error {
f, err := openRelativeInternal(
path,
root,
0,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
FILE_CREATE,
FILE_DIRECTORY_FILE)
if err == nil {
f.Close()
} else {
err = &os.PathError{Op: "mkdir", Path: filepath.Join(root.Name(), path), Err: err}
}
return err
} | [
"func",
"MkdirRelative",
"(",
"path",
"string",
",",
"root",
"*",
"os",
".",
"File",
")",
"error",
"{",
"f",
",",
"err",
":=",
"openRelativeInternal",
"(",
"path",
",",
"root",
",",
"0",
",",
"syscall",
".",
"FILE_SHARE_READ",
"|",
"syscall",
".",
"FILE_SHARE_WRITE",
"|",
"syscall",
".",
"FILE_SHARE_DELETE",
",",
"FILE_CREATE",
",",
"FILE_DIRECTORY_FILE",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"f",
".",
"Close",
"(",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"&",
"os",
".",
"PathError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Path",
":",
"filepath",
".",
"Join",
"(",
"root",
".",
"Name",
"(",
")",
",",
"path",
")",
",",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // MkdirRelative creates a directory relative to a root, failing if any
// intermediate path components are reparse points. | [
"MkdirRelative",
"creates",
"a",
"directory",
"relative",
"to",
"a",
"root",
"failing",
"if",
"any",
"intermediate",
"path",
"components",
"are",
"reparse",
"points",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/safefile/safeopen.go#L382-L396 | train |
Microsoft/hcsshim | internal/safefile/safeopen.go | LstatRelative | func LstatRelative(path string, root *os.File) (os.FileInfo, error) {
f, err := openRelativeInternal(
path,
root,
FILE_READ_ATTRIBUTES,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
FILE_OPEN,
FILE_OPEN_REPARSE_POINT)
if err != nil {
return nil, &os.PathError{Op: "stat", Path: filepath.Join(root.Name(), path), Err: err}
}
defer f.Close()
return f.Stat()
} | go | func LstatRelative(path string, root *os.File) (os.FileInfo, error) {
f, err := openRelativeInternal(
path,
root,
FILE_READ_ATTRIBUTES,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE|syscall.FILE_SHARE_DELETE,
FILE_OPEN,
FILE_OPEN_REPARSE_POINT)
if err != nil {
return nil, &os.PathError{Op: "stat", Path: filepath.Join(root.Name(), path), Err: err}
}
defer f.Close()
return f.Stat()
} | [
"func",
"LstatRelative",
"(",
"path",
"string",
",",
"root",
"*",
"os",
".",
"File",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"openRelativeInternal",
"(",
"path",
",",
"root",
",",
"FILE_READ_ATTRIBUTES",
",",
"syscall",
".",
"FILE_SHARE_READ",
"|",
"syscall",
".",
"FILE_SHARE_WRITE",
"|",
"syscall",
".",
"FILE_SHARE_DELETE",
",",
"FILE_OPEN",
",",
"FILE_OPEN_REPARSE_POINT",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"&",
"os",
".",
"PathError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Path",
":",
"filepath",
".",
"Join",
"(",
"root",
".",
"Name",
"(",
")",
",",
"path",
")",
",",
"Err",
":",
"err",
"}",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"return",
"f",
".",
"Stat",
"(",
")",
"\n",
"}"
] | // LstatRelative performs a stat operation on a file relative to a root, failing
// if any intermediate path components are reparse points. | [
"LstatRelative",
"performs",
"a",
"stat",
"operation",
"on",
"a",
"file",
"relative",
"to",
"a",
"root",
"failing",
"if",
"any",
"intermediate",
"path",
"components",
"are",
"reparse",
"points",
"."
] | 5a7443890943600c562e1f2390ab3fef8c56a45f | https://github.com/Microsoft/hcsshim/blob/5a7443890943600c562e1f2390ab3fef8c56a45f/internal/safefile/safeopen.go#L400-L413 | train |
libopenstorage/openstorage | api/server/sdk/identity.go | Capabilities | func (s *IdentityServer) Capabilities(
ctx context.Context,
req *api.SdkIdentityCapabilitiesRequest,
) (*api.SdkIdentityCapabilitiesResponse, error) {
capCluster := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_CLUSTER,
},
},
}
capCloudBackup := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_CLOUD_BACKUP,
},
},
}
capCredentials := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_CREDENTIALS,
},
},
}
capNode := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_NODE,
},
},
}
capObjectStorage := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_OBJECT_STORAGE,
},
},
}
capSchedulePolicy := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_SCHEDULE_POLICY,
},
},
}
capVolume := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_VOLUME,
},
},
}
capAlerts := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_ALERTS,
},
},
}
capMountAttach := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_MOUNT_ATTACH,
},
},
}
capRole := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_ROLE,
},
},
}
capClusterPair := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_CLUSTER_PAIR,
},
},
}
capMigrate := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_MIGRATE,
},
},
}
capStoragePolicy := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_STORAGE_POLICY,
},
},
}
return &api.SdkIdentityCapabilitiesResponse{
Capabilities: []*api.SdkServiceCapability{
capCluster,
capCloudBackup,
capCredentials,
capNode,
capObjectStorage,
capSchedulePolicy,
capVolume,
capAlerts,
capMountAttach,
capRole,
capClusterPair,
capMigrate,
capStoragePolicy,
},
}, nil
} | go | func (s *IdentityServer) Capabilities(
ctx context.Context,
req *api.SdkIdentityCapabilitiesRequest,
) (*api.SdkIdentityCapabilitiesResponse, error) {
capCluster := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_CLUSTER,
},
},
}
capCloudBackup := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_CLOUD_BACKUP,
},
},
}
capCredentials := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_CREDENTIALS,
},
},
}
capNode := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_NODE,
},
},
}
capObjectStorage := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_OBJECT_STORAGE,
},
},
}
capSchedulePolicy := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_SCHEDULE_POLICY,
},
},
}
capVolume := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_VOLUME,
},
},
}
capAlerts := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_ALERTS,
},
},
}
capMountAttach := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_MOUNT_ATTACH,
},
},
}
capRole := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_ROLE,
},
},
}
capClusterPair := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_CLUSTER_PAIR,
},
},
}
capMigrate := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_MIGRATE,
},
},
}
capStoragePolicy := &api.SdkServiceCapability{
Type: &api.SdkServiceCapability_Service{
Service: &api.SdkServiceCapability_OpenStorageService{
Type: api.SdkServiceCapability_OpenStorageService_STORAGE_POLICY,
},
},
}
return &api.SdkIdentityCapabilitiesResponse{
Capabilities: []*api.SdkServiceCapability{
capCluster,
capCloudBackup,
capCredentials,
capNode,
capObjectStorage,
capSchedulePolicy,
capVolume,
capAlerts,
capMountAttach,
capRole,
capClusterPair,
capMigrate,
capStoragePolicy,
},
}, nil
} | [
"func",
"(",
"s",
"*",
"IdentityServer",
")",
"Capabilities",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkIdentityCapabilitiesRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkIdentityCapabilitiesResponse",
",",
"error",
")",
"{",
"capCluster",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_CLUSTER",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capCloudBackup",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_CLOUD_BACKUP",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capCredentials",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_CREDENTIALS",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capNode",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_NODE",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capObjectStorage",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_OBJECT_STORAGE",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capSchedulePolicy",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_SCHEDULE_POLICY",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capVolume",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_VOLUME",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capAlerts",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_ALERTS",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capMountAttach",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_MOUNT_ATTACH",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capRole",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_ROLE",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capClusterPair",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_CLUSTER_PAIR",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capMigrate",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_MIGRATE",
",",
"}",
",",
"}",
",",
"}",
"\n",
"capStoragePolicy",
":=",
"&",
"api",
".",
"SdkServiceCapability",
"{",
"Type",
":",
"&",
"api",
".",
"SdkServiceCapability_Service",
"{",
"Service",
":",
"&",
"api",
".",
"SdkServiceCapability_OpenStorageService",
"{",
"Type",
":",
"api",
".",
"SdkServiceCapability_OpenStorageService_STORAGE_POLICY",
",",
"}",
",",
"}",
",",
"}",
"\n",
"return",
"&",
"api",
".",
"SdkIdentityCapabilitiesResponse",
"{",
"Capabilities",
":",
"[",
"]",
"*",
"api",
".",
"SdkServiceCapability",
"{",
"capCluster",
",",
"capCloudBackup",
",",
"capCredentials",
",",
"capNode",
",",
"capObjectStorage",
",",
"capSchedulePolicy",
",",
"capVolume",
",",
"capAlerts",
",",
"capMountAttach",
",",
"capRole",
",",
"capClusterPair",
",",
"capMigrate",
",",
"capStoragePolicy",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Capabilities returns the capabilities of the SDK server | [
"Capabilities",
"returns",
"the",
"capabilities",
"of",
"the",
"SDK",
"server"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/identity.go#L39-L152 | train |
libopenstorage/openstorage | api/server/sdk/identity.go | Version | func (s *IdentityServer) Version(
ctx context.Context,
req *api.SdkIdentityVersionRequest,
) (*api.SdkIdentityVersionResponse, error) {
var (
version *api.StorageVersion
err error
)
if s.driver(ctx) == nil {
version = &api.StorageVersion{
Driver: "no driver running",
}
} else {
version, err = s.driver(ctx).Version()
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to get version information: %v", err,
)
}
}
sdkVersion := &api.SdkVersion{
Major: int32(api.SdkVersion_Major),
Minor: int32(api.SdkVersion_Minor),
Patch: int32(api.SdkVersion_Patch),
Version: fmt.Sprintf("%d.%d.%d",
api.SdkVersion_Major,
api.SdkVersion_Minor,
api.SdkVersion_Patch,
),
}
return &api.SdkIdentityVersionResponse{
SdkVersion: sdkVersion,
Version: version,
}, nil
} | go | func (s *IdentityServer) Version(
ctx context.Context,
req *api.SdkIdentityVersionRequest,
) (*api.SdkIdentityVersionResponse, error) {
var (
version *api.StorageVersion
err error
)
if s.driver(ctx) == nil {
version = &api.StorageVersion{
Driver: "no driver running",
}
} else {
version, err = s.driver(ctx).Version()
if err != nil {
return nil, status.Errorf(
codes.Internal,
"Failed to get version information: %v", err,
)
}
}
sdkVersion := &api.SdkVersion{
Major: int32(api.SdkVersion_Major),
Minor: int32(api.SdkVersion_Minor),
Patch: int32(api.SdkVersion_Patch),
Version: fmt.Sprintf("%d.%d.%d",
api.SdkVersion_Major,
api.SdkVersion_Minor,
api.SdkVersion_Patch,
),
}
return &api.SdkIdentityVersionResponse{
SdkVersion: sdkVersion,
Version: version,
}, nil
} | [
"func",
"(",
"s",
"*",
"IdentityServer",
")",
"Version",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkIdentityVersionRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkIdentityVersionResponse",
",",
"error",
")",
"{",
"var",
"(",
"version",
"*",
"api",
".",
"StorageVersion",
"\n",
"err",
"error",
"\n",
")",
"\n",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"version",
"=",
"&",
"api",
".",
"StorageVersion",
"{",
"Driver",
":",
"\"",
"\"",
",",
"}",
"\n",
"}",
"else",
"{",
"version",
",",
"err",
"=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"Version",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
",",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"sdkVersion",
":=",
"&",
"api",
".",
"SdkVersion",
"{",
"Major",
":",
"int32",
"(",
"api",
".",
"SdkVersion_Major",
")",
",",
"Minor",
":",
"int32",
"(",
"api",
".",
"SdkVersion_Minor",
")",
",",
"Patch",
":",
"int32",
"(",
"api",
".",
"SdkVersion_Patch",
")",
",",
"Version",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"api",
".",
"SdkVersion_Major",
",",
"api",
".",
"SdkVersion_Minor",
",",
"api",
".",
"SdkVersion_Patch",
",",
")",
",",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkIdentityVersionResponse",
"{",
"SdkVersion",
":",
"sdkVersion",
",",
"Version",
":",
"version",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Version returns version of the storage system | [
"Version",
"returns",
"version",
"of",
"the",
"storage",
"system"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/identity.go#L155-L193 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | Create | func (s *CloudBackupServer) Create(
ctx context.Context,
req *api.SdkCloudBackupCreateRequest,
) (*api.SdkCloudBackupCreateResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply a volume id")
}
if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
}
// Check ownership
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), req.GetVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
if len(req.GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, credId); err != nil {
return nil, err
}
}
r, err := s.driver(ctx).CloudBackupCreate(&api.CloudBackupCreateRequest{
VolumeID: req.GetVolumeId(),
CredentialUUID: credId,
Full: req.GetFull(),
Name: req.GetTaskId(),
Labels: req.GetLabels(),
})
if err != nil {
if err == volume.ErrInvalidName {
return nil, status.Errorf(codes.AlreadyExists, "Backup with this name already exists: %v", err)
}
return nil, status.Errorf(codes.Internal, "Failed to create backup: %v", err)
}
return &api.SdkCloudBackupCreateResponse{
TaskId: r.Name,
}, nil
} | go | func (s *CloudBackupServer) Create(
ctx context.Context,
req *api.SdkCloudBackupCreateRequest,
) (*api.SdkCloudBackupCreateResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply a volume id")
}
if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
}
// Check ownership
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), req.GetVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
if len(req.GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, credId); err != nil {
return nil, err
}
}
r, err := s.driver(ctx).CloudBackupCreate(&api.CloudBackupCreateRequest{
VolumeID: req.GetVolumeId(),
CredentialUUID: credId,
Full: req.GetFull(),
Name: req.GetTaskId(),
Labels: req.GetLabels(),
})
if err != nil {
if err == volume.ErrInvalidName {
return nil, status.Errorf(codes.AlreadyExists, "Backup with this name already exists: %v", err)
}
return nil, status.Errorf(codes.Internal, "Failed to create backup: %v", err)
}
return &api.SdkCloudBackupCreateResponse{
TaskId: r.Name,
}, nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupCreateRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupCreateResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"credId",
":=",
"req",
".",
"GetCredentialId",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"if",
"len",
"(",
"req",
".",
"GetVolumeId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"req",
".",
"GetCredentialId",
"(",
")",
")",
"==",
"0",
"{",
"credId",
",",
"err",
"=",
"s",
".",
"defaultCloudBackupCreds",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Check ownership",
"if",
"err",
":=",
"checkAccessFromDriverForVolumeId",
"(",
"ctx",
",",
"s",
".",
"driver",
"(",
"ctx",
")",
",",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"api",
".",
"Ownership_Read",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"req",
".",
"GetCredentialId",
"(",
")",
")",
"!=",
"0",
"{",
"if",
"err",
":=",
"s",
".",
"checkAccessToCredential",
"(",
"ctx",
",",
"credId",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"r",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupCreate",
"(",
"&",
"api",
".",
"CloudBackupCreateRequest",
"{",
"VolumeID",
":",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"CredentialUUID",
":",
"credId",
",",
"Full",
":",
"req",
".",
"GetFull",
"(",
")",
",",
"Name",
":",
"req",
".",
"GetTaskId",
"(",
")",
",",
"Labels",
":",
"req",
".",
"GetLabels",
"(",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"volume",
".",
"ErrInvalidName",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"AlreadyExists",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkCloudBackupCreateResponse",
"{",
"TaskId",
":",
"r",
".",
"Name",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Create creates a backup for a volume | [
"Create",
"creates",
"a",
"backup",
"for",
"a",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L38-L86 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | Restore | func (s *CloudBackupServer) Restore(
ctx context.Context,
req *api.SdkCloudBackupRestoreRequest,
) (*api.SdkCloudBackupRestoreResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetBackupId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide backup id")
} else if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
}
if len(req.GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, req.GetCredentialId()); err != nil {
return nil, err
}
}
r, err := s.driver(ctx).CloudBackupRestore(&api.CloudBackupRestoreRequest{
ID: req.GetBackupId(),
RestoreVolumeName: req.GetRestoreVolumeName(),
CredentialUUID: credId,
NodeID: req.GetNodeId(),
Name: req.GetTaskId(),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to restore backup: %v", err)
}
return &api.SdkCloudBackupRestoreResponse{
RestoreVolumeId: r.RestoreVolumeID,
TaskId: r.Name,
}, nil
} | go | func (s *CloudBackupServer) Restore(
ctx context.Context,
req *api.SdkCloudBackupRestoreRequest,
) (*api.SdkCloudBackupRestoreResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetBackupId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide backup id")
} else if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
}
if len(req.GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, req.GetCredentialId()); err != nil {
return nil, err
}
}
r, err := s.driver(ctx).CloudBackupRestore(&api.CloudBackupRestoreRequest{
ID: req.GetBackupId(),
RestoreVolumeName: req.GetRestoreVolumeName(),
CredentialUUID: credId,
NodeID: req.GetNodeId(),
Name: req.GetTaskId(),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to restore backup: %v", err)
}
return &api.SdkCloudBackupRestoreResponse{
RestoreVolumeId: r.RestoreVolumeID,
TaskId: r.Name,
}, nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"Restore",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupRestoreRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupRestoreResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"credId",
":=",
"req",
".",
"GetCredentialId",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"if",
"len",
"(",
"req",
".",
"GetBackupId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"req",
".",
"GetCredentialId",
"(",
")",
")",
"==",
"0",
"{",
"credId",
",",
"err",
"=",
"s",
".",
"defaultCloudBackupCreds",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"req",
".",
"GetCredentialId",
"(",
")",
")",
"!=",
"0",
"{",
"if",
"err",
":=",
"s",
".",
"checkAccessToCredential",
"(",
"ctx",
",",
"req",
".",
"GetCredentialId",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"r",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupRestore",
"(",
"&",
"api",
".",
"CloudBackupRestoreRequest",
"{",
"ID",
":",
"req",
".",
"GetBackupId",
"(",
")",
",",
"RestoreVolumeName",
":",
"req",
".",
"GetRestoreVolumeName",
"(",
")",
",",
"CredentialUUID",
":",
"credId",
",",
"NodeID",
":",
"req",
".",
"GetNodeId",
"(",
")",
",",
"Name",
":",
"req",
".",
"GetTaskId",
"(",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkCloudBackupRestoreResponse",
"{",
"RestoreVolumeId",
":",
"r",
".",
"RestoreVolumeID",
",",
"TaskId",
":",
"r",
".",
"Name",
",",
"}",
",",
"nil",
"\n\n",
"}"
] | // Restore a backup | [
"Restore",
"a",
"backup"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L89-L129 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | Delete | func (s *CloudBackupServer) Delete(
ctx context.Context,
req *api.SdkCloudBackupDeleteRequest,
) (*api.SdkCloudBackupDeleteResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetBackupId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide backup id")
} else if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
}
if len(req.GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, req.GetCredentialId()); err != nil {
return nil, err
}
}
if err := s.driver(ctx).CloudBackupDelete(&api.CloudBackupDeleteRequest{
ID: req.GetBackupId(),
CredentialUUID: credId,
Force: req.GetForce(),
}); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to delete backup: %v", err)
}
return &api.SdkCloudBackupDeleteResponse{}, nil
} | go | func (s *CloudBackupServer) Delete(
ctx context.Context,
req *api.SdkCloudBackupDeleteRequest,
) (*api.SdkCloudBackupDeleteResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetBackupId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide backup id")
} else if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
}
if len(req.GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, req.GetCredentialId()); err != nil {
return nil, err
}
}
if err := s.driver(ctx).CloudBackupDelete(&api.CloudBackupDeleteRequest{
ID: req.GetBackupId(),
CredentialUUID: credId,
Force: req.GetForce(),
}); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to delete backup: %v", err)
}
return &api.SdkCloudBackupDeleteResponse{}, nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupDeleteRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupDeleteResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"credId",
":=",
"req",
".",
"GetCredentialId",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"if",
"len",
"(",
"req",
".",
"GetBackupId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"req",
".",
"GetCredentialId",
"(",
")",
")",
"==",
"0",
"{",
"credId",
",",
"err",
"=",
"s",
".",
"defaultCloudBackupCreds",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"req",
".",
"GetCredentialId",
"(",
")",
")",
"!=",
"0",
"{",
"if",
"err",
":=",
"s",
".",
"checkAccessToCredential",
"(",
"ctx",
",",
"req",
".",
"GetCredentialId",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupDelete",
"(",
"&",
"api",
".",
"CloudBackupDeleteRequest",
"{",
"ID",
":",
"req",
".",
"GetBackupId",
"(",
")",
",",
"CredentialUUID",
":",
"credId",
",",
"Force",
":",
"req",
".",
"GetForce",
"(",
")",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkCloudBackupDeleteResponse",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // Delete deletes a backup | [
"Delete",
"deletes",
"a",
"backup"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L132-L164 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | DeleteAll | func (s *CloudBackupServer) DeleteAll(
ctx context.Context,
req *api.SdkCloudBackupDeleteAllRequest,
) (*api.SdkCloudBackupDeleteAllResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetSrcVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide source volume id")
} else if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
}
if len(req.GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, req.GetCredentialId()); err != nil {
return nil, err
}
}
if err := s.driver(ctx).CloudBackupDeleteAll(&api.CloudBackupDeleteAllRequest{
CloudBackupGenericRequest: api.CloudBackupGenericRequest{
SrcVolumeID: req.GetSrcVolumeId(),
CredentialUUID: credId,
},
}); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to delete backup: %v", err)
}
return &api.SdkCloudBackupDeleteAllResponse{}, nil
} | go | func (s *CloudBackupServer) DeleteAll(
ctx context.Context,
req *api.SdkCloudBackupDeleteAllRequest,
) (*api.SdkCloudBackupDeleteAllResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetSrcVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide source volume id")
} else if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
}
if len(req.GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, req.GetCredentialId()); err != nil {
return nil, err
}
}
if err := s.driver(ctx).CloudBackupDeleteAll(&api.CloudBackupDeleteAllRequest{
CloudBackupGenericRequest: api.CloudBackupGenericRequest{
SrcVolumeID: req.GetSrcVolumeId(),
CredentialUUID: credId,
},
}); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to delete backup: %v", err)
}
return &api.SdkCloudBackupDeleteAllResponse{}, nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"DeleteAll",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupDeleteAllRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupDeleteAllResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"credId",
":=",
"req",
".",
"GetCredentialId",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"if",
"len",
"(",
"req",
".",
"GetSrcVolumeId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"req",
".",
"GetCredentialId",
"(",
")",
")",
"==",
"0",
"{",
"credId",
",",
"err",
"=",
"s",
".",
"defaultCloudBackupCreds",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"req",
".",
"GetCredentialId",
"(",
")",
")",
"!=",
"0",
"{",
"if",
"err",
":=",
"s",
".",
"checkAccessToCredential",
"(",
"ctx",
",",
"req",
".",
"GetCredentialId",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupDeleteAll",
"(",
"&",
"api",
".",
"CloudBackupDeleteAllRequest",
"{",
"CloudBackupGenericRequest",
":",
"api",
".",
"CloudBackupGenericRequest",
"{",
"SrcVolumeID",
":",
"req",
".",
"GetSrcVolumeId",
"(",
")",
",",
"CredentialUUID",
":",
"credId",
",",
"}",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkCloudBackupDeleteAllResponse",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // DeleteAll deletes all backups for a certain volume | [
"DeleteAll",
"deletes",
"all",
"backups",
"for",
"a",
"certain",
"volume"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L167-L199 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | EnumerateWithFilters | func (s *CloudBackupServer) EnumerateWithFilters(
ctx context.Context,
req *api.SdkCloudBackupEnumerateWithFiltersRequest,
) (*api.SdkCloudBackupEnumerateWithFiltersResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
} else {
if err := s.checkAccessToCredential(ctx, req.GetCredentialId()); err != nil {
return nil, err
}
}
r, err := s.driver(ctx).CloudBackupEnumerate(&api.CloudBackupEnumerateRequest{
CloudBackupGenericRequest: api.CloudBackupGenericRequest{
SrcVolumeID: req.GetSrcVolumeId(),
ClusterID: req.GetClusterId(),
CredentialUUID: credId,
All: req.GetAll(),
},
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to enumerate backups: %v", err)
}
return r.ToSdkCloudBackupEnumerateWithFiltersResponse(), nil
} | go | func (s *CloudBackupServer) EnumerateWithFilters(
ctx context.Context,
req *api.SdkCloudBackupEnumerateWithFiltersRequest,
) (*api.SdkCloudBackupEnumerateWithFiltersResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCredentialId()
var err error
if len(req.GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
} else {
if err := s.checkAccessToCredential(ctx, req.GetCredentialId()); err != nil {
return nil, err
}
}
r, err := s.driver(ctx).CloudBackupEnumerate(&api.CloudBackupEnumerateRequest{
CloudBackupGenericRequest: api.CloudBackupGenericRequest{
SrcVolumeID: req.GetSrcVolumeId(),
ClusterID: req.GetClusterId(),
CredentialUUID: credId,
All: req.GetAll(),
},
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to enumerate backups: %v", err)
}
return r.ToSdkCloudBackupEnumerateWithFiltersResponse(), nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"EnumerateWithFilters",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupEnumerateWithFiltersRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupEnumerateWithFiltersResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"credId",
":=",
"req",
".",
"GetCredentialId",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"if",
"len",
"(",
"req",
".",
"GetCredentialId",
"(",
")",
")",
"==",
"0",
"{",
"credId",
",",
"err",
"=",
"s",
".",
"defaultCloudBackupCreds",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"s",
".",
"checkAccessToCredential",
"(",
"ctx",
",",
"req",
".",
"GetCredentialId",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"r",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupEnumerate",
"(",
"&",
"api",
".",
"CloudBackupEnumerateRequest",
"{",
"CloudBackupGenericRequest",
":",
"api",
".",
"CloudBackupGenericRequest",
"{",
"SrcVolumeID",
":",
"req",
".",
"GetSrcVolumeId",
"(",
")",
",",
"ClusterID",
":",
"req",
".",
"GetClusterId",
"(",
")",
",",
"CredentialUUID",
":",
"credId",
",",
"All",
":",
"req",
".",
"GetAll",
"(",
")",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"r",
".",
"ToSdkCloudBackupEnumerateWithFiltersResponse",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Enumerate returns information about the backups | [
"Enumerate",
"returns",
"information",
"about",
"the",
"backups"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L202-L235 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | Status | func (s *CloudBackupServer) Status(
ctx context.Context,
req *api.SdkCloudBackupStatusRequest,
) (*api.SdkCloudBackupStatusResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
// Check ownership
if req.GetVolumeId() != "" {
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), req.GetVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
}
r, err := s.driver(ctx).CloudBackupStatus(&api.CloudBackupStatusRequest{
SrcVolumeID: req.GetVolumeId(),
Local: req.GetLocal(),
ID: req.GetTaskId(),
})
if err != nil {
if err == volume.ErrInvalidName {
return nil, status.Errorf(codes.Unavailable, "No Backup status found")
}
return nil, status.Errorf(codes.Internal, "Failed to get status of backup: %v", err)
}
// Get volume id from task id
// remove the volumes that dont belong to caller
for key, sts := range r.Statuses {
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), sts.SrcVolumeID, api.Ownership_Read); err != nil {
delete(r.Statuses, key)
}
}
return r.ToSdkCloudBackupStatusResponse(), nil
} | go | func (s *CloudBackupServer) Status(
ctx context.Context,
req *api.SdkCloudBackupStatusRequest,
) (*api.SdkCloudBackupStatusResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
// Check ownership
if req.GetVolumeId() != "" {
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), req.GetVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
}
r, err := s.driver(ctx).CloudBackupStatus(&api.CloudBackupStatusRequest{
SrcVolumeID: req.GetVolumeId(),
Local: req.GetLocal(),
ID: req.GetTaskId(),
})
if err != nil {
if err == volume.ErrInvalidName {
return nil, status.Errorf(codes.Unavailable, "No Backup status found")
}
return nil, status.Errorf(codes.Internal, "Failed to get status of backup: %v", err)
}
// Get volume id from task id
// remove the volumes that dont belong to caller
for key, sts := range r.Statuses {
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), sts.SrcVolumeID, api.Ownership_Read); err != nil {
delete(r.Statuses, key)
}
}
return r.ToSdkCloudBackupStatusResponse(), nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"Status",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupStatusRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupStatusResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check ownership",
"if",
"req",
".",
"GetVolumeId",
"(",
")",
"!=",
"\"",
"\"",
"{",
"if",
"err",
":=",
"checkAccessFromDriverForVolumeId",
"(",
"ctx",
",",
"s",
".",
"driver",
"(",
"ctx",
")",
",",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"api",
".",
"Ownership_Read",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"r",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupStatus",
"(",
"&",
"api",
".",
"CloudBackupStatusRequest",
"{",
"SrcVolumeID",
":",
"req",
".",
"GetVolumeId",
"(",
")",
",",
"Local",
":",
"req",
".",
"GetLocal",
"(",
")",
",",
"ID",
":",
"req",
".",
"GetTaskId",
"(",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"volume",
".",
"ErrInvalidName",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// Get volume id from task id",
"// remove the volumes that dont belong to caller",
"for",
"key",
",",
"sts",
":=",
"range",
"r",
".",
"Statuses",
"{",
"if",
"err",
":=",
"checkAccessFromDriverForVolumeId",
"(",
"ctx",
",",
"s",
".",
"driver",
"(",
"ctx",
")",
",",
"sts",
".",
"SrcVolumeID",
",",
"api",
".",
"Ownership_Read",
")",
";",
"err",
"!=",
"nil",
"{",
"delete",
"(",
"r",
".",
"Statuses",
",",
"key",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"r",
".",
"ToSdkCloudBackupStatusResponse",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Status provides status on a backup | [
"Status",
"provides",
"status",
"on",
"a",
"backup"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L238-L272 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | History | func (s *CloudBackupServer) History(
ctx context.Context,
req *api.SdkCloudBackupHistoryRequest,
) (*api.SdkCloudBackupHistoryResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetSrcVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide volume id")
}
// Check ownership
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), req.GetSrcVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
r, err := s.driver(ctx).CloudBackupHistory(&api.CloudBackupHistoryRequest{
SrcVolumeID: req.GetSrcVolumeId(),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to get history: %v", err)
}
return r.ToSdkCloudBackupHistoryResponse(), nil
} | go | func (s *CloudBackupServer) History(
ctx context.Context,
req *api.SdkCloudBackupHistoryRequest,
) (*api.SdkCloudBackupHistoryResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
if len(req.GetSrcVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide volume id")
}
// Check ownership
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), req.GetSrcVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
r, err := s.driver(ctx).CloudBackupHistory(&api.CloudBackupHistoryRequest{
SrcVolumeID: req.GetSrcVolumeId(),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to get history: %v", err)
}
return r.ToSdkCloudBackupHistoryResponse(), nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"History",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupHistoryRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupHistoryResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"req",
".",
"GetSrcVolumeId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check ownership",
"if",
"err",
":=",
"checkAccessFromDriverForVolumeId",
"(",
"ctx",
",",
"s",
".",
"driver",
"(",
"ctx",
")",
",",
"req",
".",
"GetSrcVolumeId",
"(",
")",
",",
"api",
".",
"Ownership_Read",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"r",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupHistory",
"(",
"&",
"api",
".",
"CloudBackupHistoryRequest",
"{",
"SrcVolumeID",
":",
"req",
".",
"GetSrcVolumeId",
"(",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"r",
".",
"ToSdkCloudBackupHistoryResponse",
"(",
")",
",",
"nil",
"\n",
"}"
] | // History returns ?? | [
"History",
"returns",
"??"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L313-L338 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | StateChange | func (s *CloudBackupServer) StateChange(
ctx context.Context,
req *api.SdkCloudBackupStateChangeRequest,
) (*api.SdkCloudBackupStateChangeResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
// TODO
// XXX Get vid from tid
if len(req.GetTaskId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide taskid")
} else if req.GetRequestedState() == api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStateUnknown {
return nil, status.Error(codes.InvalidArgument, "Must provide requested state")
}
var rs string
switch req.GetRequestedState() {
// Not supported yet
/*
case api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStatePause:
rs = api.CloudBackupRequestedStatePause
case api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStateResume:
rs = api.CloudBackupRequestedStateResume
*/
case api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStateStop:
rs = api.CloudBackupRequestedStateStop
default:
return nil, status.Errorf(codes.InvalidArgument, "Invalid requested state: %v", req.GetRequestedState())
}
// Get Status to get the volId
r, err := s.driver(ctx).CloudBackupStatus(&api.CloudBackupStatusRequest{
ID: req.GetTaskId(),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to get status of backup: %v", err)
}
// Get volume id from task id
// remove the volumes that dont belong to caller
for _, sts := range r.Statuses {
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), sts.SrcVolumeID, api.Ownership_Write); err != nil {
return nil, err
}
}
err = s.driver(ctx).CloudBackupStateChange(&api.CloudBackupStateChangeRequest{
Name: req.GetTaskId(),
RequestedState: rs,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to change state: %v", err)
}
return &api.SdkCloudBackupStateChangeResponse{}, nil
} | go | func (s *CloudBackupServer) StateChange(
ctx context.Context,
req *api.SdkCloudBackupStateChangeRequest,
) (*api.SdkCloudBackupStateChangeResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
// TODO
// XXX Get vid from tid
if len(req.GetTaskId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide taskid")
} else if req.GetRequestedState() == api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStateUnknown {
return nil, status.Error(codes.InvalidArgument, "Must provide requested state")
}
var rs string
switch req.GetRequestedState() {
// Not supported yet
/*
case api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStatePause:
rs = api.CloudBackupRequestedStatePause
case api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStateResume:
rs = api.CloudBackupRequestedStateResume
*/
case api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStateStop:
rs = api.CloudBackupRequestedStateStop
default:
return nil, status.Errorf(codes.InvalidArgument, "Invalid requested state: %v", req.GetRequestedState())
}
// Get Status to get the volId
r, err := s.driver(ctx).CloudBackupStatus(&api.CloudBackupStatusRequest{
ID: req.GetTaskId(),
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to get status of backup: %v", err)
}
// Get volume id from task id
// remove the volumes that dont belong to caller
for _, sts := range r.Statuses {
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), sts.SrcVolumeID, api.Ownership_Write); err != nil {
return nil, err
}
}
err = s.driver(ctx).CloudBackupStateChange(&api.CloudBackupStateChangeRequest{
Name: req.GetTaskId(),
RequestedState: rs,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to change state: %v", err)
}
return &api.SdkCloudBackupStateChangeResponse{}, nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"StateChange",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupStateChangeRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupStateChangeResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// TODO",
"// XXX Get vid from tid",
"if",
"len",
"(",
"req",
".",
"GetTaskId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"req",
".",
"GetRequestedState",
"(",
")",
"==",
"api",
".",
"SdkCloudBackupRequestedState_SdkCloudBackupRequestedStateUnknown",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"rs",
"string",
"\n",
"switch",
"req",
".",
"GetRequestedState",
"(",
")",
"{",
"// Not supported yet",
"/*\n\t\tcase api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStatePause:\n\t\t\trs = api.CloudBackupRequestedStatePause\n\t\tcase api.SdkCloudBackupRequestedState_SdkCloudBackupRequestedStateResume:\n\t\t\trs = api.CloudBackupRequestedStateResume\n\t*/",
"case",
"api",
".",
"SdkCloudBackupRequestedState_SdkCloudBackupRequestedStateStop",
":",
"rs",
"=",
"api",
".",
"CloudBackupRequestedStateStop",
"\n",
"default",
":",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
",",
"req",
".",
"GetRequestedState",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Get Status to get the volId",
"r",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupStatus",
"(",
"&",
"api",
".",
"CloudBackupStatusRequest",
"{",
"ID",
":",
"req",
".",
"GetTaskId",
"(",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// Get volume id from task id",
"// remove the volumes that dont belong to caller",
"for",
"_",
",",
"sts",
":=",
"range",
"r",
".",
"Statuses",
"{",
"if",
"err",
":=",
"checkAccessFromDriverForVolumeId",
"(",
"ctx",
",",
"s",
".",
"driver",
"(",
"ctx",
")",
",",
"sts",
".",
"SrcVolumeID",
",",
"api",
".",
"Ownership_Write",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"err",
"=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupStateChange",
"(",
"&",
"api",
".",
"CloudBackupStateChangeRequest",
"{",
"Name",
":",
"req",
".",
"GetTaskId",
"(",
")",
",",
"RequestedState",
":",
"rs",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkCloudBackupStateChangeResponse",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // StateChange pauses and resumes backups | [
"StateChange",
"pauses",
"and",
"resumes",
"backups"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L341-L396 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | SchedCreate | func (s *CloudBackupServer) SchedCreate(
ctx context.Context,
req *api.SdkCloudBackupSchedCreateRequest,
) (*api.SdkCloudBackupSchedCreateResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCloudSchedInfo().GetCredentialId()
var err error
if req.GetCloudSchedInfo() == nil {
return nil, status.Error(codes.InvalidArgument, "BackupSchedule object cannot be nil")
} else if len(req.GetCloudSchedInfo().GetSrcVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply source volume id")
} else if len(req.GetCloudSchedInfo().GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
} else if req.GetCloudSchedInfo().GetSchedules() == nil ||
len(req.GetCloudSchedInfo().GetSchedules()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply Schedule")
}
// Check ownership
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), req.GetCloudSchedInfo().GetSrcVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
if len(req.GetCloudSchedInfo().GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, req.GetCloudSchedInfo().GetCredentialId()); err != nil {
return nil, err
}
}
sched, err := sdkSchedToRetainInternalSpecYamlByte(req.GetCloudSchedInfo().GetSchedules())
if err != nil {
return nil, err
}
bkpRequest := api.CloudBackupSchedCreateRequest{}
bkpRequest.SrcVolumeID = req.GetCloudSchedInfo().GetSrcVolumeId()
bkpRequest.CredentialUUID = credId
bkpRequest.Schedule = string(sched)
bkpRequest.MaxBackups = uint(req.GetCloudSchedInfo().GetMaxBackups())
bkpRequest.RetentionDays = req.GetCloudSchedInfo().GetRetentionDays()
bkpRequest.Full = req.GetCloudSchedInfo().GetFull()
// Create the backup
schedResp, err := s.driver(ctx).CloudBackupSchedCreate(&bkpRequest)
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to create backup: %v", err)
}
return &api.SdkCloudBackupSchedCreateResponse{
BackupScheduleId: schedResp.UUID,
}, nil
} | go | func (s *CloudBackupServer) SchedCreate(
ctx context.Context,
req *api.SdkCloudBackupSchedCreateRequest,
) (*api.SdkCloudBackupSchedCreateResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
credId := req.GetCloudSchedInfo().GetCredentialId()
var err error
if req.GetCloudSchedInfo() == nil {
return nil, status.Error(codes.InvalidArgument, "BackupSchedule object cannot be nil")
} else if len(req.GetCloudSchedInfo().GetSrcVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply source volume id")
} else if len(req.GetCloudSchedInfo().GetCredentialId()) == 0 {
credId, err = s.defaultCloudBackupCreds(ctx)
if err != nil {
return nil, err
}
} else if req.GetCloudSchedInfo().GetSchedules() == nil ||
len(req.GetCloudSchedInfo().GetSchedules()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply Schedule")
}
// Check ownership
if err := checkAccessFromDriverForVolumeId(ctx, s.driver(ctx), req.GetCloudSchedInfo().GetSrcVolumeId(), api.Ownership_Read); err != nil {
return nil, err
}
if len(req.GetCloudSchedInfo().GetCredentialId()) != 0 {
if err := s.checkAccessToCredential(ctx, req.GetCloudSchedInfo().GetCredentialId()); err != nil {
return nil, err
}
}
sched, err := sdkSchedToRetainInternalSpecYamlByte(req.GetCloudSchedInfo().GetSchedules())
if err != nil {
return nil, err
}
bkpRequest := api.CloudBackupSchedCreateRequest{}
bkpRequest.SrcVolumeID = req.GetCloudSchedInfo().GetSrcVolumeId()
bkpRequest.CredentialUUID = credId
bkpRequest.Schedule = string(sched)
bkpRequest.MaxBackups = uint(req.GetCloudSchedInfo().GetMaxBackups())
bkpRequest.RetentionDays = req.GetCloudSchedInfo().GetRetentionDays()
bkpRequest.Full = req.GetCloudSchedInfo().GetFull()
// Create the backup
schedResp, err := s.driver(ctx).CloudBackupSchedCreate(&bkpRequest)
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to create backup: %v", err)
}
return &api.SdkCloudBackupSchedCreateResponse{
BackupScheduleId: schedResp.UUID,
}, nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"SchedCreate",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupSchedCreateRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupSchedCreateResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"credId",
":=",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetCredentialId",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"if",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetSrcVolumeId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetCredentialId",
"(",
")",
")",
"==",
"0",
"{",
"credId",
",",
"err",
"=",
"s",
".",
"defaultCloudBackupCreds",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"if",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetSchedules",
"(",
")",
"==",
"nil",
"||",
"len",
"(",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetSchedules",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check ownership",
"if",
"err",
":=",
"checkAccessFromDriverForVolumeId",
"(",
"ctx",
",",
"s",
".",
"driver",
"(",
"ctx",
")",
",",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetSrcVolumeId",
"(",
")",
",",
"api",
".",
"Ownership_Read",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetCredentialId",
"(",
")",
")",
"!=",
"0",
"{",
"if",
"err",
":=",
"s",
".",
"checkAccessToCredential",
"(",
"ctx",
",",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetCredentialId",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"sched",
",",
"err",
":=",
"sdkSchedToRetainInternalSpecYamlByte",
"(",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetSchedules",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"bkpRequest",
":=",
"api",
".",
"CloudBackupSchedCreateRequest",
"{",
"}",
"\n",
"bkpRequest",
".",
"SrcVolumeID",
"=",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetSrcVolumeId",
"(",
")",
"\n",
"bkpRequest",
".",
"CredentialUUID",
"=",
"credId",
"\n",
"bkpRequest",
".",
"Schedule",
"=",
"string",
"(",
"sched",
")",
"\n",
"bkpRequest",
".",
"MaxBackups",
"=",
"uint",
"(",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetMaxBackups",
"(",
")",
")",
"\n",
"bkpRequest",
".",
"RetentionDays",
"=",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetRetentionDays",
"(",
")",
"\n",
"bkpRequest",
".",
"Full",
"=",
"req",
".",
"GetCloudSchedInfo",
"(",
")",
".",
"GetFull",
"(",
")",
"\n\n",
"// Create the backup",
"schedResp",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupSchedCreate",
"(",
"&",
"bkpRequest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkCloudBackupSchedCreateResponse",
"{",
"BackupScheduleId",
":",
"schedResp",
".",
"UUID",
",",
"}",
",",
"nil",
"\n\n",
"}"
] | // SchedCreate new schedule for cloud backup | [
"SchedCreate",
"new",
"schedule",
"for",
"cloud",
"backup"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L399-L456 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | SchedDelete | func (s *CloudBackupServer) SchedDelete(
ctx context.Context,
req *api.SdkCloudBackupSchedDeleteRequest,
) (*api.SdkCloudBackupSchedDeleteResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
// TODO
// XXX inspect from uuid and get volume id
if len(req.GetBackupScheduleId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide volumeId")
}
// Call cloud backup driver function to delete cloud schedule
if err := s.driver(ctx).CloudBackupSchedDelete(&api.CloudBackupSchedDeleteRequest{
UUID: req.GetBackupScheduleId(),
}); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to delete cloud backup schedule: %v", err)
}
return &api.SdkCloudBackupSchedDeleteResponse{}, nil
} | go | func (s *CloudBackupServer) SchedDelete(
ctx context.Context,
req *api.SdkCloudBackupSchedDeleteRequest,
) (*api.SdkCloudBackupSchedDeleteResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
// TODO
// XXX inspect from uuid and get volume id
if len(req.GetBackupScheduleId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must provide volumeId")
}
// Call cloud backup driver function to delete cloud schedule
if err := s.driver(ctx).CloudBackupSchedDelete(&api.CloudBackupSchedDeleteRequest{
UUID: req.GetBackupScheduleId(),
}); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to delete cloud backup schedule: %v", err)
}
return &api.SdkCloudBackupSchedDeleteResponse{}, nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"SchedDelete",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupSchedDeleteRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupSchedDeleteResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// TODO",
"// XXX inspect from uuid and get volume id",
"if",
"len",
"(",
"req",
".",
"GetBackupScheduleId",
"(",
")",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"InvalidArgument",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Call cloud backup driver function to delete cloud schedule",
"if",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupSchedDelete",
"(",
"&",
"api",
".",
"CloudBackupSchedDeleteRequest",
"{",
"UUID",
":",
"req",
".",
"GetBackupScheduleId",
"(",
")",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"api",
".",
"SdkCloudBackupSchedDeleteResponse",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // SchedDelete cloud backup schedule | [
"SchedDelete",
"cloud",
"backup",
"schedule"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L459-L482 | train |
libopenstorage/openstorage | api/server/sdk/cloud_backup.go | SchedEnumerate | func (s *CloudBackupServer) SchedEnumerate(
ctx context.Context,
req *api.SdkCloudBackupSchedEnumerateRequest,
) (*api.SdkCloudBackupSchedEnumerateResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
// Pass in ownership and show only valid ones
r, err := s.driver(ctx).CloudBackupSchedEnumerate()
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to enumerate backups: %v", err)
}
// since can't import sdk/utils to api because of cyclic import, converting
// api.CloudBackupScheduleInfo to api.SdkCloudBackupScheduleInfo
return ToSdkCloudBackupSchedEnumerateResponse(r), nil
} | go | func (s *CloudBackupServer) SchedEnumerate(
ctx context.Context,
req *api.SdkCloudBackupSchedEnumerateRequest,
) (*api.SdkCloudBackupSchedEnumerateResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
// Pass in ownership and show only valid ones
r, err := s.driver(ctx).CloudBackupSchedEnumerate()
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to enumerate backups: %v", err)
}
// since can't import sdk/utils to api because of cyclic import, converting
// api.CloudBackupScheduleInfo to api.SdkCloudBackupScheduleInfo
return ToSdkCloudBackupSchedEnumerateResponse(r), nil
} | [
"func",
"(",
"s",
"*",
"CloudBackupServer",
")",
"SchedEnumerate",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkCloudBackupSchedEnumerateRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkCloudBackupSchedEnumerateResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"driver",
"(",
"ctx",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Pass in ownership and show only valid ones",
"r",
",",
"err",
":=",
"s",
".",
"driver",
"(",
"ctx",
")",
".",
"CloudBackupSchedEnumerate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Errorf",
"(",
"codes",
".",
"Internal",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"// since can't import sdk/utils to api because of cyclic import, converting",
"// api.CloudBackupScheduleInfo to api.SdkCloudBackupScheduleInfo",
"return",
"ToSdkCloudBackupSchedEnumerateResponse",
"(",
"r",
")",
",",
"nil",
"\n",
"}"
] | // SchedEnumerate cloud backup schedule | [
"SchedEnumerate",
"cloud",
"backup",
"schedule"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cloud_backup.go#L485-L501 | train |
libopenstorage/openstorage | api/server/sdk/cluster.go | InspectCurrent | func (s *ClusterServer) InspectCurrent(
ctx context.Context,
req *api.SdkClusterInspectCurrentRequest,
) (*api.SdkClusterInspectCurrentResponse, error) {
if s.cluster() == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
c, err := s.cluster().Enumerate()
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
// Get cluster information
cluster := c.ToStorageCluster()
// Get cluster unique id
cluster.Id = s.cluster().Uuid()
return &api.SdkClusterInspectCurrentResponse{
Cluster: cluster,
}, nil
} | go | func (s *ClusterServer) InspectCurrent(
ctx context.Context,
req *api.SdkClusterInspectCurrentRequest,
) (*api.SdkClusterInspectCurrentResponse, error) {
if s.cluster() == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
c, err := s.cluster().Enumerate()
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
// Get cluster information
cluster := c.ToStorageCluster()
// Get cluster unique id
cluster.Id = s.cluster().Uuid()
return &api.SdkClusterInspectCurrentResponse{
Cluster: cluster,
}, nil
} | [
"func",
"(",
"s",
"*",
"ClusterServer",
")",
"InspectCurrent",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"api",
".",
"SdkClusterInspectCurrentRequest",
",",
")",
"(",
"*",
"api",
".",
"SdkClusterInspectCurrentResponse",
",",
"error",
")",
"{",
"if",
"s",
".",
"cluster",
"(",
")",
"==",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unavailable",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"c",
",",
"err",
":=",
"s",
".",
"cluster",
"(",
")",
".",
"Enumerate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Internal",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"// Get cluster information",
"cluster",
":=",
"c",
".",
"ToStorageCluster",
"(",
")",
"\n\n",
"// Get cluster unique id",
"cluster",
".",
"Id",
"=",
"s",
".",
"cluster",
"(",
")",
".",
"Uuid",
"(",
")",
"\n\n",
"return",
"&",
"api",
".",
"SdkClusterInspectCurrentResponse",
"{",
"Cluster",
":",
"cluster",
",",
"}",
",",
"nil",
"\n",
"}"
] | // InspectCurrent returns information about the current cluster | [
"InspectCurrent",
"returns",
"information",
"about",
"the",
"current",
"cluster"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/server/sdk/cluster.go#L38-L60 | train |
libopenstorage/openstorage | csi/v0.3/controller.go | ControllerGetCapabilities | func (s *OsdCsiServer) ControllerGetCapabilities(
ctx context.Context,
req *csi.ControllerGetCapabilitiesRequest,
) (*csi.ControllerGetCapabilitiesResponse, error) {
// Creating and deleting volumes supported
capCreateDeleteVolume := &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
},
},
}
// Creating and deleting snapshots
capCreateDeleteSnapshot := &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
},
},
}
// ListVolumes supported
capListVolumes := &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_LIST_VOLUMES,
},
},
}
return &csi.ControllerGetCapabilitiesResponse{
Capabilities: []*csi.ControllerServiceCapability{
capCreateDeleteVolume,
capCreateDeleteSnapshot,
capListVolumes,
},
}, nil
} | go | func (s *OsdCsiServer) ControllerGetCapabilities(
ctx context.Context,
req *csi.ControllerGetCapabilitiesRequest,
) (*csi.ControllerGetCapabilitiesResponse, error) {
// Creating and deleting volumes supported
capCreateDeleteVolume := &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
},
},
}
// Creating and deleting snapshots
capCreateDeleteSnapshot := &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
},
},
}
// ListVolumes supported
capListVolumes := &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: csi.ControllerServiceCapability_RPC_LIST_VOLUMES,
},
},
}
return &csi.ControllerGetCapabilitiesResponse{
Capabilities: []*csi.ControllerServiceCapability{
capCreateDeleteVolume,
capCreateDeleteSnapshot,
capListVolumes,
},
}, nil
} | [
"func",
"(",
"s",
"*",
"OsdCsiServer",
")",
"ControllerGetCapabilities",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"csi",
".",
"ControllerGetCapabilitiesRequest",
",",
")",
"(",
"*",
"csi",
".",
"ControllerGetCapabilitiesResponse",
",",
"error",
")",
"{",
"// Creating and deleting volumes supported",
"capCreateDeleteVolume",
":=",
"&",
"csi",
".",
"ControllerServiceCapability",
"{",
"Type",
":",
"&",
"csi",
".",
"ControllerServiceCapability_Rpc",
"{",
"Rpc",
":",
"&",
"csi",
".",
"ControllerServiceCapability_RPC",
"{",
"Type",
":",
"csi",
".",
"ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"// Creating and deleting snapshots",
"capCreateDeleteSnapshot",
":=",
"&",
"csi",
".",
"ControllerServiceCapability",
"{",
"Type",
":",
"&",
"csi",
".",
"ControllerServiceCapability_Rpc",
"{",
"Rpc",
":",
"&",
"csi",
".",
"ControllerServiceCapability_RPC",
"{",
"Type",
":",
"csi",
".",
"ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"// ListVolumes supported",
"capListVolumes",
":=",
"&",
"csi",
".",
"ControllerServiceCapability",
"{",
"Type",
":",
"&",
"csi",
".",
"ControllerServiceCapability_Rpc",
"{",
"Rpc",
":",
"&",
"csi",
".",
"ControllerServiceCapability_RPC",
"{",
"Type",
":",
"csi",
".",
"ControllerServiceCapability_RPC_LIST_VOLUMES",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"return",
"&",
"csi",
".",
"ControllerGetCapabilitiesResponse",
"{",
"Capabilities",
":",
"[",
"]",
"*",
"csi",
".",
"ControllerServiceCapability",
"{",
"capCreateDeleteVolume",
",",
"capCreateDeleteSnapshot",
",",
"capListVolumes",
",",
"}",
",",
"}",
",",
"nil",
"\n\n",
"}"
] | // ControllerGetCapabilities is a CSI API functions which returns to the caller
// the capabilities of the OSD CSI driver. | [
"ControllerGetCapabilities",
"is",
"a",
"CSI",
"API",
"functions",
"which",
"returns",
"to",
"the",
"caller",
"the",
"capabilities",
"of",
"the",
"OSD",
"CSI",
"driver",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/csi/v0.3/controller.go#L46-L86 | train |
libopenstorage/openstorage | csi/v0.3/controller.go | ControllerPublishVolume | func (s *OsdCsiServer) ControllerPublishVolume(
context.Context,
*csi.ControllerPublishVolumeRequest,
) (*csi.ControllerPublishVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "This request is not supported")
} | go | func (s *OsdCsiServer) ControllerPublishVolume(
context.Context,
*csi.ControllerPublishVolumeRequest,
) (*csi.ControllerPublishVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "This request is not supported")
} | [
"func",
"(",
"s",
"*",
"OsdCsiServer",
")",
"ControllerPublishVolume",
"(",
"context",
".",
"Context",
",",
"*",
"csi",
".",
"ControllerPublishVolumeRequest",
",",
")",
"(",
"*",
"csi",
".",
"ControllerPublishVolumeResponse",
",",
"error",
")",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unimplemented",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // ControllerPublishVolume is a CSI API implements the attachment of a volume
// on to a node. | [
"ControllerPublishVolume",
"is",
"a",
"CSI",
"API",
"implements",
"the",
"attachment",
"of",
"a",
"volume",
"on",
"to",
"a",
"node",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/csi/v0.3/controller.go#L90-L95 | train |
libopenstorage/openstorage | csi/v0.3/controller.go | ControllerUnpublishVolume | func (s *OsdCsiServer) ControllerUnpublishVolume(
context.Context,
*csi.ControllerUnpublishVolumeRequest,
) (*csi.ControllerUnpublishVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "This request is not supported")
} | go | func (s *OsdCsiServer) ControllerUnpublishVolume(
context.Context,
*csi.ControllerUnpublishVolumeRequest,
) (*csi.ControllerUnpublishVolumeResponse, error) {
return nil, status.Error(codes.Unimplemented, "This request is not supported")
} | [
"func",
"(",
"s",
"*",
"OsdCsiServer",
")",
"ControllerUnpublishVolume",
"(",
"context",
".",
"Context",
",",
"*",
"csi",
".",
"ControllerUnpublishVolumeRequest",
",",
")",
"(",
"*",
"csi",
".",
"ControllerUnpublishVolumeResponse",
",",
"error",
")",
"{",
"return",
"nil",
",",
"status",
".",
"Error",
"(",
"codes",
".",
"Unimplemented",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // ControllerUnpublishVolume is a CSI API which implements the detaching of a volume
// onto a node. | [
"ControllerUnpublishVolume",
"is",
"a",
"CSI",
"API",
"which",
"implements",
"the",
"detaching",
"of",
"a",
"volume",
"onto",
"a",
"node",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/csi/v0.3/controller.go#L99-L104 | train |
libopenstorage/openstorage | csi/v0.3/controller.go | osdVolumeAttributes | func osdVolumeAttributes(v *api.Volume) map[string]string {
return map[string]string{
api.SpecParent: v.GetSource().GetParent(),
api.SpecSecure: fmt.Sprintf("%v", v.GetSpec().GetEncrypted()),
api.SpecShared: fmt.Sprintf("%v", v.GetSpec().GetShared()),
"readonly": fmt.Sprintf("%v", v.GetReadonly()),
"attached": v.AttachedState.String(),
"state": v.State.String(),
"error": v.GetError(),
}
} | go | func osdVolumeAttributes(v *api.Volume) map[string]string {
return map[string]string{
api.SpecParent: v.GetSource().GetParent(),
api.SpecSecure: fmt.Sprintf("%v", v.GetSpec().GetEncrypted()),
api.SpecShared: fmt.Sprintf("%v", v.GetSpec().GetShared()),
"readonly": fmt.Sprintf("%v", v.GetReadonly()),
"attached": v.AttachedState.String(),
"state": v.State.String(),
"error": v.GetError(),
}
} | [
"func",
"osdVolumeAttributes",
"(",
"v",
"*",
"api",
".",
"Volume",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"return",
"map",
"[",
"string",
"]",
"string",
"{",
"api",
".",
"SpecParent",
":",
"v",
".",
"GetSource",
"(",
")",
".",
"GetParent",
"(",
")",
",",
"api",
".",
"SpecSecure",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
".",
"GetSpec",
"(",
")",
".",
"GetEncrypted",
"(",
")",
")",
",",
"api",
".",
"SpecShared",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
".",
"GetSpec",
"(",
")",
".",
"GetShared",
"(",
")",
")",
",",
"\"",
"\"",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
".",
"GetReadonly",
"(",
")",
")",
",",
"\"",
"\"",
":",
"v",
".",
"AttachedState",
".",
"String",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"State",
".",
"String",
"(",
")",
",",
"\"",
"\"",
":",
"v",
".",
"GetError",
"(",
")",
",",
"}",
"\n",
"}"
] | // osdVolumeAttributes returns the attributes of a volume as a map
// to be returned to the CSI API caller | [
"osdVolumeAttributes",
"returns",
"the",
"attributes",
"of",
"a",
"volume",
"as",
"a",
"map",
"to",
"be",
"returned",
"to",
"the",
"CSI",
"API",
"caller"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/csi/v0.3/controller.go#L294-L304 | train |
libopenstorage/openstorage | pkg/util/volume.go | VolumeFromName | func VolumeFromName(v volume.VolumeDriver, name string) (*api.Volume, error) {
vols, err := v.Inspect([]string{name})
if err == nil && len(vols) == 1 {
return vols[0], nil
}
vols, err = v.Enumerate(&api.VolumeLocator{Name: name}, nil)
if err != nil {
return nil, fmt.Errorf("Failed to locate volume %s. Error: %s", name, err.Error())
} else if err == nil && len(vols) == 1 {
return vols[0], nil
}
return nil, fmt.Errorf("Cannot locate volume with name %s", name)
} | go | func VolumeFromName(v volume.VolumeDriver, name string) (*api.Volume, error) {
vols, err := v.Inspect([]string{name})
if err == nil && len(vols) == 1 {
return vols[0], nil
}
vols, err = v.Enumerate(&api.VolumeLocator{Name: name}, nil)
if err != nil {
return nil, fmt.Errorf("Failed to locate volume %s. Error: %s", name, err.Error())
} else if err == nil && len(vols) == 1 {
return vols[0], nil
}
return nil, fmt.Errorf("Cannot locate volume with name %s", name)
} | [
"func",
"VolumeFromName",
"(",
"v",
"volume",
".",
"VolumeDriver",
",",
"name",
"string",
")",
"(",
"*",
"api",
".",
"Volume",
",",
"error",
")",
"{",
"vols",
",",
"err",
":=",
"v",
".",
"Inspect",
"(",
"[",
"]",
"string",
"{",
"name",
"}",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"len",
"(",
"vols",
")",
"==",
"1",
"{",
"return",
"vols",
"[",
"0",
"]",
",",
"nil",
"\n",
"}",
"\n",
"vols",
",",
"err",
"=",
"v",
".",
"Enumerate",
"(",
"&",
"api",
".",
"VolumeLocator",
"{",
"Name",
":",
"name",
"}",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"else",
"if",
"err",
"==",
"nil",
"&&",
"len",
"(",
"vols",
")",
"==",
"1",
"{",
"return",
"vols",
"[",
"0",
"]",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}"
] | // VolumeFromName returns the volume object associated with the specified name. | [
"VolumeFromName",
"returns",
"the",
"volume",
"object",
"associated",
"with",
"the",
"specified",
"name",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/util/volume.go#L28-L40 | train |
libopenstorage/openstorage | pkg/util/volume.go | VolumeFromIdSdk | func VolumeFromIdSdk(ctx context.Context, volumes api.OpenStorageVolumeClient, id string) (*api.Volume, error) {
inspectResp, err := volumes.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: id,
})
if err != nil {
return nil, fmt.Errorf("Cannot locate volume with id %s", id)
}
return inspectResp.Volume, nil
} | go | func VolumeFromIdSdk(ctx context.Context, volumes api.OpenStorageVolumeClient, id string) (*api.Volume, error) {
inspectResp, err := volumes.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: id,
})
if err != nil {
return nil, fmt.Errorf("Cannot locate volume with id %s", id)
}
return inspectResp.Volume, nil
} | [
"func",
"VolumeFromIdSdk",
"(",
"ctx",
"context",
".",
"Context",
",",
"volumes",
"api",
".",
"OpenStorageVolumeClient",
",",
"id",
"string",
")",
"(",
"*",
"api",
".",
"Volume",
",",
"error",
")",
"{",
"inspectResp",
",",
"err",
":=",
"volumes",
".",
"Inspect",
"(",
"ctx",
",",
"&",
"api",
".",
"SdkVolumeInspectRequest",
"{",
"VolumeId",
":",
"id",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"return",
"inspectResp",
".",
"Volume",
",",
"nil",
"\n",
"}"
] | // VolumeFromIdSdk uses the SDK to fetch the volume object associated with the specified id. | [
"VolumeFromIdSdk",
"uses",
"the",
"SDK",
"to",
"fetch",
"the",
"volume",
"object",
"associated",
"with",
"the",
"specified",
"id",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/util/volume.go#L43-L51 | train |
libopenstorage/openstorage | pkg/util/volume.go | VolumeFromNameSdk | func VolumeFromNameSdk(ctx context.Context, volumes api.OpenStorageVolumeClient, name string) (*api.Volume, error) {
// get volume id
volId, err := VolumeIdFromNameSdk(ctx, volumes, name)
if err != nil {
return nil, err
}
// inspect for actual volume
inspectResp, err := volumes.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: volId,
})
if err != nil {
return nil, err
}
return inspectResp.Volume, nil
} | go | func VolumeFromNameSdk(ctx context.Context, volumes api.OpenStorageVolumeClient, name string) (*api.Volume, error) {
// get volume id
volId, err := VolumeIdFromNameSdk(ctx, volumes, name)
if err != nil {
return nil, err
}
// inspect for actual volume
inspectResp, err := volumes.Inspect(ctx, &api.SdkVolumeInspectRequest{
VolumeId: volId,
})
if err != nil {
return nil, err
}
return inspectResp.Volume, nil
} | [
"func",
"VolumeFromNameSdk",
"(",
"ctx",
"context",
".",
"Context",
",",
"volumes",
"api",
".",
"OpenStorageVolumeClient",
",",
"name",
"string",
")",
"(",
"*",
"api",
".",
"Volume",
",",
"error",
")",
"{",
"// get volume id",
"volId",
",",
"err",
":=",
"VolumeIdFromNameSdk",
"(",
"ctx",
",",
"volumes",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// inspect for actual volume",
"inspectResp",
",",
"err",
":=",
"volumes",
".",
"Inspect",
"(",
"ctx",
",",
"&",
"api",
".",
"SdkVolumeInspectRequest",
"{",
"VolumeId",
":",
"volId",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"inspectResp",
".",
"Volume",
",",
"nil",
"\n",
"}"
] | // VolumeFromNameSdk uses the SDK to fetch the volume associated with a specified name. | [
"VolumeFromNameSdk",
"uses",
"the",
"SDK",
"to",
"fetch",
"the",
"volume",
"associated",
"with",
"a",
"specified",
"name",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/util/volume.go#L68-L83 | train |
libopenstorage/openstorage | pkg/storageops/aws/aws.go | NewEnvClient | func NewEnvClient() (storageops.Ops, error) {
region, err := storageops.GetEnvValueStrict("AWS_REGION")
if err != nil {
return nil, err
}
instance, err := storageops.GetEnvValueStrict("AWS_INSTANCE_NAME")
if err != nil {
return nil, err
}
instanceType, err := storageops.GetEnvValueStrict("AWS_INSTANCE_TYPE")
if err != nil {
return nil, err
}
if _, err := credentials.NewEnvCredentials().Get(); err != nil {
return nil, ErrAWSEnvNotAvailable
}
ec2 := ec2.New(
session.New(
&aws.Config{
Region: ®ion,
Credentials: credentials.NewEnvCredentials(),
},
),
)
return NewEc2Storage(instance, instanceType, ec2), nil
} | go | func NewEnvClient() (storageops.Ops, error) {
region, err := storageops.GetEnvValueStrict("AWS_REGION")
if err != nil {
return nil, err
}
instance, err := storageops.GetEnvValueStrict("AWS_INSTANCE_NAME")
if err != nil {
return nil, err
}
instanceType, err := storageops.GetEnvValueStrict("AWS_INSTANCE_TYPE")
if err != nil {
return nil, err
}
if _, err := credentials.NewEnvCredentials().Get(); err != nil {
return nil, ErrAWSEnvNotAvailable
}
ec2 := ec2.New(
session.New(
&aws.Config{
Region: ®ion,
Credentials: credentials.NewEnvCredentials(),
},
),
)
return NewEc2Storage(instance, instanceType, ec2), nil
} | [
"func",
"NewEnvClient",
"(",
")",
"(",
"storageops",
".",
"Ops",
",",
"error",
")",
"{",
"region",
",",
"err",
":=",
"storageops",
".",
"GetEnvValueStrict",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"instance",
",",
"err",
":=",
"storageops",
".",
"GetEnvValueStrict",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"instanceType",
",",
"err",
":=",
"storageops",
".",
"GetEnvValueStrict",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"credentials",
".",
"NewEnvCredentials",
"(",
")",
".",
"Get",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"ErrAWSEnvNotAvailable",
"\n",
"}",
"\n\n",
"ec2",
":=",
"ec2",
".",
"New",
"(",
"session",
".",
"New",
"(",
"&",
"aws",
".",
"Config",
"{",
"Region",
":",
"&",
"region",
",",
"Credentials",
":",
"credentials",
".",
"NewEnvCredentials",
"(",
")",
",",
"}",
",",
")",
",",
")",
"\n\n",
"return",
"NewEc2Storage",
"(",
"instance",
",",
"instanceType",
",",
"ec2",
")",
",",
"nil",
"\n",
"}"
] | // NewEnvClient creates a new AWS storage ops instance using environment vars | [
"NewEnvClient",
"creates",
"a",
"new",
"AWS",
"storage",
"ops",
"instance",
"using",
"environment",
"vars"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/aws/aws.go#L44-L74 | train |
libopenstorage/openstorage | pkg/storageops/aws/aws.go | NewEc2Storage | func NewEc2Storage(instance, instanceType string, ec2 *ec2.EC2) storageops.Ops {
return &ec2Ops{
instance: instance,
instanceType: instanceType,
ec2: ec2,
}
} | go | func NewEc2Storage(instance, instanceType string, ec2 *ec2.EC2) storageops.Ops {
return &ec2Ops{
instance: instance,
instanceType: instanceType,
ec2: ec2,
}
} | [
"func",
"NewEc2Storage",
"(",
"instance",
",",
"instanceType",
"string",
",",
"ec2",
"*",
"ec2",
".",
"EC2",
")",
"storageops",
".",
"Ops",
"{",
"return",
"&",
"ec2Ops",
"{",
"instance",
":",
"instance",
",",
"instanceType",
":",
"instanceType",
",",
"ec2",
":",
"ec2",
",",
"}",
"\n",
"}"
] | // NewEc2Storage creates a new aws storage ops instance | [
"NewEc2Storage",
"creates",
"a",
"new",
"aws",
"storage",
"ops",
"instance"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/aws/aws.go#L77-L83 | train |
libopenstorage/openstorage | pkg/storageops/aws/aws.go | getParentDevice | func (s *ec2Ops) getParentDevice(ipDevPath string) (string, error) {
// Check if the path is a symbolic link
var parentDevPath string
fi, err := os.Lstat(ipDevPath)
if err != nil {
return "", err
}
if fi.Mode()&os.ModeSymlink != 0 {
// input device path is a symbolic link
// get the parent device
output, err := filepath.EvalSymlinks(ipDevPath)
if err != nil {
return "", fmt.Errorf("failed to read symlink due to: %v", err)
}
parentDevPath = strings.TrimSpace(string(output))
} else {
parentDevPath = ipDevPath
}
return parentDevPath, nil
} | go | func (s *ec2Ops) getParentDevice(ipDevPath string) (string, error) {
// Check if the path is a symbolic link
var parentDevPath string
fi, err := os.Lstat(ipDevPath)
if err != nil {
return "", err
}
if fi.Mode()&os.ModeSymlink != 0 {
// input device path is a symbolic link
// get the parent device
output, err := filepath.EvalSymlinks(ipDevPath)
if err != nil {
return "", fmt.Errorf("failed to read symlink due to: %v", err)
}
parentDevPath = strings.TrimSpace(string(output))
} else {
parentDevPath = ipDevPath
}
return parentDevPath, nil
} | [
"func",
"(",
"s",
"*",
"ec2Ops",
")",
"getParentDevice",
"(",
"ipDevPath",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Check if the path is a symbolic link",
"var",
"parentDevPath",
"string",
"\n",
"fi",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"ipDevPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"fi",
".",
"Mode",
"(",
")",
"&",
"os",
".",
"ModeSymlink",
"!=",
"0",
"{",
"// input device path is a symbolic link",
"// get the parent device",
"output",
",",
"err",
":=",
"filepath",
".",
"EvalSymlinks",
"(",
"ipDevPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"parentDevPath",
"=",
"strings",
".",
"TrimSpace",
"(",
"string",
"(",
"output",
")",
")",
"\n",
"}",
"else",
"{",
"parentDevPath",
"=",
"ipDevPath",
"\n",
"}",
"\n",
"return",
"parentDevPath",
",",
"nil",
"\n",
"}"
] | // getParentDevice returns the parent device of the given device path
// by following the symbolic link. It is expected that the input device
// path exists | [
"getParentDevice",
"returns",
"the",
"parent",
"device",
"of",
"the",
"given",
"device",
"path",
"by",
"following",
"the",
"symbolic",
"link",
".",
"It",
"is",
"expected",
"that",
"the",
"input",
"device",
"path",
"exists"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/storageops/aws/aws.go#L311-L330 | train |
libopenstorage/openstorage | api/client/cluster/osdconfig.go | GetClusterConf | func (c *clusterClient) GetClusterConf() (*osdconfig.ClusterConfig, error) {
config := new(osdconfig.ClusterConfig)
request := c.c.Get().Resource(clusterPath + UriCluster)
if err := request.Do().Unmarshal(config); err != nil {
return nil, err
}
return config, nil
} | go | func (c *clusterClient) GetClusterConf() (*osdconfig.ClusterConfig, error) {
config := new(osdconfig.ClusterConfig)
request := c.c.Get().Resource(clusterPath + UriCluster)
if err := request.Do().Unmarshal(config); err != nil {
return nil, err
}
return config, nil
} | [
"func",
"(",
"c",
"*",
"clusterClient",
")",
"GetClusterConf",
"(",
")",
"(",
"*",
"osdconfig",
".",
"ClusterConfig",
",",
"error",
")",
"{",
"config",
":=",
"new",
"(",
"osdconfig",
".",
"ClusterConfig",
")",
"\n",
"request",
":=",
"c",
".",
"c",
".",
"Get",
"(",
")",
".",
"Resource",
"(",
"clusterPath",
"+",
"UriCluster",
")",
"\n",
"if",
"err",
":=",
"request",
".",
"Do",
"(",
")",
".",
"Unmarshal",
"(",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"config",
",",
"nil",
"\n",
"}"
] | // osdconfig.ConfigCaller interface compliance | [
"osdconfig",
".",
"ConfigCaller",
"interface",
"compliance"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/cluster/osdconfig.go#L16-L23 | train |
libopenstorage/openstorage | csi/identity.go | GetPluginCapabilities | func (s *OsdCsiServer) GetPluginCapabilities(
ctx context.Context,
req *csi.GetPluginCapabilitiesRequest,
) (*csi.GetPluginCapabilitiesResponse, error) {
return &csi.GetPluginCapabilitiesResponse{
Capabilities: []*csi.PluginCapability{
&csi.PluginCapability{
Type: &csi.PluginCapability_Service_{
Service: &csi.PluginCapability_Service{
Type: csi.PluginCapability_Service_CONTROLLER_SERVICE,
},
},
},
&csi.PluginCapability{
Type: &csi.PluginCapability_VolumeExpansion_{
VolumeExpansion: &csi.PluginCapability_VolumeExpansion{
Type: csi.PluginCapability_VolumeExpansion_ONLINE,
},
},
},
},
}, nil
} | go | func (s *OsdCsiServer) GetPluginCapabilities(
ctx context.Context,
req *csi.GetPluginCapabilitiesRequest,
) (*csi.GetPluginCapabilitiesResponse, error) {
return &csi.GetPluginCapabilitiesResponse{
Capabilities: []*csi.PluginCapability{
&csi.PluginCapability{
Type: &csi.PluginCapability_Service_{
Service: &csi.PluginCapability_Service{
Type: csi.PluginCapability_Service_CONTROLLER_SERVICE,
},
},
},
&csi.PluginCapability{
Type: &csi.PluginCapability_VolumeExpansion_{
VolumeExpansion: &csi.PluginCapability_VolumeExpansion{
Type: csi.PluginCapability_VolumeExpansion_ONLINE,
},
},
},
},
}, nil
} | [
"func",
"(",
"s",
"*",
"OsdCsiServer",
")",
"GetPluginCapabilities",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"csi",
".",
"GetPluginCapabilitiesRequest",
",",
")",
"(",
"*",
"csi",
".",
"GetPluginCapabilitiesResponse",
",",
"error",
")",
"{",
"return",
"&",
"csi",
".",
"GetPluginCapabilitiesResponse",
"{",
"Capabilities",
":",
"[",
"]",
"*",
"csi",
".",
"PluginCapability",
"{",
"&",
"csi",
".",
"PluginCapability",
"{",
"Type",
":",
"&",
"csi",
".",
"PluginCapability_Service_",
"{",
"Service",
":",
"&",
"csi",
".",
"PluginCapability_Service",
"{",
"Type",
":",
"csi",
".",
"PluginCapability_Service_CONTROLLER_SERVICE",
",",
"}",
",",
"}",
",",
"}",
",",
"&",
"csi",
".",
"PluginCapability",
"{",
"Type",
":",
"&",
"csi",
".",
"PluginCapability_VolumeExpansion_",
"{",
"VolumeExpansion",
":",
"&",
"csi",
".",
"PluginCapability_VolumeExpansion",
"{",
"Type",
":",
"csi",
".",
"PluginCapability_VolumeExpansion_ONLINE",
",",
"}",
",",
"}",
",",
"}",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // GetPluginCapabilities is a CSI API | [
"GetPluginCapabilities",
"is",
"a",
"CSI",
"API"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/csi/identity.go#L30-L52 | train |
libopenstorage/openstorage | csi/identity.go | Probe | func (s *OsdCsiServer) Probe(
ctx context.Context,
req *csi.ProbeRequest,
) (*csi.ProbeResponse, error) {
return &csi.ProbeResponse{}, nil
} | go | func (s *OsdCsiServer) Probe(
ctx context.Context,
req *csi.ProbeRequest,
) (*csi.ProbeResponse, error) {
return &csi.ProbeResponse{}, nil
} | [
"func",
"(",
"s",
"*",
"OsdCsiServer",
")",
"Probe",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"csi",
".",
"ProbeRequest",
",",
")",
"(",
"*",
"csi",
".",
"ProbeResponse",
",",
"error",
")",
"{",
"return",
"&",
"csi",
".",
"ProbeResponse",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // Probe is a CSI API | [
"Probe",
"is",
"a",
"CSI",
"API"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/csi/identity.go#L55-L60 | train |
libopenstorage/openstorage | csi/identity.go | GetPluginInfo | func (s *OsdCsiServer) GetPluginInfo(
ctx context.Context,
req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
return &csi.GetPluginInfoResponse{
Name: csiDriverNamePrefix + s.driver.Name(),
VendorVersion: csiDriverVersion,
// As OSD CSI Driver matures, add here more information
Manifest: map[string]string{
"driver": s.driver.Name(),
},
}, nil
} | go | func (s *OsdCsiServer) GetPluginInfo(
ctx context.Context,
req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
return &csi.GetPluginInfoResponse{
Name: csiDriverNamePrefix + s.driver.Name(),
VendorVersion: csiDriverVersion,
// As OSD CSI Driver matures, add here more information
Manifest: map[string]string{
"driver": s.driver.Name(),
},
}, nil
} | [
"func",
"(",
"s",
"*",
"OsdCsiServer",
")",
"GetPluginInfo",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"*",
"csi",
".",
"GetPluginInfoRequest",
")",
"(",
"*",
"csi",
".",
"GetPluginInfoResponse",
",",
"error",
")",
"{",
"return",
"&",
"csi",
".",
"GetPluginInfoResponse",
"{",
"Name",
":",
"csiDriverNamePrefix",
"+",
"s",
".",
"driver",
".",
"Name",
"(",
")",
",",
"VendorVersion",
":",
"csiDriverVersion",
",",
"// As OSD CSI Driver matures, add here more information",
"Manifest",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"s",
".",
"driver",
".",
"Name",
"(",
")",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // GetPluginInfo is a CSI API which returns the information about the plugin.
// This includes name, version, and any other OSD specific information | [
"GetPluginInfo",
"is",
"a",
"CSI",
"API",
"which",
"returns",
"the",
"information",
"about",
"the",
"plugin",
".",
"This",
"includes",
"name",
"version",
"and",
"any",
"other",
"OSD",
"specific",
"information"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/csi/identity.go#L64-L77 | train |
libopenstorage/openstorage | api/client/client.go | NewClient | func NewClient(host, version, userAgent string) (*Client, error) {
baseURL, err := url.Parse(host)
if err != nil {
return nil, err
}
if baseURL.Path == "" {
baseURL.Path = "/"
}
unix2HTTP(baseURL)
hClient := getHTTPClient(host)
if hClient == nil {
return nil, fmt.Errorf("Unable to parse provided url: %v", host)
}
c := &Client{
base: baseURL,
version: version,
httpClient: hClient,
authstring: "",
accesstoken: "",
userAgent: fmt.Sprintf("%v/%v", userAgent, version),
}
return c, nil
} | go | func NewClient(host, version, userAgent string) (*Client, error) {
baseURL, err := url.Parse(host)
if err != nil {
return nil, err
}
if baseURL.Path == "" {
baseURL.Path = "/"
}
unix2HTTP(baseURL)
hClient := getHTTPClient(host)
if hClient == nil {
return nil, fmt.Errorf("Unable to parse provided url: %v", host)
}
c := &Client{
base: baseURL,
version: version,
httpClient: hClient,
authstring: "",
accesstoken: "",
userAgent: fmt.Sprintf("%v/%v", userAgent, version),
}
return c, nil
} | [
"func",
"NewClient",
"(",
"host",
",",
"version",
",",
"userAgent",
"string",
")",
"(",
"*",
"Client",
",",
"error",
")",
"{",
"baseURL",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"host",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"baseURL",
".",
"Path",
"==",
"\"",
"\"",
"{",
"baseURL",
".",
"Path",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"unix2HTTP",
"(",
"baseURL",
")",
"\n",
"hClient",
":=",
"getHTTPClient",
"(",
"host",
")",
"\n",
"if",
"hClient",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"host",
")",
"\n",
"}",
"\n",
"c",
":=",
"&",
"Client",
"{",
"base",
":",
"baseURL",
",",
"version",
":",
"version",
",",
"httpClient",
":",
"hClient",
",",
"authstring",
":",
"\"",
"\"",
",",
"accesstoken",
":",
"\"",
"\"",
",",
"userAgent",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"userAgent",
",",
"version",
")",
",",
"}",
"\n",
"return",
"c",
",",
"nil",
"\n",
"}"
] | // NewClient returns a new REST client for specified server. | [
"NewClient",
"returns",
"a",
"new",
"REST",
"client",
"for",
"specified",
"server",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/client.go#L19-L41 | train |
libopenstorage/openstorage | api/client/client.go | GetUnixServerPath | func GetUnixServerPath(socketName string, paths ...string) string {
serverPath := "unix://"
for _, path := range paths {
serverPath = serverPath + path
}
serverPath = serverPath + socketName + ".sock"
return serverPath
} | go | func GetUnixServerPath(socketName string, paths ...string) string {
serverPath := "unix://"
for _, path := range paths {
serverPath = serverPath + path
}
serverPath = serverPath + socketName + ".sock"
return serverPath
} | [
"func",
"GetUnixServerPath",
"(",
"socketName",
"string",
",",
"paths",
"...",
"string",
")",
"string",
"{",
"serverPath",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"path",
":=",
"range",
"paths",
"{",
"serverPath",
"=",
"serverPath",
"+",
"path",
"\n",
"}",
"\n",
"serverPath",
"=",
"serverPath",
"+",
"socketName",
"+",
"\"",
"\"",
"\n",
"return",
"serverPath",
"\n",
"}"
] | // GetUnixServerPath returns a unix domain socket prepended with the
// provided path. | [
"GetUnixServerPath",
"returns",
"a",
"unix",
"domain",
"socket",
"prepended",
"with",
"the",
"provided",
"path",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/client.go#L70-L77 | train |
libopenstorage/openstorage | api/client/client.go | Get | func (c *Client) Get() *Request {
return NewRequest(c.httpClient, c.base, "GET", c.version, c.authstring, c.userAgent)
} | go | func (c *Client) Get() *Request {
return NewRequest(c.httpClient, c.base, "GET", c.version, c.authstring, c.userAgent)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Get",
"(",
")",
"*",
"Request",
"{",
"return",
"NewRequest",
"(",
"c",
".",
"httpClient",
",",
"c",
".",
"base",
",",
"\"",
"\"",
",",
"c",
".",
"version",
",",
"c",
".",
"authstring",
",",
"c",
".",
"userAgent",
")",
"\n",
"}"
] | // Get returns a Request object setup for GET call. | [
"Get",
"returns",
"a",
"Request",
"object",
"setup",
"for",
"GET",
"call",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/client.go#L104-L106 | train |
libopenstorage/openstorage | cli/cluster.go | ClusterCommands | func ClusterCommands() []cli.Command {
c := &clusterClient{}
commands := []cli.Command{
{
Name: "status",
Aliases: []string{"s"},
Usage: "Inspect the cluster",
Action: c.status,
Flags: []cli.Flag{
cli.StringFlag{
Name: "machine,m",
Usage: "Comma separated machine ids, e.g uuid1,uuid2",
Value: "",
},
},
},
{
Name: "inspect",
Aliases: []string{"l"},
Usage: "Inspect nodes in the cluster",
Action: c.inspect,
Flags: []cli.Flag{
cli.StringFlag{
Name: "machine,m",
Usage: "Comma separated machine ids, e.g uuid1,uuid2",
Value: "",
},
},
},
{
Name: "disable-gossip",
Aliases: []string{"dg"},
Usage: "Disable gossip updates",
Action: c.disableGossip,
},
{
Name: "enable-gossip",
Aliases: []string{"eg"},
Usage: "Enable gossip updates",
Action: c.enableGossip,
},
{
Name: "gossip-status",
Aliases: []string{"gs"},
Usage: "Display gossip status",
Action: c.gossipStatus,
},
{
Name: "remove",
Aliases: []string{"r"},
Usage: "Remove a machine from the cluster",
Action: c.remove,
Flags: []cli.Flag{
cli.StringFlag{
Name: "machine,m",
Usage: "Comma separated machine ids, e.g uuid1,uuid2",
Value: "",
},
},
},
{
Name: "shutdown",
Usage: "Shutdown a cluster or a specific machine",
Action: c.shutdown,
Flags: []cli.Flag{
cli.StringFlag{
Name: "machine,m",
Usage: "Comma separated machine ids, e.g uuid1,uuid2",
Value: "",
},
},
},
}
return commands
} | go | func ClusterCommands() []cli.Command {
c := &clusterClient{}
commands := []cli.Command{
{
Name: "status",
Aliases: []string{"s"},
Usage: "Inspect the cluster",
Action: c.status,
Flags: []cli.Flag{
cli.StringFlag{
Name: "machine,m",
Usage: "Comma separated machine ids, e.g uuid1,uuid2",
Value: "",
},
},
},
{
Name: "inspect",
Aliases: []string{"l"},
Usage: "Inspect nodes in the cluster",
Action: c.inspect,
Flags: []cli.Flag{
cli.StringFlag{
Name: "machine,m",
Usage: "Comma separated machine ids, e.g uuid1,uuid2",
Value: "",
},
},
},
{
Name: "disable-gossip",
Aliases: []string{"dg"},
Usage: "Disable gossip updates",
Action: c.disableGossip,
},
{
Name: "enable-gossip",
Aliases: []string{"eg"},
Usage: "Enable gossip updates",
Action: c.enableGossip,
},
{
Name: "gossip-status",
Aliases: []string{"gs"},
Usage: "Display gossip status",
Action: c.gossipStatus,
},
{
Name: "remove",
Aliases: []string{"r"},
Usage: "Remove a machine from the cluster",
Action: c.remove,
Flags: []cli.Flag{
cli.StringFlag{
Name: "machine,m",
Usage: "Comma separated machine ids, e.g uuid1,uuid2",
Value: "",
},
},
},
{
Name: "shutdown",
Usage: "Shutdown a cluster or a specific machine",
Action: c.shutdown,
Flags: []cli.Flag{
cli.StringFlag{
Name: "machine,m",
Usage: "Comma separated machine ids, e.g uuid1,uuid2",
Value: "",
},
},
},
}
return commands
} | [
"func",
"ClusterCommands",
"(",
")",
"[",
"]",
"cli",
".",
"Command",
"{",
"c",
":=",
"&",
"clusterClient",
"{",
"}",
"\n\n",
"commands",
":=",
"[",
"]",
"cli",
".",
"Command",
"{",
"{",
"Name",
":",
"\"",
"\"",
",",
"Aliases",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",
"c",
".",
"status",
",",
"Flags",
":",
"[",
"]",
"cli",
".",
"Flag",
"{",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Value",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"Aliases",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",
"c",
".",
"inspect",
",",
"Flags",
":",
"[",
"]",
"cli",
".",
"Flag",
"{",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Value",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"Aliases",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",
"c",
".",
"disableGossip",
",",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"Aliases",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",
"c",
".",
"enableGossip",
",",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"Aliases",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",
"c",
".",
"gossipStatus",
",",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"Aliases",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",
"c",
".",
"remove",
",",
"Flags",
":",
"[",
"]",
"cli",
".",
"Flag",
"{",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Value",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Action",
":",
"c",
".",
"shutdown",
",",
"Flags",
":",
"[",
"]",
"cli",
".",
"Flag",
"{",
"cli",
".",
"StringFlag",
"{",
"Name",
":",
"\"",
"\"",
",",
"Usage",
":",
"\"",
"\"",
",",
"Value",
":",
"\"",
"\"",
",",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n",
"return",
"commands",
"\n",
"}"
] | // ClusterCommands exports CLI comamnds for File VolumeDriver | [
"ClusterCommands",
"exports",
"CLI",
"comamnds",
"for",
"File",
"VolumeDriver"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/cli/cluster.go#L147-L222 | train |
libopenstorage/openstorage | pkg/sched/intervals.go | parseDaily | func parseDaily(dailyStr string) (RetainIntervalSpec, error) {
r, daily, err := parseRetainNumber(dailyStr)
if err != nil {
return r, err
}
if daily == "" {
return r, fmt.Errorf("Daily schedule is missing")
}
dt := strings.Split(daily, "@")
h, m, err := timeOfDay(dt[len(dt)-1])
if err != nil {
return RetainIntervalSpec{}, err
}
r.IntervalSpec = Daily(h, m).Spec()
return r, nil
} | go | func parseDaily(dailyStr string) (RetainIntervalSpec, error) {
r, daily, err := parseRetainNumber(dailyStr)
if err != nil {
return r, err
}
if daily == "" {
return r, fmt.Errorf("Daily schedule is missing")
}
dt := strings.Split(daily, "@")
h, m, err := timeOfDay(dt[len(dt)-1])
if err != nil {
return RetainIntervalSpec{}, err
}
r.IntervalSpec = Daily(h, m).Spec()
return r, nil
} | [
"func",
"parseDaily",
"(",
"dailyStr",
"string",
")",
"(",
"RetainIntervalSpec",
",",
"error",
")",
"{",
"r",
",",
"daily",
",",
"err",
":=",
"parseRetainNumber",
"(",
"dailyStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n",
"if",
"daily",
"==",
"\"",
"\"",
"{",
"return",
"r",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"dt",
":=",
"strings",
".",
"Split",
"(",
"daily",
",",
"\"",
"\"",
")",
"\n",
"h",
",",
"m",
",",
"err",
":=",
"timeOfDay",
"(",
"dt",
"[",
"len",
"(",
"dt",
")",
"-",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RetainIntervalSpec",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"r",
".",
"IntervalSpec",
"=",
"Daily",
"(",
"h",
",",
"m",
")",
".",
"Spec",
"(",
")",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] | // parseDaily item [@]hh:mm,r | [
"parseDaily",
"item",
"["
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/sched/intervals.go#L407-L422 | train |
libopenstorage/openstorage | pkg/sched/intervals.go | parseWeekly | func parseWeekly(weeklyStr string) (RetainIntervalSpec, error) {
r, weekly, err := parseRetainNumber(weeklyStr)
if err != nil {
return r, err
}
if weekly == "" {
return r, fmt.Errorf("Weekly schedule is missing")
}
dt := strings.Split(weekly, "@")
if len(dt) == 1 {
dt = append(dt, "0:0")
}
if len(dt) != 2 {
return RetainIntervalSpec{},
fmt.Errorf("Invalid weekly spec %v", weeklyStr)
}
d, err := dayOfWeek(dt[0])
if err != nil {
return RetainIntervalSpec{}, err
}
h, m, err := timeOfDay(dt[1])
r.IntervalSpec = Weekly(d, h, m).Spec()
return r, err
} | go | func parseWeekly(weeklyStr string) (RetainIntervalSpec, error) {
r, weekly, err := parseRetainNumber(weeklyStr)
if err != nil {
return r, err
}
if weekly == "" {
return r, fmt.Errorf("Weekly schedule is missing")
}
dt := strings.Split(weekly, "@")
if len(dt) == 1 {
dt = append(dt, "0:0")
}
if len(dt) != 2 {
return RetainIntervalSpec{},
fmt.Errorf("Invalid weekly spec %v", weeklyStr)
}
d, err := dayOfWeek(dt[0])
if err != nil {
return RetainIntervalSpec{}, err
}
h, m, err := timeOfDay(dt[1])
r.IntervalSpec = Weekly(d, h, m).Spec()
return r, err
} | [
"func",
"parseWeekly",
"(",
"weeklyStr",
"string",
")",
"(",
"RetainIntervalSpec",
",",
"error",
")",
"{",
"r",
",",
"weekly",
",",
"err",
":=",
"parseRetainNumber",
"(",
"weeklyStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n",
"if",
"weekly",
"==",
"\"",
"\"",
"{",
"return",
"r",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"dt",
":=",
"strings",
".",
"Split",
"(",
"weekly",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"dt",
")",
"==",
"1",
"{",
"dt",
"=",
"append",
"(",
"dt",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"dt",
")",
"!=",
"2",
"{",
"return",
"RetainIntervalSpec",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"weeklyStr",
")",
"\n",
"}",
"\n",
"d",
",",
"err",
":=",
"dayOfWeek",
"(",
"dt",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RetainIntervalSpec",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"h",
",",
"m",
",",
"err",
":=",
"timeOfDay",
"(",
"dt",
"[",
"1",
"]",
")",
"\n",
"r",
".",
"IntervalSpec",
"=",
"Weekly",
"(",
"d",
",",
"h",
",",
"m",
")",
".",
"Spec",
"(",
")",
"\n",
"return",
"r",
",",
"err",
"\n",
"}"
] | // parseWeekly item weekday@hh:mm,r | [
"parseWeekly",
"item",
"weekday"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/sched/intervals.go#L425-L448 | train |
libopenstorage/openstorage | pkg/sched/intervals.go | parseMonthly | func parseMonthly(monthlyStr string) (RetainIntervalSpec, error) {
r, monthly, err := parseRetainNumber(monthlyStr)
if err != nil {
return r, err
}
if monthly == "" {
return r, fmt.Errorf("Monthly schedule is missing")
}
dt := strings.Split(monthly, "@")
if len(dt) == 1 {
dt = append(dt, "0:0")
}
if len(dt) != 2 {
return RetainIntervalSpec{},
fmt.Errorf("Invalid monthly spec %v", monthlyStr)
}
d, err := strconv.Atoi(dt[0])
if err != nil || d < 0 || d > 31 {
return RetainIntervalSpec{},
fmt.Errorf("Invalid day of month %v", dt[0])
}
h, m, err := timeOfDay(dt[1])
if err != nil {
return RetainIntervalSpec{}, err
}
r.IntervalSpec = Monthly(d, h, m).Spec()
return r, nil
} | go | func parseMonthly(monthlyStr string) (RetainIntervalSpec, error) {
r, monthly, err := parseRetainNumber(monthlyStr)
if err != nil {
return r, err
}
if monthly == "" {
return r, fmt.Errorf("Monthly schedule is missing")
}
dt := strings.Split(monthly, "@")
if len(dt) == 1 {
dt = append(dt, "0:0")
}
if len(dt) != 2 {
return RetainIntervalSpec{},
fmt.Errorf("Invalid monthly spec %v", monthlyStr)
}
d, err := strconv.Atoi(dt[0])
if err != nil || d < 0 || d > 31 {
return RetainIntervalSpec{},
fmt.Errorf("Invalid day of month %v", dt[0])
}
h, m, err := timeOfDay(dt[1])
if err != nil {
return RetainIntervalSpec{}, err
}
r.IntervalSpec = Monthly(d, h, m).Spec()
return r, nil
} | [
"func",
"parseMonthly",
"(",
"monthlyStr",
"string",
")",
"(",
"RetainIntervalSpec",
",",
"error",
")",
"{",
"r",
",",
"monthly",
",",
"err",
":=",
"parseRetainNumber",
"(",
"monthlyStr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n",
"if",
"monthly",
"==",
"\"",
"\"",
"{",
"return",
"r",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"dt",
":=",
"strings",
".",
"Split",
"(",
"monthly",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"dt",
")",
"==",
"1",
"{",
"dt",
"=",
"append",
"(",
"dt",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"dt",
")",
"!=",
"2",
"{",
"return",
"RetainIntervalSpec",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"monthlyStr",
")",
"\n",
"}",
"\n",
"d",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"dt",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"d",
"<",
"0",
"||",
"d",
">",
"31",
"{",
"return",
"RetainIntervalSpec",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dt",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"h",
",",
"m",
",",
"err",
":=",
"timeOfDay",
"(",
"dt",
"[",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"RetainIntervalSpec",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"r",
".",
"IntervalSpec",
"=",
"Monthly",
"(",
"d",
",",
"h",
",",
"m",
")",
".",
"Spec",
"(",
")",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] | // parseMonthly item day@hh:mm,r | [
"parseMonthly",
"item",
"day"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/sched/intervals.go#L451-L478 | train |
libopenstorage/openstorage | pkg/sched/intervals.go | NewPolicyTagsFromSlice | func NewPolicyTagsFromSlice(policies []string) (*PolicyTags, error) {
p := &PolicyTags{Names: policies}
return p, p.verifyPolicyTags()
} | go | func NewPolicyTagsFromSlice(policies []string) (*PolicyTags, error) {
p := &PolicyTags{Names: policies}
return p, p.verifyPolicyTags()
} | [
"func",
"NewPolicyTagsFromSlice",
"(",
"policies",
"[",
"]",
"string",
")",
"(",
"*",
"PolicyTags",
",",
"error",
")",
"{",
"p",
":=",
"&",
"PolicyTags",
"{",
"Names",
":",
"policies",
"}",
"\n",
"return",
"p",
",",
"p",
".",
"verifyPolicyTags",
"(",
")",
"\n",
"}"
] | // NewPolicyTagsFromSlice returns a new object from a string slice of names | [
"NewPolicyTagsFromSlice",
"returns",
"a",
"new",
"object",
"from",
"a",
"string",
"slice",
"of",
"names"
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/sched/intervals.go#L603-L606 | train |
libopenstorage/openstorage | volume/drivers/vfs/vfs.go | Init | func Init(params map[string]string) (volume.VolumeDriver, error) {
return &driver{
volume.IONotSupported,
volume.BlockNotSupported,
volume.SnapshotNotSupported,
common.NewDefaultStoreEnumerator(Name, kvdb.Instance()),
volume.StatsNotSupported,
volume.CredsNotSupported,
volume.CloudBackupNotSupported,
volume.CloudMigrateNotSupported,
}, nil
} | go | func Init(params map[string]string) (volume.VolumeDriver, error) {
return &driver{
volume.IONotSupported,
volume.BlockNotSupported,
volume.SnapshotNotSupported,
common.NewDefaultStoreEnumerator(Name, kvdb.Instance()),
volume.StatsNotSupported,
volume.CredsNotSupported,
volume.CloudBackupNotSupported,
volume.CloudMigrateNotSupported,
}, nil
} | [
"func",
"Init",
"(",
"params",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"volume",
".",
"VolumeDriver",
",",
"error",
")",
"{",
"return",
"&",
"driver",
"{",
"volume",
".",
"IONotSupported",
",",
"volume",
".",
"BlockNotSupported",
",",
"volume",
".",
"SnapshotNotSupported",
",",
"common",
".",
"NewDefaultStoreEnumerator",
"(",
"Name",
",",
"kvdb",
".",
"Instance",
"(",
")",
")",
",",
"volume",
".",
"StatsNotSupported",
",",
"volume",
".",
"CredsNotSupported",
",",
"volume",
".",
"CloudBackupNotSupported",
",",
"volume",
".",
"CloudMigrateNotSupported",
",",
"}",
",",
"nil",
"\n",
"}"
] | // Init Driver intialization. | [
"Init",
"Driver",
"intialization",
"."
] | 71b7f37f99c70e697aa31ca57fa8fb1404629329 | https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/volume/drivers/vfs/vfs.go#L42-L53 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.