repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
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",
"{",
"// This one should be auto closed if t doesn't close it.",
"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\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",
"{",
"// TODO: this parsing is somewhat lame and not exact.",
"// It works for all actual cases, though.",
"idx",
":=",
"strings",
".",
"Index",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"if",
"idx",
"==",
"-",
"1",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"v",
":=",
"s",
"[",
"idx",
"+",
"len",
"(",
"\"",
"\"",
")",
":",
"]",
"\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",
":=",
"\"",
"\"",
"\n\n",
"if",
"err",
":=",
"p",
".",
"Properties",
"(",
"ctx",
",",
"p",
".",
"Reference",
"(",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"prop",
"}",
",",
"&",
"dvp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// \"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",
"(",
"\"",
"\"",
",",
"p",
".",
"Reference",
"(",
")",
",",
"prop",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"p",
".",
"Properties",
"(",
"ctx",
",",
"*",
"dvp",
".",
"Config",
".",
"DistributedVirtualSwitch",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"&",
"dvs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"backing",
":=",
"&",
"types",
".",
"VirtualEthernetCardDistributedVirtualPortBackingInfo",
"{",
"Port",
":",
"types",
".",
"DistributedVirtualSwitchPortConnection",
"{",
"PortgroupKey",
":",
"dvp",
".",
"Key",
",",
"SwitchUuid",
":",
"dvs",
".",
"Uuid",
",",
"}",
",",
"}",
"\n\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"AddPortGroup",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"res",
",",
"err",
":=",
"methods",
".",
"AddServiceConsoleVirtualNic",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"AddVirtualSwitch",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"QueryNetworkHint",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"RefreshNetworkSystem",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"RemovePortGroup",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"RemoveVirtualSwitch",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"UpdateConsoleIpRouteConfig",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"res",
",",
"err",
":=",
"methods",
".",
"UpdateNetworkConfig",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"UpdatePhysicalNicLinkSpeed",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"UpdatePortGroup",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"_",
",",
"err",
":=",
"methods",
".",
"UpdateVirtualNic",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\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\n",
"tv",
":=",
"&",
"TaskView",
"{",
"ListView",
":",
"l",
",",
"Watch",
":",
"watch",
",",
"}",
"\n\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",
"{",
"// Using TaskHistoryCollector would be less clunky, but it isn't supported on ESX at all.",
"ref",
":=",
"v",
".",
"Reference",
"(",
")",
"\n",
"filter",
":=",
"new",
"(",
"property",
".",
"WaitFilter",
")",
".",
"Add",
"(",
"ref",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"v",
".",
"TraversalSpec",
"(",
")",
")",
"\n\n",
"if",
"v",
".",
"Watch",
"!=",
"nil",
"{",
"filter",
".",
"Add",
"(",
"*",
"v",
".",
"Watch",
",",
"v",
".",
"Watch",
".",
"Type",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
")",
"\n",
"}",
"\n\n",
"pc",
":=",
"property",
".",
"DefaultCollector",
"(",
"v",
".",
"Client",
"(",
")",
")",
"\n\n",
"completed",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n\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\n",
"for",
"_",
",",
"update",
":=",
"range",
"updates",
"{",
"for",
"_",
",",
"change",
":=",
"range",
"update",
".",
"ChangeSet",
"{",
"if",
"change",
".",
"Name",
"==",
"\"",
"\"",
"{",
"tasks",
"=",
"change",
".",
"Val",
".",
"(",
"types",
".",
"ArrayOfManagedObjectReference",
")",
".",
"ManagedObjectReference",
"\n",
"if",
"len",
"(",
"tasks",
")",
"!=",
"0",
"{",
"reset",
"=",
"func",
"(",
")",
"{",
"_",
"=",
"v",
".",
"Reset",
"(",
"ctx",
",",
"tasks",
")",
"\n\n",
"// Remember any tasks we've reported as complete already,",
"// to avoid reporting multiple times when Reset is triggered.",
"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\n",
"continue",
"\n",
"}",
"\n\n",
"info",
",",
"ok",
":=",
"change",
".",
"Val",
".",
"(",
"types",
".",
"TaskInfo",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"!",
"completed",
"[",
"info",
".",
"Task",
".",
"Value",
"]",
"{",
"infos",
"=",
"append",
"(",
"infos",
",",
"info",
")",
"\n",
"}",
"\n\n",
"if",
"v",
".",
"Follow",
"&&",
"info",
".",
"CompleteTime",
"!=",
"nil",
"{",
"prune",
"=",
"append",
"(",
"prune",
",",
"info",
".",
"Task",
")",
"\n",
"completed",
"[",
"info",
".",
"Task",
".",
"Value",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"infos",
")",
"!=",
"0",
"{",
"f",
"(",
"infos",
")",
"\n",
"}",
"\n\n",
"if",
"reset",
"!=",
"nil",
"{",
"reset",
"(",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"prune",
")",
"!=",
"0",
"{",
"_",
"=",
"v",
".",
"Remove",
"(",
"ctx",
",",
"prune",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"tasks",
")",
"!=",
"0",
"&&",
"len",
"(",
"infos",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\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\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",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"if",
"s",
",",
"ok",
":=",
"ctx",
".",
"Value",
"(",
"signerContext",
"{",
"}",
")",
".",
"(",
"Signer",
")",
";",
"ok",
"{",
"if",
"err",
":=",
"s",
".",
"SignRequest",
"(",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"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",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"res",
".",
"Status",
",",
"bytes",
".",
"TrimSpace",
"(",
"detail",
")",
")",
"\n",
"default",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"req",
".",
"Method",
",",
"req",
".",
"URL",
",",
"res",
".",
"Status",
")",
"\n",
"}",
"\n\n",
"if",
"resBody",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\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\n",
"if",
"user",
"!=",
"nil",
"{",
"if",
"password",
",",
"ok",
":=",
"user",
".",
"Password",
"(",
")",
";",
"ok",
"{",
"req",
".",
"SetBasicAuth",
"(",
"user",
".",
"Username",
"(",
")",
",",
"password",
")",
"\n",
"}",
"\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\n",
"req",
":=",
"types",
".",
"RetrieveServiceContent",
"{",
"This",
":",
"ServiceInstance",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"RetrieveServiceContent",
"(",
"ctx",
",",
"sc",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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\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\n",
"b",
",",
"err",
":=",
"base64",
".",
"StdEncoding",
".",
"DecodeString",
"(",
"enc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"enc",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"cert",
",",
"err",
":=",
"x509",
".",
"ParseCertificate",
"(",
"b",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"enc",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
"\n",
"}",
"\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\n",
"res",
",",
"err",
":=",
"methods",
".",
"CreateDescriptor",
"(",
"ctx",
",",
"m",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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\n",
"res",
",",
"err",
":=",
"methods",
".",
"CreateImportSpec",
"(",
"ctx",
",",
"m",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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\n",
"res",
",",
"err",
":=",
"methods",
".",
"ParseDescriptor",
"(",
"ctx",
",",
"m",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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\n",
"res",
",",
"err",
":=",
"methods",
".",
"ValidateHost",
"(",
"ctx",
",",
"m",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
")",
"\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\n",
"res",
",",
"err",
":=",
"x",
".",
"Run",
"(",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"info",
":=",
"&",
"FirewallInfo",
"{",
"Loaded",
":",
"res",
".",
"Values",
"[",
"0",
"]",
"[",
"\"",
"\"",
"]",
"[",
"0",
"]",
"==",
"\"",
"\"",
",",
"Enabled",
":",
"res",
".",
"Values",
"[",
"0",
"]",
"[",
"\"",
"\"",
"]",
"[",
"0",
"]",
"==",
"\"",
"\"",
",",
"DefaultAction",
":",
"res",
".",
"Values",
"[",
"0",
"]",
"[",
"\"",
"\"",
"]",
"[",
"0",
"]",
",",
"}",
"\n\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
")",
"\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",
"(",
"\"",
"\"",
",",
"ref",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"info",
"[",
"]",
"Tag",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"tag",
",",
"err",
":=",
"c",
".",
"GetTag",
"(",
"ctx",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
")",
"\n",
"var",
"res",
"[",
"]",
"internal",
".",
"AssociatedObject",
"\n",
"if",
"err",
":=",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodPost",
",",
"nil",
")",
",",
"&",
"res",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\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\n",
"reply",
",",
"err",
":=",
"c",
".",
"Receive",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"bytes",
".",
"HasPrefix",
"(",
"reply",
",",
"rpciOK",
")",
"{",
"return",
"reply",
"[",
"2",
":",
"]",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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\n",
"// Chop leaves under the Datacenter",
"for",
"i",
":=",
"len",
"(",
"mes",
")",
"-",
"1",
";",
"i",
">",
"0",
";",
"i",
"--",
"{",
"if",
"mes",
"[",
"i",
"]",
".",
"Self",
".",
"Type",
"==",
"\"",
"\"",
"{",
"break",
"\n",
"}",
"\n",
"mes",
"=",
"mes",
"[",
":",
"i",
"]",
"\n",
"}",
"\n\n",
"var",
"p",
"string",
"\n\n",
"for",
"_",
",",
"me",
":=",
"range",
"mes",
"{",
"// Skip root entity in building inventory path.",
"if",
"me",
".",
"Parent",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"p",
"=",
"p",
"+",
"\"",
"\"",
"+",
"me",
".",
"Name",
"\n",
"}",
"\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\n",
"s",
":=",
"&",
"spec",
"{",
"Relative",
":",
"rl",
",",
"}",
"\n\n",
"e",
",",
"err",
":=",
"f",
".",
"find",
"(",
"ctx",
",",
"\"",
"\"",
",",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"e",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"&",
"NotFoundError",
"{",
"ref",
".",
"Type",
",",
"ref",
".",
"Value",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"e",
")",
">",
"1",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\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\n",
"r",
":=",
"object",
".",
"NewReference",
"(",
"f",
".",
"client",
",",
"ref",
")",
"\n\n",
"type",
"common",
"interface",
"{",
"SetInventoryPath",
"(",
"string",
")",
"\n",
"}",
"\n\n",
"r",
".",
"(",
"common",
")",
".",
"SetInventoryPath",
"(",
"e",
".",
"Path",
")",
"\n\n",
"if",
"f",
".",
"dc",
"!=",
"nil",
"{",
"if",
"ds",
",",
"ok",
":=",
"r",
".",
"(",
"*",
"object",
".",
"Datastore",
")",
";",
"ok",
"{",
"ds",
".",
"DatacenterPath",
"=",
"f",
".",
"dc",
".",
"InventoryPath",
"\n",
"}",
"\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\n",
"vapps",
",",
"_",
":=",
"f",
".",
"VirtualAppList",
"(",
"ctx",
",",
"path",
")",
"\n\n",
"if",
"len",
"(",
"vapps",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"vapp",
":=",
"range",
"vapps",
"{",
"pools",
"=",
"append",
"(",
"pools",
",",
"vapp",
".",
"ResourcePool",
")",
"\n",
"}",
"\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",
"// 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",
"\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",
"{",
"// Must be a pointer to a named type,",
"// since it has the Marshaler methods.",
"start",
".",
"Name",
".",
"Local",
"=",
"typ",
".",
"Elem",
"(",
")",
".",
"Name",
"(",
")",
"\n",
"}",
"\n\n",
"// Add type attribute if necessary",
"if",
"finfo",
"!=",
"nil",
"&&",
"finfo",
".",
"flags",
"&",
"fTypeAttr",
"!=",
"0",
"{",
"start",
".",
"Attr",
"=",
"append",
"(",
"start",
".",
"Attr",
",",
"Attr",
"{",
"xmlSchemaInstance",
",",
"typeToString",
"(",
"typ",
")",
"}",
")",
"\n",
"}",
"\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",
"{",
"// 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",
"n",
":=",
"len",
"(",
"p",
".",
"tags",
")",
"\n\n",
"err",
":=",
"val",
".",
"MarshalXML",
"(",
"p",
".",
"encoder",
",",
"start",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Make sure MarshalXML closed all its tags. p.tags[n-1] is the mark.",
"if",
"len",
"(",
"p",
".",
"tags",
")",
">",
"n",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"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",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"p",
".",
"tags",
"=",
"append",
"(",
"p",
".",
"tags",
",",
"start",
".",
"Name",
")",
"\n",
"p",
".",
"markPrefix",
"(",
")",
"\n\n",
"p",
".",
"writeIndent",
"(",
"1",
")",
"\n",
"p",
".",
"WriteByte",
"(",
"'<'",
")",
"\n",
"p",
".",
"WriteString",
"(",
"start",
".",
"Name",
".",
"Local",
")",
"\n\n",
"if",
"start",
".",
"Name",
".",
"Space",
"!=",
"\"",
"\"",
"{",
"p",
".",
"WriteString",
"(",
"` xmlns=\"`",
")",
"\n",
"p",
".",
"EscapeString",
"(",
"start",
".",
"Name",
".",
"Space",
")",
"\n",
"p",
".",
"WriteByte",
"(",
"'\"'",
")",
"\n",
"}",
"\n\n",
"// Attributes",
"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\n",
"if",
"!",
"cmd",
".",
"kind",
".",
"wanted",
"(",
"ref",
".",
"Type",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"filter",
")",
"==",
"1",
"&&",
"filter",
"[",
"\"",
"\"",
"]",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"var",
"content",
"[",
"]",
"types",
".",
"ObjectContent",
"\n\n",
"pc",
":=",
"property",
".",
"DefaultCollector",
"(",
"client",
")",
"\n",
"_",
"=",
"pc",
".",
"RetrieveWithFilter",
"(",
"ctx",
",",
"[",
"]",
"types",
".",
"ManagedObjectReference",
"{",
"ref",
"}",
",",
"filter",
".",
"Keys",
"(",
")",
",",
"&",
"content",
",",
"filter",
")",
"\n\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\n",
"if",
"len",
"(",
"ref",
")",
"==",
"1",
"{",
"mref",
"=",
"ref",
"[",
"0",
"]",
"\n",
"}",
"\n\n",
"m",
":=",
"ObjectManager",
"{",
"ManagedObjectReference",
":",
"mref",
",",
"c",
":",
"client",
",",
"isVC",
":",
"mref",
".",
"Type",
"==",
"\"",
"\"",
",",
"}",
"\n\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",
"!=",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\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\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\n",
"req",
":=",
"types",
".",
"RecommendDatastores",
"{",
"This",
":",
"*",
"m",
".",
"c",
".",
"ServiceContent",
".",
"StorageResourceManager",
",",
"StorageSpec",
":",
"storage",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"RecommendDatastores",
"(",
"ctx",
",",
"m",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"r",
":=",
"res",
".",
"Returnval",
".",
"Recommendations",
"\n",
"if",
"len",
"(",
"r",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"backing",
".",
"Datastore",
"=",
"r",
"[",
"0",
"]",
".",
"Action",
"[",
"0",
"]",
".",
"(",
"*",
"types",
".",
"StoragePlacementAction",
")",
".",
"Destination",
"\n\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\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\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\n",
"if",
"ref",
".",
"Type",
"==",
"\"",
"\"",
"{",
"ref",
".",
"Type",
"=",
"typeName",
"(",
"item",
")",
"\n",
"}",
"\n\n",
"if",
"ref",
".",
"Value",
"==",
"\"",
"\"",
"{",
"n",
":=",
"atomic",
".",
"AddInt64",
"(",
"&",
"r",
".",
"counter",
",",
"1",
")",
"\n",
"ref",
".",
"Value",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"valuePrefix",
"(",
"ref",
".",
"Type",
")",
",",
"n",
")",
"\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\n",
"if",
"parent",
"!=",
"nil",
"{",
"e",
".",
"Parent",
"=",
"&",
"parent",
".",
"Entity",
"(",
")",
".",
"Self",
"\n",
"}",
"\n\n",
"r",
".",
"Put",
"(",
"item",
")",
"\n\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\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\n",
"for",
"ref",
",",
"val",
":=",
"range",
"r",
".",
"objects",
"{",
"if",
"ref",
".",
"Type",
"==",
"kind",
"{",
"return",
"val",
".",
"(",
"mo",
".",
"Entity",
")",
"\n",
"}",
"\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\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\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\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\n",
"ref",
":=",
"item",
".",
"Reference",
"(",
")",
"\n",
"if",
"ref",
".",
"Type",
"==",
"\"",
"\"",
"||",
"ref",
".",
"Value",
"==",
"\"",
"\"",
"{",
"ref",
"=",
"r",
".",
"newReference",
"(",
"item",
")",
"\n",
"r",
".",
"setReference",
"(",
"item",
",",
"ref",
")",
"\n",
"}",
"\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",
"}",
"// Admin",
"\n",
"}",
"\n\n",
"r",
".",
"objects",
"[",
"ref",
"]",
"=",
"item",
"\n\n",
"r",
".",
"m",
".",
"Unlock",
"(",
")",
"\n\n",
"r",
".",
"applyHandlers",
"(",
"func",
"(",
"o",
"RegisterObject",
")",
"{",
"o",
".",
"PutObject",
"(",
"item",
")",
"\n",
"}",
")",
"\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\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 |
vmware/govmomi | simulator/registry.go | Update | func (r *Registry) Update(obj mo.Reference, changes []types.PropertyChange) {
for i := range changes {
if changes[i].Op == "" {
changes[i].Op = types.PropertyChangeOpAssign
}
if changes[i].Val != nil {
rval := reflect.ValueOf(changes[i].Val)
changes[i].Val = wrapValue(rval, rval.Type())
}
}
val := getManagedObject(obj).Addr().Interface().(mo.Reference)
mo.ApplyPropertyChange(val, changes)
r.applyHandlers(func(o RegisterObject) {
o.UpdateObject(val, changes)
})
} | go | func (r *Registry) Update(obj mo.Reference, changes []types.PropertyChange) {
for i := range changes {
if changes[i].Op == "" {
changes[i].Op = types.PropertyChangeOpAssign
}
if changes[i].Val != nil {
rval := reflect.ValueOf(changes[i].Val)
changes[i].Val = wrapValue(rval, rval.Type())
}
}
val := getManagedObject(obj).Addr().Interface().(mo.Reference)
mo.ApplyPropertyChange(val, changes)
r.applyHandlers(func(o RegisterObject) {
o.UpdateObject(val, changes)
})
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"Update",
"(",
"obj",
"mo",
".",
"Reference",
",",
"changes",
"[",
"]",
"types",
".",
"PropertyChange",
")",
"{",
"for",
"i",
":=",
"range",
"changes",
"{",
"if",
"changes",
"[",
"i",
"]",
".",
"Op",
"==",
"\"",
"\"",
"{",
"changes",
"[",
"i",
"]",
".",
"Op",
"=",
"types",
".",
"PropertyChangeOpAssign",
"\n",
"}",
"\n",
"if",
"changes",
"[",
"i",
"]",
".",
"Val",
"!=",
"nil",
"{",
"rval",
":=",
"reflect",
".",
"ValueOf",
"(",
"changes",
"[",
"i",
"]",
".",
"Val",
")",
"\n",
"changes",
"[",
"i",
"]",
".",
"Val",
"=",
"wrapValue",
"(",
"rval",
",",
"rval",
".",
"Type",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"val",
":=",
"getManagedObject",
"(",
"obj",
")",
".",
"Addr",
"(",
")",
".",
"Interface",
"(",
")",
".",
"(",
"mo",
".",
"Reference",
")",
"\n\n",
"mo",
".",
"ApplyPropertyChange",
"(",
"val",
",",
"changes",
")",
"\n\n",
"r",
".",
"applyHandlers",
"(",
"func",
"(",
"o",
"RegisterObject",
")",
"{",
"o",
".",
"UpdateObject",
"(",
"val",
",",
"changes",
")",
"\n",
"}",
")",
"\n",
"}"
] | // Update dispatches object property changes to RegisterObject handlers,
// such as any PropertyCollector instances with in-progress WaitForUpdates calls.
// The changes are also applied to the given object via mo.ApplyPropertyChange,
// so there is no need to set object fields directly. | [
"Update",
"dispatches",
"object",
"property",
"changes",
"to",
"RegisterObject",
"handlers",
"such",
"as",
"any",
"PropertyCollector",
"instances",
"with",
"in",
"-",
"progress",
"WaitForUpdates",
"calls",
".",
"The",
"changes",
"are",
"also",
"applied",
"to",
"the",
"given",
"object",
"via",
"mo",
".",
"ApplyPropertyChange",
"so",
"there",
"is",
"no",
"need",
"to",
"set",
"object",
"fields",
"directly",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L266-L284 | train |
vmware/govmomi | simulator/registry.go | getEntityParent | func (r *Registry) getEntityParent(item mo.Entity, kind string) mo.Entity {
for {
parent := item.Entity().Parent
item = r.Get(*parent).(mo.Entity)
if item.Reference().Type == kind {
return item
}
}
} | go | func (r *Registry) getEntityParent(item mo.Entity, kind string) mo.Entity {
for {
parent := item.Entity().Parent
item = r.Get(*parent).(mo.Entity)
if item.Reference().Type == kind {
return item
}
}
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"getEntityParent",
"(",
"item",
"mo",
".",
"Entity",
",",
"kind",
"string",
")",
"mo",
".",
"Entity",
"{",
"for",
"{",
"parent",
":=",
"item",
".",
"Entity",
"(",
")",
".",
"Parent",
"\n\n",
"item",
"=",
"r",
".",
"Get",
"(",
"*",
"parent",
")",
".",
"(",
"mo",
".",
"Entity",
")",
"\n\n",
"if",
"item",
".",
"Reference",
"(",
")",
".",
"Type",
"==",
"kind",
"{",
"return",
"item",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // getEntityParent traverses up the inventory and returns the first object of type kind.
// If no object of type kind is found, the method will panic when it reaches the
// inventory root Folder where the Parent field is nil. | [
"getEntityParent",
"traverses",
"up",
"the",
"inventory",
"and",
"returns",
"the",
"first",
"object",
"of",
"type",
"kind",
".",
"If",
"no",
"object",
"of",
"type",
"kind",
"is",
"found",
"the",
"method",
"will",
"panic",
"when",
"it",
"reaches",
"the",
"inventory",
"root",
"Folder",
"where",
"the",
"Parent",
"field",
"is",
"nil",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L289-L299 | train |
vmware/govmomi | simulator/registry.go | getEntityDatacenter | func (r *Registry) getEntityDatacenter(item mo.Entity) *Datacenter {
return r.getEntityParent(item, "Datacenter").(*Datacenter)
} | go | func (r *Registry) getEntityDatacenter(item mo.Entity) *Datacenter {
return r.getEntityParent(item, "Datacenter").(*Datacenter)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"getEntityDatacenter",
"(",
"item",
"mo",
".",
"Entity",
")",
"*",
"Datacenter",
"{",
"return",
"r",
".",
"getEntityParent",
"(",
"item",
",",
"\"",
"\"",
")",
".",
"(",
"*",
"Datacenter",
")",
"\n",
"}"
] | // getEntityDatacenter returns the Datacenter containing the given item | [
"getEntityDatacenter",
"returns",
"the",
"Datacenter",
"containing",
"the",
"given",
"item"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L302-L304 | train |
vmware/govmomi | simulator/registry.go | getEntityComputeResource | func (r *Registry) getEntityComputeResource(item mo.Entity) mo.Entity {
for {
parent := item.Entity().Parent
item = r.Get(*parent).(mo.Entity)
switch item.Reference().Type {
case "ComputeResource":
return item
case "ClusterComputeResource":
return item
}
}
} | go | func (r *Registry) getEntityComputeResource(item mo.Entity) mo.Entity {
for {
parent := item.Entity().Parent
item = r.Get(*parent).(mo.Entity)
switch item.Reference().Type {
case "ComputeResource":
return item
case "ClusterComputeResource":
return item
}
}
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"getEntityComputeResource",
"(",
"item",
"mo",
".",
"Entity",
")",
"mo",
".",
"Entity",
"{",
"for",
"{",
"parent",
":=",
"item",
".",
"Entity",
"(",
")",
".",
"Parent",
"\n\n",
"item",
"=",
"r",
".",
"Get",
"(",
"*",
"parent",
")",
".",
"(",
"mo",
".",
"Entity",
")",
"\n\n",
"switch",
"item",
".",
"Reference",
"(",
")",
".",
"Type",
"{",
"case",
"\"",
"\"",
":",
"return",
"item",
"\n",
"case",
"\"",
"\"",
":",
"return",
"item",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // getEntityComputeResource returns the ComputeResource parent for the given item.
// A ResourcePool for example may have N Parents of type ResourcePool, but the top
// most Parent pool is always a ComputeResource child. | [
"getEntityComputeResource",
"returns",
"the",
"ComputeResource",
"parent",
"for",
"the",
"given",
"item",
".",
"A",
"ResourcePool",
"for",
"example",
"may",
"have",
"N",
"Parents",
"of",
"type",
"ResourcePool",
"but",
"the",
"top",
"most",
"Parent",
"pool",
"is",
"always",
"a",
"ComputeResource",
"child",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L332-L345 | train |
vmware/govmomi | simulator/registry.go | FindByName | func (r *Registry) FindByName(name string, refs []types.ManagedObjectReference) mo.Entity {
for _, ref := range refs {
if e, ok := r.Get(ref).(mo.Entity); ok {
if name == e.Entity().Name {
return e
}
}
}
return nil
} | go | func (r *Registry) FindByName(name string, refs []types.ManagedObjectReference) mo.Entity {
for _, ref := range refs {
if e, ok := r.Get(ref).(mo.Entity); ok {
if name == e.Entity().Name {
return e
}
}
}
return nil
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"FindByName",
"(",
"name",
"string",
",",
"refs",
"[",
"]",
"types",
".",
"ManagedObjectReference",
")",
"mo",
".",
"Entity",
"{",
"for",
"_",
",",
"ref",
":=",
"range",
"refs",
"{",
"if",
"e",
",",
"ok",
":=",
"r",
".",
"Get",
"(",
"ref",
")",
".",
"(",
"mo",
".",
"Entity",
")",
";",
"ok",
"{",
"if",
"name",
"==",
"e",
".",
"Entity",
"(",
")",
".",
"Name",
"{",
"return",
"e",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // FindByName returns the first mo.Entity of the given refs whose Name field is equal to the given name.
// If there is no match, nil is returned.
// This method is useful for cases where objects are required to have a unique name, such as Datastore with
// a HostStorageSystem or HostSystem within a ClusterComputeResource. | [
"FindByName",
"returns",
"the",
"first",
"mo",
".",
"Entity",
"of",
"the",
"given",
"refs",
"whose",
"Name",
"field",
"is",
"equal",
"to",
"the",
"given",
"name",
".",
"If",
"there",
"is",
"no",
"match",
"nil",
"is",
"returned",
".",
"This",
"method",
"is",
"useful",
"for",
"cases",
"where",
"objects",
"are",
"required",
"to",
"have",
"a",
"unique",
"name",
"such",
"as",
"Datastore",
"with",
"a",
"HostStorageSystem",
"or",
"HostSystem",
"within",
"a",
"ClusterComputeResource",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L351-L361 | train |
vmware/govmomi | simulator/registry.go | FindReference | func FindReference(refs []types.ManagedObjectReference, match ...types.ManagedObjectReference) *types.ManagedObjectReference {
for _, ref := range refs {
for _, m := range match {
if ref == m {
return &ref
}
}
}
return nil
} | go | func FindReference(refs []types.ManagedObjectReference, match ...types.ManagedObjectReference) *types.ManagedObjectReference {
for _, ref := range refs {
for _, m := range match {
if ref == m {
return &ref
}
}
}
return nil
} | [
"func",
"FindReference",
"(",
"refs",
"[",
"]",
"types",
".",
"ManagedObjectReference",
",",
"match",
"...",
"types",
".",
"ManagedObjectReference",
")",
"*",
"types",
".",
"ManagedObjectReference",
"{",
"for",
"_",
",",
"ref",
":=",
"range",
"refs",
"{",
"for",
"_",
",",
"m",
":=",
"range",
"match",
"{",
"if",
"ref",
"==",
"m",
"{",
"return",
"&",
"ref",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // FindReference returns the 1st match found in refs, or nil if not found. | [
"FindReference",
"returns",
"the",
"1st",
"match",
"found",
"in",
"refs",
"or",
"nil",
"if",
"not",
"found",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L364-L374 | train |
vmware/govmomi | simulator/registry.go | AppendReference | func (r *Registry) AppendReference(obj mo.Reference, field *[]types.ManagedObjectReference, ref ...types.ManagedObjectReference) {
r.WithLock(obj, func() {
*field = append(*field, ref...)
})
} | go | func (r *Registry) AppendReference(obj mo.Reference, field *[]types.ManagedObjectReference, ref ...types.ManagedObjectReference) {
r.WithLock(obj, func() {
*field = append(*field, ref...)
})
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"AppendReference",
"(",
"obj",
"mo",
".",
"Reference",
",",
"field",
"*",
"[",
"]",
"types",
".",
"ManagedObjectReference",
",",
"ref",
"...",
"types",
".",
"ManagedObjectReference",
")",
"{",
"r",
".",
"WithLock",
"(",
"obj",
",",
"func",
"(",
")",
"{",
"*",
"field",
"=",
"append",
"(",
"*",
"field",
",",
"ref",
"...",
")",
"\n",
"}",
")",
"\n",
"}"
] | // AppendReference appends the given refs to field. | [
"AppendReference",
"appends",
"the",
"given",
"refs",
"to",
"field",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L377-L381 | train |
vmware/govmomi | simulator/registry.go | AddReference | func (r *Registry) AddReference(obj mo.Reference, field *[]types.ManagedObjectReference, ref types.ManagedObjectReference) {
r.WithLock(obj, func() {
if FindReference(*field, ref) == nil {
*field = append(*field, ref)
}
})
} | go | func (r *Registry) AddReference(obj mo.Reference, field *[]types.ManagedObjectReference, ref types.ManagedObjectReference) {
r.WithLock(obj, func() {
if FindReference(*field, ref) == nil {
*field = append(*field, ref)
}
})
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"AddReference",
"(",
"obj",
"mo",
".",
"Reference",
",",
"field",
"*",
"[",
"]",
"types",
".",
"ManagedObjectReference",
",",
"ref",
"types",
".",
"ManagedObjectReference",
")",
"{",
"r",
".",
"WithLock",
"(",
"obj",
",",
"func",
"(",
")",
"{",
"if",
"FindReference",
"(",
"*",
"field",
",",
"ref",
")",
"==",
"nil",
"{",
"*",
"field",
"=",
"append",
"(",
"*",
"field",
",",
"ref",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // AddReference appends ref to field if not already in the given field. | [
"AddReference",
"appends",
"ref",
"to",
"field",
"if",
"not",
"already",
"in",
"the",
"given",
"field",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L384-L390 | train |
vmware/govmomi | simulator/registry.go | SearchIndex | func (r *Registry) SearchIndex() *SearchIndex {
return r.Get(r.content().SearchIndex.Reference()).(*SearchIndex)
} | go | func (r *Registry) SearchIndex() *SearchIndex {
return r.Get(r.content().SearchIndex.Reference()).(*SearchIndex)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"SearchIndex",
"(",
")",
"*",
"SearchIndex",
"{",
"return",
"r",
".",
"Get",
"(",
"r",
".",
"content",
"(",
")",
".",
"SearchIndex",
".",
"Reference",
"(",
")",
")",
".",
"(",
"*",
"SearchIndex",
")",
"\n",
"}"
] | // SearchIndex returns the SearchIndex singleton | [
"SearchIndex",
"returns",
"the",
"SearchIndex",
"singleton"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L435-L437 | train |
vmware/govmomi | simulator/registry.go | EventManager | func (r *Registry) EventManager() *EventManager {
return r.Get(r.content().EventManager.Reference()).(*EventManager)
} | go | func (r *Registry) EventManager() *EventManager {
return r.Get(r.content().EventManager.Reference()).(*EventManager)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"EventManager",
"(",
")",
"*",
"EventManager",
"{",
"return",
"r",
".",
"Get",
"(",
"r",
".",
"content",
"(",
")",
".",
"EventManager",
".",
"Reference",
"(",
")",
")",
".",
"(",
"*",
"EventManager",
")",
"\n",
"}"
] | // EventManager returns the EventManager singleton | [
"EventManager",
"returns",
"the",
"EventManager",
"singleton"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L440-L442 | train |
vmware/govmomi | simulator/registry.go | FileManager | func (r *Registry) FileManager() *FileManager {
return r.Get(r.content().FileManager.Reference()).(*FileManager)
} | go | func (r *Registry) FileManager() *FileManager {
return r.Get(r.content().FileManager.Reference()).(*FileManager)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"FileManager",
"(",
")",
"*",
"FileManager",
"{",
"return",
"r",
".",
"Get",
"(",
"r",
".",
"content",
"(",
")",
".",
"FileManager",
".",
"Reference",
"(",
")",
")",
".",
"(",
"*",
"FileManager",
")",
"\n",
"}"
] | // FileManager returns the FileManager singleton | [
"FileManager",
"returns",
"the",
"FileManager",
"singleton"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L445-L447 | train |
vmware/govmomi | simulator/registry.go | VirtualDiskManager | func (r *Registry) VirtualDiskManager() *VirtualDiskManager {
return r.Get(r.content().VirtualDiskManager.Reference()).(*VirtualDiskManager)
} | go | func (r *Registry) VirtualDiskManager() *VirtualDiskManager {
return r.Get(r.content().VirtualDiskManager.Reference()).(*VirtualDiskManager)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"VirtualDiskManager",
"(",
")",
"*",
"VirtualDiskManager",
"{",
"return",
"r",
".",
"Get",
"(",
"r",
".",
"content",
"(",
")",
".",
"VirtualDiskManager",
".",
"Reference",
"(",
")",
")",
".",
"(",
"*",
"VirtualDiskManager",
")",
"\n",
"}"
] | // VirtualDiskManager returns the VirtualDiskManager singleton | [
"VirtualDiskManager",
"returns",
"the",
"VirtualDiskManager",
"singleton"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L450-L452 | train |
vmware/govmomi | simulator/registry.go | ViewManager | func (r *Registry) ViewManager() *ViewManager {
return r.Get(r.content().ViewManager.Reference()).(*ViewManager)
} | go | func (r *Registry) ViewManager() *ViewManager {
return r.Get(r.content().ViewManager.Reference()).(*ViewManager)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"ViewManager",
"(",
")",
"*",
"ViewManager",
"{",
"return",
"r",
".",
"Get",
"(",
"r",
".",
"content",
"(",
")",
".",
"ViewManager",
".",
"Reference",
"(",
")",
")",
".",
"(",
"*",
"ViewManager",
")",
"\n",
"}"
] | // ViewManager returns the ViewManager singleton | [
"ViewManager",
"returns",
"the",
"ViewManager",
"singleton"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L455-L457 | train |
vmware/govmomi | simulator/registry.go | UserDirectory | func (r *Registry) UserDirectory() *UserDirectory {
return r.Get(r.content().UserDirectory.Reference()).(*UserDirectory)
} | go | func (r *Registry) UserDirectory() *UserDirectory {
return r.Get(r.content().UserDirectory.Reference()).(*UserDirectory)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"UserDirectory",
"(",
")",
"*",
"UserDirectory",
"{",
"return",
"r",
".",
"Get",
"(",
"r",
".",
"content",
"(",
")",
".",
"UserDirectory",
".",
"Reference",
"(",
")",
")",
".",
"(",
"*",
"UserDirectory",
")",
"\n",
"}"
] | // UserDirectory returns the UserDirectory singleton | [
"UserDirectory",
"returns",
"the",
"UserDirectory",
"singleton"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L460-L462 | train |
vmware/govmomi | simulator/registry.go | SessionManager | func (r *Registry) SessionManager() *SessionManager {
return r.Get(r.content().SessionManager.Reference()).(*SessionManager)
} | go | func (r *Registry) SessionManager() *SessionManager {
return r.Get(r.content().SessionManager.Reference()).(*SessionManager)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"SessionManager",
"(",
")",
"*",
"SessionManager",
"{",
"return",
"r",
".",
"Get",
"(",
"r",
".",
"content",
"(",
")",
".",
"SessionManager",
".",
"Reference",
"(",
")",
")",
".",
"(",
"*",
"SessionManager",
")",
"\n",
"}"
] | // SessionManager returns the SessionManager singleton | [
"SessionManager",
"returns",
"the",
"SessionManager",
"singleton"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L465-L467 | train |
vmware/govmomi | simulator/registry.go | OptionManager | func (r *Registry) OptionManager() *OptionManager {
return r.Get(r.content().Setting.Reference()).(*OptionManager)
} | go | func (r *Registry) OptionManager() *OptionManager {
return r.Get(r.content().Setting.Reference()).(*OptionManager)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"OptionManager",
"(",
")",
"*",
"OptionManager",
"{",
"return",
"r",
".",
"Get",
"(",
"r",
".",
"content",
"(",
")",
".",
"Setting",
".",
"Reference",
"(",
")",
")",
".",
"(",
"*",
"OptionManager",
")",
"\n",
"}"
] | // OptionManager returns the OptionManager singleton | [
"OptionManager",
"returns",
"the",
"OptionManager",
"singleton"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L470-L472 | train |
vmware/govmomi | simulator/registry.go | CustomFieldsManager | func (r *Registry) CustomFieldsManager() *CustomFieldsManager {
return r.Get(r.content().CustomFieldsManager.Reference()).(*CustomFieldsManager)
} | go | func (r *Registry) CustomFieldsManager() *CustomFieldsManager {
return r.Get(r.content().CustomFieldsManager.Reference()).(*CustomFieldsManager)
} | [
"func",
"(",
"r",
"*",
"Registry",
")",
"CustomFieldsManager",
"(",
")",
"*",
"CustomFieldsManager",
"{",
"return",
"r",
".",
"Get",
"(",
"r",
".",
"content",
"(",
")",
".",
"CustomFieldsManager",
".",
"Reference",
"(",
")",
")",
".",
"(",
"*",
"CustomFieldsManager",
")",
"\n",
"}"
] | // CustomFieldsManager returns CustomFieldsManager singleton | [
"CustomFieldsManager",
"returns",
"CustomFieldsManager",
"singleton"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/registry.go#L475-L477 | train |
vmware/govmomi | vim25/mo/type_info.go | LoadFromObjectContent | func (t *typeInfo) LoadFromObjectContent(o types.ObjectContent) (reflect.Value, error) {
v := reflect.New(t.typ)
assignValue(v, t.self, reflect.ValueOf(o.Obj))
for _, p := range o.PropSet {
rv, ok := t.props[p.Name]
if !ok {
continue
}
assignValue(v, rv, reflect.ValueOf(p.Val))
}
return v, nil
} | go | func (t *typeInfo) LoadFromObjectContent(o types.ObjectContent) (reflect.Value, error) {
v := reflect.New(t.typ)
assignValue(v, t.self, reflect.ValueOf(o.Obj))
for _, p := range o.PropSet {
rv, ok := t.props[p.Name]
if !ok {
continue
}
assignValue(v, rv, reflect.ValueOf(p.Val))
}
return v, nil
} | [
"func",
"(",
"t",
"*",
"typeInfo",
")",
"LoadFromObjectContent",
"(",
"o",
"types",
".",
"ObjectContent",
")",
"(",
"reflect",
".",
"Value",
",",
"error",
")",
"{",
"v",
":=",
"reflect",
".",
"New",
"(",
"t",
".",
"typ",
")",
"\n",
"assignValue",
"(",
"v",
",",
"t",
".",
"self",
",",
"reflect",
".",
"ValueOf",
"(",
"o",
".",
"Obj",
")",
")",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"o",
".",
"PropSet",
"{",
"rv",
",",
"ok",
":=",
"t",
".",
"props",
"[",
"p",
".",
"Name",
"]",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"assignValue",
"(",
"v",
",",
"rv",
",",
"reflect",
".",
"ValueOf",
"(",
"p",
".",
"Val",
")",
")",
"\n",
"}",
"\n\n",
"return",
"v",
",",
"nil",
"\n",
"}"
] | // LoadObjectFromContent loads properties from the 'PropSet' field in the
// specified ObjectContent value into the value it represents, which is
// returned as a reflect.Value. | [
"LoadObjectFromContent",
"loads",
"properties",
"from",
"the",
"PropSet",
"field",
"in",
"the",
"specified",
"ObjectContent",
"value",
"into",
"the",
"value",
"it",
"represents",
"which",
"is",
"returned",
"as",
"a",
"reflect",
".",
"Value",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/mo/type_info.go#L245-L258 | train |
vmware/govmomi | simulator/simulator.go | New | func New(instance *ServiceInstance) *Service {
s := &Service{
readAll: ioutil.ReadAll,
sm: Map.SessionManager(),
sdk: make(map[string]*Registry),
}
s.client, _ = vim25.NewClient(context.Background(), s)
return s
} | go | func New(instance *ServiceInstance) *Service {
s := &Service{
readAll: ioutil.ReadAll,
sm: Map.SessionManager(),
sdk: make(map[string]*Registry),
}
s.client, _ = vim25.NewClient(context.Background(), s)
return s
} | [
"func",
"New",
"(",
"instance",
"*",
"ServiceInstance",
")",
"*",
"Service",
"{",
"s",
":=",
"&",
"Service",
"{",
"readAll",
":",
"ioutil",
".",
"ReadAll",
",",
"sm",
":",
"Map",
".",
"SessionManager",
"(",
")",
",",
"sdk",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Registry",
")",
",",
"}",
"\n\n",
"s",
".",
"client",
",",
"_",
"=",
"vim25",
".",
"NewClient",
"(",
"context",
".",
"Background",
"(",
")",
",",
"s",
")",
"\n\n",
"return",
"s",
"\n",
"}"
] | // New returns an initialized simulator Service instance | [
"New",
"returns",
"an",
"initialized",
"simulator",
"Service",
"instance"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L88-L98 | train |
vmware/govmomi | simulator/simulator.go | Fault | func Fault(msg string, fault types.BaseMethodFault) *soap.Fault {
f := &soap.Fault{
Code: "ServerFaultCode",
String: msg,
}
f.Detail.Fault = fault
return f
} | go | func Fault(msg string, fault types.BaseMethodFault) *soap.Fault {
f := &soap.Fault{
Code: "ServerFaultCode",
String: msg,
}
f.Detail.Fault = fault
return f
} | [
"func",
"Fault",
"(",
"msg",
"string",
",",
"fault",
"types",
".",
"BaseMethodFault",
")",
"*",
"soap",
".",
"Fault",
"{",
"f",
":=",
"&",
"soap",
".",
"Fault",
"{",
"Code",
":",
"\"",
"\"",
",",
"String",
":",
"msg",
",",
"}",
"\n\n",
"f",
".",
"Detail",
".",
"Fault",
"=",
"fault",
"\n\n",
"return",
"f",
"\n",
"}"
] | // Fault wraps the given message and fault in a soap.Fault | [
"Fault",
"wraps",
"the",
"given",
"message",
"and",
"fault",
"in",
"a",
"soap",
".",
"Fault"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L111-L120 | train |
vmware/govmomi | simulator/simulator.go | About | func (s *Service) About(w http.ResponseWriter, r *http.Request) {
var about struct {
Methods []string
Types []string
}
seen := make(map[string]bool)
f := reflect.TypeOf((*soap.HasFault)(nil)).Elem()
for _, obj := range Map.objects {
kind := obj.Reference().Type
if seen[kind] {
continue
}
seen[kind] = true
about.Types = append(about.Types, kind)
t := reflect.TypeOf(obj)
for i := 0; i < t.NumMethod(); i++ {
m := t.Method(i)
if seen[m.Name] {
continue
}
seen[m.Name] = true
in := m.Type.NumIn()
if in < 2 || in > 3 { // at least 2 params (receiver and request), optionally a 3rd param (context)
continue
}
if m.Type.NumOut() != 1 || m.Type.Out(0) != f { // all methods return soap.HasFault
continue
}
about.Methods = append(about.Methods, strings.Replace(m.Name, "Task", "_Task", 1))
}
}
sort.Strings(about.Methods)
sort.Strings(about.Types)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
_ = enc.Encode(&about)
} | go | func (s *Service) About(w http.ResponseWriter, r *http.Request) {
var about struct {
Methods []string
Types []string
}
seen := make(map[string]bool)
f := reflect.TypeOf((*soap.HasFault)(nil)).Elem()
for _, obj := range Map.objects {
kind := obj.Reference().Type
if seen[kind] {
continue
}
seen[kind] = true
about.Types = append(about.Types, kind)
t := reflect.TypeOf(obj)
for i := 0; i < t.NumMethod(); i++ {
m := t.Method(i)
if seen[m.Name] {
continue
}
seen[m.Name] = true
in := m.Type.NumIn()
if in < 2 || in > 3 { // at least 2 params (receiver and request), optionally a 3rd param (context)
continue
}
if m.Type.NumOut() != 1 || m.Type.Out(0) != f { // all methods return soap.HasFault
continue
}
about.Methods = append(about.Methods, strings.Replace(m.Name, "Task", "_Task", 1))
}
}
sort.Strings(about.Methods)
sort.Strings(about.Types)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
_ = enc.Encode(&about)
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"About",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"about",
"struct",
"{",
"Methods",
"[",
"]",
"string",
"\n",
"Types",
"[",
"]",
"string",
"\n",
"}",
"\n\n",
"seen",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n\n",
"f",
":=",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"soap",
".",
"HasFault",
")",
"(",
"nil",
")",
")",
".",
"Elem",
"(",
")",
"\n\n",
"for",
"_",
",",
"obj",
":=",
"range",
"Map",
".",
"objects",
"{",
"kind",
":=",
"obj",
".",
"Reference",
"(",
")",
".",
"Type",
"\n",
"if",
"seen",
"[",
"kind",
"]",
"{",
"continue",
"\n",
"}",
"\n",
"seen",
"[",
"kind",
"]",
"=",
"true",
"\n\n",
"about",
".",
"Types",
"=",
"append",
"(",
"about",
".",
"Types",
",",
"kind",
")",
"\n\n",
"t",
":=",
"reflect",
".",
"TypeOf",
"(",
"obj",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"t",
".",
"NumMethod",
"(",
")",
";",
"i",
"++",
"{",
"m",
":=",
"t",
".",
"Method",
"(",
"i",
")",
"\n",
"if",
"seen",
"[",
"m",
".",
"Name",
"]",
"{",
"continue",
"\n",
"}",
"\n",
"seen",
"[",
"m",
".",
"Name",
"]",
"=",
"true",
"\n\n",
"in",
":=",
"m",
".",
"Type",
".",
"NumIn",
"(",
")",
"\n",
"if",
"in",
"<",
"2",
"||",
"in",
">",
"3",
"{",
"// at least 2 params (receiver and request), optionally a 3rd param (context)",
"continue",
"\n",
"}",
"\n",
"if",
"m",
".",
"Type",
".",
"NumOut",
"(",
")",
"!=",
"1",
"||",
"m",
".",
"Type",
".",
"Out",
"(",
"0",
")",
"!=",
"f",
"{",
"// all methods return soap.HasFault",
"continue",
"\n",
"}",
"\n\n",
"about",
".",
"Methods",
"=",
"append",
"(",
"about",
".",
"Methods",
",",
"strings",
".",
"Replace",
"(",
"m",
".",
"Name",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"1",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"sort",
".",
"Strings",
"(",
"about",
".",
"Methods",
")",
"\n",
"sort",
".",
"Strings",
"(",
"about",
".",
"Types",
")",
"\n\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"enc",
".",
"SetIndent",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"_",
"=",
"enc",
".",
"Encode",
"(",
"&",
"about",
")",
"\n",
"}"
] | // About generates some info about the simulator. | [
"About",
"generates",
"some",
"info",
"about",
"the",
"simulator",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L317-L363 | train |
vmware/govmomi | simulator/simulator.go | Handle | func (s *Service) Handle(pattern string, handler http.Handler) {
s.ServeMux.Handle(pattern, handler)
// Not ideal, but avoids having to add yet another registration mechanism
// so we can optionally use vapi/simulator internally.
if m, ok := handler.(tagManager); ok {
s.sdk[vim25.Path].tagManager = m
}
} | go | func (s *Service) Handle(pattern string, handler http.Handler) {
s.ServeMux.Handle(pattern, handler)
// Not ideal, but avoids having to add yet another registration mechanism
// so we can optionally use vapi/simulator internally.
if m, ok := handler.(tagManager); ok {
s.sdk[vim25.Path].tagManager = m
}
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Handle",
"(",
"pattern",
"string",
",",
"handler",
"http",
".",
"Handler",
")",
"{",
"s",
".",
"ServeMux",
".",
"Handle",
"(",
"pattern",
",",
"handler",
")",
"\n",
"// Not ideal, but avoids having to add yet another registration mechanism",
"// so we can optionally use vapi/simulator internally.",
"if",
"m",
",",
"ok",
":=",
"handler",
".",
"(",
"tagManager",
")",
";",
"ok",
"{",
"s",
".",
"sdk",
"[",
"vim25",
".",
"Path",
"]",
".",
"tagManager",
"=",
"m",
"\n",
"}",
"\n",
"}"
] | // Handle registers the handler for the given pattern with Service.ServeMux. | [
"Handle",
"registers",
"the",
"handler",
"for",
"the",
"given",
"pattern",
"with",
"Service",
".",
"ServeMux",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/simulator.go#L366-L373 | train |