id
int32 0
167k
| 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
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
143,700 |
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
|
143,701 |
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
|
143,702 |
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
|
143,703 |
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
|
143,704 |
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
|
143,705 |
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
|
143,706 |
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
|
143,707 |
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
|
143,708 |
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
|
143,709 |
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
|
143,710 |
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
|
143,711 |
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
|
143,712 |
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
|
143,713 |
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
|
143,714 |
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
|
143,715 |
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
|
143,716 |
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
|
143,717 |
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
|
143,718 |
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
|
143,719 |
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
|
143,720 |
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
|
143,721 |
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
|
143,722 |
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
|
143,723 |
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
|
143,724 |
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
|
143,725 |
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
|
143,726 |
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
|
143,727 |
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
|
143,728 |
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
|
143,729 |
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
|
143,730 |
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
|
143,731 |
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
|
143,732 |
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
|
143,733 |
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
|
143,734 |
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
|
143,735 |
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
|
143,736 |
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
|
143,737 |
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
|
143,738 |
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
|
143,739 |
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
|
143,740 |
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
|
143,741 |
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
|
143,742 |
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
|
143,743 |
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
|
143,744 |
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
|
143,745 |
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
|
143,746 |
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
|
143,747 |
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
|
143,748 |
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
|
143,749 |
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
|
143,750 |
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
|
143,751 |
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
|
143,752 |
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
|
143,753 |
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
|
143,754 |
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
|
143,755 |
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
|
143,756 |
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
|
143,757 |
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
|
143,758 |
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
|
143,759 |
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
|
143,760 |
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
|
143,761 |
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
|
143,762 |
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
|
143,763 |
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
|
143,764 |
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
|
143,765 |
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
|
143,766 |
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
|
143,767 |
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
|
143,768 |
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
|
143,769 |
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
|
143,770 |
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
|
143,771 |
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
|
143,772 |
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
|
143,773 |
libopenstorage/openstorage
|
api/client/request.go
|
Resource
|
func (r *Request) Resource(resource string) *Request {
if r.err == nil {
r.err = checkSet("resource", &r.resource, resource)
}
return r
}
|
go
|
func (r *Request) Resource(resource string) *Request {
if r.err == nil {
r.err = checkSet("resource", &r.resource, resource)
}
return r
}
|
[
"func",
"(",
"r",
"*",
"Request",
")",
"Resource",
"(",
"resource",
"string",
")",
"*",
"Request",
"{",
"if",
"r",
".",
"err",
"==",
"nil",
"{",
"r",
".",
"err",
"=",
"checkSet",
"(",
"\"",
"\"",
",",
"&",
"r",
".",
"resource",
",",
"resource",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// Resource specifies the resource to be accessed.
|
[
"Resource",
"specifies",
"the",
"resource",
"to",
"be",
"accessed",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L91-L96
|
143,774 |
libopenstorage/openstorage
|
api/client/request.go
|
Instance
|
func (r *Request) Instance(instance string) *Request {
if r.err == nil {
r.err = checkExists("resource", "instance")
if r.err == nil {
r.err = checkSet("instance", &r.instance, instance)
}
}
return r
}
|
go
|
func (r *Request) Instance(instance string) *Request {
if r.err == nil {
r.err = checkExists("resource", "instance")
if r.err == nil {
r.err = checkSet("instance", &r.instance, instance)
}
}
return r
}
|
[
"func",
"(",
"r",
"*",
"Request",
")",
"Instance",
"(",
"instance",
"string",
")",
"*",
"Request",
"{",
"if",
"r",
".",
"err",
"==",
"nil",
"{",
"r",
".",
"err",
"=",
"checkExists",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"r",
".",
"err",
"==",
"nil",
"{",
"r",
".",
"err",
"=",
"checkSet",
"(",
"\"",
"\"",
",",
"&",
"r",
".",
"instance",
",",
"instance",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// Instance specifies the instance of the resource to be accessed.
|
[
"Instance",
"specifies",
"the",
"instance",
"of",
"the",
"resource",
"to",
"be",
"accessed",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L99-L107
|
143,775 |
libopenstorage/openstorage
|
api/client/request.go
|
UsePath
|
func (r *Request) UsePath(path string) *Request {
if r.err == nil {
r.err = checkSet("path", &r.path, path)
}
return r
}
|
go
|
func (r *Request) UsePath(path string) *Request {
if r.err == nil {
r.err = checkSet("path", &r.path, path)
}
return r
}
|
[
"func",
"(",
"r",
"*",
"Request",
")",
"UsePath",
"(",
"path",
"string",
")",
"*",
"Request",
"{",
"if",
"r",
".",
"err",
"==",
"nil",
"{",
"r",
".",
"err",
"=",
"checkSet",
"(",
"\"",
"\"",
",",
"&",
"r",
".",
"path",
",",
"path",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// UsePath use the specified path and don't build up a request.
|
[
"UsePath",
"use",
"the",
"specified",
"path",
"and",
"don",
"t",
"build",
"up",
"a",
"request",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L110-L115
|
143,776 |
libopenstorage/openstorage
|
api/client/request.go
|
QueryOption
|
func (r *Request) QueryOption(key string, value string) *Request {
if r.err != nil {
return r
}
if r.params == nil {
r.params = make(url.Values)
}
r.params.Add(string(key), value)
return r
}
|
go
|
func (r *Request) QueryOption(key string, value string) *Request {
if r.err != nil {
return r
}
if r.params == nil {
r.params = make(url.Values)
}
r.params.Add(string(key), value)
return r
}
|
[
"func",
"(",
"r",
"*",
"Request",
")",
"QueryOption",
"(",
"key",
"string",
",",
"value",
"string",
")",
"*",
"Request",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"r",
"\n",
"}",
"\n",
"if",
"r",
".",
"params",
"==",
"nil",
"{",
"r",
".",
"params",
"=",
"make",
"(",
"url",
".",
"Values",
")",
"\n",
"}",
"\n",
"r",
".",
"params",
".",
"Add",
"(",
"string",
"(",
"key",
")",
",",
"value",
")",
"\n",
"return",
"r",
"\n",
"}"
] |
// QueryOption adds specified options to query.
|
[
"QueryOption",
"adds",
"specified",
"options",
"to",
"query",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L118-L127
|
143,777 |
libopenstorage/openstorage
|
api/client/request.go
|
QueryOptionLabel
|
func (r *Request) QueryOptionLabel(key string, labels map[string]string) *Request {
if r.err != nil {
return r
}
if b, err := json.Marshal(labels); err != nil {
r.err = err
} else {
if r.params == nil {
r.params = make(url.Values)
}
r.params.Add(string(key), string(b))
}
return r
}
|
go
|
func (r *Request) QueryOptionLabel(key string, labels map[string]string) *Request {
if r.err != nil {
return r
}
if b, err := json.Marshal(labels); err != nil {
r.err = err
} else {
if r.params == nil {
r.params = make(url.Values)
}
r.params.Add(string(key), string(b))
}
return r
}
|
[
"func",
"(",
"r",
"*",
"Request",
")",
"QueryOptionLabel",
"(",
"key",
"string",
",",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"Request",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"r",
"\n",
"}",
"\n",
"if",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"labels",
")",
";",
"err",
"!=",
"nil",
"{",
"r",
".",
"err",
"=",
"err",
"\n",
"}",
"else",
"{",
"if",
"r",
".",
"params",
"==",
"nil",
"{",
"r",
".",
"params",
"=",
"make",
"(",
"url",
".",
"Values",
")",
"\n",
"}",
"\n",
"r",
".",
"params",
".",
"Add",
"(",
"string",
"(",
"key",
")",
",",
"string",
"(",
"b",
")",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// QueryOptionLabel adds specified label to query.
|
[
"QueryOptionLabel",
"adds",
"specified",
"label",
"to",
"query",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L130-L143
|
143,778 |
libopenstorage/openstorage
|
api/client/request.go
|
Body
|
func (r *Request) Body(v interface{}) *Request {
var err error
if r.err != nil {
return r
}
r.body, err = json.Marshal(v)
if err != nil {
r.err = err
return r
}
return r
}
|
go
|
func (r *Request) Body(v interface{}) *Request {
var err error
if r.err != nil {
return r
}
r.body, err = json.Marshal(v)
if err != nil {
r.err = err
return r
}
return r
}
|
[
"func",
"(",
"r",
"*",
"Request",
")",
"Body",
"(",
"v",
"interface",
"{",
"}",
")",
"*",
"Request",
"{",
"var",
"err",
"error",
"\n",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"r",
"\n",
"}",
"\n",
"r",
".",
"body",
",",
"err",
"=",
"json",
".",
"Marshal",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r",
".",
"err",
"=",
"err",
"\n",
"return",
"r",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] |
// Body sets the request Body.
|
[
"Body",
"sets",
"the",
"request",
"Body",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L165-L176
|
143,779 |
libopenstorage/openstorage
|
api/client/request.go
|
headerVal
|
func headerVal(key string, resp *http.Response) (int, bool) {
if h := resp.Header.Get(key); len(h) > 0 {
if i, err := strconv.Atoi(h); err == nil {
return i, true
}
}
return 0, false
}
|
go
|
func headerVal(key string, resp *http.Response) (int, bool) {
if h := resp.Header.Get(key); len(h) > 0 {
if i, err := strconv.Atoi(h); err == nil {
return i, true
}
}
return 0, false
}
|
[
"func",
"headerVal",
"(",
"key",
"string",
",",
"resp",
"*",
"http",
".",
"Response",
")",
"(",
"int",
",",
"bool",
")",
"{",
"if",
"h",
":=",
"resp",
".",
"Header",
".",
"Get",
"(",
"key",
")",
";",
"len",
"(",
"h",
")",
">",
"0",
"{",
"if",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"h",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"i",
",",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"0",
",",
"false",
"\n",
"}"
] |
// headerVal for key as an int. Return false if header is not present or valid.
|
[
"headerVal",
"for",
"key",
"as",
"an",
"int",
".",
"Return",
"false",
"if",
"header",
"is",
"not",
"present",
"or",
"valid",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L209-L216
|
143,780 |
libopenstorage/openstorage
|
api/client/request.go
|
Do
|
func (r *Request) Do() *Response {
var (
err error
req *http.Request
resp *http.Response
url string
body []byte
)
if r.err != nil {
return &Response{err: r.err}
}
url = r.URL().String()
req, err = http.NewRequest(r.verb, url, bytes.NewBuffer(r.body))
if err != nil {
return &Response{err: err}
}
if r.headers == nil {
r.headers = http.Header{}
}
req.Header = r.headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Date", time.Now().String())
if len(r.authstring) > 0 {
if auth.IsJwtToken(r.authstring) {
req.Header.Set("Authorization", "bearer "+r.authstring)
} else {
req.Header.Set("Authorization", "Basic "+r.authstring)
}
}
if len(r.accesstoken) > 0 {
req.Header.Set("Access-Token", r.accesstoken)
}
start := time.Now()
attemptNum := 0
for {
if resp, err = r.client.Do(req); err != nil {
return &Response{err: err}
}
if time.Since(start) >= maxRetryDuration ||
resp.StatusCode != http.StatusServiceUnavailable {
break
}
attemptNum++
handleServiceUnavailable(resp, attemptNum)
}
if resp.Body != nil {
defer resp.Body.Close()
if body, err = ioutil.ReadAll(resp.Body); err != nil {
return &Response{err: err}
}
}
return &Response{
status: resp.Status,
statusCode: resp.StatusCode,
body: body,
err: parseHTTPStatus(resp, body),
}
}
|
go
|
func (r *Request) Do() *Response {
var (
err error
req *http.Request
resp *http.Response
url string
body []byte
)
if r.err != nil {
return &Response{err: r.err}
}
url = r.URL().String()
req, err = http.NewRequest(r.verb, url, bytes.NewBuffer(r.body))
if err != nil {
return &Response{err: err}
}
if r.headers == nil {
r.headers = http.Header{}
}
req.Header = r.headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Date", time.Now().String())
if len(r.authstring) > 0 {
if auth.IsJwtToken(r.authstring) {
req.Header.Set("Authorization", "bearer "+r.authstring)
} else {
req.Header.Set("Authorization", "Basic "+r.authstring)
}
}
if len(r.accesstoken) > 0 {
req.Header.Set("Access-Token", r.accesstoken)
}
start := time.Now()
attemptNum := 0
for {
if resp, err = r.client.Do(req); err != nil {
return &Response{err: err}
}
if time.Since(start) >= maxRetryDuration ||
resp.StatusCode != http.StatusServiceUnavailable {
break
}
attemptNum++
handleServiceUnavailable(resp, attemptNum)
}
if resp.Body != nil {
defer resp.Body.Close()
if body, err = ioutil.ReadAll(resp.Body); err != nil {
return &Response{err: err}
}
}
return &Response{
status: resp.Status,
statusCode: resp.StatusCode,
body: body,
err: parseHTTPStatus(resp, body),
}
}
|
[
"func",
"(",
"r",
"*",
"Request",
")",
"Do",
"(",
")",
"*",
"Response",
"{",
"var",
"(",
"err",
"error",
"\n",
"req",
"*",
"http",
".",
"Request",
"\n",
"resp",
"*",
"http",
".",
"Response",
"\n",
"url",
"string",
"\n",
"body",
"[",
"]",
"byte",
"\n",
")",
"\n\n",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"&",
"Response",
"{",
"err",
":",
"r",
".",
"err",
"}",
"\n",
"}",
"\n",
"url",
"=",
"r",
".",
"URL",
"(",
")",
".",
"String",
"(",
")",
"\n",
"req",
",",
"err",
"=",
"http",
".",
"NewRequest",
"(",
"r",
".",
"verb",
",",
"url",
",",
"bytes",
".",
"NewBuffer",
"(",
"r",
".",
"body",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"&",
"Response",
"{",
"err",
":",
"err",
"}",
"\n",
"}",
"\n",
"if",
"r",
".",
"headers",
"==",
"nil",
"{",
"r",
".",
"headers",
"=",
"http",
".",
"Header",
"{",
"}",
"\n",
"}",
"\n\n",
"req",
".",
"Header",
"=",
"r",
".",
"headers",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"time",
".",
"Now",
"(",
")",
".",
"String",
"(",
")",
")",
"\n\n",
"if",
"len",
"(",
"r",
".",
"authstring",
")",
">",
"0",
"{",
"if",
"auth",
".",
"IsJwtToken",
"(",
"r",
".",
"authstring",
")",
"{",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"r",
".",
"authstring",
")",
"\n",
"}",
"else",
"{",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"r",
".",
"authstring",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"r",
".",
"accesstoken",
")",
">",
"0",
"{",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"r",
".",
"accesstoken",
")",
"\n",
"}",
"\n\n",
"start",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"attemptNum",
":=",
"0",
"\n",
"for",
"{",
"if",
"resp",
",",
"err",
"=",
"r",
".",
"client",
".",
"Do",
"(",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"&",
"Response",
"{",
"err",
":",
"err",
"}",
"\n",
"}",
"\n\n",
"if",
"time",
".",
"Since",
"(",
"start",
")",
">=",
"maxRetryDuration",
"||",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusServiceUnavailable",
"{",
"break",
"\n",
"}",
"\n",
"attemptNum",
"++",
"\n",
"handleServiceUnavailable",
"(",
"resp",
",",
"attemptNum",
")",
"\n",
"}",
"\n\n",
"if",
"resp",
".",
"Body",
"!=",
"nil",
"{",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"body",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"&",
"Response",
"{",
"err",
":",
"err",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"&",
"Response",
"{",
"status",
":",
"resp",
".",
"Status",
",",
"statusCode",
":",
"resp",
".",
"StatusCode",
",",
"body",
":",
"body",
",",
"err",
":",
"parseHTTPStatus",
"(",
"resp",
",",
"body",
")",
",",
"}",
"\n",
"}"
] |
// Do executes the request and returns a Response.
|
[
"Do",
"executes",
"the",
"request",
"and",
"returns",
"a",
"Response",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L235-L300
|
143,781 |
libopenstorage/openstorage
|
api/client/request.go
|
Unmarshal
|
func (r Response) Unmarshal(v interface{}) error {
if r.err != nil {
return r.err
}
return json.Unmarshal(r.body, v)
}
|
go
|
func (r Response) Unmarshal(v interface{}) error {
if r.err != nil {
return r.err
}
return json.Unmarshal(r.body, v)
}
|
[
"func",
"(",
"r",
"Response",
")",
"Unmarshal",
"(",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"r",
".",
"err",
"!=",
"nil",
"{",
"return",
"r",
".",
"err",
"\n",
"}",
"\n",
"return",
"json",
".",
"Unmarshal",
"(",
"r",
".",
"body",
",",
"v",
")",
"\n",
"}"
] |
// Unmarshal result into obj
|
[
"Unmarshal",
"result",
"into",
"obj"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L326-L331
|
143,782 |
libopenstorage/openstorage
|
api/client/request.go
|
FormatError
|
func (r Response) FormatError() error {
if len(r.body) == 0 {
return fmt.Errorf("Error: %v", r.err)
}
return fmt.Errorf("%v", strings.TrimSpace(string(r.body)))
}
|
go
|
func (r Response) FormatError() error {
if len(r.body) == 0 {
return fmt.Errorf("Error: %v", r.err)
}
return fmt.Errorf("%v", strings.TrimSpace(string(r.body)))
}
|
[
"func",
"(",
"r",
"Response",
")",
"FormatError",
"(",
")",
"error",
"{",
"if",
"len",
"(",
"r",
".",
"body",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"r",
".",
"err",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"strings",
".",
"TrimSpace",
"(",
"string",
"(",
"r",
".",
"body",
")",
")",
")",
"\n",
"}"
] |
// FormatError formats the error
|
[
"FormatError",
"formats",
"the",
"error"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/api/client/request.go#L339-L344
|
143,783 |
libopenstorage/openstorage
|
pkg/mount/bind_mount.go
|
NewBindMounter
|
func NewBindMounter(
rootSubstrings []string,
mountImpl MountImpl,
allowedDirs []string,
trashLocation string,
) (*bindMounter, error) {
b := &bindMounter{
Mounter: Mounter{
mountImpl: mountImpl,
mounts: make(DeviceMap),
paths: make(PathMap),
allowedDirs: allowedDirs,
kl: keylock.New(),
trashLocation: trashLocation,
},
}
if err := b.Load(rootSubstrings); err != nil {
return nil, err
}
return b, nil
}
|
go
|
func NewBindMounter(
rootSubstrings []string,
mountImpl MountImpl,
allowedDirs []string,
trashLocation string,
) (*bindMounter, error) {
b := &bindMounter{
Mounter: Mounter{
mountImpl: mountImpl,
mounts: make(DeviceMap),
paths: make(PathMap),
allowedDirs: allowedDirs,
kl: keylock.New(),
trashLocation: trashLocation,
},
}
if err := b.Load(rootSubstrings); err != nil {
return nil, err
}
return b, nil
}
|
[
"func",
"NewBindMounter",
"(",
"rootSubstrings",
"[",
"]",
"string",
",",
"mountImpl",
"MountImpl",
",",
"allowedDirs",
"[",
"]",
"string",
",",
"trashLocation",
"string",
",",
")",
"(",
"*",
"bindMounter",
",",
"error",
")",
"{",
"b",
":=",
"&",
"bindMounter",
"{",
"Mounter",
":",
"Mounter",
"{",
"mountImpl",
":",
"mountImpl",
",",
"mounts",
":",
"make",
"(",
"DeviceMap",
")",
",",
"paths",
":",
"make",
"(",
"PathMap",
")",
",",
"allowedDirs",
":",
"allowedDirs",
",",
"kl",
":",
"keylock",
".",
"New",
"(",
")",
",",
"trashLocation",
":",
"trashLocation",
",",
"}",
",",
"}",
"\n",
"if",
"err",
":=",
"b",
".",
"Load",
"(",
"rootSubstrings",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"b",
",",
"nil",
"\n",
"}"
] |
// NewBindMounter returns a new bindMounter
|
[
"NewBindMounter",
"returns",
"a",
"new",
"bindMounter"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/mount/bind_mount.go#L22-L42
|
143,784 |
libopenstorage/openstorage
|
pkg/options/options.go
|
IsBoolOptionSet
|
func IsBoolOptionSet(options map[string]string, key string) bool {
if options != nil {
if value, ok := options[key]; ok {
if b, err := strconv.ParseBool(value); err == nil {
return b
}
}
}
return false
}
|
go
|
func IsBoolOptionSet(options map[string]string, key string) bool {
if options != nil {
if value, ok := options[key]; ok {
if b, err := strconv.ParseBool(value); err == nil {
return b
}
}
}
return false
}
|
[
"func",
"IsBoolOptionSet",
"(",
"options",
"map",
"[",
"string",
"]",
"string",
",",
"key",
"string",
")",
"bool",
"{",
"if",
"options",
"!=",
"nil",
"{",
"if",
"value",
",",
"ok",
":=",
"options",
"[",
"key",
"]",
";",
"ok",
"{",
"if",
"b",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"value",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"b",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// IsBoolOptionSet checks if a boolean option key is set
|
[
"IsBoolOptionSet",
"checks",
"if",
"a",
"boolean",
"option",
"key",
"is",
"set"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/options/options.go#L57-L67
|
143,785 |
libopenstorage/openstorage
|
pkg/options/options.go
|
NewVolumeAttachOptions
|
func NewVolumeAttachOptions(options map[string]string) *api.SdkVolumeAttachOptions {
return &api.SdkVolumeAttachOptions{
SecretName: options[OptionsSecret],
SecretKey: options[OptionsSecretKey],
SecretContext: options[OptionsSecretContext],
}
}
|
go
|
func NewVolumeAttachOptions(options map[string]string) *api.SdkVolumeAttachOptions {
return &api.SdkVolumeAttachOptions{
SecretName: options[OptionsSecret],
SecretKey: options[OptionsSecretKey],
SecretContext: options[OptionsSecretContext],
}
}
|
[
"func",
"NewVolumeAttachOptions",
"(",
"options",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"api",
".",
"SdkVolumeAttachOptions",
"{",
"return",
"&",
"api",
".",
"SdkVolumeAttachOptions",
"{",
"SecretName",
":",
"options",
"[",
"OptionsSecret",
"]",
",",
"SecretKey",
":",
"options",
"[",
"OptionsSecretKey",
"]",
",",
"SecretContext",
":",
"options",
"[",
"OptionsSecretContext",
"]",
",",
"}",
"\n",
"}"
] |
// NewVolumeAttachOptions converts a map of options to api.SdkVolumeAttachOptions
|
[
"NewVolumeAttachOptions",
"converts",
"a",
"map",
"of",
"options",
"to",
"api",
".",
"SdkVolumeAttachOptions"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/options/options.go#L70-L76
|
143,786 |
libopenstorage/openstorage
|
pkg/options/options.go
|
NewVolumeUnmountOptions
|
func NewVolumeUnmountOptions(options map[string]string) *api.SdkVolumeUnmountOptions {
return &api.SdkVolumeUnmountOptions{
DeleteMountPath: IsBoolOptionSet(options, OptionsDeleteAfterUnmount),
NoDelayBeforeDeletingMountPath: IsBoolOptionSet(options, OptionsWaitBeforeDelete),
}
}
|
go
|
func NewVolumeUnmountOptions(options map[string]string) *api.SdkVolumeUnmountOptions {
return &api.SdkVolumeUnmountOptions{
DeleteMountPath: IsBoolOptionSet(options, OptionsDeleteAfterUnmount),
NoDelayBeforeDeletingMountPath: IsBoolOptionSet(options, OptionsWaitBeforeDelete),
}
}
|
[
"func",
"NewVolumeUnmountOptions",
"(",
"options",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"api",
".",
"SdkVolumeUnmountOptions",
"{",
"return",
"&",
"api",
".",
"SdkVolumeUnmountOptions",
"{",
"DeleteMountPath",
":",
"IsBoolOptionSet",
"(",
"options",
",",
"OptionsDeleteAfterUnmount",
")",
",",
"NoDelayBeforeDeletingMountPath",
":",
"IsBoolOptionSet",
"(",
"options",
",",
"OptionsWaitBeforeDelete",
")",
",",
"}",
"\n",
"}"
] |
// NewVolumeUnmountOptions converts a map of options to api.SdkVolumeUnmounOptions
|
[
"NewVolumeUnmountOptions",
"converts",
"a",
"map",
"of",
"options",
"to",
"api",
".",
"SdkVolumeUnmounOptions"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/options/options.go#L79-L84
|
143,787 |
libopenstorage/openstorage
|
graph/drivers/chainfs/chainfs.go
|
Create
|
func (d *Driver) Create(id string, parent string, ml string, storageOpts map[string]string) error {
if parent != "" {
logrus.Infof("Creating layer %s with parent %s", id, parent)
} else {
logrus.Infof("Creating parent layer %s", id)
}
cID := C.CString(id)
cParent := C.CString(parent)
ret, err := C.create_layer(cID, cParent)
if int(ret) != 0 {
logrus.Warnf("Error while creating layer %s", id)
return err
}
return nil
}
|
go
|
func (d *Driver) Create(id string, parent string, ml string, storageOpts map[string]string) error {
if parent != "" {
logrus.Infof("Creating layer %s with parent %s", id, parent)
} else {
logrus.Infof("Creating parent layer %s", id)
}
cID := C.CString(id)
cParent := C.CString(parent)
ret, err := C.create_layer(cID, cParent)
if int(ret) != 0 {
logrus.Warnf("Error while creating layer %s", id)
return err
}
return nil
}
|
[
"func",
"(",
"d",
"*",
"Driver",
")",
"Create",
"(",
"id",
"string",
",",
"parent",
"string",
",",
"ml",
"string",
",",
"storageOpts",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"if",
"parent",
"!=",
"\"",
"\"",
"{",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"id",
",",
"parent",
")",
"\n",
"}",
"else",
"{",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n\n",
"cID",
":=",
"C",
".",
"CString",
"(",
"id",
")",
"\n",
"cParent",
":=",
"C",
".",
"CString",
"(",
"parent",
")",
"\n\n",
"ret",
",",
"err",
":=",
"C",
".",
"create_layer",
"(",
"cID",
",",
"cParent",
")",
"\n",
"if",
"int",
"(",
"ret",
")",
"!=",
"0",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Create creates a new, empty, filesystem layer with the
// specified id and parent and mountLabel. Parent and mountLabel may be "".
|
[
"Create",
"creates",
"a",
"new",
"empty",
"filesystem",
"layer",
"with",
"the",
"specified",
"id",
"and",
"parent",
"and",
"mountLabel",
".",
"Parent",
"and",
"mountLabel",
"may",
"be",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/chainfs/chainfs.go#L80-L97
|
143,788 |
libopenstorage/openstorage
|
graph/drivers/chainfs/chainfs.go
|
Remove
|
func (d *Driver) Remove(id string) error {
logrus.Infof("Removing layer %s", id)
cID := C.CString(id)
ret, err := C.remove_layer(cID)
if int(ret) != 0 {
logrus.Warnf("Error while removing layer %s", id)
return err
}
return nil
}
|
go
|
func (d *Driver) Remove(id string) error {
logrus.Infof("Removing layer %s", id)
cID := C.CString(id)
ret, err := C.remove_layer(cID)
if int(ret) != 0 {
logrus.Warnf("Error while removing layer %s", id)
return err
}
return nil
}
|
[
"func",
"(",
"d",
"*",
"Driver",
")",
"Remove",
"(",
"id",
"string",
")",
"error",
"{",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"id",
")",
"\n\n",
"cID",
":=",
"C",
".",
"CString",
"(",
"id",
")",
"\n",
"ret",
",",
"err",
":=",
"C",
".",
"remove_layer",
"(",
"cID",
")",
"\n",
"if",
"int",
"(",
"ret",
")",
"!=",
"0",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Remove attempts to remove the filesystem layer with this id.
|
[
"Remove",
"attempts",
"to",
"remove",
"the",
"filesystem",
"layer",
"with",
"this",
"id",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/chainfs/chainfs.go#L100-L111
|
143,789 |
libopenstorage/openstorage
|
graph/drivers/chainfs/chainfs.go
|
Get
|
func (d *Driver) Get(id, mountLabel string) (string, error) {
cID := C.CString(id)
ret, err := C.alloc_chainfs(cID)
if int(ret) != 0 {
logrus.Warnf("Error while creating a chain FS for %s", id)
return "", err
} else {
logrus.Debugf("Created a chain FS for %s", id)
chainPath := path.Join(virtPath, id)
return chainPath, err
}
}
|
go
|
func (d *Driver) Get(id, mountLabel string) (string, error) {
cID := C.CString(id)
ret, err := C.alloc_chainfs(cID)
if int(ret) != 0 {
logrus.Warnf("Error while creating a chain FS for %s", id)
return "", err
} else {
logrus.Debugf("Created a chain FS for %s", id)
chainPath := path.Join(virtPath, id)
return chainPath, err
}
}
|
[
"func",
"(",
"d",
"*",
"Driver",
")",
"Get",
"(",
"id",
",",
"mountLabel",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"cID",
":=",
"C",
".",
"CString",
"(",
"id",
")",
"\n\n",
"ret",
",",
"err",
":=",
"C",
".",
"alloc_chainfs",
"(",
"cID",
")",
"\n",
"if",
"int",
"(",
"ret",
")",
"!=",
"0",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"else",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"chainPath",
":=",
"path",
".",
"Join",
"(",
"virtPath",
",",
"id",
")",
"\n",
"return",
"chainPath",
",",
"err",
"\n",
"}",
"\n",
"}"
] |
// Get returns the mountpoint for the layered filesystem referred
// to by this id. You can optionally specify a mountLabel or "".
// Returns the absolute path to the mounted layered filesystem.
|
[
"Get",
"returns",
"the",
"mountpoint",
"for",
"the",
"layered",
"filesystem",
"referred",
"to",
"by",
"this",
"id",
".",
"You",
"can",
"optionally",
"specify",
"a",
"mountLabel",
"or",
".",
"Returns",
"the",
"absolute",
"path",
"to",
"the",
"mounted",
"layered",
"filesystem",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/chainfs/chainfs.go#L122-L134
|
143,790 |
libopenstorage/openstorage
|
graph/drivers/chainfs/chainfs.go
|
Exists
|
func (d *Driver) Exists(id string) bool {
path := path.Join(virtPath, id)
_, err := os.Stat(path)
if err == nil {
return true
} else {
return false
}
}
|
go
|
func (d *Driver) Exists(id string) bool {
path := path.Join(virtPath, id)
_, err := os.Stat(path)
if err == nil {
return true
} else {
return false
}
}
|
[
"func",
"(",
"d",
"*",
"Driver",
")",
"Exists",
"(",
"id",
"string",
")",
"bool",
"{",
"path",
":=",
"path",
".",
"Join",
"(",
"virtPath",
",",
"id",
")",
"\n\n",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"path",
")",
"\n\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"else",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}"
] |
// Exists returns whether a filesystem layer with the specified
// ID exists on this driver.
// All cache entries exist.
|
[
"Exists",
"returns",
"whether",
"a",
"filesystem",
"layer",
"with",
"the",
"specified",
"ID",
"exists",
"on",
"this",
"driver",
".",
"All",
"cache",
"entries",
"exist",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/chainfs/chainfs.go#L152-L162
|
143,791 |
libopenstorage/openstorage
|
graph/drivers/chainfs/chainfs.go
|
ApplyDiff
|
func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size int64, err error) {
dir := path.Join(virtPath, id)
// dir := path.Join("/tmp/chainfs/", id)
logrus.Infof("Applying diff at path %s\n", dir)
if err := chrootarchive.UntarUncompressed(diff, dir, nil); err != nil {
logrus.Warnf("Error while applying diff to %s: %v", id, err)
return 0, err
}
// show invalid whiteouts warning.
files, err := ioutil.ReadDir(path.Join(dir, archive.WhiteoutLinkDir))
if err == nil && len(files) > 0 {
logrus.Warnf("Archive contains aufs hardlink references that are not supported.")
}
return d.DiffSize(id, parent)
}
|
go
|
func (d *Driver) ApplyDiff(id string, parent string, diff archive.Reader) (size int64, err error) {
dir := path.Join(virtPath, id)
// dir := path.Join("/tmp/chainfs/", id)
logrus.Infof("Applying diff at path %s\n", dir)
if err := chrootarchive.UntarUncompressed(diff, dir, nil); err != nil {
logrus.Warnf("Error while applying diff to %s: %v", id, err)
return 0, err
}
// show invalid whiteouts warning.
files, err := ioutil.ReadDir(path.Join(dir, archive.WhiteoutLinkDir))
if err == nil && len(files) > 0 {
logrus.Warnf("Archive contains aufs hardlink references that are not supported.")
}
return d.DiffSize(id, parent)
}
|
[
"func",
"(",
"d",
"*",
"Driver",
")",
"ApplyDiff",
"(",
"id",
"string",
",",
"parent",
"string",
",",
"diff",
"archive",
".",
"Reader",
")",
"(",
"size",
"int64",
",",
"err",
"error",
")",
"{",
"dir",
":=",
"path",
".",
"Join",
"(",
"virtPath",
",",
"id",
")",
"\n",
"// dir := path.Join(\"/tmp/chainfs/\", id)",
"logrus",
".",
"Infof",
"(",
"\"",
"\\n",
"\"",
",",
"dir",
")",
"\n\n",
"if",
"err",
":=",
"chrootarchive",
".",
"UntarUncompressed",
"(",
"diff",
",",
"dir",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"id",
",",
"err",
")",
"\n",
"return",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"// show invalid whiteouts warning.",
"files",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"path",
".",
"Join",
"(",
"dir",
",",
"archive",
".",
"WhiteoutLinkDir",
")",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"len",
"(",
"files",
")",
">",
"0",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"d",
".",
"DiffSize",
"(",
"id",
",",
"parent",
")",
"\n",
"}"
] |
// ApplyDiff extracts the changeset from the given diff into the
// layer with the specified id and parent, returning the size of the
// new layer in bytes.
// The archive.Reader must be an uncompressed stream.
|
[
"ApplyDiff",
"extracts",
"the",
"changeset",
"from",
"the",
"given",
"diff",
"into",
"the",
"layer",
"with",
"the",
"specified",
"id",
"and",
"parent",
"returning",
"the",
"size",
"of",
"the",
"new",
"layer",
"in",
"bytes",
".",
"The",
"archive",
".",
"Reader",
"must",
"be",
"an",
"uncompressed",
"stream",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/chainfs/chainfs.go#L168-L186
|
143,792 |
libopenstorage/openstorage
|
pkg/jsonpb/jsonpb.go
|
RegisterSimpleStringEnum
|
func RegisterSimpleStringEnum(typeName string, typePrefix string, valueMap map[string]int32) {
if _, ok := simpleStringValueMaps[typeName]; ok {
panic("jsonpb: duplicate enum registered: " + typeName)
}
m := make(map[string]int32)
for key, value := range valueMap {
m[strings.TrimPrefix(strings.ToLower(key), fmt.Sprintf("%s_", strings.ToLower(typePrefix)))] = value
}
simpleStringValueMaps[typeName] = m
}
|
go
|
func RegisterSimpleStringEnum(typeName string, typePrefix string, valueMap map[string]int32) {
if _, ok := simpleStringValueMaps[typeName]; ok {
panic("jsonpb: duplicate enum registered: " + typeName)
}
m := make(map[string]int32)
for key, value := range valueMap {
m[strings.TrimPrefix(strings.ToLower(key), fmt.Sprintf("%s_", strings.ToLower(typePrefix)))] = value
}
simpleStringValueMaps[typeName] = m
}
|
[
"func",
"RegisterSimpleStringEnum",
"(",
"typeName",
"string",
",",
"typePrefix",
"string",
",",
"valueMap",
"map",
"[",
"string",
"]",
"int32",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"simpleStringValueMaps",
"[",
"typeName",
"]",
";",
"ok",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"typeName",
")",
"\n",
"}",
"\n",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"int32",
")",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"valueMap",
"{",
"m",
"[",
"strings",
".",
"TrimPrefix",
"(",
"strings",
".",
"ToLower",
"(",
"key",
")",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"strings",
".",
"ToLower",
"(",
"typePrefix",
")",
")",
")",
"]",
"=",
"value",
"\n",
"}",
"\n",
"simpleStringValueMaps",
"[",
"typeName",
"]",
"=",
"m",
"\n",
"}"
] |
// RegisterSimpleStringEnum registers a simple string value map.
|
[
"RegisterSimpleStringEnum",
"registers",
"a",
"simple",
"string",
"value",
"map",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/jsonpb/jsonpb.go#L64-L73
|
143,793 |
libopenstorage/openstorage
|
pkg/jsonpb/jsonpb.go
|
UnmarshalString
|
func UnmarshalString(str string, pb proto.Message) error {
return Unmarshal(strings.NewReader(str), pb)
}
|
go
|
func UnmarshalString(str string, pb proto.Message) error {
return Unmarshal(strings.NewReader(str), pb)
}
|
[
"func",
"UnmarshalString",
"(",
"str",
"string",
",",
"pb",
"proto",
".",
"Message",
")",
"error",
"{",
"return",
"Unmarshal",
"(",
"strings",
".",
"NewReader",
"(",
"str",
")",
",",
"pb",
")",
"\n",
"}"
] |
// UnmarshalString will populate the fields of a protocol buffer based
// on a JSON string. This function is lenient and will decode any options
// permutations of the related Marshaler.
|
[
"UnmarshalString",
"will",
"populate",
"the",
"fields",
"of",
"a",
"protocol",
"buffer",
"based",
"on",
"a",
"JSON",
"string",
".",
"This",
"function",
"is",
"lenient",
"and",
"will",
"decode",
"any",
"options",
"permutations",
"of",
"the",
"related",
"Marshaler",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/jsonpb/jsonpb.go#L391-L393
|
143,794 |
libopenstorage/openstorage
|
pkg/jsonpb/jsonpb.go
|
jsonProperties
|
func jsonProperties(f reflect.StructField) *proto.Properties {
var prop proto.Properties
prop.Init(f.Type, f.Name, f.Tag.Get("protobuf"), &f)
return &prop
}
|
go
|
func jsonProperties(f reflect.StructField) *proto.Properties {
var prop proto.Properties
prop.Init(f.Type, f.Name, f.Tag.Get("protobuf"), &f)
return &prop
}
|
[
"func",
"jsonProperties",
"(",
"f",
"reflect",
".",
"StructField",
")",
"*",
"proto",
".",
"Properties",
"{",
"var",
"prop",
"proto",
".",
"Properties",
"\n",
"prop",
".",
"Init",
"(",
"f",
".",
"Type",
",",
"f",
".",
"Name",
",",
"f",
".",
"Tag",
".",
"Get",
"(",
"\"",
"\"",
")",
",",
"&",
"f",
")",
"\n",
"return",
"&",
"prop",
"\n",
"}"
] |
// jsonProperties returns parsed proto.Properties for the field.
|
[
"jsonProperties",
"returns",
"parsed",
"proto",
".",
"Properties",
"for",
"the",
"field",
"."
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/pkg/jsonpb/jsonpb.go#L554-L558
|
143,795 |
libopenstorage/openstorage
|
graph/drivers/layer0/layer0.go
|
Create
|
func (l *Layer0) Create(id string, parent string, mountLabel string, storageOpts map[string]string) error {
id, vol, err := l.create(id, parent)
if err != nil {
return err
}
err = l.Driver.Create(id, parent, mountLabel, storageOpts)
if err != nil || vol == nil {
return err
}
// This is layer0. Restore saved upper dir, if one exists.
savedUpper := path.Join(vol.path, "upper")
if _, err := os.Stat(savedUpper); err != nil {
// It's not an error if didn't have a saved upper
return nil
}
// We found a saved upper, restore to newly created upper.
upperDir := path.Join(path.Join(l.home, id), "upper")
os.RemoveAll(upperDir)
return os.Rename(savedUpper, upperDir)
}
|
go
|
func (l *Layer0) Create(id string, parent string, mountLabel string, storageOpts map[string]string) error {
id, vol, err := l.create(id, parent)
if err != nil {
return err
}
err = l.Driver.Create(id, parent, mountLabel, storageOpts)
if err != nil || vol == nil {
return err
}
// This is layer0. Restore saved upper dir, if one exists.
savedUpper := path.Join(vol.path, "upper")
if _, err := os.Stat(savedUpper); err != nil {
// It's not an error if didn't have a saved upper
return nil
}
// We found a saved upper, restore to newly created upper.
upperDir := path.Join(path.Join(l.home, id), "upper")
os.RemoveAll(upperDir)
return os.Rename(savedUpper, upperDir)
}
|
[
"func",
"(",
"l",
"*",
"Layer0",
")",
"Create",
"(",
"id",
"string",
",",
"parent",
"string",
",",
"mountLabel",
"string",
",",
"storageOpts",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"id",
",",
"vol",
",",
"err",
":=",
"l",
".",
"create",
"(",
"id",
",",
"parent",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"l",
".",
"Driver",
".",
"Create",
"(",
"id",
",",
"parent",
",",
"mountLabel",
",",
"storageOpts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"||",
"vol",
"==",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// This is layer0. Restore saved upper dir, if one exists.",
"savedUpper",
":=",
"path",
".",
"Join",
"(",
"vol",
".",
"path",
",",
"\"",
"\"",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"savedUpper",
")",
";",
"err",
"!=",
"nil",
"{",
"// It's not an error if didn't have a saved upper",
"return",
"nil",
"\n",
"}",
"\n",
"// We found a saved upper, restore to newly created upper.",
"upperDir",
":=",
"path",
".",
"Join",
"(",
"path",
".",
"Join",
"(",
"l",
".",
"home",
",",
"id",
")",
",",
"\"",
"\"",
")",
"\n",
"os",
".",
"RemoveAll",
"(",
"upperDir",
")",
"\n",
"return",
"os",
".",
"Rename",
"(",
"savedUpper",
",",
"upperDir",
")",
"\n",
"}"
] |
// Create creates a new and empty filesystem layer
|
[
"Create",
"creates",
"a",
"new",
"and",
"empty",
"filesystem",
"layer"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/layer0/layer0.go#L214-L233
|
143,796 |
libopenstorage/openstorage
|
graph/drivers/layer0/layer0.go
|
Remove
|
func (l *Layer0) Remove(id string) error {
if !l.isLayer0(id) {
return l.Driver.Remove(l.realID(id))
}
l.Lock()
defer l.Unlock()
var err error
v, ok := l.volumes[id]
if ok {
atomic.AddInt32(&v.ref, -1)
if v.ref == 0 {
// Save the upper dir and blow away the rest.
upperDir := path.Join(path.Join(l.home, l.realID(id)), "upper")
err := os.Rename(upperDir, path.Join(v.path, "upper"))
if err != nil {
logrus.Warnf("Failed in rename(%v): %v", id, err)
}
l.Driver.Remove(l.realID(id))
opts := make(map[string]string)
opts[options.OptionsDeleteAfterUnmount] = "true"
err = l.volDriver.Unmount(v.volumeID, v.path, opts)
if l.volDriver.Type() == api.DriverType_DRIVER_TYPE_BLOCK {
_ = l.volDriver.Detach(v.volumeID, nil)
}
err = os.RemoveAll(v.path)
delete(l.volumes, v.id)
}
} else {
logrus.Warnf("Failed to find layer0 vol for id %v", id)
}
return err
}
|
go
|
func (l *Layer0) Remove(id string) error {
if !l.isLayer0(id) {
return l.Driver.Remove(l.realID(id))
}
l.Lock()
defer l.Unlock()
var err error
v, ok := l.volumes[id]
if ok {
atomic.AddInt32(&v.ref, -1)
if v.ref == 0 {
// Save the upper dir and blow away the rest.
upperDir := path.Join(path.Join(l.home, l.realID(id)), "upper")
err := os.Rename(upperDir, path.Join(v.path, "upper"))
if err != nil {
logrus.Warnf("Failed in rename(%v): %v", id, err)
}
l.Driver.Remove(l.realID(id))
opts := make(map[string]string)
opts[options.OptionsDeleteAfterUnmount] = "true"
err = l.volDriver.Unmount(v.volumeID, v.path, opts)
if l.volDriver.Type() == api.DriverType_DRIVER_TYPE_BLOCK {
_ = l.volDriver.Detach(v.volumeID, nil)
}
err = os.RemoveAll(v.path)
delete(l.volumes, v.id)
}
} else {
logrus.Warnf("Failed to find layer0 vol for id %v", id)
}
return err
}
|
[
"func",
"(",
"l",
"*",
"Layer0",
")",
"Remove",
"(",
"id",
"string",
")",
"error",
"{",
"if",
"!",
"l",
".",
"isLayer0",
"(",
"id",
")",
"{",
"return",
"l",
".",
"Driver",
".",
"Remove",
"(",
"l",
".",
"realID",
"(",
"id",
")",
")",
"\n",
"}",
"\n",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"v",
",",
"ok",
":=",
"l",
".",
"volumes",
"[",
"id",
"]",
"\n\n",
"if",
"ok",
"{",
"atomic",
".",
"AddInt32",
"(",
"&",
"v",
".",
"ref",
",",
"-",
"1",
")",
"\n",
"if",
"v",
".",
"ref",
"==",
"0",
"{",
"// Save the upper dir and blow away the rest.",
"upperDir",
":=",
"path",
".",
"Join",
"(",
"path",
".",
"Join",
"(",
"l",
".",
"home",
",",
"l",
".",
"realID",
"(",
"id",
")",
")",
",",
"\"",
"\"",
")",
"\n",
"err",
":=",
"os",
".",
"Rename",
"(",
"upperDir",
",",
"path",
".",
"Join",
"(",
"v",
".",
"path",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"id",
",",
"err",
")",
"\n",
"}",
"\n",
"l",
".",
"Driver",
".",
"Remove",
"(",
"l",
".",
"realID",
"(",
"id",
")",
")",
"\n\n",
"opts",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"opts",
"[",
"options",
".",
"OptionsDeleteAfterUnmount",
"]",
"=",
"\"",
"\"",
"\n\n",
"err",
"=",
"l",
".",
"volDriver",
".",
"Unmount",
"(",
"v",
".",
"volumeID",
",",
"v",
".",
"path",
",",
"opts",
")",
"\n",
"if",
"l",
".",
"volDriver",
".",
"Type",
"(",
")",
"==",
"api",
".",
"DriverType_DRIVER_TYPE_BLOCK",
"{",
"_",
"=",
"l",
".",
"volDriver",
".",
"Detach",
"(",
"v",
".",
"volumeID",
",",
"nil",
")",
"\n",
"}",
"\n",
"err",
"=",
"os",
".",
"RemoveAll",
"(",
"v",
".",
"path",
")",
"\n",
"delete",
"(",
"l",
".",
"volumes",
",",
"v",
".",
"id",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"id",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] |
// Remove removes a layer based on its id
|
[
"Remove",
"removes",
"a",
"layer",
"based",
"on",
"its",
"id"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/layer0/layer0.go#L236-L270
|
143,797 |
libopenstorage/openstorage
|
graph/drivers/layer0/layer0.go
|
Get
|
func (l *Layer0) Get(id string, mountLabel string) (string, error) {
id = l.realID(id)
return l.Driver.Get(id, mountLabel)
}
|
go
|
func (l *Layer0) Get(id string, mountLabel string) (string, error) {
id = l.realID(id)
return l.Driver.Get(id, mountLabel)
}
|
[
"func",
"(",
"l",
"*",
"Layer0",
")",
"Get",
"(",
"id",
"string",
",",
"mountLabel",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"id",
"=",
"l",
".",
"realID",
"(",
"id",
")",
"\n",
"return",
"l",
".",
"Driver",
".",
"Get",
"(",
"id",
",",
"mountLabel",
")",
"\n",
"}"
] |
// Get returns the mountpoint for the layered filesystem
|
[
"Get",
"returns",
"the",
"mountpoint",
"for",
"the",
"layered",
"filesystem"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/layer0/layer0.go#L273-L276
|
143,798 |
libopenstorage/openstorage
|
graph/drivers/layer0/layer0.go
|
Put
|
func (l *Layer0) Put(id string) error {
id = l.realID(id)
return l.Driver.Put(id)
}
|
go
|
func (l *Layer0) Put(id string) error {
id = l.realID(id)
return l.Driver.Put(id)
}
|
[
"func",
"(",
"l",
"*",
"Layer0",
")",
"Put",
"(",
"id",
"string",
")",
"error",
"{",
"id",
"=",
"l",
".",
"realID",
"(",
"id",
")",
"\n",
"return",
"l",
".",
"Driver",
".",
"Put",
"(",
"id",
")",
"\n",
"}"
] |
// Put releases the system resources for the specified id
|
[
"Put",
"releases",
"the",
"system",
"resources",
"for",
"the",
"specified",
"id"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/layer0/layer0.go#L279-L282
|
143,799 |
libopenstorage/openstorage
|
graph/drivers/layer0/layer0.go
|
ApplyDiff
|
func (l *Layer0) ApplyDiff(id string, parent string, diff archive.Reader) (size int64, err error) {
id = l.realID(id)
return l.Driver.ApplyDiff(id, parent, diff)
}
|
go
|
func (l *Layer0) ApplyDiff(id string, parent string, diff archive.Reader) (size int64, err error) {
id = l.realID(id)
return l.Driver.ApplyDiff(id, parent, diff)
}
|
[
"func",
"(",
"l",
"*",
"Layer0",
")",
"ApplyDiff",
"(",
"id",
"string",
",",
"parent",
"string",
",",
"diff",
"archive",
".",
"Reader",
")",
"(",
"size",
"int64",
",",
"err",
"error",
")",
"{",
"id",
"=",
"l",
".",
"realID",
"(",
"id",
")",
"\n",
"return",
"l",
".",
"Driver",
".",
"ApplyDiff",
"(",
"id",
",",
"parent",
",",
"diff",
")",
"\n",
"}"
] |
// ApplyDiff extracts the changeset between the specified layer and its parent
|
[
"ApplyDiff",
"extracts",
"the",
"changeset",
"between",
"the",
"specified",
"layer",
"and",
"its",
"parent"
] |
71b7f37f99c70e697aa31ca57fa8fb1404629329
|
https://github.com/libopenstorage/openstorage/blob/71b7f37f99c70e697aa31ca57fa8fb1404629329/graph/drivers/layer0/layer0.go#L285-L288
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.