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
21,300
vmware/govmomi
object/virtual_machine.go
RevertToCurrentSnapshot
func (v VirtualMachine) RevertToCurrentSnapshot(ctx context.Context, suppressPowerOn bool) (*Task, error) { req := types.RevertToCurrentSnapshot_Task{ This: v.Reference(), SuppressPowerOn: types.NewBool(suppressPowerOn), } res, err := methods.RevertToCurrentSnapshot_Task(ctx, v.c, &req) if err != nil { return nil, err } return NewTask(v.c, res.Returnval), nil }
go
func (v VirtualMachine) RevertToCurrentSnapshot(ctx context.Context, suppressPowerOn bool) (*Task, error) { req := types.RevertToCurrentSnapshot_Task{ This: v.Reference(), SuppressPowerOn: types.NewBool(suppressPowerOn), } res, err := methods.RevertToCurrentSnapshot_Task(ctx, v.c, &req) if err != nil { return nil, err } return NewTask(v.c, res.Returnval), nil }
[ "func", "(", "v", "VirtualMachine", ")", "RevertToCurrentSnapshot", "(", "ctx", "context", ".", "Context", ",", "suppressPowerOn", "bool", ")", "(", "*", "Task", ",", "error", ")", "{", "req", ":=", "types", ".", "RevertToCurrentSnapshot_Task", "{", "This", ":", "v", ".", "Reference", "(", ")", ",", "SuppressPowerOn", ":", "types", ".", "NewBool", "(", "suppressPowerOn", ")", ",", "}", "\n\n", "res", ",", "err", ":=", "methods", ".", "RevertToCurrentSnapshot_Task", "(", "ctx", ",", "v", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "NewTask", "(", "v", ".", "c", ",", "res", ".", "Returnval", ")", ",", "nil", "\n", "}" ]
// RevertToCurrentSnapshot reverts to the current snapshot
[ "RevertToCurrentSnapshot", "reverts", "to", "the", "current", "snapshot" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L615-L627
21,301
vmware/govmomi
object/virtual_machine.go
RevertToSnapshot
func (v VirtualMachine) RevertToSnapshot(ctx context.Context, name string, suppressPowerOn bool) (*Task, error) { snapshot, err := v.FindSnapshot(ctx, name) if err != nil { return nil, err } req := types.RevertToSnapshot_Task{ This: snapshot.Reference(), SuppressPowerOn: types.NewBool(suppressPowerOn), } res, err := methods.RevertToSnapshot_Task(ctx, v.c, &req) if err != nil { return nil, err } return NewTask(v.c, res.Returnval), nil }
go
func (v VirtualMachine) RevertToSnapshot(ctx context.Context, name string, suppressPowerOn bool) (*Task, error) { snapshot, err := v.FindSnapshot(ctx, name) if err != nil { return nil, err } req := types.RevertToSnapshot_Task{ This: snapshot.Reference(), SuppressPowerOn: types.NewBool(suppressPowerOn), } res, err := methods.RevertToSnapshot_Task(ctx, v.c, &req) if err != nil { return nil, err } return NewTask(v.c, res.Returnval), nil }
[ "func", "(", "v", "VirtualMachine", ")", "RevertToSnapshot", "(", "ctx", "context", ".", "Context", ",", "name", "string", ",", "suppressPowerOn", "bool", ")", "(", "*", "Task", ",", "error", ")", "{", "snapshot", ",", "err", ":=", "v", ".", "FindSnapshot", "(", "ctx", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "req", ":=", "types", ".", "RevertToSnapshot_Task", "{", "This", ":", "snapshot", ".", "Reference", "(", ")", ",", "SuppressPowerOn", ":", "types", ".", "NewBool", "(", "suppressPowerOn", ")", ",", "}", "\n\n", "res", ",", "err", ":=", "methods", ".", "RevertToSnapshot_Task", "(", "ctx", ",", "v", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "NewTask", "(", "v", ".", "c", ",", "res", ".", "Returnval", ")", ",", "nil", "\n", "}" ]
// RevertToSnapshot reverts to a named snapshot
[ "RevertToSnapshot", "reverts", "to", "a", "named", "snapshot" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L630-L647
21,302
vmware/govmomi
object/virtual_machine.go
IsToolsRunning
func (v VirtualMachine) IsToolsRunning(ctx context.Context) (bool, error) { var o mo.VirtualMachine err := v.Properties(ctx, v.Reference(), []string{"guest.toolsRunningStatus"}, &o) if err != nil { return false, err } return o.Guest.ToolsRunningStatus == string(types.VirtualMachineToolsRunningStatusGuestToolsRunning), nil }
go
func (v VirtualMachine) IsToolsRunning(ctx context.Context) (bool, error) { var o mo.VirtualMachine err := v.Properties(ctx, v.Reference(), []string{"guest.toolsRunningStatus"}, &o) if err != nil { return false, err } return o.Guest.ToolsRunningStatus == string(types.VirtualMachineToolsRunningStatusGuestToolsRunning), nil }
[ "func", "(", "v", "VirtualMachine", ")", "IsToolsRunning", "(", "ctx", "context", ".", "Context", ")", "(", "bool", ",", "error", ")", "{", "var", "o", "mo", ".", "VirtualMachine", "\n\n", "err", ":=", "v", ".", "Properties", "(", "ctx", ",", "v", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"", "\"", "}", ",", "&", "o", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "o", ".", "Guest", ".", "ToolsRunningStatus", "==", "string", "(", "types", ".", "VirtualMachineToolsRunningStatusGuestToolsRunning", ")", ",", "nil", "\n", "}" ]
// IsToolsRunning returns true if VMware Tools is currently running in the guest OS, and false otherwise.
[ "IsToolsRunning", "returns", "true", "if", "VMware", "Tools", "is", "currently", "running", "in", "the", "guest", "OS", "and", "false", "otherwise", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L650-L659
21,303
vmware/govmomi
object/virtual_machine.go
WaitForPowerState
func (v VirtualMachine) WaitForPowerState(ctx context.Context, state types.VirtualMachinePowerState) error { p := property.DefaultCollector(v.c) err := property.Wait(ctx, p, v.Reference(), []string{PropRuntimePowerState}, func(pc []types.PropertyChange) bool { for _, c := range pc { if c.Name != PropRuntimePowerState { continue } if c.Val == nil { continue } ps := c.Val.(types.VirtualMachinePowerState) if ps == state { return true } } return false }) return err }
go
func (v VirtualMachine) WaitForPowerState(ctx context.Context, state types.VirtualMachinePowerState) error { p := property.DefaultCollector(v.c) err := property.Wait(ctx, p, v.Reference(), []string{PropRuntimePowerState}, func(pc []types.PropertyChange) bool { for _, c := range pc { if c.Name != PropRuntimePowerState { continue } if c.Val == nil { continue } ps := c.Val.(types.VirtualMachinePowerState) if ps == state { return true } } return false }) return err }
[ "func", "(", "v", "VirtualMachine", ")", "WaitForPowerState", "(", "ctx", "context", ".", "Context", ",", "state", "types", ".", "VirtualMachinePowerState", ")", "error", "{", "p", ":=", "property", ".", "DefaultCollector", "(", "v", ".", "c", ")", "\n", "err", ":=", "property", ".", "Wait", "(", "ctx", ",", "p", ",", "v", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "PropRuntimePowerState", "}", ",", "func", "(", "pc", "[", "]", "types", ".", "PropertyChange", ")", "bool", "{", "for", "_", ",", "c", ":=", "range", "pc", "{", "if", "c", ".", "Name", "!=", "PropRuntimePowerState", "{", "continue", "\n", "}", "\n", "if", "c", ".", "Val", "==", "nil", "{", "continue", "\n", "}", "\n\n", "ps", ":=", "c", ".", "Val", ".", "(", "types", ".", "VirtualMachinePowerState", ")", "\n", "if", "ps", "==", "state", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}", ")", "\n\n", "return", "err", "\n", "}" ]
// Wait for the VirtualMachine to change to the desired power state.
[ "Wait", "for", "the", "VirtualMachine", "to", "change", "to", "the", "desired", "power", "state", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L662-L682
21,304
vmware/govmomi
object/virtual_machine.go
QueryConfigTarget
func (v VirtualMachine) QueryConfigTarget(ctx context.Context) (*types.ConfigTarget, error) { var vm mo.VirtualMachine err := v.Properties(ctx, v.Reference(), []string{"environmentBrowser"}, &vm) if err != nil { return nil, err } req := types.QueryConfigTarget{ This: vm.EnvironmentBrowser, } res, err := methods.QueryConfigTarget(ctx, v.Client(), &req) if err != nil { return nil, err } return res.Returnval, nil }
go
func (v VirtualMachine) QueryConfigTarget(ctx context.Context) (*types.ConfigTarget, error) { var vm mo.VirtualMachine err := v.Properties(ctx, v.Reference(), []string{"environmentBrowser"}, &vm) if err != nil { return nil, err } req := types.QueryConfigTarget{ This: vm.EnvironmentBrowser, } res, err := methods.QueryConfigTarget(ctx, v.Client(), &req) if err != nil { return nil, err } return res.Returnval, nil }
[ "func", "(", "v", "VirtualMachine", ")", "QueryConfigTarget", "(", "ctx", "context", ".", "Context", ")", "(", "*", "types", ".", "ConfigTarget", ",", "error", ")", "{", "var", "vm", "mo", ".", "VirtualMachine", "\n\n", "err", ":=", "v", ".", "Properties", "(", "ctx", ",", "v", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"", "\"", "}", ",", "&", "vm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "req", ":=", "types", ".", "QueryConfigTarget", "{", "This", ":", "vm", ".", "EnvironmentBrowser", ",", "}", "\n\n", "res", ",", "err", ":=", "methods", ".", "QueryConfigTarget", "(", "ctx", ",", "v", ".", "Client", "(", ")", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// QueryEnvironmentBrowser is a helper to get the environmentBrowser property.
[ "QueryEnvironmentBrowser", "is", "a", "helper", "to", "get", "the", "environmentBrowser", "property", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L751-L769
21,305
vmware/govmomi
object/virtual_machine.go
UUID
func (v VirtualMachine) UUID(ctx context.Context) string { var o mo.VirtualMachine err := v.Properties(ctx, v.Reference(), []string{"config.uuid"}, &o) if err != nil { return "" } return o.Config.Uuid }
go
func (v VirtualMachine) UUID(ctx context.Context) string { var o mo.VirtualMachine err := v.Properties(ctx, v.Reference(), []string{"config.uuid"}, &o) if err != nil { return "" } return o.Config.Uuid }
[ "func", "(", "v", "VirtualMachine", ")", "UUID", "(", "ctx", "context", ".", "Context", ")", "string", "{", "var", "o", "mo", ".", "VirtualMachine", "\n\n", "err", ":=", "v", ".", "Properties", "(", "ctx", ",", "v", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"", "\"", "}", ",", "&", "o", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", "\n", "}", "\n\n", "return", "o", ".", "Config", ".", "Uuid", "\n", "}" ]
// UUID is a helper to get the UUID of the VirtualMachine managed object. // This method returns an empty string if an error occurs when retrieving UUID from the VirtualMachine object.
[ "UUID", "is", "a", "helper", "to", "get", "the", "UUID", "of", "the", "VirtualMachine", "managed", "object", ".", "This", "method", "returns", "an", "empty", "string", "if", "an", "error", "occurs", "when", "retrieving", "UUID", "from", "the", "VirtualMachine", "object", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L832-L841
21,306
vmware/govmomi
vim25/xml/extras.go
typeToString
func typeToString(typ reflect.Type) string { switch typ.Kind() { case reflect.Bool: return "xsd:boolean" case reflect.Int8: return "xsd:byte" case reflect.Int16: return "xsd:short" case reflect.Int32: return "xsd:int" case reflect.Int, reflect.Int64: return "xsd:long" case reflect.Uint8: return "xsd:unsignedByte" case reflect.Uint16: return "xsd:unsignedShort" case reflect.Uint32: return "xsd:unsignedInt" case reflect.Uint, reflect.Uint64: return "xsd:unsignedLong" case reflect.Float32: return "xsd:float" case reflect.Float64: return "xsd:double" case reflect.String: name := typ.Name() if name == "string" { return "xsd:string" } return name case reflect.Struct: if typ == stringToTypeMap["xsd:dateTime"] { return "xsd:dateTime" } // Expect any other struct to be handled... return typ.Name() case reflect.Slice: if typ.Elem().Kind() == reflect.Uint8 { return "xsd:base64Binary" } case reflect.Array: if typ.Elem().Kind() == reflect.Uint8 { return "xsd:base64Binary" } } panic("don't know what to do for type: " + typ.String()) }
go
func typeToString(typ reflect.Type) string { switch typ.Kind() { case reflect.Bool: return "xsd:boolean" case reflect.Int8: return "xsd:byte" case reflect.Int16: return "xsd:short" case reflect.Int32: return "xsd:int" case reflect.Int, reflect.Int64: return "xsd:long" case reflect.Uint8: return "xsd:unsignedByte" case reflect.Uint16: return "xsd:unsignedShort" case reflect.Uint32: return "xsd:unsignedInt" case reflect.Uint, reflect.Uint64: return "xsd:unsignedLong" case reflect.Float32: return "xsd:float" case reflect.Float64: return "xsd:double" case reflect.String: name := typ.Name() if name == "string" { return "xsd:string" } return name case reflect.Struct: if typ == stringToTypeMap["xsd:dateTime"] { return "xsd:dateTime" } // Expect any other struct to be handled... return typ.Name() case reflect.Slice: if typ.Elem().Kind() == reflect.Uint8 { return "xsd:base64Binary" } case reflect.Array: if typ.Elem().Kind() == reflect.Uint8 { return "xsd:base64Binary" } } panic("don't know what to do for type: " + typ.String()) }
[ "func", "typeToString", "(", "typ", "reflect", ".", "Type", ")", "string", "{", "switch", "typ", ".", "Kind", "(", ")", "{", "case", "reflect", ".", "Bool", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Int8", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Int16", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Int32", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Int", ",", "reflect", ".", "Int64", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Uint8", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Uint16", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Uint32", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Uint", ",", "reflect", ".", "Uint64", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Float32", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "Float64", ":", "return", "\"", "\"", "\n", "case", "reflect", ".", "String", ":", "name", ":=", "typ", ".", "Name", "(", ")", "\n", "if", "name", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "name", "\n", "case", "reflect", ".", "Struct", ":", "if", "typ", "==", "stringToTypeMap", "[", "\"", "\"", "]", "{", "return", "\"", "\"", "\n", "}", "\n\n", "// Expect any other struct to be handled...", "return", "typ", ".", "Name", "(", ")", "\n", "case", "reflect", ".", "Slice", ":", "if", "typ", ".", "Elem", "(", ")", ".", "Kind", "(", ")", "==", "reflect", ".", "Uint8", "{", "return", "\"", "\"", "\n", "}", "\n", "case", "reflect", ".", "Array", ":", "if", "typ", ".", "Elem", "(", ")", ".", "Kind", "(", ")", "==", "reflect", ".", "Uint8", "{", "return", "\"", "\"", "\n", "}", "\n", "}", "\n\n", "panic", "(", "\"", "\"", "+", "typ", ".", "String", "(", ")", ")", "\n", "}" ]
// Return a string for the specified reflect.Type. Panic if unknown.
[ "Return", "a", "string", "for", "the", "specified", "reflect", ".", "Type", ".", "Panic", "if", "unknown", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/extras.go#L51-L99
21,307
vmware/govmomi
simulator/container.go
inspect
func (c *container) inspect(vm *VirtualMachine) error { if c.id == "" { return nil } var objects []struct { NetworkSettings struct { Gateway string IPAddress string IPPrefixLen int MacAddress string } } cmd := exec.Command("docker", "inspect", c.id) out, err := cmd.Output() if err != nil { return err } if err = json.NewDecoder(bytes.NewReader(out)).Decode(&objects); err != nil { return err } vm.Config.Annotation = strings.Join(cmd.Args, " ") vm.logPrintf("%s: %s", vm.Config.Annotation, string(out)) for _, o := range objects { s := o.NetworkSettings if s.IPAddress == "" { continue } vm.Guest.IpAddress = s.IPAddress vm.Summary.Guest.IpAddress = s.IPAddress if len(vm.Guest.Net) != 0 { net := &vm.Guest.Net[0] net.IpAddress = []string{s.IPAddress} net.MacAddress = s.MacAddress } } return nil }
go
func (c *container) inspect(vm *VirtualMachine) error { if c.id == "" { return nil } var objects []struct { NetworkSettings struct { Gateway string IPAddress string IPPrefixLen int MacAddress string } } cmd := exec.Command("docker", "inspect", c.id) out, err := cmd.Output() if err != nil { return err } if err = json.NewDecoder(bytes.NewReader(out)).Decode(&objects); err != nil { return err } vm.Config.Annotation = strings.Join(cmd.Args, " ") vm.logPrintf("%s: %s", vm.Config.Annotation, string(out)) for _, o := range objects { s := o.NetworkSettings if s.IPAddress == "" { continue } vm.Guest.IpAddress = s.IPAddress vm.Summary.Guest.IpAddress = s.IPAddress if len(vm.Guest.Net) != 0 { net := &vm.Guest.Net[0] net.IpAddress = []string{s.IPAddress} net.MacAddress = s.MacAddress } } return nil }
[ "func", "(", "c", "*", "container", ")", "inspect", "(", "vm", "*", "VirtualMachine", ")", "error", "{", "if", "c", ".", "id", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "var", "objects", "[", "]", "struct", "{", "NetworkSettings", "struct", "{", "Gateway", "string", "\n", "IPAddress", "string", "\n", "IPPrefixLen", "int", "\n", "MacAddress", "string", "\n", "}", "\n", "}", "\n\n", "cmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "c", ".", "id", ")", "\n", "out", ",", "err", ":=", "cmd", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", "=", "json", ".", "NewDecoder", "(", "bytes", ".", "NewReader", "(", "out", ")", ")", ".", "Decode", "(", "&", "objects", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "vm", ".", "Config", ".", "Annotation", "=", "strings", ".", "Join", "(", "cmd", ".", "Args", ",", "\"", "\"", ")", "\n", "vm", ".", "logPrintf", "(", "\"", "\"", ",", "vm", ".", "Config", ".", "Annotation", ",", "string", "(", "out", ")", ")", "\n\n", "for", "_", ",", "o", ":=", "range", "objects", "{", "s", ":=", "o", ".", "NetworkSettings", "\n", "if", "s", ".", "IPAddress", "==", "\"", "\"", "{", "continue", "\n", "}", "\n\n", "vm", ".", "Guest", ".", "IpAddress", "=", "s", ".", "IPAddress", "\n", "vm", ".", "Summary", ".", "Guest", ".", "IpAddress", "=", "s", ".", "IPAddress", "\n\n", "if", "len", "(", "vm", ".", "Guest", ".", "Net", ")", "!=", "0", "{", "net", ":=", "&", "vm", ".", "Guest", ".", "Net", "[", "0", "]", "\n", "net", ".", "IpAddress", "=", "[", "]", "string", "{", "s", ".", "IPAddress", "}", "\n", "net", ".", "MacAddress", "=", "s", ".", "MacAddress", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// inspect applies container network settings to vm.Guest properties.
[ "inspect", "applies", "container", "network", "settings", "to", "vm", ".", "Guest", "properties", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/container.go#L35-L78
21,308
vmware/govmomi
simulator/container.go
start
func (c *container) start(vm *VirtualMachine) { if c.id != "" { start := "start" if vm.Runtime.PowerState == types.VirtualMachinePowerStateSuspended { start = "unpause" } cmd := exec.Command("docker", start, c.id) err := cmd.Run() if err != nil { log.Printf("%s %s: %s", vm.Name, cmd.Args, err) } return } var args []string for _, opt := range vm.Config.ExtraConfig { val := opt.GetOptionValue() if val.Key == "RUN.container" { run := val.Value.(string) err := json.Unmarshal([]byte(run), &args) if err != nil { args = []string{run} } break } } if len(args) == 0 { return } args = append([]string{"run", "-d", "--name", vm.Name}, args...) cmd := exec.Command("docker", args...) out, err := cmd.Output() if err != nil { log.Printf("%s %s: %s", vm.Name, cmd.Args, err) return } c.id = strings.TrimSpace(string(out)) vm.logPrintf("%s %s: %s", cmd.Path, cmd.Args, c.id) if err = c.inspect(vm); err != nil { log.Printf("%s inspect %s: %s", vm.Name, c.id, err) } }
go
func (c *container) start(vm *VirtualMachine) { if c.id != "" { start := "start" if vm.Runtime.PowerState == types.VirtualMachinePowerStateSuspended { start = "unpause" } cmd := exec.Command("docker", start, c.id) err := cmd.Run() if err != nil { log.Printf("%s %s: %s", vm.Name, cmd.Args, err) } return } var args []string for _, opt := range vm.Config.ExtraConfig { val := opt.GetOptionValue() if val.Key == "RUN.container" { run := val.Value.(string) err := json.Unmarshal([]byte(run), &args) if err != nil { args = []string{run} } break } } if len(args) == 0 { return } args = append([]string{"run", "-d", "--name", vm.Name}, args...) cmd := exec.Command("docker", args...) out, err := cmd.Output() if err != nil { log.Printf("%s %s: %s", vm.Name, cmd.Args, err) return } c.id = strings.TrimSpace(string(out)) vm.logPrintf("%s %s: %s", cmd.Path, cmd.Args, c.id) if err = c.inspect(vm); err != nil { log.Printf("%s inspect %s: %s", vm.Name, c.id, err) } }
[ "func", "(", "c", "*", "container", ")", "start", "(", "vm", "*", "VirtualMachine", ")", "{", "if", "c", ".", "id", "!=", "\"", "\"", "{", "start", ":=", "\"", "\"", "\n", "if", "vm", ".", "Runtime", ".", "PowerState", "==", "types", ".", "VirtualMachinePowerStateSuspended", "{", "start", "=", "\"", "\"", "\n", "}", "\n", "cmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "start", ",", "c", ".", "id", ")", "\n", "err", ":=", "cmd", ".", "Run", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "vm", ".", "Name", ",", "cmd", ".", "Args", ",", "err", ")", "\n", "}", "\n", "return", "\n", "}", "\n\n", "var", "args", "[", "]", "string", "\n\n", "for", "_", ",", "opt", ":=", "range", "vm", ".", "Config", ".", "ExtraConfig", "{", "val", ":=", "opt", ".", "GetOptionValue", "(", ")", "\n", "if", "val", ".", "Key", "==", "\"", "\"", "{", "run", ":=", "val", ".", "Value", ".", "(", "string", ")", "\n", "err", ":=", "json", ".", "Unmarshal", "(", "[", "]", "byte", "(", "run", ")", ",", "&", "args", ")", "\n", "if", "err", "!=", "nil", "{", "args", "=", "[", "]", "string", "{", "run", "}", "\n", "}", "\n\n", "break", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "args", ")", "==", "0", "{", "return", "\n", "}", "\n\n", "args", "=", "append", "(", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "vm", ".", "Name", "}", ",", "args", "...", ")", "\n", "cmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "args", "...", ")", "\n", "out", ",", "err", ":=", "cmd", ".", "Output", "(", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "vm", ".", "Name", ",", "cmd", ".", "Args", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "c", ".", "id", "=", "strings", ".", "TrimSpace", "(", "string", "(", "out", ")", ")", "\n", "vm", ".", "logPrintf", "(", "\"", "\"", ",", "cmd", ".", "Path", ",", "cmd", ".", "Args", ",", "c", ".", "id", ")", "\n\n", "if", "err", "=", "c", ".", "inspect", "(", "vm", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "vm", ".", "Name", ",", "c", ".", "id", ",", "err", ")", "\n", "}", "\n", "}" ]
// start runs the container if specified by the RUN.container extraConfig property.
[ "start", "runs", "the", "container", "if", "specified", "by", "the", "RUN", ".", "container", "extraConfig", "property", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/container.go#L81-L128
21,309
vmware/govmomi
client.go
Login
func (c *Client) Login(ctx context.Context, u *url.Userinfo) error { return c.SessionManager.Login(ctx, u) }
go
func (c *Client) Login(ctx context.Context, u *url.Userinfo) error { return c.SessionManager.Login(ctx, u) }
[ "func", "(", "c", "*", "Client", ")", "Login", "(", "ctx", "context", ".", "Context", ",", "u", "*", "url", ".", "Userinfo", ")", "error", "{", "return", "c", ".", "SessionManager", ".", "Login", "(", "ctx", ",", "u", ")", "\n", "}" ]
// Login dispatches to the SessionManager.
[ "Login", "dispatches", "to", "the", "SessionManager", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/client.go#L102-L104
21,310
vmware/govmomi
client.go
Logout
func (c *Client) Logout(ctx context.Context) error { // Close any idle connections after logging out. defer c.Client.CloseIdleConnections() return c.SessionManager.Logout(ctx) }
go
func (c *Client) Logout(ctx context.Context) error { // Close any idle connections after logging out. defer c.Client.CloseIdleConnections() return c.SessionManager.Logout(ctx) }
[ "func", "(", "c", "*", "Client", ")", "Logout", "(", "ctx", "context", ".", "Context", ")", "error", "{", "// Close any idle connections after logging out.", "defer", "c", ".", "Client", ".", "CloseIdleConnections", "(", ")", "\n", "return", "c", ".", "SessionManager", ".", "Logout", "(", "ctx", ")", "\n", "}" ]
// Logout dispatches to the SessionManager.
[ "Logout", "dispatches", "to", "the", "SessionManager", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/client.go#L107-L111
21,311
vmware/govmomi
client.go
RetrieveOne
func (c *Client) RetrieveOne(ctx context.Context, obj types.ManagedObjectReference, p []string, dst interface{}) error { return c.PropertyCollector().RetrieveOne(ctx, obj, p, dst) }
go
func (c *Client) RetrieveOne(ctx context.Context, obj types.ManagedObjectReference, p []string, dst interface{}) error { return c.PropertyCollector().RetrieveOne(ctx, obj, p, dst) }
[ "func", "(", "c", "*", "Client", ")", "RetrieveOne", "(", "ctx", "context", ".", "Context", ",", "obj", "types", ".", "ManagedObjectReference", ",", "p", "[", "]", "string", ",", "dst", "interface", "{", "}", ")", "error", "{", "return", "c", ".", "PropertyCollector", "(", ")", ".", "RetrieveOne", "(", "ctx", ",", "obj", ",", "p", ",", "dst", ")", "\n", "}" ]
// RetrieveOne dispatches to the Retrieve function on the default property collector.
[ "RetrieveOne", "dispatches", "to", "the", "Retrieve", "function", "on", "the", "default", "property", "collector", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/client.go#L119-L121
21,312
vmware/govmomi
client.go
Retrieve
func (c *Client) Retrieve(ctx context.Context, objs []types.ManagedObjectReference, p []string, dst interface{}) error { return c.PropertyCollector().Retrieve(ctx, objs, p, dst) }
go
func (c *Client) Retrieve(ctx context.Context, objs []types.ManagedObjectReference, p []string, dst interface{}) error { return c.PropertyCollector().Retrieve(ctx, objs, p, dst) }
[ "func", "(", "c", "*", "Client", ")", "Retrieve", "(", "ctx", "context", ".", "Context", ",", "objs", "[", "]", "types", ".", "ManagedObjectReference", ",", "p", "[", "]", "string", ",", "dst", "interface", "{", "}", ")", "error", "{", "return", "c", ".", "PropertyCollector", "(", ")", ".", "Retrieve", "(", "ctx", ",", "objs", ",", "p", ",", "dst", ")", "\n", "}" ]
// Retrieve dispatches to the Retrieve function on the default property collector.
[ "Retrieve", "dispatches", "to", "the", "Retrieve", "function", "on", "the", "default", "property", "collector", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/client.go#L124-L126
21,313
vmware/govmomi
client.go
Wait
func (c *Client) Wait(ctx context.Context, obj types.ManagedObjectReference, ps []string, f func([]types.PropertyChange) bool) error { return property.Wait(ctx, c.PropertyCollector(), obj, ps, f) }
go
func (c *Client) Wait(ctx context.Context, obj types.ManagedObjectReference, ps []string, f func([]types.PropertyChange) bool) error { return property.Wait(ctx, c.PropertyCollector(), obj, ps, f) }
[ "func", "(", "c", "*", "Client", ")", "Wait", "(", "ctx", "context", ".", "Context", ",", "obj", "types", ".", "ManagedObjectReference", ",", "ps", "[", "]", "string", ",", "f", "func", "(", "[", "]", "types", ".", "PropertyChange", ")", "bool", ")", "error", "{", "return", "property", ".", "Wait", "(", "ctx", ",", "c", ".", "PropertyCollector", "(", ")", ",", "obj", ",", "ps", ",", "f", ")", "\n", "}" ]
// Wait dispatches to property.Wait.
[ "Wait", "dispatches", "to", "property", ".", "Wait", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/client.go#L129-L131
21,314
vmware/govmomi
sts/client.go
NewClient
func NewClient(ctx context.Context, c *vim25.Client) (*Client, error) { filter := &types.LookupServiceRegistrationFilter{ ServiceType: &types.LookupServiceRegistrationServiceType{ Product: "com.vmware.cis", Type: "sso:sts", }, EndpointType: &types.LookupServiceRegistrationEndpointType{ Protocol: "wsTrust", Type: "com.vmware.cis.cs.identity.sso", }, } url := lookup.EndpointURL(ctx, c, Path, filter) sc := c.Client.NewServiceClient(url, Namespace) return &Client{sc}, nil }
go
func NewClient(ctx context.Context, c *vim25.Client) (*Client, error) { filter := &types.LookupServiceRegistrationFilter{ ServiceType: &types.LookupServiceRegistrationServiceType{ Product: "com.vmware.cis", Type: "sso:sts", }, EndpointType: &types.LookupServiceRegistrationEndpointType{ Protocol: "wsTrust", Type: "com.vmware.cis.cs.identity.sso", }, } url := lookup.EndpointURL(ctx, c, Path, filter) sc := c.Client.NewServiceClient(url, Namespace) return &Client{sc}, nil }
[ "func", "NewClient", "(", "ctx", "context", ".", "Context", ",", "c", "*", "vim25", ".", "Client", ")", "(", "*", "Client", ",", "error", ")", "{", "filter", ":=", "&", "types", ".", "LookupServiceRegistrationFilter", "{", "ServiceType", ":", "&", "types", ".", "LookupServiceRegistrationServiceType", "{", "Product", ":", "\"", "\"", ",", "Type", ":", "\"", "\"", ",", "}", ",", "EndpointType", ":", "&", "types", ".", "LookupServiceRegistrationEndpointType", "{", "Protocol", ":", "\"", "\"", ",", "Type", ":", "\"", "\"", ",", "}", ",", "}", "\n\n", "url", ":=", "lookup", ".", "EndpointURL", "(", "ctx", ",", "c", ",", "Path", ",", "filter", ")", "\n", "sc", ":=", "c", ".", "Client", ".", "NewServiceClient", "(", "url", ",", "Namespace", ")", "\n\n", "return", "&", "Client", "{", "sc", "}", ",", "nil", "\n", "}" ]
// NewClient returns a client targeting the STS API endpoint. // The Client.URL will be set to that of the Lookup Service's endpoint registration, // as the SSO endpoint can be external to vCenter. If the Lookup Service is not available, // URL defaults to Path on the vim25.Client.URL.Host.
[ "NewClient", "returns", "a", "client", "targeting", "the", "STS", "API", "endpoint", ".", "The", "Client", ".", "URL", "will", "be", "set", "to", "that", "of", "the", "Lookup", "Service", "s", "endpoint", "registration", "as", "the", "SSO", "endpoint", "can", "be", "external", "to", "vCenter", ".", "If", "the", "Lookup", "Service", "is", "not", "available", "URL", "defaults", "to", "Path", "on", "the", "vim25", ".", "Client", ".", "URL", ".", "Host", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/sts/client.go#L47-L63
21,315
vmware/govmomi
sts/client.go
Renew
func (c *Client) Renew(ctx context.Context, req TokenRequest) (*Signer, error) { s := &Signer{ Certificate: req.Certificate, } rst, err := c.newRequest(req, "Renew", s) if err != nil { return nil, err } if req.Token == "" { return nil, errors.New("TokenRequest Token is required") } rst.RenewTarget = &internal.Target{Token: req.Token} header := soap.Header{ Security: s, Action: rst.Action(), } res, err := internal.Renew(c.WithHeader(ctx, header), c, &rst) if err != nil { return nil, err } s.Token = res.RequestedSecurityToken.Assertion return s, s.setLifetime(res.Lifetime) }
go
func (c *Client) Renew(ctx context.Context, req TokenRequest) (*Signer, error) { s := &Signer{ Certificate: req.Certificate, } rst, err := c.newRequest(req, "Renew", s) if err != nil { return nil, err } if req.Token == "" { return nil, errors.New("TokenRequest Token is required") } rst.RenewTarget = &internal.Target{Token: req.Token} header := soap.Header{ Security: s, Action: rst.Action(), } res, err := internal.Renew(c.WithHeader(ctx, header), c, &rst) if err != nil { return nil, err } s.Token = res.RequestedSecurityToken.Assertion return s, s.setLifetime(res.Lifetime) }
[ "func", "(", "c", "*", "Client", ")", "Renew", "(", "ctx", "context", ".", "Context", ",", "req", "TokenRequest", ")", "(", "*", "Signer", ",", "error", ")", "{", "s", ":=", "&", "Signer", "{", "Certificate", ":", "req", ".", "Certificate", ",", "}", "\n\n", "rst", ",", "err", ":=", "c", ".", "newRequest", "(", "req", ",", "\"", "\"", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "if", "req", ".", "Token", "==", "\"", "\"", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "rst", ".", "RenewTarget", "=", "&", "internal", ".", "Target", "{", "Token", ":", "req", ".", "Token", "}", "\n\n", "header", ":=", "soap", ".", "Header", "{", "Security", ":", "s", ",", "Action", ":", "rst", ".", "Action", "(", ")", ",", "}", "\n\n", "res", ",", "err", ":=", "internal", ".", "Renew", "(", "c", ".", "WithHeader", "(", "ctx", ",", "header", ")", ",", "c", ",", "&", "rst", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "s", ".", "Token", "=", "res", ".", "RequestedSecurityToken", ".", "Assertion", "\n\n", "return", "s", ",", "s", ".", "setLifetime", "(", "res", ".", "Lifetime", ")", "\n", "}" ]
// Renew is used to request a security token renewal.
[ "Renew", "is", "used", "to", "request", "a", "security", "token", "renewal", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/sts/client.go#L180-L209
21,316
vmware/govmomi
object/host_vsan_internal_system.go
QueryVsanObjectUuidsByFilter
func (m HostVsanInternalSystem) QueryVsanObjectUuidsByFilter(ctx context.Context, uuids []string, limit int32, version int32) ([]string, error) { req := types.QueryVsanObjectUuidsByFilter{ This: m.Reference(), Uuids: uuids, Limit: &limit, Version: version, } res, err := methods.QueryVsanObjectUuidsByFilter(ctx, m.Client(), &req) if err != nil { return nil, err } return res.Returnval, nil }
go
func (m HostVsanInternalSystem) QueryVsanObjectUuidsByFilter(ctx context.Context, uuids []string, limit int32, version int32) ([]string, error) { req := types.QueryVsanObjectUuidsByFilter{ This: m.Reference(), Uuids: uuids, Limit: &limit, Version: version, } res, err := methods.QueryVsanObjectUuidsByFilter(ctx, m.Client(), &req) if err != nil { return nil, err } return res.Returnval, nil }
[ "func", "(", "m", "HostVsanInternalSystem", ")", "QueryVsanObjectUuidsByFilter", "(", "ctx", "context", ".", "Context", ",", "uuids", "[", "]", "string", ",", "limit", "int32", ",", "version", "int32", ")", "(", "[", "]", "string", ",", "error", ")", "{", "req", ":=", "types", ".", "QueryVsanObjectUuidsByFilter", "{", "This", ":", "m", ".", "Reference", "(", ")", ",", "Uuids", ":", "uuids", ",", "Limit", ":", "&", "limit", ",", "Version", ":", "version", ",", "}", "\n\n", "res", ",", "err", ":=", "methods", ".", "QueryVsanObjectUuidsByFilter", "(", "ctx", ",", "m", ".", "Client", "(", ")", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// QueryVsanObjectUuidsByFilter returns vSAN DOM object uuids by filter.
[ "QueryVsanObjectUuidsByFilter", "returns", "vSAN", "DOM", "object", "uuids", "by", "filter", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_vsan_internal_system.go#L41-L55
21,317
vmware/govmomi
object/datastore.go
NewURL
func (d Datastore) NewURL(path string) *url.URL { u := d.c.URL() return &url.URL{ Scheme: u.Scheme, Host: u.Host, Path: fmt.Sprintf("/folder/%s", path), RawQuery: url.Values{ "dcPath": []string{d.DatacenterPath}, "dsName": []string{d.Name()}, }.Encode(), } }
go
func (d Datastore) NewURL(path string) *url.URL { u := d.c.URL() return &url.URL{ Scheme: u.Scheme, Host: u.Host, Path: fmt.Sprintf("/folder/%s", path), RawQuery: url.Values{ "dcPath": []string{d.DatacenterPath}, "dsName": []string{d.Name()}, }.Encode(), } }
[ "func", "(", "d", "Datastore", ")", "NewURL", "(", "path", "string", ")", "*", "url", ".", "URL", "{", "u", ":=", "d", ".", "c", ".", "URL", "(", ")", "\n\n", "return", "&", "url", ".", "URL", "{", "Scheme", ":", "u", ".", "Scheme", ",", "Host", ":", "u", ".", "Host", ",", "Path", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "path", ")", ",", "RawQuery", ":", "url", ".", "Values", "{", "\"", "\"", ":", "[", "]", "string", "{", "d", ".", "DatacenterPath", "}", ",", "\"", "\"", ":", "[", "]", "string", "{", "d", ".", "Name", "(", ")", "}", ",", "}", ".", "Encode", "(", ")", ",", "}", "\n", "}" ]
// NewURL constructs a url.URL with the given file path for datastore access over HTTP.
[ "NewURL", "constructs", "a", "url", ".", "URL", "with", "the", "given", "file", "path", "for", "datastore", "access", "over", "HTTP", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L83-L95
21,318
vmware/govmomi
object/datastore.go
URL
func (d Datastore) URL(ctx context.Context, dc *Datacenter, path string) (*url.URL, error) { return d.NewURL(path), nil }
go
func (d Datastore) URL(ctx context.Context, dc *Datacenter, path string) (*url.URL, error) { return d.NewURL(path), nil }
[ "func", "(", "d", "Datastore", ")", "URL", "(", "ctx", "context", ".", "Context", ",", "dc", "*", "Datacenter", ",", "path", "string", ")", "(", "*", "url", ".", "URL", ",", "error", ")", "{", "return", "d", ".", "NewURL", "(", "path", ")", ",", "nil", "\n", "}" ]
// URL is deprecated, use NewURL instead.
[ "URL", "is", "deprecated", "use", "NewURL", "instead", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L98-L100
21,319
vmware/govmomi
object/datastore.go
HostContext
func (d Datastore) HostContext(ctx context.Context, host *HostSystem) context.Context { return context.WithValue(ctx, datastoreServiceTicketHostKey{}, host) }
go
func (d Datastore) HostContext(ctx context.Context, host *HostSystem) context.Context { return context.WithValue(ctx, datastoreServiceTicketHostKey{}, host) }
[ "func", "(", "d", "Datastore", ")", "HostContext", "(", "ctx", "context", ".", "Context", ",", "host", "*", "HostSystem", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "datastoreServiceTicketHostKey", "{", "}", ",", "host", ")", "\n", "}" ]
// HostContext returns a Context where the given host will be used for datastore HTTP access // via the ServiceTicket method.
[ "HostContext", "returns", "a", "Context", "where", "the", "given", "host", "will", "be", "used", "for", "datastore", "HTTP", "access", "via", "the", "ServiceTicket", "method", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L174-L176
21,320
vmware/govmomi
object/datastore.go
ServiceTicket
func (d Datastore) ServiceTicket(ctx context.Context, path string, method string) (*url.URL, *http.Cookie, error) { u := d.NewURL(path) host, ok := ctx.Value(datastoreServiceTicketHostKey{}).(*HostSystem) if !ok { if !d.useServiceTicket() { return u, nil, nil } hosts, err := d.AttachedHosts(ctx) if err != nil { return nil, nil, err } if len(hosts) == 0 { // Fallback to letting vCenter choose a host return u, nil, nil } // Pick a random attached host host = hosts[rand.Intn(len(hosts))] } ips, err := host.ManagementIPs(ctx) if err != nil { return nil, nil, err } if len(ips) > 0 { // prefer a ManagementIP u.Host = ips[0].String() } else { // fallback to inventory name u.Host, err = host.ObjectName(ctx) if err != nil { return nil, nil, err } } // VC datacenter path will not be valid against ESX q := u.Query() delete(q, "dcPath") u.RawQuery = q.Encode() spec := types.SessionManagerHttpServiceRequestSpec{ Url: u.String(), // See SessionManagerHttpServiceRequestSpecMethod enum Method: fmt.Sprintf("http%s%s", method[0:1], strings.ToLower(method[1:])), } sm := session.NewManager(d.Client()) ticket, err := sm.AcquireGenericServiceTicket(ctx, &spec) if err != nil { return nil, nil, err } cookie := &http.Cookie{ Name: "vmware_cgi_ticket", Value: ticket.Id, } if d.useServiceTicketHostName(ticket.HostName) { u.Host = ticket.HostName } d.Client().SetThumbprint(u.Host, ticket.SslThumbprint) return u, cookie, nil }
go
func (d Datastore) ServiceTicket(ctx context.Context, path string, method string) (*url.URL, *http.Cookie, error) { u := d.NewURL(path) host, ok := ctx.Value(datastoreServiceTicketHostKey{}).(*HostSystem) if !ok { if !d.useServiceTicket() { return u, nil, nil } hosts, err := d.AttachedHosts(ctx) if err != nil { return nil, nil, err } if len(hosts) == 0 { // Fallback to letting vCenter choose a host return u, nil, nil } // Pick a random attached host host = hosts[rand.Intn(len(hosts))] } ips, err := host.ManagementIPs(ctx) if err != nil { return nil, nil, err } if len(ips) > 0 { // prefer a ManagementIP u.Host = ips[0].String() } else { // fallback to inventory name u.Host, err = host.ObjectName(ctx) if err != nil { return nil, nil, err } } // VC datacenter path will not be valid against ESX q := u.Query() delete(q, "dcPath") u.RawQuery = q.Encode() spec := types.SessionManagerHttpServiceRequestSpec{ Url: u.String(), // See SessionManagerHttpServiceRequestSpecMethod enum Method: fmt.Sprintf("http%s%s", method[0:1], strings.ToLower(method[1:])), } sm := session.NewManager(d.Client()) ticket, err := sm.AcquireGenericServiceTicket(ctx, &spec) if err != nil { return nil, nil, err } cookie := &http.Cookie{ Name: "vmware_cgi_ticket", Value: ticket.Id, } if d.useServiceTicketHostName(ticket.HostName) { u.Host = ticket.HostName } d.Client().SetThumbprint(u.Host, ticket.SslThumbprint) return u, cookie, nil }
[ "func", "(", "d", "Datastore", ")", "ServiceTicket", "(", "ctx", "context", ".", "Context", ",", "path", "string", ",", "method", "string", ")", "(", "*", "url", ".", "URL", ",", "*", "http", ".", "Cookie", ",", "error", ")", "{", "u", ":=", "d", ".", "NewURL", "(", "path", ")", "\n\n", "host", ",", "ok", ":=", "ctx", ".", "Value", "(", "datastoreServiceTicketHostKey", "{", "}", ")", ".", "(", "*", "HostSystem", ")", "\n\n", "if", "!", "ok", "{", "if", "!", "d", ".", "useServiceTicket", "(", ")", "{", "return", "u", ",", "nil", ",", "nil", "\n", "}", "\n\n", "hosts", ",", "err", ":=", "d", ".", "AttachedHosts", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "hosts", ")", "==", "0", "{", "// Fallback to letting vCenter choose a host", "return", "u", ",", "nil", ",", "nil", "\n", "}", "\n\n", "// Pick a random attached host", "host", "=", "hosts", "[", "rand", ".", "Intn", "(", "len", "(", "hosts", ")", ")", "]", "\n", "}", "\n\n", "ips", ",", "err", ":=", "host", ".", "ManagementIPs", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "if", "len", "(", "ips", ")", ">", "0", "{", "// prefer a ManagementIP", "u", ".", "Host", "=", "ips", "[", "0", "]", ".", "String", "(", ")", "\n", "}", "else", "{", "// fallback to inventory name", "u", ".", "Host", ",", "err", "=", "host", ".", "ObjectName", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n", "}", "\n\n", "// VC datacenter path will not be valid against ESX", "q", ":=", "u", ".", "Query", "(", ")", "\n", "delete", "(", "q", ",", "\"", "\"", ")", "\n", "u", ".", "RawQuery", "=", "q", ".", "Encode", "(", ")", "\n\n", "spec", ":=", "types", ".", "SessionManagerHttpServiceRequestSpec", "{", "Url", ":", "u", ".", "String", "(", ")", ",", "// See SessionManagerHttpServiceRequestSpecMethod enum", "Method", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "method", "[", "0", ":", "1", "]", ",", "strings", ".", "ToLower", "(", "method", "[", "1", ":", "]", ")", ")", ",", "}", "\n\n", "sm", ":=", "session", ".", "NewManager", "(", "d", ".", "Client", "(", ")", ")", "\n\n", "ticket", ",", "err", ":=", "sm", ".", "AcquireGenericServiceTicket", "(", "ctx", ",", "&", "spec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "cookie", ":=", "&", "http", ".", "Cookie", "{", "Name", ":", "\"", "\"", ",", "Value", ":", "ticket", ".", "Id", ",", "}", "\n\n", "if", "d", ".", "useServiceTicketHostName", "(", "ticket", ".", "HostName", ")", "{", "u", ".", "Host", "=", "ticket", ".", "HostName", "\n", "}", "\n\n", "d", ".", "Client", "(", ")", ".", "SetThumbprint", "(", "u", ".", "Host", ",", "ticket", ".", "SslThumbprint", ")", "\n\n", "return", "u", ",", "cookie", ",", "nil", "\n", "}" ]
// ServiceTicket obtains a ticket via AcquireGenericServiceTicket and returns it an http.Cookie with the url.URL // that can be used along with the ticket cookie to access the given path. An host is chosen at random unless the // the given Context was created with a specific host via the HostContext method.
[ "ServiceTicket", "obtains", "a", "ticket", "via", "AcquireGenericServiceTicket", "and", "returns", "it", "an", "http", ".", "Cookie", "with", "the", "url", ".", "URL", "that", "can", "be", "used", "along", "with", "the", "ticket", "cookie", "to", "access", "the", "given", "path", ".", "An", "host", "is", "chosen", "at", "random", "unless", "the", "the", "given", "Context", "was", "created", "with", "a", "specific", "host", "via", "the", "HostContext", "method", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L181-L251
21,321
vmware/govmomi
object/datastore.go
Upload
func (d Datastore) Upload(ctx context.Context, f io.Reader, path string, param *soap.Upload) error { u, p, err := d.uploadTicket(ctx, path, param) if err != nil { return err } return d.Client().Upload(ctx, f, u, p) }
go
func (d Datastore) Upload(ctx context.Context, f io.Reader, path string, param *soap.Upload) error { u, p, err := d.uploadTicket(ctx, path, param) if err != nil { return err } return d.Client().Upload(ctx, f, u, p) }
[ "func", "(", "d", "Datastore", ")", "Upload", "(", "ctx", "context", ".", "Context", ",", "f", "io", ".", "Reader", ",", "path", "string", ",", "param", "*", "soap", ".", "Upload", ")", "error", "{", "u", ",", "p", ",", "err", ":=", "d", ".", "uploadTicket", "(", "ctx", ",", "path", ",", "param", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "d", ".", "Client", "(", ")", ".", "Upload", "(", "ctx", ",", "f", ",", "u", ",", "p", ")", "\n", "}" ]
// Upload via soap.Upload with an http service ticket
[ "Upload", "via", "soap", ".", "Upload", "with", "an", "http", "service", "ticket" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L286-L292
21,322
vmware/govmomi
object/datastore.go
UploadFile
func (d Datastore) UploadFile(ctx context.Context, file string, path string, param *soap.Upload) error { u, p, err := d.uploadTicket(ctx, path, param) if err != nil { return err } return d.Client().UploadFile(ctx, file, u, p) }
go
func (d Datastore) UploadFile(ctx context.Context, file string, path string, param *soap.Upload) error { u, p, err := d.uploadTicket(ctx, path, param) if err != nil { return err } return d.Client().UploadFile(ctx, file, u, p) }
[ "func", "(", "d", "Datastore", ")", "UploadFile", "(", "ctx", "context", ".", "Context", ",", "file", "string", ",", "path", "string", ",", "param", "*", "soap", ".", "Upload", ")", "error", "{", "u", ",", "p", ",", "err", ":=", "d", ".", "uploadTicket", "(", "ctx", ",", "path", ",", "param", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "d", ".", "Client", "(", ")", ".", "UploadFile", "(", "ctx", ",", "file", ",", "u", ",", "p", ")", "\n", "}" ]
// UploadFile via soap.Upload with an http service ticket
[ "UploadFile", "via", "soap", ".", "Upload", "with", "an", "http", "service", "ticket" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L295-L301
21,323
vmware/govmomi
object/datastore.go
Download
func (d Datastore) Download(ctx context.Context, path string, param *soap.Download) (io.ReadCloser, int64, error) { u, p, err := d.downloadTicket(ctx, path, param) if err != nil { return nil, 0, err } return d.Client().Download(ctx, u, p) }
go
func (d Datastore) Download(ctx context.Context, path string, param *soap.Download) (io.ReadCloser, int64, error) { u, p, err := d.downloadTicket(ctx, path, param) if err != nil { return nil, 0, err } return d.Client().Download(ctx, u, p) }
[ "func", "(", "d", "Datastore", ")", "Download", "(", "ctx", "context", ".", "Context", ",", "path", "string", ",", "param", "*", "soap", ".", "Download", ")", "(", "io", ".", "ReadCloser", ",", "int64", ",", "error", ")", "{", "u", ",", "p", ",", "err", ":=", "d", ".", "downloadTicket", "(", "ctx", ",", "path", ",", "param", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n", "return", "d", ".", "Client", "(", ")", ".", "Download", "(", "ctx", ",", "u", ",", "p", ")", "\n", "}" ]
// Download via soap.Download with an http service ticket
[ "Download", "via", "soap", ".", "Download", "with", "an", "http", "service", "ticket" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L304-L310
21,324
vmware/govmomi
object/datastore.go
DownloadFile
func (d Datastore) DownloadFile(ctx context.Context, path string, file string, param *soap.Download) error { u, p, err := d.downloadTicket(ctx, path, param) if err != nil { return err } return d.Client().DownloadFile(ctx, file, u, p) }
go
func (d Datastore) DownloadFile(ctx context.Context, path string, file string, param *soap.Download) error { u, p, err := d.downloadTicket(ctx, path, param) if err != nil { return err } return d.Client().DownloadFile(ctx, file, u, p) }
[ "func", "(", "d", "Datastore", ")", "DownloadFile", "(", "ctx", "context", ".", "Context", ",", "path", "string", ",", "file", "string", ",", "param", "*", "soap", ".", "Download", ")", "error", "{", "u", ",", "p", ",", "err", ":=", "d", ".", "downloadTicket", "(", "ctx", ",", "path", ",", "param", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "d", ".", "Client", "(", ")", ".", "DownloadFile", "(", "ctx", ",", "file", ",", "u", ",", "p", ")", "\n", "}" ]
// DownloadFile via soap.Download with an http service ticket
[ "DownloadFile", "via", "soap", ".", "Download", "with", "an", "http", "service", "ticket" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L313-L319
21,325
vmware/govmomi
object/datastore.go
AttachedHosts
func (d Datastore) AttachedHosts(ctx context.Context) ([]*HostSystem, error) { var ds mo.Datastore var hosts []*HostSystem pc := property.DefaultCollector(d.Client()) err := pc.RetrieveOne(ctx, d.Reference(), []string{"host"}, &ds) if err != nil { return nil, err } mounts := make(map[types.ManagedObjectReference]types.DatastoreHostMount) var refs []types.ManagedObjectReference for _, host := range ds.Host { refs = append(refs, host.Key) mounts[host.Key] = host } var hs []mo.HostSystem err = pc.Retrieve(ctx, refs, []string{"runtime.connectionState", "runtime.powerState"}, &hs) if err != nil { return nil, err } for _, host := range hs { if host.Runtime.ConnectionState == types.HostSystemConnectionStateConnected && host.Runtime.PowerState == types.HostSystemPowerStatePoweredOn { mount := mounts[host.Reference()] info := mount.MountInfo if *info.Mounted && *info.Accessible && info.AccessMode == string(types.HostMountModeReadWrite) { hosts = append(hosts, NewHostSystem(d.Client(), mount.Key)) } } } return hosts, nil }
go
func (d Datastore) AttachedHosts(ctx context.Context) ([]*HostSystem, error) { var ds mo.Datastore var hosts []*HostSystem pc := property.DefaultCollector(d.Client()) err := pc.RetrieveOne(ctx, d.Reference(), []string{"host"}, &ds) if err != nil { return nil, err } mounts := make(map[types.ManagedObjectReference]types.DatastoreHostMount) var refs []types.ManagedObjectReference for _, host := range ds.Host { refs = append(refs, host.Key) mounts[host.Key] = host } var hs []mo.HostSystem err = pc.Retrieve(ctx, refs, []string{"runtime.connectionState", "runtime.powerState"}, &hs) if err != nil { return nil, err } for _, host := range hs { if host.Runtime.ConnectionState == types.HostSystemConnectionStateConnected && host.Runtime.PowerState == types.HostSystemPowerStatePoweredOn { mount := mounts[host.Reference()] info := mount.MountInfo if *info.Mounted && *info.Accessible && info.AccessMode == string(types.HostMountModeReadWrite) { hosts = append(hosts, NewHostSystem(d.Client(), mount.Key)) } } } return hosts, nil }
[ "func", "(", "d", "Datastore", ")", "AttachedHosts", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "*", "HostSystem", ",", "error", ")", "{", "var", "ds", "mo", ".", "Datastore", "\n", "var", "hosts", "[", "]", "*", "HostSystem", "\n\n", "pc", ":=", "property", ".", "DefaultCollector", "(", "d", ".", "Client", "(", ")", ")", "\n", "err", ":=", "pc", ".", "RetrieveOne", "(", "ctx", ",", "d", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"", "\"", "}", ",", "&", "ds", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "mounts", ":=", "make", "(", "map", "[", "types", ".", "ManagedObjectReference", "]", "types", ".", "DatastoreHostMount", ")", "\n", "var", "refs", "[", "]", "types", ".", "ManagedObjectReference", "\n", "for", "_", ",", "host", ":=", "range", "ds", ".", "Host", "{", "refs", "=", "append", "(", "refs", ",", "host", ".", "Key", ")", "\n", "mounts", "[", "host", ".", "Key", "]", "=", "host", "\n", "}", "\n\n", "var", "hs", "[", "]", "mo", ".", "HostSystem", "\n", "err", "=", "pc", ".", "Retrieve", "(", "ctx", ",", "refs", ",", "[", "]", "string", "{", "\"", "\"", ",", "\"", "\"", "}", ",", "&", "hs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "host", ":=", "range", "hs", "{", "if", "host", ".", "Runtime", ".", "ConnectionState", "==", "types", ".", "HostSystemConnectionStateConnected", "&&", "host", ".", "Runtime", ".", "PowerState", "==", "types", ".", "HostSystemPowerStatePoweredOn", "{", "mount", ":=", "mounts", "[", "host", ".", "Reference", "(", ")", "]", "\n", "info", ":=", "mount", ".", "MountInfo", "\n\n", "if", "*", "info", ".", "Mounted", "&&", "*", "info", ".", "Accessible", "&&", "info", ".", "AccessMode", "==", "string", "(", "types", ".", "HostMountModeReadWrite", ")", "{", "hosts", "=", "append", "(", "hosts", ",", "NewHostSystem", "(", "d", ".", "Client", "(", ")", ",", "mount", ".", "Key", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "hosts", ",", "nil", "\n", "}" ]
// AttachedHosts returns hosts that have this Datastore attached, accessible and writable.
[ "AttachedHosts", "returns", "hosts", "that", "have", "this", "Datastore", "attached", "accessible", "and", "writable", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L322-L359
21,326
vmware/govmomi
object/datastore.go
AttachedClusterHosts
func (d Datastore) AttachedClusterHosts(ctx context.Context, cluster *ComputeResource) ([]*HostSystem, error) { var hosts []*HostSystem clusterHosts, err := cluster.Hosts(ctx) if err != nil { return nil, err } attachedHosts, err := d.AttachedHosts(ctx) if err != nil { return nil, err } refs := make(map[types.ManagedObjectReference]bool) for _, host := range attachedHosts { refs[host.Reference()] = true } for _, host := range clusterHosts { if refs[host.Reference()] { hosts = append(hosts, host) } } return hosts, nil }
go
func (d Datastore) AttachedClusterHosts(ctx context.Context, cluster *ComputeResource) ([]*HostSystem, error) { var hosts []*HostSystem clusterHosts, err := cluster.Hosts(ctx) if err != nil { return nil, err } attachedHosts, err := d.AttachedHosts(ctx) if err != nil { return nil, err } refs := make(map[types.ManagedObjectReference]bool) for _, host := range attachedHosts { refs[host.Reference()] = true } for _, host := range clusterHosts { if refs[host.Reference()] { hosts = append(hosts, host) } } return hosts, nil }
[ "func", "(", "d", "Datastore", ")", "AttachedClusterHosts", "(", "ctx", "context", ".", "Context", ",", "cluster", "*", "ComputeResource", ")", "(", "[", "]", "*", "HostSystem", ",", "error", ")", "{", "var", "hosts", "[", "]", "*", "HostSystem", "\n\n", "clusterHosts", ",", "err", ":=", "cluster", ".", "Hosts", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "attachedHosts", ",", "err", ":=", "d", ".", "AttachedHosts", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "refs", ":=", "make", "(", "map", "[", "types", ".", "ManagedObjectReference", "]", "bool", ")", "\n", "for", "_", ",", "host", ":=", "range", "attachedHosts", "{", "refs", "[", "host", ".", "Reference", "(", ")", "]", "=", "true", "\n", "}", "\n\n", "for", "_", ",", "host", ":=", "range", "clusterHosts", "{", "if", "refs", "[", "host", ".", "Reference", "(", ")", "]", "{", "hosts", "=", "append", "(", "hosts", ",", "host", ")", "\n", "}", "\n", "}", "\n\n", "return", "hosts", ",", "nil", "\n", "}" ]
// AttachedClusterHosts returns hosts that have this Datastore attached, accessible and writable and are members of the given cluster.
[ "AttachedClusterHosts", "returns", "hosts", "that", "have", "this", "Datastore", "attached", "accessible", "and", "writable", "and", "are", "members", "of", "the", "given", "cluster", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L362-L387
21,327
vmware/govmomi
object/datastore.go
Type
func (d Datastore) Type(ctx context.Context) (types.HostFileSystemVolumeFileSystemType, error) { var mds mo.Datastore if err := d.Properties(ctx, d.Reference(), []string{"summary.type"}, &mds); err != nil { return types.HostFileSystemVolumeFileSystemType(""), err } return types.HostFileSystemVolumeFileSystemType(mds.Summary.Type), nil }
go
func (d Datastore) Type(ctx context.Context) (types.HostFileSystemVolumeFileSystemType, error) { var mds mo.Datastore if err := d.Properties(ctx, d.Reference(), []string{"summary.type"}, &mds); err != nil { return types.HostFileSystemVolumeFileSystemType(""), err } return types.HostFileSystemVolumeFileSystemType(mds.Summary.Type), nil }
[ "func", "(", "d", "Datastore", ")", "Type", "(", "ctx", "context", ".", "Context", ")", "(", "types", ".", "HostFileSystemVolumeFileSystemType", ",", "error", ")", "{", "var", "mds", "mo", ".", "Datastore", "\n\n", "if", "err", ":=", "d", ".", "Properties", "(", "ctx", ",", "d", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"", "\"", "}", ",", "&", "mds", ")", ";", "err", "!=", "nil", "{", "return", "types", ".", "HostFileSystemVolumeFileSystemType", "(", "\"", "\"", ")", ",", "err", "\n", "}", "\n", "return", "types", ".", "HostFileSystemVolumeFileSystemType", "(", "mds", ".", "Summary", ".", "Type", ")", ",", "nil", "\n", "}" ]
// Type returns the type of file system volume.
[ "Type", "returns", "the", "type", "of", "file", "system", "volume", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore.go#L432-L439
21,328
vmware/govmomi
vapi/internal/internal.go
NewAssociation
func NewAssociation(ref mo.Reference) Association { obj := AssociatedObject(ref.Reference()) return Association{ ObjectID: &obj, } }
go
func NewAssociation(ref mo.Reference) Association { obj := AssociatedObject(ref.Reference()) return Association{ ObjectID: &obj, } }
[ "func", "NewAssociation", "(", "ref", "mo", ".", "Reference", ")", "Association", "{", "obj", ":=", "AssociatedObject", "(", "ref", ".", "Reference", "(", ")", ")", "\n", "return", "Association", "{", "ObjectID", ":", "&", "obj", ",", "}", "\n", "}" ]
// NewAssociation returns an Association, converting ref to an AssociatedObject.
[ "NewAssociation", "returns", "an", "Association", "converting", "ref", "to", "an", "AssociatedObject", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/internal/internal.go#L67-L72
21,329
vmware/govmomi
vapi/internal/internal.go
URL
func URL(c CloneURL, path string) *Resource { r := &Resource{u: c.URL()} r.u.Path = Path + path return r }
go
func URL(c CloneURL, path string) *Resource { r := &Resource{u: c.URL()} r.u.Path = Path + path return r }
[ "func", "URL", "(", "c", "CloneURL", ",", "path", "string", ")", "*", "Resource", "{", "r", ":=", "&", "Resource", "{", "u", ":", "c", ".", "URL", "(", ")", "}", "\n", "r", ".", "u", ".", "Path", "=", "Path", "+", "path", "\n", "return", "r", "\n", "}" ]
// URL creates a URL resource
[ "URL", "creates", "a", "URL", "resource" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/internal/internal.go#L85-L89
21,330
vmware/govmomi
vapi/internal/internal.go
WithID
func (r *Resource) WithID(id string) *Resource { r.u.Path += "/id:" + id return r }
go
func (r *Resource) WithID(id string) *Resource { r.u.Path += "/id:" + id return r }
[ "func", "(", "r", "*", "Resource", ")", "WithID", "(", "id", "string", ")", "*", "Resource", "{", "r", ".", "u", ".", "Path", "+=", "\"", "\"", "+", "id", "\n", "return", "r", "\n", "}" ]
// WithID appends id to the URL.Path
[ "WithID", "appends", "id", "to", "the", "URL", ".", "Path" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/internal/internal.go#L96-L99
21,331
vmware/govmomi
vapi/internal/internal.go
WithAction
func (r *Resource) WithAction(action string) *Resource { r.u.RawQuery = url.Values{ "~action": []string{action}, }.Encode() return r }
go
func (r *Resource) WithAction(action string) *Resource { r.u.RawQuery = url.Values{ "~action": []string{action}, }.Encode() return r }
[ "func", "(", "r", "*", "Resource", ")", "WithAction", "(", "action", "string", ")", "*", "Resource", "{", "r", ".", "u", ".", "RawQuery", "=", "url", ".", "Values", "{", "\"", "\"", ":", "[", "]", "string", "{", "action", "}", ",", "}", ".", "Encode", "(", ")", "\n", "return", "r", "\n", "}" ]
// WithAction sets adds action to the URL.RawQuery
[ "WithAction", "sets", "adds", "action", "to", "the", "URL", ".", "RawQuery" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/internal/internal.go#L102-L107
21,332
vmware/govmomi
vapi/internal/internal.go
WithParameter
func (r *Resource) WithParameter(name string, value string) *Resource { parameter := url.Values{} parameter.Set(name, value) r.u.RawQuery = parameter.Encode() return r }
go
func (r *Resource) WithParameter(name string, value string) *Resource { parameter := url.Values{} parameter.Set(name, value) r.u.RawQuery = parameter.Encode() return r }
[ "func", "(", "r", "*", "Resource", ")", "WithParameter", "(", "name", "string", ",", "value", "string", ")", "*", "Resource", "{", "parameter", ":=", "url", ".", "Values", "{", "}", "\n", "parameter", ".", "Set", "(", "name", ",", "value", ")", "\n", "r", ".", "u", ".", "RawQuery", "=", "parameter", ".", "Encode", "(", ")", "\n", "return", "r", "\n", "}" ]
// WithParameter sets adds a parameter to the URL.RawQuery
[ "WithParameter", "sets", "adds", "a", "parameter", "to", "the", "URL", ".", "RawQuery" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/internal/internal.go#L110-L115
21,333
vmware/govmomi
vapi/internal/internal.go
Request
func (r *Resource) Request(method string, body ...interface{}) *http.Request { rdr := io.MultiReader() // empty body by default if len(body) != 0 { rdr = encode(body[0]) } req, err := http.NewRequest(method, r.u.String(), rdr) if err != nil { panic(err) } return req }
go
func (r *Resource) Request(method string, body ...interface{}) *http.Request { rdr := io.MultiReader() // empty body by default if len(body) != 0 { rdr = encode(body[0]) } req, err := http.NewRequest(method, r.u.String(), rdr) if err != nil { panic(err) } return req }
[ "func", "(", "r", "*", "Resource", ")", "Request", "(", "method", "string", ",", "body", "...", "interface", "{", "}", ")", "*", "http", ".", "Request", "{", "rdr", ":=", "io", ".", "MultiReader", "(", ")", "// empty body by default", "\n", "if", "len", "(", "body", ")", "!=", "0", "{", "rdr", "=", "encode", "(", "body", "[", "0", "]", ")", "\n", "}", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "method", ",", "r", ".", "u", ".", "String", "(", ")", ",", "rdr", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "req", "\n", "}" ]
// Request returns a new http.Request for the given method. // An optional body can be provided for POST and PATCH methods.
[ "Request", "returns", "a", "new", "http", ".", "Request", "for", "the", "given", "method", ".", "An", "optional", "body", "can", "be", "provided", "for", "POST", "and", "PATCH", "methods", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/internal/internal.go#L119-L129
21,334
vmware/govmomi
vapi/internal/internal.go
encode
func encode(body interface{}) io.Reader { var b bytes.Buffer err := json.NewEncoder(&b).Encode(body) if err != nil { return errorReader{err} } return &b }
go
func encode(body interface{}) io.Reader { var b bytes.Buffer err := json.NewEncoder(&b).Encode(body) if err != nil { return errorReader{err} } return &b }
[ "func", "encode", "(", "body", "interface", "{", "}", ")", "io", ".", "Reader", "{", "var", "b", "bytes", ".", "Buffer", "\n", "err", ":=", "json", ".", "NewEncoder", "(", "&", "b", ")", ".", "Encode", "(", "body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errorReader", "{", "err", "}", "\n", "}", "\n", "return", "&", "b", "\n", "}" ]
// encode body as JSON, deferring any errors until io.Reader is used.
[ "encode", "body", "as", "JSON", "deferring", "any", "errors", "until", "io", ".", "Reader", "is", "used", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/internal/internal.go#L140-L147
21,335
vmware/govmomi
vim25/client.go
NewClient
func NewClient(ctx context.Context, rt soap.RoundTripper) (*Client, error) { c := Client{ RoundTripper: rt, } // Set client if it happens to be a soap.Client if sc, ok := rt.(*soap.Client); ok { c.Client = sc if c.Namespace == "" { c.Namespace = "urn:" + Namespace } else if !strings.Contains(c.Namespace, ":") { c.Namespace = "urn:" + c.Namespace // ensure valid URI format } if c.Version == "" { c.Version = Version } } var err error c.ServiceContent, err = methods.GetServiceContent(ctx, rt) if err != nil { return nil, err } return &c, nil }
go
func NewClient(ctx context.Context, rt soap.RoundTripper) (*Client, error) { c := Client{ RoundTripper: rt, } // Set client if it happens to be a soap.Client if sc, ok := rt.(*soap.Client); ok { c.Client = sc if c.Namespace == "" { c.Namespace = "urn:" + Namespace } else if !strings.Contains(c.Namespace, ":") { c.Namespace = "urn:" + c.Namespace // ensure valid URI format } if c.Version == "" { c.Version = Version } } var err error c.ServiceContent, err = methods.GetServiceContent(ctx, rt) if err != nil { return nil, err } return &c, nil }
[ "func", "NewClient", "(", "ctx", "context", ".", "Context", ",", "rt", "soap", ".", "RoundTripper", ")", "(", "*", "Client", ",", "error", ")", "{", "c", ":=", "Client", "{", "RoundTripper", ":", "rt", ",", "}", "\n\n", "// Set client if it happens to be a soap.Client", "if", "sc", ",", "ok", ":=", "rt", ".", "(", "*", "soap", ".", "Client", ")", ";", "ok", "{", "c", ".", "Client", "=", "sc", "\n\n", "if", "c", ".", "Namespace", "==", "\"", "\"", "{", "c", ".", "Namespace", "=", "\"", "\"", "+", "Namespace", "\n", "}", "else", "if", "!", "strings", ".", "Contains", "(", "c", ".", "Namespace", ",", "\"", "\"", ")", "{", "c", ".", "Namespace", "=", "\"", "\"", "+", "c", ".", "Namespace", "// ensure valid URI format", "\n", "}", "\n", "if", "c", ".", "Version", "==", "\"", "\"", "{", "c", ".", "Version", "=", "Version", "\n", "}", "\n", "}", "\n\n", "var", "err", "error", "\n", "c", ".", "ServiceContent", ",", "err", "=", "methods", ".", "GetServiceContent", "(", "ctx", ",", "rt", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "c", ",", "nil", "\n", "}" ]
// NewClient creates and returns a new client with the ServiceContent field // filled in.
[ "NewClient", "creates", "and", "returns", "a", "new", "client", "with", "the", "ServiceContent", "field", "filled", "in", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/client.go#L59-L85
21,336
vmware/govmomi
vim25/client.go
RoundTrip
func (c *Client) RoundTrip(ctx context.Context, req, res soap.HasFault) error { return c.RoundTripper.RoundTrip(ctx, req, res) }
go
func (c *Client) RoundTrip(ctx context.Context, req, res soap.HasFault) error { return c.RoundTripper.RoundTrip(ctx, req, res) }
[ "func", "(", "c", "*", "Client", ")", "RoundTrip", "(", "ctx", "context", ".", "Context", ",", "req", ",", "res", "soap", ".", "HasFault", ")", "error", "{", "return", "c", ".", "RoundTripper", ".", "RoundTrip", "(", "ctx", ",", "req", ",", "res", ")", "\n", "}" ]
// RoundTrip dispatches to the RoundTripper field.
[ "RoundTrip", "dispatches", "to", "the", "RoundTripper", "field", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/client.go#L88-L90
21,337
vmware/govmomi
vim25/client.go
Valid
func (c *Client) Valid() bool { if c == nil { return false } if c.Client == nil { return false } // Use arbitrary pointer field in the service content. // Doesn't matter which one, as long as it is populated by default. if c.ServiceContent.SessionManager == nil { return false } return true }
go
func (c *Client) Valid() bool { if c == nil { return false } if c.Client == nil { return false } // Use arbitrary pointer field in the service content. // Doesn't matter which one, as long as it is populated by default. if c.ServiceContent.SessionManager == nil { return false } return true }
[ "func", "(", "c", "*", "Client", ")", "Valid", "(", ")", "bool", "{", "if", "c", "==", "nil", "{", "return", "false", "\n", "}", "\n\n", "if", "c", ".", "Client", "==", "nil", "{", "return", "false", "\n", "}", "\n\n", "// Use arbitrary pointer field in the service content.", "// Doesn't matter which one, as long as it is populated by default.", "if", "c", ".", "ServiceContent", ".", "SessionManager", "==", "nil", "{", "return", "false", "\n", "}", "\n\n", "return", "true", "\n", "}" ]
// Valid returns whether or not the client is valid and ready for use. // This should be called after unmarshalling the client.
[ "Valid", "returns", "whether", "or", "not", "the", "client", "is", "valid", "and", "ready", "for", "use", ".", "This", "should", "be", "called", "after", "unmarshalling", "the", "client", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/client.go#L125-L141
21,338
vmware/govmomi
govc/task/recent.go
taskName
func taskName(info *types.TaskInfo) string { name := strings.TrimSuffix(info.Name, "_Task") switch name { case "": return info.DescriptionId case "Destroy", "Rename": return info.Entity.Type + "." + name default: return name } }
go
func taskName(info *types.TaskInfo) string { name := strings.TrimSuffix(info.Name, "_Task") switch name { case "": return info.DescriptionId case "Destroy", "Rename": return info.Entity.Type + "." + name default: return name } }
[ "func", "taskName", "(", "info", "*", "types", ".", "TaskInfo", ")", "string", "{", "name", ":=", "strings", ".", "TrimSuffix", "(", "info", ".", "Name", ",", "\"", "\"", ")", "\n", "switch", "name", "{", "case", "\"", "\"", ":", "return", "info", ".", "DescriptionId", "\n", "case", "\"", "\"", ",", "\"", "\"", ":", "return", "info", ".", "Entity", ".", "Type", "+", "\"", "\"", "+", "name", "\n", "default", ":", "return", "name", "\n", "}", "\n", "}" ]
// taskName describes the tasks similar to the ESX ui
[ "taskName", "describes", "the", "tasks", "similar", "to", "the", "ESX", "ui" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/task/recent.go#L91-L101
21,339
vmware/govmomi
govc/flags/datastore.go
NewCustomDatastoreFlag
func NewCustomDatastoreFlag(ctx context.Context) (*DatastoreFlag, context.Context) { v := &DatastoreFlag{} v.DatacenterFlag, ctx = NewDatacenterFlag(ctx) return v, ctx }
go
func NewCustomDatastoreFlag(ctx context.Context) (*DatastoreFlag, context.Context) { v := &DatastoreFlag{} v.DatacenterFlag, ctx = NewDatacenterFlag(ctx) return v, ctx }
[ "func", "NewCustomDatastoreFlag", "(", "ctx", "context", ".", "Context", ")", "(", "*", "DatastoreFlag", ",", "context", ".", "Context", ")", "{", "v", ":=", "&", "DatastoreFlag", "{", "}", "\n", "v", ".", "DatacenterFlag", ",", "ctx", "=", "NewDatacenterFlag", "(", "ctx", ")", "\n", "return", "v", ",", "ctx", "\n", "}" ]
// NewCustomDatastoreFlag creates and returns a new DatastoreFlag without // trying to retrieve an existing one from the specified context.
[ "NewCustomDatastoreFlag", "creates", "and", "returns", "a", "new", "DatastoreFlag", "without", "trying", "to", "retrieve", "an", "existing", "one", "from", "the", "specified", "context", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/datastore.go#L43-L47
21,340
vmware/govmomi
object/datastore_file_manager.go
NewFileManager
func (d Datastore) NewFileManager(dc *Datacenter, force bool) *DatastoreFileManager { c := d.Client() m := &DatastoreFileManager{ Datacenter: dc, Datastore: &d, FileManager: NewFileManager(c), VirtualDiskManager: NewVirtualDiskManager(c), Force: force, DatacenterTarget: dc, } return m }
go
func (d Datastore) NewFileManager(dc *Datacenter, force bool) *DatastoreFileManager { c := d.Client() m := &DatastoreFileManager{ Datacenter: dc, Datastore: &d, FileManager: NewFileManager(c), VirtualDiskManager: NewVirtualDiskManager(c), Force: force, DatacenterTarget: dc, } return m }
[ "func", "(", "d", "Datastore", ")", "NewFileManager", "(", "dc", "*", "Datacenter", ",", "force", "bool", ")", "*", "DatastoreFileManager", "{", "c", ":=", "d", ".", "Client", "(", ")", "\n\n", "m", ":=", "&", "DatastoreFileManager", "{", "Datacenter", ":", "dc", ",", "Datastore", ":", "&", "d", ",", "FileManager", ":", "NewFileManager", "(", "c", ")", ",", "VirtualDiskManager", ":", "NewVirtualDiskManager", "(", "c", ")", ",", "Force", ":", "force", ",", "DatacenterTarget", ":", "dc", ",", "}", "\n\n", "return", "m", "\n", "}" ]
// NewFileManager creates a new instance of DatastoreFileManager
[ "NewFileManager", "creates", "a", "new", "instance", "of", "DatastoreFileManager" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file_manager.go#L45-L58
21,341
vmware/govmomi
object/datastore_file_manager.go
Delete
func (m *DatastoreFileManager) Delete(ctx context.Context, name string) error { switch path.Ext(name) { case ".vmdk": return m.DeleteVirtualDisk(ctx, name) default: return m.DeleteFile(ctx, name) } }
go
func (m *DatastoreFileManager) Delete(ctx context.Context, name string) error { switch path.Ext(name) { case ".vmdk": return m.DeleteVirtualDisk(ctx, name) default: return m.DeleteFile(ctx, name) } }
[ "func", "(", "m", "*", "DatastoreFileManager", ")", "Delete", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "error", "{", "switch", "path", ".", "Ext", "(", "name", ")", "{", "case", "\"", "\"", ":", "return", "m", ".", "DeleteVirtualDisk", "(", "ctx", ",", "name", ")", "\n", "default", ":", "return", "m", ".", "DeleteFile", "(", "ctx", ",", "name", ")", "\n", "}", "\n", "}" ]
// Delete dispatches to the appropriate Delete method based on file name extension
[ "Delete", "dispatches", "to", "the", "appropriate", "Delete", "method", "based", "on", "file", "name", "extension" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file_manager.go#L74-L81
21,342
vmware/govmomi
object/datastore_file_manager.go
DeleteFile
func (m *DatastoreFileManager) DeleteFile(ctx context.Context, name string) error { p := m.Path(name) task, err := m.FileManager.DeleteDatastoreFile(ctx, p.String(), m.Datacenter) if err != nil { return err } return m.wait(ctx, task) }
go
func (m *DatastoreFileManager) DeleteFile(ctx context.Context, name string) error { p := m.Path(name) task, err := m.FileManager.DeleteDatastoreFile(ctx, p.String(), m.Datacenter) if err != nil { return err } return m.wait(ctx, task) }
[ "func", "(", "m", "*", "DatastoreFileManager", ")", "DeleteFile", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "error", "{", "p", ":=", "m", ".", "Path", "(", "name", ")", "\n\n", "task", ",", "err", ":=", "m", ".", "FileManager", ".", "DeleteDatastoreFile", "(", "ctx", ",", "p", ".", "String", "(", ")", ",", "m", ".", "Datacenter", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "m", ".", "wait", "(", "ctx", ",", "task", ")", "\n", "}" ]
// DeleteFile calls FileManager.DeleteDatastoreFile
[ "DeleteFile", "calls", "FileManager", ".", "DeleteDatastoreFile" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file_manager.go#L84-L93
21,343
vmware/govmomi
object/datastore_file_manager.go
DeleteVirtualDisk
func (m *DatastoreFileManager) DeleteVirtualDisk(ctx context.Context, name string) error { p := m.Path(name) var merr error if m.Force { merr = m.markDiskAsDeletable(ctx, p) } task, err := m.VirtualDiskManager.DeleteVirtualDisk(ctx, p.String(), m.Datacenter) if err != nil { log.Printf("markDiskAsDeletable(%s): %s", p, merr) return err } return m.wait(ctx, task) }
go
func (m *DatastoreFileManager) DeleteVirtualDisk(ctx context.Context, name string) error { p := m.Path(name) var merr error if m.Force { merr = m.markDiskAsDeletable(ctx, p) } task, err := m.VirtualDiskManager.DeleteVirtualDisk(ctx, p.String(), m.Datacenter) if err != nil { log.Printf("markDiskAsDeletable(%s): %s", p, merr) return err } return m.wait(ctx, task) }
[ "func", "(", "m", "*", "DatastoreFileManager", ")", "DeleteVirtualDisk", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "error", "{", "p", ":=", "m", ".", "Path", "(", "name", ")", "\n\n", "var", "merr", "error", "\n\n", "if", "m", ".", "Force", "{", "merr", "=", "m", ".", "markDiskAsDeletable", "(", "ctx", ",", "p", ")", "\n", "}", "\n\n", "task", ",", "err", ":=", "m", ".", "VirtualDiskManager", ".", "DeleteVirtualDisk", "(", "ctx", ",", "p", ".", "String", "(", ")", ",", "m", ".", "Datacenter", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "p", ",", "merr", ")", "\n", "return", "err", "\n", "}", "\n\n", "return", "m", ".", "wait", "(", "ctx", ",", "task", ")", "\n", "}" ]
// DeleteVirtualDisk calls VirtualDiskManager.DeleteVirtualDisk // Regardless of the Datastore type, DeleteVirtualDisk will fail if 'ddb.deletable=false', // so if Force=true this method attempts to set 'ddb.deletable=true' before starting the delete task.
[ "DeleteVirtualDisk", "calls", "VirtualDiskManager", ".", "DeleteVirtualDisk", "Regardless", "of", "the", "Datastore", "type", "DeleteVirtualDisk", "will", "fail", "if", "ddb", ".", "deletable", "=", "false", "so", "if", "Force", "=", "true", "this", "method", "attempts", "to", "set", "ddb", ".", "deletable", "=", "true", "before", "starting", "the", "delete", "task", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file_manager.go#L98-L114
21,344
vmware/govmomi
object/datastore_file_manager.go
Copy
func (m *DatastoreFileManager) Copy(ctx context.Context, src string, dst string) error { srcp := m.Path(src) dstp := m.Path(dst) f := m.FileManager.CopyDatastoreFile if srcp.IsVMDK() { // types.VirtualDiskSpec=nil as it is not implemented by vCenter f = func(ctx context.Context, src string, srcDC *Datacenter, dst string, dstDC *Datacenter, force bool) (*Task, error) { return m.VirtualDiskManager.CopyVirtualDisk(ctx, src, srcDC, dst, dstDC, nil, force) } } task, err := f(ctx, srcp.String(), m.Datacenter, dstp.String(), m.DatacenterTarget, m.Force) if err != nil { return err } return m.wait(ctx, task) }
go
func (m *DatastoreFileManager) Copy(ctx context.Context, src string, dst string) error { srcp := m.Path(src) dstp := m.Path(dst) f := m.FileManager.CopyDatastoreFile if srcp.IsVMDK() { // types.VirtualDiskSpec=nil as it is not implemented by vCenter f = func(ctx context.Context, src string, srcDC *Datacenter, dst string, dstDC *Datacenter, force bool) (*Task, error) { return m.VirtualDiskManager.CopyVirtualDisk(ctx, src, srcDC, dst, dstDC, nil, force) } } task, err := f(ctx, srcp.String(), m.Datacenter, dstp.String(), m.DatacenterTarget, m.Force) if err != nil { return err } return m.wait(ctx, task) }
[ "func", "(", "m", "*", "DatastoreFileManager", ")", "Copy", "(", "ctx", "context", ".", "Context", ",", "src", "string", ",", "dst", "string", ")", "error", "{", "srcp", ":=", "m", ".", "Path", "(", "src", ")", "\n", "dstp", ":=", "m", ".", "Path", "(", "dst", ")", "\n\n", "f", ":=", "m", ".", "FileManager", ".", "CopyDatastoreFile", "\n\n", "if", "srcp", ".", "IsVMDK", "(", ")", "{", "// types.VirtualDiskSpec=nil as it is not implemented by vCenter", "f", "=", "func", "(", "ctx", "context", ".", "Context", ",", "src", "string", ",", "srcDC", "*", "Datacenter", ",", "dst", "string", ",", "dstDC", "*", "Datacenter", ",", "force", "bool", ")", "(", "*", "Task", ",", "error", ")", "{", "return", "m", ".", "VirtualDiskManager", ".", "CopyVirtualDisk", "(", "ctx", ",", "src", ",", "srcDC", ",", "dst", ",", "dstDC", ",", "nil", ",", "force", ")", "\n", "}", "\n", "}", "\n\n", "task", ",", "err", ":=", "f", "(", "ctx", ",", "srcp", ".", "String", "(", ")", ",", "m", ".", "Datacenter", ",", "dstp", ".", "String", "(", ")", ",", "m", ".", "DatacenterTarget", ",", "m", ".", "Force", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "m", ".", "wait", "(", "ctx", ",", "task", ")", "\n", "}" ]
// Copy dispatches to the appropriate FileManager or VirtualDiskManager Copy method based on file name extension
[ "Copy", "dispatches", "to", "the", "appropriate", "FileManager", "or", "VirtualDiskManager", "Copy", "method", "based", "on", "file", "name", "extension" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file_manager.go#L130-L149
21,345
vmware/govmomi
object/datastore_file_manager.go
MoveFile
func (m *DatastoreFileManager) MoveFile(ctx context.Context, src string, dst string) error { srcp := m.Path(src) dstp := m.Path(dst) task, err := m.FileManager.MoveDatastoreFile(ctx, srcp.String(), m.Datacenter, dstp.String(), m.DatacenterTarget, m.Force) if err != nil { return err } return m.wait(ctx, task) }
go
func (m *DatastoreFileManager) MoveFile(ctx context.Context, src string, dst string) error { srcp := m.Path(src) dstp := m.Path(dst) task, err := m.FileManager.MoveDatastoreFile(ctx, srcp.String(), m.Datacenter, dstp.String(), m.DatacenterTarget, m.Force) if err != nil { return err } return m.wait(ctx, task) }
[ "func", "(", "m", "*", "DatastoreFileManager", ")", "MoveFile", "(", "ctx", "context", ".", "Context", ",", "src", "string", ",", "dst", "string", ")", "error", "{", "srcp", ":=", "m", ".", "Path", "(", "src", ")", "\n", "dstp", ":=", "m", ".", "Path", "(", "dst", ")", "\n\n", "task", ",", "err", ":=", "m", ".", "FileManager", ".", "MoveDatastoreFile", "(", "ctx", ",", "srcp", ".", "String", "(", ")", ",", "m", ".", "Datacenter", ",", "dstp", ".", "String", "(", ")", ",", "m", ".", "DatacenterTarget", ",", "m", ".", "Force", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "m", ".", "wait", "(", "ctx", ",", "task", ")", "\n", "}" ]
// MoveFile calls FileManager.MoveDatastoreFile
[ "MoveFile", "calls", "FileManager", ".", "MoveDatastoreFile" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file_manager.go#L152-L162
21,346
vmware/govmomi
object/datastore_file_manager.go
Move
func (m *DatastoreFileManager) Move(ctx context.Context, src string, dst string) error { srcp := m.Path(src) dstp := m.Path(dst) f := m.FileManager.MoveDatastoreFile if srcp.IsVMDK() { f = m.VirtualDiskManager.MoveVirtualDisk } task, err := f(ctx, srcp.String(), m.Datacenter, dstp.String(), m.DatacenterTarget, m.Force) if err != nil { return err } return m.wait(ctx, task) }
go
func (m *DatastoreFileManager) Move(ctx context.Context, src string, dst string) error { srcp := m.Path(src) dstp := m.Path(dst) f := m.FileManager.MoveDatastoreFile if srcp.IsVMDK() { f = m.VirtualDiskManager.MoveVirtualDisk } task, err := f(ctx, srcp.String(), m.Datacenter, dstp.String(), m.DatacenterTarget, m.Force) if err != nil { return err } return m.wait(ctx, task) }
[ "func", "(", "m", "*", "DatastoreFileManager", ")", "Move", "(", "ctx", "context", ".", "Context", ",", "src", "string", ",", "dst", "string", ")", "error", "{", "srcp", ":=", "m", ".", "Path", "(", "src", ")", "\n", "dstp", ":=", "m", ".", "Path", "(", "dst", ")", "\n\n", "f", ":=", "m", ".", "FileManager", ".", "MoveDatastoreFile", "\n\n", "if", "srcp", ".", "IsVMDK", "(", ")", "{", "f", "=", "m", ".", "VirtualDiskManager", ".", "MoveVirtualDisk", "\n", "}", "\n\n", "task", ",", "err", ":=", "f", "(", "ctx", ",", "srcp", ".", "String", "(", ")", ",", "m", ".", "Datacenter", ",", "dstp", ".", "String", "(", ")", ",", "m", ".", "DatacenterTarget", ",", "m", ".", "Force", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "m", ".", "wait", "(", "ctx", ",", "task", ")", "\n", "}" ]
// Move dispatches to the appropriate FileManager or VirtualDiskManager Move method based on file name extension
[ "Move", "dispatches", "to", "the", "appropriate", "FileManager", "or", "VirtualDiskManager", "Move", "method", "based", "on", "file", "name", "extension" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file_manager.go#L165-L181
21,347
vmware/govmomi
object/datastore_file_manager.go
Path
func (m *DatastoreFileManager) Path(name string) *DatastorePath { var p DatastorePath if !p.FromString(name) { p.Path = name p.Datastore = m.Datastore.Name() } return &p }
go
func (m *DatastoreFileManager) Path(name string) *DatastorePath { var p DatastorePath if !p.FromString(name) { p.Path = name p.Datastore = m.Datastore.Name() } return &p }
[ "func", "(", "m", "*", "DatastoreFileManager", ")", "Path", "(", "name", "string", ")", "*", "DatastorePath", "{", "var", "p", "DatastorePath", "\n\n", "if", "!", "p", ".", "FromString", "(", "name", ")", "{", "p", ".", "Path", "=", "name", "\n", "p", ".", "Datastore", "=", "m", ".", "Datastore", ".", "Name", "(", ")", "\n", "}", "\n\n", "return", "&", "p", "\n", "}" ]
// Path converts path name to a DatastorePath
[ "Path", "converts", "path", "name", "to", "a", "DatastorePath" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file_manager.go#L184-L193
21,348
vmware/govmomi
nfc/lease.go
Abort
func (l *Lease) Abort(ctx context.Context, fault *types.LocalizedMethodFault) error { req := types.HttpNfcLeaseAbort{ This: l.Reference(), Fault: fault, } _, err := methods.HttpNfcLeaseAbort(ctx, l.c, &req) if err != nil { return err } return nil }
go
func (l *Lease) Abort(ctx context.Context, fault *types.LocalizedMethodFault) error { req := types.HttpNfcLeaseAbort{ This: l.Reference(), Fault: fault, } _, err := methods.HttpNfcLeaseAbort(ctx, l.c, &req) if err != nil { return err } return nil }
[ "func", "(", "l", "*", "Lease", ")", "Abort", "(", "ctx", "context", ".", "Context", ",", "fault", "*", "types", ".", "LocalizedMethodFault", ")", "error", "{", "req", ":=", "types", ".", "HttpNfcLeaseAbort", "{", "This", ":", "l", ".", "Reference", "(", ")", ",", "Fault", ":", "fault", ",", "}", "\n\n", "_", ",", "err", ":=", "methods", ".", "HttpNfcLeaseAbort", "(", "ctx", ",", "l", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Abort wraps methods.Abort
[ "Abort", "wraps", "methods", ".", "Abort" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/nfc/lease.go#L45-L57
21,349
vmware/govmomi
nfc/lease.go
Complete
func (l *Lease) Complete(ctx context.Context) error { req := types.HttpNfcLeaseComplete{ This: l.Reference(), } _, err := methods.HttpNfcLeaseComplete(ctx, l.c, &req) if err != nil { return err } return nil }
go
func (l *Lease) Complete(ctx context.Context) error { req := types.HttpNfcLeaseComplete{ This: l.Reference(), } _, err := methods.HttpNfcLeaseComplete(ctx, l.c, &req) if err != nil { return err } return nil }
[ "func", "(", "l", "*", "Lease", ")", "Complete", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ":=", "types", ".", "HttpNfcLeaseComplete", "{", "This", ":", "l", ".", "Reference", "(", ")", ",", "}", "\n\n", "_", ",", "err", ":=", "methods", ".", "HttpNfcLeaseComplete", "(", "ctx", ",", "l", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Complete wraps methods.Complete
[ "Complete", "wraps", "methods", ".", "Complete" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/nfc/lease.go#L60-L71
21,350
vmware/govmomi
nfc/lease.go
GetManifest
func (l *Lease) GetManifest(ctx context.Context) error { req := types.HttpNfcLeaseGetManifest{ This: l.Reference(), } _, err := methods.HttpNfcLeaseGetManifest(ctx, l.c, &req) if err != nil { return err } return nil }
go
func (l *Lease) GetManifest(ctx context.Context) error { req := types.HttpNfcLeaseGetManifest{ This: l.Reference(), } _, err := methods.HttpNfcLeaseGetManifest(ctx, l.c, &req) if err != nil { return err } return nil }
[ "func", "(", "l", "*", "Lease", ")", "GetManifest", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ":=", "types", ".", "HttpNfcLeaseGetManifest", "{", "This", ":", "l", ".", "Reference", "(", ")", ",", "}", "\n\n", "_", ",", "err", ":=", "methods", ".", "HttpNfcLeaseGetManifest", "(", "ctx", ",", "l", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// GetManifest wraps methods.GetManifest
[ "GetManifest", "wraps", "methods", ".", "GetManifest" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/nfc/lease.go#L74-L85
21,351
vmware/govmomi
nfc/lease.go
Progress
func (l *Lease) Progress(ctx context.Context, percent int32) error { req := types.HttpNfcLeaseProgress{ This: l.Reference(), Percent: percent, } _, err := methods.HttpNfcLeaseProgress(ctx, l.c, &req) if err != nil { return err } return nil }
go
func (l *Lease) Progress(ctx context.Context, percent int32) error { req := types.HttpNfcLeaseProgress{ This: l.Reference(), Percent: percent, } _, err := methods.HttpNfcLeaseProgress(ctx, l.c, &req) if err != nil { return err } return nil }
[ "func", "(", "l", "*", "Lease", ")", "Progress", "(", "ctx", "context", ".", "Context", ",", "percent", "int32", ")", "error", "{", "req", ":=", "types", ".", "HttpNfcLeaseProgress", "{", "This", ":", "l", ".", "Reference", "(", ")", ",", "Percent", ":", "percent", ",", "}", "\n\n", "_", ",", "err", ":=", "methods", ".", "HttpNfcLeaseProgress", "(", "ctx", ",", "l", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Progress wraps methods.Progress
[ "Progress", "wraps", "methods", ".", "Progress" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/nfc/lease.go#L88-L100
21,352
vmware/govmomi
vapi/library/library.go
FindLibrary
func (c *Manager) FindLibrary(ctx context.Context, search Find) ([]string, error) { url := internal.URL(c, internal.LibraryPath).WithAction("find") spec := struct { Spec Find `json:"spec"` }{search} var res []string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
go
func (c *Manager) FindLibrary(ctx context.Context, search Find) ([]string, error) { url := internal.URL(c, internal.LibraryPath).WithAction("find") spec := struct { Spec Find `json:"spec"` }{search} var res []string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
[ "func", "(", "c", "*", "Manager", ")", "FindLibrary", "(", "ctx", "context", ".", "Context", ",", "search", "Find", ")", "(", "[", "]", "string", ",", "error", ")", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LibraryPath", ")", ".", "WithAction", "(", "\"", "\"", ")", "\n", "spec", ":=", "struct", "{", "Spec", "Find", "`json:\"spec\"`", "\n", "}", "{", "search", "}", "\n", "var", "res", "[", "]", "string", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "spec", ")", ",", "&", "res", ")", "\n", "}" ]
// FindLibrary returns one or more libraries that match the provided search // criteria. // // The provided name is case-insensitive. // // Either the name or type of library may be set to empty values in order // to search for all libraries, all libraries with a specific name, regardless // of type, or all libraries of a specified type.
[ "FindLibrary", "returns", "one", "or", "more", "libraries", "that", "match", "the", "provided", "search", "criteria", ".", "The", "provided", "name", "is", "case", "-", "insensitive", ".", "Either", "the", "name", "or", "type", "of", "library", "may", "be", "set", "to", "empty", "values", "in", "order", "to", "search", "for", "all", "libraries", "all", "libraries", "with", "a", "specific", "name", "regardless", "of", "type", "or", "all", "libraries", "of", "a", "specified", "type", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library.go#L83-L90
21,353
vmware/govmomi
vapi/library/library.go
CreateLibrary
func (c *Manager) CreateLibrary(ctx context.Context, library Library) (string, error) { if library.Type != "LOCAL" { return "", fmt.Errorf("unsupported library type: %q", library.Type) } spec := struct { Library Library `json:"create_spec"` }{library} url := internal.URL(c, internal.LocalLibraryPath) var res string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
go
func (c *Manager) CreateLibrary(ctx context.Context, library Library) (string, error) { if library.Type != "LOCAL" { return "", fmt.Errorf("unsupported library type: %q", library.Type) } spec := struct { Library Library `json:"create_spec"` }{library} url := internal.URL(c, internal.LocalLibraryPath) var res string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
[ "func", "(", "c", "*", "Manager", ")", "CreateLibrary", "(", "ctx", "context", ".", "Context", ",", "library", "Library", ")", "(", "string", ",", "error", ")", "{", "if", "library", ".", "Type", "!=", "\"", "\"", "{", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "library", ".", "Type", ")", "\n", "}", "\n", "spec", ":=", "struct", "{", "Library", "Library", "`json:\"create_spec\"`", "\n", "}", "{", "library", "}", "\n", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LocalLibraryPath", ")", "\n", "var", "res", "string", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "spec", ")", ",", "&", "res", ")", "\n", "}" ]
// CreateLibrary creates a new library with the given Type, Name, // Description, and CategoryID.
[ "CreateLibrary", "creates", "a", "new", "library", "with", "the", "given", "Type", "Name", "Description", "and", "CategoryID", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library.go#L94-L104
21,354
vmware/govmomi
vapi/library/library.go
DeleteLibrary
func (c *Manager) DeleteLibrary(ctx context.Context, library *Library) error { url := internal.URL(c, internal.LocalLibraryPath).WithID(library.ID) return c.Do(ctx, url.Request(http.MethodDelete), nil) }
go
func (c *Manager) DeleteLibrary(ctx context.Context, library *Library) error { url := internal.URL(c, internal.LocalLibraryPath).WithID(library.ID) return c.Do(ctx, url.Request(http.MethodDelete), nil) }
[ "func", "(", "c", "*", "Manager", ")", "DeleteLibrary", "(", "ctx", "context", ".", "Context", ",", "library", "*", "Library", ")", "error", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LocalLibraryPath", ")", ".", "WithID", "(", "library", ".", "ID", ")", "\n", "return", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodDelete", ")", ",", "nil", ")", "\n", "}" ]
// DeleteLibrary deletes an existing library.
[ "DeleteLibrary", "deletes", "an", "existing", "library", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library.go#L107-L110
21,355
vmware/govmomi
vapi/library/library.go
ListLibraries
func (c *Manager) ListLibraries(ctx context.Context) ([]string, error) { url := internal.URL(c, internal.LibraryPath) var res []string return res, c.Do(ctx, url.Request(http.MethodGet), &res) }
go
func (c *Manager) ListLibraries(ctx context.Context) ([]string, error) { url := internal.URL(c, internal.LibraryPath) var res []string return res, c.Do(ctx, url.Request(http.MethodGet), &res) }
[ "func", "(", "c", "*", "Manager", ")", "ListLibraries", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LibraryPath", ")", "\n", "var", "res", "[", "]", "string", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodGet", ")", ",", "&", "res", ")", "\n", "}" ]
// ListLibraries returns a list of all content library IDs in the system.
[ "ListLibraries", "returns", "a", "list", "of", "all", "content", "library", "IDs", "in", "the", "system", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library.go#L113-L117
21,356
vmware/govmomi
vapi/library/library.go
GetLibraryByID
func (c *Manager) GetLibraryByID(ctx context.Context, id string) (*Library, error) { url := internal.URL(c, internal.LibraryPath).WithID(id) var res Library return &res, c.Do(ctx, url.Request(http.MethodGet), &res) }
go
func (c *Manager) GetLibraryByID(ctx context.Context, id string) (*Library, error) { url := internal.URL(c, internal.LibraryPath).WithID(id) var res Library return &res, c.Do(ctx, url.Request(http.MethodGet), &res) }
[ "func", "(", "c", "*", "Manager", ")", "GetLibraryByID", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "(", "*", "Library", ",", "error", ")", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LibraryPath", ")", ".", "WithID", "(", "id", ")", "\n", "var", "res", "Library", "\n", "return", "&", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodGet", ")", ",", "&", "res", ")", "\n", "}" ]
// GetLibraryByID returns information on a library for the given ID.
[ "GetLibraryByID", "returns", "information", "on", "a", "library", "for", "the", "given", "ID", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library.go#L120-L124
21,357
vmware/govmomi
vapi/library/library.go
GetLibraryByName
func (c *Manager) GetLibraryByName(ctx context.Context, name string) (*Library, error) { // Lookup by name libraries, err := c.GetLibraries(ctx) if err != nil { return nil, err } for i := range libraries { if libraries[i].Name == name { return &libraries[i], nil } } return nil, fmt.Errorf("library name (%s) not found", name) }
go
func (c *Manager) GetLibraryByName(ctx context.Context, name string) (*Library, error) { // Lookup by name libraries, err := c.GetLibraries(ctx) if err != nil { return nil, err } for i := range libraries { if libraries[i].Name == name { return &libraries[i], nil } } return nil, fmt.Errorf("library name (%s) not found", name) }
[ "func", "(", "c", "*", "Manager", ")", "GetLibraryByName", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "(", "*", "Library", ",", "error", ")", "{", "// Lookup by name", "libraries", ",", "err", ":=", "c", ".", "GetLibraries", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "i", ":=", "range", "libraries", "{", "if", "libraries", "[", "i", "]", ".", "Name", "==", "name", "{", "return", "&", "libraries", "[", "i", "]", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}" ]
// GetLibraryByName returns information on a library for the given name.
[ "GetLibraryByName", "returns", "information", "on", "a", "library", "for", "the", "given", "name", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library.go#L127-L139
21,358
vmware/govmomi
vapi/library/library.go
GetLibraries
func (c *Manager) GetLibraries(ctx context.Context) ([]Library, error) { ids, err := c.ListLibraries(ctx) if err != nil { return nil, fmt.Errorf("get libraries failed for: %s", err) } var libraries []Library for _, id := range ids { library, err := c.GetLibraryByID(ctx, id) if err != nil { return nil, fmt.Errorf("get library %s failed for %s", id, err) } libraries = append(libraries, *library) } return libraries, nil }
go
func (c *Manager) GetLibraries(ctx context.Context) ([]Library, error) { ids, err := c.ListLibraries(ctx) if err != nil { return nil, fmt.Errorf("get libraries failed for: %s", err) } var libraries []Library for _, id := range ids { library, err := c.GetLibraryByID(ctx, id) if err != nil { return nil, fmt.Errorf("get library %s failed for %s", id, err) } libraries = append(libraries, *library) } return libraries, nil }
[ "func", "(", "c", "*", "Manager", ")", "GetLibraries", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "Library", ",", "error", ")", "{", "ids", ",", "err", ":=", "c", ".", "ListLibraries", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "var", "libraries", "[", "]", "Library", "\n", "for", "_", ",", "id", ":=", "range", "ids", "{", "library", ",", "err", ":=", "c", ".", "GetLibraryByID", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "id", ",", "err", ")", "\n", "}", "\n\n", "libraries", "=", "append", "(", "libraries", ",", "*", "library", ")", "\n\n", "}", "\n", "return", "libraries", ",", "nil", "\n", "}" ]
// GetLibraries returns a list of all content library details in the system.
[ "GetLibraries", "returns", "a", "list", "of", "all", "content", "library", "details", "in", "the", "system", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library.go#L142-L159
21,359
vmware/govmomi
simulator/property_collector.go
wrapValue
func wrapValue(rval reflect.Value, rtype reflect.Type) interface{} { pval := rval.Interface() if rval.Kind() == reflect.Slice { // Convert slice to types.ArrayOf* switch v := pval.(type) { case []string: pval = &types.ArrayOfString{ String: v, } case []uint8: pval = &types.ArrayOfByte{ Byte: v, } case []int16: pval = &types.ArrayOfShort{ Short: v, } case []int32: pval = &types.ArrayOfInt{ Int: v, } case []int64: pval = &types.ArrayOfLong{ Long: v, } default: kind := rtype.Elem().Name() // Remove govmomi interface prefix name kind = strings.TrimPrefix(kind, "Base") akind, _ := defaultMapType("ArrayOf" + kind) a := reflect.New(akind) a.Elem().FieldByName(kind).Set(rval) pval = a.Interface() } } return pval }
go
func wrapValue(rval reflect.Value, rtype reflect.Type) interface{} { pval := rval.Interface() if rval.Kind() == reflect.Slice { // Convert slice to types.ArrayOf* switch v := pval.(type) { case []string: pval = &types.ArrayOfString{ String: v, } case []uint8: pval = &types.ArrayOfByte{ Byte: v, } case []int16: pval = &types.ArrayOfShort{ Short: v, } case []int32: pval = &types.ArrayOfInt{ Int: v, } case []int64: pval = &types.ArrayOfLong{ Long: v, } default: kind := rtype.Elem().Name() // Remove govmomi interface prefix name kind = strings.TrimPrefix(kind, "Base") akind, _ := defaultMapType("ArrayOf" + kind) a := reflect.New(akind) a.Elem().FieldByName(kind).Set(rval) pval = a.Interface() } } return pval }
[ "func", "wrapValue", "(", "rval", "reflect", ".", "Value", ",", "rtype", "reflect", ".", "Type", ")", "interface", "{", "}", "{", "pval", ":=", "rval", ".", "Interface", "(", ")", "\n\n", "if", "rval", ".", "Kind", "(", ")", "==", "reflect", ".", "Slice", "{", "// Convert slice to types.ArrayOf*", "switch", "v", ":=", "pval", ".", "(", "type", ")", "{", "case", "[", "]", "string", ":", "pval", "=", "&", "types", ".", "ArrayOfString", "{", "String", ":", "v", ",", "}", "\n", "case", "[", "]", "uint8", ":", "pval", "=", "&", "types", ".", "ArrayOfByte", "{", "Byte", ":", "v", ",", "}", "\n", "case", "[", "]", "int16", ":", "pval", "=", "&", "types", ".", "ArrayOfShort", "{", "Short", ":", "v", ",", "}", "\n", "case", "[", "]", "int32", ":", "pval", "=", "&", "types", ".", "ArrayOfInt", "{", "Int", ":", "v", ",", "}", "\n", "case", "[", "]", "int64", ":", "pval", "=", "&", "types", ".", "ArrayOfLong", "{", "Long", ":", "v", ",", "}", "\n", "default", ":", "kind", ":=", "rtype", ".", "Elem", "(", ")", ".", "Name", "(", ")", "\n", "// Remove govmomi interface prefix name", "kind", "=", "strings", ".", "TrimPrefix", "(", "kind", ",", "\"", "\"", ")", "\n", "akind", ",", "_", ":=", "defaultMapType", "(", "\"", "\"", "+", "kind", ")", "\n", "a", ":=", "reflect", ".", "New", "(", "akind", ")", "\n", "a", ".", "Elem", "(", ")", ".", "FieldByName", "(", "kind", ")", ".", "Set", "(", "rval", ")", "\n", "pval", "=", "a", ".", "Interface", "(", ")", "\n", "}", "\n", "}", "\n\n", "return", "pval", "\n", "}" ]
// wrapValue converts slice types to the appropriate ArrayOf type used in property collector responses.
[ "wrapValue", "converts", "slice", "types", "to", "the", "appropriate", "ArrayOf", "type", "used", "in", "property", "collector", "responses", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/property_collector.go#L113-L151
21,360
vmware/govmomi
simulator/property_collector.go
RetrieveProperties
func (pc *PropertyCollector) RetrieveProperties(ctx *Context, r *types.RetrieveProperties) soap.HasFault { body := &methods.RetrievePropertiesBody{} res := pc.RetrievePropertiesEx(ctx, &types.RetrievePropertiesEx{ This: r.This, SpecSet: r.SpecSet, }) if res.Fault() != nil { body.Fault_ = res.Fault() } else { body.Res = &types.RetrievePropertiesResponse{ Returnval: res.(*methods.RetrievePropertiesExBody).Res.Returnval.Objects, } } return body }
go
func (pc *PropertyCollector) RetrieveProperties(ctx *Context, r *types.RetrieveProperties) soap.HasFault { body := &methods.RetrievePropertiesBody{} res := pc.RetrievePropertiesEx(ctx, &types.RetrievePropertiesEx{ This: r.This, SpecSet: r.SpecSet, }) if res.Fault() != nil { body.Fault_ = res.Fault() } else { body.Res = &types.RetrievePropertiesResponse{ Returnval: res.(*methods.RetrievePropertiesExBody).Res.Returnval.Objects, } } return body }
[ "func", "(", "pc", "*", "PropertyCollector", ")", "RetrieveProperties", "(", "ctx", "*", "Context", ",", "r", "*", "types", ".", "RetrieveProperties", ")", "soap", ".", "HasFault", "{", "body", ":=", "&", "methods", ".", "RetrievePropertiesBody", "{", "}", "\n\n", "res", ":=", "pc", ".", "RetrievePropertiesEx", "(", "ctx", ",", "&", "types", ".", "RetrievePropertiesEx", "{", "This", ":", "r", ".", "This", ",", "SpecSet", ":", "r", ".", "SpecSet", ",", "}", ")", "\n\n", "if", "res", ".", "Fault", "(", ")", "!=", "nil", "{", "body", ".", "Fault_", "=", "res", ".", "Fault", "(", ")", "\n", "}", "else", "{", "body", ".", "Res", "=", "&", "types", ".", "RetrievePropertiesResponse", "{", "Returnval", ":", "res", ".", "(", "*", "methods", ".", "RetrievePropertiesExBody", ")", ".", "Res", ".", "Returnval", ".", "Objects", ",", "}", "\n", "}", "\n\n", "return", "body", "\n", "}" ]
// RetrieveProperties is deprecated, but govmomi is still using it at the moment.
[ "RetrieveProperties", "is", "deprecated", "but", "govmomi", "is", "still", "using", "it", "at", "the", "moment", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/property_collector.go#L531-L548
21,361
vmware/govmomi
simulator/property_collector.go
WaitForUpdates
func (pc *PropertyCollector) WaitForUpdates(ctx *Context, r *types.WaitForUpdates) soap.HasFault { body := &methods.WaitForUpdatesBody{} res := pc.WaitForUpdatesEx(ctx, &types.WaitForUpdatesEx{ This: r.This, Version: r.Version, }) if res.Fault() != nil { body.Fault_ = res.Fault() } else { body.Res = &types.WaitForUpdatesResponse{ Returnval: *res.(*methods.WaitForUpdatesExBody).Res.Returnval, } } return body }
go
func (pc *PropertyCollector) WaitForUpdates(ctx *Context, r *types.WaitForUpdates) soap.HasFault { body := &methods.WaitForUpdatesBody{} res := pc.WaitForUpdatesEx(ctx, &types.WaitForUpdatesEx{ This: r.This, Version: r.Version, }) if res.Fault() != nil { body.Fault_ = res.Fault() } else { body.Res = &types.WaitForUpdatesResponse{ Returnval: *res.(*methods.WaitForUpdatesExBody).Res.Returnval, } } return body }
[ "func", "(", "pc", "*", "PropertyCollector", ")", "WaitForUpdates", "(", "ctx", "*", "Context", ",", "r", "*", "types", ".", "WaitForUpdates", ")", "soap", ".", "HasFault", "{", "body", ":=", "&", "methods", ".", "WaitForUpdatesBody", "{", "}", "\n\n", "res", ":=", "pc", ".", "WaitForUpdatesEx", "(", "ctx", ",", "&", "types", ".", "WaitForUpdatesEx", "{", "This", ":", "r", ".", "This", ",", "Version", ":", "r", ".", "Version", ",", "}", ")", "\n\n", "if", "res", ".", "Fault", "(", ")", "!=", "nil", "{", "body", ".", "Fault_", "=", "res", ".", "Fault", "(", ")", "\n", "}", "else", "{", "body", ".", "Res", "=", "&", "types", ".", "WaitForUpdatesResponse", "{", "Returnval", ":", "*", "res", ".", "(", "*", "methods", ".", "WaitForUpdatesExBody", ")", ".", "Res", ".", "Returnval", ",", "}", "\n", "}", "\n\n", "return", "body", "\n", "}" ]
// WaitForUpdates is deprecated, but pyvmomi is still using it at the moment.
[ "WaitForUpdates", "is", "deprecated", "but", "pyvmomi", "is", "still", "using", "it", "at", "the", "moment", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/property_collector.go#L759-L776
21,362
vmware/govmomi
simulator/property_collector.go
Fetch
func (pc *PropertyCollector) Fetch(ctx *Context, req *internal.Fetch) soap.HasFault { body := new(internal.FetchBody) if req.This == vim25.ServiceInstance && req.Prop == "content" { content := ctx.Map.content() // ovftool uses API version for 6.0 and fails when these fields are non-nil; TODO content.VStorageObjectManager = nil content.HostProfileManager = nil content.HostSpecManager = nil content.CryptoManager = nil content.HostProfileManager = nil content.HealthUpdateManager = nil content.FailoverClusterConfigurator = nil content.FailoverClusterManager = nil body.Res = &internal.FetchResponse{ Returnval: content, } return body } if ctx.Map.Get(req.This) == nil { // The Fetch method supports use of super class types, this is a quick hack to support the cases used by ovftool switch req.This.Type { case "ManagedEntity": for o := range ctx.Map.objects { if o.Value == req.This.Value { req.This.Type = o.Type break } } case "ComputeResource": req.This.Type = "Cluster" + req.This.Type } } res := pc.RetrievePropertiesEx(ctx, &types.RetrievePropertiesEx{ SpecSet: []types.PropertyFilterSpec{{ PropSet: []types.PropertySpec{{ Type: req.This.Type, PathSet: []string{req.Prop}, }}, ObjectSet: []types.ObjectSpec{{ Obj: req.This, }}, }}}) if res.Fault() != nil { return res } obj := res.(*methods.RetrievePropertiesExBody).Res.Returnval.Objects[0] if len(obj.PropSet) == 0 { fault := obj.MissingSet[0].Fault body.Fault_ = Fault(fault.LocalizedMessage, fault.Fault) return body } body.Res = &internal.FetchResponse{ Returnval: obj.PropSet[0].Val, } return body }
go
func (pc *PropertyCollector) Fetch(ctx *Context, req *internal.Fetch) soap.HasFault { body := new(internal.FetchBody) if req.This == vim25.ServiceInstance && req.Prop == "content" { content := ctx.Map.content() // ovftool uses API version for 6.0 and fails when these fields are non-nil; TODO content.VStorageObjectManager = nil content.HostProfileManager = nil content.HostSpecManager = nil content.CryptoManager = nil content.HostProfileManager = nil content.HealthUpdateManager = nil content.FailoverClusterConfigurator = nil content.FailoverClusterManager = nil body.Res = &internal.FetchResponse{ Returnval: content, } return body } if ctx.Map.Get(req.This) == nil { // The Fetch method supports use of super class types, this is a quick hack to support the cases used by ovftool switch req.This.Type { case "ManagedEntity": for o := range ctx.Map.objects { if o.Value == req.This.Value { req.This.Type = o.Type break } } case "ComputeResource": req.This.Type = "Cluster" + req.This.Type } } res := pc.RetrievePropertiesEx(ctx, &types.RetrievePropertiesEx{ SpecSet: []types.PropertyFilterSpec{{ PropSet: []types.PropertySpec{{ Type: req.This.Type, PathSet: []string{req.Prop}, }}, ObjectSet: []types.ObjectSpec{{ Obj: req.This, }}, }}}) if res.Fault() != nil { return res } obj := res.(*methods.RetrievePropertiesExBody).Res.Returnval.Objects[0] if len(obj.PropSet) == 0 { fault := obj.MissingSet[0].Fault body.Fault_ = Fault(fault.LocalizedMessage, fault.Fault) return body } body.Res = &internal.FetchResponse{ Returnval: obj.PropSet[0].Val, } return body }
[ "func", "(", "pc", "*", "PropertyCollector", ")", "Fetch", "(", "ctx", "*", "Context", ",", "req", "*", "internal", ".", "Fetch", ")", "soap", ".", "HasFault", "{", "body", ":=", "new", "(", "internal", ".", "FetchBody", ")", "\n\n", "if", "req", ".", "This", "==", "vim25", ".", "ServiceInstance", "&&", "req", ".", "Prop", "==", "\"", "\"", "{", "content", ":=", "ctx", ".", "Map", ".", "content", "(", ")", "\n", "// ovftool uses API version for 6.0 and fails when these fields are non-nil; TODO", "content", ".", "VStorageObjectManager", "=", "nil", "\n", "content", ".", "HostProfileManager", "=", "nil", "\n", "content", ".", "HostSpecManager", "=", "nil", "\n", "content", ".", "CryptoManager", "=", "nil", "\n", "content", ".", "HostProfileManager", "=", "nil", "\n", "content", ".", "HealthUpdateManager", "=", "nil", "\n", "content", ".", "FailoverClusterConfigurator", "=", "nil", "\n", "content", ".", "FailoverClusterManager", "=", "nil", "\n", "body", ".", "Res", "=", "&", "internal", ".", "FetchResponse", "{", "Returnval", ":", "content", ",", "}", "\n", "return", "body", "\n", "}", "\n\n", "if", "ctx", ".", "Map", ".", "Get", "(", "req", ".", "This", ")", "==", "nil", "{", "// The Fetch method supports use of super class types, this is a quick hack to support the cases used by ovftool", "switch", "req", ".", "This", ".", "Type", "{", "case", "\"", "\"", ":", "for", "o", ":=", "range", "ctx", ".", "Map", ".", "objects", "{", "if", "o", ".", "Value", "==", "req", ".", "This", ".", "Value", "{", "req", ".", "This", ".", "Type", "=", "o", ".", "Type", "\n", "break", "\n", "}", "\n", "}", "\n", "case", "\"", "\"", ":", "req", ".", "This", ".", "Type", "=", "\"", "\"", "+", "req", ".", "This", ".", "Type", "\n", "}", "\n", "}", "\n\n", "res", ":=", "pc", ".", "RetrievePropertiesEx", "(", "ctx", ",", "&", "types", ".", "RetrievePropertiesEx", "{", "SpecSet", ":", "[", "]", "types", ".", "PropertyFilterSpec", "{", "{", "PropSet", ":", "[", "]", "types", ".", "PropertySpec", "{", "{", "Type", ":", "req", ".", "This", ".", "Type", ",", "PathSet", ":", "[", "]", "string", "{", "req", ".", "Prop", "}", ",", "}", "}", ",", "ObjectSet", ":", "[", "]", "types", ".", "ObjectSpec", "{", "{", "Obj", ":", "req", ".", "This", ",", "}", "}", ",", "}", "}", "}", ")", "\n\n", "if", "res", ".", "Fault", "(", ")", "!=", "nil", "{", "return", "res", "\n", "}", "\n\n", "obj", ":=", "res", ".", "(", "*", "methods", ".", "RetrievePropertiesExBody", ")", ".", "Res", ".", "Returnval", ".", "Objects", "[", "0", "]", "\n", "if", "len", "(", "obj", ".", "PropSet", ")", "==", "0", "{", "fault", ":=", "obj", ".", "MissingSet", "[", "0", "]", ".", "Fault", "\n", "body", ".", "Fault_", "=", "Fault", "(", "fault", ".", "LocalizedMessage", ",", "fault", ".", "Fault", ")", "\n", "return", "body", "\n", "}", "\n\n", "body", ".", "Res", "=", "&", "internal", ".", "FetchResponse", "{", "Returnval", ":", "obj", ".", "PropSet", "[", "0", "]", ".", "Val", ",", "}", "\n", "return", "body", "\n", "}" ]
// Fetch is not documented in the vSphere SDK, but ovftool depends on it. // A Fetch request is converted to a RetrievePropertiesEx method call by vcsim.
[ "Fetch", "is", "not", "documented", "in", "the", "vSphere", "SDK", "but", "ovftool", "depends", "on", "it", ".", "A", "Fetch", "request", "is", "converted", "to", "a", "RetrievePropertiesEx", "method", "call", "by", "vcsim", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/property_collector.go#L780-L841
21,363
vmware/govmomi
object/datastore_path.go
FromString
func (p *DatastorePath) FromString(s string) bool { if s == "" { return false } s = strings.TrimSpace(s) if !strings.HasPrefix(s, "[") { return false } s = s[1:] ix := strings.Index(s, "]") if ix < 0 { return false } p.Datastore = s[:ix] p.Path = strings.TrimSpace(s[ix+1:]) return true }
go
func (p *DatastorePath) FromString(s string) bool { if s == "" { return false } s = strings.TrimSpace(s) if !strings.HasPrefix(s, "[") { return false } s = s[1:] ix := strings.Index(s, "]") if ix < 0 { return false } p.Datastore = s[:ix] p.Path = strings.TrimSpace(s[ix+1:]) return true }
[ "func", "(", "p", "*", "DatastorePath", ")", "FromString", "(", "s", "string", ")", "bool", "{", "if", "s", "==", "\"", "\"", "{", "return", "false", "\n", "}", "\n\n", "s", "=", "strings", ".", "TrimSpace", "(", "s", ")", "\n\n", "if", "!", "strings", ".", "HasPrefix", "(", "s", ",", "\"", "\"", ")", "{", "return", "false", "\n", "}", "\n\n", "s", "=", "s", "[", "1", ":", "]", "\n\n", "ix", ":=", "strings", ".", "Index", "(", "s", ",", "\"", "\"", ")", "\n", "if", "ix", "<", "0", "{", "return", "false", "\n", "}", "\n\n", "p", ".", "Datastore", "=", "s", "[", ":", "ix", "]", "\n", "p", ".", "Path", "=", "strings", ".", "TrimSpace", "(", "s", "[", "ix", "+", "1", ":", "]", ")", "\n\n", "return", "true", "\n", "}" ]
// FromString parses a datastore path. // Returns true if the path could be parsed, false otherwise.
[ "FromString", "parses", "a", "datastore", "path", ".", "Returns", "true", "if", "the", "path", "could", "be", "parsed", "false", "otherwise", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_path.go#L33-L55
21,364
vmware/govmomi
object/datastore_path.go
String
func (p *DatastorePath) String() string { s := fmt.Sprintf("[%s]", p.Datastore) if p.Path == "" { return s } return strings.Join([]string{s, p.Path}, " ") }
go
func (p *DatastorePath) String() string { s := fmt.Sprintf("[%s]", p.Datastore) if p.Path == "" { return s } return strings.Join([]string{s, p.Path}, " ") }
[ "func", "(", "p", "*", "DatastorePath", ")", "String", "(", ")", "string", "{", "s", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "p", ".", "Datastore", ")", "\n\n", "if", "p", ".", "Path", "==", "\"", "\"", "{", "return", "s", "\n", "}", "\n\n", "return", "strings", ".", "Join", "(", "[", "]", "string", "{", "s", ",", "p", ".", "Path", "}", ",", "\"", "\"", ")", "\n", "}" ]
// String formats a datastore path.
[ "String", "formats", "a", "datastore", "path", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_path.go#L58-L66
21,365
vmware/govmomi
object/common.go
Name
func (c Common) Name() string { if c.InventoryPath == "" { return "" } return path.Base(c.InventoryPath) }
go
func (c Common) Name() string { if c.InventoryPath == "" { return "" } return path.Base(c.InventoryPath) }
[ "func", "(", "c", "Common", ")", "Name", "(", ")", "string", "{", "if", "c", ".", "InventoryPath", "==", "\"", "\"", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "path", ".", "Base", "(", "c", ".", "InventoryPath", ")", "\n", "}" ]
// Name returns the base name of the InventoryPath field
[ "Name", "returns", "the", "base", "name", "of", "the", "InventoryPath", "field" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/common.go#L67-L72
21,366
vmware/govmomi
object/common.go
ObjectName
func (c Common) ObjectName(ctx context.Context) (string, error) { var o mo.ManagedEntity err := c.Properties(ctx, c.Reference(), []string{"name"}, &o) if err != nil { return "", err } if o.Name != "" { return o.Name, nil } // Network has its own "name" field... var n mo.Network err = c.Properties(ctx, c.Reference(), []string{"name"}, &n) if err != nil { return "", err } return n.Name, nil }
go
func (c Common) ObjectName(ctx context.Context) (string, error) { var o mo.ManagedEntity err := c.Properties(ctx, c.Reference(), []string{"name"}, &o) if err != nil { return "", err } if o.Name != "" { return o.Name, nil } // Network has its own "name" field... var n mo.Network err = c.Properties(ctx, c.Reference(), []string{"name"}, &n) if err != nil { return "", err } return n.Name, nil }
[ "func", "(", "c", "Common", ")", "ObjectName", "(", "ctx", "context", ".", "Context", ")", "(", "string", ",", "error", ")", "{", "var", "o", "mo", ".", "ManagedEntity", "\n\n", "err", ":=", "c", ".", "Properties", "(", "ctx", ",", "c", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"", "\"", "}", ",", "&", "o", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "if", "o", ".", "Name", "!=", "\"", "\"", "{", "return", "o", ".", "Name", ",", "nil", "\n", "}", "\n\n", "// Network has its own \"name\" field...", "var", "n", "mo", ".", "Network", "\n\n", "err", "=", "c", ".", "Properties", "(", "ctx", ",", "c", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"", "\"", "}", ",", "&", "n", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "n", ".", "Name", ",", "nil", "\n", "}" ]
// ObjectName returns the base name of the InventoryPath field if set, // otherwise fetches the mo.ManagedEntity.Name field via the property collector.
[ "ObjectName", "returns", "the", "base", "name", "of", "the", "InventoryPath", "field", "if", "set", "otherwise", "fetches", "the", "mo", ".", "ManagedEntity", ".", "Name", "field", "via", "the", "property", "collector", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/common.go#L80-L101
21,367
vmware/govmomi
session/manager.go
UserSession
func (sm *Manager) UserSession(ctx context.Context) (*types.UserSession, error) { var mgr mo.SessionManager pc := property.DefaultCollector(sm.client) err := pc.RetrieveOne(ctx, sm.Reference(), []string{"currentSession"}, &mgr) if err != nil { // It's OK if we can't retrieve properties because we're not authenticated if f, ok := err.(types.HasFault); ok { switch f.Fault().(type) { case *types.NotAuthenticated: return nil, nil } } return nil, err } return mgr.CurrentSession, nil }
go
func (sm *Manager) UserSession(ctx context.Context) (*types.UserSession, error) { var mgr mo.SessionManager pc := property.DefaultCollector(sm.client) err := pc.RetrieveOne(ctx, sm.Reference(), []string{"currentSession"}, &mgr) if err != nil { // It's OK if we can't retrieve properties because we're not authenticated if f, ok := err.(types.HasFault); ok { switch f.Fault().(type) { case *types.NotAuthenticated: return nil, nil } } return nil, err } return mgr.CurrentSession, nil }
[ "func", "(", "sm", "*", "Manager", ")", "UserSession", "(", "ctx", "context", ".", "Context", ")", "(", "*", "types", ".", "UserSession", ",", "error", ")", "{", "var", "mgr", "mo", ".", "SessionManager", "\n\n", "pc", ":=", "property", ".", "DefaultCollector", "(", "sm", ".", "client", ")", "\n", "err", ":=", "pc", ".", "RetrieveOne", "(", "ctx", ",", "sm", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"", "\"", "}", ",", "&", "mgr", ")", "\n", "if", "err", "!=", "nil", "{", "// It's OK if we can't retrieve properties because we're not authenticated", "if", "f", ",", "ok", ":=", "err", ".", "(", "types", ".", "HasFault", ")", ";", "ok", "{", "switch", "f", ".", "Fault", "(", ")", ".", "(", "type", ")", "{", "case", "*", "types", ".", "NotAuthenticated", ":", "return", "nil", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "mgr", ".", "CurrentSession", ",", "nil", "\n", "}" ]
// UserSession retrieves and returns the SessionManager's CurrentSession field. // Nil is returned if the session is not authenticated.
[ "UserSession", "retrieves", "and", "returns", "the", "SessionManager", "s", "CurrentSession", "field", ".", "Nil", "is", "returned", "if", "the", "session", "is", "not", "authenticated", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/session/manager.go#L162-L180
21,368
vmware/govmomi
session/manager.go
SessionIsActive
func (sm *Manager) SessionIsActive(ctx context.Context) (bool, error) { if sm.userSession == nil { return false, nil } req := types.SessionIsActive{ This: sm.Reference(), SessionID: sm.userSession.Key, UserName: sm.userSession.UserName, } active, err := methods.SessionIsActive(ctx, sm.client, &req) if err != nil { return false, err } return active.Returnval, err }
go
func (sm *Manager) SessionIsActive(ctx context.Context) (bool, error) { if sm.userSession == nil { return false, nil } req := types.SessionIsActive{ This: sm.Reference(), SessionID: sm.userSession.Key, UserName: sm.userSession.UserName, } active, err := methods.SessionIsActive(ctx, sm.client, &req) if err != nil { return false, err } return active.Returnval, err }
[ "func", "(", "sm", "*", "Manager", ")", "SessionIsActive", "(", "ctx", "context", ".", "Context", ")", "(", "bool", ",", "error", ")", "{", "if", "sm", ".", "userSession", "==", "nil", "{", "return", "false", ",", "nil", "\n", "}", "\n\n", "req", ":=", "types", ".", "SessionIsActive", "{", "This", ":", "sm", ".", "Reference", "(", ")", ",", "SessionID", ":", "sm", ".", "userSession", ".", "Key", ",", "UserName", ":", "sm", ".", "userSession", ".", "UserName", ",", "}", "\n\n", "active", ",", "err", ":=", "methods", ".", "SessionIsActive", "(", "ctx", ",", "sm", ".", "client", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "return", "active", ".", "Returnval", ",", "err", "\n", "}" ]
// SessionIsActive checks whether the session that was created at login is // still valid. This function only works against vCenter.
[ "SessionIsActive", "checks", "whether", "the", "session", "that", "was", "created", "at", "login", "is", "still", "valid", ".", "This", "function", "only", "works", "against", "vCenter", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/session/manager.go#L194-L211
21,369
vmware/govmomi
property/collector.go
DefaultCollector
func DefaultCollector(c *vim25.Client) *Collector { p := Collector{ roundTripper: c, reference: c.ServiceContent.PropertyCollector, } return &p }
go
func DefaultCollector(c *vim25.Client) *Collector { p := Collector{ roundTripper: c, reference: c.ServiceContent.PropertyCollector, } return &p }
[ "func", "DefaultCollector", "(", "c", "*", "vim25", ".", "Client", ")", "*", "Collector", "{", "p", ":=", "Collector", "{", "roundTripper", ":", "c", ",", "reference", ":", "c", ".", "ServiceContent", ".", "PropertyCollector", ",", "}", "\n\n", "return", "&", "p", "\n", "}" ]
// DefaultCollector returns the session's default property collector.
[ "DefaultCollector", "returns", "the", "session", "s", "default", "property", "collector", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/property/collector.go#L41-L48
21,370
vmware/govmomi
property/collector.go
Create
func (p *Collector) Create(ctx context.Context) (*Collector, error) { req := types.CreatePropertyCollector{ This: p.Reference(), } res, err := methods.CreatePropertyCollector(ctx, p.roundTripper, &req) if err != nil { return nil, err } newp := Collector{ roundTripper: p.roundTripper, reference: res.Returnval, } return &newp, nil }
go
func (p *Collector) Create(ctx context.Context) (*Collector, error) { req := types.CreatePropertyCollector{ This: p.Reference(), } res, err := methods.CreatePropertyCollector(ctx, p.roundTripper, &req) if err != nil { return nil, err } newp := Collector{ roundTripper: p.roundTripper, reference: res.Returnval, } return &newp, nil }
[ "func", "(", "p", "*", "Collector", ")", "Create", "(", "ctx", "context", ".", "Context", ")", "(", "*", "Collector", ",", "error", ")", "{", "req", ":=", "types", ".", "CreatePropertyCollector", "{", "This", ":", "p", ".", "Reference", "(", ")", ",", "}", "\n\n", "res", ",", "err", ":=", "methods", ".", "CreatePropertyCollector", "(", "ctx", ",", "p", ".", "roundTripper", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "newp", ":=", "Collector", "{", "roundTripper", ":", "p", ".", "roundTripper", ",", "reference", ":", "res", ".", "Returnval", ",", "}", "\n\n", "return", "&", "newp", ",", "nil", "\n", "}" ]
// Create creates a new session-specific Collector that can be used to // retrieve property updates independent of any other Collector.
[ "Create", "creates", "a", "new", "session", "-", "specific", "Collector", "that", "can", "be", "used", "to", "retrieve", "property", "updates", "independent", "of", "any", "other", "Collector", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/property/collector.go#L56-L72
21,371
vmware/govmomi
property/collector.go
Destroy
func (p *Collector) Destroy(ctx context.Context) error { req := types.DestroyPropertyCollector{ This: p.Reference(), } _, err := methods.DestroyPropertyCollector(ctx, p.roundTripper, &req) if err != nil { return err } p.reference = types.ManagedObjectReference{} return nil }
go
func (p *Collector) Destroy(ctx context.Context) error { req := types.DestroyPropertyCollector{ This: p.Reference(), } _, err := methods.DestroyPropertyCollector(ctx, p.roundTripper, &req) if err != nil { return err } p.reference = types.ManagedObjectReference{} return nil }
[ "func", "(", "p", "*", "Collector", ")", "Destroy", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ":=", "types", ".", "DestroyPropertyCollector", "{", "This", ":", "p", ".", "Reference", "(", ")", ",", "}", "\n\n", "_", ",", "err", ":=", "methods", ".", "DestroyPropertyCollector", "(", "ctx", ",", "p", ".", "roundTripper", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "p", ".", "reference", "=", "types", ".", "ManagedObjectReference", "{", "}", "\n", "return", "nil", "\n", "}" ]
// Destroy destroys this Collector.
[ "Destroy", "destroys", "this", "Collector", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/property/collector.go#L75-L87
21,372
vmware/govmomi
property/wait.go
Add
func (f *WaitFilter) Add(obj types.ManagedObjectReference, kind string, ps []string, set ...types.BaseSelectionSpec) *WaitFilter { spec := types.ObjectSpec{ Obj: obj, SelectSet: set, } pset := types.PropertySpec{ Type: kind, PathSet: ps, } if len(ps) == 0 { pset.All = types.NewBool(true) } f.Spec.ObjectSet = append(f.Spec.ObjectSet, spec) f.Spec.PropSet = append(f.Spec.PropSet, pset) return f }
go
func (f *WaitFilter) Add(obj types.ManagedObjectReference, kind string, ps []string, set ...types.BaseSelectionSpec) *WaitFilter { spec := types.ObjectSpec{ Obj: obj, SelectSet: set, } pset := types.PropertySpec{ Type: kind, PathSet: ps, } if len(ps) == 0 { pset.All = types.NewBool(true) } f.Spec.ObjectSet = append(f.Spec.ObjectSet, spec) f.Spec.PropSet = append(f.Spec.PropSet, pset) return f }
[ "func", "(", "f", "*", "WaitFilter", ")", "Add", "(", "obj", "types", ".", "ManagedObjectReference", ",", "kind", "string", ",", "ps", "[", "]", "string", ",", "set", "...", "types", ".", "BaseSelectionSpec", ")", "*", "WaitFilter", "{", "spec", ":=", "types", ".", "ObjectSpec", "{", "Obj", ":", "obj", ",", "SelectSet", ":", "set", ",", "}", "\n\n", "pset", ":=", "types", ".", "PropertySpec", "{", "Type", ":", "kind", ",", "PathSet", ":", "ps", ",", "}", "\n\n", "if", "len", "(", "ps", ")", "==", "0", "{", "pset", ".", "All", "=", "types", ".", "NewBool", "(", "true", ")", "\n", "}", "\n\n", "f", ".", "Spec", ".", "ObjectSet", "=", "append", "(", "f", ".", "Spec", ".", "ObjectSet", ",", "spec", ")", "\n\n", "f", ".", "Spec", ".", "PropSet", "=", "append", "(", "f", ".", "Spec", ".", "PropSet", ",", "pset", ")", "\n\n", "return", "f", "\n", "}" ]
// Add a new ObjectSpec and PropertySpec to the WaitFilter
[ "Add", "a", "new", "ObjectSpec", "and", "PropertySpec", "to", "the", "WaitFilter" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/property/wait.go#L33-L53
21,373
vmware/govmomi
property/wait.go
Wait
func Wait(ctx context.Context, c *Collector, obj types.ManagedObjectReference, ps []string, f func([]types.PropertyChange) bool) error { filter := new(WaitFilter).Add(obj, obj.Type, ps) return WaitForUpdates(ctx, c, filter, func(updates []types.ObjectUpdate) bool { for _, update := range updates { if f(update.ChangeSet) { return true } } return false }) }
go
func Wait(ctx context.Context, c *Collector, obj types.ManagedObjectReference, ps []string, f func([]types.PropertyChange) bool) error { filter := new(WaitFilter).Add(obj, obj.Type, ps) return WaitForUpdates(ctx, c, filter, func(updates []types.ObjectUpdate) bool { for _, update := range updates { if f(update.ChangeSet) { return true } } return false }) }
[ "func", "Wait", "(", "ctx", "context", ".", "Context", ",", "c", "*", "Collector", ",", "obj", "types", ".", "ManagedObjectReference", ",", "ps", "[", "]", "string", ",", "f", "func", "(", "[", "]", "types", ".", "PropertyChange", ")", "bool", ")", "error", "{", "filter", ":=", "new", "(", "WaitFilter", ")", ".", "Add", "(", "obj", ",", "obj", ".", "Type", ",", "ps", ")", "\n\n", "return", "WaitForUpdates", "(", "ctx", ",", "c", ",", "filter", ",", "func", "(", "updates", "[", "]", "types", ".", "ObjectUpdate", ")", "bool", "{", "for", "_", ",", "update", ":=", "range", "updates", "{", "if", "f", "(", "update", ".", "ChangeSet", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n\n", "return", "false", "\n", "}", ")", "\n", "}" ]
// Wait creates a new WaitFilter and calls the specified function for each ObjectUpdate via WaitForUpdates
[ "Wait", "creates", "a", "new", "WaitFilter", "and", "calls", "the", "specified", "function", "for", "each", "ObjectUpdate", "via", "WaitForUpdates" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/property/wait.go#L56-L68
21,374
vmware/govmomi
govc/flags/network.go
Change
func (flag *NetworkFlag) Change(device types.BaseVirtualDevice, update types.BaseVirtualDevice) { current := device.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard() changed := update.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard() current.Backing = changed.Backing if changed.MacAddress != "" { current.MacAddress = changed.MacAddress } if changed.AddressType != "" { current.AddressType = changed.AddressType } }
go
func (flag *NetworkFlag) Change(device types.BaseVirtualDevice, update types.BaseVirtualDevice) { current := device.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard() changed := update.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard() current.Backing = changed.Backing if changed.MacAddress != "" { current.MacAddress = changed.MacAddress } if changed.AddressType != "" { current.AddressType = changed.AddressType } }
[ "func", "(", "flag", "*", "NetworkFlag", ")", "Change", "(", "device", "types", ".", "BaseVirtualDevice", ",", "update", "types", ".", "BaseVirtualDevice", ")", "{", "current", ":=", "device", ".", "(", "types", ".", "BaseVirtualEthernetCard", ")", ".", "GetVirtualEthernetCard", "(", ")", "\n", "changed", ":=", "update", ".", "(", "types", ".", "BaseVirtualEthernetCard", ")", ".", "GetVirtualEthernetCard", "(", ")", "\n\n", "current", ".", "Backing", "=", "changed", ".", "Backing", "\n\n", "if", "changed", ".", "MacAddress", "!=", "\"", "\"", "{", "current", ".", "MacAddress", "=", "changed", ".", "MacAddress", "\n", "}", "\n\n", "if", "changed", ".", "AddressType", "!=", "\"", "\"", "{", "current", ".", "AddressType", "=", "changed", ".", "AddressType", "\n", "}", "\n", "}" ]
// Change applies update backing and hardware address changes to the given network device.
[ "Change", "applies", "update", "backing", "and", "hardware", "address", "changes", "to", "the", "given", "network", "device", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/network.go#L134-L147
21,375
vmware/govmomi
object/extension_manager.go
GetExtensionManager
func GetExtensionManager(c *vim25.Client) (*ExtensionManager, error) { if c.ServiceContent.ExtensionManager == nil { return nil, ErrNotSupported } return NewExtensionManager(c), nil }
go
func GetExtensionManager(c *vim25.Client) (*ExtensionManager, error) { if c.ServiceContent.ExtensionManager == nil { return nil, ErrNotSupported } return NewExtensionManager(c), nil }
[ "func", "GetExtensionManager", "(", "c", "*", "vim25", ".", "Client", ")", "(", "*", "ExtensionManager", ",", "error", ")", "{", "if", "c", ".", "ServiceContent", ".", "ExtensionManager", "==", "nil", "{", "return", "nil", ",", "ErrNotSupported", "\n", "}", "\n", "return", "NewExtensionManager", "(", "c", ")", ",", "nil", "\n", "}" ]
// GetExtensionManager wraps NewExtensionManager, returning ErrNotSupported // when the client is not connected to a vCenter instance.
[ "GetExtensionManager", "wraps", "NewExtensionManager", "returning", "ErrNotSupported", "when", "the", "client", "is", "not", "connected", "to", "a", "vCenter", "instance", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/extension_manager.go#L34-L39
21,376
vmware/govmomi
simulator/datacenter.go
NewDatacenter
func NewDatacenter(f *Folder) *Datacenter { dc := &Datacenter{ isESX: f.Self == esx.RootFolder.Self, } if dc.isESX { dc.Datacenter = esx.Datacenter } f.putChild(dc) dc.createFolders() return dc }
go
func NewDatacenter(f *Folder) *Datacenter { dc := &Datacenter{ isESX: f.Self == esx.RootFolder.Self, } if dc.isESX { dc.Datacenter = esx.Datacenter } f.putChild(dc) dc.createFolders() return dc }
[ "func", "NewDatacenter", "(", "f", "*", "Folder", ")", "*", "Datacenter", "{", "dc", ":=", "&", "Datacenter", "{", "isESX", ":", "f", ".", "Self", "==", "esx", ".", "RootFolder", ".", "Self", ",", "}", "\n\n", "if", "dc", ".", "isESX", "{", "dc", ".", "Datacenter", "=", "esx", ".", "Datacenter", "\n", "}", "\n\n", "f", ".", "putChild", "(", "dc", ")", "\n\n", "dc", ".", "createFolders", "(", ")", "\n\n", "return", "dc", "\n", "}" ]
// NewDatacenter creates a Datacenter and its child folders.
[ "NewDatacenter", "creates", "a", "Datacenter", "and", "its", "child", "folders", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/datacenter.go#L36-L50
21,377
vmware/govmomi
vapi/tags/tags.go
CreateTag
func (c *Manager) CreateTag(ctx context.Context, tag *Tag) (string, error) { // create avoids the annoyance of CreateTag requiring a "description" key to be included in the request, // even though the field value can be empty. type create struct { Name string `json:"name"` Description string `json:"description"` CategoryID string `json:"category_id"` } spec := struct { Tag create `json:"create_spec"` }{ Tag: create{ Name: tag.Name, Description: tag.Description, CategoryID: tag.CategoryID, }, } if isName(tag.CategoryID) { cat, err := c.GetCategory(ctx, tag.CategoryID) if err != nil { return "", err } spec.Tag.CategoryID = cat.ID } url := internal.URL(c, internal.TagPath) var res string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
go
func (c *Manager) CreateTag(ctx context.Context, tag *Tag) (string, error) { // create avoids the annoyance of CreateTag requiring a "description" key to be included in the request, // even though the field value can be empty. type create struct { Name string `json:"name"` Description string `json:"description"` CategoryID string `json:"category_id"` } spec := struct { Tag create `json:"create_spec"` }{ Tag: create{ Name: tag.Name, Description: tag.Description, CategoryID: tag.CategoryID, }, } if isName(tag.CategoryID) { cat, err := c.GetCategory(ctx, tag.CategoryID) if err != nil { return "", err } spec.Tag.CategoryID = cat.ID } url := internal.URL(c, internal.TagPath) var res string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
[ "func", "(", "c", "*", "Manager", ")", "CreateTag", "(", "ctx", "context", ".", "Context", ",", "tag", "*", "Tag", ")", "(", "string", ",", "error", ")", "{", "// create avoids the annoyance of CreateTag requiring a \"description\" key to be included in the request,", "// even though the field value can be empty.", "type", "create", "struct", "{", "Name", "string", "`json:\"name\"`", "\n", "Description", "string", "`json:\"description\"`", "\n", "CategoryID", "string", "`json:\"category_id\"`", "\n", "}", "\n", "spec", ":=", "struct", "{", "Tag", "create", "`json:\"create_spec\"`", "\n", "}", "{", "Tag", ":", "create", "{", "Name", ":", "tag", ".", "Name", ",", "Description", ":", "tag", ".", "Description", ",", "CategoryID", ":", "tag", ".", "CategoryID", ",", "}", ",", "}", "\n", "if", "isName", "(", "tag", ".", "CategoryID", ")", "{", "cat", ",", "err", ":=", "c", ".", "GetCategory", "(", "ctx", ",", "tag", ".", "CategoryID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "spec", ".", "Tag", ".", "CategoryID", "=", "cat", ".", "ID", "\n", "}", "\n", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "TagPath", ")", "\n", "var", "res", "string", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "spec", ")", ",", "&", "res", ")", "\n", "}" ]
// CreateTag creates a new tag with the given Name, Description and CategoryID.
[ "CreateTag", "creates", "a", "new", "tag", "with", "the", "given", "Name", "Description", "and", "CategoryID", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L69-L96
21,378
vmware/govmomi
vapi/tags/tags.go
UpdateTag
func (c *Manager) UpdateTag(ctx context.Context, tag *Tag) error { spec := struct { Tag Tag `json:"update_spec"` }{ Tag: Tag{ Name: tag.Name, Description: tag.Description, }, } url := internal.URL(c, internal.TagPath).WithID(tag.ID) return c.Do(ctx, url.Request(http.MethodPatch, spec), nil) }
go
func (c *Manager) UpdateTag(ctx context.Context, tag *Tag) error { spec := struct { Tag Tag `json:"update_spec"` }{ Tag: Tag{ Name: tag.Name, Description: tag.Description, }, } url := internal.URL(c, internal.TagPath).WithID(tag.ID) return c.Do(ctx, url.Request(http.MethodPatch, spec), nil) }
[ "func", "(", "c", "*", "Manager", ")", "UpdateTag", "(", "ctx", "context", ".", "Context", ",", "tag", "*", "Tag", ")", "error", "{", "spec", ":=", "struct", "{", "Tag", "Tag", "`json:\"update_spec\"`", "\n", "}", "{", "Tag", ":", "Tag", "{", "Name", ":", "tag", ".", "Name", ",", "Description", ":", "tag", ".", "Description", ",", "}", ",", "}", "\n", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "TagPath", ")", ".", "WithID", "(", "tag", ".", "ID", ")", "\n", "return", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPatch", ",", "spec", ")", ",", "nil", ")", "\n", "}" ]
// UpdateTag can update one or both of the tag Description and Name fields.
[ "UpdateTag", "can", "update", "one", "or", "both", "of", "the", "tag", "Description", "and", "Name", "fields", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L99-L110
21,379
vmware/govmomi
vapi/tags/tags.go
DeleteTag
func (c *Manager) DeleteTag(ctx context.Context, tag *Tag) error { url := internal.URL(c, internal.TagPath).WithID(tag.ID) return c.Do(ctx, url.Request(http.MethodDelete), nil) }
go
func (c *Manager) DeleteTag(ctx context.Context, tag *Tag) error { url := internal.URL(c, internal.TagPath).WithID(tag.ID) return c.Do(ctx, url.Request(http.MethodDelete), nil) }
[ "func", "(", "c", "*", "Manager", ")", "DeleteTag", "(", "ctx", "context", ".", "Context", ",", "tag", "*", "Tag", ")", "error", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "TagPath", ")", ".", "WithID", "(", "tag", ".", "ID", ")", "\n", "return", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodDelete", ")", ",", "nil", ")", "\n", "}" ]
// DeleteTag deletes an existing tag.
[ "DeleteTag", "deletes", "an", "existing", "tag", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L113-L116
21,380
vmware/govmomi
vapi/tags/tags.go
GetTag
func (c *Manager) GetTag(ctx context.Context, id string) (*Tag, error) { if isName(id) { tags, err := c.GetTags(ctx) if err != nil { return nil, err } for i := range tags { if tags[i].Name == id { return &tags[i], nil } } } url := internal.URL(c, internal.TagPath).WithID(id) var res Tag return &res, c.Do(ctx, url.Request(http.MethodGet), &res) }
go
func (c *Manager) GetTag(ctx context.Context, id string) (*Tag, error) { if isName(id) { tags, err := c.GetTags(ctx) if err != nil { return nil, err } for i := range tags { if tags[i].Name == id { return &tags[i], nil } } } url := internal.URL(c, internal.TagPath).WithID(id) var res Tag return &res, c.Do(ctx, url.Request(http.MethodGet), &res) }
[ "func", "(", "c", "*", "Manager", ")", "GetTag", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "(", "*", "Tag", ",", "error", ")", "{", "if", "isName", "(", "id", ")", "{", "tags", ",", "err", ":=", "c", ".", "GetTags", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "i", ":=", "range", "tags", "{", "if", "tags", "[", "i", "]", ".", "Name", "==", "id", "{", "return", "&", "tags", "[", "i", "]", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n\n", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "TagPath", ")", ".", "WithID", "(", "id", ")", "\n", "var", "res", "Tag", "\n", "return", "&", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodGet", ")", ",", "&", "res", ")", "\n\n", "}" ]
// GetTag fetches the tag information for the given identifier. // The id parameter can be a Tag ID or Tag Name.
[ "GetTag", "fetches", "the", "tag", "information", "for", "the", "given", "identifier", ".", "The", "id", "parameter", "can", "be", "a", "Tag", "ID", "or", "Tag", "Name", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L120-L138
21,381
vmware/govmomi
vapi/tags/tags.go
GetTagForCategory
func (c *Manager) GetTagForCategory(ctx context.Context, id, category string) (*Tag, error) { if category == "" { return c.GetTag(ctx, id) } ids, err := c.ListTagsForCategory(ctx, category) if err != nil { return nil, err } for _, tagid := range ids { tag, err := c.GetTag(ctx, tagid) if err != nil { return nil, fmt.Errorf("get tag for category %s %s: %s", category, tagid, err) } if tag.ID == id || tag.Name == id { return tag, nil } } return nil, fmt.Errorf("tag %q not found in category %q", id, category) }
go
func (c *Manager) GetTagForCategory(ctx context.Context, id, category string) (*Tag, error) { if category == "" { return c.GetTag(ctx, id) } ids, err := c.ListTagsForCategory(ctx, category) if err != nil { return nil, err } for _, tagid := range ids { tag, err := c.GetTag(ctx, tagid) if err != nil { return nil, fmt.Errorf("get tag for category %s %s: %s", category, tagid, err) } if tag.ID == id || tag.Name == id { return tag, nil } } return nil, fmt.Errorf("tag %q not found in category %q", id, category) }
[ "func", "(", "c", "*", "Manager", ")", "GetTagForCategory", "(", "ctx", "context", ".", "Context", ",", "id", ",", "category", "string", ")", "(", "*", "Tag", ",", "error", ")", "{", "if", "category", "==", "\"", "\"", "{", "return", "c", ".", "GetTag", "(", "ctx", ",", "id", ")", "\n", "}", "\n\n", "ids", ",", "err", ":=", "c", ".", "ListTagsForCategory", "(", "ctx", ",", "category", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "for", "_", ",", "tagid", ":=", "range", "ids", "{", "tag", ",", "err", ":=", "c", ".", "GetTag", "(", "ctx", ",", "tagid", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "category", ",", "tagid", ",", "err", ")", "\n", "}", "\n", "if", "tag", ".", "ID", "==", "id", "||", "tag", ".", "Name", "==", "id", "{", "return", "tag", ",", "nil", "\n", "}", "\n", "}", "\n\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "id", ",", "category", ")", "\n", "}" ]
// GetTagForCategory fetches the tag information for the given identifier in the given category.
[ "GetTagForCategory", "fetches", "the", "tag", "information", "for", "the", "given", "identifier", "in", "the", "given", "category", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L141-L162
21,382
vmware/govmomi
vapi/tags/tags.go
ListTags
func (c *Manager) ListTags(ctx context.Context) ([]string, error) { url := internal.URL(c, internal.TagPath) var res []string return res, c.Do(ctx, url.Request(http.MethodGet), &res) }
go
func (c *Manager) ListTags(ctx context.Context) ([]string, error) { url := internal.URL(c, internal.TagPath) var res []string return res, c.Do(ctx, url.Request(http.MethodGet), &res) }
[ "func", "(", "c", "*", "Manager", ")", "ListTags", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "string", ",", "error", ")", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "TagPath", ")", "\n", "var", "res", "[", "]", "string", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodGet", ")", ",", "&", "res", ")", "\n", "}" ]
// ListTags returns all tag IDs in the system.
[ "ListTags", "returns", "all", "tag", "IDs", "in", "the", "system", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L165-L169
21,383
vmware/govmomi
vapi/tags/tags.go
GetTags
func (c *Manager) GetTags(ctx context.Context) ([]Tag, error) { ids, err := c.ListTags(ctx) if err != nil { return nil, fmt.Errorf("get tags failed for: %s", err) } var tags []Tag for _, id := range ids { tag, err := c.GetTag(ctx, id) if err != nil { return nil, fmt.Errorf("get category %s failed for %s", id, err) } tags = append(tags, *tag) } return tags, nil }
go
func (c *Manager) GetTags(ctx context.Context) ([]Tag, error) { ids, err := c.ListTags(ctx) if err != nil { return nil, fmt.Errorf("get tags failed for: %s", err) } var tags []Tag for _, id := range ids { tag, err := c.GetTag(ctx, id) if err != nil { return nil, fmt.Errorf("get category %s failed for %s", id, err) } tags = append(tags, *tag) } return tags, nil }
[ "func", "(", "c", "*", "Manager", ")", "GetTags", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "Tag", ",", "error", ")", "{", "ids", ",", "err", ":=", "c", ".", "ListTags", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "var", "tags", "[", "]", "Tag", "\n", "for", "_", ",", "id", ":=", "range", "ids", "{", "tag", ",", "err", ":=", "c", ".", "GetTag", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "id", ",", "err", ")", "\n", "}", "\n\n", "tags", "=", "append", "(", "tags", ",", "*", "tag", ")", "\n\n", "}", "\n", "return", "tags", ",", "nil", "\n", "}" ]
// GetTags fetches an array of tag information in the system.
[ "GetTags", "fetches", "an", "array", "of", "tag", "information", "in", "the", "system", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L172-L189
21,384
vmware/govmomi
vim25/soap/client.go
NewServiceClient
func (c *Client) NewServiceClient(path string, namespace string) *Client { vc := c.URL() u, err := url.Parse(path) if err != nil { log.Panicf("url.Parse(%q): %s", path, err) } if u.Host == "" { u.Scheme = vc.Scheme u.Host = vc.Host } client := NewClient(u, c.k) client.Namespace = "urn:" + namespace if cert := c.Certificate(); cert != nil { client.SetCertificate(*cert) } // Copy the trusted thumbprints c.hostsMu.Lock() for k, v := range c.hosts { client.hosts[k] = v } c.hostsMu.Unlock() // Copy the cookies client.Client.Jar.SetCookies(u, c.Client.Jar.Cookies(u)) // Set SOAP Header cookie for _, cookie := range client.Jar.Cookies(u) { if cookie.Name == SessionCookieName { client.cookie = cookie.Value break } } // Copy any query params (e.g. GOVMOMI_TUNNEL_PROXY_PORT used in testing) client.u.RawQuery = vc.RawQuery client.UserAgent = c.UserAgent return client }
go
func (c *Client) NewServiceClient(path string, namespace string) *Client { vc := c.URL() u, err := url.Parse(path) if err != nil { log.Panicf("url.Parse(%q): %s", path, err) } if u.Host == "" { u.Scheme = vc.Scheme u.Host = vc.Host } client := NewClient(u, c.k) client.Namespace = "urn:" + namespace if cert := c.Certificate(); cert != nil { client.SetCertificate(*cert) } // Copy the trusted thumbprints c.hostsMu.Lock() for k, v := range c.hosts { client.hosts[k] = v } c.hostsMu.Unlock() // Copy the cookies client.Client.Jar.SetCookies(u, c.Client.Jar.Cookies(u)) // Set SOAP Header cookie for _, cookie := range client.Jar.Cookies(u) { if cookie.Name == SessionCookieName { client.cookie = cookie.Value break } } // Copy any query params (e.g. GOVMOMI_TUNNEL_PROXY_PORT used in testing) client.u.RawQuery = vc.RawQuery client.UserAgent = c.UserAgent return client }
[ "func", "(", "c", "*", "Client", ")", "NewServiceClient", "(", "path", "string", ",", "namespace", "string", ")", "*", "Client", "{", "vc", ":=", "c", ".", "URL", "(", ")", "\n", "u", ",", "err", ":=", "url", ".", "Parse", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Panicf", "(", "\"", "\"", ",", "path", ",", "err", ")", "\n", "}", "\n", "if", "u", ".", "Host", "==", "\"", "\"", "{", "u", ".", "Scheme", "=", "vc", ".", "Scheme", "\n", "u", ".", "Host", "=", "vc", ".", "Host", "\n", "}", "\n\n", "client", ":=", "NewClient", "(", "u", ",", "c", ".", "k", ")", "\n", "client", ".", "Namespace", "=", "\"", "\"", "+", "namespace", "\n", "if", "cert", ":=", "c", ".", "Certificate", "(", ")", ";", "cert", "!=", "nil", "{", "client", ".", "SetCertificate", "(", "*", "cert", ")", "\n", "}", "\n\n", "// Copy the trusted thumbprints", "c", ".", "hostsMu", ".", "Lock", "(", ")", "\n", "for", "k", ",", "v", ":=", "range", "c", ".", "hosts", "{", "client", ".", "hosts", "[", "k", "]", "=", "v", "\n", "}", "\n", "c", ".", "hostsMu", ".", "Unlock", "(", ")", "\n\n", "// Copy the cookies", "client", ".", "Client", ".", "Jar", ".", "SetCookies", "(", "u", ",", "c", ".", "Client", ".", "Jar", ".", "Cookies", "(", "u", ")", ")", "\n\n", "// Set SOAP Header cookie", "for", "_", ",", "cookie", ":=", "range", "client", ".", "Jar", ".", "Cookies", "(", "u", ")", "{", "if", "cookie", ".", "Name", "==", "SessionCookieName", "{", "client", ".", "cookie", "=", "cookie", ".", "Value", "\n", "break", "\n", "}", "\n", "}", "\n\n", "// Copy any query params (e.g. GOVMOMI_TUNNEL_PROXY_PORT used in testing)", "client", ".", "u", ".", "RawQuery", "=", "vc", ".", "RawQuery", "\n\n", "client", ".", "UserAgent", "=", "c", ".", "UserAgent", "\n\n", "return", "client", "\n", "}" ]
// NewServiceClient creates a NewClient with the given URL.Path and namespace.
[ "NewServiceClient", "creates", "a", "NewClient", "with", "the", "given", "URL", ".", "Path", "and", "namespace", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L159-L200
21,385
vmware/govmomi
vim25/soap/client.go
hostAddr
func hostAddr(addr string) string { _, port := splitHostPort(addr) if port == "" { return addr + ":443" } return addr }
go
func hostAddr(addr string) string { _, port := splitHostPort(addr) if port == "" { return addr + ":443" } return addr }
[ "func", "hostAddr", "(", "addr", "string", ")", "string", "{", "_", ",", "port", ":=", "splitHostPort", "(", "addr", ")", "\n", "if", "port", "==", "\"", "\"", "{", "return", "addr", "+", "\"", "\"", "\n", "}", "\n", "return", "addr", "\n", "}" ]
// Add default https port if missing
[ "Add", "default", "https", "port", "if", "missing" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L229-L235
21,386
vmware/govmomi
vim25/soap/client.go
Thumbprint
func (c *Client) Thumbprint(host string) string { host = hostAddr(host) c.hostsMu.Lock() defer c.hostsMu.Unlock() return c.hosts[host] }
go
func (c *Client) Thumbprint(host string) string { host = hostAddr(host) c.hostsMu.Lock() defer c.hostsMu.Unlock() return c.hosts[host] }
[ "func", "(", "c", "*", "Client", ")", "Thumbprint", "(", "host", "string", ")", "string", "{", "host", "=", "hostAddr", "(", "host", ")", "\n", "c", ".", "hostsMu", ".", "Lock", "(", ")", "\n", "defer", "c", ".", "hostsMu", ".", "Unlock", "(", ")", "\n", "return", "c", ".", "hosts", "[", "host", "]", "\n", "}" ]
// Thumbprint returns the certificate thumbprint for the given host if known to this client.
[ "Thumbprint", "returns", "the", "certificate", "thumbprint", "for", "the", "given", "host", "if", "known", "to", "this", "client", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L256-L261
21,387
vmware/govmomi
vim25/soap/client.go
LoadThumbprints
func (c *Client) LoadThumbprints(file string) error { if file == "" { return nil } for _, name := range filepath.SplitList(file) { err := c.loadThumbprints(name) if err != nil { return err } } return nil }
go
func (c *Client) LoadThumbprints(file string) error { if file == "" { return nil } for _, name := range filepath.SplitList(file) { err := c.loadThumbprints(name) if err != nil { return err } } return nil }
[ "func", "(", "c", "*", "Client", ")", "LoadThumbprints", "(", "file", "string", ")", "error", "{", "if", "file", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n\n", "for", "_", ",", "name", ":=", "range", "filepath", ".", "SplitList", "(", "file", ")", "{", "err", ":=", "c", ".", "loadThumbprints", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// LoadThumbprints from file with the give name. // If name is empty or name does not exist this function will return nil.
[ "LoadThumbprints", "from", "file", "with", "the", "give", "name", ".", "If", "name", "is", "empty", "or", "name", "does", "not", "exist", "this", "function", "will", "return", "nil", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L265-L278
21,388
vmware/govmomi
vim25/soap/client.go
WithHeader
func (c *Client) WithHeader(ctx context.Context, header Header) context.Context { return context.WithValue(ctx, headerContext{}, header) }
go
func (c *Client) WithHeader(ctx context.Context, header Header) context.Context { return context.WithValue(ctx, headerContext{}, header) }
[ "func", "(", "c", "*", "Client", ")", "WithHeader", "(", "ctx", "context", ".", "Context", ",", "header", "Header", ")", "context", ".", "Context", "{", "return", "context", ".", "WithValue", "(", "ctx", ",", "headerContext", "{", "}", ",", "header", ")", "\n", "}" ]
// WithHeader can be used to modify the outgoing request soap.Header fields.
[ "WithHeader", "can", "be", "used", "to", "modify", "the", "outgoing", "request", "soap", ".", "Header", "fields", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L511-L513
21,389
vmware/govmomi
vim25/soap/client.go
Upload
func (c *Client) Upload(ctx context.Context, f io.Reader, u *url.URL, param *Upload) error { var err error if param.Progress != nil { pr := progress.NewReader(ctx, param.Progress, f, param.ContentLength) f = pr // Mark progress reader as done when returning from this function. defer func() { pr.Done(err) }() } req, err := http.NewRequest(param.Method, u.String(), f) if err != nil { return err } req = req.WithContext(ctx) req.ContentLength = param.ContentLength req.Header.Set("Content-Type", param.Type) for k, v := range param.Headers { req.Header.Add(k, v) } if param.Ticket != nil { req.AddCookie(param.Ticket) } res, err := c.Client.Do(req) if err != nil { return err } defer res.Body.Close() switch res.StatusCode { case http.StatusOK: case http.StatusCreated: default: err = errors.New(res.Status) } return err }
go
func (c *Client) Upload(ctx context.Context, f io.Reader, u *url.URL, param *Upload) error { var err error if param.Progress != nil { pr := progress.NewReader(ctx, param.Progress, f, param.ContentLength) f = pr // Mark progress reader as done when returning from this function. defer func() { pr.Done(err) }() } req, err := http.NewRequest(param.Method, u.String(), f) if err != nil { return err } req = req.WithContext(ctx) req.ContentLength = param.ContentLength req.Header.Set("Content-Type", param.Type) for k, v := range param.Headers { req.Header.Add(k, v) } if param.Ticket != nil { req.AddCookie(param.Ticket) } res, err := c.Client.Do(req) if err != nil { return err } defer res.Body.Close() switch res.StatusCode { case http.StatusOK: case http.StatusCreated: default: err = errors.New(res.Status) } return err }
[ "func", "(", "c", "*", "Client", ")", "Upload", "(", "ctx", "context", ".", "Context", ",", "f", "io", ".", "Reader", ",", "u", "*", "url", ".", "URL", ",", "param", "*", "Upload", ")", "error", "{", "var", "err", "error", "\n\n", "if", "param", ".", "Progress", "!=", "nil", "{", "pr", ":=", "progress", ".", "NewReader", "(", "ctx", ",", "param", ".", "Progress", ",", "f", ",", "param", ".", "ContentLength", ")", "\n", "f", "=", "pr", "\n\n", "// Mark progress reader as done when returning from this function.", "defer", "func", "(", ")", "{", "pr", ".", "Done", "(", "err", ")", "\n", "}", "(", ")", "\n", "}", "\n\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "param", ".", "Method", ",", "u", ".", "String", "(", ")", ",", "f", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "req", "=", "req", ".", "WithContext", "(", "ctx", ")", "\n\n", "req", ".", "ContentLength", "=", "param", ".", "ContentLength", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "param", ".", "Type", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "param", ".", "Headers", "{", "req", ".", "Header", ".", "Add", "(", "k", ",", "v", ")", "\n", "}", "\n\n", "if", "param", ".", "Ticket", "!=", "nil", "{", "req", ".", "AddCookie", "(", "param", ".", "Ticket", ")", "\n", "}", "\n\n", "res", ",", "err", ":=", "c", ".", "Client", ".", "Do", "(", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "res", ".", "Body", ".", "Close", "(", ")", "\n\n", "switch", "res", ".", "StatusCode", "{", "case", "http", ".", "StatusOK", ":", "case", "http", ".", "StatusCreated", ":", "default", ":", "err", "=", "errors", ".", "New", "(", "res", ".", "Status", ")", "\n", "}", "\n\n", "return", "err", "\n", "}" ]
// Upload PUTs the local file to the given URL
[ "Upload", "PUTs", "the", "local", "file", "to", "the", "given", "URL" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L625-L671
21,390
vmware/govmomi
vim25/soap/client.go
UploadFile
func (c *Client) UploadFile(ctx context.Context, file string, u *url.URL, param *Upload) error { if param == nil { p := DefaultUpload // Copy since we set ContentLength param = &p } s, err := os.Stat(file) if err != nil { return err } f, err := os.Open(filepath.Clean(file)) if err != nil { return err } defer f.Close() param.ContentLength = s.Size() return c.Upload(ctx, f, u, param) }
go
func (c *Client) UploadFile(ctx context.Context, file string, u *url.URL, param *Upload) error { if param == nil { p := DefaultUpload // Copy since we set ContentLength param = &p } s, err := os.Stat(file) if err != nil { return err } f, err := os.Open(filepath.Clean(file)) if err != nil { return err } defer f.Close() param.ContentLength = s.Size() return c.Upload(ctx, f, u, param) }
[ "func", "(", "c", "*", "Client", ")", "UploadFile", "(", "ctx", "context", ".", "Context", ",", "file", "string", ",", "u", "*", "url", ".", "URL", ",", "param", "*", "Upload", ")", "error", "{", "if", "param", "==", "nil", "{", "p", ":=", "DefaultUpload", "// Copy since we set ContentLength", "\n", "param", "=", "&", "p", "\n", "}", "\n\n", "s", ",", "err", ":=", "os", ".", "Stat", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "f", ",", "err", ":=", "os", ".", "Open", "(", "filepath", ".", "Clean", "(", "file", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "param", ".", "ContentLength", "=", "s", ".", "Size", "(", ")", "\n\n", "return", "c", ".", "Upload", "(", "ctx", ",", "f", ",", "u", ",", "param", ")", "\n", "}" ]
// UploadFile PUTs the local file to the given URL
[ "UploadFile", "PUTs", "the", "local", "file", "to", "the", "given", "URL" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L674-L694
21,391
vmware/govmomi
vim25/soap/client.go
DownloadRequest
func (c *Client) DownloadRequest(ctx context.Context, u *url.URL, param *Download) (*http.Response, error) { req, err := http.NewRequest(param.Method, u.String(), nil) if err != nil { return nil, err } req = req.WithContext(ctx) for k, v := range param.Headers { req.Header.Add(k, v) } if param.Ticket != nil { req.AddCookie(param.Ticket) } return c.Client.Do(req) }
go
func (c *Client) DownloadRequest(ctx context.Context, u *url.URL, param *Download) (*http.Response, error) { req, err := http.NewRequest(param.Method, u.String(), nil) if err != nil { return nil, err } req = req.WithContext(ctx) for k, v := range param.Headers { req.Header.Add(k, v) } if param.Ticket != nil { req.AddCookie(param.Ticket) } return c.Client.Do(req) }
[ "func", "(", "c", "*", "Client", ")", "DownloadRequest", "(", "ctx", "context", ".", "Context", ",", "u", "*", "url", ".", "URL", ",", "param", "*", "Download", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "param", ".", "Method", ",", "u", ".", "String", "(", ")", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "req", "=", "req", ".", "WithContext", "(", "ctx", ")", "\n\n", "for", "k", ",", "v", ":=", "range", "param", ".", "Headers", "{", "req", ".", "Header", ".", "Add", "(", "k", ",", "v", ")", "\n", "}", "\n\n", "if", "param", ".", "Ticket", "!=", "nil", "{", "req", ".", "AddCookie", "(", "param", ".", "Ticket", ")", "\n", "}", "\n\n", "return", "c", ".", "Client", ".", "Do", "(", "req", ")", "\n", "}" ]
// DownloadRequest wraps http.Client.Do, returning the http.Response without checking its StatusCode
[ "DownloadRequest", "wraps", "http", ".", "Client", ".", "Do", "returning", "the", "http", ".", "Response", "without", "checking", "its", "StatusCode" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L709-L726
21,392
vmware/govmomi
vim25/soap/client.go
Download
func (c *Client) Download(ctx context.Context, u *url.URL, param *Download) (io.ReadCloser, int64, error) { res, err := c.DownloadRequest(ctx, u, param) if err != nil { return nil, 0, err } switch res.StatusCode { case http.StatusOK: default: err = errors.New(res.Status) } if err != nil { return nil, 0, err } r := res.Body return r, res.ContentLength, nil }
go
func (c *Client) Download(ctx context.Context, u *url.URL, param *Download) (io.ReadCloser, int64, error) { res, err := c.DownloadRequest(ctx, u, param) if err != nil { return nil, 0, err } switch res.StatusCode { case http.StatusOK: default: err = errors.New(res.Status) } if err != nil { return nil, 0, err } r := res.Body return r, res.ContentLength, nil }
[ "func", "(", "c", "*", "Client", ")", "Download", "(", "ctx", "context", ".", "Context", ",", "u", "*", "url", ".", "URL", ",", "param", "*", "Download", ")", "(", "io", ".", "ReadCloser", ",", "int64", ",", "error", ")", "{", "res", ",", "err", ":=", "c", ".", "DownloadRequest", "(", "ctx", ",", "u", ",", "param", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n\n", "switch", "res", ".", "StatusCode", "{", "case", "http", ".", "StatusOK", ":", "default", ":", "err", "=", "errors", ".", "New", "(", "res", ".", "Status", ")", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n\n", "r", ":=", "res", ".", "Body", "\n\n", "return", "r", ",", "res", ".", "ContentLength", ",", "nil", "\n", "}" ]
// Download GETs the remote file from the given URL
[ "Download", "GETs", "the", "remote", "file", "from", "the", "given", "URL" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L729-L748
21,393
vmware/govmomi
vim25/soap/client.go
DownloadFile
func (c *Client) DownloadFile(ctx context.Context, file string, u *url.URL, param *Download) error { var err error if param == nil { param = &DefaultDownload } rc, contentLength, err := c.Download(ctx, u, param) if err != nil { return err } return c.WriteFile(ctx, file, rc, contentLength, param.Progress, param.Writer) }
go
func (c *Client) DownloadFile(ctx context.Context, file string, u *url.URL, param *Download) error { var err error if param == nil { param = &DefaultDownload } rc, contentLength, err := c.Download(ctx, u, param) if err != nil { return err } return c.WriteFile(ctx, file, rc, contentLength, param.Progress, param.Writer) }
[ "func", "(", "c", "*", "Client", ")", "DownloadFile", "(", "ctx", "context", ".", "Context", ",", "file", "string", ",", "u", "*", "url", ".", "URL", ",", "param", "*", "Download", ")", "error", "{", "var", "err", "error", "\n", "if", "param", "==", "nil", "{", "param", "=", "&", "DefaultDownload", "\n", "}", "\n\n", "rc", ",", "contentLength", ",", "err", ":=", "c", ".", "Download", "(", "ctx", ",", "u", ",", "param", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "c", ".", "WriteFile", "(", "ctx", ",", "file", ",", "rc", ",", "contentLength", ",", "param", ".", "Progress", ",", "param", ".", "Writer", ")", "\n", "}" ]
// DownloadFile GETs the given URL to a local file
[ "DownloadFile", "GETs", "the", "given", "URL", "to", "a", "local", "file" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L788-L800
21,394
vmware/govmomi
toolbox/process.go
WithIO
func (p *Process) WithIO() *Process { p.IO = &ProcessIO{ Out: new(bytes.Buffer), Err: new(bytes.Buffer), } return p }
go
func (p *Process) WithIO() *Process { p.IO = &ProcessIO{ Out: new(bytes.Buffer), Err: new(bytes.Buffer), } return p }
[ "func", "(", "p", "*", "Process", ")", "WithIO", "(", ")", "*", "Process", "{", "p", ".", "IO", "=", "&", "ProcessIO", "{", "Out", ":", "new", "(", "bytes", ".", "Buffer", ")", ",", "Err", ":", "new", "(", "bytes", ".", "Buffer", ")", ",", "}", "\n\n", "return", "p", "\n", "}" ]
// WithIO enables toolbox Process IO without file system disk IO.
[ "WithIO", "enables", "toolbox", "Process", "IO", "without", "file", "system", "disk", "IO", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L110-L117
21,395
vmware/govmomi
toolbox/process.go
NewProcessManager
func NewProcessManager() *ProcessManager { // We use pseudo PIDs that don't conflict with OS PIDs, so they can live in the same table. // For the pseudo PIDs, we use a sync.Pool rather than a plain old counter to avoid the unlikely, // but possible wrapping should such a counter exceed MaxInt64. pid := int64(32768) // TODO: /proc/sys/kernel/pid_max return &ProcessManager{ expire: time.Minute * 5, entries: make(map[int64]*Process), pids: sync.Pool{ New: func() interface{} { return atomic.AddInt64(&pid, 1) }, }, } }
go
func NewProcessManager() *ProcessManager { // We use pseudo PIDs that don't conflict with OS PIDs, so they can live in the same table. // For the pseudo PIDs, we use a sync.Pool rather than a plain old counter to avoid the unlikely, // but possible wrapping should such a counter exceed MaxInt64. pid := int64(32768) // TODO: /proc/sys/kernel/pid_max return &ProcessManager{ expire: time.Minute * 5, entries: make(map[int64]*Process), pids: sync.Pool{ New: func() interface{} { return atomic.AddInt64(&pid, 1) }, }, } }
[ "func", "NewProcessManager", "(", ")", "*", "ProcessManager", "{", "// We use pseudo PIDs that don't conflict with OS PIDs, so they can live in the same table.", "// For the pseudo PIDs, we use a sync.Pool rather than a plain old counter to avoid the unlikely,", "// but possible wrapping should such a counter exceed MaxInt64.", "pid", ":=", "int64", "(", "32768", ")", "// TODO: /proc/sys/kernel/pid_max", "\n\n", "return", "&", "ProcessManager", "{", "expire", ":", "time", ".", "Minute", "*", "5", ",", "entries", ":", "make", "(", "map", "[", "int64", "]", "*", "Process", ")", ",", "pids", ":", "sync", ".", "Pool", "{", "New", ":", "func", "(", ")", "interface", "{", "}", "{", "return", "atomic", ".", "AddInt64", "(", "&", "pid", ",", "1", ")", "\n", "}", ",", "}", ",", "}", "\n", "}" ]
// NewProcessManager creates a new ProcessManager instance.
[ "NewProcessManager", "creates", "a", "new", "ProcessManager", "instance", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L221-L236
21,396
vmware/govmomi
toolbox/process.go
Start
func (m *ProcessManager) Start(r *vix.StartProgramRequest, p *Process) (int64, error) { p.Name = r.ProgramPath p.Args = r.Arguments // Owner is cosmetic, but useful for example with: govc guest.ps -U $uid if p.Owner == "" { p.Owner = defaultOwner } p.StartTime = time.Now().Unix() p.ctx, p.Kill = context.WithCancel(context.Background()) pid, err := p.Start(p, r) if err != nil { return -1, err } if pid == 0 { p.Pid = m.pids.Get().(int64) // pseudo pid for funcs } else { p.Pid = pid } m.mu.Lock() m.entries[p.Pid] = p m.mu.Unlock() m.wg.Add(1) go func() { werr := p.Wait() atomic.StoreInt64(&p.EndTime, time.Now().Unix()) if werr != nil { rc := int32(1) if xerr, ok := werr.(*ProcessError); ok { rc = xerr.ExitCode } atomic.StoreInt32(&p.ExitCode, rc) } m.wg.Done() p.Kill() // cancel context for those waiting on p.ctx.Done() // See: http://pubs.vmware.com/vsphere-65/topic/com.vmware.wssdk.apiref.doc/vim.vm.guest.ProcessManager.ProcessInfo.html // "If the process was started using StartProgramInGuest then the process completion time // will be available if queried within 5 minutes after it completes." <-time.After(m.expire) m.mu.Lock() delete(m.entries, p.Pid) m.mu.Unlock() if pid == 0 { m.pids.Put(p.Pid) // pseudo pid can be reused now } }() return p.Pid, nil }
go
func (m *ProcessManager) Start(r *vix.StartProgramRequest, p *Process) (int64, error) { p.Name = r.ProgramPath p.Args = r.Arguments // Owner is cosmetic, but useful for example with: govc guest.ps -U $uid if p.Owner == "" { p.Owner = defaultOwner } p.StartTime = time.Now().Unix() p.ctx, p.Kill = context.WithCancel(context.Background()) pid, err := p.Start(p, r) if err != nil { return -1, err } if pid == 0 { p.Pid = m.pids.Get().(int64) // pseudo pid for funcs } else { p.Pid = pid } m.mu.Lock() m.entries[p.Pid] = p m.mu.Unlock() m.wg.Add(1) go func() { werr := p.Wait() atomic.StoreInt64(&p.EndTime, time.Now().Unix()) if werr != nil { rc := int32(1) if xerr, ok := werr.(*ProcessError); ok { rc = xerr.ExitCode } atomic.StoreInt32(&p.ExitCode, rc) } m.wg.Done() p.Kill() // cancel context for those waiting on p.ctx.Done() // See: http://pubs.vmware.com/vsphere-65/topic/com.vmware.wssdk.apiref.doc/vim.vm.guest.ProcessManager.ProcessInfo.html // "If the process was started using StartProgramInGuest then the process completion time // will be available if queried within 5 minutes after it completes." <-time.After(m.expire) m.mu.Lock() delete(m.entries, p.Pid) m.mu.Unlock() if pid == 0 { m.pids.Put(p.Pid) // pseudo pid can be reused now } }() return p.Pid, nil }
[ "func", "(", "m", "*", "ProcessManager", ")", "Start", "(", "r", "*", "vix", ".", "StartProgramRequest", ",", "p", "*", "Process", ")", "(", "int64", ",", "error", ")", "{", "p", ".", "Name", "=", "r", ".", "ProgramPath", "\n", "p", ".", "Args", "=", "r", ".", "Arguments", "\n\n", "// Owner is cosmetic, but useful for example with: govc guest.ps -U $uid", "if", "p", ".", "Owner", "==", "\"", "\"", "{", "p", ".", "Owner", "=", "defaultOwner", "\n", "}", "\n\n", "p", ".", "StartTime", "=", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", "\n\n", "p", ".", "ctx", ",", "p", ".", "Kill", "=", "context", ".", "WithCancel", "(", "context", ".", "Background", "(", ")", ")", "\n\n", "pid", ",", "err", ":=", "p", ".", "Start", "(", "p", ",", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "err", "\n", "}", "\n\n", "if", "pid", "==", "0", "{", "p", ".", "Pid", "=", "m", ".", "pids", ".", "Get", "(", ")", ".", "(", "int64", ")", "// pseudo pid for funcs", "\n", "}", "else", "{", "p", ".", "Pid", "=", "pid", "\n", "}", "\n\n", "m", ".", "mu", ".", "Lock", "(", ")", "\n", "m", ".", "entries", "[", "p", ".", "Pid", "]", "=", "p", "\n", "m", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "m", ".", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{", "werr", ":=", "p", ".", "Wait", "(", ")", "\n\n", "atomic", ".", "StoreInt64", "(", "&", "p", ".", "EndTime", ",", "time", ".", "Now", "(", ")", ".", "Unix", "(", ")", ")", "\n\n", "if", "werr", "!=", "nil", "{", "rc", ":=", "int32", "(", "1", ")", "\n", "if", "xerr", ",", "ok", ":=", "werr", ".", "(", "*", "ProcessError", ")", ";", "ok", "{", "rc", "=", "xerr", ".", "ExitCode", "\n", "}", "\n\n", "atomic", ".", "StoreInt32", "(", "&", "p", ".", "ExitCode", ",", "rc", ")", "\n", "}", "\n\n", "m", ".", "wg", ".", "Done", "(", ")", "\n", "p", ".", "Kill", "(", ")", "// cancel context for those waiting on p.ctx.Done()", "\n\n", "// See: http://pubs.vmware.com/vsphere-65/topic/com.vmware.wssdk.apiref.doc/vim.vm.guest.ProcessManager.ProcessInfo.html", "// \"If the process was started using StartProgramInGuest then the process completion time", "// will be available if queried within 5 minutes after it completes.\"", "<-", "time", ".", "After", "(", "m", ".", "expire", ")", "\n\n", "m", ".", "mu", ".", "Lock", "(", ")", "\n", "delete", "(", "m", ".", "entries", ",", "p", ".", "Pid", ")", "\n", "m", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "pid", "==", "0", "{", "m", ".", "pids", ".", "Put", "(", "p", ".", "Pid", ")", "// pseudo pid can be reused now", "\n", "}", "\n", "}", "(", ")", "\n\n", "return", "p", ".", "Pid", ",", "nil", "\n", "}" ]
// Start calls the Process.Start function, returning the pid on success or an error. // A goroutine is started that calls the Process.Wait function. After Process.Wait has // returned, the ProcessState EndTime and ExitCode fields are set. The process state can be // queried via ListProcessesInGuest until it is removed, 5 minutes after Wait returns.
[ "Start", "calls", "the", "Process", ".", "Start", "function", "returning", "the", "pid", "on", "success", "or", "an", "error", ".", "A", "goroutine", "is", "started", "that", "calls", "the", "Process", ".", "Wait", "function", ".", "After", "Process", ".", "Wait", "has", "returned", "the", "ProcessState", "EndTime", "and", "ExitCode", "fields", "are", "set", ".", "The", "process", "state", "can", "be", "queried", "via", "ListProcessesInGuest", "until", "it", "is", "removed", "5", "minutes", "after", "Wait", "returns", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L242-L303
21,397
vmware/govmomi
toolbox/process.go
Kill
func (m *ProcessManager) Kill(pid int64) bool { m.mu.Lock() entry, ok := m.entries[pid] m.mu.Unlock() if ok { entry.Kill() return true } return false }
go
func (m *ProcessManager) Kill(pid int64) bool { m.mu.Lock() entry, ok := m.entries[pid] m.mu.Unlock() if ok { entry.Kill() return true } return false }
[ "func", "(", "m", "*", "ProcessManager", ")", "Kill", "(", "pid", "int64", ")", "bool", "{", "m", ".", "mu", ".", "Lock", "(", ")", "\n", "entry", ",", "ok", ":=", "m", ".", "entries", "[", "pid", "]", "\n", "m", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "ok", "{", "entry", ".", "Kill", "(", ")", "\n", "return", "true", "\n", "}", "\n\n", "return", "false", "\n", "}" ]
// Kill cancels the Process Context. // Returns true if pid exists in the process table, false otherwise.
[ "Kill", "cancels", "the", "Process", "Context", ".", "Returns", "true", "if", "pid", "exists", "in", "the", "process", "table", "false", "otherwise", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L307-L318
21,398
vmware/govmomi
toolbox/process.go
ListProcesses
func (m *ProcessManager) ListProcesses(pids []int64) []byte { w := new(bytes.Buffer) m.mu.Lock() if len(pids) == 0 { for _, p := range m.entries { _, _ = w.WriteString(p.toXML()) } } else { for _, id := range pids { p, ok := m.entries[id] if !ok { continue } _, _ = w.WriteString(p.toXML()) } } m.mu.Unlock() return w.Bytes() }
go
func (m *ProcessManager) ListProcesses(pids []int64) []byte { w := new(bytes.Buffer) m.mu.Lock() if len(pids) == 0 { for _, p := range m.entries { _, _ = w.WriteString(p.toXML()) } } else { for _, id := range pids { p, ok := m.entries[id] if !ok { continue } _, _ = w.WriteString(p.toXML()) } } m.mu.Unlock() return w.Bytes() }
[ "func", "(", "m", "*", "ProcessManager", ")", "ListProcesses", "(", "pids", "[", "]", "int64", ")", "[", "]", "byte", "{", "w", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n\n", "m", ".", "mu", ".", "Lock", "(", ")", "\n\n", "if", "len", "(", "pids", ")", "==", "0", "{", "for", "_", ",", "p", ":=", "range", "m", ".", "entries", "{", "_", ",", "_", "=", "w", ".", "WriteString", "(", "p", ".", "toXML", "(", ")", ")", "\n", "}", "\n", "}", "else", "{", "for", "_", ",", "id", ":=", "range", "pids", "{", "p", ",", "ok", ":=", "m", ".", "entries", "[", "id", "]", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n\n", "_", ",", "_", "=", "w", ".", "WriteString", "(", "p", ".", "toXML", "(", ")", ")", "\n", "}", "\n", "}", "\n\n", "m", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "return", "w", ".", "Bytes", "(", ")", "\n", "}" ]
// ListProcesses marshals the ProcessState for the given pids. // If no pids are specified, all current processes are included. // The return value can be used for responding to a VixMsgListProcessesExRequest.
[ "ListProcesses", "marshals", "the", "ProcessState", "for", "the", "given", "pids", ".", "If", "no", "pids", "are", "specified", "all", "current", "processes", "are", "included", ".", "The", "return", "value", "can", "be", "used", "for", "responding", "to", "a", "VixMsgListProcessesExRequest", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L323-L346
21,399
vmware/govmomi
toolbox/process.go
Stat
func (m *ProcessManager) Stat(u *url.URL) (os.FileInfo, error) { name := path.Join("/proc", u.Path) info, err := os.Stat(name) if err == nil && info.Size() == 0 { // This is a real /proc file return &procFileInfo{info}, nil } dir, file := path.Split(u.Path) pid, err := strconv.ParseInt(path.Base(dir), 10, 64) if err != nil { return nil, os.ErrNotExist } m.mu.Lock() p := m.entries[pid] m.mu.Unlock() if p == nil || p.IO == nil { return nil, os.ErrNotExist } pf := &ProcessFile{ name: name, Closer: ioutil.NopCloser(nil), // via hgfs, nop for stdout and stderr } var r *bytes.Buffer switch file { case "stdin": pf.Writer = p.IO.In.Writer pf.Closer = p.IO.In.Closer return pf, nil case "stdout": r = p.IO.Out case "stderr": r = p.IO.Err default: return nil, os.ErrNotExist } select { case <-p.ctx.Done(): case <-time.After(time.Second): // The vmx guest RPC calls are queue based, serialized on the vmx side. // There are 5 seconds between "ping" RPC calls and after a few misses, // the vmx considers tools as not running. In this case, the vmx would timeout // a file transfer after 60 seconds. // // vix.FileAccessError is converted to a CannotAccessFile fault, // so the client can choose to retry the transfer in this case. // Would have preferred vix.ObjectIsBusy (EBUSY), but VC/ESX converts that // to a general SystemErrorFault with nothing but a localized string message // to check against: "<reason>vix error codes = (5, 0).</reason>" // Is standard vmware-tools, EACCES is converted to a CannotAccessFile fault. return nil, vix.Error(vix.FileAccessError) } pf.Reader = r pf.size = r.Len() return pf, nil }
go
func (m *ProcessManager) Stat(u *url.URL) (os.FileInfo, error) { name := path.Join("/proc", u.Path) info, err := os.Stat(name) if err == nil && info.Size() == 0 { // This is a real /proc file return &procFileInfo{info}, nil } dir, file := path.Split(u.Path) pid, err := strconv.ParseInt(path.Base(dir), 10, 64) if err != nil { return nil, os.ErrNotExist } m.mu.Lock() p := m.entries[pid] m.mu.Unlock() if p == nil || p.IO == nil { return nil, os.ErrNotExist } pf := &ProcessFile{ name: name, Closer: ioutil.NopCloser(nil), // via hgfs, nop for stdout and stderr } var r *bytes.Buffer switch file { case "stdin": pf.Writer = p.IO.In.Writer pf.Closer = p.IO.In.Closer return pf, nil case "stdout": r = p.IO.Out case "stderr": r = p.IO.Err default: return nil, os.ErrNotExist } select { case <-p.ctx.Done(): case <-time.After(time.Second): // The vmx guest RPC calls are queue based, serialized on the vmx side. // There are 5 seconds between "ping" RPC calls and after a few misses, // the vmx considers tools as not running. In this case, the vmx would timeout // a file transfer after 60 seconds. // // vix.FileAccessError is converted to a CannotAccessFile fault, // so the client can choose to retry the transfer in this case. // Would have preferred vix.ObjectIsBusy (EBUSY), but VC/ESX converts that // to a general SystemErrorFault with nothing but a localized string message // to check against: "<reason>vix error codes = (5, 0).</reason>" // Is standard vmware-tools, EACCES is converted to a CannotAccessFile fault. return nil, vix.Error(vix.FileAccessError) } pf.Reader = r pf.size = r.Len() return pf, nil }
[ "func", "(", "m", "*", "ProcessManager", ")", "Stat", "(", "u", "*", "url", ".", "URL", ")", "(", "os", ".", "FileInfo", ",", "error", ")", "{", "name", ":=", "path", ".", "Join", "(", "\"", "\"", ",", "u", ".", "Path", ")", "\n\n", "info", ",", "err", ":=", "os", ".", "Stat", "(", "name", ")", "\n", "if", "err", "==", "nil", "&&", "info", ".", "Size", "(", ")", "==", "0", "{", "// This is a real /proc file", "return", "&", "procFileInfo", "{", "info", "}", ",", "nil", "\n", "}", "\n\n", "dir", ",", "file", ":=", "path", ".", "Split", "(", "u", ".", "Path", ")", "\n\n", "pid", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "path", ".", "Base", "(", "dir", ")", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "os", ".", "ErrNotExist", "\n", "}", "\n\n", "m", ".", "mu", ".", "Lock", "(", ")", "\n", "p", ":=", "m", ".", "entries", "[", "pid", "]", "\n", "m", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "if", "p", "==", "nil", "||", "p", ".", "IO", "==", "nil", "{", "return", "nil", ",", "os", ".", "ErrNotExist", "\n", "}", "\n\n", "pf", ":=", "&", "ProcessFile", "{", "name", ":", "name", ",", "Closer", ":", "ioutil", ".", "NopCloser", "(", "nil", ")", ",", "// via hgfs, nop for stdout and stderr", "}", "\n\n", "var", "r", "*", "bytes", ".", "Buffer", "\n\n", "switch", "file", "{", "case", "\"", "\"", ":", "pf", ".", "Writer", "=", "p", ".", "IO", ".", "In", ".", "Writer", "\n", "pf", ".", "Closer", "=", "p", ".", "IO", ".", "In", ".", "Closer", "\n", "return", "pf", ",", "nil", "\n", "case", "\"", "\"", ":", "r", "=", "p", ".", "IO", ".", "Out", "\n", "case", "\"", "\"", ":", "r", "=", "p", ".", "IO", ".", "Err", "\n", "default", ":", "return", "nil", ",", "os", ".", "ErrNotExist", "\n", "}", "\n\n", "select", "{", "case", "<-", "p", ".", "ctx", ".", "Done", "(", ")", ":", "case", "<-", "time", ".", "After", "(", "time", ".", "Second", ")", ":", "// The vmx guest RPC calls are queue based, serialized on the vmx side.", "// There are 5 seconds between \"ping\" RPC calls and after a few misses,", "// the vmx considers tools as not running. In this case, the vmx would timeout", "// a file transfer after 60 seconds.", "//", "// vix.FileAccessError is converted to a CannotAccessFile fault,", "// so the client can choose to retry the transfer in this case.", "// Would have preferred vix.ObjectIsBusy (EBUSY), but VC/ESX converts that", "// to a general SystemErrorFault with nothing but a localized string message", "// to check against: \"<reason>vix error codes = (5, 0).</reason>\"", "// Is standard vmware-tools, EACCES is converted to a CannotAccessFile fault.", "return", "nil", ",", "vix", ".", "Error", "(", "vix", ".", "FileAccessError", ")", "\n", "}", "\n\n", "pf", ".", "Reader", "=", "r", "\n", "pf", ".", "size", "=", "r", ".", "Len", "(", ")", "\n\n", "return", "pf", ",", "nil", "\n", "}" ]
// Stat implements hgfs.FileHandler.Stat
[ "Stat", "implements", "hgfs", ".", "FileHandler", ".", "Stat" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L359-L424