id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
listlengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
listlengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
|---|---|---|---|---|---|---|---|---|---|---|---|
21,500
|
vmware/govmomi
|
vapi/tags/categories.go
|
CreateCategory
|
func (c *Manager) CreateCategory(ctx context.Context, category *Category) (string, error) {
// create avoids the annoyance of CreateTag requiring field keys to be included in the request,
// even though the field value can be empty.
type create struct {
Name string `json:"name"`
Description string `json:"description"`
Cardinality string `json:"cardinality"`
AssociableTypes []string `json:"associable_types"`
}
spec := struct {
Category create `json:"create_spec"`
}{
Category: create{
Name: category.Name,
Description: category.Description,
Cardinality: category.Cardinality,
AssociableTypes: category.AssociableTypes,
},
}
if spec.Category.AssociableTypes == nil {
// otherwise create fails with invalid_argument
spec.Category.AssociableTypes = []string{}
}
url := internal.URL(c, internal.CategoryPath)
var res string
return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res)
}
|
go
|
func (c *Manager) CreateCategory(ctx context.Context, category *Category) (string, error) {
// create avoids the annoyance of CreateTag requiring field keys to be included in the request,
// even though the field value can be empty.
type create struct {
Name string `json:"name"`
Description string `json:"description"`
Cardinality string `json:"cardinality"`
AssociableTypes []string `json:"associable_types"`
}
spec := struct {
Category create `json:"create_spec"`
}{
Category: create{
Name: category.Name,
Description: category.Description,
Cardinality: category.Cardinality,
AssociableTypes: category.AssociableTypes,
},
}
if spec.Category.AssociableTypes == nil {
// otherwise create fails with invalid_argument
spec.Category.AssociableTypes = []string{}
}
url := internal.URL(c, internal.CategoryPath)
var res string
return res, c.Do(ctx, url.Request(http.MethodPost, spec), &res)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"CreateCategory",
"(",
"ctx",
"context",
".",
"Context",
",",
"category",
"*",
"Category",
")",
"(",
"string",
",",
"error",
")",
"{",
"// create avoids the annoyance of CreateTag requiring field keys to be included in the request,",
"// even though the field value can be empty.",
"type",
"create",
"struct",
"{",
"Name",
"string",
"`json:\"name\"`",
"\n",
"Description",
"string",
"`json:\"description\"`",
"\n",
"Cardinality",
"string",
"`json:\"cardinality\"`",
"\n",
"AssociableTypes",
"[",
"]",
"string",
"`json:\"associable_types\"`",
"\n",
"}",
"\n",
"spec",
":=",
"struct",
"{",
"Category",
"create",
"`json:\"create_spec\"`",
"\n",
"}",
"{",
"Category",
":",
"create",
"{",
"Name",
":",
"category",
".",
"Name",
",",
"Description",
":",
"category",
".",
"Description",
",",
"Cardinality",
":",
"category",
".",
"Cardinality",
",",
"AssociableTypes",
":",
"category",
".",
"AssociableTypes",
",",
"}",
",",
"}",
"\n",
"if",
"spec",
".",
"Category",
".",
"AssociableTypes",
"==",
"nil",
"{",
"// otherwise create fails with invalid_argument",
"spec",
".",
"Category",
".",
"AssociableTypes",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"CategoryPath",
")",
"\n",
"var",
"res",
"string",
"\n",
"return",
"res",
",",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodPost",
",",
"spec",
")",
",",
"&",
"res",
")",
"\n",
"}"
] |
// CreateCategory creates a new category and returns the category ID.
|
[
"CreateCategory",
"creates",
"a",
"new",
"category",
"and",
"returns",
"the",
"category",
"ID",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/categories.go#L67-L93
|
21,501
|
vmware/govmomi
|
vapi/tags/categories.go
|
UpdateCategory
|
func (c *Manager) UpdateCategory(ctx context.Context, category *Category) error {
spec := struct {
Category Category `json:"update_spec"`
}{
Category: Category{
AssociableTypes: category.AssociableTypes,
Cardinality: category.Cardinality,
Description: category.Description,
Name: category.Name,
},
}
url := internal.URL(c, internal.CategoryPath).WithID(category.ID)
return c.Do(ctx, url.Request(http.MethodPatch, spec), nil)
}
|
go
|
func (c *Manager) UpdateCategory(ctx context.Context, category *Category) error {
spec := struct {
Category Category `json:"update_spec"`
}{
Category: Category{
AssociableTypes: category.AssociableTypes,
Cardinality: category.Cardinality,
Description: category.Description,
Name: category.Name,
},
}
url := internal.URL(c, internal.CategoryPath).WithID(category.ID)
return c.Do(ctx, url.Request(http.MethodPatch, spec), nil)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"UpdateCategory",
"(",
"ctx",
"context",
".",
"Context",
",",
"category",
"*",
"Category",
")",
"error",
"{",
"spec",
":=",
"struct",
"{",
"Category",
"Category",
"`json:\"update_spec\"`",
"\n",
"}",
"{",
"Category",
":",
"Category",
"{",
"AssociableTypes",
":",
"category",
".",
"AssociableTypes",
",",
"Cardinality",
":",
"category",
".",
"Cardinality",
",",
"Description",
":",
"category",
".",
"Description",
",",
"Name",
":",
"category",
".",
"Name",
",",
"}",
",",
"}",
"\n",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"CategoryPath",
")",
".",
"WithID",
"(",
"category",
".",
"ID",
")",
"\n",
"return",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodPatch",
",",
"spec",
")",
",",
"nil",
")",
"\n",
"}"
] |
// UpdateCategory can update one or more of the AssociableTypes, Cardinality, Description and Name fields.
|
[
"UpdateCategory",
"can",
"update",
"one",
"or",
"more",
"of",
"the",
"AssociableTypes",
"Cardinality",
"Description",
"and",
"Name",
"fields",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/categories.go#L96-L109
|
21,502
|
vmware/govmomi
|
vapi/tags/categories.go
|
DeleteCategory
|
func (c *Manager) DeleteCategory(ctx context.Context, category *Category) error {
url := internal.URL(c, internal.CategoryPath).WithID(category.ID)
return c.Do(ctx, url.Request(http.MethodDelete), nil)
}
|
go
|
func (c *Manager) DeleteCategory(ctx context.Context, category *Category) error {
url := internal.URL(c, internal.CategoryPath).WithID(category.ID)
return c.Do(ctx, url.Request(http.MethodDelete), nil)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"DeleteCategory",
"(",
"ctx",
"context",
".",
"Context",
",",
"category",
"*",
"Category",
")",
"error",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"CategoryPath",
")",
".",
"WithID",
"(",
"category",
".",
"ID",
")",
"\n",
"return",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodDelete",
")",
",",
"nil",
")",
"\n",
"}"
] |
// DeleteCategory deletes an existing category.
|
[
"DeleteCategory",
"deletes",
"an",
"existing",
"category",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/categories.go#L112-L115
|
21,503
|
vmware/govmomi
|
vapi/tags/categories.go
|
GetCategory
|
func (c *Manager) GetCategory(ctx context.Context, id string) (*Category, error) {
if isName(id) {
cat, err := c.GetCategories(ctx)
if err != nil {
return nil, err
}
for i := range cat {
if cat[i].Name == id {
return &cat[i], nil
}
}
}
url := internal.URL(c, internal.CategoryPath).WithID(id)
var res Category
return &res, c.Do(ctx, url.Request(http.MethodGet), &res)
}
|
go
|
func (c *Manager) GetCategory(ctx context.Context, id string) (*Category, error) {
if isName(id) {
cat, err := c.GetCategories(ctx)
if err != nil {
return nil, err
}
for i := range cat {
if cat[i].Name == id {
return &cat[i], nil
}
}
}
url := internal.URL(c, internal.CategoryPath).WithID(id)
var res Category
return &res, c.Do(ctx, url.Request(http.MethodGet), &res)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"GetCategory",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
"string",
")",
"(",
"*",
"Category",
",",
"error",
")",
"{",
"if",
"isName",
"(",
"id",
")",
"{",
"cat",
",",
"err",
":=",
"c",
".",
"GetCategories",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"cat",
"{",
"if",
"cat",
"[",
"i",
"]",
".",
"Name",
"==",
"id",
"{",
"return",
"&",
"cat",
"[",
"i",
"]",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"CategoryPath",
")",
".",
"WithID",
"(",
"id",
")",
"\n",
"var",
"res",
"Category",
"\n",
"return",
"&",
"res",
",",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodGet",
")",
",",
"&",
"res",
")",
"\n",
"}"
] |
// GetCategory fetches the category information for the given identifier.
// The id parameter can be a Category ID or Category Name.
|
[
"GetCategory",
"fetches",
"the",
"category",
"information",
"for",
"the",
"given",
"identifier",
".",
"The",
"id",
"parameter",
"can",
"be",
"a",
"Category",
"ID",
"or",
"Category",
"Name",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/categories.go#L119-L135
|
21,504
|
vmware/govmomi
|
vapi/tags/categories.go
|
ListCategories
|
func (c *Manager) ListCategories(ctx context.Context) ([]string, error) {
url := internal.URL(c, internal.CategoryPath)
var res []string
return res, c.Do(ctx, url.Request(http.MethodGet), &res)
}
|
go
|
func (c *Manager) ListCategories(ctx context.Context) ([]string, error) {
url := internal.URL(c, internal.CategoryPath)
var res []string
return res, c.Do(ctx, url.Request(http.MethodGet), &res)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"ListCategories",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"CategoryPath",
")",
"\n",
"var",
"res",
"[",
"]",
"string",
"\n",
"return",
"res",
",",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodGet",
")",
",",
"&",
"res",
")",
"\n",
"}"
] |
// ListCategories returns all category IDs in the system.
|
[
"ListCategories",
"returns",
"all",
"category",
"IDs",
"in",
"the",
"system",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/categories.go#L138-L142
|
21,505
|
vmware/govmomi
|
vapi/tags/categories.go
|
GetCategories
|
func (c *Manager) GetCategories(ctx context.Context) ([]Category, error) {
ids, err := c.ListCategories(ctx)
if err != nil {
return nil, fmt.Errorf("list categories: %s", err)
}
var categories []Category
for _, id := range ids {
category, err := c.GetCategory(ctx, id)
if err != nil {
return nil, fmt.Errorf("get category %s: %s", id, err)
}
categories = append(categories, *category)
}
return categories, nil
}
|
go
|
func (c *Manager) GetCategories(ctx context.Context) ([]Category, error) {
ids, err := c.ListCategories(ctx)
if err != nil {
return nil, fmt.Errorf("list categories: %s", err)
}
var categories []Category
for _, id := range ids {
category, err := c.GetCategory(ctx, id)
if err != nil {
return nil, fmt.Errorf("get category %s: %s", id, err)
}
categories = append(categories, *category)
}
return categories, nil
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"GetCategories",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"Category",
",",
"error",
")",
"{",
"ids",
",",
"err",
":=",
"c",
".",
"ListCategories",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"categories",
"[",
"]",
"Category",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"ids",
"{",
"category",
",",
"err",
":=",
"c",
".",
"GetCategory",
"(",
"ctx",
",",
"id",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"id",
",",
"err",
")",
"\n",
"}",
"\n\n",
"categories",
"=",
"append",
"(",
"categories",
",",
"*",
"category",
")",
"\n\n",
"}",
"\n",
"return",
"categories",
",",
"nil",
"\n",
"}"
] |
// GetCategories fetches an array of category information in the system.
|
[
"GetCategories",
"fetches",
"an",
"array",
"of",
"category",
"information",
"in",
"the",
"system",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/tags/categories.go#L145-L162
|
21,506
|
vmware/govmomi
|
vapi/simulator/simulator.go
|
New
|
func New(u *url.URL, settings []vim.BaseOptionValue) (string, http.Handler) {
s := &handler{
ServeMux: http.NewServeMux(),
URL: *u,
Category: make(map[string]*tags.Category),
Tag: make(map[string]*tags.Tag),
Association: make(map[string]map[internal.AssociatedObject]bool),
Session: make(map[string]*session),
Library: make(map[string]content),
Update: make(map[string]update),
}
handlers := []struct {
p string
m http.HandlerFunc
}{
{internal.SessionPath, s.session},
{internal.CategoryPath, s.category},
{internal.CategoryPath + "/", s.categoryID},
{internal.TagPath, s.tag},
{internal.TagPath + "/", s.tagID},
{internal.AssociationPath, s.association},
{internal.AssociationPath + "/", s.associationID},
{internal.LibraryPath, s.library},
{internal.LocalLibraryPath, s.library},
{internal.LibraryPath + "/", s.libraryID},
{internal.LocalLibraryPath + "/", s.libraryID},
{internal.LibraryItemPath, s.libraryItem},
{internal.LibraryItemPath + "/", s.libraryItemID},
{internal.LibraryItemUpdateSession, s.libraryItemUpdateSession},
{internal.LibraryItemUpdateSession + "/", s.libraryItemUpdateSessionID},
{internal.LibraryItemUpdateSessionFile, s.libraryItemUpdateSessionFile},
{internal.LibraryItemUpdateSessionFile + "/", s.libraryItemUpdateSessionFileID},
{internal.LibraryItemAdd + "/", s.libraryItemAdd},
{internal.LibraryItemFilePath, s.libraryItemFile},
{internal.LibraryItemFilePath + "/", s.libraryItemFileID},
{internal.VCenterOVFLibraryItem + "/", s.libraryItemDeployID},
}
for i := range handlers {
h := handlers[i]
s.HandleFunc(internal.Path+h.p, func(w http.ResponseWriter, r *http.Request) {
s.Lock()
defer s.Unlock()
if !s.isAuthorized(r) {
w.WriteHeader(http.StatusUnauthorized)
return
}
h.m(w, r)
})
}
return internal.Path + "/", s
}
|
go
|
func New(u *url.URL, settings []vim.BaseOptionValue) (string, http.Handler) {
s := &handler{
ServeMux: http.NewServeMux(),
URL: *u,
Category: make(map[string]*tags.Category),
Tag: make(map[string]*tags.Tag),
Association: make(map[string]map[internal.AssociatedObject]bool),
Session: make(map[string]*session),
Library: make(map[string]content),
Update: make(map[string]update),
}
handlers := []struct {
p string
m http.HandlerFunc
}{
{internal.SessionPath, s.session},
{internal.CategoryPath, s.category},
{internal.CategoryPath + "/", s.categoryID},
{internal.TagPath, s.tag},
{internal.TagPath + "/", s.tagID},
{internal.AssociationPath, s.association},
{internal.AssociationPath + "/", s.associationID},
{internal.LibraryPath, s.library},
{internal.LocalLibraryPath, s.library},
{internal.LibraryPath + "/", s.libraryID},
{internal.LocalLibraryPath + "/", s.libraryID},
{internal.LibraryItemPath, s.libraryItem},
{internal.LibraryItemPath + "/", s.libraryItemID},
{internal.LibraryItemUpdateSession, s.libraryItemUpdateSession},
{internal.LibraryItemUpdateSession + "/", s.libraryItemUpdateSessionID},
{internal.LibraryItemUpdateSessionFile, s.libraryItemUpdateSessionFile},
{internal.LibraryItemUpdateSessionFile + "/", s.libraryItemUpdateSessionFileID},
{internal.LibraryItemAdd + "/", s.libraryItemAdd},
{internal.LibraryItemFilePath, s.libraryItemFile},
{internal.LibraryItemFilePath + "/", s.libraryItemFileID},
{internal.VCenterOVFLibraryItem + "/", s.libraryItemDeployID},
}
for i := range handlers {
h := handlers[i]
s.HandleFunc(internal.Path+h.p, func(w http.ResponseWriter, r *http.Request) {
s.Lock()
defer s.Unlock()
if !s.isAuthorized(r) {
w.WriteHeader(http.StatusUnauthorized)
return
}
h.m(w, r)
})
}
return internal.Path + "/", s
}
|
[
"func",
"New",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"settings",
"[",
"]",
"vim",
".",
"BaseOptionValue",
")",
"(",
"string",
",",
"http",
".",
"Handler",
")",
"{",
"s",
":=",
"&",
"handler",
"{",
"ServeMux",
":",
"http",
".",
"NewServeMux",
"(",
")",
",",
"URL",
":",
"*",
"u",
",",
"Category",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"tags",
".",
"Category",
")",
",",
"Tag",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"tags",
".",
"Tag",
")",
",",
"Association",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"map",
"[",
"internal",
".",
"AssociatedObject",
"]",
"bool",
")",
",",
"Session",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"session",
")",
",",
"Library",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"content",
")",
",",
"Update",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"update",
")",
",",
"}",
"\n\n",
"handlers",
":=",
"[",
"]",
"struct",
"{",
"p",
"string",
"\n",
"m",
"http",
".",
"HandlerFunc",
"\n",
"}",
"{",
"{",
"internal",
".",
"SessionPath",
",",
"s",
".",
"session",
"}",
",",
"{",
"internal",
".",
"CategoryPath",
",",
"s",
".",
"category",
"}",
",",
"{",
"internal",
".",
"CategoryPath",
"+",
"\"",
"\"",
",",
"s",
".",
"categoryID",
"}",
",",
"{",
"internal",
".",
"TagPath",
",",
"s",
".",
"tag",
"}",
",",
"{",
"internal",
".",
"TagPath",
"+",
"\"",
"\"",
",",
"s",
".",
"tagID",
"}",
",",
"{",
"internal",
".",
"AssociationPath",
",",
"s",
".",
"association",
"}",
",",
"{",
"internal",
".",
"AssociationPath",
"+",
"\"",
"\"",
",",
"s",
".",
"associationID",
"}",
",",
"{",
"internal",
".",
"LibraryPath",
",",
"s",
".",
"library",
"}",
",",
"{",
"internal",
".",
"LocalLibraryPath",
",",
"s",
".",
"library",
"}",
",",
"{",
"internal",
".",
"LibraryPath",
"+",
"\"",
"\"",
",",
"s",
".",
"libraryID",
"}",
",",
"{",
"internal",
".",
"LocalLibraryPath",
"+",
"\"",
"\"",
",",
"s",
".",
"libraryID",
"}",
",",
"{",
"internal",
".",
"LibraryItemPath",
",",
"s",
".",
"libraryItem",
"}",
",",
"{",
"internal",
".",
"LibraryItemPath",
"+",
"\"",
"\"",
",",
"s",
".",
"libraryItemID",
"}",
",",
"{",
"internal",
".",
"LibraryItemUpdateSession",
",",
"s",
".",
"libraryItemUpdateSession",
"}",
",",
"{",
"internal",
".",
"LibraryItemUpdateSession",
"+",
"\"",
"\"",
",",
"s",
".",
"libraryItemUpdateSessionID",
"}",
",",
"{",
"internal",
".",
"LibraryItemUpdateSessionFile",
",",
"s",
".",
"libraryItemUpdateSessionFile",
"}",
",",
"{",
"internal",
".",
"LibraryItemUpdateSessionFile",
"+",
"\"",
"\"",
",",
"s",
".",
"libraryItemUpdateSessionFileID",
"}",
",",
"{",
"internal",
".",
"LibraryItemAdd",
"+",
"\"",
"\"",
",",
"s",
".",
"libraryItemAdd",
"}",
",",
"{",
"internal",
".",
"LibraryItemFilePath",
",",
"s",
".",
"libraryItemFile",
"}",
",",
"{",
"internal",
".",
"LibraryItemFilePath",
"+",
"\"",
"\"",
",",
"s",
".",
"libraryItemFileID",
"}",
",",
"{",
"internal",
".",
"VCenterOVFLibraryItem",
"+",
"\"",
"\"",
",",
"s",
".",
"libraryItemDeployID",
"}",
",",
"}",
"\n\n",
"for",
"i",
":=",
"range",
"handlers",
"{",
"h",
":=",
"handlers",
"[",
"i",
"]",
"\n",
"s",
".",
"HandleFunc",
"(",
"internal",
".",
"Path",
"+",
"h",
".",
"p",
",",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"!",
"s",
".",
"isAuthorized",
"(",
"r",
")",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusUnauthorized",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"h",
".",
"m",
"(",
"w",
",",
"r",
")",
"\n",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"internal",
".",
"Path",
"+",
"\"",
"\"",
",",
"s",
"\n",
"}"
] |
// New creates a vAPI simulator.
|
[
"New",
"creates",
"a",
"vAPI",
"simulator",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/simulator/simulator.go#L85-L140
|
21,507
|
vmware/govmomi
|
vapi/simulator/simulator.go
|
AttachedObjects
|
func (s *handler) AttachedObjects(tag vim.VslmTagEntry) ([]vim.ManagedObjectReference, vim.BaseMethodFault) {
t := s.findTag(tag)
if t == nil {
return nil, new(vim.NotFound)
}
var ids []vim.ManagedObjectReference
for id := range s.Association[t.ID] {
ids = append(ids, vim.ManagedObjectReference(id))
}
return ids, nil
}
|
go
|
func (s *handler) AttachedObjects(tag vim.VslmTagEntry) ([]vim.ManagedObjectReference, vim.BaseMethodFault) {
t := s.findTag(tag)
if t == nil {
return nil, new(vim.NotFound)
}
var ids []vim.ManagedObjectReference
for id := range s.Association[t.ID] {
ids = append(ids, vim.ManagedObjectReference(id))
}
return ids, nil
}
|
[
"func",
"(",
"s",
"*",
"handler",
")",
"AttachedObjects",
"(",
"tag",
"vim",
".",
"VslmTagEntry",
")",
"(",
"[",
"]",
"vim",
".",
"ManagedObjectReference",
",",
"vim",
".",
"BaseMethodFault",
")",
"{",
"t",
":=",
"s",
".",
"findTag",
"(",
"tag",
")",
"\n",
"if",
"t",
"==",
"nil",
"{",
"return",
"nil",
",",
"new",
"(",
"vim",
".",
"NotFound",
")",
"\n",
"}",
"\n",
"var",
"ids",
"[",
"]",
"vim",
".",
"ManagedObjectReference",
"\n",
"for",
"id",
":=",
"range",
"s",
".",
"Association",
"[",
"t",
".",
"ID",
"]",
"{",
"ids",
"=",
"append",
"(",
"ids",
",",
"vim",
".",
"ManagedObjectReference",
"(",
"id",
")",
")",
"\n",
"}",
"\n",
"return",
"ids",
",",
"nil",
"\n",
"}"
] |
// AttachedObjects is meant for internal use via simulator.Registry.tagManager
|
[
"AttachedObjects",
"is",
"meant",
"for",
"internal",
"use",
"via",
"simulator",
".",
"Registry",
".",
"tagManager"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/simulator/simulator.go#L188-L198
|
21,508
|
vmware/govmomi
|
vapi/simulator/simulator.go
|
AttachedTags
|
func (s *handler) AttachedTags(ref vim.ManagedObjectReference) ([]vim.VslmTagEntry, vim.BaseMethodFault) {
oid := internal.AssociatedObject(ref)
var tags []vim.VslmTagEntry
for id, objs := range s.Association {
if objs[oid] {
tag := s.Tag[id]
cat := s.Category[tag.CategoryID]
tags = append(tags, vim.VslmTagEntry{
TagName: tag.Name,
ParentCategoryName: cat.Name,
})
}
}
return tags, nil
}
|
go
|
func (s *handler) AttachedTags(ref vim.ManagedObjectReference) ([]vim.VslmTagEntry, vim.BaseMethodFault) {
oid := internal.AssociatedObject(ref)
var tags []vim.VslmTagEntry
for id, objs := range s.Association {
if objs[oid] {
tag := s.Tag[id]
cat := s.Category[tag.CategoryID]
tags = append(tags, vim.VslmTagEntry{
TagName: tag.Name,
ParentCategoryName: cat.Name,
})
}
}
return tags, nil
}
|
[
"func",
"(",
"s",
"*",
"handler",
")",
"AttachedTags",
"(",
"ref",
"vim",
".",
"ManagedObjectReference",
")",
"(",
"[",
"]",
"vim",
".",
"VslmTagEntry",
",",
"vim",
".",
"BaseMethodFault",
")",
"{",
"oid",
":=",
"internal",
".",
"AssociatedObject",
"(",
"ref",
")",
"\n",
"var",
"tags",
"[",
"]",
"vim",
".",
"VslmTagEntry",
"\n",
"for",
"id",
",",
"objs",
":=",
"range",
"s",
".",
"Association",
"{",
"if",
"objs",
"[",
"oid",
"]",
"{",
"tag",
":=",
"s",
".",
"Tag",
"[",
"id",
"]",
"\n",
"cat",
":=",
"s",
".",
"Category",
"[",
"tag",
".",
"CategoryID",
"]",
"\n",
"tags",
"=",
"append",
"(",
"tags",
",",
"vim",
".",
"VslmTagEntry",
"{",
"TagName",
":",
"tag",
".",
"Name",
",",
"ParentCategoryName",
":",
"cat",
".",
"Name",
",",
"}",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"tags",
",",
"nil",
"\n",
"}"
] |
// AttachedTags is meant for internal use via simulator.Registry.tagManager
|
[
"AttachedTags",
"is",
"meant",
"for",
"internal",
"use",
"via",
"simulator",
".",
"Registry",
".",
"tagManager"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/simulator/simulator.go#L201-L215
|
21,509
|
vmware/govmomi
|
vapi/simulator/simulator.go
|
AttachTag
|
func (s *handler) AttachTag(ref vim.ManagedObjectReference, tag vim.VslmTagEntry) vim.BaseMethodFault {
t := s.findTag(tag)
if t == nil {
return new(vim.NotFound)
}
s.Association[t.ID][internal.AssociatedObject(ref)] = true
return nil
}
|
go
|
func (s *handler) AttachTag(ref vim.ManagedObjectReference, tag vim.VslmTagEntry) vim.BaseMethodFault {
t := s.findTag(tag)
if t == nil {
return new(vim.NotFound)
}
s.Association[t.ID][internal.AssociatedObject(ref)] = true
return nil
}
|
[
"func",
"(",
"s",
"*",
"handler",
")",
"AttachTag",
"(",
"ref",
"vim",
".",
"ManagedObjectReference",
",",
"tag",
"vim",
".",
"VslmTagEntry",
")",
"vim",
".",
"BaseMethodFault",
"{",
"t",
":=",
"s",
".",
"findTag",
"(",
"tag",
")",
"\n",
"if",
"t",
"==",
"nil",
"{",
"return",
"new",
"(",
"vim",
".",
"NotFound",
")",
"\n",
"}",
"\n",
"s",
".",
"Association",
"[",
"t",
".",
"ID",
"]",
"[",
"internal",
".",
"AssociatedObject",
"(",
"ref",
")",
"]",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AttachTag is meant for internal use via simulator.Registry.tagManager
|
[
"AttachTag",
"is",
"meant",
"for",
"internal",
"use",
"via",
"simulator",
".",
"Registry",
".",
"tagManager"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/simulator/simulator.go#L218-L225
|
21,510
|
vmware/govmomi
|
vapi/simulator/simulator.go
|
DetachTag
|
func (s *handler) DetachTag(id vim.ManagedObjectReference, tag vim.VslmTagEntry) vim.BaseMethodFault {
t := s.findTag(tag)
if t == nil {
return new(vim.NotFound)
}
delete(s.Association[t.ID], internal.AssociatedObject(id))
return nil
}
|
go
|
func (s *handler) DetachTag(id vim.ManagedObjectReference, tag vim.VslmTagEntry) vim.BaseMethodFault {
t := s.findTag(tag)
if t == nil {
return new(vim.NotFound)
}
delete(s.Association[t.ID], internal.AssociatedObject(id))
return nil
}
|
[
"func",
"(",
"s",
"*",
"handler",
")",
"DetachTag",
"(",
"id",
"vim",
".",
"ManagedObjectReference",
",",
"tag",
"vim",
".",
"VslmTagEntry",
")",
"vim",
".",
"BaseMethodFault",
"{",
"t",
":=",
"s",
".",
"findTag",
"(",
"tag",
")",
"\n",
"if",
"t",
"==",
"nil",
"{",
"return",
"new",
"(",
"vim",
".",
"NotFound",
")",
"\n",
"}",
"\n",
"delete",
"(",
"s",
".",
"Association",
"[",
"t",
".",
"ID",
"]",
",",
"internal",
".",
"AssociatedObject",
"(",
"id",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// DetachTag is meant for internal use via simulator.Registry.tagManager
|
[
"DetachTag",
"is",
"meant",
"for",
"internal",
"use",
"via",
"simulator",
".",
"Registry",
".",
"tagManager"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/simulator/simulator.go#L228-L235
|
21,511
|
vmware/govmomi
|
vapi/simulator/simulator.go
|
ok
|
func (s *handler) ok(w http.ResponseWriter, val ...interface{}) {
w.WriteHeader(http.StatusOK)
if len(val) == 0 {
return
}
err := json.NewEncoder(w).Encode(struct {
Value interface{} `json:"value,omitempty"`
}{
val[0],
})
if err != nil {
log.Panic(err)
}
}
|
go
|
func (s *handler) ok(w http.ResponseWriter, val ...interface{}) {
w.WriteHeader(http.StatusOK)
if len(val) == 0 {
return
}
err := json.NewEncoder(w).Encode(struct {
Value interface{} `json:"value,omitempty"`
}{
val[0],
})
if err != nil {
log.Panic(err)
}
}
|
[
"func",
"(",
"s",
"*",
"handler",
")",
"ok",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"val",
"...",
"interface",
"{",
"}",
")",
"{",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n\n",
"if",
"len",
"(",
"val",
")",
"==",
"0",
"{",
"return",
"\n",
"}",
"\n\n",
"err",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
".",
"Encode",
"(",
"struct",
"{",
"Value",
"interface",
"{",
"}",
"`json:\"value,omitempty\"`",
"\n",
"}",
"{",
"val",
"[",
"0",
"]",
",",
"}",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// ok responds with http.StatusOK and json encodes val if given.
|
[
"ok",
"responds",
"with",
"http",
".",
"StatusOK",
"and",
"json",
"encodes",
"val",
"if",
"given",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/simulator/simulator.go#L238-L254
|
21,512
|
vmware/govmomi
|
vapi/simulator/simulator.go
|
ServeHTTP
|
func (s *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPost, http.MethodDelete, http.MethodGet, http.MethodPatch, http.MethodPut:
default:
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
h, _ := s.Handler(r)
h.ServeHTTP(w, r)
}
|
go
|
func (s *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPost, http.MethodDelete, http.MethodGet, http.MethodPatch, http.MethodPut:
default:
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
h, _ := s.Handler(r)
h.ServeHTTP(w, r)
}
|
[
"func",
"(",
"s",
"*",
"handler",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"switch",
"r",
".",
"Method",
"{",
"case",
"http",
".",
"MethodPost",
",",
"http",
".",
"MethodDelete",
",",
"http",
".",
"MethodGet",
",",
"http",
".",
"MethodPatch",
",",
"http",
".",
"MethodPut",
":",
"default",
":",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusMethodNotAllowed",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"h",
",",
"_",
":=",
"s",
".",
"Handler",
"(",
"r",
")",
"\n",
"h",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n",
"}"
] |
// ServeHTTP handles vAPI requests.
|
[
"ServeHTTP",
"handles",
"vAPI",
"requests",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/simulator/simulator.go#L279-L289
|
21,513
|
vmware/govmomi
|
vapi/simulator/simulator.go
|
libraryPath
|
func libraryPath(l *library.Library, id string) string {
// DatastoreID (moref) format is "$local-path@$ds-folder-id",
// see simulator.HostDatastoreSystem.CreateLocalDatastore
ds := strings.SplitN(l.Storage[0].DatastoreID, "@", 2)[0]
return path.Join(append([]string{ds, "contentlib-" + l.ID}, id)...)
}
|
go
|
func libraryPath(l *library.Library, id string) string {
// DatastoreID (moref) format is "$local-path@$ds-folder-id",
// see simulator.HostDatastoreSystem.CreateLocalDatastore
ds := strings.SplitN(l.Storage[0].DatastoreID, "@", 2)[0]
return path.Join(append([]string{ds, "contentlib-" + l.ID}, id)...)
}
|
[
"func",
"libraryPath",
"(",
"l",
"*",
"library",
".",
"Library",
",",
"id",
"string",
")",
"string",
"{",
"// DatastoreID (moref) format is \"$local-path@$ds-folder-id\",",
"// see simulator.HostDatastoreSystem.CreateLocalDatastore",
"ds",
":=",
"strings",
".",
"SplitN",
"(",
"l",
".",
"Storage",
"[",
"0",
"]",
".",
"DatastoreID",
",",
"\"",
"\"",
",",
"2",
")",
"[",
"0",
"]",
"\n",
"return",
"path",
".",
"Join",
"(",
"append",
"(",
"[",
"]",
"string",
"{",
"ds",
",",
"\"",
"\"",
"+",
"l",
".",
"ID",
"}",
",",
"id",
")",
"...",
")",
"\n",
"}"
] |
// libraryPath returns the local Datastore fs path for a Library or Item if id is specified.
|
[
"libraryPath",
"returns",
"the",
"local",
"Datastore",
"fs",
"path",
"for",
"a",
"Library",
"or",
"Item",
"if",
"id",
"is",
"specified",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/simulator/simulator.go#L898-L903
|
21,514
|
vmware/govmomi
|
govc/library/ova.go
|
NewOVAFile
|
func NewOVAFile(filename string) (*OVAFile, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
tarFile := tar.NewReader(f)
return &OVAFile{filename: filename, file: f, tarFile: tarFile}, nil
}
|
go
|
func NewOVAFile(filename string) (*OVAFile, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
tarFile := tar.NewReader(f)
return &OVAFile{filename: filename, file: f, tarFile: tarFile}, nil
}
|
[
"func",
"NewOVAFile",
"(",
"filename",
"string",
")",
"(",
"*",
"OVAFile",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tarFile",
":=",
"tar",
".",
"NewReader",
"(",
"f",
")",
"\n",
"return",
"&",
"OVAFile",
"{",
"filename",
":",
"filename",
",",
"file",
":",
"f",
",",
"tarFile",
":",
"tarFile",
"}",
",",
"nil",
"\n",
"}"
] |
// NewOVAFile creates a new OVA file reader
|
[
"NewOVAFile",
"creates",
"a",
"new",
"OVA",
"file",
"reader"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/library/ova.go#L87-L94
|
21,515
|
vmware/govmomi
|
govc/library/ova.go
|
Find
|
func (of *OVAFile) Find(filename string) (*tar.Header, error) {
for {
header, err := of.tarFile.Next()
if err == io.EOF {
return nil, err
}
if header.Name == filename {
return header, nil
}
}
}
|
go
|
func (of *OVAFile) Find(filename string) (*tar.Header, error) {
for {
header, err := of.tarFile.Next()
if err == io.EOF {
return nil, err
}
if header.Name == filename {
return header, nil
}
}
}
|
[
"func",
"(",
"of",
"*",
"OVAFile",
")",
"Find",
"(",
"filename",
"string",
")",
"(",
"*",
"tar",
".",
"Header",
",",
"error",
")",
"{",
"for",
"{",
"header",
",",
"err",
":=",
"of",
".",
"tarFile",
".",
"Next",
"(",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"header",
".",
"Name",
"==",
"filename",
"{",
"return",
"header",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Find looks for a filename match in the OVA file
|
[
"Find",
"looks",
"for",
"a",
"filename",
"match",
"in",
"the",
"OVA",
"file"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/library/ova.go#L97-L107
|
21,516
|
vmware/govmomi
|
govc/library/ova.go
|
Read
|
func (of *OVAFile) Read(b []byte) (int, error) {
if of.tarFile == nil {
return 0, io.EOF
}
return of.tarFile.Read(b)
}
|
go
|
func (of *OVAFile) Read(b []byte) (int, error) {
if of.tarFile == nil {
return 0, io.EOF
}
return of.tarFile.Read(b)
}
|
[
"func",
"(",
"of",
"*",
"OVAFile",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"of",
".",
"tarFile",
"==",
"nil",
"{",
"return",
"0",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"return",
"of",
".",
"tarFile",
".",
"Read",
"(",
"b",
")",
"\n",
"}"
] |
// Read reads from the current file in the OVA file
|
[
"Read",
"reads",
"from",
"the",
"current",
"file",
"in",
"the",
"OVA",
"file"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/library/ova.go#L115-L120
|
21,517
|
vmware/govmomi
|
govc/library/ova.go
|
getOVAFileInfo
|
func getOVAFileInfo(ovafile string, filename string) (int64, string, error) {
of, err := NewOVAFile(ovafile)
if err != nil {
return 0, "", err
}
hdr, err := of.Find(filename)
if err != nil {
return 0, "", err
}
hash := md5.New()
_, err = io.Copy(hash, of)
if err != nil {
return 0, "", err
}
md5String := hex.EncodeToString(hash.Sum(nil)[:16])
return hdr.Size, md5String, nil
}
|
go
|
func getOVAFileInfo(ovafile string, filename string) (int64, string, error) {
of, err := NewOVAFile(ovafile)
if err != nil {
return 0, "", err
}
hdr, err := of.Find(filename)
if err != nil {
return 0, "", err
}
hash := md5.New()
_, err = io.Copy(hash, of)
if err != nil {
return 0, "", err
}
md5String := hex.EncodeToString(hash.Sum(nil)[:16])
return hdr.Size, md5String, nil
}
|
[
"func",
"getOVAFileInfo",
"(",
"ovafile",
"string",
",",
"filename",
"string",
")",
"(",
"int64",
",",
"string",
",",
"error",
")",
"{",
"of",
",",
"err",
":=",
"NewOVAFile",
"(",
"ovafile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"hdr",
",",
"err",
":=",
"of",
".",
"Find",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"hash",
":=",
"md5",
".",
"New",
"(",
")",
"\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"hash",
",",
"of",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"md5String",
":=",
"hex",
".",
"EncodeToString",
"(",
"hash",
".",
"Sum",
"(",
"nil",
")",
"[",
":",
"16",
"]",
")",
"\n\n",
"return",
"hdr",
".",
"Size",
",",
"md5String",
",",
"nil",
"\n",
"}"
] |
// getOVAFileInfo opens an OVA, finds the file entry, and returns both the size and md5 checksum
|
[
"getOVAFileInfo",
"opens",
"an",
"OVA",
"finds",
"the",
"file",
"entry",
"and",
"returns",
"both",
"the",
"size",
"and",
"md5",
"checksum"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/library/ova.go#L128-L147
|
21,518
|
vmware/govmomi
|
govc/library/ova.go
|
uploadFile
|
func uploadFile(ctx context.Context, m *library.Manager, sessionID string, ovafile string, filename string) error {
var updateFileInfo library.UpdateFile
fmt.Printf("Uploading %s from %s\n", filename, ovafile)
size, md5String, _ := getOVAFileInfo(ovafile, filename)
// Get the URI for the file upload
updateFileInfo.Name = filename
updateFileInfo.Size = &size
updateFileInfo.SourceType = "PUSH"
updateFileInfo.Checksum = &library.Checksum{
Algorithm: "MD5",
Checksum: md5String,
}
addFileInfo, err := m.AddLibraryItemFile(ctx, sessionID, updateFileInfo)
if err != nil {
return err
}
of, err := NewOVAFile(ovafile)
if err != nil {
return err
}
defer of.Close()
// Setup to point to the OVA file to be transferred
_, err = of.Find(filename)
if err != nil {
return err
}
req, err := http.NewRequest("PUT", addFileInfo.UploadEndpoint.URI, of)
if err != nil {
return err
}
req.Header.Set("vmware-api-session-id", sessionID)
return m.Do(ctx, req, nil)
}
|
go
|
func uploadFile(ctx context.Context, m *library.Manager, sessionID string, ovafile string, filename string) error {
var updateFileInfo library.UpdateFile
fmt.Printf("Uploading %s from %s\n", filename, ovafile)
size, md5String, _ := getOVAFileInfo(ovafile, filename)
// Get the URI for the file upload
updateFileInfo.Name = filename
updateFileInfo.Size = &size
updateFileInfo.SourceType = "PUSH"
updateFileInfo.Checksum = &library.Checksum{
Algorithm: "MD5",
Checksum: md5String,
}
addFileInfo, err := m.AddLibraryItemFile(ctx, sessionID, updateFileInfo)
if err != nil {
return err
}
of, err := NewOVAFile(ovafile)
if err != nil {
return err
}
defer of.Close()
// Setup to point to the OVA file to be transferred
_, err = of.Find(filename)
if err != nil {
return err
}
req, err := http.NewRequest("PUT", addFileInfo.UploadEndpoint.URI, of)
if err != nil {
return err
}
req.Header.Set("vmware-api-session-id", sessionID)
return m.Do(ctx, req, nil)
}
|
[
"func",
"uploadFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"m",
"*",
"library",
".",
"Manager",
",",
"sessionID",
"string",
",",
"ovafile",
"string",
",",
"filename",
"string",
")",
"error",
"{",
"var",
"updateFileInfo",
"library",
".",
"UpdateFile",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"filename",
",",
"ovafile",
")",
"\n",
"size",
",",
"md5String",
",",
"_",
":=",
"getOVAFileInfo",
"(",
"ovafile",
",",
"filename",
")",
"\n\n",
"// Get the URI for the file upload",
"updateFileInfo",
".",
"Name",
"=",
"filename",
"\n",
"updateFileInfo",
".",
"Size",
"=",
"&",
"size",
"\n",
"updateFileInfo",
".",
"SourceType",
"=",
"\"",
"\"",
"\n",
"updateFileInfo",
".",
"Checksum",
"=",
"&",
"library",
".",
"Checksum",
"{",
"Algorithm",
":",
"\"",
"\"",
",",
"Checksum",
":",
"md5String",
",",
"}",
"\n\n",
"addFileInfo",
",",
"err",
":=",
"m",
".",
"AddLibraryItemFile",
"(",
"ctx",
",",
"sessionID",
",",
"updateFileInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"of",
",",
"err",
":=",
"NewOVAFile",
"(",
"ovafile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"of",
".",
"Close",
"(",
")",
"\n\n",
"// Setup to point to the OVA file to be transferred",
"_",
",",
"err",
"=",
"of",
".",
"Find",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"addFileInfo",
".",
"UploadEndpoint",
".",
"URI",
",",
"of",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"sessionID",
")",
"\n\n",
"return",
"m",
".",
"Do",
"(",
"ctx",
",",
"req",
",",
"nil",
")",
"\n",
"}"
] |
// uploadFile will upload a single file from an OVA using the sessionID provided
|
[
"uploadFile",
"will",
"upload",
"a",
"single",
"file",
"from",
"an",
"OVA",
"using",
"the",
"sessionID",
"provided"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/library/ova.go#L150-L190
|
21,519
|
vmware/govmomi
|
simulator/folder.go
|
hostsWithDatastore
|
func hostsWithDatastore(hosts []types.ManagedObjectReference, path string) []types.ManagedObjectReference {
attached := hosts[:0]
var p object.DatastorePath
p.FromString(path)
for _, host := range hosts {
h := Map.Get(host).(*HostSystem)
if Map.FindByName(p.Datastore, h.Datastore) != nil {
attached = append(attached, host)
}
}
return attached
}
|
go
|
func hostsWithDatastore(hosts []types.ManagedObjectReference, path string) []types.ManagedObjectReference {
attached := hosts[:0]
var p object.DatastorePath
p.FromString(path)
for _, host := range hosts {
h := Map.Get(host).(*HostSystem)
if Map.FindByName(p.Datastore, h.Datastore) != nil {
attached = append(attached, host)
}
}
return attached
}
|
[
"func",
"hostsWithDatastore",
"(",
"hosts",
"[",
"]",
"types",
".",
"ManagedObjectReference",
",",
"path",
"string",
")",
"[",
"]",
"types",
".",
"ManagedObjectReference",
"{",
"attached",
":=",
"hosts",
"[",
":",
"0",
"]",
"\n",
"var",
"p",
"object",
".",
"DatastorePath",
"\n",
"p",
".",
"FromString",
"(",
"path",
")",
"\n\n",
"for",
"_",
",",
"host",
":=",
"range",
"hosts",
"{",
"h",
":=",
"Map",
".",
"Get",
"(",
"host",
")",
".",
"(",
"*",
"HostSystem",
")",
"\n",
"if",
"Map",
".",
"FindByName",
"(",
"p",
".",
"Datastore",
",",
"h",
".",
"Datastore",
")",
"!=",
"nil",
"{",
"attached",
"=",
"append",
"(",
"attached",
",",
"host",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"attached",
"\n",
"}"
] |
// hostsWithDatastore returns hosts that have access to the given datastore path
|
[
"hostsWithDatastore",
"returns",
"hosts",
"that",
"have",
"access",
"to",
"the",
"given",
"datastore",
"path"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/folder.go#L260-L273
|
21,520
|
vmware/govmomi
|
ovf/env.go
|
Marshal
|
func (e Env) Marshal() (string, error) {
x, err := xml.Marshal(e)
if err != nil {
return "", err
}
return fmt.Sprintf("%s%s", xml.Header, x), nil
}
|
go
|
func (e Env) Marshal() (string, error) {
x, err := xml.Marshal(e)
if err != nil {
return "", err
}
return fmt.Sprintf("%s%s", xml.Header, x), nil
}
|
[
"func",
"(",
"e",
"Env",
")",
"Marshal",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"x",
",",
"err",
":=",
"xml",
".",
"Marshal",
"(",
"e",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"xml",
".",
"Header",
",",
"x",
")",
",",
"nil",
"\n",
"}"
] |
// Marshal marshals Env to xml by using xml.Marshal.
|
[
"Marshal",
"marshals",
"Env",
"to",
"xml",
"by",
"using",
"xml",
".",
"Marshal",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/ovf/env.go#L72-L79
|
21,521
|
vmware/govmomi
|
ovf/env.go
|
MarshalManual
|
func (e Env) MarshalManual() string {
var buffer bytes.Buffer
buffer.WriteString(xml.Header)
buffer.WriteString(fmt.Sprintf(ovfEnvHeader, e.EsxID))
buffer.WriteString(fmt.Sprintf(ovfEnvPlatformSection, e.Platform.Kind, e.Platform.Version, e.Platform.Vendor, e.Platform.Locale))
buffer.WriteString(fmt.Sprint(ovfEnvPropertyHeader))
for _, p := range e.Property.Properties {
buffer.WriteString(fmt.Sprintf(ovfEnvPropertyEntry, p.Key, p.Value))
}
buffer.WriteString(fmt.Sprint(ovfEnvPropertyFooter))
buffer.WriteString(fmt.Sprint(ovfEnvFooter))
return buffer.String()
}
|
go
|
func (e Env) MarshalManual() string {
var buffer bytes.Buffer
buffer.WriteString(xml.Header)
buffer.WriteString(fmt.Sprintf(ovfEnvHeader, e.EsxID))
buffer.WriteString(fmt.Sprintf(ovfEnvPlatformSection, e.Platform.Kind, e.Platform.Version, e.Platform.Vendor, e.Platform.Locale))
buffer.WriteString(fmt.Sprint(ovfEnvPropertyHeader))
for _, p := range e.Property.Properties {
buffer.WriteString(fmt.Sprintf(ovfEnvPropertyEntry, p.Key, p.Value))
}
buffer.WriteString(fmt.Sprint(ovfEnvPropertyFooter))
buffer.WriteString(fmt.Sprint(ovfEnvFooter))
return buffer.String()
}
|
[
"func",
"(",
"e",
"Env",
")",
"MarshalManual",
"(",
")",
"string",
"{",
"var",
"buffer",
"bytes",
".",
"Buffer",
"\n\n",
"buffer",
".",
"WriteString",
"(",
"xml",
".",
"Header",
")",
"\n",
"buffer",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"ovfEnvHeader",
",",
"e",
".",
"EsxID",
")",
")",
"\n",
"buffer",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"ovfEnvPlatformSection",
",",
"e",
".",
"Platform",
".",
"Kind",
",",
"e",
".",
"Platform",
".",
"Version",
",",
"e",
".",
"Platform",
".",
"Vendor",
",",
"e",
".",
"Platform",
".",
"Locale",
")",
")",
"\n\n",
"buffer",
".",
"WriteString",
"(",
"fmt",
".",
"Sprint",
"(",
"ovfEnvPropertyHeader",
")",
")",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"e",
".",
"Property",
".",
"Properties",
"{",
"buffer",
".",
"WriteString",
"(",
"fmt",
".",
"Sprintf",
"(",
"ovfEnvPropertyEntry",
",",
"p",
".",
"Key",
",",
"p",
".",
"Value",
")",
")",
"\n",
"}",
"\n",
"buffer",
".",
"WriteString",
"(",
"fmt",
".",
"Sprint",
"(",
"ovfEnvPropertyFooter",
")",
")",
"\n\n",
"buffer",
".",
"WriteString",
"(",
"fmt",
".",
"Sprint",
"(",
"ovfEnvFooter",
")",
")",
"\n\n",
"return",
"buffer",
".",
"String",
"(",
")",
"\n",
"}"
] |
// MarshalManual manually marshals Env to xml suitable for a vApp guest.
// It exists to overcome the lack of expressiveness in Go's XML namespaces.
|
[
"MarshalManual",
"manually",
"marshals",
"Env",
"to",
"xml",
"suitable",
"for",
"a",
"vApp",
"guest",
".",
"It",
"exists",
"to",
"overcome",
"the",
"lack",
"of",
"expressiveness",
"in",
"Go",
"s",
"XML",
"namespaces",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/ovf/env.go#L83-L99
|
21,522
|
vmware/govmomi
|
vim25/xml/read.go
|
DecodeElement
|
func (d *Decoder) DecodeElement(v interface{}, start *StartElement) error {
val := reflect.ValueOf(v)
if val.Kind() != reflect.Ptr {
return errors.New("non-pointer passed to Unmarshal")
}
return d.unmarshal(val.Elem(), start)
}
|
go
|
func (d *Decoder) DecodeElement(v interface{}, start *StartElement) error {
val := reflect.ValueOf(v)
if val.Kind() != reflect.Ptr {
return errors.New("non-pointer passed to Unmarshal")
}
return d.unmarshal(val.Elem(), start)
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"DecodeElement",
"(",
"v",
"interface",
"{",
"}",
",",
"start",
"*",
"StartElement",
")",
"error",
"{",
"val",
":=",
"reflect",
".",
"ValueOf",
"(",
"v",
")",
"\n",
"if",
"val",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Ptr",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"d",
".",
"unmarshal",
"(",
"val",
".",
"Elem",
"(",
")",
",",
"start",
")",
"\n",
"}"
] |
// DecodeElement works like xml.Unmarshal except that it takes
// a pointer to the start XML element to decode into v.
// It is useful when a client reads some raw XML tokens itself
// but also wants to defer to Unmarshal for some elements.
|
[
"DecodeElement",
"works",
"like",
"xml",
".",
"Unmarshal",
"except",
"that",
"it",
"takes",
"a",
"pointer",
"to",
"the",
"start",
"XML",
"element",
"to",
"decode",
"into",
"v",
".",
"It",
"is",
"useful",
"when",
"a",
"client",
"reads",
"some",
"raw",
"XML",
"tokens",
"itself",
"but",
"also",
"wants",
"to",
"defer",
"to",
"Unmarshal",
"for",
"some",
"elements",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/read.go#L128-L134
|
21,523
|
vmware/govmomi
|
vim25/xml/read.go
|
receiverType
|
func receiverType(val interface{}) string {
t := reflect.TypeOf(val)
if t.Name() != "" {
return t.String()
}
return "(" + t.String() + ")"
}
|
go
|
func receiverType(val interface{}) string {
t := reflect.TypeOf(val)
if t.Name() != "" {
return t.String()
}
return "(" + t.String() + ")"
}
|
[
"func",
"receiverType",
"(",
"val",
"interface",
"{",
"}",
")",
"string",
"{",
"t",
":=",
"reflect",
".",
"TypeOf",
"(",
"val",
")",
"\n",
"if",
"t",
".",
"Name",
"(",
")",
"!=",
"\"",
"\"",
"{",
"return",
"t",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"+",
"t",
".",
"String",
"(",
")",
"+",
"\"",
"\"",
"\n",
"}"
] |
// receiverType returns the receiver type to use in an expression like "%s.MethodName".
|
[
"receiverType",
"returns",
"the",
"receiver",
"type",
"to",
"use",
"in",
"an",
"expression",
"like",
"%s",
".",
"MethodName",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/read.go#L173-L179
|
21,524
|
vmware/govmomi
|
vim25/xml/read.go
|
typeForElement
|
func (p *Decoder) typeForElement(val reflect.Value, start *StartElement) reflect.Type {
t := ""
for i, a := range start.Attr {
if a.Name == xmlSchemaInstance || a.Name == xsiType {
t = a.Value
// HACK: ensure xsi:type is last in the list to avoid using that value for
// a "type" attribute, such as ManagedObjectReference.Type for example.
// Note that xsi:type is already the last attribute in VC/ESX responses.
// This is only an issue with govmomi simulator generated responses.
// Proper fix will require finding a few needles in this xml package haystack.
// Note: govmomi uses xmlSchemaInstance, other clients (e.g. rbvmomi) use xsiType.
// They are the same thing to XML parsers, but not to this hack here.
x := len(start.Attr) - 1
if i != x {
start.Attr[i] = start.Attr[x]
start.Attr[x] = a
}
break
}
}
if t == "" {
// No type attribute; fall back to looking up type by interface name.
t = val.Type().Name()
}
// Maybe the type is a basic xsd:* type.
typ := stringToType(t)
if typ != nil {
return typ
}
// Maybe the type is a custom type.
if p.TypeFunc != nil {
if typ, ok := p.TypeFunc(t); ok {
return typ
}
}
return nil
}
|
go
|
func (p *Decoder) typeForElement(val reflect.Value, start *StartElement) reflect.Type {
t := ""
for i, a := range start.Attr {
if a.Name == xmlSchemaInstance || a.Name == xsiType {
t = a.Value
// HACK: ensure xsi:type is last in the list to avoid using that value for
// a "type" attribute, such as ManagedObjectReference.Type for example.
// Note that xsi:type is already the last attribute in VC/ESX responses.
// This is only an issue with govmomi simulator generated responses.
// Proper fix will require finding a few needles in this xml package haystack.
// Note: govmomi uses xmlSchemaInstance, other clients (e.g. rbvmomi) use xsiType.
// They are the same thing to XML parsers, but not to this hack here.
x := len(start.Attr) - 1
if i != x {
start.Attr[i] = start.Attr[x]
start.Attr[x] = a
}
break
}
}
if t == "" {
// No type attribute; fall back to looking up type by interface name.
t = val.Type().Name()
}
// Maybe the type is a basic xsd:* type.
typ := stringToType(t)
if typ != nil {
return typ
}
// Maybe the type is a custom type.
if p.TypeFunc != nil {
if typ, ok := p.TypeFunc(t); ok {
return typ
}
}
return nil
}
|
[
"func",
"(",
"p",
"*",
"Decoder",
")",
"typeForElement",
"(",
"val",
"reflect",
".",
"Value",
",",
"start",
"*",
"StartElement",
")",
"reflect",
".",
"Type",
"{",
"t",
":=",
"\"",
"\"",
"\n",
"for",
"i",
",",
"a",
":=",
"range",
"start",
".",
"Attr",
"{",
"if",
"a",
".",
"Name",
"==",
"xmlSchemaInstance",
"||",
"a",
".",
"Name",
"==",
"xsiType",
"{",
"t",
"=",
"a",
".",
"Value",
"\n",
"// HACK: ensure xsi:type is last in the list to avoid using that value for",
"// a \"type\" attribute, such as ManagedObjectReference.Type for example.",
"// Note that xsi:type is already the last attribute in VC/ESX responses.",
"// This is only an issue with govmomi simulator generated responses.",
"// Proper fix will require finding a few needles in this xml package haystack.",
"// Note: govmomi uses xmlSchemaInstance, other clients (e.g. rbvmomi) use xsiType.",
"// They are the same thing to XML parsers, but not to this hack here.",
"x",
":=",
"len",
"(",
"start",
".",
"Attr",
")",
"-",
"1",
"\n",
"if",
"i",
"!=",
"x",
"{",
"start",
".",
"Attr",
"[",
"i",
"]",
"=",
"start",
".",
"Attr",
"[",
"x",
"]",
"\n",
"start",
".",
"Attr",
"[",
"x",
"]",
"=",
"a",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"t",
"==",
"\"",
"\"",
"{",
"// No type attribute; fall back to looking up type by interface name.",
"t",
"=",
"val",
".",
"Type",
"(",
")",
".",
"Name",
"(",
")",
"\n",
"}",
"\n\n",
"// Maybe the type is a basic xsd:* type.",
"typ",
":=",
"stringToType",
"(",
"t",
")",
"\n",
"if",
"typ",
"!=",
"nil",
"{",
"return",
"typ",
"\n",
"}",
"\n\n",
"// Maybe the type is a custom type.",
"if",
"p",
".",
"TypeFunc",
"!=",
"nil",
"{",
"if",
"typ",
",",
"ok",
":=",
"p",
".",
"TypeFunc",
"(",
"t",
")",
";",
"ok",
"{",
"return",
"typ",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Find reflect.Type for an element's type attribute.
|
[
"Find",
"reflect",
".",
"Type",
"for",
"an",
"element",
"s",
"type",
"attribute",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/read.go#L272-L312
|
21,525
|
vmware/govmomi
|
vim25/xml/read.go
|
unmarshalPath
|
func (p *Decoder) unmarshalPath(tinfo *typeInfo, sv reflect.Value, parents []string, start *StartElement) (consumed bool, err error) {
recurse := false
Loop:
for i := range tinfo.fields {
finfo := &tinfo.fields[i]
if finfo.flags&fElement == 0 || len(finfo.parents) < len(parents) || finfo.xmlns != "" && finfo.xmlns != start.Name.Space {
continue
}
for j := range parents {
if parents[j] != finfo.parents[j] {
continue Loop
}
}
if len(finfo.parents) == len(parents) && finfo.name == start.Name.Local {
// It's a perfect match, unmarshal the field.
return true, p.unmarshal(finfo.value(sv), start)
}
if len(finfo.parents) > len(parents) && finfo.parents[len(parents)] == start.Name.Local {
// It's a prefix for the field. Break and recurse
// since it's not ok for one field path to be itself
// the prefix for another field path.
recurse = true
// We can reuse the same slice as long as we
// don't try to append to it.
parents = finfo.parents[:len(parents)+1]
break
}
}
if !recurse {
// We have no business with this element.
return false, nil
}
// The element is not a perfect match for any field, but one
// or more fields have the path to this element as a parent
// prefix. Recurse and attempt to match these.
for {
var tok Token
tok, err = p.Token()
if err != nil {
return true, err
}
switch t := tok.(type) {
case StartElement:
consumed2, err := p.unmarshalPath(tinfo, sv, parents, &t)
if err != nil {
return true, err
}
if !consumed2 {
if err := p.Skip(); err != nil {
return true, err
}
}
case EndElement:
return true, nil
}
}
}
|
go
|
func (p *Decoder) unmarshalPath(tinfo *typeInfo, sv reflect.Value, parents []string, start *StartElement) (consumed bool, err error) {
recurse := false
Loop:
for i := range tinfo.fields {
finfo := &tinfo.fields[i]
if finfo.flags&fElement == 0 || len(finfo.parents) < len(parents) || finfo.xmlns != "" && finfo.xmlns != start.Name.Space {
continue
}
for j := range parents {
if parents[j] != finfo.parents[j] {
continue Loop
}
}
if len(finfo.parents) == len(parents) && finfo.name == start.Name.Local {
// It's a perfect match, unmarshal the field.
return true, p.unmarshal(finfo.value(sv), start)
}
if len(finfo.parents) > len(parents) && finfo.parents[len(parents)] == start.Name.Local {
// It's a prefix for the field. Break and recurse
// since it's not ok for one field path to be itself
// the prefix for another field path.
recurse = true
// We can reuse the same slice as long as we
// don't try to append to it.
parents = finfo.parents[:len(parents)+1]
break
}
}
if !recurse {
// We have no business with this element.
return false, nil
}
// The element is not a perfect match for any field, but one
// or more fields have the path to this element as a parent
// prefix. Recurse and attempt to match these.
for {
var tok Token
tok, err = p.Token()
if err != nil {
return true, err
}
switch t := tok.(type) {
case StartElement:
consumed2, err := p.unmarshalPath(tinfo, sv, parents, &t)
if err != nil {
return true, err
}
if !consumed2 {
if err := p.Skip(); err != nil {
return true, err
}
}
case EndElement:
return true, nil
}
}
}
|
[
"func",
"(",
"p",
"*",
"Decoder",
")",
"unmarshalPath",
"(",
"tinfo",
"*",
"typeInfo",
",",
"sv",
"reflect",
".",
"Value",
",",
"parents",
"[",
"]",
"string",
",",
"start",
"*",
"StartElement",
")",
"(",
"consumed",
"bool",
",",
"err",
"error",
")",
"{",
"recurse",
":=",
"false",
"\n",
"Loop",
":",
"for",
"i",
":=",
"range",
"tinfo",
".",
"fields",
"{",
"finfo",
":=",
"&",
"tinfo",
".",
"fields",
"[",
"i",
"]",
"\n",
"if",
"finfo",
".",
"flags",
"&",
"fElement",
"==",
"0",
"||",
"len",
"(",
"finfo",
".",
"parents",
")",
"<",
"len",
"(",
"parents",
")",
"||",
"finfo",
".",
"xmlns",
"!=",
"\"",
"\"",
"&&",
"finfo",
".",
"xmlns",
"!=",
"start",
".",
"Name",
".",
"Space",
"{",
"continue",
"\n",
"}",
"\n",
"for",
"j",
":=",
"range",
"parents",
"{",
"if",
"parents",
"[",
"j",
"]",
"!=",
"finfo",
".",
"parents",
"[",
"j",
"]",
"{",
"continue",
"Loop",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"finfo",
".",
"parents",
")",
"==",
"len",
"(",
"parents",
")",
"&&",
"finfo",
".",
"name",
"==",
"start",
".",
"Name",
".",
"Local",
"{",
"// It's a perfect match, unmarshal the field.",
"return",
"true",
",",
"p",
".",
"unmarshal",
"(",
"finfo",
".",
"value",
"(",
"sv",
")",
",",
"start",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"finfo",
".",
"parents",
")",
">",
"len",
"(",
"parents",
")",
"&&",
"finfo",
".",
"parents",
"[",
"len",
"(",
"parents",
")",
"]",
"==",
"start",
".",
"Name",
".",
"Local",
"{",
"// It's a prefix for the field. Break and recurse",
"// since it's not ok for one field path to be itself",
"// the prefix for another field path.",
"recurse",
"=",
"true",
"\n\n",
"// We can reuse the same slice as long as we",
"// don't try to append to it.",
"parents",
"=",
"finfo",
".",
"parents",
"[",
":",
"len",
"(",
"parents",
")",
"+",
"1",
"]",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"recurse",
"{",
"// We have no business with this element.",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"// The element is not a perfect match for any field, but one",
"// or more fields have the path to this element as a parent",
"// prefix. Recurse and attempt to match these.",
"for",
"{",
"var",
"tok",
"Token",
"\n",
"tok",
",",
"err",
"=",
"p",
".",
"Token",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"true",
",",
"err",
"\n",
"}",
"\n",
"switch",
"t",
":=",
"tok",
".",
"(",
"type",
")",
"{",
"case",
"StartElement",
":",
"consumed2",
",",
"err",
":=",
"p",
".",
"unmarshalPath",
"(",
"tinfo",
",",
"sv",
",",
"parents",
",",
"&",
"t",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"true",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"consumed2",
"{",
"if",
"err",
":=",
"p",
".",
"Skip",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"true",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"EndElement",
":",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// unmarshalPath walks down an XML structure looking for wanted
// paths, and calls unmarshal on them.
// The consumed result tells whether XML elements have been consumed
// from the Decoder until start's matching end element, or if it's
// still untouched because start is uninteresting for sv's fields.
|
[
"unmarshalPath",
"walks",
"down",
"an",
"XML",
"structure",
"looking",
"for",
"wanted",
"paths",
"and",
"calls",
"unmarshal",
"on",
"them",
".",
"The",
"consumed",
"result",
"tells",
"whether",
"XML",
"elements",
"have",
"been",
"consumed",
"from",
"the",
"Decoder",
"until",
"start",
"s",
"matching",
"end",
"element",
"or",
"if",
"it",
"s",
"still",
"untouched",
"because",
"start",
"is",
"uninteresting",
"for",
"sv",
"s",
"fields",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/read.go#L701-L758
|
21,526
|
vmware/govmomi
|
vim25/xml/read.go
|
Skip
|
func (d *Decoder) Skip() error {
for {
tok, err := d.Token()
if err != nil {
return err
}
switch tok.(type) {
case StartElement:
if err := d.Skip(); err != nil {
return err
}
case EndElement:
return nil
}
}
}
|
go
|
func (d *Decoder) Skip() error {
for {
tok, err := d.Token()
if err != nil {
return err
}
switch tok.(type) {
case StartElement:
if err := d.Skip(); err != nil {
return err
}
case EndElement:
return nil
}
}
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"Skip",
"(",
")",
"error",
"{",
"for",
"{",
"tok",
",",
"err",
":=",
"d",
".",
"Token",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"switch",
"tok",
".",
"(",
"type",
")",
"{",
"case",
"StartElement",
":",
"if",
"err",
":=",
"d",
".",
"Skip",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"case",
"EndElement",
":",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Skip reads tokens until it has consumed the end element
// matching the most recent start element already consumed.
// It recurs if it encounters a start element, so it can be used to
// skip nested structures.
// It returns nil if it finds an end element matching the start
// element; otherwise it returns an error describing the problem.
|
[
"Skip",
"reads",
"tokens",
"until",
"it",
"has",
"consumed",
"the",
"end",
"element",
"matching",
"the",
"most",
"recent",
"start",
"element",
"already",
"consumed",
".",
"It",
"recurs",
"if",
"it",
"encounters",
"a",
"start",
"element",
"so",
"it",
"can",
"be",
"used",
"to",
"skip",
"nested",
"structures",
".",
"It",
"returns",
"nil",
"if",
"it",
"finds",
"an",
"end",
"element",
"matching",
"the",
"start",
"element",
";",
"otherwise",
"it",
"returns",
"an",
"error",
"describing",
"the",
"problem",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/read.go#L766-L781
|
21,527
|
vmware/govmomi
|
vapi/library/library_item_updatesession_file.go
|
AddLibraryItemFile
|
func (c *Manager) AddLibraryItemFile(ctx context.Context, sessionID string, updateFile UpdateFile) (*UpdateFileInfo, error) {
url := internal.URL(c, internal.LibraryItemUpdateSessionFile).WithID(sessionID).WithAction("add")
spec := struct {
FileSpec UpdateFile `json:"file_spec"`
}{updateFile}
var res UpdateFileInfo
return &res, c.Do(ctx, url.Request(http.MethodPost, spec), &res)
}
|
go
|
func (c *Manager) AddLibraryItemFile(ctx context.Context, sessionID string, updateFile UpdateFile) (*UpdateFileInfo, error) {
url := internal.URL(c, internal.LibraryItemUpdateSessionFile).WithID(sessionID).WithAction("add")
spec := struct {
FileSpec UpdateFile `json:"file_spec"`
}{updateFile}
var res UpdateFileInfo
return &res, c.Do(ctx, url.Request(http.MethodPost, spec), &res)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"AddLibraryItemFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"sessionID",
"string",
",",
"updateFile",
"UpdateFile",
")",
"(",
"*",
"UpdateFileInfo",
",",
"error",
")",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"LibraryItemUpdateSessionFile",
")",
".",
"WithID",
"(",
"sessionID",
")",
".",
"WithAction",
"(",
"\"",
"\"",
")",
"\n",
"spec",
":=",
"struct",
"{",
"FileSpec",
"UpdateFile",
"`json:\"file_spec\"`",
"\n",
"}",
"{",
"updateFile",
"}",
"\n",
"var",
"res",
"UpdateFileInfo",
"\n",
"return",
"&",
"res",
",",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodPost",
",",
"spec",
")",
",",
"&",
"res",
")",
"\n",
"}"
] |
// AddLibraryItemFile adds a file
|
[
"AddLibraryItemFile",
"adds",
"a",
"file"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession_file.go#L59-L66
|
21,528
|
vmware/govmomi
|
vapi/library/library_item_updatesession_file.go
|
AddLibraryItemFileFromURI
|
func (c *Manager) AddLibraryItemFileFromURI(
ctx context.Context,
sessionID, fileName, uri string) (*UpdateFileInfo, error) {
n, fingerprint, err := GetContentLengthAndFingerprint(ctx, uri)
if err != nil {
return nil, err
}
info, err := c.AddLibraryItemFile(ctx, sessionID, UpdateFile{
Name: fileName,
SourceType: "PULL",
Size: &n,
SourceEndpoint: &SourceEndpoint{
URI: uri,
SSLCertificateThumbprint: fingerprint,
},
})
if err != nil {
return nil, err
}
return info, c.CompleteLibraryItemUpdateSession(ctx, sessionID)
}
|
go
|
func (c *Manager) AddLibraryItemFileFromURI(
ctx context.Context,
sessionID, fileName, uri string) (*UpdateFileInfo, error) {
n, fingerprint, err := GetContentLengthAndFingerprint(ctx, uri)
if err != nil {
return nil, err
}
info, err := c.AddLibraryItemFile(ctx, sessionID, UpdateFile{
Name: fileName,
SourceType: "PULL",
Size: &n,
SourceEndpoint: &SourceEndpoint{
URI: uri,
SSLCertificateThumbprint: fingerprint,
},
})
if err != nil {
return nil, err
}
return info, c.CompleteLibraryItemUpdateSession(ctx, sessionID)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"AddLibraryItemFileFromURI",
"(",
"ctx",
"context",
".",
"Context",
",",
"sessionID",
",",
"fileName",
",",
"uri",
"string",
")",
"(",
"*",
"UpdateFileInfo",
",",
"error",
")",
"{",
"n",
",",
"fingerprint",
",",
"err",
":=",
"GetContentLengthAndFingerprint",
"(",
"ctx",
",",
"uri",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"info",
",",
"err",
":=",
"c",
".",
"AddLibraryItemFile",
"(",
"ctx",
",",
"sessionID",
",",
"UpdateFile",
"{",
"Name",
":",
"fileName",
",",
"SourceType",
":",
"\"",
"\"",
",",
"Size",
":",
"&",
"n",
",",
"SourceEndpoint",
":",
"&",
"SourceEndpoint",
"{",
"URI",
":",
"uri",
",",
"SSLCertificateThumbprint",
":",
"fingerprint",
",",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"info",
",",
"c",
".",
"CompleteLibraryItemUpdateSession",
"(",
"ctx",
",",
"sessionID",
")",
"\n",
"}"
] |
// AddLibraryItemFileFromURI adds a file from a remote URI.
|
[
"AddLibraryItemFileFromURI",
"adds",
"a",
"file",
"from",
"a",
"remote",
"URI",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession_file.go#L69-L92
|
21,529
|
vmware/govmomi
|
vapi/library/library_item_updatesession_file.go
|
GetLibraryItemUpdateSessionFile
|
func (c *Manager) GetLibraryItemUpdateSessionFile(ctx context.Context, sessionID string, fileName string) (*UpdateFileInfo, error) {
url := internal.URL(c, internal.LibraryItemUpdateSessionFile).WithID(sessionID).WithAction("get")
spec := struct {
Name string `json:"file_name"`
}{fileName}
var res UpdateFileInfo
return &res, c.Do(ctx, url.Request(http.MethodPost, spec), &res)
}
|
go
|
func (c *Manager) GetLibraryItemUpdateSessionFile(ctx context.Context, sessionID string, fileName string) (*UpdateFileInfo, error) {
url := internal.URL(c, internal.LibraryItemUpdateSessionFile).WithID(sessionID).WithAction("get")
spec := struct {
Name string `json:"file_name"`
}{fileName}
var res UpdateFileInfo
return &res, c.Do(ctx, url.Request(http.MethodPost, spec), &res)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"GetLibraryItemUpdateSessionFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"sessionID",
"string",
",",
"fileName",
"string",
")",
"(",
"*",
"UpdateFileInfo",
",",
"error",
")",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"LibraryItemUpdateSessionFile",
")",
".",
"WithID",
"(",
"sessionID",
")",
".",
"WithAction",
"(",
"\"",
"\"",
")",
"\n",
"spec",
":=",
"struct",
"{",
"Name",
"string",
"`json:\"file_name\"`",
"\n",
"}",
"{",
"fileName",
"}",
"\n",
"var",
"res",
"UpdateFileInfo",
"\n",
"return",
"&",
"res",
",",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodPost",
",",
"spec",
")",
",",
"&",
"res",
")",
"\n",
"}"
] |
// GetLibraryItemUpdateSessionFile retrieves information about a specific file
// that is a part of an update session.
|
[
"GetLibraryItemUpdateSessionFile",
"retrieves",
"information",
"about",
"a",
"specific",
"file",
"that",
"is",
"a",
"part",
"of",
"an",
"update",
"session",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession_file.go#L96-L103
|
21,530
|
vmware/govmomi
|
vapi/library/library_item_updatesession_file.go
|
GetContentLengthAndFingerprint
|
func GetContentLengthAndFingerprint(
ctx context.Context, uri string) (int64, string, error) {
resp, err := http.Head(uri)
if err != nil {
return 0, "", err
}
if resp.TLS == nil || len(resp.TLS.PeerCertificates) == 0 {
return resp.ContentLength, "", nil
}
fingerprint := &bytes.Buffer{}
sum := sha1.Sum(resp.TLS.PeerCertificates[0].Raw)
for i, b := range sum {
fmt.Fprintf(fingerprint, "%X", b)
if i < len(sum)-1 {
fmt.Fprint(fingerprint, ":")
}
}
return resp.ContentLength, fingerprint.String(), nil
}
|
go
|
func GetContentLengthAndFingerprint(
ctx context.Context, uri string) (int64, string, error) {
resp, err := http.Head(uri)
if err != nil {
return 0, "", err
}
if resp.TLS == nil || len(resp.TLS.PeerCertificates) == 0 {
return resp.ContentLength, "", nil
}
fingerprint := &bytes.Buffer{}
sum := sha1.Sum(resp.TLS.PeerCertificates[0].Raw)
for i, b := range sum {
fmt.Fprintf(fingerprint, "%X", b)
if i < len(sum)-1 {
fmt.Fprint(fingerprint, ":")
}
}
return resp.ContentLength, fingerprint.String(), nil
}
|
[
"func",
"GetContentLengthAndFingerprint",
"(",
"ctx",
"context",
".",
"Context",
",",
"uri",
"string",
")",
"(",
"int64",
",",
"string",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Head",
"(",
"uri",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"resp",
".",
"TLS",
"==",
"nil",
"||",
"len",
"(",
"resp",
".",
"TLS",
".",
"PeerCertificates",
")",
"==",
"0",
"{",
"return",
"resp",
".",
"ContentLength",
",",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"fingerprint",
":=",
"&",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"sum",
":=",
"sha1",
".",
"Sum",
"(",
"resp",
".",
"TLS",
".",
"PeerCertificates",
"[",
"0",
"]",
".",
"Raw",
")",
"\n",
"for",
"i",
",",
"b",
":=",
"range",
"sum",
"{",
"fmt",
".",
"Fprintf",
"(",
"fingerprint",
",",
"\"",
"\"",
",",
"b",
")",
"\n",
"if",
"i",
"<",
"len",
"(",
"sum",
")",
"-",
"1",
"{",
"fmt",
".",
"Fprint",
"(",
"fingerprint",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"resp",
".",
"ContentLength",
",",
"fingerprint",
".",
"String",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// GetContentLengthAndFingerprint gets the number of bytes returned
// by the URI as well as the SHA1 fingerprint of the peer certificate
// if the URI's scheme is https.
|
[
"GetContentLengthAndFingerprint",
"gets",
"the",
"number",
"of",
"bytes",
"returned",
"by",
"the",
"URI",
"as",
"well",
"as",
"the",
"SHA1",
"fingerprint",
"of",
"the",
"peer",
"certificate",
"if",
"the",
"URI",
"s",
"scheme",
"is",
"https",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/library/library_item_updatesession_file.go#L108-L126
|
21,531
|
vmware/govmomi
|
simulator/event_manager.go
|
formatMessage
|
func (m *EventManager) formatMessage(event types.BaseEvent) {
id := reflect.ValueOf(event).Elem().Type().Name()
e := event.GetEvent()
t, ok := m.templates[id]
if !ok {
for _, info := range m.Description.EventInfo {
if info.Key == id {
t = template.Must(template.New(id).Parse(info.FullFormat))
m.templates[id] = t
break
}
}
}
if t != nil {
var buf bytes.Buffer
if err := t.Execute(&buf, event); err != nil {
log.Print(err)
}
e.FullFormattedMessage = buf.String()
}
if logEvents {
log.Printf("[%s] %s", id, e.FullFormattedMessage)
}
}
|
go
|
func (m *EventManager) formatMessage(event types.BaseEvent) {
id := reflect.ValueOf(event).Elem().Type().Name()
e := event.GetEvent()
t, ok := m.templates[id]
if !ok {
for _, info := range m.Description.EventInfo {
if info.Key == id {
t = template.Must(template.New(id).Parse(info.FullFormat))
m.templates[id] = t
break
}
}
}
if t != nil {
var buf bytes.Buffer
if err := t.Execute(&buf, event); err != nil {
log.Print(err)
}
e.FullFormattedMessage = buf.String()
}
if logEvents {
log.Printf("[%s] %s", id, e.FullFormattedMessage)
}
}
|
[
"func",
"(",
"m",
"*",
"EventManager",
")",
"formatMessage",
"(",
"event",
"types",
".",
"BaseEvent",
")",
"{",
"id",
":=",
"reflect",
".",
"ValueOf",
"(",
"event",
")",
".",
"Elem",
"(",
")",
".",
"Type",
"(",
")",
".",
"Name",
"(",
")",
"\n",
"e",
":=",
"event",
".",
"GetEvent",
"(",
")",
"\n\n",
"t",
",",
"ok",
":=",
"m",
".",
"templates",
"[",
"id",
"]",
"\n",
"if",
"!",
"ok",
"{",
"for",
"_",
",",
"info",
":=",
"range",
"m",
".",
"Description",
".",
"EventInfo",
"{",
"if",
"info",
".",
"Key",
"==",
"id",
"{",
"t",
"=",
"template",
".",
"Must",
"(",
"template",
".",
"New",
"(",
"id",
")",
".",
"Parse",
"(",
"info",
".",
"FullFormat",
")",
")",
"\n",
"m",
".",
"templates",
"[",
"id",
"]",
"=",
"t",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"t",
"!=",
"nil",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"err",
":=",
"t",
".",
"Execute",
"(",
"&",
"buf",
",",
"event",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Print",
"(",
"err",
")",
"\n",
"}",
"\n",
"e",
".",
"FullFormattedMessage",
"=",
"buf",
".",
"String",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"logEvents",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"id",
",",
"e",
".",
"FullFormattedMessage",
")",
"\n",
"}",
"\n",
"}"
] |
// formatMessage applies the EventDescriptionEventDetail.FullFormat template to the given event's FullFormattedMessage field.
|
[
"formatMessage",
"applies",
"the",
"EventDescriptionEventDetail",
".",
"FullFormat",
"template",
"to",
"the",
"given",
"event",
"s",
"FullFormattedMessage",
"field",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/event_manager.go#L126-L152
|
21,532
|
vmware/govmomi
|
simulator/event_manager.go
|
doEntityEventArgument
|
func doEntityEventArgument(event types.BaseEvent, f func(types.ManagedObjectReference, *types.EntityEventArgument) bool) bool {
e := event.GetEvent()
if arg := e.Vm; arg != nil {
if f(arg.Vm, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Host; arg != nil {
if f(arg.Host, &arg.EntityEventArgument) {
return true
}
}
if arg := e.ComputeResource; arg != nil {
if f(arg.ComputeResource, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Ds; arg != nil {
if f(arg.Datastore, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Net; arg != nil {
if f(arg.Network, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Dvs; arg != nil {
if f(arg.Dvs, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Datacenter; arg != nil {
if f(arg.Datacenter, &arg.EntityEventArgument) {
return true
}
}
return false
}
|
go
|
func doEntityEventArgument(event types.BaseEvent, f func(types.ManagedObjectReference, *types.EntityEventArgument) bool) bool {
e := event.GetEvent()
if arg := e.Vm; arg != nil {
if f(arg.Vm, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Host; arg != nil {
if f(arg.Host, &arg.EntityEventArgument) {
return true
}
}
if arg := e.ComputeResource; arg != nil {
if f(arg.ComputeResource, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Ds; arg != nil {
if f(arg.Datastore, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Net; arg != nil {
if f(arg.Network, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Dvs; arg != nil {
if f(arg.Dvs, &arg.EntityEventArgument) {
return true
}
}
if arg := e.Datacenter; arg != nil {
if f(arg.Datacenter, &arg.EntityEventArgument) {
return true
}
}
return false
}
|
[
"func",
"doEntityEventArgument",
"(",
"event",
"types",
".",
"BaseEvent",
",",
"f",
"func",
"(",
"types",
".",
"ManagedObjectReference",
",",
"*",
"types",
".",
"EntityEventArgument",
")",
"bool",
")",
"bool",
"{",
"e",
":=",
"event",
".",
"GetEvent",
"(",
")",
"\n\n",
"if",
"arg",
":=",
"e",
".",
"Vm",
";",
"arg",
"!=",
"nil",
"{",
"if",
"f",
"(",
"arg",
".",
"Vm",
",",
"&",
"arg",
".",
"EntityEventArgument",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"arg",
":=",
"e",
".",
"Host",
";",
"arg",
"!=",
"nil",
"{",
"if",
"f",
"(",
"arg",
".",
"Host",
",",
"&",
"arg",
".",
"EntityEventArgument",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"arg",
":=",
"e",
".",
"ComputeResource",
";",
"arg",
"!=",
"nil",
"{",
"if",
"f",
"(",
"arg",
".",
"ComputeResource",
",",
"&",
"arg",
".",
"EntityEventArgument",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"arg",
":=",
"e",
".",
"Ds",
";",
"arg",
"!=",
"nil",
"{",
"if",
"f",
"(",
"arg",
".",
"Datastore",
",",
"&",
"arg",
".",
"EntityEventArgument",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"arg",
":=",
"e",
".",
"Net",
";",
"arg",
"!=",
"nil",
"{",
"if",
"f",
"(",
"arg",
".",
"Network",
",",
"&",
"arg",
".",
"EntityEventArgument",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"arg",
":=",
"e",
".",
"Dvs",
";",
"arg",
"!=",
"nil",
"{",
"if",
"f",
"(",
"arg",
".",
"Dvs",
",",
"&",
"arg",
".",
"EntityEventArgument",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"arg",
":=",
"e",
".",
"Datacenter",
";",
"arg",
"!=",
"nil",
"{",
"if",
"f",
"(",
"arg",
".",
"Datacenter",
",",
"&",
"arg",
".",
"EntityEventArgument",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// doEntityEventArgument calls f for each entity argument in the event.
// If f returns true, the iteration stops.
|
[
"doEntityEventArgument",
"calls",
"f",
"for",
"each",
"entity",
"argument",
"in",
"the",
"event",
".",
"If",
"f",
"returns",
"true",
"the",
"iteration",
"stops",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/event_manager.go#L191-L237
|
21,533
|
vmware/govmomi
|
simulator/event_manager.go
|
eventFilterSelf
|
func eventFilterSelf(event types.BaseEvent, self types.ManagedObjectReference) bool {
return doEntityEventArgument(event, func(ref types.ManagedObjectReference, _ *types.EntityEventArgument) bool {
return self == ref
})
}
|
go
|
func eventFilterSelf(event types.BaseEvent, self types.ManagedObjectReference) bool {
return doEntityEventArgument(event, func(ref types.ManagedObjectReference, _ *types.EntityEventArgument) bool {
return self == ref
})
}
|
[
"func",
"eventFilterSelf",
"(",
"event",
"types",
".",
"BaseEvent",
",",
"self",
"types",
".",
"ManagedObjectReference",
")",
"bool",
"{",
"return",
"doEntityEventArgument",
"(",
"event",
",",
"func",
"(",
"ref",
"types",
".",
"ManagedObjectReference",
",",
"_",
"*",
"types",
".",
"EntityEventArgument",
")",
"bool",
"{",
"return",
"self",
"==",
"ref",
"\n",
"}",
")",
"\n",
"}"
] |
// eventFilterSelf returns true if self is one of the entity arguments in the event.
|
[
"eventFilterSelf",
"returns",
"true",
"if",
"self",
"is",
"one",
"of",
"the",
"entity",
"arguments",
"in",
"the",
"event",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/event_manager.go#L240-L244
|
21,534
|
vmware/govmomi
|
simulator/event_manager.go
|
eventFilterChildren
|
func eventFilterChildren(event types.BaseEvent, self types.ManagedObjectReference) bool {
return doEntityEventArgument(event, func(ref types.ManagedObjectReference, _ *types.EntityEventArgument) bool {
seen := false
var match func(types.ManagedObjectReference)
match = func(child types.ManagedObjectReference) {
if child == self {
seen = true
return
}
walk(child, match)
}
walk(ref, match)
return seen
})
}
|
go
|
func eventFilterChildren(event types.BaseEvent, self types.ManagedObjectReference) bool {
return doEntityEventArgument(event, func(ref types.ManagedObjectReference, _ *types.EntityEventArgument) bool {
seen := false
var match func(types.ManagedObjectReference)
match = func(child types.ManagedObjectReference) {
if child == self {
seen = true
return
}
walk(child, match)
}
walk(ref, match)
return seen
})
}
|
[
"func",
"eventFilterChildren",
"(",
"event",
"types",
".",
"BaseEvent",
",",
"self",
"types",
".",
"ManagedObjectReference",
")",
"bool",
"{",
"return",
"doEntityEventArgument",
"(",
"event",
",",
"func",
"(",
"ref",
"types",
".",
"ManagedObjectReference",
",",
"_",
"*",
"types",
".",
"EntityEventArgument",
")",
"bool",
"{",
"seen",
":=",
"false",
"\n\n",
"var",
"match",
"func",
"(",
"types",
".",
"ManagedObjectReference",
")",
"\n\n",
"match",
"=",
"func",
"(",
"child",
"types",
".",
"ManagedObjectReference",
")",
"{",
"if",
"child",
"==",
"self",
"{",
"seen",
"=",
"true",
"\n",
"return",
"\n",
"}",
"\n\n",
"walk",
"(",
"child",
",",
"match",
")",
"\n",
"}",
"\n\n",
"walk",
"(",
"ref",
",",
"match",
")",
"\n\n",
"return",
"seen",
"\n",
"}",
")",
"\n",
"}"
] |
// eventFilterChildren returns true if a child of self is one of the entity arguments in the event.
|
[
"eventFilterChildren",
"returns",
"true",
"if",
"a",
"child",
"of",
"self",
"is",
"one",
"of",
"the",
"entity",
"arguments",
"in",
"the",
"event",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/event_manager.go#L247-L266
|
21,535
|
vmware/govmomi
|
simulator/event_manager.go
|
entityMatches
|
func (c *EventHistoryCollector) entityMatches(event types.BaseEvent, spec *types.EventFilterSpec) bool {
e := spec.Entity
if e == nil {
return true
}
isRootFolder := c.m.root == e.Entity
switch e.Recursion {
case types.EventFilterSpecRecursionOptionSelf:
return isRootFolder || eventFilterSelf(event, e.Entity)
case types.EventFilterSpecRecursionOptionChildren:
return eventFilterChildren(event, e.Entity)
case types.EventFilterSpecRecursionOptionAll:
if isRootFolder || eventFilterSelf(event, e.Entity) {
return true
}
return eventFilterChildren(event, e.Entity)
}
return false
}
|
go
|
func (c *EventHistoryCollector) entityMatches(event types.BaseEvent, spec *types.EventFilterSpec) bool {
e := spec.Entity
if e == nil {
return true
}
isRootFolder := c.m.root == e.Entity
switch e.Recursion {
case types.EventFilterSpecRecursionOptionSelf:
return isRootFolder || eventFilterSelf(event, e.Entity)
case types.EventFilterSpecRecursionOptionChildren:
return eventFilterChildren(event, e.Entity)
case types.EventFilterSpecRecursionOptionAll:
if isRootFolder || eventFilterSelf(event, e.Entity) {
return true
}
return eventFilterChildren(event, e.Entity)
}
return false
}
|
[
"func",
"(",
"c",
"*",
"EventHistoryCollector",
")",
"entityMatches",
"(",
"event",
"types",
".",
"BaseEvent",
",",
"spec",
"*",
"types",
".",
"EventFilterSpec",
")",
"bool",
"{",
"e",
":=",
"spec",
".",
"Entity",
"\n",
"if",
"e",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"isRootFolder",
":=",
"c",
".",
"m",
".",
"root",
"==",
"e",
".",
"Entity",
"\n\n",
"switch",
"e",
".",
"Recursion",
"{",
"case",
"types",
".",
"EventFilterSpecRecursionOptionSelf",
":",
"return",
"isRootFolder",
"||",
"eventFilterSelf",
"(",
"event",
",",
"e",
".",
"Entity",
")",
"\n",
"case",
"types",
".",
"EventFilterSpecRecursionOptionChildren",
":",
"return",
"eventFilterChildren",
"(",
"event",
",",
"e",
".",
"Entity",
")",
"\n",
"case",
"types",
".",
"EventFilterSpecRecursionOptionAll",
":",
"if",
"isRootFolder",
"||",
"eventFilterSelf",
"(",
"event",
",",
"e",
".",
"Entity",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"eventFilterChildren",
"(",
"event",
",",
"e",
".",
"Entity",
")",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// entityMatches returns true if the spec Entity filter matches the event.
|
[
"entityMatches",
"returns",
"true",
"if",
"the",
"spec",
"Entity",
"filter",
"matches",
"the",
"event",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/event_manager.go#L269-L290
|
21,536
|
vmware/govmomi
|
simulator/event_manager.go
|
typeMatches
|
func (c *EventHistoryCollector) typeMatches(event types.BaseEvent, spec *types.EventFilterSpec) bool {
if len(spec.EventTypeId) == 0 {
return true
}
matches := func(name string) bool {
for _, id := range spec.EventTypeId {
if id == name {
return true
}
}
return false
}
kind := reflect.ValueOf(event).Elem().Type()
if matches(kind.Name()) {
return true // concrete type
}
field, ok := kind.FieldByNameFunc(matches)
if ok {
return field.Anonymous // base type (embedded field)
}
return false
}
|
go
|
func (c *EventHistoryCollector) typeMatches(event types.BaseEvent, spec *types.EventFilterSpec) bool {
if len(spec.EventTypeId) == 0 {
return true
}
matches := func(name string) bool {
for _, id := range spec.EventTypeId {
if id == name {
return true
}
}
return false
}
kind := reflect.ValueOf(event).Elem().Type()
if matches(kind.Name()) {
return true // concrete type
}
field, ok := kind.FieldByNameFunc(matches)
if ok {
return field.Anonymous // base type (embedded field)
}
return false
}
|
[
"func",
"(",
"c",
"*",
"EventHistoryCollector",
")",
"typeMatches",
"(",
"event",
"types",
".",
"BaseEvent",
",",
"spec",
"*",
"types",
".",
"EventFilterSpec",
")",
"bool",
"{",
"if",
"len",
"(",
"spec",
".",
"EventTypeId",
")",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"matches",
":=",
"func",
"(",
"name",
"string",
")",
"bool",
"{",
"for",
"_",
",",
"id",
":=",
"range",
"spec",
".",
"EventTypeId",
"{",
"if",
"id",
"==",
"name",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"kind",
":=",
"reflect",
".",
"ValueOf",
"(",
"event",
")",
".",
"Elem",
"(",
")",
".",
"Type",
"(",
")",
"\n\n",
"if",
"matches",
"(",
"kind",
".",
"Name",
"(",
")",
")",
"{",
"return",
"true",
"// concrete type",
"\n",
"}",
"\n\n",
"field",
",",
"ok",
":=",
"kind",
".",
"FieldByNameFunc",
"(",
"matches",
")",
"\n",
"if",
"ok",
"{",
"return",
"field",
".",
"Anonymous",
"// base type (embedded field)",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] |
// typeMatches returns true if one of the spec EventTypeId types matches the event.
|
[
"typeMatches",
"returns",
"true",
"if",
"one",
"of",
"the",
"spec",
"EventTypeId",
"types",
"matches",
"the",
"event",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/event_manager.go#L293-L317
|
21,537
|
vmware/govmomi
|
simulator/event_manager.go
|
eventMatches
|
func (c *EventHistoryCollector) eventMatches(event types.BaseEvent) bool {
spec := c.Filter.(types.EventFilterSpec)
if !c.typeMatches(event, &spec) {
return false
}
// TODO: spec.Time, spec.UserName, etc
return c.entityMatches(event, &spec)
}
|
go
|
func (c *EventHistoryCollector) eventMatches(event types.BaseEvent) bool {
spec := c.Filter.(types.EventFilterSpec)
if !c.typeMatches(event, &spec) {
return false
}
// TODO: spec.Time, spec.UserName, etc
return c.entityMatches(event, &spec)
}
|
[
"func",
"(",
"c",
"*",
"EventHistoryCollector",
")",
"eventMatches",
"(",
"event",
"types",
".",
"BaseEvent",
")",
"bool",
"{",
"spec",
":=",
"c",
".",
"Filter",
".",
"(",
"types",
".",
"EventFilterSpec",
")",
"\n\n",
"if",
"!",
"c",
".",
"typeMatches",
"(",
"event",
",",
"&",
"spec",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// TODO: spec.Time, spec.UserName, etc",
"return",
"c",
".",
"entityMatches",
"(",
"event",
",",
"&",
"spec",
")",
"\n",
"}"
] |
// eventMatches returns true one of the filters matches the event.
|
[
"eventMatches",
"returns",
"true",
"one",
"of",
"the",
"filters",
"matches",
"the",
"event",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/event_manager.go#L320-L330
|
21,538
|
vmware/govmomi
|
simulator/event_manager.go
|
fillPage
|
func (c *EventHistoryCollector) fillPage(size int) {
c.pos = 0
l := c.page.Len()
delta := size - l
if delta < 0 {
// Shrink ring size
c.page = c.page.Unlink(-delta)
return
}
matches := 0
mpage := c.m.page
page := c.page
if delta != 0 {
// Grow ring size
c.page = c.page.Link(ring.New(delta))
}
for i := 0; i < maxPageSize; i++ {
event, ok := mpage.Value.(types.BaseEvent)
mpage = mpage.Prev()
if !ok {
continue
}
if c.eventMatches(event) {
page.Value = event
page = page.Prev()
matches++
if matches == size {
break
}
}
}
}
|
go
|
func (c *EventHistoryCollector) fillPage(size int) {
c.pos = 0
l := c.page.Len()
delta := size - l
if delta < 0 {
// Shrink ring size
c.page = c.page.Unlink(-delta)
return
}
matches := 0
mpage := c.m.page
page := c.page
if delta != 0 {
// Grow ring size
c.page = c.page.Link(ring.New(delta))
}
for i := 0; i < maxPageSize; i++ {
event, ok := mpage.Value.(types.BaseEvent)
mpage = mpage.Prev()
if !ok {
continue
}
if c.eventMatches(event) {
page.Value = event
page = page.Prev()
matches++
if matches == size {
break
}
}
}
}
|
[
"func",
"(",
"c",
"*",
"EventHistoryCollector",
")",
"fillPage",
"(",
"size",
"int",
")",
"{",
"c",
".",
"pos",
"=",
"0",
"\n",
"l",
":=",
"c",
".",
"page",
".",
"Len",
"(",
")",
"\n",
"delta",
":=",
"size",
"-",
"l",
"\n\n",
"if",
"delta",
"<",
"0",
"{",
"// Shrink ring size",
"c",
".",
"page",
"=",
"c",
".",
"page",
".",
"Unlink",
"(",
"-",
"delta",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"matches",
":=",
"0",
"\n",
"mpage",
":=",
"c",
".",
"m",
".",
"page",
"\n",
"page",
":=",
"c",
".",
"page",
"\n\n",
"if",
"delta",
"!=",
"0",
"{",
"// Grow ring size",
"c",
".",
"page",
"=",
"c",
".",
"page",
".",
"Link",
"(",
"ring",
".",
"New",
"(",
"delta",
")",
")",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxPageSize",
";",
"i",
"++",
"{",
"event",
",",
"ok",
":=",
"mpage",
".",
"Value",
".",
"(",
"types",
".",
"BaseEvent",
")",
"\n",
"mpage",
"=",
"mpage",
".",
"Prev",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"c",
".",
"eventMatches",
"(",
"event",
")",
"{",
"page",
".",
"Value",
"=",
"event",
"\n",
"page",
"=",
"page",
".",
"Prev",
"(",
")",
"\n",
"matches",
"++",
"\n",
"if",
"matches",
"==",
"size",
"{",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// filePage copies the manager's latest events into the collector's page with Filter applied.
|
[
"filePage",
"copies",
"the",
"manager",
"s",
"latest",
"events",
"into",
"the",
"collector",
"s",
"page",
"with",
"Filter",
"applied",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/event_manager.go#L333-L369
|
21,539
|
vmware/govmomi
|
object/virtual_disk_manager.go
|
CopyVirtualDisk
|
func (m VirtualDiskManager) CopyVirtualDisk(
ctx context.Context,
sourceName string, sourceDatacenter *Datacenter,
destName string, destDatacenter *Datacenter,
destSpec *types.VirtualDiskSpec, force bool) (*Task, error) {
req := types.CopyVirtualDisk_Task{
This: m.Reference(),
SourceName: sourceName,
DestName: destName,
DestSpec: destSpec,
Force: types.NewBool(force),
}
if sourceDatacenter != nil {
ref := sourceDatacenter.Reference()
req.SourceDatacenter = &ref
}
if destDatacenter != nil {
ref := destDatacenter.Reference()
req.DestDatacenter = &ref
}
res, err := methods.CopyVirtualDisk_Task(ctx, m.c, &req)
if err != nil {
return nil, err
}
return NewTask(m.c, res.Returnval), nil
}
|
go
|
func (m VirtualDiskManager) CopyVirtualDisk(
ctx context.Context,
sourceName string, sourceDatacenter *Datacenter,
destName string, destDatacenter *Datacenter,
destSpec *types.VirtualDiskSpec, force bool) (*Task, error) {
req := types.CopyVirtualDisk_Task{
This: m.Reference(),
SourceName: sourceName,
DestName: destName,
DestSpec: destSpec,
Force: types.NewBool(force),
}
if sourceDatacenter != nil {
ref := sourceDatacenter.Reference()
req.SourceDatacenter = &ref
}
if destDatacenter != nil {
ref := destDatacenter.Reference()
req.DestDatacenter = &ref
}
res, err := methods.CopyVirtualDisk_Task(ctx, m.c, &req)
if err != nil {
return nil, err
}
return NewTask(m.c, res.Returnval), nil
}
|
[
"func",
"(",
"m",
"VirtualDiskManager",
")",
"CopyVirtualDisk",
"(",
"ctx",
"context",
".",
"Context",
",",
"sourceName",
"string",
",",
"sourceDatacenter",
"*",
"Datacenter",
",",
"destName",
"string",
",",
"destDatacenter",
"*",
"Datacenter",
",",
"destSpec",
"*",
"types",
".",
"VirtualDiskSpec",
",",
"force",
"bool",
")",
"(",
"*",
"Task",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"CopyVirtualDisk_Task",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"SourceName",
":",
"sourceName",
",",
"DestName",
":",
"destName",
",",
"DestSpec",
":",
"destSpec",
",",
"Force",
":",
"types",
".",
"NewBool",
"(",
"force",
")",
",",
"}",
"\n\n",
"if",
"sourceDatacenter",
"!=",
"nil",
"{",
"ref",
":=",
"sourceDatacenter",
".",
"Reference",
"(",
")",
"\n",
"req",
".",
"SourceDatacenter",
"=",
"&",
"ref",
"\n",
"}",
"\n\n",
"if",
"destDatacenter",
"!=",
"nil",
"{",
"ref",
":=",
"destDatacenter",
".",
"Reference",
"(",
")",
"\n",
"req",
".",
"DestDatacenter",
"=",
"&",
"ref",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"CopyVirtualDisk_Task",
"(",
"ctx",
",",
"m",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewTask",
"(",
"m",
".",
"c",
",",
"res",
".",
"Returnval",
")",
",",
"nil",
"\n",
"}"
] |
// CopyVirtualDisk copies a virtual disk, performing conversions as specified in the spec.
|
[
"CopyVirtualDisk",
"copies",
"a",
"virtual",
"disk",
"performing",
"conversions",
"as",
"specified",
"in",
"the",
"spec",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_disk_manager.go#L40-L70
|
21,540
|
vmware/govmomi
|
object/virtual_disk_manager.go
|
CreateVirtualDisk
|
func (m VirtualDiskManager) CreateVirtualDisk(
ctx context.Context,
name string, datacenter *Datacenter,
spec types.BaseVirtualDiskSpec) (*Task, error) {
req := types.CreateVirtualDisk_Task{
This: m.Reference(),
Name: name,
Spec: spec,
}
if datacenter != nil {
ref := datacenter.Reference()
req.Datacenter = &ref
}
res, err := methods.CreateVirtualDisk_Task(ctx, m.c, &req)
if err != nil {
return nil, err
}
return NewTask(m.c, res.Returnval), nil
}
|
go
|
func (m VirtualDiskManager) CreateVirtualDisk(
ctx context.Context,
name string, datacenter *Datacenter,
spec types.BaseVirtualDiskSpec) (*Task, error) {
req := types.CreateVirtualDisk_Task{
This: m.Reference(),
Name: name,
Spec: spec,
}
if datacenter != nil {
ref := datacenter.Reference()
req.Datacenter = &ref
}
res, err := methods.CreateVirtualDisk_Task(ctx, m.c, &req)
if err != nil {
return nil, err
}
return NewTask(m.c, res.Returnval), nil
}
|
[
"func",
"(",
"m",
"VirtualDiskManager",
")",
"CreateVirtualDisk",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"datacenter",
"*",
"Datacenter",
",",
"spec",
"types",
".",
"BaseVirtualDiskSpec",
")",
"(",
"*",
"Task",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"CreateVirtualDisk_Task",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"Name",
":",
"name",
",",
"Spec",
":",
"spec",
",",
"}",
"\n\n",
"if",
"datacenter",
"!=",
"nil",
"{",
"ref",
":=",
"datacenter",
".",
"Reference",
"(",
")",
"\n",
"req",
".",
"Datacenter",
"=",
"&",
"ref",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"CreateVirtualDisk_Task",
"(",
"ctx",
",",
"m",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewTask",
"(",
"m",
".",
"c",
",",
"res",
".",
"Returnval",
")",
",",
"nil",
"\n",
"}"
] |
// CreateVirtualDisk creates a new virtual disk.
|
[
"CreateVirtualDisk",
"creates",
"a",
"new",
"virtual",
"disk",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_disk_manager.go#L73-L95
|
21,541
|
vmware/govmomi
|
object/virtual_disk_manager.go
|
ShrinkVirtualDisk
|
func (m VirtualDiskManager) ShrinkVirtualDisk(ctx context.Context, name string, dc *Datacenter, copy *bool) (*Task, error) {
req := types.ShrinkVirtualDisk_Task{
This: m.Reference(),
Name: name,
Copy: copy,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
res, err := methods.ShrinkVirtualDisk_Task(ctx, m.c, &req)
if err != nil {
return nil, err
}
return NewTask(m.c, res.Returnval), nil
}
|
go
|
func (m VirtualDiskManager) ShrinkVirtualDisk(ctx context.Context, name string, dc *Datacenter, copy *bool) (*Task, error) {
req := types.ShrinkVirtualDisk_Task{
This: m.Reference(),
Name: name,
Copy: copy,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
res, err := methods.ShrinkVirtualDisk_Task(ctx, m.c, &req)
if err != nil {
return nil, err
}
return NewTask(m.c, res.Returnval), nil
}
|
[
"func",
"(",
"m",
"VirtualDiskManager",
")",
"ShrinkVirtualDisk",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"dc",
"*",
"Datacenter",
",",
"copy",
"*",
"bool",
")",
"(",
"*",
"Task",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"ShrinkVirtualDisk_Task",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"Name",
":",
"name",
",",
"Copy",
":",
"copy",
",",
"}",
"\n\n",
"if",
"dc",
"!=",
"nil",
"{",
"ref",
":=",
"dc",
".",
"Reference",
"(",
")",
"\n",
"req",
".",
"Datacenter",
"=",
"&",
"ref",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"ShrinkVirtualDisk_Task",
"(",
"ctx",
",",
"m",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewTask",
"(",
"m",
".",
"c",
",",
"res",
".",
"Returnval",
")",
",",
"nil",
"\n",
"}"
] |
// ShrinkVirtualDisk shrinks a virtual disk.
|
[
"ShrinkVirtualDisk",
"shrinks",
"a",
"virtual",
"disk",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_disk_manager.go#L169-L187
|
21,542
|
vmware/govmomi
|
object/virtual_disk_manager.go
|
QueryVirtualDiskUuid
|
func (m VirtualDiskManager) QueryVirtualDiskUuid(ctx context.Context, name string, dc *Datacenter) (string, error) {
req := types.QueryVirtualDiskUuid{
This: m.Reference(),
Name: name,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
res, err := methods.QueryVirtualDiskUuid(ctx, m.c, &req)
if err != nil {
return "", err
}
if res == nil {
return "", nil
}
return res.Returnval, nil
}
|
go
|
func (m VirtualDiskManager) QueryVirtualDiskUuid(ctx context.Context, name string, dc *Datacenter) (string, error) {
req := types.QueryVirtualDiskUuid{
This: m.Reference(),
Name: name,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
res, err := methods.QueryVirtualDiskUuid(ctx, m.c, &req)
if err != nil {
return "", err
}
if res == nil {
return "", nil
}
return res.Returnval, nil
}
|
[
"func",
"(",
"m",
"VirtualDiskManager",
")",
"QueryVirtualDiskUuid",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"dc",
"*",
"Datacenter",
")",
"(",
"string",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"QueryVirtualDiskUuid",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"Name",
":",
"name",
",",
"}",
"\n\n",
"if",
"dc",
"!=",
"nil",
"{",
"ref",
":=",
"dc",
".",
"Reference",
"(",
")",
"\n",
"req",
".",
"Datacenter",
"=",
"&",
"ref",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"QueryVirtualDiskUuid",
"(",
"ctx",
",",
"m",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"res",
"==",
"nil",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"res",
".",
"Returnval",
",",
"nil",
"\n",
"}"
] |
// Queries virtual disk uuid
|
[
"Queries",
"virtual",
"disk",
"uuid"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_disk_manager.go#L190-L211
|
21,543
|
vmware/govmomi
|
toolbox/service.go
|
NewService
|
func NewService(rpcIn Channel, rpcOut Channel) *Service {
s := &Service{
name: "toolbox", // Same name used by vmtoolsd
in: NewTraceChannel(rpcIn),
out: &ChannelOut{NewTraceChannel(rpcOut)},
handlers: make(map[string]Handler),
wg: new(sync.WaitGroup),
stop: make(chan struct{}),
PrimaryIP: DefaultIP,
}
s.RegisterHandler("reset", s.Reset)
s.RegisterHandler("ping", s.Ping)
s.RegisterHandler("Set_Option", s.SetOption)
s.RegisterHandler("Capabilities_Register", s.CapabilitiesRegister)
s.Command = registerCommandServer(s)
s.Command.FileServer = hgfs.NewServer()
s.Command.FileServer.RegisterFileHandler("proc", s.Command.ProcessManager)
s.Command.FileServer.RegisterFileHandler(hgfs.ArchiveScheme, hgfs.NewArchiveHandler())
s.Power = registerPowerCommandHandler(s)
return s
}
|
go
|
func NewService(rpcIn Channel, rpcOut Channel) *Service {
s := &Service{
name: "toolbox", // Same name used by vmtoolsd
in: NewTraceChannel(rpcIn),
out: &ChannelOut{NewTraceChannel(rpcOut)},
handlers: make(map[string]Handler),
wg: new(sync.WaitGroup),
stop: make(chan struct{}),
PrimaryIP: DefaultIP,
}
s.RegisterHandler("reset", s.Reset)
s.RegisterHandler("ping", s.Ping)
s.RegisterHandler("Set_Option", s.SetOption)
s.RegisterHandler("Capabilities_Register", s.CapabilitiesRegister)
s.Command = registerCommandServer(s)
s.Command.FileServer = hgfs.NewServer()
s.Command.FileServer.RegisterFileHandler("proc", s.Command.ProcessManager)
s.Command.FileServer.RegisterFileHandler(hgfs.ArchiveScheme, hgfs.NewArchiveHandler())
s.Power = registerPowerCommandHandler(s)
return s
}
|
[
"func",
"NewService",
"(",
"rpcIn",
"Channel",
",",
"rpcOut",
"Channel",
")",
"*",
"Service",
"{",
"s",
":=",
"&",
"Service",
"{",
"name",
":",
"\"",
"\"",
",",
"// Same name used by vmtoolsd",
"in",
":",
"NewTraceChannel",
"(",
"rpcIn",
")",
",",
"out",
":",
"&",
"ChannelOut",
"{",
"NewTraceChannel",
"(",
"rpcOut",
")",
"}",
",",
"handlers",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"Handler",
")",
",",
"wg",
":",
"new",
"(",
"sync",
".",
"WaitGroup",
")",
",",
"stop",
":",
"make",
"(",
"chan",
"struct",
"{",
"}",
")",
",",
"PrimaryIP",
":",
"DefaultIP",
",",
"}",
"\n\n",
"s",
".",
"RegisterHandler",
"(",
"\"",
"\"",
",",
"s",
".",
"Reset",
")",
"\n",
"s",
".",
"RegisterHandler",
"(",
"\"",
"\"",
",",
"s",
".",
"Ping",
")",
"\n",
"s",
".",
"RegisterHandler",
"(",
"\"",
"\"",
",",
"s",
".",
"SetOption",
")",
"\n",
"s",
".",
"RegisterHandler",
"(",
"\"",
"\"",
",",
"s",
".",
"CapabilitiesRegister",
")",
"\n\n",
"s",
".",
"Command",
"=",
"registerCommandServer",
"(",
"s",
")",
"\n",
"s",
".",
"Command",
".",
"FileServer",
"=",
"hgfs",
".",
"NewServer",
"(",
")",
"\n",
"s",
".",
"Command",
".",
"FileServer",
".",
"RegisterFileHandler",
"(",
"\"",
"\"",
",",
"s",
".",
"Command",
".",
"ProcessManager",
")",
"\n",
"s",
".",
"Command",
".",
"FileServer",
".",
"RegisterFileHandler",
"(",
"hgfs",
".",
"ArchiveScheme",
",",
"hgfs",
".",
"NewArchiveHandler",
"(",
")",
")",
"\n\n",
"s",
".",
"Power",
"=",
"registerPowerCommandHandler",
"(",
"s",
")",
"\n\n",
"return",
"s",
"\n",
"}"
] |
// NewService initializes a Service instance
|
[
"NewService",
"initializes",
"a",
"Service",
"instance"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/service.go#L75-L100
|
21,544
|
vmware/govmomi
|
toolbox/service.go
|
backoff
|
func (s *Service) backoff() {
if s.delay < maxDelay {
if s.delay > 0 {
d := s.delay * 2
if d > s.delay && d < maxDelay {
s.delay = d
} else {
s.delay = maxDelay
}
} else {
s.delay = 1
}
}
}
|
go
|
func (s *Service) backoff() {
if s.delay < maxDelay {
if s.delay > 0 {
d := s.delay * 2
if d > s.delay && d < maxDelay {
s.delay = d
} else {
s.delay = maxDelay
}
} else {
s.delay = 1
}
}
}
|
[
"func",
"(",
"s",
"*",
"Service",
")",
"backoff",
"(",
")",
"{",
"if",
"s",
".",
"delay",
"<",
"maxDelay",
"{",
"if",
"s",
".",
"delay",
">",
"0",
"{",
"d",
":=",
"s",
".",
"delay",
"*",
"2",
"\n",
"if",
"d",
">",
"s",
".",
"delay",
"&&",
"d",
"<",
"maxDelay",
"{",
"s",
".",
"delay",
"=",
"d",
"\n",
"}",
"else",
"{",
"s",
".",
"delay",
"=",
"maxDelay",
"\n",
"}",
"\n",
"}",
"else",
"{",
"s",
".",
"delay",
"=",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// backoff exponentially increases the RPC poll delay up to maxDelay
|
[
"backoff",
"exponentially",
"increases",
"the",
"RPC",
"poll",
"delay",
"up",
"to",
"maxDelay"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/service.go#L103-L116
|
21,545
|
vmware/govmomi
|
toolbox/service.go
|
Start
|
func (s *Service) Start() error {
err := s.startChannel()
if err != nil {
return err
}
s.wg.Add(1)
go func() {
defer s.wg.Done()
// Same polling interval and backoff logic as vmtoolsd.
// Required in our case at startup at least, otherwise it is possible
// we miss the 1 Capabilities_Register call for example.
// Note we Send(response) even when nil, to let the VMX know we are here
var response []byte
for {
select {
case <-s.stop:
s.stopChannel()
return
case <-time.After(time.Millisecond * 10 * s.delay):
if err = s.checkReset(); err != nil {
continue
}
err = s.in.Send(response)
response = nil
if err != nil {
s.delay = resetDelay
s.rpcError = true
continue
}
request, _ := s.in.Receive()
if len(request) > 0 {
response = s.Dispatch(request)
s.delay = 0
} else {
s.backoff()
}
}
}
}()
return nil
}
|
go
|
func (s *Service) Start() error {
err := s.startChannel()
if err != nil {
return err
}
s.wg.Add(1)
go func() {
defer s.wg.Done()
// Same polling interval and backoff logic as vmtoolsd.
// Required in our case at startup at least, otherwise it is possible
// we miss the 1 Capabilities_Register call for example.
// Note we Send(response) even when nil, to let the VMX know we are here
var response []byte
for {
select {
case <-s.stop:
s.stopChannel()
return
case <-time.After(time.Millisecond * 10 * s.delay):
if err = s.checkReset(); err != nil {
continue
}
err = s.in.Send(response)
response = nil
if err != nil {
s.delay = resetDelay
s.rpcError = true
continue
}
request, _ := s.in.Receive()
if len(request) > 0 {
response = s.Dispatch(request)
s.delay = 0
} else {
s.backoff()
}
}
}
}()
return nil
}
|
[
"func",
"(",
"s",
"*",
"Service",
")",
"Start",
"(",
")",
"error",
"{",
"err",
":=",
"s",
".",
"startChannel",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"s",
".",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"s",
".",
"wg",
".",
"Done",
"(",
")",
"\n\n",
"// Same polling interval and backoff logic as vmtoolsd.",
"// Required in our case at startup at least, otherwise it is possible",
"// we miss the 1 Capabilities_Register call for example.",
"// Note we Send(response) even when nil, to let the VMX know we are here",
"var",
"response",
"[",
"]",
"byte",
"\n\n",
"for",
"{",
"select",
"{",
"case",
"<-",
"s",
".",
"stop",
":",
"s",
".",
"stopChannel",
"(",
")",
"\n",
"return",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"time",
".",
"Millisecond",
"*",
"10",
"*",
"s",
".",
"delay",
")",
":",
"if",
"err",
"=",
"s",
".",
"checkReset",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"err",
"=",
"s",
".",
"in",
".",
"Send",
"(",
"response",
")",
"\n",
"response",
"=",
"nil",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
".",
"delay",
"=",
"resetDelay",
"\n",
"s",
".",
"rpcError",
"=",
"true",
"\n",
"continue",
"\n",
"}",
"\n\n",
"request",
",",
"_",
":=",
"s",
".",
"in",
".",
"Receive",
"(",
")",
"\n\n",
"if",
"len",
"(",
"request",
")",
">",
"0",
"{",
"response",
"=",
"s",
".",
"Dispatch",
"(",
"request",
")",
"\n\n",
"s",
".",
"delay",
"=",
"0",
"\n",
"}",
"else",
"{",
"s",
".",
"backoff",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Start initializes the RPC channels and starts a goroutine to listen for incoming RPC requests
|
[
"Start",
"initializes",
"the",
"RPC",
"channels",
"and",
"starts",
"a",
"goroutine",
"to",
"listen",
"for",
"incoming",
"RPC",
"requests"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/service.go#L147-L196
|
21,546
|
vmware/govmomi
|
toolbox/service.go
|
RegisterHandler
|
func (s *Service) RegisterHandler(name string, handler Handler) {
s.handlers[name] = handler
}
|
go
|
func (s *Service) RegisterHandler(name string, handler Handler) {
s.handlers[name] = handler
}
|
[
"func",
"(",
"s",
"*",
"Service",
")",
"RegisterHandler",
"(",
"name",
"string",
",",
"handler",
"Handler",
")",
"{",
"s",
".",
"handlers",
"[",
"name",
"]",
"=",
"handler",
"\n",
"}"
] |
// RegisterHandler for the given RPC name
|
[
"RegisterHandler",
"for",
"the",
"given",
"RPC",
"name"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/service.go#L212-L214
|
21,547
|
vmware/govmomi
|
toolbox/service.go
|
Dispatch
|
func (s *Service) Dispatch(request []byte) []byte {
msg := bytes.SplitN(request, []byte{' '}, 2)
name := msg[0]
// Trim NULL byte terminator
name = bytes.TrimRight(name, "\x00")
handler, ok := s.handlers[string(name)]
if !ok {
log.Printf("unknown command: %q\n", name)
return []byte("Unknown Command")
}
var args []byte
if len(msg) == 2 {
args = msg[1]
}
response, err := handler(args)
if err == nil {
response = append([]byte("OK "), response...)
} else {
log.Printf("error calling %s: %s\n", name, err)
response = append([]byte("ERR "), response...)
}
return response
}
|
go
|
func (s *Service) Dispatch(request []byte) []byte {
msg := bytes.SplitN(request, []byte{' '}, 2)
name := msg[0]
// Trim NULL byte terminator
name = bytes.TrimRight(name, "\x00")
handler, ok := s.handlers[string(name)]
if !ok {
log.Printf("unknown command: %q\n", name)
return []byte("Unknown Command")
}
var args []byte
if len(msg) == 2 {
args = msg[1]
}
response, err := handler(args)
if err == nil {
response = append([]byte("OK "), response...)
} else {
log.Printf("error calling %s: %s\n", name, err)
response = append([]byte("ERR "), response...)
}
return response
}
|
[
"func",
"(",
"s",
"*",
"Service",
")",
"Dispatch",
"(",
"request",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"msg",
":=",
"bytes",
".",
"SplitN",
"(",
"request",
",",
"[",
"]",
"byte",
"{",
"' '",
"}",
",",
"2",
")",
"\n",
"name",
":=",
"msg",
"[",
"0",
"]",
"\n\n",
"// Trim NULL byte terminator",
"name",
"=",
"bytes",
".",
"TrimRight",
"(",
"name",
",",
"\"",
"\\x00",
"\"",
")",
"\n\n",
"handler",
",",
"ok",
":=",
"s",
".",
"handlers",
"[",
"string",
"(",
"name",
")",
"]",
"\n\n",
"if",
"!",
"ok",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"name",
")",
"\n",
"return",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"args",
"[",
"]",
"byte",
"\n",
"if",
"len",
"(",
"msg",
")",
"==",
"2",
"{",
"args",
"=",
"msg",
"[",
"1",
"]",
"\n",
"}",
"\n\n",
"response",
",",
"err",
":=",
"handler",
"(",
"args",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"response",
"=",
"append",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
",",
"response",
"...",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"name",
",",
"err",
")",
"\n",
"response",
"=",
"append",
"(",
"[",
"]",
"byte",
"(",
"\"",
"\"",
")",
",",
"response",
"...",
")",
"\n",
"}",
"\n\n",
"return",
"response",
"\n",
"}"
] |
// Dispatch an incoming RPC request to a Handler
|
[
"Dispatch",
"an",
"incoming",
"RPC",
"request",
"to",
"a",
"Handler"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/service.go#L217-L245
|
21,548
|
vmware/govmomi
|
toolbox/service.go
|
Reset
|
func (s *Service) Reset([]byte) ([]byte, error) {
s.SendGuestInfo() // Send the IP info ASAP
return []byte("ATR " + s.name), nil
}
|
go
|
func (s *Service) Reset([]byte) ([]byte, error) {
s.SendGuestInfo() // Send the IP info ASAP
return []byte("ATR " + s.name), nil
}
|
[
"func",
"(",
"s",
"*",
"Service",
")",
"Reset",
"(",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"s",
".",
"SendGuestInfo",
"(",
")",
"// Send the IP info ASAP",
"\n\n",
"return",
"[",
"]",
"byte",
"(",
"\"",
"\"",
"+",
"s",
".",
"name",
")",
",",
"nil",
"\n",
"}"
] |
// Reset is the default Handler for reset requests
|
[
"Reset",
"is",
"the",
"default",
"Handler",
"for",
"reset",
"requests"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/service.go#L248-L252
|
21,549
|
vmware/govmomi
|
toolbox/service.go
|
SetOption
|
func (s *Service) SetOption(args []byte) ([]byte, error) {
opts := bytes.SplitN(args, []byte{' '}, 2)
key := string(opts[0])
val := string(opts[1])
if Trace {
fmt.Fprintf(os.Stderr, "set option %q=%q\n", key, val)
}
switch key {
case "broadcastIP": // TODO: const-ify
if val == "1" {
ip := s.PrimaryIP()
if ip == "" {
log.Printf("failed to find primary IP")
return nil, nil
}
msg := fmt.Sprintf("info-set guestinfo.ip %s", ip)
_, err := s.out.Request([]byte(msg))
if err != nil {
return nil, err
}
s.SendGuestInfo()
}
default:
// TODO: handle other options...
}
return nil, nil
}
|
go
|
func (s *Service) SetOption(args []byte) ([]byte, error) {
opts := bytes.SplitN(args, []byte{' '}, 2)
key := string(opts[0])
val := string(opts[1])
if Trace {
fmt.Fprintf(os.Stderr, "set option %q=%q\n", key, val)
}
switch key {
case "broadcastIP": // TODO: const-ify
if val == "1" {
ip := s.PrimaryIP()
if ip == "" {
log.Printf("failed to find primary IP")
return nil, nil
}
msg := fmt.Sprintf("info-set guestinfo.ip %s", ip)
_, err := s.out.Request([]byte(msg))
if err != nil {
return nil, err
}
s.SendGuestInfo()
}
default:
// TODO: handle other options...
}
return nil, nil
}
|
[
"func",
"(",
"s",
"*",
"Service",
")",
"SetOption",
"(",
"args",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"opts",
":=",
"bytes",
".",
"SplitN",
"(",
"args",
",",
"[",
"]",
"byte",
"{",
"' '",
"}",
",",
"2",
")",
"\n",
"key",
":=",
"string",
"(",
"opts",
"[",
"0",
"]",
")",
"\n",
"val",
":=",
"string",
"(",
"opts",
"[",
"1",
"]",
")",
"\n\n",
"if",
"Trace",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"key",
",",
"val",
")",
"\n",
"}",
"\n\n",
"switch",
"key",
"{",
"case",
"\"",
"\"",
":",
"// TODO: const-ify",
"if",
"val",
"==",
"\"",
"\"",
"{",
"ip",
":=",
"s",
".",
"PrimaryIP",
"(",
")",
"\n",
"if",
"ip",
"==",
"\"",
"\"",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ip",
")",
"\n",
"_",
",",
"err",
":=",
"s",
".",
"out",
".",
"Request",
"(",
"[",
"]",
"byte",
"(",
"msg",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"s",
".",
"SendGuestInfo",
"(",
")",
"\n",
"}",
"\n",
"default",
":",
"// TODO: handle other options...",
"}",
"\n\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// SetOption is the default Handler for Set_Option requests
|
[
"SetOption",
"is",
"the",
"default",
"Handler",
"for",
"Set_Option",
"requests"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/service.go#L260-L290
|
21,550
|
vmware/govmomi
|
toolbox/service.go
|
DefaultIP
|
func DefaultIP() string {
addrs, err := netInterfaceAddrs()
if err == nil {
for _, addr := range addrs {
if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() {
if ip.IP.To4() != nil {
return ip.IP.String()
}
}
}
}
return ""
}
|
go
|
func DefaultIP() string {
addrs, err := netInterfaceAddrs()
if err == nil {
for _, addr := range addrs {
if ip, ok := addr.(*net.IPNet); ok && !ip.IP.IsLoopback() {
if ip.IP.To4() != nil {
return ip.IP.String()
}
}
}
}
return ""
}
|
[
"func",
"DefaultIP",
"(",
")",
"string",
"{",
"addrs",
",",
"err",
":=",
"netInterfaceAddrs",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{",
"if",
"ip",
",",
"ok",
":=",
"addr",
".",
"(",
"*",
"net",
".",
"IPNet",
")",
";",
"ok",
"&&",
"!",
"ip",
".",
"IP",
".",
"IsLoopback",
"(",
")",
"{",
"if",
"ip",
".",
"IP",
".",
"To4",
"(",
")",
"!=",
"nil",
"{",
"return",
"ip",
".",
"IP",
".",
"String",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
"\n",
"}"
] |
// DefaultIP is used by default when responding to a Set_Option broadcastIP request
// It can be overridden with the Service.PrimaryIP field
|
[
"DefaultIP",
"is",
"used",
"by",
"default",
"when",
"responding",
"to",
"a",
"Set_Option",
"broadcastIP",
"request",
"It",
"can",
"be",
"overridden",
"with",
"the",
"Service",
".",
"PrimaryIP",
"field"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/service.go#L294-L307
|
21,551
|
vmware/govmomi
|
object/namespace_manager.go
|
CreateDirectory
|
func (nm DatastoreNamespaceManager) CreateDirectory(ctx context.Context, ds *Datastore, displayName string, policy string) (string, error) {
req := &types.CreateDirectory{
This: nm.Reference(),
Datastore: ds.Reference(),
DisplayName: displayName,
Policy: policy,
}
resp, err := methods.CreateDirectory(ctx, nm.c, req)
if err != nil {
return "", err
}
return resp.Returnval, nil
}
|
go
|
func (nm DatastoreNamespaceManager) CreateDirectory(ctx context.Context, ds *Datastore, displayName string, policy string) (string, error) {
req := &types.CreateDirectory{
This: nm.Reference(),
Datastore: ds.Reference(),
DisplayName: displayName,
Policy: policy,
}
resp, err := methods.CreateDirectory(ctx, nm.c, req)
if err != nil {
return "", err
}
return resp.Returnval, nil
}
|
[
"func",
"(",
"nm",
"DatastoreNamespaceManager",
")",
"CreateDirectory",
"(",
"ctx",
"context",
".",
"Context",
",",
"ds",
"*",
"Datastore",
",",
"displayName",
"string",
",",
"policy",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"req",
":=",
"&",
"types",
".",
"CreateDirectory",
"{",
"This",
":",
"nm",
".",
"Reference",
"(",
")",
",",
"Datastore",
":",
"ds",
".",
"Reference",
"(",
")",
",",
"DisplayName",
":",
"displayName",
",",
"Policy",
":",
"policy",
",",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"methods",
".",
"CreateDirectory",
"(",
"ctx",
",",
"nm",
".",
"c",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"resp",
".",
"Returnval",
",",
"nil",
"\n",
"}"
] |
// CreateDirectory creates a top-level directory on the given vsan datastore, using
// the given user display name hint and opaque storage policy.
|
[
"CreateDirectory",
"creates",
"a",
"top",
"-",
"level",
"directory",
"on",
"the",
"given",
"vsan",
"datastore",
"using",
"the",
"given",
"user",
"display",
"name",
"hint",
"and",
"opaque",
"storage",
"policy",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/namespace_manager.go#L41-L56
|
21,552
|
vmware/govmomi
|
object/namespace_manager.go
|
DeleteDirectory
|
func (nm DatastoreNamespaceManager) DeleteDirectory(ctx context.Context, dc *Datacenter, datastorePath string) error {
req := &types.DeleteDirectory{
This: nm.Reference(),
DatastorePath: datastorePath,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
if _, err := methods.DeleteDirectory(ctx, nm.c, req); err != nil {
return err
}
return nil
}
|
go
|
func (nm DatastoreNamespaceManager) DeleteDirectory(ctx context.Context, dc *Datacenter, datastorePath string) error {
req := &types.DeleteDirectory{
This: nm.Reference(),
DatastorePath: datastorePath,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
if _, err := methods.DeleteDirectory(ctx, nm.c, req); err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"nm",
"DatastoreNamespaceManager",
")",
"DeleteDirectory",
"(",
"ctx",
"context",
".",
"Context",
",",
"dc",
"*",
"Datacenter",
",",
"datastorePath",
"string",
")",
"error",
"{",
"req",
":=",
"&",
"types",
".",
"DeleteDirectory",
"{",
"This",
":",
"nm",
".",
"Reference",
"(",
")",
",",
"DatastorePath",
":",
"datastorePath",
",",
"}",
"\n\n",
"if",
"dc",
"!=",
"nil",
"{",
"ref",
":=",
"dc",
".",
"Reference",
"(",
")",
"\n",
"req",
".",
"Datacenter",
"=",
"&",
"ref",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"methods",
".",
"DeleteDirectory",
"(",
"ctx",
",",
"nm",
".",
"c",
",",
"req",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// DeleteDirectory deletes the given top-level directory from a vsan datastore.
|
[
"DeleteDirectory",
"deletes",
"the",
"given",
"top",
"-",
"level",
"directory",
"from",
"a",
"vsan",
"datastore",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/namespace_manager.go#L59-L76
|
21,553
|
vmware/govmomi
|
performance/manager.go
|
NewManager
|
func NewManager(client *vim25.Client) *Manager {
m := Manager{
Common: object.NewCommon(client, *client.ServiceContent.PerfManager),
}
m.pm.PerformanceManager = new(mo.PerformanceManager)
return &m
}
|
go
|
func NewManager(client *vim25.Client) *Manager {
m := Manager{
Common: object.NewCommon(client, *client.ServiceContent.PerfManager),
}
m.pm.PerformanceManager = new(mo.PerformanceManager)
return &m
}
|
[
"func",
"NewManager",
"(",
"client",
"*",
"vim25",
".",
"Client",
")",
"*",
"Manager",
"{",
"m",
":=",
"Manager",
"{",
"Common",
":",
"object",
".",
"NewCommon",
"(",
"client",
",",
"*",
"client",
".",
"ServiceContent",
".",
"PerfManager",
")",
",",
"}",
"\n\n",
"m",
".",
"pm",
".",
"PerformanceManager",
"=",
"new",
"(",
"mo",
".",
"PerformanceManager",
")",
"\n\n",
"return",
"&",
"m",
"\n",
"}"
] |
// NewManager creates a new Manager instance.
|
[
"NewManager",
"creates",
"a",
"new",
"Manager",
"instance",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L58-L66
|
21,554
|
vmware/govmomi
|
performance/manager.go
|
HistoricalInterval
|
func (m *Manager) HistoricalInterval(ctx context.Context) (IntervalList, error) {
var pm mo.PerformanceManager
err := m.Properties(ctx, m.Reference(), []string{"historicalInterval"}, &pm)
if err != nil {
return nil, err
}
return IntervalList(pm.HistoricalInterval), nil
}
|
go
|
func (m *Manager) HistoricalInterval(ctx context.Context) (IntervalList, error) {
var pm mo.PerformanceManager
err := m.Properties(ctx, m.Reference(), []string{"historicalInterval"}, &pm)
if err != nil {
return nil, err
}
return IntervalList(pm.HistoricalInterval), nil
}
|
[
"func",
"(",
"m",
"*",
"Manager",
")",
"HistoricalInterval",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"IntervalList",
",",
"error",
")",
"{",
"var",
"pm",
"mo",
".",
"PerformanceManager",
"\n\n",
"err",
":=",
"m",
".",
"Properties",
"(",
"ctx",
",",
"m",
".",
"Reference",
"(",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"&",
"pm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"IntervalList",
"(",
"pm",
".",
"HistoricalInterval",
")",
",",
"nil",
"\n",
"}"
] |
// HistoricalInterval gets the PerformanceManager.HistoricalInterval property and wraps as an IntervalList.
|
[
"HistoricalInterval",
"gets",
"the",
"PerformanceManager",
".",
"HistoricalInterval",
"property",
"and",
"wraps",
"as",
"an",
"IntervalList",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L91-L100
|
21,555
|
vmware/govmomi
|
performance/manager.go
|
CounterInfo
|
func (m *Manager) CounterInfo(ctx context.Context) ([]types.PerfCounterInfo, error) {
m.pm.Lock()
defer m.pm.Unlock()
if len(m.pm.PerfCounter) == 0 {
err := m.Properties(ctx, m.Reference(), []string{"perfCounter"}, m.pm.PerformanceManager)
if err != nil {
return nil, err
}
}
return m.pm.PerfCounter, nil
}
|
go
|
func (m *Manager) CounterInfo(ctx context.Context) ([]types.PerfCounterInfo, error) {
m.pm.Lock()
defer m.pm.Unlock()
if len(m.pm.PerfCounter) == 0 {
err := m.Properties(ctx, m.Reference(), []string{"perfCounter"}, m.pm.PerformanceManager)
if err != nil {
return nil, err
}
}
return m.pm.PerfCounter, nil
}
|
[
"func",
"(",
"m",
"*",
"Manager",
")",
"CounterInfo",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"types",
".",
"PerfCounterInfo",
",",
"error",
")",
"{",
"m",
".",
"pm",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"pm",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"len",
"(",
"m",
".",
"pm",
".",
"PerfCounter",
")",
"==",
"0",
"{",
"err",
":=",
"m",
".",
"Properties",
"(",
"ctx",
",",
"m",
".",
"Reference",
"(",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"m",
".",
"pm",
".",
"PerformanceManager",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"m",
".",
"pm",
".",
"PerfCounter",
",",
"nil",
"\n",
"}"
] |
// CounterInfo gets the PerformanceManager.PerfCounter property.
// The property value is only collected once, subsequent calls return the cached value.
|
[
"CounterInfo",
"gets",
"the",
"PerformanceManager",
".",
"PerfCounter",
"property",
".",
"The",
"property",
"value",
"is",
"only",
"collected",
"once",
"subsequent",
"calls",
"return",
"the",
"cached",
"value",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L104-L116
|
21,556
|
vmware/govmomi
|
performance/manager.go
|
CounterInfoByKey
|
func (m *Manager) CounterInfoByKey(ctx context.Context) (map[int32]*types.PerfCounterInfo, error) {
m.infoByKey.Lock()
defer m.infoByKey.Unlock()
if m.infoByKey.m != nil {
return m.infoByKey.m, nil
}
info, err := m.CounterInfo(ctx)
if err != nil {
return nil, err
}
m.infoByKey.m = make(map[int32]*types.PerfCounterInfo)
for i := range info {
c := &info[i]
m.infoByKey.m[c.Key] = c
}
return m.infoByKey.m, nil
}
|
go
|
func (m *Manager) CounterInfoByKey(ctx context.Context) (map[int32]*types.PerfCounterInfo, error) {
m.infoByKey.Lock()
defer m.infoByKey.Unlock()
if m.infoByKey.m != nil {
return m.infoByKey.m, nil
}
info, err := m.CounterInfo(ctx)
if err != nil {
return nil, err
}
m.infoByKey.m = make(map[int32]*types.PerfCounterInfo)
for i := range info {
c := &info[i]
m.infoByKey.m[c.Key] = c
}
return m.infoByKey.m, nil
}
|
[
"func",
"(",
"m",
"*",
"Manager",
")",
"CounterInfoByKey",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"map",
"[",
"int32",
"]",
"*",
"types",
".",
"PerfCounterInfo",
",",
"error",
")",
"{",
"m",
".",
"infoByKey",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"infoByKey",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"m",
".",
"infoByKey",
".",
"m",
"!=",
"nil",
"{",
"return",
"m",
".",
"infoByKey",
".",
"m",
",",
"nil",
"\n",
"}",
"\n\n",
"info",
",",
"err",
":=",
"m",
".",
"CounterInfo",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"m",
".",
"infoByKey",
".",
"m",
"=",
"make",
"(",
"map",
"[",
"int32",
"]",
"*",
"types",
".",
"PerfCounterInfo",
")",
"\n\n",
"for",
"i",
":=",
"range",
"info",
"{",
"c",
":=",
"&",
"info",
"[",
"i",
"]",
"\n\n",
"m",
".",
"infoByKey",
".",
"m",
"[",
"c",
".",
"Key",
"]",
"=",
"c",
"\n",
"}",
"\n\n",
"return",
"m",
".",
"infoByKey",
".",
"m",
",",
"nil",
"\n",
"}"
] |
// CounterInfoByKey converts the PerformanceManager.PerfCounter property to a map,
// where key is types.PerfCounterInfo.Key.
|
[
"CounterInfoByKey",
"converts",
"the",
"PerformanceManager",
".",
"PerfCounter",
"property",
"to",
"a",
"map",
"where",
"key",
"is",
"types",
".",
"PerfCounterInfo",
".",
"Key",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L146-L168
|
21,557
|
vmware/govmomi
|
performance/manager.go
|
ProviderSummary
|
func (m *Manager) ProviderSummary(ctx context.Context, entity types.ManagedObjectReference) (*types.PerfProviderSummary, error) {
req := types.QueryPerfProviderSummary{
This: m.Reference(),
Entity: entity,
}
res, err := methods.QueryPerfProviderSummary(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
return &res.Returnval, nil
}
|
go
|
func (m *Manager) ProviderSummary(ctx context.Context, entity types.ManagedObjectReference) (*types.PerfProviderSummary, error) {
req := types.QueryPerfProviderSummary{
This: m.Reference(),
Entity: entity,
}
res, err := methods.QueryPerfProviderSummary(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
return &res.Returnval, nil
}
|
[
"func",
"(",
"m",
"*",
"Manager",
")",
"ProviderSummary",
"(",
"ctx",
"context",
".",
"Context",
",",
"entity",
"types",
".",
"ManagedObjectReference",
")",
"(",
"*",
"types",
".",
"PerfProviderSummary",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"QueryPerfProviderSummary",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"Entity",
":",
"entity",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"QueryPerfProviderSummary",
"(",
"ctx",
",",
"m",
".",
"Client",
"(",
")",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"res",
".",
"Returnval",
",",
"nil",
"\n",
"}"
] |
// ProviderSummary wraps the QueryPerfProviderSummary method, caching the value based on entity.Type.
|
[
"ProviderSummary",
"wraps",
"the",
"QueryPerfProviderSummary",
"method",
"caching",
"the",
"value",
"based",
"on",
"entity",
".",
"Type",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L171-L183
|
21,558
|
vmware/govmomi
|
performance/manager.go
|
AvailableMetric
|
func (m *Manager) AvailableMetric(ctx context.Context, entity types.ManagedObjectReference, interval int32) (MetricList, error) {
req := types.QueryAvailablePerfMetric{
This: m.Reference(),
Entity: entity.Reference(),
IntervalId: interval,
}
res, err := methods.QueryAvailablePerfMetric(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
if m.Sort {
info, err := m.CounterInfoByKey(ctx)
if err != nil {
return nil, err
}
sort.Sort(groupPerfCounterInfo{info, res.Returnval})
}
return MetricList(res.Returnval), nil
}
|
go
|
func (m *Manager) AvailableMetric(ctx context.Context, entity types.ManagedObjectReference, interval int32) (MetricList, error) {
req := types.QueryAvailablePerfMetric{
This: m.Reference(),
Entity: entity.Reference(),
IntervalId: interval,
}
res, err := methods.QueryAvailablePerfMetric(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
if m.Sort {
info, err := m.CounterInfoByKey(ctx)
if err != nil {
return nil, err
}
sort.Sort(groupPerfCounterInfo{info, res.Returnval})
}
return MetricList(res.Returnval), nil
}
|
[
"func",
"(",
"m",
"*",
"Manager",
")",
"AvailableMetric",
"(",
"ctx",
"context",
".",
"Context",
",",
"entity",
"types",
".",
"ManagedObjectReference",
",",
"interval",
"int32",
")",
"(",
"MetricList",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"QueryAvailablePerfMetric",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"Entity",
":",
"entity",
".",
"Reference",
"(",
")",
",",
"IntervalId",
":",
"interval",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"QueryAvailablePerfMetric",
"(",
"ctx",
",",
"m",
".",
"Client",
"(",
")",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"m",
".",
"Sort",
"{",
"info",
",",
"err",
":=",
"m",
".",
"CounterInfoByKey",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"sort",
".",
"Sort",
"(",
"groupPerfCounterInfo",
"{",
"info",
",",
"res",
".",
"Returnval",
"}",
")",
"\n",
"}",
"\n\n",
"return",
"MetricList",
"(",
"res",
".",
"Returnval",
")",
",",
"nil",
"\n",
"}"
] |
// AvailableMetric wraps the QueryAvailablePerfMetric method.
// The MetricList is sorted by PerfCounterInfo.GroupInfo.Key if Manager.Sort == true.
|
[
"AvailableMetric",
"wraps",
"the",
"QueryAvailablePerfMetric",
"method",
".",
"The",
"MetricList",
"is",
"sorted",
"by",
"PerfCounterInfo",
".",
"GroupInfo",
".",
"Key",
"if",
"Manager",
".",
"Sort",
"==",
"true",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L224-L246
|
21,559
|
vmware/govmomi
|
performance/manager.go
|
Query
|
func (m *Manager) Query(ctx context.Context, spec []types.PerfQuerySpec) ([]types.BasePerfEntityMetricBase, error) {
req := types.QueryPerf{
This: m.Reference(),
QuerySpec: spec,
}
res, err := methods.QueryPerf(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
return res.Returnval, nil
}
|
go
|
func (m *Manager) Query(ctx context.Context, spec []types.PerfQuerySpec) ([]types.BasePerfEntityMetricBase, error) {
req := types.QueryPerf{
This: m.Reference(),
QuerySpec: spec,
}
res, err := methods.QueryPerf(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
return res.Returnval, nil
}
|
[
"func",
"(",
"m",
"*",
"Manager",
")",
"Query",
"(",
"ctx",
"context",
".",
"Context",
",",
"spec",
"[",
"]",
"types",
".",
"PerfQuerySpec",
")",
"(",
"[",
"]",
"types",
".",
"BasePerfEntityMetricBase",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"QueryPerf",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"QuerySpec",
":",
"spec",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"QueryPerf",
"(",
"ctx",
",",
"m",
".",
"Client",
"(",
")",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"res",
".",
"Returnval",
",",
"nil",
"\n",
"}"
] |
// Query wraps the QueryPerf method.
|
[
"Query",
"wraps",
"the",
"QueryPerf",
"method",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L249-L261
|
21,560
|
vmware/govmomi
|
performance/manager.go
|
ValueCSV
|
func (s *MetricSeries) ValueCSV() string {
vals := make([]string, len(s.Value))
for i := range s.Value {
vals[i] = s.Format(s.Value[i])
}
return strings.Join(vals, ",")
}
|
go
|
func (s *MetricSeries) ValueCSV() string {
vals := make([]string, len(s.Value))
for i := range s.Value {
vals[i] = s.Format(s.Value[i])
}
return strings.Join(vals, ",")
}
|
[
"func",
"(",
"s",
"*",
"MetricSeries",
")",
"ValueCSV",
"(",
")",
"string",
"{",
"vals",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"s",
".",
"Value",
")",
")",
"\n\n",
"for",
"i",
":=",
"range",
"s",
".",
"Value",
"{",
"vals",
"[",
"i",
"]",
"=",
"s",
".",
"Format",
"(",
"s",
".",
"Value",
"[",
"i",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"vals",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// ValueCSV converts the Value field to a CSV string
|
[
"ValueCSV",
"converts",
"the",
"Value",
"field",
"to",
"a",
"CSV",
"string"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L341-L349
|
21,561
|
vmware/govmomi
|
performance/manager.go
|
SampleInfoCSV
|
func (m *EntityMetric) SampleInfoCSV() string {
vals := make([]string, len(m.SampleInfo)*2)
i := 0
for _, s := range m.SampleInfo {
vals[i] = s.Timestamp.Format(time.RFC3339)
i++
vals[i] = strconv.Itoa(int(s.Interval))
i++
}
return strings.Join(vals, ",")
}
|
go
|
func (m *EntityMetric) SampleInfoCSV() string {
vals := make([]string, len(m.SampleInfo)*2)
i := 0
for _, s := range m.SampleInfo {
vals[i] = s.Timestamp.Format(time.RFC3339)
i++
vals[i] = strconv.Itoa(int(s.Interval))
i++
}
return strings.Join(vals, ",")
}
|
[
"func",
"(",
"m",
"*",
"EntityMetric",
")",
"SampleInfoCSV",
"(",
")",
"string",
"{",
"vals",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"m",
".",
"SampleInfo",
")",
"*",
"2",
")",
"\n\n",
"i",
":=",
"0",
"\n\n",
"for",
"_",
",",
"s",
":=",
"range",
"m",
".",
"SampleInfo",
"{",
"vals",
"[",
"i",
"]",
"=",
"s",
".",
"Timestamp",
".",
"Format",
"(",
"time",
".",
"RFC3339",
")",
"\n",
"i",
"++",
"\n",
"vals",
"[",
"i",
"]",
"=",
"strconv",
".",
"Itoa",
"(",
"int",
"(",
"s",
".",
"Interval",
")",
")",
"\n",
"i",
"++",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"vals",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// SampleInfoCSV converts the SampleInfo field to a CSV string
|
[
"SampleInfoCSV",
"converts",
"the",
"SampleInfo",
"field",
"to",
"a",
"CSV",
"string"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/performance/manager.go#L360-L373
|
21,562
|
vmware/govmomi
|
govc/flags/host_connect.go
|
Spec
|
func (flag *HostConnectFlag) Spec(c *vim25.Client) types.HostConnectSpec {
spec := flag.HostConnectSpec
if spec.SslThumbprint == "" {
spec.SslThumbprint = c.Thumbprint(spec.HostName)
if spec.SslThumbprint == "" && flag.noverify {
var info object.HostCertificateInfo
t := c.Transport.(*http.Transport)
_ = info.FromURL(&url.URL{Host: spec.HostName}, t.TLSClientConfig)
spec.SslThumbprint = info.ThumbprintSHA1
}
}
return spec
}
|
go
|
func (flag *HostConnectFlag) Spec(c *vim25.Client) types.HostConnectSpec {
spec := flag.HostConnectSpec
if spec.SslThumbprint == "" {
spec.SslThumbprint = c.Thumbprint(spec.HostName)
if spec.SslThumbprint == "" && flag.noverify {
var info object.HostCertificateInfo
t := c.Transport.(*http.Transport)
_ = info.FromURL(&url.URL{Host: spec.HostName}, t.TLSClientConfig)
spec.SslThumbprint = info.ThumbprintSHA1
}
}
return spec
}
|
[
"func",
"(",
"flag",
"*",
"HostConnectFlag",
")",
"Spec",
"(",
"c",
"*",
"vim25",
".",
"Client",
")",
"types",
".",
"HostConnectSpec",
"{",
"spec",
":=",
"flag",
".",
"HostConnectSpec",
"\n\n",
"if",
"spec",
".",
"SslThumbprint",
"==",
"\"",
"\"",
"{",
"spec",
".",
"SslThumbprint",
"=",
"c",
".",
"Thumbprint",
"(",
"spec",
".",
"HostName",
")",
"\n\n",
"if",
"spec",
".",
"SslThumbprint",
"==",
"\"",
"\"",
"&&",
"flag",
".",
"noverify",
"{",
"var",
"info",
"object",
".",
"HostCertificateInfo",
"\n",
"t",
":=",
"c",
".",
"Transport",
".",
"(",
"*",
"http",
".",
"Transport",
")",
"\n",
"_",
"=",
"info",
".",
"FromURL",
"(",
"&",
"url",
".",
"URL",
"{",
"Host",
":",
"spec",
".",
"HostName",
"}",
",",
"t",
".",
"TLSClientConfig",
")",
"\n",
"spec",
".",
"SslThumbprint",
"=",
"info",
".",
"ThumbprintSHA1",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"spec",
"\n",
"}"
] |
// Spec attempts to fill in SslThumbprint if empty.
// First checks GOVC_TLS_KNOWN_HOSTS, if not found and noverify=true then
// use object.HostCertificateInfo to get the thumbprint.
|
[
"Spec",
"attempts",
"to",
"fill",
"in",
"SslThumbprint",
"if",
"empty",
".",
"First",
"checks",
"GOVC_TLS_KNOWN_HOSTS",
"if",
"not",
"found",
"and",
"noverify",
"=",
"true",
"then",
"use",
"object",
".",
"HostCertificateInfo",
"to",
"get",
"the",
"thumbprint",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/host_connect.go#L70-L85
|
21,563
|
vmware/govmomi
|
govc/flags/host_connect.go
|
Fault
|
func (flag *HostConnectFlag) Fault(err error) error {
if err == nil {
return nil
}
if f, ok := err.(types.HasFault); ok {
switch fault := f.Fault().(type) {
case *types.SSLVerifyFault:
return fmt.Errorf("%s thumbprint=%s", err, fault.Thumbprint)
}
}
return err
}
|
go
|
func (flag *HostConnectFlag) Fault(err error) error {
if err == nil {
return nil
}
if f, ok := err.(types.HasFault); ok {
switch fault := f.Fault().(type) {
case *types.SSLVerifyFault:
return fmt.Errorf("%s thumbprint=%s", err, fault.Thumbprint)
}
}
return err
}
|
[
"func",
"(",
"flag",
"*",
"HostConnectFlag",
")",
"Fault",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"f",
",",
"ok",
":=",
"err",
".",
"(",
"types",
".",
"HasFault",
")",
";",
"ok",
"{",
"switch",
"fault",
":=",
"f",
".",
"Fault",
"(",
")",
".",
"(",
"type",
")",
"{",
"case",
"*",
"types",
".",
"SSLVerifyFault",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"fault",
".",
"Thumbprint",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// Fault checks if error is SSLVerifyFault, including the thumbprint if so
|
[
"Fault",
"checks",
"if",
"error",
"is",
"SSLVerifyFault",
"including",
"the",
"thumbprint",
"if",
"so"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/govc/flags/host_connect.go#L88-L101
|
21,564
|
vmware/govmomi
|
guest/toolbox/client.go
|
Run
|
func (c *Client) Run(ctx context.Context, cmd *exec.Cmd) error {
vc := c.ProcessManager.Client()
spec := types.GuestProgramSpec{
ProgramPath: cmd.Path,
Arguments: strings.Join(cmd.Args, " "),
EnvVariables: cmd.Env,
WorkingDirectory: cmd.Dir,
}
pid, serr := c.ProcessManager.StartProgram(ctx, c.Authentication, &spec)
if serr != nil {
return serr
}
if cmd.Stdin != nil {
dst := fmt.Sprintf("/proc/%d/stdin", pid)
var buf bytes.Buffer
size, err := io.Copy(&buf, cmd.Stdin)
if err != nil {
return err
}
attr := new(types.GuestPosixFileAttributes)
url, err := c.FileManager.InitiateFileTransferToGuest(ctx, c.Authentication, dst, attr, size, true)
if err != nil {
return err
}
u, err := c.FileManager.TransferURL(ctx, url)
if err != nil {
return err
}
p := soap.DefaultUpload
p.ContentLength = size
err = vc.Client.Upload(ctx, &buf, u, &p)
if err != nil {
return err
}
}
names := []string{"out", "err"}
for i, w := range []io.Writer{cmd.Stdout, cmd.Stderr} {
if w == nil {
continue
}
src := fmt.Sprintf("/proc/%d/std%s", pid, names[i])
info, err := c.procReader(ctx, src)
if err != nil {
return err
}
u, err := c.FileManager.TransferURL(ctx, info.Url)
if err != nil {
return err
}
f, _, err := vc.Client.Download(ctx, u, &soap.DefaultDownload)
if err != nil {
return err
}
_, err = io.Copy(w, f)
_ = f.Close()
if err != nil {
return err
}
}
procs, err := c.ProcessManager.ListProcesses(ctx, c.Authentication, []int64{pid})
if err != nil {
return err
}
if len(procs) == 1 {
rc := procs[0].ExitCode
if rc != 0 {
return fmt.Errorf("%s: exit %d", cmd.Path, rc)
}
}
return nil
}
|
go
|
func (c *Client) Run(ctx context.Context, cmd *exec.Cmd) error {
vc := c.ProcessManager.Client()
spec := types.GuestProgramSpec{
ProgramPath: cmd.Path,
Arguments: strings.Join(cmd.Args, " "),
EnvVariables: cmd.Env,
WorkingDirectory: cmd.Dir,
}
pid, serr := c.ProcessManager.StartProgram(ctx, c.Authentication, &spec)
if serr != nil {
return serr
}
if cmd.Stdin != nil {
dst := fmt.Sprintf("/proc/%d/stdin", pid)
var buf bytes.Buffer
size, err := io.Copy(&buf, cmd.Stdin)
if err != nil {
return err
}
attr := new(types.GuestPosixFileAttributes)
url, err := c.FileManager.InitiateFileTransferToGuest(ctx, c.Authentication, dst, attr, size, true)
if err != nil {
return err
}
u, err := c.FileManager.TransferURL(ctx, url)
if err != nil {
return err
}
p := soap.DefaultUpload
p.ContentLength = size
err = vc.Client.Upload(ctx, &buf, u, &p)
if err != nil {
return err
}
}
names := []string{"out", "err"}
for i, w := range []io.Writer{cmd.Stdout, cmd.Stderr} {
if w == nil {
continue
}
src := fmt.Sprintf("/proc/%d/std%s", pid, names[i])
info, err := c.procReader(ctx, src)
if err != nil {
return err
}
u, err := c.FileManager.TransferURL(ctx, info.Url)
if err != nil {
return err
}
f, _, err := vc.Client.Download(ctx, u, &soap.DefaultDownload)
if err != nil {
return err
}
_, err = io.Copy(w, f)
_ = f.Close()
if err != nil {
return err
}
}
procs, err := c.ProcessManager.ListProcesses(ctx, c.Authentication, []int64{pid})
if err != nil {
return err
}
if len(procs) == 1 {
rc := procs[0].ExitCode
if rc != 0 {
return fmt.Errorf("%s: exit %d", cmd.Path, rc)
}
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"cmd",
"*",
"exec",
".",
"Cmd",
")",
"error",
"{",
"vc",
":=",
"c",
".",
"ProcessManager",
".",
"Client",
"(",
")",
"\n\n",
"spec",
":=",
"types",
".",
"GuestProgramSpec",
"{",
"ProgramPath",
":",
"cmd",
".",
"Path",
",",
"Arguments",
":",
"strings",
".",
"Join",
"(",
"cmd",
".",
"Args",
",",
"\"",
"\"",
")",
",",
"EnvVariables",
":",
"cmd",
".",
"Env",
",",
"WorkingDirectory",
":",
"cmd",
".",
"Dir",
",",
"}",
"\n\n",
"pid",
",",
"serr",
":=",
"c",
".",
"ProcessManager",
".",
"StartProgram",
"(",
"ctx",
",",
"c",
".",
"Authentication",
",",
"&",
"spec",
")",
"\n",
"if",
"serr",
"!=",
"nil",
"{",
"return",
"serr",
"\n",
"}",
"\n\n",
"if",
"cmd",
".",
"Stdin",
"!=",
"nil",
"{",
"dst",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
")",
"\n\n",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"size",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"&",
"buf",
",",
"cmd",
".",
"Stdin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"attr",
":=",
"new",
"(",
"types",
".",
"GuestPosixFileAttributes",
")",
"\n\n",
"url",
",",
"err",
":=",
"c",
".",
"FileManager",
".",
"InitiateFileTransferToGuest",
"(",
"ctx",
",",
"c",
".",
"Authentication",
",",
"dst",
",",
"attr",
",",
"size",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"u",
",",
"err",
":=",
"c",
".",
"FileManager",
".",
"TransferURL",
"(",
"ctx",
",",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"p",
":=",
"soap",
".",
"DefaultUpload",
"\n",
"p",
".",
"ContentLength",
"=",
"size",
"\n\n",
"err",
"=",
"vc",
".",
"Client",
".",
"Upload",
"(",
"ctx",
",",
"&",
"buf",
",",
"u",
",",
"&",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"names",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n\n",
"for",
"i",
",",
"w",
":=",
"range",
"[",
"]",
"io",
".",
"Writer",
"{",
"cmd",
".",
"Stdout",
",",
"cmd",
".",
"Stderr",
"}",
"{",
"if",
"w",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"\n\n",
"src",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pid",
",",
"names",
"[",
"i",
"]",
")",
"\n\n",
"info",
",",
"err",
":=",
"c",
".",
"procReader",
"(",
"ctx",
",",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"u",
",",
"err",
":=",
"c",
".",
"FileManager",
".",
"TransferURL",
"(",
"ctx",
",",
"info",
".",
"Url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"f",
",",
"_",
",",
"err",
":=",
"vc",
".",
"Client",
".",
"Download",
"(",
"ctx",
",",
"u",
",",
"&",
"soap",
".",
"DefaultDownload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"w",
",",
"f",
")",
"\n",
"_",
"=",
"f",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"procs",
",",
"err",
":=",
"c",
".",
"ProcessManager",
".",
"ListProcesses",
"(",
"ctx",
",",
"c",
".",
"Authentication",
",",
"[",
"]",
"int64",
"{",
"pid",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"procs",
")",
"==",
"1",
"{",
"rc",
":=",
"procs",
"[",
"0",
"]",
".",
"ExitCode",
"\n",
"if",
"rc",
"!=",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"cmd",
".",
"Path",
",",
"rc",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Run implements exec.Cmd.Run over vmx guest RPC.
|
[
"Run",
"implements",
"exec",
".",
"Cmd",
".",
"Run",
"over",
"vmx",
"guest",
"RPC",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/guest/toolbox/client.go#L141-L230
|
21,565
|
vmware/govmomi
|
guest/toolbox/client.go
|
Download
|
func (c *Client) Download(ctx context.Context, src string) (io.ReadCloser, int64, error) {
vc := c.ProcessManager.Client()
info, err := c.FileManager.InitiateFileTransferFromGuest(ctx, c.Authentication, src)
if err != nil {
return nil, 0, err
}
u, err := c.FileManager.TransferURL(ctx, info.Url)
if err != nil {
return nil, 0, err
}
p := soap.DefaultDownload
f, n, err := vc.Download(ctx, u, &p)
if err != nil {
return nil, n, err
}
if strings.HasPrefix(src, "/archive:/") || isDir(src) {
f = &archiveReader{ReadCloser: f} // look for the gzip trailer
}
return f, n, nil
}
|
go
|
func (c *Client) Download(ctx context.Context, src string) (io.ReadCloser, int64, error) {
vc := c.ProcessManager.Client()
info, err := c.FileManager.InitiateFileTransferFromGuest(ctx, c.Authentication, src)
if err != nil {
return nil, 0, err
}
u, err := c.FileManager.TransferURL(ctx, info.Url)
if err != nil {
return nil, 0, err
}
p := soap.DefaultDownload
f, n, err := vc.Download(ctx, u, &p)
if err != nil {
return nil, n, err
}
if strings.HasPrefix(src, "/archive:/") || isDir(src) {
f = &archiveReader{ReadCloser: f} // look for the gzip trailer
}
return f, n, nil
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Download",
"(",
"ctx",
"context",
".",
"Context",
",",
"src",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"int64",
",",
"error",
")",
"{",
"vc",
":=",
"c",
".",
"ProcessManager",
".",
"Client",
"(",
")",
"\n\n",
"info",
",",
"err",
":=",
"c",
".",
"FileManager",
".",
"InitiateFileTransferFromGuest",
"(",
"ctx",
",",
"c",
".",
"Authentication",
",",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"u",
",",
"err",
":=",
"c",
".",
"FileManager",
".",
"TransferURL",
"(",
"ctx",
",",
"info",
".",
"Url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"p",
":=",
"soap",
".",
"DefaultDownload",
"\n\n",
"f",
",",
"n",
",",
"err",
":=",
"vc",
".",
"Download",
"(",
"ctx",
",",
"u",
",",
"&",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"n",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"strings",
".",
"HasPrefix",
"(",
"src",
",",
"\"",
"\"",
")",
"||",
"isDir",
"(",
"src",
")",
"{",
"f",
"=",
"&",
"archiveReader",
"{",
"ReadCloser",
":",
"f",
"}",
"// look for the gzip trailer",
"\n",
"}",
"\n\n",
"return",
"f",
",",
"n",
",",
"nil",
"\n",
"}"
] |
// Download initiates a file transfer from the guest
|
[
"Download",
"initiates",
"a",
"file",
"transfer",
"from",
"the",
"guest"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/guest/toolbox/client.go#L272-L297
|
21,566
|
vmware/govmomi
|
guest/toolbox/client.go
|
Upload
|
func (c *Client) Upload(ctx context.Context, src io.Reader, dst string, p soap.Upload, attr types.BaseGuestFileAttributes, force bool) error {
vc := c.ProcessManager.Client()
var err error
if p.ContentLength == 0 { // Content-Length is required
switch r := src.(type) {
case *bytes.Buffer:
p.ContentLength = int64(r.Len())
case *bytes.Reader:
p.ContentLength = int64(r.Len())
case *strings.Reader:
p.ContentLength = int64(r.Len())
case *os.File:
info, serr := r.Stat()
if serr != nil {
return serr
}
p.ContentLength = info.Size()
}
if p.ContentLength == 0 { // os.File for example could be a device (stdin)
buf := new(bytes.Buffer)
p.ContentLength, err = io.Copy(buf, src)
if err != nil {
return err
}
src = buf
}
}
url, err := c.FileManager.InitiateFileTransferToGuest(ctx, c.Authentication, dst, attr, p.ContentLength, force)
if err != nil {
return err
}
u, err := c.FileManager.TransferURL(ctx, url)
if err != nil {
return err
}
return vc.Client.Upload(ctx, src, u, &p)
}
|
go
|
func (c *Client) Upload(ctx context.Context, src io.Reader, dst string, p soap.Upload, attr types.BaseGuestFileAttributes, force bool) error {
vc := c.ProcessManager.Client()
var err error
if p.ContentLength == 0 { // Content-Length is required
switch r := src.(type) {
case *bytes.Buffer:
p.ContentLength = int64(r.Len())
case *bytes.Reader:
p.ContentLength = int64(r.Len())
case *strings.Reader:
p.ContentLength = int64(r.Len())
case *os.File:
info, serr := r.Stat()
if serr != nil {
return serr
}
p.ContentLength = info.Size()
}
if p.ContentLength == 0 { // os.File for example could be a device (stdin)
buf := new(bytes.Buffer)
p.ContentLength, err = io.Copy(buf, src)
if err != nil {
return err
}
src = buf
}
}
url, err := c.FileManager.InitiateFileTransferToGuest(ctx, c.Authentication, dst, attr, p.ContentLength, force)
if err != nil {
return err
}
u, err := c.FileManager.TransferURL(ctx, url)
if err != nil {
return err
}
return vc.Client.Upload(ctx, src, u, &p)
}
|
[
"func",
"(",
"c",
"*",
"Client",
")",
"Upload",
"(",
"ctx",
"context",
".",
"Context",
",",
"src",
"io",
".",
"Reader",
",",
"dst",
"string",
",",
"p",
"soap",
".",
"Upload",
",",
"attr",
"types",
".",
"BaseGuestFileAttributes",
",",
"force",
"bool",
")",
"error",
"{",
"vc",
":=",
"c",
".",
"ProcessManager",
".",
"Client",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n\n",
"if",
"p",
".",
"ContentLength",
"==",
"0",
"{",
"// Content-Length is required",
"switch",
"r",
":=",
"src",
".",
"(",
"type",
")",
"{",
"case",
"*",
"bytes",
".",
"Buffer",
":",
"p",
".",
"ContentLength",
"=",
"int64",
"(",
"r",
".",
"Len",
"(",
")",
")",
"\n",
"case",
"*",
"bytes",
".",
"Reader",
":",
"p",
".",
"ContentLength",
"=",
"int64",
"(",
"r",
".",
"Len",
"(",
")",
")",
"\n",
"case",
"*",
"strings",
".",
"Reader",
":",
"p",
".",
"ContentLength",
"=",
"int64",
"(",
"r",
".",
"Len",
"(",
")",
")",
"\n",
"case",
"*",
"os",
".",
"File",
":",
"info",
",",
"serr",
":=",
"r",
".",
"Stat",
"(",
")",
"\n",
"if",
"serr",
"!=",
"nil",
"{",
"return",
"serr",
"\n",
"}",
"\n\n",
"p",
".",
"ContentLength",
"=",
"info",
".",
"Size",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"p",
".",
"ContentLength",
"==",
"0",
"{",
"// os.File for example could be a device (stdin)",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n\n",
"p",
".",
"ContentLength",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"buf",
",",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"src",
"=",
"buf",
"\n",
"}",
"\n",
"}",
"\n\n",
"url",
",",
"err",
":=",
"c",
".",
"FileManager",
".",
"InitiateFileTransferToGuest",
"(",
"ctx",
",",
"c",
".",
"Authentication",
",",
"dst",
",",
"attr",
",",
"p",
".",
"ContentLength",
",",
"force",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"u",
",",
"err",
":=",
"c",
".",
"FileManager",
".",
"TransferURL",
"(",
"ctx",
",",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"vc",
".",
"Client",
".",
"Upload",
"(",
"ctx",
",",
"src",
",",
"u",
",",
"&",
"p",
")",
"\n",
"}"
] |
// Upload transfers a file to the guest
|
[
"Upload",
"transfers",
"a",
"file",
"to",
"the",
"guest"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/guest/toolbox/client.go#L300-L345
|
21,567
|
vmware/govmomi
|
object/host_firewall_system.go
|
ByRule
|
func (l HostFirewallRulesetList) ByRule(rule types.HostFirewallRule) HostFirewallRulesetList {
var matches HostFirewallRulesetList
for _, rs := range l {
for _, r := range rs.Rule {
if r.PortType != rule.PortType ||
r.Protocol != rule.Protocol ||
r.Direction != rule.Direction {
continue
}
if r.EndPort == 0 && rule.Port == r.Port ||
rule.Port >= r.Port && rule.Port <= r.EndPort {
matches = append(matches, rs)
break
}
}
}
return matches
}
|
go
|
func (l HostFirewallRulesetList) ByRule(rule types.HostFirewallRule) HostFirewallRulesetList {
var matches HostFirewallRulesetList
for _, rs := range l {
for _, r := range rs.Rule {
if r.PortType != rule.PortType ||
r.Protocol != rule.Protocol ||
r.Direction != rule.Direction {
continue
}
if r.EndPort == 0 && rule.Port == r.Port ||
rule.Port >= r.Port && rule.Port <= r.EndPort {
matches = append(matches, rs)
break
}
}
}
return matches
}
|
[
"func",
"(",
"l",
"HostFirewallRulesetList",
")",
"ByRule",
"(",
"rule",
"types",
".",
"HostFirewallRule",
")",
"HostFirewallRulesetList",
"{",
"var",
"matches",
"HostFirewallRulesetList",
"\n\n",
"for",
"_",
",",
"rs",
":=",
"range",
"l",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"rs",
".",
"Rule",
"{",
"if",
"r",
".",
"PortType",
"!=",
"rule",
".",
"PortType",
"||",
"r",
".",
"Protocol",
"!=",
"rule",
".",
"Protocol",
"||",
"r",
".",
"Direction",
"!=",
"rule",
".",
"Direction",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"r",
".",
"EndPort",
"==",
"0",
"&&",
"rule",
".",
"Port",
"==",
"r",
".",
"Port",
"||",
"rule",
".",
"Port",
">=",
"r",
".",
"Port",
"&&",
"rule",
".",
"Port",
"<=",
"r",
".",
"EndPort",
"{",
"matches",
"=",
"append",
"(",
"matches",
",",
"rs",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"matches",
"\n",
"}"
] |
// ByRule returns a HostFirewallRulesetList where Direction, PortType and Protocol are equal and Port is within range
|
[
"ByRule",
"returns",
"a",
"HostFirewallRulesetList",
"where",
"Direction",
"PortType",
"and",
"Protocol",
"are",
"equal",
"and",
"Port",
"is",
"within",
"range"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_firewall_system.go#L85-L105
|
21,568
|
vmware/govmomi
|
object/host_firewall_system.go
|
Enabled
|
func (l HostFirewallRulesetList) Enabled() HostFirewallRulesetList {
var matches HostFirewallRulesetList
for _, rs := range l {
if rs.Enabled {
matches = append(matches, rs)
}
}
return matches
}
|
go
|
func (l HostFirewallRulesetList) Enabled() HostFirewallRulesetList {
var matches HostFirewallRulesetList
for _, rs := range l {
if rs.Enabled {
matches = append(matches, rs)
}
}
return matches
}
|
[
"func",
"(",
"l",
"HostFirewallRulesetList",
")",
"Enabled",
"(",
")",
"HostFirewallRulesetList",
"{",
"var",
"matches",
"HostFirewallRulesetList",
"\n\n",
"for",
"_",
",",
"rs",
":=",
"range",
"l",
"{",
"if",
"rs",
".",
"Enabled",
"{",
"matches",
"=",
"append",
"(",
"matches",
",",
"rs",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"matches",
"\n",
"}"
] |
// Enabled returns a HostFirewallRulesetList with enabled rules
|
[
"Enabled",
"returns",
"a",
"HostFirewallRulesetList",
"with",
"enabled",
"rules"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_firewall_system.go#L147-L157
|
21,569
|
vmware/govmomi
|
object/host_firewall_system.go
|
Keys
|
func (l HostFirewallRulesetList) Keys() []string {
var keys []string
for _, rs := range l {
keys = append(keys, rs.Key)
}
return keys
}
|
go
|
func (l HostFirewallRulesetList) Keys() []string {
var keys []string
for _, rs := range l {
keys = append(keys, rs.Key)
}
return keys
}
|
[
"func",
"(",
"l",
"HostFirewallRulesetList",
")",
"Keys",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"keys",
"[",
"]",
"string",
"\n\n",
"for",
"_",
",",
"rs",
":=",
"range",
"l",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"rs",
".",
"Key",
")",
"\n",
"}",
"\n\n",
"return",
"keys",
"\n",
"}"
] |
// Keys returns the HostFirewallRuleset.Key for each ruleset in the list
|
[
"Keys",
"returns",
"the",
"HostFirewallRuleset",
".",
"Key",
"for",
"each",
"ruleset",
"in",
"the",
"list"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_firewall_system.go#L173-L181
|
21,570
|
vmware/govmomi
|
vim25/xml/xml.go
|
CopyToken
|
func CopyToken(t Token) Token {
switch v := t.(type) {
case CharData:
return v.Copy()
case Comment:
return v.Copy()
case Directive:
return v.Copy()
case ProcInst:
return v.Copy()
case StartElement:
return v.Copy()
}
return t
}
|
go
|
func CopyToken(t Token) Token {
switch v := t.(type) {
case CharData:
return v.Copy()
case Comment:
return v.Copy()
case Directive:
return v.Copy()
case ProcInst:
return v.Copy()
case StartElement:
return v.Copy()
}
return t
}
|
[
"func",
"CopyToken",
"(",
"t",
"Token",
")",
"Token",
"{",
"switch",
"v",
":=",
"t",
".",
"(",
"type",
")",
"{",
"case",
"CharData",
":",
"return",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"Comment",
":",
"return",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"Directive",
":",
"return",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"ProcInst",
":",
"return",
"v",
".",
"Copy",
"(",
")",
"\n",
"case",
"StartElement",
":",
"return",
"v",
".",
"Copy",
"(",
")",
"\n",
"}",
"\n",
"return",
"t",
"\n",
"}"
] |
// CopyToken returns a copy of a Token.
|
[
"CopyToken",
"returns",
"a",
"copy",
"of",
"a",
"Token",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L118-L132
|
21,571
|
vmware/govmomi
|
vim25/xml/xml.go
|
NewDecoder
|
func NewDecoder(r io.Reader) *Decoder {
d := &Decoder{
ns: make(map[string]string),
nextByte: -1,
line: 1,
Strict: true,
}
d.switchToReader(r)
return d
}
|
go
|
func NewDecoder(r io.Reader) *Decoder {
d := &Decoder{
ns: make(map[string]string),
nextByte: -1,
line: 1,
Strict: true,
}
d.switchToReader(r)
return d
}
|
[
"func",
"NewDecoder",
"(",
"r",
"io",
".",
"Reader",
")",
"*",
"Decoder",
"{",
"d",
":=",
"&",
"Decoder",
"{",
"ns",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
",",
"nextByte",
":",
"-",
"1",
",",
"line",
":",
"1",
",",
"Strict",
":",
"true",
",",
"}",
"\n",
"d",
".",
"switchToReader",
"(",
"r",
")",
"\n",
"return",
"d",
"\n",
"}"
] |
// NewDecoder creates a new XML parser reading from r.
// If r does not implement io.ByteReader, NewDecoder will
// do its own buffering.
|
[
"NewDecoder",
"creates",
"a",
"new",
"XML",
"parser",
"reading",
"from",
"r",
".",
"If",
"r",
"does",
"not",
"implement",
"io",
".",
"ByteReader",
"NewDecoder",
"will",
"do",
"its",
"own",
"buffering",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L209-L218
|
21,572
|
vmware/govmomi
|
vim25/xml/xml.go
|
popEOF
|
func (d *Decoder) popEOF() bool {
if d.stk == nil || d.stk.kind != stkEOF {
return false
}
d.pop()
return true
}
|
go
|
func (d *Decoder) popEOF() bool {
if d.stk == nil || d.stk.kind != stkEOF {
return false
}
d.pop()
return true
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"popEOF",
"(",
")",
"bool",
"{",
"if",
"d",
".",
"stk",
"==",
"nil",
"||",
"d",
".",
"stk",
".",
"kind",
"!=",
"stkEOF",
"{",
"return",
"false",
"\n",
"}",
"\n",
"d",
".",
"pop",
"(",
")",
"\n",
"return",
"true",
"\n",
"}"
] |
// Undo a pushEOF.
// The element must have been finished, so the EOF should be at the top of the stack.
|
[
"Undo",
"a",
"pushEOF",
".",
"The",
"element",
"must",
"have",
"been",
"finished",
"so",
"the",
"EOF",
"should",
"be",
"at",
"the",
"top",
"of",
"the",
"stack",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L401-L407
|
21,573
|
vmware/govmomi
|
vim25/xml/xml.go
|
pushElement
|
func (d *Decoder) pushElement(name Name) {
s := d.push(stkStart)
s.name = name
}
|
go
|
func (d *Decoder) pushElement(name Name) {
s := d.push(stkStart)
s.name = name
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"pushElement",
"(",
"name",
"Name",
")",
"{",
"s",
":=",
"d",
".",
"push",
"(",
"stkStart",
")",
"\n",
"s",
".",
"name",
"=",
"name",
"\n",
"}"
] |
// Record that we are starting an element with the given name.
|
[
"Record",
"that",
"we",
"are",
"starting",
"an",
"element",
"with",
"the",
"given",
"name",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L410-L413
|
21,574
|
vmware/govmomi
|
vim25/xml/xml.go
|
syntaxError
|
func (d *Decoder) syntaxError(msg string) error {
return &SyntaxError{Msg: msg, Line: d.line}
}
|
go
|
func (d *Decoder) syntaxError(msg string) error {
return &SyntaxError{Msg: msg, Line: d.line}
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"syntaxError",
"(",
"msg",
"string",
")",
"error",
"{",
"return",
"&",
"SyntaxError",
"{",
"Msg",
":",
"msg",
",",
"Line",
":",
"d",
".",
"line",
"}",
"\n",
"}"
] |
// Creates a SyntaxError with the current line number.
|
[
"Creates",
"a",
"SyntaxError",
"with",
"the",
"current",
"line",
"number",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L425-L427
|
21,575
|
vmware/govmomi
|
vim25/xml/xml.go
|
popElement
|
func (d *Decoder) popElement(t *EndElement) bool {
s := d.pop()
name := t.Name
switch {
case s == nil || s.kind != stkStart:
d.err = d.syntaxError("unexpected end element </" + name.Local + ">")
return false
case s.name.Local != name.Local:
if !d.Strict {
d.needClose = true
d.toClose = t.Name
t.Name = s.name
return true
}
d.err = d.syntaxError("element <" + s.name.Local + "> closed by </" + name.Local + ">")
return false
case s.name.Space != name.Space:
d.err = d.syntaxError("element <" + s.name.Local + "> in space " + s.name.Space +
"closed by </" + name.Local + "> in space " + name.Space)
return false
}
// Pop stack until a Start or EOF is on the top, undoing the
// translations that were associated with the element we just closed.
for d.stk != nil && d.stk.kind != stkStart && d.stk.kind != stkEOF {
s := d.pop()
if s.ok {
d.ns[s.name.Local] = s.name.Space
} else {
delete(d.ns, s.name.Local)
}
}
return true
}
|
go
|
func (d *Decoder) popElement(t *EndElement) bool {
s := d.pop()
name := t.Name
switch {
case s == nil || s.kind != stkStart:
d.err = d.syntaxError("unexpected end element </" + name.Local + ">")
return false
case s.name.Local != name.Local:
if !d.Strict {
d.needClose = true
d.toClose = t.Name
t.Name = s.name
return true
}
d.err = d.syntaxError("element <" + s.name.Local + "> closed by </" + name.Local + ">")
return false
case s.name.Space != name.Space:
d.err = d.syntaxError("element <" + s.name.Local + "> in space " + s.name.Space +
"closed by </" + name.Local + "> in space " + name.Space)
return false
}
// Pop stack until a Start or EOF is on the top, undoing the
// translations that were associated with the element we just closed.
for d.stk != nil && d.stk.kind != stkStart && d.stk.kind != stkEOF {
s := d.pop()
if s.ok {
d.ns[s.name.Local] = s.name.Space
} else {
delete(d.ns, s.name.Local)
}
}
return true
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"popElement",
"(",
"t",
"*",
"EndElement",
")",
"bool",
"{",
"s",
":=",
"d",
".",
"pop",
"(",
")",
"\n",
"name",
":=",
"t",
".",
"Name",
"\n",
"switch",
"{",
"case",
"s",
"==",
"nil",
"||",
"s",
".",
"kind",
"!=",
"stkStart",
":",
"d",
".",
"err",
"=",
"d",
".",
"syntaxError",
"(",
"\"",
"\"",
"+",
"name",
".",
"Local",
"+",
"\"",
"\"",
")",
"\n",
"return",
"false",
"\n",
"case",
"s",
".",
"name",
".",
"Local",
"!=",
"name",
".",
"Local",
":",
"if",
"!",
"d",
".",
"Strict",
"{",
"d",
".",
"needClose",
"=",
"true",
"\n",
"d",
".",
"toClose",
"=",
"t",
".",
"Name",
"\n",
"t",
".",
"Name",
"=",
"s",
".",
"name",
"\n",
"return",
"true",
"\n",
"}",
"\n",
"d",
".",
"err",
"=",
"d",
".",
"syntaxError",
"(",
"\"",
"\"",
"+",
"s",
".",
"name",
".",
"Local",
"+",
"\"",
"\"",
"+",
"name",
".",
"Local",
"+",
"\"",
"\"",
")",
"\n",
"return",
"false",
"\n",
"case",
"s",
".",
"name",
".",
"Space",
"!=",
"name",
".",
"Space",
":",
"d",
".",
"err",
"=",
"d",
".",
"syntaxError",
"(",
"\"",
"\"",
"+",
"s",
".",
"name",
".",
"Local",
"+",
"\"",
"\"",
"+",
"s",
".",
"name",
".",
"Space",
"+",
"\"",
"\"",
"+",
"name",
".",
"Local",
"+",
"\"",
"\"",
"+",
"name",
".",
"Space",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n\n",
"// Pop stack until a Start or EOF is on the top, undoing the",
"// translations that were associated with the element we just closed.",
"for",
"d",
".",
"stk",
"!=",
"nil",
"&&",
"d",
".",
"stk",
".",
"kind",
"!=",
"stkStart",
"&&",
"d",
".",
"stk",
".",
"kind",
"!=",
"stkEOF",
"{",
"s",
":=",
"d",
".",
"pop",
"(",
")",
"\n",
"if",
"s",
".",
"ok",
"{",
"d",
".",
"ns",
"[",
"s",
".",
"name",
".",
"Local",
"]",
"=",
"s",
".",
"name",
".",
"Space",
"\n",
"}",
"else",
"{",
"delete",
"(",
"d",
".",
"ns",
",",
"s",
".",
"name",
".",
"Local",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// Record that we are ending an element with the given name.
// The name must match the record at the top of the stack,
// which must be a pushElement record.
// After popping the element, apply any undo records from
// the stack to restore the name translations that existed
// before we saw this element.
|
[
"Record",
"that",
"we",
"are",
"ending",
"an",
"element",
"with",
"the",
"given",
"name",
".",
"The",
"name",
"must",
"match",
"the",
"record",
"at",
"the",
"top",
"of",
"the",
"stack",
"which",
"must",
"be",
"a",
"pushElement",
"record",
".",
"After",
"popping",
"the",
"element",
"apply",
"any",
"undo",
"records",
"from",
"the",
"stack",
"to",
"restore",
"the",
"name",
"translations",
"that",
"existed",
"before",
"we",
"saw",
"this",
"element",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L435-L469
|
21,576
|
vmware/govmomi
|
vim25/xml/xml.go
|
autoClose
|
func (d *Decoder) autoClose(t Token) (Token, bool) {
if d.stk == nil || d.stk.kind != stkStart {
return nil, false
}
name := strings.ToLower(d.stk.name.Local)
for _, s := range d.AutoClose {
if strings.ToLower(s) == name {
// This one should be auto closed if t doesn't close it.
et, ok := t.(EndElement)
if !ok || et.Name.Local != name {
return EndElement{d.stk.name}, true
}
break
}
}
return nil, false
}
|
go
|
func (d *Decoder) autoClose(t Token) (Token, bool) {
if d.stk == nil || d.stk.kind != stkStart {
return nil, false
}
name := strings.ToLower(d.stk.name.Local)
for _, s := range d.AutoClose {
if strings.ToLower(s) == name {
// This one should be auto closed if t doesn't close it.
et, ok := t.(EndElement)
if !ok || et.Name.Local != name {
return EndElement{d.stk.name}, true
}
break
}
}
return nil, false
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"autoClose",
"(",
"t",
"Token",
")",
"(",
"Token",
",",
"bool",
")",
"{",
"if",
"d",
".",
"stk",
"==",
"nil",
"||",
"d",
".",
"stk",
".",
"kind",
"!=",
"stkStart",
"{",
"return",
"nil",
",",
"false",
"\n",
"}",
"\n",
"name",
":=",
"strings",
".",
"ToLower",
"(",
"d",
".",
"stk",
".",
"name",
".",
"Local",
")",
"\n",
"for",
"_",
",",
"s",
":=",
"range",
"d",
".",
"AutoClose",
"{",
"if",
"strings",
".",
"ToLower",
"(",
"s",
")",
"==",
"name",
"{",
"// This one should be auto closed if t doesn't close it.",
"et",
",",
"ok",
":=",
"t",
".",
"(",
"EndElement",
")",
"\n",
"if",
"!",
"ok",
"||",
"et",
".",
"Name",
".",
"Local",
"!=",
"name",
"{",
"return",
"EndElement",
"{",
"d",
".",
"stk",
".",
"name",
"}",
",",
"true",
"\n",
"}",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"false",
"\n",
"}"
] |
// If the top element on the stack is autoclosing and
// t is not the end tag, invent the end tag.
|
[
"If",
"the",
"top",
"element",
"on",
"the",
"stack",
"is",
"autoclosing",
"and",
"t",
"is",
"not",
"the",
"end",
"tag",
"invent",
"the",
"end",
"tag",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L473-L489
|
21,577
|
vmware/govmomi
|
vim25/xml/xml.go
|
RawToken
|
func (d *Decoder) RawToken() (Token, error) {
if d.unmarshalDepth > 0 {
return nil, errRawToken
}
return d.rawToken()
}
|
go
|
func (d *Decoder) RawToken() (Token, error) {
if d.unmarshalDepth > 0 {
return nil, errRawToken
}
return d.rawToken()
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"RawToken",
"(",
")",
"(",
"Token",
",",
"error",
")",
"{",
"if",
"d",
".",
"unmarshalDepth",
">",
"0",
"{",
"return",
"nil",
",",
"errRawToken",
"\n",
"}",
"\n",
"return",
"d",
".",
"rawToken",
"(",
")",
"\n",
"}"
] |
// RawToken is like Token but does not verify that
// start and end elements match and does not translate
// name space prefixes to their corresponding URLs.
|
[
"RawToken",
"is",
"like",
"Token",
"but",
"does",
"not",
"verify",
"that",
"start",
"and",
"end",
"elements",
"match",
"and",
"does",
"not",
"translate",
"name",
"space",
"prefixes",
"to",
"their",
"corresponding",
"URLs",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L496-L501
|
21,578
|
vmware/govmomi
|
vim25/xml/xml.go
|
space
|
func (d *Decoder) space() {
for {
b, ok := d.getc()
if !ok {
return
}
switch b {
case ' ', '\r', '\n', '\t':
default:
d.ungetc(b)
return
}
}
}
|
go
|
func (d *Decoder) space() {
for {
b, ok := d.getc()
if !ok {
return
}
switch b {
case ' ', '\r', '\n', '\t':
default:
d.ungetc(b)
return
}
}
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"space",
"(",
")",
"{",
"for",
"{",
"b",
",",
"ok",
":=",
"d",
".",
"getc",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"switch",
"b",
"{",
"case",
"' '",
",",
"'\\r'",
",",
"'\\n'",
",",
"'\\t'",
":",
"default",
":",
"d",
".",
"ungetc",
"(",
"b",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// Skip spaces if any
|
[
"Skip",
"spaces",
"if",
"any"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L828-L841
|
21,579
|
vmware/govmomi
|
vim25/xml/xml.go
|
getc
|
func (d *Decoder) getc() (b byte, ok bool) {
if d.err != nil {
return 0, false
}
if d.nextByte >= 0 {
b = byte(d.nextByte)
d.nextByte = -1
} else {
b, d.err = d.r.ReadByte()
if d.err != nil {
return 0, false
}
if d.saved != nil {
d.saved.WriteByte(b)
}
}
if b == '\n' {
d.line++
}
return b, true
}
|
go
|
func (d *Decoder) getc() (b byte, ok bool) {
if d.err != nil {
return 0, false
}
if d.nextByte >= 0 {
b = byte(d.nextByte)
d.nextByte = -1
} else {
b, d.err = d.r.ReadByte()
if d.err != nil {
return 0, false
}
if d.saved != nil {
d.saved.WriteByte(b)
}
}
if b == '\n' {
d.line++
}
return b, true
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"getc",
"(",
")",
"(",
"b",
"byte",
",",
"ok",
"bool",
")",
"{",
"if",
"d",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"if",
"d",
".",
"nextByte",
">=",
"0",
"{",
"b",
"=",
"byte",
"(",
"d",
".",
"nextByte",
")",
"\n",
"d",
".",
"nextByte",
"=",
"-",
"1",
"\n",
"}",
"else",
"{",
"b",
",",
"d",
".",
"err",
"=",
"d",
".",
"r",
".",
"ReadByte",
"(",
")",
"\n",
"if",
"d",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"if",
"d",
".",
"saved",
"!=",
"nil",
"{",
"d",
".",
"saved",
".",
"WriteByte",
"(",
"b",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"b",
"==",
"'\\n'",
"{",
"d",
".",
"line",
"++",
"\n",
"}",
"\n",
"return",
"b",
",",
"true",
"\n",
"}"
] |
// Read a single byte.
// If there is no byte to read, return ok==false
// and leave the error in d.err.
// Maintain line number.
|
[
"Read",
"a",
"single",
"byte",
".",
"If",
"there",
"is",
"no",
"byte",
"to",
"read",
"return",
"ok",
"==",
"false",
"and",
"leave",
"the",
"error",
"in",
"d",
".",
"err",
".",
"Maintain",
"line",
"number",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L847-L867
|
21,580
|
vmware/govmomi
|
vim25/xml/xml.go
|
readName
|
func (d *Decoder) readName() (ok bool) {
var b byte
if b, ok = d.mustgetc(); !ok {
return
}
if b < utf8.RuneSelf && !isNameByte(b) {
d.ungetc(b)
return false
}
d.buf.WriteByte(b)
for {
if b, ok = d.mustgetc(); !ok {
return
}
if b < utf8.RuneSelf && !isNameByte(b) {
d.ungetc(b)
break
}
d.buf.WriteByte(b)
}
return true
}
|
go
|
func (d *Decoder) readName() (ok bool) {
var b byte
if b, ok = d.mustgetc(); !ok {
return
}
if b < utf8.RuneSelf && !isNameByte(b) {
d.ungetc(b)
return false
}
d.buf.WriteByte(b)
for {
if b, ok = d.mustgetc(); !ok {
return
}
if b < utf8.RuneSelf && !isNameByte(b) {
d.ungetc(b)
break
}
d.buf.WriteByte(b)
}
return true
}
|
[
"func",
"(",
"d",
"*",
"Decoder",
")",
"readName",
"(",
")",
"(",
"ok",
"bool",
")",
"{",
"var",
"b",
"byte",
"\n",
"if",
"b",
",",
"ok",
"=",
"d",
".",
"mustgetc",
"(",
")",
";",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"if",
"b",
"<",
"utf8",
".",
"RuneSelf",
"&&",
"!",
"isNameByte",
"(",
"b",
")",
"{",
"d",
".",
"ungetc",
"(",
"b",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"d",
".",
"buf",
".",
"WriteByte",
"(",
"b",
")",
"\n\n",
"for",
"{",
"if",
"b",
",",
"ok",
"=",
"d",
".",
"mustgetc",
"(",
")",
";",
"!",
"ok",
"{",
"return",
"\n",
"}",
"\n",
"if",
"b",
"<",
"utf8",
".",
"RuneSelf",
"&&",
"!",
"isNameByte",
"(",
"b",
")",
"{",
"d",
".",
"ungetc",
"(",
"b",
")",
"\n",
"break",
"\n",
"}",
"\n",
"d",
".",
"buf",
".",
"WriteByte",
"(",
"b",
")",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// Read a name and append its bytes to d.buf.
// The name is delimited by any single-byte character not valid in names.
// All multi-byte characters are accepted; the caller must check their validity.
|
[
"Read",
"a",
"name",
"and",
"append",
"its",
"bytes",
"to",
"d",
".",
"buf",
".",
"The",
"name",
"is",
"delimited",
"by",
"any",
"single",
"-",
"byte",
"character",
"not",
"valid",
"in",
"names",
".",
"All",
"multi",
"-",
"byte",
"characters",
"are",
"accepted",
";",
"the",
"caller",
"must",
"check",
"their",
"validity",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L1127-L1149
|
21,581
|
vmware/govmomi
|
vim25/xml/xml.go
|
procInstEncoding
|
func procInstEncoding(s string) string {
// TODO: this parsing is somewhat lame and not exact.
// It works for all actual cases, though.
idx := strings.Index(s, "encoding=")
if idx == -1 {
return ""
}
v := s[idx+len("encoding="):]
if v == "" {
return ""
}
if v[0] != '\'' && v[0] != '"' {
return ""
}
idx = strings.IndexRune(v[1:], rune(v[0]))
if idx == -1 {
return ""
}
return v[1 : idx+1]
}
|
go
|
func procInstEncoding(s string) string {
// TODO: this parsing is somewhat lame and not exact.
// It works for all actual cases, though.
idx := strings.Index(s, "encoding=")
if idx == -1 {
return ""
}
v := s[idx+len("encoding="):]
if v == "" {
return ""
}
if v[0] != '\'' && v[0] != '"' {
return ""
}
idx = strings.IndexRune(v[1:], rune(v[0]))
if idx == -1 {
return ""
}
return v[1 : idx+1]
}
|
[
"func",
"procInstEncoding",
"(",
"s",
"string",
")",
"string",
"{",
"// TODO: this parsing is somewhat lame and not exact.",
"// It works for all actual cases, though.",
"idx",
":=",
"strings",
".",
"Index",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"if",
"idx",
"==",
"-",
"1",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"v",
":=",
"s",
"[",
"idx",
"+",
"len",
"(",
"\"",
"\"",
")",
":",
"]",
"\n",
"if",
"v",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"v",
"[",
"0",
"]",
"!=",
"'\\''",
"&&",
"v",
"[",
"0",
"]",
"!=",
"'\"'",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"idx",
"=",
"strings",
".",
"IndexRune",
"(",
"v",
"[",
"1",
":",
"]",
",",
"rune",
"(",
"v",
"[",
"0",
"]",
")",
")",
"\n",
"if",
"idx",
"==",
"-",
"1",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"v",
"[",
"1",
":",
"idx",
"+",
"1",
"]",
"\n",
"}"
] |
// procInstEncoding parses the `encoding="..."` or `encoding='...'`
// value out of the provided string, returning "" if not found.
|
[
"procInstEncoding",
"parses",
"the",
"encoding",
"=",
"...",
"or",
"encoding",
"=",
"...",
"value",
"out",
"of",
"the",
"provided",
"string",
"returning",
"if",
"not",
"found",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vim25/xml/xml.go#L1920-L1939
|
21,582
|
vmware/govmomi
|
object/distributed_virtual_portgroup.go
|
EthernetCardBackingInfo
|
func (p DistributedVirtualPortgroup) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) {
var dvp mo.DistributedVirtualPortgroup
var dvs mo.DistributedVirtualSwitch
prop := "config.distributedVirtualSwitch"
if err := p.Properties(ctx, p.Reference(), []string{"key", prop}, &dvp); err != nil {
return nil, err
}
// "This property should always be set unless the user's setting does not have System.Read privilege on the object referred to by this property."
if dvp.Config.DistributedVirtualSwitch == nil {
return nil, fmt.Errorf("no System.Read privilege on: %s.%s", p.Reference(), prop)
}
if err := p.Properties(ctx, *dvp.Config.DistributedVirtualSwitch, []string{"uuid"}, &dvs); err != nil {
return nil, err
}
backing := &types.VirtualEthernetCardDistributedVirtualPortBackingInfo{
Port: types.DistributedVirtualSwitchPortConnection{
PortgroupKey: dvp.Key,
SwitchUuid: dvs.Uuid,
},
}
return backing, nil
}
|
go
|
func (p DistributedVirtualPortgroup) EthernetCardBackingInfo(ctx context.Context) (types.BaseVirtualDeviceBackingInfo, error) {
var dvp mo.DistributedVirtualPortgroup
var dvs mo.DistributedVirtualSwitch
prop := "config.distributedVirtualSwitch"
if err := p.Properties(ctx, p.Reference(), []string{"key", prop}, &dvp); err != nil {
return nil, err
}
// "This property should always be set unless the user's setting does not have System.Read privilege on the object referred to by this property."
if dvp.Config.DistributedVirtualSwitch == nil {
return nil, fmt.Errorf("no System.Read privilege on: %s.%s", p.Reference(), prop)
}
if err := p.Properties(ctx, *dvp.Config.DistributedVirtualSwitch, []string{"uuid"}, &dvs); err != nil {
return nil, err
}
backing := &types.VirtualEthernetCardDistributedVirtualPortBackingInfo{
Port: types.DistributedVirtualSwitchPortConnection{
PortgroupKey: dvp.Key,
SwitchUuid: dvs.Uuid,
},
}
return backing, nil
}
|
[
"func",
"(",
"p",
"DistributedVirtualPortgroup",
")",
"EthernetCardBackingInfo",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"types",
".",
"BaseVirtualDeviceBackingInfo",
",",
"error",
")",
"{",
"var",
"dvp",
"mo",
".",
"DistributedVirtualPortgroup",
"\n",
"var",
"dvs",
"mo",
".",
"DistributedVirtualSwitch",
"\n",
"prop",
":=",
"\"",
"\"",
"\n\n",
"if",
"err",
":=",
"p",
".",
"Properties",
"(",
"ctx",
",",
"p",
".",
"Reference",
"(",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"prop",
"}",
",",
"&",
"dvp",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// \"This property should always be set unless the user's setting does not have System.Read privilege on the object referred to by this property.\"",
"if",
"dvp",
".",
"Config",
".",
"DistributedVirtualSwitch",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"p",
".",
"Reference",
"(",
")",
",",
"prop",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"p",
".",
"Properties",
"(",
"ctx",
",",
"*",
"dvp",
".",
"Config",
".",
"DistributedVirtualSwitch",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"&",
"dvs",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"backing",
":=",
"&",
"types",
".",
"VirtualEthernetCardDistributedVirtualPortBackingInfo",
"{",
"Port",
":",
"types",
".",
"DistributedVirtualSwitchPortConnection",
"{",
"PortgroupKey",
":",
"dvp",
".",
"Key",
",",
"SwitchUuid",
":",
"dvs",
".",
"Uuid",
",",
"}",
",",
"}",
"\n\n",
"return",
"backing",
",",
"nil",
"\n",
"}"
] |
// EthernetCardBackingInfo returns the VirtualDeviceBackingInfo for this DistributedVirtualPortgroup
|
[
"EthernetCardBackingInfo",
"returns",
"the",
"VirtualDeviceBackingInfo",
"for",
"this",
"DistributedVirtualPortgroup"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/distributed_virtual_portgroup.go#L40-L66
|
21,583
|
vmware/govmomi
|
object/host_network_system.go
|
AddPortGroup
|
func (o HostNetworkSystem) AddPortGroup(ctx context.Context, portgrp types.HostPortGroupSpec) error {
req := types.AddPortGroup{
This: o.Reference(),
Portgrp: portgrp,
}
_, err := methods.AddPortGroup(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) AddPortGroup(ctx context.Context, portgrp types.HostPortGroupSpec) error {
req := types.AddPortGroup{
This: o.Reference(),
Portgrp: portgrp,
}
_, err := methods.AddPortGroup(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"AddPortGroup",
"(",
"ctx",
"context",
".",
"Context",
",",
"portgrp",
"types",
".",
"HostPortGroupSpec",
")",
"error",
"{",
"req",
":=",
"types",
".",
"AddPortGroup",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"Portgrp",
":",
"portgrp",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"AddPortGroup",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// AddPortGroup wraps methods.AddPortGroup
|
[
"AddPortGroup",
"wraps",
"methods",
".",
"AddPortGroup"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L38-L50
|
21,584
|
vmware/govmomi
|
object/host_network_system.go
|
AddServiceConsoleVirtualNic
|
func (o HostNetworkSystem) AddServiceConsoleVirtualNic(ctx context.Context, portgroup string, nic types.HostVirtualNicSpec) (string, error) {
req := types.AddServiceConsoleVirtualNic{
This: o.Reference(),
Portgroup: portgroup,
Nic: nic,
}
res, err := methods.AddServiceConsoleVirtualNic(ctx, o.c, &req)
if err != nil {
return "", err
}
return res.Returnval, nil
}
|
go
|
func (o HostNetworkSystem) AddServiceConsoleVirtualNic(ctx context.Context, portgroup string, nic types.HostVirtualNicSpec) (string, error) {
req := types.AddServiceConsoleVirtualNic{
This: o.Reference(),
Portgroup: portgroup,
Nic: nic,
}
res, err := methods.AddServiceConsoleVirtualNic(ctx, o.c, &req)
if err != nil {
return "", err
}
return res.Returnval, nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"AddServiceConsoleVirtualNic",
"(",
"ctx",
"context",
".",
"Context",
",",
"portgroup",
"string",
",",
"nic",
"types",
".",
"HostVirtualNicSpec",
")",
"(",
"string",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"AddServiceConsoleVirtualNic",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"Portgroup",
":",
"portgroup",
",",
"Nic",
":",
"nic",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"AddServiceConsoleVirtualNic",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"res",
".",
"Returnval",
",",
"nil",
"\n",
"}"
] |
// AddServiceConsoleVirtualNic wraps methods.AddServiceConsoleVirtualNic
|
[
"AddServiceConsoleVirtualNic",
"wraps",
"methods",
".",
"AddServiceConsoleVirtualNic"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L53-L66
|
21,585
|
vmware/govmomi
|
object/host_network_system.go
|
AddVirtualSwitch
|
func (o HostNetworkSystem) AddVirtualSwitch(ctx context.Context, vswitchName string, spec *types.HostVirtualSwitchSpec) error {
req := types.AddVirtualSwitch{
This: o.Reference(),
VswitchName: vswitchName,
Spec: spec,
}
_, err := methods.AddVirtualSwitch(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) AddVirtualSwitch(ctx context.Context, vswitchName string, spec *types.HostVirtualSwitchSpec) error {
req := types.AddVirtualSwitch{
This: o.Reference(),
VswitchName: vswitchName,
Spec: spec,
}
_, err := methods.AddVirtualSwitch(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"AddVirtualSwitch",
"(",
"ctx",
"context",
".",
"Context",
",",
"vswitchName",
"string",
",",
"spec",
"*",
"types",
".",
"HostVirtualSwitchSpec",
")",
"error",
"{",
"req",
":=",
"types",
".",
"AddVirtualSwitch",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"VswitchName",
":",
"vswitchName",
",",
"Spec",
":",
"spec",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"AddVirtualSwitch",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// AddVirtualSwitch wraps methods.AddVirtualSwitch
|
[
"AddVirtualSwitch",
"wraps",
"methods",
".",
"AddVirtualSwitch"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L85-L98
|
21,586
|
vmware/govmomi
|
object/host_network_system.go
|
QueryNetworkHint
|
func (o HostNetworkSystem) QueryNetworkHint(ctx context.Context, device []string) error {
req := types.QueryNetworkHint{
This: o.Reference(),
Device: device,
}
_, err := methods.QueryNetworkHint(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) QueryNetworkHint(ctx context.Context, device []string) error {
req := types.QueryNetworkHint{
This: o.Reference(),
Device: device,
}
_, err := methods.QueryNetworkHint(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"QueryNetworkHint",
"(",
"ctx",
"context",
".",
"Context",
",",
"device",
"[",
"]",
"string",
")",
"error",
"{",
"req",
":=",
"types",
".",
"QueryNetworkHint",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"Device",
":",
"device",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"QueryNetworkHint",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// QueryNetworkHint wraps methods.QueryNetworkHint
|
[
"QueryNetworkHint",
"wraps",
"methods",
".",
"QueryNetworkHint"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L101-L113
|
21,587
|
vmware/govmomi
|
object/host_network_system.go
|
RefreshNetworkSystem
|
func (o HostNetworkSystem) RefreshNetworkSystem(ctx context.Context) error {
req := types.RefreshNetworkSystem{
This: o.Reference(),
}
_, err := methods.RefreshNetworkSystem(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) RefreshNetworkSystem(ctx context.Context) error {
req := types.RefreshNetworkSystem{
This: o.Reference(),
}
_, err := methods.RefreshNetworkSystem(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"RefreshNetworkSystem",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"req",
":=",
"types",
".",
"RefreshNetworkSystem",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"RefreshNetworkSystem",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// RefreshNetworkSystem wraps methods.RefreshNetworkSystem
|
[
"RefreshNetworkSystem",
"wraps",
"methods",
".",
"RefreshNetworkSystem"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L116-L127
|
21,588
|
vmware/govmomi
|
object/host_network_system.go
|
RemovePortGroup
|
func (o HostNetworkSystem) RemovePortGroup(ctx context.Context, pgName string) error {
req := types.RemovePortGroup{
This: o.Reference(),
PgName: pgName,
}
_, err := methods.RemovePortGroup(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) RemovePortGroup(ctx context.Context, pgName string) error {
req := types.RemovePortGroup{
This: o.Reference(),
PgName: pgName,
}
_, err := methods.RemovePortGroup(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"RemovePortGroup",
"(",
"ctx",
"context",
".",
"Context",
",",
"pgName",
"string",
")",
"error",
"{",
"req",
":=",
"types",
".",
"RemovePortGroup",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"PgName",
":",
"pgName",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"RemovePortGroup",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// RemovePortGroup wraps methods.RemovePortGroup
|
[
"RemovePortGroup",
"wraps",
"methods",
".",
"RemovePortGroup"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L130-L142
|
21,589
|
vmware/govmomi
|
object/host_network_system.go
|
RemoveVirtualSwitch
|
func (o HostNetworkSystem) RemoveVirtualSwitch(ctx context.Context, vswitchName string) error {
req := types.RemoveVirtualSwitch{
This: o.Reference(),
VswitchName: vswitchName,
}
_, err := methods.RemoveVirtualSwitch(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) RemoveVirtualSwitch(ctx context.Context, vswitchName string) error {
req := types.RemoveVirtualSwitch{
This: o.Reference(),
VswitchName: vswitchName,
}
_, err := methods.RemoveVirtualSwitch(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"RemoveVirtualSwitch",
"(",
"ctx",
"context",
".",
"Context",
",",
"vswitchName",
"string",
")",
"error",
"{",
"req",
":=",
"types",
".",
"RemoveVirtualSwitch",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"VswitchName",
":",
"vswitchName",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"RemoveVirtualSwitch",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// RemoveVirtualSwitch wraps methods.RemoveVirtualSwitch
|
[
"RemoveVirtualSwitch",
"wraps",
"methods",
".",
"RemoveVirtualSwitch"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L175-L187
|
21,590
|
vmware/govmomi
|
object/host_network_system.go
|
UpdateConsoleIpRouteConfig
|
func (o HostNetworkSystem) UpdateConsoleIpRouteConfig(ctx context.Context, config types.BaseHostIpRouteConfig) error {
req := types.UpdateConsoleIpRouteConfig{
This: o.Reference(),
Config: config,
}
_, err := methods.UpdateConsoleIpRouteConfig(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) UpdateConsoleIpRouteConfig(ctx context.Context, config types.BaseHostIpRouteConfig) error {
req := types.UpdateConsoleIpRouteConfig{
This: o.Reference(),
Config: config,
}
_, err := methods.UpdateConsoleIpRouteConfig(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"UpdateConsoleIpRouteConfig",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"types",
".",
"BaseHostIpRouteConfig",
")",
"error",
"{",
"req",
":=",
"types",
".",
"UpdateConsoleIpRouteConfig",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"Config",
":",
"config",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"UpdateConsoleIpRouteConfig",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// UpdateConsoleIpRouteConfig wraps methods.UpdateConsoleIpRouteConfig
|
[
"UpdateConsoleIpRouteConfig",
"wraps",
"methods",
".",
"UpdateConsoleIpRouteConfig"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L205-L217
|
21,591
|
vmware/govmomi
|
object/host_network_system.go
|
UpdateNetworkConfig
|
func (o HostNetworkSystem) UpdateNetworkConfig(ctx context.Context, config types.HostNetworkConfig, changeMode string) (*types.HostNetworkConfigResult, error) {
req := types.UpdateNetworkConfig{
This: o.Reference(),
Config: config,
ChangeMode: changeMode,
}
res, err := methods.UpdateNetworkConfig(ctx, o.c, &req)
if err != nil {
return nil, err
}
return &res.Returnval, nil
}
|
go
|
func (o HostNetworkSystem) UpdateNetworkConfig(ctx context.Context, config types.HostNetworkConfig, changeMode string) (*types.HostNetworkConfigResult, error) {
req := types.UpdateNetworkConfig{
This: o.Reference(),
Config: config,
ChangeMode: changeMode,
}
res, err := methods.UpdateNetworkConfig(ctx, o.c, &req)
if err != nil {
return nil, err
}
return &res.Returnval, nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"UpdateNetworkConfig",
"(",
"ctx",
"context",
".",
"Context",
",",
"config",
"types",
".",
"HostNetworkConfig",
",",
"changeMode",
"string",
")",
"(",
"*",
"types",
".",
"HostNetworkConfigResult",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"UpdateNetworkConfig",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"Config",
":",
"config",
",",
"ChangeMode",
":",
"changeMode",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"UpdateNetworkConfig",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"res",
".",
"Returnval",
",",
"nil",
"\n",
"}"
] |
// UpdateNetworkConfig wraps methods.UpdateNetworkConfig
|
[
"UpdateNetworkConfig",
"wraps",
"methods",
".",
"UpdateNetworkConfig"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L265-L278
|
21,592
|
vmware/govmomi
|
object/host_network_system.go
|
UpdatePhysicalNicLinkSpeed
|
func (o HostNetworkSystem) UpdatePhysicalNicLinkSpeed(ctx context.Context, device string, linkSpeed *types.PhysicalNicLinkInfo) error {
req := types.UpdatePhysicalNicLinkSpeed{
This: o.Reference(),
Device: device,
LinkSpeed: linkSpeed,
}
_, err := methods.UpdatePhysicalNicLinkSpeed(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) UpdatePhysicalNicLinkSpeed(ctx context.Context, device string, linkSpeed *types.PhysicalNicLinkInfo) error {
req := types.UpdatePhysicalNicLinkSpeed{
This: o.Reference(),
Device: device,
LinkSpeed: linkSpeed,
}
_, err := methods.UpdatePhysicalNicLinkSpeed(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"UpdatePhysicalNicLinkSpeed",
"(",
"ctx",
"context",
".",
"Context",
",",
"device",
"string",
",",
"linkSpeed",
"*",
"types",
".",
"PhysicalNicLinkInfo",
")",
"error",
"{",
"req",
":=",
"types",
".",
"UpdatePhysicalNicLinkSpeed",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"Device",
":",
"device",
",",
"LinkSpeed",
":",
"linkSpeed",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"UpdatePhysicalNicLinkSpeed",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// UpdatePhysicalNicLinkSpeed wraps methods.UpdatePhysicalNicLinkSpeed
|
[
"UpdatePhysicalNicLinkSpeed",
"wraps",
"methods",
".",
"UpdatePhysicalNicLinkSpeed"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L281-L294
|
21,593
|
vmware/govmomi
|
object/host_network_system.go
|
UpdatePortGroup
|
func (o HostNetworkSystem) UpdatePortGroup(ctx context.Context, pgName string, portgrp types.HostPortGroupSpec) error {
req := types.UpdatePortGroup{
This: o.Reference(),
PgName: pgName,
Portgrp: portgrp,
}
_, err := methods.UpdatePortGroup(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) UpdatePortGroup(ctx context.Context, pgName string, portgrp types.HostPortGroupSpec) error {
req := types.UpdatePortGroup{
This: o.Reference(),
PgName: pgName,
Portgrp: portgrp,
}
_, err := methods.UpdatePortGroup(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"UpdatePortGroup",
"(",
"ctx",
"context",
".",
"Context",
",",
"pgName",
"string",
",",
"portgrp",
"types",
".",
"HostPortGroupSpec",
")",
"error",
"{",
"req",
":=",
"types",
".",
"UpdatePortGroup",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"PgName",
":",
"pgName",
",",
"Portgrp",
":",
"portgrp",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"UpdatePortGroup",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// UpdatePortGroup wraps methods.UpdatePortGroup
|
[
"UpdatePortGroup",
"wraps",
"methods",
".",
"UpdatePortGroup"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L297-L310
|
21,594
|
vmware/govmomi
|
object/host_network_system.go
|
UpdateVirtualNic
|
func (o HostNetworkSystem) UpdateVirtualNic(ctx context.Context, device string, nic types.HostVirtualNicSpec) error {
req := types.UpdateVirtualNic{
This: o.Reference(),
Device: device,
Nic: nic,
}
_, err := methods.UpdateVirtualNic(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (o HostNetworkSystem) UpdateVirtualNic(ctx context.Context, device string, nic types.HostVirtualNicSpec) error {
req := types.UpdateVirtualNic{
This: o.Reference(),
Device: device,
Nic: nic,
}
_, err := methods.UpdateVirtualNic(ctx, o.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"o",
"HostNetworkSystem",
")",
"UpdateVirtualNic",
"(",
"ctx",
"context",
".",
"Context",
",",
"device",
"string",
",",
"nic",
"types",
".",
"HostVirtualNicSpec",
")",
"error",
"{",
"req",
":=",
"types",
".",
"UpdateVirtualNic",
"{",
"This",
":",
"o",
".",
"Reference",
"(",
")",
",",
"Device",
":",
"device",
",",
"Nic",
":",
"nic",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"UpdateVirtualNic",
"(",
"ctx",
",",
"o",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// UpdateVirtualNic wraps methods.UpdateVirtualNic
|
[
"UpdateVirtualNic",
"wraps",
"methods",
".",
"UpdateVirtualNic"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_network_system.go#L329-L342
|
21,595
|
vmware/govmomi
|
view/task_view.go
|
CreateTaskView
|
func (m Manager) CreateTaskView(ctx context.Context, watch *types.ManagedObjectReference) (*TaskView, error) {
l, err := m.CreateListView(ctx, nil)
if err != nil {
return nil, err
}
tv := &TaskView{
ListView: l,
Watch: watch,
}
return tv, nil
}
|
go
|
func (m Manager) CreateTaskView(ctx context.Context, watch *types.ManagedObjectReference) (*TaskView, error) {
l, err := m.CreateListView(ctx, nil)
if err != nil {
return nil, err
}
tv := &TaskView{
ListView: l,
Watch: watch,
}
return tv, nil
}
|
[
"func",
"(",
"m",
"Manager",
")",
"CreateTaskView",
"(",
"ctx",
"context",
".",
"Context",
",",
"watch",
"*",
"types",
".",
"ManagedObjectReference",
")",
"(",
"*",
"TaskView",
",",
"error",
")",
"{",
"l",
",",
"err",
":=",
"m",
".",
"CreateListView",
"(",
"ctx",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"tv",
":=",
"&",
"TaskView",
"{",
"ListView",
":",
"l",
",",
"Watch",
":",
"watch",
",",
"}",
"\n\n",
"return",
"tv",
",",
"nil",
"\n",
"}"
] |
// CreateTaskView creates a new ListView that optionally watches for a ManagedEntity's recentTask updates.
|
[
"CreateTaskView",
"creates",
"a",
"new",
"ListView",
"that",
"optionally",
"watches",
"for",
"a",
"ManagedEntity",
"s",
"recentTask",
"updates",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/view/task_view.go#L36-L48
|
21,596
|
vmware/govmomi
|
view/task_view.go
|
Collect
|
func (v TaskView) Collect(ctx context.Context, f func([]types.TaskInfo)) error {
// Using TaskHistoryCollector would be less clunky, but it isn't supported on ESX at all.
ref := v.Reference()
filter := new(property.WaitFilter).Add(ref, "Task", []string{"info"}, v.TraversalSpec())
if v.Watch != nil {
filter.Add(*v.Watch, v.Watch.Type, []string{"recentTask"})
}
pc := property.DefaultCollector(v.Client())
completed := make(map[string]bool)
return property.WaitForUpdates(ctx, pc, filter, func(updates []types.ObjectUpdate) bool {
var infos []types.TaskInfo
var prune []types.ManagedObjectReference
var tasks []types.ManagedObjectReference
var reset func()
for _, update := range updates {
for _, change := range update.ChangeSet {
if change.Name == "recentTask" {
tasks = change.Val.(types.ArrayOfManagedObjectReference).ManagedObjectReference
if len(tasks) != 0 {
reset = func() {
_ = v.Reset(ctx, tasks)
// Remember any tasks we've reported as complete already,
// to avoid reporting multiple times when Reset is triggered.
rtasks := make(map[string]bool)
for i := range tasks {
if _, ok := completed[tasks[i].Value]; ok {
rtasks[tasks[i].Value] = true
}
}
completed = rtasks
}
}
continue
}
info, ok := change.Val.(types.TaskInfo)
if !ok {
continue
}
if !completed[info.Task.Value] {
infos = append(infos, info)
}
if v.Follow && info.CompleteTime != nil {
prune = append(prune, info.Task)
completed[info.Task.Value] = true
}
}
}
if len(infos) != 0 {
f(infos)
}
if reset != nil {
reset()
} else if len(prune) != 0 {
_ = v.Remove(ctx, prune)
}
if len(tasks) != 0 && len(infos) == 0 {
return false
}
return !v.Follow
})
}
|
go
|
func (v TaskView) Collect(ctx context.Context, f func([]types.TaskInfo)) error {
// Using TaskHistoryCollector would be less clunky, but it isn't supported on ESX at all.
ref := v.Reference()
filter := new(property.WaitFilter).Add(ref, "Task", []string{"info"}, v.TraversalSpec())
if v.Watch != nil {
filter.Add(*v.Watch, v.Watch.Type, []string{"recentTask"})
}
pc := property.DefaultCollector(v.Client())
completed := make(map[string]bool)
return property.WaitForUpdates(ctx, pc, filter, func(updates []types.ObjectUpdate) bool {
var infos []types.TaskInfo
var prune []types.ManagedObjectReference
var tasks []types.ManagedObjectReference
var reset func()
for _, update := range updates {
for _, change := range update.ChangeSet {
if change.Name == "recentTask" {
tasks = change.Val.(types.ArrayOfManagedObjectReference).ManagedObjectReference
if len(tasks) != 0 {
reset = func() {
_ = v.Reset(ctx, tasks)
// Remember any tasks we've reported as complete already,
// to avoid reporting multiple times when Reset is triggered.
rtasks := make(map[string]bool)
for i := range tasks {
if _, ok := completed[tasks[i].Value]; ok {
rtasks[tasks[i].Value] = true
}
}
completed = rtasks
}
}
continue
}
info, ok := change.Val.(types.TaskInfo)
if !ok {
continue
}
if !completed[info.Task.Value] {
infos = append(infos, info)
}
if v.Follow && info.CompleteTime != nil {
prune = append(prune, info.Task)
completed[info.Task.Value] = true
}
}
}
if len(infos) != 0 {
f(infos)
}
if reset != nil {
reset()
} else if len(prune) != 0 {
_ = v.Remove(ctx, prune)
}
if len(tasks) != 0 && len(infos) == 0 {
return false
}
return !v.Follow
})
}
|
[
"func",
"(",
"v",
"TaskView",
")",
"Collect",
"(",
"ctx",
"context",
".",
"Context",
",",
"f",
"func",
"(",
"[",
"]",
"types",
".",
"TaskInfo",
")",
")",
"error",
"{",
"// Using TaskHistoryCollector would be less clunky, but it isn't supported on ESX at all.",
"ref",
":=",
"v",
".",
"Reference",
"(",
")",
"\n",
"filter",
":=",
"new",
"(",
"property",
".",
"WaitFilter",
")",
".",
"Add",
"(",
"ref",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"v",
".",
"TraversalSpec",
"(",
")",
")",
"\n\n",
"if",
"v",
".",
"Watch",
"!=",
"nil",
"{",
"filter",
".",
"Add",
"(",
"*",
"v",
".",
"Watch",
",",
"v",
".",
"Watch",
".",
"Type",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
")",
"\n",
"}",
"\n\n",
"pc",
":=",
"property",
".",
"DefaultCollector",
"(",
"v",
".",
"Client",
"(",
")",
")",
"\n\n",
"completed",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n\n",
"return",
"property",
".",
"WaitForUpdates",
"(",
"ctx",
",",
"pc",
",",
"filter",
",",
"func",
"(",
"updates",
"[",
"]",
"types",
".",
"ObjectUpdate",
")",
"bool",
"{",
"var",
"infos",
"[",
"]",
"types",
".",
"TaskInfo",
"\n",
"var",
"prune",
"[",
"]",
"types",
".",
"ManagedObjectReference",
"\n",
"var",
"tasks",
"[",
"]",
"types",
".",
"ManagedObjectReference",
"\n",
"var",
"reset",
"func",
"(",
")",
"\n\n",
"for",
"_",
",",
"update",
":=",
"range",
"updates",
"{",
"for",
"_",
",",
"change",
":=",
"range",
"update",
".",
"ChangeSet",
"{",
"if",
"change",
".",
"Name",
"==",
"\"",
"\"",
"{",
"tasks",
"=",
"change",
".",
"Val",
".",
"(",
"types",
".",
"ArrayOfManagedObjectReference",
")",
".",
"ManagedObjectReference",
"\n",
"if",
"len",
"(",
"tasks",
")",
"!=",
"0",
"{",
"reset",
"=",
"func",
"(",
")",
"{",
"_",
"=",
"v",
".",
"Reset",
"(",
"ctx",
",",
"tasks",
")",
"\n\n",
"// Remember any tasks we've reported as complete already,",
"// to avoid reporting multiple times when Reset is triggered.",
"rtasks",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"for",
"i",
":=",
"range",
"tasks",
"{",
"if",
"_",
",",
"ok",
":=",
"completed",
"[",
"tasks",
"[",
"i",
"]",
".",
"Value",
"]",
";",
"ok",
"{",
"rtasks",
"[",
"tasks",
"[",
"i",
"]",
".",
"Value",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"completed",
"=",
"rtasks",
"\n",
"}",
"\n",
"}",
"\n\n",
"continue",
"\n",
"}",
"\n\n",
"info",
",",
"ok",
":=",
"change",
".",
"Val",
".",
"(",
"types",
".",
"TaskInfo",
")",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n\n",
"if",
"!",
"completed",
"[",
"info",
".",
"Task",
".",
"Value",
"]",
"{",
"infos",
"=",
"append",
"(",
"infos",
",",
"info",
")",
"\n",
"}",
"\n\n",
"if",
"v",
".",
"Follow",
"&&",
"info",
".",
"CompleteTime",
"!=",
"nil",
"{",
"prune",
"=",
"append",
"(",
"prune",
",",
"info",
".",
"Task",
")",
"\n",
"completed",
"[",
"info",
".",
"Task",
".",
"Value",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"infos",
")",
"!=",
"0",
"{",
"f",
"(",
"infos",
")",
"\n",
"}",
"\n\n",
"if",
"reset",
"!=",
"nil",
"{",
"reset",
"(",
")",
"\n",
"}",
"else",
"if",
"len",
"(",
"prune",
")",
"!=",
"0",
"{",
"_",
"=",
"v",
".",
"Remove",
"(",
"ctx",
",",
"prune",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"tasks",
")",
"!=",
"0",
"&&",
"len",
"(",
"infos",
")",
"==",
"0",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"return",
"!",
"v",
".",
"Follow",
"\n",
"}",
")",
"\n",
"}"
] |
// Collect calls function f for each Task update.
|
[
"Collect",
"calls",
"function",
"f",
"for",
"each",
"Task",
"update",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/view/task_view.go#L51-L125
|
21,597
|
vmware/govmomi
|
vapi/vcenter/vcenter_ovf.go
|
DeployLibraryItem
|
func (c *Manager) DeployLibraryItem(ctx context.Context, libraryItemID string, deploy Deploy) (Deployment, error) {
url := internal.URL(c, internal.VCenterOVFLibraryItem).WithID(libraryItemID).WithAction("deploy")
var res Deployment
return res, c.Do(ctx, url.Request(http.MethodPost, deploy), &res)
}
|
go
|
func (c *Manager) DeployLibraryItem(ctx context.Context, libraryItemID string, deploy Deploy) (Deployment, error) {
url := internal.URL(c, internal.VCenterOVFLibraryItem).WithID(libraryItemID).WithAction("deploy")
var res Deployment
return res, c.Do(ctx, url.Request(http.MethodPost, deploy), &res)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"DeployLibraryItem",
"(",
"ctx",
"context",
".",
"Context",
",",
"libraryItemID",
"string",
",",
"deploy",
"Deploy",
")",
"(",
"Deployment",
",",
"error",
")",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"VCenterOVFLibraryItem",
")",
".",
"WithID",
"(",
"libraryItemID",
")",
".",
"WithAction",
"(",
"\"",
"\"",
")",
"\n",
"var",
"res",
"Deployment",
"\n",
"return",
"res",
",",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodPost",
",",
"deploy",
")",
",",
"&",
"res",
")",
"\n",
"}"
] |
// DeployLibraryItem deploys a library OVF
|
[
"DeployLibraryItem",
"deploys",
"a",
"library",
"OVF"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/vcenter/vcenter_ovf.go#L141-L145
|
21,598
|
vmware/govmomi
|
vapi/vcenter/vcenter_ovf.go
|
FilterLibraryItem
|
func (c *Manager) FilterLibraryItem(ctx context.Context, libraryItemID string, filter FilterRequest) (FilterResponse, error) {
url := internal.URL(c, internal.VCenterOVFLibraryItem).WithID(libraryItemID).WithAction("filter")
var res FilterResponse
return res, c.Do(ctx, url.Request(http.MethodPost, filter), &res)
}
|
go
|
func (c *Manager) FilterLibraryItem(ctx context.Context, libraryItemID string, filter FilterRequest) (FilterResponse, error) {
url := internal.URL(c, internal.VCenterOVFLibraryItem).WithID(libraryItemID).WithAction("filter")
var res FilterResponse
return res, c.Do(ctx, url.Request(http.MethodPost, filter), &res)
}
|
[
"func",
"(",
"c",
"*",
"Manager",
")",
"FilterLibraryItem",
"(",
"ctx",
"context",
".",
"Context",
",",
"libraryItemID",
"string",
",",
"filter",
"FilterRequest",
")",
"(",
"FilterResponse",
",",
"error",
")",
"{",
"url",
":=",
"internal",
".",
"URL",
"(",
"c",
",",
"internal",
".",
"VCenterOVFLibraryItem",
")",
".",
"WithID",
"(",
"libraryItemID",
")",
".",
"WithAction",
"(",
"\"",
"\"",
")",
"\n",
"var",
"res",
"FilterResponse",
"\n",
"return",
"res",
",",
"c",
".",
"Do",
"(",
"ctx",
",",
"url",
".",
"Request",
"(",
"http",
".",
"MethodPost",
",",
"filter",
")",
",",
"&",
"res",
")",
"\n",
"}"
] |
// FilterLibraryItem deploys a library OVF
|
[
"FilterLibraryItem",
"deploys",
"a",
"library",
"OVF"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/vcenter/vcenter_ovf.go#L148-L152
|
21,599
|
vmware/govmomi
|
vapi/rest/client.go
|
NewClient
|
func NewClient(c *vim25.Client) *Client {
sc := c.Client.NewServiceClient(internal.Path, "")
return &Client{sc}
}
|
go
|
func NewClient(c *vim25.Client) *Client {
sc := c.Client.NewServiceClient(internal.Path, "")
return &Client{sc}
}
|
[
"func",
"NewClient",
"(",
"c",
"*",
"vim25",
".",
"Client",
")",
"*",
"Client",
"{",
"sc",
":=",
"c",
".",
"Client",
".",
"NewServiceClient",
"(",
"internal",
".",
"Path",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"&",
"Client",
"{",
"sc",
"}",
"\n",
"}"
] |
// NewClient creates a new Client instance.
|
[
"NewClient",
"creates",
"a",
"new",
"Client",
"instance",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/vapi/rest/client.go#L40-L44
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.