repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
vmware/govmomi | simulator/datacenter.go | NewDatacenter | func NewDatacenter(f *Folder) *Datacenter {
dc := &Datacenter{
isESX: f.Self == esx.RootFolder.Self,
}
if dc.isESX {
dc.Datacenter = esx.Datacenter
}
f.putChild(dc)
dc.createFolders()
return dc
} | go | func NewDatacenter(f *Folder) *Datacenter {
dc := &Datacenter{
isESX: f.Self == esx.RootFolder.Self,
}
if dc.isESX {
dc.Datacenter = esx.Datacenter
}
f.putChild(dc)
dc.createFolders()
return dc
} | [
"func",
"NewDatacenter",
"(",
"f",
"*",
"Folder",
")",
"*",
"Datacenter",
"{",
"dc",
":=",
"&",
"Datacenter",
"{",
"isESX",
":",
"f",
".",
"Self",
"==",
"esx",
".",
"RootFolder",
".",
"Self",
",",
"}",
"\n\n",
"if",
"dc",
".",
"isESX",
"{",
"dc",
... | // NewDatacenter creates a Datacenter and its child folders. | [
"NewDatacenter",
"creates",
"a",
"Datacenter",
"and",
"its",
"child",
"folders",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/datacenter.go#L36-L50 | train |
vmware/govmomi | vapi/tags/tags.go | CreateTag | func (c *Manager) CreateTag(ctx context.Context, tag *Tag) (string, error) {
// create avoids the annoyance of CreateTag requiring a "description" key to be included in the request,
// even though the field value can be empty.
type create struct {
Name string `json:"name"`
Description string `json:"descri... | go | func (c *Manager) CreateTag(ctx context.Context, tag *Tag) (string, error) {
// create avoids the annoyance of CreateTag requiring a "description" key to be included in the request,
// even though the field value can be empty.
type create struct {
Name string `json:"name"`
Description string `json:"descri... | [
"func",
"(",
"c",
"*",
"Manager",
")",
"CreateTag",
"(",
"ctx",
"context",
".",
"Context",
",",
"tag",
"*",
"Tag",
")",
"(",
"string",
",",
"error",
")",
"{",
"// create avoids the annoyance of CreateTag requiring a \"description\" key to be included in the request,",
... | // CreateTag creates a new tag with the given Name, Description and CategoryID. | [
"CreateTag",
"creates",
"a",
"new",
"tag",
"with",
"the",
"given",
"Name",
"Description",
"and",
"CategoryID",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L69-L96 | train |
vmware/govmomi | vapi/tags/tags.go | UpdateTag | func (c *Manager) UpdateTag(ctx context.Context, tag *Tag) error {
spec := struct {
Tag Tag `json:"update_spec"`
}{
Tag: Tag{
Name: tag.Name,
Description: tag.Description,
},
}
url := internal.URL(c, internal.TagPath).WithID(tag.ID)
return c.Do(ctx, url.Request(http.MethodPatch, spec), nil)
} | go | func (c *Manager) UpdateTag(ctx context.Context, tag *Tag) error {
spec := struct {
Tag Tag `json:"update_spec"`
}{
Tag: Tag{
Name: tag.Name,
Description: tag.Description,
},
}
url := internal.URL(c, internal.TagPath).WithID(tag.ID)
return c.Do(ctx, url.Request(http.MethodPatch, spec), nil)
} | [
"func",
"(",
"c",
"*",
"Manager",
")",
"UpdateTag",
"(",
"ctx",
"context",
".",
"Context",
",",
"tag",
"*",
"Tag",
")",
"error",
"{",
"spec",
":=",
"struct",
"{",
"Tag",
"Tag",
"`json:\"update_spec\"`",
"\n",
"}",
"{",
"Tag",
":",
"Tag",
"{",
"Name",... | // UpdateTag can update one or both of the tag Description and Name fields. | [
"UpdateTag",
"can",
"update",
"one",
"or",
"both",
"of",
"the",
"tag",
"Description",
"and",
"Name",
"fields",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L99-L110 | train |
vmware/govmomi | vapi/tags/tags.go | DeleteTag | func (c *Manager) DeleteTag(ctx context.Context, tag *Tag) error {
url := internal.URL(c, internal.TagPath).WithID(tag.ID)
return c.Do(ctx, url.Request(http.MethodDelete), nil)
} | go | func (c *Manager) DeleteTag(ctx context.Context, tag *Tag) error {
url := internal.URL(c, internal.TagPath).WithID(tag.ID)
return c.Do(ctx, url.Request(http.MethodDelete), nil)
} | [
"func",
"(",
"c",
"*",
"Manager",
")",
"DeleteTag",
"(",
"ctx",
"context",
".",
"Context",
",",
"tag",
"*",
"Tag",
")",
"error",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"TagPath",
")",
".",
"WithID",
"(",
"tag",
... | // DeleteTag deletes an existing tag. | [
"DeleteTag",
"deletes",
"an",
"existing",
"tag",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L113-L116 | train |
vmware/govmomi | vapi/tags/tags.go | GetTag | func (c *Manager) GetTag(ctx context.Context, id string) (*Tag, error) {
if isName(id) {
tags, err := c.GetTags(ctx)
if err != nil {
return nil, err
}
for i := range tags {
if tags[i].Name == id {
return &tags[i], nil
}
}
}
url := internal.URL(c, internal.TagPath).WithID(id)
var res Tag
re... | go | func (c *Manager) GetTag(ctx context.Context, id string) (*Tag, error) {
if isName(id) {
tags, err := c.GetTags(ctx)
if err != nil {
return nil, err
}
for i := range tags {
if tags[i].Name == id {
return &tags[i], nil
}
}
}
url := internal.URL(c, internal.TagPath).WithID(id)
var res Tag
re... | [
"func",
"(",
"c",
"*",
"Manager",
")",
"GetTag",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"*",
"Tag",
",",
"error",
")",
"{",
"if",
"isName",
"(",
"id",
")",
"{",
"tags",
",",
"err",
":=",
"c",
".",
"GetTags",
"(",
... | // GetTag fetches the tag information for the given identifier.
// The id parameter can be a Tag ID or Tag Name. | [
"GetTag",
"fetches",
"the",
"tag",
"information",
"for",
"the",
"given",
"identifier",
".",
"The",
"id",
"parameter",
"can",
"be",
"a",
"Tag",
"ID",
"or",
"Tag",
"Name",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L120-L138 | train |
vmware/govmomi | vapi/tags/tags.go | GetTagForCategory | func (c *Manager) GetTagForCategory(ctx context.Context, id, category string) (*Tag, error) {
if category == "" {
return c.GetTag(ctx, id)
}
ids, err := c.ListTagsForCategory(ctx, category)
if err != nil {
return nil, err
}
for _, tagid := range ids {
tag, err := c.GetTag(ctx, tagid)
if err != nil {
... | go | func (c *Manager) GetTagForCategory(ctx context.Context, id, category string) (*Tag, error) {
if category == "" {
return c.GetTag(ctx, id)
}
ids, err := c.ListTagsForCategory(ctx, category)
if err != nil {
return nil, err
}
for _, tagid := range ids {
tag, err := c.GetTag(ctx, tagid)
if err != nil {
... | [
"func",
"(",
"c",
"*",
"Manager",
")",
"GetTagForCategory",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
",",
"category",
"string",
")",
"(",
"*",
"Tag",
",",
"error",
")",
"{",
"if",
"category",
"==",
"\"",
"\"",
"{",
"return",
"c",
".",
"Get... | // GetTagForCategory fetches the tag information for the given identifier in the given category. | [
"GetTagForCategory",
"fetches",
"the",
"tag",
"information",
"for",
"the",
"given",
"identifier",
"in",
"the",
"given",
"category",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L141-L162 | train |
vmware/govmomi | vapi/tags/tags.go | ListTags | func (c *Manager) ListTags(ctx context.Context) ([]string, error) {
url := internal.URL(c, internal.TagPath)
var res []string
return res, c.Do(ctx, url.Request(http.MethodGet), &res)
} | go | func (c *Manager) ListTags(ctx context.Context) ([]string, error) {
url := internal.URL(c, internal.TagPath)
var res []string
return res, c.Do(ctx, url.Request(http.MethodGet), &res)
} | [
"func",
"(",
"c",
"*",
"Manager",
")",
"ListTags",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"TagPath",
")",
"\n",
"var",
"res... | // ListTags returns all tag IDs in the system. | [
"ListTags",
"returns",
"all",
"tag",
"IDs",
"in",
"the",
"system",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L165-L169 | train |
vmware/govmomi | vapi/tags/tags.go | GetTags | func (c *Manager) GetTags(ctx context.Context) ([]Tag, error) {
ids, err := c.ListTags(ctx)
if err != nil {
return nil, fmt.Errorf("get tags failed for: %s", err)
}
var tags []Tag
for _, id := range ids {
tag, err := c.GetTag(ctx, id)
if err != nil {
return nil, fmt.Errorf("get category %s failed for %s"... | go | func (c *Manager) GetTags(ctx context.Context) ([]Tag, error) {
ids, err := c.ListTags(ctx)
if err != nil {
return nil, fmt.Errorf("get tags failed for: %s", err)
}
var tags []Tag
for _, id := range ids {
tag, err := c.GetTag(ctx, id)
if err != nil {
return nil, fmt.Errorf("get category %s failed for %s"... | [
"func",
"(",
"c",
"*",
"Manager",
")",
"GetTags",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"Tag",
",",
"error",
")",
"{",
"ids",
",",
"err",
":=",
"c",
".",
"ListTags",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"... | // GetTags fetches an array of tag information in the system. | [
"GetTags",
"fetches",
"an",
"array",
"of",
"tag",
"information",
"in",
"the",
"system",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/tags.go#L172-L189 | train |
vmware/govmomi | vim25/soap/client.go | NewServiceClient | func (c *Client) NewServiceClient(path string, namespace string) *Client {
vc := c.URL()
u, err := url.Parse(path)
if err != nil {
log.Panicf("url.Parse(%q): %s", path, err)
}
if u.Host == "" {
u.Scheme = vc.Scheme
u.Host = vc.Host
}
client := NewClient(u, c.k)
client.Namespace = "urn:" + namespace
if c... | go | func (c *Client) NewServiceClient(path string, namespace string) *Client {
vc := c.URL()
u, err := url.Parse(path)
if err != nil {
log.Panicf("url.Parse(%q): %s", path, err)
}
if u.Host == "" {
u.Scheme = vc.Scheme
u.Host = vc.Host
}
client := NewClient(u, c.k)
client.Namespace = "urn:" + namespace
if c... | [
"func",
"(",
"c",
"*",
"Client",
")",
"NewServiceClient",
"(",
"path",
"string",
",",
"namespace",
"string",
")",
"*",
"Client",
"{",
"vc",
":=",
"c",
".",
"URL",
"(",
")",
"\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"path",
")",
"\n",... | // NewServiceClient creates a NewClient with the given URL.Path and namespace. | [
"NewServiceClient",
"creates",
"a",
"NewClient",
"with",
"the",
"given",
"URL",
".",
"Path",
"and",
"namespace",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L159-L200 | train |
vmware/govmomi | vim25/soap/client.go | hostAddr | func hostAddr(addr string) string {
_, port := splitHostPort(addr)
if port == "" {
return addr + ":443"
}
return addr
} | go | func hostAddr(addr string) string {
_, port := splitHostPort(addr)
if port == "" {
return addr + ":443"
}
return addr
} | [
"func",
"hostAddr",
"(",
"addr",
"string",
")",
"string",
"{",
"_",
",",
"port",
":=",
"splitHostPort",
"(",
"addr",
")",
"\n",
"if",
"port",
"==",
"\"",
"\"",
"{",
"return",
"addr",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"addr",
"\n",
"}"
] | // Add default https port if missing | [
"Add",
"default",
"https",
"port",
"if",
"missing"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L229-L235 | train |
vmware/govmomi | vim25/soap/client.go | Thumbprint | func (c *Client) Thumbprint(host string) string {
host = hostAddr(host)
c.hostsMu.Lock()
defer c.hostsMu.Unlock()
return c.hosts[host]
} | go | func (c *Client) Thumbprint(host string) string {
host = hostAddr(host)
c.hostsMu.Lock()
defer c.hostsMu.Unlock()
return c.hosts[host]
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Thumbprint",
"(",
"host",
"string",
")",
"string",
"{",
"host",
"=",
"hostAddr",
"(",
"host",
")",
"\n",
"c",
".",
"hostsMu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"hostsMu",
".",
"Unlock",
"(",
")... | // Thumbprint returns the certificate thumbprint for the given host if known to this client. | [
"Thumbprint",
"returns",
"the",
"certificate",
"thumbprint",
"for",
"the",
"given",
"host",
"if",
"known",
"to",
"this",
"client",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L256-L261 | train |
vmware/govmomi | vim25/soap/client.go | LoadThumbprints | func (c *Client) LoadThumbprints(file string) error {
if file == "" {
return nil
}
for _, name := range filepath.SplitList(file) {
err := c.loadThumbprints(name)
if err != nil {
return err
}
}
return nil
} | go | func (c *Client) LoadThumbprints(file string) error {
if file == "" {
return nil
}
for _, name := range filepath.SplitList(file) {
err := c.loadThumbprints(name)
if err != nil {
return err
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"LoadThumbprints",
"(",
"file",
"string",
")",
"error",
"{",
"if",
"file",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"name",
":=",
"range",
"filepath",
".",
"SplitList",
"(",
"... | // LoadThumbprints from file with the give name.
// If name is empty or name does not exist this function will return nil. | [
"LoadThumbprints",
"from",
"file",
"with",
"the",
"give",
"name",
".",
"If",
"name",
"is",
"empty",
"or",
"name",
"does",
"not",
"exist",
"this",
"function",
"will",
"return",
"nil",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L265-L278 | train |
vmware/govmomi | vim25/soap/client.go | WithHeader | func (c *Client) WithHeader(ctx context.Context, header Header) context.Context {
return context.WithValue(ctx, headerContext{}, header)
} | go | func (c *Client) WithHeader(ctx context.Context, header Header) context.Context {
return context.WithValue(ctx, headerContext{}, header)
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"WithHeader",
"(",
"ctx",
"context",
".",
"Context",
",",
"header",
"Header",
")",
"context",
".",
"Context",
"{",
"return",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"headerContext",
"{",
"}",
",",
"header",
"... | // WithHeader can be used to modify the outgoing request soap.Header fields. | [
"WithHeader",
"can",
"be",
"used",
"to",
"modify",
"the",
"outgoing",
"request",
"soap",
".",
"Header",
"fields",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L511-L513 | train |
vmware/govmomi | vim25/soap/client.go | Upload | func (c *Client) Upload(ctx context.Context, f io.Reader, u *url.URL, param *Upload) error {
var err error
if param.Progress != nil {
pr := progress.NewReader(ctx, param.Progress, f, param.ContentLength)
f = pr
// Mark progress reader as done when returning from this function.
defer func() {
pr.Done(err)... | go | func (c *Client) Upload(ctx context.Context, f io.Reader, u *url.URL, param *Upload) error {
var err error
if param.Progress != nil {
pr := progress.NewReader(ctx, param.Progress, f, param.ContentLength)
f = pr
// Mark progress reader as done when returning from this function.
defer func() {
pr.Done(err)... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Upload",
"(",
"ctx",
"context",
".",
"Context",
",",
"f",
"io",
".",
"Reader",
",",
"u",
"*",
"url",
".",
"URL",
",",
"param",
"*",
"Upload",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"param",
... | // Upload PUTs the local file to the given URL | [
"Upload",
"PUTs",
"the",
"local",
"file",
"to",
"the",
"given",
"URL"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L625-L671 | train |
vmware/govmomi | vim25/soap/client.go | UploadFile | func (c *Client) UploadFile(ctx context.Context, file string, u *url.URL, param *Upload) error {
if param == nil {
p := DefaultUpload // Copy since we set ContentLength
param = &p
}
s, err := os.Stat(file)
if err != nil {
return err
}
f, err := os.Open(filepath.Clean(file))
if err != nil {
return err
... | go | func (c *Client) UploadFile(ctx context.Context, file string, u *url.URL, param *Upload) error {
if param == nil {
p := DefaultUpload // Copy since we set ContentLength
param = &p
}
s, err := os.Stat(file)
if err != nil {
return err
}
f, err := os.Open(filepath.Clean(file))
if err != nil {
return err
... | [
"func",
"(",
"c",
"*",
"Client",
")",
"UploadFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"file",
"string",
",",
"u",
"*",
"url",
".",
"URL",
",",
"param",
"*",
"Upload",
")",
"error",
"{",
"if",
"param",
"==",
"nil",
"{",
"p",
":=",
"Defau... | // UploadFile PUTs the local file to the given URL | [
"UploadFile",
"PUTs",
"the",
"local",
"file",
"to",
"the",
"given",
"URL"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L674-L694 | train |
vmware/govmomi | vim25/soap/client.go | DownloadRequest | func (c *Client) DownloadRequest(ctx context.Context, u *url.URL, param *Download) (*http.Response, error) {
req, err := http.NewRequest(param.Method, u.String(), nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
for k, v := range param.Headers {
req.Header.Add(k, v)
}
if param.Ticket != n... | go | func (c *Client) DownloadRequest(ctx context.Context, u *url.URL, param *Download) (*http.Response, error) {
req, err := http.NewRequest(param.Method, u.String(), nil)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
for k, v := range param.Headers {
req.Header.Add(k, v)
}
if param.Ticket != n... | [
"func",
"(",
"c",
"*",
"Client",
")",
"DownloadRequest",
"(",
"ctx",
"context",
".",
"Context",
",",
"u",
"*",
"url",
".",
"URL",
",",
"param",
"*",
"Download",
")",
"(",
"*",
"http",
".",
"Response",
",",
"error",
")",
"{",
"req",
",",
"err",
":... | // DownloadRequest wraps http.Client.Do, returning the http.Response without checking its StatusCode | [
"DownloadRequest",
"wraps",
"http",
".",
"Client",
".",
"Do",
"returning",
"the",
"http",
".",
"Response",
"without",
"checking",
"its",
"StatusCode"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L709-L726 | train |
vmware/govmomi | vim25/soap/client.go | Download | func (c *Client) Download(ctx context.Context, u *url.URL, param *Download) (io.ReadCloser, int64, error) {
res, err := c.DownloadRequest(ctx, u, param)
if err != nil {
return nil, 0, err
}
switch res.StatusCode {
case http.StatusOK:
default:
err = errors.New(res.Status)
}
if err != nil {
return nil, 0,... | go | func (c *Client) Download(ctx context.Context, u *url.URL, param *Download) (io.ReadCloser, int64, error) {
res, err := c.DownloadRequest(ctx, u, param)
if err != nil {
return nil, 0, err
}
switch res.StatusCode {
case http.StatusOK:
default:
err = errors.New(res.Status)
}
if err != nil {
return nil, 0,... | [
"func",
"(",
"c",
"*",
"Client",
")",
"Download",
"(",
"ctx",
"context",
".",
"Context",
",",
"u",
"*",
"url",
".",
"URL",
",",
"param",
"*",
"Download",
")",
"(",
"io",
".",
"ReadCloser",
",",
"int64",
",",
"error",
")",
"{",
"res",
",",
"err",
... | // Download GETs the remote file from the given URL | [
"Download",
"GETs",
"the",
"remote",
"file",
"from",
"the",
"given",
"URL"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L729-L748 | train |
vmware/govmomi | vim25/soap/client.go | DownloadFile | func (c *Client) DownloadFile(ctx context.Context, file string, u *url.URL, param *Download) error {
var err error
if param == nil {
param = &DefaultDownload
}
rc, contentLength, err := c.Download(ctx, u, param)
if err != nil {
return err
}
return c.WriteFile(ctx, file, rc, contentLength, param.Progress, p... | go | func (c *Client) DownloadFile(ctx context.Context, file string, u *url.URL, param *Download) error {
var err error
if param == nil {
param = &DefaultDownload
}
rc, contentLength, err := c.Download(ctx, u, param)
if err != nil {
return err
}
return c.WriteFile(ctx, file, rc, contentLength, param.Progress, p... | [
"func",
"(",
"c",
"*",
"Client",
")",
"DownloadFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"file",
"string",
",",
"u",
"*",
"url",
".",
"URL",
",",
"param",
"*",
"Download",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"param",
"=="... | // DownloadFile GETs the given URL to a local file | [
"DownloadFile",
"GETs",
"the",
"given",
"URL",
"to",
"a",
"local",
"file"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/soap/client.go#L788-L800 | train |
vmware/govmomi | toolbox/process.go | WithIO | func (p *Process) WithIO() *Process {
p.IO = &ProcessIO{
Out: new(bytes.Buffer),
Err: new(bytes.Buffer),
}
return p
} | go | func (p *Process) WithIO() *Process {
p.IO = &ProcessIO{
Out: new(bytes.Buffer),
Err: new(bytes.Buffer),
}
return p
} | [
"func",
"(",
"p",
"*",
"Process",
")",
"WithIO",
"(",
")",
"*",
"Process",
"{",
"p",
".",
"IO",
"=",
"&",
"ProcessIO",
"{",
"Out",
":",
"new",
"(",
"bytes",
".",
"Buffer",
")",
",",
"Err",
":",
"new",
"(",
"bytes",
".",
"Buffer",
")",
",",
"}... | // WithIO enables toolbox Process IO without file system disk IO. | [
"WithIO",
"enables",
"toolbox",
"Process",
"IO",
"without",
"file",
"system",
"disk",
"IO",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L110-L117 | train |
vmware/govmomi | toolbox/process.go | NewProcessManager | func NewProcessManager() *ProcessManager {
// We use pseudo PIDs that don't conflict with OS PIDs, so they can live in the same table.
// For the pseudo PIDs, we use a sync.Pool rather than a plain old counter to avoid the unlikely,
// but possible wrapping should such a counter exceed MaxInt64.
pid := int64(32768)... | go | func NewProcessManager() *ProcessManager {
// We use pseudo PIDs that don't conflict with OS PIDs, so they can live in the same table.
// For the pseudo PIDs, we use a sync.Pool rather than a plain old counter to avoid the unlikely,
// but possible wrapping should such a counter exceed MaxInt64.
pid := int64(32768)... | [
"func",
"NewProcessManager",
"(",
")",
"*",
"ProcessManager",
"{",
"// We use pseudo PIDs that don't conflict with OS PIDs, so they can live in the same table.",
"// For the pseudo PIDs, we use a sync.Pool rather than a plain old counter to avoid the unlikely,",
"// but possible wrapping should su... | // NewProcessManager creates a new ProcessManager instance. | [
"NewProcessManager",
"creates",
"a",
"new",
"ProcessManager",
"instance",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L221-L236 | train |
vmware/govmomi | toolbox/process.go | Start | func (m *ProcessManager) Start(r *vix.StartProgramRequest, p *Process) (int64, error) {
p.Name = r.ProgramPath
p.Args = r.Arguments
// Owner is cosmetic, but useful for example with: govc guest.ps -U $uid
if p.Owner == "" {
p.Owner = defaultOwner
}
p.StartTime = time.Now().Unix()
p.ctx, p.Kill = context.Wit... | go | func (m *ProcessManager) Start(r *vix.StartProgramRequest, p *Process) (int64, error) {
p.Name = r.ProgramPath
p.Args = r.Arguments
// Owner is cosmetic, but useful for example with: govc guest.ps -U $uid
if p.Owner == "" {
p.Owner = defaultOwner
}
p.StartTime = time.Now().Unix()
p.ctx, p.Kill = context.Wit... | [
"func",
"(",
"m",
"*",
"ProcessManager",
")",
"Start",
"(",
"r",
"*",
"vix",
".",
"StartProgramRequest",
",",
"p",
"*",
"Process",
")",
"(",
"int64",
",",
"error",
")",
"{",
"p",
".",
"Name",
"=",
"r",
".",
"ProgramPath",
"\n",
"p",
".",
"Args",
... | // Start calls the Process.Start function, returning the pid on success or an error.
// A goroutine is started that calls the Process.Wait function. After Process.Wait has
// returned, the ProcessState EndTime and ExitCode fields are set. The process state can be
// queried via ListProcessesInGuest until it is remove... | [
"Start",
"calls",
"the",
"Process",
".",
"Start",
"function",
"returning",
"the",
"pid",
"on",
"success",
"or",
"an",
"error",
".",
"A",
"goroutine",
"is",
"started",
"that",
"calls",
"the",
"Process",
".",
"Wait",
"function",
".",
"After",
"Process",
".",... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L242-L303 | train |
vmware/govmomi | toolbox/process.go | Kill | func (m *ProcessManager) Kill(pid int64) bool {
m.mu.Lock()
entry, ok := m.entries[pid]
m.mu.Unlock()
if ok {
entry.Kill()
return true
}
return false
} | go | func (m *ProcessManager) Kill(pid int64) bool {
m.mu.Lock()
entry, ok := m.entries[pid]
m.mu.Unlock()
if ok {
entry.Kill()
return true
}
return false
} | [
"func",
"(",
"m",
"*",
"ProcessManager",
")",
"Kill",
"(",
"pid",
"int64",
")",
"bool",
"{",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"entry",
",",
"ok",
":=",
"m",
".",
"entries",
"[",
"pid",
"]",
"\n",
"m",
".",
"mu",
".",
"Unlock",
"("... | // Kill cancels the Process Context.
// Returns true if pid exists in the process table, false otherwise. | [
"Kill",
"cancels",
"the",
"Process",
"Context",
".",
"Returns",
"true",
"if",
"pid",
"exists",
"in",
"the",
"process",
"table",
"false",
"otherwise",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L307-L318 | train |
vmware/govmomi | toolbox/process.go | ListProcesses | func (m *ProcessManager) ListProcesses(pids []int64) []byte {
w := new(bytes.Buffer)
m.mu.Lock()
if len(pids) == 0 {
for _, p := range m.entries {
_, _ = w.WriteString(p.toXML())
}
} else {
for _, id := range pids {
p, ok := m.entries[id]
if !ok {
continue
}
_, _ = w.WriteString(p.toXML(... | go | func (m *ProcessManager) ListProcesses(pids []int64) []byte {
w := new(bytes.Buffer)
m.mu.Lock()
if len(pids) == 0 {
for _, p := range m.entries {
_, _ = w.WriteString(p.toXML())
}
} else {
for _, id := range pids {
p, ok := m.entries[id]
if !ok {
continue
}
_, _ = w.WriteString(p.toXML(... | [
"func",
"(",
"m",
"*",
"ProcessManager",
")",
"ListProcesses",
"(",
"pids",
"[",
"]",
"int64",
")",
"[",
"]",
"byte",
"{",
"w",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"m",
".",
"mu",
".",
"Lock",
"(",
")",
"\n\n",
"if",
"len",
"... | // ListProcesses marshals the ProcessState for the given pids.
// If no pids are specified, all current processes are included.
// The return value can be used for responding to a VixMsgListProcessesExRequest. | [
"ListProcesses",
"marshals",
"the",
"ProcessState",
"for",
"the",
"given",
"pids",
".",
"If",
"no",
"pids",
"are",
"specified",
"all",
"current",
"processes",
"are",
"included",
".",
"The",
"return",
"value",
"can",
"be",
"used",
"for",
"responding",
"to",
"... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L323-L346 | train |
vmware/govmomi | toolbox/process.go | Stat | func (m *ProcessManager) Stat(u *url.URL) (os.FileInfo, error) {
name := path.Join("/proc", u.Path)
info, err := os.Stat(name)
if err == nil && info.Size() == 0 {
// This is a real /proc file
return &procFileInfo{info}, nil
}
dir, file := path.Split(u.Path)
pid, err := strconv.ParseInt(path.Base(dir), 10, ... | go | func (m *ProcessManager) Stat(u *url.URL) (os.FileInfo, error) {
name := path.Join("/proc", u.Path)
info, err := os.Stat(name)
if err == nil && info.Size() == 0 {
// This is a real /proc file
return &procFileInfo{info}, nil
}
dir, file := path.Split(u.Path)
pid, err := strconv.ParseInt(path.Base(dir), 10, ... | [
"func",
"(",
"m",
"*",
"ProcessManager",
")",
"Stat",
"(",
"u",
"*",
"url",
".",
"URL",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"name",
":=",
"path",
".",
"Join",
"(",
"\"",
"\"",
",",
"u",
".",
"Path",
")",
"\n\n",
"info",
"... | // Stat implements hgfs.FileHandler.Stat | [
"Stat",
"implements",
"hgfs",
".",
"FileHandler",
".",
"Stat"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L359-L424 | train |
vmware/govmomi | toolbox/process.go | Open | func (m *ProcessManager) Open(u *url.URL, mode int32) (hgfs.File, error) {
info, err := m.Stat(u)
if err != nil {
return nil, err
}
pinfo, ok := info.(*ProcessFile)
if !ok {
return nil, os.ErrNotExist // fall through to default os.Open
}
switch path.Base(u.Path) {
case "stdin":
if mode != hgfs.OpenMode... | go | func (m *ProcessManager) Open(u *url.URL, mode int32) (hgfs.File, error) {
info, err := m.Stat(u)
if err != nil {
return nil, err
}
pinfo, ok := info.(*ProcessFile)
if !ok {
return nil, os.ErrNotExist // fall through to default os.Open
}
switch path.Base(u.Path) {
case "stdin":
if mode != hgfs.OpenMode... | [
"func",
"(",
"m",
"*",
"ProcessManager",
")",
"Open",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"mode",
"int32",
")",
"(",
"hgfs",
".",
"File",
",",
"error",
")",
"{",
"info",
",",
"err",
":=",
"m",
".",
"Stat",
"(",
"u",
")",
"\n",
"if",
"err",... | // Open implements hgfs.FileHandler.Open | [
"Open",
"implements",
"hgfs",
".",
"FileHandler",
".",
"Open"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L427-L451 | train |
vmware/govmomi | toolbox/process.go | NewProcessFunc | func NewProcessFunc(run func(ctx context.Context, args string) error) *Process {
f := &processFunc{run: run}
return &Process{
Start: f.start,
Wait: f.wait,
}
} | go | func NewProcessFunc(run func(ctx context.Context, args string) error) *Process {
f := &processFunc{run: run}
return &Process{
Start: f.start,
Wait: f.wait,
}
} | [
"func",
"NewProcessFunc",
"(",
"run",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"args",
"string",
")",
"error",
")",
"*",
"Process",
"{",
"f",
":=",
"&",
"processFunc",
"{",
"run",
":",
"run",
"}",
"\n\n",
"return",
"&",
"Process",
"{",
"St... | // NewProcessFunc creates a new Process, where the Start function calls the given run function within a goroutine.
// The Wait function waits for the goroutine to finish and returns the error returned by run.
// The run ctx param may be used to return early via the ProcessManager.Kill method.
// The run args command is... | [
"NewProcessFunc",
"creates",
"a",
"new",
"Process",
"where",
"the",
"Start",
"function",
"calls",
"the",
"given",
"run",
"function",
"within",
"a",
"goroutine",
".",
"The",
"Wait",
"function",
"waits",
"for",
"the",
"goroutine",
"to",
"finish",
"and",
"returns... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L465-L472 | train |
vmware/govmomi | toolbox/process.go | NewProcessRoundTrip | func NewProcessRoundTrip() *Process {
return NewProcessFunc(func(ctx context.Context, host string) error {
p, _ := ctx.Value(ProcessFuncIO).(*ProcessIO)
closers := []io.Closer{p.In.Closer}
defer func() {
for _, c := range closers {
_ = c.Close()
}
}()
c, err := new(net.Dialer).DialContext(ctx, "... | go | func NewProcessRoundTrip() *Process {
return NewProcessFunc(func(ctx context.Context, host string) error {
p, _ := ctx.Value(ProcessFuncIO).(*ProcessIO)
closers := []io.Closer{p.In.Closer}
defer func() {
for _, c := range closers {
_ = c.Close()
}
}()
c, err := new(net.Dialer).DialContext(ctx, "... | [
"func",
"NewProcessRoundTrip",
"(",
")",
"*",
"Process",
"{",
"return",
"NewProcessFunc",
"(",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"host",
"string",
")",
"error",
"{",
"p",
",",
"_",
":=",
"ctx",
".",
"Value",
"(",
"ProcessFuncIO",
")",
... | // NewProcessRoundTrip starts a Go function to implement a toolbox backed http.RoundTripper | [
"NewProcessRoundTrip",
"starts",
"a",
"Go",
"function",
"to",
"implement",
"a",
"toolbox",
"backed",
"http",
".",
"RoundTripper"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/process.go#L593-L631 | train |
vmware/govmomi | vim25/progress/reader.go | Read | func (r *reader) Read(b []byte) (int, error) {
n, err := r.r.Read(b)
r.pos += int64(n)
if err != nil && err != io.EOF {
return n, err
}
q := readerReport{
t: time.Now(),
pos: r.pos,
size: r.size,
bps: &r.bps,
}
select {
case r.ch <- q:
case <-r.ctx.Done():
}
return n, err
} | go | func (r *reader) Read(b []byte) (int, error) {
n, err := r.r.Read(b)
r.pos += int64(n)
if err != nil && err != io.EOF {
return n, err
}
q := readerReport{
t: time.Now(),
pos: r.pos,
size: r.size,
bps: &r.bps,
}
select {
case r.ch <- q:
case <-r.ctx.Done():
}
return n, err
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"r",
".",
"r",
".",
"Read",
"(",
"b",
")",
"\n",
"r",
".",
"pos",
"+=",
"int64",
"(",
"n",
")",
"\... | // Read calls the Read function on the underlying io.Reader. Additionally,
// every read causes a progress report to be sent to the progress reader's
// underlying channel. | [
"Read",
"calls",
"the",
"Read",
"function",
"on",
"the",
"underlying",
"io",
".",
"Reader",
".",
"Additionally",
"every",
"read",
"causes",
"a",
"progress",
"report",
"to",
"be",
"sent",
"to",
"the",
"progress",
"reader",
"s",
"underlying",
"channel",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/progress/reader.go#L101-L122 | train |
vmware/govmomi | vim25/progress/reader.go | Done | func (r *reader) Done(err error) {
q := readerReport{
t: time.Now(),
pos: r.pos,
size: r.size,
bps: &r.bps,
err: err,
}
select {
case r.ch <- q:
close(r.ch)
case <-r.ctx.Done():
}
} | go | func (r *reader) Done(err error) {
q := readerReport{
t: time.Now(),
pos: r.pos,
size: r.size,
bps: &r.bps,
err: err,
}
select {
case r.ch <- q:
close(r.ch)
case <-r.ctx.Done():
}
} | [
"func",
"(",
"r",
"*",
"reader",
")",
"Done",
"(",
"err",
"error",
")",
"{",
"q",
":=",
"readerReport",
"{",
"t",
":",
"time",
".",
"Now",
"(",
")",
",",
"pos",
":",
"r",
".",
"pos",
",",
"size",
":",
"r",
".",
"size",
",",
"bps",
":",
"&",... | // Done marks the progress reader as done, optionally including an error in the
// progress report. After sending it, the underlying channel is closed. | [
"Done",
"marks",
"the",
"progress",
"reader",
"as",
"done",
"optionally",
"including",
"an",
"error",
"in",
"the",
"progress",
"report",
".",
"After",
"sending",
"it",
"the",
"underlying",
"channel",
"is",
"closed",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/progress/reader.go#L126-L140 | train |
vmware/govmomi | vim25/progress/reader.go | newBpsLoop | func newBpsLoop(dst *uint64) SinkFunc {
fn := func() chan<- Report {
sink := make(chan Report)
go bpsLoop(sink, dst)
return sink
}
return fn
} | go | func newBpsLoop(dst *uint64) SinkFunc {
fn := func() chan<- Report {
sink := make(chan Report)
go bpsLoop(sink, dst)
return sink
}
return fn
} | [
"func",
"newBpsLoop",
"(",
"dst",
"*",
"uint64",
")",
"SinkFunc",
"{",
"fn",
":=",
"func",
"(",
")",
"chan",
"<-",
"Report",
"{",
"sink",
":=",
"make",
"(",
"chan",
"Report",
")",
"\n",
"go",
"bpsLoop",
"(",
"sink",
",",
"dst",
")",
"\n",
"return",... | // newBpsLoop returns a sink that monitors and stores throughput. | [
"newBpsLoop",
"returns",
"a",
"sink",
"that",
"monitors",
"and",
"stores",
"throughput",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/progress/reader.go#L143-L151 | train |
vmware/govmomi | vmdk/import.go | stat | func stat(name string) (*info, error) {
f, err := os.Open(filepath.Clean(name))
if err != nil {
return nil, err
}
var di info
var buf bytes.Buffer
_, err = io.CopyN(&buf, f, int64(binary.Size(di.Header)))
if err != nil {
return nil, err
}
fi, err := f.Stat()
if err != nil {
return nil, err
}
err ... | go | func stat(name string) (*info, error) {
f, err := os.Open(filepath.Clean(name))
if err != nil {
return nil, err
}
var di info
var buf bytes.Buffer
_, err = io.CopyN(&buf, f, int64(binary.Size(di.Header)))
if err != nil {
return nil, err
}
fi, err := f.Stat()
if err != nil {
return nil, err
}
err ... | [
"func",
"stat",
"(",
"name",
"string",
")",
"(",
"*",
"info",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filepath",
".",
"Clean",
"(",
"name",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"... | // stat looks at the vmdk header to make sure the format is streamOptimized and
// extracts the disk capacity required to properly generate the ovf descriptor. | [
"stat",
"looks",
"at",
"the",
"vmdk",
"header",
"to",
"make",
"sure",
"the",
"format",
"is",
"streamOptimized",
"and",
"extracts",
"the",
"disk",
"capacity",
"required",
"to",
"properly",
"generate",
"the",
"ovf",
"descriptor",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vmdk/import.go#L61-L108 | train |
vmware/govmomi | vmdk/import.go | ovf | func (di *info) ovf() (string, error) {
var buf bytes.Buffer
tmpl, err := template.New("ovf").Parse(ovfenv)
if err != nil {
return "", err
}
err = tmpl.Execute(&buf, di)
if err != nil {
return "", err
}
return buf.String(), nil
} | go | func (di *info) ovf() (string, error) {
var buf bytes.Buffer
tmpl, err := template.New("ovf").Parse(ovfenv)
if err != nil {
return "", err
}
err = tmpl.Execute(&buf, di)
if err != nil {
return "", err
}
return buf.String(), nil
} | [
"func",
"(",
"di",
"*",
"info",
")",
"ovf",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n\n",
"tmpl",
",",
"err",
":=",
"template",
".",
"New",
"(",
"\"",
"\"",
")",
".",
"Parse",
"(",
"ovfenv",
")",... | // ovf returns an expanded descriptor template | [
"ovf",
"returns",
"an",
"expanded",
"descriptor",
"template"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vmdk/import.go#L178-L192 | train |
vmware/govmomi | examples/examples.go | getEnvString | func getEnvString(v string, def string) string {
r := os.Getenv(v)
if r == "" {
return def
}
return r
} | go | func getEnvString(v string, def string) string {
r := os.Getenv(v)
if r == "" {
return def
}
return r
} | [
"func",
"getEnvString",
"(",
"v",
"string",
",",
"def",
"string",
")",
"string",
"{",
"r",
":=",
"os",
".",
"Getenv",
"(",
"v",
")",
"\n",
"if",
"r",
"==",
"\"",
"\"",
"{",
"return",
"def",
"\n",
"}",
"\n\n",
"return",
"r",
"\n",
"}"
] | // getEnvString returns string from environment variable. | [
"getEnvString",
"returns",
"string",
"from",
"environment",
"variable",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/examples/examples.go#L33-L40 | train |
vmware/govmomi | examples/examples.go | getEnvBool | func getEnvBool(v string, def bool) bool {
r := os.Getenv(v)
if r == "" {
return def
}
switch strings.ToLower(r[0:1]) {
case "t", "y", "1":
return true
}
return false
} | go | func getEnvBool(v string, def bool) bool {
r := os.Getenv(v)
if r == "" {
return def
}
switch strings.ToLower(r[0:1]) {
case "t", "y", "1":
return true
}
return false
} | [
"func",
"getEnvBool",
"(",
"v",
"string",
",",
"def",
"bool",
")",
"bool",
"{",
"r",
":=",
"os",
".",
"Getenv",
"(",
"v",
")",
"\n",
"if",
"r",
"==",
"\"",
"\"",
"{",
"return",
"def",
"\n",
"}",
"\n\n",
"switch",
"strings",
".",
"ToLower",
"(",
... | // getEnvBool returns boolean from environment variable. | [
"getEnvBool",
"returns",
"boolean",
"from",
"environment",
"variable",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/examples/examples.go#L43-L55 | train |
vmware/govmomi | examples/examples.go | NewClient | func NewClient(ctx context.Context) (*govmomi.Client, error) {
flag.Parse()
// Parse URL from string
u, err := soap.ParseURL(*urlFlag)
if err != nil {
return nil, err
}
// Override username and/or password as required
processOverride(u)
// Connect and log in to ESX or vCenter
return govmomi.NewClient(ctx,... | go | func NewClient(ctx context.Context) (*govmomi.Client, error) {
flag.Parse()
// Parse URL from string
u, err := soap.ParseURL(*urlFlag)
if err != nil {
return nil, err
}
// Override username and/or password as required
processOverride(u)
// Connect and log in to ESX or vCenter
return govmomi.NewClient(ctx,... | [
"func",
"NewClient",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"govmomi",
".",
"Client",
",",
"error",
")",
"{",
"flag",
".",
"Parse",
"(",
")",
"\n\n",
"// Parse URL from string",
"u",
",",
"err",
":=",
"soap",
".",
"ParseURL",
"(",
"*",
... | // NewClient creates a govmomi.Client for use in the examples | [
"NewClient",
"creates",
"a",
"govmomi",
".",
"Client",
"for",
"use",
"in",
"the",
"examples"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/examples/examples.go#L103-L117 | train |
vmware/govmomi | task/wait.go | Wait | func Wait(ctx context.Context, ref types.ManagedObjectReference, pc *property.Collector, s progress.Sinker) (*types.TaskInfo, error) {
cb := &taskCallback{}
// Include progress sink if specified
if s != nil {
cb.ch = s.Sink()
defer close(cb.ch)
}
err := property.Wait(ctx, pc, ref, []string{"info"}, cb.fn)
i... | go | func Wait(ctx context.Context, ref types.ManagedObjectReference, pc *property.Collector, s progress.Sinker) (*types.TaskInfo, error) {
cb := &taskCallback{}
// Include progress sink if specified
if s != nil {
cb.ch = s.Sink()
defer close(cb.ch)
}
err := property.Wait(ctx, pc, ref, []string{"info"}, cb.fn)
i... | [
"func",
"Wait",
"(",
"ctx",
"context",
".",
"Context",
",",
"ref",
"types",
".",
"ManagedObjectReference",
",",
"pc",
"*",
"property",
".",
"Collector",
",",
"s",
"progress",
".",
"Sinker",
")",
"(",
"*",
"types",
".",
"TaskInfo",
",",
"error",
")",
"{... | // Wait waits for a task to finish with either success or failure. It does so
// by waiting for the "info" property of task managed object to change. The
// function returns when it finds the task in the "success" or "error" state.
// In the former case, the return value is nil. In the latter case the return
// value i... | [
"Wait",
"waits",
"for",
"a",
"task",
"to",
"finish",
"with",
"either",
"success",
"or",
"failure",
".",
"It",
"does",
"so",
"by",
"waiting",
"for",
"the",
"info",
"property",
"of",
"task",
"managed",
"object",
"to",
"change",
".",
"The",
"function",
"ret... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/task/wait.go#L117-L132 | train |
vmware/govmomi | object/datastore_file.go | Open | func (d Datastore) Open(ctx context.Context, name string) (*DatastoreFile, error) {
return &DatastoreFile{
d: d,
name: name,
length: -1,
ctx: ctx,
}, nil
} | go | func (d Datastore) Open(ctx context.Context, name string) (*DatastoreFile, error) {
return &DatastoreFile{
d: d,
name: name,
length: -1,
ctx: ctx,
}, nil
} | [
"func",
"(",
"d",
"Datastore",
")",
"Open",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
")",
"(",
"*",
"DatastoreFile",
",",
"error",
")",
"{",
"return",
"&",
"DatastoreFile",
"{",
"d",
":",
"d",
",",
"name",
":",
"name",
",",
"le... | // Open opens the named file relative to the Datastore. | [
"Open",
"opens",
"the",
"named",
"file",
"relative",
"to",
"the",
"Datastore",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file.go#L49-L56 | train |
vmware/govmomi | object/datastore_file.go | Close | func (f *DatastoreFile) Close() error {
var err error
if f.body != nil {
err = f.body.Close()
f.body = nil
}
f.buf = nil
return err
} | go | func (f *DatastoreFile) Close() error {
var err error
if f.body != nil {
err = f.body.Close()
f.body = nil
}
f.buf = nil
return err
} | [
"func",
"(",
"f",
"*",
"DatastoreFile",
")",
"Close",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"if",
"f",
".",
"body",
"!=",
"nil",
"{",
"err",
"=",
"f",
".",
"body",
".",
"Close",
"(",
")",
"\n",
"f",
".",
"body",
"=",
"nil",
"... | // Close closes the DatastoreFile. | [
"Close",
"closes",
"the",
"DatastoreFile",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file.go#L90-L101 | train |
vmware/govmomi | object/datastore_file.go | Seek | func (f *DatastoreFile) Seek(offset int64, whence int) (int64, error) {
switch whence {
case io.SeekStart:
case io.SeekCurrent:
offset += f.offset.seek
case io.SeekEnd:
if f.length < 0 {
_, err := f.Stat()
if err != nil {
return 0, err
}
}
offset += f.length
default:
return 0, errors.New("Se... | go | func (f *DatastoreFile) Seek(offset int64, whence int) (int64, error) {
switch whence {
case io.SeekStart:
case io.SeekCurrent:
offset += f.offset.seek
case io.SeekEnd:
if f.length < 0 {
_, err := f.Stat()
if err != nil {
return 0, err
}
}
offset += f.length
default:
return 0, errors.New("Se... | [
"func",
"(",
"f",
"*",
"DatastoreFile",
")",
"Seek",
"(",
"offset",
"int64",
",",
"whence",
"int",
")",
"(",
"int64",
",",
"error",
")",
"{",
"switch",
"whence",
"{",
"case",
"io",
".",
"SeekStart",
":",
"case",
"io",
".",
"SeekCurrent",
":",
"offset... | // Seek sets the offset for the next Read on the DatastoreFile. | [
"Seek",
"sets",
"the",
"offset",
"for",
"the",
"next",
"Read",
"on",
"the",
"DatastoreFile",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file.go#L104-L129 | train |
vmware/govmomi | object/datastore_file.go | Stat | func (f *DatastoreFile) Stat() (os.FileInfo, error) {
// TODO: consider using Datastore.Stat() instead
u, p, err := f.d.downloadTicket(f.ctx, f.name, &soap.Download{Method: "HEAD"})
if err != nil {
return nil, err
}
res, err := f.d.Client().DownloadRequest(f.ctx, u, p)
if err != nil {
return nil, err
}
if... | go | func (f *DatastoreFile) Stat() (os.FileInfo, error) {
// TODO: consider using Datastore.Stat() instead
u, p, err := f.d.downloadTicket(f.ctx, f.name, &soap.Download{Method: "HEAD"})
if err != nil {
return nil, err
}
res, err := f.d.Client().DownloadRequest(f.ctx, u, p)
if err != nil {
return nil, err
}
if... | [
"func",
"(",
"f",
"*",
"DatastoreFile",
")",
"Stat",
"(",
")",
"(",
"os",
".",
"FileInfo",
",",
"error",
")",
"{",
"// TODO: consider using Datastore.Stat() instead",
"u",
",",
"p",
",",
"err",
":=",
"f",
".",
"d",
".",
"downloadTicket",
"(",
"f",
".",
... | // Stat returns the os.FileInfo interface describing file. | [
"Stat",
"returns",
"the",
"os",
".",
"FileInfo",
"interface",
"describing",
"file",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file.go#L168-L187 | train |
vmware/govmomi | object/datastore_file.go | Tail | func (f *DatastoreFile) Tail(n int) error {
return f.TailFunc(n, func(line int, _ string) bool { return n > line })
} | go | func (f *DatastoreFile) Tail(n int) error {
return f.TailFunc(n, func(line int, _ string) bool { return n > line })
} | [
"func",
"(",
"f",
"*",
"DatastoreFile",
")",
"Tail",
"(",
"n",
"int",
")",
"error",
"{",
"return",
"f",
".",
"TailFunc",
"(",
"n",
",",
"func",
"(",
"line",
"int",
",",
"_",
"string",
")",
"bool",
"{",
"return",
"n",
">",
"line",
"}",
")",
"\n"... | // Tail seeks to the position of the last N lines of the file. | [
"Tail",
"seeks",
"to",
"the",
"position",
"of",
"the",
"last",
"N",
"lines",
"of",
"the",
"file",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file.go#L260-L262 | train |
vmware/govmomi | object/datastore_file.go | TailFunc | func (f *DatastoreFile) TailFunc(lines int, include func(line int, message string) bool) error {
// Read the file in reverse using bsize chunks
const bsize = int64(1024 * 16)
fsize, err := f.Seek(0, io.SeekEnd)
if err != nil {
return err
}
if lines == 0 {
return nil
}
chunk := int64(-1)
buf := bytes.Ne... | go | func (f *DatastoreFile) TailFunc(lines int, include func(line int, message string) bool) error {
// Read the file in reverse using bsize chunks
const bsize = int64(1024 * 16)
fsize, err := f.Seek(0, io.SeekEnd)
if err != nil {
return err
}
if lines == 0 {
return nil
}
chunk := int64(-1)
buf := bytes.Ne... | [
"func",
"(",
"f",
"*",
"DatastoreFile",
")",
"TailFunc",
"(",
"lines",
"int",
",",
"include",
"func",
"(",
"line",
"int",
",",
"message",
"string",
")",
"bool",
")",
"error",
"{",
"// Read the file in reverse using bsize chunks",
"const",
"bsize",
"=",
"int64"... | // TailFunc will seek backwards in the datastore file until it hits a line that does
// not satisfy the supplied `include` function. | [
"TailFunc",
"will",
"seek",
"backwards",
"in",
"the",
"datastore",
"file",
"until",
"it",
"hits",
"a",
"line",
"that",
"does",
"not",
"satisfy",
"the",
"supplied",
"include",
"function",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file.go#L266-L343 | train |
vmware/govmomi | object/datastore_file.go | Close | func (f *followDatastoreFile) Close() error {
f.o.Do(func() { close(f.c) })
return nil
} | go | func (f *followDatastoreFile) Close() error {
f.o.Do(func() { close(f.c) })
return nil
} | [
"func",
"(",
"f",
"*",
"followDatastoreFile",
")",
"Close",
"(",
")",
"error",
"{",
"f",
".",
"o",
".",
"Do",
"(",
"func",
"(",
")",
"{",
"close",
"(",
"f",
".",
"c",
")",
"}",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // Close will stop Follow polling and close the underlying DatastoreFile. | [
"Close",
"will",
"stop",
"Follow",
"polling",
"and",
"close",
"the",
"underlying",
"DatastoreFile",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file.go#L400-L403 | train |
vmware/govmomi | object/datastore_file.go | Follow | func (f *DatastoreFile) Follow(interval time.Duration) io.ReadCloser {
return &followDatastoreFile{
r: f,
c: make(chan struct{}),
i: interval,
}
} | go | func (f *DatastoreFile) Follow(interval time.Duration) io.ReadCloser {
return &followDatastoreFile{
r: f,
c: make(chan struct{}),
i: interval,
}
} | [
"func",
"(",
"f",
"*",
"DatastoreFile",
")",
"Follow",
"(",
"interval",
"time",
".",
"Duration",
")",
"io",
".",
"ReadCloser",
"{",
"return",
"&",
"followDatastoreFile",
"{",
"r",
":",
"f",
",",
"c",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",... | // Follow returns an io.ReadCloser to stream the file contents as data is appended. | [
"Follow",
"returns",
"an",
"io",
".",
"ReadCloser",
"to",
"stream",
"the",
"file",
"contents",
"as",
"data",
"is",
"appended",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/datastore_file.go#L406-L412 | train |
vmware/govmomi | object/host_certificate_info.go | FromCertificate | func (info *HostCertificateInfo) FromCertificate(cert *x509.Certificate) *HostCertificateInfo {
info.Certificate = cert
info.subjectName = &cert.Subject
info.issuerName = &cert.Issuer
info.Issuer = info.fromName(info.issuerName)
info.NotBefore = &cert.NotBefore
info.NotAfter = &cert.NotAfter
info.Subject = info... | go | func (info *HostCertificateInfo) FromCertificate(cert *x509.Certificate) *HostCertificateInfo {
info.Certificate = cert
info.subjectName = &cert.Subject
info.issuerName = &cert.Issuer
info.Issuer = info.fromName(info.issuerName)
info.NotBefore = &cert.NotBefore
info.NotAfter = &cert.NotAfter
info.Subject = info... | [
"func",
"(",
"info",
"*",
"HostCertificateInfo",
")",
"FromCertificate",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
")",
"*",
"HostCertificateInfo",
"{",
"info",
".",
"Certificate",
"=",
"cert",
"\n",
"info",
".",
"subjectName",
"=",
"&",
"cert",
".",
"... | // FromCertificate converts x509.Certificate to HostCertificateInfo | [
"FromCertificate",
"converts",
"x509",
".",
"Certificate",
"to",
"HostCertificateInfo"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_info.go#L50-L75 | train |
vmware/govmomi | object/host_certificate_info.go | FromURL | func (info *HostCertificateInfo) FromURL(u *url.URL, config *tls.Config) error {
addr := u.Host
if !(strings.LastIndex(addr, ":") > strings.LastIndex(addr, "]")) {
addr += ":443"
}
conn, err := tls.Dial("tcp", addr, config)
if err != nil {
switch err.(type) {
case x509.UnknownAuthorityError:
case x509.Hos... | go | func (info *HostCertificateInfo) FromURL(u *url.URL, config *tls.Config) error {
addr := u.Host
if !(strings.LastIndex(addr, ":") > strings.LastIndex(addr, "]")) {
addr += ":443"
}
conn, err := tls.Dial("tcp", addr, config)
if err != nil {
switch err.(type) {
case x509.UnknownAuthorityError:
case x509.Hos... | [
"func",
"(",
"info",
"*",
"HostCertificateInfo",
")",
"FromURL",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"config",
"*",
"tls",
".",
"Config",
")",
"error",
"{",
"addr",
":=",
"u",
".",
"Host",
"\n",
"if",
"!",
"(",
"strings",
".",
"LastIndex",
"(",
... | // FromURL connects to the given URL.Host via tls.Dial with the given tls.Config and populates the HostCertificateInfo
// via tls.ConnectionState. If the certificate was verified with the given tls.Config, the Err field will be nil.
// Otherwise, Err will be set to the x509.UnknownAuthorityError or x509.HostnameError.... | [
"FromURL",
"connects",
"to",
"the",
"given",
"URL",
".",
"Host",
"via",
"tls",
".",
"Dial",
"with",
"the",
"given",
"tls",
".",
"Config",
"and",
"populates",
"the",
"HostCertificateInfo",
"via",
"tls",
".",
"ConnectionState",
".",
"If",
"the",
"certificate",... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_info.go#L81-L111 | train |
vmware/govmomi | object/host_certificate_info.go | SubjectName | func (info *HostCertificateInfo) SubjectName() *pkix.Name {
if info.subjectName != nil {
return info.subjectName
}
return info.toName(info.Subject)
} | go | func (info *HostCertificateInfo) SubjectName() *pkix.Name {
if info.subjectName != nil {
return info.subjectName
}
return info.toName(info.Subject)
} | [
"func",
"(",
"info",
"*",
"HostCertificateInfo",
")",
"SubjectName",
"(",
")",
"*",
"pkix",
".",
"Name",
"{",
"if",
"info",
".",
"subjectName",
"!=",
"nil",
"{",
"return",
"info",
".",
"subjectName",
"\n",
"}",
"\n\n",
"return",
"info",
".",
"toName",
... | // SubjectName parses Subject into a pkix.Name | [
"SubjectName",
"parses",
"Subject",
"into",
"a",
"pkix",
".",
"Name"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_info.go#L187-L193 | train |
vmware/govmomi | object/host_certificate_info.go | IssuerName | func (info *HostCertificateInfo) IssuerName() *pkix.Name {
if info.issuerName != nil {
return info.issuerName
}
return info.toName(info.Issuer)
} | go | func (info *HostCertificateInfo) IssuerName() *pkix.Name {
if info.issuerName != nil {
return info.issuerName
}
return info.toName(info.Issuer)
} | [
"func",
"(",
"info",
"*",
"HostCertificateInfo",
")",
"IssuerName",
"(",
")",
"*",
"pkix",
".",
"Name",
"{",
"if",
"info",
".",
"issuerName",
"!=",
"nil",
"{",
"return",
"info",
".",
"issuerName",
"\n",
"}",
"\n\n",
"return",
"info",
".",
"toName",
"("... | // IssuerName parses Issuer into a pkix.Name | [
"IssuerName",
"parses",
"Issuer",
"into",
"a",
"pkix",
".",
"Name"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_info.go#L196-L202 | train |
vmware/govmomi | object/host_certificate_info.go | Write | func (info *HostCertificateInfo) Write(w io.Writer) error {
tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)
s := func(val string) string {
if val != "" {
return val
}
return "<Not Part Of Certificate>"
}
ss := func(val []string) string {
return s(strings.Join(val, ","))
}
name := func(n *pkix.Name) {
... | go | func (info *HostCertificateInfo) Write(w io.Writer) error {
tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0)
s := func(val string) string {
if val != "" {
return val
}
return "<Not Part Of Certificate>"
}
ss := func(val []string) string {
return s(strings.Join(val, ","))
}
name := func(n *pkix.Name) {
... | [
"func",
"(",
"info",
"*",
"HostCertificateInfo",
")",
"Write",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"tw",
":=",
"tabwriter",
".",
"NewWriter",
"(",
"w",
",",
"2",
",",
"0",
",",
"2",
",",
"' '",
",",
"0",
")",
"\n\n",
"s",
":=",
"f... | // Write outputs info similar to the Chrome Certificate Viewer. | [
"Write",
"outputs",
"info",
"similar",
"to",
"the",
"Chrome",
"Certificate",
"Viewer",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_info.go#L205-L250 | train |
vmware/govmomi | toolbox/hgfs/encoding.go | MarshalBinary | func MarshalBinary(fields ...interface{}) ([]byte, error) {
buf := new(bytes.Buffer)
for _, p := range fields {
switch m := p.(type) {
case encoding.BinaryMarshaler:
data, err := m.MarshalBinary()
if err != nil {
return nil, ProtocolError(err)
}
_, _ = buf.Write(data)
case []byte:
_, _ = bu... | go | func MarshalBinary(fields ...interface{}) ([]byte, error) {
buf := new(bytes.Buffer)
for _, p := range fields {
switch m := p.(type) {
case encoding.BinaryMarshaler:
data, err := m.MarshalBinary()
if err != nil {
return nil, ProtocolError(err)
}
_, _ = buf.Write(data)
case []byte:
_, _ = bu... | [
"func",
"MarshalBinary",
"(",
"fields",
"...",
"interface",
"{",
"}",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"fields",
"{",
"switch",
... | // MarshalBinary is a wrapper around binary.Write | [
"MarshalBinary",
"is",
"a",
"wrapper",
"around",
"binary",
".",
"Write"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/encoding.go#L26-L51 | train |
vmware/govmomi | toolbox/hgfs/encoding.go | UnmarshalBinary | func UnmarshalBinary(data []byte, fields ...interface{}) error {
buf := bytes.NewBuffer(data)
for _, p := range fields {
switch m := p.(type) {
case encoding.BinaryUnmarshaler:
return m.UnmarshalBinary(buf.Bytes())
case *[]byte:
*m = buf.Bytes()
return nil
default:
err := binary.Read(buf, binary.... | go | func UnmarshalBinary(data []byte, fields ...interface{}) error {
buf := bytes.NewBuffer(data)
for _, p := range fields {
switch m := p.(type) {
case encoding.BinaryUnmarshaler:
return m.UnmarshalBinary(buf.Bytes())
case *[]byte:
*m = buf.Bytes()
return nil
default:
err := binary.Read(buf, binary.... | [
"func",
"UnmarshalBinary",
"(",
"data",
"[",
"]",
"byte",
",",
"fields",
"...",
"interface",
"{",
"}",
")",
"error",
"{",
"buf",
":=",
"bytes",
".",
"NewBuffer",
"(",
"data",
")",
"\n\n",
"for",
"_",
",",
"p",
":=",
"range",
"fields",
"{",
"switch",
... | // UnmarshalBinary is a wrapper around binary.Read | [
"UnmarshalBinary",
"is",
"a",
"wrapper",
"around",
"binary",
".",
"Read"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/encoding.go#L54-L73 | train |
vmware/govmomi | ssoadmin/methods/role.go | C14N | func (b *LoginBody) C14N() string {
req, err := xml.Marshal(b.Req)
if err != nil {
panic(err)
}
return string(req)
} | go | func (b *LoginBody) C14N() string {
req, err := xml.Marshal(b.Req)
if err != nil {
panic(err)
}
return string(req)
} | [
"func",
"(",
"b",
"*",
"LoginBody",
")",
"C14N",
"(",
")",
"string",
"{",
"req",
",",
"err",
":=",
"xml",
".",
"Marshal",
"(",
"b",
".",
"Req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"st... | // C14N returns the canonicalized form of LoginBody.Req, for use by sts.Signer | [
"C14N",
"returns",
"the",
"canonicalized",
"form",
"of",
"LoginBody",
".",
"Req",
"for",
"use",
"by",
"sts",
".",
"Signer"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/ssoadmin/methods/role.go#L70-L76 | train |
vmware/govmomi | simulator/model.go | ESX | func ESX() *Model {
return &Model{
ServiceContent: esx.ServiceContent,
RootFolder: esx.RootFolder,
Autostart: true,
Datastore: 1,
Machine: 2,
DelayConfig: DelayConfig{
Delay: 0,
DelayJitter: 0,
MethodDelay: nil,
},
}
} | go | func ESX() *Model {
return &Model{
ServiceContent: esx.ServiceContent,
RootFolder: esx.RootFolder,
Autostart: true,
Datastore: 1,
Machine: 2,
DelayConfig: DelayConfig{
Delay: 0,
DelayJitter: 0,
MethodDelay: nil,
},
}
} | [
"func",
"ESX",
"(",
")",
"*",
"Model",
"{",
"return",
"&",
"Model",
"{",
"ServiceContent",
":",
"esx",
".",
"ServiceContent",
",",
"RootFolder",
":",
"esx",
".",
"RootFolder",
",",
"Autostart",
":",
"true",
",",
"Datastore",
":",
"1",
",",
"Machine",
"... | // ESX is the default Model for a standalone ESX instance | [
"ESX",
"is",
"the",
"default",
"Model",
"for",
"a",
"standalone",
"ESX",
"instance"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/model.go#L107-L120 | train |
vmware/govmomi | simulator/model.go | VPX | func VPX() *Model {
return &Model{
ServiceContent: vpx.ServiceContent,
RootFolder: vpx.RootFolder,
Autostart: true,
Datacenter: 1,
Portgroup: 1,
Host: 1,
Cluster: 1,
ClusterHost: 3,
Datastore: 1,
Machine: 2,
DelayConfig: DelayConfig{
Delay: ... | go | func VPX() *Model {
return &Model{
ServiceContent: vpx.ServiceContent,
RootFolder: vpx.RootFolder,
Autostart: true,
Datacenter: 1,
Portgroup: 1,
Host: 1,
Cluster: 1,
ClusterHost: 3,
Datastore: 1,
Machine: 2,
DelayConfig: DelayConfig{
Delay: ... | [
"func",
"VPX",
"(",
")",
"*",
"Model",
"{",
"return",
"&",
"Model",
"{",
"ServiceContent",
":",
"vpx",
".",
"ServiceContent",
",",
"RootFolder",
":",
"vpx",
".",
"RootFolder",
",",
"Autostart",
":",
"true",
",",
"Datacenter",
":",
"1",
",",
"Portgroup",
... | // VPX is the default Model for a vCenter instance | [
"VPX",
"is",
"the",
"default",
"Model",
"for",
"a",
"vCenter",
"instance"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/model.go#L123-L141 | train |
vmware/govmomi | simulator/model.go | Count | func (m *Model) Count() Model {
count := Model{}
for ref, obj := range Map.objects {
if _, ok := obj.(mo.Entity); !ok {
continue
}
count.total++
switch ref.Type {
case "Datacenter":
count.Datacenter++
case "DistributedVirtualPortgroup":
count.Portgroup++
case "ClusterComputeResource":
cou... | go | func (m *Model) Count() Model {
count := Model{}
for ref, obj := range Map.objects {
if _, ok := obj.(mo.Entity); !ok {
continue
}
count.total++
switch ref.Type {
case "Datacenter":
count.Datacenter++
case "DistributedVirtualPortgroup":
count.Portgroup++
case "ClusterComputeResource":
cou... | [
"func",
"(",
"m",
"*",
"Model",
")",
"Count",
"(",
")",
"Model",
"{",
"count",
":=",
"Model",
"{",
"}",
"\n\n",
"for",
"ref",
",",
"obj",
":=",
"range",
"Map",
".",
"objects",
"{",
"if",
"_",
",",
"ok",
":=",
"obj",
".",
"(",
"mo",
".",
"Enti... | // Count returns a Model with total number of each existing type | [
"Count",
"returns",
"a",
"Model",
"with",
"total",
"number",
"of",
"each",
"existing",
"type"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/model.go#L144-L179 | train |
vmware/govmomi | simulator/model.go | Remove | func (m *Model) Remove() {
for _, dir := range m.dirs {
_ = os.RemoveAll(dir)
}
} | go | func (m *Model) Remove() {
for _, dir := range m.dirs {
_ = os.RemoveAll(dir)
}
} | [
"func",
"(",
"m",
"*",
"Model",
")",
"Remove",
"(",
")",
"{",
"for",
"_",
",",
"dir",
":=",
"range",
"m",
".",
"dirs",
"{",
"_",
"=",
"os",
".",
"RemoveAll",
"(",
"dir",
")",
"\n",
"}",
"\n",
"}"
] | // Remove cleans up items created by the Model, such as local datastore directories | [
"Remove",
"cleans",
"up",
"items",
"created",
"by",
"the",
"Model",
"such",
"as",
"local",
"datastore",
"directories"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/model.go#L516-L520 | train |
vmware/govmomi | govc/host/autostart/autostart.go | VirtualMachines | func (f *AutostartFlag) VirtualMachines(args []string) ([]*object.VirtualMachine, error) {
ctx := context.TODO()
if len(args) == 0 {
return nil, errors.New("no argument")
}
finder, err := f.Finder()
if err != nil {
return nil, err
}
var out []*object.VirtualMachine
for _, arg := range args {
vms, err :=... | go | func (f *AutostartFlag) VirtualMachines(args []string) ([]*object.VirtualMachine, error) {
ctx := context.TODO()
if len(args) == 0 {
return nil, errors.New("no argument")
}
finder, err := f.Finder()
if err != nil {
return nil, err
}
var out []*object.VirtualMachine
for _, arg := range args {
vms, err :=... | [
"func",
"(",
"f",
"*",
"AutostartFlag",
")",
"VirtualMachines",
"(",
"args",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"object",
".",
"VirtualMachine",
",",
"error",
")",
"{",
"ctx",
":=",
"context",
".",
"TODO",
"(",
")",
"\n",
"if",
"len",
"("... | // VirtualMachines returns list of virtual machine objects based on the
// arguments specified on the command line. This helper is defined in
// flags.SearchFlag as well, but that pulls in other virtual machine flags that
// are not relevant here. | [
"VirtualMachines",
"returns",
"list",
"of",
"virtual",
"machine",
"objects",
"based",
"on",
"the",
"arguments",
"specified",
"on",
"the",
"command",
"line",
".",
"This",
"helper",
"is",
"defined",
"in",
"flags",
".",
"SearchFlag",
"as",
"well",
"but",
"that",
... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/host/autostart/autostart.go#L68-L90 | train |
vmware/govmomi | vim25/retry.go | Retry | func Retry(roundTripper soap.RoundTripper, fn RetryFunc) soap.RoundTripper {
r := &retry{
roundTripper: roundTripper,
fn: fn,
}
return r
} | go | func Retry(roundTripper soap.RoundTripper, fn RetryFunc) soap.RoundTripper {
r := &retry{
roundTripper: roundTripper,
fn: fn,
}
return r
} | [
"func",
"Retry",
"(",
"roundTripper",
"soap",
".",
"RoundTripper",
",",
"fn",
"RetryFunc",
")",
"soap",
".",
"RoundTripper",
"{",
"r",
":=",
"&",
"retry",
"{",
"roundTripper",
":",
"roundTripper",
",",
"fn",
":",
"fn",
",",
"}",
"\n\n",
"return",
"r",
... | // Retry wraps the specified soap.RoundTripper and invokes the
// specified RetryFunc. The RetryFunc returns whether or not to
// retry the call, and if so, how long to wait before retrying. If
// the result of this function is to not retry, the original error
// is returned from the RoundTrip function. | [
"Retry",
"wraps",
"the",
"specified",
"soap",
".",
"RoundTripper",
"and",
"invokes",
"the",
"specified",
"RetryFunc",
".",
"The",
"RetryFunc",
"returns",
"whether",
"or",
"not",
"to",
"retry",
"the",
"call",
"and",
"if",
"so",
"how",
"long",
"to",
"wait",
... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/retry.go#L77-L84 | train |
vmware/govmomi | object/custom_fields_manager.go | GetCustomFieldsManager | func GetCustomFieldsManager(c *vim25.Client) (*CustomFieldsManager, error) {
if c.ServiceContent.CustomFieldsManager == nil {
return nil, ErrNotSupported
}
return NewCustomFieldsManager(c), nil
} | go | func GetCustomFieldsManager(c *vim25.Client) (*CustomFieldsManager, error) {
if c.ServiceContent.CustomFieldsManager == nil {
return nil, ErrNotSupported
}
return NewCustomFieldsManager(c), nil
} | [
"func",
"GetCustomFieldsManager",
"(",
"c",
"*",
"vim25",
".",
"Client",
")",
"(",
"*",
"CustomFieldsManager",
",",
"error",
")",
"{",
"if",
"c",
".",
"ServiceContent",
".",
"CustomFieldsManager",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNotSupported",
"\... | // GetCustomFieldsManager wraps NewCustomFieldsManager, returning ErrNotSupported
// when the client is not connected to a vCenter instance. | [
"GetCustomFieldsManager",
"wraps",
"NewCustomFieldsManager",
"returning",
"ErrNotSupported",
"when",
"the",
"client",
"is",
"not",
"connected",
"to",
"a",
"vCenter",
"instance",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/custom_fields_manager.go#L40-L45 | train |
vmware/govmomi | object/diagnostic_log.go | Seek | func (l *DiagnosticLog) Seek(ctx context.Context, nlines int32) error {
h, err := l.m.BrowseLog(ctx, l.Host, l.Key, math.MaxInt32, 0)
if err != nil {
return err
}
l.Start = h.LineEnd - nlines
return nil
} | go | func (l *DiagnosticLog) Seek(ctx context.Context, nlines int32) error {
h, err := l.m.BrowseLog(ctx, l.Host, l.Key, math.MaxInt32, 0)
if err != nil {
return err
}
l.Start = h.LineEnd - nlines
return nil
} | [
"func",
"(",
"l",
"*",
"DiagnosticLog",
")",
"Seek",
"(",
"ctx",
"context",
".",
"Context",
",",
"nlines",
"int32",
")",
"error",
"{",
"h",
",",
"err",
":=",
"l",
".",
"m",
".",
"BrowseLog",
"(",
"ctx",
",",
"l",
".",
"Host",
",",
"l",
".",
"Ke... | // Seek to log position starting at the last nlines of the log | [
"Seek",
"to",
"log",
"position",
"starting",
"at",
"the",
"last",
"nlines",
"of",
"the",
"log"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/diagnostic_log.go#L37-L46 | train |
vmware/govmomi | object/diagnostic_log.go | Copy | func (l *DiagnosticLog) Copy(ctx context.Context, w io.Writer) (int, error) {
const max = 500 // VC max == 500, ESX max == 1000
written := 0
for {
h, err := l.m.BrowseLog(ctx, l.Host, l.Key, l.Start, max)
if err != nil {
return 0, err
}
for _, line := range h.LineText {
n, err := fmt.Fprintln(w, line... | go | func (l *DiagnosticLog) Copy(ctx context.Context, w io.Writer) (int, error) {
const max = 500 // VC max == 500, ESX max == 1000
written := 0
for {
h, err := l.m.BrowseLog(ctx, l.Host, l.Key, l.Start, max)
if err != nil {
return 0, err
}
for _, line := range h.LineText {
n, err := fmt.Fprintln(w, line... | [
"func",
"(",
"l",
"*",
"DiagnosticLog",
")",
"Copy",
"(",
"ctx",
"context",
".",
"Context",
",",
"w",
"io",
".",
"Writer",
")",
"(",
"int",
",",
"error",
")",
"{",
"const",
"max",
"=",
"500",
"// VC max == 500, ESX max == 1000",
"\n",
"written",
":=",
... | // Copy log starting from l.Start to the given io.Writer
// Returns on error or when end of log is reached. | [
"Copy",
"log",
"starting",
"from",
"l",
".",
"Start",
"to",
"the",
"given",
"io",
".",
"Writer",
"Returns",
"on",
"error",
"or",
"when",
"end",
"of",
"log",
"is",
"reached",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/diagnostic_log.go#L50-L76 | train |
vmware/govmomi | object/search_index.go | FindByDatastorePath | func (s SearchIndex) FindByDatastorePath(ctx context.Context, dc *Datacenter, path string) (Reference, error) {
req := types.FindByDatastorePath{
This: s.Reference(),
Datacenter: dc.Reference(),
Path: path,
}
res, err := methods.FindByDatastorePath(ctx, s.c, &req)
if err != nil {
return nil, er... | go | func (s SearchIndex) FindByDatastorePath(ctx context.Context, dc *Datacenter, path string) (Reference, error) {
req := types.FindByDatastorePath{
This: s.Reference(),
Datacenter: dc.Reference(),
Path: path,
}
res, err := methods.FindByDatastorePath(ctx, s.c, &req)
if err != nil {
return nil, er... | [
"func",
"(",
"s",
"SearchIndex",
")",
"FindByDatastorePath",
"(",
"ctx",
"context",
".",
"Context",
",",
"dc",
"*",
"Datacenter",
",",
"path",
"string",
")",
"(",
"Reference",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"FindByDatastorePath",
"{",
... | // FindByDatastorePath finds a virtual machine by its location on a datastore. | [
"FindByDatastorePath",
"finds",
"a",
"virtual",
"machine",
"by",
"its",
"location",
"on",
"a",
"datastore",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/search_index.go#L40-L56 | train |
vmware/govmomi | object/search_index.go | FindByDnsName | func (s SearchIndex) FindByDnsName(ctx context.Context, dc *Datacenter, dnsName string, vmSearch bool) (Reference, error) {
req := types.FindByDnsName{
This: s.Reference(),
DnsName: dnsName,
VmSearch: vmSearch,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
res, err := methods.FindB... | go | func (s SearchIndex) FindByDnsName(ctx context.Context, dc *Datacenter, dnsName string, vmSearch bool) (Reference, error) {
req := types.FindByDnsName{
This: s.Reference(),
DnsName: dnsName,
VmSearch: vmSearch,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
res, err := methods.FindB... | [
"func",
"(",
"s",
"SearchIndex",
")",
"FindByDnsName",
"(",
"ctx",
"context",
".",
"Context",
",",
"dc",
"*",
"Datacenter",
",",
"dnsName",
"string",
",",
"vmSearch",
"bool",
")",
"(",
"Reference",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"Fi... | // FindByDnsName finds a virtual machine or host by DNS name. | [
"FindByDnsName",
"finds",
"a",
"virtual",
"machine",
"or",
"host",
"by",
"DNS",
"name",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/search_index.go#L59-L79 | train |
vmware/govmomi | object/search_index.go | FindByInventoryPath | func (s SearchIndex) FindByInventoryPath(ctx context.Context, path string) (Reference, error) {
req := types.FindByInventoryPath{
This: s.Reference(),
InventoryPath: path,
}
res, err := methods.FindByInventoryPath(ctx, s.c, &req)
if err != nil {
return nil, err
}
if res.Returnval == nil {
retur... | go | func (s SearchIndex) FindByInventoryPath(ctx context.Context, path string) (Reference, error) {
req := types.FindByInventoryPath{
This: s.Reference(),
InventoryPath: path,
}
res, err := methods.FindByInventoryPath(ctx, s.c, &req)
if err != nil {
return nil, err
}
if res.Returnval == nil {
retur... | [
"func",
"(",
"s",
"SearchIndex",
")",
"FindByInventoryPath",
"(",
"ctx",
"context",
".",
"Context",
",",
"path",
"string",
")",
"(",
"Reference",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"FindByInventoryPath",
"{",
"This",
":",
"s",
".",
"Refer... | // FindByInventoryPath finds a managed entity based on its location in the inventory. | [
"FindByInventoryPath",
"finds",
"a",
"managed",
"entity",
"based",
"on",
"its",
"location",
"in",
"the",
"inventory",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/search_index.go#L82-L97 | train |
vmware/govmomi | object/search_index.go | FindByUuid | func (s SearchIndex) FindByUuid(ctx context.Context, dc *Datacenter, uuid string, vmSearch bool, instanceUuid *bool) (Reference, error) {
req := types.FindByUuid{
This: s.Reference(),
Uuid: uuid,
VmSearch: vmSearch,
InstanceUuid: instanceUuid,
}
if dc != nil {
ref := dc.Reference()
re... | go | func (s SearchIndex) FindByUuid(ctx context.Context, dc *Datacenter, uuid string, vmSearch bool, instanceUuid *bool) (Reference, error) {
req := types.FindByUuid{
This: s.Reference(),
Uuid: uuid,
VmSearch: vmSearch,
InstanceUuid: instanceUuid,
}
if dc != nil {
ref := dc.Reference()
re... | [
"func",
"(",
"s",
"SearchIndex",
")",
"FindByUuid",
"(",
"ctx",
"context",
".",
"Context",
",",
"dc",
"*",
"Datacenter",
",",
"uuid",
"string",
",",
"vmSearch",
"bool",
",",
"instanceUuid",
"*",
"bool",
")",
"(",
"Reference",
",",
"error",
")",
"{",
"r... | // FindByUuid finds a virtual machine or host by UUID. | [
"FindByUuid",
"finds",
"a",
"virtual",
"machine",
"or",
"host",
"by",
"UUID",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/search_index.go#L123-L144 | train |
vmware/govmomi | object/search_index.go | FindChild | func (s SearchIndex) FindChild(ctx context.Context, entity Reference, name string) (Reference, error) {
req := types.FindChild{
This: s.Reference(),
Entity: entity.Reference(),
Name: name,
}
res, err := methods.FindChild(ctx, s.c, &req)
if err != nil {
return nil, err
}
if res.Returnval == nil {
r... | go | func (s SearchIndex) FindChild(ctx context.Context, entity Reference, name string) (Reference, error) {
req := types.FindChild{
This: s.Reference(),
Entity: entity.Reference(),
Name: name,
}
res, err := methods.FindChild(ctx, s.c, &req)
if err != nil {
return nil, err
}
if res.Returnval == nil {
r... | [
"func",
"(",
"s",
"SearchIndex",
")",
"FindChild",
"(",
"ctx",
"context",
".",
"Context",
",",
"entity",
"Reference",
",",
"name",
"string",
")",
"(",
"Reference",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"FindChild",
"{",
"This",
":",
"s",
... | // FindChild finds a particular child based on a managed entity name. | [
"FindChild",
"finds",
"a",
"particular",
"child",
"based",
"on",
"a",
"managed",
"entity",
"name",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/search_index.go#L147-L163 | train |
vmware/govmomi | toolbox/toolbox/main.go | main | func main() {
flag.Parse()
in := toolbox.NewBackdoorChannelIn()
out := toolbox.NewBackdoorChannelOut()
service := toolbox.NewService(in, out)
if os.Getuid() == 0 {
service.Power.Halt.Handler = toolbox.Halt
service.Power.Reboot.Handler = toolbox.Reboot
}
err := service.Start()
if err != nil {
log.Fatal... | go | func main() {
flag.Parse()
in := toolbox.NewBackdoorChannelIn()
out := toolbox.NewBackdoorChannelOut()
service := toolbox.NewService(in, out)
if os.Getuid() == 0 {
service.Power.Halt.Handler = toolbox.Halt
service.Power.Reboot.Handler = toolbox.Reboot
}
err := service.Start()
if err != nil {
log.Fatal... | [
"func",
"main",
"(",
")",
"{",
"flag",
".",
"Parse",
"(",
")",
"\n\n",
"in",
":=",
"toolbox",
".",
"NewBackdoorChannelIn",
"(",
")",
"\n",
"out",
":=",
"toolbox",
".",
"NewBackdoorChannelOut",
"(",
")",
"\n\n",
"service",
":=",
"toolbox",
".",
"NewServic... | // This example can be run on a VM hosted by ESX, Fusion or Workstation | [
"This",
"example",
"can",
"be",
"run",
"on",
"a",
"VM",
"hosted",
"by",
"ESX",
"Fusion",
"or",
"Workstation"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/toolbox/main.go#L43-L71 | train |
vmware/govmomi | govc/flags/client.go | configure | func (flag *ClientFlag) configure(sc *soap.Client) (soap.RoundTripper, error) {
if flag.cert != "" {
cert, err := tls.LoadX509KeyPair(flag.cert, flag.key)
if err != nil {
return nil, err
}
sc.SetCertificate(cert)
}
// Set namespace and version
sc.Namespace = "urn:" + flag.vimNamespace
sc.Version = fla... | go | func (flag *ClientFlag) configure(sc *soap.Client) (soap.RoundTripper, error) {
if flag.cert != "" {
cert, err := tls.LoadX509KeyPair(flag.cert, flag.key)
if err != nil {
return nil, err
}
sc.SetCertificate(cert)
}
// Set namespace and version
sc.Namespace = "urn:" + flag.vimNamespace
sc.Version = fla... | [
"func",
"(",
"flag",
"*",
"ClientFlag",
")",
"configure",
"(",
"sc",
"*",
"soap",
".",
"Client",
")",
"(",
"soap",
".",
"RoundTripper",
",",
"error",
")",
"{",
"if",
"flag",
".",
"cert",
"!=",
"\"",
"\"",
"{",
"cert",
",",
"err",
":=",
"tls",
"."... | // configure TLS and retry settings before making any connections | [
"configure",
"TLS",
"and",
"retry",
"settings",
"before",
"making",
"any",
"connections"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/client.go#L277-L316 | train |
vmware/govmomi | govc/flags/client.go | apiVersionValid | func apiVersionValid(c *vim25.Client, minVersionString string) error {
if minVersionString == "-" {
// Disable version check
return nil
}
apiVersion := c.ServiceContent.About.ApiVersion
if isDevelopmentVersion(apiVersion) {
return nil
}
realVersion, err := ParseVersion(apiVersion)
if err != nil {
retur... | go | func apiVersionValid(c *vim25.Client, minVersionString string) error {
if minVersionString == "-" {
// Disable version check
return nil
}
apiVersion := c.ServiceContent.About.ApiVersion
if isDevelopmentVersion(apiVersion) {
return nil
}
realVersion, err := ParseVersion(apiVersion)
if err != nil {
retur... | [
"func",
"apiVersionValid",
"(",
"c",
"*",
"vim25",
".",
"Client",
",",
"minVersionString",
"string",
")",
"error",
"{",
"if",
"minVersionString",
"==",
"\"",
"\"",
"{",
"// Disable version check",
"return",
"nil",
"\n",
"}",
"\n\n",
"apiVersion",
":=",
"c",
... | // apiVersionValid returns whether or not the API version supported by the
// server the client is connected to is not recent enough. | [
"apiVersionValid",
"returns",
"whether",
"or",
"not",
"the",
"API",
"version",
"supported",
"by",
"the",
"server",
"the",
"client",
"is",
"connected",
"to",
"is",
"not",
"recent",
"enough",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/client.go#L494-L524 | train |
vmware/govmomi | govc/flags/client.go | Environ | func (flag *ClientFlag) Environ(extra bool) []string {
var env []string
add := func(k, v string) {
env = append(env, fmt.Sprintf("%s=%s", k, v))
}
u := *flag.url
if u.User != nil {
add(envUsername, u.User.Username())
if p, ok := u.User.Password(); ok {
add(envPassword, p)
}
u.User = nil
}
if u.P... | go | func (flag *ClientFlag) Environ(extra bool) []string {
var env []string
add := func(k, v string) {
env = append(env, fmt.Sprintf("%s=%s", k, v))
}
u := *flag.url
if u.User != nil {
add(envUsername, u.User.Username())
if p, ok := u.User.Password(); ok {
add(envPassword, p)
}
u.User = nil
}
if u.P... | [
"func",
"(",
"flag",
"*",
"ClientFlag",
")",
"Environ",
"(",
"extra",
"bool",
")",
"[",
"]",
"string",
"{",
"var",
"env",
"[",
"]",
"string",
"\n",
"add",
":=",
"func",
"(",
"k",
",",
"v",
"string",
")",
"{",
"env",
"=",
"append",
"(",
"env",
"... | // Environ returns the govc environment variables for this connection | [
"Environ",
"returns",
"the",
"govc",
"environment",
"variables",
"for",
"this",
"connection"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/client.go#L606-L668 | train |
vmware/govmomi | govc/flags/client.go | WithCancel | func (flag *ClientFlag) WithCancel(ctx context.Context, f func(context.Context) error) error {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT)
wctx, cancel := context.WithCancel(ctx)
defer cancel()
done := make(chan bool)
var werr error
go func() {
defer close(done)
werr = f(wctx)
}()
... | go | func (flag *ClientFlag) WithCancel(ctx context.Context, f func(context.Context) error) error {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT)
wctx, cancel := context.WithCancel(ctx)
defer cancel()
done := make(chan bool)
var werr error
go func() {
defer close(done)
werr = f(wctx)
}()
... | [
"func",
"(",
"flag",
"*",
"ClientFlag",
")",
"WithCancel",
"(",
"ctx",
"context",
".",
"Context",
",",
"f",
"func",
"(",
"context",
".",
"Context",
")",
"error",
")",
"error",
"{",
"sig",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")... | // WithCancel calls the given function, returning when complete or canceled via SIGINT. | [
"WithCancel",
"calls",
"the",
"given",
"function",
"returning",
"when",
"complete",
"or",
"canceled",
"via",
"SIGINT",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/client.go#L671-L694 | train |
vmware/govmomi | vim25/progress/tee.go | Tee | func Tee(s1, s2 Sinker) Sinker {
fn := func() chan<- Report {
d1 := s1.Sink()
d2 := s2.Sink()
u := make(chan Report)
go tee(u, d1, d2)
return u
}
return SinkFunc(fn)
} | go | func Tee(s1, s2 Sinker) Sinker {
fn := func() chan<- Report {
d1 := s1.Sink()
d2 := s2.Sink()
u := make(chan Report)
go tee(u, d1, d2)
return u
}
return SinkFunc(fn)
} | [
"func",
"Tee",
"(",
"s1",
",",
"s2",
"Sinker",
")",
"Sinker",
"{",
"fn",
":=",
"func",
"(",
")",
"chan",
"<-",
"Report",
"{",
"d1",
":=",
"s1",
".",
"Sink",
"(",
")",
"\n",
"d2",
":=",
"s2",
".",
"Sink",
"(",
")",
"\n",
"u",
":=",
"make",
"... | // Tee works like Unix tee; it forwards all progress reports it receives to the
// specified sinks | [
"Tee",
"works",
"like",
"Unix",
"tee",
";",
"it",
"forwards",
"all",
"progress",
"reports",
"it",
"receives",
"to",
"the",
"specified",
"sinks"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/progress/tee.go#L21-L31 | train |
vmware/govmomi | simulator/host_system.go | CreateStandaloneHost | func CreateStandaloneHost(f *Folder, spec types.HostConnectSpec) (*HostSystem, types.BaseMethodFault) {
if spec.HostName == "" {
return nil, &types.NoHost{}
}
pool := NewResourcePool()
host := NewHostSystem(esx.HostSystem)
host.Summary.Config.Name = spec.HostName
host.Name = host.Summary.Config.Name
host.Run... | go | func CreateStandaloneHost(f *Folder, spec types.HostConnectSpec) (*HostSystem, types.BaseMethodFault) {
if spec.HostName == "" {
return nil, &types.NoHost{}
}
pool := NewResourcePool()
host := NewHostSystem(esx.HostSystem)
host.Summary.Config.Name = spec.HostName
host.Name = host.Summary.Config.Name
host.Run... | [
"func",
"CreateStandaloneHost",
"(",
"f",
"*",
"Folder",
",",
"spec",
"types",
".",
"HostConnectSpec",
")",
"(",
"*",
"HostSystem",
",",
"types",
".",
"BaseMethodFault",
")",
"{",
"if",
"spec",
".",
"HostName",
"==",
"\"",
"\"",
"{",
"return",
"nil",
","... | // CreateStandaloneHost uses esx.HostSystem as a template, applying the given spec
// and creating the ComputeResource parent and ResourcePool sibling. | [
"CreateStandaloneHost",
"uses",
"esx",
".",
"HostSystem",
"as",
"a",
"template",
"applying",
"the",
"given",
"spec",
"and",
"creating",
"the",
"ComputeResource",
"parent",
"and",
"ResourcePool",
"sibling",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/host_system.go#L165-L203 | train |
vmware/govmomi | vapi/library/library_item_updatesession.go | CreateLibraryItemUpdateSession | func (c *Manager) CreateLibraryItemUpdateSession(ctx context.Context, session UpdateSession) (string, error) {
url := internal.URL(c, internal.LibraryItemUpdateSession)
spec := struct {
CreateSpec UpdateSession `json:"create_spec"`
}{session}
var res string
return res, c.Do(ctx, url.Request(http.MethodPost, spec... | go | func (c *Manager) CreateLibraryItemUpdateSession(ctx context.Context, session UpdateSession) (string, error) {
url := internal.URL(c, internal.LibraryItemUpdateSession)
spec := struct {
CreateSpec UpdateSession `json:"create_spec"`
}{session}
var res string
return res, c.Do(ctx, url.Request(http.MethodPost, spec... | [
"func",
"(",
"c",
"*",
"Manager",
")",
"CreateLibraryItemUpdateSession",
"(",
"ctx",
"context",
".",
"Context",
",",
"session",
"UpdateSession",
")",
"(",
"string",
",",
"error",
")",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
"... | // CreateLibraryItemUpdateSession creates a new library item | [
"CreateLibraryItemUpdateSession",
"creates",
"a",
"new",
"library",
"item"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession.go#L43-L50 | train |
vmware/govmomi | vapi/library/library_item_updatesession.go | GetLibraryItemUpdateSession | func (c *Manager) GetLibraryItemUpdateSession(ctx context.Context, id string) (*UpdateSession, error) {
url := internal.URL(c, internal.LibraryItemUpdateSession).WithID(id)
var res UpdateSession
return &res, c.Do(ctx, url.Request(http.MethodGet), &res)
} | go | func (c *Manager) GetLibraryItemUpdateSession(ctx context.Context, id string) (*UpdateSession, error) {
url := internal.URL(c, internal.LibraryItemUpdateSession).WithID(id)
var res UpdateSession
return &res, c.Do(ctx, url.Request(http.MethodGet), &res)
} | [
"func",
"(",
"c",
"*",
"Manager",
")",
"GetLibraryItemUpdateSession",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"*",
"UpdateSession",
",",
"error",
")",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".... | // GetLibraryItemUpdateSession gets the update session information with status | [
"GetLibraryItemUpdateSession",
"gets",
"the",
"update",
"session",
"information",
"with",
"status"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession.go#L53-L57 | train |
vmware/govmomi | vapi/library/library_item_updatesession.go | ListLibraryItemUpdateSession | func (c *Manager) ListLibraryItemUpdateSession(ctx context.Context) (*[]string, error) {
url := internal.URL(c, internal.LibraryItemUpdateSession)
var res []string
return &res, c.Do(ctx, url.Request(http.MethodGet), &res)
} | go | func (c *Manager) ListLibraryItemUpdateSession(ctx context.Context) (*[]string, error) {
url := internal.URL(c, internal.LibraryItemUpdateSession)
var res []string
return &res, c.Do(ctx, url.Request(http.MethodGet), &res)
} | [
"func",
"(",
"c",
"*",
"Manager",
")",
"ListLibraryItemUpdateSession",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"[",
"]",
"string",
",",
"error",
")",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"LibraryItemUp... | // ListLibraryItemUpdateSession gets the list of update sessions | [
"ListLibraryItemUpdateSession",
"gets",
"the",
"list",
"of",
"update",
"sessions"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession.go#L60-L64 | train |
vmware/govmomi | vapi/library/library_item_updatesession.go | DeleteLibraryItemUpdateSession | func (c *Manager) DeleteLibraryItemUpdateSession(ctx context.Context, id string) error {
url := internal.URL(c, internal.LibraryItemUpdateSession).WithID(id)
return c.Do(ctx, url.Request(http.MethodDelete), nil)
} | go | func (c *Manager) DeleteLibraryItemUpdateSession(ctx context.Context, id string) error {
url := internal.URL(c, internal.LibraryItemUpdateSession).WithID(id)
return c.Do(ctx, url.Request(http.MethodDelete), nil)
} | [
"func",
"(",
"c",
"*",
"Manager",
")",
"DeleteLibraryItemUpdateSession",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"error",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"LibraryItemUpdateSession",
")",
".... | // DeleteLibraryItemUpdateSession deletes an update session | [
"DeleteLibraryItemUpdateSession",
"deletes",
"an",
"update",
"session"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession.go#L79-L82 | train |
vmware/govmomi | vapi/library/library_item_updatesession.go | FailLibraryItemUpdateSession | func (c *Manager) FailLibraryItemUpdateSession(ctx context.Context, id string) error {
url := internal.URL(c, internal.LibraryItemUpdateSession).WithID(id).WithAction("fail")
return c.Do(ctx, url.Request(http.MethodPost), nil)
} | go | func (c *Manager) FailLibraryItemUpdateSession(ctx context.Context, id string) error {
url := internal.URL(c, internal.LibraryItemUpdateSession).WithID(id).WithAction("fail")
return c.Do(ctx, url.Request(http.MethodPost), nil)
} | [
"func",
"(",
"c",
"*",
"Manager",
")",
"FailLibraryItemUpdateSession",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"error",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"LibraryItemUpdateSession",
")",
".",... | // FailLibraryItemUpdateSession fails an update session | [
"FailLibraryItemUpdateSession",
"fails",
"an",
"update",
"session"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession.go#L85-L88 | train |
vmware/govmomi | vapi/library/library_item_updatesession.go | WaitOnLibraryItemUpdateSession | func (c *Manager) WaitOnLibraryItemUpdateSession(
ctx context.Context, sessionID string,
interval time.Duration, intervalCallback func()) error {
// Wait until the upload operation is complete to return.
for {
session, err := c.GetLibraryItemUpdateSession(ctx, sessionID)
if err != nil {
return err
}
if ... | go | func (c *Manager) WaitOnLibraryItemUpdateSession(
ctx context.Context, sessionID string,
interval time.Duration, intervalCallback func()) error {
// Wait until the upload operation is complete to return.
for {
session, err := c.GetLibraryItemUpdateSession(ctx, sessionID)
if err != nil {
return err
}
if ... | [
"func",
"(",
"c",
"*",
"Manager",
")",
"WaitOnLibraryItemUpdateSession",
"(",
"ctx",
"context",
".",
"Context",
",",
"sessionID",
"string",
",",
"interval",
"time",
".",
"Duration",
",",
"intervalCallback",
"func",
"(",
")",
")",
"error",
"{",
"// Wait until t... | // WaitOnLibraryItemUpdateSession blocks until the update session is no longer
// in the ACTIVE state. | [
"WaitOnLibraryItemUpdateSession",
"blocks",
"until",
"the",
"update",
"session",
"is",
"no",
"longer",
"in",
"the",
"ACTIVE",
"state",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession.go#L98-L116 | train |
vmware/govmomi | sts/internal/types.go | toString | func (r *RequestSecurityToken) toString(c14n bool) string {
actas := ""
if r.ActAs != nil {
token := r.ActAs.Token
if c14n {
var a Assertion
err := Unmarshal([]byte(r.ActAs.Token), &a)
if err != nil {
log.Printf("decode ActAs: %s", err)
}
token = a.C14N()
}
actas = fmt.Sprintf(`<wst:ActAs ... | go | func (r *RequestSecurityToken) toString(c14n bool) string {
actas := ""
if r.ActAs != nil {
token := r.ActAs.Token
if c14n {
var a Assertion
err := Unmarshal([]byte(r.ActAs.Token), &a)
if err != nil {
log.Printf("decode ActAs: %s", err)
}
token = a.C14N()
}
actas = fmt.Sprintf(`<wst:ActAs ... | [
"func",
"(",
"r",
"*",
"RequestSecurityToken",
")",
"toString",
"(",
"c14n",
"bool",
")",
"string",
"{",
"actas",
":=",
"\"",
"\"",
"\n",
"if",
"r",
".",
"ActAs",
"!=",
"nil",
"{",
"token",
":=",
"r",
".",
"ActAs",
".",
"Token",
"\n",
"if",
"c14n",... | // toString returns an XML encoded RequestSecurityToken.
// When c14n is true, returns the canonicalized ActAs.Assertion which is required to sign the Issue request.
// When c14n is false, returns the original content of the ActAs.Assertion.
// The original content must be used within the request Body, as it has its ow... | [
"toString",
"returns",
"an",
"XML",
"encoded",
"RequestSecurityToken",
".",
"When",
"c14n",
"is",
"true",
"returns",
"the",
"canonicalized",
"ActAs",
".",
"Assertion",
"which",
"is",
"required",
"to",
"sign",
"the",
"Issue",
"request",
".",
"When",
"c14n",
"is... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/sts/internal/types.go#L552-L600 | train |
vmware/govmomi | sts/internal/types.go | Marshal | func Marshal(val interface{}) string {
b, err := xml.Marshal(val)
if err != nil {
panic(err)
}
return string(b)
} | go | func Marshal(val interface{}) string {
b, err := xml.Marshal(val)
if err != nil {
panic(err)
}
return string(b)
} | [
"func",
"Marshal",
"(",
"val",
"interface",
"{",
"}",
")",
"string",
"{",
"b",
",",
"err",
":=",
"xml",
".",
"Marshal",
"(",
"val",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"b... | // Marshal panics if xml.Marshal returns an error | [
"Marshal",
"panics",
"if",
"xml",
".",
"Marshal",
"returns",
"an",
"error"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/sts/internal/types.go#L673-L679 | train |
vmware/govmomi | sts/internal/types.go | mkns | func mkns(ns string, obj interface{}, name ...*xml.Name) string {
ns += ":"
for i := range name {
name[i].Space = ""
if !strings.HasPrefix(name[i].Local, ns) {
name[i].Local = ns + name[i].Local
}
}
return Marshal(obj)
} | go | func mkns(ns string, obj interface{}, name ...*xml.Name) string {
ns += ":"
for i := range name {
name[i].Space = ""
if !strings.HasPrefix(name[i].Local, ns) {
name[i].Local = ns + name[i].Local
}
}
return Marshal(obj)
} | [
"func",
"mkns",
"(",
"ns",
"string",
",",
"obj",
"interface",
"{",
"}",
",",
"name",
"...",
"*",
"xml",
".",
"Name",
")",
"string",
"{",
"ns",
"+=",
"\"",
"\"",
"\n",
"for",
"i",
":=",
"range",
"name",
"{",
"name",
"[",
"i",
"]",
".",
"Space",
... | // mkns prepends the given namespace to xml.Name.Local and returns obj encoded as xml.
// Note that the namespace is required when encoding, but the namespace prefix must not be
// present when decoding as Go's decoding does not handle namespace prefix. | [
"mkns",
"prepends",
"the",
"given",
"namespace",
"to",
"xml",
".",
"Name",
".",
"Local",
"and",
"returns",
"obj",
"encoded",
"as",
"xml",
".",
"Note",
"that",
"the",
"namespace",
"is",
"required",
"when",
"encoding",
"but",
"the",
"namespace",
"prefix",
"m... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/sts/internal/types.go#L684-L694 | train |
vmware/govmomi | view/container_view.go | Retrieve | func (v ContainerView) Retrieve(ctx context.Context, kind []string, ps []string, dst interface{}) error {
pc := property.DefaultCollector(v.Client())
ospec := types.ObjectSpec{
Obj: v.Reference(),
Skip: types.NewBool(true),
SelectSet: []types.BaseSelectionSpec{
&types.TraversalSpec{
Type: v.Reference()... | go | func (v ContainerView) Retrieve(ctx context.Context, kind []string, ps []string, dst interface{}) error {
pc := property.DefaultCollector(v.Client())
ospec := types.ObjectSpec{
Obj: v.Reference(),
Skip: types.NewBool(true),
SelectSet: []types.BaseSelectionSpec{
&types.TraversalSpec{
Type: v.Reference()... | [
"func",
"(",
"v",
"ContainerView",
")",
"Retrieve",
"(",
"ctx",
"context",
".",
"Context",
",",
"kind",
"[",
"]",
"string",
",",
"ps",
"[",
"]",
"string",
",",
"dst",
"interface",
"{",
"}",
")",
"error",
"{",
"pc",
":=",
"property",
".",
"DefaultColl... | // Retrieve populates dst as property.Collector.Retrieve does, for all entities in the view of types specified by kind. | [
"Retrieve",
"populates",
"dst",
"as",
"property",
".",
"Collector",
".",
"Retrieve",
"does",
"for",
"all",
"entities",
"in",
"the",
"view",
"of",
"types",
"specified",
"by",
"kind",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/view/container_view.go#L39-L93 | train |
vmware/govmomi | view/container_view.go | Find | func (v ContainerView) Find(ctx context.Context, kind []string, filter property.Filter) ([]types.ManagedObjectReference, error) {
if len(filter) == 0 {
// Ensure we have at least 1 filter to avoid retrieving all properties.
filter = property.Filter{"name": "*"}
}
var content []types.ObjectContent
err := v.Ret... | go | func (v ContainerView) Find(ctx context.Context, kind []string, filter property.Filter) ([]types.ManagedObjectReference, error) {
if len(filter) == 0 {
// Ensure we have at least 1 filter to avoid retrieving all properties.
filter = property.Filter{"name": "*"}
}
var content []types.ObjectContent
err := v.Ret... | [
"func",
"(",
"v",
"ContainerView",
")",
"Find",
"(",
"ctx",
"context",
".",
"Context",
",",
"kind",
"[",
"]",
"string",
",",
"filter",
"property",
".",
"Filter",
")",
"(",
"[",
"]",
"types",
".",
"ManagedObjectReference",
",",
"error",
")",
"{",
"if",
... | // Find returns object references for entities of type kind, matching the given filter. | [
"Find",
"returns",
"object",
"references",
"for",
"entities",
"of",
"type",
"kind",
"matching",
"the",
"given",
"filter",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/view/container_view.go#L116-L130 | train |
vmware/govmomi | simulator/virtual_machine.go | updateDiskLayouts | func (vm *VirtualMachine) updateDiskLayouts() types.BaseMethodFault {
var disksLayout []types.VirtualMachineFileLayoutDiskLayout
var disksLayoutEx []types.VirtualMachineFileLayoutExDiskLayout
disks := object.VirtualDeviceList(vm.Config.Hardware.Device).SelectByType((*types.VirtualDisk)(nil))
for _, disk := range d... | go | func (vm *VirtualMachine) updateDiskLayouts() types.BaseMethodFault {
var disksLayout []types.VirtualMachineFileLayoutDiskLayout
var disksLayoutEx []types.VirtualMachineFileLayoutExDiskLayout
disks := object.VirtualDeviceList(vm.Config.Hardware.Device).SelectByType((*types.VirtualDisk)(nil))
for _, disk := range d... | [
"func",
"(",
"vm",
"*",
"VirtualMachine",
")",
"updateDiskLayouts",
"(",
")",
"types",
".",
"BaseMethodFault",
"{",
"var",
"disksLayout",
"[",
"]",
"types",
".",
"VirtualMachineFileLayoutDiskLayout",
"\n",
"var",
"disksLayoutEx",
"[",
"]",
"types",
".",
"Virtual... | // Updates both vm.Layout.Disk and vm.LayoutEx.Disk | [
"Updates",
"both",
"vm",
".",
"Layout",
".",
"Disk",
"and",
"vm",
".",
"LayoutEx",
".",
"Disk"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/virtual_machine.go#L519-L583 | train |
vmware/govmomi | govc/flags/output.go | Log | func (flag *OutputFlag) Log(s string) (int, error) {
if len(s) > 0 && s[0] == '\r' {
flag.Write([]byte{'\r', 033, '[', 'K'})
s = s[1:]
}
return flag.WriteString(time.Now().Format("[02-01-06 15:04:05] ") + s)
} | go | func (flag *OutputFlag) Log(s string) (int, error) {
if len(s) > 0 && s[0] == '\r' {
flag.Write([]byte{'\r', 033, '[', 'K'})
s = s[1:]
}
return flag.WriteString(time.Now().Format("[02-01-06 15:04:05] ") + s)
} | [
"func",
"(",
"flag",
"*",
"OutputFlag",
")",
"Log",
"(",
"s",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
">",
"0",
"&&",
"s",
"[",
"0",
"]",
"==",
"'\\r'",
"{",
"flag",
".",
"Write",
"(",
"[",
"]",
"byte"... | // Log outputs the specified string, prefixed with the current time.
// A newline is not automatically added. If the specified string
// starts with a '\r', the current line is cleared first. | [
"Log",
"outputs",
"the",
"specified",
"string",
"prefixed",
"with",
"the",
"current",
"time",
".",
"A",
"newline",
"is",
"not",
"automatically",
"added",
".",
"If",
"the",
"specified",
"string",
"starts",
"with",
"a",
"\\",
"r",
"the",
"current",
"line",
"... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/output.go#L80-L87 | train |
vmware/govmomi | vim25/mo/retrieve.go | ObjectContentToType | func ObjectContentToType(o types.ObjectContent) (interface{}, error) {
// Expect no properties in the missing set
for _, p := range o.MissingSet {
if ignoreMissingProperty(o.Obj, p) {
continue
}
return nil, soap.WrapVimFault(p.Fault.Fault)
}
ti := typeInfoForType(o.Obj.Type)
v, err := ti.LoadFromObjectC... | go | func ObjectContentToType(o types.ObjectContent) (interface{}, error) {
// Expect no properties in the missing set
for _, p := range o.MissingSet {
if ignoreMissingProperty(o.Obj, p) {
continue
}
return nil, soap.WrapVimFault(p.Fault.Fault)
}
ti := typeInfoForType(o.Obj.Type)
v, err := ti.LoadFromObjectC... | [
"func",
"ObjectContentToType",
"(",
"o",
"types",
".",
"ObjectContent",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"// Expect no properties in the missing set",
"for",
"_",
",",
"p",
":=",
"range",
"o",
".",
"MissingSet",
"{",
"if",
"ignoreMissin... | // ObjectContentToType loads an ObjectContent value into the value it
// represents. If the ObjectContent value has a non-empty 'MissingSet' field,
// it returns the first fault it finds there as error. If the 'MissingSet'
// field is empty, it returns a pointer to a reflect.Value. It handles contain
// nested properti... | [
"ObjectContentToType",
"loads",
"an",
"ObjectContent",
"value",
"into",
"the",
"value",
"it",
"represents",
".",
"If",
"the",
"ObjectContent",
"value",
"has",
"a",
"non",
"-",
"empty",
"MissingSet",
"field",
"it",
"returns",
"the",
"first",
"fault",
"it",
"fin... | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/mo/retrieve.go#L49-L66 | train |
vmware/govmomi | vim25/mo/retrieve.go | ApplyPropertyChange | func ApplyPropertyChange(obj Reference, changes []types.PropertyChange) {
t := typeInfoForType(obj.Reference().Type)
v := reflect.ValueOf(obj)
for _, p := range changes {
rv, ok := t.props[p.Name]
if !ok {
continue
}
assignValue(v, rv, reflect.ValueOf(p.Val))
}
} | go | func ApplyPropertyChange(obj Reference, changes []types.PropertyChange) {
t := typeInfoForType(obj.Reference().Type)
v := reflect.ValueOf(obj)
for _, p := range changes {
rv, ok := t.props[p.Name]
if !ok {
continue
}
assignValue(v, rv, reflect.ValueOf(p.Val))
}
} | [
"func",
"ApplyPropertyChange",
"(",
"obj",
"Reference",
",",
"changes",
"[",
"]",
"types",
".",
"PropertyChange",
")",
"{",
"t",
":=",
"typeInfoForType",
"(",
"obj",
".",
"Reference",
"(",
")",
".",
"Type",
")",
"\n",
"v",
":=",
"reflect",
".",
"ValueOf"... | // ApplyPropertyChange converts the response of a call to WaitForUpdates
// and applies it to the given managed object. | [
"ApplyPropertyChange",
"converts",
"the",
"response",
"of",
"a",
"call",
"to",
"WaitForUpdates",
"and",
"applies",
"it",
"to",
"the",
"given",
"managed",
"object",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/mo/retrieve.go#L70-L82 | train |
vmware/govmomi | vim25/mo/retrieve.go | LoadRetrievePropertiesResponse | func LoadRetrievePropertiesResponse(res *types.RetrievePropertiesResponse, dst interface{}) error {
rt := reflect.TypeOf(dst)
if rt == nil || rt.Kind() != reflect.Ptr {
panic("need pointer")
}
rv := reflect.ValueOf(dst).Elem()
if !rv.CanSet() {
panic("cannot set dst")
}
isSlice := false
switch rt.Elem().K... | go | func LoadRetrievePropertiesResponse(res *types.RetrievePropertiesResponse, dst interface{}) error {
rt := reflect.TypeOf(dst)
if rt == nil || rt.Kind() != reflect.Ptr {
panic("need pointer")
}
rv := reflect.ValueOf(dst).Elem()
if !rv.CanSet() {
panic("cannot set dst")
}
isSlice := false
switch rt.Elem().K... | [
"func",
"LoadRetrievePropertiesResponse",
"(",
"res",
"*",
"types",
".",
"RetrievePropertiesResponse",
",",
"dst",
"interface",
"{",
"}",
")",
"error",
"{",
"rt",
":=",
"reflect",
".",
"TypeOf",
"(",
"dst",
")",
"\n",
"if",
"rt",
"==",
"nil",
"||",
"rt",
... | // LoadRetrievePropertiesResponse converts the response of a call to
// RetrieveProperties to one or more managed objects. | [
"LoadRetrievePropertiesResponse",
"converts",
"the",
"response",
"of",
"a",
"call",
"to",
"RetrieveProperties",
"to",
"one",
"or",
"more",
"managed",
"objects",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/mo/retrieve.go#L86-L152 | train |
vmware/govmomi | vim25/mo/retrieve.go | RetrievePropertiesForRequest | func RetrievePropertiesForRequest(ctx context.Context, r soap.RoundTripper, req types.RetrieveProperties, dst interface{}) error {
res, err := methods.RetrieveProperties(ctx, r, &req)
if err != nil {
return err
}
return LoadRetrievePropertiesResponse(res, dst)
} | go | func RetrievePropertiesForRequest(ctx context.Context, r soap.RoundTripper, req types.RetrieveProperties, dst interface{}) error {
res, err := methods.RetrieveProperties(ctx, r, &req)
if err != nil {
return err
}
return LoadRetrievePropertiesResponse(res, dst)
} | [
"func",
"RetrievePropertiesForRequest",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"soap",
".",
"RoundTripper",
",",
"req",
"types",
".",
"RetrieveProperties",
",",
"dst",
"interface",
"{",
"}",
")",
"error",
"{",
"res",
",",
"err",
":=",
"methods",
... | // RetrievePropertiesForRequest calls the RetrieveProperties method with the
// specified request and decodes the response struct into the value pointed to
// by dst. | [
"RetrievePropertiesForRequest",
"calls",
"the",
"RetrieveProperties",
"method",
"with",
"the",
"specified",
"request",
"and",
"decodes",
"the",
"response",
"struct",
"into",
"the",
"value",
"pointed",
"to",
"by",
"dst",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/mo/retrieve.go#L157-L164 | train |
vmware/govmomi | vim25/mo/retrieve.go | RetrieveProperties | func RetrieveProperties(ctx context.Context, r soap.RoundTripper, pc, obj types.ManagedObjectReference, dst interface{}) error {
req := types.RetrieveProperties{
This: pc,
SpecSet: []types.PropertyFilterSpec{
{
ObjectSet: []types.ObjectSpec{
{
Obj: obj,
Skip: types.NewBool(false),
},
... | go | func RetrieveProperties(ctx context.Context, r soap.RoundTripper, pc, obj types.ManagedObjectReference, dst interface{}) error {
req := types.RetrieveProperties{
This: pc,
SpecSet: []types.PropertyFilterSpec{
{
ObjectSet: []types.ObjectSpec{
{
Obj: obj,
Skip: types.NewBool(false),
},
... | [
"func",
"RetrieveProperties",
"(",
"ctx",
"context",
".",
"Context",
",",
"r",
"soap",
".",
"RoundTripper",
",",
"pc",
",",
"obj",
"types",
".",
"ManagedObjectReference",
",",
"dst",
"interface",
"{",
"}",
")",
"error",
"{",
"req",
":=",
"types",
".",
"R... | // RetrieveProperties retrieves the properties of the managed object specified
// as obj and decodes the response struct into the value pointed to by dst. | [
"RetrieveProperties",
"retrieves",
"the",
"properties",
"of",
"the",
"managed",
"object",
"specified",
"as",
"obj",
"and",
"decodes",
"the",
"response",
"struct",
"into",
"the",
"value",
"pointed",
"to",
"by",
"dst",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/mo/retrieve.go#L168-L190 | train |
vmware/govmomi | toolbox/hgfs/server.go | NewServer | func NewServer() *Server {
if f := flag.Lookup("toolbox.trace"); f != nil {
Trace, _ = strconv.ParseBool(f.Value.String())
}
s := &Server{
sessions: make(map[uint64]*session),
schemes: make(map[string]FileHandler),
chmod: os.Chmod,
chown: os.Chown,
}
s.handlers = map[int32]func(*Packet) (interfa... | go | func NewServer() *Server {
if f := flag.Lookup("toolbox.trace"); f != nil {
Trace, _ = strconv.ParseBool(f.Value.String())
}
s := &Server{
sessions: make(map[uint64]*session),
schemes: make(map[string]FileHandler),
chmod: os.Chmod,
chown: os.Chown,
}
s.handlers = map[int32]func(*Packet) (interfa... | [
"func",
"NewServer",
"(",
")",
"*",
"Server",
"{",
"if",
"f",
":=",
"flag",
".",
"Lookup",
"(",
"\"",
"\"",
")",
";",
"f",
"!=",
"nil",
"{",
"Trace",
",",
"_",
"=",
"strconv",
".",
"ParseBool",
"(",
"f",
".",
"Value",
".",
"String",
"(",
")",
... | // NewServer creates a new Server instance with the default handlers | [
"NewServer",
"creates",
"a",
"new",
"Server",
"instance",
"with",
"the",
"default",
"handlers"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/server.go#L57-L86 | train |
vmware/govmomi | toolbox/hgfs/server.go | RegisterFileHandler | func (s *Server) RegisterFileHandler(scheme string, handler FileHandler) {
if handler == nil {
delete(s.schemes, scheme)
return
}
s.schemes[scheme] = handler
} | go | func (s *Server) RegisterFileHandler(scheme string, handler FileHandler) {
if handler == nil {
delete(s.schemes, scheme)
return
}
s.schemes[scheme] = handler
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"RegisterFileHandler",
"(",
"scheme",
"string",
",",
"handler",
"FileHandler",
")",
"{",
"if",
"handler",
"==",
"nil",
"{",
"delete",
"(",
"s",
".",
"schemes",
",",
"scheme",
")",
"\n",
"return",
"\n",
"}",
"\n",
... | // RegisterFileHandler enables dispatch to handler for the given scheme. | [
"RegisterFileHandler",
"enables",
"dispatch",
"to",
"handler",
"for",
"the",
"given",
"scheme",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/server.go#L89-L95 | train |
vmware/govmomi | toolbox/hgfs/server.go | Dispatch | func (s *Server) Dispatch(packet []byte) ([]byte, error) {
req := &Packet{}
err := req.UnmarshalBinary(packet)
if err != nil {
return nil, err
}
if Trace {
fmt.Fprintf(os.Stderr, "[hgfs] request %#v\n", req.Header)
}
var res interface{}
handler, ok := s.handlers[req.Op]
if ok {
res, err = handler(re... | go | func (s *Server) Dispatch(packet []byte) ([]byte, error) {
req := &Packet{}
err := req.UnmarshalBinary(packet)
if err != nil {
return nil, err
}
if Trace {
fmt.Fprintf(os.Stderr, "[hgfs] request %#v\n", req.Header)
}
var res interface{}
handler, ok := s.handlers[req.Op]
if ok {
res, err = handler(re... | [
"func",
"(",
"s",
"*",
"Server",
")",
"Dispatch",
"(",
"packet",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"req",
":=",
"&",
"Packet",
"{",
"}",
"\n\n",
"err",
":=",
"req",
".",
"UnmarshalBinary",
"(",
"packet",
")",
... | // Dispatch unpacks the given request packet and dispatches to the appropriate handler | [
"Dispatch",
"unpacks",
"the",
"given",
"request",
"packet",
"and",
"dispatches",
"to",
"the",
"appropriate",
"handler"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/server.go#L98-L123 | train |
vmware/govmomi | toolbox/hgfs/server.go | urlParse | func urlParse(name string) *url.URL {
var info os.FileInfo
u, err := url.Parse(name)
if err == nil && u.Scheme == "" {
info, err = os.Stat(u.Path)
if err == nil && info.IsDir() {
u.Scheme = ArchiveScheme // special case for IsDir()
return u
}
}
u, err = url.Parse(strings.TrimPrefix(name, "/")) // mus... | go | func urlParse(name string) *url.URL {
var info os.FileInfo
u, err := url.Parse(name)
if err == nil && u.Scheme == "" {
info, err = os.Stat(u.Path)
if err == nil && info.IsDir() {
u.Scheme = ArchiveScheme // special case for IsDir()
return u
}
}
u, err = url.Parse(strings.TrimPrefix(name, "/")) // mus... | [
"func",
"urlParse",
"(",
"name",
"string",
")",
"*",
"url",
".",
"URL",
"{",
"var",
"info",
"os",
".",
"FileInfo",
"\n\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"name",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"u",
".",
"Scheme",
"... | // urlParse attempts to convert the given name to a URL with scheme for use as FileHandler dispatch. | [
"urlParse",
"attempts",
"to",
"convert",
"the",
"given",
"name",
"to",
"a",
"URL",
"with",
"scheme",
"for",
"use",
"as",
"FileHandler",
"dispatch",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/server.go#L142-L168 | train |
vmware/govmomi | toolbox/hgfs/server.go | OpenFile | func (s *Server) OpenFile(name string, mode int32) (File, error) {
u := urlParse(name)
if h, ok := s.schemes[u.Scheme]; ok {
f, serr := h.Open(u, mode)
if serr != os.ErrNotExist {
return f, serr
}
}
switch mode {
case OpenModeReadOnly:
return os.Open(filepath.Clean(name))
case OpenModeWriteOnly:
fl... | go | func (s *Server) OpenFile(name string, mode int32) (File, error) {
u := urlParse(name)
if h, ok := s.schemes[u.Scheme]; ok {
f, serr := h.Open(u, mode)
if serr != os.ErrNotExist {
return f, serr
}
}
switch mode {
case OpenModeReadOnly:
return os.Open(filepath.Clean(name))
case OpenModeWriteOnly:
fl... | [
"func",
"(",
"s",
"*",
"Server",
")",
"OpenFile",
"(",
"name",
"string",
",",
"mode",
"int32",
")",
"(",
"File",
",",
"error",
")",
"{",
"u",
":=",
"urlParse",
"(",
"name",
")",
"\n\n",
"if",
"h",
",",
"ok",
":=",
"s",
".",
"schemes",
"[",
"u",... | // OpenFile selects the File implementation based on file type and mode. | [
"OpenFile",
"selects",
"the",
"File",
"implementation",
"based",
"on",
"file",
"type",
"and",
"mode",
"."
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/server.go#L171-L193 | train |
vmware/govmomi | toolbox/hgfs/server.go | CreateSessionV4 | func (s *Server) CreateSessionV4(p *Packet) (interface{}, error) {
const SessionMaxPacketSizeValid = 0x1
req := new(RequestCreateSessionV4)
err := UnmarshalBinary(p.Payload, req)
if err != nil {
return nil, err
}
res := &ReplyCreateSessionV4{
SessionID: uint64(rand.Int63()),
NumCapabilities: uint32(... | go | func (s *Server) CreateSessionV4(p *Packet) (interface{}, error) {
const SessionMaxPacketSizeValid = 0x1
req := new(RequestCreateSessionV4)
err := UnmarshalBinary(p.Payload, req)
if err != nil {
return nil, err
}
res := &ReplyCreateSessionV4{
SessionID: uint64(rand.Int63()),
NumCapabilities: uint32(... | [
"func",
"(",
"s",
"*",
"Server",
")",
"CreateSessionV4",
"(",
"p",
"*",
"Packet",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"const",
"SessionMaxPacketSizeValid",
"=",
"0x1",
"\n\n",
"req",
":=",
"new",
"(",
"RequestCreateSessionV4",
")",
"... | // CreateSessionV4 handls OpCreateSessionV4 requests | [
"CreateSessionV4",
"handls",
"OpCreateSessionV4",
"requests"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/server.go#L271-L297 | train |
vmware/govmomi | toolbox/hgfs/server.go | DestroySessionV4 | func (s *Server) DestroySessionV4(p *Packet) (interface{}, error) {
if s.removeSession(p.SessionID) {
return &ReplyDestroySessionV4{}, nil
}
return nil, &Status{Code: StatusStaleSession}
} | go | func (s *Server) DestroySessionV4(p *Packet) (interface{}, error) {
if s.removeSession(p.SessionID) {
return &ReplyDestroySessionV4{}, nil
}
return nil, &Status{Code: StatusStaleSession}
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"DestroySessionV4",
"(",
"p",
"*",
"Packet",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"s",
".",
"removeSession",
"(",
"p",
".",
"SessionID",
")",
"{",
"return",
"&",
"ReplyDestroySessionV4",
... | // DestroySessionV4 handls OpDestroySessionV4 requests | [
"DestroySessionV4",
"handls",
"OpDestroySessionV4",
"requests"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/server.go#L300-L306 | train |
vmware/govmomi | toolbox/hgfs/server.go | Stat | func (a *AttrV2) Stat(info os.FileInfo) {
switch {
case info.IsDir():
a.Type = FileTypeDirectory
case info.Mode()&os.ModeSymlink == os.ModeSymlink:
a.Type = FileTypeSymlink
default:
a.Type = FileTypeRegular
}
a.Size = uint64(info.Size())
a.Mask = AttrValidType | AttrValidSize
a.sysStat(info)
} | go | func (a *AttrV2) Stat(info os.FileInfo) {
switch {
case info.IsDir():
a.Type = FileTypeDirectory
case info.Mode()&os.ModeSymlink == os.ModeSymlink:
a.Type = FileTypeSymlink
default:
a.Type = FileTypeRegular
}
a.Size = uint64(info.Size())
a.Mask = AttrValidType | AttrValidSize
a.sysStat(info)
} | [
"func",
"(",
"a",
"*",
"AttrV2",
")",
"Stat",
"(",
"info",
"os",
".",
"FileInfo",
")",
"{",
"switch",
"{",
"case",
"info",
".",
"IsDir",
"(",
")",
":",
"a",
".",
"Type",
"=",
"FileTypeDirectory",
"\n",
"case",
"info",
".",
"Mode",
"(",
")",
"&",
... | // Stat maps os.FileInfo to AttrV2 | [
"Stat",
"maps",
"os",
".",
"FileInfo",
"to",
"AttrV2"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/server.go#L309-L324 | train |
vmware/govmomi | toolbox/hgfs/server.go | GetattrV2 | func (s *Server) GetattrV2(p *Packet) (interface{}, error) {
res := &ReplyGetattrV2{}
req := new(RequestGetattrV2)
err := UnmarshalBinary(p.Payload, req)
if err != nil {
return nil, err
}
name := req.FileName.Path()
info, err := s.Stat(name)
if err != nil {
return nil, err
}
res.Attr.Stat(info)
retur... | go | func (s *Server) GetattrV2(p *Packet) (interface{}, error) {
res := &ReplyGetattrV2{}
req := new(RequestGetattrV2)
err := UnmarshalBinary(p.Payload, req)
if err != nil {
return nil, err
}
name := req.FileName.Path()
info, err := s.Stat(name)
if err != nil {
return nil, err
}
res.Attr.Stat(info)
retur... | [
"func",
"(",
"s",
"*",
"Server",
")",
"GetattrV2",
"(",
"p",
"*",
"Packet",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"res",
":=",
"&",
"ReplyGetattrV2",
"{",
"}",
"\n\n",
"req",
":=",
"new",
"(",
"RequestGetattrV2",
")",
"\n",
"err"... | // GetattrV2 handles OpGetattrV2 requests | [
"GetattrV2",
"handles",
"OpGetattrV2",
"requests"
] | fc3f0e9d2275df0e497a80917807a7c72d3c35bc | https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/server.go#L327-L345 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.