repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
vmware/govmomi
performance/manager.go
HistoricalInterval
func (m *Manager) HistoricalInterval(ctx context.Context) (IntervalList, error) { var pm mo.PerformanceManager err := m.Properties(ctx, m.Reference(), []string{"historicalInterval"}, &pm) if err != nil { return nil, err } return IntervalList(pm.HistoricalInterval), nil }
go
func (m *Manager) HistoricalInterval(ctx context.Context) (IntervalList, error) { var pm mo.PerformanceManager err := m.Properties(ctx, m.Reference(), []string{"historicalInterval"}, &pm) if err != nil { return nil, err } return IntervalList(pm.HistoricalInterval), nil }
[ "func", "(", "m", "*", "Manager", ")", "HistoricalInterval", "(", "ctx", "context", ".", "Context", ")", "(", "IntervalList", ",", "error", ")", "{", "var", "pm", "mo", ".", "PerformanceManager", "\n", "err", ":=", "m", ".", "Properties", "(", "ctx", ",", "m", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"historicalInterval\"", "}", ",", "&", "pm", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "IntervalList", "(", "pm", ".", "HistoricalInterval", ")", ",", "nil", "\n", "}" ]
// HistoricalInterval gets the PerformanceManager.HistoricalInterval property and wraps as an IntervalList.
[ "HistoricalInterval", "gets", "the", "PerformanceManager", ".", "HistoricalInterval", "property", "and", "wraps", "as", "an", "IntervalList", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L91-L100
train
vmware/govmomi
performance/manager.go
CounterInfo
func (m *Manager) CounterInfo(ctx context.Context) ([]types.PerfCounterInfo, error) { m.pm.Lock() defer m.pm.Unlock() if len(m.pm.PerfCounter) == 0 { err := m.Properties(ctx, m.Reference(), []string{"perfCounter"}, m.pm.PerformanceManager) if err != nil { return nil, err } } return m.pm.PerfCounter, nil }
go
func (m *Manager) CounterInfo(ctx context.Context) ([]types.PerfCounterInfo, error) { m.pm.Lock() defer m.pm.Unlock() if len(m.pm.PerfCounter) == 0 { err := m.Properties(ctx, m.Reference(), []string{"perfCounter"}, m.pm.PerformanceManager) if err != nil { return nil, err } } return m.pm.PerfCounter, nil }
[ "func", "(", "m", "*", "Manager", ")", "CounterInfo", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "types", ".", "PerfCounterInfo", ",", "error", ")", "{", "m", ".", "pm", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "pm", ".", "Unlock", "(", ")", "\n", "if", "len", "(", "m", ".", "pm", ".", "PerfCounter", ")", "==", "0", "{", "err", ":=", "m", ".", "Properties", "(", "ctx", ",", "m", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"perfCounter\"", "}", ",", "m", ".", "pm", ".", "PerformanceManager", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "}", "\n", "return", "m", ".", "pm", ".", "PerfCounter", ",", "nil", "\n", "}" ]
// CounterInfo gets the PerformanceManager.PerfCounter property. // The property value is only collected once, subsequent calls return the cached value.
[ "CounterInfo", "gets", "the", "PerformanceManager", ".", "PerfCounter", "property", ".", "The", "property", "value", "is", "only", "collected", "once", "subsequent", "calls", "return", "the", "cached", "value", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L104-L116
train
vmware/govmomi
performance/manager.go
CounterInfoByKey
func (m *Manager) CounterInfoByKey(ctx context.Context) (map[int32]*types.PerfCounterInfo, error) { m.infoByKey.Lock() defer m.infoByKey.Unlock() if m.infoByKey.m != nil { return m.infoByKey.m, nil } info, err := m.CounterInfo(ctx) if err != nil { return nil, err } m.infoByKey.m = make(map[int32]*types.PerfCounterInfo) for i := range info { c := &info[i] m.infoByKey.m[c.Key] = c } return m.infoByKey.m, nil }
go
func (m *Manager) CounterInfoByKey(ctx context.Context) (map[int32]*types.PerfCounterInfo, error) { m.infoByKey.Lock() defer m.infoByKey.Unlock() if m.infoByKey.m != nil { return m.infoByKey.m, nil } info, err := m.CounterInfo(ctx) if err != nil { return nil, err } m.infoByKey.m = make(map[int32]*types.PerfCounterInfo) for i := range info { c := &info[i] m.infoByKey.m[c.Key] = c } return m.infoByKey.m, nil }
[ "func", "(", "m", "*", "Manager", ")", "CounterInfoByKey", "(", "ctx", "context", ".", "Context", ")", "(", "map", "[", "int32", "]", "*", "types", ".", "PerfCounterInfo", ",", "error", ")", "{", "m", ".", "infoByKey", ".", "Lock", "(", ")", "\n", "defer", "m", ".", "infoByKey", ".", "Unlock", "(", ")", "\n", "if", "m", ".", "infoByKey", ".", "m", "!=", "nil", "{", "return", "m", ".", "infoByKey", ".", "m", ",", "nil", "\n", "}", "\n", "info", ",", "err", ":=", "m", ".", "CounterInfo", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "m", ".", "infoByKey", ".", "m", "=", "make", "(", "map", "[", "int32", "]", "*", "types", ".", "PerfCounterInfo", ")", "\n", "for", "i", ":=", "range", "info", "{", "c", ":=", "&", "info", "[", "i", "]", "\n", "m", ".", "infoByKey", ".", "m", "[", "c", ".", "Key", "]", "=", "c", "\n", "}", "\n", "return", "m", ".", "infoByKey", ".", "m", ",", "nil", "\n", "}" ]
// CounterInfoByKey converts the PerformanceManager.PerfCounter property to a map, // where key is types.PerfCounterInfo.Key.
[ "CounterInfoByKey", "converts", "the", "PerformanceManager", ".", "PerfCounter", "property", "to", "a", "map", "where", "key", "is", "types", ".", "PerfCounterInfo", ".", "Key", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L146-L168
train
vmware/govmomi
performance/manager.go
ProviderSummary
func (m *Manager) ProviderSummary(ctx context.Context, entity types.ManagedObjectReference) (*types.PerfProviderSummary, error) { req := types.QueryPerfProviderSummary{ This: m.Reference(), Entity: entity, } res, err := methods.QueryPerfProviderSummary(ctx, m.Client(), &req) if err != nil { return nil, err } return &res.Returnval, nil }
go
func (m *Manager) ProviderSummary(ctx context.Context, entity types.ManagedObjectReference) (*types.PerfProviderSummary, error) { req := types.QueryPerfProviderSummary{ This: m.Reference(), Entity: entity, } res, err := methods.QueryPerfProviderSummary(ctx, m.Client(), &req) if err != nil { return nil, err } return &res.Returnval, nil }
[ "func", "(", "m", "*", "Manager", ")", "ProviderSummary", "(", "ctx", "context", ".", "Context", ",", "entity", "types", ".", "ManagedObjectReference", ")", "(", "*", "types", ".", "PerfProviderSummary", ",", "error", ")", "{", "req", ":=", "types", ".", "QueryPerfProviderSummary", "{", "This", ":", "m", ".", "Reference", "(", ")", ",", "Entity", ":", "entity", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "QueryPerfProviderSummary", "(", "ctx", ",", "m", ".", "Client", "(", ")", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// ProviderSummary wraps the QueryPerfProviderSummary method, caching the value based on entity.Type.
[ "ProviderSummary", "wraps", "the", "QueryPerfProviderSummary", "method", "caching", "the", "value", "based", "on", "entity", ".", "Type", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L171-L183
train
vmware/govmomi
performance/manager.go
AvailableMetric
func (m *Manager) AvailableMetric(ctx context.Context, entity types.ManagedObjectReference, interval int32) (MetricList, error) { req := types.QueryAvailablePerfMetric{ This: m.Reference(), Entity: entity.Reference(), IntervalId: interval, } res, err := methods.QueryAvailablePerfMetric(ctx, m.Client(), &req) if err != nil { return nil, err } if m.Sort { info, err := m.CounterInfoByKey(ctx) if err != nil { return nil, err } sort.Sort(groupPerfCounterInfo{info, res.Returnval}) } return MetricList(res.Returnval), nil }
go
func (m *Manager) AvailableMetric(ctx context.Context, entity types.ManagedObjectReference, interval int32) (MetricList, error) { req := types.QueryAvailablePerfMetric{ This: m.Reference(), Entity: entity.Reference(), IntervalId: interval, } res, err := methods.QueryAvailablePerfMetric(ctx, m.Client(), &req) if err != nil { return nil, err } if m.Sort { info, err := m.CounterInfoByKey(ctx) if err != nil { return nil, err } sort.Sort(groupPerfCounterInfo{info, res.Returnval}) } return MetricList(res.Returnval), nil }
[ "func", "(", "m", "*", "Manager", ")", "AvailableMetric", "(", "ctx", "context", ".", "Context", ",", "entity", "types", ".", "ManagedObjectReference", ",", "interval", "int32", ")", "(", "MetricList", ",", "error", ")", "{", "req", ":=", "types", ".", "QueryAvailablePerfMetric", "{", "This", ":", "m", ".", "Reference", "(", ")", ",", "Entity", ":", "entity", ".", "Reference", "(", ")", ",", "IntervalId", ":", "interval", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "QueryAvailablePerfMetric", "(", "ctx", ",", "m", ".", "Client", "(", ")", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "m", ".", "Sort", "{", "info", ",", "err", ":=", "m", ".", "CounterInfoByKey", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "sort", ".", "Sort", "(", "groupPerfCounterInfo", "{", "info", ",", "res", ".", "Returnval", "}", ")", "\n", "}", "\n", "return", "MetricList", "(", "res", ".", "Returnval", ")", ",", "nil", "\n", "}" ]
// AvailableMetric wraps the QueryAvailablePerfMetric method. // The MetricList is sorted by PerfCounterInfo.GroupInfo.Key if Manager.Sort == true.
[ "AvailableMetric", "wraps", "the", "QueryAvailablePerfMetric", "method", ".", "The", "MetricList", "is", "sorted", "by", "PerfCounterInfo", ".", "GroupInfo", ".", "Key", "if", "Manager", ".", "Sort", "==", "true", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L224-L246
train
vmware/govmomi
performance/manager.go
Query
func (m *Manager) Query(ctx context.Context, spec []types.PerfQuerySpec) ([]types.BasePerfEntityMetricBase, error) { req := types.QueryPerf{ This: m.Reference(), QuerySpec: spec, } res, err := methods.QueryPerf(ctx, m.Client(), &req) if err != nil { return nil, err } return res.Returnval, nil }
go
func (m *Manager) Query(ctx context.Context, spec []types.PerfQuerySpec) ([]types.BasePerfEntityMetricBase, error) { req := types.QueryPerf{ This: m.Reference(), QuerySpec: spec, } res, err := methods.QueryPerf(ctx, m.Client(), &req) if err != nil { return nil, err } return res.Returnval, nil }
[ "func", "(", "m", "*", "Manager", ")", "Query", "(", "ctx", "context", ".", "Context", ",", "spec", "[", "]", "types", ".", "PerfQuerySpec", ")", "(", "[", "]", "types", ".", "BasePerfEntityMetricBase", ",", "error", ")", "{", "req", ":=", "types", ".", "QueryPerf", "{", "This", ":", "m", ".", "Reference", "(", ")", ",", "QuerySpec", ":", "spec", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "QueryPerf", "(", "ctx", ",", "m", ".", "Client", "(", ")", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// Query wraps the QueryPerf method.
[ "Query", "wraps", "the", "QueryPerf", "method", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L249-L261
train
vmware/govmomi
performance/manager.go
ValueCSV
func (s *MetricSeries) ValueCSV() string { vals := make([]string, len(s.Value)) for i := range s.Value { vals[i] = s.Format(s.Value[i]) } return strings.Join(vals, ",") }
go
func (s *MetricSeries) ValueCSV() string { vals := make([]string, len(s.Value)) for i := range s.Value { vals[i] = s.Format(s.Value[i]) } return strings.Join(vals, ",") }
[ "func", "(", "s", "*", "MetricSeries", ")", "ValueCSV", "(", ")", "string", "{", "vals", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "s", ".", "Value", ")", ")", "\n", "for", "i", ":=", "range", "s", ".", "Value", "{", "vals", "[", "i", "]", "=", "s", ".", "Format", "(", "s", ".", "Value", "[", "i", "]", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "vals", ",", "\",\"", ")", "\n", "}" ]
// ValueCSV converts the Value field to a CSV string
[ "ValueCSV", "converts", "the", "Value", "field", "to", "a", "CSV", "string" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L341-L349
train
vmware/govmomi
performance/manager.go
SampleInfoCSV
func (m *EntityMetric) SampleInfoCSV() string { vals := make([]string, len(m.SampleInfo)*2) i := 0 for _, s := range m.SampleInfo { vals[i] = s.Timestamp.Format(time.RFC3339) i++ vals[i] = strconv.Itoa(int(s.Interval)) i++ } return strings.Join(vals, ",") }
go
func (m *EntityMetric) SampleInfoCSV() string { vals := make([]string, len(m.SampleInfo)*2) i := 0 for _, s := range m.SampleInfo { vals[i] = s.Timestamp.Format(time.RFC3339) i++ vals[i] = strconv.Itoa(int(s.Interval)) i++ } return strings.Join(vals, ",") }
[ "func", "(", "m", "*", "EntityMetric", ")", "SampleInfoCSV", "(", ")", "string", "{", "vals", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "m", ".", "SampleInfo", ")", "*", "2", ")", "\n", "i", ":=", "0", "\n", "for", "_", ",", "s", ":=", "range", "m", ".", "SampleInfo", "{", "vals", "[", "i", "]", "=", "s", ".", "Timestamp", ".", "Format", "(", "time", ".", "RFC3339", ")", "\n", "i", "++", "\n", "vals", "[", "i", "]", "=", "strconv", ".", "Itoa", "(", "int", "(", "s", ".", "Interval", ")", ")", "\n", "i", "++", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "vals", ",", "\",\"", ")", "\n", "}" ]
// SampleInfoCSV converts the SampleInfo field to a CSV string
[ "SampleInfoCSV", "converts", "the", "SampleInfo", "field", "to", "a", "CSV", "string" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L360-L373
train
vmware/govmomi
govc/flags/host_connect.go
Spec
func (flag *HostConnectFlag) Spec(c *vim25.Client) types.HostConnectSpec { spec := flag.HostConnectSpec if spec.SslThumbprint == "" { spec.SslThumbprint = c.Thumbprint(spec.HostName) if spec.SslThumbprint == "" && flag.noverify { var info object.HostCertificateInfo t := c.Transport.(*http.Transport) _ = info.FromURL(&url.URL{Host: spec.HostName}, t.TLSClientConfig) spec.SslThumbprint = info.ThumbprintSHA1 } } return spec }
go
func (flag *HostConnectFlag) Spec(c *vim25.Client) types.HostConnectSpec { spec := flag.HostConnectSpec if spec.SslThumbprint == "" { spec.SslThumbprint = c.Thumbprint(spec.HostName) if spec.SslThumbprint == "" && flag.noverify { var info object.HostCertificateInfo t := c.Transport.(*http.Transport) _ = info.FromURL(&url.URL{Host: spec.HostName}, t.TLSClientConfig) spec.SslThumbprint = info.ThumbprintSHA1 } } return spec }
[ "func", "(", "flag", "*", "HostConnectFlag", ")", "Spec", "(", "c", "*", "vim25", ".", "Client", ")", "types", ".", "HostConnectSpec", "{", "spec", ":=", "flag", ".", "HostConnectSpec", "\n", "if", "spec", ".", "SslThumbprint", "==", "\"\"", "{", "spec", ".", "SslThumbprint", "=", "c", ".", "Thumbprint", "(", "spec", ".", "HostName", ")", "\n", "if", "spec", ".", "SslThumbprint", "==", "\"\"", "&&", "flag", ".", "noverify", "{", "var", "info", "object", ".", "HostCertificateInfo", "\n", "t", ":=", "c", ".", "Transport", ".", "(", "*", "http", ".", "Transport", ")", "\n", "_", "=", "info", ".", "FromURL", "(", "&", "url", ".", "URL", "{", "Host", ":", "spec", ".", "HostName", "}", ",", "t", ".", "TLSClientConfig", ")", "\n", "spec", ".", "SslThumbprint", "=", "info", ".", "ThumbprintSHA1", "\n", "}", "\n", "}", "\n", "return", "spec", "\n", "}" ]
// Spec attempts to fill in SslThumbprint if empty. // First checks GOVC_TLS_KNOWN_HOSTS, if not found and noverify=true then // use object.HostCertificateInfo to get the thumbprint.
[ "Spec", "attempts", "to", "fill", "in", "SslThumbprint", "if", "empty", ".", "First", "checks", "GOVC_TLS_KNOWN_HOSTS", "if", "not", "found", "and", "noverify", "=", "true", "then", "use", "object", ".", "HostCertificateInfo", "to", "get", "the", "thumbprint", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/host_connect.go#L70-L85
train
vmware/govmomi
govc/flags/host_connect.go
Fault
func (flag *HostConnectFlag) Fault(err error) error { if err == nil { return nil } if f, ok := err.(types.HasFault); ok { switch fault := f.Fault().(type) { case *types.SSLVerifyFault: return fmt.Errorf("%s thumbprint=%s", err, fault.Thumbprint) } } return err }
go
func (flag *HostConnectFlag) Fault(err error) error { if err == nil { return nil } if f, ok := err.(types.HasFault); ok { switch fault := f.Fault().(type) { case *types.SSLVerifyFault: return fmt.Errorf("%s thumbprint=%s", err, fault.Thumbprint) } } return err }
[ "func", "(", "flag", "*", "HostConnectFlag", ")", "Fault", "(", "err", "error", ")", "error", "{", "if", "err", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "f", ",", "ok", ":=", "err", ".", "(", "types", ".", "HasFault", ")", ";", "ok", "{", "switch", "fault", ":=", "f", ".", "Fault", "(", ")", ".", "(", "type", ")", "{", "case", "*", "types", ".", "SSLVerifyFault", ":", "return", "fmt", ".", "Errorf", "(", "\"%s thumbprint=%s\"", ",", "err", ",", "fault", ".", "Thumbprint", ")", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}" ]
// Fault checks if error is SSLVerifyFault, including the thumbprint if so
[ "Fault", "checks", "if", "error", "is", "SSLVerifyFault", "including", "the", "thumbprint", "if", "so" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/host_connect.go#L88-L101
train
vmware/govmomi
guest/toolbox/client.go
Run
func (c *Client) Run(ctx context.Context, cmd *exec.Cmd) error { vc := c.ProcessManager.Client() spec := types.GuestProgramSpec{ ProgramPath: cmd.Path, Arguments: strings.Join(cmd.Args, " "), EnvVariables: cmd.Env, WorkingDirectory: cmd.Dir, } pid, serr := c.ProcessManager.StartProgram(ctx, c.Authentication, &spec) if serr != nil { return serr } if cmd.Stdin != nil { dst := fmt.Sprintf("/proc/%d/stdin", pid) var buf bytes.Buffer size, err := io.Copy(&buf, cmd.Stdin) if err != nil { return err } attr := new(types.GuestPosixFileAttributes) url, err := c.FileManager.InitiateFileTransferToGuest(ctx, c.Authentication, dst, attr, size, true) if err != nil { return err } u, err := c.FileManager.TransferURL(ctx, url) if err != nil { return err } p := soap.DefaultUpload p.ContentLength = size err = vc.Client.Upload(ctx, &buf, u, &p) if err != nil { return err } } names := []string{"out", "err"} for i, w := range []io.Writer{cmd.Stdout, cmd.Stderr} { if w == nil { continue } src := fmt.Sprintf("/proc/%d/std%s", pid, names[i]) info, err := c.procReader(ctx, src) if err != nil { return err } u, err := c.FileManager.TransferURL(ctx, info.Url) if err != nil { return err } f, _, err := vc.Client.Download(ctx, u, &soap.DefaultDownload) if err != nil { return err } _, err = io.Copy(w, f) _ = f.Close() if err != nil { return err } } procs, err := c.ProcessManager.ListProcesses(ctx, c.Authentication, []int64{pid}) if err != nil { return err } if len(procs) == 1 { rc := procs[0].ExitCode if rc != 0 { return fmt.Errorf("%s: exit %d", cmd.Path, rc) } } return nil }
go
func (c *Client) Run(ctx context.Context, cmd *exec.Cmd) error { vc := c.ProcessManager.Client() spec := types.GuestProgramSpec{ ProgramPath: cmd.Path, Arguments: strings.Join(cmd.Args, " "), EnvVariables: cmd.Env, WorkingDirectory: cmd.Dir, } pid, serr := c.ProcessManager.StartProgram(ctx, c.Authentication, &spec) if serr != nil { return serr } if cmd.Stdin != nil { dst := fmt.Sprintf("/proc/%d/stdin", pid) var buf bytes.Buffer size, err := io.Copy(&buf, cmd.Stdin) if err != nil { return err } attr := new(types.GuestPosixFileAttributes) url, err := c.FileManager.InitiateFileTransferToGuest(ctx, c.Authentication, dst, attr, size, true) if err != nil { return err } u, err := c.FileManager.TransferURL(ctx, url) if err != nil { return err } p := soap.DefaultUpload p.ContentLength = size err = vc.Client.Upload(ctx, &buf, u, &p) if err != nil { return err } } names := []string{"out", "err"} for i, w := range []io.Writer{cmd.Stdout, cmd.Stderr} { if w == nil { continue } src := fmt.Sprintf("/proc/%d/std%s", pid, names[i]) info, err := c.procReader(ctx, src) if err != nil { return err } u, err := c.FileManager.TransferURL(ctx, info.Url) if err != nil { return err } f, _, err := vc.Client.Download(ctx, u, &soap.DefaultDownload) if err != nil { return err } _, err = io.Copy(w, f) _ = f.Close() if err != nil { return err } } procs, err := c.ProcessManager.ListProcesses(ctx, c.Authentication, []int64{pid}) if err != nil { return err } if len(procs) == 1 { rc := procs[0].ExitCode if rc != 0 { return fmt.Errorf("%s: exit %d", cmd.Path, rc) } } return nil }
[ "func", "(", "c", "*", "Client", ")", "Run", "(", "ctx", "context", ".", "Context", ",", "cmd", "*", "exec", ".", "Cmd", ")", "error", "{", "vc", ":=", "c", ".", "ProcessManager", ".", "Client", "(", ")", "\n", "spec", ":=", "types", ".", "GuestProgramSpec", "{", "ProgramPath", ":", "cmd", ".", "Path", ",", "Arguments", ":", "strings", ".", "Join", "(", "cmd", ".", "Args", ",", "\" \"", ")", ",", "EnvVariables", ":", "cmd", ".", "Env", ",", "WorkingDirectory", ":", "cmd", ".", "Dir", ",", "}", "\n", "pid", ",", "serr", ":=", "c", ".", "ProcessManager", ".", "StartProgram", "(", "ctx", ",", "c", ".", "Authentication", ",", "&", "spec", ")", "\n", "if", "serr", "!=", "nil", "{", "return", "serr", "\n", "}", "\n", "if", "cmd", ".", "Stdin", "!=", "nil", "{", "dst", ":=", "fmt", ".", "Sprintf", "(", "\"/proc/%d/stdin\"", ",", "pid", ")", "\n", "var", "buf", "bytes", ".", "Buffer", "\n", "size", ",", "err", ":=", "io", ".", "Copy", "(", "&", "buf", ",", "cmd", ".", "Stdin", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "attr", ":=", "new", "(", "types", ".", "GuestPosixFileAttributes", ")", "\n", "url", ",", "err", ":=", "c", ".", "FileManager", ".", "InitiateFileTransferToGuest", "(", "ctx", ",", "c", ".", "Authentication", ",", "dst", ",", "attr", ",", "size", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "u", ",", "err", ":=", "c", ".", "FileManager", ".", "TransferURL", "(", "ctx", ",", "url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "p", ":=", "soap", ".", "DefaultUpload", "\n", "p", ".", "ContentLength", "=", "size", "\n", "err", "=", "vc", ".", "Client", ".", "Upload", "(", "ctx", ",", "&", "buf", ",", "u", ",", "&", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "names", ":=", "[", "]", "string", "{", "\"out\"", ",", "\"err\"", "}", "\n", "for", "i", ",", "w", ":=", "range", "[", "]", "io", ".", "Writer", "{", "cmd", ".", "Stdout", ",", "cmd", ".", "Stderr", "}", "{", "if", "w", "==", "nil", "{", "continue", "\n", "}", "\n", "src", ":=", "fmt", ".", "Sprintf", "(", "\"/proc/%d/std%s\"", ",", "pid", ",", "names", "[", "i", "]", ")", "\n", "info", ",", "err", ":=", "c", ".", "procReader", "(", "ctx", ",", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "u", ",", "err", ":=", "c", ".", "FileManager", ".", "TransferURL", "(", "ctx", ",", "info", ".", "Url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "f", ",", "_", ",", "err", ":=", "vc", ".", "Client", ".", "Download", "(", "ctx", ",", "u", ",", "&", "soap", ".", "DefaultDownload", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", "=", "io", ".", "Copy", "(", "w", ",", "f", ")", "\n", "_", "=", "f", ".", "Close", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "procs", ",", "err", ":=", "c", ".", "ProcessManager", ".", "ListProcesses", "(", "ctx", ",", "c", ".", "Authentication", ",", "[", "]", "int64", "{", "pid", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "len", "(", "procs", ")", "==", "1", "{", "rc", ":=", "procs", "[", "0", "]", ".", "ExitCode", "\n", "if", "rc", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"%s: exit %d\"", ",", "cmd", ".", "Path", ",", "rc", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Run implements exec.Cmd.Run over vmx guest RPC.
[ "Run", "implements", "exec", ".", "Cmd", ".", "Run", "over", "vmx", "guest", "RPC", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/guest/toolbox/client.go#L141-L230
train
vmware/govmomi
guest/toolbox/client.go
Download
func (c *Client) Download(ctx context.Context, src string) (io.ReadCloser, int64, error) { vc := c.ProcessManager.Client() info, err := c.FileManager.InitiateFileTransferFromGuest(ctx, c.Authentication, src) if err != nil { return nil, 0, err } u, err := c.FileManager.TransferURL(ctx, info.Url) if err != nil { return nil, 0, err } p := soap.DefaultDownload f, n, err := vc.Download(ctx, u, &p) if err != nil { return nil, n, err } if strings.HasPrefix(src, "/archive:/") || isDir(src) { f = &archiveReader{ReadCloser: f} // look for the gzip trailer } return f, n, nil }
go
func (c *Client) Download(ctx context.Context, src string) (io.ReadCloser, int64, error) { vc := c.ProcessManager.Client() info, err := c.FileManager.InitiateFileTransferFromGuest(ctx, c.Authentication, src) if err != nil { return nil, 0, err } u, err := c.FileManager.TransferURL(ctx, info.Url) if err != nil { return nil, 0, err } p := soap.DefaultDownload f, n, err := vc.Download(ctx, u, &p) if err != nil { return nil, n, err } if strings.HasPrefix(src, "/archive:/") || isDir(src) { f = &archiveReader{ReadCloser: f} // look for the gzip trailer } return f, n, nil }
[ "func", "(", "c", "*", "Client", ")", "Download", "(", "ctx", "context", ".", "Context", ",", "src", "string", ")", "(", "io", ".", "ReadCloser", ",", "int64", ",", "error", ")", "{", "vc", ":=", "c", ".", "ProcessManager", ".", "Client", "(", ")", "\n", "info", ",", "err", ":=", "c", ".", "FileManager", ".", "InitiateFileTransferFromGuest", "(", "ctx", ",", "c", ".", "Authentication", ",", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n", "u", ",", "err", ":=", "c", ".", "FileManager", ".", "TransferURL", "(", "ctx", ",", "info", ".", "Url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "0", ",", "err", "\n", "}", "\n", "p", ":=", "soap", ".", "DefaultDownload", "\n", "f", ",", "n", ",", "err", ":=", "vc", ".", "Download", "(", "ctx", ",", "u", ",", "&", "p", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "n", ",", "err", "\n", "}", "\n", "if", "strings", ".", "HasPrefix", "(", "src", ",", "\"/archive:/\"", ")", "||", "isDir", "(", "src", ")", "{", "f", "=", "&", "archiveReader", "{", "ReadCloser", ":", "f", "}", "\n", "}", "\n", "return", "f", ",", "n", ",", "nil", "\n", "}" ]
// Download initiates a file transfer from the guest
[ "Download", "initiates", "a", "file", "transfer", "from", "the", "guest" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/guest/toolbox/client.go#L272-L297
train
vmware/govmomi
guest/toolbox/client.go
Upload
func (c *Client) Upload(ctx context.Context, src io.Reader, dst string, p soap.Upload, attr types.BaseGuestFileAttributes, force bool) error { vc := c.ProcessManager.Client() var err error if p.ContentLength == 0 { // Content-Length is required switch r := src.(type) { case *bytes.Buffer: p.ContentLength = int64(r.Len()) case *bytes.Reader: p.ContentLength = int64(r.Len()) case *strings.Reader: p.ContentLength = int64(r.Len()) case *os.File: info, serr := r.Stat() if serr != nil { return serr } p.ContentLength = info.Size() } if p.ContentLength == 0 { // os.File for example could be a device (stdin) buf := new(bytes.Buffer) p.ContentLength, err = io.Copy(buf, src) if err != nil { return err } src = buf } } url, err := c.FileManager.InitiateFileTransferToGuest(ctx, c.Authentication, dst, attr, p.ContentLength, force) if err != nil { return err } u, err := c.FileManager.TransferURL(ctx, url) if err != nil { return err } return vc.Client.Upload(ctx, src, u, &p) }
go
func (c *Client) Upload(ctx context.Context, src io.Reader, dst string, p soap.Upload, attr types.BaseGuestFileAttributes, force bool) error { vc := c.ProcessManager.Client() var err error if p.ContentLength == 0 { // Content-Length is required switch r := src.(type) { case *bytes.Buffer: p.ContentLength = int64(r.Len()) case *bytes.Reader: p.ContentLength = int64(r.Len()) case *strings.Reader: p.ContentLength = int64(r.Len()) case *os.File: info, serr := r.Stat() if serr != nil { return serr } p.ContentLength = info.Size() } if p.ContentLength == 0 { // os.File for example could be a device (stdin) buf := new(bytes.Buffer) p.ContentLength, err = io.Copy(buf, src) if err != nil { return err } src = buf } } url, err := c.FileManager.InitiateFileTransferToGuest(ctx, c.Authentication, dst, attr, p.ContentLength, force) if err != nil { return err } u, err := c.FileManager.TransferURL(ctx, url) if err != nil { return err } return vc.Client.Upload(ctx, src, u, &p) }
[ "func", "(", "c", "*", "Client", ")", "Upload", "(", "ctx", "context", ".", "Context", ",", "src", "io", ".", "Reader", ",", "dst", "string", ",", "p", "soap", ".", "Upload", ",", "attr", "types", ".", "BaseGuestFileAttributes", ",", "force", "bool", ")", "error", "{", "vc", ":=", "c", ".", "ProcessManager", ".", "Client", "(", ")", "\n", "var", "err", "error", "\n", "if", "p", ".", "ContentLength", "==", "0", "{", "switch", "r", ":=", "src", ".", "(", "type", ")", "{", "case", "*", "bytes", ".", "Buffer", ":", "p", ".", "ContentLength", "=", "int64", "(", "r", ".", "Len", "(", ")", ")", "\n", "case", "*", "bytes", ".", "Reader", ":", "p", ".", "ContentLength", "=", "int64", "(", "r", ".", "Len", "(", ")", ")", "\n", "case", "*", "strings", ".", "Reader", ":", "p", ".", "ContentLength", "=", "int64", "(", "r", ".", "Len", "(", ")", ")", "\n", "case", "*", "os", ".", "File", ":", "info", ",", "serr", ":=", "r", ".", "Stat", "(", ")", "\n", "if", "serr", "!=", "nil", "{", "return", "serr", "\n", "}", "\n", "p", ".", "ContentLength", "=", "info", ".", "Size", "(", ")", "\n", "}", "\n", "if", "p", ".", "ContentLength", "==", "0", "{", "buf", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "p", ".", "ContentLength", ",", "err", "=", "io", ".", "Copy", "(", "buf", ",", "src", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "src", "=", "buf", "\n", "}", "\n", "}", "\n", "url", ",", "err", ":=", "c", ".", "FileManager", ".", "InitiateFileTransferToGuest", "(", "ctx", ",", "c", ".", "Authentication", ",", "dst", ",", "attr", ",", "p", ".", "ContentLength", ",", "force", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "u", ",", "err", ":=", "c", ".", "FileManager", ".", "TransferURL", "(", "ctx", ",", "url", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "vc", ".", "Client", ".", "Upload", "(", "ctx", ",", "src", ",", "u", ",", "&", "p", ")", "\n", "}" ]
// Upload transfers a file to the guest
[ "Upload", "transfers", "a", "file", "to", "the", "guest" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/guest/toolbox/client.go#L300-L345
train
vmware/govmomi
object/host_firewall_system.go
ByRule
func (l HostFirewallRulesetList) ByRule(rule types.HostFirewallRule) HostFirewallRulesetList { var matches HostFirewallRulesetList for _, rs := range l { for _, r := range rs.Rule { if r.PortType != rule.PortType || r.Protocol != rule.Protocol || r.Direction != rule.Direction { continue } if r.EndPort == 0 && rule.Port == r.Port || rule.Port >= r.Port && rule.Port <= r.EndPort { matches = append(matches, rs) break } } } return matches }
go
func (l HostFirewallRulesetList) ByRule(rule types.HostFirewallRule) HostFirewallRulesetList { var matches HostFirewallRulesetList for _, rs := range l { for _, r := range rs.Rule { if r.PortType != rule.PortType || r.Protocol != rule.Protocol || r.Direction != rule.Direction { continue } if r.EndPort == 0 && rule.Port == r.Port || rule.Port >= r.Port && rule.Port <= r.EndPort { matches = append(matches, rs) break } } } return matches }
[ "func", "(", "l", "HostFirewallRulesetList", ")", "ByRule", "(", "rule", "types", ".", "HostFirewallRule", ")", "HostFirewallRulesetList", "{", "var", "matches", "HostFirewallRulesetList", "\n", "for", "_", ",", "rs", ":=", "range", "l", "{", "for", "_", ",", "r", ":=", "range", "rs", ".", "Rule", "{", "if", "r", ".", "PortType", "!=", "rule", ".", "PortType", "||", "r", ".", "Protocol", "!=", "rule", ".", "Protocol", "||", "r", ".", "Direction", "!=", "rule", ".", "Direction", "{", "continue", "\n", "}", "\n", "if", "r", ".", "EndPort", "==", "0", "&&", "rule", ".", "Port", "==", "r", ".", "Port", "||", "rule", ".", "Port", ">=", "r", ".", "Port", "&&", "rule", ".", "Port", "<=", "r", ".", "EndPort", "{", "matches", "=", "append", "(", "matches", ",", "rs", ")", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "matches", "\n", "}" ]
// ByRule returns a HostFirewallRulesetList where Direction, PortType and Protocol are equal and Port is within range
[ "ByRule", "returns", "a", "HostFirewallRulesetList", "where", "Direction", "PortType", "and", "Protocol", "are", "equal", "and", "Port", "is", "within", "range" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_firewall_system.go#L85-L105
train
vmware/govmomi
object/host_firewall_system.go
Enabled
func (l HostFirewallRulesetList) Enabled() HostFirewallRulesetList { var matches HostFirewallRulesetList for _, rs := range l { if rs.Enabled { matches = append(matches, rs) } } return matches }
go
func (l HostFirewallRulesetList) Enabled() HostFirewallRulesetList { var matches HostFirewallRulesetList for _, rs := range l { if rs.Enabled { matches = append(matches, rs) } } return matches }
[ "func", "(", "l", "HostFirewallRulesetList", ")", "Enabled", "(", ")", "HostFirewallRulesetList", "{", "var", "matches", "HostFirewallRulesetList", "\n", "for", "_", ",", "rs", ":=", "range", "l", "{", "if", "rs", ".", "Enabled", "{", "matches", "=", "append", "(", "matches", ",", "rs", ")", "\n", "}", "\n", "}", "\n", "return", "matches", "\n", "}" ]
// Enabled returns a HostFirewallRulesetList with enabled rules
[ "Enabled", "returns", "a", "HostFirewallRulesetList", "with", "enabled", "rules" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_firewall_system.go#L147-L157
train
vmware/govmomi
object/host_firewall_system.go
Keys
func (l HostFirewallRulesetList) Keys() []string { var keys []string for _, rs := range l { keys = append(keys, rs.Key) } return keys }
go
func (l HostFirewallRulesetList) Keys() []string { var keys []string for _, rs := range l { keys = append(keys, rs.Key) } return keys }
[ "func", "(", "l", "HostFirewallRulesetList", ")", "Keys", "(", ")", "[", "]", "string", "{", "var", "keys", "[", "]", "string", "\n", "for", "_", ",", "rs", ":=", "range", "l", "{", "keys", "=", "append", "(", "keys", ",", "rs", ".", "Key", ")", "\n", "}", "\n", "return", "keys", "\n", "}" ]
// Keys returns the HostFirewallRuleset.Key for each ruleset in the list
[ "Keys", "returns", "the", "HostFirewallRuleset", ".", "Key", "for", "each", "ruleset", "in", "the", "list" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_firewall_system.go#L173-L181
train
vmware/govmomi
vim25/xml/xml.go
CopyToken
func CopyToken(t Token) Token { switch v := t.(type) { case CharData: return v.Copy() case Comment: return v.Copy() case Directive: return v.Copy() case ProcInst: return v.Copy() case StartElement: return v.Copy() } return t }
go
func CopyToken(t Token) Token { switch v := t.(type) { case CharData: return v.Copy() case Comment: return v.Copy() case Directive: return v.Copy() case ProcInst: return v.Copy() case StartElement: return v.Copy() } return t }
[ "func", "CopyToken", "(", "t", "Token", ")", "Token", "{", "switch", "v", ":=", "t", ".", "(", "type", ")", "{", "case", "CharData", ":", "return", "v", ".", "Copy", "(", ")", "\n", "case", "Comment", ":", "return", "v", ".", "Copy", "(", ")", "\n", "case", "Directive", ":", "return", "v", ".", "Copy", "(", ")", "\n", "case", "ProcInst", ":", "return", "v", ".", "Copy", "(", ")", "\n", "case", "StartElement", ":", "return", "v", ".", "Copy", "(", ")", "\n", "}", "\n", "return", "t", "\n", "}" ]
// CopyToken returns a copy of a Token.
[ "CopyToken", "returns", "a", "copy", "of", "a", "Token", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L118-L132
train
vmware/govmomi
vim25/xml/xml.go
NewDecoder
func NewDecoder(r io.Reader) *Decoder { d := &Decoder{ ns: make(map[string]string), nextByte: -1, line: 1, Strict: true, } d.switchToReader(r) return d }
go
func NewDecoder(r io.Reader) *Decoder { d := &Decoder{ ns: make(map[string]string), nextByte: -1, line: 1, Strict: true, } d.switchToReader(r) return d }
[ "func", "NewDecoder", "(", "r", "io", ".", "Reader", ")", "*", "Decoder", "{", "d", ":=", "&", "Decoder", "{", "ns", ":", "make", "(", "map", "[", "string", "]", "string", ")", ",", "nextByte", ":", "-", "1", ",", "line", ":", "1", ",", "Strict", ":", "true", ",", "}", "\n", "d", ".", "switchToReader", "(", "r", ")", "\n", "return", "d", "\n", "}" ]
// NewDecoder creates a new XML parser reading from r. // If r does not implement io.ByteReader, NewDecoder will // do its own buffering.
[ "NewDecoder", "creates", "a", "new", "XML", "parser", "reading", "from", "r", ".", "If", "r", "does", "not", "implement", "io", ".", "ByteReader", "NewDecoder", "will", "do", "its", "own", "buffering", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L209-L218
train
vmware/govmomi
vim25/xml/xml.go
popEOF
func (d *Decoder) popEOF() bool { if d.stk == nil || d.stk.kind != stkEOF { return false } d.pop() return true }
go
func (d *Decoder) popEOF() bool { if d.stk == nil || d.stk.kind != stkEOF { return false } d.pop() return true }
[ "func", "(", "d", "*", "Decoder", ")", "popEOF", "(", ")", "bool", "{", "if", "d", ".", "stk", "==", "nil", "||", "d", ".", "stk", ".", "kind", "!=", "stkEOF", "{", "return", "false", "\n", "}", "\n", "d", ".", "pop", "(", ")", "\n", "return", "true", "\n", "}" ]
// Undo a pushEOF. // The element must have been finished, so the EOF should be at the top of the stack.
[ "Undo", "a", "pushEOF", ".", "The", "element", "must", "have", "been", "finished", "so", "the", "EOF", "should", "be", "at", "the", "top", "of", "the", "stack", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L401-L407
train
vmware/govmomi
vim25/xml/xml.go
pushElement
func (d *Decoder) pushElement(name Name) { s := d.push(stkStart) s.name = name }
go
func (d *Decoder) pushElement(name Name) { s := d.push(stkStart) s.name = name }
[ "func", "(", "d", "*", "Decoder", ")", "pushElement", "(", "name", "Name", ")", "{", "s", ":=", "d", ".", "push", "(", "stkStart", ")", "\n", "s", ".", "name", "=", "name", "\n", "}" ]
// Record that we are starting an element with the given name.
[ "Record", "that", "we", "are", "starting", "an", "element", "with", "the", "given", "name", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L410-L413
train
vmware/govmomi
vim25/xml/xml.go
syntaxError
func (d *Decoder) syntaxError(msg string) error { return &SyntaxError{Msg: msg, Line: d.line} }
go
func (d *Decoder) syntaxError(msg string) error { return &SyntaxError{Msg: msg, Line: d.line} }
[ "func", "(", "d", "*", "Decoder", ")", "syntaxError", "(", "msg", "string", ")", "error", "{", "return", "&", "SyntaxError", "{", "Msg", ":", "msg", ",", "Line", ":", "d", ".", "line", "}", "\n", "}" ]
// Creates a SyntaxError with the current line number.
[ "Creates", "a", "SyntaxError", "with", "the", "current", "line", "number", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L425-L427
train
vmware/govmomi
vim25/xml/xml.go
popElement
func (d *Decoder) popElement(t *EndElement) bool { s := d.pop() name := t.Name switch { case s == nil || s.kind != stkStart: d.err = d.syntaxError("unexpected end element </" + name.Local + ">") return false case s.name.Local != name.Local: if !d.Strict { d.needClose = true d.toClose = t.Name t.Name = s.name return true } d.err = d.syntaxError("element <" + s.name.Local + "> closed by </" + name.Local + ">") return false case s.name.Space != name.Space: d.err = d.syntaxError("element <" + s.name.Local + "> in space " + s.name.Space + "closed by </" + name.Local + "> in space " + name.Space) return false } // Pop stack until a Start or EOF is on the top, undoing the // translations that were associated with the element we just closed. for d.stk != nil && d.stk.kind != stkStart && d.stk.kind != stkEOF { s := d.pop() if s.ok { d.ns[s.name.Local] = s.name.Space } else { delete(d.ns, s.name.Local) } } return true }
go
func (d *Decoder) popElement(t *EndElement) bool { s := d.pop() name := t.Name switch { case s == nil || s.kind != stkStart: d.err = d.syntaxError("unexpected end element </" + name.Local + ">") return false case s.name.Local != name.Local: if !d.Strict { d.needClose = true d.toClose = t.Name t.Name = s.name return true } d.err = d.syntaxError("element <" + s.name.Local + "> closed by </" + name.Local + ">") return false case s.name.Space != name.Space: d.err = d.syntaxError("element <" + s.name.Local + "> in space " + s.name.Space + "closed by </" + name.Local + "> in space " + name.Space) return false } // Pop stack until a Start or EOF is on the top, undoing the // translations that were associated with the element we just closed. for d.stk != nil && d.stk.kind != stkStart && d.stk.kind != stkEOF { s := d.pop() if s.ok { d.ns[s.name.Local] = s.name.Space } else { delete(d.ns, s.name.Local) } } return true }
[ "func", "(", "d", "*", "Decoder", ")", "popElement", "(", "t", "*", "EndElement", ")", "bool", "{", "s", ":=", "d", ".", "pop", "(", ")", "\n", "name", ":=", "t", ".", "Name", "\n", "switch", "{", "case", "s", "==", "nil", "||", "s", ".", "kind", "!=", "stkStart", ":", "d", ".", "err", "=", "d", ".", "syntaxError", "(", "\"unexpected end element </\"", "+", "name", ".", "Local", "+", "\">\"", ")", "\n", "return", "false", "\n", "case", "s", ".", "name", ".", "Local", "!=", "name", ".", "Local", ":", "if", "!", "d", ".", "Strict", "{", "d", ".", "needClose", "=", "true", "\n", "d", ".", "toClose", "=", "t", ".", "Name", "\n", "t", ".", "Name", "=", "s", ".", "name", "\n", "return", "true", "\n", "}", "\n", "d", ".", "err", "=", "d", ".", "syntaxError", "(", "\"element <\"", "+", "s", ".", "name", ".", "Local", "+", "\"> closed by </\"", "+", "name", ".", "Local", "+", "\">\"", ")", "\n", "return", "false", "\n", "case", "s", ".", "name", ".", "Space", "!=", "name", ".", "Space", ":", "d", ".", "err", "=", "d", ".", "syntaxError", "(", "\"element <\"", "+", "s", ".", "name", ".", "Local", "+", "\"> in space \"", "+", "s", ".", "name", ".", "Space", "+", "\"closed by </\"", "+", "name", ".", "Local", "+", "\"> in space \"", "+", "name", ".", "Space", ")", "\n", "return", "false", "\n", "}", "\n", "for", "d", ".", "stk", "!=", "nil", "&&", "d", ".", "stk", ".", "kind", "!=", "stkStart", "&&", "d", ".", "stk", ".", "kind", "!=", "stkEOF", "{", "s", ":=", "d", ".", "pop", "(", ")", "\n", "if", "s", ".", "ok", "{", "d", ".", "ns", "[", "s", ".", "name", ".", "Local", "]", "=", "s", ".", "name", ".", "Space", "\n", "}", "else", "{", "delete", "(", "d", ".", "ns", ",", "s", ".", "name", ".", "Local", ")", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Record that we are ending an element with the given name. // The name must match the record at the top of the stack, // which must be a pushElement record. // After popping the element, apply any undo records from // the stack to restore the name translations that existed // before we saw this element.
[ "Record", "that", "we", "are", "ending", "an", "element", "with", "the", "given", "name", ".", "The", "name", "must", "match", "the", "record", "at", "the", "top", "of", "the", "stack", "which", "must", "be", "a", "pushElement", "record", ".", "After", "popping", "the", "element", "apply", "any", "undo", "records", "from", "the", "stack", "to", "restore", "the", "name", "translations", "that", "existed", "before", "we", "saw", "this", "element", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L435-L469
train
vmware/govmomi
vim25/xml/xml.go
autoClose
func (d *Decoder) autoClose(t Token) (Token, bool) { if d.stk == nil || d.stk.kind != stkStart { return nil, false } name := strings.ToLower(d.stk.name.Local) for _, s := range d.AutoClose { if strings.ToLower(s) == name { // This one should be auto closed if t doesn't close it. et, ok := t.(EndElement) if !ok || et.Name.Local != name { return EndElement{d.stk.name}, true } break } } return nil, false }
go
func (d *Decoder) autoClose(t Token) (Token, bool) { if d.stk == nil || d.stk.kind != stkStart { return nil, false } name := strings.ToLower(d.stk.name.Local) for _, s := range d.AutoClose { if strings.ToLower(s) == name { // This one should be auto closed if t doesn't close it. et, ok := t.(EndElement) if !ok || et.Name.Local != name { return EndElement{d.stk.name}, true } break } } return nil, false }
[ "func", "(", "d", "*", "Decoder", ")", "autoClose", "(", "t", "Token", ")", "(", "Token", ",", "bool", ")", "{", "if", "d", ".", "stk", "==", "nil", "||", "d", ".", "stk", ".", "kind", "!=", "stkStart", "{", "return", "nil", ",", "false", "\n", "}", "\n", "name", ":=", "strings", ".", "ToLower", "(", "d", ".", "stk", ".", "name", ".", "Local", ")", "\n", "for", "_", ",", "s", ":=", "range", "d", ".", "AutoClose", "{", "if", "strings", ".", "ToLower", "(", "s", ")", "==", "name", "{", "et", ",", "ok", ":=", "t", ".", "(", "EndElement", ")", "\n", "if", "!", "ok", "||", "et", ".", "Name", ".", "Local", "!=", "name", "{", "return", "EndElement", "{", "d", ".", "stk", ".", "name", "}", ",", "true", "\n", "}", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "nil", ",", "false", "\n", "}" ]
// If the top element on the stack is autoclosing and // t is not the end tag, invent the end tag.
[ "If", "the", "top", "element", "on", "the", "stack", "is", "autoclosing", "and", "t", "is", "not", "the", "end", "tag", "invent", "the", "end", "tag", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L473-L489
train
vmware/govmomi
vim25/xml/xml.go
RawToken
func (d *Decoder) RawToken() (Token, error) { if d.unmarshalDepth > 0 { return nil, errRawToken } return d.rawToken() }
go
func (d *Decoder) RawToken() (Token, error) { if d.unmarshalDepth > 0 { return nil, errRawToken } return d.rawToken() }
[ "func", "(", "d", "*", "Decoder", ")", "RawToken", "(", ")", "(", "Token", ",", "error", ")", "{", "if", "d", ".", "unmarshalDepth", ">", "0", "{", "return", "nil", ",", "errRawToken", "\n", "}", "\n", "return", "d", ".", "rawToken", "(", ")", "\n", "}" ]
// RawToken is like Token but does not verify that // start and end elements match and does not translate // name space prefixes to their corresponding URLs.
[ "RawToken", "is", "like", "Token", "but", "does", "not", "verify", "that", "start", "and", "end", "elements", "match", "and", "does", "not", "translate", "name", "space", "prefixes", "to", "their", "corresponding", "URLs", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L496-L501
train
vmware/govmomi
vim25/xml/xml.go
space
func (d *Decoder) space() { for { b, ok := d.getc() if !ok { return } switch b { case ' ', '\r', '\n', '\t': default: d.ungetc(b) return } } }
go
func (d *Decoder) space() { for { b, ok := d.getc() if !ok { return } switch b { case ' ', '\r', '\n', '\t': default: d.ungetc(b) return } } }
[ "func", "(", "d", "*", "Decoder", ")", "space", "(", ")", "{", "for", "{", "b", ",", "ok", ":=", "d", ".", "getc", "(", ")", "\n", "if", "!", "ok", "{", "return", "\n", "}", "\n", "switch", "b", "{", "case", "' '", ",", "'\\r'", ",", "'\\n'", ",", "'\\t'", ":", "default", ":", "d", ".", "ungetc", "(", "b", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}" ]
// Skip spaces if any
[ "Skip", "spaces", "if", "any" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L828-L841
train
vmware/govmomi
vim25/xml/xml.go
getc
func (d *Decoder) getc() (b byte, ok bool) { if d.err != nil { return 0, false } if d.nextByte >= 0 { b = byte(d.nextByte) d.nextByte = -1 } else { b, d.err = d.r.ReadByte() if d.err != nil { return 0, false } if d.saved != nil { d.saved.WriteByte(b) } } if b == '\n' { d.line++ } return b, true }
go
func (d *Decoder) getc() (b byte, ok bool) { if d.err != nil { return 0, false } if d.nextByte >= 0 { b = byte(d.nextByte) d.nextByte = -1 } else { b, d.err = d.r.ReadByte() if d.err != nil { return 0, false } if d.saved != nil { d.saved.WriteByte(b) } } if b == '\n' { d.line++ } return b, true }
[ "func", "(", "d", "*", "Decoder", ")", "getc", "(", ")", "(", "b", "byte", ",", "ok", "bool", ")", "{", "if", "d", ".", "err", "!=", "nil", "{", "return", "0", ",", "false", "\n", "}", "\n", "if", "d", ".", "nextByte", ">=", "0", "{", "b", "=", "byte", "(", "d", ".", "nextByte", ")", "\n", "d", ".", "nextByte", "=", "-", "1", "\n", "}", "else", "{", "b", ",", "d", ".", "err", "=", "d", ".", "r", ".", "ReadByte", "(", ")", "\n", "if", "d", ".", "err", "!=", "nil", "{", "return", "0", ",", "false", "\n", "}", "\n", "if", "d", ".", "saved", "!=", "nil", "{", "d", ".", "saved", ".", "WriteByte", "(", "b", ")", "\n", "}", "\n", "}", "\n", "if", "b", "==", "'\\n'", "{", "d", ".", "line", "++", "\n", "}", "\n", "return", "b", ",", "true", "\n", "}" ]
// Read a single byte. // If there is no byte to read, return ok==false // and leave the error in d.err. // Maintain line number.
[ "Read", "a", "single", "byte", ".", "If", "there", "is", "no", "byte", "to", "read", "return", "ok", "==", "false", "and", "leave", "the", "error", "in", "d", ".", "err", ".", "Maintain", "line", "number", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L847-L867
train
vmware/govmomi
vim25/xml/xml.go
readName
func (d *Decoder) readName() (ok bool) { var b byte if b, ok = d.mustgetc(); !ok { return } if b < utf8.RuneSelf && !isNameByte(b) { d.ungetc(b) return false } d.buf.WriteByte(b) for { if b, ok = d.mustgetc(); !ok { return } if b < utf8.RuneSelf && !isNameByte(b) { d.ungetc(b) break } d.buf.WriteByte(b) } return true }
go
func (d *Decoder) readName() (ok bool) { var b byte if b, ok = d.mustgetc(); !ok { return } if b < utf8.RuneSelf && !isNameByte(b) { d.ungetc(b) return false } d.buf.WriteByte(b) for { if b, ok = d.mustgetc(); !ok { return } if b < utf8.RuneSelf && !isNameByte(b) { d.ungetc(b) break } d.buf.WriteByte(b) } return true }
[ "func", "(", "d", "*", "Decoder", ")", "readName", "(", ")", "(", "ok", "bool", ")", "{", "var", "b", "byte", "\n", "if", "b", ",", "ok", "=", "d", ".", "mustgetc", "(", ")", ";", "!", "ok", "{", "return", "\n", "}", "\n", "if", "b", "<", "utf8", ".", "RuneSelf", "&&", "!", "isNameByte", "(", "b", ")", "{", "d", ".", "ungetc", "(", "b", ")", "\n", "return", "false", "\n", "}", "\n", "d", ".", "buf", ".", "WriteByte", "(", "b", ")", "\n", "for", "{", "if", "b", ",", "ok", "=", "d", ".", "mustgetc", "(", ")", ";", "!", "ok", "{", "return", "\n", "}", "\n", "if", "b", "<", "utf8", ".", "RuneSelf", "&&", "!", "isNameByte", "(", "b", ")", "{", "d", ".", "ungetc", "(", "b", ")", "\n", "break", "\n", "}", "\n", "d", ".", "buf", ".", "WriteByte", "(", "b", ")", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Read a name and append its bytes to d.buf. // The name is delimited by any single-byte character not valid in names. // All multi-byte characters are accepted; the caller must check their validity.
[ "Read", "a", "name", "and", "append", "its", "bytes", "to", "d", ".", "buf", ".", "The", "name", "is", "delimited", "by", "any", "single", "-", "byte", "character", "not", "valid", "in", "names", ".", "All", "multi", "-", "byte", "characters", "are", "accepted", ";", "the", "caller", "must", "check", "their", "validity", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L1127-L1149
train
vmware/govmomi
vim25/xml/xml.go
procInstEncoding
func procInstEncoding(s string) string { // TODO: this parsing is somewhat lame and not exact. // It works for all actual cases, though. idx := strings.Index(s, "encoding=") if idx == -1 { return "" } v := s[idx+len("encoding="):] if v == "" { return "" } if v[0] != '\'' && v[0] != '"' { return "" } idx = strings.IndexRune(v[1:], rune(v[0])) if idx == -1 { return "" } return v[1 : idx+1] }
go
func procInstEncoding(s string) string { // TODO: this parsing is somewhat lame and not exact. // It works for all actual cases, though. idx := strings.Index(s, "encoding=") if idx == -1 { return "" } v := s[idx+len("encoding="):] if v == "" { return "" } if v[0] != '\'' && v[0] != '"' { return "" } idx = strings.IndexRune(v[1:], rune(v[0])) if idx == -1 { return "" } return v[1 : idx+1] }
[ "func", "procInstEncoding", "(", "s", "string", ")", "string", "{", "idx", ":=", "strings", ".", "Index", "(", "s", ",", "\"encoding=\"", ")", "\n", "if", "idx", "==", "-", "1", "{", "return", "\"\"", "\n", "}", "\n", "v", ":=", "s", "[", "idx", "+", "len", "(", "\"encoding=\"", ")", ":", "]", "\n", "if", "v", "==", "\"\"", "{", "return", "\"\"", "\n", "}", "\n", "if", "v", "[", "0", "]", "!=", "'\\''", "&&", "v", "[", "0", "]", "!=", "'\"'", "{", "return", "\"\"", "\n", "}", "\n", "idx", "=", "strings", ".", "IndexRune", "(", "v", "[", "1", ":", "]", ",", "rune", "(", "v", "[", "0", "]", ")", ")", "\n", "if", "idx", "==", "-", "1", "{", "return", "\"\"", "\n", "}", "\n", "return", "v", "[", "1", ":", "idx", "+", "1", "]", "\n", "}" ]
// procInstEncoding parses the `encoding="..."` or `encoding='...'` // value out of the provided string, returning "" if not found.
[ "procInstEncoding", "parses", "the", "encoding", "=", "...", "or", "encoding", "=", "...", "value", "out", "of", "the", "provided", "string", "returning", "if", "not", "found", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L1920-L1939
train
vmware/govmomi
object/distributed_virtual_portgroup.go
EthernetCardBackingInfo
func (p DistributedVirtualPortgroup) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) { var dvp mo.DistributedVirtualPortgroup var dvs mo.DistributedVirtualSwitch prop := "config.distributedVirtualSwitch" if err := p.Properties(ctx, p.Reference(), []string{"key", prop}, &dvp); err != nil { return nil, err } // "This property should always be set unless the user's setting does not have System.Read privilege on the object referred to by this property." if dvp.Config.DistributedVirtualSwitch == nil { return nil, fmt.Errorf("no System.Read privilege on: %s.%s", p.Reference(), prop) } if err := p.Properties(ctx, *dvp.Config.DistributedVirtualSwitch, []string{"uuid"}, &dvs); err != nil { return nil, err } backing := &types.VirtualEthernetCardDistributedVirtualPortBackingInfo{ Port: types.DistributedVirtualSwitchPortConnection{ PortgroupKey: dvp.Key, SwitchUuid: dvs.Uuid, }, } return backing, nil }
go
func (p DistributedVirtualPortgroup) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) { var dvp mo.DistributedVirtualPortgroup var dvs mo.DistributedVirtualSwitch prop := "config.distributedVirtualSwitch" if err := p.Properties(ctx, p.Reference(), []string{"key", prop}, &dvp); err != nil { return nil, err } // "This property should always be set unless the user's setting does not have System.Read privilege on the object referred to by this property." if dvp.Config.DistributedVirtualSwitch == nil { return nil, fmt.Errorf("no System.Read privilege on: %s.%s", p.Reference(), prop) } if err := p.Properties(ctx, *dvp.Config.DistributedVirtualSwitch, []string{"uuid"}, &dvs); err != nil { return nil, err } backing := &types.VirtualEthernetCardDistributedVirtualPortBackingInfo{ Port: types.DistributedVirtualSwitchPortConnection{ PortgroupKey: dvp.Key, SwitchUuid: dvs.Uuid, }, } return backing, nil }
[ "func", "(", "p", "DistributedVirtualPortgroup", ")", "EthernetCardBackingInfo", "(", "ctx", "context", ".", "Context", ")", "(", "types", ".", "BaseVirtualDeviceBackingInfo", ",", "error", ")", "{", "var", "dvp", "mo", ".", "DistributedVirtualPortgroup", "\n", "var", "dvs", "mo", ".", "DistributedVirtualSwitch", "\n", "prop", ":=", "\"config.distributedVirtualSwitch\"", "\n", "if", "err", ":=", "p", ".", "Properties", "(", "ctx", ",", "p", ".", "Reference", "(", ")", ",", "[", "]", "string", "{", "\"key\"", ",", "prop", "}", ",", "&", "dvp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "dvp", ".", "Config", ".", "DistributedVirtualSwitch", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"no System.Read privilege on: %s.%s\"", ",", "p", ".", "Reference", "(", ")", ",", "prop", ")", "\n", "}", "\n", "if", "err", ":=", "p", ".", "Properties", "(", "ctx", ",", "*", "dvp", ".", "Config", ".", "DistributedVirtualSwitch", ",", "[", "]", "string", "{", "\"uuid\"", "}", ",", "&", "dvs", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "backing", ":=", "&", "types", ".", "VirtualEthernetCardDistributedVirtualPortBackingInfo", "{", "Port", ":", "types", ".", "DistributedVirtualSwitchPortConnection", "{", "PortgroupKey", ":", "dvp", ".", "Key", ",", "SwitchUuid", ":", "dvs", ".", "Uuid", ",", "}", ",", "}", "\n", "return", "backing", ",", "nil", "\n", "}" ]
// EthernetCardBackingInfo returns the VirtualDeviceBackingInfo for this DistributedVirtualPortgroup
[ "EthernetCardBackingInfo", "returns", "the", "VirtualDeviceBackingInfo", "for", "this", "DistributedVirtualPortgroup" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/distributed_virtual_portgroup.go#L40-L66
train
vmware/govmomi
object/host_network_system.go
AddPortGroup
func (o HostNetworkSystem) AddPortGroup(ctx context.Context, portgrp types.HostPortGroupSpec) error { req := types.AddPortGroup{ This: o.Reference(), Portgrp: portgrp, } _, err := methods.AddPortGroup(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) AddPortGroup(ctx context.Context, portgrp types.HostPortGroupSpec) error { req := types.AddPortGroup{ This: o.Reference(), Portgrp: portgrp, } _, err := methods.AddPortGroup(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "AddPortGroup", "(", "ctx", "context", ".", "Context", ",", "portgrp", "types", ".", "HostPortGroupSpec", ")", "error", "{", "req", ":=", "types", ".", "AddPortGroup", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "Portgrp", ":", "portgrp", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "AddPortGroup", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// AddPortGroup wraps methods.AddPortGroup
[ "AddPortGroup", "wraps", "methods", ".", "AddPortGroup" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L38-L50
train
vmware/govmomi
object/host_network_system.go
AddServiceConsoleVirtualNic
func (o HostNetworkSystem) AddServiceConsoleVirtualNic(ctx context.Context, portgroup string, nic types.HostVirtualNicSpec) (string, error) { req := types.AddServiceConsoleVirtualNic{ This: o.Reference(), Portgroup: portgroup, Nic: nic, } res, err := methods.AddServiceConsoleVirtualNic(ctx, o.c, &req) if err != nil { return "", err } return res.Returnval, nil }
go
func (o HostNetworkSystem) AddServiceConsoleVirtualNic(ctx context.Context, portgroup string, nic types.HostVirtualNicSpec) (string, error) { req := types.AddServiceConsoleVirtualNic{ This: o.Reference(), Portgroup: portgroup, Nic: nic, } res, err := methods.AddServiceConsoleVirtualNic(ctx, o.c, &req) if err != nil { return "", err } return res.Returnval, nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "AddServiceConsoleVirtualNic", "(", "ctx", "context", ".", "Context", ",", "portgroup", "string", ",", "nic", "types", ".", "HostVirtualNicSpec", ")", "(", "string", ",", "error", ")", "{", "req", ":=", "types", ".", "AddServiceConsoleVirtualNic", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "Portgroup", ":", "portgroup", ",", "Nic", ":", "nic", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "AddServiceConsoleVirtualNic", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "return", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// AddServiceConsoleVirtualNic wraps methods.AddServiceConsoleVirtualNic
[ "AddServiceConsoleVirtualNic", "wraps", "methods", ".", "AddServiceConsoleVirtualNic" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L53-L66
train
vmware/govmomi
object/host_network_system.go
AddVirtualSwitch
func (o HostNetworkSystem) AddVirtualSwitch(ctx context.Context, vswitchName string, spec *types.HostVirtualSwitchSpec) error { req := types.AddVirtualSwitch{ This: o.Reference(), VswitchName: vswitchName, Spec: spec, } _, err := methods.AddVirtualSwitch(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) AddVirtualSwitch(ctx context.Context, vswitchName string, spec *types.HostVirtualSwitchSpec) error { req := types.AddVirtualSwitch{ This: o.Reference(), VswitchName: vswitchName, Spec: spec, } _, err := methods.AddVirtualSwitch(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "AddVirtualSwitch", "(", "ctx", "context", ".", "Context", ",", "vswitchName", "string", ",", "spec", "*", "types", ".", "HostVirtualSwitchSpec", ")", "error", "{", "req", ":=", "types", ".", "AddVirtualSwitch", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "VswitchName", ":", "vswitchName", ",", "Spec", ":", "spec", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "AddVirtualSwitch", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// AddVirtualSwitch wraps methods.AddVirtualSwitch
[ "AddVirtualSwitch", "wraps", "methods", ".", "AddVirtualSwitch" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L85-L98
train
vmware/govmomi
object/host_network_system.go
QueryNetworkHint
func (o HostNetworkSystem) QueryNetworkHint(ctx context.Context, device []string) error { req := types.QueryNetworkHint{ This: o.Reference(), Device: device, } _, err := methods.QueryNetworkHint(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) QueryNetworkHint(ctx context.Context, device []string) error { req := types.QueryNetworkHint{ This: o.Reference(), Device: device, } _, err := methods.QueryNetworkHint(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "QueryNetworkHint", "(", "ctx", "context", ".", "Context", ",", "device", "[", "]", "string", ")", "error", "{", "req", ":=", "types", ".", "QueryNetworkHint", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "Device", ":", "device", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "QueryNetworkHint", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// QueryNetworkHint wraps methods.QueryNetworkHint
[ "QueryNetworkHint", "wraps", "methods", ".", "QueryNetworkHint" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L101-L113
train
vmware/govmomi
object/host_network_system.go
RefreshNetworkSystem
func (o HostNetworkSystem) RefreshNetworkSystem(ctx context.Context) error { req := types.RefreshNetworkSystem{ This: o.Reference(), } _, err := methods.RefreshNetworkSystem(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) RefreshNetworkSystem(ctx context.Context) error { req := types.RefreshNetworkSystem{ This: o.Reference(), } _, err := methods.RefreshNetworkSystem(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "RefreshNetworkSystem", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ":=", "types", ".", "RefreshNetworkSystem", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "RefreshNetworkSystem", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RefreshNetworkSystem wraps methods.RefreshNetworkSystem
[ "RefreshNetworkSystem", "wraps", "methods", ".", "RefreshNetworkSystem" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L116-L127
train
vmware/govmomi
object/host_network_system.go
RemovePortGroup
func (o HostNetworkSystem) RemovePortGroup(ctx context.Context, pgName string) error { req := types.RemovePortGroup{ This: o.Reference(), PgName: pgName, } _, err := methods.RemovePortGroup(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) RemovePortGroup(ctx context.Context, pgName string) error { req := types.RemovePortGroup{ This: o.Reference(), PgName: pgName, } _, err := methods.RemovePortGroup(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "RemovePortGroup", "(", "ctx", "context", ".", "Context", ",", "pgName", "string", ")", "error", "{", "req", ":=", "types", ".", "RemovePortGroup", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "PgName", ":", "pgName", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "RemovePortGroup", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemovePortGroup wraps methods.RemovePortGroup
[ "RemovePortGroup", "wraps", "methods", ".", "RemovePortGroup" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L130-L142
train
vmware/govmomi
object/host_network_system.go
RemoveVirtualSwitch
func (o HostNetworkSystem) RemoveVirtualSwitch(ctx context.Context, vswitchName string) error { req := types.RemoveVirtualSwitch{ This: o.Reference(), VswitchName: vswitchName, } _, err := methods.RemoveVirtualSwitch(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) RemoveVirtualSwitch(ctx context.Context, vswitchName string) error { req := types.RemoveVirtualSwitch{ This: o.Reference(), VswitchName: vswitchName, } _, err := methods.RemoveVirtualSwitch(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "RemoveVirtualSwitch", "(", "ctx", "context", ".", "Context", ",", "vswitchName", "string", ")", "error", "{", "req", ":=", "types", ".", "RemoveVirtualSwitch", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "VswitchName", ":", "vswitchName", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "RemoveVirtualSwitch", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RemoveVirtualSwitch wraps methods.RemoveVirtualSwitch
[ "RemoveVirtualSwitch", "wraps", "methods", ".", "RemoveVirtualSwitch" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L175-L187
train
vmware/govmomi
object/host_network_system.go
UpdateConsoleIpRouteConfig
func (o HostNetworkSystem) UpdateConsoleIpRouteConfig(ctx context.Context, config types.BaseHostIpRouteConfig) error { req := types.UpdateConsoleIpRouteConfig{ This: o.Reference(), Config: config, } _, err := methods.UpdateConsoleIpRouteConfig(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) UpdateConsoleIpRouteConfig(ctx context.Context, config types.BaseHostIpRouteConfig) error { req := types.UpdateConsoleIpRouteConfig{ This: o.Reference(), Config: config, } _, err := methods.UpdateConsoleIpRouteConfig(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "UpdateConsoleIpRouteConfig", "(", "ctx", "context", ".", "Context", ",", "config", "types", ".", "BaseHostIpRouteConfig", ")", "error", "{", "req", ":=", "types", ".", "UpdateConsoleIpRouteConfig", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "Config", ":", "config", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "UpdateConsoleIpRouteConfig", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdateConsoleIpRouteConfig wraps methods.UpdateConsoleIpRouteConfig
[ "UpdateConsoleIpRouteConfig", "wraps", "methods", ".", "UpdateConsoleIpRouteConfig" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L205-L217
train
vmware/govmomi
object/host_network_system.go
UpdateNetworkConfig
func (o HostNetworkSystem) UpdateNetworkConfig(ctx context.Context, config types.HostNetworkConfig, changeMode string) (*types.HostNetworkConfigResult, error) { req := types.UpdateNetworkConfig{ This: o.Reference(), Config: config, ChangeMode: changeMode, } res, err := methods.UpdateNetworkConfig(ctx, o.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
go
func (o HostNetworkSystem) UpdateNetworkConfig(ctx context.Context, config types.HostNetworkConfig, changeMode string) (*types.HostNetworkConfigResult, error) { req := types.UpdateNetworkConfig{ This: o.Reference(), Config: config, ChangeMode: changeMode, } res, err := methods.UpdateNetworkConfig(ctx, o.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "UpdateNetworkConfig", "(", "ctx", "context", ".", "Context", ",", "config", "types", ".", "HostNetworkConfig", ",", "changeMode", "string", ")", "(", "*", "types", ".", "HostNetworkConfigResult", ",", "error", ")", "{", "req", ":=", "types", ".", "UpdateNetworkConfig", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "Config", ":", "config", ",", "ChangeMode", ":", "changeMode", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "UpdateNetworkConfig", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// UpdateNetworkConfig wraps methods.UpdateNetworkConfig
[ "UpdateNetworkConfig", "wraps", "methods", ".", "UpdateNetworkConfig" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L265-L278
train
vmware/govmomi
object/host_network_system.go
UpdatePhysicalNicLinkSpeed
func (o HostNetworkSystem) UpdatePhysicalNicLinkSpeed(ctx context.Context, device string, linkSpeed *types.PhysicalNicLinkInfo) error { req := types.UpdatePhysicalNicLinkSpeed{ This: o.Reference(), Device: device, LinkSpeed: linkSpeed, } _, err := methods.UpdatePhysicalNicLinkSpeed(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) UpdatePhysicalNicLinkSpeed(ctx context.Context, device string, linkSpeed *types.PhysicalNicLinkInfo) error { req := types.UpdatePhysicalNicLinkSpeed{ This: o.Reference(), Device: device, LinkSpeed: linkSpeed, } _, err := methods.UpdatePhysicalNicLinkSpeed(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "UpdatePhysicalNicLinkSpeed", "(", "ctx", "context", ".", "Context", ",", "device", "string", ",", "linkSpeed", "*", "types", ".", "PhysicalNicLinkInfo", ")", "error", "{", "req", ":=", "types", ".", "UpdatePhysicalNicLinkSpeed", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "Device", ":", "device", ",", "LinkSpeed", ":", "linkSpeed", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "UpdatePhysicalNicLinkSpeed", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdatePhysicalNicLinkSpeed wraps methods.UpdatePhysicalNicLinkSpeed
[ "UpdatePhysicalNicLinkSpeed", "wraps", "methods", ".", "UpdatePhysicalNicLinkSpeed" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L281-L294
train
vmware/govmomi
object/host_network_system.go
UpdatePortGroup
func (o HostNetworkSystem) UpdatePortGroup(ctx context.Context, pgName string, portgrp types.HostPortGroupSpec) error { req := types.UpdatePortGroup{ This: o.Reference(), PgName: pgName, Portgrp: portgrp, } _, err := methods.UpdatePortGroup(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) UpdatePortGroup(ctx context.Context, pgName string, portgrp types.HostPortGroupSpec) error { req := types.UpdatePortGroup{ This: o.Reference(), PgName: pgName, Portgrp: portgrp, } _, err := methods.UpdatePortGroup(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "UpdatePortGroup", "(", "ctx", "context", ".", "Context", ",", "pgName", "string", ",", "portgrp", "types", ".", "HostPortGroupSpec", ")", "error", "{", "req", ":=", "types", ".", "UpdatePortGroup", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "PgName", ":", "pgName", ",", "Portgrp", ":", "portgrp", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "UpdatePortGroup", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdatePortGroup wraps methods.UpdatePortGroup
[ "UpdatePortGroup", "wraps", "methods", ".", "UpdatePortGroup" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L297-L310
train
vmware/govmomi
object/host_network_system.go
UpdateVirtualNic
func (o HostNetworkSystem) UpdateVirtualNic(ctx context.Context, device string, nic types.HostVirtualNicSpec) error { req := types.UpdateVirtualNic{ This: o.Reference(), Device: device, Nic: nic, } _, err := methods.UpdateVirtualNic(ctx, o.c, &req) if err != nil { return err } return nil }
go
func (o HostNetworkSystem) UpdateVirtualNic(ctx context.Context, device string, nic types.HostVirtualNicSpec) error { req := types.UpdateVirtualNic{ This: o.Reference(), Device: device, Nic: nic, } _, err := methods.UpdateVirtualNic(ctx, o.c, &req) if err != nil { return err } return nil }
[ "func", "(", "o", "HostNetworkSystem", ")", "UpdateVirtualNic", "(", "ctx", "context", ".", "Context", ",", "device", "string", ",", "nic", "types", ".", "HostVirtualNicSpec", ")", "error", "{", "req", ":=", "types", ".", "UpdateVirtualNic", "{", "This", ":", "o", ".", "Reference", "(", ")", ",", "Device", ":", "device", ",", "Nic", ":", "nic", ",", "}", "\n", "_", ",", "err", ":=", "methods", ".", "UpdateVirtualNic", "(", "ctx", ",", "o", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// UpdateVirtualNic wraps methods.UpdateVirtualNic
[ "UpdateVirtualNic", "wraps", "methods", ".", "UpdateVirtualNic" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L329-L342
train
vmware/govmomi
view/task_view.go
CreateTaskView
func (m Manager) CreateTaskView(ctx context.Context, watch *types.ManagedObjectReference) (*TaskView, error) { l, err := m.CreateListView(ctx, nil) if err != nil { return nil, err } tv := &TaskView{ ListView: l, Watch: watch, } return tv, nil }
go
func (m Manager) CreateTaskView(ctx context.Context, watch *types.ManagedObjectReference) (*TaskView, error) { l, err := m.CreateListView(ctx, nil) if err != nil { return nil, err } tv := &TaskView{ ListView: l, Watch: watch, } return tv, nil }
[ "func", "(", "m", "Manager", ")", "CreateTaskView", "(", "ctx", "context", ".", "Context", ",", "watch", "*", "types", ".", "ManagedObjectReference", ")", "(", "*", "TaskView", ",", "error", ")", "{", "l", ",", "err", ":=", "m", ".", "CreateListView", "(", "ctx", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "tv", ":=", "&", "TaskView", "{", "ListView", ":", "l", ",", "Watch", ":", "watch", ",", "}", "\n", "return", "tv", ",", "nil", "\n", "}" ]
// CreateTaskView creates a new ListView that optionally watches for a ManagedEntity's recentTask updates.
[ "CreateTaskView", "creates", "a", "new", "ListView", "that", "optionally", "watches", "for", "a", "ManagedEntity", "s", "recentTask", "updates", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/view/task_view.go#L36-L48
train
vmware/govmomi
view/task_view.go
Collect
func (v TaskView) Collect(ctx context.Context, f func([]types.TaskInfo)) error { // Using TaskHistoryCollector would be less clunky, but it isn't supported on ESX at all. ref := v.Reference() filter := new(property.WaitFilter).Add(ref, "Task", []string{"info"}, v.TraversalSpec()) if v.Watch != nil { filter.Add(*v.Watch, v.Watch.Type, []string{"recentTask"}) } pc := property.DefaultCollector(v.Client()) completed := make(map[string]bool) return property.WaitForUpdates(ctx, pc, filter, func(updates []types.ObjectUpdate) bool { var infos []types.TaskInfo var prune []types.ManagedObjectReference var tasks []types.ManagedObjectReference var reset func() for _, update := range updates { for _, change := range update.ChangeSet { if change.Name == "recentTask" { tasks = change.Val.(types.ArrayOfManagedObjectReference).ManagedObjectReference if len(tasks) != 0 { reset = func() { _ = v.Reset(ctx, tasks) // Remember any tasks we've reported as complete already, // to avoid reporting multiple times when Reset is triggered. rtasks := make(map[string]bool) for i := range tasks { if _, ok := completed[tasks[i].Value]; ok { rtasks[tasks[i].Value] = true } } completed = rtasks } } continue } info, ok := change.Val.(types.TaskInfo) if !ok { continue } if !completed[info.Task.Value] { infos = append(infos, info) } if v.Follow && info.CompleteTime != nil { prune = append(prune, info.Task) completed[info.Task.Value] = true } } } if len(infos) != 0 { f(infos) } if reset != nil { reset() } else if len(prune) != 0 { _ = v.Remove(ctx, prune) } if len(tasks) != 0 && len(infos) == 0 { return false } return !v.Follow }) }
go
func (v TaskView) Collect(ctx context.Context, f func([]types.TaskInfo)) error { // Using TaskHistoryCollector would be less clunky, but it isn't supported on ESX at all. ref := v.Reference() filter := new(property.WaitFilter).Add(ref, "Task", []string{"info"}, v.TraversalSpec()) if v.Watch != nil { filter.Add(*v.Watch, v.Watch.Type, []string{"recentTask"}) } pc := property.DefaultCollector(v.Client()) completed := make(map[string]bool) return property.WaitForUpdates(ctx, pc, filter, func(updates []types.ObjectUpdate) bool { var infos []types.TaskInfo var prune []types.ManagedObjectReference var tasks []types.ManagedObjectReference var reset func() for _, update := range updates { for _, change := range update.ChangeSet { if change.Name == "recentTask" { tasks = change.Val.(types.ArrayOfManagedObjectReference).ManagedObjectReference if len(tasks) != 0 { reset = func() { _ = v.Reset(ctx, tasks) // Remember any tasks we've reported as complete already, // to avoid reporting multiple times when Reset is triggered. rtasks := make(map[string]bool) for i := range tasks { if _, ok := completed[tasks[i].Value]; ok { rtasks[tasks[i].Value] = true } } completed = rtasks } } continue } info, ok := change.Val.(types.TaskInfo) if !ok { continue } if !completed[info.Task.Value] { infos = append(infos, info) } if v.Follow && info.CompleteTime != nil { prune = append(prune, info.Task) completed[info.Task.Value] = true } } } if len(infos) != 0 { f(infos) } if reset != nil { reset() } else if len(prune) != 0 { _ = v.Remove(ctx, prune) } if len(tasks) != 0 && len(infos) == 0 { return false } return !v.Follow }) }
[ "func", "(", "v", "TaskView", ")", "Collect", "(", "ctx", "context", ".", "Context", ",", "f", "func", "(", "[", "]", "types", ".", "TaskInfo", ")", ")", "error", "{", "ref", ":=", "v", ".", "Reference", "(", ")", "\n", "filter", ":=", "new", "(", "property", ".", "WaitFilter", ")", ".", "Add", "(", "ref", ",", "\"Task\"", ",", "[", "]", "string", "{", "\"info\"", "}", ",", "v", ".", "TraversalSpec", "(", ")", ")", "\n", "if", "v", ".", "Watch", "!=", "nil", "{", "filter", ".", "Add", "(", "*", "v", ".", "Watch", ",", "v", ".", "Watch", ".", "Type", ",", "[", "]", "string", "{", "\"recentTask\"", "}", ")", "\n", "}", "\n", "pc", ":=", "property", ".", "DefaultCollector", "(", "v", ".", "Client", "(", ")", ")", "\n", "completed", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "return", "property", ".", "WaitForUpdates", "(", "ctx", ",", "pc", ",", "filter", ",", "func", "(", "updates", "[", "]", "types", ".", "ObjectUpdate", ")", "bool", "{", "var", "infos", "[", "]", "types", ".", "TaskInfo", "\n", "var", "prune", "[", "]", "types", ".", "ManagedObjectReference", "\n", "var", "tasks", "[", "]", "types", ".", "ManagedObjectReference", "\n", "var", "reset", "func", "(", ")", "\n", "for", "_", ",", "update", ":=", "range", "updates", "{", "for", "_", ",", "change", ":=", "range", "update", ".", "ChangeSet", "{", "if", "change", ".", "Name", "==", "\"recentTask\"", "{", "tasks", "=", "change", ".", "Val", ".", "(", "types", ".", "ArrayOfManagedObjectReference", ")", ".", "ManagedObjectReference", "\n", "if", "len", "(", "tasks", ")", "!=", "0", "{", "reset", "=", "func", "(", ")", "{", "_", "=", "v", ".", "Reset", "(", "ctx", ",", "tasks", ")", "\n", "rtasks", ":=", "make", "(", "map", "[", "string", "]", "bool", ")", "\n", "for", "i", ":=", "range", "tasks", "{", "if", "_", ",", "ok", ":=", "completed", "[", "tasks", "[", "i", "]", ".", "Value", "]", ";", "ok", "{", "rtasks", "[", "tasks", "[", "i", "]", ".", "Value", "]", "=", "true", "\n", "}", "\n", "}", "\n", "completed", "=", "rtasks", "\n", "}", "\n", "}", "\n", "continue", "\n", "}", "\n", "info", ",", "ok", ":=", "change", ".", "Val", ".", "(", "types", ".", "TaskInfo", ")", "\n", "if", "!", "ok", "{", "continue", "\n", "}", "\n", "if", "!", "completed", "[", "info", ".", "Task", ".", "Value", "]", "{", "infos", "=", "append", "(", "infos", ",", "info", ")", "\n", "}", "\n", "if", "v", ".", "Follow", "&&", "info", ".", "CompleteTime", "!=", "nil", "{", "prune", "=", "append", "(", "prune", ",", "info", ".", "Task", ")", "\n", "completed", "[", "info", ".", "Task", ".", "Value", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "infos", ")", "!=", "0", "{", "f", "(", "infos", ")", "\n", "}", "\n", "if", "reset", "!=", "nil", "{", "reset", "(", ")", "\n", "}", "else", "if", "len", "(", "prune", ")", "!=", "0", "{", "_", "=", "v", ".", "Remove", "(", "ctx", ",", "prune", ")", "\n", "}", "\n", "if", "len", "(", "tasks", ")", "!=", "0", "&&", "len", "(", "infos", ")", "==", "0", "{", "return", "false", "\n", "}", "\n", "return", "!", "v", ".", "Follow", "\n", "}", ")", "\n", "}" ]
// Collect calls function f for each Task update.
[ "Collect", "calls", "function", "f", "for", "each", "Task", "update", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/view/task_view.go#L51-L125
train
vmware/govmomi
vapi/vcenter/vcenter_ovf.go
DeployLibraryItem
func (c *Manager) DeployLibraryItem(ctx context.Context, libraryItemID string, deploy Deploy) (Deployment, error) { url := internal.URL(c, internal.VCenterOVFLibraryItem).WithID(libraryItemID).WithAction("deploy") var res Deployment return res, c.Do(ctx, url.Request(http.MethodPost, deploy), &res) }
go
func (c *Manager) DeployLibraryItem(ctx context.Context, libraryItemID string, deploy Deploy) (Deployment, error) { url := internal.URL(c, internal.VCenterOVFLibraryItem).WithID(libraryItemID).WithAction("deploy") var res Deployment return res, c.Do(ctx, url.Request(http.MethodPost, deploy), &res) }
[ "func", "(", "c", "*", "Manager", ")", "DeployLibraryItem", "(", "ctx", "context", ".", "Context", ",", "libraryItemID", "string", ",", "deploy", "Deploy", ")", "(", "Deployment", ",", "error", ")", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "VCenterOVFLibraryItem", ")", ".", "WithID", "(", "libraryItemID", ")", ".", "WithAction", "(", "\"deploy\"", ")", "\n", "var", "res", "Deployment", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "deploy", ")", ",", "&", "res", ")", "\n", "}" ]
// DeployLibraryItem deploys a library OVF
[ "DeployLibraryItem", "deploys", "a", "library", "OVF" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/vcenter/vcenter_ovf.go#L141-L145
train
vmware/govmomi
vapi/vcenter/vcenter_ovf.go
FilterLibraryItem
func (c *Manager) FilterLibraryItem(ctx context.Context, libraryItemID string, filter FilterRequest) (FilterResponse, error) { url := internal.URL(c, internal.VCenterOVFLibraryItem).WithID(libraryItemID).WithAction("filter") var res FilterResponse return res, c.Do(ctx, url.Request(http.MethodPost, filter), &res) }
go
func (c *Manager) FilterLibraryItem(ctx context.Context, libraryItemID string, filter FilterRequest) (FilterResponse, error) { url := internal.URL(c, internal.VCenterOVFLibraryItem).WithID(libraryItemID).WithAction("filter") var res FilterResponse return res, c.Do(ctx, url.Request(http.MethodPost, filter), &res) }
[ "func", "(", "c", "*", "Manager", ")", "FilterLibraryItem", "(", "ctx", "context", ".", "Context", ",", "libraryItemID", "string", ",", "filter", "FilterRequest", ")", "(", "FilterResponse", ",", "error", ")", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "VCenterOVFLibraryItem", ")", ".", "WithID", "(", "libraryItemID", ")", ".", "WithAction", "(", "\"filter\"", ")", "\n", "var", "res", "FilterResponse", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "filter", ")", ",", "&", "res", ")", "\n", "}" ]
// FilterLibraryItem deploys a library OVF
[ "FilterLibraryItem", "deploys", "a", "library", "OVF" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/vcenter/vcenter_ovf.go#L148-L152
train
vmware/govmomi
vapi/rest/client.go
NewClient
func NewClient(c *vim25.Client) *Client { sc := c.Client.NewServiceClient(internal.Path, "") return &Client{sc} }
go
func NewClient(c *vim25.Client) *Client { sc := c.Client.NewServiceClient(internal.Path, "") return &Client{sc} }
[ "func", "NewClient", "(", "c", "*", "vim25", ".", "Client", ")", "*", "Client", "{", "sc", ":=", "c", ".", "Client", ".", "NewServiceClient", "(", "internal", ".", "Path", ",", "\"\"", ")", "\n", "return", "&", "Client", "{", "sc", "}", "\n", "}" ]
// NewClient creates a new Client instance.
[ "NewClient", "creates", "a", "new", "Client", "instance", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/rest/client.go#L40-L44
train
vmware/govmomi
vapi/rest/client.go
Do
func (c *Client) Do(ctx context.Context, req *http.Request, resBody interface{}) error { switch req.Method { case http.MethodPost, http.MethodPatch: req.Header.Set("Content-Type", "application/json") } req.Header.Set("Accept", "application/json") if s, ok := ctx.Value(signerContext{}).(Signer); ok { if err := s.SignRequest(req); err != nil { return err } } return c.Client.Do(ctx, req, func(res *http.Response) error { switch res.StatusCode { case http.StatusOK: case http.StatusBadRequest: // TODO: structured error types detail, err := ioutil.ReadAll(res.Body) if err != nil { return err } return fmt.Errorf("%s: %s", res.Status, bytes.TrimSpace(detail)) default: return fmt.Errorf("%s %s: %s", req.Method, req.URL, res.Status) } if resBody == nil { return nil } switch b := resBody.(type) { case io.Writer: _, err := io.Copy(b, res.Body) return err default: val := struct { Value interface{} `json:"value,omitempty"` }{ resBody, } return json.NewDecoder(res.Body).Decode(&val) } }) }
go
func (c *Client) Do(ctx context.Context, req *http.Request, resBody interface{}) error { switch req.Method { case http.MethodPost, http.MethodPatch: req.Header.Set("Content-Type", "application/json") } req.Header.Set("Accept", "application/json") if s, ok := ctx.Value(signerContext{}).(Signer); ok { if err := s.SignRequest(req); err != nil { return err } } return c.Client.Do(ctx, req, func(res *http.Response) error { switch res.StatusCode { case http.StatusOK: case http.StatusBadRequest: // TODO: structured error types detail, err := ioutil.ReadAll(res.Body) if err != nil { return err } return fmt.Errorf("%s: %s", res.Status, bytes.TrimSpace(detail)) default: return fmt.Errorf("%s %s: %s", req.Method, req.URL, res.Status) } if resBody == nil { return nil } switch b := resBody.(type) { case io.Writer: _, err := io.Copy(b, res.Body) return err default: val := struct { Value interface{} `json:"value,omitempty"` }{ resBody, } return json.NewDecoder(res.Body).Decode(&val) } }) }
[ "func", "(", "c", "*", "Client", ")", "Do", "(", "ctx", "context", ".", "Context", ",", "req", "*", "http", ".", "Request", ",", "resBody", "interface", "{", "}", ")", "error", "{", "switch", "req", ".", "Method", "{", "case", "http", ".", "MethodPost", ",", "http", ".", "MethodPatch", ":", "req", ".", "Header", ".", "Set", "(", "\"Content-Type\"", ",", "\"application/json\"", ")", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"Accept\"", ",", "\"application/json\"", ")", "\n", "if", "s", ",", "ok", ":=", "ctx", ".", "Value", "(", "signerContext", "{", "}", ")", ".", "(", "Signer", ")", ";", "ok", "{", "if", "err", ":=", "s", ".", "SignRequest", "(", "req", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "c", ".", "Client", ".", "Do", "(", "ctx", ",", "req", ",", "func", "(", "res", "*", "http", ".", "Response", ")", "error", "{", "switch", "res", ".", "StatusCode", "{", "case", "http", ".", "StatusOK", ":", "case", "http", ".", "StatusBadRequest", ":", "detail", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "res", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"%s: %s\"", ",", "res", ".", "Status", ",", "bytes", ".", "TrimSpace", "(", "detail", ")", ")", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"%s %s: %s\"", ",", "req", ".", "Method", ",", "req", ".", "URL", ",", "res", ".", "Status", ")", "\n", "}", "\n", "if", "resBody", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "switch", "b", ":=", "resBody", ".", "(", "type", ")", "{", "case", "io", ".", "Writer", ":", "_", ",", "err", ":=", "io", ".", "Copy", "(", "b", ",", "res", ".", "Body", ")", "\n", "return", "err", "\n", "default", ":", "val", ":=", "struct", "{", "Value", "interface", "{", "}", "`json:\"value,omitempty\"`", "\n", "}", "{", "resBody", ",", "}", "\n", "return", "json", ".", "NewDecoder", "(", "res", ".", "Body", ")", ".", "Decode", "(", "&", "val", ")", "\n", "}", "\n", "}", ")", "\n", "}" ]
// Do sends the http.Request, decoding resBody if provided.
[ "Do", "sends", "the", "http", ".", "Request", "decoding", "resBody", "if", "provided", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/rest/client.go#L57-L102
train
vmware/govmomi
vapi/rest/client.go
Login
func (c *Client) Login(ctx context.Context, user *url.Userinfo) error { req := internal.URL(c, internal.SessionPath).Request(http.MethodPost) if user != nil { if password, ok := user.Password(); ok { req.SetBasicAuth(user.Username(), password) } } return c.Do(ctx, req, nil) }
go
func (c *Client) Login(ctx context.Context, user *url.Userinfo) error { req := internal.URL(c, internal.SessionPath).Request(http.MethodPost) if user != nil { if password, ok := user.Password(); ok { req.SetBasicAuth(user.Username(), password) } } return c.Do(ctx, req, nil) }
[ "func", "(", "c", "*", "Client", ")", "Login", "(", "ctx", "context", ".", "Context", ",", "user", "*", "url", ".", "Userinfo", ")", "error", "{", "req", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "SessionPath", ")", ".", "Request", "(", "http", ".", "MethodPost", ")", "\n", "if", "user", "!=", "nil", "{", "if", "password", ",", "ok", ":=", "user", ".", "Password", "(", ")", ";", "ok", "{", "req", ".", "SetBasicAuth", "(", "user", ".", "Username", "(", ")", ",", "password", ")", "\n", "}", "\n", "}", "\n", "return", "c", ".", "Do", "(", "ctx", ",", "req", ",", "nil", ")", "\n", "}" ]
// Login creates a new session via Basic Authentication with the given url.Userinfo.
[ "Login", "creates", "a", "new", "session", "via", "Basic", "Authentication", "with", "the", "given", "url", ".", "Userinfo", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/rest/client.go#L105-L115
train
vmware/govmomi
vapi/rest/client.go
Logout
func (c *Client) Logout(ctx context.Context) error { req := internal.URL(c, internal.SessionPath).Request(http.MethodDelete) return c.Do(ctx, req, nil) }
go
func (c *Client) Logout(ctx context.Context) error { req := internal.URL(c, internal.SessionPath).Request(http.MethodDelete) return c.Do(ctx, req, nil) }
[ "func", "(", "c", "*", "Client", ")", "Logout", "(", "ctx", "context", ".", "Context", ")", "error", "{", "req", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "SessionPath", ")", ".", "Request", "(", "http", ".", "MethodDelete", ")", "\n", "return", "c", ".", "Do", "(", "ctx", ",", "req", ",", "nil", ")", "\n", "}" ]
// Logout deletes the current session.
[ "Logout", "deletes", "the", "current", "session", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/rest/client.go#L122-L125
train
vmware/govmomi
lookup/client.go
NewClient
func NewClient(ctx context.Context, c *vim25.Client) (*Client, error) { sc := c.Client.NewServiceClient(Path, Namespace) sc.Version = Version req := types.RetrieveServiceContent{ This: ServiceInstance, } res, err := methods.RetrieveServiceContent(ctx, sc, &req) if err != nil { return nil, err } return &Client{sc, res.Returnval}, nil }
go
func NewClient(ctx context.Context, c *vim25.Client) (*Client, error) { sc := c.Client.NewServiceClient(Path, Namespace) sc.Version = Version req := types.RetrieveServiceContent{ This: ServiceInstance, } res, err := methods.RetrieveServiceContent(ctx, sc, &req) if err != nil { return nil, err } return &Client{sc, res.Returnval}, nil }
[ "func", "NewClient", "(", "ctx", "context", ".", "Context", ",", "c", "*", "vim25", ".", "Client", ")", "(", "*", "Client", ",", "error", ")", "{", "sc", ":=", "c", ".", "Client", ".", "NewServiceClient", "(", "Path", ",", "Namespace", ")", "\n", "sc", ".", "Version", "=", "Version", "\n", "req", ":=", "types", ".", "RetrieveServiceContent", "{", "This", ":", "ServiceInstance", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "RetrieveServiceContent", "(", "ctx", ",", "sc", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "Client", "{", "sc", ",", "res", ".", "Returnval", "}", ",", "nil", "\n", "}" ]
// NewClient returns a client targeting the SSO Lookup Service API endpoint.
[ "NewClient", "returns", "a", "client", "targeting", "the", "SSO", "Lookup", "Service", "API", "endpoint", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/lookup/client.go#L54-L68
train
vmware/govmomi
lookup/client.go
EndpointURL
func EndpointURL(ctx context.Context, c *vim25.Client, path string, filter *types.LookupServiceRegistrationFilter) string { if lu, err := NewClient(ctx, c); err == nil { info, _ := lu.List(ctx, filter) if len(info) != 0 && len(info[0].ServiceEndpoints) != 0 { endpoint := &info[0].ServiceEndpoints[0] path = endpoint.Url if u, err := url.Parse(path); err == nil { if c.Thumbprint(u.Host) == "" { c.SetThumbprint(u.Host, endpointThumbprint(endpoint)) } } } } return path }
go
func EndpointURL(ctx context.Context, c *vim25.Client, path string, filter *types.LookupServiceRegistrationFilter) string { if lu, err := NewClient(ctx, c); err == nil { info, _ := lu.List(ctx, filter) if len(info) != 0 && len(info[0].ServiceEndpoints) != 0 { endpoint := &info[0].ServiceEndpoints[0] path = endpoint.Url if u, err := url.Parse(path); err == nil { if c.Thumbprint(u.Host) == "" { c.SetThumbprint(u.Host, endpointThumbprint(endpoint)) } } } } return path }
[ "func", "EndpointURL", "(", "ctx", "context", ".", "Context", ",", "c", "*", "vim25", ".", "Client", ",", "path", "string", ",", "filter", "*", "types", ".", "LookupServiceRegistrationFilter", ")", "string", "{", "if", "lu", ",", "err", ":=", "NewClient", "(", "ctx", ",", "c", ")", ";", "err", "==", "nil", "{", "info", ",", "_", ":=", "lu", ".", "List", "(", "ctx", ",", "filter", ")", "\n", "if", "len", "(", "info", ")", "!=", "0", "&&", "len", "(", "info", "[", "0", "]", ".", "ServiceEndpoints", ")", "!=", "0", "{", "endpoint", ":=", "&", "info", "[", "0", "]", ".", "ServiceEndpoints", "[", "0", "]", "\n", "path", "=", "endpoint", ".", "Url", "\n", "if", "u", ",", "err", ":=", "url", ".", "Parse", "(", "path", ")", ";", "err", "==", "nil", "{", "if", "c", ".", "Thumbprint", "(", "u", ".", "Host", ")", "==", "\"\"", "{", "c", ".", "SetThumbprint", "(", "u", ".", "Host", ",", "endpointThumbprint", "(", "endpoint", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "path", "\n", "}" ]
// EndpointURL uses the Lookup Service to find the endpoint URL and thumbprint for the given filter. // If the endpoint is found, its TLS certificate is also added to the vim25.Client's trusted host thumbprints. // If the Lookup Service is not available, the given path is returned as the default.
[ "EndpointURL", "uses", "the", "Lookup", "Service", "to", "find", "the", "endpoint", "URL", "and", "thumbprint", "for", "the", "given", "filter", ".", "If", "the", "endpoint", "is", "found", "its", "TLS", "certificate", "is", "also", "added", "to", "the", "vim25", ".", "Client", "s", "trusted", "host", "thumbprints", ".", "If", "the", "Lookup", "Service", "is", "not", "available", "the", "given", "path", "is", "returned", "as", "the", "default", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/lookup/client.go#L98-L113
train
vmware/govmomi
lookup/client.go
endpointThumbprint
func endpointThumbprint(endpoint *types.LookupServiceRegistrationEndpoint) string { if len(endpoint.SslTrust) == 0 { return "" } enc := endpoint.SslTrust[0] b, err := base64.StdEncoding.DecodeString(enc) if err != nil { log.Printf("base64.Decode(%q): %s", enc, err) return "" } cert, err := x509.ParseCertificate(b) if err != nil { log.Printf("x509.ParseCertificate(%q): %s", enc, err) return "" } return soap.ThumbprintSHA1(cert) }
go
func endpointThumbprint(endpoint *types.LookupServiceRegistrationEndpoint) string { if len(endpoint.SslTrust) == 0 { return "" } enc := endpoint.SslTrust[0] b, err := base64.StdEncoding.DecodeString(enc) if err != nil { log.Printf("base64.Decode(%q): %s", enc, err) return "" } cert, err := x509.ParseCertificate(b) if err != nil { log.Printf("x509.ParseCertificate(%q): %s", enc, err) return "" } return soap.ThumbprintSHA1(cert) }
[ "func", "endpointThumbprint", "(", "endpoint", "*", "types", ".", "LookupServiceRegistrationEndpoint", ")", "string", "{", "if", "len", "(", "endpoint", ".", "SslTrust", ")", "==", "0", "{", "return", "\"\"", "\n", "}", "\n", "enc", ":=", "endpoint", ".", "SslTrust", "[", "0", "]", "\n", "b", ",", "err", ":=", "base64", ".", "StdEncoding", ".", "DecodeString", "(", "enc", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"base64.Decode(%q): %s\"", ",", "enc", ",", "err", ")", "\n", "return", "\"\"", "\n", "}", "\n", "cert", ",", "err", ":=", "x509", ".", "ParseCertificate", "(", "b", ")", "\n", "if", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"x509.ParseCertificate(%q): %s\"", ",", "enc", ",", "err", ")", "\n", "return", "\"\"", "\n", "}", "\n", "return", "soap", ".", "ThumbprintSHA1", "(", "cert", ")", "\n", "}" ]
// endpointThumbprint converts the base64 encoded endpoint certificate to a SHA1 thumbprint.
[ "endpointThumbprint", "converts", "the", "base64", "encoded", "endpoint", "certificate", "to", "a", "SHA1", "thumbprint", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/lookup/client.go#L116-L135
train
vmware/govmomi
ovf/manager.go
CreateDescriptor
func (m *Manager) CreateDescriptor(ctx context.Context, obj mo.Reference, cdp types.OvfCreateDescriptorParams) (*types.OvfCreateDescriptorResult, error) { req := types.CreateDescriptor{ This: m.Reference(), Obj: obj.Reference(), Cdp: cdp, } res, err := methods.CreateDescriptor(ctx, m.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
go
func (m *Manager) CreateDescriptor(ctx context.Context, obj mo.Reference, cdp types.OvfCreateDescriptorParams) (*types.OvfCreateDescriptorResult, error) { req := types.CreateDescriptor{ This: m.Reference(), Obj: obj.Reference(), Cdp: cdp, } res, err := methods.CreateDescriptor(ctx, m.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
[ "func", "(", "m", "*", "Manager", ")", "CreateDescriptor", "(", "ctx", "context", ".", "Context", ",", "obj", "mo", ".", "Reference", ",", "cdp", "types", ".", "OvfCreateDescriptorParams", ")", "(", "*", "types", ".", "OvfCreateDescriptorResult", ",", "error", ")", "{", "req", ":=", "types", ".", "CreateDescriptor", "{", "This", ":", "m", ".", "Reference", "(", ")", ",", "Obj", ":", "obj", ".", "Reference", "(", ")", ",", "Cdp", ":", "cdp", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "CreateDescriptor", "(", "ctx", ",", "m", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// CreateDescriptor wraps methods.CreateDescriptor
[ "CreateDescriptor", "wraps", "methods", ".", "CreateDescriptor" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/ovf/manager.go#L39-L52
train
vmware/govmomi
ovf/manager.go
CreateImportSpec
func (m *Manager) CreateImportSpec(ctx context.Context, ovfDescriptor string, resourcePool mo.Reference, datastore mo.Reference, cisp types.OvfCreateImportSpecParams) (*types.OvfCreateImportSpecResult, error) { req := types.CreateImportSpec{ This: m.Reference(), OvfDescriptor: ovfDescriptor, ResourcePool: resourcePool.Reference(), Datastore: datastore.Reference(), Cisp: cisp, } res, err := methods.CreateImportSpec(ctx, m.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
go
func (m *Manager) CreateImportSpec(ctx context.Context, ovfDescriptor string, resourcePool mo.Reference, datastore mo.Reference, cisp types.OvfCreateImportSpecParams) (*types.OvfCreateImportSpecResult, error) { req := types.CreateImportSpec{ This: m.Reference(), OvfDescriptor: ovfDescriptor, ResourcePool: resourcePool.Reference(), Datastore: datastore.Reference(), Cisp: cisp, } res, err := methods.CreateImportSpec(ctx, m.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
[ "func", "(", "m", "*", "Manager", ")", "CreateImportSpec", "(", "ctx", "context", ".", "Context", ",", "ovfDescriptor", "string", ",", "resourcePool", "mo", ".", "Reference", ",", "datastore", "mo", ".", "Reference", ",", "cisp", "types", ".", "OvfCreateImportSpecParams", ")", "(", "*", "types", ".", "OvfCreateImportSpecResult", ",", "error", ")", "{", "req", ":=", "types", ".", "CreateImportSpec", "{", "This", ":", "m", ".", "Reference", "(", ")", ",", "OvfDescriptor", ":", "ovfDescriptor", ",", "ResourcePool", ":", "resourcePool", ".", "Reference", "(", ")", ",", "Datastore", ":", "datastore", ".", "Reference", "(", ")", ",", "Cisp", ":", "cisp", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "CreateImportSpec", "(", "ctx", ",", "m", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// CreateImportSpec wraps methods.CreateImportSpec
[ "CreateImportSpec", "wraps", "methods", ".", "CreateImportSpec" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/ovf/manager.go#L55-L70
train
vmware/govmomi
ovf/manager.go
ParseDescriptor
func (m *Manager) ParseDescriptor(ctx context.Context, ovfDescriptor string, pdp types.OvfParseDescriptorParams) (*types.OvfParseDescriptorResult, error) { req := types.ParseDescriptor{ This: m.Reference(), OvfDescriptor: ovfDescriptor, Pdp: pdp, } res, err := methods.ParseDescriptor(ctx, m.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
go
func (m *Manager) ParseDescriptor(ctx context.Context, ovfDescriptor string, pdp types.OvfParseDescriptorParams) (*types.OvfParseDescriptorResult, error) { req := types.ParseDescriptor{ This: m.Reference(), OvfDescriptor: ovfDescriptor, Pdp: pdp, } res, err := methods.ParseDescriptor(ctx, m.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
[ "func", "(", "m", "*", "Manager", ")", "ParseDescriptor", "(", "ctx", "context", ".", "Context", ",", "ovfDescriptor", "string", ",", "pdp", "types", ".", "OvfParseDescriptorParams", ")", "(", "*", "types", ".", "OvfParseDescriptorResult", ",", "error", ")", "{", "req", ":=", "types", ".", "ParseDescriptor", "{", "This", ":", "m", ".", "Reference", "(", ")", ",", "OvfDescriptor", ":", "ovfDescriptor", ",", "Pdp", ":", "pdp", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "ParseDescriptor", "(", "ctx", ",", "m", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// ParseDescriptor wraps methods.ParseDescriptor
[ "ParseDescriptor", "wraps", "methods", ".", "ParseDescriptor" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/ovf/manager.go#L73-L86
train
vmware/govmomi
ovf/manager.go
ValidateHost
func (m *Manager) ValidateHost(ctx context.Context, ovfDescriptor string, host mo.Reference, vhp types.OvfValidateHostParams) (*types.OvfValidateHostResult, error) { req := types.ValidateHost{ This: m.Reference(), OvfDescriptor: ovfDescriptor, Host: host.Reference(), Vhp: vhp, } res, err := methods.ValidateHost(ctx, m.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
go
func (m *Manager) ValidateHost(ctx context.Context, ovfDescriptor string, host mo.Reference, vhp types.OvfValidateHostParams) (*types.OvfValidateHostResult, error) { req := types.ValidateHost{ This: m.Reference(), OvfDescriptor: ovfDescriptor, Host: host.Reference(), Vhp: vhp, } res, err := methods.ValidateHost(ctx, m.c, &req) if err != nil { return nil, err } return &res.Returnval, nil }
[ "func", "(", "m", "*", "Manager", ")", "ValidateHost", "(", "ctx", "context", ".", "Context", ",", "ovfDescriptor", "string", ",", "host", "mo", ".", "Reference", ",", "vhp", "types", ".", "OvfValidateHostParams", ")", "(", "*", "types", ".", "OvfValidateHostResult", ",", "error", ")", "{", "req", ":=", "types", ".", "ValidateHost", "{", "This", ":", "m", ".", "Reference", "(", ")", ",", "OvfDescriptor", ":", "ovfDescriptor", ",", "Host", ":", "host", ".", "Reference", "(", ")", ",", "Vhp", ":", "vhp", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "ValidateHost", "(", "ctx", ",", "m", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "&", "res", ".", "Returnval", ",", "nil", "\n", "}" ]
// ValidateHost wraps methods.ValidateHost
[ "ValidateHost", "wraps", "methods", ".", "ValidateHost" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/ovf/manager.go#L89-L103
train
vmware/govmomi
vapi/library/library_item.go
CreateLibraryItem
func (c *Manager) CreateLibraryItem(ctx context.Context, item Item) (string, error) { type createItemSpec struct { Name string `json:"name"` Description string `json:"description"` LibraryID string `json:"library_id,omitempty"` Type string `json:"type"` } spec := struct { Item createItemSpec `json:"create_spec"` }{ Item: createItemSpec{ Name: item.Name, Description: item.Description, LibraryID: item.LibraryID, Type: item.Type, }, } url := internal.URL(c, internal.LibraryItemPath) var res string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
go
func (c *Manager) CreateLibraryItem(ctx context.Context, item Item) (string, error) { type createItemSpec struct { Name string `json:"name"` Description string `json:"description"` LibraryID string `json:"library_id,omitempty"` Type string `json:"type"` } spec := struct { Item createItemSpec `json:"create_spec"` }{ Item: createItemSpec{ Name: item.Name, Description: item.Description, LibraryID: item.LibraryID, Type: item.Type, }, } url := internal.URL(c, internal.LibraryItemPath) var res string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
[ "func", "(", "c", "*", "Manager", ")", "CreateLibraryItem", "(", "ctx", "context", ".", "Context", ",", "item", "Item", ")", "(", "string", ",", "error", ")", "{", "type", "createItemSpec", "struct", "{", "Name", "string", "`json:\"name\"`", "\n", "Description", "string", "`json:\"description\"`", "\n", "LibraryID", "string", "`json:\"library_id,omitempty\"`", "\n", "Type", "string", "`json:\"type\"`", "\n", "}", "\n", "spec", ":=", "struct", "{", "Item", "createItemSpec", "`json:\"create_spec\"`", "\n", "}", "{", "Item", ":", "createItemSpec", "{", "Name", ":", "item", ".", "Name", ",", "Description", ":", "item", ".", "Description", ",", "LibraryID", ":", "item", ".", "LibraryID", ",", "Type", ":", "item", ".", "Type", ",", "}", ",", "}", "\n", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LibraryItemPath", ")", "\n", "var", "res", "string", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "spec", ")", ",", "&", "res", ")", "\n", "}" ]
// CreateLibraryItem creates a new library item
[ "CreateLibraryItem", "creates", "a", "new", "library", "item" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item.go#L62-L82
train
vmware/govmomi
vapi/library/library_item.go
DeleteLibraryItem
func (c *Manager) DeleteLibraryItem(ctx context.Context, item *Item) error { url := internal.URL(c, internal.LibraryItemPath).WithID(item.ID) return c.Do(ctx, url.Request(http.MethodDelete), nil) }
go
func (c *Manager) DeleteLibraryItem(ctx context.Context, item *Item) error { url := internal.URL(c, internal.LibraryItemPath).WithID(item.ID) return c.Do(ctx, url.Request(http.MethodDelete), nil) }
[ "func", "(", "c", "*", "Manager", ")", "DeleteLibraryItem", "(", "ctx", "context", ".", "Context", ",", "item", "*", "Item", ")", "error", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LibraryItemPath", ")", ".", "WithID", "(", "item", ".", "ID", ")", "\n", "return", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodDelete", ")", ",", "nil", ")", "\n", "}" ]
// DeleteLibraryItem deletes an existing library item.
[ "DeleteLibraryItem", "deletes", "an", "existing", "library", "item", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item.go#L85-L88
train
vmware/govmomi
vapi/library/library_item.go
ListLibraryItems
func (c *Manager) ListLibraryItems(ctx context.Context, id string) ([]string, error) { url := internal.URL(c, internal.LibraryItemPath).WithParameter("library_id", id) var res []string return res, c.Do(ctx, url.Request(http.MethodGet), &res) }
go
func (c *Manager) ListLibraryItems(ctx context.Context, id string) ([]string, error) { url := internal.URL(c, internal.LibraryItemPath).WithParameter("library_id", id) var res []string return res, c.Do(ctx, url.Request(http.MethodGet), &res) }
[ "func", "(", "c", "*", "Manager", ")", "ListLibraryItems", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LibraryItemPath", ")", ".", "WithParameter", "(", "\"library_id\"", ",", "id", ")", "\n", "var", "res", "[", "]", "string", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodGet", ")", ",", "&", "res", ")", "\n", "}" ]
// ListLibraryItems returns a list of all items in a content library.
[ "ListLibraryItems", "returns", "a", "list", "of", "all", "items", "in", "a", "content", "library", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item.go#L91-L95
train
vmware/govmomi
vapi/library/library_item.go
GetLibraryItem
func (c *Manager) GetLibraryItem(ctx context.Context, id string) (*Item, error) { url := internal.URL(c, internal.LibraryItemPath).WithID(id) var res Item return &res, c.Do(ctx, url.Request(http.MethodGet), &res) }
go
func (c *Manager) GetLibraryItem(ctx context.Context, id string) (*Item, error) { url := internal.URL(c, internal.LibraryItemPath).WithID(id) var res Item return &res, c.Do(ctx, url.Request(http.MethodGet), &res) }
[ "func", "(", "c", "*", "Manager", ")", "GetLibraryItem", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "(", "*", "Item", ",", "error", ")", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LibraryItemPath", ")", ".", "WithID", "(", "id", ")", "\n", "var", "res", "Item", "\n", "return", "&", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodGet", ")", ",", "&", "res", ")", "\n", "}" ]
// GetLibraryItem returns information on a library item for the given ID.
[ "GetLibraryItem", "returns", "information", "on", "a", "library", "item", "for", "the", "given", "ID", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item.go#L98-L102
train
vmware/govmomi
vapi/library/library_item.go
GetLibraryItems
func (c *Manager) GetLibraryItems(ctx context.Context, libraryID string) ([]Item, error) { ids, err := c.ListLibraryItems(ctx, libraryID) if err != nil { return nil, fmt.Errorf("get library items failed for: %s", err) } var items []Item for _, id := range ids { item, err := c.GetLibraryItem(ctx, id) if err != nil { return nil, fmt.Errorf("get library item for %s failed for %s", id, err) } items = append(items, *item) } return items, nil }
go
func (c *Manager) GetLibraryItems(ctx context.Context, libraryID string) ([]Item, error) { ids, err := c.ListLibraryItems(ctx, libraryID) if err != nil { return nil, fmt.Errorf("get library items failed for: %s", err) } var items []Item for _, id := range ids { item, err := c.GetLibraryItem(ctx, id) if err != nil { return nil, fmt.Errorf("get library item for %s failed for %s", id, err) } items = append(items, *item) } return items, nil }
[ "func", "(", "c", "*", "Manager", ")", "GetLibraryItems", "(", "ctx", "context", ".", "Context", ",", "libraryID", "string", ")", "(", "[", "]", "Item", ",", "error", ")", "{", "ids", ",", "err", ":=", "c", ".", "ListLibraryItems", "(", "ctx", ",", "libraryID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"get library items failed for: %s\"", ",", "err", ")", "\n", "}", "\n", "var", "items", "[", "]", "Item", "\n", "for", "_", ",", "id", ":=", "range", "ids", "{", "item", ",", "err", ":=", "c", ".", "GetLibraryItem", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"get library item for %s failed for %s\"", ",", "id", ",", "err", ")", "\n", "}", "\n", "items", "=", "append", "(", "items", ",", "*", "item", ")", "\n", "}", "\n", "return", "items", ",", "nil", "\n", "}" ]
// GetLibraryItems returns a list of all the library items for the specified library.
[ "GetLibraryItems", "returns", "a", "list", "of", "all", "the", "library", "items", "for", "the", "specified", "library", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item.go#L105-L119
train
vmware/govmomi
vapi/library/library_item.go
FindLibraryItems
func (c *Manager) FindLibraryItems( ctx context.Context, search FindItem) ([]string, error) { url := internal.URL(c, internal.LibraryItemPath).WithAction("find") spec := struct { Spec FindItem `json:"spec"` }{search} var res []string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
go
func (c *Manager) FindLibraryItems( ctx context.Context, search FindItem) ([]string, error) { url := internal.URL(c, internal.LibraryItemPath).WithAction("find") spec := struct { Spec FindItem `json:"spec"` }{search} var res []string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
[ "func", "(", "c", "*", "Manager", ")", "FindLibraryItems", "(", "ctx", "context", ".", "Context", ",", "search", "FindItem", ")", "(", "[", "]", "string", ",", "error", ")", "{", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "LibraryItemPath", ")", ".", "WithAction", "(", "\"find\"", ")", "\n", "spec", ":=", "struct", "{", "Spec", "FindItem", "`json:\"spec\"`", "\n", "}", "{", "search", "}", "\n", "var", "res", "[", "]", "string", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "spec", ")", ",", "&", "res", ")", "\n", "}" ]
// FindLibraryItems returns the IDs of all the library items that match the // search criteria.
[ "FindLibraryItems", "returns", "the", "IDs", "of", "all", "the", "library", "items", "that", "match", "the", "search", "criteria", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item.go#L132-L141
train
vmware/govmomi
govc/host/esxcli/firewall_info.go
GetFirewallInfo
func GetFirewallInfo(s *object.HostSystem) (*FirewallInfo, error) { x, err := NewExecutor(s.Client(), s) if err != nil { return nil, err } res, err := x.Run([]string{"network", "firewall", "get"}) if err != nil { return nil, err } info := &FirewallInfo{ Loaded: res.Values[0]["Loaded"][0] == "true", Enabled: res.Values[0]["Enabled"][0] == "true", DefaultAction: res.Values[0]["DefaultAction"][0], } return info, nil }
go
func GetFirewallInfo(s *object.HostSystem) (*FirewallInfo, error) { x, err := NewExecutor(s.Client(), s) if err != nil { return nil, err } res, err := x.Run([]string{"network", "firewall", "get"}) if err != nil { return nil, err } info := &FirewallInfo{ Loaded: res.Values[0]["Loaded"][0] == "true", Enabled: res.Values[0]["Enabled"][0] == "true", DefaultAction: res.Values[0]["DefaultAction"][0], } return info, nil }
[ "func", "GetFirewallInfo", "(", "s", "*", "object", ".", "HostSystem", ")", "(", "*", "FirewallInfo", ",", "error", ")", "{", "x", ",", "err", ":=", "NewExecutor", "(", "s", ".", "Client", "(", ")", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "res", ",", "err", ":=", "x", ".", "Run", "(", "[", "]", "string", "{", "\"network\"", ",", "\"firewall\"", ",", "\"get\"", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "info", ":=", "&", "FirewallInfo", "{", "Loaded", ":", "res", ".", "Values", "[", "0", "]", "[", "\"Loaded\"", "]", "[", "0", "]", "==", "\"true\"", ",", "Enabled", ":", "res", ".", "Values", "[", "0", "]", "[", "\"Enabled\"", "]", "[", "0", "]", "==", "\"true\"", ",", "DefaultAction", ":", "res", ".", "Values", "[", "0", "]", "[", "\"DefaultAction\"", "]", "[", "0", "]", ",", "}", "\n", "return", "info", ",", "nil", "\n", "}" ]
// GetFirewallInfo via 'esxcli network firewall get' // The HostFirewallSystem type does not expose this data. // This helper can be useful in particular to determine if the firewall is enabled or disabled.
[ "GetFirewallInfo", "via", "esxcli", "network", "firewall", "get", "The", "HostFirewallSystem", "type", "does", "not", "expose", "this", "data", ".", "This", "helper", "can", "be", "useful", "in", "particular", "to", "determine", "if", "the", "firewall", "is", "enabled", "or", "disabled", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/host/esxcli/firewall_info.go#L30-L48
train
vmware/govmomi
session/keep_alive.go
KeepAlive
func KeepAlive(roundTripper soap.RoundTripper, idleTime time.Duration) soap.RoundTripper { return KeepAliveHandler(roundTripper, idleTime, defaultKeepAlive) }
go
func KeepAlive(roundTripper soap.RoundTripper, idleTime time.Duration) soap.RoundTripper { return KeepAliveHandler(roundTripper, idleTime, defaultKeepAlive) }
[ "func", "KeepAlive", "(", "roundTripper", "soap", ".", "RoundTripper", ",", "idleTime", "time", ".", "Duration", ")", "soap", ".", "RoundTripper", "{", "return", "KeepAliveHandler", "(", "roundTripper", ",", "idleTime", ",", "defaultKeepAlive", ")", "\n", "}" ]
// KeepAlive wraps the specified soap.RoundTripper and executes a meaningless // API request in the background after the RoundTripper has been idle for the // specified amount of idle time. The keep alive process only starts once a // user logs in and runs until the user logs out again.
[ "KeepAlive", "wraps", "the", "specified", "soap", ".", "RoundTripper", "and", "executes", "a", "meaningless", "API", "request", "in", "the", "background", "after", "the", "RoundTripper", "has", "been", "idle", "for", "the", "specified", "amount", "of", "idle", "time", ".", "The", "keep", "alive", "process", "only", "starts", "once", "a", "user", "logs", "in", "and", "runs", "until", "the", "user", "logs", "out", "again", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/session/keep_alive.go#L51-L53
train
vmware/govmomi
vapi/tags/tag_association.go
AttachTag
func (c *Manager) AttachTag(ctx context.Context, tagID string, ref mo.Reference) error { id, err := c.tagID(ctx, tagID) if err != nil { return err } spec := internal.NewAssociation(ref) url := internal.URL(c, internal.AssociationPath).WithID(id).WithAction("attach") return c.Do(ctx, url.Request(http.MethodPost, spec), nil) }
go
func (c *Manager) AttachTag(ctx context.Context, tagID string, ref mo.Reference) error { id, err := c.tagID(ctx, tagID) if err != nil { return err } spec := internal.NewAssociation(ref) url := internal.URL(c, internal.AssociationPath).WithID(id).WithAction("attach") return c.Do(ctx, url.Request(http.MethodPost, spec), nil) }
[ "func", "(", "c", "*", "Manager", ")", "AttachTag", "(", "ctx", "context", ".", "Context", ",", "tagID", "string", ",", "ref", "mo", ".", "Reference", ")", "error", "{", "id", ",", "err", ":=", "c", ".", "tagID", "(", "ctx", ",", "tagID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "spec", ":=", "internal", ".", "NewAssociation", "(", "ref", ")", "\n", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "AssociationPath", ")", ".", "WithID", "(", "id", ")", ".", "WithAction", "(", "\"attach\"", ")", "\n", "return", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "spec", ")", ",", "nil", ")", "\n", "}" ]
// AttachTag attaches a tag ID to a managed object.
[ "AttachTag", "attaches", "a", "tag", "ID", "to", "a", "managed", "object", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tag_association.go#L40-L48
train
vmware/govmomi
vapi/tags/tag_association.go
ListAttachedTags
func (c *Manager) ListAttachedTags(ctx context.Context, ref mo.Reference) ([]string, error) { spec := internal.NewAssociation(ref) url := internal.URL(c, internal.AssociationPath).WithAction("list-attached-tags") var res []string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
go
func (c *Manager) ListAttachedTags(ctx context.Context, ref mo.Reference) ([]string, error) { spec := internal.NewAssociation(ref) url := internal.URL(c, internal.AssociationPath).WithAction("list-attached-tags") var res []string return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res) }
[ "func", "(", "c", "*", "Manager", ")", "ListAttachedTags", "(", "ctx", "context", ".", "Context", ",", "ref", "mo", ".", "Reference", ")", "(", "[", "]", "string", ",", "error", ")", "{", "spec", ":=", "internal", ".", "NewAssociation", "(", "ref", ")", "\n", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "AssociationPath", ")", ".", "WithAction", "(", "\"list-attached-tags\"", ")", "\n", "var", "res", "[", "]", "string", "\n", "return", "res", ",", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "spec", ")", ",", "&", "res", ")", "\n", "}" ]
// ListAttachedTags fetches the array of tag IDs attached to the given object.
[ "ListAttachedTags", "fetches", "the", "array", "of", "tag", "IDs", "attached", "to", "the", "given", "object", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tag_association.go#L63-L68
train
vmware/govmomi
vapi/tags/tag_association.go
GetAttachedTags
func (c *Manager) GetAttachedTags(ctx context.Context, ref mo.Reference) ([]Tag, error) { ids, err := c.ListAttachedTags(ctx, ref) if err != nil { return nil, fmt.Errorf("get attached tags %s: %s", ref, err) } var info []Tag for _, id := range ids { tag, err := c.GetTag(ctx, id) if err != nil { return nil, fmt.Errorf("get tag %s: %s", id, err) } info = append(info, *tag) } return info, nil }
go
func (c *Manager) GetAttachedTags(ctx context.Context, ref mo.Reference) ([]Tag, error) { ids, err := c.ListAttachedTags(ctx, ref) if err != nil { return nil, fmt.Errorf("get attached tags %s: %s", ref, err) } var info []Tag for _, id := range ids { tag, err := c.GetTag(ctx, id) if err != nil { return nil, fmt.Errorf("get tag %s: %s", id, err) } info = append(info, *tag) } return info, nil }
[ "func", "(", "c", "*", "Manager", ")", "GetAttachedTags", "(", "ctx", "context", ".", "Context", ",", "ref", "mo", ".", "Reference", ")", "(", "[", "]", "Tag", ",", "error", ")", "{", "ids", ",", "err", ":=", "c", ".", "ListAttachedTags", "(", "ctx", ",", "ref", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"get attached tags %s: %s\"", ",", "ref", ",", "err", ")", "\n", "}", "\n", "var", "info", "[", "]", "Tag", "\n", "for", "_", ",", "id", ":=", "range", "ids", "{", "tag", ",", "err", ":=", "c", ".", "GetTag", "(", "ctx", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"get tag %s: %s\"", ",", "id", ",", "err", ")", "\n", "}", "\n", "info", "=", "append", "(", "info", ",", "*", "tag", ")", "\n", "}", "\n", "return", "info", ",", "nil", "\n", "}" ]
// GetAttachedTags fetches the array of tags attached to the given object.
[ "GetAttachedTags", "fetches", "the", "array", "of", "tags", "attached", "to", "the", "given", "object", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tag_association.go#L71-L86
train
vmware/govmomi
vapi/tags/tag_association.go
ListAttachedObjects
func (c *Manager) ListAttachedObjects(ctx context.Context, tagID string) ([]mo.Reference, error) { id, err := c.tagID(ctx, tagID) if err != nil { return nil, err } url := internal.URL(c, internal.AssociationPath).WithID(id).WithAction("list-attached-objects") var res []internal.AssociatedObject if err := c.Do(ctx, url.Request(http.MethodPost, nil), &res); err != nil { return nil, err } refs := make([]mo.Reference, len(res)) for i := range res { refs[i] = res[i] } return refs, nil }
go
func (c *Manager) ListAttachedObjects(ctx context.Context, tagID string) ([]mo.Reference, error) { id, err := c.tagID(ctx, tagID) if err != nil { return nil, err } url := internal.URL(c, internal.AssociationPath).WithID(id).WithAction("list-attached-objects") var res []internal.AssociatedObject if err := c.Do(ctx, url.Request(http.MethodPost, nil), &res); err != nil { return nil, err } refs := make([]mo.Reference, len(res)) for i := range res { refs[i] = res[i] } return refs, nil }
[ "func", "(", "c", "*", "Manager", ")", "ListAttachedObjects", "(", "ctx", "context", ".", "Context", ",", "tagID", "string", ")", "(", "[", "]", "mo", ".", "Reference", ",", "error", ")", "{", "id", ",", "err", ":=", "c", ".", "tagID", "(", "ctx", ",", "tagID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "url", ":=", "internal", ".", "URL", "(", "c", ",", "internal", ".", "AssociationPath", ")", ".", "WithID", "(", "id", ")", ".", "WithAction", "(", "\"list-attached-objects\"", ")", "\n", "var", "res", "[", "]", "internal", ".", "AssociatedObject", "\n", "if", "err", ":=", "c", ".", "Do", "(", "ctx", ",", "url", ".", "Request", "(", "http", ".", "MethodPost", ",", "nil", ")", ",", "&", "res", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "refs", ":=", "make", "(", "[", "]", "mo", ".", "Reference", ",", "len", "(", "res", ")", ")", "\n", "for", "i", ":=", "range", "res", "{", "refs", "[", "i", "]", "=", "res", "[", "i", "]", "\n", "}", "\n", "return", "refs", ",", "nil", "\n", "}" ]
// ListAttachedObjects fetches the array of attached objects for the given tag ID.
[ "ListAttachedObjects", "fetches", "the", "array", "of", "attached", "objects", "for", "the", "given", "tag", "ID", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tag_association.go#L89-L105
train
vmware/govmomi
toolbox/channel.go
Request
func (c *ChannelOut) Request(request []byte) ([]byte, error) { if err := c.Send(request); err != nil { return nil, err } reply, err := c.Receive() if err != nil { return nil, err } if bytes.HasPrefix(reply, rpciOK) { return reply[2:], nil } return nil, fmt.Errorf("request %q: %q", request, reply) }
go
func (c *ChannelOut) Request(request []byte) ([]byte, error) { if err := c.Send(request); err != nil { return nil, err } reply, err := c.Receive() if err != nil { return nil, err } if bytes.HasPrefix(reply, rpciOK) { return reply[2:], nil } return nil, fmt.Errorf("request %q: %q", request, reply) }
[ "func", "(", "c", "*", "ChannelOut", ")", "Request", "(", "request", "[", "]", "byte", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "err", ":=", "c", ".", "Send", "(", "request", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "reply", ",", "err", ":=", "c", ".", "Receive", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "bytes", ".", "HasPrefix", "(", "reply", ",", "rpciOK", ")", "{", "return", "reply", "[", "2", ":", "]", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"request %q: %q\"", ",", "request", ",", "reply", ")", "\n", "}" ]
// Request sends an RPC command to the vmx and checks the return code for success or error
[ "Request", "sends", "an", "RPC", "command", "to", "the", "vmx", "and", "checks", "the", "return", "code", "for", "success", "or", "error" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/channel.go#L43-L58
train
vmware/govmomi
find/finder.go
datacenterPath
func (f *Finder) datacenterPath(ctx context.Context, ref types.ManagedObjectReference) (string, error) { mes, err := mo.Ancestors(ctx, f.client, f.client.ServiceContent.PropertyCollector, ref) if err != nil { return "", err } // Chop leaves under the Datacenter for i := len(mes) - 1; i > 0; i-- { if mes[i].Self.Type == "Datacenter" { break } mes = mes[:i] } var p string for _, me := range mes { // Skip root entity in building inventory path. if me.Parent == nil { continue } p = p + "/" + me.Name } return p, nil }
go
func (f *Finder) datacenterPath(ctx context.Context, ref types.ManagedObjectReference) (string, error) { mes, err := mo.Ancestors(ctx, f.client, f.client.ServiceContent.PropertyCollector, ref) if err != nil { return "", err } // Chop leaves under the Datacenter for i := len(mes) - 1; i > 0; i-- { if mes[i].Self.Type == "Datacenter" { break } mes = mes[:i] } var p string for _, me := range mes { // Skip root entity in building inventory path. if me.Parent == nil { continue } p = p + "/" + me.Name } return p, nil }
[ "func", "(", "f", "*", "Finder", ")", "datacenterPath", "(", "ctx", "context", ".", "Context", ",", "ref", "types", ".", "ManagedObjectReference", ")", "(", "string", ",", "error", ")", "{", "mes", ",", "err", ":=", "mo", ".", "Ancestors", "(", "ctx", ",", "f", ".", "client", ",", "f", ".", "client", ".", "ServiceContent", ".", "PropertyCollector", ",", "ref", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "for", "i", ":=", "len", "(", "mes", ")", "-", "1", ";", "i", ">", "0", ";", "i", "--", "{", "if", "mes", "[", "i", "]", ".", "Self", ".", "Type", "==", "\"Datacenter\"", "{", "break", "\n", "}", "\n", "mes", "=", "mes", "[", ":", "i", "]", "\n", "}", "\n", "var", "p", "string", "\n", "for", "_", ",", "me", ":=", "range", "mes", "{", "if", "me", ".", "Parent", "==", "nil", "{", "continue", "\n", "}", "\n", "p", "=", "p", "+", "\"/\"", "+", "me", ".", "Name", "\n", "}", "\n", "return", "p", ",", "nil", "\n", "}" ]
// datacenterPath returns the absolute path to the Datacenter containing the given ref
[ "datacenterPath", "returns", "the", "absolute", "path", "to", "the", "Datacenter", "containing", "the", "given", "ref" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/find/finder.go#L152-L178
train
vmware/govmomi
find/finder.go
Element
func (f *Finder) Element(ctx context.Context, ref types.ManagedObjectReference) (*list.Element, error) { rl := func(_ context.Context) (object.Reference, error) { return ref, nil } s := &spec{ Relative: rl, } e, err := f.find(ctx, "./", s) if err != nil { return nil, err } if len(e) == 0 { return nil, &NotFoundError{ref.Type, ref.Value} } if len(e) > 1 { panic("ManagedObjectReference must be unique") } return &e[0], nil }
go
func (f *Finder) Element(ctx context.Context, ref types.ManagedObjectReference) (*list.Element, error) { rl := func(_ context.Context) (object.Reference, error) { return ref, nil } s := &spec{ Relative: rl, } e, err := f.find(ctx, "./", s) if err != nil { return nil, err } if len(e) == 0 { return nil, &NotFoundError{ref.Type, ref.Value} } if len(e) > 1 { panic("ManagedObjectReference must be unique") } return &e[0], nil }
[ "func", "(", "f", "*", "Finder", ")", "Element", "(", "ctx", "context", ".", "Context", ",", "ref", "types", ".", "ManagedObjectReference", ")", "(", "*", "list", ".", "Element", ",", "error", ")", "{", "rl", ":=", "func", "(", "_", "context", ".", "Context", ")", "(", "object", ".", "Reference", ",", "error", ")", "{", "return", "ref", ",", "nil", "\n", "}", "\n", "s", ":=", "&", "spec", "{", "Relative", ":", "rl", ",", "}", "\n", "e", ",", "err", ":=", "f", ".", "find", "(", "ctx", ",", "\"./\"", ",", "s", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "if", "len", "(", "e", ")", "==", "0", "{", "return", "nil", ",", "&", "NotFoundError", "{", "ref", ".", "Type", ",", "ref", ".", "Value", "}", "\n", "}", "\n", "if", "len", "(", "e", ")", ">", "1", "{", "panic", "(", "\"ManagedObjectReference must be unique\"", ")", "\n", "}", "\n", "return", "&", "e", "[", "0", "]", ",", "nil", "\n", "}" ]
// Element returns an Element for the given ManagedObjectReference // This method is only useful for looking up the InventoryPath of a ManagedObjectReference.
[ "Element", "returns", "an", "Element", "for", "the", "given", "ManagedObjectReference", "This", "method", "is", "only", "useful", "for", "looking", "up", "the", "InventoryPath", "of", "a", "ManagedObjectReference", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/find/finder.go#L276-L299
train
vmware/govmomi
find/finder.go
ObjectReference
func (f *Finder) ObjectReference(ctx context.Context, ref types.ManagedObjectReference) (object.Reference, error) { e, err := f.Element(ctx, ref) if err != nil { return nil, err } r := object.NewReference(f.client, ref) type common interface { SetInventoryPath(string) } r.(common).SetInventoryPath(e.Path) if f.dc != nil { if ds, ok := r.(*object.Datastore); ok { ds.DatacenterPath = f.dc.InventoryPath } } return r, nil }
go
func (f *Finder) ObjectReference(ctx context.Context, ref types.ManagedObjectReference) (object.Reference, error) { e, err := f.Element(ctx, ref) if err != nil { return nil, err } r := object.NewReference(f.client, ref) type common interface { SetInventoryPath(string) } r.(common).SetInventoryPath(e.Path) if f.dc != nil { if ds, ok := r.(*object.Datastore); ok { ds.DatacenterPath = f.dc.InventoryPath } } return r, nil }
[ "func", "(", "f", "*", "Finder", ")", "ObjectReference", "(", "ctx", "context", ".", "Context", ",", "ref", "types", ".", "ManagedObjectReference", ")", "(", "object", ".", "Reference", ",", "error", ")", "{", "e", ",", "err", ":=", "f", ".", "Element", "(", "ctx", ",", "ref", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "r", ":=", "object", ".", "NewReference", "(", "f", ".", "client", ",", "ref", ")", "\n", "type", "common", "interface", "{", "SetInventoryPath", "(", "string", ")", "\n", "}", "\n", "r", ".", "(", "common", ")", ".", "SetInventoryPath", "(", "e", ".", "Path", ")", "\n", "if", "f", ".", "dc", "!=", "nil", "{", "if", "ds", ",", "ok", ":=", "r", ".", "(", "*", "object", ".", "Datastore", ")", ";", "ok", "{", "ds", ".", "DatacenterPath", "=", "f", ".", "dc", ".", "InventoryPath", "\n", "}", "\n", "}", "\n", "return", "r", ",", "nil", "\n", "}" ]
// ObjectReference converts the given ManagedObjectReference to a type from the object package via object.NewReference // with the object.Common.InventoryPath field set.
[ "ObjectReference", "converts", "the", "given", "ManagedObjectReference", "to", "a", "type", "from", "the", "object", "package", "via", "object", ".", "NewReference", "with", "the", "object", ".", "Common", ".", "InventoryPath", "field", "set", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/find/finder.go#L303-L324
train
vmware/govmomi
find/finder.go
ResourcePoolListAll
func (f *Finder) ResourcePoolListAll(ctx context.Context, path string) ([]*object.ResourcePool, error) { pools, err := f.ResourcePoolList(ctx, path) if err != nil { if _, ok := err.(*NotFoundError); !ok { return nil, err } vapps, _ := f.VirtualAppList(ctx, path) if len(vapps) == 0 { return nil, err } for _, vapp := range vapps { pools = append(pools, vapp.ResourcePool) } } return pools, nil }
go
func (f *Finder) ResourcePoolListAll(ctx context.Context, path string) ([]*object.ResourcePool, error) { pools, err := f.ResourcePoolList(ctx, path) if err != nil { if _, ok := err.(*NotFoundError); !ok { return nil, err } vapps, _ := f.VirtualAppList(ctx, path) if len(vapps) == 0 { return nil, err } for _, vapp := range vapps { pools = append(pools, vapp.ResourcePool) } } return pools, nil }
[ "func", "(", "f", "*", "Finder", ")", "ResourcePoolListAll", "(", "ctx", "context", ".", "Context", ",", "path", "string", ")", "(", "[", "]", "*", "object", ".", "ResourcePool", ",", "error", ")", "{", "pools", ",", "err", ":=", "f", ".", "ResourcePoolList", "(", "ctx", ",", "path", ")", "\n", "if", "err", "!=", "nil", "{", "if", "_", ",", "ok", ":=", "err", ".", "(", "*", "NotFoundError", ")", ";", "!", "ok", "{", "return", "nil", ",", "err", "\n", "}", "\n", "vapps", ",", "_", ":=", "f", ".", "VirtualAppList", "(", "ctx", ",", "path", ")", "\n", "if", "len", "(", "vapps", ")", "==", "0", "{", "return", "nil", ",", "err", "\n", "}", "\n", "for", "_", ",", "vapp", ":=", "range", "vapps", "{", "pools", "=", "append", "(", "pools", ",", "vapp", ".", "ResourcePool", ")", "\n", "}", "\n", "}", "\n", "return", "pools", ",", "nil", "\n", "}" ]
// ResourcePoolListAll combines ResourcePoolList and VirtualAppList // VirtualAppList is only called if ResourcePoolList does not find any pools with the given path.
[ "ResourcePoolListAll", "combines", "ResourcePoolList", "and", "VirtualAppList", "VirtualAppList", "is", "only", "called", "if", "ResourcePoolList", "does", "not", "find", "any", "pools", "with", "the", "given", "path", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/find/finder.go#L881-L900
train
vmware/govmomi
vim25/xml/marshal.go
MarshalIndent
func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { var b bytes.Buffer enc := NewEncoder(&b) enc.Indent(prefix, indent) if err := enc.Encode(v); err != nil { return nil, err } return b.Bytes(), nil }
go
func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { var b bytes.Buffer enc := NewEncoder(&b) enc.Indent(prefix, indent) if err := enc.Encode(v); err != nil { return nil, err } return b.Bytes(), nil }
[ "func", "MarshalIndent", "(", "v", "interface", "{", "}", ",", "prefix", ",", "indent", "string", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "var", "b", "bytes", ".", "Buffer", "\n", "enc", ":=", "NewEncoder", "(", "&", "b", ")", "\n", "enc", ".", "Indent", "(", "prefix", ",", "indent", ")", "\n", "if", "err", ":=", "enc", ".", "Encode", "(", "v", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "b", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// MarshalIndent works like Marshal, but each XML element begins on a new // indented line that starts with prefix and is followed by one or more // copies of indent according to the nesting depth.
[ "MarshalIndent", "works", "like", "Marshal", "but", "each", "XML", "element", "begins", "on", "a", "new", "indented", "line", "that", "starts", "with", "prefix", "and", "is", "followed", "by", "one", "or", "more", "copies", "of", "indent", "according", "to", "the", "nesting", "depth", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L116-L124
train
vmware/govmomi
vim25/xml/marshal.go
Indent
func (enc *Encoder) Indent(prefix, indent string) { enc.p.prefix = prefix enc.p.indent = indent }
go
func (enc *Encoder) Indent(prefix, indent string) { enc.p.prefix = prefix enc.p.indent = indent }
[ "func", "(", "enc", "*", "Encoder", ")", "Indent", "(", "prefix", ",", "indent", "string", ")", "{", "enc", ".", "p", ".", "prefix", "=", "prefix", "\n", "enc", ".", "p", ".", "indent", "=", "indent", "\n", "}" ]
// Indent sets the encoder to generate XML in which each element // begins on a new indented line that starts with prefix and is followed by // one or more copies of indent according to the nesting depth.
[ "Indent", "sets", "the", "encoder", "to", "generate", "XML", "in", "which", "each", "element", "begins", "on", "a", "new", "indented", "line", "that", "starts", "with", "prefix", "and", "is", "followed", "by", "one", "or", "more", "copies", "of", "indent", "according", "to", "the", "nesting", "depth", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L141-L144
train
vmware/govmomi
vim25/xml/marshal.go
Encode
func (enc *Encoder) Encode(v interface{}) error { err := enc.p.marshalValue(reflect.ValueOf(v), nil, nil) if err != nil { return err } return enc.p.Flush() }
go
func (enc *Encoder) Encode(v interface{}) error { err := enc.p.marshalValue(reflect.ValueOf(v), nil, nil) if err != nil { return err } return enc.p.Flush() }
[ "func", "(", "enc", "*", "Encoder", ")", "Encode", "(", "v", "interface", "{", "}", ")", "error", "{", "err", ":=", "enc", ".", "p", ".", "marshalValue", "(", "reflect", ".", "ValueOf", "(", "v", ")", ",", "nil", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "enc", ".", "p", ".", "Flush", "(", ")", "\n", "}" ]
// Encode writes the XML encoding of v to the stream. // // See the documentation for Marshal for details about the conversion // of Go values to XML. // // Encode calls Flush before returning.
[ "Encode", "writes", "the", "XML", "encoding", "of", "v", "to", "the", "stream", ".", "See", "the", "documentation", "for", "Marshal", "for", "details", "about", "the", "conversion", "of", "Go", "values", "to", "XML", ".", "Encode", "calls", "Flush", "before", "returning", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L152-L158
train
vmware/govmomi
vim25/xml/marshal.go
EncodeElement
func (enc *Encoder) EncodeElement(v interface{}, start StartElement) error { err := enc.p.marshalValue(reflect.ValueOf(v), nil, &start) if err != nil { return err } return enc.p.Flush() }
go
func (enc *Encoder) EncodeElement(v interface{}, start StartElement) error { err := enc.p.marshalValue(reflect.ValueOf(v), nil, &start) if err != nil { return err } return enc.p.Flush() }
[ "func", "(", "enc", "*", "Encoder", ")", "EncodeElement", "(", "v", "interface", "{", "}", ",", "start", "StartElement", ")", "error", "{", "err", ":=", "enc", ".", "p", ".", "marshalValue", "(", "reflect", ".", "ValueOf", "(", "v", ")", ",", "nil", ",", "&", "start", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "enc", ".", "p", ".", "Flush", "(", ")", "\n", "}" ]
// EncodeElement writes the XML encoding of v to the stream, // using start as the outermost tag in the encoding. // // See the documentation for Marshal for details about the conversion // of Go values to XML. // // EncodeElement calls Flush before returning.
[ "EncodeElement", "writes", "the", "XML", "encoding", "of", "v", "to", "the", "stream", "using", "start", "as", "the", "outermost", "tag", "in", "the", "encoding", ".", "See", "the", "documentation", "for", "Marshal", "for", "details", "about", "the", "conversion", "of", "Go", "values", "to", "XML", ".", "EncodeElement", "calls", "Flush", "before", "returning", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L167-L173
train
vmware/govmomi
vim25/xml/marshal.go
deleteAttrPrefix
func (p *printer) deleteAttrPrefix(prefix string) { delete(p.attrPrefix, p.attrNS[prefix]) delete(p.attrNS, prefix) }
go
func (p *printer) deleteAttrPrefix(prefix string) { delete(p.attrPrefix, p.attrNS[prefix]) delete(p.attrNS, prefix) }
[ "func", "(", "p", "*", "printer", ")", "deleteAttrPrefix", "(", "prefix", "string", ")", "{", "delete", "(", "p", ".", "attrPrefix", ",", "p", ".", "attrNS", "[", "prefix", "]", ")", "\n", "delete", "(", "p", ".", "attrNS", ",", "prefix", ")", "\n", "}" ]
// deleteAttrPrefix removes an attribute name space prefix.
[ "deleteAttrPrefix", "removes", "an", "attribute", "name", "space", "prefix", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L324-L327
train
vmware/govmomi
vim25/xml/marshal.go
defaultStart
func defaultStart(typ reflect.Type, finfo *fieldInfo, startTemplate *StartElement) StartElement { var start StartElement // Precedence for the XML element name is as above, // except that we do not look inside structs for the first field. if startTemplate != nil { start.Name = startTemplate.Name start.Attr = append(start.Attr, startTemplate.Attr...) } else if finfo != nil && finfo.name != "" { start.Name.Local = finfo.name start.Name.Space = finfo.xmlns } else if typ.Name() != "" { start.Name.Local = typ.Name() } else { // Must be a pointer to a named type, // since it has the Marshaler methods. start.Name.Local = typ.Elem().Name() } // Add type attribute if necessary if finfo != nil && finfo.flags&fTypeAttr != 0 { start.Attr = append(start.Attr, Attr{xmlSchemaInstance, typeToString(typ)}) } return start }
go
func defaultStart(typ reflect.Type, finfo *fieldInfo, startTemplate *StartElement) StartElement { var start StartElement // Precedence for the XML element name is as above, // except that we do not look inside structs for the first field. if startTemplate != nil { start.Name = startTemplate.Name start.Attr = append(start.Attr, startTemplate.Attr...) } else if finfo != nil && finfo.name != "" { start.Name.Local = finfo.name start.Name.Space = finfo.xmlns } else if typ.Name() != "" { start.Name.Local = typ.Name() } else { // Must be a pointer to a named type, // since it has the Marshaler methods. start.Name.Local = typ.Elem().Name() } // Add type attribute if necessary if finfo != nil && finfo.flags&fTypeAttr != 0 { start.Attr = append(start.Attr, Attr{xmlSchemaInstance, typeToString(typ)}) } return start }
[ "func", "defaultStart", "(", "typ", "reflect", ".", "Type", ",", "finfo", "*", "fieldInfo", ",", "startTemplate", "*", "StartElement", ")", "StartElement", "{", "var", "start", "StartElement", "\n", "if", "startTemplate", "!=", "nil", "{", "start", ".", "Name", "=", "startTemplate", ".", "Name", "\n", "start", ".", "Attr", "=", "append", "(", "start", ".", "Attr", ",", "startTemplate", ".", "Attr", "...", ")", "\n", "}", "else", "if", "finfo", "!=", "nil", "&&", "finfo", ".", "name", "!=", "\"\"", "{", "start", ".", "Name", ".", "Local", "=", "finfo", ".", "name", "\n", "start", ".", "Name", ".", "Space", "=", "finfo", ".", "xmlns", "\n", "}", "else", "if", "typ", ".", "Name", "(", ")", "!=", "\"\"", "{", "start", ".", "Name", ".", "Local", "=", "typ", ".", "Name", "(", ")", "\n", "}", "else", "{", "start", ".", "Name", ".", "Local", "=", "typ", ".", "Elem", "(", ")", ".", "Name", "(", ")", "\n", "}", "\n", "if", "finfo", "!=", "nil", "&&", "finfo", ".", "flags", "&", "fTypeAttr", "!=", "0", "{", "start", ".", "Attr", "=", "append", "(", "start", ".", "Attr", ",", "Attr", "{", "xmlSchemaInstance", ",", "typeToString", "(", "typ", ")", "}", ")", "\n", "}", "\n", "return", "start", "\n", "}" ]
// defaultStart returns the default start element to use, // given the reflect type, field info, and start template.
[ "defaultStart", "returns", "the", "default", "start", "element", "to", "use", "given", "the", "reflect", "type", "field", "info", "and", "start", "template", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L560-L584
train
vmware/govmomi
vim25/xml/marshal.go
marshalInterface
func (p *printer) marshalInterface(val Marshaler, start StartElement) error { // Push a marker onto the tag stack so that MarshalXML // cannot close the XML tags that it did not open. p.tags = append(p.tags, Name{}) n := len(p.tags) err := val.MarshalXML(p.encoder, start) if err != nil { return err } // Make sure MarshalXML closed all its tags. p.tags[n-1] is the mark. if len(p.tags) > n { return fmt.Errorf("xml: %s.MarshalXML wrote invalid XML: <%s> not closed", receiverType(val), p.tags[len(p.tags)-1].Local) } p.tags = p.tags[:n-1] return nil }
go
func (p *printer) marshalInterface(val Marshaler, start StartElement) error { // Push a marker onto the tag stack so that MarshalXML // cannot close the XML tags that it did not open. p.tags = append(p.tags, Name{}) n := len(p.tags) err := val.MarshalXML(p.encoder, start) if err != nil { return err } // Make sure MarshalXML closed all its tags. p.tags[n-1] is the mark. if len(p.tags) > n { return fmt.Errorf("xml: %s.MarshalXML wrote invalid XML: <%s> not closed", receiverType(val), p.tags[len(p.tags)-1].Local) } p.tags = p.tags[:n-1] return nil }
[ "func", "(", "p", "*", "printer", ")", "marshalInterface", "(", "val", "Marshaler", ",", "start", "StartElement", ")", "error", "{", "p", ".", "tags", "=", "append", "(", "p", ".", "tags", ",", "Name", "{", "}", ")", "\n", "n", ":=", "len", "(", "p", ".", "tags", ")", "\n", "err", ":=", "val", ".", "MarshalXML", "(", "p", ".", "encoder", ",", "start", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "len", "(", "p", ".", "tags", ")", ">", "n", "{", "return", "fmt", ".", "Errorf", "(", "\"xml: %s.MarshalXML wrote invalid XML: <%s> not closed\"", ",", "receiverType", "(", "val", ")", ",", "p", ".", "tags", "[", "len", "(", "p", ".", "tags", ")", "-", "1", "]", ".", "Local", ")", "\n", "}", "\n", "p", ".", "tags", "=", "p", ".", "tags", "[", ":", "n", "-", "1", "]", "\n", "return", "nil", "\n", "}" ]
// marshalInterface marshals a Marshaler interface value.
[ "marshalInterface", "marshals", "a", "Marshaler", "interface", "value", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L587-L604
train
vmware/govmomi
vim25/xml/marshal.go
marshalTextInterface
func (p *printer) marshalTextInterface(val encoding.TextMarshaler, start StartElement) error { if err := p.writeStart(&start); err != nil { return err } text, err := val.MarshalText() if err != nil { return err } EscapeText(p, text) return p.writeEnd(start.Name) }
go
func (p *printer) marshalTextInterface(val encoding.TextMarshaler, start StartElement) error { if err := p.writeStart(&start); err != nil { return err } text, err := val.MarshalText() if err != nil { return err } EscapeText(p, text) return p.writeEnd(start.Name) }
[ "func", "(", "p", "*", "printer", ")", "marshalTextInterface", "(", "val", "encoding", ".", "TextMarshaler", ",", "start", "StartElement", ")", "error", "{", "if", "err", ":=", "p", ".", "writeStart", "(", "&", "start", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "text", ",", "err", ":=", "val", ".", "MarshalText", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "EscapeText", "(", "p", ",", "text", ")", "\n", "return", "p", ".", "writeEnd", "(", "start", ".", "Name", ")", "\n", "}" ]
// marshalTextInterface marshals a TextMarshaler interface value.
[ "marshalTextInterface", "marshals", "a", "TextMarshaler", "interface", "value", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L607-L617
train
vmware/govmomi
vim25/xml/marshal.go
writeStart
func (p *printer) writeStart(start *StartElement) error { if start.Name.Local == "" { return fmt.Errorf("xml: start tag with no name") } p.tags = append(p.tags, start.Name) p.markPrefix() p.writeIndent(1) p.WriteByte('<') p.WriteString(start.Name.Local) if start.Name.Space != "" { p.WriteString(` xmlns="`) p.EscapeString(start.Name.Space) p.WriteByte('"') } // Attributes for _, attr := range start.Attr { name := attr.Name if name.Local == "" { continue } p.WriteByte(' ') if name.Space != "" { p.WriteString(p.createAttrPrefix(name.Space)) p.WriteByte(':') } p.WriteString(name.Local) p.WriteString(`="`) p.EscapeString(attr.Value) p.WriteByte('"') } p.WriteByte('>') return nil }
go
func (p *printer) writeStart(start *StartElement) error { if start.Name.Local == "" { return fmt.Errorf("xml: start tag with no name") } p.tags = append(p.tags, start.Name) p.markPrefix() p.writeIndent(1) p.WriteByte('<') p.WriteString(start.Name.Local) if start.Name.Space != "" { p.WriteString(` xmlns="`) p.EscapeString(start.Name.Space) p.WriteByte('"') } // Attributes for _, attr := range start.Attr { name := attr.Name if name.Local == "" { continue } p.WriteByte(' ') if name.Space != "" { p.WriteString(p.createAttrPrefix(name.Space)) p.WriteByte(':') } p.WriteString(name.Local) p.WriteString(`="`) p.EscapeString(attr.Value) p.WriteByte('"') } p.WriteByte('>') return nil }
[ "func", "(", "p", "*", "printer", ")", "writeStart", "(", "start", "*", "StartElement", ")", "error", "{", "if", "start", ".", "Name", ".", "Local", "==", "\"\"", "{", "return", "fmt", ".", "Errorf", "(", "\"xml: start tag with no name\"", ")", "\n", "}", "\n", "p", ".", "tags", "=", "append", "(", "p", ".", "tags", ",", "start", ".", "Name", ")", "\n", "p", ".", "markPrefix", "(", ")", "\n", "p", ".", "writeIndent", "(", "1", ")", "\n", "p", ".", "WriteByte", "(", "'<'", ")", "\n", "p", ".", "WriteString", "(", "start", ".", "Name", ".", "Local", ")", "\n", "if", "start", ".", "Name", ".", "Space", "!=", "\"\"", "{", "p", ".", "WriteString", "(", "` xmlns=\"`", ")", "\n", "p", ".", "EscapeString", "(", "start", ".", "Name", ".", "Space", ")", "\n", "p", ".", "WriteByte", "(", "'\"'", ")", "\n", "}", "\n", "for", "_", ",", "attr", ":=", "range", "start", ".", "Attr", "{", "name", ":=", "attr", ".", "Name", "\n", "if", "name", ".", "Local", "==", "\"\"", "{", "continue", "\n", "}", "\n", "p", ".", "WriteByte", "(", "' '", ")", "\n", "if", "name", ".", "Space", "!=", "\"\"", "{", "p", ".", "WriteString", "(", "p", ".", "createAttrPrefix", "(", "name", ".", "Space", ")", ")", "\n", "p", ".", "WriteByte", "(", "':'", ")", "\n", "}", "\n", "p", ".", "WriteString", "(", "name", ".", "Local", ")", "\n", "p", ".", "WriteString", "(", "`=\"`", ")", "\n", "p", ".", "EscapeString", "(", "attr", ".", "Value", ")", "\n", "p", ".", "WriteByte", "(", "'\"'", ")", "\n", "}", "\n", "p", ".", "WriteByte", "(", "'>'", ")", "\n", "return", "nil", "\n", "}" ]
// writeStart writes the given start element.
[ "writeStart", "writes", "the", "given", "start", "element", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L620-L656
train
vmware/govmomi
vim25/xml/marshal.go
cachedWriteError
func (p *printer) cachedWriteError() error { _, err := p.Write(nil) return err }
go
func (p *printer) cachedWriteError() error { _, err := p.Write(nil) return err }
[ "func", "(", "p", "*", "printer", ")", "cachedWriteError", "(", ")", "error", "{", "_", ",", "err", ":=", "p", ".", "Write", "(", "nil", ")", "\n", "return", "err", "\n", "}" ]
// return the bufio Writer's cached write error
[ "return", "the", "bufio", "Writer", "s", "cached", "write", "error" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L852-L855
train
vmware/govmomi
vim25/xml/marshal.go
trim
func (s *parentStack) trim(parents []string) error { split := 0 for ; split < len(parents) && split < len(s.stack); split++ { if parents[split] != s.stack[split] { break } } for i := len(s.stack) - 1; i >= split; i-- { if err := s.p.writeEnd(Name{Local: s.stack[i]}); err != nil { return err } } s.stack = parents[:split] return nil }
go
func (s *parentStack) trim(parents []string) error { split := 0 for ; split < len(parents) && split < len(s.stack); split++ { if parents[split] != s.stack[split] { break } } for i := len(s.stack) - 1; i >= split; i-- { if err := s.p.writeEnd(Name{Local: s.stack[i]}); err != nil { return err } } s.stack = parents[:split] return nil }
[ "func", "(", "s", "*", "parentStack", ")", "trim", "(", "parents", "[", "]", "string", ")", "error", "{", "split", ":=", "0", "\n", "for", ";", "split", "<", "len", "(", "parents", ")", "&&", "split", "<", "len", "(", "s", ".", "stack", ")", ";", "split", "++", "{", "if", "parents", "[", "split", "]", "!=", "s", ".", "stack", "[", "split", "]", "{", "break", "\n", "}", "\n", "}", "\n", "for", "i", ":=", "len", "(", "s", ".", "stack", ")", "-", "1", ";", "i", ">=", "split", ";", "i", "--", "{", "if", "err", ":=", "s", ".", "p", ".", "writeEnd", "(", "Name", "{", "Local", ":", "s", ".", "stack", "[", "i", "]", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "s", ".", "stack", "=", "parents", "[", ":", "split", "]", "\n", "return", "nil", "\n", "}" ]
// trim updates the XML context to match the longest common prefix of the stack // and the given parents. A closing tag will be written for every parent // popped. Passing a zero slice or nil will close all the elements.
[ "trim", "updates", "the", "XML", "context", "to", "match", "the", "longest", "common", "prefix", "of", "the", "stack", "and", "the", "given", "parents", ".", "A", "closing", "tag", "will", "be", "written", "for", "every", "parent", "popped", ".", "Passing", "a", "zero", "slice", "or", "nil", "will", "close", "all", "the", "elements", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L896-L910
train
vmware/govmomi
vim25/xml/marshal.go
push
func (s *parentStack) push(parents []string) error { for i := 0; i < len(parents); i++ { if err := s.p.writeStart(&StartElement{Name: Name{Local: parents[i]}}); err != nil { return err } } s.stack = append(s.stack, parents...) return nil }
go
func (s *parentStack) push(parents []string) error { for i := 0; i < len(parents); i++ { if err := s.p.writeStart(&StartElement{Name: Name{Local: parents[i]}}); err != nil { return err } } s.stack = append(s.stack, parents...) return nil }
[ "func", "(", "s", "*", "parentStack", ")", "push", "(", "parents", "[", "]", "string", ")", "error", "{", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "parents", ")", ";", "i", "++", "{", "if", "err", ":=", "s", ".", "p", ".", "writeStart", "(", "&", "StartElement", "{", "Name", ":", "Name", "{", "Local", ":", "parents", "[", "i", "]", "}", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "s", ".", "stack", "=", "append", "(", "s", ".", "stack", ",", "parents", "...", ")", "\n", "return", "nil", "\n", "}" ]
// push adds parent elements to the stack and writes open tags.
[ "push", "adds", "parent", "elements", "to", "the", "stack", "and", "writes", "open", "tags", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/marshal.go#L913-L921
train
vmware/govmomi
govc/object/find.go
rootMatch
func (cmd *find) rootMatch(ctx context.Context, root object.Reference, client *vim25.Client, filter property.Filter) bool { ref := root.Reference() if !cmd.kind.wanted(ref.Type) { return false } if len(filter) == 1 && filter["name"] == "*" { return true } var content []types.ObjectContent pc := property.DefaultCollector(client) _ = pc.RetrieveWithFilter(ctx, []types.ManagedObjectReference{ref}, filter.Keys(), &content, filter) return content != nil }
go
func (cmd *find) rootMatch(ctx context.Context, root object.Reference, client *vim25.Client, filter property.Filter) bool { ref := root.Reference() if !cmd.kind.wanted(ref.Type) { return false } if len(filter) == 1 && filter["name"] == "*" { return true } var content []types.ObjectContent pc := property.DefaultCollector(client) _ = pc.RetrieveWithFilter(ctx, []types.ManagedObjectReference{ref}, filter.Keys(), &content, filter) return content != nil }
[ "func", "(", "cmd", "*", "find", ")", "rootMatch", "(", "ctx", "context", ".", "Context", ",", "root", "object", ".", "Reference", ",", "client", "*", "vim25", ".", "Client", ",", "filter", "property", ".", "Filter", ")", "bool", "{", "ref", ":=", "root", ".", "Reference", "(", ")", "\n", "if", "!", "cmd", ".", "kind", ".", "wanted", "(", "ref", ".", "Type", ")", "{", "return", "false", "\n", "}", "\n", "if", "len", "(", "filter", ")", "==", "1", "&&", "filter", "[", "\"name\"", "]", "==", "\"*\"", "{", "return", "true", "\n", "}", "\n", "var", "content", "[", "]", "types", ".", "ObjectContent", "\n", "pc", ":=", "property", ".", "DefaultCollector", "(", "client", ")", "\n", "_", "=", "pc", ".", "RetrieveWithFilter", "(", "ctx", ",", "[", "]", "types", ".", "ManagedObjectReference", "{", "ref", "}", ",", "filter", ".", "Keys", "(", ")", ",", "&", "content", ",", "filter", ")", "\n", "return", "content", "!=", "nil", "\n", "}" ]
// rootMatch returns true if the root object path should be printed
[ "rootMatch", "returns", "true", "if", "the", "root", "object", "path", "should", "be", "printed" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/object/find.go#L157-L174
train
vmware/govmomi
vslm/object_manager.go
NewObjectManager
func NewObjectManager(client *vim25.Client, ref ...types.ManagedObjectReference) *ObjectManager { mref := *client.ServiceContent.VStorageObjectManager if len(ref) == 1 { mref = ref[0] } m := ObjectManager{ ManagedObjectReference: mref, c: client, isVC: mref.Type == "VcenterVStorageObjectManager", } return &m }
go
func NewObjectManager(client *vim25.Client, ref ...types.ManagedObjectReference) *ObjectManager { mref := *client.ServiceContent.VStorageObjectManager if len(ref) == 1 { mref = ref[0] } m := ObjectManager{ ManagedObjectReference: mref, c: client, isVC: mref.Type == "VcenterVStorageObjectManager", } return &m }
[ "func", "NewObjectManager", "(", "client", "*", "vim25", ".", "Client", ",", "ref", "...", "types", ".", "ManagedObjectReference", ")", "*", "ObjectManager", "{", "mref", ":=", "*", "client", ".", "ServiceContent", ".", "VStorageObjectManager", "\n", "if", "len", "(", "ref", ")", "==", "1", "{", "mref", "=", "ref", "[", "0", "]", "\n", "}", "\n", "m", ":=", "ObjectManager", "{", "ManagedObjectReference", ":", "mref", ",", "c", ":", "client", ",", "isVC", ":", "mref", ".", "Type", "==", "\"VcenterVStorageObjectManager\"", ",", "}", "\n", "return", "&", "m", "\n", "}" ]
// NewObjectManager returns an ObjectManager referencing the VcenterVStorageObjectManager singleton when connected to vCenter or // the HostVStorageObjectManager singleton when connected to an ESX host. The optional ref param can be used to specify a ESX // host instead, when connected to vCenter.
[ "NewObjectManager", "returns", "an", "ObjectManager", "referencing", "the", "VcenterVStorageObjectManager", "singleton", "when", "connected", "to", "vCenter", "or", "the", "HostVStorageObjectManager", "singleton", "when", "connected", "to", "an", "ESX", "host", ".", "The", "optional", "ref", "param", "can", "be", "used", "to", "specify", "a", "ESX", "host", "instead", "when", "connected", "to", "vCenter", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vslm/object_manager.go#L40-L54
train
vmware/govmomi
vslm/object_manager.go
PlaceDisk
func (m ObjectManager) PlaceDisk(ctx context.Context, spec *types.VslmCreateSpec, pool types.ManagedObjectReference) error { backing := spec.BackingSpec.GetVslmCreateSpecBackingSpec() if backing.Datastore.Type != "StoragePod" { return nil } device := &types.VirtualDisk{ VirtualDevice: types.VirtualDevice{ Key: 0, Backing: &types.VirtualDiskFlatVer2BackingInfo{ DiskMode: string(types.VirtualDiskModePersistent), ThinProvisioned: types.NewBool(true), }, UnitNumber: types.NewInt32(0), }, CapacityInKB: spec.CapacityInMB * 1024, } storage := types.StoragePlacementSpec{ Type: string(types.StoragePlacementSpecPlacementTypeCreate), ResourcePool: &pool, PodSelectionSpec: types.StorageDrsPodSelectionSpec{ StoragePod: &backing.Datastore, InitialVmConfig: []types.VmPodConfigForPlacement{ { StoragePod: backing.Datastore, Disk: []types.PodDiskLocator{ { DiskId: device.Key, DiskBackingInfo: device.Backing, }, }, }, }, }, ConfigSpec: &types.VirtualMachineConfigSpec{ Name: spec.Name, DeviceChange: []types.BaseVirtualDeviceConfigSpec{ &types.VirtualDeviceConfigSpec{ Operation: types.VirtualDeviceConfigSpecOperationAdd, FileOperation: types.VirtualDeviceConfigSpecFileOperationCreate, Device: device, }, }, }, } req := types.RecommendDatastores{ This: *m.c.ServiceContent.StorageResourceManager, StorageSpec: storage, } res, err := methods.RecommendDatastores(ctx, m.c, &req) if err != nil { return err } r := res.Returnval.Recommendations if len(r) == 0 { return errors.New("no storage placement recommendations") } backing.Datastore = r[0].Action[0].(*types.StoragePlacementAction).Destination return nil }
go
func (m ObjectManager) PlaceDisk(ctx context.Context, spec *types.VslmCreateSpec, pool types.ManagedObjectReference) error { backing := spec.BackingSpec.GetVslmCreateSpecBackingSpec() if backing.Datastore.Type != "StoragePod" { return nil } device := &types.VirtualDisk{ VirtualDevice: types.VirtualDevice{ Key: 0, Backing: &types.VirtualDiskFlatVer2BackingInfo{ DiskMode: string(types.VirtualDiskModePersistent), ThinProvisioned: types.NewBool(true), }, UnitNumber: types.NewInt32(0), }, CapacityInKB: spec.CapacityInMB * 1024, } storage := types.StoragePlacementSpec{ Type: string(types.StoragePlacementSpecPlacementTypeCreate), ResourcePool: &pool, PodSelectionSpec: types.StorageDrsPodSelectionSpec{ StoragePod: &backing.Datastore, InitialVmConfig: []types.VmPodConfigForPlacement{ { StoragePod: backing.Datastore, Disk: []types.PodDiskLocator{ { DiskId: device.Key, DiskBackingInfo: device.Backing, }, }, }, }, }, ConfigSpec: &types.VirtualMachineConfigSpec{ Name: spec.Name, DeviceChange: []types.BaseVirtualDeviceConfigSpec{ &types.VirtualDeviceConfigSpec{ Operation: types.VirtualDeviceConfigSpecOperationAdd, FileOperation: types.VirtualDeviceConfigSpecFileOperationCreate, Device: device, }, }, }, } req := types.RecommendDatastores{ This: *m.c.ServiceContent.StorageResourceManager, StorageSpec: storage, } res, err := methods.RecommendDatastores(ctx, m.c, &req) if err != nil { return err } r := res.Returnval.Recommendations if len(r) == 0 { return errors.New("no storage placement recommendations") } backing.Datastore = r[0].Action[0].(*types.StoragePlacementAction).Destination return nil }
[ "func", "(", "m", "ObjectManager", ")", "PlaceDisk", "(", "ctx", "context", ".", "Context", ",", "spec", "*", "types", ".", "VslmCreateSpec", ",", "pool", "types", ".", "ManagedObjectReference", ")", "error", "{", "backing", ":=", "spec", ".", "BackingSpec", ".", "GetVslmCreateSpecBackingSpec", "(", ")", "\n", "if", "backing", ".", "Datastore", ".", "Type", "!=", "\"StoragePod\"", "{", "return", "nil", "\n", "}", "\n", "device", ":=", "&", "types", ".", "VirtualDisk", "{", "VirtualDevice", ":", "types", ".", "VirtualDevice", "{", "Key", ":", "0", ",", "Backing", ":", "&", "types", ".", "VirtualDiskFlatVer2BackingInfo", "{", "DiskMode", ":", "string", "(", "types", ".", "VirtualDiskModePersistent", ")", ",", "ThinProvisioned", ":", "types", ".", "NewBool", "(", "true", ")", ",", "}", ",", "UnitNumber", ":", "types", ".", "NewInt32", "(", "0", ")", ",", "}", ",", "CapacityInKB", ":", "spec", ".", "CapacityInMB", "*", "1024", ",", "}", "\n", "storage", ":=", "types", ".", "StoragePlacementSpec", "{", "Type", ":", "string", "(", "types", ".", "StoragePlacementSpecPlacementTypeCreate", ")", ",", "ResourcePool", ":", "&", "pool", ",", "PodSelectionSpec", ":", "types", ".", "StorageDrsPodSelectionSpec", "{", "StoragePod", ":", "&", "backing", ".", "Datastore", ",", "InitialVmConfig", ":", "[", "]", "types", ".", "VmPodConfigForPlacement", "{", "{", "StoragePod", ":", "backing", ".", "Datastore", ",", "Disk", ":", "[", "]", "types", ".", "PodDiskLocator", "{", "{", "DiskId", ":", "device", ".", "Key", ",", "DiskBackingInfo", ":", "device", ".", "Backing", ",", "}", ",", "}", ",", "}", ",", "}", ",", "}", ",", "ConfigSpec", ":", "&", "types", ".", "VirtualMachineConfigSpec", "{", "Name", ":", "spec", ".", "Name", ",", "DeviceChange", ":", "[", "]", "types", ".", "BaseVirtualDeviceConfigSpec", "{", "&", "types", ".", "VirtualDeviceConfigSpec", "{", "Operation", ":", "types", ".", "VirtualDeviceConfigSpecOperationAdd", ",", "FileOperation", ":", "types", ".", "VirtualDeviceConfigSpecFileOperationCreate", ",", "Device", ":", "device", ",", "}", ",", "}", ",", "}", ",", "}", "\n", "req", ":=", "types", ".", "RecommendDatastores", "{", "This", ":", "*", "m", ".", "c", ".", "ServiceContent", ".", "StorageResourceManager", ",", "StorageSpec", ":", "storage", ",", "}", "\n", "res", ",", "err", ":=", "methods", ".", "RecommendDatastores", "(", "ctx", ",", "m", ".", "c", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "r", ":=", "res", ".", "Returnval", ".", "Recommendations", "\n", "if", "len", "(", "r", ")", "==", "0", "{", "return", "errors", ".", "New", "(", "\"no storage placement recommendations\"", ")", "\n", "}", "\n", "backing", ".", "Datastore", "=", "r", "[", "0", "]", ".", "Action", "[", "0", "]", ".", "(", "*", "types", ".", "StoragePlacementAction", ")", ".", "Destination", "\n", "return", "nil", "\n", "}" ]
// PlaceDisk uses StorageResourceManager datastore placement recommendations to choose a Datastore from a Datastore cluster. // If the given spec backing Datastore field is not that of type StoragePod, the spec is unmodifed. // Otherwise, the backing Datastore field is replaced with a Datastore suggestion.
[ "PlaceDisk", "uses", "StorageResourceManager", "datastore", "placement", "recommendations", "to", "choose", "a", "Datastore", "from", "a", "Datastore", "cluster", ".", "If", "the", "given", "spec", "backing", "Datastore", "field", "is", "not", "that", "of", "type", "StoragePod", "the", "spec", "is", "unmodifed", ".", "Otherwise", "the", "backing", "Datastore", "field", "is", "replaced", "with", "a", "Datastore", "suggestion", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vslm/object_manager.go#L59-L124
train
vmware/govmomi
simulator/registry.go
NewRegistry
func NewRegistry() *Registry { r := &Registry{ objects: make(map[types.ManagedObjectReference]mo.Reference), handlers: make(map[types.ManagedObjectReference]RegisterObject), locks: make(map[types.ManagedObjectReference]sync.Locker), Namespace: vim25.Namespace, Path: vim25.Path, } return r }
go
func NewRegistry() *Registry { r := &Registry{ objects: make(map[types.ManagedObjectReference]mo.Reference), handlers: make(map[types.ManagedObjectReference]RegisterObject), locks: make(map[types.ManagedObjectReference]sync.Locker), Namespace: vim25.Namespace, Path: vim25.Path, } return r }
[ "func", "NewRegistry", "(", ")", "*", "Registry", "{", "r", ":=", "&", "Registry", "{", "objects", ":", "make", "(", "map", "[", "types", ".", "ManagedObjectReference", "]", "mo", ".", "Reference", ")", ",", "handlers", ":", "make", "(", "map", "[", "types", ".", "ManagedObjectReference", "]", "RegisterObject", ")", ",", "locks", ":", "make", "(", "map", "[", "types", ".", "ManagedObjectReference", "]", "sync", ".", "Locker", ")", ",", "Namespace", ":", "vim25", ".", "Namespace", ",", "Path", ":", "vim25", ".", "Path", ",", "}", "\n", "return", "r", "\n", "}" ]
// NewRegistry creates a new instances of Registry
[ "NewRegistry", "creates", "a", "new", "instances", "of", "Registry" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L81-L92
train
vmware/govmomi
simulator/registry.go
typeName
func typeName(item mo.Reference) string { return reflect.TypeOf(item).Elem().Name() }
go
func typeName(item mo.Reference) string { return reflect.TypeOf(item).Elem().Name() }
[ "func", "typeName", "(", "item", "mo", ".", "Reference", ")", "string", "{", "return", "reflect", ".", "TypeOf", "(", "item", ")", ".", "Elem", "(", ")", ".", "Name", "(", ")", "\n", "}" ]
// typeName returns the type of the given object.
[ "typeName", "returns", "the", "type", "of", "the", "given", "object", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L104-L106
train
vmware/govmomi
simulator/registry.go
valuePrefix
func valuePrefix(typeName string) string { if v, ok := refValueMap[typeName]; ok { return v } return strings.ToLower(typeName) }
go
func valuePrefix(typeName string) string { if v, ok := refValueMap[typeName]; ok { return v } return strings.ToLower(typeName) }
[ "func", "valuePrefix", "(", "typeName", "string", ")", "string", "{", "if", "v", ",", "ok", ":=", "refValueMap", "[", "typeName", "]", ";", "ok", "{", "return", "v", "\n", "}", "\n", "return", "strings", ".", "ToLower", "(", "typeName", ")", "\n", "}" ]
// valuePrefix returns the value name prefix of a given object
[ "valuePrefix", "returns", "the", "value", "name", "prefix", "of", "a", "given", "object" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L109-L115
train
vmware/govmomi
simulator/registry.go
newReference
func (r *Registry) newReference(item mo.Reference) types.ManagedObjectReference { ref := item.Reference() if ref.Type == "" { ref.Type = typeName(item) } if ref.Value == "" { n := atomic.AddInt64(&r.counter, 1) ref.Value = fmt.Sprintf("%s-%d", valuePrefix(ref.Type), n) } return ref }
go
func (r *Registry) newReference(item mo.Reference) types.ManagedObjectReference { ref := item.Reference() if ref.Type == "" { ref.Type = typeName(item) } if ref.Value == "" { n := atomic.AddInt64(&r.counter, 1) ref.Value = fmt.Sprintf("%s-%d", valuePrefix(ref.Type), n) } return ref }
[ "func", "(", "r", "*", "Registry", ")", "newReference", "(", "item", "mo", ".", "Reference", ")", "types", ".", "ManagedObjectReference", "{", "ref", ":=", "item", ".", "Reference", "(", ")", "\n", "if", "ref", ".", "Type", "==", "\"\"", "{", "ref", ".", "Type", "=", "typeName", "(", "item", ")", "\n", "}", "\n", "if", "ref", ".", "Value", "==", "\"\"", "{", "n", ":=", "atomic", ".", "AddInt64", "(", "&", "r", ".", "counter", ",", "1", ")", "\n", "ref", ".", "Value", "=", "fmt", ".", "Sprintf", "(", "\"%s-%d\"", ",", "valuePrefix", "(", "ref", ".", "Type", ")", ",", "n", ")", "\n", "}", "\n", "return", "ref", "\n", "}" ]
// newReference returns a new MOR, where Type defaults to type of the given item // and Value defaults to a unique id for the given type.
[ "newReference", "returns", "a", "new", "MOR", "where", "Type", "defaults", "to", "type", "of", "the", "given", "item", "and", "Value", "defaults", "to", "a", "unique", "id", "for", "the", "given", "type", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L119-L132
train
vmware/govmomi
simulator/registry.go
AddHandler
func (r *Registry) AddHandler(h RegisterObject) { r.m.Lock() r.handlers[h.Reference()] = h r.m.Unlock() }
go
func (r *Registry) AddHandler(h RegisterObject) { r.m.Lock() r.handlers[h.Reference()] = h r.m.Unlock() }
[ "func", "(", "r", "*", "Registry", ")", "AddHandler", "(", "h", "RegisterObject", ")", "{", "r", ".", "m", ".", "Lock", "(", ")", "\n", "r", ".", "handlers", "[", "h", ".", "Reference", "(", ")", "]", "=", "h", "\n", "r", ".", "m", ".", "Unlock", "(", ")", "\n", "}" ]
// AddHandler adds a RegisterObject handler to the Registry.
[ "AddHandler", "adds", "a", "RegisterObject", "handler", "to", "the", "Registry", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L140-L144
train
vmware/govmomi
simulator/registry.go
PutEntity
func (r *Registry) PutEntity(parent mo.Entity, item mo.Entity) mo.Entity { e := item.Entity() if parent != nil { e.Parent = &parent.Entity().Self } r.Put(item) return item }
go
func (r *Registry) PutEntity(parent mo.Entity, item mo.Entity) mo.Entity { e := item.Entity() if parent != nil { e.Parent = &parent.Entity().Self } r.Put(item) return item }
[ "func", "(", "r", "*", "Registry", ")", "PutEntity", "(", "parent", "mo", ".", "Entity", ",", "item", "mo", ".", "Entity", ")", "mo", ".", "Entity", "{", "e", ":=", "item", ".", "Entity", "(", ")", "\n", "if", "parent", "!=", "nil", "{", "e", ".", "Parent", "=", "&", "parent", ".", "Entity", "(", ")", ".", "Self", "\n", "}", "\n", "r", ".", "Put", "(", "item", ")", "\n", "return", "item", "\n", "}" ]
// PutEntity sets item.Parent to that of parent.Self before adding item to the Registry.
[ "PutEntity", "sets", "item", ".", "Parent", "to", "that", "of", "parent", ".", "Self", "before", "adding", "item", "to", "the", "Registry", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L156-L166
train
vmware/govmomi
simulator/registry.go
Get
func (r *Registry) Get(ref types.ManagedObjectReference) mo.Reference { r.m.Lock() defer r.m.Unlock() return r.objects[ref] }
go
func (r *Registry) Get(ref types.ManagedObjectReference) mo.Reference { r.m.Lock() defer r.m.Unlock() return r.objects[ref] }
[ "func", "(", "r", "*", "Registry", ")", "Get", "(", "ref", "types", ".", "ManagedObjectReference", ")", "mo", ".", "Reference", "{", "r", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "m", ".", "Unlock", "(", ")", "\n", "return", "r", ".", "objects", "[", "ref", "]", "\n", "}" ]
// Get returns the object for the given reference.
[ "Get", "returns", "the", "object", "for", "the", "given", "reference", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L169-L174
train
vmware/govmomi
simulator/registry.go
Any
func (r *Registry) Any(kind string) mo.Entity { r.m.Lock() defer r.m.Unlock() for ref, val := range r.objects { if ref.Type == kind { return val.(mo.Entity) } } return nil }
go
func (r *Registry) Any(kind string) mo.Entity { r.m.Lock() defer r.m.Unlock() for ref, val := range r.objects { if ref.Type == kind { return val.(mo.Entity) } } return nil }
[ "func", "(", "r", "*", "Registry", ")", "Any", "(", "kind", "string", ")", "mo", ".", "Entity", "{", "r", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "m", ".", "Unlock", "(", ")", "\n", "for", "ref", ",", "val", ":=", "range", "r", ".", "objects", "{", "if", "ref", ".", "Type", "==", "kind", "{", "return", "val", ".", "(", "mo", ".", "Entity", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Any returns the first instance of entity type specified by kind.
[ "Any", "returns", "the", "first", "instance", "of", "entity", "type", "specified", "by", "kind", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L177-L188
train
vmware/govmomi
simulator/registry.go
All
func (r *Registry) All(kind string) []mo.Entity { r.m.Lock() defer r.m.Unlock() var entities []mo.Entity for ref, val := range r.objects { if kind == "" || ref.Type == kind { if e, ok := val.(mo.Entity); ok { entities = append(entities, e) } } } return entities }
go
func (r *Registry) All(kind string) []mo.Entity { r.m.Lock() defer r.m.Unlock() var entities []mo.Entity for ref, val := range r.objects { if kind == "" || ref.Type == kind { if e, ok := val.(mo.Entity); ok { entities = append(entities, e) } } } return entities }
[ "func", "(", "r", "*", "Registry", ")", "All", "(", "kind", "string", ")", "[", "]", "mo", ".", "Entity", "{", "r", ".", "m", ".", "Lock", "(", ")", "\n", "defer", "r", ".", "m", ".", "Unlock", "(", ")", "\n", "var", "entities", "[", "]", "mo", ".", "Entity", "\n", "for", "ref", ",", "val", ":=", "range", "r", ".", "objects", "{", "if", "kind", "==", "\"\"", "||", "ref", ".", "Type", "==", "kind", "{", "if", "e", ",", "ok", ":=", "val", ".", "(", "mo", ".", "Entity", ")", ";", "ok", "{", "entities", "=", "append", "(", "entities", ",", "e", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "entities", "\n", "}" ]
// All returns all entities of type specified by kind. // If kind is empty - all entities will be returned.
[ "All", "returns", "all", "entities", "of", "type", "specified", "by", "kind", ".", "If", "kind", "is", "empty", "-", "all", "entities", "will", "be", "returned", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L192-L206
train
vmware/govmomi
simulator/registry.go
applyHandlers
func (r *Registry) applyHandlers(f func(o RegisterObject)) { r.m.Lock() handlers := make([]RegisterObject, 0, len(r.handlers)) for _, handler := range r.handlers { handlers = append(handlers, handler) } r.m.Unlock() for i := range handlers { f(handlers[i]) } }
go
func (r *Registry) applyHandlers(f func(o RegisterObject)) { r.m.Lock() handlers := make([]RegisterObject, 0, len(r.handlers)) for _, handler := range r.handlers { handlers = append(handlers, handler) } r.m.Unlock() for i := range handlers { f(handlers[i]) } }
[ "func", "(", "r", "*", "Registry", ")", "applyHandlers", "(", "f", "func", "(", "o", "RegisterObject", ")", ")", "{", "r", ".", "m", ".", "Lock", "(", ")", "\n", "handlers", ":=", "make", "(", "[", "]", "RegisterObject", ",", "0", ",", "len", "(", "r", ".", "handlers", ")", ")", "\n", "for", "_", ",", "handler", ":=", "range", "r", ".", "handlers", "{", "handlers", "=", "append", "(", "handlers", ",", "handler", ")", "\n", "}", "\n", "r", ".", "m", ".", "Unlock", "(", ")", "\n", "for", "i", ":=", "range", "handlers", "{", "f", "(", "handlers", "[", "i", "]", ")", "\n", "}", "\n", "}" ]
// applyHandlers calls the given func for each r.handlers
[ "applyHandlers", "calls", "the", "given", "func", "for", "each", "r", ".", "handlers" ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L209-L220
train
vmware/govmomi
simulator/registry.go
Put
func (r *Registry) Put(item mo.Reference) mo.Reference { r.m.Lock() ref := item.Reference() if ref.Type == "" || ref.Value == "" { ref = r.newReference(item) r.setReference(item, ref) } if me, ok := item.(mo.Entity); ok { me.Entity().ConfigStatus = types.ManagedEntityStatusGreen me.Entity().OverallStatus = types.ManagedEntityStatusGreen me.Entity().EffectiveRole = []int32{-1} // Admin } r.objects[ref] = item r.m.Unlock() r.applyHandlers(func(o RegisterObject) { o.PutObject(item) }) return item }
go
func (r *Registry) Put(item mo.Reference) mo.Reference { r.m.Lock() ref := item.Reference() if ref.Type == "" || ref.Value == "" { ref = r.newReference(item) r.setReference(item, ref) } if me, ok := item.(mo.Entity); ok { me.Entity().ConfigStatus = types.ManagedEntityStatusGreen me.Entity().OverallStatus = types.ManagedEntityStatusGreen me.Entity().EffectiveRole = []int32{-1} // Admin } r.objects[ref] = item r.m.Unlock() r.applyHandlers(func(o RegisterObject) { o.PutObject(item) }) return item }
[ "func", "(", "r", "*", "Registry", ")", "Put", "(", "item", "mo", ".", "Reference", ")", "mo", ".", "Reference", "{", "r", ".", "m", ".", "Lock", "(", ")", "\n", "ref", ":=", "item", ".", "Reference", "(", ")", "\n", "if", "ref", ".", "Type", "==", "\"\"", "||", "ref", ".", "Value", "==", "\"\"", "{", "ref", "=", "r", ".", "newReference", "(", "item", ")", "\n", "r", ".", "setReference", "(", "item", ",", "ref", ")", "\n", "}", "\n", "if", "me", ",", "ok", ":=", "item", ".", "(", "mo", ".", "Entity", ")", ";", "ok", "{", "me", ".", "Entity", "(", ")", ".", "ConfigStatus", "=", "types", ".", "ManagedEntityStatusGreen", "\n", "me", ".", "Entity", "(", ")", ".", "OverallStatus", "=", "types", ".", "ManagedEntityStatusGreen", "\n", "me", ".", "Entity", "(", ")", ".", "EffectiveRole", "=", "[", "]", "int32", "{", "-", "1", "}", "\n", "}", "\n", "r", ".", "objects", "[", "ref", "]", "=", "item", "\n", "r", ".", "m", ".", "Unlock", "(", ")", "\n", "r", ".", "applyHandlers", "(", "func", "(", "o", "RegisterObject", ")", "{", "o", ".", "PutObject", "(", "item", ")", "\n", "}", ")", "\n", "return", "item", "\n", "}" ]
// Put adds a new object to Registry, generating a ManagedObjectReference if not already set.
[ "Put", "adds", "a", "new", "object", "to", "Registry", "generating", "a", "ManagedObjectReference", "if", "not", "already", "set", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L223-L247
train
vmware/govmomi
simulator/registry.go
Remove
func (r *Registry) Remove(item types.ManagedObjectReference) { r.applyHandlers(func(o RegisterObject) { o.RemoveObject(item) }) r.m.Lock() delete(r.objects, item) delete(r.handlers, item) delete(r.locks, item) r.m.Unlock() }
go
func (r *Registry) Remove(item types.ManagedObjectReference) { r.applyHandlers(func(o RegisterObject) { o.RemoveObject(item) }) r.m.Lock() delete(r.objects, item) delete(r.handlers, item) delete(r.locks, item) r.m.Unlock() }
[ "func", "(", "r", "*", "Registry", ")", "Remove", "(", "item", "types", ".", "ManagedObjectReference", ")", "{", "r", ".", "applyHandlers", "(", "func", "(", "o", "RegisterObject", ")", "{", "o", ".", "RemoveObject", "(", "item", ")", "\n", "}", ")", "\n", "r", ".", "m", ".", "Lock", "(", ")", "\n", "delete", "(", "r", ".", "objects", ",", "item", ")", "\n", "delete", "(", "r", ".", "handlers", ",", "item", ")", "\n", "delete", "(", "r", ".", "locks", ",", "item", ")", "\n", "r", ".", "m", ".", "Unlock", "(", ")", "\n", "}" ]
// Remove removes an object from the Registry.
[ "Remove", "removes", "an", "object", "from", "the", "Registry", "." ]
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L250-L260
train